142
St
startsInvasion / files
startsInvasion / libs / node_modules / bonzo / integration / ender.js
27.2 KB
1/*! 2 * Ender: open module JavaScript framework 3 * copyright Dustin Diaz & Jacob Thornton 2011 (@ded @fat) 4 * https://ender.no.de 5 * License MIT 6 * Build: ender build scriptjs qwery domready bean 7 */ 8!function (context) { 9 10 function aug(o, o2) { 11 for (var k in o2) { 12 k != 'noConflict' && k != '_VERSION' && (o[k] = o2[k]); 13 } 14 return o; 15 } 16 17 function boosh(s, r, els) { 18 // string || node || nodelist || window 19 if (ender._select && (typeof s == 'string' || s.nodeName || s.length && 'item' in s || s == window)) { 20 els = ender._select(s, r); 21 els.selector = s; 22 } else { 23 els = isFinite(s.length) ? s : [s]; 24 } 25 return aug(els, boosh); 26 } 27 28 function ender(s, r) { 29 return boosh(s, r); 30 } 31 32 aug(ender, { 33 _VERSION: '0.2.4', 34 ender: function (o, chain) { 35 aug(chain ? boosh : ender, o); 36 }, 37 fn: context.$ && context.$.fn || {} // for easy compat to jQuery plugins 38 }); 39 40 aug(boosh, { 41 forEach: function (fn, scope, i) { 42 // opt out of native forEach so we can intentionally call our own scope 43 // defaulting to the current item and be able to return self 44 for (i = 0, l = this.length; i < l; ++i) { 45 i in this && fn.call(scope || this[i], this[i], i, this); 46 } 47 // return self for chaining 48 return this; 49 }, 50 $: ender // handy reference to self 51 }); 52 53 var old = context.$; 54 ender.noConflict = function () { 55 context.$ = old; 56 return this; 57 }; 58 59 (typeof module !== 'undefined') && module.exports && (module.exports = ender); 60 // use subscript notation as extern for Closure compilation 61 context['ender'] = context['$'] = ender; 62 63}(this); 64/*! 65 * $script.js v1.3 66 * https://github.com/ded/script.js 67 * Copyright: @ded & @fat - Dustin Diaz, Jacob Thornton 2011 68 * Follow our software http://twitter.com/dedfat 69 * License: MIT 70 */ 71!function(win, doc, timeout) { 72 var head = doc.getElementsByTagName('head')[0], 73 list = {}, ids = {}, delay = {}, 74 scripts = {}, s = 'string', f = false, 75 push = 'push', domContentLoaded = 'DOMContentLoaded', readyState = 'readyState', 76 addEventListener = 'addEventListener', onreadystatechange = 'onreadystatechange', 77 every = function(ar, fn) { 78 for (var i = 0, j = ar.length; i < j; ++i) { 79 if (!fn(ar[i])) { 80 return f; 81 } 82 } 83 return 1; 84 }; 85 function each(ar, fn) { 86 every(ar, function(el) { 87 return !fn(el); 88 }); 89 } 90 91 if (!doc[readyState] && doc[addEventListener]) { 92 doc[addEventListener](domContentLoaded, function fn() { 93 doc.removeEventListener(domContentLoaded, fn, f); 94 doc[readyState] = "complete"; 95 }, f); 96 doc[readyState] = "loading"; 97 } 98 99 var $script = function(paths, idOrDone, optDone) { 100 paths = paths[push] ? paths : [paths]; 101 var idOrDoneIsDone = idOrDone && idOrDone.call, 102 done = idOrDoneIsDone ? idOrDone : optDone, 103 id = idOrDoneIsDone ? paths.join('') : idOrDone, 104 queue = paths.length; 105 function loopFn(item) { 106 return item.call ? item() : list[item]; 107 } 108 function callback() { 109 if (!--queue) { 110 list[id] = 1; 111 done && done(); 112 for (var dset in delay) { 113 every(dset.split('|'), loopFn) && !each(delay[dset], loopFn) && (delay[dset] = []); 114 } 115 } 116 } 117 timeout(function() { 118 each(paths, function(path) { 119 if (scripts[path]) { 120 id && (ids[id] = 1); 121 callback(); 122 return; 123 } 124 scripts[path] = 1; 125 id && (ids[id] = 1); 126 create($script.path ? 127 $script.path + path + '.js' : 128 path, callback); 129 }); 130 }, 0); 131 return $script; 132 }; 133 134 function create(path, fn) { 135 var el = doc.createElement("script"), 136 loaded = f; 137 el.onload = el.onerror = el[onreadystatechange] = function () { 138 if ((el[readyState] && !(/^c|loade/.test(el[readyState]))) || loaded) { 139 return; 140 } 141 el.onload = el[onreadystatechange] = null; 142 loaded = 1; 143 fn(); 144 }; 145 el.async = 1; 146 el.src = path; 147 head.insertBefore(el, head.firstChild); 148 } 149 150 $script.get = create; 151 152 $script.ready = function(deps, ready, req) { 153 deps = deps[push] ? deps : [deps]; 154 var missing = []; 155 !each(deps, function(dep) { 156 list[dep] || missing[push](dep); 157 }) && every(deps, function(dep) { 158 return list[dep]; 159 }) ? ready() : !function(key) { 160 delay[key] = delay[key] || []; 161 delay[key][push](ready); 162 req && req(missing); 163 }(deps.join('|')); 164 return $script; 165 }; 166 167 var old = win.$script; 168 $script.noConflict = function () { 169 win.$script = old; 170 return this; 171 }; 172 173 (typeof module !== 'undefined' && module.exports) ? 174 (module.exports = $script) : 175 (win['$script'] = $script); 176 177}(this, document, setTimeout); 178ender.ender({ 179 script: $script, 180 ready: $script.ready, 181 require: $script, 182 getScript: $script.get 183}); 184/*! 185 * Qwery - A Blazing Fast query selector engine 186 * https://github.com/ded/qwery 187 * copyright Dustin Diaz & Jacob Thornton 2011 188 * MIT License 189 */ 190 191!function (context, doc) { 192 193 var c, i, j, k, l, m, o, p, r, v, 194 el, node, len, found, classes, item, items, token, 195 id = /#([\w\-]+)/, 196 clas = /\.[\w\-]+/g, 197 idOnly = /^#([\w\-]+$)/, 198 classOnly = /^\.([\w\-]+)$/, 199 tagOnly = /^([\w\-]+)$/, 200 tagAndOrClass = /^([\w]+)?\.([\w\-]+)$/, 201 html = doc.documentElement, 202 tokenizr = /\s(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\])/, 203 specialChars = /([.*+?\^=!:${}()|\[\]\/\\])/g, 204 simple = /^([a-z0-9]+)?(?:([\.\#]+[\w\-\.#]+)?)/, 205 attr = /\[([\w\-]+)(?:([\|\^\$\*\~]?\=)['"]?([ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+)["']?)?\]/, 206 chunker = new RegExp(simple.source + '(' + attr.source + ')?'); 207 208 function array(ar) { 209 r = []; 210 for (i = 0, len = ar.length; i < len; i++) { 211 r[i] = ar[i]; 212 } 213 return r; 214 } 215 216 var cache = function () { 217 this.c = {}; 218 }; 219 cache.prototype = { 220 g: function (k) { 221 return this.c[k] || undefined; 222 }, 223 s: function (k, v) { 224 this.c[k] = v; 225 return v; 226 } 227 }; 228 229 var classCache = new cache(), 230 cleanCache = new cache(), 231 attrCache = new cache(), 232 tokenCache = new cache(); 233 234 function q(query) { 235 return query.match(chunker); 236 } 237 238 function interpret(whole, tag, idsAndClasses, wholeAttribute, attribute, qualifier, value) { 239 var m, c, k; 240 if (tag && this.tagName.toLowerCase() !== tag) { 241 return false; 242 } 243 if (idsAndClasses && (m = idsAndClasses.match(id)) && m[1] !== this.id) { 244 return false; 245 } 246 if (idsAndClasses && (classes = idsAndClasses.match(clas))) { 247 for (i = classes.length; i--;) { 248 c = classes[i].slice(1); 249 if (!(classCache.g(c) || classCache.s(c, new RegExp('(^|\\s+)' + c + '(\\s+|$)'))).test(this.className)) { 250 return false; 251 } 252 } 253 } 254 if (wholeAttribute && !value) { 255 o = this.attributes; 256 for (k in o) { 257 if (Object.prototype.hasOwnProperty.call(o, k) && (o[k].name || k) == attribute) { 258 return this; 259 } 260 } 261 } 262 if (wholeAttribute && !checkAttr(qualifier, this.getAttribute(attribute) || '', value)) { 263 return false; 264 } 265 return this; 266 } 267 268 function loopAll(tokens) { 269 var r = [], token = tokens.pop(), intr = q(token), tag = intr[1] || '*', i, l, els, 270 root = tokens.length && (m = tokens[0].match(idOnly)) ? doc.getElementById(m[1]) : doc; 271 if (!root) { 272 return r; 273 } 274 els = root.getElementsByTagName(tag); 275 for (i = 0, l = els.length; i < l; i++) { 276 el = els[i]; 277 if (item = interpret.apply(el, intr)) { 278 r.push(item); 279 } 280 } 281 return r; 282 } 283 284 function clean(s) { 285 return cleanCache.g(s) || cleanCache.s(s, s.replace(specialChars, '\\$1')); 286 } 287 288 function checkAttr(qualify, actual, val) { 289 switch (qualify) { 290 case '=': 291 return actual == val; 292 case '^=': 293 return actual.match(attrCache.g('^=' + val) || attrCache.s('^=' + val, new RegExp('^' + clean(val)))); 294 case '$=': 295 return actual.match(attrCache.g('$=' + val) || attrCache.s('$=' + val, new RegExp(clean(val) + '$'))); 296 case '*=': 297 return actual.match(attrCache.g(val) || attrCache.s(val, new RegExp(clean(val)))); 298 case '~=': 299 return actual.match(attrCache.g('~=' + val) || attrCache.s('~=' + val, new RegExp('(?:^|\\s+)' + clean(val) + '(?:\\s+|$)'))); 300 case '|=': 301 return actual.match(attrCache.g('|=' + val) || attrCache.s('|=' + val, new RegExp('^' + clean(val) + '(-|$)'))); 302 } 303 return false; 304 } 305 306 function _qwery(selector) { 307 var r = [], ret = [], i, l, 308 tokens = tokenCache.g(selector) || tokenCache.s(selector, selector.split(tokenizr)); 309 tokens = tokens.slice(0); 310 if (!tokens.length) { 311 return r; 312 } 313 r = loopAll(tokens); 314 if (!tokens.length) { 315 return r; 316 } 317 // loop through all descendent tokens 318 for (j = 0, l = r.length, k = 0; j < l; j++) { 319 node = r[j]; 320 p = node; 321 // loop through each token 322 for (i = tokens.length; i--;) { 323 z: // loop through parent nodes 324 while (p !== html && (p = p.parentNode)) { 325 if (found = interpret.apply(p, q(tokens[i]))) { 326 break z; 327 } 328 } 329 } 330 found && (ret[k++] = node); 331 } 332 return ret; 333 } 334 335 function boilerPlate(selector, _root, fn) { 336 var root = (typeof _root == 'string') ? fn(_root)[0] : (_root || doc); 337 if (selector === window || isNode(selector)) { 338 return !_root || (selector !== window && isNode(root) && isAncestor(selector, root)) ? [selector] : []; 339 } 340 if (selector && typeof selector === 'object' && isFinite(selector.length)) { 341 return array(selector); 342 } 343 if (m = selector.match(idOnly)) { 344 return (el = doc.getElementById(m[1])) ? [el] : []; 345 } 346 if (m = selector.match(tagOnly)) { 347 return array(root.getElementsByTagName(m[1])); 348 } 349 return false; 350 } 351 352 function isNode(el) { 353 return (el && el.nodeType && (el.nodeType == 1 || el.nodeType == 9)); 354 } 355 356 function uniq(ar) { 357 var a = [], i, j; 358 label: 359 for (i = 0; i < ar.length; i++) { 360 for (j = 0; j < a.length; j++) { 361 if (a[j] == ar[i]) { 362 continue label; 363 } 364 } 365 a[a.length] = ar[i]; 366 } 367 return a; 368 } 369 370 function qwery(selector, _root) { 371 var root = (typeof _root == 'string') ? qwery(_root)[0] : (_root || doc); 372 if (!root || !selector) { 373 return []; 374 } 375 if (m = boilerPlate(selector, _root, qwery)) { 376 return m; 377 } 378 return select(selector, root); 379 } 380 381 var isAncestor = 'compareDocumentPosition' in html ? 382 function (element, container) { 383 return (container.compareDocumentPosition(element) & 16) == 16; 384 } : 'contains' in html ? 385 function (element, container) { 386 container = container == doc || container == window ? html : container; 387 return container !== element && container.contains(element); 388 } : 389 function (element, container) { 390 while (element = element.parentNode) { 391 if (element === container) { 392 return 1; 393 } 394 } 395 return 0; 396 }, 397 398 select = (doc.querySelector && doc.querySelectorAll) ? 399 function (selector, root) { 400 if (doc.getElementsByClassName && (m = selector.match(classOnly))) { 401 return array((root).getElementsByClassName(m[1])); 402 } 403 return array((root).querySelectorAll(selector)); 404 } : 405 function (selector, root) { 406 var result = [], collection, collections = [], i; 407 if (m = selector.match(tagAndOrClass)) { 408 items = root.getElementsByTagName(m[1] || '*'); 409 r = classCache.g(m[2]) || classCache.s(m[2], new RegExp('(^|\\s+)' + m[2] + '(\\s+|$)')); 410 for (i = 0, l = items.length, j = 0; i < l; i++) { 411 r.test(items[i].className) && (result[j++] = items[i]); 412 } 413 return result; 414 } 415 for (i = 0, items = selector.split(','), l = items.length; i < l; i++) { 416 collections[i] = _qwery(items[i]); 417 } 418 for (i = 0, l = collections.length; i < l && (collection = collections[i]); i++) { 419 var ret = collection; 420 if (root !== doc) { 421 ret = []; 422 for (j = 0, m = collection.length; j < m && (element = collection[j]); j++) { 423 // make sure element is a descendent of root 424 isAncestor(element, root) && ret.push(element); 425 } 426 } 427 result = result.concat(ret); 428 } 429 return uniq(result); 430 }; 431 432 qwery.uniq = uniq; 433 var oldQwery = context.qwery; 434 qwery.noConflict = function () { 435 context.qwery = oldQwery; 436 return this; 437 }; 438 context['qwery'] = qwery; 439 440}(this, document);!function (doc) { 441 var q = qwery.noConflict(); 442 var table = 'table', 443 nodeMap = { 444 thead: table, 445 tbody: table, 446 tfoot: table, 447 tr: 'tbody', 448 th: 'tr', 449 td: 'tr', 450 fieldset: 'form', 451 option: 'select' 452 } 453 function create(node, root) { 454 var tag = /^<([^\s>]+)/.exec(node)[1] 455 var el = (root || doc).createElement(nodeMap[tag] || 'div'), els = []; 456 el.innerHTML = node; 457 var nodes = el.childNodes; 458 el = el.firstChild; 459 els.push(el); 460 while (el = el.nextSibling) { 461 (el.nodeType == 1) && els.push(el); 462 } 463 return els; 464 } 465 $._select = function (s, r) { 466 return /^\s*</.test(s) ? create(s, r) : q(s, r); 467 }; 468 $.ender({ 469 find: function (s) { 470 var r = [], i, l, j, k, els; 471 for (i = 0, l = this.length; i < l; i++) { 472 els = q(s, this[i]); 473 for (j = 0, k = els.length; j < k; j++) { 474 r.push(els[j]); 475 } 476 } 477 return $(q.uniq(r)); 478 } 479 , and: function (s) { 480 var plus = $(s); 481 for (var i = this.length, j = 0, l = this.length + plus.length; i < l; i++, j++) { 482 this[i] = plus[j]; 483 } 484 return this; 485 } 486 }, true); 487}(document); 488!function (context, doc) { 489 var loaded = 0, fns = [], ol, f = false, 490 testEl = doc.createElement('a'), 491 domContentLoaded = 'DOMContentLoaded', 492 addEventListener = 'addEventListener', 493 onreadystatechange = 'onreadystatechange'; 494 495 /^loade|c/.test(doc.readyState) && (loaded = 1); 496 497 function flush() { 498 loaded = 1; 499 for (var i = 0, l = fns.length; i < l; i++) { 500 fns[i](); 501 } 502 } 503 doc[addEventListener] && doc[addEventListener](domContentLoaded, function fn() { 504 doc.removeEventListener(domContentLoaded, fn, f); 505 flush(); 506 }, f); 507 508 509 testEl.doScroll && doc.attachEvent(onreadystatechange, (ol = function ol() { 510 if (/^c/.test(doc.readyState)) { 511 doc.detachEvent(onreadystatechange, ol); 512 flush(); 513 } 514 })); 515 516 var domReady = testEl.doScroll ? 517 function (fn) { 518 self != top ? 519 !loaded ? 520 fns.push(fn) : 521 fn() : 522 !function () { 523 try { 524 testEl.doScroll('left'); 525 } catch (e) { 526 return setTimeout(function() { 527 domReady(fn); 528 }, 50); 529 } 530 fn(); 531 }(); 532 } : 533 function (fn) { 534 loaded ? fn() : fns.push(fn); 535 }; 536 537 context['domReady'] = domReady; 538 539}(this, document);!function ($) { 540 $.ender({domReady: domReady}); 541 $.ender({ 542 ready: function (f) { 543 domReady(f); 544 return this; 545 } 546 }, true); 547}(ender); 548/*! 549 * bean.js - copyright Jacob Thornton 2011 550 * https://github.com/fat/bean 551 * MIT License 552 * special thanks to: 553 * dean edwards: http://dean.edwards.name/ 554 * dperini: https://github.com/dperini/nwevents 555 * the entire mootools team: github.com/mootools/mootools-core 556 */ 557!function (context) { 558 var __uid = 1, registry = {}, collected = {}, 559 overOut = /over|out/, 560 namespace = /[^\.]*(?=\..*)\.|.*/, 561 stripName = /\..*/, 562 addEvent = 'addEventListener', 563 attachEvent = 'attachEvent', 564 removeEvent = 'removeEventListener', 565 detachEvent = 'detachEvent', 566 doc = context.document || {}, 567 root = doc.documentElement || {}, 568 W3C_MODEL = root[addEvent], 569 eventSupport = W3C_MODEL ? addEvent : attachEvent, 570 571 isDescendant = function (parent, child) { 572 var node = child.parentNode; 573 while (node != null) { 574 if (node == parent) { 575 return true; 576 } 577 node = node.parentNode; 578 } 579 }, 580 581 retrieveUid = function (obj, uid) { 582 return (obj.__uid = uid || obj.__uid || __uid++); 583 }, 584 585 retrieveEvents = function (element) { 586 var uid = retrieveUid(element); 587 return (registry[uid] = registry[uid] || {}); 588 }, 589 590 listener = W3C_MODEL ? function (element, type, fn, add) { 591 element[add ? addEvent : removeEvent](type, fn, false); 592 } : function (element, type, fn, add, custom) { 593 custom && add && (element['_on' + custom] = element['_on' + custom] || 0); 594 element[add ? attachEvent : detachEvent]('on' + type, fn); 595 }, 596 597 nativeHandler = function (element, fn, args) { 598 return function (event) { 599 event = fixEvent(event || ((this.ownerDocument || this.document || this).parentWindow || context).event); 600 return fn.apply(element, [event].concat(args)); 601 }; 602 }, 603 604 customHandler = function (element, fn, type, condition, args) { 605 return function (event) { 606 if (condition ? condition.call(this, event) : W3C_MODEL ? true : event && event.propertyName == '_on' + type || !event) { 607 fn.apply(element, [event].concat(args)); 608 } 609 }; 610 }, 611 612 addListener = function (element, orgType, fn, args) { 613 var type = orgType.replace(stripName, ''), 614 events = retrieveEvents(element), 615 handlers = events[type] || (events[type] = {}), 616 uid = retrieveUid(fn, orgType.replace(namespace, '')); 617 if (handlers[uid]) { 618 return element; 619 } 620 var custom = customEvents[type]; 621 if (custom) { 622 fn = custom.condition ? customHandler(element, fn, type, custom.condition) : fn; 623 type = custom.base || type; 624 } 625 var isNative = nativeEvents[type]; 626 fn = isNative ? nativeHandler(element, fn, args) : customHandler(element, fn, type, false, args); 627 isNative = W3C_MODEL || isNative; 628 if (type == 'unload') { 629 var org = fn; 630 fn = function () { 631 removeListener(element, type, fn) && org(); 632 }; 633 } 634 element[eventSupport] && listener(element, isNative ? type : 'propertychange', fn, true, !isNative && type); 635 handlers[uid] = fn; 636 fn.__uid = uid; 637 return type == 'unload' ? element : (collected[retrieveUid(element)] = element); 638 }, 639 640 removeListener = function (element, orgType, handler) { 641 var uid, names, uids, i, events = retrieveEvents(element), type = orgType.replace(stripName, ''); 642 if (!events || !events[type]) { 643 return element; 644 } 645 names = orgType.replace(namespace, ''); 646 uids = names ? names.split('.') : [handler.__uid]; 647 for (i = uids.length; i--;) { 648 uid = uids[i]; 649 handler = events[type][uid]; 650 delete events[type][uid]; 651 if (element[eventSupport]) { 652 type = customEvents[type] ? customEvents[type].base : type; 653 var isNative = W3C_MODEL || nativeEvents[type]; 654 listener(element, isNative ? type : 'propertychange', handler, false, !isNative && type); 655 } 656 } 657 return element; 658 }, 659 660 del = function (selector, fn, $) { 661 return function (e) { 662 var array = typeof selector == 'string' ? $(selector, this) : selector; 663 for (var target = e.target; target && target != this; target = target.parentNode) { 664 for (var i = array.length; i--;) { 665 if (array[i] == target) { 666 return fn.apply(target, arguments); 667 } 668 } 669 } 670 }; 671 }, 672 673 add = function (element, events, fn, delfn, $) { 674 if (typeof events == 'object' && !fn) { 675 for (var type in events) { 676 events.hasOwnProperty(type) && add(element, type, events[type]); 677 } 678 } else { 679 var isDel = typeof fn == 'string', types = (isDel ? fn : events).split(' '); 680 fn = isDel ? del(events, delfn, $) : fn; 681 for (var i = types.length; i--;) { 682 addListener(element, types[i], fn, Array.prototype.slice.call(arguments, isDel ? 4 : 3)); 683 } 684 } 685 return element; 686 }, 687 688 remove = function (element, orgEvents, fn) { 689 var k, type, events, 690 isString = typeof(orgEvents) == 'string', 691 names = isString && orgEvents.replace(namespace, ''), 692 rm = removeListener, 693 attached = retrieveEvents(element); 694 if (isString && /\s/.test(orgEvents)) { 695 orgEvents = orgEvents.split(' '); 696 var i = orgEvents.length - 1; 697 while (remove(element, orgEvents[i]) && i--) {} 698 return element; 699 } 700 events = isString ? orgEvents.replace(stripName, '') : orgEvents; 701 if (!attached || (isString && !attached[events])) { 702 return element; 703 } 704 if (typeof fn == 'function') { 705 rm(element, events, fn); 706 } else if (names) { 707 rm(element, orgEvents); 708 } else { 709 rm = events ? rm : remove; 710 type = isString && events; 711 events = events ? (fn || attached[events] || events) : attached; 712 for (k in events) { 713 events.hasOwnProperty(k) && rm(element, type || k, events[k]); 714 } 715 } 716 return element; 717 }, 718 719 fire = function (element, type, args) { 720 var evt, k, i, types = type.split(' '); 721 for (i = types.length; i--;) { 722 type = types[i].replace(stripName, ''); 723 var isNative = nativeEvents[type], 724 isNamespace = types[i].replace(namespace, ''), 725 handlers = retrieveEvents(element)[type]; 726 if (isNamespace) { 727 isNamespace = isNamespace.split('.'); 728 for (k = isNamespace.length; k--;) { 729 handlers[isNamespace[k]] && handlers[isNamespace[k]].apply(element, args); 730 } 731 } else if (!args && element[eventSupport]) { 732 fireListener(isNative, type, element); 733 } else { 734 for (k in handlers) { 735 handlers.hasOwnProperty(k) && handlers[k].apply(element, args); 736 } 737 } 738 } 739 return element; 740 }, 741 742 fireListener = W3C_MODEL ? function (isNative, type, element) { 743 evt = document.createEvent(isNative ? "HTMLEvents" : "UIEvents"); 744 evt[isNative ? 'initEvent' : 'initUIEvent'](type, true, true, context, 1); 745 element.dispatchEvent(evt); 746 } : function (isNative, type, element) { 747 isNative ? element.fireEvent('on' + type, document.createEventObject()) : element['_on' + type]++; 748 }, 749 750 clone = function (element, from, type) { 751 var events = retrieveEvents(from), obj, k; 752 obj = type ? events[type] : events; 753 for (k in obj) { 754 obj.hasOwnProperty(k) && (type ? add : clone)(element, type || from, type ? obj[k] : k); 755 } 756 return element; 757 }, 758 759 fixEvent = function (e) { 760 var result = {}; 761 if (!e) { 762 return result; 763 } 764 var type = e.type, target = e.target || e.srcElement; 765 result.preventDefault = fixEvent.preventDefault(e); 766 result.stopPropagation = fixEvent.stopPropagation(e); 767 result.target = target && target.nodeType == 3 ? target.parentNode : target; 768 if (~type.indexOf('key')) { 769 result.keyCode = e.which || e.keyCode; 770 } else if ((/click|mouse|menu/i).test(type)) { 771 result.rightClick = e.which == 3 || e.button == 2; 772 result.pos = { x: 0, y: 0 }; 773 if (e.pageX || e.pageY) { 774 result.clientX = e.pageX; 775 result.clientY = e.pageY; 776 } else if (e.clientX || e.clientY) { 777 result.clientX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; 778 result.clientY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; 779 } 780 overOut.test(type) && (result.relatedTarget = e.relatedTarget || e[(type == 'mouseover' ? 'from' : 'to') + 'Element']); 781 } 782 for (var k in e) { 783 if (!(k in result)) { 784 result[k] = e[k]; 785 } 786 } 787 return result; 788 }; 789 790 fixEvent.preventDefault = function (e) { 791 return function () { 792 if (e.preventDefault) { 793 e.preventDefault(); 794 } 795 else { 796 e.returnValue = false; 797 } 798 }; 799 }; 800 801 fixEvent.stopPropagation = function (e) { 802 return function () { 803 if (e.stopPropagation) { 804 e.stopPropagation(); 805 } else { 806 e.cancelBubble = true; 807 } 808 }; 809 }; 810 811 var nativeEvents = { click: 1, dblclick: 1, mouseup: 1, mousedown: 1, contextmenu: 1, //mouse buttons 812 mousewheel: 1, DOMMouseScroll: 1, //mouse wheel 813 mouseover: 1, mouseout: 1, mousemove: 1, selectstart: 1, selectend: 1, //mouse movement 814 keydown: 1, keypress: 1, keyup: 1, //keyboard 815 orientationchange: 1, // mobile 816 touchstart: 1, touchmove: 1, touchend: 1, touchcancel: 1, // touch 817 gesturestart: 1, gesturechange: 1, gestureend: 1, // gesture 818 focus: 1, blur: 1, change: 1, reset: 1, select: 1, submit: 1, //form elements 819 load: 1, unload: 1, beforeunload: 1, resize: 1, move: 1, DOMContentLoaded: 1, readystatechange: 1, //window 820 error: 1, abort: 1, scroll: 1 }; //misc 821 822 function check(event) { 823 var related = event.relatedTarget; 824 if (!related) { 825 return related == null; 826 } 827 return (related != this && related.prefix != 'xul' && !/document/.test(this.toString()) && !isDescendant(this, related)); 828 } 829 830 var customEvents = { 831 mouseenter: { base: 'mouseover', condition: check }, 832 mouseleave: { base: 'mouseout', condition: check }, 833 mousewheel: { base: /Firefox/.test(navigator.userAgent) ? 'DOMMouseScroll' : 'mousewheel' } 834 }; 835 836 var bean = { add: add, remove: remove, clone: clone, fire: fire }; 837 838 var clean = function (el) { 839 var uid = remove(el).__uid; 840 if (uid) { 841 delete collected[uid]; 842 delete registry[uid]; 843 } 844 }; 845 846 if (context[attachEvent]) { 847 add(context, 'unload', function () { 848 for (var k in collected) { 849 collected.hasOwnProperty(k) && clean(collected[k]); 850 } 851 context.CollectGarbage && CollectGarbage(); 852 }); 853 } 854 855 var oldBean = context.bean; 856 bean.noConflict = function () { 857 context.bean = oldBean; 858 return this; 859 }; 860 861 (typeof module !== 'undefined' && module.exports) ? 862 (module.exports = bean) : 863 (context['bean'] = bean); 864 865}(this);!function ($) { 866 var b = bean.noConflict(), 867 integrate = function (method, type, method2) { 868 var _args = type ? [type] : []; 869 return function () { 870 for (var args, i = 0, l = this.length; i < l; i++) { 871 args = [this[i]].concat(_args, Array.prototype.slice.call(arguments, 0)); 872 args.length == 4 && args.push($); 873 !arguments.length && method == 'add' && type && (method = 'fire'); 874 b[method].apply(this, args); 875 } 876 return this; 877 }; 878 }; 879 880 var add = integrate('add'), 881 remove = integrate('remove'), 882 fire = integrate('fire'); 883 884 var methods = { 885 886 on: add, 887 addListener: add, 888 bind: add, 889 listen: add, 890 delegate: add, 891 892 unbind: remove, 893 unlisten: remove, 894 removeListener: remove, 895 undelegate: remove, 896 897 emit: fire, 898 trigger: fire, 899 900 cloneEvents: integrate('clone'), 901 902 hover: function (enter, leave) { 903 for (var i = 0, l = this.length; i < l; i++) { 904 b.add.call(this, this[i], 'mouseenter', enter); 905 b.add.call(this, this[i], 'mouseleave', leave); 906 } 907 return this; 908 } 909 }; 910 911 var shortcuts = [ 912 'blur', 'change', 'click', 'dblclick', 'error', 'focus', 'focusin', 913 'focusout', 'keydown', 'keypress', 'keyup', 'load', 'mousedown', 914 'mouseenter', 'mouseleave', 'mouseout', 'mouseover', 'mouseup', 'mousemove', 915 'resize', 'scroll', 'select', 'submit', 'unload' 916 ]; 917 918 for (var i = shortcuts.length; i--;) { 919 var shortcut = shortcuts[i]; 920 methods[shortcut] = integrate('add', shortcut); 921 } 922 923 $.ender(methods, true); 924}(ender);