mootools.js 115 KB

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