Here is a snippet much longer, and hope a bit clearer, than the one Andrea wrote:
(function(global) { if (typeof document.readyState == 'undefined') { HTMLDocument.prototype. __defineGetter__("readyState", function () { return domReady; }); HTMLDocument.prototype. __defineSetter__("readyState", function (state) { domReady = state; }); function interactive(e) { domReady = 'interactive'; top.status += ' * ' + document.readyState; domImage.removeEventListener('error', interactive, false); domImage = null; } function loading() { domReady = 'loading'; top.status += ' * ' + document.readyState; global.document.addEventListener('DOMContentLoaded', complete, false); } function complete() { domReady = 'complete'; top.status += ' * ' + document.readyState; global.document.removeEventListener('DOMContentLoaded', complete, false); } function initialize(document) { domReady = 'uninitialized'; top.status += ' * ' + document.readyState; domImage.addEventListener('error', interactive, false); domImage.src = "mozilla://"; loading(document); } var domImage = new Image(), domReady = 'uninitialized'; initialize(global.document); } })(this); It adds an extra "interactive" state where the BODY is available, also possibly not completely parsed and rendered. For the rest it is just similar to what Andrea does in his code, add a "readyState" property to document the W3C way. Still not a solution for what jQuery needs. - Diego On 25 Nov, 02:15, Diego Perini <diego.per...@gmail.com> wrote: > I don't understand why you are writing code like this in a developer > group... some ongoing competition. > > It is not clear if you have trade secrets or just don't want others to > see the errors in it. ;-) > > Do you want to talk about them and discuss them or is this a way of > just posting a snippet, for this we have javascript.com and at list > they are well commented. > > Diego > > On 20 Nov, 12:50, Andrea Giammarchi <andrea.giammar...@gmail.com> > wrote: > > > @Shade, just to inform you I have removed the named function expression > > reusing a variable: > > (function(s,o,l,v,e,d){if(s[o]==null&&s[l+e]){s[o]="loading";s[l+e](d,l=function(){s[o]="complete";s[v+e](d,l,!1)},!1)}})(document,"readyState","add","remove","EventListener","DOMContentLoaded") > > > Regards > > > On Thu, Nov 19, 2009 at 12:10 AM, Shade <get...@gmail.com> wrote: > > > Here's my minified version... it's *slightly* larger at 209 characters > > > (vs 195), but it works, and bonus, it doesn't use a memory-leaky named- > > > function-expression: > > > > (function(a,b,c,d){if(a[b]==null&&a[c]){a[c](d,function() > > > {a.removeEventListener(d,arguments.callee,false);a[b] > > > ="complete"},false);a[b]="loading"}}) > > > (document,"readyState","addEventListener","DOMContentLoaded"); > > > > Thanks for the inspiration, though, Andrea! > > > > --Kyle > > > > On Nov 18, 5:55 pm, Shade <get...@gmail.com> wrote: > > > > Ummm... ammendment: The complete snippet works: > > > > > if(document.readyState == null && document.addEventListener){ > > > > // on DOMContentLoaded event, supported since ages > > > > document.addEventListener("DOMContentLoaded", function > > > > DOMContentLoaded(){ > > > > // remove the listener itself > > > > document.removeEventListener("DOMContentLoaded", > > > > DOMContentLoaded, false); > > > > // assign readyState as complete > > > > document.readyState = "complete"; > > > > }, false); > > > > // set readyState = loading or interactive > > > > // it does not really matter for this purpose > > > > document.readyState = "loading"; > > > > > } > > > > > But, the minified/re-arranged snippet (the 195 chars) Andrea provided > > > > does not work. Do you own minification and you'll be fine, just don't > > > > use what he posted. > > > > > --Kyle > > > > > On Nov 18, 5:44 pm, Shade <get...@gmail.com> wrote: > > > > > > I have confirmed in this test: > > > > > >http://test.getify.com/archive/dynloadjquery/index6.html > > > > > > ...that Andrea's proposed snippet does in fact "patch a page" to have > > > > > a proper readyState, assuming of course the snippet itself is > > > > > guaranteed to run before domready. The test includes it in a manual > > > > > script tag at the bottom of the page, and then you can click a button > > > > > to dynamically load jquery into the page, then click the other button > > > > > to see if jquery's internal ready flag is set properly or not. > > > > > > I used a patched version of jQuery 1.3.2 (1.3.2.1 I called it) which > > > > > only has the changes to the bindReady() function as they appear in > > > > > GitHub right now (namely, the additional check for the > > > > > document.readyState which John landed as a result of that previous bug > > > > > I linked to earlier in this thread). > > > > > > I tested this just now in both FF3 and 3.5 (both windows), and it > > > > > works fine. > > > > > > That means, that at least for now, even though patching jquery itself > > > > > doesn't do much or help anything with the problem of being able to > > > > > lazy-load jquery core, which my biggest concern/use-case, you can > > > > > still "patch" a page to be able to lazy-load jquery. That's definitely > > > > > an improvement. > > > > > > It also means that any code that relies on jquery's test (such as code > > > > > that uses document.ready) is now also safe to lazy load right along > > > > > with jquery core itself, as long as doing so in a "patched" page. > > > > > > I'm satisfied that this being included in LABjs will allow users to > > > > > adequately load jquery.js on-demand without fear of the isReady checks > > > > > failing later. The only caveat then will be that LABjs has to make > > > > > sure it's there before dom-ready, but for all the use cases I care > > > > > about, it's quite unlikely that people will use some other loading > > > > > technique to lazy-load the Loader itself. > > > > > > --Kyle > > > > > > On Nov 18, 5:03 pm, Már Örlygsson <mar.orlygs...@gmail.com> wrote: > > > > > > > Am I right to think that there's a similar problem with the > > > > > > window.onload event? > > > > > > i.e. if you're too late in binding a handler to window.onload, it > > > will > > > > > > never fire? > > > > > > > -- > > > > > > Már- Hide quoted text - > > > > > > - Show quoted text -- Hide quoted text - > > > > > - Show quoted text - > > > > -- > > > > You received this message because you are subscribed to the Google Groups > > > "jQuery Development" group. > > > To post to this group, send email to jquery-...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > jquery-dev+unsubscr...@googlegroups.com<jquery-dev%2bunsubscr...@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/jquery-dev?hl=. -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-...@googlegroups.com. To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.