142
St
startsInvasion / files
startsInvasion / libs / node_modules / bonzo / build / qwery / integration / ender.js
16.0 KB
1/*! 2 * Ender: open module JavaScript framework 3 * copyright Dustin Diaz & Jacob Thornton 2011 (@ded @fat) 4 * https://github.com/ender-js/ender 5 * License MIT 6 * Build: ender build domready bonzo 7 */ 8!function (context) { 9 10 function aug(o, o2) { 11 for (var k in o2) { 12 k != 'noConflict' && (o[k] = o2[k]); 13 } 14 } 15 16 function _$(s, r) { 17 this.elements = typeof s !== 'string' && !s.nodeType && typeof s.length !== 'undefined' ? s : $._select(s, r); 18 this.length = this.elements.length; 19 for (var i = 0; i < this.length; i++) { 20 this[i] = this.elements[i]; 21 } 22 } 23 24 function $(s, r) { 25 return new _$(s, r); 26 } 27 28 aug($, { 29 ender: function (o, proto) { 30 aug(proto ? _$.prototype : $, o); 31 }, 32 _select: function () { 33 return []; 34 } 35 }); 36 37 var old = context.$; 38 $.noConflict = function () { 39 context.$ = old; 40 return this; 41 }; 42 43 (typeof module !== 'undefined') && module.exports ? 44 (module.exports = $) : 45 (context.$ = $); 46 47}(this); 48!function () { var exports = {}, module = { exports: exports }; !function (doc) { 49 var loaded = 0, fns = [], ol, f = false, 50 testEl = doc.createElement('a'), 51 domContentLoaded = 'DOMContentLoaded', 52 addEventListener = 'addEventListener', 53 onreadystatechange = 'onreadystatechange'; 54 55 /^loade|c/.test(doc.readyState) && (loaded = 1); 56 57 function flush() { 58 loaded = 1; 59 for (var i = 0, l = fns.length; i < l; i++) { 60 fns[i](); 61 } 62 } 63 doc[addEventListener] && doc[addEventListener](domContentLoaded, function fn() { 64 doc.removeEventListener(domContentLoaded, fn, f); 65 flush(); 66 }, f); 67 68 69 testEl.doScroll && doc.attachEvent(onreadystatechange, (ol = function ol() { 70 if (/^c/.test(doc.readyState)) { 71 doc.detachEvent(onreadystatechange, ol); 72 flush(); 73 } 74 })); 75 76 var domReady = testEl.doScroll ? 77 function (fn) { 78 self != top ? 79 !loaded ? 80 fns.push(fn) : 81 fn() : 82 !function () { 83 try { 84 testEl.doScroll('left'); 85 } catch (e) { 86 return setTimeout(function() { 87 domReady(fn); 88 }, 50); 89 } 90 fn(); 91 }(); 92 } : 93 function (fn) { 94 loaded ? fn() : fns.push(fn); 95 }; 96 97 (typeof module !== 'undefined') && module.exports ? 98 (module.exports = {domReady: domReady}) : 99 (window.domReady = domReady); 100 101}(document); $.ender(module.exports); }(); 102/*! 103 * bonzo.js - copyright @dedfat 2011 104 * https://github.com/ded/bonzo 105 * Follow our software http://twitter.com/dedfat 106 * MIT License 107 */ 108!function (context) { 109 110 var doc = document, 111 html = doc.documentElement, 112 specialAttributes = /^checked|value|selected$/, 113 stateAttributes = /^checked|selected$/, 114 ie = /msie/.test(navigator.userAgent), 115 uidList = [], 116 uuids = 0; 117 118 function classReg(c) { 119 return new RegExp("(^|\\s+)" + c + "(\\s+|$)"); 120 } 121 122 function each(ar, fn) { 123 for (i = 0, len = ar.length; i < len; i++) { 124 fn(ar[i]); 125 } 126 } 127 128 function trim(s) { 129 return s.replace(/(^\s*|\s*$)/g, ''); 130 } 131 132 function camelize(s) { 133 return s.replace(/-(.)/g, function (m, m1) { 134 return m1.toUpperCase(); 135 }); 136 } 137 138 function is(node) { 139 return node && node.nodeName && node.nodeType == 1; 140 } 141 142 function some(ar, fn, scope) { 143 for (var i = 0, j = ar.length; i < j; ++i) { 144 if (fn.call(scope, ar[i], i, ar)) { 145 return true; 146 } 147 } 148 return false; 149 } 150 151 function sucks(o) { 152 for (var k in o) { 153 switch (k) { 154 case 'opacity': 155 o.filter = 'alpha(opacity=' + (o[k] * 100) + ')'; 156 delete o[k]; 157 break; 158 case '': 159 break; 160 } 161 } 162 } 163 164 function _bonzo(elements) { 165 this.elements = []; 166 this.length = 0; 167 if (elements) { 168 this.elements = typeof elements !== 'string' && !elements.nodeType && typeof elements.length !== 'undefined' ? elements : [elements]; 169 this.length = this.elements.length; 170 for (var i = 0; i < this.length; i++) { 171 this[i] = this.elements[i]; 172 } 173 } 174 } 175 176 _bonzo.prototype = { 177 178 each: function (fn) { 179 for (var i = 0, l = this.length; i < l; i++) { 180 fn.call(this, this[i], i); 181 } 182 return this; 183 }, 184 185 map: function (fn, reject) { 186 var m = [], n; 187 for (var i = 0; i < this.length; i++) { 188 n = fn.call(this, this[i]); 189 reject ? (reject(n) && m.push(n)) : m.push(n); 190 } 191 return m; 192 }, 193 194 first: function () { 195 return bonzo(this[0]); 196 }, 197 198 last: function () { 199 return bonzo(this[this.length - 1]); 200 }, 201 202 html: function (html) { 203 return typeof html !== 'undefined' ? 204 this.each(function (el) { 205 el.innerHTML = html; 206 }) : 207 this.elements[0] ? this.elements[0].innerHTML : ''; 208 }, 209 210 addClass: function (c) { 211 return this.each(function (el) { 212 this.hasClass(el, c) || (el.className = trim(el.className + ' ' + c)); 213 }); 214 }, 215 216 removeClass: function (c) { 217 return this.each(function (el) { 218 this.hasClass(el, c) && (el.className = trim(el.className.replace(classReg(c), ' '))); 219 }); 220 }, 221 222 hasClass: function (el, c) { 223 return typeof c == 'undefined' ? 224 some(this.elements, function (i) { 225 return classReg(el).test(i.className); 226 }) : 227 classReg(c).test(el.className); 228 }, 229 230 toggleClass: function (c, condition) { 231 if (typeof condition !== 'undefined' && !condition) { 232 return this; 233 } 234 return this.each(function (el) { 235 this.hasClass(el, c) ? 236 (el.className = trim(el.className.replace(classReg(c), ' '))) : 237 (el.className = trim(el.className + ' ' + c)); 238 }); 239 }, 240 241 show: function (elements) { 242 return this.each(function (el) { 243 el.style.display = ''; 244 }); 245 }, 246 247 hide: function (elements) { 248 return this.each(function (el) { 249 el.style.display = 'none'; 250 }); 251 }, 252 253 append: function (node) { 254 return this.each(function (el) { 255 each(normalize(node), function (i) { 256 el.appendChild(i); 257 }); 258 }); 259 }, 260 261 prepend: function (node) { 262 return this.each(function (el) { 263 var first = el.firstChild; 264 each(normalize(node), function (i) { 265 el.insertBefore(i, first); 266 }); 267 }); 268 }, 269 270 appendTo: function (target) { 271 return this.each(function (el) { 272 target.appendChild(el); 273 }); 274 }, 275 276 next: function () { 277 return this.related('nextSibling'); 278 }, 279 280 previous: function () { 281 return this.related('previousSibling'); 282 }, 283 284 related: function (method) { 285 return this.map( 286 function (el) { 287 el = el[method]; 288 while (el && el.nodeType !== 1) { 289 el = el[method]; 290 } 291 return el || 0; 292 }, 293 function (el) { 294 return el; 295 } 296 ); 297 }, 298 299 prependTo: function (target) { 300 return this.each(function (el) { 301 target.insertBefore(el, bonzo.firstChild(target)); 302 }); 303 }, 304 305 before: function (node) { 306 return this.each(function (el) { 307 each(bonzo.create(node), function (i) { 308 el.parentNode.insertBefore(i, el); 309 }); 310 }); 311 }, 312 313 insertBefore: function (node) { 314 return this.each(function (el) { 315 each(normalize(node), function (n) { 316 n.parentNode.insertBefore(el, n); 317 }); 318 }); 319 }, 320 321 insertAfter: function (node) { 322 return this.each(function (el) { 323 each(normalize(node), function (n) { 324 n.parentNode.insertBefore(el, (n.nextSibling || n)); 325 }); 326 }); 327 }, 328 329 after: function (node) { 330 return this.each(function (el) { 331 each(bonzo.create(node), function (i) { 332 el.parentNode.insertBefore(i, el.nextSibling); 333 }); 334 }); 335 }, 336 337 css: function (o, v) { 338 if (v === undefined && typeof o == 'string') { 339 return this[0].style[camelize(o)]; 340 } 341 var iter = o; 342 if (typeof o == 'string') { 343 iter = {}; 344 iter[o] = v; 345 } 346 ie && sucks(iter); 347 var fn = function (el) { 348 for (var k in iter) { 349 iter.hasOwnProperty(k) && (el.style[camelize(k)] = iter[k]); 350 } 351 }; 352 return this.each(fn); 353 }, 354 355 offset: function () { 356 var el = this.elements[0]; 357 var width = el.offsetWidth; 358 var height = el.offsetHeight; 359 var top = el.offsetTop; 360 var left = el.offsetLeft; 361 while (el = el.offsetParent) { 362 top = top + el.offsetTop; 363 left = left + el.offsetLeft; 364 } 365 366 return { 367 top: top, 368 left: left, 369 height: height, 370 width: width 371 }; 372 }, 373 374 attr: function (k, v) { 375 var el = this.elements[0]; 376 return typeof v == 'undefined' ? 377 specialAttributes.test(k) ? 378 stateAttributes.test(k) && typeof el[k] == 'string' ? 379 true : el[k] : el.getAttribute(k) : 380 this.each(function (el) { 381 el.setAttribute(k, v); 382 }); 383 }, 384 385 removeAttr: function (k) { 386 return this.each(function (el) { 387 el.removeAttribute(k); 388 }); 389 }, 390 391 data: function (k, v) { 392 var el = this.elements[0]; 393 if (typeof v === 'undefined') { 394 el.getAttribute('data-node-uid') || el.setAttribute('data-node-uid', ++uuids); 395 var uid = el.getAttribute('data-node-uid'); 396 uidList[uid] || (uidList[uid] = {}); 397 return uidList[uid][k]; 398 } else { 399 return this.each(function (el) { 400 el.getAttribute('data-node-uid') || el.setAttribute('data-node-uid', ++uuids); 401 var uid = el.getAttribute('data-node-uid'); 402 var o = {}; 403 o[k] = v; 404 uidList[uid] = o; 405 }); 406 } 407 }, 408 409 remove: function () { 410 return this.each(function (el) { 411 el.parentNode && el.parentNode.removeChild(el); 412 }); 413 }, 414 415 empty: function () { 416 return this.each(function (el) { 417 while (el.firstChild) { 418 el.removeChild(el.firstChild); 419 } 420 }); 421 }, 422 423 detach: function () { 424 return this.map(function (el) { 425 return el.parentNode.removeChild(el); 426 }); 427 }, 428 429 scrollTop: function (y) { 430 return scroll.call(this, null, y, 'y'); 431 }, 432 433 scrollLeft: function (x) { 434 return scroll.call(this, x, null, 'x'); 435 }, 436 437 serialize: function () { 438 var form = this[0], 439 inputs = form.getElementsByTagName('input'), 440 selects = form.getElementsByTagName('select'), 441 texts = form.getElementsByTagName('textarea'); 442 return (bonzo(inputs).map(serial).join('') + 443 bonzo(selects).map(serial).join('') + 444 bonzo(texts).map(serial).join('')).replace(/&$/, ''); 445 }, 446 447 serializeArray: function () { 448 for (var pairs = this.serialize().split('&'), i = 0, l = pairs.length, r = [], o; i < l; i++) { 449 pairs[i] && (o = pairs[i].split('=')) && r.push({name: o[0], value: o[1]}); 450 } 451 return r; 452 } 453 }; 454 455 function enc(v) { 456 return encodeURIComponent(v); 457 } 458 459 function serial(el) { 460 var n = el.name; 461 // don't serialize elements that are disabled or without a name 462 if (el.disabled || !n) { 463 return ''; 464 } 465 n = enc(n); 466 switch (el.tagName.toLowerCase()) { 467 case 'input': 468 switch (el.type) { 469 case 'reset': 470 case 'button': 471 case 'image': 472 case 'file': 473 return ''; 474 case 'checkbox': 475 case 'radio': 476 return el.checked ? n + '=' + (el.value ? enc(el.value) : true) + '&' : ''; 477 default: // text hidden password submit 478 return n + '=' + (el.value ? enc(el.value) : true) + '&'; 479 } 480 break; 481 case 'textarea': 482 return n + '=' + enc(el.value) + '&'; 483 case 'select': 484 // @todo refactor beyond basic single selected value case 485 return n + '=' + enc(el.options[el.selectedIndex].value) + '&'; 486 } 487 return ''; 488 } 489 490 function normalize(node) { 491 return typeof node == 'string' ? bonzo.create(node) : is(node) ? [node] : node; 492 } 493 494 function scroll(x, y, type) { 495 var el = this.elements[0]; 496 if (x == null && y == null) { 497 return (isBody(el) ? getWindowScroll() : { x: el.scrollLeft, y: el.scrollTop })[type]; 498 } 499 if (isBody(el)) { 500 window.scrollTo(x, y); 501 } else { 502 x != null && (el.scrollLeft = x); 503 y != null && (el.scrollTop = y); 504 } 505 return this; 506 } 507 508 function isBody(element) { 509 return element === window || (/^(?:body|html)$/i).test(element.tagName); 510 } 511 512 function getWindowScroll() { 513 return { x: window.pageXOffset || html.scrollLeft, y: window.pageYOffset || html.scrollTop }; 514 } 515 516 function bonzo(els) { 517 return new _bonzo(els); 518 } 519 520 bonzo.aug = function (o, target) { 521 for (var k in o) { 522 o.hasOwnProperty(k) && ((target || _bonzo.prototype)[k] = o[k]); 523 } 524 }; 525 526 bonzo.create = function (node) { 527 return typeof node == 'string' ? 528 function () { 529 var el = doc.createElement('div'), els = []; 530 el.innerHTML = node; 531 var nodes = el.childNodes; 532 el = el.firstChild; 533 els.push(el); 534 while (el = el.nextSibling) { 535 (el.nodeType == 1) && els.push(el); 536 } 537 return els; 538 539 }() : is(node) ? [node.cloneNode(true)] : []; 540 }; 541 542 bonzo.doc = function () { 543 var w = html.scrollWidth, 544 h = html.scrollHeight, 545 vp = this.viewport(); 546 return { 547 width: Math.max(w, vp.width), 548 height: Math.max(h, vp.height) 549 }; 550 }; 551 552 bonzo.firstChild = function (el) { 553 for (var c = el.childNodes, i = 0, j = (c && c.length) || 0, e; i < j; i++) { 554 if (c[i].nodeType === 1) { 555 e = c[j = i]; 556 } 557 } 558 return e; 559 }; 560 561 bonzo.viewport = function () { 562 var h = self.innerHeight, 563 w = self.innerWidth; 564 ie && (h = html.clientHeight) && (w = html.clientWidth); 565 return { 566 width: w, 567 height: h 568 }; 569 }; 570 571 bonzo.isAncestor = 'compareDocumentPosition' in html ? 572 function (container, element) { 573 return (container.compareDocumentPosition(element) & 16) == 16; 574 } : 'contains' in html ? 575 function (container, element) { 576 return container !== element && container.contains(element); 577 } : 578 function (container, element) { 579 while (element = element.parentNode) { 580 if (element === container) { 581 return true; 582 } 583 } 584 return false; 585 }; 586 587 var old = context.bonzo; 588 bonzo.noConflict = function () { 589 context.bonzo = old; 590 return this; 591 }; 592 context.bonzo = bonzo; 593 594}(this);!function () { 595 var b = bonzo.noConflict(); 596 $.ender(b); 597 $.ender(b(), true); 598 $.ender({ 599 create: function (node) { 600 return $(b.create(node)); 601 } 602 }); 603 604 function indexOf(ar, val) { 605 for (var i = 0; i < ar.length; i++) { 606 if ( ar[i] === val ) { 607 return i; 608 } 609 } 610 return -1; 611 } 612 613 function uniq(ar) { 614 var a = [], i, j; 615 label: 616 for (i = 0; i < ar.length; i++) { 617 for (j = 0; j < a.length; j++) { 618 if (a[j] == ar[i]) { 619 continue label; 620 } 621 } 622 a[a.length] = ar[i]; 623 } 624 return a; 625 } 626 $.ender({ 627 parents: function (selector, closest) { 628 var collection = $(selector), j, k, p, r = []; 629 for (j = 0, k = this.length; j < k; j++) { 630 p = this[j]; 631 while (p = p.parentNode) { 632 if (indexOf(collection, p) !== -1) { 633 r.push(p); 634 if (closest) break; 635 } 636 } 637 } 638 return $(uniq(r)); 639 }, 640 641 closest: function (selector) { 642 return this.parents(selector, true); 643 }, 644 645 first: function () { 646 return $(this[0]); 647 }, 648 649 last: function () { 650 return $(this[this.length - 1]); 651 }, 652 653 next: function () { 654 return $(b(this).next()); 655 }, 656 657 previous: function () { 658 return $(b(this).previous()); 659 }, 660 661 siblings: function () { 662 var i, l, p, r = []; 663 for (i = 0, l = this.length; i < l; i++) { 664 p = this[i]; 665 while (p = p.previousSibling) { 666 p.nodeType == 1 && r.push(p); 667 } 668 p = this[i]; 669 while (p = p.nextSibling) { 670 p.nodeType == 1 && r.push(p); 671 } 672 } 673 return $(uniq(r)); 674 } 675 }, true); 676 677}();