Skip to content

Commit

Permalink
Merging with self.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Apr 24, 2009
1 parent 4507d2b commit 9754926
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 196 deletions.
24 changes: 20 additions & 4 deletions cake/libs/view/helpers/jquery_engine.php
Expand Up @@ -47,8 +47,13 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
'drop' => array( 'drop' => array(
'leave' => 'out', 'leave' => 'out',
'hover' => 'over' 'hover' => 'over'
),
'slider' => array(
'complete' => 'stop',
'direction' => 'orientation'
) )
); );

/** /**
* Helper function to wrap repetitive simple method templating. * Helper function to wrap repetitive simple method templating.
* *
Expand All @@ -65,6 +70,7 @@ function _methodTemplate($method, $template, $options, $callbacks) {
$options = $this->_parseOptions($options, $callbacks); $options = $this->_parseOptions($options, $callbacks);
return sprintf($template, $this->selection, $options); return sprintf($template, $this->selection, $options);
} }

/** /**
* Create javascript selector for a CSS rule * Create javascript selector for a CSS rule
* *
Expand All @@ -79,6 +85,7 @@ function get($selector) {
} }
return $this; return $this;
} }

/** /**
* Add an event to the script cache. Operates on the currently selected elements. * Add an event to the script cache. Operates on the currently selected elements.
* *
Expand All @@ -105,6 +112,7 @@ function event($type, $callback, $options = array()) {
} }
return sprintf('%s.bind("%s", %s);', $this->selection, $type, $callback); return sprintf('%s.bind("%s", %s);', $this->selection, $type, $callback);
} }

/** /**
* Create a domReady event. This is a special event in many libraries * Create a domReady event. This is a special event in many libraries
* *
Expand All @@ -114,6 +122,7 @@ function event($type, $callback, $options = array()) {
function domReady($functionBody) { function domReady($functionBody) {
return $this->get('document')->event('ready', $functionBody, array('stop' => false)); return $this->get('document')->event('ready', $functionBody, array('stop' => false));
} }

/** /**
* Create an iteration over the current selection result. * Create an iteration over the current selection result.
* *
Expand All @@ -124,6 +133,7 @@ function domReady($functionBody) {
function each($callback) { function each($callback) {
return $this->selection . '.each(function () {' . $callback . '});'; return $this->selection . '.each(function () {' . $callback . '});';
} }

/** /**
* Trigger an Effect. * Trigger an Effect.
* *
Expand Down Expand Up @@ -151,6 +161,7 @@ function effect($name, $options = array()) {
} }
return $this->selection . $effect; return $this->selection . $effect;
} }

/** /**
* Create an $.ajax() call. * Create an $.ajax() call.
* *
Expand All @@ -175,6 +186,7 @@ function request($url, $options = array()) {
$options = $this->_parseOptions($options, $callbacks); $options = $this->_parseOptions($options, $callbacks);
return '$.ajax({' . $options .'});'; return '$.ajax({' . $options .'});';
} }

/** /**
* Create a sortable element. * Create a sortable element.
* *
Expand All @@ -190,6 +202,7 @@ function sortable($options = array()) {
$template = '%s.sortable({%s});'; $template = '%s.sortable({%s});';
return $this->_methodTemplate('sortable', $template, $options, $callbacks); return $this->_methodTemplate('sortable', $template, $options, $callbacks);
} }

/** /**
* Create a Draggable element * Create a Draggable element
* *
Expand All @@ -204,6 +217,7 @@ function drag($options = array()) {
$template = '%s.draggable({%s});'; $template = '%s.draggable({%s});';
return $this->_methodTemplate('drag', $template, $options, $callbacks); return $this->_methodTemplate('drag', $template, $options, $callbacks);
} }

/** /**
* Create a Droppable element * Create a Droppable element
* *
Expand All @@ -223,12 +237,14 @@ function drop($options = array()) {
* *
* Requires the Ui.Core and Ui.Slider to be loaded. * Requires the Ui.Core and Ui.Slider to be loaded.
* *
* @param array $options Array of options for the slider. * @param array $options Array of options for the slider element.
* @return string Completed slider script. * @return string Completed Slider script.
* @see JsHelper::slider() for options list. * @see JsHelper::slider() for options list.
**/ **/
function slider($options = array()) { function slider($options = array()) {

$callbacks = array('start', 'change', 'slide', 'stop');
$template = '%s.slider({%s});';
return $this->_methodTemplate('slider', $template, $options, $callbacks);
} }
} }
?> ?>
197 changes: 13 additions & 184 deletions cake/libs/view/helpers/js.php
Expand Up @@ -588,14 +588,22 @@ function sortable() {
* *
* ### Options * ### Options
* *
* ### Event Options * - handle - The id of the element used in sliding.
* - direction - The direction of the slider either 'vertical' or 'horizontal'
* - min - The min value for the slider.
* - max - The max value for the slider.
* - step - The number of steps or ticks the slider will have.
* - value - The initial offset of the slider.
*
* ### Events
* *
* - change - Fired when the slider's value is updated
* - complete - Fired when the user stops sliding the handle
* *
* @param array $options Array of options for the slider. See above. * @return string Completed slider script
* @return string Completed slider script.
**/ **/
function slider() { function slider() {
trigger_error(sprintf(__('%s does not have slider() implemented', true), get_class($this)), E_USER_WARNING); trigger_error(sprintf(__('%s does not have slider() implemented', true), get_class($this)), E_USER_WARNING);
} }
/** /**
* Parse an options assoc array into an Javascript object literal. * Parse an options assoc array into an Javascript object literal.
Expand Down Expand Up @@ -659,183 +667,4 @@ function _toQuerystring($parameters) {
return $out; return $out;
} }
} }

?>

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);
}
}
?>

0 comments on commit 9754926

Please sign in to comment.