From 07d2b0d2d380d01bcd1807ed33ddaadcf908fbe8 Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 15 Mar 2008 22:48:46 +0000 Subject: [PATCH] Fixing AjaxHelper::sortable() options and filtering Ajax callbacks from link options in AjaxHelper::link(), fixes #4279, fixes #4274 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6576 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/ajax.php | 15 ++++++--------- .../tests/cases/libs/view/helpers/ajax.test.php | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cake/libs/view/helpers/ajax.php b/cake/libs/view/helpers/ajax.php index 56b866820..dec030478 100644 --- a/cake/libs/view/helpers/ajax.php +++ b/cake/libs/view/helpers/ajax.php @@ -641,10 +641,12 @@ class AjaxHelper extends AppHelper { $block = $options['block']; unset($options['block']); } + $strings = array('tag', 'constraint', 'only', 'handle', 'hoverclass', 'tree', 'treeTag', 'update', 'overlap'); + if (isset($options['scroll']) && $options['scroll'] != 'window' && strpos($options['scroll'], '$(') !== 0) { + $strings[] = 'scroll'; + } - $options = $this->_optionsToString($options, array( - 'tag', 'constraint', 'only', 'handle', 'hoverclass', 'scroll', 'tree', 'treeTag', 'update', 'overlap' - )); + $options = $this->_optionsToString($options, $strings); $options = array_merge($options, $this->_buildCallbacks($options)); $options = $this->_buildOptions($options, $this->sortOptions); $result = "Sortable.create('$id', $options);"; @@ -724,12 +726,7 @@ class AjaxHelper extends AppHelper { * @access private */ function __getHtmlOptions($options, $extra = array()) { - foreach ($this->ajaxOptions as $key) { - if (isset($options[$key])) { - unset($options[$key]); - } - } - foreach ($extra as $key) { + foreach (array_merge($this->ajaxOptions, $this->callbacks, $extra) as $key) { if (isset($options[$key])) { unset($options[$key]); } diff --git a/cake/tests/cases/libs/view/helpers/ajax.test.php b/cake/tests/cases/libs/view/helpers/ajax.test.php index 408556f9c..5c07bcfc0 100644 --- a/cake/tests/cases/libs/view/helpers/ajax.test.php +++ b/cake/tests/cases/libs/view/helpers/ajax.test.php @@ -195,6 +195,18 @@ class AjaxTest extends UnitTestCase { $result = $this->Ajax->sortable('div', array('block' => false)); $expected = "Sortable.create('div', {});"; $this->assertEqual($result, $expected); + + $result = $this->Ajax->sortable('div', array('block' => false, 'scroll' => 'someID')); + $expected = "Sortable.create('div', {scroll:'someID'});"; + $this->assertEqual($result, $expected); + + $result = $this->Ajax->sortable('div', array('block' => false, 'scroll' => 'window')); + $expected = "Sortable.create('div', {scroll:window});"; + $this->assertEqual($result, $expected); + + $result = $this->Ajax->sortable('div', array('block' => false, 'scroll' => '$("someElement")')); + $expected = "Sortable.create('div', {scroll:$(\"someElement\")});"; + $this->assertEqual($result, $expected); } function testSubmitWithIndicator() { @@ -290,6 +302,11 @@ class AjaxTest extends UnitTestCase { $this->assertNoPattern('/]+[^type]=[^<>]*>/', $result); $this->assertPattern('/Event.observe\(\'\w+\',\s*\'click\',\s*function\(event\)\s*{.+},\s*false\);\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result); $this->assertPattern('/function\(event\)\s*{\s*new Ajax\.Updater\(\'myDiv\',\s*\'http:\/\/www.cakephp.org\/downloads\',\s*{asynchronous:true, evalScripts:true, onFailure:function\(request\) {failure\(\);}, requestHeaders:\[\'X-Update\', \'myDiv\'\]}\)\s*},\s*false\);/', $result); + + $result = $this->Ajax->link('Ajax Link', '/test', array('complete' => 'test')); + $this->assertPattern('/^]+>Ajax Link<\/a>