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);