diff --git a/cake/libs/view/helpers/jquery_engine.php b/cake/libs/view/helpers/jquery_engine.php index 3f1f4b9a6..eb1cddfa4 100644 --- a/cake/libs/view/helpers/jquery_engine.php +++ b/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 @@ class JqueryEngineHelper extends JsBaseEngineHelper { $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 . '});'; + } } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php index 1758255e8..90e048c11 100644 --- a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php @@ -154,5 +154,21 @@ class JqueryEngineHelperTestCase extends CakeTestCase { $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); + } } ?> \ No newline at end of file