Permalink
Browse files

pyro:theme:js can now take extra attributes like image and css.

  • Loading branch information...
Phil Sturgeon
Phil Sturgeon committed Sep 29, 2011
1 parent caef975 commit 6209490aac3fa3c76e6d6639b87d2aa6f117e21d
Showing with 21 additions and 11 deletions.
  1. +4 −4 system/cms/helpers/asset_helper.php
  2. +5 −5 system/cms/libraries/Asset.php
  3. +12 −2 system/cms/plugins/theme.php
@@ -85,16 +85,16 @@ function image_path($asset_name, $module_name = NULL)
// ------------------------------------------------------------------------
-function js($asset_name, $module_name = NULL)
+function js($asset_name, $module_name = NULL, $attributes = array())
{
$CI =& get_instance();
$CI->load->library('asset');
- return $CI->asset->js($asset_name, $module_name);
+ return $CI->asset->js($asset_name, $module_name, $attributes);
}
-function theme_js($asset)
+function theme_js($asset, $attributes = array())
{
- return js($asset, '_theme_');
+ return js($asset, '_theme_', $attributes);
}
function js_url($asset_name, $module_name = NULL)
@@ -176,11 +176,13 @@ public function image_url($asset_name, $module_name = NULL)
* @param string optional, module name
* @return string HTML code for JavaScript asset
*/
- public function js($asset_name, $module_name = NULL, $location_type = '')
+ public function js($asset_name, $module_name = NULL, $attributes = array(), $location_type = '')
{
+ $attribute_str = $this->_parse_asset_html($attributes);
+
$location_type = 'js_' . (in_array($location_type, array('url', 'path')) ? $location_type : 'path');
- return '<script type="text/javascript" src="' . $this->{$location_type}($asset_name, $module_name) . '"></script>';
+ return '<script type="text/javascript" src="' . $this->{$location_type}($asset_name, $module_name) . '"'.$attribute_str.'></script>';
}
// ------------------------------------------------------------------------
@@ -351,7 +353,7 @@ private function _parse_asset_html($attributes = NULL)
if (is_string($attributes))
{
- $attribute_str = $attributes;
+ $attribute_str = ' '.$attributes;
}
else if (is_array($attributes) || is_object($attributes))
{
@@ -381,6 +383,4 @@ public function set_theme($theme)
}
-// END Asset Class
-
/* End of file Asset.php */
@@ -220,16 +220,26 @@ function js($return = '')
$this->load->library('asset');
$file = $this->attribute('file');
+ $attributes = $this->attributes();
$module = $this->attribute('module', '_theme_');
$method = 'js' . (in_array($return, array('url', 'path')) ? '_' . $return : ($return = ''));
$base = $this->attribute('base', '');
+
+
+ foreach (array('file', 'module', 'base') as $key)
+ {
+ if (isset($attributes[$key]))
+ {
+ unset($attributes[$key]);
+ }
+ }
if ( ! $return)
{
- return $this->asset->{$method}($file, $module, $base);
+ return $this->asset->{$method}($file, $module, $attributes, $base);
}
- return $this->asset->{$method}($file, $module);
+ return $this->asset->{$method}($file, $module, $attributes);
}
/**

0 comments on commit 6209490

Please sign in to comment.