From 77d4613bd8324c58fa8a3d1877ecdbbc09f2b9c6 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Tue, 2 Mar 2021 09:23:27 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B03750=20Allow=20to=20detect=20when=20read?= =?UTF-8?q?y=20scripts=20are=20done=20processing=20In=20iTop=203.0.0=20the?= =?UTF-8?q?re=20are=20sometimes=20lots=20of=20scripts=20launched=20after?= =?UTF-8?q?=20domReady,=20so=20we=20needed=20something=20to=20know=20when?= =?UTF-8?q?=20those=20scripts=20are=20done=20!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/application/WebPage/AjaxPage.php | 2 +- sources/application/WebPage/NiceWebPage.php | 14 ++++++ sources/application/WebPage/WebPage.php | 51 +++++++++++++++++++-- sources/application/WebPage/iTopWebPage.php | 7 ++- 4 files changed, 66 insertions(+), 8 deletions(-) diff --git a/sources/application/WebPage/AjaxPage.php b/sources/application/WebPage/AjaxPage.php index db42dcd8e..6b2517fb3 100644 --- a/sources/application/WebPage/AjaxPage.php +++ b/sources/application/WebPage/AjaxPage.php @@ -179,7 +179,7 @@ EOF 'aCssInline' => $this->a_styles, 'aJsFiles' => $this->a_linked_scripts, 'aJsInlineLive' => $this->a_scripts, - 'aJsInlineOnDomReady' => $this->a_ready_scripts, + 'aJsInlineOnDomReady' => $this->GetReadyScripts(), 'aJsInlineOnInit' => $this->a_init_scripts, 'bEscapeContent' => ($this->sContentType == 'text/html') && ($this->sContentDisposition == 'inline'), // TODO 3.0.0: TEMP, used while developping, remove it. diff --git a/sources/application/WebPage/NiceWebPage.php b/sources/application/WebPage/NiceWebPage.php index 602bd2df1..4afea7c8a 100644 --- a/sources/application/WebPage/NiceWebPage.php +++ b/sources/application/WebPage/NiceWebPage.php @@ -235,4 +235,18 @@ EOF ) ); } + + protected function GetReadyScriptsStartedTrigger(): ?string + { + return <<a_ready_scripts; + + $sReadyStartedTriggerScript = $this->GetReadyScriptsStartedTrigger(); + if (!empty($sReadyStartedTriggerScript)) { + array_unshift($aReadyScripts, $sReadyStartedTriggerScript); + } + + $sReadyFinishedTriggerScript = $this->GetReadyScriptsFinishedTrigger(); + if (!empty($sReadyFinishedTriggerScript)) { + $aReadyScripts[] = $sReadyFinishedTriggerScript; + } + + return $aReadyScripts; + } + + /** + * @return ?string script to execute before all ready scripts + * @since 3.0.0 N°3750 method creation + */ + protected function GetReadyScriptsStartedTrigger(): ?string + { + return null; + } + + /** + * @return ?string script to execute after all ready scripts are done processing + * @since 3.0.0 N°3750 method creation + */ + protected function GetReadyScriptsFinishedTrigger(): ?string + { + return null; + } + /** * Empty all base linked scripts for the page * - * @uses \WebPage::$a_linked_scripts * @return void + * @uses \WebPage::$a_linked_scripts * @since 3.0.0 */ protected function EmptyLinkedScripts(): void @@ -1041,7 +1086,7 @@ class WebPage implements Page 'aCssInline' => $this->a_styles, 'aJsFiles' => $this->a_linked_scripts, 'aJsInlineLive' => $this->a_scripts, - 'aJsInlineOnDomReady' => $this->a_ready_scripts, + 'aJsInlineOnDomReady' => $this->GetReadyScripts(), 'aJsInlineOnInit' => $this->a_init_scripts, // TODO 3.0.0: TEMP, used while developing, remove it. diff --git a/sources/application/WebPage/iTopWebPage.php b/sources/application/WebPage/iTopWebPage.php index aa7839c66..37ced3fd0 100644 --- a/sources/application/WebPage/iTopWebPage.php +++ b/sources/application/WebPage/iTopWebPage.php @@ -925,7 +925,7 @@ HTML; 'aCssInline' => $this->a_styles, 'aJsFiles' => $this->a_linked_scripts, 'aJsInlineOnInit' => $this->a_init_scripts, - 'aJsInlineOnDomReady' => $this->a_ready_scripts, + 'aJsInlineOnDomReady' => $this->GetReadyScripts(), 'aJsInlineLive' => $this->a_scripts, // TODO 3.0.0: TEMP, used while developping, remove it. 'sSanitizedContent' => utils::FilterXSS($this->s_content), @@ -1244,9 +1244,8 @@ EOF */ protected function OutputPrintable(): BlockPrintHeader { - $oBlock= new BlockPrintHeader(); + $oBlock = new BlockPrintHeader(); + return $oBlock; } - - }