Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding sortable to jQuery engine.

  • Loading branch information...
commit d59a704fb1903ea56a833e1de358253d2331cf52 1 parent dfe6fe1
@markstory markstory authored
View
19 cake/libs/view/helpers/jquery_engine.php
@@ -37,6 +37,9 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
'type' => 'dataType',
'complete' => 'success',
'request' => 'beforeSend',
+ ),
+ 'sortable' => array(
+ 'complete' => 'stop',
)
);
/**
@@ -142,5 +145,21 @@ function request($url, $options = array()) {
$options = $this->_parseOptions($options, $callbacks);
return '$.ajax({' . $options .'});';
}
+/**
+ * Create a sortable element.
+ *
+ * Requires both Ui.Core and Ui.Sortables to be loaded.
+ *
+ * @param array $options Array of options for the sortable.
+ * @return string Completed sortable script.
+ * @see JsHelper::sortable() for options list.
+ **/
+ function sortable($options = array()) {
+ $options = $this->_mapOptions('sortable', $options);
+ $callbacks = array('start', 'sort', 'change', 'beforeStop', 'stop', 'update', 'receive', 'remove',
+ 'over', 'out', 'activate', 'deactivate');
+ $options = $this->_parseOptions($options, $callbacks);
+ return $this->selection . '.sortable({' . $options . '});';
+ }
}
?>
View
16 cake/tests/cases/libs/view/helpers/jquery_engine.test.php
@@ -154,5 +154,21 @@ function testRequest() {
$expected = '$.ajax({method:"post", error:handleError, data:"name=jim&height=185cm", dataType:"json", success:doSuccess, url:"/people/edit/1"});';
$this->assertEqual($result, $expected);
}
+/**
+ * test sortable list generation
+ *
+ * @return void
+ **/
+ function testSortable() {
+ $result = $this->Jquery->get('#myList')->sortable(array(
+ 'distance' => 5,
+ 'containment' => 'parent',
+ 'start' => 'onStart',
+ 'complete' => 'onStop',
+ 'sort' => 'onSort',
+ ));
+ $expected = '$("#myList").sortable({distance:5, containment:"parent", start:onStart, sort:onSort, stop:onStop});';
+ $this->assertEqual($result, $expected);
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.