Changeset 6596
- Timestamp:
- 04/27/07 22:31:13 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spinoffs/prototype/branches/event/src/event.js
r6537 r6596 1 if (!window.Event) { 2 var Event = new Object(); 3 } 1 if (!window.Event) var Event = {}; 4 2 5 3 Object.extend(Event, { … … 93 91 }, 94 92 add: function() { 93 if (this.type == 'DOMContentLoaded' && this.element == document) { 94 onReady(this.observer); 95 return; 96 } 95 97 this._add(); 96 98 this.cache(); … … 186 188 return true; // the calling method can end 187 189 }; 190 191 // based on work by Dan Webb, Matthias Miller, Dean Edwards and John Resig 192 var readyCallbacks, timer; 193 194 function domReady() { 195 if (arguments.callee.done) return; 196 arguments.callee.done = true; 197 if (timer) clearInterval(timer); 198 199 readyCallbacks.each(function(f) { f() }); 200 readyCallbacks = null; 201 } 202 function onReady(f) { 203 if (!readyCallbacks) { 204 if (domReady.done) return f(); 205 206 if (document.addEventListener) { 207 if (B.WebKit) { 208 timer = setInterval(function() { 209 if (/loaded|complete/.test(document.readyState)) domReady(); 210 }, 10); 211 } 212 else document.addEventListener('DOMContentLoaded', domReady, false); 213 } 214 else if (B.IE) { 215 var dummy = location.protocol == "https:" ? "https://javascript:void(0)" : "javascript:void(0)"; 216 document.write("<script id=__ie_onload defer src='" + dummy + "'><\/script>"); 217 $("__ie_onload").onreadystatechange = function() { if (this.readyState == "complete") { 218 this.onreadystatechange = null; domReady(); 219 }}; 220 } 221 222 Event.observe(window, 'load', domReady); 223 readyCallbacks = []; 224 } 225 readyCallbacks.push(f); 226 } 188 227 189 228 return { spinoffs/prototype/branches/event/test/functional/event.html
r6462 r6596 44 44 <script type="text/javascript"> Element.addMethods(); </script> 45 45 46 <script src="../lib/unittest.js" type="text/javascript"></script>47 <link rel="stylesheet" href="../test.css" type="text/css" />48 49 46 <style type="text/css" media="screen"> 50 47 /* <![CDATA[ */ 51 body { margin:1em 2em; padding:0 }48 body { margin:1em 2em; padding:0; font-size:0.8em } 52 49 hr { width:31.2em; margin:1em 0; text-align:left } 53 50 p { width:30em; margin:0.5em 0; padding:0.3em 0.6em; color:#222; background:#eee; border:1px solid silver; }