effectMap = array_combine( array_map('strtolower', $this->effectMap), $this->effectMap ); parent::__construct(); } function call__($method, $params) { if (is_object($this->hook) && method_exists($this->hook, $method)) { $this->hook->dispatchMethod($method . '_', $params); } if (method_exists($this, $method . '_')) { return $this->dispatchMethod($method . '_', $params); } } function alert_($message) { return 'alert("' . $this->escape($message) . '");'; } function if_($if, $then, $else = null, $elseIf = array()) { $len = strlen($if) - 1; if ($if{$len} == ';') { $if{$len} = null; } $out = 'if (' . $if . ') { ' . $then . ' }'; foreach ($elseIf as $cond => $exec) { //$out .= } if (!empty($else)) { $out .= ' else { ' . $else . ' }'; } return $out; } function confirm_($message) { return 'confirm("' . $this->escape($message) . '");'; } function prompt_($message, $default = '') { return 'prompt("' . $this->escape($message) . '", "' . $this->escape($default) . '");'; } /* * Tries a series of expressions, and executes after first successful completion. * (See Prototype's Try.these). * * @return string */ function tryThese_($expr1, $expr2, $expr3) { } /** * Loads a remote URL * * @param string $url * @param array $options * @return string */ function load_($url = null, $options = array()) { if (isset($options['update'])) { if (!is_array($options['update'])) { $func = "new Ajax.Updater('{$options['update']}',"; } else { $func = "new Ajax.Updater(document.createElement('div'),"; } if (!isset($options['requestHeaders'])) { $options['requestHeaders'] = array(); } if (is_array($options['update'])) { $options['update'] = implode(' ', $options['update']); } $options['requestHeaders']['X-Update'] = $options['update']; } else { $func = "new Ajax.Request("; } $func .= "'" . Router::url($url) . "'"; $ajax =& new AjaxHelper(); $func .= ", " . $ajax->__optionsForAjax($options) . ")"; if (isset($options['before'])) { $func = "{$options['before']}; $func"; } if (isset($options['after'])) { $func = "$func; {$options['after']};"; } if (isset($options['condition'])) { $func = "if ({$options['condition']}) { $func; }"; } if (isset($options['confirm'])) { $func = "if (confirm('" . $this->Javascript->escapeString($options['confirm']) . "')) { $func; } else { return false; }"; } return $func; } /** * Redirects to a URL * * @param mixed $url * @param array $options * @return string */ function redirect_($url = null) { return 'window.location = "' . Router::url($url) . '";'; } /** * Escape a string to be JavaScript friendly. * * List of escaped ellements: * + "\r\n" => '\n' * + "\r" => '\n' * + "\n" => '\n' * + '"' => '\"' * + "'" => "\\'" * * @param string $script String that needs to get escaped. * @return string Escaped string. */ function escape($string) { $escape = array("\r\n" => '\n', "\r" => '\n', "\n" => '\n', '"' => '\"', "'" => "\\'"); return str_replace(array_keys($escape), array_values($escape), $string); } function get__($name) { return $this->__object($name, 'id'); } function select($pattern) { return $this->__object($pattern, 'pattern'); } function real($var) { return $this->__object($var, 'real'); } function __object($name, $var) { if (!isset($this->__objects[$name])) { $this->__objects[$name] = new JsHelperObject($this); $this->__objects[$name]->{$var} = $name; } return $this->__objects[$name]; } /** * Generates a JavaScript object in JavaScript Object Notation (JSON) * from an array * * @param array $data Data to be converted * @param boolean $block Wraps return value in a