From 375a194e2f1da30a5d1f159ae6a2797627a00da5 Mon Sep 17 00:00:00 2001 From: secretr Date: Mon, 14 May 2012 06:26:52 +0000 Subject: [PATCH] introducing e107::css() and e107::js() - easy way to register CSS and JS scripts (core, themes, plugins). --- e107_handlers/e107_class.php | 97 ++++++++++++++++++++++++++++++++++++ e107_handlers/js_manager.php | 2 +- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index cd5cbdf4f..68dfd9a17 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -1346,6 +1346,103 @@ class e107 } return e_jsmanager::getInstance(); } + + /** + * Proxy method for easy js registering. Prefered is shortcode script path + * @param string $type core|theme|footer|inline|footer-inline|url or any existing plugin_name + * @param string $data depends on the type - path/url or inline js source + * @param integer $zone [optional] leave it null for default zone + */ + public static function js($type, $data, $zone = null) + { + $jshandler = e107::getJs(); + switch ($type) + { + case 'core': + // data is e.g. 'core/tabs.js' + if(null !== $zone) $jshandler->requireCoreLib($data, $zone); + else $jshandler->requireCoreLib($data); + break; + + case 'theme': + // data is e.g. 'jslib/mytheme.js' + if(null !== $zone) $jshandler->headerTheme($data, $zone); + else $jshandler->headerTheme($data); + break; + + case 'inline': + // data is JS source (without script tags) + if(null !== $zone) $jshandler->headerInline($data, $zone); + else $jshandler->headerInline($data); + break; + + case 'footer-inline': + // data is JS source (without script tags) + if(null !== $zone) $jshandler->footerInline($data, $zone); + else $jshandler->footerInline($data); + break; + + case 'url': + // data is e.g. 'http://cdn.somesite.com/some.js' + if(null !== $zone) $jshandler->headerFile($data, $zone); + else $jshandler->headerFile($data); + break; + + case 'footer': + // data is e.g. '{e_PLUGIN}myplugin/jslib/myplug.js' + if(null !== $zone) $jshandler->footerFile($data, $zone); + else $jshandler->footerFile($data); + break; + + // $type is plugin name + default: + // data is e.g. 'jslib/myplug.js' + if(null !== $zone) $jshandler->requirePluginLib($type, $data, $zone); + else $jshandler->requirePluginLib($type, $data); + break; + } + } + + /** + * Proxy method for easy css registering + * @param string $type core|theme|footer|inline|footer-inline|url or any existing plugin_name + * @param string $data depends on the type - path/url or inline js source + * @param string $media any valid media attribute string - http://www.w3schools.com/TAGS/att_link_media.asp + * @param string $preComment possible comment e.g. + */ + public static function css($type, $data, $media = 'all', $preComment = '', $postComment = '') + { + $jshandler = e107::getJs(); + switch ($type) + { + case 'core': + // data is path relative to e_FILE/jslib/ + $jshandler->coreCSS($data, $media, $preComment, $postComment); + break; + + case 'theme': + // data is path relative to current theme + $jshandler->themeCSS($data, $media, $preComment, $postComment); + break; + + case 'inline': + // data is CSS source (without style tags) + $jshandler->inlineCSS($data, $media); + break; + + case 'url': + // data is e.g. 'http://cdn.somesite.com/some.css' + $jshandler->otherCSS($data, $media, $preComment, $postComment); + break; + + // $type is plugin name + default: + // data is e.g. 'css/myplug.css' + $jshandler->pluginCSS($type, $data, $media, $preComment, $postComment); + break; + } + } /** * Retrieve JS Helper object diff --git a/e107_handlers/js_manager.php b/e107_handlers/js_manager.php index 2dbc63c6d..b1a669323 100644 --- a/e107_handlers/js_manager.php +++ b/e107_handlers/js_manager.php @@ -7,7 +7,7 @@ * GNU General Public License (http://gnu.org). * * $URL$ - * Id$ + * $Id$ * */ global $pref, $eplug_admin, $THEME_JSLIB, $THEME_CORE_JSLIB;