"MDL-13368, improve ufo.js to HEAD, backport to 1.9 later"

This commit is contained in:
dongsheng 2008-06-26 06:21:32 +00:00
parent 9c1ae6fc65
commit 16aab58bd4

View File

@ -1,8 +1,10 @@
/* Unobtrusive Flash Objects (UFO) v3.22 <http://www.bobbyvandersluis.com/ufo/>
Copyright 2005-2007 Bobby van der Sluis
This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
/* Unobtrusive Flash Objects (UFO) v3.22 <http://www.bobbyvandersluis.com/ufo/>
Copyright 2005-2007 Bobby van der Sluis
This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
--
Modified by Guy Thomas
- made more IE friendly by using better on DOM loaded check
CONTAINS MINOR CHANGE FOR MOODLE (bottom code for MDL-9825)
*/
var UFO = {
@ -37,15 +39,7 @@ var UFO = {
},
domLoad: function(id) {
var _t = setInterval(function() {
if ((document.getElementsByTagName("body")[0] != null || document.body != null) && document.getElementById(id) != null) {
UFO.main(id);
clearInterval(_t);
}
}, 250);
if (typeof document.addEventListener != "undefined") {
document.addEventListener("DOMContentLoaded", function() { UFO.main(id); clearInterval(_t); } , null); // Gecko, Opera 9+
}
onDOMComplete(window, function(){UFO.main(id);});
},
main: function(id) {
@ -273,17 +267,10 @@ var UFO = {
var _l = _o.length
for (var i = 0; i < _l; i++) {
_o[i].style.display = "none";
var j = 0;
for (var x in _o[i]) {
j++;
if (typeof _o[i][x] == "function") {
_o[i][x] = null;
}
if (j > 1000) {
// something is wrong, probably infinite loop caused by embedded html file
// see MDL-9825
break;
}
}
}
}
@ -293,3 +280,61 @@ var UFO = {
if (typeof window.attachEvent != "undefined" && UFO.uaHas("ieWin")) {
window.attachEvent("onunload", UFO.cleanupIELeaks);
}
/*
*
* DOMComplete - Load Event
*
* Author: Diego Perini (diego.perini@gmail.com)
* Updated: 28/06/2007
* Version: 0.99.8
* http://javascript.nwbox.com/DOMComplete/
* Modified: By Guy Thomas 07/02/2008
* Changed to scroll temporary node instead of actual document
*/
function onDOMComplete(w, f) {
var d = w.document, done = false;
//create temporary node to check scroll left ( see http://www.hedgerwow.com/360/dhtml/ie-dom-ondocumentready.html)
var tempNode = document.createElement('document:ready');
wait();
if ((/WebKit|KHTML|MSIE/i).test(navigator.userAgent)) {
poll();
}
function load(e) {
if (!done) {
tempNode = null;
done = true; stop(); f(e);
}
}
function has(p) { return typeof d[p] != 'undefined'; }
function poll() {
if (d.body !== null && d.getElementsByTagName) {
// please see http://javascript.nwbox.com/IEContentLoaded/ for the IE improvement part of DOMComplete
// GT modified to use tempNode.doScroll('left') to check DOM loaded (instead of actually scrolling the page)
if (has('fileSize')) { try { tempNode.doScroll('left'); load('documentready'); } catch (e) { } }
if (has('readyState') && (/loaded|complete/).test(d.readyState)) { load('readyState'); }
}
if (!done) { setTimeout(poll, 10); }
}
function stop() {
if (typeof d.removeEventListener == 'function') {
d.removeEventListener('DOMContentLoaded', load, false);
}
}
function wait() {
if (typeof d.addEventListener == 'function') {
d.addEventListener('DOMContentLoaded', load, false);
}
var oldonload = w.onload;
w.onload = function (e) {
if (typeof oldonload == 'function') {
oldonload();
}
load(e || this.event);
};
}
}