2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Javascript Generator class file.
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* CakePHP : Rapid Development Framework (http://www.cakephp.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2008-10-30 17:30:26 +00:00
|
|
|
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view.helpers
|
|
|
|
* @since CakePHP v 1.2
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Javascript Generator helper class for easy use of JavaScript.
|
|
|
|
*
|
|
|
|
* JsHelper provides an abstract interface for authoring JavaScript with a
|
|
|
|
* given client-side library.
|
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view.helpers
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-07 18:10:50 +00:00
|
|
|
class JsHelper extends AppHelper {
|
2009-03-07 16:08:49 +00:00
|
|
|
/**
|
2009-03-29 18:23:42 +00:00
|
|
|
* Whether or not you want scripts to be buffered or output.
|
2009-03-07 16:08:49 +00:00
|
|
|
*
|
2009-03-16 03:42:25 +00:00
|
|
|
* @var boolean
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-29 18:23:42 +00:00
|
|
|
var $bufferScripts = true;
|
2009-03-07 16:08:49 +00:00
|
|
|
/**
|
2009-03-16 03:42:25 +00:00
|
|
|
* helpers
|
2009-03-07 16:08:49 +00:00
|
|
|
*
|
|
|
|
* @var array
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-16 03:42:25 +00:00
|
|
|
var $helpers = array('Html');
|
2009-03-07 16:08:49 +00:00
|
|
|
/**
|
2009-03-16 03:42:25 +00:00
|
|
|
* Scripts that are queued for output
|
2009-03-07 16:08:49 +00:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
**/
|
2009-03-29 18:23:42 +00:00
|
|
|
var $__bufferedScripts = array();
|
2009-03-07 16:08:49 +00:00
|
|
|
/**
|
|
|
|
* Current Javascript Engine that is being used
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access private
|
|
|
|
**/
|
|
|
|
var $__engineName;
|
|
|
|
/**
|
|
|
|
* __objects
|
|
|
|
*
|
|
|
|
* @var array
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $__objects = array();
|
2009-03-07 16:08:49 +00:00
|
|
|
/**
|
|
|
|
* output
|
|
|
|
*
|
|
|
|
* @var string
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $output = false;
|
2009-03-07 16:08:49 +00:00
|
|
|
/**
|
|
|
|
* Constructor - determines engine helper
|
|
|
|
*
|
|
|
|
* @param array $settings Settings array contains name of engine helper.
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-07 16:08:49 +00:00
|
|
|
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';
|
2009-03-13 03:48:19 +00:00
|
|
|
$this->helpers[] = $engineClass;
|
2008-05-30 11:40:08 +00:00
|
|
|
parent::__construct();
|
|
|
|
}
|
2009-03-07 16:08:49 +00:00
|
|
|
/**
|
2009-03-29 18:38:09 +00:00
|
|
|
* call__ Allows for dispatching of methods to the Engine Helper.
|
|
|
|
* methods in the Engines bufferedMethods list will be automatically buffered.
|
|
|
|
* You can control buffering with the buffer param as well. By setting the last parameter to
|
|
|
|
* any engine method to a boolean you can force or disable buffering.
|
|
|
|
*
|
|
|
|
* e.g. ```$js->get('#foo')->effect('fadeIn', array('speed' => 'slow'), true);```
|
|
|
|
*
|
|
|
|
* Will force buffering for the effect method. If the method takes an options array you may also add
|
|
|
|
* a 'buffer' param to the options array and control buffering there as well.
|
|
|
|
*
|
|
|
|
* e.g. ```$js->get('#foo')->event('click', $functionContents, array('buffer' => true));
|
|
|
|
*
|
|
|
|
* The buffer parameter will not be passed onto the EngineHelper.
|
2009-03-07 16:08:49 +00:00
|
|
|
*
|
|
|
|
* @param string $method Method to be called
|
|
|
|
* @param array $params Parameters for the method being called.
|
|
|
|
* @access public
|
2009-03-29 18:38:09 +00:00
|
|
|
* @return mixed
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2008-05-30 11:40:08 +00:00
|
|
|
function call__($method, $params) {
|
2009-03-07 16:08:49 +00:00
|
|
|
if (isset($this->{$this->__engineName}) && method_exists($this->{$this->__engineName}, $method)) {
|
2009-03-29 20:10:04 +00:00
|
|
|
$buffer = false;
|
|
|
|
if (in_array(strtolower($method), $this->{$this->__engineName}->bufferedMethods)) {
|
|
|
|
$buffer = true;
|
|
|
|
}
|
|
|
|
if (count($params) > 0) {
|
|
|
|
$lastParam = $params[count($params) - 1];
|
|
|
|
$hasBufferParam = (is_bool($lastParam) || is_array($lastParam) && isset($lastParam['buffer']));
|
|
|
|
if ($hasBufferParam && is_bool($lastParam)) {
|
|
|
|
$buffer = $lastParam;
|
|
|
|
unset($params[count($params) - 1]);
|
|
|
|
} elseif ($hasBufferParam && is_array($lastParam)) {
|
|
|
|
$buffer = $lastParam['buffer'];
|
|
|
|
unset($params['buffer']);
|
|
|
|
}
|
|
|
|
}
|
2009-03-16 03:42:25 +00:00
|
|
|
$out = $this->{$this->__engineName}->dispatchMethod($method, $params);
|
2009-03-29 20:10:04 +00:00
|
|
|
if ($this->bufferScripts && $buffer && is_string($out)) {
|
2009-03-29 18:23:42 +00:00
|
|
|
$this->buffer($out);
|
2009-03-29 20:10:04 +00:00
|
|
|
return null;
|
2009-03-29 18:23:42 +00:00
|
|
|
}
|
|
|
|
if (is_object($out) && is_a($out, 'JsBaseEngineHelper')) {
|
|
|
|
return $this;
|
2009-03-16 03:42:25 +00:00
|
|
|
}
|
|
|
|
return $out;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
if (method_exists($this, $method . '_')) {
|
2008-09-07 03:26:58 +00:00
|
|
|
return $this->dispatchMethod($method . '_', $params);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-03-07 16:08:49 +00:00
|
|
|
trigger_error(sprintf(__('JsHelper:: Missing Method %s is undefined', true), $method), E_USER_WARNING);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-03-07 18:10:50 +00:00
|
|
|
/**
|
2009-03-13 03:48:19 +00:00
|
|
|
* Writes all Javascript generated so far to a code block or
|
|
|
|
* caches them to a file and returns a linked script.
|
2009-03-07 18:10:50 +00:00
|
|
|
*
|
2009-03-13 03:48:19 +00:00
|
|
|
* Options
|
2009-03-07 18:10:50 +00:00
|
|
|
*
|
2009-03-13 03:48:19 +00:00
|
|
|
* - 'inline' - Set to true to have scripts output as a script block inline
|
|
|
|
* if 'cache' is also true, a script link tag will be generated. (default true)
|
2009-03-20 02:05:06 +00:00
|
|
|
* - 'cache' - Set to true to have scripts cached to a file and linked in (default false)
|
2009-03-13 03:48:19 +00:00
|
|
|
* - 'clear' - Set to false to prevent script cache from being cleared (default true)
|
|
|
|
* - 'onDomReady' - wrap cached scripts in domready event (default true)
|
|
|
|
* - 'safe' - if an inline block is generated should it be wrapped in <![CDATA[ ... ]]> (default true)
|
2009-03-07 18:10:50 +00:00
|
|
|
*
|
2009-03-13 03:48:19 +00:00
|
|
|
* @param array $options options for the code block
|
|
|
|
* @return string completed javascript tag.
|
2009-03-07 18:10:50 +00:00
|
|
|
**/
|
2009-03-29 18:23:42 +00:00
|
|
|
function writeBuffer($options = array()) {
|
2009-03-20 02:05:06 +00:00
|
|
|
$defaults = array('onDomReady' => true, 'inline' => true, 'cache' => false, 'clear' => true, 'safe' => true);
|
2009-03-13 03:48:19 +00:00
|
|
|
$options = array_merge($defaults, $options);
|
2009-03-29 18:23:42 +00:00
|
|
|
$script = implode("\n", $this->getBuffer($options['clear']));
|
2009-03-13 03:48:19 +00:00
|
|
|
|
|
|
|
if ($options['onDomReady']) {
|
|
|
|
$script = $this->{$this->__engineName}->domReady($script);
|
2009-03-07 18:10:50 +00:00
|
|
|
}
|
2009-03-13 03:48:19 +00:00
|
|
|
if (!$options['cache'] && $options['inline']) {
|
|
|
|
return $this->Html->scriptBlock($script, $options);
|
2009-03-08 03:06:00 +00:00
|
|
|
}
|
2009-03-13 03:48:19 +00:00
|
|
|
if ($options['cache'] && $options['inline']) {
|
2009-03-20 02:02:18 +00:00
|
|
|
$filename = md5($script);
|
|
|
|
if (!file_exists(JS . $filename . '.js')) {
|
|
|
|
cache(str_replace(WWW_ROOT, '', JS) . $filename . '.js', $script, '+999 days', 'public');
|
|
|
|
}
|
|
|
|
return $this->Html->script($filename);
|
2009-03-07 18:10:50 +00:00
|
|
|
}
|
2009-03-13 03:48:19 +00:00
|
|
|
$view =& ClassRegistry::getObject('view');
|
|
|
|
$view->addScript($script);
|
|
|
|
return null;
|
2009-03-07 18:10:50 +00:00
|
|
|
}
|
2009-03-16 03:42:25 +00:00
|
|
|
/**
|
|
|
|
* Write a script to the cached scripts.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
2009-03-29 18:23:42 +00:00
|
|
|
function buffer($script) {
|
|
|
|
$this->__bufferedScripts[] = $script;
|
2009-03-16 03:42:25 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Get all the cached scripts
|
|
|
|
*
|
|
|
|
* @param boolean $clear Whether or not to clear the script caches
|
|
|
|
* @return array Array of scripts added to the request.
|
|
|
|
**/
|
2009-03-29 18:23:42 +00:00
|
|
|
function getBuffer($clear = true) {
|
|
|
|
$scripts = $this->__bufferedScripts;
|
2009-03-16 03:42:25 +00:00
|
|
|
if ($clear) {
|
2009-03-29 18:23:42 +00:00
|
|
|
$this->__bufferedScripts = array();
|
2009-03-16 03:42:25 +00:00
|
|
|
}
|
|
|
|
return $scripts;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Loads a remote URL
|
|
|
|
*
|
|
|
|
* @param string $url
|
|
|
|
* @param array $options
|
|
|
|
* @return string
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-13 03:48:19 +00:00
|
|
|
/* function load_($url = null, $options = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
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'] = join(' ', $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;
|
|
|
|
}
|
2009-03-08 03:06:00 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-03-13 03:48:19 +00:00
|
|
|
/*
|
|
|
|
function get__($name) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->__object($name, 'id');
|
|
|
|
}
|
2009-03-13 03:48:19 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
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];
|
|
|
|
}
|
2009-03-13 03:48:19 +00:00
|
|
|
*/
|
2009-03-08 01:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-03-29 18:38:09 +00:00
|
|
|
* JsEngineBaseClass
|
|
|
|
*
|
2009-03-08 01:16:11 +00:00
|
|
|
* Abstract Base Class for All JsEngines to extend. Provides generic methods.
|
|
|
|
*
|
|
|
|
* @package cake.view.helpers
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-08 01:16:11 +00:00
|
|
|
class JsBaseEngineHelper extends AppHelper {
|
|
|
|
/**
|
|
|
|
* Determines whether native JSON extension is used for encoding. Set by object constructor.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
* @access public
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-08 01:16:11 +00:00
|
|
|
var $useNative = false;
|
2009-03-13 03:48:19 +00:00
|
|
|
/**
|
|
|
|
* The js snippet for the current selection.
|
|
|
|
*
|
|
|
|
* @var string
|
2009-03-14 00:50:31 +00:00
|
|
|
* @access public
|
2009-03-13 03:48:19 +00:00
|
|
|
**/
|
2009-03-14 00:50:31 +00:00
|
|
|
var $selection;
|
2009-03-14 21:01:49 +00:00
|
|
|
/**
|
|
|
|
* Collection of option maps.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
**/
|
|
|
|
var $_optionMap = array();
|
2009-03-29 18:38:09 +00:00
|
|
|
/**
|
2009-03-29 20:10:04 +00:00
|
|
|
* An array of lowercase method names in the Engine that are buffered unless otherwise disabled.
|
|
|
|
* This allows specific 'end point' methods to be automatically buffered by the JsHelper.
|
2009-03-29 18:38:09 +00:00
|
|
|
*
|
2009-03-29 20:10:04 +00:00
|
|
|
* @var array
|
2009-03-29 18:38:09 +00:00
|
|
|
**/
|
2009-03-29 20:14:56 +00:00
|
|
|
var $bufferedMethods = array('event', 'sortable', 'drag', 'drop');
|
2009-03-08 01:16:11 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function __construct() {
|
|
|
|
$this->useNative = function_exists('json_encode');
|
|
|
|
}
|
2009-03-08 03:06:00 +00:00
|
|
|
/**
|
|
|
|
* Create an alert message in Javascript
|
|
|
|
*
|
|
|
|
* @param string $message Message you want to alter.
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-08 03:06:00 +00:00
|
|
|
function alert($message) {
|
|
|
|
return 'alert("' . $this->escape($message) . '");';
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Redirects to a URL
|
|
|
|
*
|
|
|
|
* @param mixed $url
|
|
|
|
* @param array $options
|
|
|
|
* @return string
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-08 03:06:00 +00:00
|
|
|
function redirect($url = null) {
|
|
|
|
return 'window.location = "' . Router::url($url) . '";';
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Create a confirm() message
|
|
|
|
*
|
|
|
|
* @param string $message Message you want confirmed.
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-08 03:06:00 +00:00
|
|
|
function confirm($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
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-08 03:06:00 +00:00
|
|
|
function prompt($message, $default = '') {
|
|
|
|
return 'prompt("' . $this->escape($message) . '", "' . $this->escape($default) . '");';
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Generates a JavaScript object in JavaScript Object Notation (JSON)
|
2009-03-08 03:06:00 +00:00
|
|
|
* from an array. Will use native JSON encode method if available, and $useNative == true
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-08 01:16:11 +00:00
|
|
|
* Options:
|
2009-03-08 06:28:07 +00:00
|
|
|
*
|
|
|
|
* - 'prefix' - String prepended to the returned data.
|
|
|
|
* - 'postfix' - String appended to the returned data.
|
|
|
|
* - 'stringKeys' - A list of array keys to be treated as a string
|
|
|
|
* - 'quoteKeys' - If false treats $options['stringKeys'] as a list of keys **not** to be quoted.
|
|
|
|
* - 'q' - Type of quote to use.
|
|
|
|
*
|
2009-03-08 01:16:11 +00:00
|
|
|
* @param array $data Data to be converted.
|
|
|
|
* @param array $options Set of options, see above.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string A JSON code block
|
2009-03-08 06:28:07 +00:00
|
|
|
* @access public
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-08 01:16:11 +00:00
|
|
|
function object($data = array(), $options = array()) {
|
|
|
|
$defaultOptions = array(
|
|
|
|
'block' => false, 'prefix' => '', 'postfix' => '',
|
|
|
|
'stringKeys' => array(), 'quoteKeys' => true, 'q' => '"'
|
|
|
|
);
|
|
|
|
$options = array_merge($defaultOptions, $options);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_object($data)) {
|
|
|
|
$data = get_object_vars($data);
|
|
|
|
}
|
|
|
|
|
2009-03-08 01:16:11 +00:00
|
|
|
$out = $keys = array();
|
2008-05-30 11:40:08 +00:00
|
|
|
$numeric = true;
|
|
|
|
|
2009-03-08 01:16:11 +00:00
|
|
|
if ($this->useNative) {
|
|
|
|
$rt = json_encode($data);
|
|
|
|
} else {
|
2009-03-13 23:37:57 +00:00
|
|
|
if (is_null($data)) {
|
|
|
|
return 'null';
|
|
|
|
}
|
|
|
|
if (is_bool($data)) {
|
|
|
|
return $data ? 'true' : 'false';
|
|
|
|
}
|
2009-03-08 01:16:11 +00:00
|
|
|
if (is_array($data)) {
|
|
|
|
$keys = array_keys($data);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2009-03-08 01:16:11 +00:00
|
|
|
if (!empty($keys)) {
|
|
|
|
$numeric = (array_values($keys) === array_keys(array_values($keys)));
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($data as $key => $val) {
|
|
|
|
if (is_array($val) || is_object($val)) {
|
|
|
|
$val = $this->object($val, array_merge($options, array('block' => false)));
|
|
|
|
} else {
|
|
|
|
$quoteStrings = (
|
|
|
|
!count($options['stringKeys']) ||
|
|
|
|
($options['quoteKeys'] && in_array($key, $options['stringKeys'], true)) ||
|
|
|
|
(!$options['quoteKeys'] && !in_array($key, $options['stringKeys'], true))
|
|
|
|
);
|
|
|
|
$val = $this->value($val, $quoteStrings);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-03-08 01:16:11 +00:00
|
|
|
if (!$numeric) {
|
|
|
|
$val = $options['q'] . $this->value($key, false) . $options['q'] . ':' . $val;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-03-08 01:16:11 +00:00
|
|
|
$out[] = $val;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$numeric) {
|
2009-03-08 01:16:11 +00:00
|
|
|
$rt = '{' . join(',', $out) . '}';
|
|
|
|
} else {
|
|
|
|
$rt = '[' . join(',', $out) . ']';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-08 01:16:11 +00:00
|
|
|
$rt = $options['prefix'] . $rt . $options['postfix'];
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-03-08 01:16:11 +00:00
|
|
|
if ($options['block']) {
|
|
|
|
$rt = $this->codeBlock($rt, array_diff_key($options, $defaultOptions));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return $rt;
|
|
|
|
}
|
2009-03-08 01:16:11 +00:00
|
|
|
/**
|
|
|
|
* Converts a PHP-native variable of any type to a JSON-equivalent representation
|
|
|
|
*
|
|
|
|
* @param mixed $val A PHP variable to be converted to JSON
|
|
|
|
* @param boolean $quoteStrings If false, leaves string values unquoted
|
|
|
|
* @return string a JavaScript-safe/JSON representation of $val
|
2009-03-08 06:28:07 +00:00
|
|
|
* @access public
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-08 01:16:11 +00:00
|
|
|
function value($val, $quoteStrings = true) {
|
|
|
|
switch (true) {
|
|
|
|
case (is_array($val) || is_object($val)):
|
|
|
|
$val = $this->object($val);
|
|
|
|
break;
|
|
|
|
case ($val === null):
|
|
|
|
$val = 'null';
|
|
|
|
break;
|
|
|
|
case (is_bool($val)):
|
|
|
|
$val = ($val === true) ? 'true' : 'false';
|
|
|
|
break;
|
|
|
|
case (is_int($val)):
|
|
|
|
$val = $val;
|
|
|
|
break;
|
|
|
|
case (is_float($val)):
|
|
|
|
$val = sprintf("%.11f", $val);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$val = $this->escape($val);
|
|
|
|
if ($quoteStrings) {
|
|
|
|
$val = '"' . $val . '"';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $val;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 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.
|
2009-03-08 06:28:07 +00:00
|
|
|
* @access public
|
2009-03-09 02:33:34 +00:00
|
|
|
**/
|
2009-03-08 01:16:11 +00:00
|
|
|
function escape($string) {
|
|
|
|
$escape = array("\r\n" => '\n', "\r" => '\n', "\n" => '\n', '"' => '\"', "'" => "\\'");
|
|
|
|
return str_replace(array_keys($escape), array_values($escape), $string);
|
|
|
|
}
|
2009-03-13 03:48:19 +00:00
|
|
|
/**
|
|
|
|
* Create javascript selector for a CSS rule
|
|
|
|
*
|
|
|
|
* @param string $selector The selector that is targeted
|
|
|
|
* @return object instance of $this. Allows chained methods.
|
|
|
|
**/
|
2009-03-15 21:48:27 +00:00
|
|
|
function get($selector) {
|
2009-03-14 04:10:43 +00:00
|
|
|
trigger_error(sprintf(__('%s does not have get() implemented', true), get_class($this)), E_USER_WARNING);
|
2009-03-13 03:48:19 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Add an event to the script cache. Operates on the currently selected elements.
|
|
|
|
*
|
2009-03-15 16:10:46 +00:00
|
|
|
* ### Options
|
|
|
|
*
|
|
|
|
* - 'wrap' - Whether you want the callback wrapped in an anonymous function. (defaults to true)
|
|
|
|
* - 'stop' - Whether you want the event to stopped. (defaults to true)
|
|
|
|
*
|
2009-03-13 03:48:19 +00:00
|
|
|
* @param string $type Type of event to bind to the current dom id
|
|
|
|
* @param string $callback The Javascript function you wish to trigger or the function literal
|
2009-03-15 16:10:46 +00:00
|
|
|
* @param array $options Options for the event.
|
2009-03-13 03:48:19 +00:00
|
|
|
* @return string completed event handler
|
|
|
|
**/
|
2009-03-15 16:10:46 +00:00
|
|
|
function event($type, $callback, $options = array()) {
|
2009-03-14 04:10:43 +00:00
|
|
|
trigger_error(sprintf(__('%s does not have event() implemented', true), get_class($this)), E_USER_WARNING);
|
2009-03-13 03:48:19 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Create a domReady event. This is a special event in many libraries
|
|
|
|
*
|
|
|
|
* @param string $functionBody The code to run on domReady
|
|
|
|
* @return string completed domReady method
|
|
|
|
**/
|
|
|
|
function domReady($functionBody) {
|
2009-03-14 04:10:43 +00:00
|
|
|
trigger_error(sprintf(__('%s does not have domReady() implemented', true), get_class($this)), E_USER_WARNING);
|
2009-03-13 03:48:19 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Create an iteration over the current selection result.
|
|
|
|
*
|
|
|
|
* @param string $callback The function body you wish to apply during the iteration.
|
|
|
|
* @return string completed iteration
|
|
|
|
**/
|
2009-03-14 00:50:31 +00:00
|
|
|
function each($callback) {
|
2009-03-14 04:10:43 +00:00
|
|
|
trigger_error(sprintf(__('%s does not have each() implemented', true), get_class($this)), E_USER_WARNING);
|
2009-03-13 03:48:19 +00:00
|
|
|
}
|
2009-03-14 05:57:24 +00:00
|
|
|
/**
|
|
|
|
* Trigger an Effect.
|
|
|
|
*
|
2009-03-14 17:48:31 +00:00
|
|
|
* ### Supported Effects
|
2009-03-14 05:57:24 +00:00
|
|
|
*
|
|
|
|
* The following effects are supported by all JsEngines
|
|
|
|
*
|
|
|
|
* - 'show' - reveal an element.
|
|
|
|
* - 'hide' - hide an element.
|
|
|
|
* - 'fadeIn' - Fade in an element.
|
|
|
|
* - 'fadeOut' - Fade out an element.
|
|
|
|
* - 'slideIn' - Slide an element in.
|
|
|
|
* - 'slideOut' - Slide an element out.
|
|
|
|
*
|
2009-03-14 17:48:31 +00:00
|
|
|
* ### Options
|
2009-03-14 05:57:24 +00:00
|
|
|
*
|
|
|
|
* - 'speed' - Speed at which the animation should occur. Accepted values are 'slow', 'fast'. Not all effects use
|
|
|
|
* the speed option.
|
|
|
|
*
|
|
|
|
* @param string $name The name of the effect to trigger.
|
|
|
|
* @param array $options Array of options for the effect.
|
|
|
|
* @return string completed string with effect.
|
|
|
|
**/
|
|
|
|
function effect($name, $options) {
|
|
|
|
trigger_error(sprintf(__('%s does not have effect() implemented', true), get_class($this)), E_USER_WARNING);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Make an XHR request
|
|
|
|
*
|
2009-03-28 03:30:03 +00:00
|
|
|
* ### Event Options
|
2009-03-14 17:48:31 +00:00
|
|
|
*
|
|
|
|
* - 'complete' - Callback to fire on complete.
|
|
|
|
* - 'request' - Callback to fire on request initialization.
|
|
|
|
* - 'error' - Callback to fire on request failure.
|
2009-03-28 03:30:03 +00:00
|
|
|
*
|
|
|
|
* ### Options
|
|
|
|
*
|
|
|
|
* - 'method' - The method to make the request with defaults to GET in more libraries
|
2009-03-14 17:48:31 +00:00
|
|
|
* - 'async' - Whether or not you want an asynchronous request.
|
|
|
|
* - 'data' - Additional data to send.
|
2009-03-30 02:08:49 +00:00
|
|
|
* - 'update' - Dom id to update with the content of the request.
|
2009-03-14 17:48:31 +00:00
|
|
|
* - 'type' - Data type for response. 'json' and 'html' are supported. Default is html for most libraries.
|
2009-03-30 02:08:49 +00:00
|
|
|
* - 'evalScripts' - Whether or not <script> tags should be eval'ed.
|
2009-03-14 17:48:31 +00:00
|
|
|
*
|
|
|
|
* @param mixed $url Array or String URL to target with the request.
|
|
|
|
* @param array $options Array of options. See above for cross library supported options
|
2009-03-14 05:57:24 +00:00
|
|
|
* @return string XHR request.
|
|
|
|
**/
|
2009-03-14 17:48:31 +00:00
|
|
|
function request($url, $options = array()) {
|
2009-03-14 05:57:24 +00:00
|
|
|
trigger_error(sprintf(__('%s does not have request() implemented', true), get_class($this)), E_USER_WARNING);
|
|
|
|
}
|
2009-03-16 03:42:25 +00:00
|
|
|
/**
|
|
|
|
* Create a draggable element. Works on the currently selected element.
|
|
|
|
* Additional options may be supported by your library.
|
|
|
|
*
|
|
|
|
* ### Options
|
2009-03-28 03:30:03 +00:00
|
|
|
*
|
2009-03-28 03:24:08 +00:00
|
|
|
* - handle - selector to the handle element.
|
2009-03-16 03:42:25 +00:00
|
|
|
* - snapGrid - The pixel grid that movement snaps to, an array(x, y)
|
|
|
|
* - container - The element that acts as a bounding box for the draggable element.
|
|
|
|
*
|
2009-03-28 03:30:03 +00:00
|
|
|
* ### Event Options
|
|
|
|
*
|
|
|
|
* - start - Event fired when the drag starts
|
|
|
|
* - drag - Event fired on every step of the drag
|
|
|
|
* - stop - Event fired when dragging stops (mouse release)
|
|
|
|
*
|
2009-03-16 03:42:25 +00:00
|
|
|
* @param array $options Options array see above.
|
|
|
|
* @return string Completed drag script
|
|
|
|
**/
|
|
|
|
function drag($options = array()) {
|
2009-03-28 03:24:08 +00:00
|
|
|
trigger_error(sprintf(__('%s does not have drag() implemented', true), get_class($this)), E_USER_WARNING);
|
2009-03-16 03:42:25 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Create a droppable element. Allows for draggable elements to be dropped on it.
|
|
|
|
* Additional options may be supported by your library.
|
|
|
|
*
|
2009-03-28 03:30:03 +00:00
|
|
|
* ### Event Options
|
|
|
|
*
|
2009-03-16 03:42:25 +00:00
|
|
|
* - drag - Elements that can be dragged into this droppable
|
|
|
|
* - drop - Event fired when an element is dropped into the drop zone.
|
|
|
|
* - hover - Event fired when a drag enters a drop zone.
|
|
|
|
* - leave - Event fired when a drag is removed from a drop zone without being dropped.
|
|
|
|
*
|
|
|
|
* @return string Completed drop script
|
|
|
|
**/
|
|
|
|
function drop($options = array()) {
|
2009-03-28 03:24:08 +00:00
|
|
|
trigger_error(sprintf(__('%s does not have drop() implemented', true), get_class($this)), E_USER_WARNING);
|
2009-03-16 03:42:25 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Create a sortable element.
|
|
|
|
*
|
|
|
|
* ### Options
|
2009-03-28 03:30:03 +00:00
|
|
|
*
|
2009-03-28 03:24:08 +00:00
|
|
|
* - containment - Container for move action
|
|
|
|
* - handle - Selector to handle element. Only this element will start sort action.
|
|
|
|
* - revert - Whether or not to use an effect to move sortable into final position.
|
|
|
|
* - opacity - Opacity of the placeholder
|
2009-03-28 03:30:03 +00:00
|
|
|
* - distance - Distance a sortable must be dragged before sorting starts.
|
|
|
|
*
|
|
|
|
* ### Event Options
|
|
|
|
*
|
2009-03-28 03:24:08 +00:00
|
|
|
* - start - Event fired when sorting starts
|
|
|
|
* - sort - Event fired during sorting
|
|
|
|
* - complete - Event fired when sorting completes.
|
2009-03-16 03:42:25 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $options Array of options for the sortable. See above.
|
|
|
|
* @return string Completed sortable script.
|
|
|
|
**/
|
|
|
|
function sortable() {
|
2009-03-28 03:24:08 +00:00
|
|
|
trigger_error(sprintf(__('%s does not have sortable() implemented', true), get_class($this)), E_USER_WARNING);
|
2009-03-16 03:42:25 +00:00
|
|
|
}
|
2009-03-08 06:28:07 +00:00
|
|
|
/**
|
|
|
|
* Parse an options assoc array into an Javascript object literal.
|
|
|
|
* Similar to object() but treats any non-integer value as a string,
|
|
|
|
* does not include { }
|
|
|
|
*
|
|
|
|
* @param array $options Options to be converted
|
2009-03-15 16:26:12 +00:00
|
|
|
* @param array $safeKeys Keys that should not be escaped.
|
2009-03-08 06:28:07 +00:00
|
|
|
* @return string
|
|
|
|
* @access protected
|
|
|
|
**/
|
2009-03-15 16:26:12 +00:00
|
|
|
function _parseOptions($options, $safeKeys = array()) {
|
2009-03-08 06:28:07 +00:00
|
|
|
$out = array();
|
|
|
|
foreach ($options as $key => $value) {
|
2009-03-15 16:26:12 +00:00
|
|
|
if (!is_int($value) && !in_array($key, $safeKeys)) {
|
2009-03-15 17:08:29 +00:00
|
|
|
$value = $this->value($value);
|
2009-03-08 06:28:07 +00:00
|
|
|
}
|
2009-03-15 16:26:12 +00:00
|
|
|
$out[] = $key . ':' . $value;
|
2009-03-08 06:28:07 +00:00
|
|
|
}
|
2009-03-28 04:31:08 +00:00
|
|
|
sort($out);
|
2009-03-13 03:48:19 +00:00
|
|
|
return join(', ', $out);
|
2009-03-08 06:28:07 +00:00
|
|
|
}
|
2009-03-14 21:01:49 +00:00
|
|
|
/**
|
|
|
|
* Maps Abstract options to engine specific option names.
|
|
|
|
* If attributes are missing from the map, they are not changed.
|
|
|
|
*
|
|
|
|
* @param string $method Name of method whose options are being worked with.
|
|
|
|
* @param array $options Array of options to map.
|
|
|
|
* @return array Array of mapped options.
|
|
|
|
* @access protected
|
|
|
|
**/
|
|
|
|
function _mapOptions($method, $options) {
|
|
|
|
if (!isset($this->_optionMap[$method])) {
|
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
foreach ($this->_optionMap[$method] as $abstract => $concrete) {
|
|
|
|
if (isset($options[$abstract])) {
|
|
|
|
$options[$concrete] = $options[$abstract];
|
|
|
|
unset($options[$abstract]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $options;
|
|
|
|
}
|
2009-03-15 17:08:29 +00:00
|
|
|
/**
|
|
|
|
* Convert an array of data into a query string
|
|
|
|
*
|
|
|
|
* @param array $parameters Array of parameters to convert to a query string
|
|
|
|
* @return string Querystring fragment
|
|
|
|
* @access protected
|
|
|
|
**/
|
|
|
|
function _toQuerystring($parameters) {
|
|
|
|
$out = '';
|
|
|
|
$keys = array_keys($parameters);
|
|
|
|
$count = count($parameters);
|
|
|
|
for ($i = 0; $i < $count; $i++) {
|
|
|
|
$out .= $keys[$i] . '=' . $parameters[$keys[$i]];
|
|
|
|
if ($i < $count - 1) {
|
|
|
|
$out .= '&';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2009-03-08 01:16:11 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
class JsHelperObject {
|
|
|
|
var $__parent = null;
|
|
|
|
|
|
|
|
var $id = null;
|
|
|
|
|
|
|
|
var $pattern = null;
|
|
|
|
|
|
|
|
var $real = null;
|
|
|
|
|
|
|
|
function __construct(&$parent) {
|
|
|
|
if (is_object($parent)) {
|
|
|
|
$this->setParent($parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toString() {
|
|
|
|
return $this->__toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
function __toString() {
|
|
|
|
return $this->literal;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ref($ref = null) {
|
|
|
|
if ($ref == null) {
|
|
|
|
foreach (array('id', 'pattern', 'real') as $ref) {
|
|
|
|
if ($this->{$ref} !== null) {
|
|
|
|
return $this->{$ref};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return ($this->{$ref} !== null);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function literal($append = null) {
|
|
|
|
if (!empty($this->id)) {
|
|
|
|
$data = '$("' . $this->id . '")';
|
|
|
|
}
|
|
|
|
if (!empty($this->pattern)) {
|
|
|
|
$data = '$$("' . $this->pattern . '")';
|
|
|
|
}
|
|
|
|
if (!empty($this->real)) {
|
|
|
|
$data = $this->real;
|
|
|
|
}
|
|
|
|
if (!empty($append)) {
|
|
|
|
$data .= '.' . $append;
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function __call($name, $args) {
|
|
|
|
$data = '';
|
|
|
|
|
|
|
|
if (isset($this->__parent->effectMap[strtolower($name)])) {
|
|
|
|
array_unshift($args, $this->__parent->effectMap[strtolower($name)]);
|
|
|
|
$name = 'effect';
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($name) {
|
|
|
|
case 'effect':
|
|
|
|
case 'visualEffect':
|
|
|
|
|
|
|
|
if (strpos($args[0], '_') || $args[0]{0} != strtoupper($args[0]{0})) {
|
|
|
|
$args[0] = Inflector::camelize($args[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strtolower($args[0]) == 'highlight') {
|
|
|
|
$data .= 'new ';
|
|
|
|
}
|
|
|
|
if ($this->pattern == null) {
|
|
|
|
$data .= 'Effect.' . $args[0] . '(' . $this->literal();
|
|
|
|
} else {
|
|
|
|
$data .= 'Effect.' . $args[0] . '(item';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($args[1]) && is_array($args[1])) {
|
|
|
|
$data .= ', {' . $this->__options($args[1]) . '}';
|
|
|
|
}
|
|
|
|
$data .= ');';
|
|
|
|
|
|
|
|
if ($this->pattern !== null) {
|
|
|
|
$data = $this->each($data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'remove':
|
|
|
|
case 'toggle':
|
|
|
|
case 'show':
|
|
|
|
case 'hide':
|
|
|
|
if (empty($args)) {
|
|
|
|
$obj = 'Element';
|
|
|
|
$params = '';
|
|
|
|
} else {
|
|
|
|
$obj = 'Effect';
|
|
|
|
$params = ', "' . $args[0] . '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->pattern != null) {
|
|
|
|
$data = $this->each($obj . ".{$name}(item);");
|
|
|
|
} else {
|
|
|
|
$data = $obj . ".{$name}(" . $this->literal() . ');';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'visible':
|
|
|
|
$data = $this->literal() . '.visible();';
|
|
|
|
break;
|
|
|
|
case 'update':
|
|
|
|
$data = $this->literal() . ".update({$args[0]});";
|
|
|
|
break;
|
|
|
|
case 'load':
|
|
|
|
$data = 'new Ajax.Updater("' . $this->id . '", "' . $args[0] . '"';
|
|
|
|
if (isset($args[1]) && is_array($args[1])) {
|
|
|
|
$data .= ', {' . $this->__options($args[1]) . '}';
|
|
|
|
}
|
|
|
|
$data .= ');';
|
|
|
|
break;
|
|
|
|
case 'each':
|
|
|
|
case 'all':
|
|
|
|
case 'any':
|
|
|
|
case 'detect':
|
|
|
|
case 'findAll':
|
|
|
|
if ($this->pattern != null) {
|
|
|
|
$data = $this->__iterate($name, $args[0]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'addClass':
|
|
|
|
case 'removeClass':
|
|
|
|
case 'hasClass':
|
|
|
|
case 'toggleClass':
|
|
|
|
$data = $this->literal() . ".{$name}Name(\"{$args[0]}\");";
|
|
|
|
break;
|
|
|
|
case 'clone':
|
|
|
|
case 'inspect':
|
|
|
|
case 'keys':
|
|
|
|
case 'values':
|
|
|
|
$data = "Object.{$name}(" . $this->literal() . ");";
|
|
|
|
break;
|
|
|
|
case 'extend':
|
|
|
|
$data = "Object.extend(" . $this->literal() . ", {$args[0]});";
|
|
|
|
break;
|
|
|
|
case '...':
|
|
|
|
// Handle other methods here
|
|
|
|
// including interfaces to load other files on-the-fly
|
|
|
|
// that add support for additional methods/replacing existing methods
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$data = $this->literal() . '.' . $name . '();';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->__parent->output) {
|
|
|
|
echo $data;
|
|
|
|
} else {
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function __iterate($method, $data) {
|
|
|
|
return '$$("' . $this->pattern . '").' . $method . '(function(item) {' . $data . '});';
|
|
|
|
}
|
|
|
|
|
|
|
|
function setParent(&$parent) {
|
|
|
|
$this->__parent =& $parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
function __options($opts) {
|
|
|
|
$options = array();
|
|
|
|
foreach ($opts as $key => $val) {
|
|
|
|
if (!is_int($val)) {
|
|
|
|
$val = '"' . $val . '"';
|
|
|
|
}
|
|
|
|
$options[] = $key . ':' . $val;
|
|
|
|
}
|
|
|
|
return join(', ', $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|