Changeset 1354

Show
Ignore:
Timestamp:
02/06/08 22:54:49 (17 months ago)
Author:
ddavis
Message:

Added fast javascript init that fires the window onload when the dom is ready. BugzID: 67754

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-29/default_templates/javascript.mtml

    r1351 r1354  
    210210    } 
    211211 
     212 
     213// BEGIN: fast browser onload init 
     214// Modificaitons by David Davis, DWD 
     215// Dean Edwards/Matthias Miller/John Resig 
     216// http://dean.edwards.name/weblog/2006/06/again/?full#comment5338 
     217 
     218function init() { 
     219  // quit if this function has already been called 
     220  if (arguments.callee.done) return; 
     221 
     222  // flag this function so we don't do the same thing twice 
     223  arguments.callee.done = true; 
     224 
     225  // kill the timer 
     226  // DWD - check against window 
     227  if ( window._timer ) clearInterval(window._timer); 
     228   
     229  // DWD - fire the window onload now, and replace it 
     230  if ( window.onload && ( window.onload !== window.init ) ) { 
     231    window.onload(); 
     232    window.onload = function() {}; 
     233  } 
     234}; 
     235 
     236/* for Mozilla/Opera9 */ 
     237if (document.addEventListener) { 
     238  document.addEventListener("DOMContentLoaded", init, false); 
     239} 
     240 
     241/* for Internet Explorer */ 
     242/*@cc_on @*/ 
     243/*@if (@_win32) 
     244  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>"); 
     245  var script = document.getElementById("__ie_onload"); 
     246  script.onreadystatechange = function() { 
     247    if (this.readyState == "complete") { 
     248      init(); // call the onload handler 
     249    } 
     250  }; 
     251/*@end @*/ 
     252 
     253/* for Safari */ 
     254if (/WebKit/i.test(navigator.userAgent)) { // sniff 
     255  _timer = setInterval(function() { 
     256    if (/loaded|complete/.test(document.readyState)) { 
     257      init(); // call the onload handler 
     258    } 
     259  }, 10); 
     260} 
     261 
     262/* for other browsers */ 
     263window.onload = init; 
     264 
     265// END: fast browser onload init 
     266