142
St
startsInvasion / files
startsInvasion / libs / ender.js
95.8 KB
1/*! 2 * ======================================================= 3 * Ender: open module JavaScript framework 4 * copyright Dustin Diaz & Jacob Thornton 2011 (@ded @fat) 5 * https://ender.no.de 6 * License MIT 7 * Module's individual licenses still apply 8 * Build: ender build domready bean bonzo underscore reqwest qwery 9 * ======================================================= 10 */ 11 12/*! 13 * Ender-JS: open module JavaScript framework (client-lib) 14 * copyright Dustin Diaz & Jacob Thornton 2011 (@ded @fat) 15 * https://ender.no.de 16 * License MIT 17 */ 18!function (context) { 19 20 // Implements simple module system 21 // losely based on CommonJS Modules spec v1.1.1 22 // ============================================ 23 24 var modules = {}; 25 26 function require (identifier) { 27 var module = modules[identifier] || window[identifier]; 28 if (!module) throw new Error("Requested module has not been defined."); 29 return module; 30 } 31 32 function provide (name, what) { 33 return modules[name] = what; 34 } 35 36 context['provide'] = provide; 37 context['require'] = require; 38 39 // Implements Ender's $ global access object 40 // ========================================= 41 42 function aug(o, o2) { 43 for (var k in o2) { 44 k != 'noConflict' && k != '_VERSION' && (o[k] = o2[k]); 45 } 46 return o; 47 } 48 49 function boosh(s, r, els) { 50 // string || node || nodelist || window 51 if (ender._select && (typeof s == 'string' || s.nodeName || s.length && 'item' in s || s == window)) { 52 els = ender._select(s, r); 53 els.selector = s; 54 } else { 55 els = isFinite(s.length) ? s : [s]; 56 } 57 return aug(els, boosh); 58 } 59 60 function ender(s, r) { 61 return boosh(s, r); 62 } 63 64 aug(ender, { 65 _VERSION: '0.2.5', 66 ender: function (o, chain) { 67 aug(chain ? boosh : ender, o); 68 }, 69 fn: context.$ && context.$.fn || {} // for easy compat to jQuery plugins 70 }); 71 72 aug(boosh, { 73 forEach: function (fn, scope, i) { 74 // opt out of native forEach so we can intentionally call our own scope 75 // defaulting to the current item and be able to return self 76 for (i = 0, l = this.length; i < l; ++i) { 77 i in this && fn.call(scope || this[i], this[i], i, this); 78 } 79 // return self for chaining 80 return this; 81 }, 82 $: ender // handy reference to self 83 }); 84 85 var old = context.$; 86 ender.noConflict = function () { 87 context.$ = old; 88 return this; 89 }; 90 91 (typeof module !== 'undefined') && module.exports && (module.exports = ender); 92 // use subscript notation as extern for Closure compilation 93 context['ender'] = context['$'] = ender; 94 95}(this); 96 97!function () { 98 99 var module = { exports: {} }, exports = module.exports; 100 101 !function (context, doc) { 102 var fns = [], ol, fn, f = false, 103 testEl = doc.documentElement, 104 hack = testEl.doScroll, 105 domContentLoaded = 'DOMContentLoaded', 106 addEventListener = 'addEventListener', 107 onreadystatechange = 'onreadystatechange', 108 loaded = /^loade|c/.test(doc.readyState); 109 110 function flush(i) { 111 loaded = 1; 112 while (i = fns.shift()) { i() } 113 } 114 doc[addEventListener] && doc[addEventListener](domContentLoaded, fn = function () { 115 doc.removeEventListener(domContentLoaded, fn, f); 116 flush(); 117 }, f); 118 119 120 hack && doc.attachEvent(onreadystatechange, (ol = function () { 121 if (/^c/.test(doc.readyState)) { 122 doc.detachEvent(onreadystatechange, ol); 123 flush(); 124 } 125 })); 126 127 context['domReady'] = hack ? 128 function (fn) { 129 self != top ? 130 loaded ? fn() : fns.push(fn) : 131 function () { 132 try { 133 testEl.doScroll('left'); 134 } catch (e) { 135 return setTimeout(function() { domReady(fn) }, 50); 136 } 137 fn(); 138 }() 139 } : 140 function (fn) { 141 loaded ? fn() : fns.push(fn); 142 }; 143 144 }(this, document); 145 146 provide("domready", module.exports); 147 148 !function ($) { 149 $.ender({domReady: domReady}); 150 $.ender({ 151 ready: function (f) { 152 domReady(f); 153 return this; 154 } 155 }, true); 156 }(ender); 157 158}(); 159 160!function () { 161 162 var module = { exports: {} }, exports = module.exports; 163 164 /*! 165 * bean.js - copyright Jacob Thornton 2011 166 * https://github.com/fat/bean 167 * MIT License 168 * special thanks to: 169 * dean edwards: http://dean.edwards.name/ 170 * dperini: https://github.com/dperini/nwevents 171 * the entire mootools team: github.com/mootools/mootools-core 172 */ 173 !function (context) { 174 var __uid = 1, registry = {}, collected = {}, 175 overOut = /over|out/, 176 namespace = /[^\.]*(?=\..*)\.|.*/, 177 stripName = /\..*/, 178 addEvent = 'addEventListener', 179 attachEvent = 'attachEvent', 180 removeEvent = 'removeEventListener', 181 detachEvent = 'detachEvent', 182 doc = context.document || {}, 183 root = doc.documentElement || {}, 184 W3C_MODEL = root[addEvent], 185 eventSupport = W3C_MODEL ? addEvent : attachEvent, 186 187 isDescendant = function (parent, child) { 188 var node = child.parentNode; 189 while (node !== null) { 190 if (node == parent) { 191 return true; 192 } 193 node = node.parentNode; 194 } 195 }, 196 197 retrieveUid = function (obj, uid) { 198 return (obj.__uid = uid || obj.__uid || __uid++); 199 }, 200 201 retrieveEvents = function (element) { 202 var uid = retrieveUid(element); 203 return (registry[uid] = registry[uid] || {}); 204 }, 205 206 listener = W3C_MODEL ? function (element, type, fn, add) { 207 element[add ? addEvent : removeEvent](type, fn, false); 208 } : function (element, type, fn, add, custom) { 209 custom && add && (element['_on' + custom] = element['_on' + custom] || 0); 210 element[add ? attachEvent : detachEvent]('on' + type, fn); 211 }, 212 213 nativeHandler = function (element, fn, args) { 214 return function (event) { 215 event = fixEvent(event || ((this.ownerDocument || this.document || this).parentWindow || context).event); 216 return fn.apply(element, [event].concat(args)); 217 }; 218 }, 219 220 customHandler = function (element, fn, type, condition, args) { 221 return function (event) { 222 if (condition ? condition.call(this, event) : W3C_MODEL ? true : event && event.propertyName == '_on' + type || !event) { 223 fn.apply(element, [event].concat(args)); 224 } 225 }; 226 }, 227 228 addListener = function (element, orgType, fn, args) { 229 var type = orgType.replace(stripName, ''), 230 events = retrieveEvents(element), 231 handlers = events[type] || (events[type] = {}), 232 originalFn = fn, 233 uid = retrieveUid(fn, orgType.replace(namespace, '')); 234 if (handlers[uid]) { 235 return element; 236 } 237 var custom = customEvents[type]; 238 if (custom) { 239 fn = custom.condition ? customHandler(element, fn, type, custom.condition) : fn; 240 type = custom.base || type; 241 } 242 var isNative = nativeEvents[type]; 243 fn = isNative ? nativeHandler(element, fn, args) : customHandler(element, fn, type, false, args); 244 isNative = W3C_MODEL || isNative; 245 if (type == 'unload') { 246 var org = fn; 247 fn = function () { 248 removeListener(element, type, fn) && org(); 249 }; 250 } 251 element[eventSupport] && listener(element, isNative ? type : 'propertychange', fn, true, !isNative && type); 252 handlers[uid] = fn; 253 fn.__uid = uid; 254 fn.__originalFn = originalFn; 255 return type == 'unload' ? element : (collected[retrieveUid(element)] = element); 256 }, 257 258 removeListener = function (element, orgType, handler) { 259 var uid, names, uids, i, events = retrieveEvents(element), type = orgType.replace(stripName, ''); 260 if (!events || !events[type]) { 261 return element; 262 } 263 names = orgType.replace(namespace, ''); 264 uids = names ? names.split('.') : [handler.__uid]; 265 for (i = uids.length; i--;) { 266 uid = uids[i]; 267 handler = events[type][uid]; 268 delete events[type][uid]; 269 if (element[eventSupport]) { 270 type = customEvents[type] ? customEvents[type].base : type; 271 var isNative = W3C_MODEL || nativeEvents[type]; 272 listener(element, isNative ? type : 'propertychange', handler, false, !isNative && type); 273 } 274 } 275 return element; 276 }, 277 278 del = function (selector, fn, $) { 279 return function (e) { 280 var array = typeof selector == 'string' ? $(selector, this) : selector; 281 for (var target = e.target; target && target != this; target = target.parentNode) { 282 for (var i = array.length; i--;) { 283 if (array[i] == target) { 284 return fn.apply(target, arguments); 285 } 286 } 287 } 288 }; 289 }, 290 291 add = function (element, events, fn, delfn, $) { 292 if (typeof events == 'object' && !fn) { 293 for (var type in events) { 294 events.hasOwnProperty(type) && add(element, type, events[type]); 295 } 296 } else { 297 var isDel = typeof fn == 'string', types = (isDel ? fn : events).split(' '); 298 fn = isDel ? del(events, delfn, $) : fn; 299 for (var i = types.length; i--;) { 300 addListener(element, types[i], fn, Array.prototype.slice.call(arguments, isDel ? 4 : 3)); 301 } 302 } 303 return element; 304 }, 305 306 remove = function (element, orgEvents, fn) { 307 var k, type, events, i, 308 isString = typeof(orgEvents) == 'string', 309 names = isString && orgEvents.replace(namespace, ''), 310 rm = removeListener, 311 attached = retrieveEvents(element); 312 if (isString && /\s/.test(orgEvents)) { 313 orgEvents = orgEvents.split(' '); 314 i = orgEvents.length - 1; 315 while (remove(element, orgEvents[i]) && i--) {} 316 return element; 317 } 318 events = isString ? orgEvents.replace(stripName, '') : orgEvents; 319 if (!attached || (isString && !attached[events])) { 320 return element; 321 } 322 if (typeof fn == 'function') { 323 rm(element, events, fn); 324 } else if (names) { 325 rm(element, orgEvents); 326 } else { 327 rm = events ? rm : remove; 328 type = isString && events; 329 events = events ? (fn || attached[events] || events) : attached; 330 for (k in events) { 331 if (events.hasOwnProperty(k)) { 332 rm(element, type || k, events[k]); 333 delete events[k]; // remove unused leaf keys 334 } 335 } 336 } 337 return element; 338 }, 339 340 fire = function (element, type, args) { 341 var evt, k, i, types = type.split(' '); 342 for (i = types.length; i--;) { 343 type = types[i].replace(stripName, ''); 344 var isNative = nativeEvents[type], 345 isNamespace = types[i].replace(namespace, ''), 346 handlers = retrieveEvents(element)[type]; 347 if (isNamespace) { 348 isNamespace = isNamespace.split('.'); 349 for (k = isNamespace.length; k--;) { 350 handlers[isNamespace[k]] && handlers[isNamespace[k]].apply(element, args); 351 } 352 } else if (!args && element[eventSupport]) { 353 fireListener(isNative, type, element); 354 } else { 355 for (k in handlers) { 356 handlers.hasOwnProperty(k) && handlers[k].apply(element, args); 357 } 358 } 359 } 360 return element; 361 }, 362 363 fireListener = W3C_MODEL ? function (isNative, type, element) { 364 evt = document.createEvent(isNative ? "HTMLEvents" : "UIEvents"); 365 evt[isNative ? 'initEvent' : 'initUIEvent'](type, true, true, context, 1); 366 element.dispatchEvent(evt); 367 } : function (isNative, type, element) { 368 isNative ? element.fireEvent('on' + type, document.createEventObject()) : element['_on' + type]++; 369 }, 370 371 clone = function (element, from, type) { 372 var events = retrieveEvents(from), obj, k; 373 var uid = retrieveUid(element); 374 obj = type ? events[type] : events; 375 for (k in obj) { 376 obj.hasOwnProperty(k) && (type ? add : clone)(element, type || from, type ? obj[k].__originalFn : k); 377 } 378 return element; 379 }, 380 381 fixEvent = function (e) { 382 var result = {}; 383 if (!e) { 384 return result; 385 } 386 var type = e.type, target = e.target || e.srcElement; 387 result.preventDefault = fixEvent.preventDefault(e); 388 result.stopPropagation = fixEvent.stopPropagation(e); 389 result.target = target && target.nodeType == 3 ? target.parentNode : target; 390 if (~type.indexOf('key')) { 391 result.keyCode = e.which || e.keyCode; 392 } else if ((/click|mouse|menu/i).test(type)) { 393 result.rightClick = e.which == 3 || e.button == 2; 394 result.pos = { x: 0, y: 0 }; 395 if (e.pageX || e.pageY) { 396 result.clientX = e.pageX; 397 result.clientY = e.pageY; 398 } else if (e.clientX || e.clientY) { 399 result.clientX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; 400 result.clientY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; 401 } 402 overOut.test(type) && (result.relatedTarget = e.relatedTarget || e[(type == 'mouseover' ? 'from' : 'to') + 'Element']); 403 } 404 for (var k in e) { 405 if (!(k in result)) { 406 result[k] = e[k]; 407 } 408 } 409 return result; 410 }; 411 412 fixEvent.preventDefault = function (e) { 413 return function () { 414 if (e.preventDefault) { 415 e.preventDefault(); 416 } 417 else { 418 e.returnValue = false; 419 } 420 }; 421 }; 422 423 fixEvent.stopPropagation = function (e) { 424 return function () { 425 if (e.stopPropagation) { 426 e.stopPropagation(); 427 } else { 428 e.cancelBubble = true; 429 } 430 }; 431 }; 432 433 var nativeEvents = { click: 1, dblclick: 1, mouseup: 1, mousedown: 1, contextmenu: 1, //mouse buttons 434 mousewheel: 1, DOMMouseScroll: 1, //mouse wheel 435 mouseover: 1, mouseout: 1, mousemove: 1, selectstart: 1, selectend: 1, //mouse movement 436 keydown: 1, keypress: 1, keyup: 1, //keyboard 437 orientationchange: 1, // mobile 438 touchstart: 1, touchmove: 1, touchend: 1, touchcancel: 1, // touch 439 gesturestart: 1, gesturechange: 1, gestureend: 1, // gesture 440 focus: 1, blur: 1, change: 1, reset: 1, select: 1, submit: 1, //form elements 441 load: 1, unload: 1, beforeunload: 1, resize: 1, move: 1, DOMContentLoaded: 1, readystatechange: 1, //window 442 error: 1, abort: 1, scroll: 1 }; //misc 443 444 function check(event) { 445 var related = event.relatedTarget; 446 if (!related) { 447 return related === null; 448 } 449 return (related != this && related.prefix != 'xul' && !/document/.test(this.toString()) && !isDescendant(this, related)); 450 } 451 452 var customEvents = { 453 mouseenter: { base: 'mouseover', condition: check }, 454 mouseleave: { base: 'mouseout', condition: check }, 455 mousewheel: { base: /Firefox/.test(navigator.userAgent) ? 'DOMMouseScroll' : 'mousewheel' } 456 }; 457 458 var bean = { add: add, remove: remove, clone: clone, fire: fire }; 459 460 var clean = function (el) { 461 var uid = remove(el).__uid; 462 if (uid) { 463 delete collected[uid]; 464 delete registry[uid]; 465 } 466 }; 467 468 if (context[attachEvent]) { 469 add(context, 'unload', function () { 470 for (var k in collected) { 471 collected.hasOwnProperty(k) && clean(collected[k]); 472 } 473 context.CollectGarbage && CollectGarbage(); 474 }); 475 } 476 477 var oldBean = context.bean; 478 bean.noConflict = function () { 479 context.bean = oldBean; 480 return this; 481 }; 482 483 (typeof module !== 'undefined' && module.exports) ? 484 (module.exports = bean) : 485 (context['bean'] = bean); 486 487 }(this); 488 489 provide("bean", module.exports); 490 491 !function ($) { 492 var b = require('bean'), 493 integrate = function (method, type, method2) { 494 var _args = type ? [type] : []; 495 return function () { 496 for (var args, i = 0, l = this.length; i < l; i++) { 497 args = [this[i]].concat(_args, Array.prototype.slice.call(arguments, 0)); 498 args.length == 4 && args.push($); 499 !arguments.length && method == 'add' && type && (method = 'fire'); 500 b[method].apply(this, args); 501 } 502 return this; 503 }; 504 }; 505 506 var add = integrate('add'), 507 remove = integrate('remove'), 508 fire = integrate('fire'); 509 510 var methods = { 511 512 on: add, 513 addListener: add, 514 bind: add, 515 listen: add, 516 delegate: add, 517 518 unbind: remove, 519 unlisten: remove, 520 removeListener: remove, 521 undelegate: remove, 522 523 emit: fire, 524 trigger: fire, 525 526 cloneEvents: integrate('clone'), 527 528 hover: function (enter, leave, i) { // i for internal 529 for (i = this.length; i--;) { 530 b.add.call(this, this[i], 'mouseenter', enter); 531 b.add.call(this, this[i], 'mouseleave', leave); 532 } 533 return this; 534 } 535 }; 536 537 var i, shortcuts = [ 538 'blur', 'change', 'click', 'dblclick', 'error', 'focus', 'focusin', 539 'focusout', 'keydown', 'keypress', 'keyup', 'load', 'mousedown', 540 'mouseenter', 'mouseleave', 'mouseout', 'mouseover', 'mouseup', 'mousemove', 541 'resize', 'scroll', 'select', 'submit', 'unload' 542 ]; 543 544 for (i = shortcuts.length; i--;) { 545 methods[shortcuts[i]] = integrate('add', shortcuts[i]); 546 } 547 548 $.ender(methods, true); 549 }(ender); 550 551}(); 552 553!function () { 554 555 var module = { exports: {} }, exports = module.exports; 556 557 /*! 558 * bonzo.js - copyright @dedfat 2011 559 * https://github.com/ded/bonzo 560 * Follow our software http://twitter.com/dedfat 561 * MIT License 562 */ 563 !function (context, win) { 564 565 var doc = context.document, 566 html = doc.documentElement, 567 parentNode = 'parentNode', 568 query = null, 569 byTag = 'getElementsByTagName', 570 specialAttributes = /^checked|value|selected$/, 571 specialTags = /select|fieldset|table|tbody|tfoot|td|tr|colgroup/i, 572 table = 'table', 573 tagMap = { thead: table, tbody: table, tfoot: table, tr: 'tbody', th: 'tr', td: 'tr', fieldset: 'form', option: 'select' }, 574 stateAttributes = /^checked|selected$/, 575 ie = /msie/i.test(navigator.userAgent), 576 uidList = [], 577 uuids = 0, 578 digit = /^-?[\d\.]+$/, 579 px = 'px', 580 // commonly used methods 581 setAttribute = 'setAttribute', 582 getAttribute = 'getAttribute', 583 trimReplace = /(^\s*|\s*$)/g, 584 unitless = { lineHeight: 1, zoom: 1, zIndex: 1, opacity: 1 }; 585 586 function classReg(c) { 587 return new RegExp("(^|\\s+)" + c + "(\\s+|$)"); 588 } 589 590 function each(ar, fn, scope) { 591 for (var i = 0, l = ar.length; i < l; i++) { 592 fn.call(scope || ar[i], ar[i], i, ar); 593 } 594 return ar; 595 } 596 597 var trim = String.prototype.trim ? 598 function (s) { 599 return s.trim(); 600 } : 601 function (s) { 602 return s.replace(trimReplace, ''); 603 }; 604 605 function camelize(s) { 606 return s.replace(/-(.)/g, function (m, m1) { 607 return m1.toUpperCase(); 608 }); 609 } 610 611 function is(node) { 612 return node && node.nodeName && node.nodeType == 1; 613 } 614 615 function some(ar, fn, scope) { 616 for (var i = 0, j = ar.length; i < j; ++i) { 617 if (fn.call(scope, ar[i], i, ar)) { 618 return true; 619 } 620 } 621 return false; 622 } 623 624 var getStyle = doc.defaultView && doc.defaultView.getComputedStyle ? 625 function (el, property) { 626 var value = null; 627 if (property == 'float') { 628 property = 'cssFloat'; 629 } 630 var computed = doc.defaultView.getComputedStyle(el, ''); 631 computed && (value = computed[camelize(property)]); 632 return el.style[property] || value; 633 634 } : (ie && html.currentStyle) ? 635 636 function (el, property) { 637 property = camelize(property); 638 property = property == 'float' ? 'styleFloat' : property; 639 640 if (property == 'opacity') { 641 var val = 100; 642 try { 643 val = el.filters['DXImageTransform.Microsoft.Alpha'].opacity; 644 } catch (e1) { 645 try { 646 val = el.filters('alpha').opacity; 647 } catch (e2) {} 648 } 649 return val / 100; 650 } 651 var value = el.currentStyle ? el.currentStyle[property] : null; 652 return el.style[property] || value; 653 } : 654 655 function (el, property) { 656 return el.style[camelize(property)]; 657 }; 658 659 function insert(target, host, fn) { 660 var i = 0, self = host || this, r = [], 661 nodes = query && typeof target == 'string' && target.charAt(0) != '<' ? function (n) { 662 return (n = query(target)) && (n.selected = 1) && n; 663 }() : target; 664 each(normalize(nodes), function (t) { 665 each(self, function (el) { 666 var n = !el[parentNode] || (el[parentNode] && !el[parentNode][parentNode]) ? 667 function () { 668 var c = el.cloneNode(true); 669 self.$ && self.cloneEvents && self.$(c).cloneEvents(el); 670 return c; 671 }() : 672 el; 673 fn(t, n); 674 r[i] = n; 675 i++; 676 }); 677 }, this); 678 each(r, function (e, i) { 679 self[i] = e; 680 }); 681 self.length = i; 682 return self; 683 } 684 685 function xy(el, x, y) { 686 var $el = bonzo(el), 687 style = $el.css('position'), 688 offset = $el.offset(), 689 rel = 'relative', 690 isRel = style == rel, 691 delta = [parseInt($el.css('left'), 10), parseInt($el.css('top'), 10)]; 692 693 if (style == 'static') { 694 $el.css('position', rel); 695 style = rel; 696 } 697 698 isNaN(delta[0]) && (delta[0] = isRel ? 0 : el.offsetLeft); 699 isNaN(delta[1]) && (delta[1] = isRel ? 0 : el.offsetTop); 700 701 x !== null && (el.style.left = x - offset.left + delta[0] + 'px'); 702 y !== null && (el.style.top = y - offset.top + delta[1] + 'px'); 703 704 } 705 706 function Bonzo(elements) { 707 this.length = 0; 708 if (elements) { 709 elements = typeof elements !== 'string' && 710 !elements.nodeType && 711 typeof elements.length !== 'undefined' ? 712 elements : 713 [elements]; 714 this.length = elements.length; 715 for (var i = 0; i < elements.length; i++) { 716 this[i] = elements[i]; 717 } 718 } 719 } 720 721 Bonzo.prototype = { 722 723 each: function (fn, scope) { 724 return each(this, fn, scope); 725 }, 726 727 map: function (fn, reject) { 728 var m = [], n, i; 729 for (i = 0; i < this.length; i++) { 730 n = fn.call(this, this[i]); 731 reject ? (reject(n) && m.push(n)) : m.push(n); 732 } 733 return m; 734 }, 735 736 first: function () { 737 return bonzo(this[0]); 738 }, 739 740 last: function () { 741 return bonzo(this[this.length - 1]); 742 }, 743 744 html: function (h, text) { 745 var method = text ? 746 html.textContent == null ? 747 'innerText' : 748 'textContent' : 749 'innerHTML', m; 750 function append(el) { 751 while (el.firstChild) { 752 el.removeChild(el.firstChild); 753 } 754 each(normalize(h), function (node) { 755 el.appendChild(node); 756 }); 757 } 758 return typeof h !== 'undefined' ? 759 this.each(function (el) { 760 (m = el.tagName.match(specialTags)) ? 761 append(el, m[0]) : 762 (el[method] = h); 763 }) : 764 this[0] ? this[0][method] : ''; 765 }, 766 767 text: function (text) { 768 return this.html(text, 1); 769 }, 770 771 addClass: function (c) { 772 return this.each(function (el) { 773 this.hasClass(el, c) || (el.className = trim(el.className + ' ' + c)); 774 }, this); 775 }, 776 777 removeClass: function (c) { 778 return this.each(function (el) { 779 this.hasClass(el, c) && (el.className = trim(el.className.replace(classReg(c), ' '))); 780 }, this); 781 }, 782 783 hasClass: function (el, c) { 784 return typeof c == 'undefined' ? 785 some(this, function (i) { 786 return classReg(el).test(i.className); 787 }) : 788 classReg(c).test(el.className); 789 }, 790 791 toggleClass: function (c, condition) { 792 if (typeof condition !== 'undefined' && !condition) { 793 return this; 794 } 795 return this.each(function (el) { 796 this.hasClass(el, c) ? 797 (el.className = trim(el.className.replace(classReg(c), ' '))) : 798 (el.className = trim(el.className + ' ' + c)); 799 }, this); 800 }, 801 802 show: function (type) { 803 return this.each(function (el) { 804 el.style.display = type || ''; 805 }); 806 }, 807 808 hide: function (elements) { 809 return this.each(function (el) { 810 el.style.display = 'none'; 811 }); 812 }, 813 814 append: function (node) { 815 return this.each(function (el) { 816 each(normalize(node), function (i) { 817 el.appendChild(i); 818 }); 819 }); 820 }, 821 822 prepend: function (node) { 823 return this.each(function (el) { 824 var first = el.firstChild; 825 each(normalize(node), function (i) { 826 el.insertBefore(i, first); 827 }); 828 }); 829 }, 830 831 appendTo: function (target, host) { 832 return insert.call(this, target, host, function (t, el) { 833 t.appendChild(el); 834 }); 835 }, 836 837 prependTo: function (target, host) { 838 return insert.call(this, target, host, function (t, el) { 839 t.insertBefore(el, t.firstChild); 840 }); 841 }, 842 843 next: function () { 844 return this.related('nextSibling'); 845 }, 846 847 previous: function () { 848 return this.related('previousSibling'); 849 }, 850 851 related: function (method) { 852 return this.map( 853 function (el) { 854 el = el[method]; 855 while (el && el.nodeType !== 1) { 856 el = el[method]; 857 } 858 return el || 0; 859 }, 860 function (el) { 861 return el; 862 } 863 ); 864 }, 865 866 before: function (node) { 867 return this.each(function (el) { 868 each(bonzo.create(node), function (i) { 869 el[parentNode].insertBefore(i, el); 870 }); 871 }); 872 }, 873 874 after: function (node) { 875 return this.each(function (el) { 876 each(bonzo.create(node), function (i) { 877 el[parentNode].insertBefore(i, el.nextSibling); 878 }); 879 }); 880 }, 881 882 insertBefore: function (target, host) { 883 return insert.call(this, target, host, function (t, el) { 884 t[parentNode].insertBefore(el, t); 885 }); 886 }, 887 888 insertAfter: function (target, host) { 889 return insert.call(this, target, host, function (t, el) { 890 var sibling = t.nextSibling; 891 if (sibling) { 892 t[parentNode].insertBefore(el, sibling); 893 } 894 else { 895 t[parentNode].appendChild(el); 896 } 897 }); 898 }, 899 900 css: function (o, v, p) { 901 // is this a request for just getting a style? 902 if (v === undefined && typeof o == 'string') { 903 // repurpose 'v' 904 v = this[0]; 905 if (!v) { 906 return null; 907 } 908 if (v == doc || v == win) { 909 p = (v == doc) ? bonzo.doc() : bonzo.viewport(); 910 return o == 'width' ? p.width : 911 o == 'height' ? p.height : ''; 912 } 913 return getStyle(v, o); 914 } 915 var iter = o; 916 if (typeof o == 'string') { 917 iter = {}; 918 iter[o] = v; 919 } 920 921 if (ie && iter.opacity) { 922 // oh this 'ol gamut 923 iter.filter = 'alpha(opacity=' + (iter.opacity * 100) + ')'; 924 // give it layout 925 iter.zoom = o.zoom || 1; 926 delete iter.opacity; 927 } 928 929 if (v = iter['float']) { 930 // float is a reserved style word. w3 uses cssFloat, ie uses styleFloat 931 ie ? (iter.styleFloat = v) : (iter.cssFloat = v); 932 delete iter['float']; 933 } 934 935 var fn = function (el, p, v) { 936 for (var k in iter) { 937 if (iter.hasOwnProperty(k)) { 938 v = iter[k]; 939 // change "5" to "5px" - unless you're line-height, which is allowed 940 (p = camelize(k)) && digit.test(v) && !(p in unitless) && (v += px); 941 el.style[p] = v; 942 } 943 } 944 }; 945 return this.each(fn); 946 }, 947 948 offset: function (x, y) { 949 if (x || y) { 950 return this.each(function (el) { 951 xy(el, x, y); 952 }); 953 } 954 var el = this[0]; 955 var width = el.offsetWidth; 956 var height = el.offsetHeight; 957 var top = el.offsetTop; 958 var left = el.offsetLeft; 959 while (el = el.offsetParent) { 960 top = top + el.offsetTop; 961 left = left + el.offsetLeft; 962 } 963 964 return { 965 top: top, 966 left: left, 967 height: height, 968 width: width 969 }; 970 }, 971 972 attr: function (k, v) { 973 var el = this[0]; 974 return typeof v == 'undefined' ? 975 specialAttributes.test(k) ? 976 stateAttributes.test(k) && typeof el[k] == 'string' ? 977 true : el[k] : el[getAttribute](k) : 978 this.each(function (el) { 979 k == 'value' ? (el.value = v) : el[setAttribute](k, v); 980 }); 981 }, 982 983 val: function (s) { 984 return (typeof s == 'string') ? this.attr('value', s) : this[0].value; 985 }, 986 987 removeAttr: function (k) { 988 return this.each(function (el) { 989 el.removeAttribute(k); 990 }); 991 }, 992 993 data: function (k, v) { 994 var el = this[0]; 995 if (typeof v === 'undefined') { 996 el[getAttribute]('data-node-uid') || el[setAttribute]('data-node-uid', ++uuids); 997 var uid = el[getAttribute]('data-node-uid'); 998 uidList[uid] || (uidList[uid] = {}); 999 return uidList[uid][k]; 1000 } else { 1001 return this.each(function (el) { 1002 el[getAttribute]('data-node-uid') || el[setAttribute]('data-node-uid', ++uuids); 1003 var uid = el[getAttribute]('data-node-uid'); 1004 var o = {}; 1005 o[k] = v; 1006 uidList[uid] = o; 1007 }); 1008 } 1009 }, 1010 1011 remove: function () { 1012 return this.each(function (el) { 1013 el[parentNode] && el[parentNode].removeChild(el); 1014 }); 1015 }, 1016 1017 empty: function () { 1018 return this.each(function (el) { 1019 while (el.firstChild) { 1020 el.removeChild(el.firstChild); 1021 } 1022 }); 1023 }, 1024 1025 detach: function () { 1026 return this.map(function (el) { 1027 return el[parentNode].removeChild(el); 1028 }); 1029 }, 1030 1031 scrollTop: function (y) { 1032 return scroll.call(this, null, y, 'y'); 1033 }, 1034 1035 scrollLeft: function (x) { 1036 return scroll.call(this, x, null, 'x'); 1037 } 1038 }; 1039 1040 function normalize(node) { 1041 return typeof node == 'string' ? bonzo.create(node) : is(node) ? [node] : node; // assume [nodes] 1042 } 1043 1044 function scroll(x, y, type) { 1045 var el = this[0]; 1046 if (x == null && y == null) { 1047 return (isBody(el) ? getWindowScroll() : { x: el.scrollLeft, y: el.scrollTop })[type]; 1048 } 1049 if (isBody(el)) { 1050 win.scrollTo(x, y); 1051 } else { 1052 x != null && (el.scrollLeft = x); 1053 y != null && (el.scrollTop = y); 1054 } 1055 return this; 1056 } 1057 1058 function isBody(element) { 1059 return element === win || (/^(?:body|html)$/i).test(element.tagName); 1060 } 1061 1062 function getWindowScroll() { 1063 return { x: win.pageXOffset || html.scrollLeft, y: win.pageYOffset || html.scrollTop }; 1064 } 1065 1066 function bonzo(els, host) { 1067 return new Bonzo(els, host); 1068 } 1069 1070 bonzo.setQueryEngine = function (q) { 1071 query = q; 1072 delete bonzo.setQueryEngine; 1073 }; 1074 1075 bonzo.aug = function (o, target) { 1076 for (var k in o) { 1077 o.hasOwnProperty(k) && ((target || Bonzo.prototype)[k] = o[k]); 1078 } 1079 }; 1080 1081 bonzo.create = function (node) { 1082 return typeof node == 'string' ? 1083 function () { 1084 var tag = /^<([^\s>]+)/.exec(node); 1085 var el = doc.createElement(tag && tagMap[tag[1].toLowerCase()] || 'div'), els = []; 1086 el.innerHTML = node; 1087 var nodes = el.childNodes; 1088 el = el.firstChild; 1089 els.push(el); 1090 while (el = el.nextSibling) { 1091 (el.nodeType == 1) && els.push(el); 1092 } 1093 return els; 1094 1095 }() : is(node) ? [node.cloneNode(true)] : []; 1096 }; 1097 1098 bonzo.doc = function () { 1099 var w = html.scrollWidth, 1100 h = html.scrollHeight, 1101 vp = this.viewport(); 1102 return { 1103 width: Math.max(w, vp.width), 1104 height: Math.max(h, vp.height) 1105 }; 1106 }; 1107 1108 bonzo.firstChild = function (el) { 1109 for (var c = el.childNodes, i = 0, j = (c && c.length) || 0, e; i < j; i++) { 1110 if (c[i].nodeType === 1) { 1111 e = c[j = i]; 1112 } 1113 } 1114 return e; 1115 }; 1116 1117 bonzo.viewport = function () { 1118 var h = self.innerHeight, 1119 w = self.innerWidth; 1120 if (ie) { 1121 h = html.clientHeight; 1122 w = html.clientWidth; 1123 } 1124 return { 1125 width: w, 1126 height: h 1127 }; 1128 }; 1129 1130 bonzo.isAncestor = 'compareDocumentPosition' in html ? 1131 function (container, element) { 1132 return (container.compareDocumentPosition(element) & 16) == 16; 1133 } : 'contains' in html ? 1134 function (container, element) { 1135 return container !== element && container.contains(element); 1136 } : 1137 function (container, element) { 1138 while (element = element[parentNode]) { 1139 if (element === container) { 1140 return true; 1141 } 1142 } 1143 return false; 1144 }; 1145 1146 var old = context.bonzo; 1147 bonzo.noConflict = function () { 1148 context.bonzo = old; 1149 return this; 1150 }; 1151 context['bonzo'] = bonzo; 1152 1153 }(this, window); 1154 1155 provide("bonzo", module.exports); 1156 1157 !function ($) { 1158 1159 var b = bonzo; 1160 b.setQueryEngine($); 1161 $.ender(b); 1162 $.ender(b(), true); 1163 $.ender({ 1164 create: function (node) { 1165 return $(b.create(node)); 1166 } 1167 }); 1168 1169 $.id = function (id) { 1170 return $([document.getElementById(id)]); 1171 }; 1172 1173 function indexOf(ar, val) { 1174 for (var i = 0; i < ar.length; i++) { 1175 if (ar[i] === val) { 1176 return i; 1177 } 1178 } 1179 return -1; 1180 } 1181 1182 function uniq(ar) { 1183 var a = [], i, j; 1184 label: 1185 for (i = 0; i < ar.length; i++) { 1186 for (j = 0; j < a.length; j++) { 1187 if (a[j] == ar[i]) { 1188 continue label; 1189 } 1190 } 1191 a[a.length] = ar[i]; 1192 } 1193 return a; 1194 } 1195 1196 $.ender({ 1197 parents: function (selector, closest) { 1198 var collection = $(selector), j, k, p, r = []; 1199 for (j = 0, k = this.length; j < k; j++) { 1200 p = this[j]; 1201 while (p = p.parentNode) { 1202 if (indexOf(collection, p) !== -1) { 1203 r.push(p); 1204 if (closest) break; 1205 } 1206 } 1207 } 1208 return $(uniq(r)); 1209 }, 1210 1211 closest: function (selector) { 1212 return this.parents(selector, true); 1213 }, 1214 1215 first: function () { 1216 return $(this[0]); 1217 }, 1218 1219 last: function () { 1220 return $(this[this.length - 1]); 1221 }, 1222 1223 next: function () { 1224 return $(b(this).next()); 1225 }, 1226 1227 previous: function () { 1228 return $(b(this).previous()); 1229 }, 1230 1231 appendTo: function (t) { 1232 return b(this.selector).appendTo(t, this); 1233 }, 1234 1235 prependTo: function (t) { 1236 return b(this.selector).prependTo(t, this); 1237 }, 1238 1239 insertAfter: function (t) { 1240 return b(this.selector).insertAfter(t, this); 1241 }, 1242 1243 insertBefore: function (t) { 1244 return b(this.selector).insertBefore(t, this); 1245 }, 1246 1247 siblings: function () { 1248 var i, l, p, r = []; 1249 for (i = 0, l = this.length; i < l; i++) { 1250 p = this[i]; 1251 while (p = p.previousSibling) { 1252 p.nodeType == 1 && r.push(p); 1253 } 1254 p = this[i]; 1255 while (p = p.nextSibling) { 1256 p.nodeType == 1 && r.push(p); 1257 } 1258 } 1259 return $(r); 1260 }, 1261 1262 children: function () { 1263 var i, el, r = []; 1264 for (i = 0, l = this.length; i < l; i++) { 1265 if (!(el = b.firstChild(this[i]))) { 1266 continue; 1267 } 1268 r.push(el); 1269 while (el = el.nextSibling) { 1270 el.nodeType == 1 && r.push(el); 1271 } 1272 } 1273 return $(uniq(r)); 1274 }, 1275 1276 height: function (v) { 1277 return dimension(v, this, 'height') 1278 }, 1279 1280 width: function (v) { 1281 return dimension(v, this, 'width') 1282 } 1283 }, true); 1284 1285 function dimension(v, self, which) { 1286 return v ? 1287 self.css(which, v) : 1288 function (r) { 1289 r = parseInt(self.css(which), 10); 1290 return isNaN(r) ? self[0]['offset' + which.replace(/^\w/, function (m) {return m.toUpperCase()})] : r 1291 }() 1292 } 1293 1294 }(ender || $); 1295 1296 1297}(); 1298 1299!function () { 1300 1301 var module = { exports: {} }, exports = module.exports; 1302 1303 /*! 1304 * Qwery - A Blazing Fast query selector engine 1305 * https://github.com/ded/qwery 1306 * copyright Dustin Diaz & Jacob Thornton 2011 1307 * MIT License 1308 */ 1309 1310 !function (context, doc) { 1311 1312 var c, i, j, k, l, m, o, p, r, v, 1313 el, node, len, found, classes, item, items, token, 1314 html = doc.documentElement, 1315 id = /#([\w\-]+)/, 1316 clas = /\.[\w\-]+/g, 1317 idOnly = /^#([\w\-]+$)/, 1318 classOnly = /^\.([\w\-]+)$/, 1319 tagOnly = /^([\w\-]+)$/, 1320 tagAndOrClass = /^([\w]+)?\.([\w\-]+)$/, 1321 normalizr = /\s*([\s\+\~>])\s*/g, 1322 splitters = /[\s\>\+\~]/, 1323 splittersMore = /(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\])/, 1324 dividers = new RegExp('(' + splitters.source + ')' + splittersMore.source, 'g'), 1325 tokenizr = new RegExp(splitters.source + splittersMore.source), 1326 specialChars = /([.*+?\^=!:${}()|\[\]\/\\])/g, 1327 simple = /^([a-z0-9]+)?(?:([\.\#]+[\w\-\.#]+)?)/, 1328 attr = /\[([\w\-]+)(?:([\|\^\$\*\~]?\=)['"]?([ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+)["']?)?\]/, 1329 pseudo = /:([\w\-]+)(\(['"]?(\w+)['"]?\))?/, 1330 chunker = new RegExp(simple.source + '(' + attr.source + ')?' + '(' + pseudo.source + ')?'), 1331 walker = { 1332 ' ': function (node) { 1333 return node && node !== html && node.parentNode 1334 }, 1335 '>': function (node, contestant) { 1336 return node && node.parentNode == contestant.parentNode && node.parentNode; 1337 }, 1338 '~': function (node) { 1339 return node && node.previousSibling; 1340 }, 1341 '+': function (node, contestant, p1, p2) { 1342 if (!node) { 1343 return false; 1344 } 1345 p1 = previous(node); 1346 p2 = previous(contestant); 1347 return p1 && p2 && p1 == p2 && p1; 1348 } 1349 }; 1350 function cache() { 1351 this.c = {}; 1352 } 1353 cache.prototype = { 1354 g: function (k) { 1355 return this.c[k] || undefined; 1356 }, 1357 s: function (k, v) { 1358 this.c[k] = v; 1359 return v; 1360 } 1361 }; 1362 1363 var classCache = new cache(), 1364 cleanCache = new cache(), 1365 attrCache = new cache(), 1366 tokenCache = new cache(); 1367 1368 function array(ar) { 1369 r = []; 1370 for (i = 0, len = ar.length; i < len; i++) { 1371 r[i] = ar[i]; 1372 } 1373 return r; 1374 } 1375 1376 function previous(n) { 1377 while (n = n.previousSibling) { 1378 if (n.nodeType == 1) { 1379 break; 1380 } 1381 } 1382 return n 1383 } 1384 1385 function q(query) { 1386 return query.match(chunker); 1387 } 1388 1389 // this next method expect at most these args 1390 // given => div.hello[title="world"]:foo('bar') 1391 1392 // div.hello[title="world"]:foo('bar'), div, .hello, [title="world"], title, =, world, :foo('bar'), foo, ('bar'), bar] 1393 1394 function interpret(whole, tag, idsAndClasses, wholeAttribute, attribute, qualifier, value, wholePseudo, pseudo, wholePseudoVal, pseudoVal) { 1395 var m, c, k; 1396 if (tag && this.tagName.toLowerCase() !== tag) { 1397 return false; 1398 } 1399 if (idsAndClasses && (m = idsAndClasses.match(id)) && m[1] !== this.id) { 1400 return false; 1401 } 1402 if (idsAndClasses && (classes = idsAndClasses.match(clas))) { 1403 for (i = classes.length; i--;) { 1404 c = classes[i].slice(1); 1405 if (!(classCache.g(c) || classCache.s(c, new RegExp('(^|\\s+)' + c + '(\\s+|$)'))).test(this.className)) { 1406 return false; 1407 } 1408 } 1409 } 1410 if (pseudo && qwery.pseudos[pseudo] && !qwery.pseudos[pseudo](this, pseudoVal)) { 1411 return false; 1412 } 1413 if (wholeAttribute && !value) { 1414 o = this.attributes; 1415 for (k in o) { 1416 if (Object.prototype.hasOwnProperty.call(o, k) && (o[k].name || k) == attribute) { 1417 return this; 1418 } 1419 } 1420 } 1421 if (wholeAttribute && !checkAttr(qualifier, this.getAttribute(attribute) || '', value)) { 1422 return false; 1423 } 1424 return this; 1425 } 1426 1427 function clean(s) { 1428 return cleanCache.g(s) || cleanCache.s(s, s.replace(specialChars, '\\$1')); 1429 } 1430 1431 function checkAttr(qualify, actual, val) { 1432 switch (qualify) { 1433 case '=': 1434 return actual == val; 1435 case '^=': 1436 return actual.match(attrCache.g('^=' + val) || attrCache.s('^=' + val, new RegExp('^' + clean(val)))); 1437 case '$=': 1438 return actual.match(attrCache.g('$=' + val) || attrCache.s('$=' + val, new RegExp(clean(val) + '$'))); 1439 case '*=': 1440 return actual.match(attrCache.g(val) || attrCache.s(val, new RegExp(clean(val)))); 1441 case '~=': 1442 return actual.match(attrCache.g('~=' + val) || attrCache.s('~=' + val, new RegExp('(?:^|\\s+)' + clean(val) + '(?:\\s+|$)'))); 1443 case '|=': 1444 return actual.match(attrCache.g('|=' + val) || attrCache.s('|=' + val, new RegExp('^' + clean(val) + '(-|$)'))); 1445 } 1446 return 0; 1447 } 1448 1449 function _qwery(selector) { 1450 var r = [], ret = [], i, j = 0, k, l, m, p, token, tag, els, root, intr, item, children, 1451 tokens = tokenCache.g(selector) || tokenCache.s(selector, selector.split(tokenizr)), 1452 dividedTokens = selector.match(dividers), dividedToken; 1453 tokens = tokens.slice(0); // this makes a copy of the array so the cached original is not effected 1454 if (!tokens.length) { 1455 return r; 1456 } 1457 1458 token = tokens.pop(); 1459 root = tokens.length && (m = tokens[tokens.length - 1].match(idOnly)) ? doc.getElementById(m[1]) : doc; 1460 if (!root) { 1461 return r; 1462 } 1463 intr = q(token); 1464 els = dividedTokens && /^[+~]$/.test(dividedTokens[dividedTokens.length - 1]) ? function (r) { 1465 while (root = root.nextSibling) { 1466 root.nodeType == 1 && (intr[1] ? intr[1] == root.tagName.toLowerCase() : 1) && r.push(root) 1467 } 1468 return r 1469 }([]) : 1470 root.getElementsByTagName(intr[1] || '*'); 1471 for (i = 0, l = els.length; i < l; i++) { 1472 if (item = interpret.apply(els[i], intr)) { 1473 r[j++] = item; 1474 } 1475 } 1476 if (!tokens.length) { 1477 return r; 1478 } 1479 1480 // loop through all descendent tokens 1481 for (j = 0, l = r.length, k = 0; j < l; j++) { 1482 p = r[j]; 1483 // loop through each token backwards crawling up tree 1484 for (i = tokens.length; i--;) { 1485 // loop through parent nodes 1486 while (p = walker[dividedTokens[i]](p, r[j])) { 1487 if (found = interpret.apply(p, q(tokens[i]))) { 1488 break; 1489 } 1490 } 1491 } 1492 found && (ret[k++] = r[j]); 1493 } 1494 return ret; 1495 } 1496 1497 function boilerPlate(selector, _root, fn) { 1498 var root = (typeof _root == 'string') ? fn(_root)[0] : (_root || doc); 1499 if (selector === window || isNode(selector)) { 1500 return !_root || (selector !== window && isNode(root) && isAncestor(selector, root)) ? [selector] : []; 1501 } 1502 if (selector && typeof selector === 'object' && isFinite(selector.length)) { 1503 return array(selector); 1504 } 1505 if (m = selector.match(idOnly)) { 1506 return (el = doc.getElementById(m[1])) ? [el] : []; 1507 } 1508 if (m = selector.match(tagOnly)) { 1509 return array(root.getElementsByTagName(m[1])); 1510 } 1511 return false; 1512 } 1513 1514 function isNode(el) { 1515 return (el && el.nodeType && (el.nodeType == 1 || el.nodeType == 9)); 1516 } 1517 1518 function uniq(ar) { 1519 var a = [], i, j; 1520 label: 1521 for (i = 0; i < ar.length; i++) { 1522 for (j = 0; j < a.length; j++) { 1523 if (a[j] == ar[i]) { 1524 continue label; 1525 } 1526 } 1527 a[a.length] = ar[i]; 1528 } 1529 return a; 1530 } 1531 1532 function qwery(selector, _root) { 1533 var root = (typeof _root == 'string') ? qwery(_root)[0] : (_root || doc); 1534 if (!root || !selector) { 1535 return []; 1536 } 1537 if (m = boilerPlate(selector, _root, qwery)) { 1538 return m; 1539 } 1540 return select(selector, root); 1541 } 1542 1543 var isAncestor = 'compareDocumentPosition' in html ? 1544 function (element, container) { 1545 return (container.compareDocumentPosition(element) & 16) == 16; 1546 } : 'contains' in html ? 1547 function (element, container) { 1548 container = container == doc || container == window ? html : container; 1549 return container !== element && container.contains(element); 1550 } : 1551 function (element, container) { 1552 while (element = element.parentNode) { 1553 if (element === container) { 1554 return 1; 1555 } 1556 } 1557 return 0; 1558 }, 1559 1560 select = (doc.querySelector && doc.querySelectorAll) ? 1561 function (selector, root) { 1562 if (doc.getElementsByClassName && (m = selector.match(classOnly))) { 1563 return array((root).getElementsByClassName(m[1])); 1564 } 1565 return array((root).querySelectorAll(selector)); 1566 } : 1567 function (selector, root) { 1568 selector = selector.replace(normalizr, '$1'); 1569 var result = [], collection, collections = [], i; 1570 if (m = selector.match(tagAndOrClass)) { 1571 items = root.getElementsByTagName(m[1] || '*'); 1572 r = classCache.g(m[2]) || classCache.s(m[2], new RegExp('(^|\\s+)' + m[2] + '(\\s+|$)')); 1573 for (i = 0, l = items.length, j = 0; i < l; i++) { 1574 r.test(items[i].className) && (result[j++] = items[i]); 1575 } 1576 return result; 1577 } 1578 for (i = 0, items = selector.split(','), l = items.length; i < l; i++) { 1579 collections[i] = _qwery(items[i]); 1580 } 1581 for (i = 0, l = collections.length; i < l && (collection = collections[i]); i++) { 1582 var ret = collection; 1583 if (root !== doc) { 1584 ret = []; 1585 for (j = 0, m = collection.length; j < m && (element = collection[j]); j++) { 1586 // make sure element is a descendent of root 1587 isAncestor(element, root) && ret.push(element); 1588 } 1589 } 1590 result = result.concat(ret); 1591 } 1592 return uniq(result); 1593 }; 1594 1595 qwery.uniq = uniq; 1596 qwery.pseudos = {}; 1597 1598 var oldQwery = context.qwery; 1599 qwery.noConflict = function () { 1600 context.qwery = oldQwery; 1601 return this; 1602 }; 1603 context['qwery'] = qwery; 1604 1605 }(this, document); 1606 1607 provide("qwery", module.exports); 1608 1609 !function (doc) { 1610 var q = qwery.noConflict(); 1611 var table = 'table', 1612 nodeMap = { 1613 thead: table, 1614 tbody: table, 1615 tfoot: table, 1616 tr: 'tbody', 1617 th: 'tr', 1618 td: 'tr', 1619 fieldset: 'form', 1620 option: 'select' 1621 } 1622 function create(node, root) { 1623 var tag = /^<([^\s>]+)/.exec(node)[1] 1624 var el = (root || doc).createElement(nodeMap[tag] || 'div'), els = []; 1625 el.innerHTML = node; 1626 var nodes = el.childNodes; 1627 el = el.firstChild; 1628 els.push(el); 1629 while (el = el.nextSibling) { 1630 (el.nodeType == 1) && els.push(el); 1631 } 1632 return els; 1633 } 1634 $._select = function (s, r) { 1635 return /^\s*</.test(s) ? create(s, r) : q(s, r); 1636 }; 1637 $.pseudos = q.pseudos; 1638 $.ender({ 1639 find: function (s) { 1640 var r = [], i, l, j, k, els; 1641 for (i = 0, l = this.length; i < l; i++) { 1642 els = q(s, this[i]); 1643 for (j = 0, k = els.length; j < k; j++) { 1644 r.push(els[j]); 1645 } 1646 } 1647 return $(q.uniq(r)); 1648 } 1649 , and: function (s) { 1650 var plus = $(s); 1651 for (var i = this.length, j = 0, l = this.length + plus.length; i < l; i++, j++) { 1652 this[i] = plus[j]; 1653 } 1654 return this; 1655 } 1656 }, true); 1657 }(document); 1658 1659}(); 1660 1661!function () { 1662 1663 var module = { exports: {} }, exports = module.exports; 1664 1665 // Underscore.js 1.1.6 1666 // (c) 2011 Jeremy Ashkenas, DocumentCloud Inc. 1667 // Underscore is freely distributable under the MIT license. 1668 // Portions of Underscore are inspired or borrowed from Prototype, 1669 // Oliver Steele's Functional, and John Resig's Micro-Templating. 1670 // For all details and documentation: 1671 // http://documentcloud.github.com/underscore 1672 1673 (function() { 1674 1675 // Baseline setup 1676 // -------------- 1677 1678 // Establish the root object, `window` in the browser, or `global` on the server. 1679 var root = this; 1680 1681 // Save the previous value of the `_` variable. 1682 var previousUnderscore = root._; 1683 1684 // Establish the object that gets returned to break out of a loop iteration. 1685 var breaker = {}; 1686 1687 // Save bytes in the minified (but not gzipped) version: 1688 var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype; 1689 1690 // Create quick reference variables for speed access to core prototypes. 1691 var slice = ArrayProto.slice, 1692 unshift = ArrayProto.unshift, 1693 toString = ObjProto.toString, 1694 hasOwnProperty = ObjProto.hasOwnProperty; 1695 1696 // All **ECMAScript 5** native function implementations that we hope to use 1697 // are declared here. 1698 var 1699 nativeForEach = ArrayProto.forEach, 1700 nativeMap = ArrayProto.map, 1701 nativeReduce = ArrayProto.reduce, 1702 nativeReduceRight = ArrayProto.reduceRight, 1703 nativeFilter = ArrayProto.filter, 1704 nativeEvery = ArrayProto.every, 1705 nativeSome = ArrayProto.some, 1706 nativeIndexOf = ArrayProto.indexOf, 1707 nativeLastIndexOf = ArrayProto.lastIndexOf, 1708 nativeIsArray = Array.isArray, 1709 nativeKeys = Object.keys, 1710 nativeBind = FuncProto.bind; 1711 1712 // Create a safe reference to the Underscore object for use below. 1713 var _ = function(obj) { return new wrapper(obj); }; 1714 1715 // Export the Underscore object for **CommonJS**, with backwards-compatibility 1716 // for the old `require()` API. If we're not in CommonJS, add `_` to the 1717 // global object. 1718 if (typeof module !== 'undefined' && module.exports) { 1719 module.exports = _; 1720 _._ = _; 1721 } else { 1722 root._ = _; 1723 } 1724 1725 // Current version. 1726 _.VERSION = '1.1.6'; 1727 1728 // Collection Functions 1729 // -------------------- 1730 1731 // The cornerstone, an `each` implementation, aka `forEach`. 1732 // Handles objects implementing `forEach`, arrays, and raw objects. 1733 // Delegates to **ECMAScript 5**'s native `forEach` if available. 1734 var each = _.each = _.forEach = function(obj, iterator, context) { 1735 if (obj == null) return; 1736 if (nativeForEach && obj.forEach === nativeForEach) { 1737 obj.forEach(iterator, context); 1738 } else if (_.isNumber(obj.length)) { 1739 for (var i = 0, l = obj.length; i < l; i++) { 1740 if (iterator.call(context, obj[i], i, obj) === breaker) return; 1741 } 1742 } else { 1743 for (var key in obj) { 1744 if (hasOwnProperty.call(obj, key)) { 1745 if (iterator.call(context, obj[key], key, obj) === breaker) return; 1746 } 1747 } 1748 } 1749 }; 1750 1751 // Return the results of applying the iterator to each element. 1752 // Delegates to **ECMAScript 5**'s native `map` if available. 1753 _.map = function(obj, iterator, context) { 1754 var results = []; 1755 if (obj == null) return results; 1756 if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); 1757 each(obj, function(value, index, list) { 1758 results[results.length] = iterator.call(context, value, index, list); 1759 }); 1760 return results; 1761 }; 1762 1763 // **Reduce** builds up a single result from a list of values, aka `inject`, 1764 // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. 1765 _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { 1766 var initial = memo !== void 0; 1767 if (obj == null) obj = []; 1768 if (nativeReduce && obj.reduce === nativeReduce) { 1769 if (context) iterator = _.bind(iterator, context); 1770 return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); 1771 } 1772 each(obj, function(value, index, list) { 1773 if (!initial && index === 0) { 1774 memo = value; 1775 initial = true; 1776 } else { 1777 memo = iterator.call(context, memo, value, index, list); 1778 } 1779 }); 1780 if (!initial) throw new TypeError("Reduce of empty array with no initial value"); 1781 return memo; 1782 }; 1783 1784 // The right-associative version of reduce, also known as `foldr`. 1785 // Delegates to **ECMAScript 5**'s native `reduceRight` if available. 1786 _.reduceRight = _.foldr = function(obj, iterator, memo, context) { 1787 if (obj == null) obj = []; 1788 if (nativeReduceRight && obj.reduceRight === nativeReduceRight) { 1789 if (context) iterator = _.bind(iterator, context); 1790 return memo !== void 0 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); 1791 } 1792 var reversed = (_.isArray(obj) ? obj.slice() : _.toArray(obj)).reverse(); 1793 return _.reduce(reversed, iterator, memo, context); 1794 }; 1795 1796 // Return the first value which passes a truth test. Aliased as `detect`. 1797 _.find = _.detect = function(obj, iterator, context) { 1798 var result; 1799 any(obj, function(value, index, list) { 1800 if (iterator.call(context, value, index, list)) { 1801 result = value; 1802 return true; 1803 } 1804 }); 1805 return result; 1806 }; 1807 1808 // Return all the elements that pass a truth test. 1809 // Delegates to **ECMAScript 5**'s native `filter` if available. 1810 // Aliased as `select`. 1811 _.filter = _.select = function(obj, iterator, context) { 1812 var results = []; 1813 if (obj == null) return results; 1814 if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context); 1815 each(obj, function(value, index, list) { 1816 if (iterator.call(context, value, index, list)) results[results.length] = value; 1817 }); 1818 return results; 1819 }; 1820 1821 // Return all the elements for which a truth test fails. 1822 _.reject = function(obj, iterator, context) { 1823 var results = []; 1824 if (obj == null) return results; 1825 each(obj, function(value, index, list) { 1826 if (!iterator.call(context, value, index, list)) results[results.length] = value; 1827 }); 1828 return results; 1829 }; 1830 1831 // Determine whether all of the elements match a truth test. 1832 // Delegates to **ECMAScript 5**'s native `every` if available. 1833 // Aliased as `all`. 1834 _.every = _.all = function(obj, iterator, context) { 1835 var result = true; 1836 if (obj == null) return result; 1837 if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context); 1838 each(obj, function(value, index, list) { 1839 if (!(result = result && iterator.call(context, value, index, list))) return breaker; 1840 }); 1841 return result; 1842 }; 1843 1844 // Determine if at least one element in the object matches a truth test. 1845 // Delegates to **ECMAScript 5**'s native `some` if available. 1846 // Aliased as `any`. 1847 var any = _.some = _.any = function(obj, iterator, context) { 1848 iterator || (iterator = _.identity); 1849 var result = false; 1850 if (obj == null) return result; 1851 if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); 1852 each(obj, function(value, index, list) { 1853 if (result = iterator.call(context, value, index, list)) return breaker; 1854 }); 1855 return result; 1856 }; 1857 1858 // Determine if a given value is included in the array or object using `===`. 1859 // Aliased as `contains`. 1860 _.include = _.contains = function(obj, target) { 1861 var found = false; 1862 if (obj == null) return found; 1863 if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; 1864 any(obj, function(value) { 1865 if (found = value === target) return true; 1866 }); 1867 return found; 1868 }; 1869 1870 // Invoke a method (with arguments) on every item in a collection. 1871 _.invoke = function(obj, method) { 1872 var args = slice.call(arguments, 2); 1873 return _.map(obj, function(value) { 1874 return (method.call ? method || value : value[method]).apply(value, args); 1875 }); 1876 }; 1877 1878 // Convenience version of a common use case of `map`: fetching a property. 1879 _.pluck = function(obj, key) { 1880 return _.map(obj, function(value){ return value[key]; }); 1881 }; 1882 1883 // Return the maximum element or (element-based computation). 1884 _.max = function(obj, iterator, context) { 1885 if (!iterator && _.isArray(obj)) return Math.max.apply(Math, obj); 1886 var result = {computed : -Infinity}; 1887 each(obj, function(value, index, list) { 1888 var computed = iterator ? iterator.call(context, value, index, list) : value; 1889 computed >= result.computed && (result = {value : value, computed : computed}); 1890 }); 1891 return result.value; 1892 }; 1893 1894 // Return the minimum element (or element-based computation). 1895 _.min = function(obj, iterator, context) { 1896 if (!iterator && _.isArray(obj)) return Math.min.apply(Math, obj); 1897 var result = {computed : Infinity}; 1898 each(obj, function(value, index, list) { 1899 var computed = iterator ? iterator.call(context, value, index, list) : value; 1900 computed < result.computed && (result = {value : value, computed : computed}); 1901 }); 1902 return result.value; 1903 }; 1904 1905 // Sort the object's values by a criterion produced by an iterator. 1906 _.sortBy = function(obj, iterator, context) { 1907 return _.pluck(_.map(obj, function(value, index, list) { 1908 return { 1909 value : value, 1910 criteria : iterator.call(context, value, index, list) 1911 }; 1912 }).sort(function(left, right) { 1913 var a = left.criteria, b = right.criteria; 1914 return a < b ? -1 : a > b ? 1 : 0; 1915 }), 'value'); 1916 }; 1917 1918 // Use a comparator function to figure out at what index an object should 1919 // be inserted so as to maintain order. Uses binary search. 1920 _.sortedIndex = function(array, obj, iterator) { 1921 iterator || (iterator = _.identity); 1922 var low = 0, high = array.length; 1923 while (low < high) { 1924 var mid = (low + high) >> 1; 1925 iterator(array[mid]) < iterator(obj) ? low = mid + 1 : high = mid; 1926 } 1927 return low; 1928 }; 1929 1930 // Safely convert anything iterable into a real, live array. 1931 _.toArray = function(iterable) { 1932 if (!iterable) return []; 1933 if (iterable.toArray) return iterable.toArray(); 1934 if (_.isArray(iterable)) return iterable; 1935 if (_.isArguments(iterable)) return slice.call(iterable); 1936 return _.values(iterable); 1937 }; 1938 1939 // Return the number of elements in an object. 1940 _.size = function(obj) { 1941 return _.toArray(obj).length; 1942 }; 1943 1944 // Array Functions 1945 // --------------- 1946 1947 // Get the first element of an array. Passing **n** will return the first N 1948 // values in the array. Aliased as `head`. The **guard** check allows it to work 1949 // with `_.map`. 1950 _.first = _.head = function(array, n, guard) { 1951 return (n != null) && !guard ? slice.call(array, 0, n) : array[0]; 1952 }; 1953 1954 // Returns everything but the first entry of the array. Aliased as `tail`. 1955 // Especially useful on the arguments object. Passing an **index** will return 1956 // the rest of the values in the array from that index onward. The **guard** 1957 // check allows it to work with `_.map`. 1958 _.rest = _.tail = function(array, index, guard) { 1959 return slice.call(array, (index == null) || guard ? 1 : index); 1960 }; 1961 1962 // Get the last element of an array. 1963 _.last = function(array) { 1964 return array[array.length - 1]; 1965 }; 1966 1967 // Trim out all falsy values from an array. 1968 _.compact = function(array) { 1969 return _.filter(array, function(value){ return !!value; }); 1970 }; 1971 1972 // Return a completely flattened version of an array. 1973 _.flatten = function(array) { 1974 return _.reduce(array, function(memo, value) { 1975 if (_.isArray(value)) return memo.concat(_.flatten(value)); 1976 memo[memo.length] = value; 1977 return memo; 1978 }, []); 1979 }; 1980 1981 // Return a version of the array that does not contain the specified value(s). 1982 _.without = function(array) { 1983 var values = slice.call(arguments, 1); 1984 return _.filter(array, function(value){ return !_.include(values, value); }); 1985 }; 1986 1987 // Produce a duplicate-free version of the array. If the array has already 1988 // been sorted, you have the option of using a faster algorithm. 1989 // Aliased as `unique`. 1990 _.uniq = _.unique = function(array, isSorted) { 1991 return _.reduce(array, function(memo, el, i) { 1992 if (0 == i || (isSorted === true ? _.last(memo) != el : !_.include(memo, el))) memo[memo.length] = el; 1993 return memo; 1994 }, []); 1995 }; 1996 1997 // Produce an array that contains every item shared between all the 1998 // passed-in arrays. 1999 _.intersect = function(array) { 2000 var rest = slice.call(arguments, 1); 2001 return _.filter(_.uniq(array), function(item) { 2002 return _.every(rest, function(other) { 2003 return _.indexOf(other, item) >= 0; 2004 }); 2005 }); 2006 }; 2007 2008 // Zip together multiple lists into a single array -- elements that share 2009 // an index go together. 2010 _.zip = function() { 2011 var args = slice.call(arguments); 2012 var length = _.max(_.pluck(args, 'length')); 2013 var results = new Array(length); 2014 for (var i = 0; i < length; i++) results[i] = _.pluck(args, "" + i); 2015 return results; 2016 }; 2017 2018 // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**), 2019 // we need this function. Return the position of the first occurrence of an 2020 // item in an array, or -1 if the item is not included in the array. 2021 // Delegates to **ECMAScript 5**'s native `indexOf` if available. 2022 // If the array is large and already in sort order, pass `true` 2023 // for **isSorted** to use binary search. 2024 _.indexOf = function(array, item, isSorted) { 2025 if (array == null) return -1; 2026 var i, l; 2027 if (isSorted) { 2028 i = _.sortedIndex(array, item); 2029 return array[i] === item ? i : -1; 2030 } 2031 if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item); 2032 for (i = 0, l = array.length; i < l; i++) if (array[i] === item) return i; 2033 return -1; 2034 }; 2035 2036 2037 // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available. 2038 _.lastIndexOf = function(array, item) { 2039 if (array == null) return -1; 2040 if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item); 2041 var i = array.length; 2042 while (i--) if (array[i] === item) return i; 2043 return -1; 2044 }; 2045 2046 // Generate an integer Array containing an arithmetic progression. A port of 2047 // the native Python `range()` function. See 2048 // [the Python documentation](http://docs.python.org/library/functions.html#range). 2049 _.range = function(start, stop, step) { 2050 if (arguments.length <= 1) { 2051 stop = start || 0; 2052 start = 0; 2053 } 2054 step = arguments[2] || 1; 2055 2056 var len = Math.max(Math.ceil((stop - start) / step), 0); 2057 var idx = 0; 2058 var range = new Array(len); 2059 2060 while(idx < len) { 2061 range[idx++] = start; 2062 start += step; 2063 } 2064 2065 return range; 2066 }; 2067 2068 // Function (ahem) Functions 2069 // ------------------ 2070 2071 // Create a function bound to a given object (assigning `this`, and arguments, 2072 // optionally). Binding with arguments is also known as `curry`. 2073 // Delegates to **ECMAScript 5**'s native `Function.bind` if available. 2074 // We check for `func.bind` first, to fail fast when `func` is undefined. 2075 _.bind = function(func, obj) { 2076 if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); 2077 var args = slice.call(arguments, 2); 2078 return function() { 2079 return func.apply(obj, args.concat(slice.call(arguments))); 2080 }; 2081 }; 2082 2083 // Bind all of an object's methods to that object. Useful for ensuring that 2084 // all callbacks defined on an object belong to it. 2085 _.bindAll = function(obj) { 2086 var funcs = slice.call(arguments, 1); 2087 if (funcs.length == 0) funcs = _.functions(obj); 2088 each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); }); 2089 return obj; 2090 }; 2091 2092 // Memoize an expensive function by storing its results. 2093 _.memoize = function(func, hasher) { 2094 var memo = {}; 2095 hasher || (hasher = _.identity); 2096 return function() { 2097 var key = hasher.apply(this, arguments); 2098 return hasOwnProperty.call(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments)); 2099 }; 2100 }; 2101 2102 // Delays a function for the given number of milliseconds, and then calls 2103 // it with the arguments supplied. 2104 _.delay = function(func, wait) { 2105 var args = slice.call(arguments, 2); 2106 return setTimeout(function(){ return func.apply(func, args); }, wait); 2107 }; 2108 2109 // Defers a function, scheduling it to run after the current call stack has 2110 // cleared. 2111 _.defer = function(func) { 2112 return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1))); 2113 }; 2114 2115 // Internal function used to implement `_.throttle` and `_.debounce`. 2116 var limit = function(func, wait, debounce) { 2117 var timeout; 2118 return function() { 2119 var context = this, args = arguments; 2120 var throttler = function() { 2121 timeout = null; 2122 func.apply(context, args); 2123 }; 2124 if (debounce) clearTimeout(timeout); 2125 if (debounce || !timeout) timeout = setTimeout(throttler, wait); 2126 }; 2127 }; 2128 2129 // Returns a function, that, when invoked, will only be triggered at most once 2130 // during a given window of time. 2131 _.throttle = function(func, wait) { 2132 return limit(func, wait, false); 2133 }; 2134 2135 // Returns a function, that, as long as it continues to be invoked, will not 2136 // be triggered. The function will be called after it stops being called for 2137 // N milliseconds. 2138 _.debounce = function(func, wait) { 2139 return limit(func, wait, true); 2140 }; 2141 2142 // Returns a function that will be executed at most one time, no matter how 2143 // often you call it. Useful for lazy initialization. 2144 _.once = function(func) { 2145 var ran = false, memo; 2146 return function() { 2147 if (ran) return memo; 2148 ran = true; 2149 return memo = func.apply(this, arguments); 2150 }; 2151 }; 2152 2153 // Returns the first function passed as an argument to the second, 2154 // allowing you to adjust arguments, run code before and after, and 2155 // conditionally execute the original function. 2156 _.wrap = function(func, wrapper) { 2157 return function() { 2158 var args = [func].concat(slice.call(arguments)); 2159 return wrapper.apply(this, args); 2160 }; 2161 }; 2162 2163 // Returns a function that is the composition of a list of functions, each 2164 // consuming the return value of the function that follows. 2165 _.compose = function() { 2166 var funcs = slice.call(arguments); 2167 return function() { 2168 var args = slice.call(arguments); 2169 for (var i=funcs.length-1; i >= 0; i--) { 2170 args = [funcs[i].apply(this, args)]; 2171 } 2172 return args[0]; 2173 }; 2174 }; 2175 2176 // Returns a function that will only be executed after being called N times. 2177 _.after = function(times, func) { 2178 return function() { 2179 if (--times < 1) { return func.apply(this, arguments); } 2180 }; 2181 }; 2182 2183 2184 // Object Functions 2185 // ---------------- 2186 2187 // Retrieve the names of an object's properties. 2188 // Delegates to **ECMAScript 5**'s native `Object.keys` 2189 _.keys = nativeKeys || function(obj) { 2190 if (obj !== Object(obj)) throw new TypeError('Invalid object'); 2191 var keys = []; 2192 for (var key in obj) if (hasOwnProperty.call(obj, key)) keys[keys.length] = key; 2193 return keys; 2194 }; 2195 2196 // Retrieve the values of an object's properties. 2197 _.values = function(obj) { 2198 return _.map(obj, _.identity); 2199 }; 2200 2201 // Return a sorted list of the function names available on the object. 2202 // Aliased as `methods` 2203 _.functions = _.methods = function(obj) { 2204 return _.filter(_.keys(obj), function(key){ return _.isFunction(obj[key]); }).sort(); 2205 }; 2206 2207 // Extend a given object with all the properties in passed-in object(s). 2208 _.extend = function(obj) { 2209 each(slice.call(arguments, 1), function(source) { 2210 for (var prop in source) { 2211 if (source[prop] !== void 0) obj[prop] = source[prop]; 2212 } 2213 }); 2214 return obj; 2215 }; 2216 2217 // Fill in a given object with default properties. 2218 _.defaults = function(obj) { 2219 each(slice.call(arguments, 1), function(source) { 2220 for (var prop in source) { 2221 if (obj[prop] == null) obj[prop] = source[prop]; 2222 } 2223 }); 2224 return obj; 2225 }; 2226 2227 // Create a (shallow-cloned) duplicate of an object. 2228 _.clone = function(obj) { 2229 return _.isArray(obj) ? obj.slice() : _.extend({}, obj); 2230 }; 2231 2232 // Invokes interceptor with the obj, and then returns obj. 2233 // The primary purpose of this method is to "tap into" a method chain, in 2234 // order to perform operations on intermediate results within the chain. 2235 _.tap = function(obj, interceptor) { 2236 interceptor(obj); 2237 return obj; 2238 }; 2239 2240 // Perform a deep comparison to check if two objects are equal. 2241 _.isEqual = function(a, b) { 2242 // Check object identity. 2243 if (a === b) return true; 2244 // Different types? 2245 var atype = typeof(a), btype = typeof(b); 2246 if (atype != btype) return false; 2247 // Basic equality test (watch out for coercions). 2248 if (a == b) return true; 2249 // One is falsy and the other truthy. 2250 if ((!a && b) || (a && !b)) return false; 2251 // Unwrap any wrapped objects. 2252 if (a._chain) a = a._wrapped; 2253 if (b._chain) b = b._wrapped; 2254 // One of them implements an isEqual()? 2255 if (a.isEqual) return a.isEqual(b); 2256 // Check dates' integer values. 2257 if (_.isDate(a) && _.isDate(b)) return a.getTime() === b.getTime(); 2258 // Both are NaN? 2259 if (_.isNaN(a) && _.isNaN(b)) return false; 2260 // Compare regular expressions. 2261 if (_.isRegExp(a) && _.isRegExp(b)) 2262 return a.source === b.source && 2263 a.global === b.global && 2264 a.ignoreCase === b.ignoreCase && 2265 a.multiline === b.multiline; 2266 // If a is not an object by this point, we can't handle it. 2267 if (atype !== 'object') return false; 2268 // Check for different array lengths before comparing contents. 2269 if (a.length && (a.length !== b.length)) return false; 2270 // Nothing else worked, deep compare the contents. 2271 var aKeys = _.keys(a), bKeys = _.keys(b); 2272 // Different object sizes? 2273 if (aKeys.length != bKeys.length) return false; 2274 // Recursive comparison of contents. 2275 for (var key in a) if (!(key in b) || !_.isEqual(a[key], b[key])) return false; 2276 return true; 2277 }; 2278 2279 // Is a given array or object empty? 2280 _.isEmpty = function(obj) { 2281 if (_.isArray(obj) || _.isString(obj)) return obj.length === 0; 2282 for (var key in obj) if (hasOwnProperty.call(obj, key)) return false; 2283 return true; 2284 }; 2285 2286 // Is a given value a DOM element? 2287 _.isElement = function(obj) { 2288 return !!(obj && obj.nodeType == 1); 2289 }; 2290 2291 // Is a given value an array? 2292 // Delegates to ECMA5's native Array.isArray 2293 _.isArray = nativeIsArray || function(obj) { 2294 return toString.call(obj) === '[object Array]'; 2295 }; 2296 2297 // Is a given variable an arguments object? 2298 _.isArguments = function(obj) { 2299 return !!(obj && hasOwnProperty.call(obj, 'callee')); 2300 }; 2301 2302 // Is a given value a function? 2303 _.isFunction = function(obj) { 2304 return !!(obj && obj.constructor && obj.call && obj.apply); 2305 }; 2306 2307 // Is a given value a string? 2308 _.isString = function(obj) { 2309 return !!(obj === '' || (obj && obj.charCodeAt && obj.substr)); 2310 }; 2311 2312 // Is a given value a number? 2313 _.isNumber = function(obj) { 2314 return !!(obj === 0 || (obj && obj.toExponential && obj.toFixed)); 2315 }; 2316 2317 // Is the given value `NaN`? `NaN` happens to be the only value in JavaScript 2318 // that does not equal itself. 2319 _.isNaN = function(obj) { 2320 return obj !== obj; 2321 }; 2322 2323 // Is a given value a boolean? 2324 _.isBoolean = function(obj) { 2325 return obj === true || obj === false; 2326 }; 2327 2328 // Is a given value a date? 2329 _.isDate = function(obj) { 2330 return !!(obj && obj.getTimezoneOffset && obj.setUTCFullYear); 2331 }; 2332 2333 // Is the given value a regular expression? 2334 _.isRegExp = function(obj) { 2335 return !!(obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false)); 2336 }; 2337 2338 // Is a given value equal to null? 2339 _.isNull = function(obj) { 2340 return obj === null; 2341 }; 2342 2343 // Is a given variable undefined? 2344 _.isUndefined = function(obj) { 2345 return obj === void 0; 2346 }; 2347 2348 // Utility Functions 2349 // ----------------- 2350 2351 // Run Underscore.js in *noConflict* mode, returning the `_` variable to its 2352 // previous owner. Returns a reference to the Underscore object. 2353 _.noConflict = function() { 2354 root._ = previousUnderscore; 2355 return this; 2356 }; 2357 2358 // Keep the identity function around for default iterators. 2359 _.identity = function(value) { 2360 return value; 2361 }; 2362 2363 // Run a function **n** times. 2364 _.times = function (n, iterator, context) { 2365 for (var i = 0; i < n; i++) iterator.call(context, i); 2366 }; 2367 2368 // Add your own custom functions to the Underscore object, ensuring that 2369 // they're correctly added to the OOP wrapper as well. 2370 _.mixin = function(obj) { 2371 each(_.functions(obj), function(name){ 2372 addToWrapper(name, _[name] = obj[name]); 2373 }); 2374 }; 2375 2376 // Generate a unique integer id (unique within the entire client session). 2377 // Useful for temporary DOM ids. 2378 var idCounter = 0; 2379 _.uniqueId = function(prefix) { 2380 var id = idCounter++; 2381 return prefix ? prefix + id : id; 2382 }; 2383 2384 // By default, Underscore uses ERB-style template delimiters, change the 2385 // following template settings to use alternative delimiters. 2386 _.templateSettings = { 2387 evaluate : /<%([\s\S]+?)%>/g, 2388 interpolate : /<%=([\s\S]+?)%>/g 2389 }; 2390 2391 // JavaScript micro-templating, similar to John Resig's implementation. 2392 // Underscore templating handles arbitrary delimiters, preserves whitespace, 2393 // and correctly escapes quotes within interpolated code. 2394 _.template = function(str, data) { 2395 var c = _.templateSettings; 2396 var tmpl = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' + 2397 'with(obj||{}){__p.push(\'' + 2398 str.replace(/\\/g, '\\\\') 2399 .replace(/'/g, "\\'") 2400 .replace(c.interpolate, function(match, code) { 2401 return "'," + code.replace(/\\'/g, "'") + ",'"; 2402 }) 2403 .replace(c.evaluate || null, function(match, code) { 2404 return "');" + code.replace(/\\'/g, "'") 2405 .replace(/[\r\n\t]/g, ' ') + "__p.push('"; 2406 }) 2407 .replace(/\r/g, '\\r') 2408 .replace(/\n/g, '\\n') 2409 .replace(/\t/g, '\\t') 2410 + "');}return __p.join('');"; 2411 var func = new Function('obj', tmpl); 2412 return data ? func(data) : func; 2413 }; 2414 2415 // The OOP Wrapper 2416 // --------------- 2417 2418 // If Underscore is called as a function, it returns a wrapped object that 2419 // can be used OO-style. This wrapper holds altered versions of all the 2420 // underscore functions. Wrapped objects may be chained. 2421 var wrapper = function(obj) { this._wrapped = obj; }; 2422 2423 // Expose `wrapper.prototype` as `_.prototype` 2424 _.prototype = wrapper.prototype; 2425 2426 // Helper function to continue chaining intermediate results. 2427 var result = function(obj, chain) { 2428 return chain ? _(obj).chain() : obj; 2429 }; 2430 2431 // A method to easily add functions to the OOP wrapper. 2432 var addToWrapper = function(name, func) { 2433 wrapper.prototype[name] = function() { 2434 var args = slice.call(arguments); 2435 unshift.call(args, this._wrapped); 2436 return result(func.apply(_, args), this._chain); 2437 }; 2438 }; 2439 2440 // Add all of the Underscore functions to the wrapper object. 2441 _.mixin(_); 2442 2443 // Add all mutator Array functions to the wrapper. 2444 each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { 2445 var method = ArrayProto[name]; 2446 wrapper.prototype[name] = function() { 2447 method.apply(this._wrapped, arguments); 2448 return result(this._wrapped, this._chain); 2449 }; 2450 }); 2451 2452 // Add all accessor Array functions to the wrapper. 2453 each(['concat', 'join', 'slice'], function(name) { 2454 var method = ArrayProto[name]; 2455 wrapper.prototype[name] = function() { 2456 return result(method.apply(this._wrapped, arguments), this._chain); 2457 }; 2458 }); 2459 2460 // Start chaining a wrapped Underscore object. 2461 wrapper.prototype.chain = function() { 2462 this._chain = true; 2463 return this; 2464 }; 2465 2466 // Extracts the result from a wrapped and chained object. 2467 wrapper.prototype.value = function() { 2468 return this._wrapped; 2469 }; 2470 2471 })(); 2472 2473 2474 provide("underscore", module.exports); 2475 2476 $.ender(module.exports); 2477 2478}(); 2479 2480!function () { 2481 2482 var module = { exports: {} }, exports = module.exports; 2483 2484 /*! 2485 * Valentine: JavaScript's Sister 2486 * copyright Dustin Diaz 2011 (@ded) 2487 * https://github.com/ded/valentine 2488 * License MIT 2489 */ 2490 2491 !function (context) { 2492 2493 var v = function (a, scope) { 2494 return new Valentine(a, scope); 2495 }, 2496 ap = [], 2497 op = {}, 2498 slice = ap.slice, 2499 nativ = 'map' in ap, 2500 nativ18 = 'reduce' in ap, 2501 trimReplace = /(^\s*|\s*$)/g; 2502 2503 var iters = { 2504 each: nativ ? 2505 function (a, fn, scope) { 2506 ap.forEach.call(a, fn, scope); 2507 } : 2508 function (a, fn, scope) { 2509 for (var i = 0, l = a.length; i < l; i++) { 2510 i in a && fn.call(scope, a[i], i, a); 2511 } 2512 }, 2513 map: nativ ? 2514 function (a, fn, scope) { 2515 return ap.map.call(a, fn, scope); 2516 } : 2517 function (a, fn, scope) { 2518 var r = [], i; 2519 for (i = 0, l = a.length; i < l; i++) { 2520 i in a && (r[i] = fn.call(scope, a[i], i, a)); 2521 } 2522 return r; 2523 }, 2524 some: nativ ? 2525 function (a, fn, scope) { 2526 return a.some(fn, scope); 2527 } : 2528 function (a, fn, scope) { 2529 for (var i = 0, l = a.length; i < l; i++) { 2530 if (i in a && fn.call(scope, a[i], i, a)) { 2531 return true; 2532 } 2533 } 2534 return false; 2535 }, 2536 every: nativ ? 2537 function (a, fn, scope) { 2538 return a.every(fn, scope); 2539 } : 2540 function (a, fn, scope) { 2541 for (var i = 0, l = a.length; i < l; i++) { 2542 if (i in a && !fn.call(scope, a[i], i, a)) { 2543 return false; 2544 } 2545 } 2546 return true; 2547 }, 2548 filter: nativ ? 2549 function (a, fn, scope) { 2550 return a.filter(fn, scope); 2551 } : 2552 function (a, fn, scope) { 2553 var r = []; 2554 for (var i = 0, j = 0, l = a.length; i < l; i++) { 2555 if (i in a) { 2556 if (!fn.call(scope, a[i], i, a)) { 2557 continue; 2558 } 2559 r[j++] = a[i]; 2560 } 2561 } 2562 return r; 2563 }, 2564 indexOf: nativ ? 2565 function (a, el, start) { 2566 return a.indexOf(el, isFinite(start) ? start : 0); 2567 } : 2568 function (a, el, start) { 2569 start = start || 0; 2570 for (var i = 0; i < a.length; i++) { 2571 if (i in a && a[i] === el) { 2572 return i; 2573 } 2574 } 2575 return -1; 2576 }, 2577 2578 lastIndexOf: nativ ? 2579 function (a, el, start) { 2580 return a.lastIndexOf(el, isFinite(start) ? start : a.length); 2581 } : 2582 function (a, el, start) { 2583 start = start || a.length; 2584 start = start >= a.length ? a.length : 2585 start < 0 ? a.length + start : start; 2586 for (var i = start; i >= 0; --i) { 2587 if (i in a && a[i] === el) { 2588 return i; 2589 } 2590 } 2591 return -1; 2592 }, 2593 2594 reduce: nativ18 ? 2595 function (o, i, m, c) { 2596 return ap.reduce.call(o, i, m, c); 2597 } : 2598 function (obj, iterator, memo, context) { 2599 !obj && (obj = []); 2600 var i = 0, l = obj.length; 2601 if (arguments.length < 3) { 2602 do { 2603 if (i in obj) { 2604 memo = obj[i++]; 2605 break; 2606 } 2607 if (++i >= l) { 2608 throw new TypeError('Empty array'); 2609 } 2610 } while (1); 2611 } 2612 for (; i < l; i++) { 2613 if (i in obj) { 2614 memo = iterator.call(context, memo, obj[i], i, obj); 2615 } 2616 } 2617 return memo; 2618 }, 2619 2620 reduceRight: nativ18 ? 2621 function (o, i, m, c) { 2622 return ap.reduceRight.call(o, i, m, c); 2623 } : 2624 function (obj, iterator, memo, context) { 2625 !obj && (obj = []); 2626 var l = obj.length, i = l - 1; 2627 if (arguments.length < 3) { 2628 do { 2629 if (i in obj) { 2630 memo = obj[i--]; 2631 break; 2632 } 2633 if (--i < 0) { 2634 throw new TypeError('Empty array'); 2635 } 2636 } while (1); 2637 } 2638 for (; i >= 0; i--) { 2639 if (i in obj) { 2640 memo = iterator.call(context, memo, obj[i], i, obj); 2641 } 2642 } 2643 return memo; 2644 }, 2645 2646 find: function (obj, iterator, context) { 2647 var result; 2648 iters.some(obj, function (value, index, list) { 2649 if (iterator.call(context, value, index, list)) { 2650 result = value; 2651 return true; 2652 } 2653 }); 2654 return result; 2655 }, 2656 2657 reject: function (a, fn, scope) { 2658 var r = []; 2659 for (var i = 0, j = 0, l = a.length; i < l; i++) { 2660 if (i in a) { 2661 if (fn.call(scope, a[i], i, a)) { 2662 continue; 2663 } 2664 r[j++] = a[i]; 2665 } 2666 } 2667 return r; 2668 }, 2669 2670 size: function (a) { 2671 return o.toArray(a).length; 2672 }, 2673 2674 pluck: function (a, k) { 2675 return iters.map(a, function (el) { 2676 return el[k]; 2677 }); 2678 }, 2679 2680 compact: function (a) { 2681 return iters.filter(a, function (value) { 2682 return !!value; 2683 }); 2684 }, 2685 2686 flatten: function (a) { 2687 return iters.reduce(a, function (memo, value) { 2688 if (is.arr(value)) { 2689 return memo.concat(iters.flatten(value)); 2690 } 2691 memo[memo.length] = value; 2692 return memo; 2693 }, []); 2694 }, 2695 2696 uniq: function (ar) { 2697 var a = [], i, j; 2698 label: 2699 for (i = 0; i < ar.length; i++) { 2700 for (j = 0; j < a.length; j++) { 2701 if (a[j] == ar[i]) { 2702 continue label; 2703 } 2704 } 2705 a[a.length] = ar[i]; 2706 } 2707 return a; 2708 }, 2709 2710 merge: function (one, two) { 2711 var i = one.length, j = 0, l; 2712 if (isFinite(two.length)) { 2713 for (l = two.length; j < l; j++) { 2714 one[i++] = two[j]; 2715 } 2716 } else { 2717 while (two[j] !== undefined) { 2718 first[i++] = second[j++]; 2719 } 2720 } 2721 one.length = i; 2722 return one; 2723 } 2724 2725 }; 2726 2727 function aug(o, o2) { 2728 for (var k in o2) { 2729 o[k] = o2[k]; 2730 } 2731 } 2732 2733 var is = { 2734 fun: function (f) { 2735 return typeof f === 'function'; 2736 }, 2737 2738 str: function (s) { 2739 return typeof s === 'string'; 2740 }, 2741 2742 ele: function (el) { 2743 !!(el && el.nodeType && el.nodeType == 1); 2744 }, 2745 2746 arr: function (ar) { 2747 return ar instanceof Array; 2748 }, 2749 2750 arrLike: function (ar) { 2751 return (ar && ar.length && isFinite(ar.length)); 2752 }, 2753 2754 num: function (n) { 2755 return typeof n === 'number'; 2756 }, 2757 2758 bool: function (b) { 2759 return (b === true) || (b === false); 2760 }, 2761 2762 args: function (a) { 2763 return !!(a && op.hasOwnProperty.call(a, 'callee')); 2764 }, 2765 2766 emp: function (o) { 2767 var i = 0; 2768 return is.arr(o) ? o.length === 0 : 2769 is.obj(o) ? (function () { 2770 for (var k in o) { 2771 i++; 2772 break; 2773 } 2774 return (i === 0); 2775 }()) : 2776 o === ''; 2777 }, 2778 2779 dat: function (d) { 2780 return !!(d && d.getTimezoneOffset && d.setUTCFullYear); 2781 }, 2782 2783 reg: function (r) { 2784 return !!(r && r.test && r.exec && (r.ignoreCase || r.ignoreCase === false)); 2785 }, 2786 2787 nan: function (n) { 2788 return n !== n; 2789 }, 2790 2791 nil: function (o) { 2792 return o === null; 2793 }, 2794 2795 und: function (o) { 2796 return typeof o === 'undefined'; 2797 }, 2798 2799 obj: function (o) { 2800 return o instanceof Object && !is.fun(o) && !is.arr(o); 2801 } 2802 }; 2803 2804 var o = { 2805 each: function (a, fn, scope) { 2806 is.arrLike(a) ? 2807 iters.each(a, fn, scope) : (function () { 2808 for (var k in a) { 2809 op.hasOwnProperty.call(a, k) && fn.call(scope, k, a[k], a); 2810 } 2811 }()); 2812 }, 2813 2814 map: function (a, fn, scope) { 2815 var r = [], i = 0; 2816 return is.arrLike(a) ? 2817 iters.map(a, fn, scope) : !function () { 2818 for (var k in a) { 2819 op.hasOwnProperty.call(a, k) && (r[i++] = fn.call(scope, k, a[k], a)); 2820 } 2821 }() && r; 2822 }, 2823 2824 toArray: function (a) { 2825 if (!a) { 2826 return []; 2827 } 2828 if (a.toArray) { 2829 return a.toArray(); 2830 } 2831 if (is.arr(a)) { 2832 return a; 2833 } 2834 if (is.args(a)) { 2835 return slice.call(a); 2836 } 2837 return iters.map(a, function (k) { 2838 return k; 2839 }); 2840 }, 2841 2842 first: function (a) { 2843 return a[0]; 2844 }, 2845 2846 last: function (a) { 2847 return a[a.length - 1]; 2848 }, 2849 2850 keys: Object.keys ? 2851 function (o) { 2852 return Object.keys(o); 2853 } : 2854 function (obj) { 2855 var keys = []; 2856 for (var key in obj) { 2857 op.hasOwnProperty.call(obj, key) && (keys[keys.length] = key); 2858 } 2859 return keys; 2860 }, 2861 2862 values: function (ob) { 2863 return o.map(ob, function (k, v) { 2864 return v; 2865 }); 2866 }, 2867 2868 extend: function (ob) { 2869 o.each(slice.call(arguments, 1), function (source) { 2870 for (var prop in source) { 2871 !is.und(source[prop]) && (ob[prop] = source[prop]); 2872 } 2873 }); 2874 return ob; 2875 }, 2876 2877 trim: String.prototype.trim ? 2878 function (s) { 2879 return s.trim(); 2880 } : 2881 function (s) { 2882 return s.replace(trimReplace, ''); 2883 }, 2884 2885 bind: function (scope, fn) { 2886 return function () { 2887 fn.apply(scope, arguments); 2888 }; 2889 } 2890 2891 }; 2892 2893 aug(v, iters); 2894 aug(v, o); 2895 v.is = is; 2896 2897 // love thyself 2898 v.v = v; 2899 2900 // peoples like the object style 2901 var Valentine = function (a, scope) { 2902 this.val = a; 2903 this._scope = scope || null; 2904 this._chained = 0; 2905 }; 2906 2907 v.each(v.extend({}, iters, o), function (name, fn) { 2908 Valentine.prototype[name] = function () { 2909 var a = v.toArray(arguments); 2910 a.unshift(this.val); 2911 var ret = fn.apply(this._scope, a); 2912 this.val = ret; 2913 return this._chained ? this : ret; 2914 }; 2915 }); 2916 2917 // back compact to underscore (peoples like chaining) 2918 Valentine.prototype.chain = function () { 2919 this._chained = 1; 2920 return this; 2921 }; 2922 2923 Valentine.prototype.value = function () { 2924 return this.val; 2925 }; 2926 2927 var old = context.v; 2928 v.noConflict = function () { 2929 context.v = old; 2930 return this; 2931 }; 2932 2933 (typeof module !== 'undefined') && module.exports ? 2934 (module.exports = v) : 2935 (context['v'] = v); 2936 2937 }(this); 2938 2939 provide("valentine", module.exports); 2940 2941 var v = require('valentine'); 2942 ender.ender(v); 2943 ender.ender({ 2944 merge: v.merge, 2945 extend: v.extend, 2946 each: v.each, 2947 map: v.map, 2948 toArray: v.toArray, 2949 keys: v.keys, 2950 values: v.values, 2951 trim: v.trim, 2952 bind: v.bind 2953 }) 2954 2955}(); 2956 2957!function () { 2958 2959 var module = { exports: {} }, exports = module.exports; 2960 2961 /*! 2962 * Reqwest! A x-browser general purpose XHR connection manager 2963 * copyright Dustin Diaz 2011 2964 * https://github.com/ded/reqwest 2965 * license MIT 2966 */ 2967 !function (window) { 2968 var twoHundo = /^20\d$/, 2969 doc = document, 2970 byTag = 'getElementsByTagName', 2971 head = doc[byTag]('head')[0], 2972 xhr = ('XMLHttpRequest' in window) ? 2973 function () { 2974 return new XMLHttpRequest(); 2975 } : 2976 function () { 2977 return new ActiveXObject('Microsoft.XMLHTTP'); 2978 }; 2979 2980 var uniqid = 0; 2981 // data stored by the most recent JSONP callback 2982 var lastValue; 2983 2984 function readyState(o, success, error) { 2985 return function () { 2986 if (o && o.readyState == 4) { 2987 if (twoHundo.test(o.status)) { 2988 success(o); 2989 } else { 2990 error(o); 2991 } 2992 } 2993 }; 2994 } 2995 2996 function setHeaders(http, options) { 2997 var headers = options.headers || {}; 2998 headers.Accept = headers.Accept || 'text/javascript, text/html, application/xml, text/xml, */*'; 2999 headers['X-Requested-With'] = headers['X-Requested-With'] || 'XMLHttpRequest'; 3000 if (options.data) { 3001 headers['Content-type'] = headers['Content-type'] || 'application/x-www-form-urlencoded'; 3002 for (var h in headers) { 3003 headers.hasOwnProperty(h) && http.setRequestHeader(h, headers[h], false); 3004 } 3005 } 3006 } 3007 3008 function getCallbackName(o) { 3009 var callbackVar = o.jsonpCallback || "callback"; 3010 if (o.url.slice(-(callbackVar.length + 2)) == (callbackVar + "=?")) { 3011 // Generate a guaranteed unique callback name 3012 var callbackName = "reqwest_" + uniqid++; 3013 3014 // Replace the ? in the URL with the generated name 3015 o.url = o.url.substr(0, o.url.length - 1) + callbackName; 3016 return callbackName; 3017 } else { 3018 // Find the supplied callback name 3019 var regex = new RegExp(callbackVar + "=([\\w]+)"); 3020 return o.url.match(regex)[1]; 3021 } 3022 } 3023 3024 // Store the data returned by the most recent callback 3025 function generalCallback(data) { 3026 lastValue = data; 3027 } 3028 3029 function getRequest(o, fn, err) { 3030 if (o.type == 'jsonp') { 3031 var script = doc.createElement('script'); 3032 3033 // Add the global callback 3034 window[getCallbackName(o)] = generalCallback; 3035 3036 // Setup our script element 3037 script.type = "text/javascript"; 3038 script.src = o.url; 3039 script.async = true; 3040 3041 var onload = function () { 3042 // Call the user callback with the last value stored 3043 // and clean up values and scripts. 3044 o.success && o.success(lastValue); 3045 lastValue = undefined; 3046 head.removeChild(script); 3047 }; 3048 3049 script.onload = onload; 3050 // onload for IE 3051 script.onreadystatechange = function () { 3052 /^loaded|complete$/.test(script.readyState) && onload(); 3053 }; 3054 3055 // Add the script to the DOM head 3056 head.appendChild(script); 3057 } else { 3058 var http = xhr(); 3059 http.open(o.method || 'GET', typeof o == 'string' ? o : o.url, true); 3060 setHeaders(http, o); 3061 http.onreadystatechange = readyState(http, fn, err); 3062 o.before && o.before(http); 3063 http.send(o.data || null); 3064 return http; 3065 } 3066 } 3067 3068 function Reqwest(o, fn) { 3069 this.o = o; 3070 this.fn = fn; 3071 init.apply(this, arguments); 3072 } 3073 3074 function setType(url) { 3075 if (/\.json$/.test(url)) { 3076 return 'json'; 3077 } 3078 if (/\.jsonp$/.test(url)) { 3079 return 'jsonp'; 3080 } 3081 if (/\.js$/.test(url)) { 3082 return 'js'; 3083 } 3084 if (/\.html?$/.test(url)) { 3085 return 'html'; 3086 } 3087 if (/\.xml$/.test(url)) { 3088 return 'xml'; 3089 } 3090 return 'js'; 3091 } 3092 3093 function init(o, fn) { 3094 this.url = typeof o == 'string' ? o : o.url; 3095 this.timeout = null; 3096 var type = o.type || setType(this.url), self = this; 3097 fn = fn || function () {}; 3098 3099 if (o.timeout) { 3100 this.timeout = setTimeout(function () { 3101 self.abort(); 3102 error(); 3103 }, o.timeout); 3104 } 3105 3106 function complete(resp) { 3107 o.complete && o.complete(resp); 3108 } 3109 3110 function success(resp) { 3111 o.timeout && clearTimeout(self.timeout) && (self.timeout = null); 3112 var r = resp.responseText, JSON; 3113 3114 switch (type) { 3115 case 'json': 3116 resp = JSON ? JSON.parse(r) : eval('(' + r + ')'); 3117 break; 3118 case 'js': 3119 resp = eval(r); 3120 break; 3121 case 'html': 3122 resp = r; 3123 break; 3124 // default is the response from server 3125 } 3126 3127 fn(resp); 3128 o.success && o.success(resp); 3129 complete(resp); 3130 } 3131 3132 function error(resp) { 3133 o.error && o.error(resp); 3134 complete(resp); 3135 } 3136 3137 this.request = getRequest(o, success, error); 3138 } 3139 3140 Reqwest.prototype = { 3141 abort: function () { 3142 this.request.abort(); 3143 }, 3144 3145 retry: function () { 3146 init.call(this, this.o, this.fn); 3147 } 3148 }; 3149 3150 function reqwest(o, fn) { 3151 return new Reqwest(o, fn); 3152 } 3153 3154 function enc(v) { 3155 return encodeURIComponent(v); 3156 } 3157 3158 function serial(el) { 3159 var n = el.name; 3160 // don't serialize elements that are disabled or without a name 3161 if (el.disabled || !n) { 3162 return ''; 3163 } 3164 n = enc(n); 3165 switch (el.tagName.toLowerCase()) { 3166 case 'input': 3167 switch (el.type) { 3168 // silly wabbit 3169 case 'reset': 3170 case 'button': 3171 case 'image': 3172 case 'file': 3173 return ''; 3174 case 'checkbox': 3175 case 'radio': 3176 return el.checked ? n + '=' + (el.value ? enc(el.value) : true) + '&' : ''; 3177 default: // text hidden password submit 3178 return n + '=' + (el.value ? enc(el.value) : '') + '&'; 3179 } 3180 break; 3181 case 'textarea': 3182 return n + '=' + enc(el.value) + '&'; 3183 case 'select': 3184 // @todo refactor beyond basic single selected value case 3185 return n + '=' + enc(el.options[el.selectedIndex].value) + '&'; 3186 } 3187 return ''; 3188 } 3189 3190 reqwest.serialize = function (form) { 3191 var inputs = form[byTag]('input'), 3192 selects = form[byTag]('select'), 3193 texts = form[byTag]('textarea'); 3194 return (v(inputs).chain().toArray().map(serial).value().join('') + 3195 v(selects).chain().toArray().map(serial).value().join('') + 3196 v(texts).chain().toArray().map(serial).value().join('')).replace(/&$/, ''); 3197 }; 3198 3199 reqwest.serializeArray = function (f) { 3200 for (var pairs = this.serialize(f).split('&'), i = 0, l = pairs.length, r = [], o; i < l; i++) { 3201 pairs[i] && (o = pairs[i].split('=')) && r.push({name: o[0], value: o[1]}); 3202 } 3203 return r; 3204 }; 3205 3206 var old = window.reqwest; 3207 reqwest.noConflict = function () { 3208 window.reqwest = old; 3209 return this; 3210 }; 3211 3212 // defined as extern for Closure Compilation 3213 // do not change to (dot) '.' syntax 3214 window['reqwest'] = reqwest; 3215 3216 }(this); 3217 3218 3219 provide("reqwest", module.exports); 3220 3221 ender.ender({ 3222 ajax: reqwest 3223 }); 3224 ender.ender({ 3225 serialize: function () { 3226 return reqwest.serialize(this[0]); 3227 } 3228 , serializeArray: function() { 3229 return reqwest.serializeArray(this[0]); 3230 } 3231 }, true); 3232 3233}();