]>
jfr.im git - irc/quakenet/qwebirc.git/blob - static/js/mootools-1.2.5-core-nc.js
6 description: The core of MooTools, contains all the base functions and the Native and Hash implementations. Required by all the other scripts.
8 license: MIT-style license.
10 copyright: Copyright (c) 2006-2008 [Valerio Proietti](http://mad4milk.net/).
12 authors: The MooTools production team (http://mootools.net/developers/)
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)
18 provides: [MooTools, Native, Hash.base, Array.each, $util]
25 'build' : '008d8f0f2fcc2044e54fdd3635341aaab274e757'
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 ;
40 object
. constructor = Native
;
41 object
.$ family
= { name : 'native' };
42 if ( legacy
&& initialize
) object
. prototype = legacy
. prototype ;
43 object
. prototype . constructor = object
;
46 var family
= name
. toLowerCase ();
47 object
. prototype .$ family
= { name : family
};
48 Native
. typize ( object
, family
);
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
);
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
);
63 for ( var a
in a1
) this . alias ( a
, a1
[ a
], a2
);
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
);
73 if ( methods
) object
. implement ( methods
);
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
);
85 Native
. implement = function ( objects
, properties
){
86 for ( var i
= 0 , l
= objects
. length
; i
< l
; i
++) objects
[ i
]. implement ( properties
);
89 Native
. typize = function ( object
, family
){
90 if (! object
. type
) object
. type = function ( item
){
91 return ($ type ( item
) === family
);
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 });
99 var types
= { 'boolean' : Boolean
, 'native' : Native
, 'object' : Object
};
100 for ( var t
in types
) Native
. typize ( types
[ t
], t
);
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" ]
106 for ( var g
in generics
){
107 for ( var i
= generics
[ g
]. length
; i
--;) Native
. genericize ( natives
[ g
], generics
[ g
][ i
], true );
111 var Hash
= new Native ({
115 initialize : function ( object
){
116 if ($ type ( object
) == 'hash' ) object
= $ unlink ( object
. getClean ());
117 for ( var key
in object
) this [ key
] = object
[ key
];
125 forEach : function ( fn
, bind
){
126 for ( var key
in this ){
127 if ( this . hasOwnProperty ( key
)) fn
. call ( bind
, this [ key
], key
, this );
131 getClean : function (){
133 for ( var key
in this ){
134 if ( this . hasOwnProperty ( key
)) clean
[ key
] = this [ key
];
139 getLength : function (){
141 for ( var key
in this ){
142 if ( this . hasOwnProperty ( key
)) length
++;
149 Hash
. alias ( 'forEach' , 'each' );
153 forEach : function ( fn
, bind
){
154 for ( var i
= 0 , l
= this . length
; i
< l
; i
++) fn
. call ( bind
, this [ i
], i
, this );
159 Array
. alias ( 'forEach' , 'each' );
161 function $ A ( iterable
){
163 var l
= iterable
. length
, array
= new Array ( l
);
164 while ( l
--) array
[ l
] = iterable
[ l
];
167 return Array
. prototype . slice
. call ( iterable
);
170 function $ arguments ( i
){
177 return !!( obj
|| obj
=== 0 );
180 function $ clear ( timer
){
182 clearInterval ( timer
);
186 function $ defined ( obj
){
187 return ( obj
!= undefined );
190 function $ each ( iterable
, fn
, bind
){
191 var type
= $ type ( iterable
);
192 (( type
== 'arguments' || type
== 'collection' || type
== 'array' ) ? Array : Hash
). each ( iterable
, fn
, bind
);
197 function $ extend ( original
, extended
){
198 for ( var key
in ( extended
|| {})) original
[ key
] = extended
[ key
];
203 return new Hash ( object
);
206 function $ lambda ( value
){
207 return ($ type ( value
) == 'function' ) ? value : function (){
213 var args
= Array
. slice ( arguments
);
215 return $ mixin
. apply ( null , args
);
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
);
231 for ( var i
= 0 , l
= arguments
. length
; i
< l
; i
++){
232 if ( arguments
[ i
] != undefined ) return arguments
[ i
];
237 function $ random ( min
, max
){
238 return Math
. floor ( Math
. random () * ( max
- min
+ 1 ) + min
);
241 function $ splat ( obj
){
242 var type
= $ type ( obj
);
243 return ( type
) ? (( type
!= 'array' && type
!= 'arguments' ) ? [ obj
] : obj
) : [];
246 var $ time
= Date
. now
|| function (){
251 for ( var i
= 0 , l
= arguments
. length
; i
< l
; i
++){
253 return arguments
[ i
]();
260 if ( obj
== undefined ) return false ;
261 if ( obj
.$ family
) return ( obj
.$ family
. name
== 'number' && ! isFinite ( obj
)) ? false : obj
.$ family
. name
;
263 switch ( obj
. nodeType
){
264 case 1 : return 'element' ;
265 case 3 : return ( /\S/ ). test ( obj
. nodeValue
) ? 'textnode' : 'whitespace' ;
267 } else if ( typeof obj
. length
== 'number' ){
268 if ( obj
. callee
) return 'arguments' ;
269 else if ( obj
. item
) return 'collection' ;
274 function $ unlink ( object
){
276 switch ($ type ( object
)){
279 for ( var p
in object
) unlinked
[ p
] = $ unlink ( object
[ p
]);
282 unlinked
= new Hash ( object
);
286 for ( var i
= 0 , l
= object
. length
; i
< l
; i
++) unlinked
[ i
] = $ unlink ( object
[ i
]);
288 default : return object
;
299 description: Contains Array Prototypes like each, contains, and erase.
301 license: MIT-style license.
303 requires: [$util, Array.each]
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 ;
319 filter : function ( fn
, bind
){
321 for ( var i
= 0 , l
= this . length
; i
< l
; i
++){
322 if ( fn
. call ( bind
, this [ i
], i
, this )) results
. push ( this [ i
]);
328 return this . filter ($ defined
);
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
;
339 map : function ( fn
, bind
){
341 for ( var i
= 0 , l
= this . length
; i
< l
; i
++) results
[ i
] = fn
. call ( bind
, this [ i
], i
, this );
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 ;
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
];
358 link : function ( object
){
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
];
372 contains : function ( item
, from ){
373 return this . indexOf ( item
, from ) != - 1 ;
376 extend : function ( array
){
377 for ( var i
= 0 , j
= array
. length
; i
< j
; i
++) this . push ( array
[ i
]);
382 return ( this . length
) ? this [ this . length
- 1 ] : null ;
385 getRandom : function (){
386 return ( this . length
) ? this [$ random ( 0 , this . length
- 1 )] : null ;
389 include : function ( item
){
390 if (! this . contains ( item
)) this . push ( item
);
394 combine : function ( array
){
395 for ( var i
= 0 , l
= array
. length
; i
< l
; i
++) this . include ( array
[ i
]);
399 erase : function ( item
){
400 for ( var i
= this . length
; i
--; i
){
401 if ( this [ i
] === item
) this . splice ( i
, 1 );
413 for ( var i
= 0 , l
= this . length
; i
< l
; i
++){
414 var type
= $ type ( this [ i
]);
416 array
= array
. concat (( type
== 'array' || type
== 'collection' || type
== 'arguments' ) ? Array
. flatten ( this [ i
]) : this [ i
]);
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 );
427 return ( array
) ? rgb : 'rgb(' + rgb
+ ')' ;
430 rgbToHex : function ( array
){
431 if ( this . length
< 3 ) return null ;
432 if ( this . length
== 4 && this [ 3 ] == 0 && ! array
) return 'transparent' ;
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
);
438 return ( array
) ? hex : '#' + hex
. join ( '' );
449 description: Contains String Prototypes like camelCase, capitalize, test, and toInt.
451 license: MIT-style license.
462 test : function ( regex
, params
){
463 return (( typeof regex
== 'string' ) ? new RegExp ( regex
, params
) : regex
). test ( this );
466 contains : function ( string
, separator
){
467 return ( separator
) ? ( separator
+ this + separator
). indexOf ( separator
+ string
+ separator
) > - 1 : this . indexOf ( string
) > - 1 ;
471 return this . replace ( /^\s+|\s+$/g , '' );
475 return this . replace ( /\s+/g , ' ' ). trim ();
478 camelCase : function (){
479 return this . replace ( /-\D/g , function ( match
){
480 return match
. charAt ( 1 ). toUpperCase ();
484 hyphenate : function (){
485 return this . replace ( /[A-Z]/g , function ( match
){
486 return ( '-' + match
. charAt ( 0 ). toLowerCase ());
490 capitalize : function (){
491 return this . replace ( /\b[a-z]/g , function ( match
){
492 return match
. toUpperCase ();
496 escapeRegExp : function (){
497 return this . replace ( /([-.*+?^${}()|[\]\/\\])/g , ' \\ $1' );
500 toInt : function ( base
){
501 return parseInt ( this , base
|| 10 );
505 return parseFloat ( this );
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 ;
513 rgbToHex : function ( array
){
514 var rgb
= this . match ( /\d{1,3}/g );
515 return ( rgb
) ? rgb
. rgbToHex ( array
) : null ;
518 stripScripts : function ( option
){
520 var text
= this . replace ( /<script[^>]*>([\s\S]*?)<\/script>/gi , function (){
521 scripts
+= arguments
[ 1 ] + ' \n ' ;
524 if ( option
=== true ) $ exec ( scripts
);
525 else if ($ type ( option
) == 'function' ) option ( scripts
, text
);
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
] : '' ;
544 description: Contains Function Prototypes like create, bind, pass, and delay.
546 license: MIT-style license.
548 requires: [Native, $util]
556 delete Function
. prototype . bind
;
561 extend : function ( properties
){
562 for ( var property
in properties
) this [ property
] = properties
[ property
];
566 create : function ( options
){
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
);
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
);
583 run : function ( args
, bind
){
584 return this . apply ( bind
, $ splat ( args
));
587 pass : function ( args
, bind
){
588 return this . create ({ bind : bind
, arguments : args
});
591 bind : function ( bind
, args
){
592 return this . create ({ bind : bind
, arguments : args
});
595 bindWithEvent : function ( bind
, args
){
596 return this . create ({ bind : bind
, arguments : args
, event : true });
599 attempt : function ( args
, bind
){
600 return this . create ({ bind : bind
, arguments : args
, attempt : true })();
603 delay : function ( delay
, bind
, args
){
604 return this . create ({ bind : bind
, arguments : args
, delay : delay
})();
607 periodical : function ( periodical
, bind
, args
){
608 return this . create ({ bind : bind
, arguments : args
, periodical : periodical
})();
619 description: Contains Number Prototypes like limit, round, times, and ceil.
621 license: MIT-style license.
623 requires: [Native, $util]
632 limit : function ( min
, max
){
633 return Math
. min ( max
, Math
. max ( min
, this ));
636 round : function ( precision
){
637 precision
= Math
. pow ( 10 , precision
|| 0 );
638 return Math
. round ( this * precision
) / precision
;
641 times : function ( fn
, bind
){
642 for ( var i
= 0 ; i
< this ; i
++) fn
. call ( bind
, i
, this );
646 return parseFloat ( this );
649 toInt : function ( base
){
650 return parseInt ( this , base
|| 10 );
655 Number
. alias ( 'times' , 'each' );
659 math
. each ( function ( name
){
660 if (! Number
[ name
]) methods
[ name
] = function (){
661 return Math
[ name
]. apply ( null , [ this ]. concat ($ A ( arguments
)));
664 Number
. implement ( methods
);
665 })([ 'abs' , 'acos' , 'asin' , 'atan' , 'atan2' , 'ceil' , 'cos' , 'exp' , 'floor' , 'log' , 'max' , 'min' , 'pow' , 'sin' , 'sqrt' , 'tan' ]);
673 description: Contains Hash Prototypes. Provides a means for overcoming the JavaScript practical impossibility of extending native Objects.
675 license: MIT-style license.
686 has : Object
. prototype . hasOwnProperty
,
688 keyOf : function ( value
){
689 for ( var key
in this ){
690 if ( this . hasOwnProperty ( key
) && this [ key
] === value
) return key
;
695 hasValue : function ( value
){
696 return ( Hash
. keyOf ( this , value
) !== null );
699 extend : function ( properties
){
700 Hash
. each ( properties
|| {}, function ( value
, key
){
701 Hash
. set ( this , key
, value
);
706 combine : function ( properties
){
707 Hash
. each ( properties
|| {}, function ( value
, key
){
708 Hash
. include ( this , key
, value
);
713 erase : function ( key
){
714 if ( this . hasOwnProperty ( key
)) delete this [ key
];
719 return ( this . hasOwnProperty ( key
)) ? this [ key
] : null ;
722 set : function ( key
, value
){
723 if (! this [ key
] || this . hasOwnProperty ( key
)) this [ key
] = value
;
728 Hash
. each ( this , function ( value
, key
){
734 include : function ( key
, value
){
735 if ( this [ key
] == undefined ) this [ key
] = value
;
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 ));
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
);
755 every : function ( fn
, bind
){
756 for ( var key
in this ){
757 if ( this . hasOwnProperty ( key
) && ! fn
. call ( bind
, this [ key
], key
)) return false ;
762 some : function ( fn
, bind
){
763 for ( var key
in this ){
764 if ( this . hasOwnProperty ( key
) && fn
. call ( bind
, this [ key
], key
)) return true ;
771 Hash
. each ( this , function ( value
, key
){
777 getValues : function (){
779 Hash
. each ( this , function ( value
){
785 toQueryString : function ( base
){
786 var queryString
= [];
787 Hash
. each ( this , function ( value
, key
){
788 if ( base
) key
= base
+ '[' + key
+ ']' ;
790 switch ($ type ( value
)){
791 case 'object' : result
= Hash
. toQueryString ( value
, key
); break ;
794 value
. each ( function ( val
, i
){
797 result
= Hash
. toQueryString ( qs
, key
);
799 default : result
= key
+ '=' + encodeURIComponent ( value
);
801 if ( value
!= undefined ) queryString
. push ( result
);
804 return queryString
. join ( '&' );
809 Hash
. alias ({ keyOf : 'indexOf' , hasValue : 'contains' });
817 description: Contains the Class Function for easily creating, extending, and implementing reusable Classes.
819 license: MIT-style license.
821 requires: [$util, Native, Array, String, Function, Number, Hash]
828 function Class ( params
){
830 if ( params
instanceof Function
) params
= { initialize : params
};
832 var newClass = function (){
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
;
841 newClass
. implement ( params
);
843 newClass
. constructor = Class
;
844 newClass
. prototype . constructor = newClass
;
850 Function
. prototype . protect = function (){
851 this . _protected
= true ;
855 Object
. reset = function ( object
, key
){
858 for ( var p
in object
) Object
. reset ( object
, p
);
864 switch ($ type ( object
[ key
])){
866 var F = function (){};
867 F
. prototype = object
[ key
];
869 object
[ key
] = Object
. reset ( i
);
871 case 'array' : object
[ key
] = $ unlink ( object
[ key
]); break ;
878 new Native ({ name : 'Class' , initialize : Class
}). extend ({
880 instantiate : function ( F
){
881 F
. _prototyping
= true ;
883 delete F
. _prototyping
;
887 wrap : function ( self
, key
, method
){
888 if ( method
. _origin
) method
= method
. _origin
;
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
;
897 }. extend ({ _owner : self
, _origin : method
, _name : key
});
905 implement : function ( key
, value
){
907 if ($ type ( key
) == 'object' ){
908 for ( var p
in key
) this . implement ( p
, key
[ p
]);
912 var mutator
= Class
. Mutators
[ key
];
915 value
= mutator
. call ( this , value
);
916 if ( value
== null ) return this ;
919 var proto
= this . prototype ;
921 switch ($ type ( value
)){
924 if ( value
. _hidden
) return this ;
925 proto
[ key
] = Class
. wrap ( this , key
, value
);
929 var previous
= proto
[ key
];
930 if ($ type ( previous
) == 'object' ) $ mixin ( previous
, value
);
931 else proto
[ key
] = $ unlink ( value
);
935 proto
[ key
] = $ unlink ( value
);
938 default : proto
[ key
] = value
;
950 Extends : function ( parent
){
952 this . parent
= parent
;
953 this . prototype = Class
. instantiate ( parent
);
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
);
963 Implements : function ( items
){
964 $ splat ( items
). each ( function ( item
){
965 if ( item
instanceof Function
) item
= Class
. instantiate ( item
);
966 this . implement ( item
);
979 description: Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks.
981 license: MIT-style license.
985 provides: [Chain, Events, Options, Class.Extras]
990 var Chain
= new Class ({
995 this .$ chain
. extend ( Array
. flatten ( arguments
));
999 callChain : function (){
1000 return ( this .$ chain
. length
) ? this .$ chain
. shift (). apply ( this , arguments
) : false ;
1003 clearChain : function (){
1004 this .$ chain
. empty ();
1010 var Events
= new Class ({
1014 addEvent : function ( type
, fn
, internal ){
1015 type
= Events
. removeOn ( type
);
1017 this .$ events
[ type
] = this .$ events
[ type
] || [];
1018 this .$ events
[ type
]. include ( fn
);
1019 if ( internal ) fn
. internal = true ;
1024 addEvents : function ( events
){
1025 for ( var type
in events
) this . addEvent ( type
, events
[ type
]);
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
})();
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
);
1045 removeEvents : function ( events
){
1047 if ($ type ( events
) == 'object' ){
1048 for ( type
in events
) this . removeEvent ( type
, events
[ type
]);
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
]);
1062 Events
. removeOn = function ( string
){
1063 return string
. replace ( /^on([A-Z])/ , function ( full
, first
){
1064 return first
. toLowerCase ();
1068 var Options
= new Class ({
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
];
1089 description: The Browser Core. Contains Browser initialization, Window and Document, and the Browser Hash.
1091 license: MIT-style license.
1093 requires: [Native, $util]
1095 provides: [Browser, Window, Document, $exec]
1100 var Browser
= $ merge ({
1102 Engine : { name : 'unknown' , version : 0 },
1104 Platform : { name : ( window
. orientation
!= undefined ) ? 'ipod' : ( navigator
. platform
. match ( /mac|win|linux/i ) || [ 'other' ])[ 0 ]. toLowerCase ()},
1106 Features : { xpath : !!( document
. evaluate
), air : !!( window
. runtime
), query : !!( document
. querySelector
)},
1113 return (! window
. opera
) ? false : (( arguments
. callee
. caller
) ? 960 : (( document
. getElementsByClassName
) ? 950 : 925 ));
1116 trident : function (){
1117 return (! window
. ActiveXObject
) ? false : (( window
. XMLHttpRequest
) ? (( document
. querySelectorAll
) ? 6 : 5 ) : 4 );
1121 return ( navigator
. taintEnabled
) ? false : (( Browser
. Features
. xpath
) ? (( Browser
. Features
. query
) ? 525 : 420 ) : 419 );
1125 return (! document
. getBoxObjectFor
&& window
. mozInnerScreenX
== null ) ? false : (( document
. getElementsByClassName
) ? 19 : 18 );
1132 Browser
. Platform
[ Browser
. Platform
. name
] = true ;
1134 Browser
. detect = function (){
1136 for ( var engine
in this . Engines
){
1137 var version
= this . Engines
[ engine
]();
1139 this . Engine
= { name : engine
, version : version
};
1140 this . Engine
[ engine
] = this . Engine
[ engine
+ version
] = true ;
1145 return { name : engine
, version : version
};
1151 Browser
. Request = function (){
1152 return $ try ( function (){
1153 return new XMLHttpRequest ();
1155 return new ActiveXObject ( 'MSXML2.XMLHTTP' );
1157 return new ActiveXObject ( 'Microsoft.XMLHTTP' );
1161 Browser
. Features
. xhr
= !!( Browser
. Request ());
1163 Browser
. Plugins
. Flash
= ( function (){
1164 var version
= ($ try ( function (){
1165 return navigator
. plugins
[ 'Shockwave Flash' ]. description
;
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 };
1172 function $ exec ( text
){
1173 if (! text
) return text
;
1174 if ( window
. execScript
){
1175 window
. execScript ( text
);
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
);
1188 var $ uid
= ( Browser
. Engine
. trident
) ? function ( item
){
1189 return ( item
. uid
|| ( item
. uid
= [ Native
. UID
++]))[ 0 ];
1191 return item
. uid
|| ( item
. uid
= Native
. UID
++);
1194 var Window
= new Native ({
1198 legacy : ( Browser
. Engine
. trident
) ? null : window
. Window
,
1200 initialize : function ( win
){
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]]" ] : {};
1207 win
. document
. window
= win
;
1208 return $ extend ( win
, Window
. Prototype
);
1211 afterImplement : function ( property
, value
){
1212 window
[ property
] = Window
. Prototype
[ property
] = value
;
1217 Window
. Prototype
= {$ family : { name : 'window' }};
1221 var Document
= new Native ({
1225 legacy : ( Browser
. Engine
. trident
) ? null : window
. Document
,
1227 initialize : function ( 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 );
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 ;
1238 return $ extend ( doc
, Document
. Prototype
);
1241 afterImplement : function ( property
, value
){
1242 document
[ property
] = Document
. Prototype
[ property
] = value
;
1247 Document
. Prototype
= {$ family : { name : 'document' }};
1249 new Document ( document
);
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.
1259 license: MIT-style license.
1261 requires: [Window, Document, Array, String, Function, Number, Hash]
1263 provides: [Element, Elements, $, $$, Iframe]
1268 var Element
= new Native ({
1272 legacy : window
. Element
,
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
);
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' );
1291 return ( elements
) ? new Elements ( items
) : items
;
1297 Element
. Prototype
= {$ family : { name : 'element' }};
1299 Element
. Constructors
= new Hash
;
1301 var IFrame
= new Native ({
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
;
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
);
1324 onload
. call ( iframe
. contentWindow
, iframe
. contentWindow
. document
);
1326 var contentWindow
= $ try ( function (){
1327 return iframe
. contentWindow
;
1329 (( contentWindow
&& contentWindow
. document
. body
) || window
. frames
[ props
. id
]) ? onFrameLoad () : iframe
. addListener ( 'load' , onFrameLoad
);
1335 var Elements
= new Native ({
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
);
1345 if ( uniques
[ el
. uid
]) continue ;
1346 uniques
[ el
. uid
] = true ;
1348 if ( el
) returned
. push ( el
);
1350 elements
= returned
;
1352 return ( options
. cash
) ? $ extend ( elements
, this ) : elements
;
1357 Elements
. implement ({
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
);
1371 var createElementAcceptsHTML
;
1373 var x
= document
. createElement ( '<input name=x>' );
1374 createElementAcceptsHTML
= ( x
. name
== 'x' );
1377 var escapeQuotes = function ( html
){
1378 return ( '' + html
). replace ( /&/g,'&').replace(/ "/g,'"');
1382 Document.implement({
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){
1389 if (props.name) tag += ' name=" ' + escapeQuotes(props.name) + ' "';
1390 if (props.type) tag += ' type=" ' + escapeQuotes(props.type) + ' "';
1396 return this.id(this.createElement(tag)).set(props);
1399 newTextNode: function(text){
1400 return this.createTextNode(text);
1403 getDocument: function(){
1407 getWindow: function(){
1415 string: function(id, nocash, doc){
1416 id = doc.getElementById(id);
1417 return (id) ? types.element(id, nocash) : null;
1420 element: function(el, nocash){
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];
1429 object: function(obj, nocash, doc){
1430 if (obj.toElement) return types.element(obj.toElement(doc), nocash);
1436 types.textnode = types.whitespace = types.window = types.document = $arguments(0);
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;
1450 if (window.$ == null) Window.implement({
1451 $: function(el, nc){
1452 return document.id(el, nc, this.document);
1458 $$: function(selector){
1459 if (arguments.length == 1 && typeof selector == 'string') return this.document.getElements(selector);
1461 var args = Array.flatten(arguments);
1462 for (var i = 0, l = args.length; i < l; i++){
1464 switch ($type(item)){
1465 case 'element': elements.push(item); break;
1466 case 'string': elements.extend(this.document.getElements(item, true));
1469 return new Elements(elements);
1472 getDocument: function(){
1473 return this.document;
1476 getWindow: function(){
1482 Native.implement([Element, Document], {
1484 getElement: function(selector, nocash){
1485 return document.id(this.getElements(selector, true)[0] || null, nocash);
1488 getElements: function(tags, nocash){
1489 tags = tags.split(',');
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;
1496 return new Elements(elements, {ddup: ddup, cash: !nocash});
1503 var collected = {}, storage = {};
1504 var props = {input: 'checked', option: 'selected', textarea: (Browser.Engine.webkit && Browser.Engine.version < 420) ? 'innerHTML' : 'value'};
1506 var get = function(uid){
1507 return (storage[uid] || (storage[uid] = {}));
1510 var clean = function(item, retain){
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();
1522 if ((/object/i).test(item.tagName)){
1523 for (var p in item){
1524 if (typeof item[p] == 'function') item[p] = $empty;
1526 Element.dispose(item);
1530 collected[uid] = storage[uid] = null;
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;
1540 var walk = function(element, walk, start, match, all, nocash){
1541 var el = element[start || walk];
1544 if (el.nodeType == 1 && (!match || Element.match(el, match))){
1545 if (!all) return document.id(el, nocash);
1550 return (all) ? new Elements(elements, {ddup: false, cash: !nocash}) : null;
1554 'html': 'innerHTML',
1555 'class': 'className',
1557 'defaultValue': 'defaultValue',
1558 'text': (Browser.Engine.trident || (Browser.Engine.webkit && Browser.Engine.version < 420)) ? 'innerText' : 'textContent'
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'];
1563 bools = bools.associate(bools);
1565 Hash.extend(attributes, bools);
1566 Hash.extend(attributes, camels.associate(camels.map(String.toLowerCase)));
1570 before: function(context, element){
1571 if (element.parentNode) element.parentNode.insertBefore(context, element);
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);
1580 bottom: function(context, element){
1581 element.appendChild(context);
1584 top: function(context, element){
1585 var first = element.firstChild;
1586 (first) ? element.insertBefore(context, first) : element.appendChild(context);
1591 inserters.inside = inserters.bottom;
1593 Hash.each(inserters, function(inserter, where){
1595 where = where.capitalize();
1597 Element.implement('inject' + where, function(el){
1598 inserter(this, document.id(el, true));
1602 Element.implement('grab' + where, function(el){
1603 inserter(document.id(el, true), this);
1611 set: function(prop, value){
1612 switch ($type(prop)){
1614 for (var p in prop) this.set(p, prop[p]);
1617 var property = Element.Properties.get(prop);
1618 (property && property.set) ? property.set.apply(this, Array.slice(arguments, 1)) : this.setProperty(prop, value);
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);
1628 erase: function(prop){
1629 var property = Element.Properties.get(prop);
1630 (property && property.erase) ? property.erase.apply(this) : this.removeProperty(prop);
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);
1642 setProperties: function(attributes){
1643 for (var attribute in attributes) this.setProperty(attribute, attributes[attribute]);
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;
1653 getProperties: function(){
1654 var args = $A(arguments);
1655 return args.map(this.getProperty, this).associate(args);
1658 removeProperty: function(attribute){
1659 var key = attributes[attribute];
1660 (key) ? this[key] = (key && bools[attribute]) ? false : '' : this.removeAttribute(attribute);
1664 removeProperties: function(){
1665 Array.each(arguments, this.removeProperty, this);
1669 hasClass: function(className){
1670 return this.className.contains(className, ' ');
1673 addClass: function(className){
1674 if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean();
1678 removeClass: function(className){
1679 this.className = this.className.replace(new RegExp('(^| \\ s)' + className + '(?: \\ s|$)'), '$1');
1683 toggleClass: function(className){
1684 return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
1688 Array.flatten(arguments).each(function(element){
1689 element = document.id(element, true);
1690 if (element) this.appendChild(element);
1695 appendText: function(text, where){
1696 return this.grab(this.getDocument().newTextNode(text), where);
1699 grab: function(el, where){
1700 inserters[where || 'bottom'](document.id(el, true), this);
1704 inject: function(el, where){
1705 inserters[where || 'bottom'](this, document.id(el, true));
1709 replaces: function(el){
1710 el = document.id(el, true);
1711 el.parentNode.replaceChild(this, el);
1715 wraps: function(el, where){
1716 el = document.id(el, true);
1717 return this.replaces(el).grab(el, where);
1720 getPrevious: function(match, nocash){
1721 return walk(this, 'previousSibling', null, match, false, nocash);
1724 getAllPrevious: function(match, nocash){
1725 return walk(this, 'previousSibling', null, match, true, nocash);
1728 getNext: function(match, nocash){
1729 return walk(this, 'nextSibling', null, match, false, nocash);
1732 getAllNext: function(match, nocash){
1733 return walk(this, 'nextSibling', null, match, true, nocash);
1736 getFirst: function(match, nocash){
1737 return walk(this, 'nextSibling', 'firstChild', match, false, nocash);
1740 getLast: function(match, nocash){
1741 return walk(this, 'previousSibling', 'lastChild', match, false, nocash);
1744 getParent: function(match, nocash){
1745 return walk(this, 'parentNode', null, match, false, nocash);
1748 getParents: function(match, nocash){
1749 return walk(this, 'parentNode', null, match, true, nocash);
1752 getSiblings: function(match, nocash){
1753 return this.getParent().getChildren(match, nocash).erase(this);
1756 getChildren: function(match, nocash){
1757 return walk(this, 'nextSibling', 'firstChild', match, true, nocash);
1760 getWindow: function(){
1761 return this.ownerDocument.window;
1764 getDocument: function(){
1765 return this.ownerDocument;
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;
1774 return document.id(el, nocash);
1777 getSelected: function(){
1778 return new Elements($A(this.options).filter(function(option){
1779 return option.selected;
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;
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){
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));
1800 return queryString.join('&');
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');
1813 var no = node.options, eo = element.options;
1814 for (var j = no.length; j--;) no[j].selected = eo[j].selected;
1817 var prop = props[element.tagName.toLowerCase()];
1818 if (prop && element[prop]) node[prop] = element[prop];
1822 var ce = clone.getElementsByTagName('*'), te = this.getElementsByTagName('*');
1823 for (var i = ce.length; i--;) clean(ce[i], te[i]);
1827 return document.id(clone);
1830 destroy: function(){
1831 Element.empty(this);
1832 Element.dispose(this);
1838 $A(this.childNodes).each(function(node){
1839 Element.destroy(node);
1844 dispose: function(){
1845 return (this.parentNode) ? this.parentNode.removeChild(this) : this;
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);
1855 match: function(tag){
1856 return (!tag || (tag == this) || (Element.get(this, 'tag') == tag));
1861 Native.implement([Element, Window, Document], {
1863 addListener: function(type, fn){
1864 if (type == 'unload'){
1865 var old = fn, self = this;
1867 self.removeListener('unload', fn);
1871 collected[this.uid] = this;
1873 if (this.addEventListener) this.addEventListener(type, fn, false);
1874 else this.attachEvent('on' + type, fn);
1878 removeListener: function(type, fn){
1879 if (this.removeEventListener) this.removeEventListener(type, fn, false);
1880 else this.detachEvent('on' + type, fn);
1884 retrieve: function(property, dflt){
1885 var storage = get(this.uid), prop = storage[property];
1886 if (dflt != undefined && prop == undefined) prop = storage[property] = dflt;
1890 store: function(property, value){
1891 var storage = get(this.uid);
1892 storage[property] = value;
1896 eliminate: function(property){
1897 var storage = get(this.uid);
1898 delete storage[property];
1904 window.addListener('unload', purge);
1908 Element.Properties = new Hash;
1910 Element.Properties.style = {
1912 set: function(style){
1913 this.style.cssText = style;
1917 return this.style.cssText;
1921 this.style.cssText = '';
1926 Element.Properties.tag = {
1929 return this.tagName.toLowerCase();
1934 Element.Properties.html = (function(){
1935 var wrapper = document.createElement('div');
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>']
1943 translations.thead = translations.tfoot = translations.tbody;
1947 var html = Array.flatten(arguments).join('');
1948 var wrap = Browser.Engine.trident && translations[this.get('tag')];
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);
1955 this.innerHTML = html;
1960 html.erase = html.set;
1965 if (Browser.Engine.webkit && Browser.Engine.version < 420) Element.Properties.text = {
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;
1979 name: Element.Dimensions
1981 description: Contains methods to work with size, scroll, or positioning of Elements and the window object.
1983 license: MIT-style license.
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).
1991 provides: Element.Dimensions
2000 scrollTo: function(x, y){
2002 this.getWindow().scrollTo(x, y);
2004 this.scrollLeft = x;
2010 getSize: function(){
2011 if (isBody(this)) return this.getWindow().getSize();
2012 return {x: this.offsetWidth, y: this.offsetHeight};
2015 getScrollSize: function(){
2016 if (isBody(this)) return this.getWindow().getScrollSize();
2017 return {x: this.scrollWidth, y: this.scrollHeight};
2020 getScroll: function(){
2021 if (isBody(this)) return this.getWindow().getScroll();
2022 return {x: this.scrollLeft, y: this.scrollTop};
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;
2035 getOffsetParent: function(){
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;
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');
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
2060 var element = this, position = {x: 0, y: 0};
2061 if (isBody(this)) return position;
2063 while (element && !isBody(element)){
2064 position.x += element.offsetLeft;
2065 position.y += element.offsetTop;
2067 if (Browser.Engine.gecko){
2068 if (!borderBox(element)){
2069 position.x += leftBorder(element);
2070 position.y += topBorder(element);
2072 var parent = element.parentNode;
2073 if (parent && styleString(parent, 'overflow') != 'visible'){
2074 position.x += leftBorder(parent);
2075 position.y += topBorder(parent);
2077 } else if (element != this && Browser.Engine.webkit){
2078 position.x += leftBorder(element);
2079 position.y += topBorder(element);
2082 element = element.offsetParent;
2084 if (Browser.Engine.gecko && !borderBox(this)){
2085 position.x -= leftBorder(this);
2086 position.y -= topBorder(this);
2091 getPosition: function(relative){
2092 if (isBody(this)) return {x: 0, y: 0};
2093 var offset = this.getOffsets(),
2094 scroll = this.getScrolls();
2096 x: offset.x - scroll.x,
2097 y: offset.y - scroll.y
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};
2103 getCoordinates: function(element){
2104 if (isBody(this)) return this.getWindow().getCoordinates();
2105 var position = this.getPosition(element),
2106 size = this.getSize();
2113 obj.right = obj.left + obj.width;
2114 obj.bottom = obj.top + obj.height;
2118 computePosition: function(obj){
2120 left: obj.x - styleNumber(this, 'margin-left'),
2121 top: obj.y - styleNumber(this, 'margin-top')
2125 setPosition: function(obj){
2126 return this.setStyles(this.computePosition(obj));
2132 Native.implement([Document, Window], {
2134 getSize: function(){
2135 if (Browser.Engine.presto || Browser.Engine.webkit){
2136 var win = this.getWindow();
2137 return {x: win.innerWidth, y: win.innerHeight};
2139 var doc = getCompatElement(this);
2140 return {x: doc.clientWidth, y: doc.clientHeight};
2143 getScroll: function(){
2144 var win = this.getWindow(), doc = getCompatElement(this);
2145 return {x: win.pageXOffset || doc.scrollLeft, y: win.pageYOffset || doc.scrollTop};
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)};
2153 getPosition: function(){
2154 return {x: 0, y: 0};
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};
2166 var styleString = Element.getComputedStyle;
2168 function styleNumber(element, style){
2169 return styleString(element, style).toInt() || 0;
2172 function borderBox(element){
2173 return styleString(element, '-moz-box-sizing') == 'border-box';
2176 function topBorder(element){
2177 return styleNumber(element, 'border-top-width');
2180 function leftBorder(element){
2181 return styleNumber(element, 'border-left-width');
2184 function isBody(element){
2185 return (/^(?:body|html)$/i).test(element.tagName);
2188 function getCompatElement(element){
2189 var doc = element.getDocument();
2190 return (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body;
2196 Element.alias('setPosition', 'position'); //compatability
2198 Native.implement([Window, Document, Element], {
2200 getHeight: function(){
2201 return this.getSize().y;
2204 getWidth: function(){
2205 return this.getSize().x;
2208 getScrollTop: function(){
2209 return this.getScroll().y;
2212 getScrollLeft: function(){
2213 return this.getScroll().x;
2216 getScrollHeight: function(){
2217 return this.getScrollSize().y;
2220 getScrollWidth: function(){
2221 return this.getScrollSize().x;
2225 return this.getPosition().y;
2228 getLeft: function(){
2229 return this.getPosition().x;
2240 description: Contains the Event Class, to make the event object cross-browser.
2242 license: MIT-style license.
2244 requires: [Window, Document, Hash, Array, Function, String]
2251 var Event = new Native({
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;
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;
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;
2276 x: event.pageX || event.clientX + doc.scrollLeft,
2277 y: event.pageY || event.clientY + doc.scrollTop
2280 x: (event.pageX) ? event.pageX - win.pageXOffset : event.clientX,
2281 y: (event.pageY) ? event.pageY - win.pageYOffset : event.clientY
2283 if (type.match(/DOMMouseScroll|mousewheel/)){
2284 var wheel = (event.wheelDelta) ? event.wheelDelta / 120 : -(event.detail || 0) / 3;
2286 var rightClick = (event.which == 3) || (event.button == 2);
2288 if (type.match(/over|out/)){
2290 case 'mouseover': related = event.relatedTarget || event.fromElement; break;
2291 case 'mouseout': related = event.relatedTarget || event.toElement;
2294 while (related && related.nodeType == 3) related = related.parentNode;
2296 }).create({attempt: Browser.Engine.gecko})()) related = false;
2300 return $extend(this, {
2306 rightClick: rightClick,
2310 relatedTarget: related,
2316 shift: event.shiftKey,
2317 control: event.ctrlKey,
2325 Event.Keys = new Hash({
2341 return this.stopPropagation().preventDefault();
2344 stopPropagation: function(){
2345 if (this.event.stopPropagation) this.event.stopPropagation();
2346 else this.event.cancelBubble = true;
2350 preventDefault: function(){
2351 if (this.event.preventDefault) this.event.preventDefault();
2352 else this.event.returnValue = false;
2364 description: Contains Element methods for dealing with events. This file also includes mouseenter and mouseleave custom Element Events.
2366 license: MIT-style license.
2368 requires: [Element, Event]
2370 provides: Element.Event
2375 Element.Properties.events = {set: function(events){
2376 this.addEvents(events);
2379 Native.implement([Element, Window, Document], {
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;
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);
2395 realType = custom.base || realType;
2397 var defn = function(){
2398 return fn.call(self);
2400 var nativeEvent = Element.NativeEvents[realType];
2402 if (nativeEvent == 2){
2403 defn = function(event){
2404 event = new Event(event, self.getWindow());
2405 if (condition.call(self, event) === false) event.stop();
2408 this.addListener(realType, defn);
2410 events[type].values.push(defn);
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);
2423 if (custom.onRemove) custom.onRemove.call(this, fn);
2424 type = custom.base || type;
2426 return (Element.NativeEvents[type]) ? this.removeListener(type, value) : this;
2429 addEvents: function(events){
2430 for (var event in events) this.addEvent(event, events[event]);
2434 removeEvents: function(events){
2436 if ($type(events) == 'object'){
2437 for (type in events) this.removeEvent(type, events[type]);
2440 var attached = this.retrieve('events');
2441 if (!attached) return this;
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;
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})();
2461 cloneEvents: function(from, type){
2462 from = document.id(from);
2463 var fevents = from.retrieve('events');
2464 if (!fevents) return this;
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);
2479 if (typeof HTMLElement != 'undefined')
2480 HTMLElement.prototype.fireEvent = Element.prototype.fireEvent;
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
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));
2502 Element.Events = new Hash({
2515 base: (Browser.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel'
2528 description: Contains methods for interacting with the styles of Elements in a fashionable way.
2530 license: MIT-style license.
2534 provides: Element.Style
2539 Element.Properties.styles = {set: function(styles){
2540 this.setStyles(styles);
2543 Element.Properties.opacity = {
2545 set: function(opacity, novisibility){
2548 if (this.style.visibility != 'hidden') this.style.visibility = 'hidden';
2550 if (this.style.visibility != 'visible') this.style.visibility = 'visible';
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);
2560 return this.retrieve('opacity', 1);
2567 setOpacity: function(value){
2568 return this.set('opacity', value, true);
2571 getOpacity: function(){
2572 return this.get('opacity');
2575 setStyle: function(property, value){
2577 case 'opacity': return this.set('opacity', parseFloat(value));
2578 case 'float': property = (Browser.Engine.trident) ? 'styleFloat' : 'cssFloat';
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;
2587 } else if (value == String(Number(value))){
2588 value = Math.round(value);
2590 this.style[property] = value;
2594 getStyle: function(property){
2596 case 'opacity': return this.get('opacity');
2597 case 'float': property = (Browser.Engine.trident) ? 'styleFloat' : 'cssFloat';
2599 property = property.camelCase();
2600 var result = this.style[property];
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(' ');
2608 result = this.getComputedStyle(property);
2611 result = String(result);
2612 var color = result.match(/rgba?\([\d\s,]+\)/);
2613 if (color) result = result.replace(color[0], color[0].rgbToHex());
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();
2621 return this['offset' + property.capitalize()] - size + 'px';
2623 if ((Browser.Engine.presto) && String(result).test('px')) return result;
2624 if (property.test(/(border(.+)Width|margin|padding)/)) return '0px';
2629 setStyles: function(styles){
2630 for (var style in styles) this.setStyle(style, styles[style]);
2634 getStyles: function(){
2636 Array.flatten(arguments).each(function(key){
2637 result[key] = this.getStyle(key);
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: '@'
2654 Element.ShortStyles = {margin: {}, padding: {}, border: {}, borderWidth: {}, borderStyle: {}, borderColor: {}};
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';
2663 var bd = 'border' + direction;
2664 Short.border[bd] = All[bd] = '@px @ rgb(@, @, @)';
2665 var bdw = bd + 'Width', bds = bd + 'Style', bdc = bd + 'Color';
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(@, @, @)';
2678 description: Contains the basic animation logic to be extended by all other Fx Classes.
2680 license: MIT-style license.
2682 requires: [Chain, Events, Options]
2689 var Fx = new Class({
2691 Implements: [Chain, Events, Options],
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';
2713 getTransition: function(){
2715 return -(Math.cos(Math.PI * p) - 1) / 2;
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));
2725 this.set(this.compute(this.from, this.to, 1));
2734 compute: function(from, to, delta){
2735 return Fx.compute(from, to, delta);
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;
2747 start: function(from, to){
2748 if (!this.check(from, to)) return this;
2752 this.transition = this.getTransition();
2758 complete: function(){
2759 if (this.stopTimer()) this.onComplete();
2764 if (this.stopTimer()) this.onCancel();
2768 onStart: function(){
2769 this.fireEvent('start', this.subject);
2772 onComplete: function(){
2773 this.fireEvent('complete', this.subject);
2774 if (!this.callChain()) this.fireEvent('chainComplete', this.subject);
2777 onCancel: function(){
2778 this.fireEvent('cancel', this.subject).clearChain();
2791 stopTimer: function(){
2792 if (!this.timer) return false;
2793 this.time = $time() - this.time;
2794 this.timer = $clear(this.timer);
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);
2807 Fx.compute = function(from, to, delta){
2808 return (to - from) * delta + from;
2811 Fx.Durations = {'short': 250, 'normal': 500, 'long': 1000};
2819 description: Contains the CSS animation logic. Used by Fx.Tween, Fx.Morph, Fx.Elements.
2821 license: MIT-style license.
2823 requires: [Fx, Element.Style]
2830 Fx.CSS = new Class({
2834 //prepares the base from/to object
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);
2843 var parsed = values.map(this.parse);
2844 return {from: parsed[0], to: parsed[1]};
2847 //parses a value into an array
2849 parse: function(value){
2850 value = $lambda(value)();
2851 value = (typeof value == 'string') ? value.split(' ') : $splat(value);
2852 return value.map(function(val){
2855 Fx.CSS.Parsers.each(function(parser, key){
2857 var parsed = parser.parse(val);
2858 if ($chk(parsed)) found = {value: parsed, parser: parser};
2860 found = found || {value: val, parser: Fx.CSS.Parsers.String};
2865 //computes by a from and to prepared objects, using their parsers.
2867 compute: function(from, to, delta){
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});
2872 computed.$family = {name: 'fx:css:value'};
2876 //serves the value as settable
2878 serve: function(value, unit){
2879 if ($type(value) != 'fx:css:value') value = this.parse(value);
2881 value.each(function(bit){
2882 returned = returned.concat(bit.parser.serve(bit.value, unit));
2887 //renders the change to an element
2889 render: function(element, property, value, unit){
2890 element.setStyle(property, this.serve(value, unit));
2893 //searches inside the page css to find the values for a selector
2895 search: function(selector){
2896 if (Fx.CSS.Cache[selector]) return Fx.CSS.Cache[selector];
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();
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;
2915 return Fx.CSS.Cache[selector] = to;
2922 Fx.CSS.Parsers = new Hash({
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;
2929 compute: function(from, to, delta){
2930 return from.map(function(value, i){
2931 return Math.round(Fx.compute(from[i], to[i], delta));
2934 serve: function(value){
2935 return value.map(Number);
2941 compute: Fx.compute,
2942 serve: function(value, unit){
2943 return (unit) ? value + unit : value;
2948 parse: $lambda(false),
2949 compute: $arguments(1),
2950 serve: $arguments(0)
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.
2963 license: MIT-style license.
2972 Fx.Morph = new Class({
2976 initialize: function(element, options){
2977 this.element = this.subject = document.id(element);
2978 this.parent(options);
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);
2987 compute: function(from, to, delta){
2989 for (var p in from) now[p] = this.parent(from[p], to[p], delta);
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;
3002 return this.parent(from, to);
3007 Element.Properties.morph = {
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));
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')));
3020 return this.retrieve('morph');
3027 morph: function(props){
3028 this.get('morph').start(props);
3038 name: Fx.Transitions
3040 description: Contains a set of advanced transitions to be used with any of the Fx Classes.
3042 license: MIT-style license.
3044 credits: Easing Equations by Robert Penner, <http://www.robertpenner.com/easing/>, modified and optimized to be used with MooTools.
3048 provides: Fx.Transitions
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() : '')];
3068 Fx.Transition = function(transition, params){
3069 params = $splat(params);
3070 return $extend(transition, {
3071 easeIn: function(pos){
3072 return transition(pos, params);
3074 easeOut: function(pos){
3075 return 1 - transition(1 - pos, params);
3077 easeInOut: function(pos){
3078 return (pos <= 0.5) ? transition(2 * pos, params) / 2 : (2 - transition(2 * (1 - pos), params)) / 2;
3083 Fx.Transitions = new Hash({
3085 linear: $arguments(0)
3089 Fx.Transitions.extend = function(transitions){
3090 for (var transition in transitions) Fx.Transitions[transition] = new Fx.Transition(transitions[transition]);
3093 Fx.Transitions.extend({
3095 Pow: function(p, x){
3096 return Math.pow(p, x[0] || 6);
3100 return Math.pow(2, 8 * (p - 1));
3104 return 1 - Math.sin(Math.acos(p));
3108 return 1 - Math.sin((1 - p) * Math.PI / 2);
3111 Back: function(p, x){
3113 return Math.pow(p, 2) * ((x + 1) * p - x);
3116 Bounce: function(p){
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);
3127 Elastic: function(p, x){
3128 return Math.pow(2, 10 * --p) * Math.cos(20 * p * Math.PI * (x[0] || 1) / 3);
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]);
3145 description: Formerly Fx.Style, effect to transition any CSS property for an element.
3147 license: MIT-style license.
3151 provides: [Fx.Tween, Element.fade, Element.highlight]
3156 Fx.Tween = new Class({
3160 initialize: function(element, options){
3161 this.element = this.subject = document.id(element);
3162 this.parent(options);
3165 set: function(property, now){
3166 if (arguments.length == 1){
3168 property = this.property || this.options.property;
3170 this.render(this.element, property, now, this.options.unit);
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);
3184 Element.Properties.tween = {
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));
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')));
3197 return this.retrieve('tween');
3204 tween: function(property, from, to){
3205 this.get('tween').start(arguments);
3209 fade: function(how){
3210 var fade = this.get('tween'), o = 'opacity', toggle;
3211 how = $pick(how, 'toggle');
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;
3218 var flag = this.retrieve('fade:flag', this.get('opacity') == 1);
3219 fade.start(o, (flag) ? 0 : 1);
3220 this.store('fade:flag', !flag);
3223 default: fade.start(o, arguments);
3225 if (!toggle) this.eliminate('fade:flag');
3229 highlight: function(start, end){
3231 end = this.retrieve('highlight:original', this.getStyle('background-color'));
3232 end = (end == 'transparent') ? '#fff' : end;
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'));
3250 description: Powerful all purpose Request Class. Uses XMLHTTPRequest.
3252 license: MIT-style license.
3254 requires: [Element, Chain, Events, Options, Browser]
3261 var Request = new Class({
3263 Implements: [Chain, Events, Options],
3271 onException: $empty,*/
3275 'X-Requested-With': 'XMLHttpRequest',
3276 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
3287 evalResponse: false,
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);
3298 onStateChange: function(){
3299 if (this.xhr.readyState != 4 || !this.running) return;
3300 this.running = false;
3303 this.status = this.xhr.status;
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);
3310 this.response = {text: null, xml: null};
3315 isSuccess: function(){
3316 return ((this.status >= 200) && (this.status < 300));
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);
3324 success: function(text, xml){
3325 this.onSuccess(this.processScripts(text), xml);
3328 onSuccess: function(){
3329 this.fireEvent('complete', arguments).fireEvent('success', arguments).callChain();
3332 failure: function(){
3336 onFailure: function(){
3337 this.fireEvent('complete').fireEvent('failure', this.xhr);
3340 setHeader: function(name, value){
3341 this.headers.set(name, value);
3345 getHeader: function(name){
3346 return $try(function(){
3347 return this.xhr.getResponseHeader(name);
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;
3360 send: function(options){
3361 if (!this.check(options)) return this;
3362 this.running = true;
3364 var type = $type(options);
3365 if (type == 'string' || type == 'element') options = {data: options};
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();
3371 switch ($type(data)){
3372 case 'element': data = document.id(data).toQueryString(); break;
3373 case 'object': case 'hash': data = Hash.toQueryString(data);
3376 if (this.options.format){
3377 var format = 'format=' + this.options.format;
3378 data = (data) ? format + '&' + data : format;
3381 if (this.options.emulation && !['get', 'post'].contains(method)){
3382 var _method = '_method=' + method;
3383 data = (data) ? _method + '&' + data : _method;
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);
3392 if (this.options.noCache){
3393 var noCache = 'noCache=' + new Date().getTime();
3394 data = (data) ? noCache + '&' + data : noCache;
3397 var trimPosition = url.lastIndexOf('/');
3398 if (trimPosition > -1 && (trimPosition = url.indexOf('#')) > -1) url = url.substr(0, trimPosition);
3400 if (data && method == 'get'){
3401 url = url + (url.contains('?') ? '&' : '?') + data;
3405 this.xhr.open(method.toUpperCase(), url, this.options.async);
3407 this.xhr.onreadystatechange = this.onStateChange.bind(this);
3409 this.headers.each(function(value, key){
3411 this.xhr.setRequestHeader(key, value);
3413 this.fireEvent('exception', [key, value]);
3417 this.fireEvent('request');
3418 this.xhr.send(data);
3419 if (!this.options.async) this.onStateChange();
3424 if (!this.running) return this;
3425 this.running = false;
3427 this.xhr.onreadystatechange = $empty;
3428 this.xhr = new Browser.Request();
3429 this.fireEvent('cancel');
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}));
3445 Request.implement(methods);
3449 Element.Properties.send = {
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')
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')));
3464 return this.retrieve('send');
3471 send: function(url){
3472 var sender = this.get('send');
3473 sender.send({data: this, url: url || sender.options.url});
3485 description: Extends the basic Request Class with additional methods for interacting with HTML responses.
3487 license: MIT-style license.
3489 requires: [Request, Element]
3491 provides: Request.HTML
3496 Request.HTML = new Class({
3507 processHTML: function(text){
3508 var match = text.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
3509 text = (match) ? match[1] : text;
3511 var container = new Element('div');
3513 return $try(function(){
3514 var root = '<root>' + text + '</root>', doc;
3515 if (Browser.Engine.trident){
3516 doc = new ActiveXObject('Microsoft.XMLDOM');
3520 doc = new DOMParser().parseFromString(root, 'text/xml');
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);
3529 }) || container.set('html', text);
3532 success: function(text){
3533 var options = this.options, response = this.response;
3535 response.html = text.stripScripts(function(script){
3536 response.javascript = script;
3539 var temp = this.processHTML(response.html);
3541 response.tree = temp.childNodes;
3542 response.elements = temp.getElements('*');
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);
3549 this.onSuccess(response.tree, response.elements, response.html, response.javascript);
3554 Element.Properties.load = {
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));
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')));
3567 return this.retrieve('load');
3575 this.get('load').send(Array.link(arguments, {data: Object.type, url: String.type}));
3587 description: JSON encoder and decoder.
3589 license: MIT-style license.
3591 see: <http://www.json.org/>
3593 requires: [Array, String, Number, Function, Hash]
3600 var JSON = new Hash(this.JSON && {
3601 stringify: JSON.stringify,
3605 $specialChars: {' \b ': ' \\ b', ' \t ': ' \\ t', ' \n ': ' \\ n', ' \f ': ' \\ f', ' \r ': ' \\ r', '" ' : ' \\ "', ' \\ ': ' \\\\ '},
3607 $replaceChars: function(chr){
3608 return JSON.$specialChars[chr] || ' \\ u00' + Math.floor(chr.charCodeAt() / 16).toString(16) + (chr.charCodeAt() % 16).toString(16);
3611 encode: function(obj){
3612 switch ($type(obj)){
3614 return '" ' + obj.replace(/[ \x00 - \x1f\\ "]/g, JSON.$replaceChars) + ' "';
3616 return '[' + String(obj.map(JSON.encode).clean()) + ']';
3617 case 'object': case 'hash':
3619 Hash.each(obj, function(value, key){
3620 var json = JSON.encode(value);
3621 if (json) string.push(JSON.encode(key) + ':' + json);
3623 return '{' + string + '}';
3624 case 'number': case 'boolean': return String(obj);
3625 case false: return 'null';
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
+ ')' );
3644 description: Extends the basic Request Class with additional methods for sending and receiving JSON data.
3646 license: MIT-style license.
3648 requires: [Request, JSON]
3650 provides: [Request.JSON]
3655 Request
. JSON
= new Class ({
3663 initialize : function ( options
){
3664 this . parent ( options
);
3665 this . headers
. extend ({ 'Accept' : 'application/json' , 'X-Request' : 'JSON' });
3668 success : function ( text
){
3669 this . response
. json
= JSON
. decode ( text
, this . options
. secure
);
3670 this . onSuccess ( this . response
. json
, text
);
3681 description: Class for creating, reading, and deleting browser Cookies.
3683 license: MIT-style license.
3685 credits: Based on the functions by Peter-Paul Koch (http://quirksmode.org).
3694 var Cookie
= new Class ({
3696 Implements : Options
,
3706 initialize : function ( key
, options
){
3708 this . setOptions ( options
);
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 ();
3720 if ( this . options
. secure
) value
+= '; secure' ;
3721 this . options
. document
. cookie
= this . key
+ '=' + value
;
3726 var value
= this . options
. document
. cookie
. match ( '(?:^|;) \\ s*' + this . key
. escapeRegExp () + '=([^;]*)' );
3727 return ( value
) ? decodeURIComponent ( value
[ 1 ]) : null ;
3730 dispose : function (){
3731 new Cookie ( this . key
, $ merge ( this . options
, { duration : - 1 })). write ( '' );
3737 Cookie
. write = function ( key
, value
, options
){
3738 return new Cookie ( key
, options
). write ( value
);
3741 Cookie
. read = function ( key
){
3742 return new Cookie ( key
). read ();
3745 Cookie
. dispose = function ( key
, options
){
3746 return new Cookie ( key
, options
). dispose ();
3755 description: Contains the custom event domready.
3757 license: MIT-style license.
3759 requires: Element.Event
3766 Element
. Events
. domready
= {
3768 onAdd : function ( fn
){
3769 if ( Browser
. loaded
) fn
. call ( this );
3776 var domready = function (){
3777 if ( Browser
. loaded
) return ;
3778 Browser
. loaded
= true ;
3779 window
. fireEvent ( 'domready' );
3780 document
. fireEvent ( 'domready' );
3783 window
. addEvent ( 'load' , domready
);
3785 if ( Browser
. Engine
. trident
){
3786 var temp
= document
. createElement ( 'div' );
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 );
3793 } else if ( Browser
. Engine
. webkit
&& Browser
. Engine
. version
< 525 ){
3795 ([ 'loaded' , 'complete' ]. contains ( document
. readyState
)) ? domready () : arguments
. callee
. delay ( 50 );
3798 document
. addEvent ( 'DOMContentLoaded' , domready
);
3809 description: Adds advanced CSS-style querying capabilities for targeting HTML Elements. Includes pseudo selectors.
3811 license: MIT-style license.
3820 Native
. implement ([ Document
, Element
], {
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
);
3830 return new Elements ( items
, { ddup : ( expression
. length
> 1 ), cash : ! nocash
});
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 ;
3848 var Selectors
= { Cache : { nth : {}, parsed : {}}};
3850 Selectors
. RegExps
= {
3853 quick : ( /^(\w+|\*)$/ ),
3854 splitter : ( /\s*([+>~\s])\s*([a-zA-Z#.*:\[])/g ),
3855 combined : ( /\.([\w-]+)|\[(\w+)(?:([!*^$~|]?=)(["']?)([^\4]*?)\4)?\]|:([\w-]+)(?:\(["']?(.*?)?["']?\)|$)/g )
3860 chk : function ( item
, uniques
){
3861 if (! uniques
) return true ;
3862 var uid
= $ uid ( item
);
3863 if (! uniques
[ uid
]) return uniques
[ uid
] = true ;
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 ;
3877 while ( b
< 1 ) b
+= a
;
3878 while ( b
>= a
) b
-= a
;
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' };
3893 return Selectors
. Cache
. nth
[ argument
] = parsed
;
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 ];
3902 parsed
. classes
. push ( cn
);
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
});
3908 parsed
. attributes
. push ({ name : an
, operator : ao
, value : av
});
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
;
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 ];
3924 filter : function ( item
, parsed
, local
){
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 ;
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 ;
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 ;
3947 getByTagAndID : function ( ctx
, tag
, id
){
3949 var item
= ( ctx
. getElementById
) ? ctx
. getElementById ( id
, true ) : Element
. getElementById ( ctx
, id
, true );
3950 return ( item
&& Selectors
. Filters
. byTag ( item
, tag
)) ? [ item
] : [];
3952 return ctx
. getElementsByTagName ( tag
);
3956 search : function ( self
, expression
, local
){
3959 var selectors
= expression
. trim (). replace ( Selectors
. RegExps
. splitter
, function ( m0
, m1
, m2
){
3964 var items
, filtered
, item
;
3966 for ( var i
= 0 , l
= selectors
. length
; i
< l
; i
++){
3968 var selector
= selectors
[ i
];
3970 if ( i
== 0 && Selectors
. RegExps
. quick
. test ( selector
)){
3971 items
= self
. getElementsByTagName ( selector
);
3975 var splitter
= splitters
[ i
- 1 ];
3977 var tagid
= Selectors
. Utils
. parseTagAndID ( selector
);
3978 var tag
= tagid
[ 0 ], id
= tagid
[ 1 ];
3981 items
= Selectors
. Utils
. getByTagAndID ( self
, tag
, id
);
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
);
3988 var parsed
= Selectors
. Utils
. parseSelector ( selector
);
3992 for ( var m
= 0 , n
= items
. length
; m
< n
; m
++){
3994 if ( Selectors
. Utils
. filter ( item
, parsed
, local
)) filtered
. push ( item
);
4007 Selectors
. Getters
= {
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
);
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
);
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
);
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
);
4049 Selectors
. Filters
= {
4051 byTag : function ( self
, tag
){
4052 return ( tag
== '*' || ( self
. tagName
&& self
. tagName
. toLowerCase () == tag
));
4055 byID : function ( self
, id
){
4056 return (! id
|| ( self
. id
&& self
. id
== id
));
4059 byClass : function ( self
, klass
){
4060 return ( self
. className
&& self
. className
. contains
&& self
. className
. contains ( klass
, ' ' ));
4063 byPseudo : function ( self
, parser
, argument
, local
){
4064 return parser
. call ( self
, argument
, local
);
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 ;
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
, '-' );
4085 Selectors
. Pseudo
= new Hash ({
4087 // w3c pseudo selectors
4089 checked : function (){
4090 return this . checked
;
4094 return !( this . innerText
|| this . textContent
|| '' ). length
;
4097 not : function ( selector
){
4098 return ! Element
. match ( this , selector
);
4101 contains : function ( text
){
4102 return ( this . innerText
|| this . textContent
|| '' ). contains ( text
);
4105 'first-child' : function (){
4106 return Selectors
. Pseudo
. index
. call ( this , 0 );
4109 'last-child' : function (){
4111 while (( element
= element
. nextSibling
)){
4112 if ( element
. nodeType
== 1 ) return false ;
4117 'only-child' : function (){
4119 while (( prev
= prev
. previousSibling
)){
4120 if ( prev
. nodeType
== 1 ) return false ;
4123 while (( next
= next
. nextSibling
)){
4124 if ( next
. nodeType
== 1 ) return false ;
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
);
4134 local
. positions
= local
. positions
|| {};
4135 var uid
= $ uid ( this );
4136 if (! local
. positions
[ uid
]){
4138 while (( self
= self
. previousSibling
)){
4139 if ( self
. nodeType
!= 1 ) continue ;
4141 var position
= local
. positions
[$ uid ( self
)];
4142 if ( position
!= undefined ){
4143 count
= position
+ count
;
4147 local
. positions
[ uid
] = count
;
4149 return ( local
. positions
[ uid
] % parsed
. a
== parsed
. b
);
4152 // custom pseudo selectors
4154 index : function ( index
){
4155 var element
= this , count
= 0 ;
4156 while (( element
= element
. previousSibling
)){
4157 if ( element
. nodeType
== 1 && ++ count
> index
) return false ;
4159 return ( count
== index
);
4162 even : function ( argument
, local
){
4163 return Selectors
. Pseudo
[ 'nth-child' ]. call ( this , '2n+1' , local
);
4166 odd : function ( argument
, local
){
4167 return Selectors
. Pseudo
[ 'nth-child' ]. call ( this , '2n' , local
);
4170 selected : function (){
4171 return this . selected
;
4174 enabled : function (){
4175 return ( this . disabled
=== false );
4186 description: Wrapper for embedding SWF movies. Supports External Interface Communication.
4188 license: MIT-style license.
4190 credits: Flash detection & Internet Explorer + Flash Player 9 fix inspired by SWFObject.
4192 requires: [Options, $util]
4199 var Swiff
= new Class ({
4201 Implements : [ Options
],
4211 allowScriptAccess : 'always' ,
4212 wMode : 'transparent' ,
4219 toElement : function (){
4223 initialize : function ( path
, options
){
4224 this . instance
= 'Swiff_' + $ time ();
4226 this . setOptions ( options
);
4227 options
= this . options
;
4228 var id
= this . id
= options
. id
|| this . instance
;
4229 var container
= document
. id ( options
. container
);
4231 Swiff
. CallBacks
[ this . instance
] = {};
4233 var params
= options
. params
, vars
= options
. vars
, callBacks
= options
. callBacks
;
4234 var properties
= $ extend ({ height : options
. height
, width : options
. width
}, options
. properties
);
4238 for ( var callBack
in callBacks
){
4239 Swiff
. CallBacks
[ this . instance
][ callBack
] = ( function ( option
){
4241 return option
. apply ( self
. object
, arguments
);
4243 })( callBacks
[ callBack
]);
4244 vars
[ callBack
] = 'Swiff.CallBacks.' + this . instance
+ '.' + callBack
;
4247 params
. flashVars
= Hash
. toQueryString ( vars
);
4248 if ( Browser
. Engine
. trident
){
4249 properties
. classid
= 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ;
4250 params
. movie
= path
;
4252 properties
. type
= 'application/x-shockwave-flash' ;
4253 properties
. data
= path
;
4255 var build
= '<object id="' + id
+ '"' ;
4256 for ( var property
in properties
) build
+= ' ' + property
+ '="' + properties
[ property
] + '"' ;
4258 for ( var param
in params
){
4259 if ( params
[ param
]) build
+= '<param name="' + param
+ '" value="' + params
[ param
] + '" />' ;
4261 build
+= '</object>' ;
4262 this . object
= (( container
) ? container
. empty () : new Element ( 'div' )). set ( 'html' , build
). firstChild
;
4265 replaces : function ( element
){
4266 element
= document
. id ( element
, true );
4267 element
. parentNode
. replaceChild ( this . toElement (), element
);
4271 inject : function ( element
){
4272 document
. id ( element
, true ). appendChild ( this . toElement ());
4277 return Swiff
. remote
. apply ( Swiff
, [ this . toElement ()]. extend ( arguments
));
4282 Swiff
. CallBacks
= {};
4284 Swiff
. remote = function ( obj
, fn
){
4285 var rs
= obj
. CallFunction ( '<invoke name="' + fn
+ '" returntype="javascript">' + __flash__argumentsToXML ( arguments
, 2 ) + '</invoke>' );