Skip to content

Commit

Permalink
Merge branch '1.3' of git@github.com:cakephp/cakephp1x into 1.3
Browse files Browse the repository at this point in the history
* '1.3' of git@github.com:cakephp/cakephp1x:
  Fixing issues in JqueryEngineHelper where eval()'ed responses wouldn't run code contained inside $js->domReady() due to implementation differences between $(document).ready() and $(document).bind('ready').  Tests updated.
  • Loading branch information
lorenzo committed Jan 29, 2010
2 parents 1dd0a64 + 832b15b commit 0abe9af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions cake/libs/view/helpers/jquery_engine.php
Expand Up @@ -178,15 +178,19 @@ function event($type, $callback, $options = array()) {
}

/**
* Create a domReady event. For jQuery
* Create a domReady event. For jQuery. This method does not
* bind a 'traditional event' as `$(document).bind('ready', fn)`
* Works in an entirely different fashion than `$(document).ready()`
* The first will not run the function when eval()'d as part of a response
* The second will. Because of the way that ajax pagination is done
* `$().ready()` is used.
*
* @param string $functionBody The code to run on domReady
* @return string completed domReady method
* @access public
*/
function domReady($functionBody) {
$this->get('document');
return $this->event('ready', $functionBody, array('stop' => false));
return $this->jQueryObject . '(document).ready(function () {' . $functionBody . '});';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/libs/view/helpers/jquery_engine.test.php
Expand Up @@ -89,7 +89,7 @@ function testEvent() {
*/
function testDomReady() {
$result = $this->Jquery->domReady('foo.name = "bar";');
$expected = '$(document).bind("ready", function (event) {foo.name = "bar";});';
$expected = '$(document).ready(function () {foo.name = "bar";});';
$this->assertEqual($result, $expected);
}

Expand Down

0 comments on commit 0abe9af

Please sign in to comment.