summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI/WebControls')
-rw-r--r--framework/Web/UI/WebControls/TClientScript.php120
-rw-r--r--framework/Web/UI/WebControls/TStyleSheet.php7
2 files changed, 29 insertions, 98 deletions
diff --git a/framework/Web/UI/WebControls/TClientScript.php b/framework/Web/UI/WebControls/TClientScript.php
index b2fbf925..abc23c45 100644
--- a/framework/Web/UI/WebControls/TClientScript.php
+++ b/framework/Web/UI/WebControls/TClientScript.php
@@ -22,11 +22,6 @@
* <com:TClientScript UsingPradoScripts="effects, rico" />
* </code>
*
- * The {@link setPreRenderControlTypes PreRenderControlTypes} property can
- * be used to specify that controls type/class names that should pre-render itself
- * even though they may not be rendered on the page. This is useful to publish
- * controls that require assets and is only visible after a callback response.
- *
* Custom javascript files can be register using the {@link setScriptUrl ScriptUrl}
* property.
* <code>
@@ -34,18 +29,13 @@
* </code>
*
* Contents within TClientScript will be treated as javascript code and will be
- * rendered.
- *
- * The {@link setScriptPosition ScriptPosition} property specifies where the script
- * will be rendered. The allows values of {@link setScriptPosition ScriptPosition} are
+ * rendered in place.
*
- * - <b>Head</b> -- renders the script within the &lt;head&gt;
- * - <b>Begin</b> -- renders the script within and near the begining of TForm
- * - <b>Here</b> -- renders the script inplace, this is the default
- * - <b>End</b> -- renders the script within and near the end of TForm
+ * The {@link setPreRenderControlTypes PreRenderControlTypes} property can
+ * be used to specify that controls type/class names that should pre-render itself
+ * even though they may not be rendered on the page. This is useful to publish
+ * controls that require assets and is only visible after a callback response.
*
- * TODO: Allow binding expressions inside scripts
- *
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
@@ -54,11 +44,6 @@
class TClientScript extends TControl
{
/**
- * @var string body contents
- */
- private $_content = '';
-
- /**
* @return string comma delimited list of javascript libraries to included
* on the page.
*/
@@ -112,26 +97,7 @@ class TClientScript extends TControl
{
return $this->getViewState('PreRenderControls', '');
}
-
- /**
- * @return string position the script should be rendered, default is 'Here'.
- */
- public function getScriptPosition()
- {
- return $this->getViewState('ScriptPosition', 'Here');
- }
-
- /**
- * Sets the position where the script will be rendered.
- * The allow positions are 'Head', 'Begin', 'Here', and 'End', default is 'Here'.
- * @param string script position 'Head', 'Begin', 'Here' or 'End'.
- */
- public function setScriptPosition($value)
- {
- $this->setViewState('ScriptPosition',
- TPropertyValue::ensureEnum($value, 'Head', 'Begin', 'Here', 'End'), 'Here');
- }
-
+
/**
* Calls the client script manager to add each of the requested client
* script libraries.
@@ -148,42 +114,9 @@ class TClientScript extends TControl
if(strlen($script) > 0)
$cs->registerPradoScript($script);
}
- if($this->getEnabled(true))
- {
- $this->registerCustomScriptFile();
- $this->registerCustomScript();
- }
$this->preRenderControls($param);
}
-
- /**
- * Registers the custom script file.
- */
- protected function registerCustomScriptFile()
- {
- $scriptUrl = $this->getScriptUrl();
- if(strlen($scriptUrl))
- {
- $position = $this->getScriptPosition();
- $cs = $this->getPage()->getClientScript();
- switch($this->getScriptPosition())
- {
- case 'Head':
- $cs->registerHeadScriptFile($scriptUrl, $scriptUrl);
- break;
- case 'Begin':
- $cs->registerScriptFile($scriptUrl, $scriptUrl);
- break;
- case 'Here':
- $this->_content .= TJavascript::renderScriptFile($scriptUrl);
- break;
- default :
- throw new TConfigurationException('clientscript_invalid_file_position',
- $this->getID(), $position);
- }
- }
- }
-
+
/**
* Renders the body content as javascript block.
* Overrides parent implementation, parent renderChildren method is called during
@@ -192,31 +125,32 @@ class TClientScript extends TControl
*/
public function render($writer)
{
- if($this->getEnabled(true) && strlen($this->_content) > 0)
- $writer->write($this->_content);
+ $this->renderCustomScriptFile($writer);
+ $this->renderCustomScript($writer);
}
/**
- * Registers the body content as scripts at specific locations. Calls
- * {@link parent::renderChildren} to capture the body contents.
+ * Renders the custom script file.
+ * @param THtmLWriter the renderer
+ */
+ protected function renderCustomScriptFile($writer)
+ {
+ $scriptUrl = $this->getScriptUrl();
+ if(strlen($scriptUrl) > 0)
+ $writer->write("<script type=\"text/javascript\" src=\"$scriptUrl\"></script>\n");
+ }
+
+ /**
+ * Registers the body content as javascript.
+ * @param THtmlWriter the renderer
*/
- protected function registerCustomScript()
+ protected function renderCustomScript($writer)
{
- $textWriter=new TTextWriter;
- $this->renderChildren(new THtmlWriter($textWriter));
- $script=$textWriter->flush();
- if(strlen($script)>0)
+ if($this->getHasControls())
{
- $cs = $this->getPage()->getClientScript();
- $position = $this->getScriptPosition();
- if($position == 'Here')
- $this->_content .= TJavaScript::renderScriptBlock($script);
- else
- {
- $key = sprintf('%08X', crc32($script));
- $method = 'register'.$position.'Script';
- $cs->{$method}($key, $script);
- }
+ $writer->write("<script type=\"text/javascript\">\n/*<![CDATA[*/\n");
+ $this->renderChildren($writer);
+ $writer->write("\n/*]]>*/\n</script>\n");
}
}
diff --git a/framework/Web/UI/WebControls/TStyleSheet.php b/framework/Web/UI/WebControls/TStyleSheet.php
index 02ac40cd..5925645c 100644
--- a/framework/Web/UI/WebControls/TStyleSheet.php
+++ b/framework/Web/UI/WebControls/TStyleSheet.php
@@ -52,11 +52,8 @@ class TStyleSheet extends TControl
*/
public function onPreRender($param)
{
- if($this->getEnabled(true))
- {
- if(($url=$this->getStyleSheetUrl())!=='')
- $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url);
- }
+ if(($url=$this->getStyleSheetUrl())!=='')
+ $this->getPage()->getClientScript()->registerStyleSheetFile($url,$url);
}
/**