mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
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:
parent
df151395c5
commit
f26d5efd0c
2 changed files with 3 additions and 3 deletions
|
@ -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) . ';');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue