prototype.js 159 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083
  1. /* Prototype JavaScript framework, version 1.7
  2. * (c) 2005-2010 Sam Stephenson
  3. *
  4. * Prototype is freely distributable under the terms of an MIT-style license.
  5. * For details, see the Prototype web site: http://www.prototypejs.org/
  6. *
  7. *--------------------------------------------------------------------------*/
  8. var Prototype = {
  9. Version: '1.7',
  10. Browser: (function(){
  11. var ua = navigator.userAgent;
  12. var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
  13. return {
  14. IE: !!window.attachEvent && !isOpera,
  15. Opera: isOpera,
  16. WebKit: ua.indexOf('AppleWebKit/') > -1,
  17. Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1,
  18. MobileSafari: /Apple.*Mobile/.test(ua)
  19. }
  20. })(),
  21. BrowserFeatures: {
  22. XPath: !!document.evaluate,
  23. SelectorsAPI: !!document.querySelector,
  24. ElementExtensions: (function() {
  25. var constructor = window.Element || window.HTMLElement;
  26. return !!(constructor && constructor.prototype);
  27. })(),
  28. SpecificElementExtensions: (function() {
  29. if (typeof window.HTMLDivElement !== 'undefined')
  30. return true;
  31. var div = document.createElement('div'),
  32. form = document.createElement('form'),
  33. isSupported = false;
  34. if (div['__proto__'] && (div['__proto__'] !== form['__proto__'])) {
  35. isSupported = true;
  36. }
  37. div = form = null;
  38. return isSupported;
  39. })()
  40. },
  41. ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
  42. JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
  43. emptyFunction: function() { },
  44. K: function(x) { return x }
  45. };
  46. if (Prototype.Browser.MobileSafari)
  47. Prototype.BrowserFeatures.SpecificElementExtensions = false;
  48. var Abstract = { };
  49. var Try = {
  50. these: function() {
  51. var returnValue;
  52. for (var i = 0, length = arguments.length; i < length; i++) {
  53. var lambda = arguments[i];
  54. try {
  55. returnValue = lambda();
  56. break;
  57. } catch (e) { }
  58. }
  59. return returnValue;
  60. }
  61. };
  62. /* Based on Alex Arnell's inheritance implementation. */
  63. var Class = (function() {
  64. var IS_DONTENUM_BUGGY = (function(){
  65. for (var p in { toString: 1 }) {
  66. if (p === 'toString') return false;
  67. }
  68. return true;
  69. })();
  70. function subclass() {};
  71. function create() {
  72. var parent = null, properties = $A(arguments);
  73. if (Object.isFunction(properties[0]))
  74. parent = properties.shift();
  75. function klass() {
  76. this.initialize.apply(this, arguments);
  77. }
  78. Object.extend(klass, Class.Methods);
  79. klass.superclass = parent;
  80. klass.subclasses = [];
  81. if (parent) {
  82. subclass.prototype = parent.prototype;
  83. klass.prototype = new subclass;
  84. parent.subclasses.push(klass);
  85. }
  86. for (var i = 0, length = properties.length; i < length; i++)
  87. klass.addMethods(properties[i]);
  88. if (!klass.prototype.initialize)
  89. klass.prototype.initialize = Prototype.emptyFunction;
  90. klass.prototype.constructor = klass;
  91. return klass;
  92. }
  93. function addMethods(source) {
  94. var ancestor = this.superclass && this.superclass.prototype,
  95. properties = Object.keys(source);
  96. if (IS_DONTENUM_BUGGY) {
  97. if (source.toString != Object.prototype.toString)
  98. properties.push("toString");
  99. if (source.valueOf != Object.prototype.valueOf)
  100. properties.push("valueOf");
  101. }
  102. for (var i = 0, length = properties.length; i < length; i++) {
  103. var property = properties[i], value = source[property];
  104. if (ancestor && Object.isFunction(value) &&
  105. value.argumentNames()[0] == "$super") {
  106. var method = value;
  107. value = (function(m) {
  108. return function() { return ancestor[m].apply(this, arguments); };
  109. })(property).wrap(method);
  110. value.valueOf = method.valueOf.bind(method);
  111. value.toString = method.toString.bind(method);
  112. }
  113. this.prototype[property] = value;
  114. }
  115. return this;
  116. }
  117. return {
  118. create: create,
  119. Methods: {
  120. addMethods: addMethods
  121. }
  122. };
  123. })();
  124. (function() {
  125. var _toString = Object.prototype.toString,
  126. NULL_TYPE = 'Null',
  127. UNDEFINED_TYPE = 'Undefined',
  128. BOOLEAN_TYPE = 'Boolean',
  129. NUMBER_TYPE = 'Number',
  130. STRING_TYPE = 'String',
  131. OBJECT_TYPE = 'Object',
  132. FUNCTION_CLASS = '[object Function]',
  133. BOOLEAN_CLASS = '[object Boolean]',
  134. NUMBER_CLASS = '[object Number]',
  135. STRING_CLASS = '[object String]',
  136. ARRAY_CLASS = '[object Array]',
  137. DATE_CLASS = '[object Date]',
  138. NATIVE_JSON_STRINGIFY_SUPPORT = window.JSON &&
  139. typeof JSON.stringify === 'function' &&
  140. JSON.stringify(0) === '0' &&
  141. typeof JSON.stringify(Prototype.K) === 'undefined';
  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. type = typeof value;
  176. if (Type(value) === OBJECT_TYPE && typeof value.toJSON === 'function') {
  177. value = value.toJSON(key);
  178. }
  179. var _class = _toString.call(value);
  180. switch (_class) {
  181. case NUMBER_CLASS:
  182. case BOOLEAN_CLASS:
  183. case STRING_CLASS:
  184. value = value.valueOf();
  185. }
  186. switch (value) {
  187. case null: return 'null';
  188. case true: return 'true';
  189. case false: return 'false';
  190. }
  191. type = typeof value;
  192. switch (type) {
  193. case 'string':
  194. return value.inspect(true);
  195. case 'number':
  196. return isFinite(value) ? String(value) : 'null';
  197. case 'object':
  198. for (var i = 0, length = stack.length; i < length; i++) {
  199. if (stack[i] === value) { throw new TypeError(); }
  200. }
  201. stack.push(value);
  202. var partial = [];
  203. if (_class === ARRAY_CLASS) {
  204. for (var i = 0, length = value.length; i < length; i++) {
  205. var str = Str(i, value, stack);
  206. partial.push(typeof str === 'undefined' ? 'null' : str);
  207. }
  208. partial = '[' + partial.join(',') + ']';
  209. } else {
  210. var keys = Object.keys(value);
  211. for (var i = 0, length = keys.length; i < length; i++) {
  212. var key = keys[i], str = Str(key, value, stack);
  213. if (typeof str !== "undefined") {
  214. partial.push(key.inspect(true)+ ':' + str);
  215. }
  216. }
  217. partial = '{' + partial.join(',') + '}';
  218. }
  219. stack.pop();
  220. return partial;
  221. }
  222. }
  223. function stringify(object) {
  224. return JSON.stringify(object);
  225. }
  226. function toQueryString(object) {
  227. return $H(object).toQueryString();
  228. }
  229. function toHTML(object) {
  230. return object && object.toHTML ? object.toHTML() : String.interpret(object);
  231. }
  232. function keys(object) {
  233. if (Type(object) !== OBJECT_TYPE) { throw new TypeError(); }
  234. var results = [];
  235. for (var property in object) {
  236. if (object.hasOwnProperty(property)) {
  237. results.push(property);
  238. }
  239. }
  240. return results;
  241. }
  242. function values(object) {
  243. var results = [];
  244. for (var property in object)
  245. results.push(object[property]);
  246. return results;
  247. }
  248. function clone(object) {
  249. return extend({ }, object);
  250. }
  251. function isElement(object) {
  252. return !!(object && object.nodeType == 1);
  253. }
  254. function isArray(object) {
  255. return _toString.call(object) === ARRAY_CLASS;
  256. }
  257. var hasNativeIsArray = (typeof Array.isArray == 'function')
  258. && Array.isArray([]) && !Array.isArray({});
  259. if (hasNativeIsArray) {
  260. isArray = Array.isArray;
  261. }
  262. function isHash(object) {
  263. return object instanceof Hash;
  264. }
  265. function isFunction(object) {
  266. return _toString.call(object) === FUNCTION_CLASS;
  267. }
  268. function isString(object) {
  269. return _toString.call(object) === STRING_CLASS;
  270. }
  271. function isNumber(object) {
  272. return _toString.call(object) === NUMBER_CLASS;
  273. }
  274. function isDate(object) {
  275. return _toString.call(object) === DATE_CLASS;
  276. }
  277. function isUndefined(object) {
  278. return typeof object === "undefined";
  279. }
  280. extend(Object, {
  281. extend: extend,
  282. inspect: inspect,
  283. toJSON: NATIVE_JSON_STRINGIFY_SUPPORT ? stringify : toJSON,
  284. toQueryString: toQueryString,
  285. toHTML: toHTML,
  286. keys: Object.keys || keys,
  287. values: values,
  288. clone: clone,
  289. isElement: isElement,
  290. isArray: isArray,
  291. isHash: isHash,
  292. isFunction: isFunction,
  293. isString: isString,
  294. isNumber: isNumber,
  295. isDate: isDate,
  296. isUndefined: isUndefined
  297. });
  298. })();
  299. Object.extend(Function.prototype, (function() {
  300. var slice = Array.prototype.slice;
  301. function update(array, args) {
  302. var arrayLength = array.length, length = args.length;
  303. while (length--) array[arrayLength + length] = args[length];
  304. return array;
  305. }
  306. function merge(array, args) {
  307. array = slice.call(array, 0);
  308. return update(array, args);
  309. }
  310. function argumentNames() {
  311. var names = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
  312. .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
  313. .replace(/\s+/g, '').split(',');
  314. return names.length == 1 && !names[0] ? [] : names;
  315. }
  316. function bind(context) {
  317. if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
  318. var __method = this, args = slice.call(arguments, 1);
  319. return function() {
  320. var a = merge(args, arguments);
  321. return __method.apply(context, a);
  322. }
  323. }
  324. function bindAsEventListener(context) {
  325. var __method = this, args = slice.call(arguments, 1);
  326. return function(event) {
  327. var a = update([event || window.event], args);
  328. return __method.apply(context, a);
  329. }
  330. }
  331. function curry() {
  332. if (!arguments.length) return this;
  333. var __method = this, args = slice.call(arguments, 0);
  334. return function() {
  335. var a = merge(args, arguments);
  336. return __method.apply(this, a);
  337. }
  338. }
  339. function delay(timeout) {
  340. var __method = this, args = slice.call(arguments, 1);
  341. timeout = timeout * 1000;
  342. return window.setTimeout(function() {
  343. return __method.apply(__method, args);
  344. }, timeout);
  345. }
  346. function defer() {
  347. var args = update([0.01], arguments);
  348. return this.delay.apply(this, args);
  349. }
  350. function wrap(wrapper) {
  351. var __method = this;
  352. return function() {
  353. var a = update([__method.bind(this)], arguments);
  354. return wrapper.apply(this, a);
  355. }
  356. }
  357. function methodize() {
  358. if (this._methodized) return this._methodized;
  359. var __method = this;
  360. return this._methodized = function() {
  361. var a = update([this], arguments);
  362. return __method.apply(null, a);
  363. };
  364. }
  365. return {
  366. argumentNames: argumentNames,
  367. bind: bind,
  368. bindAsEventListener: bindAsEventListener,
  369. curry: curry,
  370. delay: delay,
  371. defer: defer,
  372. wrap: wrap,
  373. methodize: methodize
  374. }
  375. })());
  376. (function(proto) {
  377. function toISOString() {
  378. return this.getUTCFullYear() + '-' +
  379. (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
  380. this.getUTCDate().toPaddedString(2) + 'T' +
  381. this.getUTCHours().toPaddedString(2) + ':' +
  382. this.getUTCMinutes().toPaddedString(2) + ':' +
  383. this.getUTCSeconds().toPaddedString(2) + 'Z';
  384. }
  385. function toJSON() {
  386. return this.toISOString();
  387. }
  388. if (!proto.toISOString) proto.toISOString = toISOString;
  389. if (!proto.toJSON) proto.toJSON = toJSON;
  390. })(Date.prototype);
  391. RegExp.prototype.match = RegExp.prototype.test;
  392. RegExp.escape = function(str) {
  393. return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
  394. };
  395. var PeriodicalExecuter = Class.create({
  396. initialize: function(callback, frequency) {
  397. this.callback = callback;
  398. this.frequency = frequency;
  399. this.currentlyExecuting = false;
  400. this.registerCallback();
  401. },
  402. registerCallback: function() {
  403. this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
  404. },
  405. execute: function() {
  406. this.callback(this);
  407. },
  408. stop: function() {
  409. if (!this.timer) return;
  410. clearInterval(this.timer);
  411. this.timer = null;
  412. },
  413. onTimerEvent: function() {
  414. if (!this.currentlyExecuting) {
  415. try {
  416. this.currentlyExecuting = true;
  417. this.execute();
  418. this.currentlyExecuting = false;
  419. } catch(e) {
  420. this.currentlyExecuting = false;
  421. throw e;
  422. }
  423. }
  424. }
  425. });
  426. Object.extend(String, {
  427. interpret: function(value) {
  428. return value == null ? '' : String(value);
  429. },
  430. specialChar: {
  431. '\b': '\\b',
  432. '\t': '\\t',
  433. '\n': '\\n',
  434. '\f': '\\f',
  435. '\r': '\\r',
  436. '\\': '\\\\'
  437. }
  438. });
  439. Object.extend(String.prototype, (function() {
  440. var NATIVE_JSON_PARSE_SUPPORT = window.JSON &&
  441. typeof JSON.parse === 'function' &&
  442. JSON.parse('{"test": true}').test;
  443. function prepareReplacement(replacement) {
  444. if (Object.isFunction(replacement)) return replacement;
  445. var template = new Template(replacement);
  446. return function(match) { return template.evaluate(match) };
  447. }
  448. function gsub(pattern, replacement) {
  449. var result = '', source = this, match;
  450. replacement = prepareReplacement(replacement);
  451. if (Object.isString(pattern))
  452. pattern = RegExp.escape(pattern);
  453. if (!(pattern.length || pattern.source)) {
  454. replacement = replacement('');
  455. return replacement + source.split('').join(replacement) + replacement;
  456. }
  457. while (source.length > 0) {
  458. if (match = source.match(pattern)) {
  459. result += source.slice(0, match.index);
  460. result += String.interpret(replacement(match));
  461. source = source.slice(match.index + match[0].length);
  462. } else {
  463. result += source, source = '';
  464. }
  465. }
  466. return result;
  467. }
  468. function sub(pattern, replacement, count) {
  469. replacement = prepareReplacement(replacement);
  470. count = Object.isUndefined(count) ? 1 : count;
  471. return this.gsub(pattern, function(match) {
  472. if (--count < 0) return match[0];
  473. return replacement(match);
  474. });
  475. }
  476. function scan(pattern, iterator) {
  477. this.gsub(pattern, iterator);
  478. return String(this);
  479. }
  480. function truncate(length, truncation) {
  481. length = length || 30;
  482. truncation = Object.isUndefined(truncation) ? '...' : truncation;
  483. return this.length > length ?
  484. this.slice(0, length - truncation.length) + truncation : String(this);
  485. }
  486. function strip() {
  487. return this.replace(/^\s+/, '').replace(/\s+$/, '');
  488. }
  489. function stripTags() {
  490. return this.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi, '');
  491. }
  492. function stripScripts() {
  493. return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
  494. }
  495. function extractScripts() {
  496. var matchAll = new RegExp(Prototype.ScriptFragment, 'img'),
  497. matchOne = new RegExp(Prototype.ScriptFragment, 'im');
  498. return (this.match(matchAll) || []).map(function(scriptTag) {
  499. return (scriptTag.match(matchOne) || ['', ''])[1];
  500. });
  501. }
  502. function evalScripts() {
  503. return this.extractScripts().map(function(script) { return eval(script) });
  504. }
  505. function escapeHTML() {
  506. return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
  507. }
  508. function unescapeHTML() {
  509. return this.stripTags().replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');
  510. }
  511. function toQueryParams(separator) {
  512. var match = this.strip().match(/([^?#]*)(#.*)?$/);
  513. if (!match) return { };
  514. return match[1].split(separator || '&').inject({ }, function(hash, pair) {
  515. if ((pair = pair.split('='))[0]) {
  516. var key = decodeURIComponent(pair.shift()),
  517. value = pair.length > 1 ? pair.join('=') : pair[0];
  518. if (value != undefined) value = decodeURIComponent(value);
  519. if (key in hash) {
  520. if (!Object.isArray(hash[key])) hash[key] = [hash[key]];
  521. hash[key].push(value);
  522. }
  523. else hash[key] = value;
  524. }
  525. return hash;
  526. });
  527. }
  528. function toArray() {
  529. return this.split('');
  530. }
  531. function succ() {
  532. return this.slice(0, this.length - 1) +
  533. String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
  534. }
  535. function times(count) {
  536. return count < 1 ? '' : new Array(count + 1).join(this);
  537. }
  538. function camelize() {
  539. return this.replace(/-+(.)?/g, function(match, chr) {
  540. return chr ? chr.toUpperCase() : '';
  541. });
  542. }
  543. function capitalize() {
  544. return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
  545. }
  546. function underscore() {
  547. return this.replace(/::/g, '/')
  548. .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
  549. .replace(/([a-z\d])([A-Z])/g, '$1_$2')
  550. .replace(/-/g, '_')
  551. .toLowerCase();
  552. }
  553. function dasherize() {
  554. return this.replace(/_/g, '-');
  555. }
  556. function inspect(useDoubleQuotes) {
  557. var escapedString = this.replace(/[\x00-\x1f\\]/g, function(character) {
  558. if (character in String.specialChar) {
  559. return String.specialChar[character];
  560. }
  561. return '\\u00' + character.charCodeAt().toPaddedString(2, 16);
  562. });
  563. if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
  564. return "'" + escapedString.replace(/'/g, '\\\'') + "'";
  565. }
  566. function unfilterJSON(filter) {
  567. return this.replace(filter || Prototype.JSONFilter, '$1');
  568. }
  569. function isJSON() {
  570. var str = this;
  571. if (str.blank()) return false;
  572. str = str.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@');
  573. str = str.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']');
  574. str = str.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
  575. return (/^[\],:{}\s]*$/).test(str);
  576. }
  577. function evalJSON(sanitize) {
  578. var json = this.unfilterJSON(),
  579. cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  580. if (cx.test(json)) {
  581. json = json.replace(cx, function (a) {
  582. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  583. });
  584. }
  585. try {
  586. if (!sanitize || json.isJSON()) return eval('(' + json + ')');
  587. } catch (e) { }
  588. throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
  589. }
  590. function parseJSON() {
  591. var json = this.unfilterJSON();
  592. return JSON.parse(json);
  593. }
  594. function include(pattern) {
  595. return this.indexOf(pattern) > -1;
  596. }
  597. function startsWith(pattern) {
  598. return this.lastIndexOf(pattern, 0) === 0;
  599. }
  600. function endsWith(pattern) {
  601. var d = this.length - pattern.length;
  602. return d >= 0 && this.indexOf(pattern, d) === d;
  603. }
  604. function empty() {
  605. return this == '';
  606. }
  607. function blank() {
  608. return /^\s*$/.test(this);
  609. }
  610. function interpolate(object, pattern) {
  611. return new Template(this, pattern).evaluate(object);
  612. }
  613. return {
  614. gsub: gsub,
  615. sub: sub,
  616. scan: scan,
  617. truncate: truncate,
  618. strip: String.prototype.trim || strip,
  619. stripTags: stripTags,
  620. stripScripts: stripScripts,
  621. extractScripts: extractScripts,
  622. evalScripts: evalScripts,
  623. escapeHTML: escapeHTML,
  624. unescapeHTML: unescapeHTML,
  625. toQueryParams: toQueryParams,
  626. parseQuery: toQueryParams,
  627. toArray: toArray,
  628. succ: succ,
  629. times: times,
  630. camelize: camelize,
  631. capitalize: capitalize,
  632. underscore: underscore,
  633. dasherize: dasherize,
  634. inspect: inspect,
  635. unfilterJSON: unfilterJSON,
  636. isJSON: isJSON,
  637. evalJSON: NATIVE_JSON_PARSE_SUPPORT ? parseJSON : evalJSON,
  638. include: include,
  639. startsWith: startsWith,
  640. endsWith: endsWith,
  641. empty: empty,
  642. blank: blank,
  643. interpolate: interpolate
  644. };
  645. })());
  646. var Template = Class.create({
  647. initialize: function(template, pattern) {
  648. this.template = template.toString();
  649. this.pattern = pattern || Template.Pattern;
  650. },
  651. evaluate: function(object) {
  652. if (object && Object.isFunction(object.toTemplateReplacements))
  653. object = object.toTemplateReplacements();
  654. return this.template.gsub(this.pattern, function(match) {
  655. if (object == null) return (match[1] + '');
  656. var before = match[1] || '';
  657. if (before == '\\') return match[2];
  658. var ctx = object, expr = match[3],
  659. pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
  660. match = pattern.exec(expr);
  661. if (match == null) return before;
  662. while (match != null) {
  663. var comp = match[1].startsWith('[') ? match[2].replace(/\\\\]/g, ']') : match[1];
  664. ctx = ctx[comp];
  665. if (null == ctx || '' == match[3]) break;
  666. expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);
  667. match = pattern.exec(expr);
  668. }
  669. return before + String.interpret(ctx);
  670. });
  671. }
  672. });
  673. Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
  674. var $break = { };
  675. var Enumerable = (function() {
  676. function each(iterator, context) {
  677. var index = 0;
  678. try {
  679. this._each(function(value) {
  680. iterator.call(context, value, index++);
  681. });
  682. } catch (e) {
  683. if (e != $break) throw e;
  684. }
  685. return this;
  686. }
  687. function eachSlice(number, iterator, context) {
  688. var index = -number, slices = [], array = this.toArray();
  689. if (number < 1) return array;
  690. while ((index += number) < array.length)
  691. slices.push(array.slice(index, index+number));
  692. return slices.collect(iterator, context);
  693. }
  694. function all(iterator, context) {
  695. iterator = iterator || Prototype.K;
  696. var result = true;
  697. this.each(function(value, index) {
  698. result = result && !!iterator.call(context, value, index);
  699. if (!result) throw $break;
  700. });
  701. return result;
  702. }
  703. function any(iterator, context) {
  704. iterator = iterator || Prototype.K;
  705. var result = false;
  706. this.each(function(value, index) {
  707. if (result = !!iterator.call(context, value, index))
  708. throw $break;
  709. });
  710. return result;
  711. }
  712. function collect(iterator, context) {
  713. iterator = iterator || Prototype.K;
  714. var results = [];
  715. this.each(function(value, index) {
  716. results.push(iterator.call(context, value, index));
  717. });
  718. return results;
  719. }
  720. function detect(iterator, context) {
  721. var result;
  722. this.each(function(value, index) {
  723. if (iterator.call(context, value, index)) {
  724. result = value;
  725. throw $break;
  726. }
  727. });
  728. return result;
  729. }
  730. function findAll(iterator, context) {
  731. var results = [];
  732. this.each(function(value, index) {
  733. if (iterator.call(context, value, index))
  734. results.push(value);
  735. });
  736. return results;
  737. }
  738. function grep(filter, iterator, context) {
  739. iterator = iterator || Prototype.K;
  740. var results = [];
  741. if (Object.isString(filter))
  742. filter = new RegExp(RegExp.escape(filter));
  743. this.each(function(value, index) {
  744. if (filter.match(value))
  745. results.push(iterator.call(context, value, index));
  746. });
  747. return results;
  748. }
  749. function include(object) {
  750. if (Object.isFunction(this.indexOf))
  751. if (this.indexOf(object) != -1) return true;
  752. var found = false;
  753. this.each(function(value) {
  754. if (value == object) {
  755. found = true;
  756. throw $break;
  757. }
  758. });
  759. return found;
  760. }
  761. function inGroupsOf(number, fillWith) {
  762. fillWith = Object.isUndefined(fillWith) ? null : fillWith;
  763. return this.eachSlice(number, function(slice) {
  764. while(slice.length < number) slice.push(fillWith);
  765. return slice;
  766. });
  767. }
  768. function inject(memo, iterator, context) {
  769. this.each(function(value, index) {
  770. memo = iterator.call(context, memo, value, index);
  771. });
  772. return memo;
  773. }
  774. function invoke(method) {
  775. var args = $A(arguments).slice(1);
  776. return this.map(function(value) {
  777. return value[method].apply(value, args);
  778. });
  779. }
  780. function max(iterator, context) {
  781. iterator = iterator || Prototype.K;
  782. var result;
  783. this.each(function(value, index) {
  784. value = iterator.call(context, value, index);
  785. if (result == null || value >= result)
  786. result = value;
  787. });
  788. return result;
  789. }
  790. function min(iterator, context) {
  791. iterator = iterator || Prototype.K;
  792. var result;
  793. this.each(function(value, index) {
  794. value = iterator.call(context, value, index);
  795. if (result == null || value < result)
  796. result = value;
  797. });
  798. return result;
  799. }
  800. function partition(iterator, context) {
  801. iterator = iterator || Prototype.K;
  802. var trues = [], falses = [];
  803. this.each(function(value, index) {
  804. (iterator.call(context, value, index) ?
  805. trues : falses).push(value);
  806. });
  807. return [trues, falses];
  808. }
  809. function pluck(property) {
  810. var results = [];
  811. this.each(function(value) {
  812. results.push(value[property]);
  813. });
  814. return results;
  815. }
  816. function reject(iterator, context) {
  817. var results = [];
  818. this.each(function(value, index) {
  819. if (!iterator.call(context, value, index))
  820. results.push(value);
  821. });
  822. return results;
  823. }
  824. function sortBy(iterator, context) {
  825. return this.map(function(value, index) {
  826. return {
  827. value: value,
  828. criteria: iterator.call(context, value, index)
  829. };
  830. }).sort(function(left, right) {
  831. var a = left.criteria, b = right.criteria;
  832. return a < b ? -1 : a > b ? 1 : 0;
  833. }).pluck('value');
  834. }
  835. function toArray() {
  836. return this.map();
  837. }
  838. function zip() {
  839. var iterator = Prototype.K, args = $A(arguments);
  840. if (Object.isFunction(args.last()))
  841. iterator = args.pop();
  842. var collections = [this].concat(args).map($A);
  843. return this.map(function(value, index) {
  844. return iterator(collections.pluck(index));
  845. });
  846. }
  847. function size() {
  848. return this.toArray().length;
  849. }
  850. function inspect() {
  851. return '#<Enumerable:' + this.toArray().inspect() + '>';
  852. }
  853. return {
  854. each: each,
  855. eachSlice: eachSlice,
  856. all: all,
  857. every: all,
  858. any: any,
  859. some: any,
  860. collect: collect,
  861. map: collect,
  862. detect: detect,
  863. findAll: findAll,
  864. select: findAll,
  865. filter: findAll,
  866. grep: grep,
  867. include: include,
  868. member: include,
  869. inGroupsOf: inGroupsOf,
  870. inject: inject,
  871. invoke: invoke,
  872. max: max,
  873. min: min,
  874. partition: partition,
  875. pluck: pluck,
  876. reject: reject,
  877. sortBy: sortBy,
  878. toArray: toArray,
  879. entries: toArray,
  880. zip: zip,
  881. size: size,
  882. inspect: inspect,
  883. find: detect
  884. };
  885. })();
  886. function $A(iterable) {
  887. if (!iterable) return [];
  888. if ('toArray' in Object(iterable)) return iterable.toArray();
  889. var length = iterable.length || 0, results = new Array(length);
  890. while (length--) results[length] = iterable[length];
  891. return results;
  892. }
  893. function $w(string) {
  894. if (!Object.isString(string)) return [];
  895. string = string.strip();
  896. return string ? string.split(/\s+/) : [];
  897. }
  898. Array.from = $A;
  899. (function() {
  900. var arrayProto = Array.prototype,
  901. slice = arrayProto.slice,
  902. _each = arrayProto.forEach; // use native browser JS 1.6 implementation if available
  903. function each(iterator, context) {
  904. for (var i = 0, length = this.length >>> 0; i < length; i++) {
  905. if (i in this) iterator.call(context, this[i], i, this);
  906. }
  907. }
  908. if (!_each) _each = each;
  909. function clear() {
  910. this.length = 0;
  911. return this;
  912. }
  913. function first() {
  914. return this[0];
  915. }
  916. function last() {
  917. return this[this.length - 1];
  918. }
  919. function compact() {
  920. return this.select(function(value) {
  921. return value != null;
  922. });
  923. }
  924. function flatten() {
  925. return this.inject([], function(array, value) {
  926. if (Object.isArray(value))
  927. return array.concat(value.flatten());
  928. array.push(value);
  929. return array;
  930. });
  931. }
  932. function without() {
  933. var values = slice.call(arguments, 0);
  934. return this.select(function(value) {
  935. return !values.include(value);
  936. });
  937. }
  938. function reverse(inline) {
  939. return (inline === false ? this.toArray() : this)._reverse();
  940. }
  941. function uniq(sorted) {
  942. return this.inject([], function(array, value, index) {
  943. if (0 == index || (sorted ? array.last() != value : !array.include(value)))
  944. array.push(value);
  945. return array;
  946. });
  947. }
  948. function intersect(array) {
  949. return this.uniq().findAll(function(item) {
  950. return array.detect(function(value) { return item === value });
  951. });
  952. }
  953. function clone() {
  954. return slice.call(this, 0);
  955. }
  956. function size() {
  957. return this.length;
  958. }
  959. function inspect() {
  960. return '[' + this.map(Object.inspect).join(', ') + ']';
  961. }
  962. function indexOf(item, i) {
  963. i || (i = 0);
  964. var length = this.length;
  965. if (i < 0) i = length + i;
  966. for (; i < length; i++)
  967. if (this[i] === item) return i;
  968. return -1;
  969. }
  970. function lastIndexOf(item, i) {
  971. i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1;
  972. var n = this.slice(0, i).reverse().indexOf(item);
  973. return (n < 0) ? n : i - n - 1;
  974. }
  975. function concat() {
  976. var array = slice.call(this, 0), item;
  977. for (var i = 0, length = arguments.length; i < length; i++) {
  978. item = arguments[i];
  979. if (Object.isArray(item) && !('callee' in item)) {
  980. for (var j = 0, arrayLength = item.length; j < arrayLength; j++)
  981. array.push(item[j]);
  982. } else {
  983. array.push(item);
  984. }
  985. }
  986. return array;
  987. }
  988. Object.extend(arrayProto, Enumerable);
  989. if (!arrayProto._reverse)
  990. arrayProto._reverse = arrayProto.reverse;
  991. Object.extend(arrayProto, {
  992. _each: _each,
  993. clear: clear,
  994. first: first,
  995. last: last,
  996. compact: compact,
  997. flatten: flatten,
  998. without: without,
  999. reverse: reverse,
  1000. uniq: uniq,
  1001. intersect: intersect,
  1002. clone: clone,
  1003. toArray: clone,
  1004. size: size,
  1005. inspect: inspect
  1006. });
  1007. var CONCAT_ARGUMENTS_BUGGY = (function() {
  1008. return [].concat(arguments)[0][0] !== 1;
  1009. })(1,2)
  1010. if (CONCAT_ARGUMENTS_BUGGY) arrayProto.concat = concat;
  1011. if (!arrayProto.indexOf) arrayProto.indexOf = indexOf;
  1012. if (!arrayProto.lastIndexOf) arrayProto.lastIndexOf = lastIndexOf;
  1013. })();
  1014. function $H(object) {
  1015. return new Hash(object);
  1016. };
  1017. var Hash = Class.create(Enumerable, (function() {
  1018. function initialize(object) {
  1019. this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
  1020. }
  1021. function _each(iterator) {
  1022. for (var key in this._object) {
  1023. var value = this._object[key], pair = [key, value];
  1024. pair.key = key;
  1025. pair.value = value;
  1026. iterator(pair);
  1027. }
  1028. }
  1029. function set(key, value) {
  1030. return this._object[key] = value;
  1031. }
  1032. function get(key) {
  1033. if (this._object[key] !== Object.prototype[key])
  1034. return this._object[key];
  1035. }
  1036. function unset(key) {
  1037. var value = this._object[key];
  1038. delete this._object[key];
  1039. return value;
  1040. }
  1041. function toObject() {
  1042. return Object.clone(this._object);
  1043. }
  1044. function keys() {
  1045. return this.pluck('key');
  1046. }
  1047. function values() {
  1048. return this.pluck('value');
  1049. }
  1050. function index(value) {
  1051. var match = this.detect(function(pair) {
  1052. return pair.value === value;
  1053. });
  1054. return match && match.key;
  1055. }
  1056. function merge(object) {
  1057. return this.clone().update(object);
  1058. }
  1059. function update(object) {
  1060. return new Hash(object).inject(this, function(result, pair) {
  1061. result.set(pair.key, pair.value);
  1062. return result;
  1063. });
  1064. }
  1065. function toQueryPair(key, value) {
  1066. if (Object.isUndefined(value)) return key;
  1067. return key + '=' + encodeURIComponent(String.interpret(value));
  1068. }
  1069. function toQueryString() {
  1070. return this.inject([], function(results, pair) {
  1071. var key = encodeURIComponent(pair.key), values = pair.value;
  1072. if (values && typeof values == 'object') {
  1073. if (Object.isArray(values)) {
  1074. var queryValues = [];
  1075. for (var i = 0, len = values.length, value; i < len; i++) {
  1076. value = values[i];
  1077. queryValues.push(toQueryPair(key, value));
  1078. }
  1079. return results.concat(queryValues);
  1080. }
  1081. } else results.push(toQueryPair(key, values));
  1082. return results;
  1083. }).join('&');
  1084. }
  1085. function inspect() {
  1086. return '#<Hash:{' + this.map(function(pair) {
  1087. return pair.map(Object.inspect).join(': ');
  1088. }).join(', ') + '}>';
  1089. }
  1090. function clone() {
  1091. return new Hash(this);
  1092. }
  1093. return {
  1094. initialize: initialize,
  1095. _each: _each,
  1096. set: set,
  1097. get: get,
  1098. unset: unset,
  1099. toObject: toObject,
  1100. toTemplateReplacements: toObject,
  1101. keys: keys,
  1102. values: values,
  1103. index: index,
  1104. merge: merge,
  1105. update: update,
  1106. toQueryString: toQueryString,
  1107. inspect: inspect,
  1108. toJSON: toObject,
  1109. clone: clone
  1110. };
  1111. })());
  1112. Hash.from = $H;
  1113. Object.extend(Number.prototype, (function() {
  1114. function toColorPart() {
  1115. return this.toPaddedString(2, 16);
  1116. }
  1117. function succ() {
  1118. return this + 1;
  1119. }
  1120. function times(iterator, context) {
  1121. $R(0, this, true).each(iterator, context);
  1122. return this;
  1123. }
  1124. function toPaddedString(length, radix) {
  1125. var string = this.toString(radix || 10);
  1126. return '0'.times(length - string.length) + string;
  1127. }
  1128. function abs() {
  1129. return Math.abs(this);
  1130. }
  1131. function round() {
  1132. return Math.round(this);
  1133. }
  1134. function ceil() {
  1135. return Math.ceil(this);
  1136. }
  1137. function floor() {
  1138. return Math.floor(this);
  1139. }
  1140. return {
  1141. toColorPart: toColorPart,
  1142. succ: succ,
  1143. times: times,
  1144. toPaddedString: toPaddedString,
  1145. abs: abs,
  1146. round: round,
  1147. ceil: ceil,
  1148. floor: floor
  1149. };
  1150. })());
  1151. function $R(start, end, exclusive) {
  1152. return new ObjectRange(start, end, exclusive);
  1153. }
  1154. var ObjectRange = Class.create(Enumerable, (function() {
  1155. function initialize(start, end, exclusive) {
  1156. this.start = start;
  1157. this.end = end;
  1158. this.exclusive = exclusive;
  1159. }
  1160. function _each(iterator) {
  1161. var value = this.start;
  1162. while (this.include(value)) {
  1163. iterator(value);
  1164. value = value.succ();
  1165. }
  1166. }
  1167. function include(value) {
  1168. if (value < this.start)
  1169. return false;
  1170. if (this.exclusive)
  1171. return value < this.end;
  1172. return value <= this.end;
  1173. }
  1174. return {
  1175. initialize: initialize,
  1176. _each: _each,
  1177. include: include
  1178. };
  1179. })());
  1180. var Ajax = {
  1181. getTransport: function() {
  1182. return Try.these(
  1183. function() {return new XMLHttpRequest()},
  1184. function() {return new ActiveXObject('Msxml2.XMLHTTP')},
  1185. function() {return new ActiveXObject('Microsoft.XMLHTTP')}
  1186. ) || false;
  1187. },
  1188. activeRequestCount: 0
  1189. };
  1190. Ajax.Responders = {
  1191. responders: [],
  1192. _each: function(iterator) {
  1193. this.responders._each(iterator);
  1194. },
  1195. register: function(responder) {
  1196. if (!this.include(responder))
  1197. this.responders.push(responder);
  1198. },
  1199. unregister: function(responder) {
  1200. this.responders = this.responders.without(responder);
  1201. },
  1202. dispatch: function(callback, request, transport, json) {
  1203. this.each(function(responder) {
  1204. if (Object.isFunction(responder[callback])) {
  1205. try {
  1206. responder[callback].apply(responder, [request, transport, json]);
  1207. } catch (e) { }
  1208. }
  1209. });
  1210. }
  1211. };
  1212. Object.extend(Ajax.Responders, Enumerable);
  1213. Ajax.Responders.register({
  1214. onCreate: function() { Ajax.activeRequestCount++ },
  1215. onComplete: function() { Ajax.activeRequestCount-- }
  1216. });
  1217. Ajax.Base = Class.create({
  1218. initialize: function(options) {
  1219. this.options = {
  1220. method: 'post',
  1221. asynchronous: true,
  1222. contentType: 'application/x-www-form-urlencoded',
  1223. encoding: 'UTF-8',
  1224. parameters: '',
  1225. evalJSON: true,
  1226. evalJS: true
  1227. };
  1228. Object.extend(this.options, options || { });
  1229. this.options.method = this.options.method.toLowerCase();
  1230. if (Object.isHash(this.options.parameters))
  1231. this.options.parameters = this.options.parameters.toObject();
  1232. }
  1233. });
  1234. Ajax.Request = Class.create(Ajax.Base, {
  1235. _complete: false,
  1236. initialize: function($super, url, options) {
  1237. $super(options);
  1238. this.transport = Ajax.getTransport();
  1239. this.request(url);
  1240. },
  1241. request: function(url) {
  1242. this.url = url;
  1243. this.method = this.options.method;
  1244. var params = Object.isString(this.options.parameters) ?
  1245. this.options.parameters :
  1246. Object.toQueryString(this.options.parameters);
  1247. if (!['get', 'post'].include(this.method)) {
  1248. params += (params ? '&' : '') + "_method=" + this.method;
  1249. this.method = 'post';
  1250. }
  1251. if (params && this.method === 'get') {
  1252. this.url += (this.url.include('?') ? '&' : '?') + params;
  1253. }
  1254. this.parameters = params.toQueryParams();
  1255. try {
  1256. var response = new Ajax.Response(this);
  1257. if (this.options.onCreate) this.options.onCreate(response);
  1258. Ajax.Responders.dispatch('onCreate', this, response);
  1259. this.transport.open(this.method.toUpperCase(), this.url,
  1260. this.options.asynchronous);
  1261. if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);
  1262. this.transport.onreadystatechange = this.onStateChange.bind(this);
  1263. this.setRequestHeaders();
  1264. this.body = this.method == 'post' ? (this.options.postBody || params) : null;
  1265. this.transport.send(this.body);
  1266. /* Force Firefox to handle ready state 4 for synchronous requests */
  1267. if (!this.options.asynchronous && this.transport.overrideMimeType)
  1268. this.onStateChange();
  1269. }
  1270. catch (e) {
  1271. this.dispatchException(e);
  1272. }
  1273. },
  1274. onStateChange: function() {
  1275. var readyState = this.transport.readyState;
  1276. if (readyState > 1 && !((readyState == 4) && this._complete))
  1277. this.respondToReadyState(this.transport.readyState);
  1278. },
  1279. setRequestHeaders: function() {
  1280. var headers = {
  1281. 'X-Requested-With': 'XMLHttpRequest',
  1282. 'X-Prototype-Version': Prototype.Version,
  1283. 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
  1284. };
  1285. if (this.method == 'post') {
  1286. headers['Content-type'] = this.options.contentType +
  1287. (this.options.encoding ? '; charset=' + this.options.encoding : '');
  1288. /* Force "Connection: close" for older Mozilla browsers to work
  1289. * around a bug where XMLHttpRequest sends an incorrect
  1290. * Content-length header. See Mozilla Bugzilla #246651.
  1291. */
  1292. if (this.transport.overrideMimeType &&
  1293. (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
  1294. headers['Connection'] = 'close';
  1295. }
  1296. if (typeof this.options.requestHeaders == 'object') {
  1297. var extras = this.options.requestHeaders;
  1298. if (Object.isFunction(extras.push))
  1299. for (var i = 0, length = extras.length; i < length; i += 2)
  1300. headers[extras[i]] = extras[i+1];
  1301. else
  1302. $H(extras).each(function(pair) { headers[pair.key] = pair.value });
  1303. }
  1304. for (var name in headers)
  1305. this.transport.setRequestHeader(name, headers[name]);
  1306. },
  1307. success: function() {
  1308. var status = this.getStatus();
  1309. return !status || (status >= 200 && status < 300) || status == 304;
  1310. },
  1311. getStatus: function() {
  1312. try {
  1313. if (this.transport.status === 1223) return 204;
  1314. return this.transport.status || 0;
  1315. } catch (e) { return 0 }
  1316. },
  1317. respondToReadyState: function(readyState) {
  1318. var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
  1319. if (state == 'Complete') {
  1320. try {
  1321. this._complete = true;
  1322. (this.options['on' + response.status]
  1323. || this.options['on' + (this.success() ? 'Success' : 'Failure')]
  1324. || Prototype.emptyFunction)(response, response.headerJSON);
  1325. } catch (e) {
  1326. this.dispatchException(e);
  1327. }
  1328. var contentType = response.getHeader('Content-type');
  1329. if (this.options.evalJS == 'force'
  1330. || (this.options.evalJS && this.isSameOrigin() && contentType
  1331. && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
  1332. this.evalResponse();
  1333. }
  1334. try {
  1335. (this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON);
  1336. Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON);
  1337. } catch (e) {
  1338. this.dispatchException(e);
  1339. }
  1340. if (state == 'Complete') {
  1341. this.transport.onreadystatechange = Prototype.emptyFunction;
  1342. }
  1343. },
  1344. isSameOrigin: function() {
  1345. var m = this.url.match(/^\s*https?:\/\/[^\/]*/);
  1346. return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({
  1347. protocol: location.protocol,
  1348. domain: document.domain,
  1349. port: location.port ? ':' + location.port : ''
  1350. }));
  1351. },
  1352. getHeader: function(name) {
  1353. try {
  1354. return this.transport.getResponseHeader(name) || null;
  1355. } catch (e) { return null; }
  1356. },
  1357. evalResponse: function() {
  1358. try {
  1359. return eval((this.transport.responseText || '').unfilterJSON());
  1360. } catch (e) {
  1361. this.dispatchException(e);
  1362. }
  1363. },
  1364. dispatchException: function(exception) {
  1365. (this.options.onException || Prototype.emptyFunction)(this, exception);
  1366. Ajax.Responders.dispatch('onException', this, exception);
  1367. }
  1368. });
  1369. Ajax.Request.Events =
  1370. ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
  1371. Ajax.Response = Class.create({
  1372. initialize: function(request){
  1373. this.request = request;
  1374. var transport = this.transport = request.transport,
  1375. readyState = this.readyState = transport.readyState;
  1376. if ((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) {
  1377. this.status = this.getStatus();
  1378. this.statusText = this.getStatusText();
  1379. this.responseText = String.interpret(transport.responseText);
  1380. this.headerJSON = this._getHeaderJSON();
  1381. }
  1382. if (readyState == 4) {
  1383. var xml = transport.responseXML;
  1384. this.responseXML = Object.isUndefined(xml) ? null : xml;
  1385. this.responseJSON = this._getResponseJSON();
  1386. }
  1387. },
  1388. status: 0,
  1389. statusText: '',
  1390. getStatus: Ajax.Request.prototype.getStatus,
  1391. getStatusText: function() {
  1392. try {
  1393. return this.transport.statusText || '';
  1394. } catch (e) { return '' }
  1395. },
  1396. getHeader: Ajax.Request.prototype.getHeader,
  1397. getAllHeaders: function() {
  1398. try {
  1399. return this.getAllResponseHeaders();
  1400. } catch (e) { return null }
  1401. },
  1402. getResponseHeader: function(name) {
  1403. return this.transport.getResponseHeader(name);
  1404. },
  1405. getAllResponseHeaders: function() {
  1406. return this.transport.getAllResponseHeaders();
  1407. },
  1408. _getHeaderJSON: function() {
  1409. var json = this.getHeader('X-JSON');
  1410. if (!json) return null;
  1411. json = decodeURIComponent(escape(json));
  1412. try {
  1413. return json.evalJSON(this.request.options.sanitizeJSON ||
  1414. !this.request.isSameOrigin());
  1415. } catch (e) {
  1416. this.request.dispatchException(e);
  1417. }
  1418. },
  1419. _getResponseJSON: function() {
  1420. var options = this.request.options;
  1421. if (!options.evalJSON || (options.evalJSON != 'force' &&
  1422. !(this.getHeader('Content-type') || '').include('application/json')) ||
  1423. this.responseText.blank())
  1424. return null;
  1425. try {
  1426. return this.responseText.evalJSON(options.sanitizeJSON ||
  1427. !this.request.isSameOrigin());
  1428. } catch (e) {
  1429. this.request.dispatchException(e);
  1430. }
  1431. }
  1432. });
  1433. Ajax.Updater = Class.create(Ajax.Request, {
  1434. initialize: function($super, container, url, options) {
  1435. this.container = {
  1436. success: (container.success || container),
  1437. failure: (container.failure || (container.success ? null : container))
  1438. };
  1439. options = Object.clone(options);
  1440. var onComplete = options.onComplete;
  1441. options.onComplete = (function(response, json) {
  1442. this.updateContent(response.responseText);
  1443. if (Object.isFunction(onComplete)) onComplete(response, json);
  1444. }).bind(this);
  1445. $super(url, options);
  1446. },
  1447. updateContent: function(responseText) {
  1448. var receiver = this.container[this.success() ? 'success' : 'failure'],
  1449. options = this.options;
  1450. if (!options.evalScripts) responseText = responseText.stripScripts();
  1451. if (receiver = $(receiver)) {
  1452. if (options.insertion) {
  1453. if (Object.isString(options.insertion)) {
  1454. var insertion = { }; insertion[options.insertion] = responseText;
  1455. receiver.insert(insertion);
  1456. }
  1457. else options.insertion(receiver, responseText);
  1458. }
  1459. else receiver.update(responseText);
  1460. }
  1461. }
  1462. });
  1463. Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {
  1464. initialize: function($super, container, url, options) {
  1465. $super(options);
  1466. this.onComplete = this.options.onComplete;
  1467. this.frequency = (this.options.frequency || 2);
  1468. this.decay = (this.options.decay || 1);
  1469. this.updater = { };
  1470. this.container = container;
  1471. this.url = url;
  1472. this.start();
  1473. },
  1474. start: function() {
  1475. this.options.onComplete = this.updateComplete.bind(this);
  1476. this.onTimerEvent();
  1477. },
  1478. stop: function() {
  1479. this.updater.options.onComplete = undefined;
  1480. clearTimeout(this.timer);
  1481. (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
  1482. },
  1483. updateComplete: function(response) {
  1484. if (this.options.decay) {
  1485. this.decay = (response.responseText == this.lastText ?
  1486. this.decay * this.options.decay : 1);
  1487. this.lastText = response.responseText;
  1488. }
  1489. this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
  1490. },
  1491. onTimerEvent: function() {
  1492. this.updater = new Ajax.Updater(this.container, this.url, this.options);
  1493. }
  1494. });
  1495. function $(element) {
  1496. if (arguments.length > 1) {
  1497. for (var i = 0, elements = [], length = arguments.length; i < length; i++)
  1498. elements.push($(arguments[i]));
  1499. return elements;
  1500. }
  1501. if (Object.isString(element))
  1502. element = document.getElementById(element);
  1503. return Element.extend(element);
  1504. }
  1505. if (Prototype.BrowserFeatures.XPath) {
  1506. document._getElementsByXPath = function(expression, parentElement) {
  1507. var results = [];
  1508. var query = document.evaluate(expression, $(parentElement) || document,
  1509. null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  1510. for (var i = 0, length = query.snapshotLength; i < length; i++)
  1511. results.push(Element.extend(query.snapshotItem(i)));
  1512. return results;
  1513. };
  1514. }
  1515. /*--------------------------------------------------------------------------*/
  1516. if (!Node) var Node = { };
  1517. if (!Node.ELEMENT_NODE) {
  1518. Object.extend(Node, {
  1519. ELEMENT_NODE: 1,
  1520. ATTRIBUTE_NODE: 2,
  1521. TEXT_NODE: 3,
  1522. CDATA_SECTION_NODE: 4,
  1523. ENTITY_REFERENCE_NODE: 5,
  1524. ENTITY_NODE: 6,
  1525. PROCESSING_INSTRUCTION_NODE: 7,
  1526. COMMENT_NODE: 8,
  1527. DOCUMENT_NODE: 9,
  1528. DOCUMENT_TYPE_NODE: 10,
  1529. DOCUMENT_FRAGMENT_NODE: 11,
  1530. NOTATION_NODE: 12
  1531. });
  1532. }
  1533. (function(global) {
  1534. function shouldUseCache(tagName, attributes) {
  1535. if (tagName === 'select') return false;
  1536. if ('type' in attributes) return false;
  1537. return true;
  1538. }
  1539. var HAS_EXTENDED_CREATE_ELEMENT_SYNTAX = (function(){
  1540. try {
  1541. var el = document.createElement('<input name="x">');
  1542. return el.tagName.toLowerCase() === 'input' && el.name === 'x';
  1543. }
  1544. catch(err) {
  1545. return false;
  1546. }
  1547. })();
  1548. var element = global.Element;
  1549. global.Element = function(tagName, attributes) {
  1550. attributes = attributes || { };
  1551. tagName = tagName.toLowerCase();
  1552. var cache = Element.cache;
  1553. if (HAS_EXTENDED_CREATE_ELEMENT_SYNTAX && attributes.name) {
  1554. tagName = '<' + tagName + ' name="' + attributes.name + '">';
  1555. delete attributes.name;
  1556. return Element.writeAttribute(document.createElement(tagName), attributes);
  1557. }
  1558. if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
  1559. var node = shouldUseCache(tagName, attributes) ?
  1560. cache[tagName].cloneNode(false) : document.createElement(tagName);
  1561. return Element.writeAttribute(node, attributes);
  1562. };
  1563. Object.extend(global.Element, element || { });
  1564. if (element) global.Element.prototype = element.prototype;
  1565. })(this);
  1566. Element.idCounter = 1;
  1567. Element.cache = { };
  1568. Element._purgeElement = function(element) {
  1569. var uid = element._prototypeUID;
  1570. if (uid) {
  1571. Element.stopObserving(element);
  1572. element._prototypeUID = void 0;
  1573. delete Element.Storage[uid];
  1574. }
  1575. }
  1576. Element.Methods = {
  1577. visible: function(element) {
  1578. return $(element).style.display != 'none';
  1579. },
  1580. toggle: function(element) {
  1581. element = $(element);
  1582. Element[Element.visible(element) ? 'hide' : 'show'](element);
  1583. return element;
  1584. },
  1585. hide: function(element) {
  1586. element = $(element);
  1587. element.style.display = 'none';
  1588. return element;
  1589. },
  1590. show: function(element) {
  1591. element = $(element);
  1592. element.style.display = '';
  1593. return element;
  1594. },
  1595. remove: function(element) {
  1596. element = $(element);
  1597. element.parentNode.removeChild(element);
  1598. return element;
  1599. },
  1600. update: (function(){
  1601. var SELECT_ELEMENT_INNERHTML_BUGGY = (function(){
  1602. var el = document.createElement("select"),
  1603. isBuggy = true;
  1604. el.innerHTML = "<option value=\"test\">test</option>";
  1605. if (el.options && el.options[0]) {
  1606. isBuggy = el.options[0].nodeName.toUpperCase() !== "OPTION";
  1607. }
  1608. el = null;
  1609. return isBuggy;
  1610. })();
  1611. var TABLE_ELEMENT_INNERHTML_BUGGY = (function(){
  1612. try {
  1613. var el = document.createElement("table");
  1614. if (el && el.tBodies) {
  1615. el.innerHTML = "<tbody><tr><td>test</td></tr></tbody>";
  1616. var isBuggy = typeof el.tBodies[0] == "undefined";
  1617. el = null;
  1618. return isBuggy;
  1619. }
  1620. } catch (e) {
  1621. return true;
  1622. }
  1623. })();
  1624. var LINK_ELEMENT_INNERHTML_BUGGY = (function() {
  1625. try {
  1626. var el = document.createElement('div');
  1627. el.innerHTML = "<link>";
  1628. var isBuggy = (el.childNodes.length === 0);
  1629. el = null;
  1630. return isBuggy;
  1631. } catch(e) {
  1632. return true;
  1633. }
  1634. })();
  1635. var ANY_INNERHTML_BUGGY = SELECT_ELEMENT_INNERHTML_BUGGY ||
  1636. TABLE_ELEMENT_INNERHTML_BUGGY || LINK_ELEMENT_INNERHTML_BUGGY;
  1637. var SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING = (function () {
  1638. var s = document.createElement("script"),
  1639. isBuggy = false;
  1640. try {
  1641. s.appendChild(document.createTextNode(""));
  1642. isBuggy = !s.firstChild ||
  1643. s.firstChild && s.firstChild.nodeType !== 3;
  1644. } catch (e) {
  1645. isBuggy = true;
  1646. }
  1647. s = null;
  1648. return isBuggy;
  1649. })();
  1650. function update(element, content) {
  1651. element = $(element);
  1652. var purgeElement = Element._purgeElement;
  1653. var descendants = element.getElementsByTagName('*'),
  1654. i = descendants.length;
  1655. while (i--) purgeElement(descendants[i]);
  1656. if (content && content.toElement)
  1657. content = content.toElement();
  1658. if (Object.isElement(content))
  1659. return element.update().insert(content);
  1660. content = Object.toHTML(content);
  1661. var tagName = element.tagName.toUpperCase();
  1662. if (tagName === 'SCRIPT' && SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING) {
  1663. element.text = content;
  1664. return element;
  1665. }
  1666. if (ANY_INNERHTML_BUGGY) {
  1667. if (tagName in Element._insertionTranslations.tags) {
  1668. while (element.firstChild) {
  1669. element.removeChild(element.firstChild);
  1670. }
  1671. Element._getContentFromAnonymousElement(tagName, content.stripScripts())
  1672. .each(function(node) {
  1673. element.appendChild(node)
  1674. });
  1675. } else if (LINK_ELEMENT_INNERHTML_BUGGY && Object.isString(content) && content.indexOf('<link') > -1) {
  1676. while (element.firstChild) {
  1677. element.removeChild(element.firstChild);
  1678. }
  1679. var nodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts(), true);
  1680. nodes.each(function(node) { element.appendChild(node) });
  1681. }
  1682. else {
  1683. element.innerHTML = content.stripScripts();
  1684. }
  1685. }
  1686. else {
  1687. element.innerHTML = content.stripScripts();
  1688. }
  1689. content.evalScripts.bind(content).defer();
  1690. return element;
  1691. }
  1692. return update;
  1693. })(),
  1694. replace: function(element, content) {
  1695. element = $(element);
  1696. if (content && content.toElement) content = content.toElement();
  1697. else if (!Object.isElement(content)) {
  1698. content = Object.toHTML(content);
  1699. var range = element.ownerDocument.createRange();
  1700. range.selectNode(element);
  1701. content.evalScripts.bind(content).defer();
  1702. content = range.createContextualFragment(content.stripScripts());
  1703. }
  1704. element.parentNode.replaceChild(content, element);
  1705. return element;
  1706. },
  1707. insert: function(element, insertions) {
  1708. element = $(element);
  1709. if (Object.isString(insertions) || Object.isNumber(insertions) ||
  1710. Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
  1711. insertions = {bottom:insertions};
  1712. var content, insert, tagName, childNodes;
  1713. for (var position in insertions) {
  1714. content = insertions[position];
  1715. position = position.toLowerCase();
  1716. insert = Element._insertionTranslations[position];
  1717. if (content && content.toElement) content = content.toElement();
  1718. if (Object.isElement(content)) {
  1719. insert(element, content);
  1720. continue;
  1721. }
  1722. content = Object.toHTML(content);
  1723. tagName = ((position == 'before' || position == 'after')
  1724. ? element.parentNode : element).tagName.toUpperCase();
  1725. childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
  1726. if (position == 'top' || position == 'after') childNodes.reverse();
  1727. childNodes.each(insert.curry(element));
  1728. content.evalScripts.bind(content).defer();
  1729. }
  1730. return element;
  1731. },
  1732. wrap: function(element, wrapper, attributes) {
  1733. element = $(element);
  1734. if (Object.isElement(wrapper))
  1735. $(wrapper).writeAttribute(attributes || { });
  1736. else if (Object.isString(wrapper)) wrapper = new Element(wrapper, attributes);
  1737. else wrapper = new Element('div', wrapper);
  1738. if (element.parentNode)
  1739. element.parentNode.replaceChild(wrapper, element);
  1740. wrapper.appendChild(element);
  1741. return wrapper;
  1742. },
  1743. inspect: function(element) {
  1744. element = $(element);
  1745. var result = '<' + element.tagName.toLowerCase();
  1746. $H({'id': 'id', 'className': 'class'}).each(function(pair) {
  1747. var property = pair.first(),
  1748. attribute = pair.last(),
  1749. value = (element[property] || '').toString();
  1750. if (value) result += ' ' + attribute + '=' + value.inspect(true);
  1751. });
  1752. return result + '>';
  1753. },
  1754. recursivelyCollect: function(element, property, maximumLength) {
  1755. element = $(element);
  1756. maximumLength = maximumLength || -1;
  1757. var elements = [];
  1758. while (element = element[property]) {
  1759. if (element.nodeType == 1)
  1760. elements.push(Element.extend(element));
  1761. if (elements.length == maximumLength)
  1762. break;
  1763. }
  1764. return elements;
  1765. },
  1766. ancestors: function(element) {
  1767. return Element.recursivelyCollect(element, 'parentNode');
  1768. },
  1769. descendants: function(element) {
  1770. return Element.select(element, "*");
  1771. },
  1772. firstDescendant: function(element) {
  1773. element = $(element).firstChild;
  1774. while (element && element.nodeType != 1) element = element.nextSibling;
  1775. return $(element);
  1776. },
  1777. immediateDescendants: function(element) {
  1778. var results = [], child = $(element).firstChild;
  1779. while (child) {
  1780. if (child.nodeType === 1) {
  1781. results.push(Element.extend(child));
  1782. }
  1783. child = child.nextSibling;
  1784. }
  1785. return results;
  1786. },
  1787. previousSiblings: function(element, maximumLength) {
  1788. return Element.recursivelyCollect(element, 'previousSibling');
  1789. },
  1790. nextSiblings: function(element) {
  1791. return Element.recursivelyCollect(element, 'nextSibling');
  1792. },
  1793. siblings: function(element) {
  1794. element = $(element);
  1795. return Element.previousSiblings(element).reverse()
  1796. .concat(Element.nextSiblings(element));
  1797. },
  1798. match: function(element, selector) {
  1799. element = $(element);
  1800. if (Object.isString(selector))
  1801. return Prototype.Selector.match(element, selector);
  1802. return selector.match(element);
  1803. },
  1804. up: function(element, expression, index) {
  1805. element = $(element);
  1806. if (arguments.length == 1) return $(element.parentNode);
  1807. var ancestors = Element.ancestors(element);
  1808. return Object.isNumber(expression) ? ancestors[expression] :
  1809. Prototype.Selector.find(ancestors, expression, index);
  1810. },
  1811. down: function(element, expression, index) {
  1812. element = $(element);
  1813. if (arguments.length == 1) return Element.firstDescendant(element);
  1814. return Object.isNumber(expression) ? Element.descendants(element)[expression] :
  1815. Element.select(element, expression)[index || 0];
  1816. },
  1817. previous: function(element, expression, index) {
  1818. element = $(element);
  1819. if (Object.isNumber(expression)) index = expression, expression = false;
  1820. if (!Object.isNumber(index)) index = 0;
  1821. if (expression) {
  1822. return Prototype.Selector.find(element.previousSiblings(), expression, index);
  1823. } else {
  1824. return element.recursivelyCollect("previousSibling", index + 1)[index];
  1825. }
  1826. },
  1827. next: function(element, expression, index) {
  1828. element = $(element);
  1829. if (Object.isNumber(expression)) index = expression, expression = false;
  1830. if (!Object.isNumber(index)) index = 0;
  1831. if (expression) {
  1832. return Prototype.Selector.find(element.nextSiblings(), expression, index);
  1833. } else {
  1834. var maximumLength = Object.isNumber(index) ? index + 1 : 1;
  1835. return element.recursivelyCollect("nextSibling", index + 1)[index];
  1836. }
  1837. },
  1838. select: function(element) {
  1839. element = $(element);
  1840. var expressions = Array.prototype.slice.call(arguments, 1).join(', ');
  1841. return Prototype.Selector.select(expressions, element);
  1842. },
  1843. adjacent: function(element) {
  1844. element = $(element);
  1845. var expressions = Array.prototype.slice.call(arguments, 1).join(', ');
  1846. return Prototype.Selector.select(expressions, element.parentNode).without(element);
  1847. },
  1848. identify: function(element) {
  1849. element = $(element);
  1850. var id = Element.readAttribute(element, 'id');
  1851. if (id) return id;
  1852. do { id = 'anonymous_element_' + Element.idCounter++ } while ($(id));
  1853. Element.writeAttribute(element, 'id', id);
  1854. return id;
  1855. },
  1856. readAttribute: function(element, name) {
  1857. element = $(element);
  1858. if (Prototype.Browser.IE) {
  1859. var t = Element._attributeTranslations.read;
  1860. if (t.values[name]) return t.values[name](element, name);
  1861. if (t.names[name]) name = t.names[name];
  1862. if (name.include(':')) {
  1863. return (!element.attributes || !element.attributes[name]) ? null :
  1864. element.attributes[name].value;
  1865. }
  1866. }
  1867. return element.getAttribute(name);
  1868. },
  1869. writeAttribute: function(element, name, value) {
  1870. element = $(element);
  1871. var attributes = { }, t = Element._attributeTranslations.write;
  1872. if (typeof name == 'object') attributes = name;
  1873. else attributes[name] = Object.isUndefined(value) ? true : value;
  1874. for (var attr in attributes) {
  1875. name = t.names[attr] || attr;
  1876. value = attributes[attr];
  1877. if (t.values[attr]) name = t.values[attr](element, value);
  1878. if (value === false || value === null)
  1879. element.removeAttribute(name);
  1880. else if (value === true)
  1881. element.setAttribute(name, name);
  1882. else element.setAttribute(name, value);
  1883. }
  1884. return element;
  1885. },
  1886. getHeight: function(element) {
  1887. return Element.getDimensions(element).height;
  1888. },
  1889. getWidth: function(element) {
  1890. return Element.getDimensions(element).width;
  1891. },
  1892. classNames: function(element) {
  1893. return new Element.ClassNames(element);
  1894. },
  1895. hasClassName: function(element, className) {
  1896. if (!(element = $(element))) return;
  1897. var elementClassName = element.className;
  1898. return (elementClassName.length > 0 && (elementClassName == className ||
  1899. new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
  1900. },
  1901. addClassName: function(element, className) {
  1902. if (!(element = $(element))) return;
  1903. if (!Element.hasClassName(element, className))
  1904. element.className += (element.className ? ' ' : '') + className;
  1905. return element;
  1906. },
  1907. removeClassName: function(element, className) {
  1908. if (!(element = $(element))) return;
  1909. element.className = element.className.replace(
  1910. new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip();
  1911. return element;
  1912. },
  1913. toggleClassName: function(element, className) {
  1914. if (!(element = $(element))) return;
  1915. return Element[Element.hasClassName(element, className) ?
  1916. 'removeClassName' : 'addClassName'](element, className);
  1917. },
  1918. cleanWhitespace: function(element) {
  1919. element = $(element);
  1920. var node = element.firstChild;
  1921. while (node) {
  1922. var nextNode = node.nextSibling;
  1923. if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
  1924. element.removeChild(node);
  1925. node = nextNode;
  1926. }
  1927. return element;
  1928. },
  1929. empty: function(element) {
  1930. return $(element).innerHTML.blank();
  1931. },
  1932. descendantOf: function(element, ancestor) {
  1933. element = $(element), ancestor = $(ancestor);
  1934. if (element.compareDocumentPosition)
  1935. return (element.compareDocumentPosition(ancestor) & 8) === 8;
  1936. if (ancestor.contains)
  1937. return ancestor.contains(element) && ancestor !== element;
  1938. while (element = element.parentNode)
  1939. if (element == ancestor) return true;
  1940. return false;
  1941. },
  1942. scrollTo: function(element) {
  1943. element = $(element);
  1944. var pos = Element.cumulativeOffset(element);
  1945. window.scrollTo(pos[0], pos[1]);
  1946. return element;
  1947. },
  1948. getStyle: function(element, style) {
  1949. element = $(element);
  1950. style = style == 'float' ? 'cssFloat' : style.camelize();
  1951. var value = element.style[style];
  1952. if (!value || value == 'auto') {
  1953. var css = document.defaultView.getComputedStyle(element, null);
  1954. value = css ? css[style] : null;
  1955. }
  1956. if (style == 'opacity') return value ? parseFloat(value) : 1.0;
  1957. return value == 'auto' ? null : value;
  1958. },
  1959. getOpacity: function(element) {
  1960. return $(element).getStyle('opacity');
  1961. },
  1962. setStyle: function(element, styles) {
  1963. element = $(element);
  1964. var elementStyle = element.style, match;
  1965. if (Object.isString(styles)) {
  1966. element.style.cssText += ';' + styles;
  1967. return styles.include('opacity') ?
  1968. element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;
  1969. }
  1970. for (var property in styles)
  1971. if (property == 'opacity') element.setOpacity(styles[property]);
  1972. else
  1973. elementStyle[(property == 'float' || property == 'cssFloat') ?
  1974. (Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
  1975. property] = styles[property];
  1976. return element;
  1977. },
  1978. setOpacity: function(element, value) {
  1979. element = $(element);
  1980. element.style.opacity = (value == 1 || value === '') ? '' :
  1981. (value < 0.00001) ? 0 : value;
  1982. return element;
  1983. },
  1984. makePositioned: function(element) {
  1985. element = $(element);
  1986. var pos = Element.getStyle(element, 'position');
  1987. if (pos == 'static' || !pos) {
  1988. element._madePositioned = true;
  1989. element.style.position = 'relative';
  1990. if (Prototype.Browser.Opera) {
  1991. element.style.top = 0;
  1992. element.style.left = 0;
  1993. }
  1994. }
  1995. return element;
  1996. },
  1997. undoPositioned: function(element) {
  1998. element = $(element);
  1999. if (element._madePositioned) {
  2000. element._madePositioned = undefined;
  2001. element.style.position =
  2002. element.style.top =
  2003. element.style.left =
  2004. element.style.bottom =
  2005. element.style.right = '';
  2006. }
  2007. return element;
  2008. },
  2009. makeClipping: function(element) {
  2010. element = $(element);
  2011. if (element._overflow) return element;
  2012. element._overflow = Element.getStyle(element, 'overflow') || 'auto';
  2013. if (element._overflow !== 'hidden')
  2014. element.style.overflow = 'hidden';
  2015. return element;
  2016. },
  2017. undoClipping: function(element) {
  2018. element = $(element);
  2019. if (!element._overflow) return element;
  2020. element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
  2021. element._overflow = null;
  2022. return element;
  2023. },
  2024. clonePosition: function(element, source) {
  2025. var options = Object.extend({
  2026. setLeft: true,
  2027. setTop: true,
  2028. setWidth: true,
  2029. setHeight: true,
  2030. offsetTop: 0,
  2031. offsetLeft: 0
  2032. }, arguments[2] || { });
  2033. source = $(source);
  2034. var p = Element.viewportOffset(source), delta = [0, 0], parent = null;
  2035. element = $(element);
  2036. if (Element.getStyle(element, 'position') == 'absolute') {
  2037. parent = Element.getOffsetParent(element);
  2038. delta = Element.viewportOffset(parent);
  2039. }
  2040. if (parent == document.body) {
  2041. delta[0] -= document.body.offsetLeft;
  2042. delta[1] -= document.body.offsetTop;
  2043. }
  2044. if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px';
  2045. if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px';
  2046. if (options.setWidth) element.style.width = source.offsetWidth + 'px';
  2047. if (options.setHeight) element.style.height = source.offsetHeight + 'px';
  2048. return element;
  2049. }
  2050. };
  2051. Object.extend(Element.Methods, {
  2052. getElementsBySelector: Element.Methods.select,
  2053. childElements: Element.Methods.immediateDescendants
  2054. });
  2055. Element._attributeTranslations = {
  2056. write: {
  2057. names: {
  2058. className: 'class',
  2059. htmlFor: 'for'
  2060. },
  2061. values: { }
  2062. }
  2063. };
  2064. if (Prototype.Browser.Opera) {
  2065. Element.Methods.getStyle = Element.Methods.getStyle.wrap(
  2066. function(proceed, element, style) {
  2067. switch (style) {
  2068. case 'height': case 'width':
  2069. if (!Element.visible(element)) return null;
  2070. var dim = parseInt(proceed(element, style), 10);
  2071. if (dim !== element['offset' + style.capitalize()])
  2072. return dim + 'px';
  2073. var properties;
  2074. if (style === 'height') {
  2075. properties = ['border-top-width', 'padding-top',
  2076. 'padding-bottom', 'border-bottom-width'];
  2077. }
  2078. else {
  2079. properties = ['border-left-width', 'padding-left',
  2080. 'padding-right', 'border-right-width'];
  2081. }
  2082. return properties.inject(dim, function(memo, property) {
  2083. var val = proceed(element, property);
  2084. return val === null ? memo : memo - parseInt(val, 10);
  2085. }) + 'px';
  2086. default: return proceed(element, style);
  2087. }
  2088. }
  2089. );
  2090. Element.Methods.readAttribute = Element.Methods.readAttribute.wrap(
  2091. function(proceed, element, attribute) {
  2092. if (attribute === 'title') return element.title;
  2093. return proceed(element, attribute);
  2094. }
  2095. );
  2096. }
  2097. else if (Prototype.Browser.IE) {
  2098. Element.Methods.getStyle = function(element, style) {
  2099. element = $(element);
  2100. style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
  2101. var value = element.style[style];
  2102. if (!value && element.currentStyle) value = element.currentStyle[style];
  2103. if (style == 'opacity') {
  2104. if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
  2105. if (value[1]) return parseFloat(value[1]) / 100;
  2106. return 1.0;
  2107. }
  2108. if (value == 'auto') {
  2109. if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
  2110. return element['offset' + style.capitalize()] + 'px';
  2111. return null;
  2112. }
  2113. return value;
  2114. };
  2115. Element.Methods.setOpacity = function(element, value) {
  2116. function stripAlpha(filter){
  2117. return filter.replace(/alpha\([^\)]*\)/gi,'');
  2118. }
  2119. element = $(element);
  2120. var currentStyle = element.currentStyle;
  2121. if ((currentStyle && !currentStyle.hasLayout) ||
  2122. (!currentStyle && element.style.zoom == 'normal'))
  2123. element.style.zoom = 1;
  2124. var filter = element.getStyle('filter'), style = element.style;
  2125. if (value == 1 || value === '') {
  2126. (filter = stripAlpha(filter)) ?
  2127. style.filter = filter : style.removeAttribute('filter');
  2128. return element;
  2129. } else if (value < 0.00001) value = 0;
  2130. style.filter = stripAlpha(filter) +
  2131. 'alpha(opacity=' + (value * 100) + ')';
  2132. return element;
  2133. };
  2134. Element._attributeTranslations = (function(){
  2135. var classProp = 'className',
  2136. forProp = 'for',
  2137. el = document.createElement('div');
  2138. el.setAttribute(classProp, 'x');
  2139. if (el.className !== 'x') {
  2140. el.setAttribute('class', 'x');
  2141. if (el.className === 'x') {
  2142. classProp = 'class';
  2143. }
  2144. }
  2145. el = null;
  2146. el = document.createElement('label');
  2147. el.setAttribute(forProp, 'x');
  2148. if (el.htmlFor !== 'x') {
  2149. el.setAttribute('htmlFor', 'x');
  2150. if (el.htmlFor === 'x') {
  2151. forProp = 'htmlFor';
  2152. }
  2153. }
  2154. el = null;
  2155. return {
  2156. read: {
  2157. names: {
  2158. 'class': classProp,
  2159. 'className': classProp,
  2160. 'for': forProp,
  2161. 'htmlFor': forProp
  2162. },
  2163. values: {
  2164. _getAttr: function(element, attribute) {
  2165. return element.getAttribute(attribute);
  2166. },
  2167. _getAttr2: function(element, attribute) {
  2168. return element.getAttribute(attribute, 2);
  2169. },
  2170. _getAttrNode: function(element, attribute) {
  2171. var node = element.getAttributeNode(attribute);
  2172. return node ? node.value : "";
  2173. },
  2174. _getEv: (function(){
  2175. var el = document.createElement('div'), f;
  2176. el.onclick = Prototype.emptyFunction;
  2177. var value = el.getAttribute('onclick');
  2178. if (String(value).indexOf('{') > -1) {
  2179. f = function(element, attribute) {
  2180. attribute = element.getAttribute(attribute);
  2181. if (!attribute) return null;
  2182. attribute = attribute.toString();
  2183. attribute = attribute.split('{')[1];
  2184. attribute = attribute.split('}')[0];
  2185. return attribute.strip();
  2186. };
  2187. }
  2188. else if (value === '') {
  2189. f = function(element, attribute) {
  2190. attribute = element.getAttribute(attribute);
  2191. if (!attribute) return null;
  2192. return attribute.strip();
  2193. };
  2194. }
  2195. el = null;
  2196. return f;
  2197. })(),
  2198. _flag: function(element, attribute) {
  2199. return $(element).hasAttribute(attribute) ? attribute : null;
  2200. },
  2201. style: function(element) {
  2202. return element.style.cssText.toLowerCase();
  2203. },
  2204. title: function(element) {
  2205. return element.title;
  2206. }
  2207. }
  2208. }
  2209. }
  2210. })();
  2211. Element._attributeTranslations.write = {
  2212. names: Object.extend({
  2213. cellpadding: 'cellPadding',
  2214. cellspacing: 'cellSpacing'
  2215. }, Element._attributeTranslations.read.names),
  2216. values: {
  2217. checked: function(element, value) {
  2218. element.checked = !!value;
  2219. },
  2220. style: function(element, value) {
  2221. element.style.cssText = value ? value : '';
  2222. }
  2223. }
  2224. };
  2225. Element._attributeTranslations.has = {};
  2226. $w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' +
  2227. 'encType maxLength readOnly longDesc frameBorder').each(function(attr) {
  2228. Element._attributeTranslations.write.names[attr.toLowerCase()] = attr;
  2229. Element._attributeTranslations.has[attr.toLowerCase()] = attr;
  2230. });
  2231. (function(v) {
  2232. Object.extend(v, {
  2233. href: v._getAttr2,
  2234. src: v._getAttr2,
  2235. type: v._getAttr,
  2236. action: v._getAttrNode,
  2237. disabled: v._flag,
  2238. checked: v._flag,
  2239. readonly: v._flag,
  2240. multiple: v._flag,
  2241. onload: v._getEv,
  2242. onunload: v._getEv,
  2243. onclick: v._getEv,
  2244. ondblclick: v._getEv,
  2245. onmousedown: v._getEv,
  2246. onmouseup: v._getEv,
  2247. onmouseover: v._getEv,
  2248. onmousemove: v._getEv,
  2249. onmouseout: v._getEv,
  2250. onfocus: v._getEv,
  2251. onblur: v._getEv,
  2252. onkeypress: v._getEv,
  2253. onkeydown: v._getEv,
  2254. onkeyup: v._getEv,
  2255. onsubmit: v._getEv,
  2256. onreset: v._getEv,
  2257. onselect: v._getEv,
  2258. onchange: v._getEv
  2259. });
  2260. })(Element._attributeTranslations.read.values);
  2261. if (Prototype.BrowserFeatures.ElementExtensions) {
  2262. (function() {
  2263. function _descendants(element) {
  2264. var nodes = element.getElementsByTagName('*'), results = [];
  2265. for (var i = 0, node; node = nodes[i]; i++)
  2266. if (node.tagName !== "!") // Filter out comment nodes.
  2267. results.push(node);
  2268. return results;
  2269. }
  2270. Element.Methods.down = function(element, expression, index) {
  2271. element = $(element);
  2272. if (arguments.length == 1) return element.firstDescendant();
  2273. return Object.isNumber(expression) ? _descendants(element)[expression] :
  2274. Element.select(element, expression)[index || 0];
  2275. }
  2276. })();
  2277. }
  2278. }
  2279. else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) {
  2280. Element.Methods.setOpacity = function(element, value) {
  2281. element = $(element);
  2282. element.style.opacity = (value == 1) ? 0.999999 :
  2283. (value === '') ? '' : (value < 0.00001) ? 0 : value;
  2284. return element;
  2285. };
  2286. }
  2287. else if (Prototype.Browser.WebKit) {
  2288. Element.Methods.setOpacity = function(element, value) {
  2289. element = $(element);
  2290. element.style.opacity = (value == 1 || value === '') ? '' :
  2291. (value < 0.00001) ? 0 : value;
  2292. if (value == 1)
  2293. if (element.tagName.toUpperCase() == 'IMG' && element.width) {
  2294. element.width++; element.width--;
  2295. } else try {
  2296. var n = document.createTextNode(' ');
  2297. element.appendChild(n);
  2298. element.removeChild(n);
  2299. } catch (e) { }
  2300. return element;
  2301. };
  2302. }
  2303. if ('outerHTML' in document.documentElement) {
  2304. Element.Methods.replace = function(element, content) {
  2305. element = $(element);
  2306. if (content && content.toElement) content = content.toElement();
  2307. if (Object.isElement(content)) {
  2308. element.parentNode.replaceChild(content, element);
  2309. return element;
  2310. }
  2311. content = Object.toHTML(content);
  2312. var parent = element.parentNode, tagName = parent.tagName.toUpperCase();
  2313. if (Element._insertionTranslations.tags[tagName]) {
  2314. var nextSibling = element.next(),
  2315. fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
  2316. parent.removeChild(element);
  2317. if (nextSibling)
  2318. fragments.each(function(node) { parent.insertBefore(node, nextSibling) });
  2319. else
  2320. fragments.each(function(node) { parent.appendChild(node) });
  2321. }
  2322. else element.outerHTML = content.stripScripts();
  2323. content.evalScripts.bind(content).defer();
  2324. return element;
  2325. };
  2326. }
  2327. Element._returnOffset = function(l, t) {
  2328. var result = [l, t];
  2329. result.left = l;
  2330. result.top = t;
  2331. return result;
  2332. };
  2333. Element._getContentFromAnonymousElement = function(tagName, html, force) {
  2334. var div = new Element('div'),
  2335. t = Element._insertionTranslations.tags[tagName];
  2336. var workaround = false;
  2337. if (t) workaround = true;
  2338. else if (force) {
  2339. workaround = true;
  2340. t = ['', '', 0];
  2341. }
  2342. if (workaround) {
  2343. div.innerHTML = '&nbsp;' + t[0] + html + t[1];
  2344. div.removeChild(div.firstChild);
  2345. for (var i = t[2]; i--; ) {
  2346. div = div.firstChild;
  2347. }
  2348. }
  2349. else {
  2350. div.innerHTML = html;
  2351. }
  2352. return $A(div.childNodes);
  2353. };
  2354. Element._insertionTranslations = {
  2355. before: function(element, node) {
  2356. element.parentNode.insertBefore(node, element);
  2357. },
  2358. top: function(element, node) {
  2359. element.insertBefore(node, element.firstChild);
  2360. },
  2361. bottom: function(element, node) {
  2362. element.appendChild(node);
  2363. },
  2364. after: function(element, node) {
  2365. element.parentNode.insertBefore(node, element.nextSibling);
  2366. },
  2367. tags: {
  2368. TABLE: ['<table>', '</table>', 1],
  2369. TBODY: ['<table><tbody>', '</tbody></table>', 2],
  2370. TR: ['<table><tbody><tr>', '</tr></tbody></table>', 3],
  2371. TD: ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],
  2372. SELECT: ['<select>', '</select>', 1]
  2373. }
  2374. };
  2375. (function() {
  2376. var tags = Element._insertionTranslations.tags;
  2377. Object.extend(tags, {
  2378. THEAD: tags.TBODY,
  2379. TFOOT: tags.TBODY,
  2380. TH: tags.TD
  2381. });
  2382. })();
  2383. Element.Methods.Simulated = {
  2384. hasAttribute: function(element, attribute) {
  2385. attribute = Element._attributeTranslations.has[attribute] || attribute;
  2386. var node = $(element).getAttributeNode(attribute);
  2387. return !!(node && node.specified);
  2388. }
  2389. };
  2390. Element.Methods.ByTag = { };
  2391. Object.extend(Element, Element.Methods);
  2392. (function(div) {
  2393. if (!Prototype.BrowserFeatures.ElementExtensions && div['__proto__']) {
  2394. window.HTMLElement = { };
  2395. window.HTMLElement.prototype = div['__proto__'];
  2396. Prototype.BrowserFeatures.ElementExtensions = true;
  2397. }
  2398. div = null;
  2399. })(document.createElement('div'));
  2400. Element.extend = (function() {
  2401. function checkDeficiency(tagName) {
  2402. if (typeof window.Element != 'undefined') {
  2403. var proto = window.Element.prototype;
  2404. if (proto) {
  2405. var id = '_' + (Math.random()+'').slice(2),
  2406. el = document.createElement(tagName);
  2407. proto[id] = 'x';
  2408. var isBuggy = (el[id] !== 'x');
  2409. delete proto[id];
  2410. el = null;
  2411. return isBuggy;
  2412. }
  2413. }
  2414. return false;
  2415. }
  2416. function extendElementWith(element, methods) {
  2417. for (var property in methods) {
  2418. var value = methods[property];
  2419. if (Object.isFunction(value) && !(property in element))
  2420. element[property] = value.methodize();
  2421. }
  2422. }
  2423. var HTMLOBJECTELEMENT_PROTOTYPE_BUGGY = checkDeficiency('object');
  2424. if (Prototype.BrowserFeatures.SpecificElementExtensions) {
  2425. if (HTMLOBJECTELEMENT_PROTOTYPE_BUGGY) {
  2426. return function(element) {
  2427. if (element && typeof element._extendedByPrototype == 'undefined') {
  2428. var t = element.tagName;
  2429. if (t && (/^(?:object|applet|embed)$/i.test(t))) {
  2430. extendElementWith(element, Element.Methods);
  2431. extendElementWith(element, Element.Methods.Simulated);
  2432. extendElementWith(element, Element.Methods.ByTag[t.toUpperCase()]);
  2433. }
  2434. }
  2435. return element;
  2436. }
  2437. }
  2438. return Prototype.K;
  2439. }
  2440. var Methods = { }, ByTag = Element.Methods.ByTag;
  2441. var extend = Object.extend(function(element) {
  2442. if (!element || typeof element._extendedByPrototype != 'undefined' ||
  2443. element.nodeType != 1 || element == window) return element;
  2444. var methods = Object.clone(Methods),
  2445. tagName = element.tagName.toUpperCase();
  2446. if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]);
  2447. extendElementWith(element, methods);
  2448. element._extendedByPrototype = Prototype.emptyFunction;
  2449. return element;
  2450. }, {
  2451. refresh: function() {
  2452. if (!Prototype.BrowserFeatures.ElementExtensions) {
  2453. Object.extend(Methods, Element.Methods);
  2454. Object.extend(Methods, Element.Methods.Simulated);
  2455. }
  2456. }
  2457. });
  2458. extend.refresh();
  2459. return extend;
  2460. })();
  2461. if (document.documentElement.hasAttribute) {
  2462. Element.hasAttribute = function(element, attribute) {
  2463. return element.hasAttribute(attribute);
  2464. };
  2465. }
  2466. else {
  2467. Element.hasAttribute = Element.Methods.Simulated.hasAttribute;
  2468. }
  2469. Element.addMethods = function(methods) {
  2470. var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag;
  2471. if (!methods) {
  2472. Object.extend(Form, Form.Methods);
  2473. Object.extend(Form.Element, Form.Element.Methods);
  2474. Object.extend(Element.Methods.ByTag, {
  2475. "FORM": Object.clone(Form.Methods),
  2476. "INPUT": Object.clone(Form.Element.Methods),
  2477. "SELECT": Object.clone(Form.Element.Methods),
  2478. "TEXTAREA": Object.clone(Form.Element.Methods),
  2479. "BUTTON": Object.clone(Form.Element.Methods)
  2480. });
  2481. }
  2482. if (arguments.length == 2) {
  2483. var tagName = methods;
  2484. methods = arguments[1];
  2485. }
  2486. if (!tagName) Object.extend(Element.Methods, methods || { });
  2487. else {
  2488. if (Object.isArray(tagName)) tagName.each(extend);
  2489. else extend(tagName);
  2490. }
  2491. function extend(tagName) {
  2492. tagName = tagName.toUpperCase();
  2493. if (!Element.Methods.ByTag[tagName])
  2494. Element.Methods.ByTag[tagName] = { };
  2495. Object.extend(Element.Methods.ByTag[tagName], methods);
  2496. }
  2497. function copy(methods, destination, onlyIfAbsent) {
  2498. onlyIfAbsent = onlyIfAbsent || false;
  2499. for (var property in methods) {
  2500. var value = methods[property];
  2501. if (!Object.isFunction(value)) continue;
  2502. if (!onlyIfAbsent || !(property in destination))
  2503. destination[property] = value.methodize();
  2504. }
  2505. }
  2506. function findDOMClass(tagName) {
  2507. var klass;
  2508. var trans = {
  2509. "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph",
  2510. "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList",
  2511. "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading",
  2512. "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote",
  2513. "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION":
  2514. "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD":
  2515. "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR":
  2516. "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET":
  2517. "FrameSet", "IFRAME": "IFrame"
  2518. };
  2519. if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';
  2520. if (window[klass]) return window[klass];
  2521. klass = 'HTML' + tagName + 'Element';
  2522. if (window[klass]) return window[klass];
  2523. klass = 'HTML' + tagName.capitalize() + 'Element';
  2524. if (window[klass]) return window[klass];
  2525. var element = document.createElement(tagName),
  2526. proto = element['__proto__'] || element.constructor.prototype;
  2527. element = null;
  2528. return proto;
  2529. }
  2530. var elementPrototype = window.HTMLElement ? HTMLElement.prototype :
  2531. Element.prototype;
  2532. if (F.ElementExtensions) {
  2533. copy(Element.Methods, elementPrototype);
  2534. copy(Element.Methods.Simulated, elementPrototype, true);
  2535. }
  2536. if (F.SpecificElementExtensions) {
  2537. for (var tag in Element.Methods.ByTag) {
  2538. var klass = findDOMClass(tag);
  2539. if (Object.isUndefined(klass)) continue;
  2540. copy(T[tag], klass.prototype);
  2541. }
  2542. }
  2543. Object.extend(Element, Element.Methods);
  2544. delete Element.ByTag;
  2545. if (Element.extend.refresh) Element.extend.refresh();
  2546. Element.cache = { };
  2547. };
  2548. document.viewport = {
  2549. getDimensions: function() {
  2550. return { width: this.getWidth(), height: this.getHeight() };
  2551. },
  2552. getScrollOffsets: function() {
  2553. return Element._returnOffset(
  2554. window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
  2555. window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
  2556. }
  2557. };
  2558. (function(viewport) {
  2559. var B = Prototype.Browser, doc = document, element, property = {};
  2560. function getRootElement() {
  2561. if (B.WebKit && !doc.evaluate)
  2562. return document;
  2563. if (B.Opera && window.parseFloat(window.opera.version()) < 9.5)
  2564. return document.body;
  2565. return document.documentElement;
  2566. }
  2567. function define(D) {
  2568. if (!element) element = getRootElement();
  2569. property[D] = 'client' + D;
  2570. viewport['get' + D] = function() { return element[property[D]] };
  2571. return viewport['get' + D]();
  2572. }
  2573. viewport.getWidth = define.curry('Width');
  2574. viewport.getHeight = define.curry('Height');
  2575. })(document.viewport);
  2576. Element.Storage = {
  2577. UID: 1
  2578. };
  2579. Element.addMethods({
  2580. getStorage: function(element) {
  2581. if (!(element = $(element))) return;
  2582. var uid;
  2583. if (element === window) {
  2584. uid = 0;
  2585. } else {
  2586. if (typeof element._prototypeUID === "undefined")
  2587. element._prototypeUID = Element.Storage.UID++;
  2588. uid = element._prototypeUID;
  2589. }
  2590. if (!Element.Storage[uid])
  2591. Element.Storage[uid] = $H();
  2592. return Element.Storage[uid];
  2593. },
  2594. store: function(element, key, value) {
  2595. if (!(element = $(element))) return;
  2596. if (arguments.length === 2) {
  2597. Element.getStorage(element).update(key);
  2598. } else {
  2599. Element.getStorage(element).set(key, value);
  2600. }
  2601. return element;
  2602. },
  2603. retrieve: function(element, key, defaultValue) {
  2604. if (!(element = $(element))) return;
  2605. var hash = Element.getStorage(element), value = hash.get(key);
  2606. if (Object.isUndefined(value)) {
  2607. hash.set(key, defaultValue);
  2608. value = defaultValue;
  2609. }
  2610. return value;
  2611. },
  2612. clone: function(element, deep) {
  2613. if (!(element = $(element))) return;
  2614. var clone = element.cloneNode(deep);
  2615. clone._prototypeUID = void 0;
  2616. if (deep) {
  2617. var descendants = Element.select(clone, '*'),
  2618. i = descendants.length;
  2619. while (i--) {
  2620. descendants[i]._prototypeUID = void 0;
  2621. }
  2622. }
  2623. return Element.extend(clone);
  2624. },
  2625. purge: function(element) {
  2626. if (!(element = $(element))) return;
  2627. var purgeElement = Element._purgeElement;
  2628. purgeElement(element);
  2629. var descendants = element.getElementsByTagName('*'),
  2630. i = descendants.length;
  2631. while (i--) purgeElement(descendants[i]);
  2632. return null;
  2633. }
  2634. });
  2635. (function() {
  2636. function toDecimal(pctString) {
  2637. var match = pctString.match(/^(\d+)%?$/i);
  2638. if (!match) return null;
  2639. return (Number(match[1]) / 100);
  2640. }
  2641. function getPixelValue(value, property, context) {
  2642. var element = null;
  2643. if (Object.isElement(value)) {
  2644. element = value;
  2645. value = element.getStyle(property);
  2646. }
  2647. if (value === null) {
  2648. return null;
  2649. }
  2650. if ((/^(?:-)?\d+(\.\d+)?(px)?$/i).test(value)) {
  2651. return window.parseFloat(value);
  2652. }
  2653. var isPercentage = value.include('%'), isViewport = (context === document.viewport);
  2654. if (/\d/.test(value) && element && element.runtimeStyle && !(isPercentage && isViewport)) {
  2655. var style = element.style.left, rStyle = element.runtimeStyle.left;
  2656. element.runtimeStyle.left = element.currentStyle.left;
  2657. element.style.left = value || 0;
  2658. value = element.style.pixelLeft;
  2659. element.style.left = style;
  2660. element.runtimeStyle.left = rStyle;
  2661. return value;
  2662. }
  2663. if (element && isPercentage) {
  2664. context = context || element.parentNode;
  2665. var decimal = toDecimal(value);
  2666. var whole = null;
  2667. var position = element.getStyle('position');
  2668. var isHorizontal = property.include('left') || property.include('right') ||
  2669. property.include('width');
  2670. var isVertical = property.include('top') || property.include('bottom') ||
  2671. property.include('height');
  2672. if (context === document.viewport) {
  2673. if (isHorizontal) {
  2674. whole = document.viewport.getWidth();
  2675. } else if (isVertical) {
  2676. whole = document.viewport.getHeight();
  2677. }
  2678. } else {
  2679. if (isHorizontal) {
  2680. whole = $(context).measure('width');
  2681. } else if (isVertical) {
  2682. whole = $(context).measure('height');
  2683. }
  2684. }
  2685. return (whole === null) ? 0 : whole * decimal;
  2686. }
  2687. return 0;
  2688. }
  2689. function toCSSPixels(number) {
  2690. if (Object.isString(number) && number.endsWith('px')) {
  2691. return number;
  2692. }
  2693. return number + 'px';
  2694. }
  2695. function isDisplayed(element) {
  2696. var originalElement = element;
  2697. while (element && element.parentNode) {
  2698. var display = element.getStyle('display');
  2699. if (display === 'none') {
  2700. return false;
  2701. }
  2702. element = $(element.parentNode);
  2703. }
  2704. return true;
  2705. }
  2706. var hasLayout = Prototype.K;
  2707. if ('currentStyle' in document.documentElement) {
  2708. hasLayout = function(element) {
  2709. if (!element.currentStyle.hasLayout) {
  2710. element.style.zoom = 1;
  2711. }
  2712. return element;
  2713. };
  2714. }
  2715. function cssNameFor(key) {
  2716. if (key.include('border')) key = key + '-width';
  2717. return key.camelize();
  2718. }
  2719. Element.Layout = Class.create(Hash, {
  2720. initialize: function($super, element, preCompute) {
  2721. $super();
  2722. this.element = $(element);
  2723. Element.Layout.PROPERTIES.each( function(property) {
  2724. this._set(property, null);
  2725. }, this);
  2726. if (preCompute) {
  2727. this._preComputing = true;
  2728. this._begin();
  2729. Element.Layout.PROPERTIES.each( this._compute, this );
  2730. this._end();
  2731. this._preComputing = false;
  2732. }
  2733. },
  2734. _set: function(property, value) {
  2735. return Hash.prototype.set.call(this, property, value);
  2736. },
  2737. set: function(property, value) {
  2738. throw "Properties of Element.Layout are read-only.";
  2739. },
  2740. get: function($super, property) {
  2741. var value = $super(property);
  2742. return value === null ? this._compute(property) : value;
  2743. },
  2744. _begin: function() {
  2745. if (this._prepared) return;
  2746. var element = this.element;
  2747. if (isDisplayed(element)) {
  2748. this._prepared = true;
  2749. return;
  2750. }
  2751. var originalStyles = {
  2752. position: element.style.position || '',
  2753. width: element.style.width || '',
  2754. visibility: element.style.visibility || '',
  2755. display: element.style.display || ''
  2756. };
  2757. element.store('prototype_original_styles', originalStyles);
  2758. var position = element.getStyle('position'),
  2759. width = element.getStyle('width');
  2760. if (width === "0px" || width === null) {
  2761. element.style.display = 'block';
  2762. width = element.getStyle('width');
  2763. }
  2764. var context = (position === 'fixed') ? document.viewport :
  2765. element.parentNode;
  2766. element.setStyle({
  2767. position: 'absolute',
  2768. visibility: 'hidden',
  2769. display: 'block'
  2770. });
  2771. var positionedWidth = element.getStyle('width');
  2772. var newWidth;
  2773. if (width && (positionedWidth === width)) {
  2774. newWidth = getPixelValue(element, 'width', context);
  2775. } else if (position === 'absolute' || position === 'fixed') {
  2776. newWidth = getPixelValue(element, 'width', context);
  2777. } else {
  2778. var parent = element.parentNode, pLayout = $(parent).getLayout();
  2779. newWidth = pLayout.get('width') -
  2780. this.get('margin-left') -
  2781. this.get('border-left') -
  2782. this.get('padding-left') -
  2783. this.get('padding-right') -
  2784. this.get('border-right') -
  2785. this.get('margin-right');
  2786. }
  2787. element.setStyle({ width: newWidth + 'px' });
  2788. this._prepared = true;
  2789. },
  2790. _end: function() {
  2791. var element = this.element;
  2792. var originalStyles = element.retrieve('prototype_original_styles');
  2793. element.store('prototype_original_styles', null);
  2794. element.setStyle(originalStyles);
  2795. this._prepared = false;
  2796. },
  2797. _compute: function(property) {
  2798. var COMPUTATIONS = Element.Layout.COMPUTATIONS;
  2799. if (!(property in COMPUTATIONS)) {
  2800. throw "Property not found.";
  2801. }
  2802. return this._set(property, COMPUTATIONS[property].call(this, this.element));
  2803. },
  2804. toObject: function() {
  2805. var args = $A(arguments);
  2806. var keys = (args.length === 0) ? Element.Layout.PROPERTIES :
  2807. args.join(' ').split(' ');
  2808. var obj = {};
  2809. keys.each( function(key) {
  2810. if (!Element.Layout.PROPERTIES.include(key)) return;
  2811. var value = this.get(key);
  2812. if (value != null) obj[key] = value;
  2813. }, this);
  2814. return obj;
  2815. },
  2816. toHash: function() {
  2817. var obj = this.toObject.apply(this, arguments);
  2818. return new Hash(obj);
  2819. },
  2820. toCSS: function() {
  2821. var args = $A(arguments);
  2822. var keys = (args.length === 0) ? Element.Layout.PROPERTIES :
  2823. args.join(' ').split(' ');
  2824. var css = {};
  2825. keys.each( function(key) {
  2826. if (!Element.Layout.PROPERTIES.include(key)) return;
  2827. if (Element.Layout.COMPOSITE_PROPERTIES.include(key)) return;
  2828. var value = this.get(key);
  2829. if (value != null) css[cssNameFor(key)] = value + 'px';
  2830. }, this);
  2831. return css;
  2832. },
  2833. inspect: function() {
  2834. return "#<Element.Layout>";
  2835. }
  2836. });
  2837. Object.extend(Element.Layout, {
  2838. 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'),
  2839. COMPOSITE_PROPERTIES: $w('padding-box-width padding-box-height margin-box-width margin-box-height border-box-width border-box-height'),
  2840. COMPUTATIONS: {
  2841. 'height': function(element) {
  2842. if (!this._preComputing) this._begin();
  2843. var bHeight = this.get('border-box-height');
  2844. if (bHeight <= 0) {
  2845. if (!this._preComputing) this._end();
  2846. return 0;
  2847. }
  2848. var bTop = this.get('border-top'),
  2849. bBottom = this.get('border-bottom');
  2850. var pTop = this.get('padding-top'),
  2851. pBottom = this.get('padding-bottom');
  2852. if (!this._preComputing) this._end();
  2853. return bHeight - bTop - bBottom - pTop - pBottom;
  2854. },
  2855. 'width': function(element) {
  2856. if (!this._preComputing) this._begin();
  2857. var bWidth = this.get('border-box-width');
  2858. if (bWidth <= 0) {
  2859. if (!this._preComputing) this._end();
  2860. return 0;
  2861. }
  2862. var bLeft = this.get('border-left'),
  2863. bRight = this.get('border-right');
  2864. var pLeft = this.get('padding-left'),
  2865. pRight = this.get('padding-right');
  2866. if (!this._preComputing) this._end();
  2867. return bWidth - bLeft - bRight - pLeft - pRight;
  2868. },
  2869. 'padding-box-height': function(element) {
  2870. var height = this.get('height'),
  2871. pTop = this.get('padding-top'),
  2872. pBottom = this.get('padding-bottom');
  2873. return height + pTop + pBottom;
  2874. },
  2875. 'padding-box-width': function(element) {
  2876. var width = this.get('width'),
  2877. pLeft = this.get('padding-left'),
  2878. pRight = this.get('padding-right');
  2879. return width + pLeft + pRight;
  2880. },
  2881. 'border-box-height': function(element) {
  2882. if (!this._preComputing) this._begin();
  2883. var height = element.offsetHeight;
  2884. if (!this._preComputing) this._end();
  2885. return height;
  2886. },
  2887. 'border-box-width': function(element) {
  2888. if (!this._preComputing) this._begin();
  2889. var width = element.offsetWidth;
  2890. if (!this._preComputing) this._end();
  2891. return width;
  2892. },
  2893. 'margin-box-height': function(element) {
  2894. var bHeight = this.get('border-box-height'),
  2895. mTop = this.get('margin-top'),
  2896. mBottom = this.get('margin-bottom');
  2897. if (bHeight <= 0) return 0;
  2898. return bHeight + mTop + mBottom;
  2899. },
  2900. 'margin-box-width': function(element) {
  2901. var bWidth = this.get('border-box-width'),
  2902. mLeft = this.get('margin-left'),
  2903. mRight = this.get('margin-right');
  2904. if (bWidth <= 0) return 0;
  2905. return bWidth + mLeft + mRight;
  2906. },
  2907. 'top': function(element) {
  2908. var offset = element.positionedOffset();
  2909. return offset.top;
  2910. },
  2911. 'bottom': function(element) {
  2912. var offset = element.positionedOffset(),
  2913. parent = element.getOffsetParent(),
  2914. pHeight = parent.measure('height');
  2915. var mHeight = this.get('border-box-height');
  2916. return pHeight - mHeight - offset.top;
  2917. },
  2918. 'left': function(element) {
  2919. var offset = element.positionedOffset();
  2920. return offset.left;
  2921. },
  2922. 'right': function(element) {
  2923. var offset = element.positionedOffset(),
  2924. parent = element.getOffsetParent(),
  2925. pWidth = parent.measure('width');
  2926. var mWidth = this.get('border-box-width');
  2927. return pWidth - mWidth - offset.left;
  2928. },
  2929. 'padding-top': function(element) {
  2930. return getPixelValue(element, 'paddingTop');
  2931. },
  2932. 'padding-bottom': function(element) {
  2933. return getPixelValue(element, 'paddingBottom');
  2934. },
  2935. 'padding-left': function(element) {
  2936. return getPixelValue(element, 'paddingLeft');
  2937. },
  2938. 'padding-right': function(element) {
  2939. return getPixelValue(element, 'paddingRight');
  2940. },
  2941. 'border-top': function(element) {
  2942. return getPixelValue(element, 'borderTopWidth');
  2943. },
  2944. 'border-bottom': function(element) {
  2945. return getPixelValue(element, 'borderBottomWidth');
  2946. },
  2947. 'border-left': function(element) {
  2948. return getPixelValue(element, 'borderLeftWidth');
  2949. },
  2950. 'border-right': function(element) {
  2951. return getPixelValue(element, 'borderRightWidth');
  2952. },
  2953. 'margin-top': function(element) {
  2954. return getPixelValue(element, 'marginTop');
  2955. },
  2956. 'margin-bottom': function(element) {
  2957. return getPixelValue(element, 'marginBottom');
  2958. },
  2959. 'margin-left': function(element) {
  2960. return getPixelValue(element, 'marginLeft');
  2961. },
  2962. 'margin-right': function(element) {
  2963. return getPixelValue(element, 'marginRight');
  2964. }
  2965. }
  2966. });
  2967. if ('getBoundingClientRect' in document.documentElement) {
  2968. Object.extend(Element.Layout.COMPUTATIONS, {
  2969. 'right': function(element) {
  2970. var parent = hasLayout(element.getOffsetParent());
  2971. var rect = element.getBoundingClientRect(),
  2972. pRect = parent.getBoundingClientRect();
  2973. return (pRect.right - rect.right).round();
  2974. },
  2975. 'bottom': function(element) {
  2976. var parent = hasLayout(element.getOffsetParent());
  2977. var rect = element.getBoundingClientRect(),
  2978. pRect = parent.getBoundingClientRect();
  2979. return (pRect.bottom - rect.bottom).round();
  2980. }
  2981. });
  2982. }
  2983. Element.Offset = Class.create({
  2984. initialize: function(left, top) {
  2985. this.left = left.round();
  2986. this.top = top.round();
  2987. this[0] = this.left;
  2988. this[1] = this.top;
  2989. },
  2990. relativeTo: function(offset) {
  2991. return new Element.Offset(
  2992. this.left - offset.left,
  2993. this.top - offset.top
  2994. );
  2995. },
  2996. inspect: function() {
  2997. return "#<Element.Offset left: #{left} top: #{top}>".interpolate(this);
  2998. },
  2999. toString: function() {
  3000. return "[#{left}, #{top}]".interpolate(this);
  3001. },
  3002. toArray: function() {
  3003. return [this.left, this.top];
  3004. }
  3005. });
  3006. function getLayout(element, preCompute) {
  3007. return new Element.Layout(element, preCompute);
  3008. }
  3009. function measure(element, property) {
  3010. return $(element).getLayout().get(property);
  3011. }
  3012. function getDimensions(element) {
  3013. element = $(element);
  3014. var display = Element.getStyle(element, 'display');
  3015. if (display && display !== 'none') {
  3016. return { width: element.offsetWidth, height: element.offsetHeight };
  3017. }
  3018. var style = element.style;
  3019. var originalStyles = {
  3020. visibility: style.visibility,
  3021. position: style.position,
  3022. display: style.display
  3023. };
  3024. var newStyles = {
  3025. visibility: 'hidden',
  3026. display: 'block'
  3027. };
  3028. if (originalStyles.position !== 'fixed')
  3029. newStyles.position = 'absolute';
  3030. Element.setStyle(element, newStyles);
  3031. var dimensions = {
  3032. width: element.offsetWidth,
  3033. height: element.offsetHeight
  3034. };
  3035. Element.setStyle(element, originalStyles);
  3036. return dimensions;
  3037. }
  3038. function getOffsetParent(element) {
  3039. element = $(element);
  3040. if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element))
  3041. return $(document.body);
  3042. var isInline = (Element.getStyle(element, 'display') === 'inline');
  3043. if (!isInline && element.offsetParent) return $(element.offsetParent);
  3044. while ((element = element.parentNode) && element !== document.body) {
  3045. if (Element.getStyle(element, 'position') !== 'static') {
  3046. return isHtml(element) ? $(document.body) : $(element);
  3047. }
  3048. }
  3049. return $(document.body);
  3050. }
  3051. function cumulativeOffset(element) {
  3052. element = $(element);
  3053. var valueT = 0, valueL = 0;
  3054. if (element.parentNode) {
  3055. do {
  3056. valueT += element.offsetTop || 0;
  3057. valueL += element.offsetLeft || 0;
  3058. element = element.offsetParent;
  3059. } while (element);
  3060. }
  3061. return new Element.Offset(valueL, valueT);
  3062. }
  3063. function positionedOffset(element) {
  3064. element = $(element);
  3065. var layout = element.getLayout();
  3066. var valueT = 0, valueL = 0;
  3067. do {
  3068. valueT += element.offsetTop || 0;
  3069. valueL += element.offsetLeft || 0;
  3070. element = element.offsetParent;
  3071. if (element) {
  3072. if (isBody(element)) break;
  3073. var p = Element.getStyle(element, 'position');
  3074. if (p !== 'static') break;
  3075. }
  3076. } while (element);
  3077. valueL -= layout.get('margin-top');
  3078. valueT -= layout.get('margin-left');
  3079. return new Element.Offset(valueL, valueT);
  3080. }
  3081. function cumulativeScrollOffset(element) {
  3082. var valueT = 0, valueL = 0;
  3083. do {
  3084. valueT += element.scrollTop || 0;
  3085. valueL += element.scrollLeft || 0;
  3086. element = element.parentNode;
  3087. } while (element);
  3088. return new Element.Offset(valueL, valueT);
  3089. }
  3090. function viewportOffset(forElement) {
  3091. element = $(element);
  3092. var valueT = 0, valueL = 0, docBody = document.body;
  3093. var element = forElement;
  3094. do {
  3095. valueT += element.offsetTop || 0;
  3096. valueL += element.offsetLeft || 0;
  3097. if (element.offsetParent == docBody &&
  3098. Element.getStyle(element, 'position') == 'absolute') break;
  3099. } while (element = element.offsetParent);
  3100. element = forElement;
  3101. do {
  3102. if (element != docBody) {
  3103. valueT -= element.scrollTop || 0;
  3104. valueL -= element.scrollLeft || 0;
  3105. }
  3106. } while (element = element.parentNode);
  3107. return new Element.Offset(valueL, valueT);
  3108. }
  3109. function absolutize(element) {
  3110. element = $(element);
  3111. if (Element.getStyle(element, 'position') === 'absolute') {
  3112. return element;
  3113. }
  3114. var offsetParent = getOffsetParent(element);
  3115. var eOffset = element.viewportOffset(),
  3116. pOffset = offsetParent.viewportOffset();
  3117. var offset = eOffset.relativeTo(pOffset);
  3118. var layout = element.getLayout();
  3119. element.store('prototype_absolutize_original_styles', {
  3120. left: element.getStyle('left'),
  3121. top: element.getStyle('top'),
  3122. width: element.getStyle('width'),
  3123. height: element.getStyle('height')
  3124. });
  3125. element.setStyle({
  3126. position: 'absolute',
  3127. top: offset.top + 'px',
  3128. left: offset.left + 'px',
  3129. width: layout.get('width') + 'px',
  3130. height: layout.get('height') + 'px'
  3131. });
  3132. return element;
  3133. }
  3134. function relativize(element) {
  3135. element = $(element);
  3136. if (Element.getStyle(element, 'position') === 'relative') {
  3137. return element;
  3138. }
  3139. var originalStyles =
  3140. element.retrieve('prototype_absolutize_original_styles');
  3141. if (originalStyles) element.setStyle(originalStyles);
  3142. return element;
  3143. }
  3144. if (Prototype.Browser.IE) {
  3145. getOffsetParent = getOffsetParent.wrap(
  3146. function(proceed, element) {
  3147. element = $(element);
  3148. if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element))
  3149. return $(document.body);
  3150. var position = element.getStyle('position');
  3151. if (position !== 'static') return proceed(element);
  3152. element.setStyle({ position: 'relative' });
  3153. var value = proceed(element);
  3154. element.setStyle({ position: position });
  3155. return value;
  3156. }
  3157. );
  3158. positionedOffset = positionedOffset.wrap(function(proceed, element) {
  3159. element = $(element);
  3160. if (!element.parentNode) return new Element.Offset(0, 0);
  3161. var position = element.getStyle('position');
  3162. if (position !== 'static') return proceed(element);
  3163. var offsetParent = element.getOffsetParent();
  3164. if (offsetParent && offsetParent.getStyle('position') === 'fixed')
  3165. hasLayout(offsetParent);
  3166. element.setStyle({ position: 'relative' });
  3167. var value = proceed(element);
  3168. element.setStyle({ position: position });
  3169. return value;
  3170. });
  3171. } else if (Prototype.Browser.Webkit) {
  3172. cumulativeOffset = function(element) {
  3173. element = $(element);
  3174. var valueT = 0, valueL = 0;
  3175. do {
  3176. valueT += element.offsetTop || 0;
  3177. valueL += element.offsetLeft || 0;
  3178. if (element.offsetParent == document.body)
  3179. if (Element.getStyle(element, 'position') == 'absolute') break;
  3180. element = element.offsetParent;
  3181. } while (element);
  3182. return new Element.Offset(valueL, valueT);
  3183. };
  3184. }
  3185. Element.addMethods({
  3186. getLayout: getLayout,
  3187. measure: measure,
  3188. getDimensions: getDimensions,
  3189. getOffsetParent: getOffsetParent,
  3190. cumulativeOffset: cumulativeOffset,
  3191. positionedOffset: positionedOffset,
  3192. cumulativeScrollOffset: cumulativeScrollOffset,
  3193. viewportOffset: viewportOffset,
  3194. absolutize: absolutize,
  3195. relativize: relativize
  3196. });
  3197. function isBody(element) {
  3198. return element.nodeName.toUpperCase() === 'BODY';
  3199. }
  3200. function isHtml(element) {
  3201. return element.nodeName.toUpperCase() === 'HTML';
  3202. }
  3203. function isDocument(element) {
  3204. return element.nodeType === Node.DOCUMENT_NODE;
  3205. }
  3206. function isDetached(element) {
  3207. return element !== document.body &&
  3208. !Element.descendantOf(element, document.body);
  3209. }
  3210. if ('getBoundingClientRect' in document.documentElement) {
  3211. Element.addMethods({
  3212. viewportOffset: function(element) {
  3213. element = $(element);
  3214. if (isDetached(element)) return new Element.Offset(0, 0);
  3215. var rect = element.getBoundingClientRect(),
  3216. docEl = document.documentElement;
  3217. return new Element.Offset(rect.left - docEl.clientLeft,
  3218. rect.top - docEl.clientTop);
  3219. }
  3220. });
  3221. }
  3222. })();
  3223. window.$$ = function() {
  3224. var expression = $A(arguments).join(', ');
  3225. return Prototype.Selector.select(expression, document);
  3226. };
  3227. Prototype.Selector = (function() {
  3228. function select() {
  3229. throw new Error('Method "Prototype.Selector.select" must be defined.');
  3230. }
  3231. function match() {
  3232. throw new Error('Method "Prototype.Selector.match" must be defined.');
  3233. }
  3234. function find(elements, expression, index) {
  3235. index = index || 0;
  3236. var match = Prototype.Selector.match, length = elements.length, matchIndex = 0, i;
  3237. for (i = 0; i < length; i++) {
  3238. if (match(elements[i], expression) && index == matchIndex++) {
  3239. return Element.extend(elements[i]);
  3240. }
  3241. }
  3242. }
  3243. function extendElements(elements) {
  3244. for (var i = 0, length = elements.length; i < length; i++) {
  3245. Element.extend(elements[i]);
  3246. }
  3247. return elements;
  3248. }
  3249. var K = Prototype.K;
  3250. return {
  3251. select: select,
  3252. match: match,
  3253. find: find,
  3254. extendElements: (Element.extend === K) ? K : extendElements,
  3255. extendElement: Element.extend
  3256. };
  3257. })();
  3258. Prototype._original_property = window.Sizzle;
  3259. /*!
  3260. * Sizzle CSS Selector Engine - v1.0
  3261. * Copyright 2009, The Dojo Foundation
  3262. * Released under the MIT, BSD, and GPL Licenses.
  3263. * More information: http://sizzlejs.com/
  3264. */
  3265. (function(){
  3266. var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
  3267. done = 0,
  3268. toString = Object.prototype.toString,
  3269. hasDuplicate = false,
  3270. baseHasDuplicate = true;
  3271. [0, 0].sort(function(){
  3272. baseHasDuplicate = false;
  3273. return 0;
  3274. });
  3275. var Sizzle = function(selector, context, results, seed) {
  3276. results = results || [];
  3277. var origContext = context = context || document;
  3278. if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
  3279. return [];
  3280. }
  3281. if ( !selector || typeof selector !== "string" ) {
  3282. return results;
  3283. }
  3284. var parts = [], m, set, checkSet, check, mode, extra, prune = true, contextXML = isXML(context),
  3285. soFar = selector;
  3286. while ( (chunker.exec(""), m = chunker.exec(soFar)) !== null ) {
  3287. soFar = m[3];
  3288. parts.push( m[1] );
  3289. if ( m[2] ) {
  3290. extra = m[3];
  3291. break;
  3292. }
  3293. }
  3294. if ( parts.length > 1 && origPOS.exec( selector ) ) {
  3295. if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
  3296. set = posProcess( parts[0] + parts[1], context );
  3297. } else {
  3298. set = Expr.relative[ parts[0] ] ?
  3299. [ context ] :
  3300. Sizzle( parts.shift(), context );
  3301. while ( parts.length ) {
  3302. selector = parts.shift();
  3303. if ( Expr.relative[ selector ] )
  3304. selector += parts.shift();
  3305. set = posProcess( selector, set );
  3306. }
  3307. }
  3308. } else {
  3309. if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
  3310. Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
  3311. var ret = Sizzle.find( parts.shift(), context, contextXML );
  3312. context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0];
  3313. }
  3314. if ( context ) {
  3315. var ret = seed ?
  3316. { expr: parts.pop(), set: makeArray(seed) } :
  3317. Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
  3318. set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set;
  3319. if ( parts.length > 0 ) {
  3320. checkSet = makeArray(set);
  3321. } else {
  3322. prune = false;
  3323. }
  3324. while ( parts.length ) {
  3325. var cur = parts.pop(), pop = cur;
  3326. if ( !Expr.relative[ cur ] ) {
  3327. cur = "";
  3328. } else {
  3329. pop = parts.pop();
  3330. }
  3331. if ( pop == null ) {
  3332. pop = context;
  3333. }
  3334. Expr.relative[ cur ]( checkSet, pop, contextXML );
  3335. }
  3336. } else {
  3337. checkSet = parts = [];
  3338. }
  3339. }
  3340. if ( !checkSet ) {
  3341. checkSet = set;
  3342. }
  3343. if ( !checkSet ) {
  3344. throw "Syntax error, unrecognized expression: " + (cur || selector);
  3345. }
  3346. if ( toString.call(checkSet) === "[object Array]" ) {
  3347. if ( !prune ) {
  3348. results.push.apply( results, checkSet );
  3349. } else if ( context && context.nodeType === 1 ) {
  3350. for ( var i = 0; checkSet[i] != null; i++ ) {
  3351. if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) {
  3352. results.push( set[i] );
  3353. }
  3354. }
  3355. } else {
  3356. for ( var i = 0; checkSet[i] != null; i++ ) {
  3357. if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
  3358. results.push( set[i] );
  3359. }
  3360. }
  3361. }
  3362. } else {
  3363. makeArray( checkSet, results );
  3364. }
  3365. if ( extra ) {
  3366. Sizzle( extra, origContext, results, seed );
  3367. Sizzle.uniqueSort( results );
  3368. }
  3369. return results;
  3370. };
  3371. Sizzle.uniqueSort = function(results){
  3372. if ( sortOrder ) {
  3373. hasDuplicate = baseHasDuplicate;
  3374. results.sort(sortOrder);
  3375. if ( hasDuplicate ) {
  3376. for ( var i = 1; i < results.length; i++ ) {
  3377. if ( results[i] === results[i-1] ) {
  3378. results.splice(i--, 1);
  3379. }
  3380. }
  3381. }
  3382. }
  3383. return results;
  3384. };
  3385. Sizzle.matches = function(expr, set){
  3386. return Sizzle(expr, null, null, set);
  3387. };
  3388. Sizzle.find = function(expr, context, isXML){
  3389. var set, match;
  3390. if ( !expr ) {
  3391. return [];
  3392. }
  3393. for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
  3394. var type = Expr.order[i], match;
  3395. if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
  3396. var left = match[1];
  3397. match.splice(1,1);
  3398. if ( left.substr( left.length - 1 ) !== "\\" ) {
  3399. match[1] = (match[1] || "").replace(/\\/g, "");
  3400. set = Expr.find[ type ]( match, context, isXML );
  3401. if ( set != null ) {
  3402. expr = expr.replace( Expr.match[ type ], "" );
  3403. break;
  3404. }
  3405. }
  3406. }
  3407. }
  3408. if ( !set ) {
  3409. set = context.getElementsByTagName("*");
  3410. }
  3411. return {set: set, expr: expr};
  3412. };
  3413. Sizzle.filter = function(expr, set, inplace, not){
  3414. var old = expr, result = [], curLoop = set, match, anyFound,
  3415. isXMLFilter = set && set[0] && isXML(set[0]);
  3416. while ( expr && set.length ) {
  3417. for ( var type in Expr.filter ) {
  3418. if ( (match = Expr.match[ type ].exec( expr )) != null ) {
  3419. var filter = Expr.filter[ type ], found, item;
  3420. anyFound = false;
  3421. if ( curLoop == result ) {
  3422. result = [];
  3423. }
  3424. if ( Expr.preFilter[ type ] ) {
  3425. match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
  3426. if ( !match ) {
  3427. anyFound = found = true;
  3428. } else if ( match === true ) {
  3429. continue;
  3430. }
  3431. }
  3432. if ( match ) {
  3433. for ( var i = 0; (item = curLoop[i]) != null; i++ ) {
  3434. if ( item ) {
  3435. found = filter( item, match, i, curLoop );
  3436. var pass = not ^ !!found;
  3437. if ( inplace && found != null ) {
  3438. if ( pass ) {
  3439. anyFound = true;
  3440. } else {
  3441. curLoop[i] = false;
  3442. }
  3443. } else if ( pass ) {
  3444. result.push( item );
  3445. anyFound = true;
  3446. }
  3447. }
  3448. }
  3449. }
  3450. if ( found !== undefined ) {
  3451. if ( !inplace ) {
  3452. curLoop = result;
  3453. }
  3454. expr = expr.replace( Expr.match[ type ], "" );
  3455. if ( !anyFound ) {
  3456. return [];
  3457. }
  3458. break;
  3459. }
  3460. }
  3461. }
  3462. if ( expr == old ) {
  3463. if ( anyFound == null ) {
  3464. throw "Syntax error, unrecognized expression: " + expr;
  3465. } else {
  3466. break;
  3467. }
  3468. }
  3469. old = expr;
  3470. }
  3471. return curLoop;
  3472. };
  3473. var Expr = Sizzle.selectors = {
  3474. order: [ "ID", "NAME", "TAG" ],
  3475. match: {
  3476. ID: /#((?:[\w\u00c0-\uFFFF-]|\\.)+)/,
  3477. CLASS: /\.((?:[\w\u00c0-\uFFFF-]|\\.)+)/,
  3478. NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF-]|\\.)+)['"]*\]/,
  3479. ATTR: /\[\s*((?:[\w\u00c0-\uFFFF-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,
  3480. TAG: /^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)/,
  3481. CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/,
  3482. POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/,
  3483. PSEUDO: /:((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/
  3484. },
  3485. leftMatch: {},
  3486. attrMap: {
  3487. "class": "className",
  3488. "for": "htmlFor"
  3489. },
  3490. attrHandle: {
  3491. href: function(elem){
  3492. return elem.getAttribute("href");
  3493. }
  3494. },
  3495. relative: {
  3496. "+": function(checkSet, part, isXML){
  3497. var isPartStr = typeof part === "string",
  3498. isTag = isPartStr && !/\W/.test(part),
  3499. isPartStrNotTag = isPartStr && !isTag;
  3500. if ( isTag && !isXML ) {
  3501. part = part.toUpperCase();
  3502. }
  3503. for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
  3504. if ( (elem = checkSet[i]) ) {
  3505. while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
  3506. checkSet[i] = isPartStrNotTag || elem && elem.nodeName === part ?
  3507. elem || false :
  3508. elem === part;
  3509. }
  3510. }
  3511. if ( isPartStrNotTag ) {
  3512. Sizzle.filter( part, checkSet, true );
  3513. }
  3514. },
  3515. ">": function(checkSet, part, isXML){
  3516. var isPartStr = typeof part === "string";
  3517. if ( isPartStr && !/\W/.test(part) ) {
  3518. part = isXML ? part : part.toUpperCase();
  3519. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  3520. var elem = checkSet[i];
  3521. if ( elem ) {
  3522. var parent = elem.parentNode;
  3523. checkSet[i] = parent.nodeName === part ? parent : false;
  3524. }
  3525. }
  3526. } else {
  3527. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  3528. var elem = checkSet[i];
  3529. if ( elem ) {
  3530. checkSet[i] = isPartStr ?
  3531. elem.parentNode :
  3532. elem.parentNode === part;
  3533. }
  3534. }
  3535. if ( isPartStr ) {
  3536. Sizzle.filter( part, checkSet, true );
  3537. }
  3538. }
  3539. },
  3540. "": function(checkSet, part, isXML){
  3541. var doneName = done++, checkFn = dirCheck;
  3542. if ( !/\W/.test(part) ) {
  3543. var nodeCheck = part = isXML ? part : part.toUpperCase();
  3544. checkFn = dirNodeCheck;
  3545. }
  3546. checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML);
  3547. },
  3548. "~": function(checkSet, part, isXML){
  3549. var doneName = done++, checkFn = dirCheck;
  3550. if ( typeof part === "string" && !/\W/.test(part) ) {
  3551. var nodeCheck = part = isXML ? part : part.toUpperCase();
  3552. checkFn = dirNodeCheck;
  3553. }
  3554. checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML);
  3555. }
  3556. },
  3557. find: {
  3558. ID: function(match, context, isXML){
  3559. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  3560. var m = context.getElementById(match[1]);
  3561. return m ? [m] : [];
  3562. }
  3563. },
  3564. NAME: function(match, context, isXML){
  3565. if ( typeof context.getElementsByName !== "undefined" ) {
  3566. var ret = [], results = context.getElementsByName(match[1]);
  3567. for ( var i = 0, l = results.length; i < l; i++ ) {
  3568. if ( results[i].getAttribute("name") === match[1] ) {
  3569. ret.push( results[i] );
  3570. }
  3571. }
  3572. return ret.length === 0 ? null : ret;
  3573. }
  3574. },
  3575. TAG: function(match, context){
  3576. return context.getElementsByTagName(match[1]);
  3577. }
  3578. },
  3579. preFilter: {
  3580. CLASS: function(match, curLoop, inplace, result, not, isXML){
  3581. match = " " + match[1].replace(/\\/g, "") + " ";
  3582. if ( isXML ) {
  3583. return match;
  3584. }
  3585. for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
  3586. if ( elem ) {
  3587. if ( not ^ (elem.className && (" " + elem.className + " ").indexOf(match) >= 0) ) {
  3588. if ( !inplace )
  3589. result.push( elem );
  3590. } else if ( inplace ) {
  3591. curLoop[i] = false;
  3592. }
  3593. }
  3594. }
  3595. return false;
  3596. },
  3597. ID: function(match){
  3598. return match[1].replace(/\\/g, "");
  3599. },
  3600. TAG: function(match, curLoop){
  3601. for ( var i = 0; curLoop[i] === false; i++ ){}
  3602. return curLoop[i] && isXML(curLoop[i]) ? match[1] : match[1].toUpperCase();
  3603. },
  3604. CHILD: function(match){
  3605. if ( match[1] == "nth" ) {
  3606. var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
  3607. match[2] == "even" && "2n" || match[2] == "odd" && "2n+1" ||
  3608. !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
  3609. match[2] = (test[1] + (test[2] || 1)) - 0;
  3610. match[3] = test[3] - 0;
  3611. }
  3612. match[0] = done++;
  3613. return match;
  3614. },
  3615. ATTR: function(match, curLoop, inplace, result, not, isXML){
  3616. var name = match[1].replace(/\\/g, "");
  3617. if ( !isXML && Expr.attrMap[name] ) {
  3618. match[1] = Expr.attrMap[name];
  3619. }
  3620. if ( match[2] === "~=" ) {
  3621. match[4] = " " + match[4] + " ";
  3622. }
  3623. return match;
  3624. },
  3625. PSEUDO: function(match, curLoop, inplace, result, not){
  3626. if ( match[1] === "not" ) {
  3627. if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
  3628. match[3] = Sizzle(match[3], null, null, curLoop);
  3629. } else {
  3630. var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
  3631. if ( !inplace ) {
  3632. result.push.apply( result, ret );
  3633. }
  3634. return false;
  3635. }
  3636. } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
  3637. return true;
  3638. }
  3639. return match;
  3640. },
  3641. POS: function(match){
  3642. match.unshift( true );
  3643. return match;
  3644. }
  3645. },
  3646. filters: {
  3647. enabled: function(elem){
  3648. return elem.disabled === false && elem.type !== "hidden";
  3649. },
  3650. disabled: function(elem){
  3651. return elem.disabled === true;
  3652. },
  3653. checked: function(elem){
  3654. return elem.checked === true;
  3655. },
  3656. selected: function(elem){
  3657. elem.parentNode.selectedIndex;
  3658. return elem.selected === true;
  3659. },
  3660. parent: function(elem){
  3661. return !!elem.firstChild;
  3662. },
  3663. empty: function(elem){
  3664. return !elem.firstChild;
  3665. },
  3666. has: function(elem, i, match){
  3667. return !!Sizzle( match[3], elem ).length;
  3668. },
  3669. header: function(elem){
  3670. return /h\d/i.test( elem.nodeName );
  3671. },
  3672. text: function(elem){
  3673. return "text" === elem.type;
  3674. },
  3675. radio: function(elem){
  3676. return "radio" === elem.type;
  3677. },
  3678. checkbox: function(elem){
  3679. return "checkbox" === elem.type;
  3680. },
  3681. file: function(elem){
  3682. return "file" === elem.type;
  3683. },
  3684. password: function(elem){
  3685. return "password" === elem.type;
  3686. },
  3687. submit: function(elem){
  3688. return "submit" === elem.type;
  3689. },
  3690. image: function(elem){
  3691. return "image" === elem.type;
  3692. },
  3693. reset: function(elem){
  3694. return "reset" === elem.type;
  3695. },
  3696. button: function(elem){
  3697. return "button" === elem.type || elem.nodeName.toUpperCase() === "BUTTON";
  3698. },
  3699. input: function(elem){
  3700. return /input|select|textarea|button/i.test(elem.nodeName);
  3701. }
  3702. },
  3703. setFilters: {
  3704. first: function(elem, i){
  3705. return i === 0;
  3706. },
  3707. last: function(elem, i, match, array){
  3708. return i === array.length - 1;
  3709. },
  3710. even: function(elem, i){
  3711. return i % 2 === 0;
  3712. },
  3713. odd: function(elem, i){
  3714. return i % 2 === 1;
  3715. },
  3716. lt: function(elem, i, match){
  3717. return i < match[3] - 0;
  3718. },
  3719. gt: function(elem, i, match){
  3720. return i > match[3] - 0;
  3721. },
  3722. nth: function(elem, i, match){
  3723. return match[3] - 0 == i;
  3724. },
  3725. eq: function(elem, i, match){
  3726. return match[3] - 0 == i;
  3727. }
  3728. },
  3729. filter: {
  3730. PSEUDO: function(elem, match, i, array){
  3731. var name = match[1], filter = Expr.filters[ name ];
  3732. if ( filter ) {
  3733. return filter( elem, i, match, array );
  3734. } else if ( name === "contains" ) {
  3735. return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
  3736. } else if ( name === "not" ) {
  3737. var not = match[3];
  3738. for ( var i = 0, l = not.length; i < l; i++ ) {
  3739. if ( not[i] === elem ) {
  3740. return false;
  3741. }
  3742. }
  3743. return true;
  3744. }
  3745. },
  3746. CHILD: function(elem, match){
  3747. var type = match[1], node = elem;
  3748. switch (type) {
  3749. case 'only':
  3750. case 'first':
  3751. while ( (node = node.previousSibling) ) {
  3752. if ( node.nodeType === 1 ) return false;
  3753. }
  3754. if ( type == 'first') return true;
  3755. node = elem;
  3756. case 'last':
  3757. while ( (node = node.nextSibling) ) {
  3758. if ( node.nodeType === 1 ) return false;
  3759. }
  3760. return true;
  3761. case 'nth':
  3762. var first = match[2], last = match[3];
  3763. if ( first == 1 && last == 0 ) {
  3764. return true;
  3765. }
  3766. var doneName = match[0],
  3767. parent = elem.parentNode;
  3768. if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) {
  3769. var count = 0;
  3770. for ( node = parent.firstChild; node; node = node.nextSibling ) {
  3771. if ( node.nodeType === 1 ) {
  3772. node.nodeIndex = ++count;
  3773. }
  3774. }
  3775. parent.sizcache = doneName;
  3776. }
  3777. var diff = elem.nodeIndex - last;
  3778. if ( first == 0 ) {
  3779. return diff == 0;
  3780. } else {
  3781. return ( diff % first == 0 && diff / first >= 0 );
  3782. }
  3783. }
  3784. },
  3785. ID: function(elem, match){
  3786. return elem.nodeType === 1 && elem.getAttribute("id") === match;
  3787. },
  3788. TAG: function(elem, match){
  3789. return (match === "*" && elem.nodeType === 1) || elem.nodeName === match;
  3790. },
  3791. CLASS: function(elem, match){
  3792. return (" " + (elem.className || elem.getAttribute("class")) + " ")
  3793. .indexOf( match ) > -1;
  3794. },
  3795. ATTR: function(elem, match){
  3796. var name = match[1],
  3797. result = Expr.attrHandle[ name ] ?
  3798. Expr.attrHandle[ name ]( elem ) :
  3799. elem[ name ] != null ?
  3800. elem[ name ] :
  3801. elem.getAttribute( name ),
  3802. value = result + "",
  3803. type = match[2],
  3804. check = match[4];
  3805. return result == null ?
  3806. type === "!=" :
  3807. type === "=" ?
  3808. value === check :
  3809. type === "*=" ?
  3810. value.indexOf(check) >= 0 :
  3811. type === "~=" ?
  3812. (" " + value + " ").indexOf(check) >= 0 :
  3813. !check ?
  3814. value && result !== false :
  3815. type === "!=" ?
  3816. value != check :
  3817. type === "^=" ?
  3818. value.indexOf(check) === 0 :
  3819. type === "$=" ?
  3820. value.substr(value.length - check.length) === check :
  3821. type === "|=" ?
  3822. value === check || value.substr(0, check.length + 1) === check + "-" :
  3823. false;
  3824. },
  3825. POS: function(elem, match, i, array){
  3826. var name = match[2], filter = Expr.setFilters[ name ];
  3827. if ( filter ) {
  3828. return filter( elem, i, match, array );
  3829. }
  3830. }
  3831. }
  3832. };
  3833. var origPOS = Expr.match.POS;
  3834. for ( var type in Expr.match ) {
  3835. Expr.match[ type ] = new RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source );
  3836. Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source );
  3837. }
  3838. var makeArray = function(array, results) {
  3839. array = Array.prototype.slice.call( array, 0 );
  3840. if ( results ) {
  3841. results.push.apply( results, array );
  3842. return results;
  3843. }
  3844. return array;
  3845. };
  3846. try {
  3847. Array.prototype.slice.call( document.documentElement.childNodes, 0 );
  3848. } catch(e){
  3849. makeArray = function(array, results) {
  3850. var ret = results || [];
  3851. if ( toString.call(array) === "[object Array]" ) {
  3852. Array.prototype.push.apply( ret, array );
  3853. } else {
  3854. if ( typeof array.length === "number" ) {
  3855. for ( var i = 0, l = array.length; i < l; i++ ) {
  3856. ret.push( array[i] );
  3857. }
  3858. } else {
  3859. for ( var i = 0; array[i]; i++ ) {
  3860. ret.push( array[i] );
  3861. }
  3862. }
  3863. }
  3864. return ret;
  3865. };
  3866. }
  3867. var sortOrder;
  3868. if ( document.documentElement.compareDocumentPosition ) {
  3869. sortOrder = function( a, b ) {
  3870. if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
  3871. if ( a == b ) {
  3872. hasDuplicate = true;
  3873. }
  3874. return 0;
  3875. }
  3876. var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1;
  3877. if ( ret === 0 ) {
  3878. hasDuplicate = true;
  3879. }
  3880. return ret;
  3881. };
  3882. } else if ( "sourceIndex" in document.documentElement ) {
  3883. sortOrder = function( a, b ) {
  3884. if ( !a.sourceIndex || !b.sourceIndex ) {
  3885. if ( a == b ) {
  3886. hasDuplicate = true;
  3887. }
  3888. return 0;
  3889. }
  3890. var ret = a.sourceIndex - b.sourceIndex;
  3891. if ( ret === 0 ) {
  3892. hasDuplicate = true;
  3893. }
  3894. return ret;
  3895. };
  3896. } else if ( document.createRange ) {
  3897. sortOrder = function( a, b ) {
  3898. if ( !a.ownerDocument || !b.ownerDocument ) {
  3899. if ( a == b ) {
  3900. hasDuplicate = true;
  3901. }
  3902. return 0;
  3903. }
  3904. var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange();
  3905. aRange.setStart(a, 0);
  3906. aRange.setEnd(a, 0);
  3907. bRange.setStart(b, 0);
  3908. bRange.setEnd(b, 0);
  3909. var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange);
  3910. if ( ret === 0 ) {
  3911. hasDuplicate = true;
  3912. }
  3913. return ret;
  3914. };
  3915. }
  3916. (function(){
  3917. var form = document.createElement("div"),
  3918. id = "script" + (new Date).getTime();
  3919. form.innerHTML = "<a name='" + id + "'/>";
  3920. var root = document.documentElement;
  3921. root.insertBefore( form, root.firstChild );
  3922. if ( !!document.getElementById( id ) ) {
  3923. Expr.find.ID = function(match, context, isXML){
  3924. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  3925. var m = context.getElementById(match[1]);
  3926. return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
  3927. }
  3928. };
  3929. Expr.filter.ID = function(elem, match){
  3930. var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
  3931. return elem.nodeType === 1 && node && node.nodeValue === match;
  3932. };
  3933. }
  3934. root.removeChild( form );
  3935. root = form = null; // release memory in IE
  3936. })();
  3937. (function(){
  3938. var div = document.createElement("div");
  3939. div.appendChild( document.createComment("") );
  3940. if ( div.getElementsByTagName("*").length > 0 ) {
  3941. Expr.find.TAG = function(match, context){
  3942. var results = context.getElementsByTagName(match[1]);
  3943. if ( match[1] === "*" ) {
  3944. var tmp = [];
  3945. for ( var i = 0; results[i]; i++ ) {
  3946. if ( results[i].nodeType === 1 ) {
  3947. tmp.push( results[i] );
  3948. }
  3949. }
  3950. results = tmp;
  3951. }
  3952. return results;
  3953. };
  3954. }
  3955. div.innerHTML = "<a href='#'></a>";
  3956. if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
  3957. div.firstChild.getAttribute("href") !== "#" ) {
  3958. Expr.attrHandle.href = function(elem){
  3959. return elem.getAttribute("href", 2);
  3960. };
  3961. }
  3962. div = null; // release memory in IE
  3963. })();
  3964. if ( document.querySelectorAll ) (function(){
  3965. var oldSizzle = Sizzle, div = document.createElement("div");
  3966. div.innerHTML = "<p class='TEST'></p>";
  3967. if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
  3968. return;
  3969. }
  3970. Sizzle = function(query, context, extra, seed){
  3971. context = context || document;
  3972. if ( !seed && context.nodeType === 9 && !isXML(context) ) {
  3973. try {
  3974. return makeArray( context.querySelectorAll(query), extra );
  3975. } catch(e){}
  3976. }
  3977. return oldSizzle(query, context, extra, seed);
  3978. };
  3979. for ( var prop in oldSizzle ) {
  3980. Sizzle[ prop ] = oldSizzle[ prop ];
  3981. }
  3982. div = null; // release memory in IE
  3983. })();
  3984. if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){
  3985. var div = document.createElement("div");
  3986. div.innerHTML = "<div class='test e'></div><div class='test'></div>";
  3987. if ( div.getElementsByClassName("e").length === 0 )
  3988. return;
  3989. div.lastChild.className = "e";
  3990. if ( div.getElementsByClassName("e").length === 1 )
  3991. return;
  3992. Expr.order.splice(1, 0, "CLASS");
  3993. Expr.find.CLASS = function(match, context, isXML) {
  3994. if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
  3995. return context.getElementsByClassName(match[1]);
  3996. }
  3997. };
  3998. div = null; // release memory in IE
  3999. })();
  4000. function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  4001. var sibDir = dir == "previousSibling" && !isXML;
  4002. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  4003. var elem = checkSet[i];
  4004. if ( elem ) {
  4005. if ( sibDir && elem.nodeType === 1 ){
  4006. elem.sizcache = doneName;
  4007. elem.sizset = i;
  4008. }
  4009. elem = elem[dir];
  4010. var match = false;
  4011. while ( elem ) {
  4012. if ( elem.sizcache === doneName ) {
  4013. match = checkSet[elem.sizset];
  4014. break;
  4015. }
  4016. if ( elem.nodeType === 1 && !isXML ){
  4017. elem.sizcache = doneName;
  4018. elem.sizset = i;
  4019. }
  4020. if ( elem.nodeName === cur ) {
  4021. match = elem;
  4022. break;
  4023. }
  4024. elem = elem[dir];
  4025. }
  4026. checkSet[i] = match;
  4027. }
  4028. }
  4029. }
  4030. function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  4031. var sibDir = dir == "previousSibling" && !isXML;
  4032. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  4033. var elem = checkSet[i];
  4034. if ( elem ) {
  4035. if ( sibDir && elem.nodeType === 1 ) {
  4036. elem.sizcache = doneName;
  4037. elem.sizset = i;
  4038. }
  4039. elem = elem[dir];
  4040. var match = false;
  4041. while ( elem ) {
  4042. if ( elem.sizcache === doneName ) {
  4043. match = checkSet[elem.sizset];
  4044. break;
  4045. }
  4046. if ( elem.nodeType === 1 ) {
  4047. if ( !isXML ) {
  4048. elem.sizcache = doneName;
  4049. elem.sizset = i;
  4050. }
  4051. if ( typeof cur !== "string" ) {
  4052. if ( elem === cur ) {
  4053. match = true;
  4054. break;
  4055. }
  4056. } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
  4057. match = elem;
  4058. break;
  4059. }
  4060. }
  4061. elem = elem[dir];
  4062. }
  4063. checkSet[i] = match;
  4064. }
  4065. }
  4066. }
  4067. var contains = document.compareDocumentPosition ? function(a, b){
  4068. return a.compareDocumentPosition(b) & 16;
  4069. } : function(a, b){
  4070. return a !== b && (a.contains ? a.contains(b) : true);
  4071. };
  4072. var isXML = function(elem){
  4073. return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
  4074. !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML";
  4075. };
  4076. var posProcess = function(selector, context){
  4077. var tmpSet = [], later = "", match,
  4078. root = context.nodeType ? [context] : context;
  4079. while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
  4080. later += match[0];
  4081. selector = selector.replace( Expr.match.PSEUDO, "" );
  4082. }
  4083. selector = Expr.relative[selector] ? selector + "*" : selector;
  4084. for ( var i = 0, l = root.length; i < l; i++ ) {
  4085. Sizzle( selector, root[i], tmpSet );
  4086. }
  4087. return Sizzle.filter( later, tmpSet );
  4088. };
  4089. window.Sizzle = Sizzle;
  4090. })();
  4091. ;(function(engine) {
  4092. var extendElements = Prototype.Selector.extendElements;
  4093. function select(selector, scope) {
  4094. return extendElements(engine(selector, scope || document));
  4095. }
  4096. function match(element, selector) {
  4097. return engine.matches(selector, [element]).length == 1;
  4098. }
  4099. Prototype.Selector.engine = engine;
  4100. Prototype.Selector.select = select;
  4101. Prototype.Selector.match = match;
  4102. })(Sizzle);
  4103. window.Sizzle = Prototype._original_property;
  4104. delete Prototype._original_property;
  4105. var Form = {
  4106. reset: function(form) {
  4107. form = $(form);
  4108. form.reset();
  4109. return form;
  4110. },
  4111. serializeElements: function(elements, options) {
  4112. if (typeof options != 'object') options = { hash: !!options };
  4113. else if (Object.isUndefined(options.hash)) options.hash = true;
  4114. var key, value, submitted = false, submit = options.submit, accumulator, initial;
  4115. if (options.hash) {
  4116. initial = {};
  4117. accumulator = function(result, key, value) {
  4118. if (key in result) {
  4119. if (!Object.isArray(result[key])) result[key] = [result[key]];
  4120. result[key].push(value);
  4121. } else result[key] = value;
  4122. return result;
  4123. };
  4124. } else {
  4125. initial = '';
  4126. accumulator = function(result, key, value) {
  4127. return result + (result ? '&' : '') + encodeURIComponent(key) + '=' + encodeURIComponent(value);
  4128. }
  4129. }
  4130. return elements.inject(initial, function(result, element) {
  4131. if (!element.disabled && element.name) {
  4132. key = element.name; value = $(element).getValue();
  4133. if (value != null && element.type != 'file' && (element.type != 'submit' || (!submitted &&
  4134. submit !== false && (!submit || key == submit) && (submitted = true)))) {
  4135. result = accumulator(result, key, value);
  4136. }
  4137. }
  4138. return result;
  4139. });
  4140. }
  4141. };
  4142. Form.Methods = {
  4143. serialize: function(form, options) {
  4144. return Form.serializeElements(Form.getElements(form), options);
  4145. },
  4146. getElements: function(form) {
  4147. var elements = $(form).getElementsByTagName('*'),
  4148. element,
  4149. arr = [ ],
  4150. serializers = Form.Element.Serializers;
  4151. for (var i = 0; element = elements[i]; i++) {
  4152. arr.push(element);
  4153. }
  4154. return arr.inject([], function(elements, child) {
  4155. if (serializers[child.tagName.toLowerCase()])
  4156. elements.push(Element.extend(child));
  4157. return elements;
  4158. })
  4159. },
  4160. getInputs: function(form, typeName, name) {
  4161. form = $(form);
  4162. var inputs = form.getElementsByTagName('input');
  4163. if (!typeName && !name) return $A(inputs).map(Element.extend);
  4164. for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
  4165. var input = inputs[i];
  4166. if ((typeName && input.type != typeName) || (name && input.name != name))
  4167. continue;
  4168. matchingInputs.push(Element.extend(input));
  4169. }
  4170. return matchingInputs;
  4171. },
  4172. disable: function(form) {
  4173. form = $(form);
  4174. Form.getElements(form).invoke('disable');
  4175. return form;
  4176. },
  4177. enable: function(form) {
  4178. form = $(form);
  4179. Form.getElements(form).invoke('enable');
  4180. return form;
  4181. },
  4182. findFirstElement: function(form) {
  4183. var elements = $(form).getElements().findAll(function(element) {
  4184. return 'hidden' != element.type && !element.disabled;
  4185. });
  4186. var firstByIndex = elements.findAll(function(element) {
  4187. return element.hasAttribute('tabIndex') && element.tabIndex >= 0;
  4188. }).sortBy(function(element) { return element.tabIndex }).first();
  4189. return firstByIndex ? firstByIndex : elements.find(function(element) {
  4190. return /^(?:input|select|textarea)$/i.test(element.tagName);
  4191. });
  4192. },
  4193. focusFirstElement: function(form) {
  4194. form = $(form);
  4195. var element = form.findFirstElement();
  4196. if (element) element.activate();
  4197. return form;
  4198. },
  4199. request: function(form, options) {
  4200. form = $(form), options = Object.clone(options || { });
  4201. var params = options.parameters, action = form.readAttribute('action') || '';
  4202. if (action.blank()) action = window.location.href;
  4203. options.parameters = form.serialize(true);
  4204. if (params) {
  4205. if (Object.isString(params)) params = params.toQueryParams();
  4206. Object.extend(options.parameters, params);
  4207. }
  4208. if (form.hasAttribute('method') && !options.method)
  4209. options.method = form.method;
  4210. return new Ajax.Request(action, options);
  4211. }
  4212. };
  4213. /*--------------------------------------------------------------------------*/
  4214. Form.Element = {
  4215. focus: function(element) {
  4216. $(element).focus();
  4217. return element;
  4218. },
  4219. select: function(element) {
  4220. $(element).select();
  4221. return element;
  4222. }
  4223. };
  4224. Form.Element.Methods = {
  4225. serialize: function(element) {
  4226. element = $(element);
  4227. if (!element.disabled && element.name) {
  4228. var value = element.getValue();
  4229. if (value != undefined) {
  4230. var pair = { };
  4231. pair[element.name] = value;
  4232. return Object.toQueryString(pair);
  4233. }
  4234. }
  4235. return '';
  4236. },
  4237. getValue: function(element) {
  4238. element = $(element);
  4239. var method = element.tagName.toLowerCase();
  4240. return Form.Element.Serializers[method](element);
  4241. },
  4242. setValue: function(element, value) {
  4243. element = $(element);
  4244. var method = element.tagName.toLowerCase();
  4245. Form.Element.Serializers[method](element, value);
  4246. return element;
  4247. },
  4248. clear: function(element) {
  4249. $(element).value = '';
  4250. return element;
  4251. },
  4252. present: function(element) {
  4253. return $(element).value != '';
  4254. },
  4255. activate: function(element) {
  4256. element = $(element);
  4257. try {
  4258. element.focus();
  4259. if (element.select && (element.tagName.toLowerCase() != 'input' ||
  4260. !(/^(?:button|reset|submit)$/i.test(element.type))))
  4261. element.select();
  4262. } catch (e) { }
  4263. return element;
  4264. },
  4265. disable: function(element) {
  4266. element = $(element);
  4267. element.disabled = true;
  4268. return element;
  4269. },
  4270. enable: function(element) {
  4271. element = $(element);
  4272. element.disabled = false;
  4273. return element;
  4274. }
  4275. };
  4276. /*--------------------------------------------------------------------------*/
  4277. var Field = Form.Element;
  4278. var $F = Form.Element.Methods.getValue;
  4279. /*--------------------------------------------------------------------------*/
  4280. Form.Element.Serializers = (function() {
  4281. function input(element, value) {
  4282. switch (element.type.toLowerCase()) {
  4283. case 'checkbox':
  4284. case 'radio':
  4285. return inputSelector(element, value);
  4286. default:
  4287. return valueSelector(element, value);
  4288. }
  4289. }
  4290. function inputSelector(element, value) {
  4291. if (Object.isUndefined(value))
  4292. return element.checked ? element.value : null;
  4293. else element.checked = !!value;
  4294. }
  4295. function valueSelector(element, value) {
  4296. if (Object.isUndefined(value)) return element.value;
  4297. else element.value = value;
  4298. }
  4299. function select(element, value) {
  4300. if (Object.isUndefined(value))
  4301. return (element.type === 'select-one' ? selectOne : selectMany)(element);
  4302. var opt, currentValue, single = !Object.isArray(value);
  4303. for (var i = 0, length = element.length; i < length; i++) {
  4304. opt = element.options[i];
  4305. currentValue = this.optionValue(opt);
  4306. if (single) {
  4307. if (currentValue == value) {
  4308. opt.selected = true;
  4309. return;
  4310. }
  4311. }
  4312. else opt.selected = value.include(currentValue);
  4313. }
  4314. }
  4315. function selectOne(element) {
  4316. var index = element.selectedIndex;
  4317. return index >= 0 ? optionValue(element.options[index]) : null;
  4318. }
  4319. function selectMany(element) {
  4320. var values, length = element.length;
  4321. if (!length) return null;
  4322. for (var i = 0, values = []; i < length; i++) {
  4323. var opt = element.options[i];
  4324. if (opt.selected) values.push(optionValue(opt));
  4325. }
  4326. return values;
  4327. }
  4328. function optionValue(opt) {
  4329. return Element.hasAttribute(opt, 'value') ? opt.value : opt.text;
  4330. }
  4331. return {
  4332. input: input,
  4333. inputSelector: inputSelector,
  4334. textarea: valueSelector,
  4335. select: select,
  4336. selectOne: selectOne,
  4337. selectMany: selectMany,
  4338. optionValue: optionValue,
  4339. button: valueSelector
  4340. };
  4341. })();
  4342. /*--------------------------------------------------------------------------*/
  4343. Abstract.TimedObserver = Class.create(PeriodicalExecuter, {
  4344. initialize: function($super, element, frequency, callback) {
  4345. $super(callback, frequency);
  4346. this.element = $(element);
  4347. this.lastValue = this.getValue();
  4348. },
  4349. execute: function() {
  4350. var value = this.getValue();
  4351. if (Object.isString(this.lastValue) && Object.isString(value) ?
  4352. this.lastValue != value : String(this.lastValue) != String(value)) {
  4353. this.callback(this.element, value);
  4354. this.lastValue = value;
  4355. }
  4356. }
  4357. });
  4358. Form.Element.Observer = Class.create(Abstract.TimedObserver, {
  4359. getValue: function() {
  4360. return Form.Element.getValue(this.element);
  4361. }
  4362. });
  4363. Form.Observer = Class.create(Abstract.TimedObserver, {
  4364. getValue: function() {
  4365. return Form.serialize(this.element);
  4366. }
  4367. });
  4368. /*--------------------------------------------------------------------------*/
  4369. Abstract.EventObserver = Class.create({
  4370. initialize: function(element, callback) {
  4371. this.element = $(element);
  4372. this.callback = callback;
  4373. this.lastValue = this.getValue();
  4374. if (this.element.tagName.toLowerCase() == 'form')
  4375. this.registerFormCallbacks();
  4376. else
  4377. this.registerCallback(this.element);
  4378. },
  4379. onElementEvent: function() {
  4380. var value = this.getValue();
  4381. if (this.lastValue != value) {
  4382. this.callback(this.element, value);
  4383. this.lastValue = value;
  4384. }
  4385. },
  4386. registerFormCallbacks: function() {
  4387. Form.getElements(this.element).each(this.registerCallback, this);
  4388. },
  4389. registerCallback: function(element) {
  4390. if (element.type) {
  4391. switch (element.type.toLowerCase()) {
  4392. case 'checkbox':
  4393. case 'radio':
  4394. Event.observe(element, 'click', this.onElementEvent.bind(this));
  4395. break;
  4396. default:
  4397. Event.observe(element, 'change', this.onElementEvent.bind(this));
  4398. break;
  4399. }
  4400. }
  4401. }
  4402. });
  4403. Form.Element.EventObserver = Class.create(Abstract.EventObserver, {
  4404. getValue: function() {
  4405. return Form.Element.getValue(this.element);
  4406. }
  4407. });
  4408. Form.EventObserver = Class.create(Abstract.EventObserver, {
  4409. getValue: function() {
  4410. return Form.serialize(this.element);
  4411. }
  4412. });
  4413. (function() {
  4414. var Event = {
  4415. KEY_BACKSPACE: 8,
  4416. KEY_TAB: 9,
  4417. KEY_RETURN: 13,
  4418. KEY_ESC: 27,
  4419. KEY_LEFT: 37,
  4420. KEY_UP: 38,
  4421. KEY_RIGHT: 39,
  4422. KEY_DOWN: 40,
  4423. KEY_DELETE: 46,
  4424. KEY_HOME: 36,
  4425. KEY_END: 35,
  4426. KEY_PAGEUP: 33,
  4427. KEY_PAGEDOWN: 34,
  4428. KEY_INSERT: 45,
  4429. cache: {}
  4430. };
  4431. var docEl = document.documentElement;
  4432. var MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED = 'onmouseenter' in docEl
  4433. && 'onmouseleave' in docEl;
  4434. var isIELegacyEvent = function(event) { return false; };
  4435. if (window.attachEvent) {
  4436. if (window.addEventListener) {
  4437. isIELegacyEvent = function(event) {
  4438. return !(event instanceof window.Event);
  4439. };
  4440. } else {
  4441. isIELegacyEvent = function(event) { return true; };
  4442. }
  4443. }
  4444. var _isButton;
  4445. function _isButtonForDOMEvents(event, code) {
  4446. return event.which ? (event.which === code + 1) : (event.button === code);
  4447. }
  4448. var legacyButtonMap = { 0: 1, 1: 4, 2: 2 };
  4449. function _isButtonForLegacyEvents(event, code) {
  4450. return event.button === legacyButtonMap[code];
  4451. }
  4452. function _isButtonForWebKit(event, code) {
  4453. switch (code) {
  4454. case 0: return event.which == 1 && !event.metaKey;
  4455. case 1: return event.which == 2 || (event.which == 1 && event.metaKey);
  4456. case 2: return event.which == 3;
  4457. default: return false;
  4458. }
  4459. }
  4460. if (window.attachEvent) {
  4461. if (!window.addEventListener) {
  4462. _isButton = _isButtonForLegacyEvents;
  4463. } else {
  4464. _isButton = function(event, code) {
  4465. return isIELegacyEvent(event) ? _isButtonForLegacyEvents(event, code) :
  4466. _isButtonForDOMEvents(event, code);
  4467. }
  4468. }
  4469. } else if (Prototype.Browser.WebKit) {
  4470. _isButton = _isButtonForWebKit;
  4471. } else {
  4472. _isButton = _isButtonForDOMEvents;
  4473. }
  4474. function isLeftClick(event) { return _isButton(event, 0) }
  4475. function isMiddleClick(event) { return _isButton(event, 1) }
  4476. function isRightClick(event) { return _isButton(event, 2) }
  4477. function element(event) {
  4478. event = Event.extend(event);
  4479. var node = event.target, type = event.type,
  4480. currentTarget = event.currentTarget;
  4481. if (currentTarget && currentTarget.tagName) {
  4482. if (type === 'load' || type === 'error' ||
  4483. (type === 'click' && currentTarget.tagName.toLowerCase() === 'input'
  4484. && currentTarget.type === 'radio'))
  4485. node = currentTarget;
  4486. }
  4487. if (node.nodeType == Node.TEXT_NODE)
  4488. node = node.parentNode;
  4489. return Element.extend(node);
  4490. }
  4491. function findElement(event, expression) {
  4492. var element = Event.element(event);
  4493. if (!expression) return element;
  4494. while (element) {
  4495. if (Object.isElement(element) && Prototype.Selector.match(element, expression)) {
  4496. return Element.extend(element);
  4497. }
  4498. element = element.parentNode;
  4499. }
  4500. }
  4501. function pointer(event) {
  4502. return { x: pointerX(event), y: pointerY(event) };
  4503. }
  4504. function pointerX(event) {
  4505. var docElement = document.documentElement,
  4506. body = document.body || { scrollLeft: 0 };
  4507. return event.pageX || (event.clientX +
  4508. (docElement.scrollLeft || body.scrollLeft) -
  4509. (docElement.clientLeft || 0));
  4510. }
  4511. function pointerY(event) {
  4512. var docElement = document.documentElement,
  4513. body = document.body || { scrollTop: 0 };
  4514. return event.pageY || (event.clientY +
  4515. (docElement.scrollTop || body.scrollTop) -
  4516. (docElement.clientTop || 0));
  4517. }
  4518. function stop(event) {
  4519. Event.extend(event);
  4520. event.preventDefault();
  4521. event.stopPropagation();
  4522. event.stopped = true;
  4523. }
  4524. Event.Methods = {
  4525. isLeftClick: isLeftClick,
  4526. isMiddleClick: isMiddleClick,
  4527. isRightClick: isRightClick,
  4528. element: element,
  4529. findElement: findElement,
  4530. pointer: pointer,
  4531. pointerX: pointerX,
  4532. pointerY: pointerY,
  4533. stop: stop
  4534. };
  4535. var methods = Object.keys(Event.Methods).inject({ }, function(m, name) {
  4536. m[name] = Event.Methods[name].methodize();
  4537. return m;
  4538. });
  4539. if (window.attachEvent) {
  4540. function _relatedTarget(event) {
  4541. var element;
  4542. switch (event.type) {
  4543. case 'mouseover':
  4544. case 'mouseenter':
  4545. element = event.fromElement;
  4546. break;
  4547. case 'mouseout':
  4548. case 'mouseleave':
  4549. element = event.toElement;
  4550. break;
  4551. default:
  4552. return null;
  4553. }
  4554. return Element.extend(element);
  4555. }
  4556. var additionalMethods = {
  4557. stopPropagation: function() { this.cancelBubble = true },
  4558. preventDefault: function() { this.returnValue = false },
  4559. inspect: function() { return '[object Event]' }
  4560. };
  4561. Event.extend = function(event, element) {
  4562. if (!event) return false;
  4563. if (!isIELegacyEvent(event)) return event;
  4564. if (event._extendedByPrototype) return event;
  4565. event._extendedByPrototype = Prototype.emptyFunction;
  4566. var pointer = Event.pointer(event);
  4567. Object.extend(event, {
  4568. target: event.srcElement || element,
  4569. relatedTarget: _relatedTarget(event),
  4570. pageX: pointer.x,
  4571. pageY: pointer.y
  4572. });
  4573. Object.extend(event, methods);
  4574. Object.extend(event, additionalMethods);
  4575. return event;
  4576. };
  4577. } else {
  4578. Event.extend = Prototype.K;
  4579. }
  4580. if (window.addEventListener) {
  4581. Event.prototype = window.Event.prototype || document.createEvent('HTMLEvents').__proto__;
  4582. Object.extend(Event.prototype, methods);
  4583. }
  4584. function _createResponder(element, eventName, handler) {
  4585. var registry = Element.retrieve(element, 'prototype_event_registry');
  4586. if (Object.isUndefined(registry)) {
  4587. CACHE.push(element);
  4588. registry = Element.retrieve(element, 'prototype_event_registry', $H());
  4589. }
  4590. var respondersForEvent = registry.get(eventName);
  4591. if (Object.isUndefined(respondersForEvent)) {
  4592. respondersForEvent = [];
  4593. registry.set(eventName, respondersForEvent);
  4594. }
  4595. if (respondersForEvent.pluck('handler').include(handler)) return false;
  4596. var responder;
  4597. if (eventName.include(":")) {
  4598. responder = function(event) {
  4599. if (Object.isUndefined(event.eventName))
  4600. return false;
  4601. if (event.eventName !== eventName)
  4602. return false;
  4603. Event.extend(event, element);
  4604. handler.call(element, event);
  4605. };
  4606. } else {
  4607. if (!MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED &&
  4608. (eventName === "mouseenter" || eventName === "mouseleave")) {
  4609. if (eventName === "mouseenter" || eventName === "mouseleave") {
  4610. responder = function(event) {
  4611. Event.extend(event, element);
  4612. var parent = event.relatedTarget;
  4613. while (parent && parent !== element) {
  4614. try { parent = parent.parentNode; }
  4615. catch(e) { parent = element; }
  4616. }
  4617. if (parent === element) return;
  4618. handler.call(element, event);
  4619. };
  4620. }
  4621. } else {
  4622. responder = function(event) {
  4623. Event.extend(event, element);
  4624. handler.call(element, event);
  4625. };
  4626. }
  4627. }
  4628. responder.handler = handler;
  4629. respondersForEvent.push(responder);
  4630. return responder;
  4631. }
  4632. function _destroyCache() {
  4633. for (var i = 0, length = CACHE.length; i < length; i++) {
  4634. Event.stopObserving(CACHE[i]);
  4635. CACHE[i] = null;
  4636. }
  4637. }
  4638. var CACHE = [];
  4639. if (Prototype.Browser.IE)
  4640. window.attachEvent('onunload', _destroyCache);
  4641. if (Prototype.Browser.WebKit)
  4642. window.addEventListener('unload', Prototype.emptyFunction, false);
  4643. var _getDOMEventName = Prototype.K,
  4644. translations = { mouseenter: "mouseover", mouseleave: "mouseout" };
  4645. if (!MOUSEENTER_MOUSELEAVE_EVENTS_SUPPORTED) {
  4646. _getDOMEventName = function(eventName) {
  4647. return (translations[eventName] || eventName);
  4648. };
  4649. }
  4650. function observe(element, eventName, handler) {
  4651. element = $(element);
  4652. var responder = _createResponder(element, eventName, handler);
  4653. if (!responder) return element;
  4654. if (eventName.include(':')) {
  4655. if (element.addEventListener)
  4656. element.addEventListener("dataavailable", responder, false);
  4657. else {
  4658. element.attachEvent("ondataavailable", responder);
  4659. element.attachEvent("onlosecapture", responder);
  4660. }
  4661. } else {
  4662. var actualEventName = _getDOMEventName(eventName);
  4663. if (element.addEventListener)
  4664. element.addEventListener(actualEventName, responder, false);
  4665. else
  4666. element.attachEvent("on" + actualEventName, responder);
  4667. }
  4668. return element;
  4669. }
  4670. function stopObserving(element, eventName, handler) {
  4671. element = $(element);
  4672. var registry = Element.retrieve(element, 'prototype_event_registry');
  4673. if (!registry) return element;
  4674. if (!eventName) {
  4675. registry.each( function(pair) {
  4676. var eventName = pair.key;
  4677. stopObserving(element, eventName);
  4678. });
  4679. return element;
  4680. }
  4681. var responders = registry.get(eventName);
  4682. if (!responders) return element;
  4683. if (!handler) {
  4684. responders.each(function(r) {
  4685. stopObserving(element, eventName, r.handler);
  4686. });
  4687. return element;
  4688. }
  4689. var i = responders.length, responder;
  4690. while (i--) {
  4691. if (responders[i].handler === handler) {
  4692. responder = responders[i];
  4693. break;
  4694. }
  4695. }
  4696. if (!responder) return element;
  4697. if (eventName.include(':')) {
  4698. if (element.removeEventListener)
  4699. element.removeEventListener("dataavailable", responder, false);
  4700. else {
  4701. element.detachEvent("ondataavailable", responder);
  4702. element.detachEvent("onlosecapture", responder);
  4703. }
  4704. } else {
  4705. var actualEventName = _getDOMEventName(eventName);
  4706. if (element.removeEventListener)
  4707. element.removeEventListener(actualEventName, responder, false);
  4708. else
  4709. element.detachEvent('on' + actualEventName, responder);
  4710. }
  4711. registry.set(eventName, responders.without(responder));
  4712. return element;
  4713. }
  4714. function fire(element, eventName, memo, bubble) {
  4715. element = $(element);
  4716. if (Object.isUndefined(bubble))
  4717. bubble = true;
  4718. if (element == document && document.createEvent && !element.dispatchEvent)
  4719. element = document.documentElement;
  4720. var event;
  4721. if (document.createEvent) {
  4722. event = document.createEvent('HTMLEvents');
  4723. event.initEvent('dataavailable', bubble, true);
  4724. } else {
  4725. event = document.createEventObject();
  4726. event.eventType = bubble ? 'ondataavailable' : 'onlosecapture';
  4727. }
  4728. event.eventName = eventName;
  4729. event.memo = memo || { };
  4730. if (document.createEvent)
  4731. element.dispatchEvent(event);
  4732. else
  4733. element.fireEvent(event.eventType, event);
  4734. return Event.extend(event);
  4735. }
  4736. Event.Handler = Class.create({
  4737. initialize: function(element, eventName, selector, callback) {
  4738. this.element = $(element);
  4739. this.eventName = eventName;
  4740. this.selector = selector;
  4741. this.callback = callback;
  4742. this.handler = this.handleEvent.bind(this);
  4743. },
  4744. start: function() {
  4745. Event.observe(this.element, this.eventName, this.handler);
  4746. return this;
  4747. },
  4748. stop: function() {
  4749. Event.stopObserving(this.element, this.eventName, this.handler);
  4750. return this;
  4751. },
  4752. handleEvent: function(event) {
  4753. var element = Event.findElement(event, this.selector);
  4754. if (element) this.callback.call(this.element, event, element);
  4755. }
  4756. });
  4757. function on(element, eventName, selector, callback) {
  4758. element = $(element);
  4759. if (Object.isFunction(selector) && Object.isUndefined(callback)) {
  4760. callback = selector, selector = null;
  4761. }
  4762. return new Event.Handler(element, eventName, selector, callback).start();
  4763. }
  4764. Object.extend(Event, Event.Methods);
  4765. Object.extend(Event, {
  4766. fire: fire,
  4767. observe: observe,
  4768. stopObserving: stopObserving,
  4769. on: on
  4770. });
  4771. Element.addMethods({
  4772. fire: fire,
  4773. observe: observe,
  4774. stopObserving: stopObserving,
  4775. on: on
  4776. });
  4777. Object.extend(document, {
  4778. fire: fire.methodize(),
  4779. observe: observe.methodize(),
  4780. stopObserving: stopObserving.methodize(),
  4781. on: on.methodize(),
  4782. loaded: false
  4783. });
  4784. if (window.Event) Object.extend(window.Event, Event);
  4785. else window.Event = Event;
  4786. })();
  4787. (function() {
  4788. /* Support for the DOMContentLoaded event is based on work by Dan Webb,
  4789. Matthias Miller, Dean Edwards, John Resig, and Diego Perini. */
  4790. var timer;
  4791. function fireContentLoadedEvent() {
  4792. if (document.loaded) return;
  4793. if (timer) window.clearTimeout(timer);
  4794. document.loaded = true;
  4795. document.fire('dom:loaded');
  4796. }
  4797. function checkReadyState() {
  4798. if (document.readyState === 'complete') {
  4799. document.stopObserving('readystatechange', checkReadyState);
  4800. fireContentLoadedEvent();
  4801. }
  4802. }
  4803. function pollDoScroll() {
  4804. try { document.documentElement.doScroll('left'); }
  4805. catch(e) {
  4806. timer = pollDoScroll.defer();
  4807. return;
  4808. }
  4809. fireContentLoadedEvent();
  4810. }
  4811. if (document.addEventListener) {
  4812. document.addEventListener('DOMContentLoaded', fireContentLoadedEvent, false);
  4813. } else {
  4814. document.observe('readystatechange', checkReadyState);
  4815. if (window == top)
  4816. timer = pollDoScroll.defer();
  4817. }
  4818. Event.observe(window, 'load', fireContentLoadedEvent);
  4819. })();
  4820. Element.addMethods();
  4821. /*------------------------------- DEPRECATED -------------------------------*/
  4822. Hash.toQueryString = Object.toQueryString;
  4823. var Toggle = { display: Element.toggle };
  4824. Element.Methods.childOf = Element.Methods.descendantOf;
  4825. var Insertion = {
  4826. Before: function(element, content) {
  4827. return Element.insert(element, {before:content});
  4828. },
  4829. Top: function(element, content) {
  4830. return Element.insert(element, {top:content});
  4831. },
  4832. Bottom: function(element, content) {
  4833. return Element.insert(element, {bottom:content});
  4834. },
  4835. After: function(element, content) {
  4836. return Element.insert(element, {after:content});
  4837. }
  4838. };
  4839. var $continue = new Error('"throw $continue" is deprecated, use "return" instead');
  4840. var Position = {
  4841. includeScrollOffsets: false,
  4842. prepare: function() {
  4843. this.deltaX = window.pageXOffset
  4844. || document.documentElement.scrollLeft
  4845. || document.body.scrollLeft
  4846. || 0;
  4847. this.deltaY = window.pageYOffset
  4848. || document.documentElement.scrollTop
  4849. || document.body.scrollTop
  4850. || 0;
  4851. },
  4852. within: function(element, x, y) {
  4853. if (this.includeScrollOffsets)
  4854. return this.withinIncludingScrolloffsets(element, x, y);
  4855. this.xcomp = x;
  4856. this.ycomp = y;
  4857. this.offset = Element.cumulativeOffset(element);
  4858. return (y >= this.offset[1] &&
  4859. y < this.offset[1] + element.offsetHeight &&
  4860. x >= this.offset[0] &&
  4861. x < this.offset[0] + element.offsetWidth);
  4862. },
  4863. withinIncludingScrolloffsets: function(element, x, y) {
  4864. var offsetcache = Element.cumulativeScrollOffset(element);
  4865. this.xcomp = x + offsetcache[0] - this.deltaX;
  4866. this.ycomp = y + offsetcache[1] - this.deltaY;
  4867. this.offset = Element.cumulativeOffset(element);
  4868. return (this.ycomp >= this.offset[1] &&
  4869. this.ycomp < this.offset[1] + element.offsetHeight &&
  4870. this.xcomp >= this.offset[0] &&
  4871. this.xcomp < this.offset[0] + element.offsetWidth);
  4872. },
  4873. overlap: function(mode, element) {
  4874. if (!mode) return 0;
  4875. if (mode == 'vertical')
  4876. return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
  4877. element.offsetHeight;
  4878. if (mode == 'horizontal')
  4879. return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
  4880. element.offsetWidth;
  4881. },
  4882. cumulativeOffset: Element.Methods.cumulativeOffset,
  4883. positionedOffset: Element.Methods.positionedOffset,
  4884. absolutize: function(element) {
  4885. Position.prepare();
  4886. return Element.absolutize(element);
  4887. },
  4888. relativize: function(element) {
  4889. Position.prepare();
  4890. return Element.relativize(element);
  4891. },
  4892. realOffset: Element.Methods.cumulativeScrollOffset,
  4893. offsetParent: Element.Methods.getOffsetParent,
  4894. page: Element.Methods.viewportOffset,
  4895. clone: function(source, target, options) {
  4896. options = options || { };
  4897. return Element.clonePosition(target, source, options);
  4898. }
  4899. };
  4900. /*--------------------------------------------------------------------------*/
  4901. if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){
  4902. function iter(name) {
  4903. return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]";
  4904. }
  4905. instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ?
  4906. function(element, className) {
  4907. className = className.toString().strip();
  4908. var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className);
  4909. return cond ? document._getElementsByXPath('.//*' + cond, element) : [];
  4910. } : function(element, className) {
  4911. className = className.toString().strip();
  4912. var elements = [], classNames = (/\s/.test(className) ? $w(className) : null);
  4913. if (!classNames && !className) return elements;
  4914. var nodes = $(element).getElementsByTagName('*');
  4915. className = ' ' + className + ' ';
  4916. for (var i = 0, child, cn; child = nodes[i]; i++) {
  4917. if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||
  4918. (classNames && classNames.all(function(name) {
  4919. return !name.toString().blank() && cn.include(' ' + name + ' ');
  4920. }))))
  4921. elements.push(Element.extend(child));
  4922. }
  4923. return elements;
  4924. };
  4925. return function(className, parentElement) {
  4926. return $(parentElement || document.body).getElementsByClassName(className);
  4927. };
  4928. }(Element.Methods);
  4929. /*--------------------------------------------------------------------------*/
  4930. Element.ClassNames = Class.create();
  4931. Element.ClassNames.prototype = {
  4932. initialize: function(element) {
  4933. this.element = $(element);
  4934. },
  4935. _each: function(iterator) {
  4936. this.element.className.split(/\s+/).select(function(name) {
  4937. return name.length > 0;
  4938. })._each(iterator);
  4939. },
  4940. set: function(className) {
  4941. this.element.className = className;
  4942. },
  4943. add: function(classNameToAdd) {
  4944. if (this.include(classNameToAdd)) return;
  4945. this.set($A(this).concat(classNameToAdd).join(' '));
  4946. },
  4947. remove: function(classNameToRemove) {
  4948. if (!this.include(classNameToRemove)) return;
  4949. this.set($A(this).without(classNameToRemove).join(' '));
  4950. },
  4951. toString: function() {
  4952. return $A(this).join(' ');
  4953. }
  4954. };
  4955. Object.extend(Element.ClassNames.prototype, Enumerable);
  4956. /*--------------------------------------------------------------------------*/
  4957. (function() {
  4958. window.Selector = Class.create({
  4959. initialize: function(expression) {
  4960. this.expression = expression.strip();
  4961. },
  4962. findElements: function(rootElement) {
  4963. return Prototype.Selector.select(this.expression, rootElement);
  4964. },
  4965. match: function(element) {
  4966. return Prototype.Selector.match(element, this.expression);
  4967. },
  4968. toString: function() {
  4969. return this.expression;
  4970. },
  4971. inspect: function() {
  4972. return "#<Selector: " + this.expression + ">";
  4973. }
  4974. });
  4975. Object.extend(Selector, {
  4976. matchElements: function(elements, expression) {
  4977. var match = Prototype.Selector.match,
  4978. results = [];
  4979. for (var i = 0, length = elements.length; i < length; i++) {
  4980. var element = elements[i];
  4981. if (match(element, expression)) {
  4982. results.push(Element.extend(element));
  4983. }
  4984. }
  4985. return results;
  4986. },
  4987. findElement: function(elements, expression, index) {
  4988. index = index || 0;
  4989. var matchIndex = 0, element;
  4990. for (var i = 0, length = elements.length; i < length; i++) {
  4991. element = elements[i];
  4992. if (Prototype.Selector.match(element, expression) && index === matchIndex++) {
  4993. return Element.extend(element);
  4994. }
  4995. }
  4996. },
  4997. findChildElements: function(element, expressions) {
  4998. var selector = expressions.toArray().join(', ');
  4999. return Prototype.Selector.select(selector, element || document);
  5000. }
  5001. });
  5002. })();