1/* 2--- 3 4name: Core 5 6description: The core of MooTools, contains all the base functions and the Native and Hash implementations. Required by all the other scripts. 7 8license: MIT-style license. 9 10copyright: Copyright (c) 2006-2008 [Valerio Proietti](http://mad4milk.net/). 11 12authors: The MooTools production team (http://mootools.net/developers/) 13 14inspiration: 15 - Class implementation inspired by [Base.js](http://dean.edwards.name/weblog/2006/03/base/) Copyright (c) 2006 Dean Edwards, [GNU Lesser General Public License](http://opensource.org/licenses/lgpl-license.php) 16 - Some functionality inspired by [Prototype.js](http://prototypejs.org) Copyright (c) 2005-2007 Sam Stephenson, [MIT License](http://opensource.org/licenses/mit-license.php) 17 18provides: [MooTools, Native, Hash.base, Array.each, $util] 19 20... 21*/ 22 23var MooTools = { 24 'version': '1.2.6', 25 'build': 'a3be7a0ef5205eb655c4ee11e8cbedcb3f2ffa95' 26}; 27 28var Native = function(options){ 29 options = options || {}; 30 var name = options.name; 31 var legacy = options.legacy; 32 var protect = options.protect; 33 var methods = options.implement; 34 var generics = options.generics; 35 var initialize = options.initialize; 36 var afterImplement = options.afterImplement || function(){}; 37 var object = initialize || legacy; 38 generics = generics !== false; 39 40 object.constructor = Native; 41 object.$family = {name: 'native'}; 42 if (legacy && initialize) object.prototype = legacy.prototype; 43 object.prototype.constructor = object; 44 45 if (name){ 46 var family = name.toLowerCase(); 47 object.prototype.$family = {name: family}; 48 Native.typize(object, family); 49 } 50 51 var add = function(obj, name, method, force){ 52 if (!protect || force || !obj.prototype[name]) obj.prototype[name] = method; 53 if (generics) Native.genericize(obj, name, protect); 54 afterImplement.call(obj, name, method); 55 return obj; 56 }; 57 58 object.alias = function(a1, a2, a3){ 59 if (typeof a1 == 'string'){ 60 var pa1 = this.prototype[a1]; 61 if ((a1 = pa1)) return add(this, a2, a1, a3); 62 } 63 for (var a in a1) this.alias(a, a1[a], a2); 64 return this; 65 }; 66 67 object.implement = function(a1, a2, a3){ 68 if (typeof a1 == 'string') return add(this, a1, a2, a3); 69 for (var p in a1) add(this, p, a1[p], a2); 70 return this; 71 }; 72 73 if (methods) object.implement(methods); 74 75 return object; 76}; 77 78Native.genericize = function(object, property, check){ 79 if ((!check || !object[property]) && typeof object.prototype[property] == 'function') object[property] = function(){ 80 var args = Array.prototype.slice.call(arguments); 81 return object.prototype[property].apply(args.shift(), args); 82 }; 83}; 84 85Native.implement = function(objects, properties){ 86 for (var i = 0, l = objects.length; i < l; i++) objects[i].implement(properties); 87}; 88 89Native.typize = function(object, family){ 90 if (!object.type) object.type = function(item){ 91 return ($type(item) === family); 92 }; 93}; 94 95(function(){ 96 var natives = {'Array': Array, 'Date': Date, 'Function': Function, 'Number': Number, 'RegExp': RegExp, 'String': String}; 97 for (var n in natives) new Native({name: n, initialize: natives[n], protect: true}); 98 99 var types = {'boolean': Boolean, 'native': Native, 'object': Object}; 100 for (var t in types) Native.typize(types[t], t); 101 102 var generics = { 103 'Array': ["concat", "indexOf", "join", "lastIndexOf", "pop", "push", "reverse", "shift", "slice", "sort", "splice", "toString", "unshift", "valueOf"], 104 'String': ["charAt", "charCodeAt", "concat", "indexOf", "lastIndexOf", "match", "replace", "search", "slice", "split", "substr", "substring", "toLowerCase", "toUpperCase", "valueOf"] 105 }; 106 for (var g in generics){ 107 for (var i = generics[g].length; i--;) Native.genericize(natives[g], generics[g][i], true); 108 } 109})(); 110 111var Hash = new Native({ 112 113 name: 'Hash', 114 115 initialize: function(object){ 116 if ($type(object) == 'hash') object = $unlink(object.getClean()); 117 for (var key in object) this[key] = object[key]; 118 return this; 119 } 120 121}); 122 123Hash.implement({ 124 125 forEach: function(fn, bind){ 126 for (var key in this){ 127 if (this.hasOwnProperty(key)) fn.call(bind, this[key], key, this); 128 } 129 }, 130 131 getClean: function(){ 132 var clean = {}; 133 for (var key in this){ 134 if (this.hasOwnProperty(key)) clean[key] = this[key]; 135 } 136 return clean; 137 }, 138 139 getLength: function(){ 140 var length = 0; 141 for (var key in this){ 142 if (this.hasOwnProperty(key)) length++; 143 } 144 return length; 145 } 146 147}); 148
149Hash.alias('forEach', 'each'); 150 151Array.implement({ 152 153 forEach: function(fn, bind){ 154 for (var i = 0, l = this.length; i < l; i++) fn.call(bind, this[i], i, this); 155 } 156 157}); 158 159Array.alias('forEach', 'each'); 160 161function $A(iterable){ 162 if (iterable.item){ 163 var l = iterable.length, array = new Array(l); 164 while (l--) array[l] = iterable[l]; 165 return array; 166 } 167 return Array.prototype.slice.call(iterable); 168}; 169 170function $arguments(i){ 171 return function(){ 172 return arguments[i]; 173 }; 174}; 175 176function $chk(obj){ 177 return !!(obj || obj === 0); 178}; 179 180function $clear(timer){ 181 clearTimeout(timer); 182 clearInterval(timer); 183 return null; 184}; 185 186function $defined(obj){ 187 return (obj != undefined); 188}; 189 190function $each(iterable, fn, bind){ 191 var type = $type(iterable); 192 ((type == 'arguments' || type == 'collection' || type == 'array') ? Array : Hash).each(iterable, fn, bind); 193}; 194 195function $empty(){}; 196 197function $extend(original, extended){ 198 for (var key in (extended || {})) original[key] = extended[key]; 199 return original; 200}; 201 202function $H(object){ 203 return new Hash(object); 204}; 205 206function $lambda(value){ 207 return ($type(value) == 'function') ? value : function(){ 208 return value; 209 }; 210}; 211 212function $merge(){ 213 var args = Array.slice(arguments); 214 args.unshift({}); 215 return $mixin.apply(null, args); 216}; 217 218function $mixin(mix){ 219 for (var i = 1, l = arguments.length; i < l; i++){ 220 var object = arguments[i]; 221 if ($type(object) != 'object') continue; 222 for (var key in object){ 223 var op = object[key], mp = mix[key]; 224 mix[key] = (mp && $type(op) == 'object' && $type(mp) == 'object') ? $mixin(mp, op) : $unlink(op); 225 } 226 } 227 return mix; 228}; 229 230function $pick(){ 231 for (var i = 0, l = arguments.length; i < l; i++){ 232 if (arguments[i] != undefined) return arguments[i]; 233 } 234 return null; 235}; 236 237function $random(min, max){ 238 return Math.floor(Math.random() * (max - min + 1) + min); 239}; 240 241function $splat(obj){ 242 var type = $type(obj); 243 return (type) ? ((type != 'array' && type != 'arguments') ? [obj] : obj) : []; 244}; 245 246var $time = Date.now || function(){ 247 return +new Date; 248}; 249 250function $try(){ 251 for (var i = 0, l = arguments.length; i < l; i++){ 252 try { 253 return arguments[i](); 254 } catch(e){} 255 } 256 return null; 257}; 258 259function $type(obj){ 260 if (obj == undefined) return false; 261 if (obj.$family) return (obj.$family.name == 'number' && !isFinite(obj)) ? false : obj.$family.name; 262 if (obj.nodeName){ 263 switch (obj.nodeType){ 264 case 1: return 'element'; 265 case 3: return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace'; 266 } 267 } else if (typeof obj.length == 'number'){ 268 if (obj.callee) return 'arguments'; 269 else if (obj.item) return 'collection'; 270 } 271 return typeof obj; 272}; 273 274function $unlink(object){ 275 var unlinked; 276 switch ($type(object)){ 277 case 'object': 278 unlinked = {}; 279 for (var p in object) unlinked[p] = $unlink(object[p]); 280 break; 281 case 'hash': 282 unlinked = new Hash(object); 283 break; 284 case 'array': 285 unlinked = []; 286 for (var i = 0, l = object.length; i < l; i++) unlinked[i] = $unlink(object[i]); 287 break; 288 default: return object; 289 } 290 return unlinked; 291}; 292 293 294/* 295--- 296 297name: Browser 298 299description: The Browser Core. Contains Browser initialization, Window and Document, and the Browser Hash. 300 301license: MIT-style license. 302 303requires: [Native, $util] 304 305provides: [Browser, Window, Document, $exec] 306 307... 308*/ 309 310var Browser = $merge({ 311 312 Engine: {name: 'unknown', version: 0}, 313 314 Platform: {name: (window.orientation != undefined) ? 'ipod' : (navigator.platform.match(/mac|win|linux/i) || ['other'])[0].toLowerCase()}, 315 316 Features: {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)}, 317 318 Plugins: {}, 319 320 Engines: { 321 322 presto: function(){ 323 return (!window.opera) ? false : ((arguments.callee.caller) ? 960 : ((document.getElementsByClassName) ? 950 : 925)); 324 }, 325 326 trident: function(){ 327 return (!window.ActiveXObject) ? false : ((window.XMLHttpRequest) ? ((document.querySelectorAll) ? 6 : 5) : 4); 328 }, 329 330 webkit: function(){ 331 return (navigator.taintEnabled) ? false : ((Browser.Features.xpath) ? ((Browser.Features.query) ? 525 : 420) : 419); 332 }, 333 334 gecko: function(){ 335 return (!document.getBoxObjectFor && window.mozInnerScreenX == null) ? false : ((document.getElementsByClassName) ? 19 : 18); 336 } 337 338 } 339 340}, Browser || {}); 341 342Browser.Platform[Browser.Platform.name] = true; 343 344Browser.detect = function(){ 345 346 for (var engine in this.Engines){ 347 var version = this.Engines[engine](); 348 if (version){ 349 this.Engine = {name: engine, version: version}; 350 this.Engine[engine] = this.Engine[engine + version] = true; 351 break; 352 } 353 } 354 355 return {name: engine, version: version}; 356 357}; 358 359Browser.detect(); 360 361Browser.Request = function(){ 362 return $try(function(){ 363 return new XMLHttpRequest(); 364 }, function(){ 365 return new ActiveXObject('MSXML2.XMLHTTP'); 366 }, function(){ 367 return new ActiveXObject('Microsoft.XMLHTTP'); 368 }); 369}; 370
371Browser.Features.xhr = !!(Browser.Request()); 372 373Browser.Plugins.Flash = (function(){ 374 var version = ($try(function(){ 375 return navigator.plugins['Shockwave Flash'].description; 376 }, function(){ 377 return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version'); 378 }) || '0 r0').match(/\d+/g); 379 return {version: parseInt(version[0] || 0 + '.' + version[1], 10) || 0, build: parseInt(version[2], 10) || 0}; 380})(); 381 382function $exec(text){ 383 if (!text) return text; 384 if (window.execScript){ 385 window.execScript(text); 386 } else { 387 var script = document.createElement('script'); 388 script.setAttribute('type', 'text/javascript'); 389 script[(Browser.Engine.webkit && Browser.Engine.version < 420) ? 'innerText' : 'text'] = text; 390 document.head.appendChild(script); 391 document.head.removeChild(script); 392 } 393 return text; 394}; 395 396Native.UID = 1; 397 398var $uid = (Browser.Engine.trident) ? function(item){ 399 return (item.uid || (item.uid = [Native.UID++]))[0]; 400} : function(item){ 401 return item.uid || (item.uid = Native.UID++); 402}; 403 404var Window = new Native({ 405 406 name: 'Window', 407 408 legacy: (Browser.Engine.trident) ? null: window.Window, 409 410 initialize: function(win){ 411 $uid(win); 412 if (!win.Element){ 413 win.Element = $empty; 414 if (Browser.Engine.webkit) win.document.createElement("iframe"); //fixes safari 2 415 win.Element.prototype = (Browser.Engine.webkit) ? window["[[DOMElement.prototype]]"] : {}; 416 } 417 win.document.window = win; 418 return $extend(win, Window.Prototype); 419 }, 420 421 afterImplement: function(property, value){ 422 window[property] = Window.Prototype[property] = value; 423 } 424 425}); 426 427Window.Prototype = {$family: {name: 'window'}}; 428 429new Window(window); 430 431var Document = new Native({ 432 433 name: 'Document', 434 435 legacy: (Browser.Engine.trident) ? null: window.Document, 436 437 initialize: function(doc){ 438 $uid(doc); 439 doc.head = doc.getElementsByTagName('head')[0]; 440 doc.html = doc.getElementsByTagName('html')[0]; 441 if (Browser.Engine.trident && Browser.Engine.version <= 4) $try(function(){ 442 doc.execCommand("BackgroundImageCache", false, true); 443 }); 444 if (Browser.Engine.trident) doc.window.attachEvent('onunload', function(){ 445 doc.window.detachEvent('onunload', arguments.callee); 446 doc.head = doc.html = doc.window = null; 447 }); 448 return $extend(doc, Document.Prototype); 449 }, 450 451 afterImplement: function(property, value){ 452 document[property] = Document.Prototype[property] = value; 453 } 454 455}); 456 457Document.Prototype = {$family: {name: 'document'}}; 458 459new Document(document); 460 461 462/* 463--- 464 465name: Array 466 467description: Contains Array Prototypes like each, contains, and erase. 468 469license: MIT-style license. 470 471requires: [$util, Array.each] 472 473provides: Array 474 475... 476*/ 477 478Array.implement({ 479 480 every: function(fn, bind){ 481 for (var i = 0, l = this.length; i < l; i++){ 482 if (!fn.call(bind, this[i], i, this)) return false; 483 } 484 return true; 485 }, 486 487 filter: function(fn, bind){ 488 var results = []; 489 for (var i = 0, l = this.length; i < l; i++){ 490 if (fn.call(bind, this[i], i, this)) results.push(this[i]); 491 } 492 return results; 493 }, 494 495 clean: function(){ 496 return this.filter($defined); 497 }, 498 499 indexOf: function(item, from){ 500 var len = this.length; 501 for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){ 502 if (this[i] === item) return i; 503 } 504 return -1; 505 }, 506 507 map: function(fn, bind){ 508 var results = []; 509 for (var i = 0, l = this.length; i < l; i++) results[i] = fn.call(bind, this[i], i, this); 510 return results; 511 }, 512 513 some: function(fn, bind){ 514 for (var i = 0, l = this.length; i < l; i++){ 515 if (fn.call(bind, this[i], i, this)) return true; 516 } 517 return false; 518 }, 519 520 associate: function(keys){ 521 var obj = {}, length = Math.min(this.length, keys.length); 522 for (var i = 0; i < length; i++) obj[keys[i]] = this[i]; 523 return obj; 524 }, 525 526 link: function(object){ 527 var result = {}; 528 for (var i = 0, l = this.length; i < l; i++){ 529 for (var key in object){ 530 if (object[key](this[i])){ 531 result[key] = this[i]; 532 delete object[key]; 533 break; 534 } 535 } 536 } 537 return result; 538 }, 539 540 contains: function(item, from){ 541 return this.indexOf(item, from) != -1; 542 }, 543 544 extend: function(array){ 545 for (var i = 0, j = array.length; i < j; i++) this.push(array[i]); 546 return this; 547 }, 548 549 getLast: function(){ 550 return (this.length) ? this[this.length - 1] : null; 551 }, 552 553 getRandom: function(){ 554 return (this.length) ? this[$random(0, this.length - 1)] : null; 555 }, 556 557 include: function(item){ 558 if (!this.contains(item)) this.push(item); 559 return this; 560 }, 561 562 combine: function(array){ 563 for (var i = 0, l = array.length; i < l; i++) this.include(array[i]); 564 return this; 565 }, 566 567 erase: function(item){ 568 for (var i = this.length; i--; i){ 569 if (this[i] === item) this.splice(i, 1); 570 } 571 return this; 572 }, 573 574 empty: function(){ 575 this.length = 0; 576 return this; 577 }, 578 579 flatten: function(){ 580 var array = []; 581 for (var i = 0, l = this.length; i < l; i++){ 582 var type = $type(this[i]); 583 if (!type) continue; 584 array = array.concat((type == 'array' || type == 'collection' || type == 'arguments') ? Array.flatten(this[i]) : this[i]); 585 } 586 return array; 587 }, 588 589 hexToRgb: function(array){ 590 if (this.length != 3) return null; 591 var rgb = this.map(function(value){ 592 if (value.length == 1) value += value; 593 return value.toInt(16); 594 }); 595 return (array) ? rgb : 'rgb(' + rgb + ')'; 596 }, 597 598 rgbToHex: function(array){ 599 if (this.length < 3) return null; 600 if (this.length == 4 && this[3] == 0 && !array) return 'transparent'; 601 var hex = []; 602 for (var i = 0; i < 3; i++){ 603 var bit = (this[i] - 0).toString(16); 604 hex.push((bit.length == 1) ? '0' + bit : bit); 605 } 606 return (array) ? hex : '#' + hex.join(''); 607 } 608 609}); 610 611 612/* 613--- 614 615name: Function 616 617description: Contains Function Prototypes like create, bind, pass, and delay. 618 619license: MIT-style license. 620 621requires: [Native, $util] 622 623provides: Function 624 625... 626*/ 627 628try { 629 delete Function.prototype.bind; 630} catch(e){} 631 632Function.implement({ 633 634 extend: function(properties){ 635 for (var property in properties) this[property] = properties[property]; 636 return this; 637 }, 638 639 create: function(options){ 640 var self = this; 641 options = options || {}; 642 return function(event){ 643 var args = options.arguments; 644 args = (args != undefined) ? $splat(args) : Array.slice(arguments, (options.event) ? 1 : 0); 645 if (options.event) args = [event || window.event].extend(args); 646 var returns = function(){
647 return self.apply(options.bind || null, args); 648 }; 649 if (options.delay) return setTimeout(returns, options.delay); 650 if (options.periodical) return setInterval(returns, options.periodical); 651 if (options.attempt) return $try(returns); 652 return returns(); 653 }; 654 }, 655 656 run: function(args, bind){ 657 return this.apply(bind, $splat(args)); 658 }, 659 660 pass: function(args, bind){ 661 return this.create({bind: bind, arguments: args}); 662 }, 663 664 bind: function(bind, args){ 665 return this.create({bind: bind, arguments: args}); 666 }, 667 668 bindWithEvent: function(bind, args){ 669 return this.create({bind: bind, arguments: args, event: true}); 670 }, 671 672 attempt: function(args, bind){ 673 return this.create({bind: bind, arguments: args, attempt: true})(); 674 }, 675 676 delay: function(delay, bind, args){ 677 return this.create({bind: bind, arguments: args, delay: delay})(); 678 }, 679 680 periodical: function(periodical, bind, args){ 681 return this.create({bind: bind, arguments: args, periodical: periodical})(); 682 } 683 684}); 685 686 687/* 688--- 689 690name: Number 691 692description: Contains Number Prototypes like limit, round, times, and ceil. 693 694license: MIT-style license. 695 696requires: [Native, $util] 697 698provides: Number 699 700... 701*/ 702 703Number.implement({ 704 705 limit: function(min, max){ 706 return Math.min(max, Math.max(min, this)); 707 }, 708 709 round: function(precision){ 710 precision = Math.pow(10, precision || 0); 711 return Math.round(this * precision) / precision; 712 }, 713 714 times: function(fn, bind){ 715 for (var i = 0; i < this; i++) fn.call(bind, i, this); 716 }, 717 718 toFloat: function(){ 719 return parseFloat(this); 720 }, 721 722 toInt: function(base){ 723 return parseInt(this, base || 10); 724 } 725 726}); 727 728Number.alias('times', 'each'); 729 730(function(math){ 731 var methods = {}; 732 math.each(function(name){ 733 if (!Number[name]) methods[name] = function(){ 734 return Math[name].apply(null, [this].concat($A(arguments))); 735 }; 736 }); 737 Number.implement(methods); 738})(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']); 739 740 741/* 742--- 743 744name: String 745 746description: Contains String Prototypes like camelCase, capitalize, test, and toInt. 747 748license: MIT-style license. 749 750requires: Native 751 752provides: String 753 754... 755*/ 756 757try { 758 delete String.prototype.contains; 759} catch(e){} 760 761String.implement({ 762 763 test: function(regex, params){ 764 return ((typeof regex == 'string') ? new RegExp(regex, params) : regex).test(this); 765 }, 766 767 contains: function(string, separator){ 768 return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : this.indexOf(string) > -1; 769 }, 770 771 trim: function(){ 772 return this.replace(/^\s+|\s+$/g, ''); 773 }, 774 775 clean: function(){ 776 return this.replace(/\s+/g, ' ').trim(); 777 }, 778 779 camelCase: function(){ 780 return this.replace(/-\D/g, function(match){ 781 return match.charAt(1).toUpperCase(); 782 }); 783 }, 784 785 hyphenate: function(){ 786 return this.replace(/[A-Z]/g, function(match){ 787 return ('-' + match.charAt(0).toLowerCase()); 788 }); 789 }, 790 791 capitalize: function(){ 792 return this.replace(/\b[a-z]/g, function(match){ 793 return match.toUpperCase(); 794 }); 795 }, 796 797 escapeRegExp: function(){ 798 return this.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1'); 799 }, 800 801 toInt: function(base){ 802 return parseInt(this, base || 10); 803 }, 804 805 toFloat: function(){ 806 return parseFloat(this); 807 }, 808 809 hexToRgb: function(array){ 810 var hex = this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/); 811 return (hex) ? hex.slice(1).hexToRgb(array) : null; 812 }, 813 814 rgbToHex: function(array){ 815 var rgb = this.match(/\d{1,3}/g); 816 return (rgb) ? rgb.rgbToHex(array) : null; 817 }, 818 819 stripScripts: function(option){ 820 var scripts = ''; 821 var text = this.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){ 822 scripts += arguments[1] + '\n'; 823 return ''; 824 }); 825 if (option === true) $exec(scripts); 826 else if ($type(option) == 'function') option(scripts, text); 827 return text; 828 }, 829 830 substitute: function(object, regexp){ 831 return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){ 832 if (match.charAt(0) == '\\') return match.slice(1); 833 return (object[name] != undefined) ? object[name] : ''; 834 }); 835 } 836 837}); 838 839 840/* 841--- 842 843name: Hash 844 845description: Contains Hash Prototypes. Provides a means for overcoming the JavaScript practical impossibility of extending native Objects. 846 847license: MIT-style license. 848 849requires: Hash.base 850 851provides: Hash 852 853... 854*/ 855 856Hash.implement({ 857 858 has: Object.prototype.hasOwnProperty, 859 860 keyOf: function(value){ 861 for (var key in this){ 862 if (this.hasOwnProperty(key) && this[key] === value) return key; 863 } 864 return null; 865 }, 866 867 hasValue: function(value){ 868 return (Hash.keyOf(this, value) !== null); 869 }, 870 871 extend: function(properties){ 872 Hash.each(properties || {}, function(value, key){ 873 Hash.set(this, key, value); 874 }, this); 875 return this; 876 }, 877 878 combine: function(properties){ 879 Hash.each(properties || {}, function(value, key){ 880 Hash.include(this, key, value); 881 }, this); 882 return this; 883 }, 884 885 erase: function(key){ 886 if (this.hasOwnProperty(key)) delete this[key]; 887 return this; 888 }, 889 890 get: function(key){ 891 return (this.hasOwnProperty(key)) ? this[key] : null; 892 }, 893 894 set: function(key, value){ 895 if (!this[key] || this.hasOwnProperty(key)) this[key] = value; 896 return this; 897 }, 898 899 empty: function(){ 900 Hash.each(this, function(value, key){ 901 delete this[key]; 902 }, this); 903 return this; 904 }, 905 906 include: function(key, value){ 907 if (this[key] == undefined) this[key] = value; 908 return this; 909 }, 910 911 map: function(fn, bind){ 912 var results = new Hash; 913 Hash.each(this, function(value, key){ 914 results.set(key, fn.call(bind, value, key, this)); 915 }, this); 916 return results; 917 }, 918 919 filter: function(fn, bind){ 920 var results = new Hash; 921 Hash.each(this, function(value, key){ 922 if (fn.call(bind, value, key, this)) results.set(key, value); 923 }, this); 924 return results; 925 }, 926 927 every: function(fn, bind){ 928 for (var key in this){ 929 if (this.hasOwnProperty(key) && !fn.call(bind, this[key], key)) return false;
930 } 931 return true; 932 }, 933 934 some: function(fn, bind){ 935 for (var key in this){ 936 if (this.hasOwnProperty(key) && fn.call(bind, this[key], key)) return true; 937 } 938 return false; 939 }, 940 941 getKeys: function(){ 942 var keys = []; 943 Hash.each(this, function(value, key){ 944 keys.push(key); 945 }); 946 return keys; 947 }, 948 949 getValues: function(){ 950 var values = []; 951 Hash.each(this, function(value){ 952 values.push(value); 953 }); 954 return values; 955 }, 956 957 toQueryString: function(base){ 958 var queryString = []; 959 Hash.each(this, function(value, key){ 960 if (base) key = base + '[' + key + ']'; 961 var result; 962 switch ($type(value)){ 963 case 'object': result = Hash.toQueryString(value, key); break; 964 case 'array': 965 var qs = {}; 966 value.each(function(val, i){ 967 qs[i] = val; 968 }); 969 result = Hash.toQueryString(qs, key); 970 break; 971 default: result = key + '=' + encodeURIComponent(value); 972 } 973 if (value != undefined) queryString.push(result); 974 }); 975 976 return queryString.join('&'); 977 } 978 979}); 980 981Hash.alias({keyOf: 'indexOf', hasValue: 'contains'}); 982 983 984/* 985--- 986 987name: Event 988 989description: Contains the Event Class, to make the event object cross-browser. 990 991license: MIT-style license. 992 993requires: [Window, Document, Hash, Array, Function, String] 994 995provides: Event 996 997... 998*/ 999 1000var Event = new Native({ 1001 1002 name: 'Event', 1003 1004 initialize: function(event, win){ 1005 win = win || window; 1006 var doc = win.document; 1007 event = event || win.event; 1008 if (event.$extended) return event; 1009 this.$extended = true; 1010 var type = event.type; 1011 var target = event.target || event.srcElement; 1012 while (target && target.nodeType == 3) target = target.parentNode; 1013 1014 if (type.test(/key/)){ 1015 var code = event.which || event.keyCode; 1016 var key = Event.Keys.keyOf(code); 1017 if (type == 'keydown'){ 1018 var fKey = code - 111; 1019 if (fKey > 0 && fKey < 13) key = 'f' + fKey; 1020 } 1021 key = key || String.fromCharCode(code).toLowerCase(); 1022 } else if (type.match(/(click|mouse|menu)/i)){ 1023 doc = (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body; 1024 var page = { 1025 x: event.pageX || event.clientX + doc.scrollLeft, 1026 y: event.pageY || event.clientY + doc.scrollTop 1027 }; 1028 var client = { 1029 x: (event.pageX) ? event.pageX - win.pageXOffset : event.clientX, 1030 y: (event.pageY) ? event.pageY - win.pageYOffset : event.clientY 1031 }; 1032 if (type.match(/DOMMouseScroll|mousewheel/)){ 1033 var wheel = (event.wheelDelta) ? event.wheelDelta / 120 : -(event.detail || 0) / 3; 1034 } 1035 var rightClick = (event.which == 3) || (event.button == 2); 1036 var related = null; 1037 if (type.match(/over|out/)){ 1038 switch (type){ 1039 case 'mouseover': related = event.relatedTarget || event.fromElement; break; 1040 case 'mouseout': related = event.relatedTarget || event.toElement; 1041 } 1042 if (!(function(){ 1043 while (related && related.nodeType == 3) related = related.parentNode; 1044 return true; 1045 }).create({attempt: Browser.Engine.gecko})()) related = false; 1046 } 1047 } 1048 1049 return $extend(this, { 1050 event: event, 1051 type: type, 1052 1053 page: page, 1054 client: client, 1055 rightClick: rightClick, 1056 1057 wheel: wheel, 1058 1059 relatedTarget: related, 1060 target: target, 1061 1062 code: code, 1063 key: key, 1064 1065 shift: event.shiftKey, 1066 control: event.ctrlKey, 1067 alt: event.altKey, 1068 meta: event.metaKey 1069 }); 1070 } 1071 1072}); 1073 1074Event.Keys = new Hash({ 1075 'enter': 13, 1076 'up': 38, 1077 'down': 40, 1078 'left': 37, 1079 'right': 39, 1080 'esc': 27, 1081 'space': 32, 1082 'backspace': 8, 1083 'tab': 9, 1084 'delete': 46 1085}); 1086 1087Event.implement({ 1088 1089 stop: function(){ 1090 return this.stopPropagation().preventDefault(); 1091 }, 1092 1093 stopPropagation: function(){ 1094 if (this.event.stopPropagation) this.event.stopPropagation(); 1095 else this.event.cancelBubble = true; 1096 return this; 1097 }, 1098 1099 preventDefault: function(){ 1100 if (this.event.preventDefault) this.event.preventDefault(); 1101 else this.event.returnValue = false; 1102 return this; 1103 } 1104 1105}); 1106 1107 1108/* 1109--- 1110 1111name: Class 1112 1113description: Contains the Class Function for easily creating, extending, and implementing reusable Classes. 1114 1115license: MIT-style license. 1116 1117requires: [$util, Native, Array, String, Function, Number, Hash] 1118 1119provides: Class 1120 1121... 1122*/ 1123 1124function Class(params){ 1125 1126 if (params instanceof Function) params = {initialize: params}; 1127 1128 var newClass = function(){ 1129 Object.reset(this); 1130 if (newClass._prototyping) return this; 1131 this._current = $empty; 1132 var value = (this.initialize) ? this.initialize.apply(this, arguments) : this; 1133 delete this._current; delete this.caller; 1134 return value; 1135 }.extend(this); 1136 1137 newClass.implement(params); 1138 1139 newClass.constructor = Class; 1140 newClass.prototype.constructor = newClass; 1141 1142 return newClass; 1143 1144}; 1145 1146Function.prototype.protect = function(){ 1147 this._protected = true; 1148 return this; 1149}; 1150 1151Object.reset = function(object, key){ 1152
1153 if (key == null){ 1154 for (var p in object) Object.reset(object, p); 1155 return object; 1156 } 1157 1158 delete object[key]; 1159 1160 switch ($type(object[key])){ 1161 case 'object': 1162 var F = function(){}; 1163 F.prototype = object[key]; 1164 var i = new F; 1165 object[key] = Object.reset(i); 1166 break; 1167 case 'array': object[key] = $unlink(object[key]); break; 1168 } 1169 1170 return object; 1171 1172}; 1173 1174new Native({name: 'Class', initialize: Class}).extend({ 1175 1176 instantiate: function(F){ 1177 F._prototyping = true; 1178 var proto = new F; 1179 delete F._prototyping; 1180 return proto; 1181 }, 1182 1183 wrap: function(self, key, method){ 1184 if (method._origin) method = method._origin; 1185 1186 return function(){ 1187 if (method._protected && this._current == null) throw new Error('The method "' + key + '" cannot be called.'); 1188 var caller = this.caller, current = this._current; 1189 this.caller = current; this._current = arguments.callee; 1190 var result = method.apply(this, arguments); 1191 this._current = current; this.caller = caller; 1192 return result; 1193 }.extend({_owner: self, _origin: method, _name: key}); 1194 1195 } 1196 1197}); 1198 1199Class.implement({ 1200 1201 implement: function(key, value){ 1202 1203 if ($type(key) == 'object'){ 1204 for (var p in key) this.implement(p, key[p]); 1205 return this; 1206 } 1207 1208 var mutator = Class.Mutators[key]; 1209 1210 if (mutator){ 1211 value = mutator.call(this, value); 1212 if (value == null) return this; 1213 } 1214 1215 var proto = this.prototype; 1216 1217 switch ($type(value)){ 1218 1219 case 'function': 1220 if (value._hidden) return this; 1221 proto[key] = Class.wrap(this, key, value); 1222 break; 1223 1224 case 'object': 1225 var previous = proto[key]; 1226 if ($type(previous) == 'object') $mixin(previous, value); 1227 else proto[key] = $unlink(value); 1228 break; 1229 1230 case 'array': 1231 proto[key] = $unlink(value); 1232 break; 1233 1234 default: proto[key] = value; 1235 1236 } 1237 1238 return this; 1239 1240 } 1241 1242}); 1243 1244Class.Mutators = { 1245 1246 Extends: function(parent){ 1247 1248 this.parent = parent; 1249 this.prototype = Class.instantiate(parent); 1250 1251 this.implement('parent', function(){ 1252 var name = this.caller._name, previous = this.caller._owner.parent.prototype[name]; 1253 if (!previous) throw new Error('The method "' + name + '" has no parent.'); 1254 return previous.apply(this, arguments); 1255 }.protect()); 1256 1257 }, 1258 1259 Implements: function(items){ 1260 $splat(items).each(function(item){ 1261 if (item instanceof Function) item = Class.instantiate(item); 1262 this.implement(item); 1263 }, this); 1264 1265 } 1266 1267}; 1268 1269 1270/* 1271--- 1272 1273name: Class.Extras 1274 1275description: Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks. 1276 1277license: MIT-style license. 1278 1279requires: Class 1280 1281provides: [Chain, Events, Options, Class.Extras] 1282 1283... 1284*/ 1285 1286var Chain = new Class({ 1287 1288 $chain: [], 1289 1290 chain: function(){ 1291 this.$chain.extend(Array.flatten(arguments)); 1292 return this; 1293 }, 1294 1295 callChain: function(){ 1296 return (this.$chain.length) ? this.$chain.shift().apply(this, arguments) : false; 1297 }, 1298 1299 clearChain: function(){ 1300 this.$chain.empty(); 1301 return this; 1302 } 1303 1304}); 1305 1306var Events = new Class({ 1307 1308 $events: {}, 1309 1310 addEvent: function(type, fn, internal){ 1311 type = Events.removeOn(type); 1312 if (fn != $empty){ 1313 this.$events[type] = this.$events[type] || []; 1314 this.$events[type].include(fn); 1315 if (internal) fn.internal = true; 1316 } 1317 return this; 1318 }, 1319 1320 addEvents: function(events){ 1321 for (var type in events) this.addEvent(type, events[type]); 1322 return this; 1323 }, 1324 1325 fireEvent: function(type, args, delay){ 1326 type = Events.removeOn(type); 1327 if (!this.$events || !this.$events[type]) return this; 1328 this.$events[type].each(function(fn){ 1329 fn.create({'bind': this, 'delay': delay, 'arguments': args})(); 1330 }, this); 1331 return this; 1332 }, 1333 1334 removeEvent: function(type, fn){ 1335 type = Events.removeOn(type); 1336 if (!this.$events[type]) return this; 1337 if (!fn.internal) this.$events[type].erase(fn); 1338 return this; 1339 }, 1340 1341 removeEvents: function(events){ 1342 var type; 1343 if ($type(events) == 'object'){ 1344 for (type in events) this.removeEvent(type, events[type]); 1345 return this; 1346 } 1347 if (events) events = Events.removeOn(events); 1348 for (type in this.$events){ 1349 if (events && events != type) continue; 1350 var fns = this.$events[type]; 1351 for (var i = fns.length; i--; i) this.removeEvent(type, fns[i]); 1352 } 1353 return this; 1354 } 1355 1356}); 1357 1358Events.removeOn = function(string){ 1359 return string.replace(/^on([A-Z])/, function(full, first){ 1360 return first.toLowerCase(); 1361 }); 1362}; 1363 1364var Options = new Class({ 1365 1366 setOptions: function(){ 1367 this.options = $merge.run([this.options].extend(arguments)); 1368 if (!this.addEvent) return this; 1369 for (var option in this.options){ 1370 if ($type(this.options[option]) != 'function' || !(/^on[A-Z]/).test(option)) continue; 1371 this.addEvent(option, this.options[option]); 1372 delete this.options[option]; 1373 } 1374 return this; 1375 } 1376 1377}); 1378 1379 1380/* 1381--- 1382 1383name: Element 1384 1385description: One of the most important items in MooTools. Contains the dollar function, the dollars function, and an handful of cross-browser, time-saver methods to let you easily work with HTML Elements. 1386 1387license: MIT-style license. 1388 1389requires: [Window, Document, Array, String, Function, Number, Hash] 1390 1391provides: [Element, Elements, $, $$, Iframe] 1392 1393... 1394*/ 1395
1396var Element = new Native({ 1397 1398 name: 'Element', 1399 1400 legacy: window.Element, 1401 1402 initialize: function(tag, props){ 1403 var konstructor = Element.Constructors.get(tag); 1404 if (konstructor) return konstructor(props); 1405 if (typeof tag == 'string') return document.newElement(tag, props); 1406 return document.id(tag).set(props); 1407 }, 1408 1409 afterImplement: function(key, value){ 1410 Element.Prototype[key] = value; 1411 if (Array[key]) return; 1412 Elements.implement(key, function(){ 1413 var items = [], elements = true; 1414 for (var i = 0, j = this.length; i < j; i++){ 1415 var returns = this[i][key].apply(this[i], arguments); 1416 items.push(returns); 1417 if (elements) elements = ($type(returns) == 'element'); 1418 } 1419 return (elements) ? new Elements(items) : items; 1420 }); 1421 } 1422 1423}); 1424 1425Element.Prototype = {$family: {name: 'element'}}; 1426 1427Element.Constructors = new Hash; 1428 1429var IFrame = new Native({ 1430 1431 name: 'IFrame', 1432 1433 generics: false, 1434 1435 initialize: function(){ 1436 var params = Array.link(arguments, {properties: Object.type, iframe: $defined}); 1437 var props = params.properties || {}; 1438 var iframe = document.id(params.iframe); 1439 var onload = props.onload || $empty; 1440 delete props.onload; 1441 props.id = props.name = $pick(props.id, props.name, iframe ? (iframe.id || iframe.name) : 'IFrame_' + $time()); 1442 iframe = new Element(iframe || 'iframe', props); 1443 var onFrameLoad = function(){ 1444 var host = $try(function(){ 1445 return iframe.contentWindow.location.host; 1446 }); 1447 if (!host || host == window.location.host){ 1448 var win = new Window(iframe.contentWindow); 1449 new Document(iframe.contentWindow.document); 1450 $extend(win.Element.prototype, Element.Prototype); 1451 } 1452 onload.call(iframe.contentWindow, iframe.contentWindow.document); 1453 }; 1454 var contentWindow = $try(function(){ 1455 return iframe.contentWindow; 1456 }); 1457 ((contentWindow && contentWindow.document.body) || window.frames[props.id]) ? onFrameLoad() : iframe.addListener('load', onFrameLoad); 1458 return iframe; 1459 } 1460 1461}); 1462 1463var Elements = new Native({ 1464 1465 initialize: function(elements, options){ 1466 options = $extend({ddup: true, cash: true}, options); 1467 elements = elements || []; 1468 if (options.ddup || options.cash){ 1469 var uniques = {}, returned = []; 1470 for (var i = 0, l = elements.length; i < l; i++){ 1471 var el = document.id(elements[i], !options.cash); 1472 if (options.ddup){ 1473 if (uniques[el.uid]) continue; 1474 uniques[el.uid] = true; 1475 } 1476 if (el) returned.push(el); 1477 } 1478 elements = returned; 1479 } 1480 return (options.cash) ? $extend(elements, this) : elements; 1481 } 1482 1483}); 1484 1485Elements.implement({ 1486 1487 filter: function(filter, bind){ 1488 if (!filter) return this; 1489 return new Elements(Array.filter(this, (typeof filter == 'string') ? function(item){ 1490 return item.match(filter); 1491 } : filter, bind)); 1492 } 1493 1494}); 1495 1496(function(){ 1497 1498/*<ltIE8>*/ 1499var createElementAcceptsHTML; 1500try { 1501 var x = document.createElement('<input name=x>'); 1502 createElementAcceptsHTML = (x.name == 'x'); 1503} catch(e){} 1504 1505var escapeQuotes = function(html){ 1506 return ('' + html).replace(/&/g,'&').replace(/"/g,'"'); 1507}; 1508/*</ltIE8>*/ 1509 1510Document.implement({ 1511 1512 newElement: function(tag, props){ 1513 if (props && props.checked != null) props.defaultChecked = props.checked; 1514 /*<ltIE8>*/// Fix for readonly name and type properties in IE < 8 1515 if (createElementAcceptsHTML && props){ 1516 tag = '<' + tag; 1517 if (props.name) tag += ' name="' + escapeQuotes(props.name) + '"'; 1518 if (props.type) tag += ' type="' + escapeQuotes(props.type) + '"'; 1519 tag += '>'; 1520 delete props.name; 1521 delete props.type; 1522 } 1523 /*</ltIE8>*/ 1524 return this.id(this.createElement(tag)).set(props); 1525 }, 1526 1527 newTextNode: function(text){ 1528 return this.createTextNode(text); 1529 }, 1530 1531 getDocument: function(){ 1532 return this; 1533 }, 1534 1535 getWindow: function(){ 1536 return this.window; 1537 }, 1538 1539 id: (function(){ 1540 1541 var types = { 1542 1543 string: function(id, nocash, doc){ 1544 id = doc.getElementById(id); 1545 return (id) ? types.element(id, nocash) : null; 1546 }, 1547 1548 element: function(el, nocash){ 1549 $uid(el); 1550 if (!nocash && !el.$family && !(/^object|embed$/i).test(el.tagName)){ 1551 var proto = Element.Prototype; 1552 for (var p in proto) el[p] = proto[p]; 1553 }; 1554 return el; 1555 }, 1556 1557 object: function(obj, nocash, doc){
1558 if (obj.toElement) return types.element(obj.toElement(doc), nocash); 1559 return null; 1560 } 1561 1562 }; 1563 1564 types.textnode = types.whitespace = types.window = types.document = $arguments(0); 1565 1566 return function(el, nocash, doc){ 1567 if (el && el.$family && el.uid) return el; 1568 var type = $type(el); 1569 return (types[type]) ? types[type](el, nocash, doc || document) : null; 1570 }; 1571 1572 })() 1573 1574}); 1575 1576})(); 1577 1578if (window.$ == null) Window.implement({ 1579 $: function(el, nc){ 1580 return document.id(el, nc, this.document); 1581 } 1582}); 1583 1584Window.implement({ 1585 1586 $$: function(selector){ 1587 if (arguments.length == 1 && typeof selector == 'string') return this.document.getElements(selector); 1588 var elements = []; 1589 var args = Array.flatten(arguments); 1590 for (var i = 0, l = args.length; i < l; i++){ 1591 var item = args[i]; 1592 switch ($type(item)){ 1593 case 'element': elements.push(item); break; 1594 case 'string': elements.extend(this.document.getElements(item, true)); 1595 } 1596 } 1597 return new Elements(elements); 1598 }, 1599 1600 getDocument: function(){ 1601 return this.document; 1602 }, 1603 1604 getWindow: function(){ 1605 return this; 1606 } 1607 1608}); 1609 1610Native.implement([Element, Document], { 1611 1612 getElement: function(selector, nocash){ 1613 return document.id(this.getElements(selector, true)[0] || null, nocash); 1614 }, 1615 1616 getElements: function(tags, nocash){ 1617 tags = tags.split(','); 1618 var elements = []; 1619 var ddup = (tags.length > 1); 1620 tags.each(function(tag){ 1621 var partial = this.getElementsByTagName(tag.trim()); 1622 (ddup) ? elements.extend(partial) : elements = partial; 1623 }, this); 1624 return new Elements(elements, {ddup: ddup, cash: !nocash}); 1625 } 1626 1627}); 1628 1629(function(){ 1630 1631var collected = {}, storage = {}; 1632var props = {input: 'checked', option: 'selected', textarea: (Browser.Engine.webkit && Browser.Engine.version < 420) ? 'innerHTML' : 'value'}; 1633 1634var get = function(uid){ 1635 return (storage[uid] || (storage[uid] = {})); 1636}; 1637 1638var clean = function(item, retain){ 1639 if (!item) return; 1640 var uid = item.uid; 1641 if (retain !== true) retain = false; 1642 if (Browser.Engine.trident){ 1643 if (item.clearAttributes){ 1644 var clone = retain && item.cloneNode(false); 1645 item.clearAttributes(); 1646 if (clone) item.mergeAttributes(clone); 1647 } else if (item.removeEvents){ 1648 item.removeEvents(); 1649 } 1650 if ((/object/i).test(item.tagName)){ 1651 for (var p in item){ 1652 if (typeof item[p] == 'function') item[p] = $empty; 1653 } 1654 Element.dispose(item); 1655 } 1656 } 1657 if (!uid) return; 1658 collected[uid] = storage[uid] = null; 1659}; 1660 1661var purge = function(){ 1662 Hash.each(collected, clean); 1663 if (Browser.Engine.trident) $A(document.getElementsByTagName('object')).each(clean); 1664 if (window.CollectGarbage) CollectGarbage(); 1665 collected = storage = null; 1666}; 1667 1668var walk = function(element, walk, start, match, all, nocash){ 1669 var el = element[start || walk]; 1670 var elements = []; 1671 while (el){ 1672 if (el.nodeType == 1 && (!match || Element.match(el, match))){ 1673 if (!all) return document.id(el, nocash); 1674 elements.push(el); 1675 } 1676 el = el[walk]; 1677 } 1678 return (all) ? new Elements(elements, {ddup: false, cash: !nocash}) : null; 1679}; 1680 1681var attributes = { 1682 'html': 'innerHTML', 1683 'class': 'className', 1684 'for': 'htmlFor', 1685 'defaultValue': 'defaultValue', 1686 'text': (Browser.Engine.trident || (Browser.Engine.webkit && Browser.Engine.version < 420)) ? 'innerText' : 'textContent' 1687}; 1688var bools = ['compact', 'nowrap', 'ismap', 'declare', 'noshade', 'checked', 'disabled', 'readonly', 'multiple', 'selected', 'noresize', 'defer']; 1689var camels = ['value', 'type', 'defaultValue', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan', 'frameBorder', 'maxLength', 'readOnly', 'rowSpan', 'tabIndex', 'useMap']; 1690 1691bools = bools.associate(bools); 1692 1693Hash.extend(attributes, bools); 1694Hash.extend(attributes, camels.associate(camels.map(String.toLowerCase))); 1695 1696var inserters = { 1697 1698 before: function(context, element){ 1699 if (element.parentNode) element.parentNode.insertBefore(context, element); 1700 }, 1701 1702 after: function(context, element){ 1703 if (!element.parentNode) return; 1704 var next = element.nextSibling; 1705 (next) ? element.parentNode.insertBefore(context, next) : element.parentNode.appendChild(context); 1706 }, 1707 1708 bottom: function(context, element){ 1709 element.appendChild(context); 1710 }, 1711 1712 top: function(context, element){ 1713 var first = element.firstChild; 1714 (first) ? element.insertBefore(context, first) : element.appendChild(context); 1715 } 1716 1717}; 1718 1719inserters.inside = inserters.bottom; 1720 1721Hash.each(inserters, function(inserter, where){ 1722 1723 where = where.capitalize(); 1724 1725 Element.implement('inject' + where, function(el){ 1726 inserter(this, document.id(el, true)); 1727 return this; 1728 }); 1729 1730 Element.implement('grab' + where, function(el){
1731 inserter(document.id(el, true), this); 1732 return this; 1733 }); 1734 1735}); 1736 1737Element.implement({ 1738 1739 set: function(prop, value){ 1740 switch ($type(prop)){ 1741 case 'object': 1742 for (var p in prop) this.set(p, prop[p]); 1743 break; 1744 case 'string': 1745 var property = Element.Properties.get(prop); 1746 (property && property.set) ? property.set.apply(this, Array.slice(arguments, 1)) : this.setProperty(prop, value); 1747 } 1748 return this; 1749 }, 1750 1751 get: function(prop){ 1752 var property = Element.Properties.get(prop); 1753 return (property && property.get) ? property.get.apply(this, Array.slice(arguments, 1)) : this.getProperty(prop); 1754 }, 1755 1756 erase: function(prop){ 1757 var property = Element.Properties.get(prop); 1758 (property && property.erase) ? property.erase.apply(this) : this.removeProperty(prop); 1759 return this; 1760 }, 1761 1762 setProperty: function(attribute, value){ 1763 var key = attributes[attribute]; 1764 if (value == undefined) return this.removeProperty(attribute); 1765 if (key && bools[attribute]) value = !!value; 1766 (key) ? this[key] = value : this.setAttribute(attribute, '' + value); 1767 return this; 1768 }, 1769 1770 setProperties: function(attributes){ 1771 for (var attribute in attributes) this.setProperty(attribute, attributes[attribute]); 1772 return this; 1773 }, 1774 1775 getProperty: function(attribute){ 1776 var key = attributes[attribute]; 1777 var value = (key) ? this[key] : this.getAttribute(attribute, 2); 1778 return (bools[attribute]) ? !!value : (key) ? value : value || null; 1779 }, 1780 1781 getProperties: function(){ 1782 var args = $A(arguments); 1783 return args.map(this.getProperty, this).associate(args); 1784 }, 1785 1786 removeProperty: function(attribute){ 1787 var key = attributes[attribute]; 1788 (key) ? this[key] = (key && bools[attribute]) ? false : '' : this.removeAttribute(attribute); 1789 return this; 1790 }, 1791 1792 removeProperties: function(){ 1793 Array.each(arguments, this.removeProperty, this); 1794 return this; 1795 }, 1796 1797 hasClass: function(className){ 1798 return this.className.contains(className, ' '); 1799 }, 1800 1801 addClass: function(className){ 1802 if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean(); 1803 return this; 1804 }, 1805 1806 removeClass: function(className){ 1807 this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1'); 1808 return this; 1809 }, 1810 1811 toggleClass: function(className){ 1812 return this.hasClass(className) ? this.removeClass(className) : this.addClass(className); 1813 }, 1814 1815 adopt: function(){ 1816 Array.flatten(arguments).each(function(element){ 1817 element = document.id(element, true); 1818 if (element) this.appendChild(element); 1819 }, this); 1820 return this; 1821 }, 1822 1823 appendText: function(text, where){ 1824 return this.grab(this.getDocument().newTextNode(text), where); 1825 }, 1826 1827 grab: function(el, where){ 1828 inserters[where || 'bottom'](document.id(el, true), this); 1829 return this; 1830 }, 1831 1832 inject: function(el, where){ 1833 inserters[where || 'bottom'](this, document.id(el, true)); 1834 return this; 1835 }, 1836 1837 replaces: function(el){ 1838 el = document.id(el, true); 1839 el.parentNode.replaceChild(this, el); 1840 return this; 1841 }, 1842 1843 wraps: function(el, where){ 1844 el = document.id(el, true); 1845 return this.replaces(el).grab(el, where); 1846 }, 1847 1848 getPrevious: function(match, nocash){ 1849 return walk(this, 'previousSibling', null, match, false, nocash); 1850 }, 1851 1852 getAllPrevious: function(match, nocash){ 1853 return walk(this, 'previousSibling', null, match, true, nocash); 1854 }, 1855 1856 getNext: function(match, nocash){ 1857 return walk(this, 'nextSibling', null, match, false, nocash); 1858 }, 1859 1860 getAllNext: function(match, nocash){ 1861 return walk(this, 'nextSibling', null, match, true, nocash); 1862 }, 1863 1864 getFirst: function(match, nocash){ 1865 return walk(this, 'nextSibling', 'firstChild', match, false, nocash); 1866 }, 1867 1868 getLast: function(match, nocash){ 1869 return walk(this, 'previousSibling', 'lastChild', match, false, nocash); 1870 }, 1871 1872 getParent: function(match, nocash){ 1873 return walk(this, 'parentNode', null, match, false, nocash); 1874 }, 1875 1876 getParents: function(match, nocash){ 1877 return walk(this, 'parentNode', null, match, true, nocash); 1878 }, 1879 1880 getSiblings: function(match, nocash){ 1881 return this.getParent().getChildren(match, nocash).erase(this); 1882 }, 1883 1884 getChildren: function(match, nocash){ 1885 return walk(this, 'nextSibling', 'firstChild', match, true, nocash); 1886 }, 1887
1888 getWindow: function(){ 1889 return this.ownerDocument.window; 1890 }, 1891 1892 getDocument: function(){ 1893 return this.ownerDocument; 1894 }, 1895 1896 getElementById: function(id, nocash){ 1897 var el = this.ownerDocument.getElementById(id); 1898 if (!el) return null; 1899 for (var parent = el.parentNode; parent != this; parent = parent.parentNode){ 1900 if (!parent) return null; 1901 } 1902 return document.id(el, nocash); 1903 }, 1904 1905 getSelected: function(){ 1906 return new Elements($A(this.options).filter(function(option){ 1907 return option.selected; 1908 })); 1909 }, 1910 1911 getComputedStyle: function(property){ 1912 if (this.currentStyle) return this.currentStyle[property.camelCase()]; 1913 var computed = this.getDocument().defaultView.getComputedStyle(this, null); 1914 return (computed) ? computed.getPropertyValue([property.hyphenate()]) : null; 1915 }, 1916 1917 toQueryString: function(){ 1918 var queryString = []; 1919 this.getElements('input, select, textarea', true).each(function(el){ 1920 if (!el.name || el.disabled || el.type == 'submit' || el.type == 'reset' || el.type == 'file') return; 1921 var value = (el.tagName.toLowerCase() == 'select') ? Element.getSelected(el).map(function(opt){ 1922 return opt.value; 1923 }) : ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) ? null : el.value; 1924 $splat(value).each(function(val){ 1925 if (typeof val != 'undefined') queryString.push(el.name + '=' + encodeURIComponent(val)); 1926 }); 1927 }); 1928 return queryString.join('&'); 1929 }, 1930 1931 clone: function(contents, keepid){ 1932 contents = contents !== false; 1933 var clone = this.cloneNode(contents); 1934 var clean = function(node, element){ 1935 if (!keepid) node.removeAttribute('id'); 1936 if (Browser.Engine.trident){ 1937 node.clearAttributes(); 1938 node.mergeAttributes(element); 1939 node.removeAttribute('uid'); 1940 if (node.options){ 1941 var no = node.options, eo = element.options; 1942 for (var j = no.length; j--;) no[j].selected = eo[j].selected; 1943 } 1944 } 1945 var prop = props[element.tagName.toLowerCase()]; 1946 if (prop && element[prop]) node[prop] = element[prop]; 1947 }; 1948 1949 if (contents){ 1950 var ce = clone.getElementsByTagName('*'), te = this.getElementsByTagName('*'); 1951 for (var i = ce.length; i--;) clean(ce[i], te[i]); 1952 } 1953 1954 clean(clone, this); 1955 return document.id(clone); 1956 }, 1957 1958 destroy: function(){ 1959 Element.empty(this); 1960 Element.dispose(this); 1961 clean(this, true); 1962 return null; 1963 }, 1964 1965 empty: function(){ 1966 $A(this.childNodes).each(function(node){ 1967 Element.destroy(node); 1968 }); 1969 return this; 1970 }, 1971 1972 dispose: function(){ 1973 return (this.parentNode) ? this.parentNode.removeChild(this) : this; 1974 }, 1975 1976 hasChild: function(el){ 1977 el = document.id(el, true); 1978 if (!el) return false; 1979 if (Browser.Engine.webkit && Browser.Engine.version < 420) return $A(this.getElementsByTagName(el.tagName)).contains(el); 1980 return (this.contains) ? (this != el && this.contains(el)) : !!(this.compareDocumentPosition(el) & 16); 1981 }, 1982 1983 match: function(tag){ 1984 return (!tag || (tag == this) || (Element.get(this, 'tag') == tag)); 1985 } 1986 1987}); 1988 1989Native.implement([Element, Window, Document], { 1990 1991 addListener: function(type, fn){ 1992 if (type == 'unload'){ 1993 var old = fn, self = this; 1994 fn = function(){ 1995 self.removeListener('unload', fn); 1996 old(); 1997 }; 1998 } else { 1999 collected[this.uid] = this; 2000 } 2001 if (this.addEventListener) this.addEventListener(type, fn, false); 2002 else this.attachEvent('on' + type, fn); 2003 return this; 2004 }, 2005 2006 removeListener: function(type, fn){ 2007 if (this.removeEventListener) this.removeEventListener(type, fn, false); 2008 else this.detachEvent('on' + type, fn); 2009 return this; 2010 }, 2011 2012 retrieve: function(property, dflt){ 2013 var storage = get(this.uid), prop = storage[property]; 2014 if (dflt != undefined && prop == undefined) prop = storage[property] = dflt; 2015 return $pick(prop); 2016 }, 2017 2018 store: function(property, value){ 2019 var storage = get(this.uid); 2020 storage[property] = value; 2021 return this; 2022 }, 2023 2024 eliminate: function(property){ 2025 var storage = get(this.uid); 2026 delete storage[property]; 2027 return this; 2028 } 2029 2030}); 2031 2032window.addListener('unload', purge); 2033 2034})(); 2035 2036Element.Properties = new Hash; 2037 2038Element.Properties.style = { 2039 2040 set: function(style){ 2041 this.style.cssText = style; 2042 }, 2043 2044 get: function(){ 2045 return this.style.cssText; 2046 }, 2047 2048 erase: function(){ 2049 this.style.cssText = ''; 2050 } 2051 2052}; 2053 2054Element.Properties.tag = { 2055 2056 get: function(){ 2057 return this.tagName.toLowerCase(); 2058 } 2059 2060}; 2061 2062Element.Properties.html = (function(){ 2063 var BUGGY_INNERHTML = true; 2064 try { 2065 var tester = document.createElement('tr'); 2066 tester.innerHTML = '<td>x'; 2067 tester = tester.firstChild; 2068 BUGGY_INNERHTML = !(tester.nodeName == 'TD' && tester.innerHTML == 'x'); 2069 } 2070 catch (e){} 2071 if (!BUGGY_INNERHTML) return { 2072 set: function(){ 2073 this.innerHTML = Array.flatten(arguments).join(''); 2074 } 2075 }; 2076 2077 var wrapper = document.createElement('div'); 2078 2079 var translations = { 2080 table: [1, '<table>', '</table>'], 2081 select: [1, '<select>', '</select>'], 2082 tbody: [2, '<table><tbody>', '</tbody></table>'], 2083 tr: [3, '<table><tbody><tr>', '</tr></tbody></table>'] 2084 }; 2085 translations.thead = translations.tfoot = translations.tbody; 2086 2087 var html = { 2088 set: function(){ 2089 var html = Array.flatten(arguments).join(''); 2090 var wrap = translations[this.get('tag')]; 2091 if (wrap){ 2092 var first = wrapper; 2093 first.innerHTML = wrap[1] + html + wrap[2]; 2094 for (var i = wrap[0]; i--;) first = first.firstChild; 2095 this.empty().adopt(first.childNodes); 2096 } else { 2097 this.innerHTML = html; 2098 } 2099 } 2100 }; 2101 2102 html.erase = html.set; 2103 2104 return html; 2105})(); 2106 2107if (Browser.Engine.webkit && Browser.Engine.version < 420) Element.Properties.text = { 2108 get: function(){ 2109 if (this.innerText) return this.innerText; 2110 var temp = this.ownerDocument.newElement('div', {html: this.innerHTML}).inject(this.ownerDocument.body); 2111 var text = temp.innerText; 2112 temp.destroy(); 2113 return text; 2114 } 2115}; 2116 2117 2118/* 2119--- 2120 2121name: Element.Event 2122 2123description: Contains Element methods for dealing with events. This file also includes mouseenter and mouseleave custom Element Events. 2124 2125license: MIT-style license. 2126 2127requires: [Element, Event] 2128 2129provides: Element.Event 2130 2131... 2132*/ 2133
2134Element.Properties.events = {set: function(events){ 2135 this.addEvents(events); 2136}}; 2137 2138Native.implement([Element, Window, Document], { 2139 2140 addEvent: function(type, fn){ 2141 var events = this.retrieve('events', {}); 2142 events[type] = events[type] || {'keys': [], 'values': []}; 2143 if (events[type].keys.contains(fn)) return this; 2144 events[type].keys.push(fn); 2145 var realType = type, custom = Element.Events.get(type), condition = fn, self = this; 2146 if (custom){ 2147 if (custom.onAdd) custom.onAdd.call(this, fn); 2148 if (custom.condition){ 2149 condition = function(event){ 2150 if (custom.condition.call(this, event)) return fn.call(this, event); 2151 return true; 2152 }; 2153 } 2154 realType = custom.base || realType; 2155 } 2156 var defn = function(){ 2157 return fn.call(self); 2158 }; 2159 var nativeEvent = Element.NativeEvents[realType]; 2160 if (nativeEvent){ 2161 if (nativeEvent == 2){ 2162 defn = function(event){ 2163 event = new Event(event, self.getWindow()); 2164 if (condition.call(self, event) === false) event.stop(); 2165 }; 2166 } 2167 this.addListener(realType, defn); 2168 } 2169 events[type].values.push(defn); 2170 return this; 2171 }, 2172 2173 removeEvent: function(type, fn){ 2174 var events = this.retrieve('events'); 2175 if (!events || !events[type]) return this; 2176 var pos = events[type].keys.indexOf(fn); 2177 if (pos == -1) return this; 2178 events[type].keys.splice(pos, 1); 2179 var value = events[type].values.splice(pos, 1)[0]; 2180 var custom = Element.Events.get(type); 2181 if (custom){ 2182 if (custom.onRemove) custom.onRemove.call(this, fn); 2183 type = custom.base || type; 2184 } 2185 return (Element.NativeEvents[type]) ? this.removeListener(type, value) : this; 2186 }, 2187 2188 addEvents: function(events){ 2189 for (var event in events) this.addEvent(event, events[event]); 2190 return this; 2191 }, 2192 2193 removeEvents: function(events){ 2194 var type; 2195 if ($type(events) == 'object'){ 2196 for (type in events) this.removeEvent(type, events[type]); 2197 return this; 2198 } 2199 var attached = this.retrieve('events'); 2200 if (!attached) return this; 2201 if (!events){ 2202 for (type in attached) this.removeEvents(type); 2203 this.eliminate('events'); 2204 } else if (attached[events]){ 2205 while (attached[events].keys[0]) this.removeEvent(events, attached[events].keys[0]); 2206 attached[events] = null; 2207 } 2208 return this; 2209 }, 2210 2211 fireEvent: function(type, args, delay){ 2212 var events = this.retrieve('events'); 2213 if (!events || !events[type]) return this; 2214 events[type].keys.each(function(fn){ 2215 fn.create({'bind': this, 'delay': delay, 'arguments': args})(); 2216 }, this); 2217 return this; 2218 }, 2219 2220 cloneEvents: function(from, type){ 2221 from = document.id(from); 2222 var fevents = from.retrieve('events'); 2223 if (!fevents) return this; 2224 if (!type){ 2225 for (var evType in fevents) this.cloneEvents(from, evType); 2226 } else if (fevents[type]){ 2227 fevents[type].keys.each(function(fn){ 2228 this.addEvent(type, fn); 2229 }, this); 2230 } 2231 return this; 2232 } 2233 2234}); 2235 2236// IE9 2237try { 2238 if (typeof HTMLElement != 'undefined') 2239 HTMLElement.prototype.fireEvent = Element.prototype.fireEvent; 2240} catch(e){} 2241 2242Element.NativeEvents = { 2243 click: 2, dblclick: 2, mouseup: 2, mousedown: 2, contextmenu: 2, //mouse buttons 2244 mousewheel: 2, DOMMouseScroll: 2, //mouse wheel 2245 mouseover: 2, mouseout: 2, mousemove: 2, selectstart: 2, selectend: 2, //mouse movement 2246 keydown: 2, keypress: 2, keyup: 2, //keyboard 2247 focus: 2, blur: 2, change: 2, reset: 2, select: 2, submit: 2, //form elements 2248 load: 1, unload: 1, beforeunload: 2, resize: 1, move: 1, DOMContentLoaded: 1, readystatechange: 1, //window 2249 error: 1, abort: 1, scroll: 1 //misc 2250}; 2251 2252(function(){ 2253 2254var $check = function(event){ 2255 var related = event.relatedTarget; 2256 if (related == undefined) return true; 2257 if (related === false) return false; 2258 return ($type(this) != 'document' && related != this && related.prefix != 'xul' && !this.hasChild(related)); 2259}; 2260 2261Element.Events = new Hash({ 2262 2263 mouseenter: { 2264 base: 'mouseover', 2265 condition: $check 2266 }, 2267 2268 mouseleave: { 2269 base: 'mouseout', 2270 condition: $check 2271 }, 2272 2273 mousewheel: { 2274 base: (Browser.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel' 2275 } 2276 2277}); 2278 2279})(); 2280 2281 2282/* 2283--- 2284 2285name: Element.Style 2286 2287description: Contains methods for interacting with the styles of Elements in a fas
2287hionable way. 2288 2289license: MIT-style license. 2290 2291requires: Element 2292 2293provides: Element.Style 2294 2295... 2296*/ 2297 2298Element.Properties.styles = {set: function(styles){ 2299 this.setStyles(styles); 2300}}; 2301 2302Element.Properties.opacity = { 2303 2304 set: function(opacity, novisibility){ 2305 if (!novisibility){ 2306 if (opacity == 0){ 2307 if (this.style.visibility != 'hidden') this.style.visibility = 'hidden'; 2308 } else { 2309 if (this.style.visibility != 'visible') this.style.visibility = 'visible'; 2310 } 2311 } 2312 if (!this.currentStyle || !this.currentStyle.hasLayout) this.style.zoom = 1; 2313 if (Browser.Engine.trident) this.style.filter = (opacity == 1) ? '' : 'alpha(opacity=' + opacity * 100 + ')'; 2314 this.style.opacity = opacity; 2315 this.store('opacity', opacity); 2316 }, 2317 2318 get: function(){ 2319 return this.retrieve('opacity', 1); 2320 } 2321 2322}; 2323 2324Element.implement({ 2325 2326 setOpacity: function(value){ 2327 return this.set('opacity', value, true); 2328 }, 2329 2330 getOpacity: function(){ 2331 return this.get('opacity'); 2332 }, 2333 2334 setStyle: function(property, value){ 2335 switch (property){ 2336 case 'opacity': return this.set('opacity', parseFloat(value)); 2337 case 'float': property = (Browser.Engine.trident) ? 'styleFloat' : 'cssFloat'; 2338 } 2339 property = property.camelCase(); 2340 if ($type(value) != 'string'){ 2341 var map = (Element.Styles.get(property) || '@').split(' '); 2342 value = $splat(value).map(function(val, i){ 2343 if (!map[i]) return ''; 2344 return ($type(val) == 'number') ? map[i].replace('@', Math.round(val)) : val; 2345 }).join(' '); 2346 } else if (value == String(Number(value))){ 2347 value = Math.round(value); 2348 } 2349 this.style[property] = value; 2350 return this; 2351 }, 2352 2353 getStyle: function(property){ 2354 switch (property){ 2355 case 'opacity': return this.get('opacity'); 2356 case 'float': property = (Browser.Engine.trident) ? 'styleFloat' : 'cssFloat'; 2357 } 2358 property = property.camelCase(); 2359 var result = this.style[property]; 2360 if (!$chk(result)){ 2361 result = []; 2362 for (var style in Element.ShortStyles){ 2363 if (property != style) continue; 2364 for (var s in Element.ShortStyles[style]) result.push(this.getStyle(s)); 2365 return result.join(' '); 2366 } 2367 result = this.getComputedStyle(property); 2368 } 2369 if (result){ 2370 result = String(result); 2371 var color = result.match(/rgba?\([\d\s,]+\)/); 2372 if (color) result = result.replace(color[0], color[0].rgbToHex()); 2373 } 2374 if (Browser.Engine.presto || (Browser.Engine.trident && !$chk(parseInt(result, 10)))){ 2375 if (property.test(/^(height|width)$/)){ 2376 var values = (property == 'width') ? ['left', 'right'] : ['top', 'bottom'], size = 0; 2377 values.each(function(value){ 2378 size += this.getStyle('border-' + value + '-width').toInt() + this.getStyle('padding-' + value).toInt(); 2379 }, this); 2380 return this['offset' + property.capitalize()] - size + 'px'; 2381 } 2382 if ((Browser.Engine.presto) && String(result).test('px')) return result; 2383 if (property.test(/(border(.+)Width|margin|padding)/)) return '0px'; 2384 } 2385 return result; 2386 }, 2387 2388 setStyles: function(styles){ 2389 for (var style in styles) this.setStyle(style, styles[style]); 2390 return this; 2391 }, 2392 2393 getStyles: function(){ 2394 var result = {}; 2395 Array.flatten(arguments).each(function(key){ 2396 result[key] = this.getStyle(key); 2397 }, this); 2398 return result; 2399 } 2400 2401}); 2402 2403Element.Styles = new Hash({ 2404 left: '@px', top: '@px', bottom: '@px', right: '@px', 2405 width: '@px', height: '@px', maxWidth: '@px', maxHeight: '@px', minWidth: '@px', minHeight: '@px', 2406 backgroundColor: 'rgb(@, @, @)', backgroundPosition: '@px @px', color: 'rgb(@, @, @)', 2407 fontSize: '@px', letterSpacing: '@px', lineHeight: '@px', clip: 'rect(@px @px @px @px)', 2408 margin: '@px @px @px @px', padding: '@px @px @px @px', border: '@px @ rgb(@, @, @) @px @ rgb(@, @, @) @px @ rgb(@, @, @)', 2409 borderWidth: '@px @px @px @px', borderStyle: '@ @ @ @', borderColor: 'rgb(@, @, @) rgb(@, @, @) rgb(@, @, @) rgb(@, @, @)', 2410 zIndex: '@', 'zoom': '@', fontWeight: '@', textIndent: '@px', opacity: '@' 2411}); 2412 2413Element.ShortStyles = {margin: {}, padding: {}, border: {}, borderWidth: {}, borderStyle: {}, borderColor: {}}; 2414 2415['Top', 'Right', 'Bottom', 'Left'].each(function(direction){ 2416 var Short = Element.ShortStyles; 2417 var All = Element.Styles; 2418 ['margin', 'padding'].each(function(style){ 2419 var sd = style + direction; 2420 Short[style][sd] = All[sd] = '@px'; 2421 }); 2422 var bd = 'border' + direction; 2423 Short.border[bd] = All[bd] = '@px @ rgb(@, @, @)'; 2424 var bdw = bd + 'Width', bds = bd + 'Style', bdc = bd + 'Color'; 2425 Short[bd] = {}; 2426 Short.borderWidth[bdw] = Short[bd][bdw] = All[bdw] = '@px'; 2427 Short.borderStyle[bds] = Short[bd][bds] = All[bds] = '@'; 2428 Short.borderColor[bdc] = Short[bd][bdc] = All[bdc] = 'rgb(@, @, @)'; 2429}); 2430 2431 2432/* 2433--- 2434 2435name: Element.Dimensions 2436 2437description: Contains methods to work with size, scroll, or positioning of Elements and the window object. 2438 2439license: MIT-style license. 2440 2441credits: 2442 - Element positioning based on the [qooxdoo](http://qooxdoo.org/) code and smart browser fixes, [LGPL License](http://www.gnu.org/licenses/lgpl.html). 2443 - Viewport dimensions based on [YUI](http://developer.yahoo.com/yui
2443/) code, [BSD License](http://developer.yahoo.com/yui/license.html). 2444 2445requires: Element 2446 2447provides: Element.Dimensions 2448 2449... 2450*/ 2451 2452(function(){ 2453 2454Element.implement({ 2455 2456 scrollTo: function(x, y){ 2457 if (isBody(this)){ 2458 this.getWindow().scrollTo(x, y); 2459 } else { 2460 this.scrollLeft = x; 2461 this.scrollTop = y; 2462 } 2463 return this; 2464 }, 2465 2466 getSize: function(){ 2467 if (isBody(this)) return this.getWindow().getSize(); 2468 return {x: this.offsetWidth, y: this.offsetHeight}; 2469 }, 2470 2471 getScrollSize: function(){ 2472 if (isBody(this)) return this.getWindow().getScrollSize(); 2473 return {x: this.scrollWidth, y: this.scrollHeight}; 2474 }, 2475 2476 getScroll: function(){ 2477 if (isBody(this)) return this.getWindow().getScroll(); 2478 return {x: this.scrollLeft, y: this.scrollTop}; 2479 }, 2480 2481 getScrolls: function(){ 2482 var element = this, position = {x: 0, y: 0}; 2483 while (element && !isBody(element)){ 2484 position.x += element.scrollLeft; 2485 position.y += element.scrollTop; 2486 element = element.parentNode; 2487 } 2488 return position; 2489 }, 2490 2491 getOffsetParent: function(){ 2492 var element = this; 2493 if (isBody(element)) return null; 2494 if (!Browser.Engine.trident) return element.offsetParent; 2495 while ((element = element.parentNode) && !isBody(element)){ 2496 if (styleString(element, 'position') != 'static') return element; 2497 } 2498 return null; 2499 }, 2500 2501 getOffsets: function(){ 2502 if (this.getBoundingClientRect){ 2503 var bound = this.getBoundingClientRect(), 2504 html = document.id(this.getDocument().documentElement), 2505 htmlScroll = html.getScroll(), 2506 elemScrolls = this.getScrolls(), 2507 elemScroll = this.getScroll(), 2508 isFixed = (styleString(this, 'position') == 'fixed'); 2509 2510 return { 2511 x: bound.left.toInt() + elemScrolls.x - elemScroll.x + ((isFixed) ? 0 : htmlScroll.x) - html.clientLeft, 2512 y: bound.top.toInt() + elemScrolls.y - elemScroll.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop 2513 }; 2514 } 2515 2516 var element = this, position = {x: 0, y: 0}; 2517 if (isBody(this)) return position; 2518 2519 while (element && !isBody(element)){ 2520 position.x += element.offsetLeft; 2521 position.y += element.offsetTop; 2522 2523 if (Browser.Engine.gecko){ 2524 if (!borderBox(element)){ 2525 position.x += leftBorder(element); 2526 position.y += topBorder(element); 2527 } 2528 var parent = element.parentNode; 2529 if (parent && styleString(parent, 'overflow') != 'visible'){ 2530 position.x += leftBorder(parent); 2531 position.y += topBorder(parent); 2532 } 2533 } else if (element != this && Browser.Engine.webkit){ 2534 position.x += leftBorder(element); 2535 position.y += topBorder(element); 2536 } 2537 2538 element = element.offsetParent; 2539 } 2540 if (Browser.Engine.gecko && !borderBox(this)){ 2541 position.x -= leftBorder(this); 2542 position.y -= topBorder(this); 2543 } 2544 return position; 2545 }, 2546 2547 getPosition: function(relative){ 2548 if (isBody(this)) return {x: 0, y: 0}; 2549 var offset = this.getOffsets(), 2550 scroll = this.getScrolls(); 2551 var position = { 2552 x: offset.x - scroll.x, 2553 y: offset.y - scroll.y 2554 }; 2555 var relativePosition = (relative && (relative = document.id(relative))) ? relative.getPosition() : {x: 0, y: 0}; 2556 return {x: position.x - relativePosition.x, y: position.y - relativePosition.y}; 2557 }, 2558 2559 getCoordinates: function(element){ 2560 if (isBody(this)) return this.getWindow().getCoordinates(); 2561 var position = this.getPosition(element), 2562 size = this.getSize(); 2563 var obj = { 2564 left: position.x, 2565 top: position.y, 2566 width: size.x, 2567 height: size.y 2568 }; 2569 obj.right = obj.left + obj.width; 2570 obj.bottom = obj.top + obj.height; 2571 return obj; 2572 }, 2573 2574 computePosition: function(obj){ 2575 return { 2576 left: obj.x - styleNumber(this, 'margin-left'), 2577 top: obj.y - styleNumber(this, 'margin-top') 2578 }; 2579 }, 2580 2581 setPosition: function(obj){ 2582 return this.setStyles(this.computePosition(obj)); 2583 } 2584 2585}); 2586 2587 2588Native.implement([Document, Window], { 2589 2590 getSize: function(){ 2591 if (Browser.Engine.presto || Browser.Engine.webkit){ 2592 var win = this.getWindow(); 2593 return {x: win.innerWidth, y: win.innerHeight}; 2594 } 2595 var doc = getCompatElement(this); 2596 return {x: doc.clientWidth, y: doc.clientHeight}; 2597 }, 2598 2599 getScroll: function(){ 2600 var win = this.getWindow(), doc = getCompatElement(this); 2601 return {x: win.pageXOffset || doc.scrollLeft, y: win.pageYOffset || doc.scrollTop}; 2602 }, 2603 2604 getScrollSize: function(){
2605 var doc = getCompatElement(this), min = this.getSize(); 2606 return {x: Math.max(doc.scrollWidth, min.x), y: Math.max(doc.scrollHeight, min.y)}; 2607 }, 2608 2609 getPosition: function(){ 2610 return {x: 0, y: 0}; 2611 }, 2612 2613 getCoordinates: function(){ 2614 var size = this.getSize(); 2615 return {top: 0, left: 0, bottom: size.y, right: size.x, height: size.y, width: size.x}; 2616 } 2617 2618}); 2619 2620// private methods 2621 2622var styleString = Element.getComputedStyle; 2623 2624function styleNumber(element, style){ 2625 return styleString(element, style).toInt() || 0; 2626}; 2627 2628function borderBox(element){ 2629 return styleString(element, '-moz-box-sizing') == 'border-box'; 2630}; 2631 2632function topBorder(element){ 2633 return styleNumber(element, 'border-top-width'); 2634}; 2635 2636function leftBorder(element){ 2637 return styleNumber(element, 'border-left-width'); 2638}; 2639 2640function isBody(element){ 2641 return (/^(?:body|html)$/i).test(element.tagName); 2642}; 2643 2644function getCompatElement(element){ 2645 var doc = element.getDocument(); 2646 return (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body; 2647}; 2648 2649})(); 2650 2651//aliases 2652Element.alias('setPosition', 'position'); //compatability 2653 2654Native.implement([Window, Document, Element], { 2655 2656 getHeight: function(){ 2657 return this.getSize().y; 2658 }, 2659 2660 getWidth: function(){ 2661 return this.getSize().x; 2662 }, 2663 2664 getScrollTop: function(){ 2665 return this.getScroll().y; 2666 }, 2667 2668 getScrollLeft: function(){ 2669 return this.getScroll().x; 2670 }, 2671 2672 getScrollHeight: function(){ 2673 return this.getScrollSize().y; 2674 }, 2675 2676 getScrollWidth: function(){ 2677 return this.getScrollSize().x; 2678 }, 2679 2680 getTop: function(){ 2681 return this.getPosition().y; 2682 }, 2683 2684 getLeft: function(){ 2685 return this.getPosition().x; 2686 } 2687 2688}); 2689 2690 2691/* 2692--- 2693 2694name: Selectors 2695 2696description: Adds advanced CSS-style querying capabilities for targeting HTML Elements. Includes pseudo selectors. 2697 2698license: MIT-style license. 2699 2700requires: Element 2701 2702provides: Selectors 2703 2704... 2705*/ 2706 2707Native.implement([Document, Element], { 2708 2709 getElements: function(expression, nocash){ 2710 expression = expression.split(','); 2711 var items, local = {}; 2712 for (var i = 0, l = expression.length; i < l; i++){ 2713 var selector = expression[i], elements = Selectors.Utils.search(this, selector, local); 2714 if (i != 0 && elements.item) elements = $A(elements); 2715 items = (i == 0) ? elements : (items.item) ? $A(items).concat(elements) : items.concat(elements); 2716 } 2717 return new Elements(items, {ddup: (expression.length > 1), cash: !nocash}); 2718 } 2719 2720}); 2721 2722Element.implement({ 2723 2724 match: function(selector){ 2725 if (!selector || (selector == this)) return true; 2726 var tagid = Selectors.Utils.parseTagAndID(selector); 2727 var tag = tagid[0], id = tagid[1]; 2728 if (!Selectors.Filters.byID(this, id) || !Selectors.Filters.byTag(this, tag)) return false; 2729 var parsed = Selectors.Utils.parseSelector(selector); 2730 return (parsed) ? Selectors.Utils.filter(this, parsed, {}) : true; 2731 } 2732 2733}); 2734 2735var Selectors = {Cache: {nth: {}, parsed: {}}}; 2736 2737Selectors.RegExps = { 2738 id: (/#([\w-]+)/), 2739 tag: (/^(\w+|\*)/), 2740 quick: (/^(\w+|\*)$/), 2741 splitter: (/\s*([+>~\s])\s*([a-zA-Z#.*:\[])/g), 2742 combined: (/\.([\w-]+)|\[(\w+)(?:([!*^$~|]?=)(["']?)([^\4]*?)\4)?\]|:([\w-]+)(?:\(["']?(.*?)?["']?\)|$)/g) 2743}; 2744 2745Selectors.Utils = { 2746 2747 chk: function(item, uniques){ 2748 if (!uniques) return true; 2749 var uid = $uid(item); 2750 if (!uniques[uid]) return uniques[uid] = true; 2751 return false; 2752 }, 2753 2754 parseNthArgument: function(argument){ 2755 if (Selectors.Cache.nth[argument]) return Selectors.Cache.nth[argument]; 2756 var parsed = argument.match(/^([+-]?\d*)?([a-z]+)?([+-]?\d*)?$/); 2757 if (!parsed) return false; 2758 var inta = parseInt(parsed[1], 10); 2759 var a = (inta || inta === 0) ? inta : 1; 2760 var special = parsed[2] || false; 2761 var b = parseInt(parsed[3], 10) || 0; 2762 if (a != 0){ 2763 b--; 2764 while (b < 1) b += a; 2765 while (b >= a) b -= a; 2766 } else { 2767 a = b; 2768 special = 'index'; 2769 } 2770 switch (special){ 2771 case 'n': parsed = {a: a, b: b, special: 'n'}; break; 2772 case 'odd': parsed = {a: 2, b: 0, special: 'n'}; break; 2773 case 'even': parsed = {a: 2, b: 1, special: 'n'}; break; 2774 case 'first': parsed = {a: 0, special: 'index'}; break; 2775 case 'last': parsed = {special: 'last-child'}; break; 2776 case 'only': parsed = {special: 'only-child'}; break; 2777 default: parsed = {a: (a - 1), special: 'index'}; 2778 } 2779 2780 return Selectors.Cache.nth[argument] = parsed; 2781 }, 2782 2783 parseSelector: function(selector){ 2784 if (Selectors.Cache.parsed[selector]) return Selectors.Cache.parsed[selector]; 2785 var m, parsed = {classes: [], pseudos: [], attributes: []}; 2786 while ((m = Selectors.RegExps.combined.exec(selector))){ 2787 var cn = m[1], an = m[2], ao = m[3], av = m[5], pn = m[6], pa = m[7]; 2788 if (cn){ 2789 parsed.classes.push(cn); 2790 } else if (pn){ 2791 var parser = Selectors.Pseudo.get(pn); 2792 if (parser) parsed.pseudos.push({parser: parser, argument: pa}); 2793 else parsed.attributes.push({name: pn, operator: '=', value: pa}); 2794 } else if (an){ 2795 parsed.attributes.push({name: an, operator: ao, value: av}); 2796 } 2797 } 2798 if (!parsed.classes.length) delete parsed.classes; 2799 if (!parsed.attributes.length) delete parsed.attributes; 2800 if (!parsed.pseudos.length) delete parsed.pseudos; 2801 if (!parsed.classes && !parsed.attributes && !parsed.pseudos) parsed = null; 2802 return Selectors.Cache.parsed[selector] = parsed; 2803 }, 2804 2805 parseTagAndID: function(selector){ 2806 var tag = selector.match(Selectors.RegExps.tag); 2807 var id = selector.match(Selectors.RegExps.id); 2808 return [(tag) ? tag[1] : '*', (id) ? id[1] : false]; 2809 }, 2810 2811 filter: function(item, parsed, local){ 2812 var i; 2813 if (parsed.classes){ 2814 for (i = parsed.classes.length; i--; i){ 2815 var cn = parsed.classes[i]; 2816 if (!Selectors.Filters.byClass(item, cn)) return false;
2817 } 2818 } 2819 if (parsed.attributes){ 2820 for (i = parsed.attributes.length; i--; i){ 2821 var att = parsed.attributes[i]; 2822 if (!Selectors.Filters.byAttribute(item, att.name, att.operator, att.value)) return false; 2823 } 2824 } 2825 if (parsed.pseudos){ 2826 for (i = parsed.pseudos.length; i--; i){ 2827 var psd = parsed.pseudos[i]; 2828 if (!Selectors.Filters.byPseudo(item, psd.parser, psd.argument, local)) return false; 2829 } 2830 } 2831 return true; 2832 }, 2833 2834 getByTagAndID: function(ctx, tag, id){ 2835 if (id){ 2836 var item = (ctx.getElementById) ? ctx.getElementById(id, true) : Element.getElementById(ctx, id, true); 2837 return (item && Selectors.Filters.byTag(item, tag)) ? [item] : []; 2838 } else { 2839 return ctx.getElementsByTagName(tag); 2840 } 2841 }, 2842 2843 search: function(self, expression, local){ 2844 var splitters = []; 2845 2846 var selectors = expression.trim().replace(Selectors.RegExps.splitter, function(m0, m1, m2){ 2847 splitters.push(m1); 2848 return ':)' + m2; 2849 }).split(':)'); 2850 2851 var items, filtered, item; 2852 2853 for (var i = 0, l = selectors.length; i < l; i++){ 2854 2855 var selector = selectors[i]; 2856 2857 if (i == 0 && Selectors.RegExps.quick.test(selector)){ 2858 items = self.getElementsByTagName(selector); 2859 continue; 2860 } 2861 2862 var splitter = splitters[i - 1]; 2863 2864 var tagid = Selectors.Utils.parseTagAndID(selector); 2865 var tag = tagid[0], id = tagid[1]; 2866 2867 if (i == 0){ 2868 items = Selectors.Utils.getByTagAndID(self, tag, id); 2869 } else { 2870 var uniques = {}, found = []; 2871 for (var j = 0, k = items.length; j < k; j++) found = Selectors.Getters[splitter](found, items[j], tag, id, uniques); 2872 items = found; 2873 } 2874 2875 var parsed = Selectors.Utils.parseSelector(selector); 2876 2877 if (parsed){ 2878 filtered = []; 2879 for (var m = 0, n = items.length; m < n; m++){ 2880 item = items[m]; 2881 if (Selectors.Utils.filter(item, parsed, local)) filtered.push(item); 2882 } 2883 items = filtered; 2884 } 2885 2886 } 2887 2888 return items; 2889 2890 } 2891 2892}; 2893 2894Selectors.Getters = { 2895 2896 ' ': function(found, self, tag, id, uniques){ 2897 var items = Selectors.Utils.getByTagAndID(self, tag, id); 2898 for (var i = 0, l = items.length; i < l; i++){ 2899 var item = items[i]; 2900 if (Selectors.Utils.chk(item, uniques)) found.push(item); 2901 } 2902 return found; 2903 }, 2904 2905 '>': function(found, self, tag, id, uniques){ 2906 var children = Selectors.Utils.getByTagAndID(self, tag, id); 2907 for (var i = 0, l = children.length; i < l; i++){ 2908 var child = children[i]; 2909 if (child.parentNode == self && Selectors.Utils.chk(child, uniques)) found.push(child); 2910 } 2911 return found; 2912 }, 2913 2914 '+': function(found, self, tag, id, uniques){ 2915 while ((self = self.nextSibling)){ 2916 if (self.nodeType == 1){ 2917 if (Selectors.Utils.chk(self, uniques) && Selectors.Filters.byTag(self, tag) && Selectors.Filters.byID(self, id)) found.push(self); 2918 break; 2919 } 2920 } 2921 return found; 2922 }, 2923 2924 '~': function(found, self, tag, id, uniques){ 2925 while ((self = self.nextSibling)){ 2926 if (self.nodeType == 1){ 2927 if (!Selectors.Utils.chk(self, uniques)) break; 2928 if (Selectors.Filters.byTag(self, tag) && Selectors.Filters.byID(self, id)) found.push(self); 2929 } 2930 } 2931 return found; 2932 } 2933 2934}; 2935 2936Selectors.Filters = { 2937 2938 byTag: function(self, tag){ 2939 return (tag == '*' || (self.tagName && self.tagName.toLowerCase() == tag)); 2940 }, 2941 2942 byID: function(self, id){ 2943 return (!id || (self.id && self.id == id)); 2944 }, 2945 2946 byClass: function(self, klass){ 2947 return (self.className && self.className.contains && self.className.contains(klass, ' ')); 2948 }, 2949 2950 byPseudo: function(self, parser, argument, local){ 2951 return parser.call(self, argument, local); 2952 }, 2953 2954 byAttribute: function(self, name, operator, value){ 2955 var result = Element.prototype.getProperty.call(self, name); 2956 if (!result) return (operator == '!='); 2957 if (!operator || value == undefined) return true; 2958 switch (operator){ 2959 case '=': return (result == value); 2960 case '*=': return (result.contains(value)); 2961 case '^=': return (result.substr(0, value.length) == value); 2962 case '$=': return (result.substr(result.length - value.length) == value); 2963 case '!=': return (result != value); 2964 case '~=': return result.contains(value, ' '); 2965 case '|=': return result.contains(value, '-'); 2966 } 2967 return false;
2968 } 2969 2970}; 2971 2972Selectors.Pseudo = new Hash({ 2973 2974 // w3c pseudo selectors 2975 2976 checked: function(){ 2977 return this.checked; 2978 }, 2979 2980 empty: function(){ 2981 return !(this.innerText || this.textContent || '').length; 2982 }, 2983 2984 not: function(selector){ 2985 return !Element.match(this, selector); 2986 }, 2987 2988 contains: function(text){ 2989 return (this.innerText || this.textContent || '').contains(text); 2990 }, 2991 2992 'first-child': function(){ 2993 return Selectors.Pseudo.index.call(this, 0); 2994 }, 2995 2996 'last-child': function(){ 2997 var element = this; 2998 while ((element = element.nextSibling)){ 2999 if (element.nodeType == 1) return false; 3000 } 3001 return true; 3002 }, 3003 3004 'only-child': function(){ 3005 var prev = this; 3006 while ((prev = prev.previousSibling)){ 3007 if (prev.nodeType == 1) return false; 3008 } 3009 var next = this; 3010 while ((next = next.nextSibling)){ 3011 if (next.nodeType == 1) return false; 3012 } 3013 return true; 3014 }, 3015 3016 'nth-child': function(argument, local){ 3017 argument = (argument == undefined) ? 'n' : argument; 3018 var parsed = Selectors.Utils.parseNthArgument(argument); 3019 if (parsed.special != 'n') return Selectors.Pseudo[parsed.special].call(this, parsed.a, local); 3020 var count = 0; 3021 local.positions = local.positions || {}; 3022 var uid = $uid(this); 3023 if (!local.positions[uid]){ 3024 var self = this; 3025 while ((self = self.previousSibling)){ 3026 if (self.nodeType != 1) continue; 3027 count ++; 3028 var position = local.positions[$uid(self)]; 3029 if (position != undefined){ 3030 count = position + count; 3031 break; 3032 } 3033 } 3034 local.positions[uid] = count; 3035 } 3036 return (local.positions[uid] % parsed.a == parsed.b); 3037 }, 3038 3039 // custom pseudo selectors 3040 3041 index: function(index){ 3042 var element = this, count = 0; 3043 while ((element = element.previousSibling)){ 3044 if (element.nodeType == 1 && ++count > index) return false; 3045 } 3046 return (count == index); 3047 }, 3048 3049 even: function(argument, local){ 3050 return Selectors.Pseudo['nth-child'].call(this, '2n+1', local); 3051 }, 3052 3053 odd: function(argument, local){ 3054 return Selectors.Pseudo['nth-child'].call(this, '2n', local); 3055 }, 3056 3057 selected: function(){ 3058 return this.selected; 3059 }, 3060 3061 enabled: function(){ 3062 return (this.disabled === false); 3063 } 3064 3065}); 3066 3067 3068/* 3069--- 3070 3071name: DomReady 3072 3073description: Contains the custom event domready. 3074 3075license: MIT-style license. 3076 3077requires: Element.Event 3078 3079provides: DomReady 3080 3081... 3082*/ 3083 3084Element.Events.domready = { 3085 3086 onAdd: function(fn){ 3087 if (Browser.loaded) fn.call(this); 3088 } 3089 3090}; 3091 3092(function(){ 3093 3094 var domready = function(){ 3095 if (Browser.loaded) return; 3096 Browser.loaded = true; 3097 window.fireEvent('domready'); 3098 document.fireEvent('domready'); 3099 }; 3100 3101 window.addEvent('load', domready); 3102 3103 if (Browser.Engine.trident){ 3104 var temp = document.createElement('div'); 3105 (function(){ 3106 ($try(function(){ 3107 temp.doScroll(); // Technique by Diego Perini 3108 return document.id(temp).inject(document.body).set('html', 'temp').dispose(); 3109 })) ? domready() : arguments.callee.delay(50); 3110 })(); 3111 } else if (Browser.Engine.webkit && Browser.Engine.version < 525){ 3112 (function(){ 3113 (['loaded', 'complete'].contains(document.readyState)) ? domready() : arguments.callee.delay(50); 3114 })(); 3115 } else { 3116 document.addEvent('DOMContentLoaded', domready); 3117 } 3118 3119})(); 3120 3121 3122/* 3123--- 3124 3125name: JSON 3126 3127description: JSON encoder and decoder. 3128 3129license: MIT-style license. 3130 3131see: <http://www.json.org/> 3132 3133requires: [Array, String, Number, Function, Hash] 3134 3135provides: JSON 3136 3137... 3138*/ 3139 3140var JSON = new Hash(this.JSON && { 3141 stringify: JSON.stringify, 3142 parse: JSON.parse 3143}).extend({ 3144 3145 $specialChars: {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'}, 3146 3147 $replaceChars: function(chr){ 3148 return JSON.$specialChars[chr] || '\\u00' + Math.floor(chr.charCodeAt() / 16).toString(16) + (chr.charCodeAt() % 16).toString(16); 3149 }, 3150 3151 encode: function(obj){ 3152 switch ($type(obj)){ 3153 case 'string': 3154 return '"' + obj.replace(/[\x00-\x1f\\"]/g, JSON.$replaceChars) + '"'; 3155 case 'array': 3156 return '[' + String(obj.map(JSON.encode).clean()) + ']'; 3157 case 'object': case 'hash': 3158 var string = []; 3159 Hash.each(obj, function(value, key){ 3160 var json = JSON.encode(value); 3161 if (json) string.push(JSON.encode(key) + ':' + json); 3162 }); 3163 return '{' + string + '}'; 3164 case 'number': case 'boolean': return String(obj); 3165 case false: return 'null';
3166 } 3167 return null; 3168 }, 3169 3170 decode: function(string, secure){ 3171 if ($type(string) != 'string' || !string.length) return null; 3172 if (secure && !(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(string.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''))) return null; 3173 return eval('(' + string + ')'); 3174 } 3175 3176}); 3177 3178 3179/* 3180--- 3181 3182name: Cookie 3183 3184description: Class for creating, reading, and deleting browser Cookies. 3185 3186license: MIT-style license. 3187 3188credits: Based on the functions by Peter-Paul Koch (http://quirksmode.org). 3189 3190requires: Options 3191 3192provides: Cookie 3193 3194... 3195*/ 3196 3197var Cookie = new Class({ 3198 3199 Implements: Options, 3200 3201 options: { 3202 path: false, 3203 domain: false, 3204 duration: false, 3205 secure: false, 3206 document: document 3207 }, 3208 3209 initialize: function(key, options){ 3210 this.key = key; 3211 this.setOptions(options); 3212 }, 3213 3214 write: function(value){ 3215 value = encodeURIComponent(value); 3216 if (this.options.domain) value += '; domain=' + this.options.domain; 3217 if (this.options.path) value += '; path=' + this.options.path; 3218 if (this.options.duration){ 3219 var date = new Date(); 3220 date.setTime(date.getTime() + this.options.duration * 24 * 60 * 60 * 1000); 3221 value += '; expires=' + date.toGMTString(); 3222 } 3223 if (this.options.secure) value += '; secure'; 3224 this.options.document.cookie = this.key + '=' + value; 3225 return this; 3226 }, 3227 3228 read: function(){ 3229 var value = this.options.document.cookie.match('(?:^|;)\\s*' + this.key.escapeRegExp() + '=([^;]*)'); 3230 return (value) ? decodeURIComponent(value[1]) : null; 3231 }, 3232 3233 dispose: function(){ 3234 new Cookie(this.key, $merge(this.options, {duration: -1})).write(''); 3235 return this; 3236 } 3237 3238}); 3239 3240Cookie.write = function(key, value, options){ 3241 return new Cookie(key, options).write(value); 3242}; 3243 3244Cookie.read = function(key){ 3245 return new Cookie(key).read(); 3246}; 3247 3248Cookie.dispose = function(key, options){ 3249 return new Cookie(key, options).dispose(); 3250}; 3251 3252 3253/* 3254--- 3255 3256name: Swiff 3257 3258description: Wrapper for embedding SWF movies. Supports External Interface Communication. 3259 3260license: MIT-style license. 3261 3262credits: Flash detection & Internet Explorer + Flash Player 9 fix inspired by SWFObject. 3263 3264requires: [Options, $util] 3265 3266provides: Swiff 3267 3268... 3269*/ 3270 3271var Swiff = new Class({ 3272 3273 Implements: [Options], 3274 3275 options: { 3276 id: null, 3277 height: 1, 3278 width: 1, 3279 container: null, 3280 properties: {}, 3281 params: { 3282 quality: 'high', 3283 allowScriptAccess: 'always', 3284 wMode: 'transparent', 3285 swLiveConnect: true 3286 }, 3287 callBacks: {}, 3288 vars: {} 3289 }, 3290 3291 toElement: function(){ 3292 return this.object; 3293 }, 3294 3295 initialize: function(path, options){ 3296 this.instance = 'Swiff_' + $time(); 3297 3298 this.setOptions(options); 3299 options = this.options; 3300 var id = this.id = options.id || this.instance; 3301 var container = document.id(options.container); 3302 3303 Swiff.CallBacks[this.instance] = {}; 3304 3305 var params = options.params, vars = options.vars, callBacks = options.callBacks; 3306 var properties = $extend({height: options.height, width: options.width}, options.properties); 3307 3308 var self = this; 3309 3310 for (var callBack in callBacks){ 3311 Swiff.CallBacks[this.instance][callBack] = (function(option){ 3312 return function(){ 3313 return option.apply(self.object, arguments); 3314 }; 3315 })(callBacks[callBack]); 3316 vars[callBack] = 'Swiff.CallBacks.' + this.instance + '.' + callBack; 3317 } 3318 3319 params.flashVars = Hash.toQueryString(vars); 3320 if (Browser.Engine.trident){ 3321 properties.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 3322 params.movie = path; 3323 } else { 3324 properties.type = 'application/x-shockwave-flash'; 3325 properties.data = path; 3326 } 3327 var build = '<object id="' + id + '"'; 3328 for (var property in properties) build += ' ' + property + '="' + properties[property] + '"'; 3329 build += '>'; 3330 for (var param in params){ 3331 if (params[param]) build += '<param name="' + param + '" value="' + params[param] + '" />'; 3332 } 3333 build += '</object>'; 3334 this.object = ((container) ? container.empty() : new Element('div')).set('html', build).firstChild; 3335 }, 3336 3337 replaces: function(element){ 3338 element = document.id(element, true); 3339 element.parentNode.replaceChild(this.toElement(), element); 3340 return this; 3341 }, 3342 3343 inject: function(element){ 3344 document.id(element, true).appendChild(this.toElement()); 3345 return this; 3346 }, 3347 3348 remote: function(){ 3349 return Swiff.remote.apply(Swiff, [this.toElement()].extend(arguments)); 3350 } 3351 3352}); 3353 3354Swiff.CallBacks = {}; 3355 3356Swiff.remote = function(obj, fn){ 3357 var rs = obj.CallFunction('<invoke name="' + fn + '" returntype="javascript">' + __flash__argumentsToXML(arguments, 2) + '</invoke>'); 3358 return eval(rs); 3359}; 3360 3361 3362/* 3363--- 3364 3365name: Fx 3366 3367description: Contains the basic animation logic to be extended by all other Fx Classes. 3368 3369license: MIT-style license. 3370 3371requires: [Chain, Events, Options] 3372 3373provides: Fx 3374 3375... 3376*/ 3377 3378var Fx = new Class({ 3379 3380 Implements: [Chain, Events, Options], 3381 3382 options: { 3383 /* 3384 onStart: $empty, 3385 onCancel: $empty, 3386 onComplete: $empty, 3387 */ 3388 fps: 50, 3389 unit: false, 3390 duration: 500, 3391 link: 'ignore' 3392 }, 3393 3394 initialize: function(options){ 3395 this.subject = this.subject || this; 3396 this.setOptions(options); 3397 this.options.duration = Fx.Durations[this.options.duration] || this.options.duration.toInt(); 3398 var wait = this.options.wait; 3399 if (wait === false) this.options.link = 'cancel'; 3400 }, 3401 3402 getTransition: function(){ 3403 return function(p){ 3404 return -(Math.cos(Math.PI * p) - 1) / 2; 3405 }; 3406 }, 3407 3408 step: function(){ 3409 var time = $time(); 3410 if (time < this.time + this.options.duration){ 3411 var delta = this.transition((time - this.time) / this.options.duration); 3412 this.set(this.compute(this.from, this.to, delta)); 3413 } else { 3414 this.set(this.compute(this.from, this.to, 1)); 3415 this.complete(); 3416 } 3417 }, 3418 3419 set: function(now){ 3420 return now; 3421 }, 3422 3423 compute: function(from, to, delta){ 3424 return Fx.compute(from, to, delta); 3425 }, 3426 3427 check: function(){ 3428 if (!this.timer) return true; 3429 switch (this.options.link){ 3430 case 'cancel': this.cancel(); return true; 3431 case 'chain': this.chain(this.caller.bind(this, arguments)); return false;
3432 } 3433 return false; 3434 }, 3435 3436 start: function(from, to){ 3437 if (!this.check(from, to)) return this; 3438 this.from = from; 3439 this.to = to; 3440 this.time = 0; 3441 this.transition = this.getTransition(); 3442 this.startTimer(); 3443 this.onStart(); 3444 return this; 3445 }, 3446 3447 complete: function(){ 3448 if (this.stopTimer()) this.onComplete(); 3449 return this; 3450 }, 3451 3452 cancel: function(){ 3453 if (this.stopTimer()) this.onCancel(); 3454 return this; 3455 }, 3456 3457 onStart: function(){ 3458 this.fireEvent('start', this.subject); 3459 }, 3460 3461 onComplete: function(){ 3462 this.fireEvent('complete', this.subject); 3463 if (!this.callChain()) this.fireEvent('chainComplete', this.subject); 3464 }, 3465 3466 onCancel: function(){ 3467 this.fireEvent('cancel', this.subject).clearChain(); 3468 }, 3469 3470 pause: function(){ 3471 this.stopTimer(); 3472 return this; 3473 }, 3474 3475 resume: function(){ 3476 this.startTimer(); 3477 return this; 3478 }, 3479 3480 stopTimer: function(){ 3481 if (!this.timer) return false; 3482 this.time = $time() - this.time; 3483 this.timer = $clear(this.timer); 3484 return true; 3485 }, 3486 3487 startTimer: function(){ 3488 if (this.timer) return false; 3489 this.time = $time() - this.time; 3490 this.timer = this.step.periodical(Math.round(1000 / this.options.fps), this); 3491 return true; 3492 } 3493 3494}); 3495 3496Fx.compute = function(from, to, delta){ 3497 return (to - from) * delta + from; 3498}; 3499 3500Fx.Durations = {'short': 250, 'normal': 500, 'long': 1000}; 3501 3502 3503/* 3504--- 3505 3506name: Fx.CSS 3507 3508description: Contains the CSS animation logic. Used by Fx.Tween, Fx.Morph, Fx.Elements. 3509 3510license: MIT-style license. 3511 3512requires: [Fx, Element.Style] 3513 3514provides: Fx.CSS 3515 3516... 3517*/ 3518 3519Fx.CSS = new Class({ 3520 3521 Extends: Fx, 3522 3523 //prepares the base from/to object 3524 3525 prepare: function(element, property, values){ 3526 values = $splat(values); 3527 var values1 = values[1]; 3528 if (!$chk(values1)){ 3529 values[1] = values[0]; 3530 values[0] = element.getStyle(property); 3531 } 3532 var parsed = values.map(this.parse); 3533 return {from: parsed[0], to: parsed[1]}; 3534 }, 3535 3536 //parses a value into an array 3537 3538 parse: function(value){ 3539 value = $lambda(value)(); 3540 value = (typeof value == 'string') ? value.split(' ') : $splat(value); 3541 return value.map(function(val){ 3542 val = String(val); 3543 var found = false; 3544 Fx.CSS.Parsers.each(function(parser, key){ 3545 if (found) return; 3546 var parsed = parser.parse(val); 3547 if ($chk(parsed)) found = {value: parsed, parser: parser}; 3548 }); 3549 found = found || {value: val, parser: Fx.CSS.Parsers.String}; 3550 return found; 3551 }); 3552 }, 3553 3554 //computes by a from and to prepared objects, using their parsers. 3555 3556 compute: function(from, to, delta){ 3557 var computed = []; 3558 (Math.min(from.length, to.length)).times(function(i){ 3559 computed.push({value: from[i].parser.compute(from[i].value, to[i].value, delta), parser: from[i].parser}); 3560 }); 3561 computed.$family = {name: 'fx:css:value'}; 3562 return computed; 3563 }, 3564 3565 //serves the value as settable 3566 3567 serve: function(value, unit){ 3568 if ($type(value) != 'fx:css:value') value = this.parse(value); 3569 var returned = []; 3570 value.each(function(bit){ 3571 returned = returned.concat(bit.parser.serve(bit.value, unit)); 3572 }); 3573 return returned; 3574 }, 3575 3576 //renders the change to an element 3577 3578 render: function(element, property, value, unit){ 3579 element.setStyle(property, this.serve(value, unit)); 3580 }, 3581 3582 //searches inside the page css to find the values for a selector 3583 3584 search: function(selector){ 3585 if (Fx.CSS.Cache[selector]) return Fx.CSS.Cache[selector]; 3586 var to = {}; 3587 Array.each(document.styleSheets, function(sheet, j){ 3588 var href = sheet.href; 3589 if (href && href.contains('://') && !href.contains(document.domain)) return; 3590 var rules = sheet.rules || sheet.cssRules; 3591 Array.each(rules, function(rule, i){ 3592 if (!rule.style) return; 3593 var selectorText = (rule.selectorText) ? rule.selectorText.replace(/^\w+/, function(m){ 3594 return m.toLowerCase(); 3595 }) : null; 3596 if (!selectorText || !selectorText.test('^' + selector + '$')) return; 3597 Element.Styles.each(function(value, style){ 3598 if (!rule.style[style] || Element.ShortStyles[style]) return; 3599 value = String(rule.style[style]); 3600 to[style] = (value.test(/^rgb/)) ? value.rgbToHex() : value; 3601 }); 3602 }); 3603 }); 3604 return Fx.CSS.Cache[selector] = to; 3605 } 3606 3607}); 3608 3609Fx.CSS.Cache = {}; 3610 3611Fx.CSS.Parsers = new Hash({ 3612 3613 Color: { 3614 parse: function(value){ 3615 if (value.match(/^#[0-9a-f]{3,6}$/i)) return value.hexToRgb(true); 3616 return ((value = value.match(/(\d+),\s*(\d+),\s*(\d+)/))) ? [value[1], value[2], value[3]] : false;
3617 }, 3618 compute: function(from, to, delta){ 3619 return from.map(function(value, i){ 3620 return Math.round(Fx.compute(from[i], to[i], delta)); 3621 }); 3622 }, 3623 serve: function(value){ 3624 return value.map(Number); 3625 } 3626 }, 3627 3628 Number: { 3629 parse: parseFloat, 3630 compute: Fx.compute, 3631 serve: function(value, unit){ 3632 return (unit) ? value + unit : value; 3633 } 3634 }, 3635 3636 String: { 3637 parse: $lambda(false), 3638 compute: $arguments(1), 3639 serve: $arguments(0) 3640 } 3641 3642}); 3643 3644 3645/* 3646--- 3647 3648name: Fx.Tween 3649 3650description: Formerly Fx.Style, effect to transition any CSS property for an element. 3651 3652license: MIT-style license. 3653 3654requires: Fx.CSS 3655 3656provides: [Fx.Tween, Element.fade, Element.highlight] 3657 3658... 3659*/ 3660 3661Fx.Tween = new Class({ 3662 3663 Extends: Fx.CSS, 3664 3665 initialize: function(element, options){ 3666 this.element = this.subject = document.id(element); 3667 this.parent(options); 3668 }, 3669 3670 set: function(property, now){ 3671 if (arguments.length == 1){ 3672 now = property; 3673 property = this.property || this.options.property; 3674 } 3675 this.render(this.element, property, now, this.options.unit); 3676 return this; 3677 }, 3678 3679 start: function(property, from, to){ 3680 if (!this.check(property, from, to)) return this; 3681 var args = Array.flatten(arguments); 3682 this.property = this.options.property || args.shift(); 3683 var parsed = this.prepare(this.element, this.property, args); 3684 return this.parent(parsed.from, parsed.to); 3685 } 3686 3687}); 3688 3689Element.Properties.tween = { 3690 3691 set: function(options){ 3692 var tween = this.retrieve('tween'); 3693 if (tween) tween.cancel(); 3694 return this.eliminate('tween').store('tween:options', $extend({link: 'cancel'}, options)); 3695 }, 3696 3697 get: function(options){ 3698 if (options || !this.retrieve('tween')){ 3699 if (options || !this.retrieve('tween:options')) this.set('tween', options); 3700 this.store('tween', new Fx.Tween(this, this.retrieve('tween:options'))); 3701 } 3702 return this.retrieve('tween'); 3703 } 3704 3705}; 3706 3707Element.implement({ 3708 3709 tween: function(property, from, to){ 3710 this.get('tween').start(arguments); 3711 return this; 3712 }, 3713 3714 fade: function(how){ 3715 var fade = this.get('tween'), o = 'opacity', toggle; 3716 how = $pick(how, 'toggle'); 3717 switch (how){ 3718 case 'in': fade.start(o, 1); break; 3719 case 'out': fade.start(o, 0); break; 3720 case 'show': fade.set(o, 1); break; 3721 case 'hide': fade.set(o, 0); break; 3722 case 'toggle': 3723 var flag = this.retrieve('fade:flag', this.get('opacity') == 1); 3724 fade.start(o, (flag) ? 0 : 1); 3725 this.store('fade:flag', !flag); 3726 toggle = true; 3727 break; 3728 default: fade.start(o, arguments); 3729 } 3730 if (!toggle) this.eliminate('fade:flag'); 3731 return this; 3732 }, 3733 3734 highlight: function(start, end){ 3735 if (!end){ 3736 end = this.retrieve('highlight:original', this.getStyle('background-color')); 3737 end = (end == 'transparent') ? '#fff' : end; 3738 } 3739 var tween = this.get('tween'); 3740 tween.start('background-color', start || '#ffff88', end).chain(function(){ 3741 this.setStyle('background-color', this.retrieve('highlight:original')); 3742 tween.callChain(); 3743 }.bind(this)); 3744 return this; 3745 } 3746 3747}); 3748 3749 3750/* 3751--- 3752 3753name: Fx.Morph 3754 3755description: Formerly Fx.Styles, effect to transition any number of CSS properties for an element using an object of rules, or CSS based selector rules. 3756 3757license: MIT-style license. 3758 3759requires: Fx.CSS 3760 3761provides: Fx.Morph 3762 3763... 3764*/ 3765 3766Fx.Morph = new Class({ 3767 3768 Extends: Fx.CSS, 3769 3770 initialize: function(element, options){ 3771 this.element = this.subject = document.id(element); 3772 this.parent(options); 3773 }, 3774 3775 set: function(now){ 3776 if (typeof now == 'string') now = this.search(now); 3777 for (var p in now) this.render(this.element, p, now[p], this.options.unit); 3778 return this; 3779 }, 3780 3781 compute: function(from, to, delta){ 3782 var now = {}; 3783 for (var p in from) now[p] = this.parent(from[p], to[p], delta); 3784 return now; 3785 }, 3786 3787 start: function(properties){ 3788 if (!this.check(properties)) return this; 3789 if (typeof properties == 'string') properties = this.search(properties); 3790 var from = {}, to = {}; 3791 for (var p in properties){ 3792 var parsed = this.prepare(this.element, p, properties[p]); 3793 from[p] = parsed.from; 3794 to[p] = parsed.to; 3795 } 3796 return this.parent(from, to); 3797 } 3798 3799}); 3800 3801Element.Properties.morph = { 3802 3803 set: function(options){ 3804 var morph = this.retrieve('morph'); 3805 if (morph) morph.cancel(); 3806 return this.eliminate('morph').store('morph:options', $extend({link: 'cancel'}, options)); 3807 }, 3808 3809 get: function(options){ 3810 if (options || !this.retrieve('morph')){ 3811 if (options || !this.retrieve('morph:options')) this.set('morph', options); 3812 this.store('morph', new Fx.Morph(this, this.retrieve('morph:options'))); 3813 } 3814 return this.retrieve('morph'); 3815 } 3816 3817}; 3818 3819Element.implement({ 3820 3821 morph: function(props){ 3822 this.get('morph').start(props); 3823 return this; 3824 } 3825 3826}); 3827 3828 3829/* 3830--- 3831 3832name: Fx.Transitions 3833 3834description: Contains a set of advanced transitions to be used with any of the Fx Classes. 3835 3836license: MIT-style license. 3837 3838credits: Easing Equations by Robert Penner, <http://www.robertpenner.com/easing/>, modified and optimized to be used with MooTools. 3839 3840requires: Fx 3841 3842provides: Fx.Transitions 3843 3844... 3845*/ 3846 3847Fx.implement({ 3848 3849 getTransition: function(){ 3850 var trans = this.options.transition || Fx.Transitions.Sine.easeInOut; 3851 if (typeof trans == 'string'){ 3852 var data = trans.split(':'); 3853 trans = Fx.Transitions; 3854 trans = trans[data[0]] || trans[data[0].capitalize()]; 3855 if (data[1]) trans = trans['ease' + data[1].capitalize() + (data[2] ? data[2].capitalize() : '')]; 3856 } 3857 return trans; 3858 } 3859 3860}); 3861 3862Fx.Transition = function(transition, params){ 3863 params = $splat(params); 3864 return $extend(transition, { 3865 easeIn: function(pos){ 3866 return transition(pos, params); 3867 }, 3868 easeOut: function(pos){ 3869 return 1 - transition(1 - pos, params); 3870 }, 3871 easeInOut: function(pos){ 3872 return (pos <= 0.5) ? transition(2 * pos, params) / 2 : (2 - transition(2 * (1 - pos), params)) / 2; 3873 } 3874 }); 3875}; 3876 3877Fx.Transitions = new Hash({ 3878 3879 linear: $arguments(0) 3880 3881}); 3882 3883Fx.Transitions.extend = function(transitions){ 3884 for (var transition in transitions) Fx.Transitions[transition] = new Fx.Transition(transitions[transition]); 3885}; 3886 3887Fx.Transitions.extend({ 3888 3889 Pow: function(p, x){ 3890 return Math.pow(p, x[0] || 6); 3891 }, 3892 3893 Expo: function(p){ 3894 return Math.pow(2, 8 * (p - 1)); 3895 }, 3896
3897 Circ: function(p){ 3898 return 1 - Math.sin(Math.acos(p)); 3899 }, 3900 3901 Sine: function(p){ 3902 return 1 - Math.sin((1 - p) * Math.PI / 2); 3903 }, 3904 3905 Back: function(p, x){ 3906 x = x[0] || 1.618; 3907 return Math.pow(p, 2) * ((x + 1) * p - x); 3908 }, 3909 3910 Bounce: function(p){ 3911 var value; 3912 for (var a = 0, b = 1; 1; a += b, b /= 2){ 3913 if (p >= (7 - 4 * a) / 11){ 3914 value = b * b - Math.pow((11 - 6 * a - 11 * p) / 4, 2); 3915 break; 3916 } 3917 } 3918 return value; 3919 }, 3920 3921 Elastic: function(p, x){ 3922 return Math.pow(2, 10 * --p) * Math.cos(20 * p * Math.PI * (x[0] || 1) / 3); 3923 } 3924 3925}); 3926 3927['Quad', 'Cubic', 'Quart', 'Quint'].each(function(transition, i){ 3928 Fx.Transitions[transition] = new Fx.Transition(function(p){ 3929 return Math.pow(p, [i + 2]); 3930 }); 3931}); 3932 3933 3934/* 3935--- 3936 3937name: Request 3938 3939description: Powerful all purpose Request Class. Uses XMLHTTPRequest. 3940 3941license: MIT-style license. 3942 3943requires: [Element, Chain, Events, Options, Browser] 3944 3945provides: Request 3946 3947... 3948*/ 3949 3950var Request = new Class({ 3951 3952 Implements: [Chain, Events, Options], 3953 3954 options: {/* 3955 onRequest: $empty, 3956 onComplete: $empty, 3957 onCancel: $empty, 3958 onSuccess: $empty, 3959 onFailure: $empty, 3960 onException: $empty,*/ 3961 url: '', 3962 data: '', 3963 headers: { 3964 'X-Requested-With': 'XMLHttpRequest', 3965 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*' 3966 }, 3967 async: true, 3968 format: false, 3969 method: 'post', 3970 link: 'ignore', 3971 isSuccess: null, 3972 emulation: true, 3973 urlEncoded: true, 3974 encoding: 'utf-8', 3975 evalScripts: false, 3976 evalResponse: false, 3977 noCache: false 3978 }, 3979 3980 initialize: function(options){ 3981 this.xhr = new Browser.Request(); 3982 this.setOptions(options); 3983 this.options.isSuccess = this.options.isSuccess || this.isSuccess; 3984 this.headers = new Hash(this.options.headers); 3985 }, 3986 3987 onStateChange: function(){ 3988 if (this.xhr.readyState != 4 || !this.running) return; 3989 this.running = false; 3990 this.status = 0; 3991 $try(function(){ 3992 this.status = this.xhr.status; 3993 }.bind(this)); 3994 this.xhr.onreadystatechange = $empty; 3995 if (this.options.isSuccess.call(this, this.status)){ 3996 this.response = {text: this.xhr.responseText, xml: this.xhr.responseXML}; 3997 this.success(this.response.text, this.response.xml); 3998 } else { 3999 this.response = {text: null, xml: null}; 4000 this.failure(); 4001 } 4002 }, 4003 4004 isSuccess: function(){ 4005 return ((this.status >= 200) && (this.status < 300)); 4006 }, 4007 4008 processScripts: function(text){ 4009 if (this.options.evalResponse || (/(ecma|java)script/).test(this.getHeader('Content-type'))) return $exec(text); 4010 return text.stripScripts(this.options.evalScripts); 4011 }, 4012 4013 success: function(text, xml){ 4014 this.onSuccess(this.processScripts(text), xml); 4015 }, 4016 4017 onSuccess: function(){ 4018 this.fireEvent('complete', arguments).fireEvent('success', arguments).callChain(); 4019 }, 4020 4021 failure: function(){ 4022 this.onFailure(); 4023 }, 4024 4025 onFailure: function(){ 4026 this.fireEvent('complete').fireEvent('failure', this.xhr); 4027 }, 4028 4029 setHeader: function(name, value){ 4030 this.headers.set(name, value); 4031 return this; 4032 }, 4033 4034 getHeader: function(name){ 4035 return $try(function(){ 4036 return this.xhr.getResponseHeader(name); 4037 }.bind(this)); 4038 }, 4039 4040 check: function(){ 4041 if (!this.running) return true; 4042 switch (this.options.link){ 4043 case 'cancel': this.cancel(); return true; 4044 case 'chain': this.chain(this.caller.bind(this, arguments)); return false; 4045 } 4046 return false; 4047 }, 4048 4049 send: function(options){ 4050 if (!this.check(options)) return this; 4051 this.running = true; 4052 4053 var type = $type(options); 4054 if (type == 'string' || type == 'element') options = {data: options}; 4055 4056 var old = this.options; 4057 options = $extend({data: old.data, url: old.url, method: old.method}, options); 4058 var data = options.data, url = String(options.url), method = options.method.toLowerCase(); 4059 4060 switch ($type(data)){ 4061 case 'element': data = document.id(data).toQueryString(); break; 4062 case 'object': case 'hash': data = Hash.toQueryString(data); 4063 } 4064 4065 if (this.options.format){ 4066 var format = 'format=' + this.options.format; 4067 data = (data) ? format + '&' + data : format; 4068 } 4069 4070 if (this.options.emulation && !['get', 'post'].contains(method)){ 4071 var _method = '_method=' + method; 4072 data = (data) ? _method + '&' + data : _method; 4073 method = 'post'; 4074 } 4075 4076 if (this.options.urlEncoded && method == 'post'){ 4077 var encoding = (this.options.encoding) ? '; charset=' + this.options.encoding : ''; 4078 this.headers.set('Content-type', 'application/x-www-form-urlencoded' + encoding); 4079 } 4080 4081 if (this.options.noCache){ 4082 var noCache = 'noCache=' + new Date().getTime(); 4083 data = (data) ? noCache + '&' + data : noCache; 4084 } 4085 4086 var trimPosition = url.lastIndexOf('/'); 4087 if (trimPosition > -1 && (trimPosition = url.indexOf('#')) > -1) url = url.substr(0, trimPosition); 4088 4089 if (data && method == 'get'){ 4090 url = url + (url.contains('?') ? '&' : '?') + data; 4091 data = null; 4092 } 4093 4094 this.xhr.open(method.toUpperCase(), url, this.options.async); 4095 4096 this.xhr.onreadystatechange = this.onStateChange.bind(this); 4097 4098 this.headers.each(function(value, key){ 4099 try { 4100 this.xhr.setRequestHeader(key, value); 4101 } catch (e){ 4102 this.fireEvent('exception', [key, value]); 4103 } 4104 }, this); 4105 4106 this.fireEvent('request'); 4107 this.xhr.send(data); 4108 if (!this.options.async) this.onStateChange(); 4109 return this; 4110 }, 4111 4112 cancel: function(){ 4113 if (!this.running) return this; 4114 this.running = false;
4115 this.xhr.abort(); 4116 this.xhr.onreadystatechange = $empty; 4117 this.xhr = new Browser.Request(); 4118 this.fireEvent('cancel'); 4119 return this; 4120 } 4121 4122}); 4123 4124(function(){ 4125 4126var methods = {}; 4127['get', 'post', 'put', 'delete', 'GET', 'POST', 'PUT', 'DELETE'].each(function(method){ 4128 methods[method] = function(){ 4129 var params = Array.link(arguments, {url: String.type, data: $defined}); 4130 return this.send($extend(params, {method: method})); 4131 }; 4132}); 4133 4134Request.implement(methods); 4135 4136})(); 4137 4138Element.Properties.send = { 4139 4140 set: function(options){ 4141 var send = this.retrieve('send'); 4142 if (send) send.cancel(); 4143 return this.eliminate('send').store('send:options', $extend({ 4144 data: this, link: 'cancel', method: this.get('method') || 'post', url: this.get('action') 4145 }, options)); 4146 }, 4147 4148 get: function(options){ 4149 if (options || !this.retrieve('send')){ 4150 if (options || !this.retrieve('send:options')) this.set('send', options); 4151 this.store('send', new Request(this.retrieve('send:options'))); 4152 } 4153 return this.retrieve('send'); 4154 } 4155 4156}; 4157 4158Element.implement({ 4159 4160 send: function(url){ 4161 var sender = this.get('send'); 4162 sender.send({data: this, url: url || sender.options.url}); 4163 return this; 4164 } 4165 4166}); 4167 4168 4169/* 4170--- 4171 4172name: Request.HTML 4173 4174description: Extends the basic Request Class with additional methods for interacting with HTML responses. 4175 4176license: MIT-style license. 4177 4178requires: [Request, Element] 4179 4180provides: Request.HTML 4181 4182... 4183*/ 4184 4185Request.HTML = new Class({ 4186 4187 Extends: Request, 4188 4189 options: { 4190 update: false, 4191 append: false, 4192 evalScripts: true, 4193 filter: false 4194 }, 4195 4196 processHTML: function(text){ 4197 var match = text.match(/<body[^>]*>([\s\S]*?)<\/body>/i); 4198 text = (match) ? match[1] : text; 4199 4200 var container = new Element('div'); 4201 4202 return $try(function(){ 4203 var root = '<root>' + text + '</root>', doc; 4204 if (Browser.Engine.trident){ 4205 doc = new ActiveXObject('Microsoft.XMLDOM'); 4206 doc.async = false; 4207 doc.loadXML(root); 4208 } else { 4209 doc = new DOMParser().parseFromString(root, 'text/xml'); 4210 } 4211 root = doc.getElementsByTagName('root')[0]; 4212 if (!root) return null; 4213 for (var i = 0, k = root.childNodes.length; i < k; i++){ 4214 var child = Element.clone(root.childNodes[i], true, true); 4215 if (child) container.grab(child); 4216 } 4217 return container; 4218 }) || container.set('html', text); 4219 }, 4220 4221 success: function(text){ 4222 var options = this.options, response = this.response; 4223 4224 response.html = text.stripScripts(function(script){ 4225 response.javascript = script; 4226 }); 4227 4228 var temp = this.processHTML(response.html); 4229 4230 response.tree = temp.childNodes; 4231 response.elements = temp.getElements('*'); 4232 4233 if (options.filter) response.tree = response.elements.filter(options.filter); 4234 if (options.update) document.id(options.update).empty().set('html', response.html); 4235 else if (options.append) document.id(options.append).adopt(temp.getChildren()); 4236 if (options.evalScripts) $exec(response.javascript); 4237 4238 this.onSuccess(response.tree, response.elements, response.html, response.javascript); 4239 } 4240 4241}); 4242 4243Element.Properties.load = { 4244 4245 set: function(options){ 4246 var load = this.retrieve('load'); 4247 if (load) load.cancel(); 4248 return this.eliminate('load').store('load:options', $extend({data: this, link: 'cancel', update: this, method: 'get'}, options)); 4249 }, 4250 4251 get: function(options){ 4252 if (options || ! this.retrieve('load')){ 4253 if (options || !this.retrieve('load:options')) this.set('load', options); 4254 this.store('load', new Request.HTML(this.retrieve('load:options'))); 4255 } 4256 return this.retrieve('load'); 4257 } 4258 4259}; 4260 4261Element.implement({ 4262 4263 load: function(){ 4264 this.get('load').send(Array.link(arguments, {data: Object.type, url: String.type})); 4265 return this; 4266 } 4267 4268}); 4269 4270 4271/* 4272--- 4273 4274name: Request.JSON 4275 4276description: Extends the basic Request Class with additional methods for sending and receiving JSON data. 4277 4278license: MIT-style license. 4279 4280requires: [Request, JSON] 4281 4282provides: [Request.JSON] 4283 4284... 4285*/ 4286 4287Request.JSON = new Class({ 4288 4289 Extends: Request, 4290 4291 options: { 4292 secure: true 4293 }, 4294 4295 initialize: function(options){ 4296 this.parent(options); 4297 this.headers.extend({'Accept': 'application/json', 'X-Request': 'JSON'}); 4298 }, 4299 4300 success: function(text){ 4301 this.response.json = JSON.decode(text, this.options.secure); 4302 this.onSuccess(this.response.json, text); 4303 } 4304 4305});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.