Skip to content

Commit

Permalink
Updating sortable options.
Browse files Browse the repository at this point in the history
Fixing drag() when selector is a multiple element selection.
  • Loading branch information
markstory committed Jul 28, 2009
1 parent ec10e90 commit ebc221d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
11 changes: 8 additions & 3 deletions cake/libs/view/helpers/prototype_engine.php
Expand Up @@ -40,8 +40,8 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
),
'sortable' => array(
'start' => 'onStart',
'sort' => 'onDrag',
'complete' => 'onDrop',
'sort' => 'onChange',
'complete' => 'onUpdate',
'distance' => 'snap',
),
'drag' => array(
Expand Down Expand Up @@ -70,6 +70,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
* @return object instance of $this. Allows chained methods.
**/
function get($selector) {
$this->_multiple = false;
if ($selector == 'window' || $selector == 'document') {
$this->selection = "$(" . $selector .")";
return $this;
Expand All @@ -78,6 +79,7 @@ function get($selector) {
$this->selection = '$("' . substr($selector, 1) . '")';
return $this;
}
$this->_multiple = true;
$this->selection = '$$("' . $selector . '")';
return $this;
}
Expand Down Expand Up @@ -214,7 +216,7 @@ function request($url, $options = array()) {
**/
function sortable($options = array()) {
$options = $this->_mapOptions('sortable', $options);
$callbacks = array('onStart', 'change', 'onDrag', 'onDrop');
$callbacks = array('onStart', 'change', 'onDrag', 'onDrop', 'onChange', 'onUpdate', 'onEnd');
$options = $this->_parseOptions($options, $callbacks);
if (!empty($options)) {
$options = ', {' . $options . '}';
Expand All @@ -237,6 +239,9 @@ function drag($options = array()) {
if (!empty($options)) {
$options = ', {' . $options . '}';
}
if ($this->_multiple) {
return $this->each('new Draggable(item' . $options . ');');
}
return 'var jsDrag = new Draggable(' . $this->selection . $options . ');';
}
/**
Expand Down
15 changes: 13 additions & 2 deletions cake/tests/cases/libs/view/helpers/prototype_engine.test.php
Expand Up @@ -230,11 +230,12 @@ function testSortable() {
'complete' => 'onComplete',
'sort' => 'onSort',
));
$expected = 'var jsSortable = Sortable.create($("myList"), {onDrag:onSort, onDrop:onComplete, onStart:onStart, snap:5});';
$expected = 'var jsSortable = Sortable.create($("myList"), {onChange:onSort, onStart:onStart, onUpdate:onComplete, snap:5});';
$this->assertEqual($result, $expected);
}
/**
* test drag() method
* test drag() method. Scriptaculous lacks the ability to take an Array of Elements
* in new Drag() when selection is a multiple type. Iterate over the array.
*
* @return void
**/
Expand All @@ -248,6 +249,16 @@ function testDrag() {
));
$expected = 'var jsDrag = new Draggable($("element"), {onDrag:onDrag, onEnd:onStop, onStart:onStart, snap:[10,10]});';
$this->assertEqual($result, $expected);

$this->Proto->get('div.dragger');
$result = $this->Proto->drag(array(
'start' => 'onStart',
'drag' => 'onDrag',
'stop' => 'onStop',
'snapGrid' => array(10, 10),
));
$expected = '$$("div.dragger").each(function (item, index) {new Draggable(item, {onDrag:onDrag, onEnd:onStop, onStart:onStart, snap:[10,10]});});';
$this->assertEqual($result, $expected);
}
/**
* test drop() method
Expand Down

0 comments on commit ebc221d

Please sign in to comment.