prototype: Add document.loaded, a boolean that is set to true once dom:loaded is fired.
This commit is contained in:
parent
b4735bca7c
commit
6f0def19c5
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Add document.loaded, a boolean that is set to true once dom:loaded is fired. Setting document.loaded to true before the document is loaded prevents dom:loaded from being fired. [Tobie Langel]
|
||||
|
||||
* Make Element#insert standard-compliant. Fixes an issue in FF3b2 when inserting HTML or text inside DOM nodes which aren't (yet) appended to the document. [Tobie Langel]
|
||||
|
||||
* Add some missing semicolons to the source tree. Closes #10659. [Richard Quadling]
|
||||
|
|
|
@ -276,20 +276,21 @@ Element.addMethods({
|
|||
Object.extend(document, {
|
||||
fire: Element.Methods.fire.methodize(),
|
||||
observe: Element.Methods.observe.methodize(),
|
||||
stopObserving: Element.Methods.stopObserving.methodize()
|
||||
stopObserving: Element.Methods.stopObserving.methodize(),
|
||||
loaded: false
|
||||
});
|
||||
|
||||
(function() {
|
||||
/* Support for the DOMContentLoaded event is based on work by Dan Webb,
|
||||
Matthias Miller, Dean Edwards and John Resig. */
|
||||
|
||||
var timer, fired = false;
|
||||
var timer;
|
||||
|
||||
function fireContentLoadedEvent() {
|
||||
if (fired) return;
|
||||
if (document.loaded) return;
|
||||
if (timer) window.clearInterval(timer);
|
||||
document.fire("dom:loaded");
|
||||
fired = true;
|
||||
document.loaded = true;
|
||||
}
|
||||
|
||||
if (document.addEventListener) {
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<script type="text/javascript" language="javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
|
||||
var eventResults = { };
|
||||
var eventResults = { }, documentLoaded = document.loaded;
|
||||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
|
@ -203,6 +203,11 @@
|
|||
assertEqual(span, span.observe("test:somethingHappened", observer)); // try to reuse the same observer
|
||||
span.stopObserving();
|
||||
}},
|
||||
|
||||
testDocumentLoaded: function() { with(this) {
|
||||
assert(!documentLoaded);
|
||||
assert(document.loaded);
|
||||
}},
|
||||
|
||||
testDocumentContentLoadedEventFiresBeforeWindowLoad: function() { with(this) {
|
||||
assert(eventResults.contentLoaded, "contentLoaded");
|
||||
|
|
Loading…
Reference in New Issue