mootools-1.2.1.js 135 KB

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