]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/ActiveControls/TActiveClientScript.php
4443ea3061ad8cd6f198dbbd3ebebb1a2ed33712
[bacula/bacula] / gui / baculum / framework / Web / UI / ActiveControls / TActiveClientScript.php
1 <?php
2 /**
3  * TActiveClientScript class file
4  *
5  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6  * @link http://www.pradosoft.com/
7  * @copyright Copyright &copy; 2005-2014 PradoSoft
8  * @license http://www.pradosoft.com/license/
9  * @package System.Web.UI.ActiveControls
10  */
11
12 /**
13  * TActiveClientScript class
14  *
15  * This is the active counterpart of the {@link TClientScript} class.
16  *
17  * TActiveClientScript has the ability to render itself on ajax
18  * callbacks. This means that every variable or function declared in javascript
19  * code will be available to the page.
20  *
21  * Beware that when rendered on normal (postback) or ajax callbacks, some
22  * javascript code won't behave in the same way.
23  * When rendered as part of a normal/postback response, scripts will execute instantly
24  * where they are in the page and in a synchronous fashion.
25  * Instead, when they are rendered as part of a callback response,
26  * they will be executed when all DOM modifications are complete and any dynamic
27  * script file includes are loaded, out-of-band and practically all blocks at once,
28  * regardless of where they actually occour in the original template/markup code.
29  * This can potentially hurt compatibility and graceful fallback.
30  *
31  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
32  * @package System.Web.UI.ActiveControls
33  * @since 3.2
34  */
35
36 class TActiveClientScript extends TClientScript
37 {
38         /**
39          * Renders the custom script file.
40          * @param THtmLWriter the renderer
41          */
42         protected function renderCustomScriptFile($writer)
43         {
44                 if(($scriptUrl = $this->getScriptUrl())!=='')
45                 {
46                         if($this->getPage()->getIsCallback())
47                         {
48                                 $cs = $this->getPage()->getClientScript();
49                                 $uniqueid=$this->ClientID.'_custom';
50                                 if(!$cs->isScriptFileRegistered($uniqueid))
51                                         $cs->registerScriptFile($uniqueid, $scriptUrl);
52                         } else {
53                                 $writer->write("<script type=\"text/javascript\" src=\"$scriptUrl\"></script>\n");
54                         }
55                 }
56         }
57
58         /**
59          * Registers the body content as javascript.
60          * @param THtmlWriter the renderer
61          */
62         protected function renderCustomScript($writer)
63         {
64                 if($this->getHasControls())
65                 {
66                         if($this->getPage()->getIsCallback())
67                         {
68                                 $extWriter= $this->getPage()->getResponse()->createHtmlWriter();
69                                 $extWriter->write("/*<![CDATA[*/\n");
70                                 $this->renderChildren($extWriter);
71                                 $extWriter->write("\n/*]]>*/");
72                                 $this->getPage()->getCallbackClient()->appendScriptBlock($extWriter);
73                         } else {
74                                 $writer->write("<script type=\"text/javascript\">\n/*<![CDATA[*/\n");
75                                 $this->renderChildren($writer);
76                                 $writer->write("\n/*]]>*/\n</script>\n");
77                         }
78                 }
79         }
80 }