Skip to content
Permalink
Browse files

Updating sortable options.

Fixing drag() when selector is a multiple element selection.
  • Loading branch information...
markstory committed Jul 28, 2009
1 parent ec10e90 commit ebc221dbf799a0d4d99ea4cf865920979d9ccbb4
@@ -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 @@ function get($selector) {
$this->selection = '$("' . substr($selector, 1) . '")';
return $this;
}
$this->_multiple = true;
$this->selection = '$$("' . $selector . '")';
return $this;
}
@@ -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 . '}';
@@ -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 . ');';
}
/**
@@ -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
**/
@@ -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

0 comments on commit ebc221d

Please sign in to comment.
You can’t perform that action at this time.