Skip to content

Commit

Permalink
Applying patch from 'kleingeist'. JsHelper::set() now generates a var…
Browse files Browse the repository at this point in the history
…iable that is assigned to window.$var instead of creating a local variable by default.

Tests updated.
Fixes #96
  • Loading branch information
markstory authored and jperras committed Dec 14, 2009
1 parent aaddd0d commit 4f985e4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cake/libs/view/helpers/js.php
Expand Up @@ -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) . ';');
}
}
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/libs/view/helpers/js.test.php
Expand Up @@ -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);
Expand Down

0 comments on commit 4f985e4

Please sign in to comment.