Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding Drag() to jquery

  • Loading branch information...
commit 0269994842561ba8497b7b07f368c4747671554c 1 parent 49f689a
@markstory markstory authored
View
19 cake/libs/view/helpers/jquery_engine.php
@@ -39,6 +39,10 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
),
'sortable' => array(
'complete' => 'stop',
+ ),
+ 'drag' => array(
+ 'snapGrid' => 'grid',
+ 'container' => 'containment',
)
);
/**
@@ -167,5 +171,20 @@ function sortable($options = array()) {
$options = $this->_parseOptions($options, $callbacks);
return $this->selection . '.sortable({' . $options . '});';
}
+/**
+ * Create a Draggable element
+ *
+ * Requires both Ui.Core and Ui.Draggable to be loaded.
+ *
+ * @param array $options Array of options for the draggable element.
+ * @return string Completed Draggabke script.
+ * @see JsHelper::drag() for options list.
+ **/
+ function drag($options = array()) {
+ $options = $this->_mapOptions('drag', $options);
+ $callbacks = array('start', 'drag', 'stop');
+ $options = $this->_parseOptions($options, $callbacks);
+ return $this->selection . '.draggable({' . $options . '});';
+ }
}
?>
View
10 cake/tests/cases/libs/view/helpers/jquery_engine.test.php
@@ -190,7 +190,15 @@ function testSortable() {
* @return void
**/
function testDrag() {
-
+ $this->Jquery->get('#element');
+ $result = $this->Jquery->drag(array(
+ 'container' => '#content',
+ 'start' => 'onStart',
+ 'drag' => 'onDrag',
+ 'stop' => 'onStop',
+ 'snapGrid' => array(10, 10),
+ ));
+ $expected = '$("#element").draggable({containment:"#content", drag:onDrag, grid:[10, 10], start:onStart, stop:onStop});';
}
/**
* test drop() method
Please sign in to comment.
Something went wrong with that request. Please try again.