Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Applying patch from 'kleingeist'. JsHelper::set() now generates a var…

…iable that is assigned to window.$var instead of creating a local variable by default.

Tests updated.
Fixes #96
  • Loading branch information...
commit f26d5efd0c8c80bc06b5da3125236d6e820bba98 1 parent df15139
Mark Story markstory authored
2  cake/libs/view/helpers/js.php
View
@@ -248,7 +248,7 @@ function getBuffer($clear = true) {
*/
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) . ';');
}
}
4 cake/tests/cases/libs/view/helpers/js.test.php
View
@@ -451,14 +451,14 @@ function testSet() {
$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);
Please sign in to comment.
Something went wrong with that request. Please try again.