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
This commit is contained in:
Mark Story 2009-12-10 23:37:55 -05:00
parent df151395c5
commit f26d5efd0c
2 changed files with 3 additions and 3 deletions

View file

@ -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) . ';');
}
}

View file

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