Updating sortable options.

Fixing drag() when selector is a multiple element selection.
This commit is contained in:
mark_story 2009-07-27 22:36:22 -04:00
parent ec10e90efb
commit ebc221dbf7
2 changed files with 21 additions and 5 deletions

View file

@ -40,8 +40,8 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
),
'sortable' => array(
'start' => 'onStart',
'sort' => 'onDrag',
'complete' => 'onDrop',
'sort' => 'onChange',
'complete' => 'onUpdate',
'distance' => 'snap',
),
'drag' => array(
@ -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;
@ -78,6 +79,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
$this->selection = '$("' . substr($selector, 1) . '")';
return $this;
}
$this->_multiple = true;
$this->selection = '$$("' . $selector . '")';
return $this;
}
@ -214,7 +216,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
**/
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 . '}';
@ -237,6 +239,9 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
if (!empty($options)) {
$options = ', {' . $options . '}';
}
if ($this->_multiple) {
return $this->each('new Draggable(item' . $options . ');');
}
return 'var jsDrag = new Draggable(' . $this->selection . $options . ');';
}
/**

View file

@ -230,11 +230,12 @@ class PrototypeEngineHelperTestCase extends CakeTestCase {
'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
**/
@ -248,6 +249,16 @@ class PrototypeEngineHelperTestCase extends CakeTestCase {
));
$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