prototype.js 195 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590
  1. // Modified document.on() to modified.p_on() to fix compatibility with Dojo -fox
  2. /* Prototype JavaScript framework, version 1.7.3
  3. * (c) 2005-2010 Sam Stephenson
  4. *
  5. * Prototype is freely distributable under the terms of an MIT-style license.
  6. * For details, see the Prototype web site: http://www.prototypejs.org/
  7. *
  8. *--------------------------------------------------------------------------*/
  9. var Prototype = {
  10. Version: '1.7.3',
  11. Browser: (function(){
  12. var ua = navigator.userAgent;
  13. var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
  14. return {
  15. IE: !!window.attachEvent && !isOpera,
  16. Opera: isOpera,
  17. WebKit: ua.indexOf('AppleWebKit/') > -1,
  18. Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1,
  19. MobileSafari: /Apple.*Mobile/.test(ua)
  20. }
  21. })(),
  22. BrowserFeatures: {
  23. XPath: !!document.evaluate,
  24. SelectorsAPI: !!document.querySelector,
  25. ElementExtensions: (function() {
  26. var constructor = window.Element || window.HTMLElement;
  27. return !!(constructor && constructor.prototype);
  28. })(),
  29. SpecificElementExtensions: (function() {
  30. if (typeof window.HTMLDivElement !== 'undefined')
  31. return true;
  32. var div = document.createElement('div'),
  33. form = document.createElement('form'),
  34. isSupported = false;
  35. if (div['__proto__'] && (div['__proto__'] !== form['__proto__'])) {
  36. isSupported = true;
  37. }
  38. div = form = null;
  39. return isSupported;
  40. })()
  41. },
  42. ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script\\s*>',
  43. JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
  44. emptyFunction: function() { },
  45. K: function(x) { return x }
  46. };
  47. if (Prototype.Browser.MobileSafari)
  48. Prototype.BrowserFeatures.SpecificElementExtensions = false;
  49. /* Based on Alex Arnell's inheritance implementation. */
  50. var Class = (function() {
  51. var IS_DONTENUM_BUGGY = (function(){
  52. for (var p in { toString: 1 }) {
  53. if (p === 'toString') return false;
  54. }
  55. return true;
  56. })();
  57. function subclass() {};
  58. function create() {
  59. var parent = null, properties = $A(arguments);
  60. if (Object.isFunction(properties[0]))
  61. parent = properties.shift();
  62. function klass() {
  63. this.initialize.apply(this, arguments);
  64. }
  65. Object.extend(klass, Class.Methods);
  66. klass.superclass = parent;
  67. klass.subclasses = [];
  68. if (parent) {
  69. subclass.prototype = parent.prototype;
  70. klass.prototype = new subclass;
  71. parent.subclasses.push(klass);
  72. }
  73. for (var i = 0, length = properties.length; i < length; i++)
  74. klass.addMethods(properties[i]);
  75. if (!klass.prototype.initialize)
  76. klass.prototype.initialize = Prototype.emptyFunction;
  77. klass.prototype.constructor = klass;
  78. return klass;
  79. }
  80. function addMethods(source) {
  81. var ancestor = this.superclass && this.superclass.prototype,
  82. properties = Object.keys(source);
  83. if (IS_DONTENUM_BUGGY) {
  84. if (source.toString != Object.prototype.toString)
  85. properties.push("toString");
  86. if (source.valueOf != Object.prototype.valueOf)
  87. properties.push("valueOf");
  88. }
  89. for (var i = 0, length = properties.length; i < length; i++) {
  90. var property = properties[i], value = source[property];
  91. if (ancestor && Object.isFunction(value) &&
  92. value.argumentNames()[0] == "$super") {
  93. var method = value;
  94. value = (function(m) {
  95. return function() { return ancestor[m].apply(this, arguments); };
  96. })(property).wrap(method);
  97. value.valueOf = (function(method) {
  98. return function() { return method.valueOf.call(method); };
  99. })(method);
  100. value.toString = (function(method) {
  101. return function() { return method.toString.call(method); };
  102. })(method);
  103. }
  104. this.prototype[property] = value;
  105. }
  106. return this;
  107. }
  108. return {
  109. create: create,
  110. Methods: {
  111. addMethods: addMethods
  112. }
  113. };
  114. })();
  115. (function() {
  116. var _toString = Object.prototype.toString,
  117. _hasOwnProperty = Object.prototype.hasOwnProperty,
  118. NULL_TYPE = 'Null',
  119. UNDEFINED_TYPE = 'Undefined',
  120. BOOLEAN_TYPE = 'Boolean',
  121. NUMBER_TYPE = 'Number',
  122. STRING_TYPE = 'String',
  123. OBJECT_TYPE = 'Object',
  124. FUNCTION_CLASS = '[object Function]',
  125. BOOLEAN_CLASS = '[object Boolean]',
  126. NUMBER_CLASS = '[object Number]',
  127. STRING_CLASS = '[object String]',
  128. ARRAY_CLASS = '[object Array]',
  129. DATE_CLASS = '[object Date]',
  130. NATIVE_JSON_STRINGIFY_SUPPORT = window.JSON &&
  131. typeof JSON.stringify === 'function' &&
  132. JSON.stringify(0) === '0' &&
  133. typeof JSON.stringify(Prototype.K) === 'undefined';
  134. var DONT_ENUMS = ['toString', 'toLocaleString', 'valueOf',
  135. 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'constructor'];
  136. var IS_DONTENUM_BUGGY = (function(){
  137. for (var p in { toString: 1 }) {
  138. if (p === 'toString') return false;
  139. }
  140. return true;
  141. })();
  142. function Type(o) {
  143. switch(o) {
  144. case null: return NULL_TYPE;
  145. case (void 0): return UNDEFINED_TYPE;
  146. }
  147. var type = typeof o;
  148. switch(type) {
  149. case 'boolean': return BOOLEAN_TYPE;
  150. case 'number': return NUMBER_TYPE;
  151. case 'string': return STRING_TYPE;
  152. }
  153. return OBJECT_TYPE;
  154. }
  155. function extend(destination, source) {
  156. for (var property in source)
  157. destination[property] = source[property];
  158. return destination;
  159. }
  160. function inspect(object) {
  161. try {
  162. if (isUndefined(object)) return 'undefined';
  163. if (object === null) return 'null';
  164. return object.inspect ? object.inspect() : String(object);
  165. } catch (e) {
  166. if (e instanceof RangeError) return '...';
  167. throw e;
  168. }
  169. }
  170. function toJSON(value) {
  171. return Str('', { '': value }, []);
  172. }
  173. function Str(key, holder, stack) {
  174. var value = holder[key];
  175. if (Type(value) === OBJECT_TYPE && typeof value.toJSON === 'function') {
  176. value = value.toJSON(key);
  177. }
  178. var _class = _toString.call(value);
  179. switch (_class) {
  180. case NUMBER_CLASS:
  181. case BOOLEAN_CLASS:
  182. case STRING_CLASS:
  183. value = value.valueOf();
  184. }
  185. switch (value) {
  186. case null: return 'null';
  187. case true: return 'true';
  188. case false: return 'false';
  189. }
  190. var type = typeof value;
  191. switch (type) {
  192. case 'string':
  193. return value.inspect(true);
  194. case 'number':
  195. return isFinite(value) ? String(value) : 'null';
  196. case 'object':
  197. for (var i = 0, length = stack.length; i < length; i++) {
  198. if (stack[i] === value) {
  199. throw new TypeError("Cyclic reference to '" + value + "' in object");
  200. }
  201. }
  202. stack.push(value);
  203. var partial = [];
  204. if (_class === ARRAY_CLASS) {
  205. for (var i = 0, length = value.length; i < length; i++) {
  206. var str = Str(i, value, stack);
  207. partial.push(typeof str === 'undefined' ? 'null' : str);
  208. }
  209. partial = '[' + partial.join(',') + ']';
  210. } else {
  211. var keys = Object.keys(value);
  212. for (var i = 0, length = keys.length; i < length; i++) {
  213. var key = keys[i], str = Str(key, value, stack);
  214. if (typeof str !== "undefined") {
  215. partial.push(key.inspect(true)+ ':' + str);
  216. }
  217. }
  218. partial = '{' + partial.join(',') + '}';
  219. }
  220. stack.pop();
  221. return partial;
  222. }
  223. }
  224. function stringify(object) {
  225. return JSON.stringify(object);
  226. }
  227. function toQueryString(object) {
  228. return $H(object).toQueryString();
  229. }
  230. function toHTML(object) {
  231. return object && object.toHTML ? object.toHTML() : String.interpret(object);
  232. }
  233. function keys(object) {
  234. if (Type(object) !== OBJECT_TYPE) { throw new TypeError(); }
  235. var results = [];
  236. for (var property in object) {
  237. if (_hasOwnProperty.call(object, property))
  238. results.push(property);
  239. }
  240. if (IS_DONTENUM_BUGGY) {
  241. for (var i = 0; property = DONT_ENUMS[i]; i++) {
  242. if (_hasOwnProperty.call(object, property))
  243. results.push(property);
  244. }
  245. }
  246. return results;
  247. }
  248. function values(object) {
  249. var results = [];
  250. for (var property in object)
  251. results.push(object[property]);
  252. return results;
  253. }
  254. function clone(object) {
  255. return extend({ }, object);
  256. }
  257. function isElement(object) {
  258. return !!(object && object.nodeType == 1);
  259. }
  260. function isArray(object) {
  261. return _toString.call(object) === ARRAY_CLASS;
  262. }
  263. var hasNativeIsArray = (typeof Array.isArray == 'function')
  264. && Array.isArray([]) && !Array.isArray({});
  265. if (hasNativeIsArray) {
  266. isArray = Array.isArray;
  267. }
  268. function isHash(object) {
  269. return object instanceof Hash;
  270. }
  271. function isFunction(object) {
  272. return _toString.call(object) === FUNCTION_CLASS;
  273. }
  274. function isString(object) {
  275. return _toString.call(object) === STRING_CLASS;
  276. }
  277. function isNumber(object) {
  278. return _toString.call(object) === NUMBER_CLASS;
  279. }
  280. function isDate(object) {
  281. return _toString.call(object) === DATE_CLASS;
  282. }
  283. function isUndefined(object) {
  284. return typeof object === "undefined";
  285. }
  286. extend(Object, {
  287. extend: extend,
  288. inspect: inspect,
  289. toJSON: NATIVE_JSON_STRINGIFY_SUPPORT ? stringify : toJSON,
  290. toQueryString: toQueryString,
  291. toHTML: toHTML,
  292. keys: Object.keys || keys,
  293. values: values,
  294. clone: clone,
  295. isElement: isElement,
  296. isArray: isArray,
  297. isHash: isHash,
  298. isFunction: isFunction,
  299. isString: isString,
  300. isNumber: isNumber,
  301. isDate: isDate,
  302. isUndefined: isUndefined
  303. });
  304. })();
  305. Object.extend(Function.prototype, (function() {
  306. var slice = Array.prototype.slice;
  307. function update(array, args) {
  308. var arrayLength = array.length, length = args.length;
  309. while (length--) array[arrayLength + length] = args[length];
  310. return array;
  311. }
  312. function merge(array, args) {
  313. array = slice.call(array, 0);
  314. return update(array, args);
  315. }
  316. function argumentNames() {
  317. var names = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
  318. .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
  319. .replace(/\s+/g, '').split(',');
  320. return names.length == 1 && !names[0] ? [] : names;
  321. }
  322. function bind(context) {
  323. if (arguments.length < 2 && Object.isUndefined(arguments[0]))
  324. return this;
  325. if (!Object.isFunction(this))
  326. throw new TypeError("The object is not callable.");
  327. var nop = function() {};
  328. var __method = this, args = slice.call(arguments, 1);
  329. var bound = function() {
  330. var a = merge(args, arguments);
  331. var c = this instanceof bound ? this : context;
  332. return __method.apply(c, a);
  333. };
  334. nop.prototype = this.prototype;
  335. bound.prototype = new nop();
  336. return bound;
  337. }
  338. function bindAsEventListener(context) {
  339. var __method = this, args = slice.call(arguments, 1);
  340. return function(event) {
  341. var a = update([event || window.event], args);
  342. return __method.apply(context, a);
  343. }
  344. }
  345. function curry() {
  346. if (!arguments.length) return this;
  347. var __method = this, args = slice.call(arguments, 0);
  348. return function() {
  349. var a = merge(args, arguments);
  350. return __method.apply(this, a);
  351. }
  352. }
  353. function delay(timeout) {
  354. var __method = this, args = slice.call(arguments, 1);
  355. timeout = timeout * 1000;
  356. return window.setTimeout(function() {
  357. return __method.apply(__method, args);
  358. }, timeout);
  359. }
  360. function defer() {
  361. var args = update([0.01], arguments);
  362. return this.delay.apply(this, args);
  363. }
  364. function wrap(wrapper) {
  365. var __method = this;
  366. return function() {
  367. var a = update([__method.bind(this)], arguments);
  368. return wrapper.apply(this, a);
  369. }
  370. }
  371. function methodize() {
  372. if (this._methodized) return this._methodized;
  373. var __method = this;
  374. return this._methodized = function() {
  375. var a = update([this], arguments);
  376. return __method.apply(null, a);
  377. };
  378. }
  379. var extensions = {
  380. argumentNames: argumentNames,
  381. bindAsEventListener: bindAsEventListener,
  382. curry: curry,
  383. delay: delay,
  384. defer: defer,
  385. wrap: wrap,
  386. methodize: methodize
  387. };
  388. if (!Function.prototype.bind)
  389. extensions.bind = bind;
  390. return extensions;
  391. })());
  392. (function(proto) {
  393. function toISOString() {
  394. return this.getUTCFullYear() + '-' +
  395. (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
  396. this.getUTCDate().toPaddedString(2) + 'T' +
  397. this.getUTCHours().toPaddedString(2) + ':' +
  398. this.getUTCMinutes().toPaddedString(2) + ':' +
  399. this.getUTCSeconds().toPaddedString(2) + 'Z';
  400. }
  401. function toJSON() {
  402. return this.toISOString();
  403. }
  404. if (!proto.toISOString) proto.toISOString = toISOString;
  405. if (!proto.toJSON) proto.toJSON = toJSON;
  406. })(Date.prototype);
  407. RegExp.prototype.match = RegExp.prototype.test;
  408. RegExp.escape = function(str) {
  409. return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
  410. };
  411. var PeriodicalExecuter = Class.create({
  412. initialize: function(callback, frequency) {
  413. this.callback = callback;
  414. this.frequency = frequency;
  415. this.currentlyExecuting = false;
  416. this.registerCallback();
  417. },
  418. registerCallback: function() {
  419. this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
  420. },
  421. execute: function() {
  422. this.callback(this);
  423. },
  424. stop: function() {
  425. if (!this.timer) return;
  426. clearInterval(this.timer);
  427. this.timer = null;
  428. },
  429. onTimerEvent: function() {
  430. if (!this.currentlyExecuting) {
  431. try {
  432. this.currentlyExecuting = true;
  433. this.execute();
  434. this.currentlyExecuting = false;
  435. } catch(e) {
  436. this.currentlyExecuting = false;
  437. throw e;
  438. }
  439. }
  440. }
  441. });
  442. Object.extend(String, {
  443. interpret: function(value) {
  444. return value == null ? '' : String(value);
  445. },
  446. specialChar: {
  447. '\b': '\\b',
  448. '\t': '\\t',
  449. '\n': '\\n',
  450. '\f': '\\f',
  451. '\r': '\\r',
  452. '\\': '\\\\'
  453. }
  454. });
  455. Object.extend(String.prototype, (function() {
  456. var NATIVE_JSON_PARSE_SUPPORT = window.JSON &&
  457. typeof JSON.parse === 'function' &&
  458. JSON.parse('{"test": true}').test;
  459. function prepareReplacement(replacement) {
  460. if (Object.isFunction(replacement)) return replacement;
  461. var template = new Template(replacement);
  462. return function(match) { return template.evaluate(match) };
  463. }
  464. function isNonEmptyRegExp(regexp) {
  465. return regexp.source && regexp.source !== '(?:)';
  466. }
  467. function gsub(pattern, replacement) {
  468. var result = '', source = this, match;
  469. replacement = prepareReplacement(replacement);
  470. if (Object.isString(pattern))
  471. pattern = RegExp.escape(pattern);
  472. if (!(pattern.length || isNonEmptyRegExp(pattern))) {
  473. replacement = replacement('');
  474. return replacement + source.split('').join(replacement) + replacement;
  475. }
  476. while (source.length > 0) {
  477. match = source.match(pattern)
  478. if (match && match[0].length > 0) {
  479. result += source.slice(0, match.index);
  480. result += String.interpret(replacement(match));
  481. source = source.slice(match.index + match[0].length);
  482. } else {
  483. result += source, source = '';
  484. }
  485. }
  486. return result;
  487. }
  488. function sub(pattern, replacement, count) {
  489. replacement = prepareReplacement(replacement);
  490. count = Object.isUndefined(count) ? 1 : count;
  491. return this.gsub(pattern, function(match) {
  492. if (--count < 0) return match[0];
  493. return replacement(match);
  494. });
  495. }
  496. function scan(pattern, iterator) {
  497. this.gsub(pattern, iterator);
  498. return String(this);
  499. }
  500. function truncate(length, truncation) {
  501. length = length || 30;
  502. truncation = Object.isUndefined(truncation) ? '...' : truncation;
  503. return this.length > length ?
  504. this.slice(0, length - truncation.length) + truncation : String(this);
  505. }
  506. function strip() {
  507. return this.replace(/^\s+/, '').replace(/\s+$/, '');
  508. }
  509. function stripTags() {
  510. return this.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?(\/)?>|<\/\w+>/gi, '');
  511. }
  512. function stripScripts() {
  513. return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
  514. }
  515. function extractScripts() {
  516. var matchAll = new RegExp(Prototype.ScriptFragment, 'img'),
  517. matchOne = new RegExp(Prototype.ScriptFragment, 'im');
  518. return (this.match(matchAll) || []).map(function(scriptTag) {
  519. return (scriptTag.match(matchOne) || ['', ''])[1];
  520. });
  521. }
  522. function evalScripts() {
  523. return this.extractScripts().map(function(script) { return eval(script); });
  524. }
  525. function escapeHTML() {
  526. return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
  527. }
  528. function unescapeHTML() {
  529. return this.stripTags().replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');
  530. }
  531. function toQueryParams(separator) {
  532. var match = this.strip().match(/([^?#]*)(#.*)?$/);
  533. if (!match) return { };
  534. return match[1].split(separator || '&').inject({ }, function(hash, pair) {
  535. if ((pair = pair.split('='))[0]) {
  536. var key = decodeURIComponent(pair.shift()),
  537. value = pair.length > 1 ? pair.join('=') : pair[0];
  538. if (value != undefined) {
  539. value = value.gsub('+', ' ');
  540. value = decodeURIComponent(value);
  541. }
  542. if (key in hash) {
  543. if (!Object.isArray(hash[key])) hash[key] = [hash[key]];
  544. hash[key].push(value);
  545. }
  546. else hash[key] = value;
  547. }
  548. return hash;
  549. });
  550. }
  551. function toArray() {
  552. return this.split('');
  553. }
  554. function succ() {
  555. return this.slice(0, this.length - 1) +
  556. String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
  557. }
  558. function times(count) {
  559. return count < 1 ? '' : new Array(count + 1).join(this);
  560. }
  561. function camelize() {
  562. return this.replace(/-+(.)?/g, function(match, chr) {
  563. return chr ? chr.toUpperCase() : '';
  564. });
  565. }
  566. function capitalize() {
  567. return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
  568. }
  569. function underscore() {
  570. return this.replace(/::/g, '/')
  571. .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
  572. .replace(/([a-z\d])([A-Z])/g, '$1_$2')
  573. .replace(/-/g, '_')
  574. .toLowerCase();
  575. }
  576. function dasherize() {
  577. return this.replace(/_/g, '-');
  578. }
  579. function inspect(useDoubleQuotes) {
  580. var escapedString = this.replace(/[\x00-\x1f\\]/g, function(character) {
  581. if (character in String.specialChar) {
  582. return String.specialChar[character];
  583. }
  584. return '\\u00' + character.charCodeAt().toPaddedString(2, 16);
  585. });
  586. if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
  587. return "'" + escapedString.replace(/'/g, '\\\'') + "'";
  588. }
  589. function unfilterJSON(filter) {
  590. return this.replace(filter || Prototype.JSONFilter, '$1');
  591. }
  592. function isJSON() {
  593. var str = this;
  594. if (str.blank()) return false;
  595. str = str.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@');
  596. str = str.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']');
  597. str = str.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
  598. return (/^[\],:{}\s]*$/).test(str);
  599. }
  600. function evalJSON(sanitize) {
  601. var json = this.unfilterJSON(),
  602. cx = /[\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff\u0000]/g;
  603. if (cx.test(json)) {
  604. json = json.replace(cx, function (a) {
  605. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  606. });
  607. }
  608. try {
  609. if (!sanitize || json.isJSON()) return eval('(' + json + ')');
  610. } catch (e) { }
  611. throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
  612. }
  613. function parseJSON() {
  614. var json = this.unfilterJSON();
  615. return JSON.parse(json);
  616. }
  617. function include(pattern) {
  618. return this.indexOf(pattern) > -1;
  619. }
  620. function startsWith(pattern, position) {
  621. position = Object.isNumber(position) ? position : 0;
  622. return this.lastIndexOf(pattern, position) === position;
  623. }
  624. function endsWith(pattern, position) {
  625. pattern = String(pattern);
  626. position = Object.isNumber(position) ? position : this.length;
  627. if (position < 0) position = 0;
  628. if (position > this.length) position = this.length;
  629. var d = position - pattern.length;
  630. return d >= 0 && this.indexOf(pattern, d) === d;
  631. }
  632. function empty() {
  633. return this == '';
  634. }
  635. function blank() {
  636. return /^\s*$/.test(this);
  637. }
  638. function interpolate(object, pattern) {
  639. return new Template(this, pattern).evaluate(object);
  640. }
  641. return {
  642. gsub: gsub,
  643. sub: sub,
  644. scan: scan,
  645. truncate: truncate,
  646. strip: String.prototype.trim || strip,
  647. stripTags: stripTags,
  648. stripScripts: stripScripts,
  649. extractScripts: extractScripts,
  650. evalScripts: evalScripts,
  651. escapeHTML: escapeHTML,
  652. unescapeHTML: unescapeHTML,
  653. toQueryParams: toQueryParams,
  654. parseQuery: toQueryParams,
  655. toArray: toArray,
  656. succ: succ,
  657. times: times,
  658. camelize: camelize,
  659. capitalize: capitalize,
  660. underscore: underscore,
  661. dasherize: dasherize,
  662. inspect: inspect,
  663. unfilterJSON: unfilterJSON,
  664. isJSON: isJSON,
  665. evalJSON: NATIVE_JSON_PARSE_SUPPORT ? parseJSON : evalJSON,
  666. include: include,
  667. startsWith: String.prototype.startsWith || startsWith,
  668. endsWith: String.prototype.endsWith || endsWith,
  669. empty: empty,
  670. blank: blank,
  671. interpolate: interpolate
  672. };
  673. })());
  674. var Template = Class.create({
  675. initialize: function(template, pattern) {
  676. this.template = template.toString();
  677. this.pattern = pattern || Template.Pattern;
  678. },
  679. evaluate: function(object) {
  680. if (object && Object.isFunction(object.toTemplateReplacements))
  681. object = object.toTemplateReplacements();
  682. return this.template.gsub(this.pattern, function(match) {
  683. if (object == null) return (match[1] + '');
  684. var before = match[1] || '';
  685. if (before == '\\') return match[2];
  686. var ctx = object, expr = match[3],
  687. pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
  688. match = pattern.exec(expr);
  689. if (match == null) return before;
  690. while (match != null) {
  691. var comp = match[1].startsWith('[') ? match[2].replace(/\\\\]/g, ']') : match[1];
  692. ctx = ctx[comp];
  693. if (null == ctx || '' == match[3]) break;
  694. expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);
  695. match = pattern.exec(expr);
  696. }
  697. return before + String.interpret(ctx);
  698. });
  699. }
  700. });
  701. Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
  702. var $break = { };
  703. var Enumerable = (function() {
  704. function each(iterator, context) {
  705. try {
  706. this._each(iterator, context);
  707. } catch (e) {
  708. if (e != $break) throw e;
  709. }
  710. return this;
  711. }
  712. function eachSlice(number, iterator, context) {
  713. var index = -number, slices = [], array = this.toArray();
  714. if (number < 1) return array;
  715. while ((index += number) < array.length)
  716. slices.push(array.slice(index, index+number));
  717. return slices.collect(iterator, context);
  718. }
  719. function all(iterator, context) {
  720. iterator = iterator || Prototype.K;
  721. var result = true;
  722. this.each(function(value, index) {
  723. result = result && !!iterator.call(context, value, index, this);
  724. if (!result) throw $break;
  725. }, this);
  726. return result;
  727. }
  728. function any(iterator, context) {
  729. iterator = iterator || Prototype.K;
  730. var result = false;
  731. this.each(function(value, index) {
  732. if (result = !!iterator.call(context, value, index, this))
  733. throw $break;
  734. }, this);
  735. return result;
  736. }
  737. function collect(iterator, context) {
  738. iterator = iterator || Prototype.K;
  739. var results = [];
  740. this.each(function(value, index) {
  741. results.push(iterator.call(context, value, index, this));
  742. }, this);
  743. return results;
  744. }
  745. function detect(iterator, context) {
  746. var result;
  747. this.each(function(value, index) {
  748. if (iterator.call(context, value, index, this)) {
  749. result = value;
  750. throw $break;
  751. }
  752. }, this);
  753. return result;
  754. }
  755. function findAll(iterator, context) {
  756. var results = [];
  757. this.each(function(value, index) {
  758. if (iterator.call(context, value, index, this))
  759. results.push(value);
  760. }, this);
  761. return results;
  762. }
  763. function grep(filter, iterator, context) {
  764. iterator = iterator || Prototype.K;
  765. var results = [];
  766. if (Object.isString(filter))
  767. filter = new RegExp(RegExp.escape(filter));
  768. this.each(function(value, index) {
  769. if (filter.match(value))
  770. results.push(iterator.call(context, value, index, this));
  771. }, this);
  772. return results;
  773. }
  774. function include(object) {
  775. if (Object.isFunction(this.indexOf) && this.indexOf(object) != -1)
  776. return true;
  777. var found = false;
  778. this.each(function(value) {
  779. if (value == object) {
  780. found = true;
  781. throw $break;
  782. }
  783. });
  784. return found;
  785. }
  786. function inGroupsOf(number, fillWith) {
  787. fillWith = Object.isUndefined(fillWith) ? null : fillWith;
  788. return this.eachSlice(number, function(slice) {
  789. while(slice.length < number) slice.push(fillWith);
  790. return slice;
  791. });
  792. }
  793. function inject(memo, iterator, context) {
  794. this.each(function(value, index) {
  795. memo = iterator.call(context, memo, value, index, this);
  796. }, this);
  797. return memo;
  798. }
  799. function invoke(method) {
  800. var args = $A(arguments).slice(1);
  801. return this.map(function(value) {
  802. return value[method].apply(value, args);
  803. });
  804. }
  805. function max(iterator, context) {
  806. iterator = iterator || Prototype.K;
  807. var result;
  808. this.each(function(value, index) {
  809. value = iterator.call(context, value, index, this);
  810. if (result == null || value >= result)
  811. result = value;
  812. }, this);
  813. return result;
  814. }
  815. function min(iterator, context) {
  816. iterator = iterator || Prototype.K;
  817. var result;
  818. this.each(function(value, index) {
  819. value = iterator.call(context, value, index, this);
  820. if (result == null || value < result)
  821. result = value;
  822. }, this);
  823. return result;
  824. }
  825. function partition(iterator, context) {
  826. iterator = iterator || Prototype.K;
  827. var trues = [], falses = [];
  828. this.each(function(value, index) {
  829. (iterator.call(context, value, index, this) ?
  830. trues : falses).push(value);
  831. }, this);
  832. return [trues, falses];
  833. }
  834. function pluck(property) {
  835. var results = [];
  836. this.each(function(value) {
  837. results.push(value[property]);
  838. });
  839. return results;
  840. }
  841. function reject(iterator, context) {
  842. var results = [];
  843. this.each(function(value, index) {
  844. if (!iterator.call(context, value, index, this))
  845. results.push(value);
  846. }, this);
  847. return results;
  848. }
  849. function sortBy(iterator, context) {
  850. return this.map(function(value, index) {
  851. return {
  852. value: value,
  853. criteria: iterator.call(context, value, index, this)
  854. };
  855. }, this).sort(function(left, right) {
  856. var a = left.criteria, b = right.criteria;
  857. return a < b ? -1 : a > b ? 1 : 0;
  858. }).pluck('value');
  859. }
  860. function toArray() {
  861. return this.map();
  862. }
  863. function zip() {
  864. var iterator = Prototype.K, args = $A(arguments);
  865. if (Object.isFunction(args.last()))
  866. iterator = args.pop();
  867. var collections = [this].concat(args).map($A);
  868. return this.map(function(value, index) {
  869. return iterator(collections.pluck(index));
  870. });
  871. }
  872. function size() {
  873. return this.toArray().length;
  874. }
  875. function inspect() {
  876. return '#<Enumerable:' + this.toArray().inspect() + '>';
  877. }
  878. return {
  879. each: each,
  880. eachSlice: eachSlice,
  881. all: all,
  882. every: all,
  883. any: any,
  884. some: any,
  885. collect: collect,
  886. map: collect,
  887. detect: detect,
  888. findAll: findAll,
  889. select: findAll,
  890. filter: findAll,
  891. grep: grep,
  892. include: include,
  893. member: include,
  894. inGroupsOf: inGroupsOf,
  895. inject: inject,
  896. invoke: invoke,
  897. max: max,
  898. min: min,
  899. partition: partition,
  900. pluck: pluck,
  901. reject: reject,
  902. sortBy: sortBy,
  903. toArray: toArray,
  904. entries: toArray,
  905. zip: zip,
  906. size: size,
  907. inspect: inspect,
  908. find: detect
  909. };
  910. })();
  911. function $A(iterable) {
  912. if (!iterable) return [];
  913. if ('toArray' in Object(iterable)) return iterable.toArray();
  914. var length = iterable.length || 0, results = new Array(length);
  915. while (length--) results[length] = iterable[length];
  916. return results;
  917. }
  918. function $w(string) {
  919. if (!Object.isString(string)) return [];
  920. string = string.strip();
  921. return string ? string.split(/\s+/) : [];
  922. }
  923. Array.from = $A;
  924. (function() {
  925. var arrayProto = Array.prototype,
  926. slice = arrayProto.slice,
  927. _each = arrayProto.forEach; // use native browser JS 1.6 implementation if available
  928. function each(iterator, context) {
  929. for (var i = 0, length = this.length >>> 0; i < length; i++) {
  930. if (i in this) iterator.call(context, this[i], i, this);
  931. }
  932. }
  933. if (!_each) _each = each;
  934. function clear() {
  935. this.length = 0;
  936. return this;
  937. }
  938. function first() {
  939. return this[0];
  940. }
  941. function last() {
  942. return this[this.length - 1];
  943. }
  944. function compact() {
  945. return this.select(function(value) {
  946. return value != null;
  947. });
  948. }
  949. function flatten() {
  950. return this.inject([], function(array, value) {
  951. if (Object.isArray(value))
  952. return array.concat(value.flatten());
  953. array.push(value);
  954. return array;
  955. });
  956. }
  957. function without() {
  958. var values = slice.call(arguments, 0);
  959. return this.select(function(value) {
  960. return !values.include(value);
  961. });
  962. }
  963. function reverse(inline) {
  964. return (inline === false ? this.toArray() : this)._reverse();
  965. }
  966. function uniq(sorted) {
  967. return this.inject([], function(array, value, index) {
  968. if (0 == index || (sorted ? array.last() != value : !array.include(value)))
  969. array.push(value);
  970. return array;
  971. });
  972. }
  973. function intersect(array) {
  974. return this.uniq().findAll(function(item) {
  975. return array.indexOf(item) !== -1;
  976. });
  977. }
  978. function clone() {
  979. return slice.call(this, 0);
  980. }
  981. function size() {
  982. return this.length;
  983. }
  984. function inspect() {
  985. return '[' + this.map(Object.inspect).join(', ') + ']';
  986. }
  987. function indexOf(item, i) {
  988. if (this == null) throw new TypeError();
  989. var array = Object(this), length = array.length >>> 0;
  990. if (length === 0) return -1;
  991. i = Number(i);
  992. if (isNaN(i)) {
  993. i = 0;
  994. } else if (i !== 0 && isFinite(i)) {
  995. i = (i > 0 ? 1 : -1) * Math.floor(Math.abs(i));
  996. }
  997. if (i > length) return -1;
  998. var k = i >= 0 ? i : Math.max(length - Math.abs(i), 0);
  999. for (; k < length; k++)
  1000. if (k in array && array[k] === item) return k;
  1001. return -1;
  1002. }
  1003. function lastIndexOf(item, i) {
  1004. if (this == null) throw new TypeError();
  1005. var array = Object(this), length = array.length >>> 0;
  1006. if (length === 0) return -1;
  1007. if (!Object.isUndefined(i)) {
  1008. i = Number(i);
  1009. if (isNaN(i)) {
  1010. i = 0;
  1011. } else if (i !== 0 && isFinite(i)) {
  1012. i = (i > 0 ? 1 : -1) * Math.floor(Math.abs(i));
  1013. }
  1014. } else {
  1015. i = length;
  1016. }
  1017. var k = i >= 0 ? Math.min(i, length - 1) :
  1018. length - Math.abs(i);
  1019. for (; k >= 0; k--)
  1020. if (k in array && array[k] === item) return k;
  1021. return -1;
  1022. }
  1023. function concat(_) {
  1024. var array = [], items = slice.call(arguments, 0), item, n = 0;
  1025. items.unshift(this);
  1026. for (var i = 0, length = items.length; i < length; i++) {
  1027. item = items[i];
  1028. if (Object.isArray(item) && !('callee' in item)) {
  1029. for (var j = 0, arrayLength = item.length; j < arrayLength; j++) {
  1030. if (j in item) array[n] = item[j];
  1031. n++;
  1032. }
  1033. } else {
  1034. array[n++] = item;
  1035. }
  1036. }
  1037. array.length = n;
  1038. return array;
  1039. }
  1040. function wrapNative(method) {
  1041. return function() {
  1042. if (arguments.length === 0) {
  1043. return method.call(this, Prototype.K);
  1044. } else if (arguments[0] === undefined) {
  1045. var args = slice.call(arguments, 1);
  1046. args.unshift(Prototype.K);
  1047. return method.apply(this, args);
  1048. } else {
  1049. return method.apply(this, arguments);
  1050. }
  1051. };
  1052. }
  1053. function map(iterator) {
  1054. if (this == null) throw new TypeError();
  1055. iterator = iterator || Prototype.K;
  1056. var object = Object(this);
  1057. var results = [], context = arguments[1], n = 0;
  1058. for (var i = 0, length = object.length >>> 0; i < length; i++) {
  1059. if (i in object) {
  1060. results[n] = iterator.call(context, object[i], i, object);
  1061. }
  1062. n++;
  1063. }
  1064. results.length = n;
  1065. return results;
  1066. }
  1067. if (arrayProto.map) {
  1068. map = wrapNative(Array.prototype.map);
  1069. }
  1070. function filter(iterator) {
  1071. if (this == null || !Object.isFunction(iterator))
  1072. throw new TypeError();
  1073. var object = Object(this);
  1074. var results = [], context = arguments[1], value;
  1075. for (var i = 0, length = object.length >>> 0; i < length; i++) {
  1076. if (i in object) {
  1077. value = object[i];
  1078. if (iterator.call(context, value, i, object)) {
  1079. results.push(value);
  1080. }
  1081. }
  1082. }
  1083. return results;
  1084. }
  1085. if (arrayProto.filter) {
  1086. filter = Array.prototype.filter;
  1087. }
  1088. function some(iterator) {
  1089. if (this == null) throw new TypeError();
  1090. iterator = iterator || Prototype.K;
  1091. var context = arguments[1];
  1092. var object = Object(this);
  1093. for (var i = 0, length = object.length >>> 0; i < length; i++) {
  1094. if (i in object && iterator.call(context, object[i], i, object)) {
  1095. return true;
  1096. }
  1097. }
  1098. return false;
  1099. }
  1100. if (arrayProto.some) {
  1101. some = wrapNative(Array.prototype.some);
  1102. }
  1103. function every(iterator) {
  1104. if (this == null) throw new TypeError();
  1105. iterator = iterator || Prototype.K;
  1106. var context = arguments[1];
  1107. var object = Object(this);
  1108. for (var i = 0, length = object.length >>> 0; i < length; i++) {
  1109. if (i in object && !iterator.call(context, object[i], i, object)) {
  1110. return false;
  1111. }
  1112. }
  1113. return true;
  1114. }
  1115. if (arrayProto.every) {
  1116. every = wrapNative(Array.prototype.every);
  1117. }
  1118. Object.extend(arrayProto, Enumerable);
  1119. if (arrayProto.entries === Enumerable.entries) {
  1120. delete arrayProto.entries;
  1121. }
  1122. if (!arrayProto._reverse)
  1123. arrayProto._reverse = arrayProto.reverse;
  1124. Object.extend(arrayProto, {
  1125. _each: _each,
  1126. map: map,
  1127. collect: map,
  1128. select: filter,
  1129. filter: filter,
  1130. findAll: filter,
  1131. some: some,
  1132. any: some,
  1133. every: every,
  1134. all: every,
  1135. clear: clear,
  1136. first: first,
  1137. last: last,
  1138. compact: compact,
  1139. flatten: flatten,
  1140. without: without,
  1141. reverse: reverse,
  1142. uniq: uniq,
  1143. intersect: intersect,
  1144. clone: clone,
  1145. toArray: clone,
  1146. size: size,
  1147. inspect: inspect
  1148. });
  1149. var CONCAT_ARGUMENTS_BUGGY = (function() {
  1150. return [].concat(arguments)[0][0] !== 1;
  1151. })(1,2);
  1152. if (CONCAT_ARGUMENTS_BUGGY) arrayProto.concat = concat;
  1153. if (!arrayProto.indexOf) arrayProto.indexOf = indexOf;
  1154. if (!arrayProto.lastIndexOf) arrayProto.lastIndexOf = lastIndexOf;
  1155. })();
  1156. function $H(object) {
  1157. return new Hash(object);
  1158. };
  1159. var Hash = Class.create(Enumerable, (function() {
  1160. function initialize(object) {
  1161. this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
  1162. }
  1163. function _each(iterator, context) {
  1164. var i = 0;
  1165. for (var key in this._object) {
  1166. var value = this._object[key], pair = [key, value];
  1167. pair.key = key;
  1168. pair.value = value;
  1169. iterator.call(context, pair, i);
  1170. i++;
  1171. }
  1172. }
  1173. function set(key, value) {
  1174. return this._object[key] = value;
  1175. }
  1176. function get(key) {
  1177. if (this._object[key] !== Object.prototype[key])
  1178. return this._object[key];
  1179. }
  1180. function unset(key) {
  1181. var value = this._object[key];
  1182. delete this._object[key];
  1183. return value;
  1184. }
  1185. function toObject() {
  1186. return Object.clone(this._object);
  1187. }
  1188. function keys() {
  1189. return this.pluck('key');
  1190. }
  1191. function values() {
  1192. return this.pluck('value');
  1193. }
  1194. function index(value) {
  1195. var match = this.detect(function(pair) {
  1196. return pair.value === value;
  1197. });
  1198. return match && match.key;
  1199. }
  1200. function merge(object) {
  1201. return this.clone().update(object);
  1202. }
  1203. function update(object) {
  1204. return new Hash(object).inject(this, function(result, pair) {
  1205. result.set(pair.key, pair.value);
  1206. return result;
  1207. });
  1208. }
  1209. function toQueryPair(key, value) {
  1210. if (Object.isUndefined(value)) return key;
  1211. value = String.interpret(value);
  1212. value = value.gsub(/(\r)?\n/, '\r\n');
  1213. value = encodeURIComponent(value);
  1214. value = value.gsub(/%20/, '+');
  1215. return key + '=' + value;
  1216. }
  1217. function toQueryString() {
  1218. return this.inject([], function(results, pair) {
  1219. var key = encodeURIComponent(pair.key), values = pair.value;
  1220. if (values && typeof values == 'object') {
  1221. if (Object.isArray(values)) {
  1222. var queryValues = [];
  1223. for (var i = 0, len = values.length, value; i < len; i++) {
  1224. value = values[i];
  1225. queryValues.push(toQueryPair(key, value));
  1226. }
  1227. return results.concat(queryValues);
  1228. }
  1229. } else results.push(toQueryPair(key, values));
  1230. return results;
  1231. }).join('&');
  1232. }
  1233. function inspect() {
  1234. return '#<Hash:{' + this.map(function(pair) {
  1235. return pair.map(Object.inspect).join(': ');
  1236. }).join(', ') + '}>';
  1237. }
  1238. function clone() {
  1239. return new Hash(this);
  1240. }
  1241. return {
  1242. initialize: initialize,
  1243. _each: _each,
  1244. set: set,
  1245. get: get,
  1246. unset: unset,
  1247. toObject: toObject,
  1248. toTemplateReplacements: toObject,
  1249. keys: keys,
  1250. values: values,
  1251. index: index,
  1252. merge: merge,
  1253. update: update,
  1254. toQueryString: toQueryString,
  1255. inspect: inspect,
  1256. toJSON: toObject,
  1257. clone: clone
  1258. };
  1259. })());
  1260. Hash.from = $H;
  1261. Object.extend(Number.prototype, (function() {
  1262. function toColorPart() {
  1263. return this.toPaddedString(2, 16);
  1264. }
  1265. function succ() {
  1266. return this + 1;
  1267. }
  1268. function times(iterator, context) {
  1269. $R(0, this, true).each(iterator, context);
  1270. return this;
  1271. }
  1272. function toPaddedString(length, radix) {
  1273. var string = this.toString(radix || 10);
  1274. return '0'.times(length - string.length) + string;
  1275. }
  1276. function abs() {
  1277. return Math.abs(this);
  1278. }
  1279. function round() {
  1280. return Math.round(this);
  1281. }
  1282. function ceil() {
  1283. return Math.ceil(this);
  1284. }
  1285. function floor() {
  1286. return Math.floor(this);
  1287. }
  1288. return {
  1289. toColorPart: toColorPart,
  1290. succ: succ,
  1291. times: times,
  1292. toPaddedString: toPaddedString,
  1293. abs: abs,
  1294. round: round,
  1295. ceil: ceil,
  1296. floor: floor
  1297. };
  1298. })());
  1299. function $R(start, end, exclusive) {
  1300. return new ObjectRange(start, end, exclusive);
  1301. }
  1302. var ObjectRange = Class.create(Enumerable, (function() {
  1303. function initialize(start, end, exclusive) {
  1304. this.start = start;
  1305. this.end = end;
  1306. this.exclusive = exclusive;
  1307. }
  1308. function _each(iterator, context) {
  1309. var value = this.start, i;
  1310. for (i = 0; this.include(value); i++) {
  1311. iterator.call(context, value, i);
  1312. value = value.succ();
  1313. }
  1314. }
  1315. function include(value) {
  1316. if (value < this.start)
  1317. return false;
  1318. if (this.exclusive)
  1319. return value < this.end;
  1320. return value <= this.end;
  1321. }
  1322. return {
  1323. initialize: initialize,
  1324. _each: _each,
  1325. include: include
  1326. };
  1327. })());
  1328. var Abstract = { };
  1329. var Try = {
  1330. these: function() {
  1331. var returnValue;
  1332. for (var i = 0, length = arguments.length; i < length; i++) {
  1333. var lambda = arguments[i];
  1334. try {
  1335. returnValue = lambda();
  1336. break;
  1337. } catch (e) { }
  1338. }
  1339. return returnValue;
  1340. }
  1341. };
  1342. var Ajax = {
  1343. getTransport: function() {
  1344. return Try.these(
  1345. function() {return new XMLHttpRequest()},
  1346. function() {return new ActiveXObject('Msxml2.XMLHTTP')},
  1347. function() {return new ActiveXObject('Microsoft.XMLHTTP')}
  1348. ) || false;
  1349. },
  1350. activeRequestCount: 0
  1351. };
  1352. Ajax.Responders = {
  1353. responders: [],
  1354. _each: function(iterator, context) {
  1355. this.responders._each(iterator, context);
  1356. },
  1357. register: function(responder) {
  1358. if (!this.include(responder))
  1359. this.responders.push(responder);
  1360. },
  1361. unregister: function(responder) {
  1362. this.responders = this.responders.without(responder);
  1363. },
  1364. dispatch: function(callback, request, transport, json) {
  1365. this.each(function(responder) {
  1366. if (Object.isFunction(responder[callback])) {
  1367. try {
  1368. responder[callback].apply(responder, [request, transport, json]);
  1369. } catch (e) { }
  1370. }
  1371. });
  1372. }
  1373. };
  1374. Object.extend(Ajax.Responders, Enumerable);
  1375. Ajax.Responders.register({
  1376. onCreate: function() { Ajax.activeRequestCount++ },
  1377. onComplete: function() { Ajax.activeRequestCount-- }
  1378. });
  1379. Ajax.Base = Class.create({
  1380. initialize: function(options) {
  1381. this.options = {
  1382. method: 'post',
  1383. asynchronous: true,
  1384. contentType: 'application/x-www-form-urlencoded',
  1385. encoding: 'UTF-8',
  1386. parameters: '',
  1387. evalJSON: true,
  1388. evalJS: true
  1389. };
  1390. Object.extend(this.options, options || { });
  1391. this.options.method = this.options.method.toLowerCase();
  1392. if (Object.isHash(this.options.parameters))
  1393. this.options.parameters = this.options.parameters.toObject();
  1394. }
  1395. });
  1396. Ajax.Request = Class.create(Ajax.Base, {
  1397. _complete: false,
  1398. initialize: function($super, url, options) {
  1399. $super(options);
  1400. this.transport = Ajax.getTransport();
  1401. this.request(url);
  1402. },
  1403. request: function(url) {
  1404. this.url = url;
  1405. this.method = this.options.method;
  1406. var params = Object.isString(this.options.parameters) ?
  1407. this.options.parameters :
  1408. Object.toQueryString(this.options.parameters);
  1409. if (!['get', 'post'].include(this.method)) {
  1410. params += (params ? '&' : '') + "_method=" + this.method;
  1411. this.method = 'post';
  1412. }
  1413. if (params && this.method === 'get') {
  1414. this.url += (this.url.include('?') ? '&' : '?') + params;
  1415. }
  1416. this.parameters = params.toQueryParams();
  1417. try {
  1418. var response = new Ajax.Response(this);
  1419. if (this.options.onCreate) this.options.onCreate(response);
  1420. Ajax.Responders.dispatch('onCreate', this, response);
  1421. this.transport.open(this.method.toUpperCase(), this.url,
  1422. this.options.asynchronous);
  1423. if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);
  1424. this.transport.onreadystatechange = this.onStateChange.bind(this);
  1425. this.setRequestHeaders();
  1426. this.body = this.method == 'post' ? (this.options.postBody || params) : null;
  1427. this.transport.send(this.body);
  1428. /* Force Firefox to handle ready state 4 for synchronous requests */
  1429. if (!this.options.asynchronous && this.transport.overrideMimeType)
  1430. this.onStateChange();
  1431. }
  1432. catch (e) {
  1433. this.dispatchException(e);
  1434. }
  1435. },
  1436. onStateChange: function() {
  1437. var readyState = this.transport.readyState;
  1438. if (readyState > 1 && !((readyState == 4) && this._complete))
  1439. this.respondToReadyState(this.transport.readyState);
  1440. },
  1441. setRequestHeaders: function() {
  1442. var headers = {
  1443. 'X-Requested-With': 'XMLHttpRequest',
  1444. 'X-Prototype-Version': Prototype.Version,
  1445. 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
  1446. };
  1447. if (this.method == 'post') {
  1448. headers['Content-type'] = this.options.contentType +
  1449. (this.options.encoding ? '; charset=' + this.options.encoding : '');
  1450. /* Force "Connection: close" for older Mozilla browsers to work
  1451. * around a bug where XMLHttpRequest sends an incorrect
  1452. * Content-length header. See Mozilla Bugzilla #246651.
  1453. */
  1454. if (this.transport.overrideMimeType &&
  1455. (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
  1456. headers['Connection'] = 'close';
  1457. }
  1458. if (typeof this.options.requestHeaders == 'object') {
  1459. var extras = this.options.requestHeaders;
  1460. if (Object.isFunction(extras.push))
  1461. for (var i = 0, length = extras.length; i < length; i += 2)
  1462. headers[extras[i]] = extras[i+1];
  1463. else
  1464. $H(extras).each(function(pair) { headers[pair.key] = pair.value });
  1465. }
  1466. for (var name in headers)
  1467. if (headers[name] != null)
  1468. this.transport.setRequestHeader(name, headers[name]);
  1469. },
  1470. success: function() {
  1471. var status = this.getStatus();
  1472. return !status || (status >= 200 && status < 300) || status == 304;
  1473. },
  1474. getStatus: function() {
  1475. try {
  1476. if (this.transport.status === 1223) return 204;
  1477. return this.transport.status || 0;
  1478. } catch (e) { return 0 }
  1479. },
  1480. respondToReadyState: function(readyState) {
  1481. var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
  1482. if (state == 'Complete') {
  1483. try {
  1484. this._complete = true;
  1485. (this.options['on' + response.status]
  1486. || this.options['on' + (this.success() ? 'Success' : 'Failure')]
  1487. || Prototype.emptyFunction)(response, response.headerJSON);
  1488. } catch (e) {
  1489. this.dispatchException(e);
  1490. }
  1491. var contentType = response.getHeader('Content-type');
  1492. if (this.options.evalJS == 'force'
  1493. || (this.options.evalJS && this.isSameOrigin() && contentType
  1494. && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
  1495. this.evalResponse();
  1496. }
  1497. try {
  1498. (this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON);
  1499. Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON);
  1500. } catch (e) {
  1501. this.dispatchException(e);
  1502. }
  1503. if (state == 'Complete') {
  1504. this.transport.onreadystatechange = Prototype.emptyFunction;
  1505. }
  1506. },
  1507. isSameOrigin: function() {
  1508. var m = this.url.match(/^\s*https?:\/\/[^\/]*/);
  1509. return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({
  1510. protocol: location.protocol,
  1511. domain: document.domain,
  1512. port: location.port ? ':' + location.port : ''
  1513. }));
  1514. },
  1515. getHeader: function(name) {
  1516. try {
  1517. return this.transport.getResponseHeader(name) || null;
  1518. } catch (e) { return null; }
  1519. },
  1520. evalResponse: function() {
  1521. try {
  1522. return eval((this.transport.responseText || '').unfilterJSON());
  1523. } catch (e) {
  1524. this.dispatchException(e);
  1525. }
  1526. },
  1527. dispatchException: function(exception) {
  1528. (this.options.onException || Prototype.emptyFunction)(this, exception);
  1529. Ajax.Responders.dispatch('onException', this, exception);
  1530. }
  1531. });
  1532. Ajax.Request.Events =
  1533. ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
  1534. Ajax.Response = Class.create({
  1535. initialize: function(request){
  1536. this.request = request;
  1537. var transport = this.transport = request.transport,
  1538. readyState = this.readyState = transport.readyState;
  1539. if ((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) {
  1540. this.status = this.getStatus();
  1541. this.statusText = this.getStatusText();
  1542. this.responseText = String.interpret(transport.responseText);
  1543. this.headerJSON = this._getHeaderJSON();
  1544. }
  1545. if (readyState == 4) {
  1546. var xml = transport.responseXML;
  1547. this.responseXML = Object.isUndefined(xml) ? null : xml;
  1548. this.responseJSON = this._getResponseJSON();
  1549. }
  1550. },
  1551. status: 0,
  1552. statusText: '',
  1553. getStatus: Ajax.Request.prototype.getStatus,
  1554. getStatusText: function() {
  1555. try {
  1556. return this.transport.statusText || '';
  1557. } catch (e) { return '' }
  1558. },
  1559. getHeader: Ajax.Request.prototype.getHeader,
  1560. getAllHeaders: function() {
  1561. try {
  1562. return this.getAllResponseHeaders();
  1563. } catch (e) { return null }
  1564. },
  1565. getResponseHeader: function(name) {
  1566. return this.transport.getResponseHeader(name);
  1567. },
  1568. getAllResponseHeaders: function() {
  1569. return this.transport.getAllResponseHeaders();
  1570. },
  1571. _getHeaderJSON: function() {
  1572. var json = this.getHeader('X-JSON');
  1573. if (!json) return null;
  1574. try {
  1575. json = decodeURIComponent(escape(json));
  1576. } catch(e) {
  1577. }
  1578. try {
  1579. return json.evalJSON(this.request.options.sanitizeJSON ||
  1580. !this.request.isSameOrigin());
  1581. } catch (e) {
  1582. this.request.dispatchException(e);
  1583. }
  1584. },
  1585. _getResponseJSON: function() {
  1586. var options = this.request.options;
  1587. if (!options.evalJSON || (options.evalJSON != 'force' &&
  1588. !(this.getHeader('Content-type') || '').include('application/json')) ||
  1589. this.responseText.blank())
  1590. return null;
  1591. try {
  1592. return this.responseText.evalJSON(options.sanitizeJSON ||
  1593. !this.request.isSameOrigin());
  1594. } catch (e) {
  1595. this.request.dispatchException(e);
  1596. }
  1597. }
  1598. });
  1599. Ajax.Updater = Class.create(Ajax.Request, {
  1600. initialize: function($super, container, url, options) {
  1601. this.container = {
  1602. success: (container.success || container),
  1603. failure: (container.failure || (container.success ? null : container))
  1604. };
  1605. options = Object.clone(options);
  1606. var onComplete = options.onComplete;
  1607. options.onComplete = (function(response, json) {
  1608. this.updateContent(response.responseText);
  1609. if (Object.isFunction(onComplete)) onComplete(response, json);
  1610. }).bind(this);
  1611. $super(url, options);
  1612. },
  1613. updateContent: function(responseText) {
  1614. var receiver = this.container[this.success() ? 'success' : 'failure'],
  1615. options = this.options;
  1616. if (!options.evalScripts) responseText = responseText.stripScripts();
  1617. if (receiver = $(receiver)) {
  1618. if (options.insertion) {
  1619. if (Object.isString(options.insertion)) {
  1620. var insertion = { }; insertion[options.insertion] = responseText;
  1621. receiver.insert(insertion);
  1622. }
  1623. else options.insertion(receiver, responseText);
  1624. }
  1625. else receiver.update(responseText);
  1626. }
  1627. }
  1628. });
  1629. Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {
  1630. initialize: function($super, container, url, options) {
  1631. $super(options);
  1632. this.onComplete = this.options.onComplete;
  1633. this.frequency = (this.options.frequency || 2);
  1634. this.decay = (this.options.decay || 1);
  1635. this.updater = { };
  1636. this.container = container;
  1637. this.url = url;
  1638. this.start();
  1639. },
  1640. start: function() {
  1641. this.options.onComplete = this.updateComplete.bind(this);
  1642. this.onTimerEvent();
  1643. },
  1644. stop: function() {
  1645. this.updater.options.onComplete = undefined;
  1646. clearTimeout(this.timer);
  1647. (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
  1648. },
  1649. updateComplete: function(response) {
  1650. if (this.options.decay) {
  1651. this.decay = (response.responseText == this.lastText ?
  1652. this.decay * this.options.decay : 1);
  1653. this.lastText = response.responseText;
  1654. }
  1655. this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
  1656. },
  1657. onTimerEvent: function() {
  1658. this.updater = new Ajax.Updater(this.container, this.url, this.options);
  1659. }
  1660. });
  1661. (function(GLOBAL) {
  1662. var UNDEFINED;
  1663. var SLICE = Array.prototype.slice;
  1664. var DIV = document.createElement('div');
  1665. function $(element) {
  1666. if (arguments.length > 1) {
  1667. for (var i = 0, elements = [], length = arguments.length; i < length; i++)
  1668. elements.push($(arguments[i]));
  1669. return elements;
  1670. }
  1671. if (Object.isString(element))
  1672. element = document.getElementById(element);
  1673. return Element.extend(element);
  1674. }
  1675. GLOBAL.$ = $;
  1676. if (!GLOBAL.Node) GLOBAL.Node = {};
  1677. if (!GLOBAL.Node.ELEMENT_NODE) {
  1678. Object.extend(GLOBAL.Node, {
  1679. ELEMENT_NODE: 1,
  1680. ATTRIBUTE_NODE: 2,
  1681. TEXT_NODE: 3,
  1682. CDATA_SECTION_NODE: 4,
  1683. ENTITY_REFERENCE_NODE: 5,
  1684. ENTITY_NODE: 6,
  1685. PROCESSING_INSTRUCTION_NODE: 7,
  1686. COMMENT_NODE: 8,
  1687. DOCUMENT_NODE: 9,
  1688. DOCUMENT_TYPE_NODE: 10,
  1689. DOCUMENT_FRAGMENT_NODE: 11,
  1690. NOTATION_NODE: 12
  1691. });
  1692. }
  1693. var ELEMENT_CACHE = {};
  1694. function shouldUseCreationCache(tagName, attributes) {
  1695. if (tagName === 'select') return false;
  1696. if ('type' in attributes) return false;
  1697. return true;
  1698. }
  1699. var HAS_EXTENDED_CREATE_ELEMENT_SYNTAX = (function(){
  1700. try {
  1701. var el = document.createElement('<input name="x">');
  1702. return el.tagName.toLowerCase() === 'input' && el.name === 'x';
  1703. }
  1704. catch(err) {
  1705. return false;
  1706. }
  1707. })();
  1708. var oldElement = GLOBAL.Element;
  1709. function Element(tagName, attributes) {
  1710. attributes = attributes || {};
  1711. tagName = tagName.toLowerCase();
  1712. if (HAS_EXTENDED_CREATE_ELEMENT_SYNTAX && attributes.name) {
  1713. tagName = '<' + tagName + ' name="' + attributes.name + '">';
  1714. delete attributes.name;
  1715. return Element.writeAttribute(document.createElement(tagName), attributes);
  1716. }
  1717. if (!ELEMENT_CACHE[tagName])
  1718. ELEMENT_CACHE[tagName] = Element.extend(document.createElement(tagName));
  1719. var node = shouldUseCreationCache(tagName, attributes) ?
  1720. ELEMENT_CACHE[tagName].cloneNode(false) : document.createElement(tagName);
  1721. return Element.writeAttribute(node, attributes);
  1722. }
  1723. GLOBAL.Element = Element;
  1724. Object.extend(GLOBAL.Element, oldElement || {});
  1725. if (oldElement) GLOBAL.Element.prototype = oldElement.prototype;
  1726. Element.Methods = { ByTag: {}, Simulated: {} };
  1727. var methods = {};
  1728. var INSPECT_ATTRIBUTES = { id: 'id', className: 'class' };
  1729. function inspect(element) {
  1730. element = $(element);
  1731. var result = '<' + element.tagName.toLowerCase();
  1732. var attribute, value;
  1733. for (var property in INSPECT_ATTRIBUTES) {
  1734. attribute = INSPECT_ATTRIBUTES[property];
  1735. value = (element[property] || '').toString();
  1736. if (value) result += ' ' + attribute + '=' + value.inspect(true);
  1737. }
  1738. return result + '>';
  1739. }
  1740. methods.inspect = inspect;
  1741. function visible(element) {
  1742. return $(element).getStyle('display') !== 'none';
  1743. }
  1744. function toggle(element, bool) {
  1745. element = $(element);
  1746. if (typeof bool !== 'boolean')
  1747. bool = !Element.visible(element);
  1748. Element[bool ? 'show' : 'hide'](element);
  1749. return element;
  1750. }
  1751. function hide(element) {
  1752. element = $(element);
  1753. element.style.display = 'none';
  1754. return element;
  1755. }
  1756. function show(element) {
  1757. element = $(element);
  1758. element.style.display = '';
  1759. return element;
  1760. }
  1761. Object.extend(methods, {
  1762. visible: visible,
  1763. toggle: toggle,
  1764. hide: hide,
  1765. show: show
  1766. });
  1767. function remove(element) {
  1768. element = $(element);
  1769. element.parentNode.removeChild(element);
  1770. return element;
  1771. }
  1772. var SELECT_ELEMENT_INNERHTML_BUGGY = (function(){
  1773. var el = document.createElement("select"),
  1774. isBuggy = true;
  1775. el.innerHTML = "<option value=\"test\">test</option>";
  1776. if (el.options && el.options[0]) {
  1777. isBuggy = el.options[0].nodeName.toUpperCase() !== "OPTION";
  1778. }
  1779. el = null;
  1780. return isBuggy;
  1781. })();
  1782. var TABLE_ELEMENT_INNERHTML_BUGGY = (function(){
  1783. try {
  1784. var el = document.createElement("table");
  1785. if (el && el.tBodies) {
  1786. el.innerHTML = "<tbody><tr><td>test</td></tr></tbody>";
  1787. var isBuggy = typeof el.tBodies[0] == "undefined";
  1788. el = null;
  1789. return isBuggy;
  1790. }
  1791. } catch (e) {
  1792. return true;
  1793. }
  1794. })();
  1795. var LINK_ELEMENT_INNERHTML_BUGGY = (function() {
  1796. try {
  1797. var el = document.createElement('div');
  1798. el.innerHTML = "<link />";
  1799. var isBuggy = (el.childNodes.length === 0);
  1800. el = null;
  1801. return isBuggy;
  1802. } catch(e) {
  1803. return true;
  1804. }
  1805. })();
  1806. var ANY_INNERHTML_BUGGY = SELECT_ELEMENT_INNERHTML_BUGGY ||
  1807. TABLE_ELEMENT_INNERHTML_BUGGY || LINK_ELEMENT_INNERHTML_BUGGY;
  1808. var SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING = (function () {
  1809. var s = document.createElement("script"),
  1810. isBuggy = false;
  1811. try {
  1812. s.appendChild(document.createTextNode(""));
  1813. isBuggy = !s.firstChild ||
  1814. s.firstChild && s.firstChild.nodeType !== 3;
  1815. } catch (e) {
  1816. isBuggy = true;
  1817. }
  1818. s = null;
  1819. return isBuggy;
  1820. })();
  1821. function update(element, content) {
  1822. element = $(element);
  1823. var descendants = element.getElementsByTagName('*'),
  1824. i = descendants.length;
  1825. while (i--) purgeElement(descendants[i]);
  1826. if (content && content.toElement)
  1827. content = content.toElement();
  1828. if (Object.isElement(content))
  1829. return element.update().insert(content);
  1830. content = Object.toHTML(content);
  1831. var tagName = element.tagName.toUpperCase();
  1832. if (tagName === 'SCRIPT' && SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING) {
  1833. element.text = content;
  1834. return element;
  1835. }
  1836. if (ANY_INNERHTML_BUGGY) {
  1837. if (tagName in INSERTION_TRANSLATIONS.tags) {
  1838. while (element.firstChild)
  1839. element.removeChild(element.firstChild);
  1840. var nodes = getContentFromAnonymousElement(tagName, content.stripScripts());
  1841. for (var i = 0, node; node = nodes[i]; i++)
  1842. element.appendChild(node);
  1843. } else if (LINK_ELEMENT_INNERHTML_BUGGY && Object.isString(content) && content.indexOf('<link') > -1) {
  1844. while (element.firstChild)
  1845. element.removeChild(element.firstChild);
  1846. var nodes = getContentFromAnonymousElement(tagName,
  1847. content.stripScripts(), true);
  1848. for (var i = 0, node; node = nodes[i]; i++)
  1849. element.appendChild(node);
  1850. } else {
  1851. element.innerHTML = content.stripScripts();
  1852. }
  1853. } else {
  1854. element.innerHTML = content.stripScripts();
  1855. }
  1856. content.evalScripts.bind(content).defer();
  1857. return element;
  1858. }
  1859. function replace(element, content) {
  1860. element = $(element);
  1861. if (content && content.toElement) {
  1862. content = content.toElement();
  1863. } else if (!Object.isElement(content)) {
  1864. content = Object.toHTML(content);
  1865. var range = element.ownerDocument.createRange();
  1866. range.selectNode(element);
  1867. content.evalScripts.bind(content).defer();
  1868. content = range.createContextualFragment(content.stripScripts());
  1869. }
  1870. element.parentNode.replaceChild(content, element);
  1871. return element;
  1872. }
  1873. var INSERTION_TRANSLATIONS = {
  1874. before: function(element, node) {
  1875. element.parentNode.insertBefore(node, element);
  1876. },
  1877. top: function(element, node) {
  1878. element.insertBefore(node, element.firstChild);
  1879. },
  1880. bottom: function(element, node) {
  1881. element.appendChild(node);
  1882. },
  1883. after: function(element, node) {
  1884. element.parentNode.insertBefore(node, element.nextSibling);
  1885. },
  1886. tags: {
  1887. TABLE: ['<table>', '</table>', 1],
  1888. TBODY: ['<table><tbody>', '</tbody></table>', 2],
  1889. TR: ['<table><tbody><tr>', '</tr></tbody></table>', 3],
  1890. TD: ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],
  1891. SELECT: ['<select>', '</select>', 1]
  1892. }
  1893. };
  1894. var tags = INSERTION_TRANSLATIONS.tags;
  1895. Object.extend(tags, {
  1896. THEAD: tags.TBODY,
  1897. TFOOT: tags.TBODY,
  1898. TH: tags.TD
  1899. });
  1900. function replace_IE(element, content) {
  1901. element = $(element);
  1902. if (content && content.toElement)
  1903. content = content.toElement();
  1904. if (Object.isElement(content)) {
  1905. element.parentNode.replaceChild(content, element);
  1906. return element;
  1907. }
  1908. content = Object.toHTML(content);
  1909. var parent = element.parentNode, tagName = parent.tagName.toUpperCase();
  1910. if (tagName in INSERTION_TRANSLATIONS.tags) {
  1911. var nextSibling = Element.next(element);
  1912. var fragments = getContentFromAnonymousElement(
  1913. tagName, content.stripScripts());
  1914. parent.removeChild(element);
  1915. var iterator;
  1916. if (nextSibling)
  1917. iterator = function(node) { parent.insertBefore(node, nextSibling) };
  1918. else
  1919. iterator = function(node) { parent.appendChild(node); }
  1920. fragments.each(iterator);
  1921. } else {
  1922. element.outerHTML = content.stripScripts();
  1923. }
  1924. content.evalScripts.bind(content).defer();
  1925. return element;
  1926. }
  1927. if ('outerHTML' in document.documentElement)
  1928. replace = replace_IE;
  1929. function isContent(content) {
  1930. if (Object.isUndefined(content) || content === null) return false;
  1931. if (Object.isString(content) || Object.isNumber(content)) return true;
  1932. if (Object.isElement(content)) return true;
  1933. if (content.toElement || content.toHTML) return true;
  1934. return false;
  1935. }
  1936. function insertContentAt(element, content, position) {
  1937. position = position.toLowerCase();
  1938. var method = INSERTION_TRANSLATIONS[position];
  1939. if (content && content.toElement) content = content.toElement();
  1940. if (Object.isElement(content)) {
  1941. method(element, content);
  1942. return element;
  1943. }
  1944. content = Object.toHTML(content);
  1945. var tagName = ((position === 'before' || position === 'after') ?
  1946. element.parentNode : element).tagName.toUpperCase();
  1947. var childNodes = getContentFromAnonymousElement(tagName, content.stripScripts());
  1948. if (position === 'top' || position === 'after') childNodes.reverse();
  1949. for (var i = 0, node; node = childNodes[i]; i++)
  1950. method(element, node);
  1951. content.evalScripts.bind(content).defer();
  1952. }
  1953. function insert(element, insertions) {
  1954. element = $(element);
  1955. if (isContent(insertions))
  1956. insertions = { bottom: insertions };
  1957. for (var position in insertions)
  1958. insertContentAt(element, insertions[position], position);
  1959. return element;
  1960. }
  1961. function wrap(element, wrapper, attributes) {
  1962. element = $(element);
  1963. if (Object.isElement(wrapper)) {
  1964. $(wrapper).writeAttribute(attributes || {});
  1965. } else if (Object.isString(wrapper)) {
  1966. wrapper = new Element(wrapper, attributes);
  1967. } else {
  1968. wrapper = new Element('div', wrapper);
  1969. }
  1970. if (element.parentNode)
  1971. element.parentNode.replaceChild(wrapper, element);
  1972. wrapper.appendChild(element);
  1973. return wrapper;
  1974. }
  1975. function cleanWhitespace(element) {
  1976. element = $(element);
  1977. var node = element.firstChild;
  1978. while (node) {
  1979. var nextNode = node.nextSibling;
  1980. if (node.nodeType === Node.TEXT_NODE && !/\S/.test(node.nodeValue))
  1981. element.removeChild(node);
  1982. node = nextNode;
  1983. }
  1984. return element;
  1985. }
  1986. function empty(element) {
  1987. return $(element).innerHTML.blank();
  1988. }
  1989. function getContentFromAnonymousElement(tagName, html, force) {
  1990. var t = INSERTION_TRANSLATIONS.tags[tagName], div = DIV;
  1991. var workaround = !!t;
  1992. if (!workaround && force) {
  1993. workaround = true;
  1994. t = ['', '', 0];
  1995. }
  1996. if (workaround) {
  1997. div.innerHTML = '&#160;' + t[0] + html + t[1];
  1998. div.removeChild(div.firstChild);
  1999. for (var i = t[2]; i--; )
  2000. div = div.firstChild;
  2001. } else {
  2002. div.innerHTML = html;
  2003. }
  2004. return $A(div.childNodes);
  2005. }
  2006. function clone(element, deep) {
  2007. if (!(element = $(element))) return;
  2008. var clone = element.cloneNode(deep);
  2009. if (!HAS_UNIQUE_ID_PROPERTY) {
  2010. clone._prototypeUID = UNDEFINED;
  2011. if (deep) {
  2012. var descendants = Element.select(clone, '*'),
  2013. i = descendants.length;
  2014. while (i--)
  2015. descendants[i]._prototypeUID = UNDEFINED;
  2016. }
  2017. }
  2018. return Element.extend(clone);
  2019. }
  2020. function purgeElement(element) {
  2021. var uid = getUniqueElementID(element);
  2022. if (uid) {
  2023. Element.stopObserving(element);
  2024. if (!HAS_UNIQUE_ID_PROPERTY)
  2025. element._prototypeUID = UNDEFINED;
  2026. delete Element.Storage[uid];
  2027. }
  2028. }
  2029. function purgeCollection(elements) {
  2030. var i = elements.length;
  2031. while (i--)
  2032. purgeElement(elements[i]);
  2033. }
  2034. function purgeCollection_IE(elements) {
  2035. var i = elements.length, element, uid;
  2036. while (i--) {
  2037. element = elements[i];
  2038. uid = getUniqueElementID(element);
  2039. delete Element.Storage[uid];
  2040. delete Event.cache[uid];
  2041. }
  2042. }
  2043. if (HAS_UNIQUE_ID_PROPERTY) {
  2044. purgeCollection = purgeCollection_IE;
  2045. }
  2046. function purge(element) {
  2047. if (!(element = $(element))) return;
  2048. purgeElement(element);
  2049. var descendants = element.getElementsByTagName('*'),
  2050. i = descendants.length;
  2051. while (i--) purgeElement(descendants[i]);
  2052. return null;
  2053. }
  2054. Object.extend(methods, {
  2055. remove: remove,
  2056. update: update,
  2057. replace: replace,
  2058. insert: insert,
  2059. wrap: wrap,
  2060. cleanWhitespace: cleanWhitespace,
  2061. empty: empty,
  2062. clone: clone,
  2063. purge: purge
  2064. });
  2065. function recursivelyCollect(element, property, maximumLength) {
  2066. element = $(element);
  2067. maximumLength = maximumLength || -1;
  2068. var elements = [];
  2069. while (element = element[property]) {
  2070. if (element.nodeType === Node.ELEMENT_NODE)
  2071. elements.push(Element.extend(element));
  2072. if (elements.length === maximumLength) break;
  2073. }
  2074. return elements;
  2075. }
  2076. function ancestors(element) {
  2077. return recursivelyCollect(element, 'parentNode');
  2078. }
  2079. function descendants(element) {
  2080. return Element.select(element, '*');
  2081. }
  2082. function firstDescendant(element) {
  2083. element = $(element).firstChild;
  2084. while (element && element.nodeType !== Node.ELEMENT_NODE)
  2085. element = element.nextSibling;
  2086. return $(element);
  2087. }
  2088. function immediateDescendants(element) {
  2089. var results = [], child = $(element).firstChild;
  2090. while (child) {
  2091. if (child.nodeType === Node.ELEMENT_NODE)
  2092. results.push(Element.extend(child));
  2093. child = child.nextSibling;
  2094. }
  2095. return results;
  2096. }
  2097. function previousSiblings(element) {
  2098. return recursivelyCollect(element, 'previousSibling');
  2099. }
  2100. function nextSiblings(element) {
  2101. return recursivelyCollect(element, 'nextSibling');
  2102. }
  2103. function siblings(element) {
  2104. element = $(element);
  2105. var previous = previousSiblings(element),
  2106. next = nextSiblings(element);
  2107. return previous.reverse().concat(next);
  2108. }
  2109. function match(element, selector) {
  2110. element = $(element);
  2111. if (Object.isString(selector))
  2112. return Prototype.Selector.match(element, selector);
  2113. return selector.match(element);
  2114. }
  2115. function _recursivelyFind(element, property, expression, index) {
  2116. element = $(element), expression = expression || 0, index = index || 0;
  2117. if (Object.isNumber(expression)) {
  2118. index = expression, expression = null;
  2119. }
  2120. while (element = element[property]) {
  2121. if (element.nodeType !== 1) continue;
  2122. if (expression && !Prototype.Selector.match(element, expression))
  2123. continue;
  2124. if (--index >= 0) continue;
  2125. return Element.extend(element);
  2126. }
  2127. }
  2128. function up(element, expression, index) {
  2129. element = $(element);
  2130. if (arguments.length === 1) return $(element.parentNode);
  2131. return _recursivelyFind(element, 'parentNode', expression, index);
  2132. }
  2133. function down(element, expression, index) {
  2134. if (arguments.length === 1) return firstDescendant(element);
  2135. element = $(element), expression = expression || 0, index = index || 0;
  2136. if (Object.isNumber(expression))
  2137. index = expression, expression = '*';
  2138. var node = Prototype.Selector.select(expression, element)[index];
  2139. return Element.extend(node);
  2140. }
  2141. function previous(element, expression, index) {
  2142. return _recursivelyFind(element, 'previousSibling', expression, index);
  2143. }
  2144. function next(element, expression, index) {
  2145. return _recursivelyFind(element, 'nextSibling', expression, index);
  2146. }
  2147. function select(element) {
  2148. element = $(element);
  2149. var expressions = SLICE.call(arguments, 1).join(', ');
  2150. return Prototype.Selector.select(expressions, element);
  2151. }
  2152. function adjacent(element) {
  2153. element = $(element);
  2154. var expressions = SLICE.call(arguments, 1).join(', ');
  2155. var siblings = Element.siblings(element), results = [];
  2156. for (var i = 0, sibling; sibling = siblings[i]; i++) {
  2157. if (Prototype.Selector.match(sibling, expressions))
  2158. results.push(sibling);
  2159. }
  2160. return results;
  2161. }
  2162. function descendantOf_DOM(element, ancestor) {
  2163. element = $(element), ancestor = $(ancestor);
  2164. if (!element || !ancestor) return false;
  2165. while (element = element.parentNode)
  2166. if (element === ancestor) return true;
  2167. return false;
  2168. }
  2169. function descendantOf_contains(element, ancestor) {
  2170. element = $(element), ancestor = $(ancestor);
  2171. if (!element || !ancestor) return false;
  2172. if (!ancestor.contains) return descendantOf_DOM(element, ancestor);
  2173. return ancestor.contains(element) && ancestor !== element;
  2174. }
  2175. function descendantOf_compareDocumentPosition(element, ancestor) {
  2176. element = $(element), ancestor = $(ancestor);
  2177. if (!element || !ancestor) return false;
  2178. return (element.compareDocumentPosition(ancestor) & 8) === 8;
  2179. }
  2180. var descendantOf;
  2181. if (DIV.compareDocumentPosition) {
  2182. descendantOf = descendantOf_compareDocumentPosition;
  2183. } else if (DIV.contains) {
  2184. descendantOf = descendantOf_contains;
  2185. } else {
  2186. descendantOf = descendantOf_DOM;
  2187. }
  2188. Object.extend(methods, {
  2189. recursivelyCollect: recursivelyCollect,
  2190. ancestors: ancestors,
  2191. descendants: descendants,
  2192. firstDescendant: firstDescendant,
  2193. immediateDescendants: immediateDescendants,
  2194. previousSiblings: previousSiblings,
  2195. nextSiblings: nextSiblings,
  2196. siblings: siblings,
  2197. match: match,
  2198. up: up,
  2199. down: down,
  2200. previous: previous,
  2201. next: next,
  2202. select: select,
  2203. adjacent: adjacent,
  2204. descendantOf: descendantOf,
  2205. getElementsBySelector: select,
  2206. childElements: immediateDescendants
  2207. });
  2208. var idCounter = 1;
  2209. function identify(element) {
  2210. element = $(element);
  2211. var id = Element.readAttribute(element, 'id');
  2212. if (id) return id;
  2213. do { id = 'anonymous_element_' + idCounter++ } while ($(id));
  2214. Element.writeAttribute(element, 'id', id);
  2215. return id;
  2216. }
  2217. function readAttribute(element, name) {
  2218. return $(element).getAttribute(name);
  2219. }
  2220. function readAttribute_IE(element, name) {
  2221. element = $(element);
  2222. var table = ATTRIBUTE_TRANSLATIONS.read;
  2223. if (table.values[name])
  2224. return table.values[name](element, name);
  2225. if (table.names[name]) name = table.names[name];
  2226. if (name.include(':')) {
  2227. if (!element.attributes || !element.attributes[name]) return null;
  2228. return element.attributes[name].value;
  2229. }
  2230. return element.getAttribute(name);
  2231. }
  2232. function readAttribute_Opera(element, name) {
  2233. if (name === 'title') return element.title;
  2234. return element.getAttribute(name);
  2235. }
  2236. var PROBLEMATIC_ATTRIBUTE_READING = (function() {
  2237. DIV.setAttribute('onclick', []);
  2238. var value = DIV.getAttribute('onclick');
  2239. var isFunction = Object.isArray(value);
  2240. DIV.removeAttribute('onclick');
  2241. return isFunction;
  2242. })();
  2243. if (PROBLEMATIC_ATTRIBUTE_READING) {
  2244. readAttribute = readAttribute_IE;
  2245. } else if (Prototype.Browser.Opera) {
  2246. readAttribute = readAttribute_Opera;
  2247. }
  2248. function writeAttribute(element, name, value) {
  2249. element = $(element);
  2250. var attributes = {}, table = ATTRIBUTE_TRANSLATIONS.write;
  2251. if (typeof name === 'object') {
  2252. attributes = name;
  2253. } else {
  2254. attributes[name] = Object.isUndefined(value) ? true : value;
  2255. }
  2256. for (var attr in attributes) {
  2257. name = table.names[attr] || attr;
  2258. value = attributes[attr];
  2259. if (table.values[attr]) {
  2260. value = table.values[attr](element, value);
  2261. if (Object.isUndefined(value)) continue;
  2262. }
  2263. if (value === false || value === null)
  2264. element.removeAttribute(name);
  2265. else if (value === true)
  2266. element.setAttribute(name, name);
  2267. else element.setAttribute(name, value);
  2268. }
  2269. return element;
  2270. }
  2271. var PROBLEMATIC_HAS_ATTRIBUTE_WITH_CHECKBOXES = (function () {
  2272. if (!HAS_EXTENDED_CREATE_ELEMENT_SYNTAX) {
  2273. return false;
  2274. }
  2275. var checkbox = document.createElement('<input type="checkbox">');
  2276. checkbox.checked = true;
  2277. var node = checkbox.getAttributeNode('checked');
  2278. return !node || !node.specified;
  2279. })();
  2280. function hasAttribute(element, attribute) {
  2281. attribute = ATTRIBUTE_TRANSLATIONS.has[attribute] || attribute;
  2282. var node = $(element).getAttributeNode(attribute);
  2283. return !!(node && node.specified);
  2284. }
  2285. function hasAttribute_IE(element, attribute) {
  2286. if (attribute === 'checked') {
  2287. return element.checked;
  2288. }
  2289. return hasAttribute(element, attribute);
  2290. }
  2291. GLOBAL.Element.Methods.Simulated.hasAttribute =
  2292. PROBLEMATIC_HAS_ATTRIBUTE_WITH_CHECKBOXES ?
  2293. hasAttribute_IE : hasAttribute;
  2294. function classNames(element) {
  2295. return new Element.ClassNames(element);
  2296. }
  2297. var regExpCache = {};
  2298. function getRegExpForClassName(className) {
  2299. if (regExpCache[className]) return regExpCache[className];
  2300. var re = new RegExp("(^|\\s+)" + className + "(\\s+|$)");
  2301. regExpCache[className] = re;
  2302. return re;
  2303. }
  2304. function hasClassName(element, className) {
  2305. if (!(element = $(element))) return;
  2306. var elementClassName = element.className;
  2307. if (elementClassName.length === 0) return false;
  2308. if (elementClassName === className) return true;
  2309. return getRegExpForClassName(className).test(elementClassName);
  2310. }
  2311. function addClassName(element, className) {
  2312. if (!(element = $(element))) return;
  2313. if (!hasClassName(element, className))
  2314. element.className += (element.className ? ' ' : '') + className;
  2315. return element;
  2316. }
  2317. function removeClassName(element, className) {
  2318. if (!(element = $(element))) return;
  2319. element.className = element.className.replace(
  2320. getRegExpForClassName(className), ' ').strip();
  2321. return element;
  2322. }
  2323. function toggleClassName(element, className, bool) {
  2324. if (!(element = $(element))) return;
  2325. if (Object.isUndefined(bool))
  2326. bool = !hasClassName(element, className);
  2327. var method = Element[bool ? 'addClassName' : 'removeClassName'];
  2328. return method(element, className);
  2329. }
  2330. var ATTRIBUTE_TRANSLATIONS = {};
  2331. var classProp = 'className', forProp = 'for';
  2332. DIV.setAttribute(classProp, 'x');
  2333. if (DIV.className !== 'x') {
  2334. DIV.setAttribute('class', 'x');
  2335. if (DIV.className === 'x')
  2336. classProp = 'class';
  2337. }
  2338. var LABEL = document.createElement('label');
  2339. LABEL.setAttribute(forProp, 'x');
  2340. if (LABEL.htmlFor !== 'x') {
  2341. LABEL.setAttribute('htmlFor', 'x');
  2342. if (LABEL.htmlFor === 'x')
  2343. forProp = 'htmlFor';
  2344. }
  2345. LABEL = null;
  2346. function _getAttr(element, attribute) {
  2347. return element.getAttribute(attribute);
  2348. }
  2349. function _getAttr2(element, attribute) {
  2350. return element.getAttribute(attribute, 2);
  2351. }
  2352. function _getAttrNode(element, attribute) {
  2353. var node = element.getAttributeNode(attribute);
  2354. return node ? node.value : '';
  2355. }
  2356. function _getFlag(element, attribute) {
  2357. return $(element).hasAttribute(attribute) ? attribute : null;
  2358. }
  2359. DIV.onclick = Prototype.emptyFunction;
  2360. var onclickValue = DIV.getAttribute('onclick');
  2361. var _getEv;
  2362. if (String(onclickValue).indexOf('{') > -1) {
  2363. _getEv = function(element, attribute) {
  2364. var value = element.getAttribute(attribute);
  2365. if (!value) return null;
  2366. value = value.toString();
  2367. value = value.split('{')[1];
  2368. value = value.split('}')[0];
  2369. return value.strip();
  2370. };
  2371. }
  2372. else if (onclickValue === '') {
  2373. _getEv = function(element, attribute) {
  2374. var value = element.getAttribute(attribute);
  2375. if (!value) return null;
  2376. return value.strip();
  2377. };
  2378. }
  2379. ATTRIBUTE_TRANSLATIONS.read = {
  2380. names: {
  2381. 'class': classProp,
  2382. 'className': classProp,
  2383. 'for': forProp,
  2384. 'htmlFor': forProp
  2385. },
  2386. values: {
  2387. style: function(element) {
  2388. return element.style.cssText.toLowerCase();
  2389. },
  2390. title: function(element) {
  2391. return element.title;
  2392. }
  2393. }
  2394. };
  2395. ATTRIBUTE_TRANSLATIONS.write = {
  2396. names: {
  2397. className: 'class',
  2398. htmlFor: 'for',
  2399. cellpadding: 'cellPadding',
  2400. cellspacing: 'cellSpacing'
  2401. },
  2402. values: {
  2403. checked: function(element, value) {
  2404. value = !!value;
  2405. element.checked = value;
  2406. return value ? 'checked' : null;
  2407. },
  2408. style: function(element, value) {
  2409. element.style.cssText = value ? value : '';
  2410. }
  2411. }
  2412. };
  2413. ATTRIBUTE_TRANSLATIONS.has = { names: {} };
  2414. Object.extend(ATTRIBUTE_TRANSLATIONS.write.names,
  2415. ATTRIBUTE_TRANSLATIONS.read.names);
  2416. var CAMEL_CASED_ATTRIBUTE_NAMES = $w('colSpan rowSpan vAlign dateTime ' +
  2417. 'accessKey tabIndex encType maxLength readOnly longDesc frameBorder');
  2418. for (var i = 0, attr; attr = CAMEL_CASED_ATTRIBUTE_NAMES[i]; i++) {
  2419. ATTRIBUTE_TRANSLATIONS.write.names[attr.toLowerCase()] = attr;
  2420. ATTRIBUTE_TRANSLATIONS.has.names[attr.toLowerCase()] = attr;
  2421. }
  2422. Object.extend(ATTRIBUTE_TRANSLATIONS.read.values, {
  2423. href: _getAttr2,
  2424. src: _getAttr2,
  2425. type: _getAttr,
  2426. action: _getAttrNode,
  2427. disabled: _getFlag,
  2428. checked: _getFlag,
  2429. readonly: _getFlag,
  2430. multiple: _getFlag,
  2431. onload: _getEv,
  2432. onunload: _getEv,
  2433. onclick: _getEv,
  2434. ondblclick: _getEv,
  2435. onmousedown: _getEv,
  2436. onmouseup: _getEv,
  2437. onmouseover: _getEv,
  2438. onmousemove: _getEv,
  2439. onmouseout: _getEv,
  2440. onfocus: _getEv,
  2441. onblur: _getEv,
  2442. onkeypress: _getEv,
  2443. onkeydown: _getEv,
  2444. onkeyup: _getEv,
  2445. onsubmit: _getEv,
  2446. onreset: _getEv,
  2447. onselect: _getEv,
  2448. onchange: _getEv
  2449. });
  2450. Object.extend(methods, {
  2451. identify: identify,
  2452. readAttribute: readAttribute,
  2453. writeAttribute: writeAttribute,
  2454. classNames: classNames,
  2455. hasClassName: hasClassName,
  2456. addClassName: addClassName,
  2457. removeClassName: removeClassName,
  2458. toggleClassName: toggleClassName
  2459. });
  2460. function normalizeStyleName(style) {
  2461. if (style === 'float' || style === 'styleFloat')
  2462. return 'cssFloat';
  2463. return style.camelize();
  2464. }
  2465. function normalizeStyleName_IE(style) {
  2466. if (style === 'float' || style === 'cssFloat')
  2467. return 'styleFloat';
  2468. return style.camelize();
  2469. }
  2470. function setStyle(element, styles) {
  2471. element = $(element);
  2472. var elementStyle = element.style, match;
  2473. if (Object.isString(styles)) {
  2474. elementStyle.cssText += ';' + styles;
  2475. if (styles.include('opacity')) {
  2476. var opacity = styles.match(/opacity:\s*(\d?\.?\d*)/)[1];
  2477. Element.setOpacity(element, opacity);
  2478. }
  2479. return element;
  2480. }
  2481. for (var property in styles) {
  2482. if (property === 'opacity') {
  2483. Element.setOpacity(element, styles[property]);
  2484. } else {
  2485. var value = styles[property];
  2486. if (property === 'float' || property === 'cssFloat') {
  2487. property = Object.isUndefined(elementStyle.styleFloat) ?
  2488. 'cssFloat' : 'styleFloat';
  2489. }
  2490. elementStyle[property] = value;
  2491. }
  2492. }
  2493. return element;
  2494. }
  2495. function getStyle(element, style) {
  2496. element = $(element);
  2497. style = normalizeStyleName(style);
  2498. var value = element.style[style];
  2499. if (!value || value === 'auto') {
  2500. var css = document.defaultView.getComputedStyle(element, null);
  2501. value = css ? css[style] : null;
  2502. }
  2503. if (style === 'opacity') return value ? parseFloat(value) : 1.0;
  2504. return value === 'auto' ? null : value;
  2505. }
  2506. function getStyle_Opera(element, style) {
  2507. switch (style) {
  2508. case 'height': case 'width':
  2509. if (!Element.visible(element)) return null;
  2510. var dim = parseInt(getStyle(element, style), 10);
  2511. if (dim !== element['offset' + style.capitalize()])
  2512. return dim + 'px';
  2513. return Element.measure(element, style);
  2514. default: return getStyle(element, style);
  2515. }
  2516. }
  2517. function getStyle_IE(element, style) {
  2518. element = $(element);
  2519. style = normalizeStyleName_IE(style);
  2520. var value = element.style[style];
  2521. if (!value && element.currentStyle) {
  2522. value = element.currentStyle[style];
  2523. }
  2524. if (style === 'opacity') {
  2525. if (!STANDARD_CSS_OPACITY_SUPPORTED)
  2526. return getOpacity_IE(element);
  2527. else return value ? parseFloat(value) : 1.0;
  2528. }
  2529. if (value === 'auto') {
  2530. if ((style === 'width' || style === 'height') && Element.visible(element))
  2531. return Element.measure(element, style) + 'px';
  2532. return null;
  2533. }
  2534. return value;
  2535. }
  2536. function stripAlphaFromFilter_IE(filter) {
  2537. return (filter || '').replace(/alpha\([^\)]*\)/gi, '');
  2538. }
  2539. function hasLayout_IE(element) {
  2540. if (!element.currentStyle || !element.currentStyle.hasLayout)
  2541. element.style.zoom = 1;
  2542. return element;
  2543. }
  2544. var STANDARD_CSS_OPACITY_SUPPORTED = (function() {
  2545. DIV.style.cssText = "opacity:.55";
  2546. return /^0.55/.test(DIV.style.opacity);
  2547. })();
  2548. function setOpacity(element, value) {
  2549. element = $(element);
  2550. if (value == 1 || value === '') value = '';
  2551. else if (value < 0.00001) value = 0;
  2552. element.style.opacity = value;
  2553. return element;
  2554. }
  2555. function setOpacity_IE(element, value) {
  2556. if (STANDARD_CSS_OPACITY_SUPPORTED)
  2557. return setOpacity(element, value);
  2558. element = hasLayout_IE($(element));
  2559. var filter = Element.getStyle(element, 'filter'),
  2560. style = element.style;
  2561. if (value == 1 || value === '') {
  2562. filter = stripAlphaFromFilter_IE(filter);
  2563. if (filter) style.filter = filter;
  2564. else style.removeAttribute('filter');
  2565. return element;
  2566. }
  2567. if (value < 0.00001) value = 0;
  2568. style.filter = stripAlphaFromFilter_IE(filter) +
  2569. ' alpha(opacity=' + (value * 100) + ')';
  2570. return element;
  2571. }
  2572. function getOpacity(element) {
  2573. return Element.getStyle(element, 'opacity');
  2574. }
  2575. function getOpacity_IE(element) {
  2576. if (STANDARD_CSS_OPACITY_SUPPORTED)
  2577. return getOpacity(element);
  2578. var filter = Element.getStyle(element, 'filter');
  2579. if (filter.length === 0) return 1.0;
  2580. var match = (filter || '').match(/alpha\(opacity=(.*)\)/i);
  2581. if (match && match[1]) return parseFloat(match[1]) / 100;
  2582. return 1.0;
  2583. }
  2584. Object.extend(methods, {
  2585. setStyle: setStyle,
  2586. getStyle: getStyle,
  2587. setOpacity: setOpacity,
  2588. getOpacity: getOpacity
  2589. });
  2590. if ('styleFloat' in DIV.style) {
  2591. methods.getStyle = getStyle_IE;
  2592. methods.setOpacity = setOpacity_IE;
  2593. methods.getOpacity = getOpacity_IE;
  2594. }
  2595. var UID = 0;
  2596. GLOBAL.Element.Storage = { UID: 1 };
  2597. function getUniqueElementID(element) {
  2598. if (element === window) return 0;
  2599. if (typeof element._prototypeUID === 'undefined')
  2600. element._prototypeUID = Element.Storage.UID++;
  2601. return element._prototypeUID;
  2602. }
  2603. function getUniqueElementID_IE(element) {
  2604. if (element === window) return 0;
  2605. if (element == document) return 1;
  2606. return element.uniqueID;
  2607. }
  2608. var HAS_UNIQUE_ID_PROPERTY = ('uniqueID' in DIV);
  2609. if (HAS_UNIQUE_ID_PROPERTY)
  2610. getUniqueElementID = getUniqueElementID_IE;
  2611. function getStorage(element) {
  2612. if (!(element = $(element))) return;
  2613. var uid = getUniqueElementID(element);
  2614. if (!Element.Storage[uid])
  2615. Element.Storage[uid] = $H();
  2616. return Element.Storage[uid];
  2617. }
  2618. function store(element, key, value) {
  2619. if (!(element = $(element))) return;
  2620. var storage = getStorage(element);
  2621. if (arguments.length === 2) {
  2622. storage.update(key);
  2623. } else {
  2624. storage.set(key, value);
  2625. }
  2626. return element;
  2627. }
  2628. function retrieve(element, key, defaultValue) {
  2629. if (!(element = $(element))) return;
  2630. var storage = getStorage(element), value = storage.get(key);
  2631. if (Object.isUndefined(value)) {
  2632. storage.set(key, defaultValue);
  2633. value = defaultValue;
  2634. }
  2635. return value;
  2636. }
  2637. Object.extend(methods, {
  2638. getStorage: getStorage,
  2639. store: store,
  2640. retrieve: retrieve
  2641. });
  2642. var Methods = {}, ByTag = Element.Methods.ByTag,
  2643. F = Prototype.BrowserFeatures;
  2644. if (!F.ElementExtensions && ('__proto__' in DIV)) {
  2645. GLOBAL.HTMLElement = {};
  2646. GLOBAL.HTMLElement.prototype = DIV['__proto__'];
  2647. F.ElementExtensions = true;
  2648. }
  2649. function checkElementPrototypeDeficiency(tagName) {
  2650. if (typeof window.Element === 'undefined') return false;
  2651. if (!HAS_EXTENDED_CREATE_ELEMENT_SYNTAX) return false;
  2652. var proto = window.Element.prototype;
  2653. if (proto) {
  2654. var id = '_' + (Math.random() + '').slice(2),
  2655. el = document.createElement(tagName);
  2656. proto[id] = 'x';
  2657. var isBuggy = (el[id] !== 'x');
  2658. delete proto[id];
  2659. el = null;
  2660. return isBuggy;
  2661. }
  2662. return false;
  2663. }
  2664. var HTMLOBJECTELEMENT_PROTOTYPE_BUGGY =
  2665. checkElementPrototypeDeficiency('object');
  2666. function extendElementWith(element, methods) {
  2667. for (var property in methods) {
  2668. var value = methods[property];
  2669. if (Object.isFunction(value) && !(property in element))
  2670. element[property] = value.methodize();
  2671. }
  2672. }
  2673. var EXTENDED = {};
  2674. function elementIsExtended(element) {
  2675. var uid = getUniqueElementID(element);
  2676. return (uid in EXTENDED);
  2677. }
  2678. function extend(element) {
  2679. if (!element || elementIsExtended(element)) return element;
  2680. if (element.nodeType !== Node.ELEMENT_NODE || element == window)
  2681. return element;
  2682. var methods = Object.clone(Methods),
  2683. tagName = element.tagName.toUpperCase();
  2684. if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]);
  2685. extendElementWith(element, methods);
  2686. EXTENDED[getUniqueElementID(element)] = true;
  2687. return element;
  2688. }
  2689. function extend_IE8(element) {
  2690. if (!element || elementIsExtended(element)) return element;
  2691. var t = element.tagName;
  2692. if (t && (/^(?:object|applet|embed)$/i.test(t))) {
  2693. extendElementWith(element, Element.Methods);
  2694. extendElementWith(element, Element.Methods.Simulated);
  2695. extendElementWith(element, Element.Methods.ByTag[t.toUpperCase()]);
  2696. }
  2697. return element;
  2698. }
  2699. if (F.SpecificElementExtensions) {
  2700. extend = HTMLOBJECTELEMENT_PROTOTYPE_BUGGY ? extend_IE8 : Prototype.K;
  2701. }
  2702. function addMethodsToTagName(tagName, methods) {
  2703. tagName = tagName.toUpperCase();
  2704. if (!ByTag[tagName]) ByTag[tagName] = {};
  2705. Object.extend(ByTag[tagName], methods);
  2706. }
  2707. function mergeMethods(destination, methods, onlyIfAbsent) {
  2708. if (Object.isUndefined(onlyIfAbsent)) onlyIfAbsent = false;
  2709. for (var property in methods) {
  2710. var value = methods[property];
  2711. if (!Object.isFunction(value)) continue;
  2712. if (!onlyIfAbsent || !(property in destination))
  2713. destination[property] = value.methodize();
  2714. }
  2715. }
  2716. function findDOMClass(tagName) {
  2717. var klass;
  2718. var trans = {
  2719. "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph",
  2720. "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList",
  2721. "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading",
  2722. "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote",
  2723. "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION":
  2724. "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD":
  2725. "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR":
  2726. "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET":
  2727. "FrameSet", "IFRAME": "IFrame"
  2728. };
  2729. if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';
  2730. if (window[klass]) return window[klass];
  2731. klass = 'HTML' + tagName + 'Element';
  2732. if (window[klass]) return window[klass];
  2733. klass = 'HTML' + tagName.capitalize() + 'Element';
  2734. if (window[klass]) return window[klass];
  2735. var element = document.createElement(tagName),
  2736. proto = element['__proto__'] || element.constructor.prototype;
  2737. element = null;
  2738. return proto;
  2739. }
  2740. function addMethods(methods) {
  2741. if (arguments.length === 0) addFormMethods();
  2742. if (arguments.length === 2) {
  2743. var tagName = methods;
  2744. methods = arguments[1];
  2745. }
  2746. if (!tagName) {
  2747. Object.extend(Element.Methods, methods || {});
  2748. } else {
  2749. if (Object.isArray(tagName)) {
  2750. for (var i = 0, tag; tag = tagName[i]; i++)
  2751. addMethodsToTagName(tag, methods);
  2752. } else {
  2753. addMethodsToTagName(tagName, methods);
  2754. }
  2755. }
  2756. var ELEMENT_PROTOTYPE = window.HTMLElement ? HTMLElement.prototype :
  2757. Element.prototype;
  2758. if (F.ElementExtensions) {
  2759. mergeMethods(ELEMENT_PROTOTYPE, Element.Methods);
  2760. mergeMethods(ELEMENT_PROTOTYPE, Element.Methods.Simulated, true);
  2761. }
  2762. if (F.SpecificElementExtensions) {
  2763. for (var tag in Element.Methods.ByTag) {
  2764. var klass = findDOMClass(tag);
  2765. if (Object.isUndefined(klass)) continue;
  2766. mergeMethods(klass.prototype, ByTag[tag]);
  2767. }
  2768. }
  2769. Object.extend(Element, Element.Methods);
  2770. Object.extend(Element, Element.Methods.Simulated);
  2771. delete Element.ByTag;
  2772. delete Element.Simulated;
  2773. Element.extend.refresh();
  2774. ELEMENT_CACHE = {};
  2775. }
  2776. Object.extend(GLOBAL.Element, {
  2777. extend: extend,
  2778. addMethods: addMethods
  2779. });
  2780. if (extend === Prototype.K) {
  2781. GLOBAL.Element.extend.refresh = Prototype.emptyFunction;
  2782. } else {
  2783. GLOBAL.Element.extend.refresh = function() {
  2784. if (Prototype.BrowserFeatures.ElementExtensions) return;
  2785. Object.extend(Methods, Element.Methods);
  2786. Object.extend(Methods, Element.Methods.Simulated);
  2787. EXTENDED = {};
  2788. };
  2789. }
  2790. function addFormMethods() {
  2791. Object.extend(Form, Form.Methods);
  2792. Object.extend(Form.Element, Form.Element.Methods);
  2793. Object.extend(Element.Methods.ByTag, {
  2794. "FORM": Object.clone(Form.Methods),
  2795. "INPUT": Object.clone(Form.Element.Methods),
  2796. "SELECT": Object.clone(Form.Element.Methods),
  2797. "TEXTAREA": Object.clone(Form.Element.Methods),
  2798. "BUTTON": Object.clone(Form.Element.Methods)
  2799. });
  2800. }
  2801. Element.addMethods(methods);
  2802. function destroyCache_IE() {
  2803. DIV = null;
  2804. ELEMENT_CACHE = null;
  2805. }
  2806. if (window.attachEvent)
  2807. window.attachEvent('onunload', destroyCache_IE);
  2808. })(this);
  2809. (function() {
  2810. function toDecimal(pctString) {
  2811. var match = pctString.match(/^(\d+)%?$/i);
  2812. if (!match) return null;
  2813. return (Number(match[1]) / 100);
  2814. }
  2815. function getRawStyle(element, style) {
  2816. element = $(element);
  2817. var value = element.style[style];
  2818. if (!value || value === 'auto') {
  2819. var css = document.defaultView.getComputedStyle(element, null);
  2820. value = css ? css[style] : null;
  2821. }
  2822. if (style === 'opacity') return value ? parseFloat(value) : 1.0;
  2823. return value === 'auto' ? null : value;
  2824. }
  2825. function getRawStyle_IE(element, style) {
  2826. var value = element.style[style];
  2827. if (!value && element.currentStyle) {
  2828. value = element.currentStyle[style];
  2829. }
  2830. return value;
  2831. }
  2832. function getContentWidth(element, context) {
  2833. var boxWidth = element.offsetWidth;
  2834. var bl = getPixelValue(element, 'borderLeftWidth', context) || 0;
  2835. var br = getPixelValue(element, 'borderRightWidth', context) || 0;
  2836. var pl = getPixelValue(element, 'paddingLeft', context) || 0;
  2837. var pr = getPixelValue(element, 'paddingRight', context) || 0;
  2838. return boxWidth - bl - br - pl - pr;
  2839. }
  2840. if (!Object.isUndefined(document.documentElement.currentStyle) && !Prototype.Browser.Opera) {
  2841. getRawStyle = getRawStyle_IE;
  2842. }
  2843. function getPixelValue(value, property, context) {
  2844. var element = null;
  2845. if (Object.isElement(value)) {
  2846. element = value;
  2847. value = getRawStyle(element, property);
  2848. }
  2849. if (value === null || Object.isUndefined(value)) {
  2850. return null;
  2851. }
  2852. if ((/^(?:-)?\d+(\.\d+)?(px)?$/i).test(value)) {
  2853. return window.parseFloat(value);
  2854. }
  2855. var isPercentage = value.include('%'), isViewport = (context === document.viewport);
  2856. if (/\d/.test(value) && element && element.runtimeStyle && !(isPercentage && isViewport)) {
  2857. var style = element.style.left, rStyle = element.runtimeStyle.left;
  2858. element.runtimeStyle.left = element.currentStyle.left;
  2859. element.style.left = value || 0;
  2860. value = element.style.pixelLeft;
  2861. element.style.left = style;
  2862. element.runtimeStyle.left = rStyle;
  2863. return value;
  2864. }
  2865. if (element && isPercentage) {
  2866. context = context || element.parentNode;
  2867. var decimal = toDecimal(value), whole = null;
  2868. var isHorizontal = property.include('left') || property.include('right') ||
  2869. property.include('width');
  2870. var isVertical = property.include('top') || property.include('bottom') ||
  2871. property.include('height');
  2872. if (context === document.viewport) {
  2873. if (isHorizontal) {
  2874. whole = document.viewport.getWidth();
  2875. } else if (isVertical) {
  2876. whole = document.viewport.getHeight();
  2877. }
  2878. } else {
  2879. if (isHorizontal) {
  2880. whole = $(context).measure('width');
  2881. } else if (isVertical) {
  2882. whole = $(context).measure('height');
  2883. }
  2884. }
  2885. return (whole === null) ? 0 : whole * decimal;
  2886. }
  2887. return 0;
  2888. }
  2889. function toCSSPixels(number) {
  2890. if (Object.isString(number) && number.endsWith('px'))
  2891. return number;
  2892. return number + 'px';
  2893. }
  2894. function isDisplayed(element) {
  2895. while (element && element.parentNode) {
  2896. var display = element.getStyle('display');
  2897. if (display === 'none') {
  2898. return false;
  2899. }
  2900. element = $(element.parentNode);
  2901. }
  2902. return true;
  2903. }
  2904. var hasLayout = Prototype.K;
  2905. if ('currentStyle' in document.documentElement) {
  2906. hasLayout = function(element) {
  2907. if (!element.currentStyle.hasLayout) {
  2908. element.style.zoom = 1;
  2909. }
  2910. return element;
  2911. };
  2912. }
  2913. function cssNameFor(key) {
  2914. if (key.include('border')) key = key + '-width';
  2915. return key.camelize();
  2916. }
  2917. Element.Layout = Class.create(Hash, {
  2918. initialize: function($super, element, preCompute) {
  2919. $super();
  2920. this.element = $(element);
  2921. Element.Layout.PROPERTIES.each( function(property) {
  2922. this._set(property, null);
  2923. }, this);
  2924. if (preCompute) {
  2925. this._preComputing = true;
  2926. this._begin();
  2927. Element.Layout.PROPERTIES.each( this._compute, this );
  2928. this._end();
  2929. this._preComputing = false;
  2930. }
  2931. },
  2932. _set: function(property, value) {
  2933. return Hash.prototype.set.call(this, property, value);
  2934. },
  2935. set: function(property, value) {
  2936. throw "Properties of Element.Layout are read-only.";
  2937. },
  2938. get: function($super, property) {
  2939. var value = $super(property);
  2940. return value === null ? this._compute(property) : value;
  2941. },
  2942. _begin: function() {
  2943. if (this._isPrepared()) return;
  2944. var element = this.element;
  2945. if (isDisplayed(element)) {
  2946. this._setPrepared(true);
  2947. return;
  2948. }
  2949. var originalStyles = {
  2950. position: element.style.position || '',
  2951. width: element.style.width || '',
  2952. visibility: element.style.visibility || '',
  2953. display: element.style.display || ''
  2954. };
  2955. element.store('prototype_original_styles', originalStyles);
  2956. var position = getRawStyle(element, 'position'), width = element.offsetWidth;
  2957. if (width === 0 || width === null) {
  2958. element.style.display = 'block';
  2959. width = element.offsetWidth;
  2960. }
  2961. var context = (position === 'fixed') ? document.viewport :
  2962. element.parentNode;
  2963. var tempStyles = {
  2964. visibility: 'hidden',
  2965. display: 'block'
  2966. };
  2967. if (position !== 'fixed') tempStyles.position = 'absolute';
  2968. element.setStyle(tempStyles);
  2969. var positionedWidth = element.offsetWidth, newWidth;
  2970. if (width && (positionedWidth === width)) {
  2971. newWidth = getContentWidth(element, context);
  2972. } else if (position === 'absolute' || position === 'fixed') {
  2973. newWidth = getContentWidth(element, context);
  2974. } else {
  2975. var parent = element.parentNode, pLayout = $(parent).getLayout();
  2976. newWidth = pLayout.get('width') -
  2977. this.get('margin-left') -
  2978. this.get('border-left') -
  2979. this.get('padding-left') -
  2980. this.get('padding-right') -
  2981. this.get('border-right') -
  2982. this.get('margin-right');
  2983. }
  2984. element.setStyle({ width: newWidth + 'px' });
  2985. this._setPrepared(true);
  2986. },
  2987. _end: function() {
  2988. var element = this.element;
  2989. var originalStyles = element.retrieve('prototype_original_styles');
  2990. element.store('prototype_original_styles', null);
  2991. element.setStyle(originalStyles);
  2992. this._setPrepared(false);
  2993. },
  2994. _compute: function(property) {
  2995. var COMPUTATIONS = Element.Layout.COMPUTATIONS;
  2996. if (!(property in COMPUTATIONS)) {
  2997. throw "Property not found.";
  2998. }
  2999. return this._set(property, COMPUTATIONS[property].call(this, this.element));
  3000. },
  3001. _isPrepared: function() {
  3002. return this.element.retrieve('prototype_element_layout_prepared', false);
  3003. },
  3004. _setPrepared: function(bool) {
  3005. return this.element.store('prototype_element_layout_prepared', bool);
  3006. },
  3007. toObject: function() {
  3008. var args = $A(arguments);
  3009. var keys = (args.length === 0) ? Element.Layout.PROPERTIES :
  3010. args.join(' ').split(' ');
  3011. var obj = {};
  3012. keys.each( function(key) {
  3013. if (!Element.Layout.PROPERTIES.include(key)) return;
  3014. var value = this.get(key);
  3015. if (value != null) obj[key] = value;
  3016. }, this);
  3017. return obj;
  3018. },
  3019. toHash: function() {
  3020. var obj = this.toObject.apply(this, arguments);
  3021. return new Hash(obj);
  3022. },
  3023. toCSS: function() {
  3024. var args = $A(arguments);
  3025. var keys = (args.length === 0) ? Element.Layout.PROPERTIES :
  3026. args.join(' ').split(' ');
  3027. var css = {};
  3028. keys.each( function(key) {
  3029. if (!Element.Layout.PROPERTIES.include(key)) return;
  3030. if (Element.Layout.COMPOSITE_PROPERTIES.include(key)) return;
  3031. var value = this.get(key);
  3032. if (value != null) css[cssNameFor(key)] = value + 'px';
  3033. }, this);
  3034. return css;
  3035. },
  3036. inspect: function() {
  3037. return "#<Element.Layout>";
  3038. }
  3039. });
  3040. Object.extend(Element.Layout, {
  3041. PROPERTIES: $w('height width top left right bottom border-left border-right border-top border-bottom padding-left padding-right padding-top padding-bottom margin-top margin-bottom margin-left margin-right padding-box-width padding-box-height border-box-width border-box-height margin-box-width margin-box-height'),
  3042. COMPOSITE_PROPERTIES: $w('padding-box-width padding-box-height margin-box-width margin-box-height border-box-width border-box-height'),
  3043. COMPUTATIONS: {
  3044. 'height': function(element) {
  3045. if (!this._preComputing) this._begin();
  3046. var bHeight = this.get('border-box-height');
  3047. if (bHeight <= 0) {
  3048. if (!this._preComputing) this._end();
  3049. return 0;
  3050. }
  3051. var bTop = this.get('border-top'),
  3052. bBottom = this.get('border-bottom');
  3053. var pTop = this.get('padding-top'),
  3054. pBottom = this.get('padding-bottom');
  3055. if (!this._preComputing) this._end();
  3056. return bHeight - bTop - bBottom - pTop - pBottom;
  3057. },
  3058. 'width': function(element) {
  3059. if (!this._preComputing) this._begin();
  3060. var bWidth = this.get('border-box-width');
  3061. if (bWidth <= 0) {
  3062. if (!this._preComputing) this._end();
  3063. return 0;
  3064. }
  3065. var bLeft = this.get('border-left'),
  3066. bRight = this.get('border-right');
  3067. var pLeft = this.get('padding-left'),
  3068. pRight = this.get('padding-right');
  3069. if (!this._preComputing) this._end();
  3070. return bWidth - bLeft - bRight - pLeft - pRight;
  3071. },
  3072. 'padding-box-height': function(element) {
  3073. var height = this.get('height'),
  3074. pTop = this.get('padding-top'),
  3075. pBottom = this.get('padding-bottom');
  3076. return height + pTop + pBottom;
  3077. },
  3078. 'padding-box-width': function(element) {
  3079. var width = this.get('width'),
  3080. pLeft = this.get('padding-left'),
  3081. pRight = this.get('padding-right');
  3082. return width + pLeft + pRight;
  3083. },
  3084. 'border-box-height': function(element) {
  3085. if (!this._preComputing) this._begin();
  3086. var height = element.offsetHeight;
  3087. if (!this._preComputing) this._end();
  3088. return height;
  3089. },
  3090. 'border-box-width': function(element) {
  3091. if (!this._preComputing) this._begin();
  3092. var width = element.offsetWidth;
  3093. if (!this._preComputing) this._end();
  3094. return width;
  3095. },
  3096. 'margin-box-height': function(element) {
  3097. var bHeight = this.get('border-box-height'),
  3098. mTop = this.get('margin-top'),
  3099. mBottom = this.get('margin-bottom');
  3100. if (bHeight <= 0) return 0;
  3101. return bHeight + mTop + mBottom;
  3102. },
  3103. 'margin-box-width': function(element) {
  3104. var bWidth = this.get('border-box-width'),
  3105. mLeft = this.get('margin-left'),
  3106. mRight = this.get('margin-right');
  3107. if (bWidth <= 0) return 0;
  3108. return bWidth + mLeft + mRight;
  3109. },
  3110. 'top': function(element) {
  3111. var offset = element.positionedOffset();
  3112. return offset.top;
  3113. },
  3114. 'bottom': function(element) {
  3115. var offset = element.positionedOffset(),
  3116. parent = element.getOffsetParent(),
  3117. pHeight = parent.measure('height');
  3118. var mHeight = this.get('border-box-height');
  3119. return pHeight - mHeight - offset.top;
  3120. },
  3121. 'left': function(element) {
  3122. var offset = element.positionedOffset();
  3123. return offset.left;
  3124. },
  3125. 'right': function(element) {
  3126. var offset = element.positionedOffset(),
  3127. parent = element.getOffsetParent(),
  3128. pWidth = parent.measure('width');
  3129. var mWidth = this.get('border-box-width');
  3130. return pWidth - mWidth - offset.left;
  3131. },
  3132. 'padding-top': function(element) {
  3133. return getPixelValue(element, 'paddingTop');
  3134. },
  3135. 'padding-bottom': function(element) {
  3136. return getPixelValue(element, 'paddingBottom');
  3137. },
  3138. 'padding-left': function(element) {
  3139. return getPixelValue(element, 'paddingLeft');
  3140. },
  3141. 'padding-right': function(element) {
  3142. return getPixelValue(element, 'paddingRight');
  3143. },
  3144. 'border-top': function(element) {
  3145. return getPixelValue(element, 'borderTopWidth');
  3146. },
  3147. 'border-bottom': function(element) {
  3148. return getPixelValue(element, 'borderBottomWidth');
  3149. },
  3150. 'border-left': function(element) {
  3151. return getPixelValue(element, 'borderLeftWidth');
  3152. },
  3153. 'border-right': function(element) {
  3154. return getPixelValue(element, 'borderRightWidth');
  3155. },
  3156. 'margin-top': function(element) {
  3157. return getPixelValue(element, 'marginTop');
  3158. },
  3159. 'margin-bottom': function(element) {
  3160. return getPixelValue(element, 'marginBottom');
  3161. },
  3162. 'margin-left': function(element) {
  3163. return getPixelValue(element, 'marginLeft');
  3164. },
  3165. 'margin-right': function(element) {
  3166. return getPixelValue(element, 'marginRight');
  3167. }
  3168. }
  3169. });
  3170. if ('getBoundingClientRect' in document.documentElement) {
  3171. Object.extend(Element.Layout.COMPUTATIONS, {
  3172. 'right': function(element) {
  3173. var parent = hasLayout(element.getOffsetParent());
  3174. var rect = element.getBoundingClientRect(),
  3175. pRect = parent.getBoundingClientRect();
  3176. return (pRect.right - rect.right).round();
  3177. },
  3178. 'bottom': function(element) {
  3179. var parent = hasLayout(element.getOffsetParent());
  3180. var rect = element.getBoundingClientRect(),
  3181. pRect = parent.getBoundingClientRect();
  3182. return (pRect.bottom - rect.bottom).round();
  3183. }
  3184. });
  3185. }
  3186. Element.Offset = Class.create({
  3187. initialize: function(left, top) {
  3188. this.left = left.round();
  3189. this.top = top.round();
  3190. this[0] = this.left;
  3191. this[1] = this.top;
  3192. },
  3193. relativeTo: function(offset) {
  3194. return new Element.Offset(
  3195. this.left - offset.left,
  3196. this.top - offset.top
  3197. );
  3198. },
  3199. inspect: function() {
  3200. return "#<Element.Offset left: #{left} top: #{top}>".interpolate(this);
  3201. },
  3202. toString: function() {
  3203. return "[#{left}, #{top}]".interpolate(this);
  3204. },
  3205. toArray: function() {
  3206. return [this.left, this.top];
  3207. }
  3208. });
  3209. function getLayout(element, preCompute) {
  3210. return new Element.Layout(element, preCompute);
  3211. }
  3212. function measure(element, property) {
  3213. return $(element).getLayout().get(property);
  3214. }
  3215. function getHeight(element) {
  3216. return Element.getDimensions(element).height;
  3217. }
  3218. function getWidth(element) {
  3219. return Element.getDimensions(element).width;
  3220. }
  3221. function getDimensions(element) {
  3222. element = $(element);
  3223. var display = Element.getStyle(element, 'display');
  3224. if (display && display !== 'none') {
  3225. return { width: element.offsetWidth, height: element.offsetHeight };
  3226. }
  3227. var style = element.style;
  3228. var originalStyles = {
  3229. visibility: style.visibility,
  3230. position: style.position,
  3231. display: style.display
  3232. };
  3233. var newStyles = {
  3234. visibility: 'hidden',
  3235. display: 'block'
  3236. };
  3237. if (originalStyles.position !== 'fixed')
  3238. newStyles.position = 'absolute';
  3239. Element.setStyle(element, newStyles);
  3240. var dimensions = {
  3241. width: element.offsetWidth,
  3242. height: element.offsetHeight
  3243. };
  3244. Element.setStyle(element, originalStyles);
  3245. return dimensions;
  3246. }
  3247. function getOffsetParent(element) {
  3248. element = $(element);
  3249. function selfOrBody(element) {
  3250. return isHtml(element) ? $(document.body) : $(element);
  3251. }
  3252. if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element))
  3253. return $(document.body);
  3254. var isInline = (Element.getStyle(element, 'display') === 'inline');
  3255. if (!isInline && element.offsetParent) return selfOrBody(element.offsetParent);
  3256. while ((element = element.parentNode) && element !== document.body) {
  3257. if (Element.getStyle(element, 'position') !== 'static') {
  3258. return selfOrBody(element);
  3259. }
  3260. }
  3261. return $(document.body);
  3262. }
  3263. function cumulativeOffset(element) {
  3264. element = $(element);
  3265. var valueT = 0, valueL = 0;
  3266. if (element.parentNode) {
  3267. do {
  3268. valueT += element.offsetTop || 0;
  3269. valueL += element.offsetLeft || 0;
  3270. element = element.offsetParent;
  3271. } while (element);
  3272. }
  3273. return new Element.Offset(valueL, valueT);
  3274. }
  3275. function positionedOffset(element) {
  3276. element = $(element);
  3277. var layout = element.getLayout();
  3278. var valueT = 0, valueL = 0;
  3279. do {
  3280. valueT += element.offsetTop || 0;
  3281. valueL += element.offsetLeft || 0;
  3282. element = element.offsetParent;
  3283. if (element) {
  3284. if (isBody(element)) break;
  3285. var p = Element.getStyle(element, 'position');
  3286. if (p !== 'static') break;
  3287. }
  3288. } while (element);
  3289. valueL -= layout.get('margin-left');
  3290. valueT -= layout.get('margin-top');
  3291. return new Element.Offset(valueL, valueT);
  3292. }
  3293. function cumulativeScrollOffset(element) {
  3294. var valueT = 0, valueL = 0;
  3295. do {
  3296. if (element === document.body) {
  3297. var bodyScrollNode = document.documentElement || document.body.parentNode || document.body;
  3298. valueT += !Object.isUndefined(window.pageYOffset) ? window.pageYOffset : bodyScrollNode.scrollTop || 0;
  3299. valueL += !Object.isUndefined(window.pageXOffset) ? window.pageXOffset : bodyScrollNode.scrollLeft || 0;
  3300. break;
  3301. } else {
  3302. valueT += element.scrollTop || 0;
  3303. valueL += element.scrollLeft || 0;
  3304. element = element.parentNode;
  3305. }
  3306. } while (element);
  3307. return new Element.Offset(valueL, valueT);
  3308. }
  3309. function viewportOffset(forElement) {
  3310. var valueT = 0, valueL = 0, docBody = document.body;
  3311. forElement = $(forElement);
  3312. var element = forElement;
  3313. do {
  3314. valueT += element.offsetTop || 0;
  3315. valueL += element.offsetLeft || 0;
  3316. if (element.offsetParent == docBody &&
  3317. Element.getStyle(element, 'position') == 'absolute') break;
  3318. } while (element = element.offsetParent);
  3319. element = forElement;
  3320. do {
  3321. if (element != docBody) {
  3322. valueT -= element.scrollTop || 0;
  3323. valueL -= element.scrollLeft || 0;
  3324. }
  3325. } while (element = element.parentNode);
  3326. return new Element.Offset(valueL, valueT);
  3327. }
  3328. function absolutize(element) {
  3329. element = $(element);
  3330. if (Element.getStyle(element, 'position') === 'absolute') {
  3331. return element;
  3332. }
  3333. var offsetParent = getOffsetParent(element);
  3334. var eOffset = element.viewportOffset(),
  3335. pOffset = offsetParent.viewportOffset();
  3336. var offset = eOffset.relativeTo(pOffset);
  3337. var layout = element.getLayout();
  3338. element.store('prototype_absolutize_original_styles', {
  3339. position: element.getStyle('position'),
  3340. left: element.getStyle('left'),
  3341. top: element.getStyle('top'),
  3342. width: element.getStyle('width'),
  3343. height: element.getStyle('height')
  3344. });
  3345. element.setStyle({
  3346. position: 'absolute',
  3347. top: offset.top + 'px',
  3348. left: offset.left + 'px',
  3349. width: layout.get('width') + 'px',
  3350. height: layout.get('height') + 'px'
  3351. });
  3352. return element;
  3353. }
  3354. function relativize(element) {
  3355. element = $(element);
  3356. if (Element.getStyle(element, 'position') === 'relative') {
  3357. return element;
  3358. }
  3359. var originalStyles =
  3360. element.retrieve('prototype_absolutize_original_styles');
  3361. if (originalStyles) element.setStyle(originalStyles);
  3362. return element;
  3363. }
  3364. function scrollTo(element) {
  3365. element = $(element);
  3366. var pos = Element.cumulativeOffset(element);
  3367. window.scrollTo(pos.left, pos.top);
  3368. return element;
  3369. }
  3370. function makePositioned(element) {
  3371. element = $(element);
  3372. var position = Element.getStyle(element, 'position'), styles = {};
  3373. if (position === 'static' || !position) {
  3374. styles.position = 'relative';
  3375. if (Prototype.Browser.Opera) {
  3376. styles.top = 0;
  3377. styles.left = 0;
  3378. }
  3379. Element.setStyle(element, styles);
  3380. Element.store(element, 'prototype_made_positioned', true);
  3381. }
  3382. return element;
  3383. }
  3384. function undoPositioned(element) {
  3385. element = $(element);
  3386. var storage = Element.getStorage(element),
  3387. madePositioned = storage.get('prototype_made_positioned');
  3388. if (madePositioned) {
  3389. storage.unset('prototype_made_positioned');
  3390. Element.setStyle(element, {
  3391. position: '',
  3392. top: '',
  3393. bottom: '',
  3394. left: '',
  3395. right: ''
  3396. });
  3397. }
  3398. return element;
  3399. }
  3400. function makeClipping(element) {
  3401. element = $(element);
  3402. var storage = Element.getStorage(element),
  3403. madeClipping = storage.get('prototype_made_clipping');
  3404. if (Object.isUndefined(madeClipping)) {
  3405. var overflow = Element.getStyle(element, 'overflow');
  3406. storage.set('prototype_made_clipping', overflow);
  3407. if (overflow !== 'hidden')
  3408. element.style.overflow = 'hidden';
  3409. }
  3410. return element;
  3411. }
  3412. function undoClipping(element) {
  3413. element = $(element);
  3414. var storage = Element.getStorage(element),
  3415. overflow = storage.get('prototype_made_clipping');
  3416. if (!Object.isUndefined(overflow)) {
  3417. storage.unset('prototype_made_clipping');
  3418. element.style.overflow = overflow || '';
  3419. }
  3420. return element;
  3421. }
  3422. function clonePosition(element, source, options) {
  3423. options = Object.extend({
  3424. setLeft: true,
  3425. setTop: true,
  3426. setWidth: true,
  3427. setHeight: true,
  3428. offsetTop: 0,
  3429. offsetLeft: 0
  3430. }, options || {});
  3431. var docEl = document.documentElement;
  3432. source = $(source);
  3433. element = $(element);
  3434. var p, delta, layout, styles = {};
  3435. if (options.setLeft || options.setTop) {
  3436. p = Element.viewportOffset(source);
  3437. delta = [0, 0];
  3438. if (Element.getStyle(element, 'position') === 'absolute') {
  3439. var parent = Element.getOffsetParent(element);
  3440. if (parent !== document.body) delta = Element.viewportOffset(parent);
  3441. }
  3442. }
  3443. function pageScrollXY() {
  3444. var x = 0, y = 0;
  3445. if (Object.isNumber(window.pageXOffset)) {
  3446. x = window.pageXOffset;
  3447. y = window.pageYOffset;
  3448. } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
  3449. x = document.body.scrollLeft;
  3450. y = document.body.scrollTop;
  3451. } else if (docEl && (docEl.scrollLeft || docEl.scrollTop)) {
  3452. x = docEl.scrollLeft;
  3453. y = docEl.scrollTop;
  3454. }
  3455. return { x: x, y: y };
  3456. }
  3457. var pageXY = pageScrollXY();
  3458. if (options.setWidth || options.setHeight) {
  3459. layout = Element.getLayout(source);
  3460. }
  3461. if (options.setLeft)
  3462. styles.left = (p[0] + pageXY.x - delta[0] + options.offsetLeft) + 'px';
  3463. if (options.setTop)
  3464. styles.top = (p[1] + pageXY.y - delta[1] + options.offsetTop) + 'px';
  3465. var currentLayout = element.getLayout();
  3466. if (options.setWidth) {
  3467. styles.width = layout.get('width') + 'px';
  3468. }
  3469. if (options.setHeight) {
  3470. styles.height = layout.get('height') + 'px';
  3471. }
  3472. return Element.setStyle(element, styles);
  3473. }
  3474. if (Prototype.Browser.IE) {
  3475. getOffsetParent = getOffsetParent.wrap(
  3476. function(proceed, element) {
  3477. element = $(element);
  3478. if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element))
  3479. return $(document.body);
  3480. var position = element.getStyle('position');
  3481. if (position !== 'static') return proceed(element);
  3482. element.setStyle({ position: 'relative' });
  3483. var value = proceed(element);
  3484. element.setStyle({ position: position });
  3485. return value;
  3486. }
  3487. );
  3488. positionedOffset = positionedOffset.wrap(function(proceed, element) {
  3489. element = $(element);
  3490. if (!element.parentNode) return new Element.Offset(0, 0);
  3491. var position = element.getStyle('position');
  3492. if (position !== 'static') return proceed(element);
  3493. var offsetParent = element.getOffsetParent();
  3494. if (offsetParent && offsetParent.getStyle('position') === 'fixed')
  3495. hasLayout(offsetParent);
  3496. element.setStyle({ position: 'relative' });
  3497. var value = proceed(element);
  3498. element.setStyle({ position: position });
  3499. return value;
  3500. });
  3501. } else if (Prototype.Browser.Webkit) {
  3502. cumulativeOffset = function(element) {
  3503. element = $(element);
  3504. var valueT = 0, valueL = 0;
  3505. do {
  3506. valueT += element.offsetTop || 0;
  3507. valueL += element.offsetLeft || 0;
  3508. if (element.offsetParent == document.body) {
  3509. if (Element.getStyle(element, 'position') == 'absolute') break;
  3510. }
  3511. element = element.offsetParent;
  3512. } while (element);
  3513. return new Element.Offset(valueL, valueT);
  3514. };
  3515. }
  3516. Element.addMethods({
  3517. getLayout: getLayout,
  3518. measure: measure,
  3519. getWidth: getWidth,
  3520. getHeight: getHeight,
  3521. getDimensions: getDimensions,
  3522. getOffsetParent: getOffsetParent,
  3523. cumulativeOffset: cumulativeOffset,
  3524. positionedOffset: positionedOffset,
  3525. cumulativeScrollOffset: cumulativeScrollOffset,
  3526. viewportOffset: viewportOffset,
  3527. absolutize: absolutize,
  3528. relativize: relativize,
  3529. scrollTo: scrollTo,
  3530. makePositioned: makePositioned,
  3531. undoPositioned: undoPositioned,
  3532. makeClipping: makeClipping,
  3533. undoClipping: undoClipping,
  3534. clonePosition: clonePosition
  3535. });
  3536. function isBody(element) {
  3537. return element.nodeName.toUpperCase() === 'BODY';
  3538. }
  3539. function isHtml(element) {
  3540. return element.nodeName.toUpperCase() === 'HTML';
  3541. }
  3542. function isDocument(element) {
  3543. return element.nodeType === Node.DOCUMENT_NODE;
  3544. }
  3545. function isDetached(element) {
  3546. return element !== document.body &&
  3547. !Element.descendantOf(element, document.body);
  3548. }
  3549. if ('getBoundingClientRect' in document.documentElement) {
  3550. Element.addMethods({
  3551. viewportOffset: function(element) {
  3552. element = $(element);
  3553. if (isDetached(element)) return new Element.Offset(0, 0);
  3554. var rect = element.getBoundingClientRect(),
  3555. docEl = document.documentElement;
  3556. return new Element.Offset(rect.left - docEl.clientLeft,
  3557. rect.top - docEl.clientTop);
  3558. }
  3559. });
  3560. }
  3561. })();
  3562. (function() {
  3563. var IS_OLD_OPERA = Prototype.Browser.Opera &&
  3564. (window.parseFloat(window.opera.version()) < 9.5);
  3565. var ROOT = null;
  3566. function getRootElement() {
  3567. if (ROOT) return ROOT;
  3568. ROOT = IS_OLD_OPERA ? document.body : document.documentElement;
  3569. return ROOT;
  3570. }
  3571. function getDimensions() {
  3572. return { width: this.getWidth(), height: this.getHeight() };
  3573. }
  3574. function getWidth() {
  3575. return getRootElement().clientWidth;
  3576. }
  3577. function getHeight() {
  3578. return getRootElement().clientHeight;
  3579. }
  3580. function getScrollOffsets() {
  3581. var x = window.pageXOffset || document.documentElement.scrollLeft ||
  3582. document.body.scrollLeft;
  3583. var y = window.pageYOffset || document.documentElement.scrollTop ||
  3584. document.body.scrollTop;
  3585. return new Element.Offset(x, y);
  3586. }
  3587. document.viewport = {
  3588. getDimensions: getDimensions,
  3589. getWidth: getWidth,
  3590. getHeight: getHeight,
  3591. getScrollOffsets: getScrollOffsets
  3592. };
  3593. })();
  3594. window.$$ = function() {
  3595. var expression = $A(arguments).join(', ');
  3596. return Prototype.Selector.select(expression, document);
  3597. };
  3598. Prototype.Selector = (function() {
  3599. function select() {
  3600. throw new Error('Method "Prototype.Selector.select" must be defined.');
  3601. }
  3602. function match() {
  3603. throw new Error('Method "Prototype.Selector.match" must be defined.');
  3604. }
  3605. function find(elements, expression, index) {
  3606. index = index || 0;
  3607. var match = Prototype.Selector.match, length = elements.length, matchIndex = 0, i;
  3608. for (i = 0; i < length; i++) {
  3609. if (match(elements[i], expression) && index == matchIndex++) {
  3610. return Element.extend(elements[i]);
  3611. }
  3612. }
  3613. }
  3614. function extendElements(elements) {
  3615. for (var i = 0, length = elements.length; i < length; i++) {
  3616. Element.extend(elements[i]);
  3617. }
  3618. return elements;
  3619. }
  3620. var K = Prototype.K;
  3621. return {
  3622. select: select,
  3623. match: match,
  3624. find: find,
  3625. extendElements: (Element.extend === K) ? K : extendElements,
  3626. extendElement: Element.extend
  3627. };
  3628. })();
  3629. Prototype._original_property = window.Sizzle;
  3630. ;(function () {
  3631. function fakeDefine(fn) {
  3632. Prototype._actual_sizzle = fn();
  3633. }
  3634. fakeDefine.amd = true;
  3635. if (typeof define !== 'undefined' && define.amd) {
  3636. Prototype._original_define = define;
  3637. Prototype._actual_sizzle = null;
  3638. window.define = fakeDefine;
  3639. }
  3640. })();
  3641. /*!
  3642. * Sizzle CSS Selector Engine v1.10.18
  3643. * http://sizzlejs.com/
  3644. *
  3645. * Copyright 2013 jQuery Foundation, Inc. and other contributors
  3646. * Released under the MIT license
  3647. * http://jquery.org/license
  3648. *
  3649. * Date: 2014-02-05
  3650. */
  3651. (function( window ) {
  3652. var i,
  3653. support,
  3654. Expr,
  3655. getText,
  3656. isXML,
  3657. compile,
  3658. select,
  3659. outermostContext,
  3660. sortInput,
  3661. hasDuplicate,
  3662. setDocument,
  3663. document,
  3664. docElem,
  3665. documentIsHTML,
  3666. rbuggyQSA,
  3667. rbuggyMatches,
  3668. matches,
  3669. contains,
  3670. expando = "sizzle" + -(new Date()),
  3671. preferredDoc = window.document,
  3672. dirruns = 0,
  3673. done = 0,
  3674. classCache = createCache(),
  3675. tokenCache = createCache(),
  3676. compilerCache = createCache(),
  3677. sortOrder = function( a, b ) {
  3678. if ( a === b ) {
  3679. hasDuplicate = true;
  3680. }
  3681. return 0;
  3682. },
  3683. strundefined = typeof undefined,
  3684. MAX_NEGATIVE = 1 << 31,
  3685. hasOwn = ({}).hasOwnProperty,
  3686. arr = [],
  3687. pop = arr.pop,
  3688. push_native = arr.push,
  3689. push = arr.push,
  3690. slice = arr.slice,
  3691. indexOf = arr.indexOf || function( elem ) {
  3692. var i = 0,
  3693. len = this.length;
  3694. for ( ; i < len; i++ ) {
  3695. if ( this[i] === elem ) {
  3696. return i;
  3697. }
  3698. }
  3699. return -1;
  3700. },
  3701. booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
  3702. whitespace = "[\\x20\\t\\r\\n\\f]",
  3703. characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
  3704. identifier = characterEncoding.replace( "w", "w#" ),
  3705. attributes = "\\[" + whitespace + "*(" + characterEncoding + ")" + whitespace +
  3706. "*(?:([*^$|!~]?=)" + whitespace + "*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|(" + identifier + ")|)|)" + whitespace + "*\\]",
  3707. pseudos = ":(" + characterEncoding + ")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|" + attributes.replace( 3, 8 ) + ")*)|.*)\\)|)",
  3708. rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
  3709. rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
  3710. rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
  3711. rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
  3712. rpseudo = new RegExp( pseudos ),
  3713. ridentifier = new RegExp( "^" + identifier + "$" ),
  3714. matchExpr = {
  3715. "ID": new RegExp( "^#(" + characterEncoding + ")" ),
  3716. "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
  3717. "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
  3718. "ATTR": new RegExp( "^" + attributes ),
  3719. "PSEUDO": new RegExp( "^" + pseudos ),
  3720. "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
  3721. "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
  3722. "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
  3723. "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
  3724. "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
  3725. whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
  3726. },
  3727. rinputs = /^(?:input|select|textarea|button)$/i,
  3728. rheader = /^h\d$/i,
  3729. rnative = /^[^{]+\{\s*\[native \w/,
  3730. rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
  3731. rsibling = /[+~]/,
  3732. rescape = /'|\\/g,
  3733. runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
  3734. funescape = function( _, escaped, escapedWhitespace ) {
  3735. var high = "0x" + escaped - 0x10000;
  3736. return high !== high || escapedWhitespace ?
  3737. escaped :
  3738. high < 0 ?
  3739. String.fromCharCode( high + 0x10000 ) :
  3740. String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
  3741. };
  3742. try {
  3743. push.apply(
  3744. (arr = slice.call( preferredDoc.childNodes )),
  3745. preferredDoc.childNodes
  3746. );
  3747. arr[ preferredDoc.childNodes.length ].nodeType;
  3748. } catch ( e ) {
  3749. push = { apply: arr.length ?
  3750. function( target, els ) {
  3751. push_native.apply( target, slice.call(els) );
  3752. } :
  3753. function( target, els ) {
  3754. var j = target.length,
  3755. i = 0;
  3756. while ( (target[j++] = els[i++]) ) {}
  3757. target.length = j - 1;
  3758. }
  3759. };
  3760. }
  3761. function Sizzle( selector, context, results, seed ) {
  3762. var match, elem, m, nodeType,
  3763. i, groups, old, nid, newContext, newSelector;
  3764. if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
  3765. setDocument( context );
  3766. }
  3767. context = context || document;
  3768. results = results || [];
  3769. if ( !selector || typeof selector !== "string" ) {
  3770. return results;
  3771. }
  3772. if ( (nodeType = context.nodeType) !== 1 && nodeType !== 9 ) {
  3773. return [];
  3774. }
  3775. if ( documentIsHTML && !seed ) {
  3776. if ( (match = rquickExpr.exec( selector )) ) {
  3777. if ( (m = match[1]) ) {
  3778. if ( nodeType === 9 ) {
  3779. elem = context.getElementById( m );
  3780. if ( elem && elem.parentNode ) {
  3781. if ( elem.id === m ) {
  3782. results.push( elem );
  3783. return results;
  3784. }
  3785. } else {
  3786. return results;
  3787. }
  3788. } else {
  3789. if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
  3790. contains( context, elem ) && elem.id === m ) {
  3791. results.push( elem );
  3792. return results;
  3793. }
  3794. }
  3795. } else if ( match[2] ) {
  3796. push.apply( results, context.getElementsByTagName( selector ) );
  3797. return results;
  3798. } else if ( (m = match[3]) && support.getElementsByClassName && context.getElementsByClassName ) {
  3799. push.apply( results, context.getElementsByClassName( m ) );
  3800. return results;
  3801. }
  3802. }
  3803. if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
  3804. nid = old = expando;
  3805. newContext = context;
  3806. newSelector = nodeType === 9 && selector;
  3807. if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
  3808. groups = tokenize( selector );
  3809. if ( (old = context.getAttribute("id")) ) {
  3810. nid = old.replace( rescape, "\\$&" );
  3811. } else {
  3812. context.setAttribute( "id", nid );
  3813. }
  3814. nid = "[id='" + nid + "'] ";
  3815. i = groups.length;
  3816. while ( i-- ) {
  3817. groups[i] = nid + toSelector( groups[i] );
  3818. }
  3819. newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
  3820. newSelector = groups.join(",");
  3821. }
  3822. if ( newSelector ) {
  3823. try {
  3824. push.apply( results,
  3825. newContext.querySelectorAll( newSelector )
  3826. );
  3827. return results;
  3828. } catch(qsaError) {
  3829. } finally {
  3830. if ( !old ) {
  3831. context.removeAttribute("id");
  3832. }
  3833. }
  3834. }
  3835. }
  3836. }
  3837. return select( selector.replace( rtrim, "$1" ), context, results, seed );
  3838. }
  3839. /**
  3840. * Create key-value caches of limited size
  3841. * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
  3842. * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
  3843. * deleting the oldest entry
  3844. */
  3845. function createCache() {
  3846. var keys = [];
  3847. function cache( key, value ) {
  3848. if ( keys.push( key + " " ) > Expr.cacheLength ) {
  3849. delete cache[ keys.shift() ];
  3850. }
  3851. return (cache[ key + " " ] = value);
  3852. }
  3853. return cache;
  3854. }
  3855. /**
  3856. * Mark a function for special use by Sizzle
  3857. * @param {Function} fn The function to mark
  3858. */
  3859. function markFunction( fn ) {
  3860. fn[ expando ] = true;
  3861. return fn;
  3862. }
  3863. /**
  3864. * Support testing using an element
  3865. * @param {Function} fn Passed the created div and expects a boolean result
  3866. */
  3867. function assert( fn ) {
  3868. var div = document.createElement("div");
  3869. try {
  3870. return !!fn( div );
  3871. } catch (e) {
  3872. return false;
  3873. } finally {
  3874. if ( div.parentNode ) {
  3875. div.parentNode.removeChild( div );
  3876. }
  3877. div = null;
  3878. }
  3879. }
  3880. /**
  3881. * Adds the same handler for all of the specified attrs
  3882. * @param {String} attrs Pipe-separated list of attributes
  3883. * @param {Function} handler The method that will be applied
  3884. */
  3885. function addHandle( attrs, handler ) {
  3886. var arr = attrs.split("|"),
  3887. i = attrs.length;
  3888. while ( i-- ) {
  3889. Expr.attrHandle[ arr[i] ] = handler;
  3890. }
  3891. }
  3892. /**
  3893. * Checks document order of two siblings
  3894. * @param {Element} a
  3895. * @param {Element} b
  3896. * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
  3897. */
  3898. function siblingCheck( a, b ) {
  3899. var cur = b && a,
  3900. diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
  3901. ( ~b.sourceIndex || MAX_NEGATIVE ) -
  3902. ( ~a.sourceIndex || MAX_NEGATIVE );
  3903. if ( diff ) {
  3904. return diff;
  3905. }
  3906. if ( cur ) {
  3907. while ( (cur = cur.nextSibling) ) {
  3908. if ( cur === b ) {
  3909. return -1;
  3910. }
  3911. }
  3912. }
  3913. return a ? 1 : -1;
  3914. }
  3915. /**
  3916. * Returns a function to use in pseudos for input types
  3917. * @param {String} type
  3918. */
  3919. function createInputPseudo( type ) {
  3920. return function( elem ) {
  3921. var name = elem.nodeName.toLowerCase();
  3922. return name === "input" && elem.type === type;
  3923. };
  3924. }
  3925. /**
  3926. * Returns a function to use in pseudos for buttons
  3927. * @param {String} type
  3928. */
  3929. function createButtonPseudo( type ) {
  3930. return function( elem ) {
  3931. var name = elem.nodeName.toLowerCase();
  3932. return (name === "input" || name === "button") && elem.type === type;
  3933. };
  3934. }
  3935. /**
  3936. * Returns a function to use in pseudos for positionals
  3937. * @param {Function} fn
  3938. */
  3939. function createPositionalPseudo( fn ) {
  3940. return markFunction(function( argument ) {
  3941. argument = +argument;
  3942. return markFunction(function( seed, matches ) {
  3943. var j,
  3944. matchIndexes = fn( [], seed.length, argument ),
  3945. i = matchIndexes.length;
  3946. while ( i-- ) {
  3947. if ( seed[ (j = matchIndexes[i]) ] ) {
  3948. seed[j] = !(matches[j] = seed[j]);
  3949. }
  3950. }
  3951. });
  3952. });
  3953. }
  3954. /**
  3955. * Checks a node for validity as a Sizzle context
  3956. * @param {Element|Object=} context
  3957. * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
  3958. */
  3959. function testContext( context ) {
  3960. return context && typeof context.getElementsByTagName !== strundefined && context;
  3961. }
  3962. support = Sizzle.support = {};
  3963. /**
  3964. * Detects XML nodes
  3965. * @param {Element|Object} elem An element or a document
  3966. * @returns {Boolean} True iff elem is a non-HTML XML node
  3967. */
  3968. isXML = Sizzle.isXML = function( elem ) {
  3969. var documentElement = elem && (elem.ownerDocument || elem).documentElement;
  3970. return documentElement ? documentElement.nodeName !== "HTML" : false;
  3971. };
  3972. /**
  3973. * Sets document-related variables once based on the current document
  3974. * @param {Element|Object} [doc] An element or document object to use to set the document
  3975. * @returns {Object} Returns the current document
  3976. */
  3977. setDocument = Sizzle.setDocument = function( node ) {
  3978. var hasCompare,
  3979. doc = node ? node.ownerDocument || node : preferredDoc,
  3980. parent = doc.defaultView;
  3981. if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
  3982. return document;
  3983. }
  3984. document = doc;
  3985. docElem = doc.documentElement;
  3986. documentIsHTML = !isXML( doc );
  3987. if ( parent && parent !== parent.top ) {
  3988. if ( parent.addEventListener ) {
  3989. parent.addEventListener( "unload", function() {
  3990. setDocument();
  3991. }, false );
  3992. } else if ( parent.attachEvent ) {
  3993. parent.attachEvent( "onunload", function() {
  3994. setDocument();
  3995. });
  3996. }
  3997. }
  3998. /* Attributes
  3999. ---------------------------------------------------------------------- */
  4000. support.attributes = assert(function( div ) {
  4001. div.className = "i";
  4002. return !div.getAttribute("className");
  4003. });
  4004. /* getElement(s)By*
  4005. ---------------------------------------------------------------------- */
  4006. support.getElementsByTagName = assert(function( div ) {
  4007. div.appendChild( doc.createComment("") );
  4008. return !div.getElementsByTagName("*").length;
  4009. });
  4010. support.getElementsByClassName = rnative.test( doc.getElementsByClassName ) && assert(function( div ) {
  4011. div.innerHTML = "<div class='a'></div><div class='a i'></div>";
  4012. div.firstChild.className = "i";
  4013. return div.getElementsByClassName("i").length === 2;
  4014. });
  4015. support.getById = assert(function( div ) {
  4016. docElem.appendChild( div ).id = expando;
  4017. return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
  4018. });
  4019. if ( support.getById ) {
  4020. Expr.find["ID"] = function( id, context ) {
  4021. if ( typeof context.getElementById !== strundefined && documentIsHTML ) {
  4022. var m = context.getElementById( id );
  4023. return m && m.parentNode ? [m] : [];
  4024. }
  4025. };
  4026. Expr.filter["ID"] = function( id ) {
  4027. var attrId = id.replace( runescape, funescape );
  4028. return function( elem ) {
  4029. return elem.getAttribute("id") === attrId;
  4030. };
  4031. };
  4032. } else {
  4033. delete Expr.find["ID"];
  4034. Expr.filter["ID"] = function( id ) {
  4035. var attrId = id.replace( runescape, funescape );
  4036. return function( elem ) {
  4037. var node = typeof elem.getAttributeNode !== strundefined && elem.getAttributeNode("id");
  4038. return node && node.value === attrId;
  4039. };
  4040. };
  4041. }
  4042. Expr.find["TAG"] = support.getElementsByTagName ?
  4043. function( tag, context ) {
  4044. if ( typeof context.getElementsByTagName !== strundefined ) {
  4045. return context.getElementsByTagName( tag );
  4046. }
  4047. } :
  4048. function( tag, context ) {
  4049. var elem,
  4050. tmp = [],
  4051. i = 0,
  4052. results = context.getElementsByTagName( tag );
  4053. if ( tag === "*" ) {
  4054. while ( (elem = results[i++]) ) {
  4055. if ( elem.nodeType === 1 ) {
  4056. tmp.push( elem );
  4057. }
  4058. }
  4059. return tmp;
  4060. }
  4061. return results;
  4062. };
  4063. Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
  4064. if ( typeof context.getElementsByClassName !== strundefined && documentIsHTML ) {
  4065. return context.getElementsByClassName( className );
  4066. }
  4067. };
  4068. /* QSA/matchesSelector
  4069. ---------------------------------------------------------------------- */
  4070. rbuggyMatches = [];
  4071. rbuggyQSA = [];
  4072. if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
  4073. assert(function( div ) {
  4074. div.innerHTML = "<select t=''><option selected=''></option></select>";
  4075. if ( div.querySelectorAll("[t^='']").length ) {
  4076. rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
  4077. }
  4078. if ( !div.querySelectorAll("[selected]").length ) {
  4079. rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
  4080. }
  4081. if ( !div.querySelectorAll(":checked").length ) {
  4082. rbuggyQSA.push(":checked");
  4083. }
  4084. });
  4085. assert(function( div ) {
  4086. var input = doc.createElement("input");
  4087. input.setAttribute( "type", "hidden" );
  4088. div.appendChild( input ).setAttribute( "name", "D" );
  4089. if ( div.querySelectorAll("[name=d]").length ) {
  4090. rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
  4091. }
  4092. if ( !div.querySelectorAll(":enabled").length ) {
  4093. rbuggyQSA.push( ":enabled", ":disabled" );
  4094. }
  4095. div.querySelectorAll("*,:x");
  4096. rbuggyQSA.push(",.*:");
  4097. });
  4098. }
  4099. if ( (support.matchesSelector = rnative.test( (matches = docElem.webkitMatchesSelector ||
  4100. docElem.mozMatchesSelector ||
  4101. docElem.oMatchesSelector ||
  4102. docElem.msMatchesSelector) )) ) {
  4103. assert(function( div ) {
  4104. support.disconnectedMatch = matches.call( div, "div" );
  4105. matches.call( div, "[s!='']:x" );
  4106. rbuggyMatches.push( "!=", pseudos );
  4107. });
  4108. }
  4109. rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
  4110. rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
  4111. /* Contains
  4112. ---------------------------------------------------------------------- */
  4113. hasCompare = rnative.test( docElem.compareDocumentPosition );
  4114. contains = hasCompare || rnative.test( docElem.contains ) ?
  4115. function( a, b ) {
  4116. var adown = a.nodeType === 9 ? a.documentElement : a,
  4117. bup = b && b.parentNode;
  4118. return a === bup || !!( bup && bup.nodeType === 1 && (
  4119. adown.contains ?
  4120. adown.contains( bup ) :
  4121. a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
  4122. ));
  4123. } :
  4124. function( a, b ) {
  4125. if ( b ) {
  4126. while ( (b = b.parentNode) ) {
  4127. if ( b === a ) {
  4128. return true;
  4129. }
  4130. }
  4131. }
  4132. return false;
  4133. };
  4134. /* Sorting
  4135. ---------------------------------------------------------------------- */
  4136. sortOrder = hasCompare ?
  4137. function( a, b ) {
  4138. if ( a === b ) {
  4139. hasDuplicate = true;
  4140. return 0;
  4141. }
  4142. var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
  4143. if ( compare ) {
  4144. return compare;
  4145. }
  4146. compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
  4147. a.compareDocumentPosition( b ) :
  4148. 1;
  4149. if ( compare & 1 ||
  4150. (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
  4151. if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
  4152. return -1;
  4153. }
  4154. if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
  4155. return 1;
  4156. }
  4157. return sortInput ?
  4158. ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) :
  4159. 0;
  4160. }
  4161. return compare & 4 ? -1 : 1;
  4162. } :
  4163. function( a, b ) {
  4164. if ( a === b ) {
  4165. hasDuplicate = true;
  4166. return 0;
  4167. }
  4168. var cur,
  4169. i = 0,
  4170. aup = a.parentNode,
  4171. bup = b.parentNode,
  4172. ap = [ a ],
  4173. bp = [ b ];
  4174. if ( !aup || !bup ) {
  4175. return a === doc ? -1 :
  4176. b === doc ? 1 :
  4177. aup ? -1 :
  4178. bup ? 1 :
  4179. sortInput ?
  4180. ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) :
  4181. 0;
  4182. } else if ( aup === bup ) {
  4183. return siblingCheck( a, b );
  4184. }
  4185. cur = a;
  4186. while ( (cur = cur.parentNode) ) {
  4187. ap.unshift( cur );
  4188. }
  4189. cur = b;
  4190. while ( (cur = cur.parentNode) ) {
  4191. bp.unshift( cur );
  4192. }
  4193. while ( ap[i] === bp[i] ) {
  4194. i++;
  4195. }
  4196. return i ?
  4197. siblingCheck( ap[i], bp[i] ) :
  4198. ap[i] === preferredDoc ? -1 :
  4199. bp[i] === preferredDoc ? 1 :
  4200. 0;
  4201. };
  4202. return doc;
  4203. };
  4204. Sizzle.matches = function( expr, elements ) {
  4205. return Sizzle( expr, null, null, elements );
  4206. };
  4207. Sizzle.matchesSelector = function( elem, expr ) {
  4208. if ( ( elem.ownerDocument || elem ) !== document ) {
  4209. setDocument( elem );
  4210. }
  4211. expr = expr.replace( rattributeQuotes, "='$1']" );
  4212. if ( support.matchesSelector && documentIsHTML &&
  4213. ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
  4214. ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
  4215. try {
  4216. var ret = matches.call( elem, expr );
  4217. if ( ret || support.disconnectedMatch ||
  4218. elem.document && elem.document.nodeType !== 11 ) {
  4219. return ret;
  4220. }
  4221. } catch(e) {}
  4222. }
  4223. return Sizzle( expr, document, null, [elem] ).length > 0;
  4224. };
  4225. Sizzle.contains = function( context, elem ) {
  4226. if ( ( context.ownerDocument || context ) !== document ) {
  4227. setDocument( context );
  4228. }
  4229. return contains( context, elem );
  4230. };
  4231. Sizzle.attr = function( elem, name ) {
  4232. if ( ( elem.ownerDocument || elem ) !== document ) {
  4233. setDocument( elem );
  4234. }
  4235. var fn = Expr.attrHandle[ name.toLowerCase() ],
  4236. val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
  4237. fn( elem, name, !documentIsHTML ) :
  4238. undefined;
  4239. return val !== undefined ?
  4240. val :
  4241. support.attributes || !documentIsHTML ?
  4242. elem.getAttribute( name ) :
  4243. (val = elem.getAttributeNode(name)) && val.specified ?
  4244. val.value :
  4245. null;
  4246. };
  4247. Sizzle.error = function( msg ) {
  4248. throw new Error( "Syntax error, unrecognized expression: " + msg );
  4249. };
  4250. /**
  4251. * Document sorting and removing duplicates
  4252. * @param {ArrayLike} results
  4253. */
  4254. Sizzle.uniqueSort = function( results ) {
  4255. var elem,
  4256. duplicates = [],
  4257. j = 0,
  4258. i = 0;
  4259. hasDuplicate = !support.detectDuplicates;
  4260. sortInput = !support.sortStable && results.slice( 0 );
  4261. results.sort( sortOrder );
  4262. if ( hasDuplicate ) {
  4263. while ( (elem = results[i++]) ) {
  4264. if ( elem === results[ i ] ) {
  4265. j = duplicates.push( i );
  4266. }
  4267. }
  4268. while ( j-- ) {
  4269. results.splice( duplicates[ j ], 1 );
  4270. }
  4271. }
  4272. sortInput = null;
  4273. return results;
  4274. };
  4275. /**
  4276. * Utility function for retrieving the text value of an array of DOM nodes
  4277. * @param {Array|Element} elem
  4278. */
  4279. getText = Sizzle.getText = function( elem ) {
  4280. var node,
  4281. ret = "",
  4282. i = 0,
  4283. nodeType = elem.nodeType;
  4284. if ( !nodeType ) {
  4285. while ( (node = elem[i++]) ) {
  4286. ret += getText( node );
  4287. }
  4288. } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
  4289. if ( typeof elem.textContent === "string" ) {
  4290. return elem.textContent;
  4291. } else {
  4292. for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
  4293. ret += getText( elem );
  4294. }
  4295. }
  4296. } else if ( nodeType === 3 || nodeType === 4 ) {
  4297. return elem.nodeValue;
  4298. }
  4299. return ret;
  4300. };
  4301. Expr = Sizzle.selectors = {
  4302. cacheLength: 50,
  4303. createPseudo: markFunction,
  4304. match: matchExpr,
  4305. attrHandle: {},
  4306. find: {},
  4307. relative: {
  4308. ">": { dir: "parentNode", first: true },
  4309. " ": { dir: "parentNode" },
  4310. "+": { dir: "previousSibling", first: true },
  4311. "~": { dir: "previousSibling" }
  4312. },
  4313. preFilter: {
  4314. "ATTR": function( match ) {
  4315. match[1] = match[1].replace( runescape, funescape );
  4316. match[3] = ( match[4] || match[5] || "" ).replace( runescape, funescape );
  4317. if ( match[2] === "~=" ) {
  4318. match[3] = " " + match[3] + " ";
  4319. }
  4320. return match.slice( 0, 4 );
  4321. },
  4322. "CHILD": function( match ) {
  4323. /* matches from matchExpr["CHILD"]
  4324. 1 type (only|nth|...)
  4325. 2 what (child|of-type)
  4326. 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
  4327. 4 xn-component of xn+y argument ([+-]?\d*n|)
  4328. 5 sign of xn-component
  4329. 6 x of xn-component
  4330. 7 sign of y-component
  4331. 8 y of y-component
  4332. */
  4333. match[1] = match[1].toLowerCase();
  4334. if ( match[1].slice( 0, 3 ) === "nth" ) {
  4335. if ( !match[3] ) {
  4336. Sizzle.error( match[0] );
  4337. }
  4338. match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
  4339. match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
  4340. } else if ( match[3] ) {
  4341. Sizzle.error( match[0] );
  4342. }
  4343. return match;
  4344. },
  4345. "PSEUDO": function( match ) {
  4346. var excess,
  4347. unquoted = !match[5] && match[2];
  4348. if ( matchExpr["CHILD"].test( match[0] ) ) {
  4349. return null;
  4350. }
  4351. if ( match[3] && match[4] !== undefined ) {
  4352. match[2] = match[4];
  4353. } else if ( unquoted && rpseudo.test( unquoted ) &&
  4354. (excess = tokenize( unquoted, true )) &&
  4355. (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
  4356. match[0] = match[0].slice( 0, excess );
  4357. match[2] = unquoted.slice( 0, excess );
  4358. }
  4359. return match.slice( 0, 3 );
  4360. }
  4361. },
  4362. filter: {
  4363. "TAG": function( nodeNameSelector ) {
  4364. var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
  4365. return nodeNameSelector === "*" ?
  4366. function() { return true; } :
  4367. function( elem ) {
  4368. return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
  4369. };
  4370. },
  4371. "CLASS": function( className ) {
  4372. var pattern = classCache[ className + " " ];
  4373. return pattern ||
  4374. (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
  4375. classCache( className, function( elem ) {
  4376. return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== strundefined && elem.getAttribute("class") || "" );
  4377. });
  4378. },
  4379. "ATTR": function( name, operator, check ) {
  4380. return function( elem ) {
  4381. var result = Sizzle.attr( elem, name );
  4382. if ( result == null ) {
  4383. return operator === "!=";
  4384. }
  4385. if ( !operator ) {
  4386. return true;
  4387. }
  4388. result += "";
  4389. return operator === "=" ? result === check :
  4390. operator === "!=" ? result !== check :
  4391. operator === "^=" ? check && result.indexOf( check ) === 0 :
  4392. operator === "*=" ? check && result.indexOf( check ) > -1 :
  4393. operator === "$=" ? check && result.slice( -check.length ) === check :
  4394. operator === "~=" ? ( " " + result + " " ).indexOf( check ) > -1 :
  4395. operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
  4396. false;
  4397. };
  4398. },
  4399. "CHILD": function( type, what, argument, first, last ) {
  4400. var simple = type.slice( 0, 3 ) !== "nth",
  4401. forward = type.slice( -4 ) !== "last",
  4402. ofType = what === "of-type";
  4403. return first === 1 && last === 0 ?
  4404. function( elem ) {
  4405. return !!elem.parentNode;
  4406. } :
  4407. function( elem, context, xml ) {
  4408. var cache, outerCache, node, diff, nodeIndex, start,
  4409. dir = simple !== forward ? "nextSibling" : "previousSibling",
  4410. parent = elem.parentNode,
  4411. name = ofType && elem.nodeName.toLowerCase(),
  4412. useCache = !xml && !ofType;
  4413. if ( parent ) {
  4414. if ( simple ) {
  4415. while ( dir ) {
  4416. node = elem;
  4417. while ( (node = node[ dir ]) ) {
  4418. if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
  4419. return false;
  4420. }
  4421. }
  4422. start = dir = type === "only" && !start && "nextSibling";
  4423. }
  4424. return true;
  4425. }
  4426. start = [ forward ? parent.firstChild : parent.lastChild ];
  4427. if ( forward && useCache ) {
  4428. outerCache = parent[ expando ] || (parent[ expando ] = {});
  4429. cache = outerCache[ type ] || [];
  4430. nodeIndex = cache[0] === dirruns && cache[1];
  4431. diff = cache[0] === dirruns && cache[2];
  4432. node = nodeIndex && parent.childNodes[ nodeIndex ];
  4433. while ( (node = ++nodeIndex && node && node[ dir ] ||
  4434. (diff = nodeIndex = 0) || start.pop()) ) {
  4435. if ( node.nodeType === 1 && ++diff && node === elem ) {
  4436. outerCache[ type ] = [ dirruns, nodeIndex, diff ];
  4437. break;
  4438. }
  4439. }
  4440. } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
  4441. diff = cache[1];
  4442. } else {
  4443. while ( (node = ++nodeIndex && node && node[ dir ] ||
  4444. (diff = nodeIndex = 0) || start.pop()) ) {
  4445. if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
  4446. if ( useCache ) {
  4447. (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
  4448. }
  4449. if ( node === elem ) {
  4450. break;
  4451. }
  4452. }
  4453. }
  4454. }
  4455. diff -= last;
  4456. return diff === first || ( diff % first === 0 && diff / first >= 0 );
  4457. }
  4458. };
  4459. },
  4460. "PSEUDO": function( pseudo, argument ) {
  4461. var args,
  4462. fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
  4463. Sizzle.error( "unsupported pseudo: " + pseudo );
  4464. if ( fn[ expando ] ) {
  4465. return fn( argument );
  4466. }
  4467. if ( fn.length > 1 ) {
  4468. args = [ pseudo, pseudo, "", argument ];
  4469. return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
  4470. markFunction(function( seed, matches ) {
  4471. var idx,
  4472. matched = fn( seed, argument ),
  4473. i = matched.length;
  4474. while ( i-- ) {
  4475. idx = indexOf.call( seed, matched[i] );
  4476. seed[ idx ] = !( matches[ idx ] = matched[i] );
  4477. }
  4478. }) :
  4479. function( elem ) {
  4480. return fn( elem, 0, args );
  4481. };
  4482. }
  4483. return fn;
  4484. }
  4485. },
  4486. pseudos: {
  4487. "not": markFunction(function( selector ) {
  4488. var input = [],
  4489. results = [],
  4490. matcher = compile( selector.replace( rtrim, "$1" ) );
  4491. return matcher[ expando ] ?
  4492. markFunction(function( seed, matches, context, xml ) {
  4493. var elem,
  4494. unmatched = matcher( seed, null, xml, [] ),
  4495. i = seed.length;
  4496. while ( i-- ) {
  4497. if ( (elem = unmatched[i]) ) {
  4498. seed[i] = !(matches[i] = elem);
  4499. }
  4500. }
  4501. }) :
  4502. function( elem, context, xml ) {
  4503. input[0] = elem;
  4504. matcher( input, null, xml, results );
  4505. return !results.pop();
  4506. };
  4507. }),
  4508. "has": markFunction(function( selector ) {
  4509. return function( elem ) {
  4510. return Sizzle( selector, elem ).length > 0;
  4511. };
  4512. }),
  4513. "contains": markFunction(function( text ) {
  4514. return function( elem ) {
  4515. return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
  4516. };
  4517. }),
  4518. "lang": markFunction( function( lang ) {
  4519. if ( !ridentifier.test(lang || "") ) {
  4520. Sizzle.error( "unsupported lang: " + lang );
  4521. }
  4522. lang = lang.replace( runescape, funescape ).toLowerCase();
  4523. return function( elem ) {
  4524. var elemLang;
  4525. do {
  4526. if ( (elemLang = documentIsHTML ?
  4527. elem.lang :
  4528. elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
  4529. elemLang = elemLang.toLowerCase();
  4530. return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
  4531. }
  4532. } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
  4533. return false;
  4534. };
  4535. }),
  4536. "target": function( elem ) {
  4537. var hash = window.location && window.location.hash;
  4538. return hash && hash.slice( 1 ) === elem.id;
  4539. },
  4540. "root": function( elem ) {
  4541. return elem === docElem;
  4542. },
  4543. "focus": function( elem ) {
  4544. return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
  4545. },
  4546. "enabled": function( elem ) {
  4547. return elem.disabled === false;
  4548. },
  4549. "disabled": function( elem ) {
  4550. return elem.disabled === true;
  4551. },
  4552. "checked": function( elem ) {
  4553. var nodeName = elem.nodeName.toLowerCase();
  4554. return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
  4555. },
  4556. "selected": function( elem ) {
  4557. if ( elem.parentNode ) {
  4558. elem.parentNode.selectedIndex;
  4559. }
  4560. return elem.selected === true;
  4561. },
  4562. "empty": function( elem ) {
  4563. for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
  4564. if ( elem.nodeType < 6 ) {
  4565. return false;
  4566. }
  4567. }
  4568. return true;
  4569. },
  4570. "parent": function( elem ) {
  4571. return !Expr.pseudos["empty"]( elem );
  4572. },
  4573. "header": function( elem ) {
  4574. return rheader.test( elem.nodeName );
  4575. },
  4576. "input": function( elem ) {
  4577. return rinputs.test( elem.nodeName );
  4578. },
  4579. "button": function( elem ) {
  4580. var name = elem.nodeName.toLowerCase();
  4581. return name === "input" && elem.type === "button" || name === "button";
  4582. },
  4583. "text": function( elem ) {
  4584. var attr;
  4585. return elem.nodeName.toLowerCase() === "input" &&
  4586. elem.type === "text" &&
  4587. ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
  4588. },
  4589. "first": createPositionalPseudo(function() {
  4590. return [ 0 ];
  4591. }),
  4592. "last": createPositionalPseudo(function( matchIndexes, length ) {
  4593. return [ length - 1 ];
  4594. }),
  4595. "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
  4596. return [ argument < 0 ? argument + length : argument ];
  4597. }),
  4598. "even": createPositionalPseudo(function( matchIndexes, length ) {
  4599. var i = 0;
  4600. for ( ; i < length; i += 2 ) {
  4601. matchIndexes.push( i );
  4602. }
  4603. return matchIndexes;
  4604. }),
  4605. "odd": createPositionalPseudo(function( matchIndexes, length ) {
  4606. var i = 1;
  4607. for ( ; i < length; i += 2 ) {
  4608. matchIndexes.push( i );
  4609. }
  4610. return matchIndexes;
  4611. }),
  4612. "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
  4613. var i = argument < 0 ? argument + length : argument;
  4614. for ( ; --i >= 0; ) {
  4615. matchIndexes.push( i );
  4616. }
  4617. return matchIndexes;
  4618. }),
  4619. "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
  4620. var i = argument < 0 ? argument + length : argument;
  4621. for ( ; ++i < length; ) {
  4622. matchIndexes.push( i );
  4623. }
  4624. return matchIndexes;
  4625. })
  4626. }
  4627. };
  4628. Expr.pseudos["nth"] = Expr.pseudos["eq"];
  4629. for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
  4630. Expr.pseudos[ i ] = createInputPseudo( i );
  4631. }
  4632. for ( i in { submit: true, reset: true } ) {
  4633. Expr.pseudos[ i ] = createButtonPseudo( i );
  4634. }
  4635. function setFilters() {}
  4636. setFilters.prototype = Expr.filters = Expr.pseudos;
  4637. Expr.setFilters = new setFilters();
  4638. function tokenize( selector, parseOnly ) {
  4639. var matched, match, tokens, type,
  4640. soFar, groups, preFilters,
  4641. cached = tokenCache[ selector + " " ];
  4642. if ( cached ) {
  4643. return parseOnly ? 0 : cached.slice( 0 );
  4644. }
  4645. soFar = selector;
  4646. groups = [];
  4647. preFilters = Expr.preFilter;
  4648. while ( soFar ) {
  4649. if ( !matched || (match = rcomma.exec( soFar )) ) {
  4650. if ( match ) {
  4651. soFar = soFar.slice( match[0].length ) || soFar;
  4652. }
  4653. groups.push( (tokens = []) );
  4654. }
  4655. matched = false;
  4656. if ( (match = rcombinators.exec( soFar )) ) {
  4657. matched = match.shift();
  4658. tokens.push({
  4659. value: matched,
  4660. type: match[0].replace( rtrim, " " )
  4661. });
  4662. soFar = soFar.slice( matched.length );
  4663. }
  4664. for ( type in Expr.filter ) {
  4665. if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
  4666. (match = preFilters[ type ]( match ))) ) {
  4667. matched = match.shift();
  4668. tokens.push({
  4669. value: matched,
  4670. type: type,
  4671. matches: match
  4672. });
  4673. soFar = soFar.slice( matched.length );
  4674. }
  4675. }
  4676. if ( !matched ) {
  4677. break;
  4678. }
  4679. }
  4680. return parseOnly ?
  4681. soFar.length :
  4682. soFar ?
  4683. Sizzle.error( selector ) :
  4684. tokenCache( selector, groups ).slice( 0 );
  4685. }
  4686. function toSelector( tokens ) {
  4687. var i = 0,
  4688. len = tokens.length,
  4689. selector = "";
  4690. for ( ; i < len; i++ ) {
  4691. selector += tokens[i].value;
  4692. }
  4693. return selector;
  4694. }
  4695. function addCombinator( matcher, combinator, base ) {
  4696. var dir = combinator.dir,
  4697. checkNonElements = base && dir === "parentNode",
  4698. doneName = done++;
  4699. return combinator.first ?
  4700. function( elem, context, xml ) {
  4701. while ( (elem = elem[ dir ]) ) {
  4702. if ( elem.nodeType === 1 || checkNonElements ) {
  4703. return matcher( elem, context, xml );
  4704. }
  4705. }
  4706. } :
  4707. function( elem, context, xml ) {
  4708. var oldCache, outerCache,
  4709. newCache = [ dirruns, doneName ];
  4710. if ( xml ) {
  4711. while ( (elem = elem[ dir ]) ) {
  4712. if ( elem.nodeType === 1 || checkNonElements ) {
  4713. if ( matcher( elem, context, xml ) ) {
  4714. return true;
  4715. }
  4716. }
  4717. }
  4718. } else {
  4719. while ( (elem = elem[ dir ]) ) {
  4720. if ( elem.nodeType === 1 || checkNonElements ) {
  4721. outerCache = elem[ expando ] || (elem[ expando ] = {});
  4722. if ( (oldCache = outerCache[ dir ]) &&
  4723. oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
  4724. return (newCache[ 2 ] = oldCache[ 2 ]);
  4725. } else {
  4726. outerCache[ dir ] = newCache;
  4727. if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
  4728. return true;
  4729. }
  4730. }
  4731. }
  4732. }
  4733. }
  4734. };
  4735. }
  4736. function elementMatcher( matchers ) {
  4737. return matchers.length > 1 ?
  4738. function( elem, context, xml ) {
  4739. var i = matchers.length;
  4740. while ( i-- ) {
  4741. if ( !matchers[i]( elem, context, xml ) ) {
  4742. return false;
  4743. }
  4744. }
  4745. return true;
  4746. } :
  4747. matchers[0];
  4748. }
  4749. function multipleContexts( selector, contexts, results ) {
  4750. var i = 0,
  4751. len = contexts.length;
  4752. for ( ; i < len; i++ ) {
  4753. Sizzle( selector, contexts[i], results );
  4754. }
  4755. return results;
  4756. }
  4757. function condense( unmatched, map, filter, context, xml ) {
  4758. var elem,
  4759. newUnmatched = [],
  4760. i = 0,
  4761. len = unmatched.length,
  4762. mapped = map != null;
  4763. for ( ; i < len; i++ ) {
  4764. if ( (elem = unmatched[i]) ) {
  4765. if ( !filter || filter( elem, context, xml ) ) {
  4766. newUnmatched.push( elem );
  4767. if ( mapped ) {
  4768. map.push( i );
  4769. }
  4770. }
  4771. }
  4772. }
  4773. return newUnmatched;
  4774. }
  4775. function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
  4776. if ( postFilter && !postFilter[ expando ] ) {
  4777. postFilter = setMatcher( postFilter );
  4778. }
  4779. if ( postFinder && !postFinder[ expando ] ) {
  4780. postFinder = setMatcher( postFinder, postSelector );
  4781. }
  4782. return markFunction(function( seed, results, context, xml ) {
  4783. var temp, i, elem,
  4784. preMap = [],
  4785. postMap = [],
  4786. preexisting = results.length,
  4787. elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
  4788. matcherIn = preFilter && ( seed || !selector ) ?
  4789. condense( elems, preMap, preFilter, context, xml ) :
  4790. elems,
  4791. matcherOut = matcher ?
  4792. postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
  4793. [] :
  4794. results :
  4795. matcherIn;
  4796. if ( matcher ) {
  4797. matcher( matcherIn, matcherOut, context, xml );
  4798. }
  4799. if ( postFilter ) {
  4800. temp = condense( matcherOut, postMap );
  4801. postFilter( temp, [], context, xml );
  4802. i = temp.length;
  4803. while ( i-- ) {
  4804. if ( (elem = temp[i]) ) {
  4805. matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
  4806. }
  4807. }
  4808. }
  4809. if ( seed ) {
  4810. if ( postFinder || preFilter ) {
  4811. if ( postFinder ) {
  4812. temp = [];
  4813. i = matcherOut.length;
  4814. while ( i-- ) {
  4815. if ( (elem = matcherOut[i]) ) {
  4816. temp.push( (matcherIn[i] = elem) );
  4817. }
  4818. }
  4819. postFinder( null, (matcherOut = []), temp, xml );
  4820. }
  4821. i = matcherOut.length;
  4822. while ( i-- ) {
  4823. if ( (elem = matcherOut[i]) &&
  4824. (temp = postFinder ? indexOf.call( seed, elem ) : preMap[i]) > -1 ) {
  4825. seed[temp] = !(results[temp] = elem);
  4826. }
  4827. }
  4828. }
  4829. } else {
  4830. matcherOut = condense(
  4831. matcherOut === results ?
  4832. matcherOut.splice( preexisting, matcherOut.length ) :
  4833. matcherOut
  4834. );
  4835. if ( postFinder ) {
  4836. postFinder( null, results, matcherOut, xml );
  4837. } else {
  4838. push.apply( results, matcherOut );
  4839. }
  4840. }
  4841. });
  4842. }
  4843. function matcherFromTokens( tokens ) {
  4844. var checkContext, matcher, j,
  4845. len = tokens.length,
  4846. leadingRelative = Expr.relative[ tokens[0].type ],
  4847. implicitRelative = leadingRelative || Expr.relative[" "],
  4848. i = leadingRelative ? 1 : 0,
  4849. matchContext = addCombinator( function( elem ) {
  4850. return elem === checkContext;
  4851. }, implicitRelative, true ),
  4852. matchAnyContext = addCombinator( function( elem ) {
  4853. return indexOf.call( checkContext, elem ) > -1;
  4854. }, implicitRelative, true ),
  4855. matchers = [ function( elem, context, xml ) {
  4856. return ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
  4857. (checkContext = context).nodeType ?
  4858. matchContext( elem, context, xml ) :
  4859. matchAnyContext( elem, context, xml ) );
  4860. } ];
  4861. for ( ; i < len; i++ ) {
  4862. if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
  4863. matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
  4864. } else {
  4865. matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
  4866. if ( matcher[ expando ] ) {
  4867. j = ++i;
  4868. for ( ; j < len; j++ ) {
  4869. if ( Expr.relative[ tokens[j].type ] ) {
  4870. break;
  4871. }
  4872. }
  4873. return setMatcher(
  4874. i > 1 && elementMatcher( matchers ),
  4875. i > 1 && toSelector(
  4876. tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
  4877. ).replace( rtrim, "$1" ),
  4878. matcher,
  4879. i < j && matcherFromTokens( tokens.slice( i, j ) ),
  4880. j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
  4881. j < len && toSelector( tokens )
  4882. );
  4883. }
  4884. matchers.push( matcher );
  4885. }
  4886. }
  4887. return elementMatcher( matchers );
  4888. }
  4889. function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
  4890. var bySet = setMatchers.length > 0,
  4891. byElement = elementMatchers.length > 0,
  4892. superMatcher = function( seed, context, xml, results, outermost ) {
  4893. var elem, j, matcher,
  4894. matchedCount = 0,
  4895. i = "0",
  4896. unmatched = seed && [],
  4897. setMatched = [],
  4898. contextBackup = outermostContext,
  4899. elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
  4900. dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
  4901. len = elems.length;
  4902. if ( outermost ) {
  4903. outermostContext = context !== document && context;
  4904. }
  4905. for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
  4906. if ( byElement && elem ) {
  4907. j = 0;
  4908. while ( (matcher = elementMatchers[j++]) ) {
  4909. if ( matcher( elem, context, xml ) ) {
  4910. results.push( elem );
  4911. break;
  4912. }
  4913. }
  4914. if ( outermost ) {
  4915. dirruns = dirrunsUnique;
  4916. }
  4917. }
  4918. if ( bySet ) {
  4919. if ( (elem = !matcher && elem) ) {
  4920. matchedCount--;
  4921. }
  4922. if ( seed ) {
  4923. unmatched.push( elem );
  4924. }
  4925. }
  4926. }
  4927. matchedCount += i;
  4928. if ( bySet && i !== matchedCount ) {
  4929. j = 0;
  4930. while ( (matcher = setMatchers[j++]) ) {
  4931. matcher( unmatched, setMatched, context, xml );
  4932. }
  4933. if ( seed ) {
  4934. if ( matchedCount > 0 ) {
  4935. while ( i-- ) {
  4936. if ( !(unmatched[i] || setMatched[i]) ) {
  4937. setMatched[i] = pop.call( results );
  4938. }
  4939. }
  4940. }
  4941. setMatched = condense( setMatched );
  4942. }
  4943. push.apply( results, setMatched );
  4944. if ( outermost && !seed && setMatched.length > 0 &&
  4945. ( matchedCount + setMatchers.length ) > 1 ) {
  4946. Sizzle.uniqueSort( results );
  4947. }
  4948. }
  4949. if ( outermost ) {
  4950. dirruns = dirrunsUnique;
  4951. outermostContext = contextBackup;
  4952. }
  4953. return unmatched;
  4954. };
  4955. return bySet ?
  4956. markFunction( superMatcher ) :
  4957. superMatcher;
  4958. }
  4959. compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
  4960. var i,
  4961. setMatchers = [],
  4962. elementMatchers = [],
  4963. cached = compilerCache[ selector + " " ];
  4964. if ( !cached ) {
  4965. if ( !match ) {
  4966. match = tokenize( selector );
  4967. }
  4968. i = match.length;
  4969. while ( i-- ) {
  4970. cached = matcherFromTokens( match[i] );
  4971. if ( cached[ expando ] ) {
  4972. setMatchers.push( cached );
  4973. } else {
  4974. elementMatchers.push( cached );
  4975. }
  4976. }
  4977. cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
  4978. cached.selector = selector;
  4979. }
  4980. return cached;
  4981. };
  4982. /**
  4983. * A low-level selection function that works with Sizzle's compiled
  4984. * selector functions
  4985. * @param {String|Function} selector A selector or a pre-compiled
  4986. * selector function built with Sizzle.compile
  4987. * @param {Element} context
  4988. * @param {Array} [results]
  4989. * @param {Array} [seed] A set of elements to match against
  4990. */
  4991. select = Sizzle.select = function( selector, context, results, seed ) {
  4992. var i, tokens, token, type, find,
  4993. compiled = typeof selector === "function" && selector,
  4994. match = !seed && tokenize( (selector = compiled.selector || selector) );
  4995. results = results || [];
  4996. if ( match.length === 1 ) {
  4997. tokens = match[0] = match[0].slice( 0 );
  4998. if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
  4999. support.getById && context.nodeType === 9 && documentIsHTML &&
  5000. Expr.relative[ tokens[1].type ] ) {
  5001. context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
  5002. if ( !context ) {
  5003. return results;
  5004. } else if ( compiled ) {
  5005. context = context.parentNode;
  5006. }
  5007. selector = selector.slice( tokens.shift().value.length );
  5008. }
  5009. i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
  5010. while ( i-- ) {
  5011. token = tokens[i];
  5012. if ( Expr.relative[ (type = token.type) ] ) {
  5013. break;
  5014. }
  5015. if ( (find = Expr.find[ type ]) ) {
  5016. if ( (seed = find(
  5017. token.matches[0].replace( runescape, funescape ),
  5018. rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
  5019. )) ) {
  5020. tokens.splice( i, 1 );
  5021. selector = seed.length && toSelector( tokens );
  5022. if ( !selector ) {
  5023. push.apply( results, seed );
  5024. return results;
  5025. }
  5026. break;
  5027. }
  5028. }
  5029. }
  5030. }
  5031. ( compiled || compile( selector, match ) )(
  5032. seed,
  5033. context,
  5034. !documentIsHTML,
  5035. results,
  5036. rsibling.test( selector ) && testContext( context.parentNode ) || context
  5037. );
  5038. return results;
  5039. };
  5040. support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
  5041. support.detectDuplicates = !!hasDuplicate;
  5042. setDocument();
  5043. support.sortDetached = assert(function( div1 ) {
  5044. return div1.compareDocumentPosition( document.createElement("div") ) & 1;
  5045. });
  5046. if ( !assert(function( div ) {
  5047. div.innerHTML = "<a href='#'></a>";
  5048. return div.firstChild.getAttribute("href") === "#" ;
  5049. }) ) {
  5050. addHandle( "type|href|height|width", function( elem, name, isXML ) {
  5051. if ( !isXML ) {
  5052. return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
  5053. }
  5054. });
  5055. }
  5056. if ( !support.attributes || !assert(function( div ) {
  5057. div.innerHTML = "<input/>";
  5058. div.firstChild.setAttribute( "value", "" );
  5059. return div.firstChild.getAttribute( "value" ) === "";
  5060. }) ) {
  5061. addHandle( "value", function( elem, name, isXML ) {
  5062. if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
  5063. return elem.defaultValue;
  5064. }
  5065. });
  5066. }
  5067. if ( !assert(function( div ) {
  5068. return div.getAttribute("disabled") == null;
  5069. }) ) {
  5070. addHandle( booleans, function( elem, name, isXML ) {
  5071. var val;
  5072. if ( !isXML ) {
  5073. return elem[ name ] === true ? name.toLowerCase() :
  5074. (val = elem.getAttributeNode( name )) && val.specified ?
  5075. val.value :
  5076. null;
  5077. }
  5078. });
  5079. }
  5080. if ( typeof define === "function" && define.amd ) {
  5081. define(function() { return Sizzle; });
  5082. } else if ( typeof module !== "undefined" && module.exports ) {
  5083. module.exports = Sizzle;
  5084. } else {
  5085. window.Sizzle = Sizzle;
  5086. }
  5087. })( window );
  5088. ;(function() {
  5089. if (typeof Sizzle !== 'undefined') {
  5090. return;
  5091. }
  5092. if (typeof define !== 'undefined' && define.amd) {
  5093. window.Sizzle = Prototype._actual_sizzle;
  5094. window.define = Prototype._original_define;
  5095. delete Prototype._actual_sizzle;
  5096. delete Prototype._original_define;
  5097. } else if (typeof module !== 'undefined' && module.exports) {
  5098. window.Sizzle = module.exports;
  5099. module.exports = {};
  5100. }
  5101. })();
  5102. ;(function(engine) {
  5103. var extendElements = Prototype.Selector.extendElements;
  5104. function select(selector, scope) {
  5105. return extendElements(engine(selector, scope || document));
  5106. }
  5107. function match(element, selector) {
  5108. return engine.matches(selector, [element]).length == 1;
  5109. }
  5110. Prototype.Selector.engine = engine;
  5111. Prototype.Selector.select = select;
  5112. Prototype.Selector.match = match;
  5113. })(Sizzle);
  5114. window.Sizzle = Prototype._original_property;
  5115. delete Prototype._original_property;
  5116. var Form = {
  5117. reset: function(form) {
  5118. form = $(form);
  5119. form.reset();
  5120. return form;
  5121. },
  5122. serializeElements: function(elements, options) {
  5123. if (typeof options != 'object') options = { hash: !!options };
  5124. else if (Object.isUndefined(options.hash)) options.hash = true;
  5125. var key, value, submitted = false, submit = options.submit, accumulator, initial;
  5126. if (options.hash) {
  5127. initial = {};
  5128. accumulator = function(result, key, value) {
  5129. if (key in result) {
  5130. if (!Object.isArray(result[key])) result[key] = [result[key]];
  5131. result[key] = result[key].concat(value);
  5132. } else result[key] = value;
  5133. return result;
  5134. };
  5135. } else {
  5136. initial = '';
  5137. accumulator = function(result, key, values) {
  5138. if (!Object.isArray(values)) {values = [values];}
  5139. if (!values.length) {return result;}
  5140. var encodedKey = encodeURIComponent(key).gsub(/%20/, '+');
  5141. return result + (result ? "&" : "") + values.map(function (value) {
  5142. value = value.gsub(/(\r)?\n/, '\r\n');
  5143. value = encodeURIComponent(value);
  5144. value = value.gsub(/%20/, '+');
  5145. return encodedKey + "=" + value;
  5146. }).join("&");
  5147. };
  5148. }
  5149. return elements.inject(initial, function(result, element) {
  5150. if (!element.disabled && element.name) {
  5151. key = element.name; value = $(element).getValue();
  5152. if (value != null && element.type != 'file' && (element.type != 'submit' || (!submitted &&
  5153. submit !== false && (!submit || key == submit) && (submitted = true)))) {
  5154. result = accumulator(result, key, value);
  5155. }
  5156. }
  5157. return result;
  5158. });
  5159. }
  5160. };
  5161. Form.Methods = {
  5162. serialize: function(form, options) {
  5163. return Form.serializeElements(Form.getElements(form), options);
  5164. },
  5165. getElements: function(form) {
  5166. var elements = $(form).getElementsByTagName('*');
  5167. var element, results = [], serializers = Form.Element.Serializers;
  5168. for (var i = 0; element = elements[i]; i++) {
  5169. if (serializers[element.tagName.toLowerCase()])
  5170. results.push(Element.extend(element));
  5171. }
  5172. return results;
  5173. },
  5174. getInputs: function(form, typeName, name) {
  5175. form = $(form);
  5176. var inputs = form.getElementsByTagName('input');
  5177. if (!typeName && !name) return $A(inputs).map(Element.extend);
  5178. for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
  5179. var input = inputs[i];
  5180. if ((typeName && input.type != typeName) || (name && input.name != name))
  5181. continue;
  5182. matchingInputs.push(Element.extend(input));
  5183. }
  5184. return matchingInputs;
  5185. },
  5186. disable: function(form) {
  5187. form = $(form);
  5188. Form.getElements(form).invoke('disable');
  5189. return form;
  5190. },
  5191. enable: function(form) {
  5192. form = $(form);
  5193. Form.getElements(form).invoke('enable');
  5194. return form;
  5195. },
  5196. findFirstElement: function(form) {
  5197. var elements = $(form).getElements().findAll(function(element) {
  5198. return 'hidden' != element.type && !element.disabled;
  5199. });
  5200. var firstByIndex = elements.findAll(function(element) {
  5201. return element.hasAttribute('tabIndex') && element.tabIndex >= 0;
  5202. }).sortBy(function(element) { return element.tabIndex }).first();
  5203. return firstByIndex ? firstByIndex : elements.find(function(element) {
  5204. return /^(?:input|select|textarea)$/i.test(element.tagName);
  5205. });
  5206. },
  5207. focusFirstElement: function(form) {
  5208. form = $(form);
  5209. var element = form.findFirstElement();
  5210. if (element) element.activate();
  5211. return form;
  5212. },
  5213. request: function(form, options) {
  5214. form = $(form), options = Object.clone(options || { });
  5215. var params = options.parameters, action = form.readAttribute('action') || '';
  5216. if (action.blank()) action = window.location.href;
  5217. options.parameters = form.serialize(true);
  5218. if (params) {
  5219. if (Object.isString(params)) params = params.toQueryParams();
  5220. Object.extend(options.parameters, params);
  5221. }
  5222. if (form.hasAttribute('method') && !options.method)
  5223. options.method = form.method;
  5224. return new Ajax.Request(action, options);
  5225. }
  5226. };
  5227. /*--------------------------------------------------------------------------*/
  5228. Form.Element = {
  5229. focus: function(element) {
  5230. $(element).focus();
  5231. return element;
  5232. },
  5233. select: function(element) {
  5234. $(element).select();
  5235. return element;
  5236. }
  5237. };
  5238. Form.Element.Methods = {
  5239. serialize: function(element) {
  5240. element = $(element);
  5241. if (!element.disabled && element.name) {
  5242. var value = element.getValue();
  5243. if (value != undefined) {
  5244. var pair = { };
  5245. pair[element.name] = value;
  5246. return Object.toQueryString(pair);
  5247. }
  5248. }
  5249. return '';
  5250. },
  5251. getValue: function(element) {
  5252. element = $(element);
  5253. var method = element.tagName.toLowerCase();
  5254. return Form.Element.Serializers[method](element);
  5255. },
  5256. setValue: function(element, value) {
  5257. element = $(element);
  5258. var method = element.tagName.toLowerCase();
  5259. Form.Element.Serializers[method](element, value);
  5260. return element;
  5261. },
  5262. clear: function(element) {
  5263. $(element).value = '';
  5264. return element;
  5265. },
  5266. present: function(element) {
  5267. return $(element).value != '';
  5268. },
  5269. activate: function(element) {
  5270. element = $(element);
  5271. try {
  5272. element.focus();
  5273. if (element.select && (element.tagName.toLowerCase() != 'input' ||
  5274. !(/^(?:button|reset|submit)$/i.test(element.type))))
  5275. element.select();
  5276. } catch (e) { }
  5277. return element;
  5278. },
  5279. disable: function(element) {
  5280. element = $(element);
  5281. element.disabled = true;
  5282. return element;
  5283. },
  5284. enable: function(element) {
  5285. element = $(element);
  5286. element.disabled = false;
  5287. return element;
  5288. }
  5289. };
  5290. /*--------------------------------------------------------------------------*/
  5291. var Field = Form.Element;
  5292. var $F = Form.Element.Methods.getValue;
  5293. /*--------------------------------------------------------------------------*/
  5294. Form.Element.Serializers = (function() {
  5295. function input(element, value) {
  5296. switch (element.type.toLowerCase()) {
  5297. case 'checkbox':
  5298. case 'radio':
  5299. return inputSelector(element, value);
  5300. default:
  5301. return valueSelector(element, value);
  5302. }
  5303. }
  5304. function inputSelector(element, value) {
  5305. if (Object.isUndefined(value))
  5306. return element.checked ? element.value : null;
  5307. else element.checked = !!value;
  5308. }
  5309. function valueSelector(element, value) {
  5310. if (Object.isUndefined(value)) return element.value;
  5311. else element.value = value;
  5312. }
  5313. function select(element, value) {
  5314. if (Object.isUndefined(value))
  5315. return (element.type === 'select-one' ? selectOne : selectMany)(element);
  5316. var opt, currentValue, single = !Object.isArray(value);
  5317. for (var i = 0, length = element.length; i < length; i++) {
  5318. opt = element.options[i];
  5319. currentValue = this.optionValue(opt);
  5320. if (single) {
  5321. if (currentValue == value) {
  5322. opt.selected = true;
  5323. return;
  5324. }
  5325. }
  5326. else opt.selected = value.include(currentValue);
  5327. }
  5328. }
  5329. function selectOne(element) {
  5330. var index = element.selectedIndex;
  5331. return index >= 0 ? optionValue(element.options[index]) : null;
  5332. }
  5333. function selectMany(element) {
  5334. var values, length = element.length;
  5335. if (!length) return null;
  5336. for (var i = 0, values = []; i < length; i++) {
  5337. var opt = element.options[i];
  5338. if (opt.selected) values.push(optionValue(opt));
  5339. }
  5340. return values;
  5341. }
  5342. function optionValue(opt) {
  5343. return Element.hasAttribute(opt, 'value') ? opt.value : opt.text;
  5344. }
  5345. return {
  5346. input: input,
  5347. inputSelector: inputSelector,
  5348. textarea: valueSelector,
  5349. select: select,
  5350. selectOne: selectOne,
  5351. selectMany: selectMany,
  5352. optionValue: optionValue,
  5353. button: valueSelector
  5354. };
  5355. })();
  5356. /*--------------------------------------------------------------------------*/
  5357. Abstract.TimedObserver = Class.create(PeriodicalExecuter, {
  5358. initialize: function($super, element, frequency, callback) {
  5359. $super(callback, frequency);
  5360. this.element = $(element);
  5361. this.lastValue = this.getValue();
  5362. },
  5363. execute: function() {
  5364. var value = this.getValue();
  5365. if (Object.isString(this.lastValue) && Object.isString(value) ?
  5366. this.lastValue != value : String(this.lastValue) != String(value)) {
  5367. this.callback(this.element, value);
  5368. this.lastValue = value;
  5369. }
  5370. }
  5371. });
  5372. Form.Element.Observer = Class.create(Abstract.TimedObserver, {
  5373. getValue: function() {
  5374. return Form.Element.getValue(this.element);
  5375. }
  5376. });
  5377. Form.Observer = Class.create(Abstract.TimedObserver, {
  5378. getValue: function() {
  5379. return Form.serialize(this.element);
  5380. }
  5381. });
  5382. /*--------------------------------------------------------------------------*/
  5383. Abstract.EventObserver = Class.create({
  5384. initialize: function(element, callback) {
  5385. this.element = $(element);
  5386. this.callback = callback;
  5387. this.lastValue = this.getValue();
  5388. if (this.element.tagName.toLowerCase() == 'form')
  5389. this.registerFormCallbacks();
  5390. else
  5391. this.registerCallback(this.element);
  5392. },
  5393. onElementEvent: function() {
  5394. var value = this.getValue();
  5395. if (this.lastValue != value) {
  5396. this.callback(this.element, value);
  5397. this.lastValue = value;
  5398. }
  5399. },
  5400. registerFormCallbacks: function() {
  5401. Form.getElements(this.element).each(this.registerCallback, this);
  5402. },
  5403. registerCallback: function(element) {
  5404. if (element.type) {
  5405. switch (element.type.toLowerCase()) {
  5406. case 'checkbox':
  5407. case 'radio':
  5408. Event.observe(element, 'click', this.onElementEvent.bind(this));
  5409. break;
  5410. default:
  5411. Event.observe(element, 'change', this.onElementEvent.bind(this));
  5412. break;
  5413. }
  5414. }
  5415. }
  5416. });
  5417. Form.Element.EventObserver = Class.create(Abstract.EventObserver, {
  5418. getValue: function() {
  5419. return Form.Element.getValue(this.element);
  5420. }
  5421. });
  5422. Form.EventObserver = Class.create(Abstract.EventObserver, {
  5423. getValue: function() {
  5424. return Form.serialize(this.element);
  5425. }
  5426. });
  5427. (function(GLOBAL) {
  5428. var DIV = document.createElement('div');
  5429. var docEl = document.documentElement;
  5430. var MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED = 'onmouseenter' in docEl
  5431. && 'onmouseleave' in docEl;
  5432. var Event = {
  5433. KEY_BACKSPACE: 8,
  5434. KEY_TAB: 9,
  5435. KEY_RETURN: 13,
  5436. KEY_ESC: 27,
  5437. KEY_LEFT: 37,
  5438. KEY_UP: 38,
  5439. KEY_RIGHT: 39,
  5440. KEY_DOWN: 40,
  5441. KEY_DELETE: 46,
  5442. KEY_HOME: 36,
  5443. KEY_END: 35,
  5444. KEY_PAGEUP: 33,
  5445. KEY_PAGEDOWN: 34,
  5446. KEY_INSERT: 45
  5447. };
  5448. var isIELegacyEvent = function(event) { return false; };
  5449. if (window.attachEvent) {
  5450. if (window.addEventListener) {
  5451. isIELegacyEvent = function(event) {
  5452. return !(event instanceof window.Event);
  5453. };
  5454. } else {
  5455. isIELegacyEvent = function(event) { return true; };
  5456. }
  5457. }
  5458. var _isButton;
  5459. function _isButtonForDOMEvents(event, code) {
  5460. return event.which ? (event.which === code + 1) : (event.button === code);
  5461. }
  5462. var legacyButtonMap = { 0: 1, 1: 4, 2: 2 };
  5463. function _isButtonForLegacyEvents(event, code) {
  5464. return event.button === legacyButtonMap[code];
  5465. }
  5466. function _isButtonForWebKit(event, code) {
  5467. switch (code) {
  5468. case 0: return event.which == 1 && !event.metaKey;
  5469. case 1: return event.which == 2 || (event.which == 1 && event.metaKey);
  5470. case 2: return event.which == 3;
  5471. default: return false;
  5472. }
  5473. }
  5474. if (window.attachEvent) {
  5475. if (!window.addEventListener) {
  5476. _isButton = _isButtonForLegacyEvents;
  5477. } else {
  5478. _isButton = function(event, code) {
  5479. return isIELegacyEvent(event) ? _isButtonForLegacyEvents(event, code) :
  5480. _isButtonForDOMEvents(event, code);
  5481. }
  5482. }
  5483. } else if (Prototype.Browser.WebKit) {
  5484. _isButton = _isButtonForWebKit;
  5485. } else {
  5486. _isButton = _isButtonForDOMEvents;
  5487. }
  5488. function isLeftClick(event) { return _isButton(event, 0) }
  5489. function isMiddleClick(event) { return _isButton(event, 1) }
  5490. function isRightClick(event) { return _isButton(event, 2) }
  5491. function element(event) {
  5492. return Element.extend(_element(event));
  5493. }
  5494. function _element(event) {
  5495. event = Event.extend(event);
  5496. var node = event.target, type = event.type,
  5497. currentTarget = event.currentTarget;
  5498. if (currentTarget && currentTarget.tagName) {
  5499. if (type === 'load' || type === 'error' ||
  5500. (type === 'click' && currentTarget.tagName.toLowerCase() === 'input'
  5501. && currentTarget.type === 'radio'))
  5502. node = currentTarget;
  5503. }
  5504. return node.nodeType == Node.TEXT_NODE ? node.parentNode : node;
  5505. }
  5506. function findElement(event, expression) {
  5507. var element = _element(event), selector = Prototype.Selector;
  5508. if (!expression) return Element.extend(element);
  5509. while (element) {
  5510. if (Object.isElement(element) && selector.match(element, expression))
  5511. return Element.extend(element);
  5512. element = element.parentNode;
  5513. }
  5514. }
  5515. function pointer(event) {
  5516. return { x: pointerX(event), y: pointerY(event) };
  5517. }
  5518. function pointerX(event) {
  5519. var docElement = document.documentElement,
  5520. body = document.body || { scrollLeft: 0 };
  5521. return event.pageX || (event.clientX +
  5522. (docElement.scrollLeft || body.scrollLeft) -
  5523. (docElement.clientLeft || 0));
  5524. }
  5525. function pointerY(event) {
  5526. var docElement = document.documentElement,
  5527. body = document.body || { scrollTop: 0 };
  5528. return event.pageY || (event.clientY +
  5529. (docElement.scrollTop || body.scrollTop) -
  5530. (docElement.clientTop || 0));
  5531. }
  5532. function stop(event) {
  5533. Event.extend(event);
  5534. event.preventDefault();
  5535. event.stopPropagation();
  5536. event.stopped = true;
  5537. }
  5538. Event.Methods = {
  5539. isLeftClick: isLeftClick,
  5540. isMiddleClick: isMiddleClick,
  5541. isRightClick: isRightClick,
  5542. element: element,
  5543. findElement: findElement,
  5544. pointer: pointer,
  5545. pointerX: pointerX,
  5546. pointerY: pointerY,
  5547. stop: stop
  5548. };
  5549. var methods = Object.keys(Event.Methods).inject({ }, function(m, name) {
  5550. m[name] = Event.Methods[name].methodize();
  5551. return m;
  5552. });
  5553. if (window.attachEvent) {
  5554. function _relatedTarget(event) {
  5555. var element;
  5556. switch (event.type) {
  5557. case 'mouseover':
  5558. case 'mouseenter':
  5559. element = event.fromElement;
  5560. break;
  5561. case 'mouseout':
  5562. case 'mouseleave':
  5563. element = event.toElement;
  5564. break;
  5565. default:
  5566. return null;
  5567. }
  5568. return Element.extend(element);
  5569. }
  5570. var additionalMethods = {
  5571. stopPropagation: function() { this.cancelBubble = true },
  5572. preventDefault: function() { this.returnValue = false },
  5573. inspect: function() { return '[object Event]' }
  5574. };
  5575. Event.extend = function(event, element) {
  5576. if (!event) return false;
  5577. if (!isIELegacyEvent(event)) return event;
  5578. if (event._extendedByPrototype) return event;
  5579. event._extendedByPrototype = Prototype.emptyFunction;
  5580. var pointer = Event.pointer(event);
  5581. Object.extend(event, {
  5582. target: event.srcElement || element,
  5583. relatedTarget: _relatedTarget(event),
  5584. pageX: pointer.x,
  5585. pageY: pointer.y
  5586. });
  5587. Object.extend(event, methods);
  5588. Object.extend(event, additionalMethods);
  5589. return event;
  5590. };
  5591. } else {
  5592. Event.extend = Prototype.K;
  5593. }
  5594. if (window.addEventListener) {
  5595. Event.prototype = window.Event.prototype || document.createEvent('HTMLEvents').__proto__;
  5596. Object.extend(Event.prototype, methods);
  5597. }
  5598. var EVENT_TRANSLATIONS = {
  5599. mouseenter: 'mouseover',
  5600. mouseleave: 'mouseout'
  5601. };
  5602. function getDOMEventName(eventName) {
  5603. return EVENT_TRANSLATIONS[eventName] || eventName;
  5604. }
  5605. if (MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED)
  5606. getDOMEventName = Prototype.K;
  5607. function getUniqueElementID(element) {
  5608. if (element === window) return 0;
  5609. if (typeof element._prototypeUID === 'undefined')
  5610. element._prototypeUID = Element.Storage.UID++;
  5611. return element._prototypeUID;
  5612. }
  5613. function getUniqueElementID_IE(element) {
  5614. if (element === window) return 0;
  5615. if (element == document) return 1;
  5616. return element.uniqueID;
  5617. }
  5618. if ('uniqueID' in DIV)
  5619. getUniqueElementID = getUniqueElementID_IE;
  5620. function isCustomEvent(eventName) {
  5621. return eventName.include(':');
  5622. }
  5623. Event._isCustomEvent = isCustomEvent;
  5624. function getOrCreateRegistryFor(element, uid) {
  5625. var CACHE = GLOBAL.Event.cache;
  5626. if (Object.isUndefined(uid))
  5627. uid = getUniqueElementID(element);
  5628. if (!CACHE[uid]) CACHE[uid] = { element: element };
  5629. return CACHE[uid];
  5630. }
  5631. function destroyRegistryForElement(element, uid) {
  5632. if (Object.isUndefined(uid))
  5633. uid = getUniqueElementID(element);
  5634. delete GLOBAL.Event.cache[uid];
  5635. }
  5636. function register(element, eventName, handler) {
  5637. var registry = getOrCreateRegistryFor(element);
  5638. if (!registry[eventName]) registry[eventName] = [];
  5639. var entries = registry[eventName];
  5640. var i = entries.length;
  5641. while (i--)
  5642. if (entries[i].handler === handler) return null;
  5643. var uid = getUniqueElementID(element);
  5644. var responder = GLOBAL.Event._createResponder(uid, eventName, handler);
  5645. var entry = {
  5646. responder: responder,
  5647. handler: handler
  5648. };
  5649. entries.push(entry);
  5650. return entry;
  5651. }
  5652. function unregister(element, eventName, handler) {
  5653. var registry = getOrCreateRegistryFor(element);
  5654. var entries = registry[eventName] || [];
  5655. var i = entries.length, entry;
  5656. while (i--) {
  5657. if (entries[i].handler === handler) {
  5658. entry = entries[i];
  5659. break;
  5660. }
  5661. }
  5662. if (entry) {
  5663. var index = entries.indexOf(entry);
  5664. entries.splice(index, 1);
  5665. }
  5666. if (entries.length === 0) {
  5667. delete registry[eventName];
  5668. if (Object.keys(registry).length === 1 && ('element' in registry))
  5669. destroyRegistryForElement(element);
  5670. }
  5671. return entry;
  5672. }
  5673. function observe(element, eventName, handler) {
  5674. element = $(element);
  5675. var entry = register(element, eventName, handler);
  5676. if (entry === null) return element;
  5677. var responder = entry.responder;
  5678. if (isCustomEvent(eventName))
  5679. observeCustomEvent(element, eventName, responder);
  5680. else
  5681. observeStandardEvent(element, eventName, responder);
  5682. return element;
  5683. }
  5684. function observeStandardEvent(element, eventName, responder) {
  5685. var actualEventName = getDOMEventName(eventName);
  5686. if (element.addEventListener) {
  5687. element.addEventListener(actualEventName, responder, false);
  5688. } else {
  5689. element.attachEvent('on' + actualEventName, responder);
  5690. }
  5691. }
  5692. function observeCustomEvent(element, eventName, responder) {
  5693. if (element.addEventListener) {
  5694. element.addEventListener('dataavailable', responder, false);
  5695. } else {
  5696. element.attachEvent('ondataavailable', responder);
  5697. element.attachEvent('onlosecapture', responder);
  5698. }
  5699. }
  5700. function stopObserving(element, eventName, handler) {
  5701. element = $(element);
  5702. var handlerGiven = !Object.isUndefined(handler),
  5703. eventNameGiven = !Object.isUndefined(eventName);
  5704. if (!eventNameGiven && !handlerGiven) {
  5705. stopObservingElement(element);
  5706. return element;
  5707. }
  5708. if (!handlerGiven) {
  5709. stopObservingEventName(element, eventName);
  5710. return element;
  5711. }
  5712. var entry = unregister(element, eventName, handler);
  5713. if (!entry) return element;
  5714. removeEvent(element, eventName, entry.responder);
  5715. return element;
  5716. }
  5717. function stopObservingStandardEvent(element, eventName, responder) {
  5718. var actualEventName = getDOMEventName(eventName);
  5719. if (element.removeEventListener) {
  5720. element.removeEventListener(actualEventName, responder, false);
  5721. } else {
  5722. element.detachEvent('on' + actualEventName, responder);
  5723. }
  5724. }
  5725. function stopObservingCustomEvent(element, eventName, responder) {
  5726. if (element.removeEventListener) {
  5727. element.removeEventListener('dataavailable', responder, false);
  5728. } else {
  5729. element.detachEvent('ondataavailable', responder);
  5730. element.detachEvent('onlosecapture', responder);
  5731. }
  5732. }
  5733. function stopObservingElement(element) {
  5734. var uid = getUniqueElementID(element), registry = GLOBAL.Event.cache[uid];
  5735. if (!registry) return;
  5736. destroyRegistryForElement(element, uid);
  5737. var entries, i;
  5738. for (var eventName in registry) {
  5739. if (eventName === 'element') continue;
  5740. entries = registry[eventName];
  5741. i = entries.length;
  5742. while (i--)
  5743. removeEvent(element, eventName, entries[i].responder);
  5744. }
  5745. }
  5746. function stopObservingEventName(element, eventName) {
  5747. var registry = getOrCreateRegistryFor(element);
  5748. var entries = registry[eventName];
  5749. if (entries) {
  5750. delete registry[eventName];
  5751. }
  5752. entries = entries || [];
  5753. var i = entries.length;
  5754. while (i--)
  5755. removeEvent(element, eventName, entries[i].responder);
  5756. for (var name in registry) {
  5757. if (name === 'element') continue;
  5758. return; // There is another registered event
  5759. }
  5760. destroyRegistryForElement(element);
  5761. }
  5762. function removeEvent(element, eventName, handler) {
  5763. if (isCustomEvent(eventName))
  5764. stopObservingCustomEvent(element, eventName, handler);
  5765. else
  5766. stopObservingStandardEvent(element, eventName, handler);
  5767. }
  5768. function getFireTarget(element) {
  5769. if (element !== document) return element;
  5770. if (document.createEvent && !element.dispatchEvent)
  5771. return document.documentElement;
  5772. return element;
  5773. }
  5774. function fire(element, eventName, memo, bubble) {
  5775. element = getFireTarget($(element));
  5776. if (Object.isUndefined(bubble)) bubble = true;
  5777. memo = memo || {};
  5778. var event = fireEvent(element, eventName, memo, bubble);
  5779. return Event.extend(event);
  5780. }
  5781. function fireEvent_DOM(element, eventName, memo, bubble) {
  5782. var event = document.createEvent('HTMLEvents');
  5783. event.initEvent('dataavailable', bubble, true);
  5784. event.eventName = eventName;
  5785. event.memo = memo;
  5786. element.dispatchEvent(event);
  5787. return event;
  5788. }
  5789. function fireEvent_IE(element, eventName, memo, bubble) {
  5790. var event = document.createEventObject();
  5791. event.eventType = bubble ? 'ondataavailable' : 'onlosecapture';
  5792. event.eventName = eventName;
  5793. event.memo = memo;
  5794. element.fireEvent(event.eventType, event);
  5795. return event;
  5796. }
  5797. var fireEvent = document.createEvent ? fireEvent_DOM : fireEvent_IE;
  5798. Event.Handler = Class.create({
  5799. initialize: function(element, eventName, selector, callback) {
  5800. this.element = $(element);
  5801. this.eventName = eventName;
  5802. this.selector = selector;
  5803. this.callback = callback;
  5804. this.handler = this.handleEvent.bind(this);
  5805. },
  5806. start: function() {
  5807. Event.observe(this.element, this.eventName, this.handler);
  5808. return this;
  5809. },
  5810. stop: function() {
  5811. Event.stopObserving(this.element, this.eventName, this.handler);
  5812. return this;
  5813. },
  5814. handleEvent: function(event) {
  5815. var element = Event.findElement(event, this.selector);
  5816. if (element) this.callback.call(this.element, event, element);
  5817. }
  5818. });
  5819. function on(element, eventName, selector, callback) {
  5820. element = $(element);
  5821. if (Object.isFunction(selector) && Object.isUndefined(callback)) {
  5822. callback = selector, selector = null;
  5823. }
  5824. return new Event.Handler(element, eventName, selector, callback).start();
  5825. }
  5826. Object.extend(Event, Event.Methods);
  5827. Object.extend(Event, {
  5828. fire: fire,
  5829. observe: observe,
  5830. stopObserving: stopObserving,
  5831. p_on: on
  5832. });
  5833. Element.addMethods({
  5834. fire: fire,
  5835. observe: observe,
  5836. stopObserving: stopObserving,
  5837. p_on: on
  5838. });
  5839. Object.extend(document, {
  5840. fire: fire.methodize(),
  5841. observe: observe.methodize(),
  5842. stopObserving: stopObserving.methodize(),
  5843. p_on: on.methodize(),
  5844. loaded: false
  5845. });
  5846. if (GLOBAL.Event) Object.extend(window.Event, Event);
  5847. else GLOBAL.Event = Event;
  5848. GLOBAL.Event.cache = {};
  5849. function destroyCache_IE() {
  5850. GLOBAL.Event.cache = null;
  5851. }
  5852. if (window.attachEvent)
  5853. window.attachEvent('onunload', destroyCache_IE);
  5854. DIV = null;
  5855. docEl = null;
  5856. })(this);
  5857. (function(GLOBAL) {
  5858. /* Code for creating leak-free event responders is based on work by
  5859. John-David Dalton. */
  5860. var docEl = document.documentElement;
  5861. var MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED = 'onmouseenter' in docEl
  5862. && 'onmouseleave' in docEl;
  5863. function isSimulatedMouseEnterLeaveEvent(eventName) {
  5864. return !MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED &&
  5865. (eventName === 'mouseenter' || eventName === 'mouseleave');
  5866. }
  5867. function createResponder(uid, eventName, handler) {
  5868. if (Event._isCustomEvent(eventName))
  5869. return createResponderForCustomEvent(uid, eventName, handler);
  5870. if (isSimulatedMouseEnterLeaveEvent(eventName))
  5871. return createMouseEnterLeaveResponder(uid, eventName, handler);
  5872. return function(event) {
  5873. if (!Event.cache) return;
  5874. var element = Event.cache[uid].element;
  5875. Event.extend(event, element);
  5876. handler.call(element, event);
  5877. };
  5878. }
  5879. function createResponderForCustomEvent(uid, eventName, handler) {
  5880. return function(event) {
  5881. var cache = Event.cache[uid];
  5882. var element = cache && cache.element;
  5883. if (Object.isUndefined(event.eventName))
  5884. return false;
  5885. if (event.eventName !== eventName)
  5886. return false;
  5887. Event.extend(event, element);
  5888. handler.call(element, event);
  5889. };
  5890. }
  5891. function createMouseEnterLeaveResponder(uid, eventName, handler) {
  5892. return function(event) {
  5893. var element = Event.cache[uid].element;
  5894. Event.extend(event, element);
  5895. var parent = event.relatedTarget;
  5896. while (parent && parent !== element) {
  5897. try { parent = parent.parentNode; }
  5898. catch(e) { parent = element; }
  5899. }
  5900. if (parent === element) return;
  5901. handler.call(element, event);
  5902. }
  5903. }
  5904. GLOBAL.Event._createResponder = createResponder;
  5905. docEl = null;
  5906. })(this);
  5907. (function(GLOBAL) {
  5908. /* Support for the DOMContentLoaded event is based on work by Dan Webb,
  5909. Matthias Miller, Dean Edwards, John Resig, and Diego Perini. */
  5910. var TIMER;
  5911. function fireContentLoadedEvent() {
  5912. if (document.loaded) return;
  5913. if (TIMER) window.clearTimeout(TIMER);
  5914. document.loaded = true;
  5915. document.fire('dom:loaded');
  5916. }
  5917. function checkReadyState() {
  5918. if (document.readyState === 'complete') {
  5919. document.detachEvent('onreadystatechange', checkReadyState);
  5920. fireContentLoadedEvent();
  5921. }
  5922. }
  5923. function pollDoScroll() {
  5924. try {
  5925. document.documentElement.doScroll('left');
  5926. } catch (e) {
  5927. TIMER = pollDoScroll.defer();
  5928. return;
  5929. }
  5930. fireContentLoadedEvent();
  5931. }
  5932. if (document.readyState === 'complete') {
  5933. fireContentLoadedEvent();
  5934. return;
  5935. }
  5936. if (document.addEventListener) {
  5937. document.addEventListener('DOMContentLoaded', fireContentLoadedEvent, false);
  5938. } else {
  5939. document.attachEvent('onreadystatechange', checkReadyState);
  5940. if (window == top) TIMER = pollDoScroll.defer();
  5941. }
  5942. Event.observe(window, 'load', fireContentLoadedEvent);
  5943. })(this);
  5944. Element.addMethods();
  5945. /*------------------------------- DEPRECATED -------------------------------*/
  5946. Hash.toQueryString = Object.toQueryString;
  5947. var Toggle = { display: Element.toggle };
  5948. Element.addMethods({
  5949. childOf: Element.Methods.descendantOf
  5950. });
  5951. var Insertion = {
  5952. Before: function(element, content) {
  5953. return Element.insert(element, {before:content});
  5954. },
  5955. Top: function(element, content) {
  5956. return Element.insert(element, {top:content});
  5957. },
  5958. Bottom: function(element, content) {
  5959. return Element.insert(element, {bottom:content});
  5960. },
  5961. After: function(element, content) {
  5962. return Element.insert(element, {after:content});
  5963. }
  5964. };
  5965. var $continue = new Error('"throw $continue" is deprecated, use "return" instead');
  5966. var Position = {
  5967. includeScrollOffsets: false,
  5968. prepare: function() {
  5969. this.deltaX = window.pageXOffset
  5970. || document.documentElement.scrollLeft
  5971. || document.body.scrollLeft
  5972. || 0;
  5973. this.deltaY = window.pageYOffset
  5974. || document.documentElement.scrollTop
  5975. || document.body.scrollTop
  5976. || 0;
  5977. },
  5978. within: function(element, x, y) {
  5979. if (this.includeScrollOffsets)
  5980. return this.withinIncludingScrolloffsets(element, x, y);
  5981. this.xcomp = x;
  5982. this.ycomp = y;
  5983. this.offset = Element.cumulativeOffset(element);
  5984. return (y >= this.offset[1] &&
  5985. y < this.offset[1] + element.offsetHeight &&
  5986. x >= this.offset[0] &&
  5987. x < this.offset[0] + element.offsetWidth);
  5988. },
  5989. withinIncludingScrolloffsets: function(element, x, y) {
  5990. var offsetcache = Element.cumulativeScrollOffset(element);
  5991. this.xcomp = x + offsetcache[0] - this.deltaX;
  5992. this.ycomp = y + offsetcache[1] - this.deltaY;
  5993. this.offset = Element.cumulativeOffset(element);
  5994. return (this.ycomp >= this.offset[1] &&
  5995. this.ycomp < this.offset[1] + element.offsetHeight &&
  5996. this.xcomp >= this.offset[0] &&
  5997. this.xcomp < this.offset[0] + element.offsetWidth);
  5998. },
  5999. overlap: function(mode, element) {
  6000. if (!mode) return 0;
  6001. if (mode == 'vertical')
  6002. return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
  6003. element.offsetHeight;
  6004. if (mode == 'horizontal')
  6005. return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
  6006. element.offsetWidth;
  6007. },
  6008. cumulativeOffset: Element.Methods.cumulativeOffset,
  6009. positionedOffset: Element.Methods.positionedOffset,
  6010. absolutize: function(element) {
  6011. Position.prepare();
  6012. return Element.absolutize(element);
  6013. },
  6014. relativize: function(element) {
  6015. Position.prepare();
  6016. return Element.relativize(element);
  6017. },
  6018. realOffset: Element.Methods.cumulativeScrollOffset,
  6019. offsetParent: Element.Methods.getOffsetParent,
  6020. page: Element.Methods.viewportOffset,
  6021. clone: function(source, target, options) {
  6022. options = options || { };
  6023. return Element.clonePosition(target, source, options);
  6024. }
  6025. };
  6026. /*--------------------------------------------------------------------------*/
  6027. if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){
  6028. function iter(name) {
  6029. return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]";
  6030. }
  6031. instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ?
  6032. function(element, className) {
  6033. className = className.toString().strip();
  6034. var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className);
  6035. return cond ? document._getElementsByXPath('.//*' + cond, element) : [];
  6036. } : function(element, className) {
  6037. className = className.toString().strip();
  6038. var elements = [], classNames = (/\s/.test(className) ? $w(className) : null);
  6039. if (!classNames && !className) return elements;
  6040. var nodes = $(element).getElementsByTagName('*');
  6041. className = ' ' + className + ' ';
  6042. for (var i = 0, child, cn; child = nodes[i]; i++) {
  6043. if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||
  6044. (classNames && classNames.all(function(name) {
  6045. return !name.toString().blank() && cn.include(' ' + name + ' ');
  6046. }))))
  6047. elements.push(Element.extend(child));
  6048. }
  6049. return elements;
  6050. };
  6051. return function(className, parentElement) {
  6052. return $(parentElement || document.body).getElementsByClassName(className);
  6053. };
  6054. }(Element.Methods);
  6055. /*--------------------------------------------------------------------------*/
  6056. Element.ClassNames = Class.create();
  6057. Element.ClassNames.prototype = {
  6058. initialize: function(element) {
  6059. this.element = $(element);
  6060. },
  6061. _each: function(iterator, context) {
  6062. this.element.className.split(/\s+/).select(function(name) {
  6063. return name.length > 0;
  6064. })._each(iterator, context);
  6065. },
  6066. set: function(className) {
  6067. this.element.className = className;
  6068. },
  6069. add: function(classNameToAdd) {
  6070. if (this.include(classNameToAdd)) return;
  6071. this.set($A(this).concat(classNameToAdd).join(' '));
  6072. },
  6073. remove: function(classNameToRemove) {
  6074. if (!this.include(classNameToRemove)) return;
  6075. this.set($A(this).without(classNameToRemove).join(' '));
  6076. },
  6077. toString: function() {
  6078. return $A(this).join(' ');
  6079. }
  6080. };
  6081. Object.extend(Element.ClassNames.prototype, Enumerable);
  6082. /*--------------------------------------------------------------------------*/
  6083. (function() {
  6084. window.Selector = Class.create({
  6085. initialize: function(expression) {
  6086. this.expression = expression.strip();
  6087. },
  6088. findElements: function(rootElement) {
  6089. return Prototype.Selector.select(this.expression, rootElement);
  6090. },
  6091. match: function(element) {
  6092. return Prototype.Selector.match(element, this.expression);
  6093. },
  6094. toString: function() {
  6095. return this.expression;
  6096. },
  6097. inspect: function() {
  6098. return "#<Selector: " + this.expression + ">";
  6099. }
  6100. });
  6101. Object.extend(Selector, {
  6102. matchElements: function(elements, expression) {
  6103. var match = Prototype.Selector.match,
  6104. results = [];
  6105. for (var i = 0, length = elements.length; i < length; i++) {
  6106. var element = elements[i];
  6107. if (match(element, expression)) {
  6108. results.push(Element.extend(element));
  6109. }
  6110. }
  6111. return results;
  6112. },
  6113. findElement: function(elements, expression, index) {
  6114. index = index || 0;
  6115. var matchIndex = 0, element;
  6116. for (var i = 0, length = elements.length; i < length; i++) {
  6117. element = elements[i];
  6118. if (Prototype.Selector.match(element, expression) && index === matchIndex++) {
  6119. return Element.extend(element);
  6120. }
  6121. }
  6122. },
  6123. findChildElements: function(element, expressions) {
  6124. var selector = expressions.toArray().join(', ');
  6125. return Prototype.Selector.select(selector, element || document);
  6126. }
  6127. });
  6128. })();