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