Skip to content

Commit

Permalink
Adding newlines and tests for slideDown slideUp alternate syntax for …
Browse files Browse the repository at this point in the history
…jquery engine.
  • Loading branch information
markstory committed Jul 30, 2009
1 parent 5b13b29 commit 3a5b782
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
18 changes: 10 additions & 8 deletions cake/libs/view/helpers/jquery_engine.php
Expand Up @@ -118,9 +118,13 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
* @access public
* @return string
**/
function _methodTemplate($method, $template, $options, $callbacks) {
function _methodTemplate($method, $template, $options, $extraSafeKeys = array()) {
$options = $this->_mapOptions($method, $options);
$options = $this->_prepareCallbacks($method, $options);
$callbacks = array_keys($this->_callbackArguments[$method]);
if (!empty($extraSafeKeys)) {
$callbacks = array_merge($callbacks, $extraSafeKeys);
}
$options = $this->_parseOptions($options, $callbacks);
return sprintf($template, $this->selection, $options);
}
Expand Down Expand Up @@ -210,6 +214,8 @@ function effect($name, $options = array()) {
case 'show':
case 'fadeIn':
case 'fadeOut':
case 'slideDown':
case 'slideUp':
$effect = ".$name($speed);";
break;
}
Expand Down Expand Up @@ -256,10 +262,8 @@ function request($url, $options = array()) {
* @see JsHelper::sortable() for options list.
**/
function sortable($options = array()) {
$callbacks = array('start', 'sort', 'change', 'beforeStop', 'stop', 'update', 'receive', 'remove',
'over', 'out', 'activate', 'deactivate');
$template = '%s.sortable({%s});';
return $this->_methodTemplate('sortable', $template, $options, $callbacks);
return $this->_methodTemplate('sortable', $template, $options);
}

/**
Expand All @@ -272,9 +276,8 @@ function sortable($options = array()) {
* @see JsHelper::drag() for options list.
**/
function drag($options = array()) {
$callbacks = array('start', 'drag', 'stop');
$template = '%s.draggable({%s});';
return $this->_methodTemplate('drag', $template, $options, $callbacks);
return $this->_methodTemplate('drag', $template, $options);
}

/**
Expand All @@ -287,9 +290,8 @@ function drag($options = array()) {
* @see JsHelper::drop() for options list.
**/
function drop($options = array()) {
$callbacks = array('activate', 'deactivate', 'over', 'out', 'drop');
$template = '%s.droppable({%s});';
return $this->_methodTemplate('drop', $template, $options, $callbacks);
return $this->_methodTemplate('drop', $template, $options);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions cake/tests/cases/libs/view/helpers/jquery_engine.test.php
Expand Up @@ -30,6 +30,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
function startTest() {
$this->Jquery =& new JqueryEngineHelper();
}

/**
* end test
*
Expand All @@ -38,6 +39,7 @@ function startTest() {
function endTest() {
unset($this->Jquery);
}

/**
* test selector method
*
Expand All @@ -60,6 +62,7 @@ function testSelector() {
$this->assertEqual($result, $this->Jquery);
$this->assertEqual($this->Jquery->selection, '$("ul")');
}

/**
* test event binding
*
Expand All @@ -79,6 +82,7 @@ function testEvent() {
$expected = '$("#myLink").bind("click", function (event) {$(this).hide();'."\n".'return false;});';
$this->assertEqual($result, $expected);
}

/**
* test dom ready event creation
*
Expand All @@ -89,6 +93,7 @@ function testDomReady() {
$expected = '$(document).bind("ready", function (event) {foo.name = "bar";});';
$this->assertEqual($result, $expected);
}

/**
* test Each method
*
Expand All @@ -100,6 +105,7 @@ function testEach() {
$expected = '$("#foo").each(function () {$(this).hide();});';
$this->assertEqual($result, $expected);
}

/**
* test Effect generation
*
Expand Down Expand Up @@ -134,7 +140,16 @@ function testEffect() {
$result = $this->Jquery->effect('slideOut');
$expected = '$("#foo").slideUp();';
$this->assertEqual($result, $expected);

$result = $this->Jquery->effect('slideDown');
$expected = '$("#foo").slideDown();';
$this->assertEqual($result, $expected);

$result = $this->Jquery->effect('slideUp');
$expected = '$("#foo").slideUp();';
$this->assertEqual($result, $expected);
}

/**
* Test Request Generation
*
Expand Down Expand Up @@ -188,6 +203,7 @@ function testRequest() {
$expected = '$.ajax({beforeSend:function (XMLHttpRequest) {doBefore}, data:$("#someId").serialize(), success:function (data, textStatus) {doFoo}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($result, $expected);
}

/**
* test sortable list generation
*
Expand Down Expand Up @@ -216,6 +232,7 @@ function testSortable() {
$expected = '$("#myList").sortable({containment:"parent", distance:5, sort:function (event, ui) {onSort}, start:function (event, ui) {onStart}, stop:function (event, ui) {onStop}});';
$this->assertEqual($result, $expected);
}

/**
* test drag() method
*
Expand Down Expand Up @@ -244,6 +261,7 @@ function testDrag() {
$expected = '$("#element").draggable({containment:"#content", drag:function (event, ui) {onDrag}, grid:[10,10], start:function (event, ui) {onStart}, stop:function (event, ui) {onStop}});';
$this->assertEqual($result, $expected);
}

/**
* test drop() method
*
Expand All @@ -270,6 +288,7 @@ function testDrop() {
$expected = '$("#element").droppable({accept:".items", drop:function (event, ui) {onDrop}, out:function (event, ui) {onExit}, over:function (event, ui) {onHover}});';
$this->assertEqual($result, $expected);
}

/**
* test slider generation
*
Expand Down Expand Up @@ -300,6 +319,7 @@ function testSlider() {
$expected = '$("#element").slider({change:function (event, ui) {onChange}, max:10, min:0, orientation:"vertical", stop:function (event, ui) {onComplete}, value:2});';
$this->assertEqual($result, $expected);
}

/**
* test the serializeForm method
*
Expand Down

0 comments on commit 3a5b782

Please sign in to comment.