Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding newlines and tests for slideDown slideUp alternate syntax for …

…jquery engine.
  • Loading branch information...
commit 3a5b78273737c2e8dc096d326142824d9ea8c21b 1 parent 5b13b29
Mark Story markstory authored
18 cake/libs/view/helpers/jquery_engine.php
View
@@ -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);
}
@@ -210,6 +214,8 @@ function effect($name, $options = array()) {
case 'show':
case 'fadeIn':
case 'fadeOut':
+ case 'slideDown':
+ case 'slideUp':
$effect = ".$name($speed);";
break;
}
@@ -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);
}
/**
@@ -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);
}
/**
@@ -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);
}
/**
20 cake/tests/cases/libs/view/helpers/jquery_engine.test.php
View
@@ -30,6 +30,7 @@ class JqueryEngineHelperTestCase extends CakeTestCase {
function startTest() {
$this->Jquery =& new JqueryEngineHelper();
}
+
/**
* end test
*
@@ -38,6 +39,7 @@ function startTest() {
function endTest() {
unset($this->Jquery);
}
+
/**
* test selector method
*
@@ -60,6 +62,7 @@ function testSelector() {
$this->assertEqual($result, $this->Jquery);
$this->assertEqual($this->Jquery->selection, '$("ul")');
}
+
/**
* test event binding
*
@@ -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
*
@@ -89,6 +93,7 @@ function testDomReady() {
$expected = '$(document).bind("ready", function (event) {foo.name = "bar";});';
$this->assertEqual($result, $expected);
}
+
/**
* test Each method
*
@@ -100,6 +105,7 @@ function testEach() {
$expected = '$("#foo").each(function () {$(this).hide();});';
$this->assertEqual($result, $expected);
}
+
/**
* test Effect generation
*
@@ -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
*
@@ -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
*
@@ -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
*
@@ -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
*
@@ -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
*
@@ -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
*
Please sign in to comment.
Something went wrong with that request. Please try again.