aboutsummaryrefslogtreecommitdiffstats
path: root/include/template.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/template.class.php')
-rw-r--r--include/template.class.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/include/template.class.php b/include/template.class.php
index 7b4e4caf1..25389b8fa 100644
--- a/include/template.class.php
+++ b/include/template.class.php
@@ -62,6 +62,7 @@ class Template {
$this->smarty->register_modifier( 'translate', array('Template', 'mod_translate') );
$this->smarty->register_modifier( 'explode', array('Template', 'mod_explode') );
$this->smarty->register_block('html_head', array(&$this, 'block_html_head') );
+ $this->smarty->register_function('known_script', array(&$this, 'func_known_script'), false );
$this->smarty->register_prefilter( array('Template', 'prefilter_white_space') );
if ( $conf['compiled_template_cache_language'] )
{
@@ -339,6 +340,37 @@ class Template {
}
}
+ /**
+ * This smarty "known_script" functions allows to insert well known java scripts
+ * such as prototype, jquery, etc... only once. Examples:
+ * {known_script id="jquery" src="{$ROOT_URL}template-common/lib/jquery.packed.js"}
+ */
+ function func_known_script($params, &$smarty )
+ {
+ if (!isset($params['id']))
+ {
+ $smarty->trigger_error("known_script: missing 'id' parameter");
+ return;
+ }
+ $id = $params['id'];
+ if (! isset( $this->known_scripts[$id] ) )
+ {
+ if (!isset($params['src']))
+ {
+ $smarty->trigger_error("known_script: missing 'src' parameter");
+ return;
+ }
+ $this->known_scripts[$id] = $params['src'];
+ $content = '<script type="text/javascript" src="'.$params['src'].'"></script>';
+ if (isset($params['now']) and $params['now'] and empty($this->output) )
+ {
+ return $content;
+ }
+ $repeat = false;
+ $this->block_html_head(null, $content, $smarty, $repeat);
+ }
+ }
+
/*static */ function prefilter_white_space($source, &$smarty)
{
$ld = $smarty->left_delimiter;