summaryrefslogtreecommitdiff
path: root/framework/Web/UI
diff options
context:
space:
mode:
authorwei <>2007-04-05 01:57:22 +0000
committerwei <>2007-04-05 01:57:22 +0000
commit5d3f9a7de5ee0b0d8976398a490ed46b7107056f (patch)
tree2507dd2df914ec5fd20902c526ea6fe5919d6b04 /framework/Web/UI
parent51db38c9423a1d3bf476bb30054cf3288ee16c88 (diff)
add clientscripts for publishing user javascript libraries
Diffstat (limited to 'framework/Web/UI')
-rw-r--r--framework/Web/UI/WebControls/TClientScript.php80
1 files changed, 78 insertions, 2 deletions
diff --git a/framework/Web/UI/WebControls/TClientScript.php b/framework/Web/UI/WebControls/TClientScript.php
index 43817c44..8b80eb69 100644
--- a/framework/Web/UI/WebControls/TClientScript.php
+++ b/framework/Web/UI/WebControls/TClientScript.php
@@ -38,6 +38,8 @@
*/
class TClientScript extends TControl
{
+ const SCRIPT_LOADER = 'Web/Javascripts/clientscripts.php';
+
/**
* @return string comma delimited list of javascript libraries to included
* on the page.
@@ -50,8 +52,7 @@ class TClientScript extends TControl
/**
* Include javascript library to the current page. The current supported
* libraries are: "prado", "effects", "ajax", "validator", "logger",
- * "datepicker", "rico", "colorpicker". Library dependencies are
- * automatically resolved.
+ * "datepicker", "colorpicker". Library dependencies are automatically resolved.
*
* @param string comma delimited list of javascript libraries to include.
*/
@@ -77,6 +78,38 @@ class TClientScript extends TControl
}
/**
+ * @param string custom javascript library directory.
+ */
+ public function setPackagePath($value)
+ {
+ $this->setViewState('PackagePath', $value);
+ }
+
+ /**
+ * @return string custom javascript library directory.
+ */
+ public function getPackagePath()
+ {
+ return $this->getViewState('PackagePath');
+ }
+
+ /**
+ * @param string load specific packages from the javascript library in the PackagePath, comma delimited package names
+ */
+ public function setPackageScripts($value)
+ {
+ $this->setViewState('PackageScripts', $value,'');
+ }
+
+ /**
+ * @return string comma delimited list of javascript library packages to load.
+ */
+ public function getPackageScripts()
+ {
+ return $this->getViewState('PackageScripts','');
+ }
+
+ /**
* Calls the client script manager to add each of the requested client
* script libraries.
* @param mixed event parameter
@@ -102,6 +135,7 @@ class TClientScript extends TControl
public function render($writer)
{
$this->renderCustomScriptFile($writer);
+ $this->renderPackageScriptFile($writer);
$this->renderCustomScript($writer);
}
@@ -128,6 +162,48 @@ class TClientScript extends TControl
$writer->write("\n/*]]>*/\n</script>\n");
}
}
+
+ protected function renderPackageScriptFile($writer)
+ {
+ $baseUrl = $this->publishScriptLoader();
+ $scripts = split('/\s*[, ]+\s*/', $this->getPackageScripts());
+ $url = $baseUrl . '?js=' . implode(',', $scripts);
+ if($this->getApplication()->getMode()===TApplicationMode::Debug)
+ $url.='&amp;mode=debug';
+ $writer->write("<script type=\"text/javascript\" src=\"{$url}\"></script>\n");
+ }
+
+ protected function publishScriptLoader()
+ {
+ list($path, $url) = $this->getPublishedPackagePath();
+ if(is_dir($path))
+ {
+ $scriptLoader = Prado::getFrameworkPath().'/'.self::SCRIPT_LOADER;
+ $scriptLoaderFile = basename($scriptLoader);
+ $dest = $path.'/'.$scriptLoaderFile;
+ if(!is_file($dest))
+ copy($scriptLoader,$dest);
+ return $url.'/'.$scriptLoaderFile;
+ }
+ else
+ throw new TConfigurationException('clientscript_invalid_package_path',
+ $this->getPackagePath(), $this->getUniqueID());
+ }
+
+ protected function getPublishedPackagePath()
+ {
+ $assets = $this->getApplication()->getAssetManager();
+ //assumes dot path first
+ $dir = Prado::getPathOfNameSpace($packageDir);
+ if(!is_null($dir))
+ {
+ $url = $assets->publishFilePath($dir); //show throw an excemption if invalid
+ return array($dir, $url);
+ }
+ $url = $this->getPackagePath();
+ $packageDir = str_replace($assets->getBaseUrl(), '', $url);
+ return array($assets->getBasePath().$packageDir,$url);
+ }
}
?> \ No newline at end of file