Skip to content

Commit

Permalink
pyro:theme:js can now take extra attributes like image and css.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Sturgeon committed Sep 29, 2011
1 parent caef975 commit 6209490
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
8 changes: 4 additions & 4 deletions system/cms/helpers/asset_helper.php
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions system/cms/libraries/Asset.php
Expand Up @@ -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>';
}

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -381,6 +383,4 @@ public function set_theme($theme)

}

// END Asset Class

/* End of file Asset.php */
14 changes: 12 additions & 2 deletions system/cms/plugins/theme.php
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 6209490

Please sign in to comment.