1 2/*****************************************************************************\ 3* Events * 4\*****************************************************************************/ 5 6 7 8/* 9 * (c)2006 Dean Edwards/Matthias Miller/John Resig 10 * Special thanks to Dan Webb's domready.js Prototype extension 11 * and Simon Willison's addLoadEvent 12 * 13 * For more info, see: 14 * http://dean.edwards.name/weblog/2006/06/again/ 15 * http://www.vivabit.com/bollocks/2006/06/21/a-dom-ready-extension-for-prototype 16 * http://simon.incutio.com/archive/2004/05/26/addLoadEvent 17 * 18 * Thrown together by Jesse Skinner (http://www.thefutureoftheweb.com/) 19 * 20 * Slightly modified by David "Dewi" Young: 21 * broadened KHTML regexp 22 * in IE hack, replaced void(0) with false to work better in a https context 23 * corrected IE hack markup 24 * amended window.onload fallback not to clobber any existing handler 25 * removed reference to Array.push() unsupported in IE5 26 * 27 * To use: call addDOMLoadEvent one or more times with functions, ie: 28 * 29 * function something() { 30 * // do something 31 * } 32 * addDOMLoadEvent(something); 33 * 34 * addDOMLoadEvent(function() { 35 * // do other stuff 36 * }); 37 * 38 */ 39 40function addDOMLoadEvent(func) { 41 if (!window.__load_events) { 42 var init = function () { 43 // quit if this function has already been called 44 if (arguments.callee.done) return; 45 46 // flag this function so we do not do the same thing twice 47 arguments.callee.done = true; 48 49 // kill the timer 50 if (window.__load_timer) { 51 clearInterval(window.__load_timer); 52 window.__load_timer = null; 53 } 54 55 // execute each function in the stack in the order they were added 56 for (var i=0;i < window.__load_events.length;i++) { 57 window.__load_events[i](); 58 } 59 window.__load_events = null; 60 }; 61 62 // for Mozilla/Opera9 63 if (document.addEventListener) { 64 document.addEventListener("DOMContentLoaded", init, false); 65 } 66 67 // for Internet Explorer 68 /*@cc_on @*/ 69 /*@if (@_win32) 70 document.write("<scr"+"ipt id='__ie_onload' defer src='javascript:false;'><\/scr"+"ipt>"); 71 var script = document.getElementById("__ie_onload"); 72 script.onreadystatechange = function() { 73 if (this.readyState == "complete") { 74 init(); // call the onload handler 75 } 76 }; 77 /*@end @*/ 78 79 // for Safari 80 if (/KHTML|WebKit/i.test(navigator.userAgent)) { // sniff 81 window.__load_timer = setInterval(function() { 82 if (/loaded|complete/.test(document.readyState)) { 83 init(); // call the onload handler 84 } 85 }, 10); 86 } 87 88 // for other browsers 89 var oldonload = window.onload; 90 if (typeof(window.onload) != 'function') { 91 window.onload = init; 92 } else { 93 window.onload = function() { 94 init(); 95 if (oldonload) { 96 oldonload(); 97 } 98 } 99 } 100 101 // create event function stack 102 window.__load_events = []; 103 } 104 105 // add function to event stack 106 window.__load_events[window.__load_events.length] = func; 107} 108 109 110 111 112/* 113 * Based on: 114 * code from "Crossbrowser DOM Scripting: Event Handlers" 115 * by Scott Andrew (http://www.scottandrew.com/weblog/articles/cbs-events) 116 * code from "Executing JavaScript on page load" 117 * by S. Willison (http://simon.incutio.com/archive/2004/05/26/addLoadEvent) 118 * 119 * Modifications by David "Dewi" Young. 120 * 121 * Notes: 122 * Take care with Capture mode; IE lacks support and Firefox is wrong. 123 * On pre-version-5 browsers, event removal is likely to fail. 124 * 125 */ 126 127function addEvent(obj, evType, fn, useCapture){ 128 if (obj.addEventListener){ 129 // W3C Registration 130 obj.addEventListener(evType, fn, useCapture); 131 return true; 132 } else if (obj.attachEvent){ 133 // IE Registration 134 return obj.attachEvent('on' + evType, fn); 135 } else { 136 // Fall back to traditional 137 var eventName = 'on' + evType; 138 var oldEvent = obj[eventName]; 139 if (typeof(oldEvent) != 'function') { 140 obj[eventName] = fn; 141 } else { 142 obj[eventName] = function() { 143 if (oldEvent) { 144 oldEvent(); 145 } 146 fn(); 147 } 148 } 149 return true; 150 } 151} 152 153function removeEvent(obj, evType, fn, useCapture){ 154 if (obj.removeEventListener){ 155 // W3C Deregistration 156 obj.removeEventListener(evType, fn, useCapture); 157 return true; 158 } else if (obj.detachEvent){ 159 // IE Deregistration
160 obj.detachEvent('on' + evType, fn); 161 return true; 162 } else { 163 // Sorry, insufficient browser support. 164 return false; 165 } 166} 167 168 169 170 171 172 173/*****************************************************************************\ 174* Effects * 175\*****************************************************************************/ 176 177 178 179function textShadowsInit() { 180 // Usage: 181 // Controlled by attribute tobor-text-shadow="color x-offset y-offset" 182 // * Element must have parent, which will end up with position: relative. 183 // * Color must be numeric (in IE, anyway) 184 // * Offsets must have unit. 185 // Problems: 186 // * Avoid margins and padding (particularly horizontal) on the 187 // element, as IE will double it on the shadow and selectively 188 // ignore the need for wrapping. 189 // * Wrap points of original and shadow differ slightly due to the offset; 190 // avoid the possibility of wrapping where possible. 191 192 // get live elements list 193 var els = document.getElementsByTagName('*'); 194 195 // get dead elements list 196 var dels = new Array(0); 197 for (var ii = 0; ii < els.length; ii++) { 198 dels[dels.length] = els[ii]; 199 } 200 201 // iterate elements 202 for (var ii = 0; ii < dels.length; ii++) { 203 var el = dels[ii]; 204 var paramstr = el.getAttribute('tobor-text-shadow'); 205 206 // do only elements with attribute 207 if (undefined != paramstr) { 208 var params = paramstr.split(' '); 209 210 // do only elements with valid attribute value 211 if (params.length >= 3) { 212 var color = params[0]; 213 var xx = params[1]; 214 var yy = params[2]; 215 216 // parent position relative (to act as container) 217 el.parentNode.style.position = 'relative'; 218 219 220 // copy element without attribute 221 var copy = el.cloneNode(true); 222 copy.removeAttribute('tobor-text-shadow'); 223 224 // original comes forward 225 el.style.position = 'relative'; 226 el.style.zIndex = 1; 227 228 // copy becomes shadow 229 copy.style.color = color; 230 copy.style.position = 'absolute'; 231 copy.style.marginTop = '0'; // or FF applies twice 232 copy.style.top = yy; 233 copy.style.left = xx; 234 235 // insert copy 236 el.parentNode.insertBefore(copy, el); 237 } 238 } 239 } 240} 241 242 243 244 245 246 247 248/* 249 * Sets the opacity of an element. Known to work with Firefox 2, Opera 9, IE 6 250 * and 7, and Safari (Windows). IE requires that the element style has an 251 * opacity filter, which can be initialised with the following property... 252 * 253 * filter:alpha(opacity=100); 254 * 255 * Fails silently if techniques are unavailable. 256 * 257 * Parameters: 258 * el the element to manipulate 259 * opacity the desired opacity, from 0 to 1. 260 */ 261function setOpacity(el, opacity) { 262 if ('undefined' != typeof(el.style.opacity)) { 263 el.style.opacity = opacity; 264 } else if ('undefined' != typeof(el.style.MozOpacity)) { 265 el.style.MozOpacity = opacity; 266 } else if ('undefined' != typeof(el.filters) && 'undefined' != typeof(el.filters.alpha) && 'undefined' != typeof(el.filters.alpha.opacity)) { 267 el.filters.alpha.opacity = opacity * 100; 268 } 269} 270 271/* 272 * Transitions a value linearly from here to a target, executing actions 273 * throughout and on completion. 274 * 275 * Properties: 276 * this.current the current counter value 277 * this.target the target counter value 278 * this.delta the change in counter value per cycle 279 * this.fps the number of cycles per second 280 * this.actionUpdate the function to call each cycle with the new value 281 * this.actionPost a function to call upon completion 282 * this.disabled dictates whether this animation can continue 283 */ 284function Animation() { 285 286 /* properties */ 287 this.current = 0; 288 this.target = 1; 289 this.delta = 0.01; 290 this.fps = 50; 291 this.actionCatch = null; 292 this.actionUpdate = null; 293 this.actionPost = null; 294 this.disabled = false; 295 296 this.run = function() { 297 try { 298 if (!this.disabled) { 299 /* validation */ 300 var togo = this.target - this.current; 301 if (togo < 0 && this.delta > 0) { 302 this.delta = -this.delta; 303 } 304 305 var changed = false; 306 307 if (togo != 0) { 308 if (Math.abs(togo) <= Math.abs(this.delta)) { 309 this.current = this.target; 310 } else { 311 this.current += this.delta; 312 } 313 changed = true; 314 } 315 316 if (changed && 'function' == typeof(this.actionUpdate)) { 317 318 /* perform action */ 319 this.actionUpdate(this.current); 320 321 /* schedule next */ 322 var _lt_an = this; 323 window.setTimeout(function() { _lt_an.run(); }, 1000 / this.fps); 324 325 } else if ('function' == typeof(this.actionPost)) { 326 327 /* clear and discharge post action */ 328 var _post = this.actionPost; 329 this.actionPost = null; 330 _post(); 331 } 332 } 333 } catch(err) { 334 if ('function' == typeof(this.actionCatch)) { 335 this.actionCatch(err); 336 } else { 337 throw err; 338 } 339 } 340 } 341}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.