From 8f641887b725084199bb5fdd533f0ea40e8dafed Mon Sep 17 00:00:00 2001 From: nate Date: Sun, 4 Feb 2007 19:28:22 +0000 Subject: [PATCH] Adding 'evalScripts' fix for AjaxHelper (Ticket #2048) git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4448 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/ajax.php | 40 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/cake/libs/view/helpers/ajax.php b/cake/libs/view/helpers/ajax.php index b065b2968..9535d4b3f 100644 --- a/cake/libs/view/helpers/ajax.php +++ b/cake/libs/view/helpers/ajax.php @@ -662,32 +662,28 @@ class AjaxHelper extends AppHelper { unset($options['indicator']); } - $js_options = $this->_buildCallbacks($options); - - if (!isset($js_options['asynchronous'])) { - $js_options['asynchronous'] = 'true'; - } - - if (!isset($js_options['evalScripts'])) { - $js_options['evalScripts'] = 'true'; - } - + $jsOptions = am( + array('asynchronous' => 'true', 'evalScripts' => 'true'), + $this->_buildCallbacks($options) + ); $options = $this->_optionsToString($options, array('method')); foreach($options as $key => $value) { switch($key) { case 'type': - $js_options['asynchronous'] = ($value == 'synchronous') ? 'false' : 'true'; + $jsOptions['asynchronous'] = ife(($value == 'synchronous'), 'false', 'true'); + break; + case 'evalScripts': + $jsOptions['evalScripts'] = ife($value, 'true', 'false'); break; - case 'position': - $js_options['insertion'] = "Insertion." . Inflector::camelize($options['position']); + $jsOptions['insertion'] = "Insertion." . Inflector::camelize($options['position']); break; case 'with': - $js_options['parameters'] = $options['with']; + $jsOptions['parameters'] = $options['with']; break; case 'form': - $js_options['parameters'] = 'Form.serialize(this)'; + $jsOptions['parameters'] = 'Form.serialize(this)'; break; case 'requestHeaders': $keys = array(); @@ -695,13 +691,21 @@ class AjaxHelper extends AppHelper { $keys[] = "'" . $key . "'"; $keys[] = "'" . $val . "'"; } - $js_options['requestHeaders'] = '[' . join(', ', $keys) . ']'; + $jsOptions['requestHeaders'] = '[' . join(', ', $keys) . ']'; break; } } - return $this->_buildOptions($js_options, $this->ajaxOptions); + return $this->_buildOptions($jsOptions, $this->ajaxOptions); } - +/** + * Private Method to return a string of html options + * option data as a JavaScript options hash. + * + * @param array $options Options in the shape of keys and values + * @param array $extra Array of legal keys in this options context + * @return array Array of html options + * @access private + */ function __getHtmlOptions($options, $extra = array()) { foreach($this->ajaxOptions as $key) { if (isset($options[$key])) {