Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 26th, 2012  |  syntax: None  |  size: 1.23 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2.  * Window onLoad Init triggers
  3.  * Use to load all functions you need on window.onload w/o the need for jQuery
  4.  *
  5.  * @author Dean Edwards/Matthias Miller/John Resig
  6.  * @link http://stackoverflow.com/a/3144510/376483
  7.  */
  8. function init()
  9. {
  10.         // quit if this function has already been called
  11.         if ( arguments.callee.done )
  12.                 return;
  13.  
  14.         // flag this function so we don't do the same thing twice
  15.         arguments.callee.done = true;
  16.  
  17.         // kill the timer
  18.         if ( _timer )
  19.                 clearInterval( _timer );
  20.  
  21.         // DO STUFF
  22. };
  23.  
  24. /**
  25.  * for Mozilla/Opera9
  26.  */
  27. if ( document.addEventListener )
  28. {
  29.         document.addEventListener( "DOMContentLoaded", init, false );
  30. }
  31.  
  32. /**
  33.  * for Internet Explorer
  34.  */
  35. /*@cc_on @*/
  36. /*@if (@_win32)
  37.         document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  38.         var script = document.getElementById("__ie_onload");
  39.         script.onreadystatechange = function() {
  40.                 if (this.readyState == "complete") {
  41.                         init(); // call the onload handler
  42.                 }
  43.         };
  44. /*@end @*/
  45.  
  46. /**
  47.  * for Safari
  48.  */
  49. if ( /WebKit/i.test( navigator.userAgent ) ) // sniff
  50. {
  51.         var _timer = setInterval( function()
  52.         {
  53.                 if ( /loaded|complete/.test( document.readyState ) )
  54.                 {
  55.                         // call the onload handler
  56.                         init();
  57.                 }
  58.         }, 10);
  59. }
  60.  
  61. /**
  62.  * Other Browsers
  63.  */
  64. window.onload = init;