Skip to content

Commit

Permalink
Adding Drag() to jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Apr 9, 2009
1 parent 49f689a commit 0269994
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
19 changes: 19 additions & 0 deletions cake/libs/view/helpers/jquery_engine.php
Expand Up @@ -39,6 +39,10 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
),
'sortable' => array(
'complete' => 'stop',
),
'drag' => array(
'snapGrid' => 'grid',
'container' => 'containment',
)
);
/**
Expand Down Expand Up @@ -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 . '});';
}
}
?>
10 changes: 9 additions & 1 deletion cake/tests/cases/libs/view/helpers/jquery_engine.test.php
Expand Up @@ -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
Expand Down

0 comments on commit 0269994

Please sign in to comment.