3 * TActiveClientScript class file
5 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6 * @link http://www.pradosoft.com/
7 * @copyright Copyright © 2005-2014 PradoSoft
8 * @license http://www.pradosoft.com/license/
9 * @package System.Web.UI.ActiveControls
13 * TActiveClientScript class
15 * This is the active counterpart of the {@link TClientScript} class.
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.
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.
31 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
32 * @package System.Web.UI.ActiveControls
36 class TActiveClientScript extends TClientScript
39 * Renders the custom script file.
40 * @param THtmLWriter the renderer
42 protected function renderCustomScriptFile($writer)
44 if(($scriptUrl = $this->getScriptUrl())!=='')
46 if($this->getPage()->getIsCallback())
48 $cs = $this->getPage()->getClientScript();
49 $uniqueid=$this->ClientID.'_custom';
50 if(!$cs->isScriptFileRegistered($uniqueid))
51 $cs->registerScriptFile($uniqueid, $scriptUrl);
53 $writer->write("<script type=\"text/javascript\" src=\"$scriptUrl\"></script>\n");
59 * Registers the body content as javascript.
60 * @param THtmlWriter the renderer
62 protected function renderCustomScript($writer)
64 if($this->getHasControls())
66 if($this->getPage()->getIsCallback())
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);
74 $writer->write("<script type=\"text/javascript\">\n/*<![CDATA[*/\n");
75 $this->renderChildren($writer);
76 $writer->write("\n/*]]>*/\n</script>\n");