From f26d5efd0c8c80bc06b5da3125236d6e820bba98 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Thu, 10 Dec 2009 23:37:55 -0500 Subject: [PATCH] Applying patch from 'kleingeist'. JsHelper::set() now generates a variable that is assigned to window.$var instead of creating a local variable by default. Tests updated. Fixes #96 --- cake/libs/view/helpers/js.php | 2 +- cake/tests/cases/libs/view/helpers/js.test.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index 5feecf8c9..d2976683f 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -248,7 +248,7 @@ class JsHelper extends AppHelper { */ function _createVars() { if (!empty($this->__jsVars)) { - $setVar = (strpos($this->setVariable, '.')) ? $this->setVariable : 'var ' . $this->setVariable; + $setVar = (strpos($this->setVariable, '.')) ? $this->setVariable : 'window.' . $this->setVariable; $this->buffer($setVar . ' = ' . $this->object($this->__jsVars) . ';'); } } diff --git a/cake/tests/cases/libs/view/helpers/js.test.php b/cake/tests/cases/libs/view/helpers/js.test.php index 015199b93..e201e1dc2 100644 --- a/cake/tests/cases/libs/view/helpers/js.test.php +++ b/cake/tests/cases/libs/view/helpers/js.test.php @@ -451,14 +451,14 @@ CODE; $this->Js->set('loggedIn', true); $this->Js->set(array('height' => 'tall', 'color' => 'purple')); $result = $this->Js->getBuffer(); - $expected = 'var app = {"loggedIn":true,"height":"tall","color":"purple"};'; + $expected = 'window.app = {"loggedIn":true,"height":"tall","color":"purple"};'; $this->assertEqual($result[0], $expected); $this->Js->set('loggedIn', true); $this->Js->set(array('height' => 'tall', 'color' => 'purple')); $this->Js->setVariable = 'WICKED'; $result = $this->Js->getBuffer(); - $expected = 'var WICKED = {"loggedIn":true,"height":"tall","color":"purple"};'; + $expected = 'window.WICKED = {"loggedIn":true,"height":"tall","color":"purple"};'; $this->assertEqual($result[0], $expected); $this->Js->set('loggedIn', true);