Permalink
Browse files

Adding drag() to mootools.

  • Loading branch information...
1 parent 02bb4e7 commit 1d5e3150a22e5eb5912844b3d3416a8bf9091113 @markstory markstory committed Apr 12, 2009
@@ -48,6 +48,12 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
'sort' => 'onSort',
'complete' => 'onComplete',
'start' => 'onStart',
+ ),
+ 'drag' => array(
+ 'snapGrid' => 'snap',
+ 'start' => 'onStart',
+ 'drag' => 'onDrag',
+ 'stop' => 'onComplete',
)
);
/**
@@ -193,7 +199,7 @@ function request($url, $options = array()) {
/**
* Create a sortable element.
*
- * Requires both the ```Sortables``` plugin from MootoolsMore
+ * Requires the ```Sortables``` plugin from MootoolsMore
*
* @param array $options Array of options for the sortable.
* @return string Completed sortable script.
@@ -205,5 +211,21 @@ function sortable($options = array()) {
$options = $this->_parseOptions($options, $callbacks);
return 'var jsSortable = new Sortables(' . $this->selection . ', {' . $options . '});';
}
+/**
+ * Create a Draggable element.
+ *
+ * Requires the ```Drag``` plugin from MootoolsMore
+ *
+ * @param array $options Array of options for the draggable.
+ * @return string Completed draggable script.
+ * @see JsHelper::drag() for options list.
+ **/
+ function drag($options = array()) {
+ $options = $this->_mapOptions('drag', $options);
+ $callbacks = array('onBeforeStart', 'onStart', 'onSnap', 'onDrag', 'onComplete');
+ $options = $this->_parseOptions($options, $callbacks);
+ return 'var jsDrag = new Drag(' . $this->selection . ', {' . $options . '});';
+ }
+
}
?>
@@ -216,7 +216,15 @@ function testSortable() {
* @return void
**/
function testDrag() {
-
+ $this->Moo->get('#drag-me');
+ $result = $this->Moo->drag(array(
+ 'start' => 'onStart',
+ 'drag' => 'onDrag',
+ 'stop' => 'onStop',
+ 'snapGrid' => array(10,10)
+ ));
+ $expected = 'var jsDrag = new Drag($("drag-me"), {onComplete:onStop, onDrag:onDrag, onStart:onStart, snap:[10,10]});';
+ $this->assertEqual($result, $expected);
}
/**
* test drop() method

0 comments on commit 1d5e315

Please sign in to comment.