From d479bdcfb9190b54f0396352f2d663a311b140e9 Mon Sep 17 00:00:00 2001 From: yois <> Date: Tue, 9 Oct 2007 01:25:44 +0000 Subject: preparing for Advanced topic translation --- .../protected/pages/Advanced/es/Scripts3.page | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 demos/quickstart/protected/pages/Advanced/es/Scripts3.page (limited to 'demos/quickstart/protected/pages/Advanced/es/Scripts3.page') diff --git a/demos/quickstart/protected/pages/Advanced/es/Scripts3.page b/demos/quickstart/protected/pages/Advanced/es/Scripts3.page new file mode 100644 index 00000000..c06a8a6b --- /dev/null +++ b/demos/quickstart/protected/pages/Advanced/es/Scripts3.page @@ -0,0 +1,91 @@ + +

Javascript in PRADO, Questions and Answers

+

How do I include the Javascript libraries distributed with Prado?

+

The javascript libraries distributed with Prado can be found in the +framework/Web/Javascripts/source directory. The packages.php +file in that directory defines a list of available package names available +to be loaded. They can be loaded as follows. +

+ +The available packaged libraries included in Prado are + + +

The dependencies for each library are automatically resolved. Components +that require a particular library will also automatically load the necessary libraries. +For example, if you add a TDatePicker component on the page, the datepicker +and its dependencies will be automatically included on the page.

+ +

See TClientScript for options of adding + your custom Javascript code to the page.

+ +

Publishing Javascript Libraries as Assets

+ +

Use TClientScriptLoader to publish and combine multiple existing javascript files (e.g. javascript libraries distributed with Prado or otherwise) +as packages.

For greater control on what and when to publish, use the +registerJavascriptPackages($base, $packages, $debug=null, $gzip=true) +method in the TClientScriptManager class, which an instance can be obtained +using $this->getPage()->getClientScript() or its equivalents. +For example, if multiple controls will use the same set of javascript libraries, +write a class to handle the registration of packages required by those controls. +

+ +class MyJavascriptLib extends TComponent +{ + private $_packages=array(); //keep track of all registrations + + private $_manager; + + protected function __construct(TPage $owner) + { + $this->_manager = $owner->getClientScript(); + $owner->onPreRenderComplete = array($this, 'registerScriptLoader'); + } + + public static function registerPackage(TControl $control, $name) + { + static $instance; + if($instance===null) + $instance=new self($control->getPage()); + $instance->_packages[$name]=true; + } + + protected function registerScriptLoader() + { + $dir = dirname(__FILE__).'/myscripts'; //contains my javascript files + $scripts = array_keys($this->_packages); + $url = $this->_manager->registerJavascriptPackages($dir, $scripts); + $this->_manager->registerScriptFile($url,$url); + } +} + +// example control class using the javascript packages +class TestComp extends TControl +{ + public function onPreRender($param) + { + parent::onPreRender($param); + MyJavascriptLib::registerPackage($this,'package1'); + } +} + + + +
$Id: Scripts3.page 1902 2007-05-07 04:17:37Z wei $
\ No newline at end of file -- cgit v1.2.3