]> err.no Git - scalable-opengroupware.org/blob - UI/WebServerResources/fastinit.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1294 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / fastinit.js
1 /*\r
2 *\r
3 * Copyright (c) 2007 Andrew Tetlaw\r
4\r
5 * Permission is hereby granted, free of charge, to any person\r
6 * obtaining a copy of this software and associated documentation\r
7 * files (the "Software"), to deal in the Software without\r
8 * restriction, including without limitation the rights to use, copy,\r
9 * modify, merge, publish, distribute, sublicense, and/or sell copies\r
10 * of the Software, and to permit persons to whom the Software is\r
11 * furnished to do so, subject to the following conditions:\r
12\r
13 * The above copyright notice and this permission notice shall be\r
14 * included in all copies or substantial portions of the Software.\r
15\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
23 * SOFTWARE.\r
24 * * \r
25 *\r
26 *\r
27 * FastInit\r
28 * http://tetlaw.id.au/view/javascript/fastinit\r
29 * Andrew Tetlaw\r
30 * Version 1.4.1 (2007-03-15)\r
31 * Based on:\r
32 * http://dean.edwards.name/weblog/2006/03/faster\r
33 * http://dean.edwards.name/weblog/2006/06/again/\r
34 * Help from:\r
35 * http://www.cherny.com/webdev/26/domloaded-object-literal-updated\r
36\r
37 */\r
38 var FastInit = {\r
39         onload : function() {\r
40                 if (FastInit.done) { return; }\r
41                 FastInit.done = true;\r
42                 for(var x = 0, al = FastInit.f.length; x < al; x++) {\r
43                         FastInit.f[x]();\r
44                 }\r
45         },\r
46         addOnLoad : function() {\r
47                 var a = arguments;\r
48                 for(var x = 0, al = a.length; x < al; x++) {\r
49                         if(typeof a[x] === 'function') {\r
50                                 if (FastInit.done ) {\r
51                                         a[x]();\r
52                                 } else {\r
53                                         FastInit.f.push(a[x]);\r
54                                 }\r
55                         }\r
56                 }\r
57         },\r
58         listen : function() {\r
59                 if (/WebKit|khtml/i.test(navigator.userAgent)) {\r
60                         FastInit.timer = setInterval(function() {\r
61                                 if (/loaded|complete/.test(document.readyState)) {\r
62                                         clearInterval(FastInit.timer);\r
63                                         delete FastInit.timer;\r
64                                         FastInit.onload();\r
65                                 }}, 10);\r
66                 } else if (document.addEventListener) {\r
67                         document.addEventListener('DOMContentLoaded', FastInit.onload, false);\r
68                 } else if(!FastInit.iew32) {\r
69                         if(window.addEventListener) {\r
70                                 window.addEventListener('load', FastInit.onload, false);\r
71                         } else if (window.attachEvent) {\r
72                                 return window.attachEvent('onload', FastInit.onload);\r
73                         }\r
74                 }\r
75         },\r
76         f:[],done:false,timer:null,iew32:false\r
77 };\r
78 /*@cc_on @*/\r
79 /*@if (@_win32)\r
80 FastInit.iew32 = true;\r
81 document.write('<script id="__ie_onload" defer src="' + ((location.protocol == 'https:') ? '//0' : 'javascript:void(0)') + '"><\/script>');\r
82 document.getElementById('__ie_onload').onreadystatechange = function(){if (this.readyState == 'complete') { FastInit.onload(); }};\r
83 /*@end @*/\r
84 FastInit.listen();\r