mootools.js 147 KB

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