2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is for rendering HTML script tags
|
|
|
|
*
|
|
|
|
* @package lnApp
|
|
|
|
* @subpackage Page
|
|
|
|
* @category Helpers
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2010 Deon George
|
|
|
|
* @license http://dev.leenooks.net/license.html
|
|
|
|
*/
|
2012-07-12 06:38:09 +00:00
|
|
|
abstract class lnApp_Script extends HTMLRender {
|
2010-11-29 22:41:08 +00:00
|
|
|
protected static $_data = array();
|
|
|
|
protected static $_spacer = "\n";
|
|
|
|
protected static $_required_keys = array('type','data');
|
|
|
|
protected static $_unique_vals = array('file'=>'type');
|
2012-06-26 14:28:18 +00:00
|
|
|
protected static $_rendered = FALSE;
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an instance of this class
|
|
|
|
*
|
|
|
|
* @return Script
|
|
|
|
*/
|
|
|
|
public static function factory() {
|
|
|
|
return new Script;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the script tag
|
|
|
|
*
|
|
|
|
* @see HTMLRender::render()
|
|
|
|
*/
|
|
|
|
protected function render() {
|
|
|
|
$foutput = $soutput = '';
|
|
|
|
$mediapath = Route::get(static::$_media_path);
|
|
|
|
|
|
|
|
foreach (static::$_data as $value) {
|
|
|
|
switch ($value['type']) {
|
|
|
|
case 'file':
|
|
|
|
$foutput .= HTML::script($mediapath->uri(array('file'=>$value['data'])));
|
|
|
|
break;
|
2012-12-10 21:48:30 +00:00
|
|
|
case 'src':
|
|
|
|
$foutput .= HTML::script($value['data']);
|
|
|
|
break;
|
2010-11-29 22:41:08 +00:00
|
|
|
case 'stdin':
|
|
|
|
$soutput .= sprintf("<script type=\"text/javascript\">//<![CDATA[\n%s\n//]]></script>",$value['data']);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Kohana_Exception('Unknown style type :type',array(':type'=>$value['type']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
static::$_rendered = TRUE;
|
2010-11-29 22:41:08 +00:00
|
|
|
return $foutput.static::$_spacer.$soutput;
|
|
|
|
}
|
2012-06-26 14:28:18 +00:00
|
|
|
|
|
|
|
public static function add($item,$prepend=FALSE,$x='') {
|
|
|
|
if (static::$_rendered)
|
|
|
|
throw new Kohana_Exception('Already rendered?');
|
|
|
|
|
|
|
|
return parent::add($item,$prepend);
|
|
|
|
}
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
?>
|