Skip to content

Commit

Permalink
Adding sortable to jQuery engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 28, 2009
1 parent dfe6fe1 commit d59a704
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cake/libs/view/helpers/jquery_engine.php
Expand Up @@ -37,6 +37,9 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
'type' => 'dataType',
'complete' => 'success',
'request' => 'beforeSend',
),
'sortable' => array(
'complete' => 'stop',
)
);
/**
Expand Down Expand Up @@ -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 . '});';
}
}
?>
16 changes: 16 additions & 0 deletions cake/tests/cases/libs/view/helpers/jquery_engine.test.php
Expand Up @@ -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);
}
}
?>

0 comments on commit d59a704

Please sign in to comment.