Correctly support domReady() callbacks when the DOM is already ready
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/f93bf63b Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/f93bf63b Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/f93bf63b Branch: refs/heads/5.4-js-rewrite Commit: f93bf63bd87f3b3d18942f0ccd3e82e3b3b2335a Parents: 579d7ff Author: Howard M. Lewis Ship <[email protected]> Authored: Mon Aug 13 15:34:09 2012 -0700 Committer: Howard M. Lewis Ship <[email protected]> Committed: Mon Aug 13 15:34:09 2012 -0700 ---------------------------------------------------------------------- .../coffeescript/META-INF/modules/core/spi.coffee | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/f93bf63b/tapestry-core/src/main/coffeescript/META-INF/modules/core/spi.coffee ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/spi.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/spi.coffee index 26c12d5..e85723d 100644 --- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/spi.coffee +++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/spi.coffee @@ -20,6 +20,10 @@ # Prototype ... but does it in a way that makes it relatively easy to swap in jQuery instead. define ["_", "prototype"], (_) -> + # When the document has loaded, convert `domReady` to just execute the callback immediately. + $(document).observe "dom:loaded", -> + exports.domReady = (callback) -> callback() + # _internal_: splits the string into words separated by whitespace split = (str) -> _(str.split " ").reject (s) -> s is "" @@ -270,6 +274,13 @@ define ["_", "prototype"], (_) -> else return null + # Finds all child elements matching the CSS selector, returning them + # as an array of ElementWrappers. + findAll: (selector) -> + matches = @element.select selector + + _.map matches, (e) -> new ElementWrapper e + # Returns an ElementWrapper for this element's containing element. The ElementWrapper is created lazily, and # cached. Returns null if this element has no parentNode (either because this element is the document object, or # because this element is not yet attached to the DOM). @@ -401,7 +412,7 @@ define ["_", "prototype"], (_) -> # still be in-transit). This is a safe time to search the DOM, modify attributes, and attach event handlers. # Returns this modules exports, for chained calls. domReady: (callback) -> - document.observe "dom:loaded", callback + $(document).observe "dom:loaded", callback exports
