Updating JsHelper

This commit is contained in:
mark_story 2009-03-07 11:08:49 -05:00
parent ea177fb7d8
commit 86c7d62fc2

View file

@ -31,46 +31,132 @@
* @package cake * @package cake
* @subpackage cake.cake.libs.view.helpers * @subpackage cake.cake.libs.view.helpers
*/ */
class JsHelper extends Overloadable2 { class JsHelper extends Overloadable {
/**
* Base URL
*
* @var string
*/
var $base = null; var $base = null;
/**
* Webroot path
*
* @var string
*/
var $webroot = null; var $webroot = null;
var $here = null; /**
var $params = null; * Theme name
var $action = null; *
var $data = null; * @var string
*/
var $themeWeb = null; var $themeWeb = null;
/**
* URL to current action.
*
* @var string
*/
var $here = null;
/**
* Parameter array.
*
* @var array
*/
var $params = array();
/**
* Current action.
*
* @var string
*/
var $action = null;
/**
* Plugin path
*
* @var string
*/
var $plugin = null; var $plugin = null;
/**
var $helpers = array(); * POST data for models
*
var $hook = null; * @var array
*/
var $data = null;
/**
* helpers
*
* @var array
**/
public $helpers = array();
/**
* Current Javascript Engine that is being used
*
* @var string
* @access private
**/
var $__engineName;
/**
* __objects
*
* @var array
*/
var $__objects = array(); var $__objects = array();
var $effectMap = array( var $effectMap = array(
'Appear', 'Fade', 'Puff', 'BlindDown', 'BlindUp', 'SwitchOff', 'SlideDown', 'SlideUp', 'Appear', 'Fade', 'Puff', 'BlindDown', 'BlindUp', 'SwitchOff', 'SlideDown', 'SlideUp',
'DropOut', 'Shake', 'Pulsate', 'Squish', 'Fold', 'Grow', 'Shrink', 'Highlight', 'toggle' 'DropOut', 'Shake', 'Pulsate', 'Squish', 'Fold', 'Grow', 'Shrink', 'Highlight', 'toggle'
); );
/**
* output
*
* @var string
*/
var $output = false; var $output = false;
/**
function __construct() { * Constructor - determines engine helper
$this->effectMap = array_combine( *
array_map('strtolower', $this->effectMap), * @param array $settings Settings array contains name of engine helper.
$this->effectMap * @access public
); * @return void
*/
function __construct($settings = array()) {
$className = 'jquery';
if (is_array($settings) && isset($settings[0])) {
$className = $settings[0];
} elseif (is_string($settings)) {
$className = $settings;
}
$engineName = $className;
if (strpos($className, '.') !== false) {
list($plugin, $className) = explode('.', $className);
}
$this->__engineName = $className . 'Engine';
$engineClass = $engineName . 'Engine';
$this->helpers = array($engineClass);
parent::__construct(); parent::__construct();
} }
/**
* call__
*
* @param string $method Method to be called
* @param array $params Parameters for the method being called.
* @access public
* @return void
*/
function call__($method, $params) { function call__($method, $params) {
if (is_object($this->hook) && method_exists($this->hook, $method)) { if (isset($this->{$this->__engineName}) && method_exists($this->{$this->__engineName}, $method)) {
$this->hook->dispatchMethod($method . '_', $params); return $this->{$this->__engineName}->dispatchMethod($method, $params);
} }
if (method_exists($this, $method . '_')) { if (method_exists($this, $method . '_')) {
return $this->dispatchMethod($method . '_', $params); return $this->dispatchMethod($method . '_', $params);
} }
trigger_error(sprintf(__('JsHelper:: Missing Method %s is undefined', true), $method), E_USER_WARNING);
} }
/**
* Create an alert message in Javascript
*
* @param string $message Message you want to alter.
* @access public
* @return void
*/
function alert_($message) { function alert_($message) {
return 'alert("' . $this->escape($message) . '");'; return 'alert("' . $this->escape($message) . '");';
} }
@ -93,11 +179,24 @@ class JsHelper extends Overloadable2 {
return $out; return $out;
} }
/**
* Create a confirm() message
*
* @param string $message Message you want confirmed.
* @access public
* @return void
*/
function confirm_($message) { function confirm_($message) {
return 'confirm("' . $this->escape($message) . '");'; return 'confirm("' . $this->escape($message) . '");';
} }
/**
* Create a prompt() Javascript function
*
* @param string $message Message you want to prompt.
* @param string $default Default message
* @access public
* @return void
*/
function prompt_($message, $default = '') { function prompt_($message, $default = '') {
return 'prompt("' . $this->escape($message) . '", "' . $this->escape($default) . '");'; return 'prompt("' . $this->escape($message) . '", "' . $this->escape($default) . '");';
} }
@ -182,10 +281,10 @@ class JsHelper extends Overloadable2 {
return str_replace(array_keys($escape), array_values($escape), $string); return str_replace(array_keys($escape), array_values($escape), $string);
} }
function get__($name) { /* function get__($name) {
return $this->__object($name, 'id'); return $this->__object($name, 'id');
} }
*/
function select($pattern) { function select($pattern) {
return $this->__object($pattern, 'pattern'); return $this->__object($pattern, 'pattern');
} }