events.js 469 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285
  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. })();
  5003. /*
  5004. * Really easy field validation with Prototype
  5005. * http://tetlaw.id.au/view/javascript/really-easy-field-validation
  5006. * Andrew Tetlaw
  5007. * Version 1.5.4.1 (2007-01-05)
  5008. *
  5009. * Copyright (c) 2007 Andrew Tetlaw
  5010. * Permission is hereby granted, free of charge, to any person
  5011. * obtaining a copy of this software and associated documentation
  5012. * files (the "Software"), to deal in the Software without
  5013. * restriction, including without limitation the rights to use, copy,
  5014. * modify, merge, publish, distribute, sublicense, and/or sell copies
  5015. * of the Software, and to permit persons to whom the Software is
  5016. * furnished to do so, subject to the following conditions:
  5017. *
  5018. * The above copyright notice and this permission notice shall be
  5019. * included in all copies or substantial portions of the Software.
  5020. *
  5021. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  5022. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  5023. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  5024. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  5025. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  5026. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  5027. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  5028. * SOFTWARE.
  5029. *
  5030. */
  5031. var Validator = Class.create();
  5032. Validator.prototype = {
  5033. initialize : function(className, error, test, options) {
  5034. if(typeof test == 'function'){
  5035. this.options = $H(options);
  5036. this._test = test;
  5037. } else {
  5038. this.options = $H(test);
  5039. this._test = function(){return true};
  5040. }
  5041. this.error = error || 'Validation failed.';
  5042. this.className = className;
  5043. },
  5044. test : function(v, elm) {
  5045. return (this._test(v,elm) && this.options.all(function(p){
  5046. return Validator.methods[p.key] ? Validator.methods[p.key](v,elm,p.value) : true;
  5047. }));
  5048. }
  5049. }
  5050. Validator.methods = {
  5051. pattern : function(v,elm,opt) {return Validation.get('IsEmpty').test(v) || opt.test(v)},
  5052. minLength : function(v,elm,opt) {return v.length >= opt},
  5053. maxLength : function(v,elm,opt) {return v.length <= opt},
  5054. min : function(v,elm,opt) {return v >= parseFloat(opt)},
  5055. max : function(v,elm,opt) {return v <= parseFloat(opt)},
  5056. notOneOf : function(v,elm,opt) {return $A(opt).all(function(value) {
  5057. return v != value;
  5058. })},
  5059. oneOf : function(v,elm,opt) {return $A(opt).any(function(value) {
  5060. return v == value;
  5061. })},
  5062. is : function(v,elm,opt) {return v == opt},
  5063. isNot : function(v,elm,opt) {return v != opt},
  5064. equalToField : function(v,elm,opt) {return v == $F(opt)},
  5065. notEqualToField : function(v,elm,opt) {return v != $F(opt)},
  5066. include : function(v,elm,opt) {return $A(opt).all(function(value) {
  5067. return Validation.get(value).test(v,elm);
  5068. })}
  5069. }
  5070. var Validation = Class.create();
  5071. Validation.defaultOptions = {
  5072. onSubmit : true,
  5073. stopOnFirst : false,
  5074. immediate : false,
  5075. focusOnError : true,
  5076. useTitles : false,
  5077. addClassNameToContainer: false,
  5078. containerClassName: '.input-box',
  5079. onFormValidate : function(result, form) {},
  5080. onElementValidate : function(result, elm) {}
  5081. };
  5082. Validation.prototype = {
  5083. initialize : function(form, options){
  5084. this.form = $(form);
  5085. if (!this.form) {
  5086. return;
  5087. }
  5088. this.options = Object.extend({
  5089. onSubmit : Validation.defaultOptions.onSubmit,
  5090. stopOnFirst : Validation.defaultOptions.stopOnFirst,
  5091. immediate : Validation.defaultOptions.immediate,
  5092. focusOnError : Validation.defaultOptions.focusOnError,
  5093. useTitles : Validation.defaultOptions.useTitles,
  5094. onFormValidate : Validation.defaultOptions.onFormValidate,
  5095. onElementValidate : Validation.defaultOptions.onElementValidate
  5096. }, options || {});
  5097. if(this.options.onSubmit) Event.observe(this.form,'submit',this.onSubmit.bind(this),false);
  5098. if(this.options.immediate) {
  5099. Form.getElements(this.form).each(function(input) { // Thanks Mike!
  5100. if (input.tagName.toLowerCase() == 'select') {
  5101. Event.observe(input, 'blur', this.onChange.bindAsEventListener(this));
  5102. }
  5103. if (input.type.toLowerCase() == 'radio' || input.type.toLowerCase() == 'checkbox') {
  5104. Event.observe(input, 'click', this.onChange.bindAsEventListener(this));
  5105. } else {
  5106. Event.observe(input, 'change', this.onChange.bindAsEventListener(this));
  5107. }
  5108. }, this);
  5109. }
  5110. },
  5111. onChange : function (ev) {
  5112. Validation.isOnChange = true;
  5113. Validation.validate(Event.element(ev),{
  5114. useTitle : this.options.useTitles,
  5115. onElementValidate : this.options.onElementValidate
  5116. });
  5117. Validation.isOnChange = false;
  5118. },
  5119. onSubmit : function(ev){
  5120. if(!this.validate()) Event.stop(ev);
  5121. },
  5122. validate : function() {
  5123. var result = false;
  5124. var useTitles = this.options.useTitles;
  5125. var callback = this.options.onElementValidate;
  5126. try {
  5127. if(this.options.stopOnFirst) {
  5128. result = Form.getElements(this.form).all(function(elm) {
  5129. if (elm.hasClassName('local-validation') && !this.isElementInForm(elm, this.form)) {
  5130. return true;
  5131. }
  5132. return Validation.validate(elm,{useTitle : useTitles, onElementValidate : callback});
  5133. }, this);
  5134. } else {
  5135. result = Form.getElements(this.form).collect(function(elm) {
  5136. if (elm.hasClassName('local-validation') && !this.isElementInForm(elm, this.form)) {
  5137. return true;
  5138. }
  5139. return Validation.validate(elm,{useTitle : useTitles, onElementValidate : callback});
  5140. }, this).all();
  5141. }
  5142. } catch (e) {
  5143. }
  5144. if(!result && this.options.focusOnError) {
  5145. try{
  5146. Form.getElements(this.form).findAll(function(elm){return $(elm).hasClassName('validation-failed')}).first().focus()
  5147. }
  5148. catch(e){
  5149. }
  5150. }
  5151. this.options.onFormValidate(result, this.form);
  5152. return result;
  5153. },
  5154. reset : function() {
  5155. Form.getElements(this.form).each(Validation.reset);
  5156. },
  5157. isElementInForm : function(elm, form) {
  5158. var domForm = elm.up('form');
  5159. if (domForm == form) {
  5160. return true;
  5161. }
  5162. return false;
  5163. }
  5164. }
  5165. Object.extend(Validation, {
  5166. validate : function(elm, options){
  5167. options = Object.extend({
  5168. useTitle : false,
  5169. onElementValidate : function(result, elm) {}
  5170. }, options || {});
  5171. elm = $(elm);
  5172. var cn = $w(elm.className);
  5173. return result = cn.all(function(value) {
  5174. var test = Validation.test(value,elm,options.useTitle);
  5175. options.onElementValidate(test, elm);
  5176. return test;
  5177. });
  5178. },
  5179. insertAdvice : function(elm, advice){
  5180. var container = $(elm).up('.field-row');
  5181. if(container){
  5182. Element.insert(container, {after: advice});
  5183. } else if (elm.up('td.value')) {
  5184. elm.up('td.value').insert({bottom: advice});
  5185. } else if (elm.advaiceContainer && $(elm.advaiceContainer)) {
  5186. $(elm.advaiceContainer).update(advice);
  5187. }
  5188. else {
  5189. switch (elm.type.toLowerCase()) {
  5190. case 'checkbox':
  5191. case 'radio':
  5192. var p = elm.parentNode;
  5193. if(p) {
  5194. Element.insert(p, {'bottom': advice});
  5195. } else {
  5196. Element.insert(elm, {'after': advice});
  5197. }
  5198. break;
  5199. default:
  5200. Element.insert(elm, {'after': advice});
  5201. }
  5202. }
  5203. },
  5204. showAdvice : function(elm, advice, adviceName){
  5205. if(!elm.advices){
  5206. elm.advices = new Hash();
  5207. }
  5208. else{
  5209. elm.advices.each(function(pair){
  5210. if (!advice || pair.value.id != advice.id) {
  5211. // hide non-current advice after delay
  5212. this.hideAdvice(elm, pair.value);
  5213. }
  5214. }.bind(this));
  5215. }
  5216. elm.advices.set(adviceName, advice);
  5217. if(typeof Effect == 'undefined') {
  5218. advice.style.display = 'block';
  5219. } else {
  5220. if(!advice._adviceAbsolutize) {
  5221. new Effect.Appear(advice, {duration : 1 });
  5222. } else {
  5223. Position.absolutize(advice);
  5224. advice.show();
  5225. advice.setStyle({
  5226. 'top':advice._adviceTop,
  5227. 'left': advice._adviceLeft,
  5228. 'width': advice._adviceWidth,
  5229. 'z-index': 1000
  5230. });
  5231. advice.addClassName('advice-absolute');
  5232. }
  5233. }
  5234. },
  5235. hideAdvice : function(elm, advice){
  5236. if (advice != null) {
  5237. new Effect.Fade(advice, {duration : 1, afterFinishInternal : function() {advice.hide();}});
  5238. }
  5239. },
  5240. updateCallback : function(elm, status) {
  5241. if (typeof elm.callbackFunction != 'undefined') {
  5242. eval(elm.callbackFunction+'(\''+elm.id+'\',\''+status+'\')');
  5243. }
  5244. },
  5245. ajaxError : function(elm, errorMsg) {
  5246. var name = 'validate-ajax';
  5247. var advice = Validation.getAdvice(name, elm);
  5248. if (advice == null) {
  5249. advice = this.createAdvice(name, elm, false, errorMsg);
  5250. }
  5251. this.showAdvice(elm, advice, 'validate-ajax');
  5252. this.updateCallback(elm, 'failed');
  5253. elm.addClassName('validation-failed');
  5254. elm.addClassName('validate-ajax');
  5255. if (Validation.defaultOptions.addClassNameToContainer && Validation.defaultOptions.containerClassName != '') {
  5256. var container = elm.up(Validation.defaultOptions.containerClassName);
  5257. if (container && this.allowContainerClassName(elm)) {
  5258. container.removeClassName('validation-passed');
  5259. container.addClassName('validation-error');
  5260. }
  5261. }
  5262. },
  5263. allowContainerClassName: function (elm) {
  5264. if (elm.type == 'radio' || elm.type == 'checkbox') {
  5265. return elm.hasClassName('change-container-classname');
  5266. }
  5267. return true;
  5268. },
  5269. test : function(name, elm, useTitle) {
  5270. var v = Validation.get(name);
  5271. var prop = '__advice'+name.camelize();
  5272. try {
  5273. if(Validation.isVisible(elm) && !v.test($F(elm), elm)) {
  5274. //if(!elm[prop]) {
  5275. var advice = Validation.getAdvice(name, elm);
  5276. if (advice == null) {
  5277. advice = this.createAdvice(name, elm, useTitle);
  5278. }
  5279. this.showAdvice(elm, advice, name);
  5280. this.updateCallback(elm, 'failed');
  5281. //}
  5282. elm[prop] = 1;
  5283. if (!elm.advaiceContainer) {
  5284. elm.removeClassName('validation-passed');
  5285. elm.addClassName('validation-failed');
  5286. }
  5287. if (Validation.defaultOptions.addClassNameToContainer && Validation.defaultOptions.containerClassName != '') {
  5288. var container = elm.up(Validation.defaultOptions.containerClassName);
  5289. if (container && this.allowContainerClassName(elm)) {
  5290. container.removeClassName('validation-passed');
  5291. container.addClassName('validation-error');
  5292. }
  5293. }
  5294. return false;
  5295. } else {
  5296. var advice = Validation.getAdvice(name, elm);
  5297. this.hideAdvice(elm, advice);
  5298. this.updateCallback(elm, 'passed');
  5299. elm[prop] = '';
  5300. elm.removeClassName('validation-failed');
  5301. elm.addClassName('validation-passed');
  5302. if (Validation.defaultOptions.addClassNameToContainer && Validation.defaultOptions.containerClassName != '') {
  5303. var container = elm.up(Validation.defaultOptions.containerClassName);
  5304. if (container && !container.down('.validation-failed') && this.allowContainerClassName(elm)) {
  5305. if (!Validation.get('IsEmpty').test(elm.value) || !this.isVisible(elm)) {
  5306. container.addClassName('validation-passed');
  5307. } else {
  5308. container.removeClassName('validation-passed');
  5309. }
  5310. container.removeClassName('validation-error');
  5311. }
  5312. }
  5313. return true;
  5314. }
  5315. } catch(e) {
  5316. throw(e)
  5317. }
  5318. },
  5319. isVisible : function(elm) {
  5320. while(elm.tagName != 'BODY') {
  5321. if(!$(elm).visible()) return false;
  5322. elm = elm.parentNode;
  5323. }
  5324. return true;
  5325. },
  5326. getAdvice : function(name, elm) {
  5327. return $('advice-' + name + '-' + Validation.getElmID(elm)) || $('advice-' + Validation.getElmID(elm));
  5328. },
  5329. createAdvice : function(name, elm, useTitle, customError) {
  5330. var v = Validation.get(name);
  5331. var errorMsg = useTitle ? ((elm && elm.title) ? elm.title : v.error) : v.error;
  5332. if (customError) {
  5333. errorMsg = customError;
  5334. }
  5335. try {
  5336. if (Translator){
  5337. errorMsg = Translator.translate(errorMsg);
  5338. }
  5339. }
  5340. catch(e){}
  5341. advice = '<div class="validation-advice" id="advice-' + name + '-' + Validation.getElmID(elm) +'" style="display:none">' + errorMsg + '</div>'
  5342. Validation.insertAdvice(elm, advice);
  5343. advice = Validation.getAdvice(name, elm);
  5344. if($(elm).hasClassName('absolute-advice')) {
  5345. var dimensions = $(elm).getDimensions();
  5346. var originalPosition = Position.cumulativeOffset(elm);
  5347. advice._adviceTop = (originalPosition[1] + dimensions.height) + 'px';
  5348. advice._adviceLeft = (originalPosition[0]) + 'px';
  5349. advice._adviceWidth = (dimensions.width) + 'px';
  5350. advice._adviceAbsolutize = true;
  5351. }
  5352. return advice;
  5353. },
  5354. getElmID : function(elm) {
  5355. return elm.id ? elm.id : elm.name;
  5356. },
  5357. reset : function(elm) {
  5358. elm = $(elm);
  5359. var cn = $w(elm.className);
  5360. cn.each(function(value) {
  5361. var prop = '__advice'+value.camelize();
  5362. if(elm[prop]) {
  5363. var advice = Validation.getAdvice(value, elm);
  5364. if (advice) {
  5365. advice.hide();
  5366. }
  5367. elm[prop] = '';
  5368. }
  5369. elm.removeClassName('validation-failed');
  5370. elm.removeClassName('validation-passed');
  5371. if (Validation.defaultOptions.addClassNameToContainer && Validation.defaultOptions.containerClassName != '') {
  5372. var container = elm.up(Validation.defaultOptions.containerClassName);
  5373. if (container) {
  5374. container.removeClassName('validation-passed');
  5375. container.removeClassName('validation-error');
  5376. }
  5377. }
  5378. });
  5379. },
  5380. add : function(className, error, test, options) {
  5381. var nv = {};
  5382. nv[className] = new Validator(className, error, test, options);
  5383. Object.extend(Validation.methods, nv);
  5384. },
  5385. addAllThese : function(validators) {
  5386. var nv = {};
  5387. $A(validators).each(function(value) {
  5388. nv[value[0]] = new Validator(value[0], value[1], value[2], (value.length > 3 ? value[3] : {}));
  5389. });
  5390. Object.extend(Validation.methods, nv);
  5391. },
  5392. get : function(name) {
  5393. return Validation.methods[name] ? Validation.methods[name] : Validation.methods['_LikeNoIDIEverSaw_'];
  5394. },
  5395. methods : {
  5396. '_LikeNoIDIEverSaw_' : new Validator('_LikeNoIDIEverSaw_','',{})
  5397. }
  5398. });
  5399. Validation.add('IsEmpty', '', function(v) {
  5400. return (v == '' || (v == null) || (v.length == 0) || /^\s+$/.test(v));
  5401. });
  5402. Validation.addAllThese([
  5403. ['validate-no-html-tags', 'HTML tags están deshabilitados', function(v) {
  5404. return !/<(\/)?\w+/.test(v);
  5405. }],
  5406. ['validate-select', 'Por favor seleccione una opción.', function(v) {
  5407. return ((v != "none") && (v != null) && (v.length != 0));
  5408. }],
  5409. ['required-entry', 'Este es un campo obligatorio.', function(v) {
  5410. return !Validation.get('IsEmpty').test(v);
  5411. }],
  5412. ['validate-number', 'Please enter a valid number in this field.', function(v) {
  5413. return Validation.get('IsEmpty').test(v)
  5414. || (!isNaN(parseNumber(v)) && /^\s*-?\d*(\.\d*)?\s*$/.test(v));
  5415. }],
  5416. ['validate-number-range', 'The value is not within the specified range.', function(v, elm) {
  5417. if (Validation.get('IsEmpty').test(v)) {
  5418. return true;
  5419. }
  5420. var numValue = parseNumber(v);
  5421. if (isNaN(numValue)) {
  5422. return false;
  5423. }
  5424. var reRange = /^number-range-(-?[\d.,]+)?-(-?[\d.,]+)?$/,
  5425. result = true;
  5426. $w(elm.className).each(function(name) {
  5427. var m = reRange.exec(name);
  5428. if (m) {
  5429. result = result
  5430. && (m[1] == null || m[1] == '' || numValue >= parseNumber(m[1]))
  5431. && (m[2] == null || m[2] == '' || numValue <= parseNumber(m[2]));
  5432. }
  5433. });
  5434. return result;
  5435. }],
  5436. ['validate-digits', 'Please use numbers only in this field. Please avoid spaces or other characters such as dots or commas.', function(v) {
  5437. return Validation.get('IsEmpty').test(v) || !/[^\d]/.test(v);
  5438. }],
  5439. ['validate-digits-range', 'The value is not within the specified range.', function(v, elm) {
  5440. if (Validation.get('IsEmpty').test(v)) {
  5441. return true;
  5442. }
  5443. var numValue = parseNumber(v);
  5444. if (isNaN(numValue)) {
  5445. return false;
  5446. }
  5447. var reRange = /^digits-range-(-?\d+)?-(-?\d+)?$/,
  5448. result = true;
  5449. $w(elm.className).each(function(name) {
  5450. var m = reRange.exec(name);
  5451. if (m) {
  5452. result = result
  5453. && (m[1] == null || m[1] == '' || numValue >= parseNumber(m[1]))
  5454. && (m[2] == null || m[2] == '' || numValue <= parseNumber(m[2]));
  5455. }
  5456. });
  5457. return result;
  5458. }],
  5459. ['validate-alpha', 'Please use letters only (a-z or A-Z) in this field.', function (v) {
  5460. return Validation.get('IsEmpty').test(v) || /^[a-zA-Z]+$/.test(v)
  5461. }],
  5462. ['validate-code', 'Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter.', function (v) {
  5463. return Validation.get('IsEmpty').test(v) || /^[a-z]+[a-z0-9_]+$/.test(v)
  5464. }],
  5465. ['validate-alphanum', 'Please use only letters (a-z or A-Z) or numbers (0-9) only in this field. No spaces or other characters are allowed.', function(v) {
  5466. return Validation.get('IsEmpty').test(v) || /^[a-zA-Z0-9]+$/.test(v)
  5467. }],
  5468. ['validate-alphanum-with-spaces', 'Please use only letters (a-z or A-Z), numbers (0-9) or spaces only in this field.', function(v) {
  5469. return Validation.get('IsEmpty').test(v) || /^[a-zA-Z0-9 ]+$/.test(v)
  5470. }],
  5471. ['validate-street', 'Please use only letters (a-z or A-Z) or numbers (0-9) or spaces and # only in this field.', function(v) {
  5472. return Validation.get('IsEmpty').test(v) || /^[ \w]{3,}([A-Za-z]\.)?([ \w]*\#\d+)?(\r\n| )[ \w]{3,}/.test(v)
  5473. }],
  5474. ['validate-phoneStrict', 'Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.', function(v) {
  5475. return Validation.get('IsEmpty').test(v) || /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/.test(v);
  5476. }],
  5477. ['validate-phoneLax', 'Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.', function(v) {
  5478. return Validation.get('IsEmpty').test(v) || /^((\d[-. ]?)?((\(\d{3}\))|\d{3}))?[-. ]?\d{3}[-. ]?\d{4}$/.test(v);
  5479. }],
  5480. ['validate-fax', 'Please enter a valid fax number. For example (123) 456-7890 or 123-456-7890.', function(v) {
  5481. return Validation.get('IsEmpty').test(v) || /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/.test(v);
  5482. }],
  5483. ['validate-date', 'Please enter a valid date.', function(v) {
  5484. var test = new Date(v);
  5485. return Validation.get('IsEmpty').test(v) || !isNaN(test);
  5486. }],
  5487. ['validate-date-range', 'The From Date value should be less than or equal to the To Date value.', function(v, elm) {
  5488. var m = /\bdate-range-(\w+)-(\w+)\b/.exec(elm.className);
  5489. if (!m || m[2] == 'to' || Validation.get('IsEmpty').test(v)) {
  5490. return true;
  5491. }
  5492. var currentYear = new Date().getFullYear() + '';
  5493. var normalizedTime = function(v) {
  5494. v = v.split(/[.\/]/);
  5495. if (v[2] && v[2].length < 4) {
  5496. v[2] = currentYear.substr(0, v[2].length) + v[2];
  5497. }
  5498. return new Date(v.join('/')).getTime();
  5499. };
  5500. var dependentElements = Element.select(elm.form, '.validate-date-range.date-range-' + m[1] + '-to');
  5501. return !dependentElements.length || Validation.get('IsEmpty').test(dependentElements[0].value)
  5502. || normalizedTime(v) <= normalizedTime(dependentElements[0].value);
  5503. }],
  5504. ['validate-email', 'Por favor ingrese una dirección de email valida. Por ejemplo juanpenas@gmail.com.', function (v) {
  5505. //return Validation.get('IsEmpty').test(v) || /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v)
  5506. //return Validation.get('IsEmpty').test(v) || /^[\!\#$%\*/?|\^\{\}`~&\'\+\-=_a-z0-9][\!\#$%\*/?|\^\{\}`~&\'\+\-=_a-z0-9\.]{1,30}[\!\#$%\*/?|\^\{\}`~&\'\+\-=_a-z0-9]@([a-z0-9_-]{1,30}\.){1,5}[a-z]{2,4}$/i.test(v)
  5507. return Validation.get('IsEmpty').test(v) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(v)
  5508. }],
  5509. ['validate-emailSender', 'Please use only visible characters and spaces.', function (v) {
  5510. return Validation.get('IsEmpty').test(v) || /^[\S ]+$/.test(v)
  5511. }],
  5512. ['validate-password', 'Please enter 6 or more characters. Leading or trailing spaces will be ignored.', function(v) {
  5513. var pass=v.strip(); /*strip leading and trailing spaces*/
  5514. return !(pass.length>0 && pass.length < 6);
  5515. }],
  5516. ['validate-admin-password', 'Please enter 7 or more characters. Password should contain both numeric and alphabetic characters.', function(v) {
  5517. var pass=v.strip();
  5518. if (0 == pass.length) {
  5519. return true;
  5520. }
  5521. if (!(/[a-z]/i.test(v)) || !(/[0-9]/.test(v))) {
  5522. return false;
  5523. }
  5524. return !(pass.length < 7);
  5525. }],
  5526. ['validate-cpassword', 'Please make sure your passwords match.', function(v) {
  5527. var conf = $('confirmation') ? $('confirmation') : $$('.validate-cpassword')[0];
  5528. var pass = false;
  5529. if ($('password')) {
  5530. pass = $('password');
  5531. }
  5532. var passwordElements = $$('.validate-password');
  5533. for (var i = 0; i < passwordElements.size(); i++) {
  5534. var passwordElement = passwordElements[i];
  5535. if (passwordElement.up('form').id == conf.up('form').id) {
  5536. pass = passwordElement;
  5537. }
  5538. }
  5539. if ($$('.validate-admin-password').size()) {
  5540. pass = $$('.validate-admin-password')[0];
  5541. }
  5542. return (pass.value == conf.value);
  5543. }],
  5544. ['validate-both-passwords', 'Please make sure your passwords match.', function(v, input) {
  5545. var dependentInput = $(input.form[input.name == 'password' ? 'confirmation' : 'password']),
  5546. isEqualValues = input.value == dependentInput.value;
  5547. if (isEqualValues && dependentInput.hasClassName('validation-failed')) {
  5548. Validation.test(this.className, dependentInput);
  5549. }
  5550. return dependentInput.value == '' || isEqualValues;
  5551. }],
  5552. ['validate-url', 'Please enter a valid URL. Protocol is required (http://, https:// or ftp://)', function (v) {
  5553. v = (v || '').replace(/^\s+/, '').replace(/\s+$/, '');
  5554. return Validation.get('IsEmpty').test(v) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(v)
  5555. }],
  5556. ['validate-clean-url', 'Please enter a valid URL. For example http://www.example.com or www.example.com', function (v) {
  5557. return Validation.get('IsEmpty').test(v) || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+.(com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se)$)(:(\d+))?\/?/i.test(v) || /^(www)((\.[A-Z0-9][A-Z0-9_-]*)+.(com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se)$)(:(\d+))?\/?/i.test(v)
  5558. }],
  5559. ['validate-identifier', 'Please enter a valid URL Key. For example "example-page", "example-page.html" or "anotherlevel/example-page".', function (v) {
  5560. return Validation.get('IsEmpty').test(v) || /^[a-z0-9][a-z0-9_\/-]+(\.[a-z0-9_-]+)?$/.test(v)
  5561. }],
  5562. ['validate-xml-identifier', 'Please enter a valid XML-identifier. For example something_1, block5, id-4.', function (v) {
  5563. return Validation.get('IsEmpty').test(v) || /^[A-Z][A-Z0-9_\/-]*$/i.test(v)
  5564. }],
  5565. ['validate-ssn', 'Please enter a valid social security number. For example 123-45-6789.', function(v) {
  5566. return Validation.get('IsEmpty').test(v) || /^\d{3}-?\d{2}-?\d{4}$/.test(v);
  5567. }],
  5568. ['validate-zip', 'Please enter a valid zip code. For example 90602 or 90602-1234.', function(v) {
  5569. return Validation.get('IsEmpty').test(v) || /(^\d{5}$)|(^\d{5}-\d{4}$)/.test(v);
  5570. }],
  5571. ['validate-zip-international', 'Please enter a valid zip code.', function(v) {
  5572. //return Validation.get('IsEmpty').test(v) || /(^[A-z0-9]{2,10}([\s]{0,1}|[\-]{0,1})[A-z0-9]{2,10}$)/.test(v);
  5573. return true;
  5574. }],
  5575. ['validate-date-au', 'Please use this date format: dd/mm/yyyy. For example 17/03/2006 for the 17th of March, 2006.', function(v) {
  5576. if(Validation.get('IsEmpty').test(v)) return true;
  5577. var regex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
  5578. if(!regex.test(v)) return false;
  5579. var d = new Date(v.replace(regex, '$2/$1/$3'));
  5580. return ( parseInt(RegExp.$2, 10) == (1+d.getMonth()) ) &&
  5581. (parseInt(RegExp.$1, 10) == d.getDate()) &&
  5582. (parseInt(RegExp.$3, 10) == d.getFullYear() );
  5583. }],
  5584. ['validate-currency-dollar', 'Please enter a valid $ amount. For example $100.00.', function(v) {
  5585. // [$]1[##][,###]+[.##]
  5586. // [$]1###+[.##]
  5587. // [$]0.##
  5588. // [$].##
  5589. return Validation.get('IsEmpty').test(v) || /^\$?\-?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}\d*(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/.test(v)
  5590. }],
  5591. ['validate-one-required', 'Please select one of the above options.', function (v,elm) {
  5592. var p = elm.parentNode;
  5593. var options = p.getElementsByTagName('INPUT');
  5594. return $A(options).any(function(elm) {
  5595. return $F(elm);
  5596. });
  5597. }],
  5598. ['validate-one-required-by-name', 'Please select one of the options.', function (v,elm) {
  5599. var inputs = $$('input[name="' + elm.name.replace(/([\\"])/g, '\\$1') + '"]');
  5600. var error = 1;
  5601. for(var i=0;i<inputs.length;i++) {
  5602. if((inputs[i].type == 'checkbox' || inputs[i].type == 'radio') && inputs[i].checked == true) {
  5603. error = 0;
  5604. }
  5605. if(Validation.isOnChange && (inputs[i].type == 'checkbox' || inputs[i].type == 'radio')) {
  5606. Validation.reset(inputs[i]);
  5607. }
  5608. }
  5609. if( error == 0 ) {
  5610. return true;
  5611. } else {
  5612. return false;
  5613. }
  5614. }],
  5615. ['validate-not-negative-number', 'Please enter a number 0 or greater in this field.', function(v) {
  5616. if (Validation.get('IsEmpty').test(v)) {
  5617. return true;
  5618. }
  5619. v = parseNumber(v);
  5620. return !isNaN(v) && v >= 0;
  5621. }],
  5622. ['validate-zero-or-greater', 'Please enter a number 0 or greater in this field.', function(v) {
  5623. return Validation.get('validate-not-negative-number').test(v);
  5624. }],
  5625. ['validate-greater-than-zero', 'Please enter a number greater than 0 in this field.', function(v) {
  5626. if (Validation.get('IsEmpty').test(v)) {
  5627. return true;
  5628. }
  5629. v = parseNumber(v);
  5630. return !isNaN(v) && v > 0;
  5631. }],
  5632. ['validate-state', 'Please select State/Province.', function(v) {
  5633. return (v!=0 || v == '');
  5634. }],
  5635. ['validate-new-password', 'Please enter 6 or more characters. Leading or trailing spaces will be ignored.', function(v) {
  5636. if (!Validation.get('validate-password').test(v)) return false;
  5637. if (Validation.get('IsEmpty').test(v) && v != '') return false;
  5638. return true;
  5639. }],
  5640. ['validate-cc-number', 'Please enter a valid credit card number.', function(v, elm) {
  5641. // remove non-numerics
  5642. var ccTypeContainer = $(elm.id.substr(0,elm.id.indexOf('_cc_number')) + '_cc_type');
  5643. if (ccTypeContainer && typeof Validation.creditCartTypes.get(ccTypeContainer.value) != 'undefined'
  5644. && Validation.creditCartTypes.get(ccTypeContainer.value)[2] == false) {
  5645. if (!Validation.get('IsEmpty').test(v) && Validation.get('validate-digits').test(v)) {
  5646. return true;
  5647. } else {
  5648. return false;
  5649. }
  5650. }
  5651. return validateCreditCard(v);
  5652. }],
  5653. ['validate-cc-type', 'Credit card number does not match credit card type.', function(v, elm) {
  5654. // remove credit card number delimiters such as "-" and space
  5655. elm.value = removeDelimiters(elm.value);
  5656. v = removeDelimiters(v);
  5657. var ccTypeContainer = $(elm.id.substr(0,elm.id.indexOf('_cc_number')) + '_cc_type');
  5658. if (!ccTypeContainer) {
  5659. return true;
  5660. }
  5661. var ccType = ccTypeContainer.value;
  5662. if (typeof Validation.creditCartTypes.get(ccType) == 'undefined') {
  5663. return false;
  5664. }
  5665. // Other card type or switch or solo card
  5666. if (Validation.creditCartTypes.get(ccType)[0]==false) {
  5667. return true;
  5668. }
  5669. var validationFailure = false;
  5670. Validation.creditCartTypes.each(function (pair) {
  5671. if (pair.key == ccType) {
  5672. if (pair.value[0] && !v.match(pair.value[0])) {
  5673. validationFailure = true;
  5674. }
  5675. throw $break;
  5676. }
  5677. });
  5678. if (validationFailure) {
  5679. return false;
  5680. }
  5681. if (ccTypeContainer.hasClassName('validation-failed') && Validation.isOnChange) {
  5682. Validation.validate(ccTypeContainer);
  5683. }
  5684. return true;
  5685. }],
  5686. ['validate-cc-type-select', 'Card type does not match credit card number.', function(v, elm) {
  5687. var ccNumberContainer = $(elm.id.substr(0,elm.id.indexOf('_cc_type')) + '_cc_number');
  5688. if (Validation.isOnChange && Validation.get('IsEmpty').test(ccNumberContainer.value)) {
  5689. return true;
  5690. }
  5691. if (Validation.get('validate-cc-type').test(ccNumberContainer.value, ccNumberContainer)) {
  5692. Validation.validate(ccNumberContainer);
  5693. }
  5694. return Validation.get('validate-cc-type').test(ccNumberContainer.value, ccNumberContainer);
  5695. }],
  5696. ['validate-cc-exp', 'Incorrect credit card expiration date.', function(v, elm) {
  5697. var ccExpMonth = v;
  5698. var ccExpYear = $(elm.id.substr(0,elm.id.indexOf('_expiration')) + '_expiration_yr').value;
  5699. var currentTime = new Date();
  5700. var currentMonth = currentTime.getMonth() + 1;
  5701. var currentYear = currentTime.getFullYear();
  5702. if (ccExpMonth < currentMonth && ccExpYear == currentYear) {
  5703. return false;
  5704. }
  5705. return true;
  5706. }],
  5707. ['validate-cc-cvn', 'Please enter a valid credit card verification number.', function(v, elm) {
  5708. var ccTypeContainer = $(elm.id.substr(0,elm.id.indexOf('_cc_cid')) + '_cc_type');
  5709. if (!ccTypeContainer) {
  5710. return true;
  5711. }
  5712. var ccType = ccTypeContainer.value;
  5713. if (typeof Validation.creditCartTypes.get(ccType) == 'undefined') {
  5714. return false;
  5715. }
  5716. var re = Validation.creditCartTypes.get(ccType)[1];
  5717. if (v.match(re)) {
  5718. return true;
  5719. }
  5720. return false;
  5721. }],
  5722. ['validate-ajax', '', function(v, elm) { return true; }],
  5723. ['validate-data', 'Please use only letters (a-z or A-Z), numbers (0-9) or underscore(_) in this field, first character should be a letter.', function (v) {
  5724. if(v != '' && v) {
  5725. return /^[A-Za-z]+[A-Za-z0-9_]+$/.test(v);
  5726. }
  5727. return true;
  5728. }],
  5729. ['validate-css-length', 'Please input a valid CSS-length. For example 100px or 77pt or 20em or .5ex or 50%.', function (v) {
  5730. if (v != '' && v) {
  5731. return /^[0-9\.]+(px|pt|em|ex|%)?$/.test(v) && (!(/\..*\./.test(v))) && !(/\.$/.test(v));
  5732. }
  5733. return true;
  5734. }],
  5735. ['validate-length', 'Text length does not satisfy specified text range.', function (v, elm) {
  5736. var reMax = new RegExp(/^maximum-length-[0-9]+$/);
  5737. var reMin = new RegExp(/^minimum-length-[0-9]+$/);
  5738. var result = true;
  5739. $w(elm.className).each(function(name, index) {
  5740. if (name.match(reMax) && result) {
  5741. var length = name.split('-')[2];
  5742. result = (v.length <= length);
  5743. }
  5744. if (name.match(reMin) && result && !Validation.get('IsEmpty').test(v)) {
  5745. var length = name.split('-')[2];
  5746. result = (v.length >= length);
  5747. }
  5748. });
  5749. return result;
  5750. }],
  5751. ['validate-percents', 'Please enter a number lower than 100.', {max:100}],
  5752. ['required-file', 'Please select a file', function(v, elm) {
  5753. var result = !Validation.get('IsEmpty').test(v);
  5754. if (result === false) {
  5755. ovId = elm.id + '_value';
  5756. if ($(ovId)) {
  5757. result = !Validation.get('IsEmpty').test($(ovId).value);
  5758. }
  5759. }
  5760. return result;
  5761. }],
  5762. ['validate-cc-ukss', 'Please enter issue number or start date for switch/solo card type.', function(v,elm) {
  5763. var endposition;
  5764. if (elm.id.match(/(.)+_cc_issue$/)) {
  5765. endposition = elm.id.indexOf('_cc_issue');
  5766. } else if (elm.id.match(/(.)+_start_month$/)) {
  5767. endposition = elm.id.indexOf('_start_month');
  5768. } else {
  5769. endposition = elm.id.indexOf('_start_year');
  5770. }
  5771. var prefix = elm.id.substr(0,endposition);
  5772. var ccTypeContainer = $(prefix + '_cc_type');
  5773. if (!ccTypeContainer) {
  5774. return true;
  5775. }
  5776. var ccType = ccTypeContainer.value;
  5777. if(['SS','SM','SO'].indexOf(ccType) == -1){
  5778. return true;
  5779. }
  5780. $(prefix + '_cc_issue').advaiceContainer
  5781. = $(prefix + '_start_month').advaiceContainer
  5782. = $(prefix + '_start_year').advaiceContainer
  5783. = $(prefix + '_cc_type_ss_div').down('ul li.adv-container');
  5784. var ccIssue = $(prefix + '_cc_issue').value;
  5785. var ccSMonth = $(prefix + '_start_month').value;
  5786. var ccSYear = $(prefix + '_start_year').value;
  5787. var ccStartDatePresent = (ccSMonth && ccSYear) ? true : false;
  5788. if (!ccStartDatePresent && !ccIssue){
  5789. return false;
  5790. }
  5791. return true;
  5792. }]
  5793. ]);
  5794. function removeDelimiters (v) {
  5795. v = v.replace(/\s/g, '');
  5796. v = v.replace(/\-/g, '');
  5797. return v;
  5798. }
  5799. function parseNumber(v)
  5800. {
  5801. if (typeof v != 'string') {
  5802. return parseFloat(v);
  5803. }
  5804. var isDot = v.indexOf('.');
  5805. var isComa = v.indexOf(',');
  5806. if (isDot != -1 && isComa != -1) {
  5807. if (isComa > isDot) {
  5808. v = v.replace('.', '').replace(',', '.');
  5809. }
  5810. else {
  5811. v = v.replace(',', '');
  5812. }
  5813. }
  5814. else if (isComa != -1) {
  5815. v = v.replace(',', '.');
  5816. }
  5817. return parseFloat(v);
  5818. }
  5819. /**
  5820. * Hash with credit card types which can be simply extended in payment modules
  5821. * 0 - regexp for card number
  5822. * 1 - regexp for cvn
  5823. * 2 - check or not credit card number trough Luhn algorithm by
  5824. * function validateCreditCard which you can find above in this file
  5825. */
  5826. Validation.creditCartTypes = $H({
  5827. // 'SS': [new RegExp('^((6759[0-9]{12})|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})|(6333[0-9]{12})|(6334[0-4]\d{11})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],
  5828. 'SO': [new RegExp('^(6334[5-9]([0-9]{11}|[0-9]{13,14}))|(6767([0-9]{12}|[0-9]{14,15}))$'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],
  5829. 'VI': [new RegExp('^4[0-9]{12}([0-9]{3})?$'), new RegExp('^[0-9]{3}$'), true],
  5830. 'MC': [new RegExp('^5[1-5][0-9]{14}$'), new RegExp('^[0-9]{3}$'), true],
  5831. 'AE': [new RegExp('^3[47][0-9]{13}$'), new RegExp('^[0-9]{4}$'), true],
  5832. 'DI': [new RegExp('^(30[0-5][0-9]{13}|3095[0-9]{12}|35(2[8-9][0-9]{12}|[3-8][0-9]{13})|36[0-9]{12}|3[8-9][0-9]{14}|6011(0[0-9]{11}|[2-4][0-9]{11}|74[0-9]{10}|7[7-9][0-9]{10}|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}|5[0-9]{14}))$'), new RegExp('^[0-9]{3}$'), true],
  5833. 'JCB': [new RegExp('^(30[0-5][0-9]{13}|3095[0-9]{12}|35(2[8-9][0-9]{12}|[3-8][0-9]{13})|36[0-9]{12}|3[8-9][0-9]{14}|6011(0[0-9]{11}|[2-4][0-9]{11}|74[0-9]{10}|7[7-9][0-9]{10}|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}|5[0-9]{14}))$'), new RegExp('^[0-9]{3,4}$'), true],
  5834. 'DICL': [new RegExp('^(30[0-5][0-9]{13}|3095[0-9]{12}|35(2[8-9][0-9]{12}|[3-8][0-9]{13})|36[0-9]{12}|3[8-9][0-9]{14}|6011(0[0-9]{11}|[2-4][0-9]{11}|74[0-9]{10}|7[7-9][0-9]{10}|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}|5[0-9]{14}))$'), new RegExp('^[0-9]{3}$'), true],
  5835. 'SM': [new RegExp('(^(5[0678])[0-9]{11,18}$)|(^(6[^05])[0-9]{11,18}$)|(^(601)[^1][0-9]{9,16}$)|(^(6011)[0-9]{9,11}$)|(^(6011)[0-9]{13,16}$)|(^(65)[0-9]{11,13}$)|(^(65)[0-9]{15,18}$)|(^(49030)[2-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49033)[5-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49110)[1-2]([0-9]{10}$|[0-9]{12,13}$))|(^(49117)[4-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49118)[0-2]([0-9]{10}$|[0-9]{12,13}$))|(^(4936)([0-9]{12}$|[0-9]{14,15}$))'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],
  5836. 'OT': [false, new RegExp('^([0-9]{3}|[0-9]{4})?$'), false]
  5837. });
  5838. // script.aculo.us builder.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008
  5839. // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
  5840. //
  5841. // script.aculo.us is freely distributable under the terms of an MIT-style license.
  5842. // For details, see the script.aculo.us web site: http://script.aculo.us/
  5843. var Builder = {
  5844. NODEMAP: {
  5845. AREA: 'map',
  5846. CAPTION: 'table',
  5847. COL: 'table',
  5848. COLGROUP: 'table',
  5849. LEGEND: 'fieldset',
  5850. OPTGROUP: 'select',
  5851. OPTION: 'select',
  5852. PARAM: 'object',
  5853. TBODY: 'table',
  5854. TD: 'table',
  5855. TFOOT: 'table',
  5856. TH: 'table',
  5857. THEAD: 'table',
  5858. TR: 'table'
  5859. },
  5860. // note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
  5861. // due to a Firefox bug
  5862. node: function(elementName) {
  5863. elementName = elementName.toUpperCase();
  5864. // try innerHTML approach
  5865. var parentTag = this.NODEMAP[elementName] || 'div';
  5866. var parentElement = document.createElement(parentTag);
  5867. try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
  5868. parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
  5869. } catch(e) {}
  5870. var element = parentElement.firstChild || null;
  5871. // see if browser added wrapping tags
  5872. if(element && (element.tagName.toUpperCase() != elementName))
  5873. element = element.getElementsByTagName(elementName)[0];
  5874. // fallback to createElement approach
  5875. if(!element) element = document.createElement(elementName);
  5876. // abort if nothing could be created
  5877. if(!element) return;
  5878. // attributes (or text)
  5879. if(arguments[1])
  5880. if(this._isStringOrNumber(arguments[1]) ||
  5881. (arguments[1] instanceof Array) ||
  5882. arguments[1].tagName) {
  5883. this._children(element, arguments[1]);
  5884. } else {
  5885. var attrs = this._attributes(arguments[1]);
  5886. if(attrs.length) {
  5887. try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
  5888. parentElement.innerHTML = "<" +elementName + " " +
  5889. attrs + "></" + elementName + ">";
  5890. } catch(e) {}
  5891. element = parentElement.firstChild || null;
  5892. // workaround firefox 1.0.X bug
  5893. if(!element) {
  5894. element = document.createElement(elementName);
  5895. for(attr in arguments[1])
  5896. element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
  5897. }
  5898. if(element.tagName.toUpperCase() != elementName)
  5899. element = parentElement.getElementsByTagName(elementName)[0];
  5900. }
  5901. }
  5902. // text, or array of children
  5903. if(arguments[2])
  5904. this._children(element, arguments[2]);
  5905. return $(element);
  5906. },
  5907. _text: function(text) {
  5908. return document.createTextNode(text);
  5909. },
  5910. ATTR_MAP: {
  5911. 'className': 'class',
  5912. 'htmlFor': 'for'
  5913. },
  5914. _attributes: function(attributes) {
  5915. var attrs = [];
  5916. for(attribute in attributes)
  5917. attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) +
  5918. '="' + attributes[attribute].toString().escapeHTML().gsub(/"/,'&quot;') + '"');
  5919. return attrs.join(" ");
  5920. },
  5921. _children: function(element, children) {
  5922. if(children.tagName) {
  5923. element.appendChild(children);
  5924. return;
  5925. }
  5926. if(typeof children=='object') { // array can hold nodes and text
  5927. children.flatten().each( function(e) {
  5928. if(typeof e=='object')
  5929. element.appendChild(e);
  5930. else
  5931. if(Builder._isStringOrNumber(e))
  5932. element.appendChild(Builder._text(e));
  5933. });
  5934. } else
  5935. if(Builder._isStringOrNumber(children))
  5936. element.appendChild(Builder._text(children));
  5937. },
  5938. _isStringOrNumber: function(param) {
  5939. return(typeof param=='string' || typeof param=='number');
  5940. },
  5941. build: function(html) {
  5942. var element = this.node('div');
  5943. $(element).update(html.strip());
  5944. return element.down();
  5945. },
  5946. dump: function(scope) {
  5947. if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope
  5948. var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
  5949. "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
  5950. "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
  5951. "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
  5952. "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
  5953. "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
  5954. tags.each( function(tag){
  5955. scope[tag] = function() {
  5956. return Builder.node.apply(Builder, [tag].concat($A(arguments)));
  5957. };
  5958. });
  5959. }
  5960. };
  5961. // script.aculo.us effects.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008
  5962. // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
  5963. // Contributors:
  5964. // Justin Palmer (http://encytemedia.com/)
  5965. // Mark Pilgrim (http://diveintomark.org/)
  5966. // Martin Bialasinki
  5967. //
  5968. // script.aculo.us is freely distributable under the terms of an MIT-style license.
  5969. // For details, see the script.aculo.us web site: http://script.aculo.us/
  5970. // converts rgb() and #xxx to #xxxxxx format,
  5971. // returns self (or first argument) if not convertable
  5972. String.prototype.parseColor = function() {
  5973. var color = '#';
  5974. if (this.slice(0,4) == 'rgb(') {
  5975. var cols = this.slice(4,this.length-1).split(',');
  5976. var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);
  5977. } else {
  5978. if (this.slice(0,1) == '#') {
  5979. if (this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();
  5980. if (this.length==7) color = this.toLowerCase();
  5981. }
  5982. }
  5983. return (color.length==7 ? color : (arguments[0] || this));
  5984. };
  5985. /*--------------------------------------------------------------------------*/
  5986. Element.collectTextNodes = function(element) {
  5987. return $A($(element).childNodes).collect( function(node) {
  5988. return (node.nodeType==3 ? node.nodeValue :
  5989. (node.hasChildNodes() ? Element.collectTextNodes(node) : ''));
  5990. }).flatten().join('');
  5991. };
  5992. Element.collectTextNodesIgnoreClass = function(element, className) {
  5993. return $A($(element).childNodes).collect( function(node) {
  5994. return (node.nodeType==3 ? node.nodeValue :
  5995. ((node.hasChildNodes() && !Element.hasClassName(node,className)) ?
  5996. Element.collectTextNodesIgnoreClass(node, className) : ''));
  5997. }).flatten().join('');
  5998. };
  5999. Element.setContentZoom = function(element, percent) {
  6000. element = $(element);
  6001. element.setStyle({fontSize: (percent/100) + 'em'});
  6002. if (Prototype.Browser.WebKit) window.scrollBy(0,0);
  6003. return element;
  6004. };
  6005. Element.getInlineOpacity = function(element){
  6006. return $(element).style.opacity || '';
  6007. };
  6008. Element.forceRerendering = function(element) {
  6009. try {
  6010. element = $(element);
  6011. var n = document.createTextNode(' ');
  6012. element.appendChild(n);
  6013. element.removeChild(n);
  6014. } catch(e) { }
  6015. };
  6016. /*--------------------------------------------------------------------------*/
  6017. var Effect = {
  6018. _elementDoesNotExistError: {
  6019. name: 'ElementDoesNotExistError',
  6020. message: 'The specified DOM element does not exist, but is required for this effect to operate'
  6021. },
  6022. Transitions: {
  6023. linear: Prototype.K,
  6024. sinoidal: function(pos) {
  6025. return (-Math.cos(pos*Math.PI)/2) + .5;
  6026. },
  6027. reverse: function(pos) {
  6028. return 1-pos;
  6029. },
  6030. flicker: function(pos) {
  6031. var pos = ((-Math.cos(pos*Math.PI)/4) + .75) + Math.random()/4;
  6032. return pos > 1 ? 1 : pos;
  6033. },
  6034. wobble: function(pos) {
  6035. return (-Math.cos(pos*Math.PI*(9*pos))/2) + .5;
  6036. },
  6037. pulse: function(pos, pulses) {
  6038. return (-Math.cos((pos*((pulses||5)-.5)*2)*Math.PI)/2) + .5;
  6039. },
  6040. spring: function(pos) {
  6041. return 1 - (Math.cos(pos * 4.5 * Math.PI) * Math.exp(-pos * 6));
  6042. },
  6043. none: function(pos) {
  6044. return 0;
  6045. },
  6046. full: function(pos) {
  6047. return 1;
  6048. }
  6049. },
  6050. DefaultOptions: {
  6051. duration: 1.0, // seconds
  6052. fps: 100, // 100= assume 66fps max.
  6053. sync: false, // true for combining
  6054. from: 0.0,
  6055. to: 1.0,
  6056. delay: 0.0,
  6057. queue: 'parallel'
  6058. },
  6059. tagifyText: function(element) {
  6060. var tagifyStyle = 'position:relative';
  6061. if (Prototype.Browser.IE) tagifyStyle += ';zoom:1';
  6062. element = $(element);
  6063. $A(element.childNodes).each( function(child) {
  6064. if (child.nodeType==3) {
  6065. child.nodeValue.toArray().each( function(character) {
  6066. element.insertBefore(
  6067. new Element('span', {style: tagifyStyle}).update(
  6068. character == ' ' ? String.fromCharCode(160) : character),
  6069. child);
  6070. });
  6071. Element.remove(child);
  6072. }
  6073. });
  6074. },
  6075. multiple: function(element, effect) {
  6076. var elements;
  6077. if (((typeof element == 'object') ||
  6078. Object.isFunction(element)) &&
  6079. (element.length))
  6080. elements = element;
  6081. else
  6082. elements = $(element).childNodes;
  6083. var options = Object.extend({
  6084. speed: 0.1,
  6085. delay: 0.0
  6086. }, arguments[2] || { });
  6087. var masterDelay = options.delay;
  6088. $A(elements).each( function(element, index) {
  6089. new effect(element, Object.extend(options, { delay: index * options.speed + masterDelay }));
  6090. });
  6091. },
  6092. PAIRS: {
  6093. 'slide': ['SlideDown','SlideUp'],
  6094. 'blind': ['BlindDown','BlindUp'],
  6095. 'appear': ['Appear','Fade']
  6096. },
  6097. toggle: function(element, effect) {
  6098. element = $(element);
  6099. effect = (effect || 'appear').toLowerCase();
  6100. var options = Object.extend({
  6101. queue: { position:'end', scope:(element.id || 'global'), limit: 1 }
  6102. }, arguments[2] || { });
  6103. Effect[element.visible() ?
  6104. Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options);
  6105. }
  6106. };
  6107. Effect.DefaultOptions.transition = Effect.Transitions.sinoidal;
  6108. /* ------------- core effects ------------- */
  6109. Effect.ScopedQueue = Class.create(Enumerable, {
  6110. initialize: function() {
  6111. this.effects = [];
  6112. this.interval = null;
  6113. },
  6114. _each: function(iterator) {
  6115. this.effects._each(iterator);
  6116. },
  6117. add: function(effect) {
  6118. var timestamp = new Date().getTime();
  6119. var position = Object.isString(effect.options.queue) ?
  6120. effect.options.queue : effect.options.queue.position;
  6121. switch(position) {
  6122. case 'front':
  6123. // move unstarted effects after this effect
  6124. this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) {
  6125. e.startOn += effect.finishOn;
  6126. e.finishOn += effect.finishOn;
  6127. });
  6128. break;
  6129. case 'with-last':
  6130. timestamp = this.effects.pluck('startOn').max() || timestamp;
  6131. break;
  6132. case 'end':
  6133. // start effect after last queued effect has finished
  6134. timestamp = this.effects.pluck('finishOn').max() || timestamp;
  6135. break;
  6136. }
  6137. effect.startOn += timestamp;
  6138. effect.finishOn += timestamp;
  6139. if (!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit))
  6140. this.effects.push(effect);
  6141. if (!this.interval)
  6142. this.interval = setInterval(this.loop.bind(this), 15);
  6143. },
  6144. remove: function(effect) {
  6145. this.effects = this.effects.reject(function(e) { return e==effect });
  6146. if (this.effects.length == 0) {
  6147. clearInterval(this.interval);
  6148. this.interval = null;
  6149. }
  6150. },
  6151. loop: function() {
  6152. var timePos = new Date().getTime();
  6153. for(var i=0, len=this.effects.length;i<len;i++)
  6154. this.effects[i] && this.effects[i].loop(timePos);
  6155. }
  6156. });
  6157. Effect.Queues = {
  6158. instances: $H(),
  6159. get: function(queueName) {
  6160. if (!Object.isString(queueName)) return queueName;
  6161. return this.instances.get(queueName) ||
  6162. this.instances.set(queueName, new Effect.ScopedQueue());
  6163. }
  6164. };
  6165. Effect.Queue = Effect.Queues.get('global');
  6166. Effect.Base = Class.create({
  6167. position: null,
  6168. start: function(options) {
  6169. function codeForEvent(options,eventName){
  6170. return (
  6171. (options[eventName+'Internal'] ? 'this.options.'+eventName+'Internal(this);' : '') +
  6172. (options[eventName] ? 'this.options.'+eventName+'(this);' : '')
  6173. );
  6174. }
  6175. if (options && options.transition === false) options.transition = Effect.Transitions.linear;
  6176. this.options = Object.extend(Object.extend({ },Effect.DefaultOptions), options || { });
  6177. this.currentFrame = 0;
  6178. this.state = 'idle';
  6179. this.startOn = this.options.delay*1000;
  6180. this.finishOn = this.startOn+(this.options.duration*1000);
  6181. this.fromToDelta = this.options.to-this.options.from;
  6182. this.totalTime = this.finishOn-this.startOn;
  6183. this.totalFrames = this.options.fps*this.options.duration;
  6184. this.render = (function() {
  6185. function dispatch(effect, eventName) {
  6186. if (effect.options[eventName + 'Internal'])
  6187. effect.options[eventName + 'Internal'](effect);
  6188. if (effect.options[eventName])
  6189. effect.options[eventName](effect);
  6190. }
  6191. return function(pos) {
  6192. if (this.state === "idle") {
  6193. this.state = "running";
  6194. dispatch(this, 'beforeSetup');
  6195. if (this.setup) this.setup();
  6196. dispatch(this, 'afterSetup');
  6197. }
  6198. if (this.state === "running") {
  6199. pos = (this.options.transition(pos) * this.fromToDelta) + this.options.from;
  6200. this.position = pos;
  6201. dispatch(this, 'beforeUpdate');
  6202. if (this.update) this.update(pos);
  6203. dispatch(this, 'afterUpdate');
  6204. }
  6205. };
  6206. })();
  6207. this.event('beforeStart');
  6208. if (!this.options.sync)
  6209. Effect.Queues.get(Object.isString(this.options.queue) ?
  6210. 'global' : this.options.queue.scope).add(this);
  6211. },
  6212. loop: function(timePos) {
  6213. if (timePos >= this.startOn) {
  6214. if (timePos >= this.finishOn) {
  6215. this.render(1.0);
  6216. this.cancel();
  6217. this.event('beforeFinish');
  6218. if (this.finish) this.finish();
  6219. this.event('afterFinish');
  6220. return;
  6221. }
  6222. var pos = (timePos - this.startOn) / this.totalTime,
  6223. frame = (pos * this.totalFrames).round();
  6224. if (frame > this.currentFrame) {
  6225. this.render(pos);
  6226. this.currentFrame = frame;
  6227. }
  6228. }
  6229. },
  6230. cancel: function() {
  6231. if (!this.options.sync)
  6232. Effect.Queues.get(Object.isString(this.options.queue) ?
  6233. 'global' : this.options.queue.scope).remove(this);
  6234. this.state = 'finished';
  6235. },
  6236. event: function(eventName) {
  6237. if (this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this);
  6238. if (this.options[eventName]) this.options[eventName](this);
  6239. },
  6240. inspect: function() {
  6241. var data = $H();
  6242. for(property in this)
  6243. if (!Object.isFunction(this[property])) data.set(property, this[property]);
  6244. return '#<Effect:' + data.inspect() + ',options:' + $H(this.options).inspect() + '>';
  6245. }
  6246. });
  6247. Effect.Parallel = Class.create(Effect.Base, {
  6248. initialize: function(effects) {
  6249. this.effects = effects || [];
  6250. this.start(arguments[1]);
  6251. },
  6252. update: function(position) {
  6253. this.effects.invoke('render', position);
  6254. },
  6255. finish: function(position) {
  6256. this.effects.each( function(effect) {
  6257. effect.render(1.0);
  6258. effect.cancel();
  6259. effect.event('beforeFinish');
  6260. if (effect.finish) effect.finish(position);
  6261. effect.event('afterFinish');
  6262. });
  6263. }
  6264. });
  6265. Effect.Tween = Class.create(Effect.Base, {
  6266. initialize: function(object, from, to) {
  6267. object = Object.isString(object) ? $(object) : object;
  6268. var args = $A(arguments), method = args.last(),
  6269. options = args.length == 5 ? args[3] : null;
  6270. this.method = Object.isFunction(method) ? method.bind(object) :
  6271. Object.isFunction(object[method]) ? object[method].bind(object) :
  6272. function(value) { object[method] = value };
  6273. this.start(Object.extend({ from: from, to: to }, options || { }));
  6274. },
  6275. update: function(position) {
  6276. this.method(position);
  6277. }
  6278. });
  6279. Effect.Event = Class.create(Effect.Base, {
  6280. initialize: function() {
  6281. this.start(Object.extend({ duration: 0 }, arguments[0] || { }));
  6282. },
  6283. update: Prototype.emptyFunction
  6284. });
  6285. Effect.Opacity = Class.create(Effect.Base, {
  6286. initialize: function(element) {
  6287. this.element = $(element);
  6288. if (!this.element) throw(Effect._elementDoesNotExistError);
  6289. // make this work on IE on elements without 'layout'
  6290. if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout))
  6291. this.element.setStyle({zoom: 1});
  6292. var options = Object.extend({
  6293. from: this.element.getOpacity() || 0.0,
  6294. to: 1.0
  6295. }, arguments[1] || { });
  6296. this.start(options);
  6297. },
  6298. update: function(position) {
  6299. this.element.setOpacity(position);
  6300. }
  6301. });
  6302. Effect.Move = Class.create(Effect.Base, {
  6303. initialize: function(element) {
  6304. this.element = $(element);
  6305. if (!this.element) throw(Effect._elementDoesNotExistError);
  6306. var options = Object.extend({
  6307. x: 0,
  6308. y: 0,
  6309. mode: 'relative'
  6310. }, arguments[1] || { });
  6311. this.start(options);
  6312. },
  6313. setup: function() {
  6314. this.element.makePositioned();
  6315. this.originalLeft = parseFloat(this.element.getStyle('left') || '0');
  6316. this.originalTop = parseFloat(this.element.getStyle('top') || '0');
  6317. if (this.options.mode == 'absolute') {
  6318. this.options.x = this.options.x - this.originalLeft;
  6319. this.options.y = this.options.y - this.originalTop;
  6320. }
  6321. },
  6322. update: function(position) {
  6323. this.element.setStyle({
  6324. left: (this.options.x * position + this.originalLeft).round() + 'px',
  6325. top: (this.options.y * position + this.originalTop).round() + 'px'
  6326. });
  6327. }
  6328. });
  6329. // for backwards compatibility
  6330. Effect.MoveBy = function(element, toTop, toLeft) {
  6331. return new Effect.Move(element,
  6332. Object.extend({ x: toLeft, y: toTop }, arguments[3] || { }));
  6333. };
  6334. Effect.Scale = Class.create(Effect.Base, {
  6335. initialize: function(element, percent) {
  6336. this.element = $(element);
  6337. if (!this.element) throw(Effect._elementDoesNotExistError);
  6338. var options = Object.extend({
  6339. scaleX: true,
  6340. scaleY: true,
  6341. scaleContent: true,
  6342. scaleFromCenter: false,
  6343. scaleMode: 'box', // 'box' or 'contents' or { } with provided values
  6344. scaleFrom: 100.0,
  6345. scaleTo: percent
  6346. }, arguments[2] || { });
  6347. this.start(options);
  6348. },
  6349. setup: function() {
  6350. this.restoreAfterFinish = this.options.restoreAfterFinish || false;
  6351. this.elementPositioning = this.element.getStyle('position');
  6352. this.originalStyle = { };
  6353. ['top','left','width','height','fontSize'].each( function(k) {
  6354. this.originalStyle[k] = this.element.style[k];
  6355. }.bind(this));
  6356. this.originalTop = this.element.offsetTop;
  6357. this.originalLeft = this.element.offsetLeft;
  6358. var fontSize = this.element.getStyle('font-size') || '100%';
  6359. ['em','px','%','pt'].each( function(fontSizeType) {
  6360. if (fontSize.indexOf(fontSizeType)>0) {
  6361. this.fontSize = parseFloat(fontSize);
  6362. this.fontSizeType = fontSizeType;
  6363. }
  6364. }.bind(this));
  6365. this.factor = (this.options.scaleTo - this.options.scaleFrom)/100;
  6366. this.dims = null;
  6367. if (this.options.scaleMode=='box')
  6368. this.dims = [this.element.offsetHeight, this.element.offsetWidth];
  6369. if (/^content/.test(this.options.scaleMode))
  6370. this.dims = [this.element.scrollHeight, this.element.scrollWidth];
  6371. if (!this.dims)
  6372. this.dims = [this.options.scaleMode.originalHeight,
  6373. this.options.scaleMode.originalWidth];
  6374. },
  6375. update: function(position) {
  6376. var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position);
  6377. if (this.options.scaleContent && this.fontSize)
  6378. this.element.setStyle({fontSize: this.fontSize * currentScale + this.fontSizeType });
  6379. this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale);
  6380. },
  6381. finish: function(position) {
  6382. if (this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
  6383. },
  6384. setDimensions: function(height, width) {
  6385. var d = { };
  6386. if (this.options.scaleX) d.width = width.round() + 'px';
  6387. if (this.options.scaleY) d.height = height.round() + 'px';
  6388. if (this.options.scaleFromCenter) {
  6389. var topd = (height - this.dims[0])/2;
  6390. var leftd = (width - this.dims[1])/2;
  6391. if (this.elementPositioning == 'absolute') {
  6392. if (this.options.scaleY) d.top = this.originalTop-topd + 'px';
  6393. if (this.options.scaleX) d.left = this.originalLeft-leftd + 'px';
  6394. } else {
  6395. if (this.options.scaleY) d.top = -topd + 'px';
  6396. if (this.options.scaleX) d.left = -leftd + 'px';
  6397. }
  6398. }
  6399. this.element.setStyle(d);
  6400. }
  6401. });
  6402. Effect.Highlight = Class.create(Effect.Base, {
  6403. initialize: function(element) {
  6404. this.element = $(element);
  6405. if (!this.element) throw(Effect._elementDoesNotExistError);
  6406. var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || { });
  6407. this.start(options);
  6408. },
  6409. setup: function() {
  6410. // Prevent executing on elements not in the layout flow
  6411. if (this.element.getStyle('display')=='none') { this.cancel(); return; }
  6412. // Disable background image during the effect
  6413. this.oldStyle = { };
  6414. if (!this.options.keepBackgroundImage) {
  6415. this.oldStyle.backgroundImage = this.element.getStyle('background-image');
  6416. this.element.setStyle({backgroundImage: 'none'});
  6417. }
  6418. if (!this.options.endcolor)
  6419. this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff');
  6420. if (!this.options.restorecolor)
  6421. this.options.restorecolor = this.element.getStyle('background-color');
  6422. // init color calculations
  6423. this._base = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this));
  6424. this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this));
  6425. },
  6426. update: function(position) {
  6427. this.element.setStyle({backgroundColor: $R(0,2).inject('#',function(m,v,i){
  6428. return m+((this._base[i]+(this._delta[i]*position)).round().toColorPart()); }.bind(this)) });
  6429. },
  6430. finish: function() {
  6431. this.element.setStyle(Object.extend(this.oldStyle, {
  6432. backgroundColor: this.options.restorecolor
  6433. }));
  6434. }
  6435. });
  6436. Effect.ScrollTo = function(element) {
  6437. var options = arguments[1] || { },
  6438. scrollOffsets = document.viewport.getScrollOffsets(),
  6439. elementOffsets = $(element).cumulativeOffset();
  6440. if (options.offset) elementOffsets[1] += options.offset;
  6441. return new Effect.Tween(null,
  6442. scrollOffsets.top,
  6443. elementOffsets[1],
  6444. options,
  6445. function(p){ scrollTo(scrollOffsets.left, p.round()); }
  6446. );
  6447. };
  6448. /* ------------- combination effects ------------- */
  6449. Effect.Fade = function(element) {
  6450. element = $(element);
  6451. var oldOpacity = element.getInlineOpacity();
  6452. var options = Object.extend({
  6453. from: element.getOpacity() || 1.0,
  6454. to: 0.0,
  6455. afterFinishInternal: function(effect) {
  6456. if (effect.options.to!=0) return;
  6457. effect.element.hide().setStyle({opacity: oldOpacity});
  6458. }
  6459. }, arguments[1] || { });
  6460. return new Effect.Opacity(element,options);
  6461. };
  6462. Effect.Appear = function(element) {
  6463. element = $(element);
  6464. var options = Object.extend({
  6465. from: (element.getStyle('display') == 'none' ? 0.0 : element.getOpacity() || 0.0),
  6466. to: 1.0,
  6467. // force Safari to render floated elements properly
  6468. afterFinishInternal: function(effect) {
  6469. effect.element.forceRerendering();
  6470. },
  6471. beforeSetup: function(effect) {
  6472. effect.element.setOpacity(effect.options.from).show();
  6473. }}, arguments[1] || { });
  6474. return new Effect.Opacity(element,options);
  6475. };
  6476. Effect.Puff = function(element) {
  6477. element = $(element);
  6478. var oldStyle = {
  6479. opacity: element.getInlineOpacity(),
  6480. position: element.getStyle('position'),
  6481. top: element.style.top,
  6482. left: element.style.left,
  6483. width: element.style.width,
  6484. height: element.style.height
  6485. };
  6486. return new Effect.Parallel(
  6487. [ new Effect.Scale(element, 200,
  6488. { sync: true, scaleFromCenter: true, scaleContent: true, restoreAfterFinish: true }),
  6489. new Effect.Opacity(element, { sync: true, to: 0.0 } ) ],
  6490. Object.extend({ duration: 1.0,
  6491. beforeSetupInternal: function(effect) {
  6492. Position.absolutize(effect.effects[0].element);
  6493. },
  6494. afterFinishInternal: function(effect) {
  6495. effect.effects[0].element.hide().setStyle(oldStyle); }
  6496. }, arguments[1] || { })
  6497. );
  6498. };
  6499. Effect.BlindUp = function(element) {
  6500. element = $(element);
  6501. element.makeClipping();
  6502. return new Effect.Scale(element, 0,
  6503. Object.extend({ scaleContent: false,
  6504. scaleX: false,
  6505. restoreAfterFinish: true,
  6506. afterFinishInternal: function(effect) {
  6507. effect.element.hide().undoClipping();
  6508. }
  6509. }, arguments[1] || { })
  6510. );
  6511. };
  6512. Effect.BlindDown = function(element) {
  6513. element = $(element);
  6514. var elementDimensions = element.getDimensions();
  6515. return new Effect.Scale(element, 100, Object.extend({
  6516. scaleContent: false,
  6517. scaleX: false,
  6518. scaleFrom: 0,
  6519. scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
  6520. restoreAfterFinish: true,
  6521. afterSetup: function(effect) {
  6522. effect.element.makeClipping().setStyle({height: '0px'}).show();
  6523. },
  6524. afterFinishInternal: function(effect) {
  6525. effect.element.undoClipping();
  6526. }
  6527. }, arguments[1] || { }));
  6528. };
  6529. Effect.SwitchOff = function(element) {
  6530. element = $(element);
  6531. var oldOpacity = element.getInlineOpacity();
  6532. return new Effect.Appear(element, Object.extend({
  6533. duration: 0.4,
  6534. from: 0,
  6535. transition: Effect.Transitions.flicker,
  6536. afterFinishInternal: function(effect) {
  6537. new Effect.Scale(effect.element, 1, {
  6538. duration: 0.3, scaleFromCenter: true,
  6539. scaleX: false, scaleContent: false, restoreAfterFinish: true,
  6540. beforeSetup: function(effect) {
  6541. effect.element.makePositioned().makeClipping();
  6542. },
  6543. afterFinishInternal: function(effect) {
  6544. effect.element.hide().undoClipping().undoPositioned().setStyle({opacity: oldOpacity});
  6545. }
  6546. });
  6547. }
  6548. }, arguments[1] || { }));
  6549. };
  6550. Effect.DropOut = function(element) {
  6551. element = $(element);
  6552. var oldStyle = {
  6553. top: element.getStyle('top'),
  6554. left: element.getStyle('left'),
  6555. opacity: element.getInlineOpacity() };
  6556. return new Effect.Parallel(
  6557. [ new Effect.Move(element, {x: 0, y: 100, sync: true }),
  6558. new Effect.Opacity(element, { sync: true, to: 0.0 }) ],
  6559. Object.extend(
  6560. { duration: 0.5,
  6561. beforeSetup: function(effect) {
  6562. effect.effects[0].element.makePositioned();
  6563. },
  6564. afterFinishInternal: function(effect) {
  6565. effect.effects[0].element.hide().undoPositioned().setStyle(oldStyle);
  6566. }
  6567. }, arguments[1] || { }));
  6568. };
  6569. Effect.Shake = function(element) {
  6570. element = $(element);
  6571. var options = Object.extend({
  6572. distance: 20,
  6573. duration: 0.5
  6574. }, arguments[1] || {});
  6575. var distance = parseFloat(options.distance);
  6576. var split = parseFloat(options.duration) / 10.0;
  6577. var oldStyle = {
  6578. top: element.getStyle('top'),
  6579. left: element.getStyle('left') };
  6580. return new Effect.Move(element,
  6581. { x: distance, y: 0, duration: split, afterFinishInternal: function(effect) {
  6582. new Effect.Move(effect.element,
  6583. { x: -distance*2, y: 0, duration: split*2, afterFinishInternal: function(effect) {
  6584. new Effect.Move(effect.element,
  6585. { x: distance*2, y: 0, duration: split*2, afterFinishInternal: function(effect) {
  6586. new Effect.Move(effect.element,
  6587. { x: -distance*2, y: 0, duration: split*2, afterFinishInternal: function(effect) {
  6588. new Effect.Move(effect.element,
  6589. { x: distance*2, y: 0, duration: split*2, afterFinishInternal: function(effect) {
  6590. new Effect.Move(effect.element,
  6591. { x: -distance, y: 0, duration: split, afterFinishInternal: function(effect) {
  6592. effect.element.undoPositioned().setStyle(oldStyle);
  6593. }}); }}); }}); }}); }}); }});
  6594. };
  6595. Effect.SlideDown = function(element) {
  6596. element = $(element).cleanWhitespace();
  6597. // SlideDown need to have the content of the element wrapped in a container element with fixed height!
  6598. var oldInnerBottom = element.down().getStyle('bottom');
  6599. var elementDimensions = element.getDimensions();
  6600. return new Effect.Scale(element, 100, Object.extend({
  6601. scaleContent: false,
  6602. scaleX: false,
  6603. scaleFrom: window.opera ? 0 : 1,
  6604. scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
  6605. restoreAfterFinish: true,
  6606. afterSetup: function(effect) {
  6607. effect.element.makePositioned();
  6608. effect.element.down().makePositioned();
  6609. if (window.opera) effect.element.setStyle({top: ''});
  6610. effect.element.makeClipping().setStyle({height: '0px'}).show();
  6611. },
  6612. afterUpdateInternal: function(effect) {
  6613. effect.element.down().setStyle({bottom:
  6614. (effect.dims[0] - effect.element.clientHeight) + 'px' });
  6615. },
  6616. afterFinishInternal: function(effect) {
  6617. effect.element.undoClipping().undoPositioned();
  6618. effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom}); }
  6619. }, arguments[1] || { })
  6620. );
  6621. };
  6622. Effect.SlideUp = function(element) {
  6623. element = $(element).cleanWhitespace();
  6624. var oldInnerBottom = element.down().getStyle('bottom');
  6625. var elementDimensions = element.getDimensions();
  6626. return new Effect.Scale(element, window.opera ? 0 : 1,
  6627. Object.extend({ scaleContent: false,
  6628. scaleX: false,
  6629. scaleMode: 'box',
  6630. scaleFrom: 100,
  6631. scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
  6632. restoreAfterFinish: true,
  6633. afterSetup: function(effect) {
  6634. effect.element.makePositioned();
  6635. effect.element.down().makePositioned();
  6636. if (window.opera) effect.element.setStyle({top: ''});
  6637. effect.element.makeClipping().show();
  6638. },
  6639. afterUpdateInternal: function(effect) {
  6640. effect.element.down().setStyle({bottom:
  6641. (effect.dims[0] - effect.element.clientHeight) + 'px' });
  6642. },
  6643. afterFinishInternal: function(effect) {
  6644. effect.element.hide().undoClipping().undoPositioned();
  6645. effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom});
  6646. }
  6647. }, arguments[1] || { })
  6648. );
  6649. };
  6650. // Bug in opera makes the TD containing this element expand for a instance after finish
  6651. Effect.Squish = function(element) {
  6652. return new Effect.Scale(element, window.opera ? 1 : 0, {
  6653. restoreAfterFinish: true,
  6654. beforeSetup: function(effect) {
  6655. effect.element.makeClipping();
  6656. },
  6657. afterFinishInternal: function(effect) {
  6658. effect.element.hide().undoClipping();
  6659. }
  6660. });
  6661. };
  6662. Effect.Grow = function(element) {
  6663. element = $(element);
  6664. var options = Object.extend({
  6665. direction: 'center',
  6666. moveTransition: Effect.Transitions.sinoidal,
  6667. scaleTransition: Effect.Transitions.sinoidal,
  6668. opacityTransition: Effect.Transitions.full
  6669. }, arguments[1] || { });
  6670. var oldStyle = {
  6671. top: element.style.top,
  6672. left: element.style.left,
  6673. height: element.style.height,
  6674. width: element.style.width,
  6675. opacity: element.getInlineOpacity() };
  6676. var dims = element.getDimensions();
  6677. var initialMoveX, initialMoveY;
  6678. var moveX, moveY;
  6679. switch (options.direction) {
  6680. case 'top-left':
  6681. initialMoveX = initialMoveY = moveX = moveY = 0;
  6682. break;
  6683. case 'top-right':
  6684. initialMoveX = dims.width;
  6685. initialMoveY = moveY = 0;
  6686. moveX = -dims.width;
  6687. break;
  6688. case 'bottom-left':
  6689. initialMoveX = moveX = 0;
  6690. initialMoveY = dims.height;
  6691. moveY = -dims.height;
  6692. break;
  6693. case 'bottom-right':
  6694. initialMoveX = dims.width;
  6695. initialMoveY = dims.height;
  6696. moveX = -dims.width;
  6697. moveY = -dims.height;
  6698. break;
  6699. case 'center':
  6700. initialMoveX = dims.width / 2;
  6701. initialMoveY = dims.height / 2;
  6702. moveX = -dims.width / 2;
  6703. moveY = -dims.height / 2;
  6704. break;
  6705. }
  6706. return new Effect.Move(element, {
  6707. x: initialMoveX,
  6708. y: initialMoveY,
  6709. duration: 0.01,
  6710. beforeSetup: function(effect) {
  6711. effect.element.hide().makeClipping().makePositioned();
  6712. },
  6713. afterFinishInternal: function(effect) {
  6714. new Effect.Parallel(
  6715. [ new Effect.Opacity(effect.element, { sync: true, to: 1.0, from: 0.0, transition: options.opacityTransition }),
  6716. new Effect.Move(effect.element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }),
  6717. new Effect.Scale(effect.element, 100, {
  6718. scaleMode: { originalHeight: dims.height, originalWidth: dims.width },
  6719. sync: true, scaleFrom: window.opera ? 1 : 0, transition: options.scaleTransition, restoreAfterFinish: true})
  6720. ], Object.extend({
  6721. beforeSetup: function(effect) {
  6722. effect.effects[0].element.setStyle({height: '0px'}).show();
  6723. },
  6724. afterFinishInternal: function(effect) {
  6725. effect.effects[0].element.undoClipping().undoPositioned().setStyle(oldStyle);
  6726. }
  6727. }, options)
  6728. );
  6729. }
  6730. });
  6731. };
  6732. Effect.Shrink = function(element) {
  6733. element = $(element);
  6734. var options = Object.extend({
  6735. direction: 'center',
  6736. moveTransition: Effect.Transitions.sinoidal,
  6737. scaleTransition: Effect.Transitions.sinoidal,
  6738. opacityTransition: Effect.Transitions.none
  6739. }, arguments[1] || { });
  6740. var oldStyle = {
  6741. top: element.style.top,
  6742. left: element.style.left,
  6743. height: element.style.height,
  6744. width: element.style.width,
  6745. opacity: element.getInlineOpacity() };
  6746. var dims = element.getDimensions();
  6747. var moveX, moveY;
  6748. switch (options.direction) {
  6749. case 'top-left':
  6750. moveX = moveY = 0;
  6751. break;
  6752. case 'top-right':
  6753. moveX = dims.width;
  6754. moveY = 0;
  6755. break;
  6756. case 'bottom-left':
  6757. moveX = 0;
  6758. moveY = dims.height;
  6759. break;
  6760. case 'bottom-right':
  6761. moveX = dims.width;
  6762. moveY = dims.height;
  6763. break;
  6764. case 'center':
  6765. moveX = dims.width / 2;
  6766. moveY = dims.height / 2;
  6767. break;
  6768. }
  6769. return new Effect.Parallel(
  6770. [ new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0, transition: options.opacityTransition }),
  6771. new Effect.Scale(element, window.opera ? 1 : 0, { sync: true, transition: options.scaleTransition, restoreAfterFinish: true}),
  6772. new Effect.Move(element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition })
  6773. ], Object.extend({
  6774. beforeStartInternal: function(effect) {
  6775. effect.effects[0].element.makePositioned().makeClipping();
  6776. },
  6777. afterFinishInternal: function(effect) {
  6778. effect.effects[0].element.hide().undoClipping().undoPositioned().setStyle(oldStyle); }
  6779. }, options)
  6780. );
  6781. };
  6782. Effect.Pulsate = function(element) {
  6783. element = $(element);
  6784. var options = arguments[1] || { },
  6785. oldOpacity = element.getInlineOpacity(),
  6786. transition = options.transition || Effect.Transitions.linear,
  6787. reverser = function(pos){
  6788. return 1 - transition((-Math.cos((pos*(options.pulses||5)*2)*Math.PI)/2) + .5);
  6789. };
  6790. return new Effect.Opacity(element,
  6791. Object.extend(Object.extend({ duration: 2.0, from: 0,
  6792. afterFinishInternal: function(effect) { effect.element.setStyle({opacity: oldOpacity}); }
  6793. }, options), {transition: reverser}));
  6794. };
  6795. Effect.Fold = function(element) {
  6796. element = $(element);
  6797. var oldStyle = {
  6798. top: element.style.top,
  6799. left: element.style.left,
  6800. width: element.style.width,
  6801. height: element.style.height };
  6802. element.makeClipping();
  6803. return new Effect.Scale(element, 5, Object.extend({
  6804. scaleContent: false,
  6805. scaleX: false,
  6806. afterFinishInternal: function(effect) {
  6807. new Effect.Scale(element, 1, {
  6808. scaleContent: false,
  6809. scaleY: false,
  6810. afterFinishInternal: function(effect) {
  6811. effect.element.hide().undoClipping().setStyle(oldStyle);
  6812. } });
  6813. }}, arguments[1] || { }));
  6814. };
  6815. Effect.Morph = Class.create(Effect.Base, {
  6816. initialize: function(element) {
  6817. this.element = $(element);
  6818. if (!this.element) throw(Effect._elementDoesNotExistError);
  6819. var options = Object.extend({
  6820. style: { }
  6821. }, arguments[1] || { });
  6822. if (!Object.isString(options.style)) this.style = $H(options.style);
  6823. else {
  6824. if (options.style.include(':'))
  6825. this.style = options.style.parseStyle();
  6826. else {
  6827. this.element.addClassName(options.style);
  6828. this.style = $H(this.element.getStyles());
  6829. this.element.removeClassName(options.style);
  6830. var css = this.element.getStyles();
  6831. this.style = this.style.reject(function(style) {
  6832. return style.value == css[style.key];
  6833. });
  6834. options.afterFinishInternal = function(effect) {
  6835. effect.element.addClassName(effect.options.style);
  6836. effect.transforms.each(function(transform) {
  6837. effect.element.style[transform.style] = '';
  6838. });
  6839. };
  6840. }
  6841. }
  6842. this.start(options);
  6843. },
  6844. setup: function(){
  6845. function parseColor(color){
  6846. if (!color || ['rgba(0, 0, 0, 0)','transparent'].include(color)) color = '#ffffff';
  6847. color = color.parseColor();
  6848. return $R(0,2).map(function(i){
  6849. return parseInt( color.slice(i*2+1,i*2+3), 16 );
  6850. });
  6851. }
  6852. this.transforms = this.style.map(function(pair){
  6853. var property = pair[0], value = pair[1], unit = null;
  6854. if (value.parseColor('#zzzzzz') != '#zzzzzz') {
  6855. value = value.parseColor();
  6856. unit = 'color';
  6857. } else if (property == 'opacity') {
  6858. value = parseFloat(value);
  6859. if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout))
  6860. this.element.setStyle({zoom: 1});
  6861. } else if (Element.CSS_LENGTH.test(value)) {
  6862. var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/);
  6863. value = parseFloat(components[1]);
  6864. unit = (components.length == 3) ? components[2] : null;
  6865. }
  6866. var originalValue = this.element.getStyle(property);
  6867. return {
  6868. style: property.camelize(),
  6869. originalValue: unit=='color' ? parseColor(originalValue) : parseFloat(originalValue || 0),
  6870. targetValue: unit=='color' ? parseColor(value) : value,
  6871. unit: unit
  6872. };
  6873. }.bind(this)).reject(function(transform){
  6874. return (
  6875. (transform.originalValue == transform.targetValue) ||
  6876. (
  6877. transform.unit != 'color' &&
  6878. (isNaN(transform.originalValue) || isNaN(transform.targetValue))
  6879. )
  6880. );
  6881. });
  6882. },
  6883. update: function(position) {
  6884. var style = { }, transform, i = this.transforms.length;
  6885. while(i--)
  6886. style[(transform = this.transforms[i]).style] =
  6887. transform.unit=='color' ? '#'+
  6888. (Math.round(transform.originalValue[0]+
  6889. (transform.targetValue[0]-transform.originalValue[0])*position)).toColorPart() +
  6890. (Math.round(transform.originalValue[1]+
  6891. (transform.targetValue[1]-transform.originalValue[1])*position)).toColorPart() +
  6892. (Math.round(transform.originalValue[2]+
  6893. (transform.targetValue[2]-transform.originalValue[2])*position)).toColorPart() :
  6894. (transform.originalValue +
  6895. (transform.targetValue - transform.originalValue) * position).toFixed(3) +
  6896. (transform.unit === null ? '' : transform.unit);
  6897. this.element.setStyle(style, true);
  6898. }
  6899. });
  6900. Effect.Transform = Class.create({
  6901. initialize: function(tracks){
  6902. this.tracks = [];
  6903. this.options = arguments[1] || { };
  6904. this.addTracks(tracks);
  6905. },
  6906. addTracks: function(tracks){
  6907. tracks.each(function(track){
  6908. track = $H(track);
  6909. var data = track.values().first();
  6910. this.tracks.push($H({
  6911. ids: track.keys().first(),
  6912. effect: Effect.Morph,
  6913. options: { style: data }
  6914. }));
  6915. }.bind(this));
  6916. return this;
  6917. },
  6918. play: function(){
  6919. return new Effect.Parallel(
  6920. this.tracks.map(function(track){
  6921. var ids = track.get('ids'), effect = track.get('effect'), options = track.get('options');
  6922. var elements = [$(ids) || $$(ids)].flatten();
  6923. return elements.map(function(e){ return new effect(e, Object.extend({ sync:true }, options)) });
  6924. }).flatten(),
  6925. this.options
  6926. );
  6927. }
  6928. });
  6929. Element.CSS_PROPERTIES = $w(
  6930. 'backgroundColor backgroundPosition borderBottomColor borderBottomStyle ' +
  6931. 'borderBottomWidth borderLeftColor borderLeftStyle borderLeftWidth ' +
  6932. 'borderRightColor borderRightStyle borderRightWidth borderSpacing ' +
  6933. 'borderTopColor borderTopStyle borderTopWidth bottom clip color ' +
  6934. 'fontSize fontWeight height left letterSpacing lineHeight ' +
  6935. 'marginBottom marginLeft marginRight marginTop markerOffset maxHeight '+
  6936. 'maxWidth minHeight minWidth opacity outlineColor outlineOffset ' +
  6937. 'outlineWidth paddingBottom paddingLeft paddingRight paddingTop ' +
  6938. 'right textIndent top width wordSpacing zIndex');
  6939. Element.CSS_LENGTH = /^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/;
  6940. String.__parseStyleElement = document.createElement('div');
  6941. String.prototype.parseStyle = function(){
  6942. var style, styleRules = $H();
  6943. if (Prototype.Browser.WebKit)
  6944. style = new Element('div',{style:this}).style;
  6945. else {
  6946. String.__parseStyleElement.innerHTML = '<div style="' + this + '"></div>';
  6947. style = String.__parseStyleElement.childNodes[0].style;
  6948. }
  6949. Element.CSS_PROPERTIES.each(function(property){
  6950. if (style[property]) styleRules.set(property, style[property]);
  6951. });
  6952. if (Prototype.Browser.IE && this.include('opacity'))
  6953. styleRules.set('opacity', this.match(/opacity:\s*((?:0|1)?(?:\.\d*)?)/)[1]);
  6954. return styleRules;
  6955. };
  6956. if (document.defaultView && document.defaultView.getComputedStyle) {
  6957. Element.getStyles = function(element) {
  6958. var css = document.defaultView.getComputedStyle($(element), null);
  6959. return Element.CSS_PROPERTIES.inject({ }, function(styles, property) {
  6960. styles[property] = css[property];
  6961. return styles;
  6962. });
  6963. };
  6964. } else {
  6965. Element.getStyles = function(element) {
  6966. element = $(element);
  6967. var css = element.currentStyle, styles;
  6968. styles = Element.CSS_PROPERTIES.inject({ }, function(results, property) {
  6969. results[property] = css[property];
  6970. return results;
  6971. });
  6972. if (!styles.opacity) styles.opacity = element.getOpacity();
  6973. return styles;
  6974. };
  6975. }
  6976. Effect.Methods = {
  6977. morph: function(element, style) {
  6978. element = $(element);
  6979. new Effect.Morph(element, Object.extend({ style: style }, arguments[2] || { }));
  6980. return element;
  6981. },
  6982. visualEffect: function(element, effect, options) {
  6983. element = $(element);
  6984. var s = effect.dasherize().camelize(), klass = s.charAt(0).toUpperCase() + s.substring(1);
  6985. new Effect[klass](element, options);
  6986. return element;
  6987. },
  6988. highlight: function(element, options) {
  6989. element = $(element);
  6990. new Effect.Highlight(element, options);
  6991. return element;
  6992. }
  6993. };
  6994. $w('fade appear grow shrink fold blindUp blindDown slideUp slideDown '+
  6995. 'pulsate shake puff squish switchOff dropOut').each(
  6996. function(effect) {
  6997. Effect.Methods[effect] = function(element, options){
  6998. element = $(element);
  6999. Effect[effect.charAt(0).toUpperCase() + effect.substring(1)](element, options);
  7000. return element;
  7001. };
  7002. }
  7003. );
  7004. $w('getInlineOpacity forceRerendering setContentZoom collectTextNodes collectTextNodesIgnoreClass getStyles').each(
  7005. function(f) { Effect.Methods[f] = Element[f]; }
  7006. );
  7007. Element.addMethods(Effect.Methods);
  7008. // script.aculo.us dragdrop.js v1.9.0, Thu Dec 23 16:54:48 -0500 2010
  7009. // Copyright (c) 2005-2010 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
  7010. //
  7011. // script.aculo.us is freely distributable under the terms of an MIT-style license.
  7012. // For details, see the script.aculo.us web site: http://script.aculo.us/
  7013. if(Object.isUndefined(Effect))
  7014. throw("dragdrop.js requires including script.aculo.us' effects.js library");
  7015. var Droppables = {
  7016. drops: [],
  7017. remove: function(element) {
  7018. this.drops = this.drops.reject(function(d) { return d.element==$(element) });
  7019. },
  7020. add: function(element) {
  7021. element = $(element);
  7022. var options = Object.extend({
  7023. greedy: true,
  7024. hoverclass: null,
  7025. tree: false
  7026. }, arguments[1] || { });
  7027. // cache containers
  7028. if(options.containment) {
  7029. options._containers = [];
  7030. var containment = options.containment;
  7031. if(Object.isArray(containment)) {
  7032. containment.each( function(c) { options._containers.push($(c)) });
  7033. } else {
  7034. options._containers.push($(containment));
  7035. }
  7036. }
  7037. if(options.accept) options.accept = [options.accept].flatten();
  7038. Element.makePositioned(element); // fix IE
  7039. options.element = element;
  7040. this.drops.push(options);
  7041. },
  7042. findDeepestChild: function(drops) {
  7043. deepest = drops[0];
  7044. for (i = 1; i < drops.length; ++i)
  7045. if (Element.isParent(drops[i].element, deepest.element))
  7046. deepest = drops[i];
  7047. return deepest;
  7048. },
  7049. isContained: function(element, drop) {
  7050. var containmentNode;
  7051. if(drop.tree) {
  7052. containmentNode = element.treeNode;
  7053. } else {
  7054. containmentNode = element.parentNode;
  7055. }
  7056. return drop._containers.detect(function(c) { return containmentNode == c });
  7057. },
  7058. isAffected: function(point, element, drop) {
  7059. return (
  7060. (drop.element!=element) &&
  7061. ((!drop._containers) ||
  7062. this.isContained(element, drop)) &&
  7063. ((!drop.accept) ||
  7064. (Element.classNames(element).detect(
  7065. function(v) { return drop.accept.include(v) } ) )) &&
  7066. Position.within(drop.element, point[0], point[1]) );
  7067. },
  7068. deactivate: function(drop) {
  7069. if(drop.hoverclass)
  7070. Element.removeClassName(drop.element, drop.hoverclass);
  7071. this.last_active = null;
  7072. },
  7073. activate: function(drop) {
  7074. if(drop.hoverclass)
  7075. Element.addClassName(drop.element, drop.hoverclass);
  7076. this.last_active = drop;
  7077. },
  7078. show: function(point, element) {
  7079. if(!this.drops.length) return;
  7080. var drop, affected = [];
  7081. this.drops.each( function(drop) {
  7082. if(Droppables.isAffected(point, element, drop))
  7083. affected.push(drop);
  7084. });
  7085. if(affected.length>0)
  7086. drop = Droppables.findDeepestChild(affected);
  7087. if(this.last_active && this.last_active != drop) this.deactivate(this.last_active);
  7088. if (drop) {
  7089. Position.within(drop.element, point[0], point[1]);
  7090. if(drop.onHover)
  7091. drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element));
  7092. if (drop != this.last_active) Droppables.activate(drop);
  7093. }
  7094. },
  7095. fire: function(event, element) {
  7096. if(!this.last_active) return;
  7097. Position.prepare();
  7098. if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active))
  7099. if (this.last_active.onDrop) {
  7100. this.last_active.onDrop(element, this.last_active.element, event);
  7101. return true;
  7102. }
  7103. },
  7104. reset: function() {
  7105. if(this.last_active)
  7106. this.deactivate(this.last_active);
  7107. }
  7108. };
  7109. var Draggables = {
  7110. drags: [],
  7111. observers: [],
  7112. register: function(draggable) {
  7113. if(this.drags.length == 0) {
  7114. this.eventMouseUp = this.endDrag.bindAsEventListener(this);
  7115. this.eventMouseMove = this.updateDrag.bindAsEventListener(this);
  7116. this.eventKeypress = this.keyPress.bindAsEventListener(this);
  7117. Event.observe(document, "mouseup", this.eventMouseUp);
  7118. Event.observe(document, "mousemove", this.eventMouseMove);
  7119. Event.observe(document, "keypress", this.eventKeypress);
  7120. }
  7121. this.drags.push(draggable);
  7122. },
  7123. unregister: function(draggable) {
  7124. this.drags = this.drags.reject(function(d) { return d==draggable });
  7125. if(this.drags.length == 0) {
  7126. Event.stopObserving(document, "mouseup", this.eventMouseUp);
  7127. Event.stopObserving(document, "mousemove", this.eventMouseMove);
  7128. Event.stopObserving(document, "keypress", this.eventKeypress);
  7129. }
  7130. },
  7131. activate: function(draggable) {
  7132. if(draggable.options.delay) {
  7133. this._timeout = setTimeout(function() {
  7134. Draggables._timeout = null;
  7135. window.focus();
  7136. Draggables.activeDraggable = draggable;
  7137. }.bind(this), draggable.options.delay);
  7138. } else {
  7139. window.focus(); // allows keypress events if window isn't currently focused, fails for Safari
  7140. this.activeDraggable = draggable;
  7141. }
  7142. },
  7143. deactivate: function() {
  7144. this.activeDraggable = null;
  7145. },
  7146. updateDrag: function(event) {
  7147. if(!this.activeDraggable) return;
  7148. var pointer = [Event.pointerX(event), Event.pointerY(event)];
  7149. // Mozilla-based browsers fire successive mousemove events with
  7150. // the same coordinates, prevent needless redrawing (moz bug?)
  7151. if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return;
  7152. this._lastPointer = pointer;
  7153. this.activeDraggable.updateDrag(event, pointer);
  7154. },
  7155. endDrag: function(event) {
  7156. if(this._timeout) {
  7157. clearTimeout(this._timeout);
  7158. this._timeout = null;
  7159. }
  7160. if(!this.activeDraggable) return;
  7161. this._lastPointer = null;
  7162. this.activeDraggable.endDrag(event);
  7163. this.activeDraggable = null;
  7164. },
  7165. keyPress: function(event) {
  7166. if(this.activeDraggable)
  7167. this.activeDraggable.keyPress(event);
  7168. },
  7169. addObserver: function(observer) {
  7170. this.observers.push(observer);
  7171. this._cacheObserverCallbacks();
  7172. },
  7173. removeObserver: function(element) { // element instead of observer fixes mem leaks
  7174. this.observers = this.observers.reject( function(o) { return o.element==element });
  7175. this._cacheObserverCallbacks();
  7176. },
  7177. notify: function(eventName, draggable, event) { // 'onStart', 'onEnd', 'onDrag'
  7178. if(this[eventName+'Count'] > 0)
  7179. this.observers.each( function(o) {
  7180. if(o[eventName]) o[eventName](eventName, draggable, event);
  7181. });
  7182. if(draggable.options[eventName]) draggable.options[eventName](draggable, event);
  7183. },
  7184. _cacheObserverCallbacks: function() {
  7185. ['onStart','onEnd','onDrag'].each( function(eventName) {
  7186. Draggables[eventName+'Count'] = Draggables.observers.select(
  7187. function(o) { return o[eventName]; }
  7188. ).length;
  7189. });
  7190. }
  7191. };
  7192. /*--------------------------------------------------------------------------*/
  7193. var Draggable = Class.create({
  7194. initialize: function(element) {
  7195. var defaults = {
  7196. handle: false,
  7197. reverteffect: function(element, top_offset, left_offset) {
  7198. var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02;
  7199. new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur,
  7200. queue: {scope:'_draggable', position:'end'}
  7201. });
  7202. },
  7203. endeffect: function(element) {
  7204. var toOpacity = Object.isNumber(element._opacity) ? element._opacity : 1.0;
  7205. new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,
  7206. queue: {scope:'_draggable', position:'end'},
  7207. afterFinish: function(){
  7208. Draggable._dragging[element] = false
  7209. }
  7210. });
  7211. },
  7212. zindex: 1000,
  7213. revert: false,
  7214. quiet: false,
  7215. scroll: false,
  7216. scrollSensitivity: 20,
  7217. scrollSpeed: 15,
  7218. snap: false, // false, or xy or [x,y] or function(x,y){ return [x,y] }
  7219. delay: 0
  7220. };
  7221. if(!arguments[1] || Object.isUndefined(arguments[1].endeffect))
  7222. Object.extend(defaults, {
  7223. starteffect: function(element) {
  7224. element._opacity = Element.getOpacity(element);
  7225. Draggable._dragging[element] = true;
  7226. new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
  7227. }
  7228. });
  7229. var options = Object.extend(defaults, arguments[1] || { });
  7230. this.element = $(element);
  7231. if(options.handle && Object.isString(options.handle))
  7232. this.handle = this.element.down('.'+options.handle, 0);
  7233. if(!this.handle) this.handle = $(options.handle);
  7234. if(!this.handle) this.handle = this.element;
  7235. if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) {
  7236. options.scroll = $(options.scroll);
  7237. this._isScrollChild = Element.childOf(this.element, options.scroll);
  7238. }
  7239. Element.makePositioned(this.element); // fix IE
  7240. this.options = options;
  7241. this.dragging = false;
  7242. this.eventMouseDown = this.initDrag.bindAsEventListener(this);
  7243. Event.observe(this.handle, "mousedown", this.eventMouseDown);
  7244. Draggables.register(this);
  7245. },
  7246. destroy: function() {
  7247. Event.stopObserving(this.handle, "mousedown", this.eventMouseDown);
  7248. Draggables.unregister(this);
  7249. },
  7250. currentDelta: function() {
  7251. return([
  7252. parseInt(Element.getStyle(this.element,'left') || '0'),
  7253. parseInt(Element.getStyle(this.element,'top') || '0')]);
  7254. },
  7255. initDrag: function(event) {
  7256. if(!Object.isUndefined(Draggable._dragging[this.element]) &&
  7257. Draggable._dragging[this.element]) return;
  7258. if(Event.isLeftClick(event)) {
  7259. // abort on form elements, fixes a Firefox issue
  7260. var src = Event.element(event);
  7261. if((tag_name = src.tagName.toUpperCase()) && (
  7262. tag_name=='INPUT' ||
  7263. tag_name=='SELECT' ||
  7264. tag_name=='OPTION' ||
  7265. tag_name=='BUTTON' ||
  7266. tag_name=='TEXTAREA')) return;
  7267. var pointer = [Event.pointerX(event), Event.pointerY(event)];
  7268. var pos = this.element.cumulativeOffset();
  7269. this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) });
  7270. Draggables.activate(this);
  7271. Event.stop(event);
  7272. }
  7273. },
  7274. startDrag: function(event) {
  7275. this.dragging = true;
  7276. if(!this.delta)
  7277. this.delta = this.currentDelta();
  7278. if(this.options.zindex) {
  7279. this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0);
  7280. this.element.style.zIndex = this.options.zindex;
  7281. }
  7282. if(this.options.ghosting) {
  7283. this._clone = this.element.cloneNode(true);
  7284. this._originallyAbsolute = (this.element.getStyle('position') == 'absolute');
  7285. if (!this._originallyAbsolute)
  7286. Position.absolutize(this.element);
  7287. this.element.parentNode.insertBefore(this._clone, this.element);
  7288. }
  7289. if(this.options.scroll) {
  7290. if (this.options.scroll == window) {
  7291. var where = this._getWindowScroll(this.options.scroll);
  7292. this.originalScrollLeft = where.left;
  7293. this.originalScrollTop = where.top;
  7294. } else {
  7295. this.originalScrollLeft = this.options.scroll.scrollLeft;
  7296. this.originalScrollTop = this.options.scroll.scrollTop;
  7297. }
  7298. }
  7299. Draggables.notify('onStart', this, event);
  7300. if(this.options.starteffect) this.options.starteffect(this.element);
  7301. },
  7302. updateDrag: function(event, pointer) {
  7303. if(!this.dragging) this.startDrag(event);
  7304. if(!this.options.quiet){
  7305. Position.prepare();
  7306. Droppables.show(pointer, this.element);
  7307. }
  7308. Draggables.notify('onDrag', this, event);
  7309. this.draw(pointer);
  7310. if(this.options.change) this.options.change(this);
  7311. if(this.options.scroll) {
  7312. this.stopScrolling();
  7313. var p;
  7314. if (this.options.scroll == window) {
  7315. with(this._getWindowScroll(this.options.scroll)) { p = [ left, top, left+width, top+height ]; }
  7316. } else {
  7317. p = Position.page(this.options.scroll).toArray();
  7318. p[0] += this.options.scroll.scrollLeft + Position.deltaX;
  7319. p[1] += this.options.scroll.scrollTop + Position.deltaY;
  7320. p.push(p[0]+this.options.scroll.offsetWidth);
  7321. p.push(p[1]+this.options.scroll.offsetHeight);
  7322. }
  7323. var speed = [0,0];
  7324. if(pointer[0] < (p[0]+this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[0]+this.options.scrollSensitivity);
  7325. if(pointer[1] < (p[1]+this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[1]+this.options.scrollSensitivity);
  7326. if(pointer[0] > (p[2]-this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[2]-this.options.scrollSensitivity);
  7327. if(pointer[1] > (p[3]-this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[3]-this.options.scrollSensitivity);
  7328. this.startScrolling(speed);
  7329. }
  7330. // fix AppleWebKit rendering
  7331. if(Prototype.Browser.WebKit) window.scrollBy(0,0);
  7332. Event.stop(event);
  7333. },
  7334. finishDrag: function(event, success) {
  7335. this.dragging = false;
  7336. if(this.options.quiet){
  7337. Position.prepare();
  7338. var pointer = [Event.pointerX(event), Event.pointerY(event)];
  7339. Droppables.show(pointer, this.element);
  7340. }
  7341. if(this.options.ghosting) {
  7342. if (!this._originallyAbsolute)
  7343. Position.relativize(this.element);
  7344. delete this._originallyAbsolute;
  7345. Element.remove(this._clone);
  7346. this._clone = null;
  7347. }
  7348. var dropped = false;
  7349. if(success) {
  7350. dropped = Droppables.fire(event, this.element);
  7351. if (!dropped) dropped = false;
  7352. }
  7353. if(dropped && this.options.onDropped) this.options.onDropped(this.element);
  7354. Draggables.notify('onEnd', this, event);
  7355. var revert = this.options.revert;
  7356. if(revert && Object.isFunction(revert)) revert = revert(this.element);
  7357. var d = this.currentDelta();
  7358. if(revert && this.options.reverteffect) {
  7359. if (dropped == 0 || revert != 'failure')
  7360. this.options.reverteffect(this.element,
  7361. d[1]-this.delta[1], d[0]-this.delta[0]);
  7362. } else {
  7363. this.delta = d;
  7364. }
  7365. if(this.options.zindex)
  7366. this.element.style.zIndex = this.originalZ;
  7367. if(this.options.endeffect)
  7368. this.options.endeffect(this.element);
  7369. Draggables.deactivate(this);
  7370. Droppables.reset();
  7371. },
  7372. keyPress: function(event) {
  7373. if(event.keyCode!=Event.KEY_ESC) return;
  7374. this.finishDrag(event, false);
  7375. Event.stop(event);
  7376. },
  7377. endDrag: function(event) {
  7378. if(!this.dragging) return;
  7379. this.stopScrolling();
  7380. this.finishDrag(event, true);
  7381. Event.stop(event);
  7382. },
  7383. draw: function(point) {
  7384. var pos = this.element.cumulativeOffset();
  7385. if(this.options.ghosting) {
  7386. var r = Position.realOffset(this.element);
  7387. pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY;
  7388. }
  7389. var d = this.currentDelta();
  7390. pos[0] -= d[0]; pos[1] -= d[1];
  7391. if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) {
  7392. pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft;
  7393. pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop;
  7394. }
  7395. var p = [0,1].map(function(i){
  7396. return (point[i]-pos[i]-this.offset[i])
  7397. }.bind(this));
  7398. if(this.options.snap) {
  7399. if(Object.isFunction(this.options.snap)) {
  7400. p = this.options.snap(p[0],p[1],this);
  7401. } else {
  7402. if(Object.isArray(this.options.snap)) {
  7403. p = p.map( function(v, i) {
  7404. return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this));
  7405. } else {
  7406. p = p.map( function(v) {
  7407. return (v/this.options.snap).round()*this.options.snap }.bind(this));
  7408. }
  7409. }}
  7410. var style = this.element.style;
  7411. if((!this.options.constraint) || (this.options.constraint=='horizontal'))
  7412. style.left = p[0] + "px";
  7413. if((!this.options.constraint) || (this.options.constraint=='vertical'))
  7414. style.top = p[1] + "px";
  7415. if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering
  7416. },
  7417. stopScrolling: function() {
  7418. if(this.scrollInterval) {
  7419. clearInterval(this.scrollInterval);
  7420. this.scrollInterval = null;
  7421. Draggables._lastScrollPointer = null;
  7422. }
  7423. },
  7424. startScrolling: function(speed) {
  7425. if(!(speed[0] || speed[1])) return;
  7426. this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed];
  7427. this.lastScrolled = new Date();
  7428. this.scrollInterval = setInterval(this.scroll.bind(this), 10);
  7429. },
  7430. scroll: function() {
  7431. var current = new Date();
  7432. var delta = current - this.lastScrolled;
  7433. this.lastScrolled = current;
  7434. if(this.options.scroll == window) {
  7435. with (this._getWindowScroll(this.options.scroll)) {
  7436. if (this.scrollSpeed[0] || this.scrollSpeed[1]) {
  7437. var d = delta / 1000;
  7438. this.options.scroll.scrollTo( left + d*this.scrollSpeed[0], top + d*this.scrollSpeed[1] );
  7439. }
  7440. }
  7441. } else {
  7442. this.options.scroll.scrollLeft += this.scrollSpeed[0] * delta / 1000;
  7443. this.options.scroll.scrollTop += this.scrollSpeed[1] * delta / 1000;
  7444. }
  7445. Position.prepare();
  7446. Droppables.show(Draggables._lastPointer, this.element);
  7447. Draggables.notify('onDrag', this);
  7448. if (this._isScrollChild) {
  7449. Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer);
  7450. Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000;
  7451. Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000;
  7452. if (Draggables._lastScrollPointer[0] < 0)
  7453. Draggables._lastScrollPointer[0] = 0;
  7454. if (Draggables._lastScrollPointer[1] < 0)
  7455. Draggables._lastScrollPointer[1] = 0;
  7456. this.draw(Draggables._lastScrollPointer);
  7457. }
  7458. if(this.options.change) this.options.change(this);
  7459. },
  7460. _getWindowScroll: function(w) {
  7461. var T, L, W, H;
  7462. with (w.document) {
  7463. if (w.document.documentElement && documentElement.scrollTop) {
  7464. T = documentElement.scrollTop;
  7465. L = documentElement.scrollLeft;
  7466. } else if (w.document.body) {
  7467. T = body.scrollTop;
  7468. L = body.scrollLeft;
  7469. }
  7470. if (w.innerWidth) {
  7471. W = w.innerWidth;
  7472. H = w.innerHeight;
  7473. } else if (w.document.documentElement && documentElement.clientWidth) {
  7474. W = documentElement.clientWidth;
  7475. H = documentElement.clientHeight;
  7476. } else {
  7477. W = body.offsetWidth;
  7478. H = body.offsetHeight;
  7479. }
  7480. }
  7481. return { top: T, left: L, width: W, height: H };
  7482. }
  7483. });
  7484. Draggable._dragging = { };
  7485. /*--------------------------------------------------------------------------*/
  7486. var SortableObserver = Class.create({
  7487. initialize: function(element, observer) {
  7488. this.element = $(element);
  7489. this.observer = observer;
  7490. this.lastValue = Sortable.serialize(this.element);
  7491. },
  7492. onStart: function() {
  7493. this.lastValue = Sortable.serialize(this.element);
  7494. },
  7495. onEnd: function() {
  7496. Sortable.unmark();
  7497. if(this.lastValue != Sortable.serialize(this.element))
  7498. this.observer(this.element)
  7499. }
  7500. });
  7501. var Sortable = {
  7502. SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/,
  7503. sortables: { },
  7504. _findRootElement: function(element) {
  7505. while (element.tagName.toUpperCase() != "BODY") {
  7506. if(element.id && Sortable.sortables[element.id]) return element;
  7507. element = element.parentNode;
  7508. }
  7509. },
  7510. options: function(element) {
  7511. element = Sortable._findRootElement($(element));
  7512. if(!element) return;
  7513. return Sortable.sortables[element.id];
  7514. },
  7515. destroy: function(element){
  7516. element = $(element);
  7517. var s = Sortable.sortables[element.id];
  7518. if(s) {
  7519. Draggables.removeObserver(s.element);
  7520. s.droppables.each(function(d){ Droppables.remove(d) });
  7521. s.draggables.invoke('destroy');
  7522. delete Sortable.sortables[s.element.id];
  7523. }
  7524. },
  7525. create: function(element) {
  7526. element = $(element);
  7527. var options = Object.extend({
  7528. element: element,
  7529. tag: 'li', // assumes li children, override with tag: 'tagname'
  7530. dropOnEmpty: false,
  7531. tree: false,
  7532. treeTag: 'ul',
  7533. overlap: 'vertical', // one of 'vertical', 'horizontal'
  7534. constraint: 'vertical', // one of 'vertical', 'horizontal', false
  7535. containment: element, // also takes array of elements (or id's); or false
  7536. handle: false, // or a CSS class
  7537. only: false,
  7538. delay: 0,
  7539. hoverclass: null,
  7540. ghosting: false,
  7541. quiet: false,
  7542. scroll: false,
  7543. scrollSensitivity: 20,
  7544. scrollSpeed: 15,
  7545. format: this.SERIALIZE_RULE,
  7546. // these take arrays of elements or ids and can be
  7547. // used for better initialization performance
  7548. elements: false,
  7549. handles: false,
  7550. onChange: Prototype.emptyFunction,
  7551. onUpdate: Prototype.emptyFunction
  7552. }, arguments[1] || { });
  7553. // clear any old sortable with same element
  7554. this.destroy(element);
  7555. // build options for the draggables
  7556. var options_for_draggable = {
  7557. revert: true,
  7558. quiet: options.quiet,
  7559. scroll: options.scroll,
  7560. scrollSpeed: options.scrollSpeed,
  7561. scrollSensitivity: options.scrollSensitivity,
  7562. delay: options.delay,
  7563. ghosting: options.ghosting,
  7564. constraint: options.constraint,
  7565. handle: options.handle };
  7566. if(options.starteffect)
  7567. options_for_draggable.starteffect = options.starteffect;
  7568. if(options.reverteffect)
  7569. options_for_draggable.reverteffect = options.reverteffect;
  7570. else
  7571. if(options.ghosting) options_for_draggable.reverteffect = function(element) {
  7572. element.style.top = 0;
  7573. element.style.left = 0;
  7574. };
  7575. if(options.endeffect)
  7576. options_for_draggable.endeffect = options.endeffect;
  7577. if(options.zindex)
  7578. options_for_draggable.zindex = options.zindex;
  7579. // build options for the droppables
  7580. var options_for_droppable = {
  7581. overlap: options.overlap,
  7582. containment: options.containment,
  7583. tree: options.tree,
  7584. hoverclass: options.hoverclass,
  7585. onHover: Sortable.onHover
  7586. };
  7587. var options_for_tree = {
  7588. onHover: Sortable.onEmptyHover,
  7589. overlap: options.overlap,
  7590. containment: options.containment,
  7591. hoverclass: options.hoverclass
  7592. };
  7593. // fix for gecko engine
  7594. Element.cleanWhitespace(element);
  7595. options.draggables = [];
  7596. options.droppables = [];
  7597. // drop on empty handling
  7598. if(options.dropOnEmpty || options.tree) {
  7599. Droppables.add(element, options_for_tree);
  7600. options.droppables.push(element);
  7601. }
  7602. (options.elements || this.findElements(element, options) || []).each( function(e,i) {
  7603. var handle = options.handles ? $(options.handles[i]) :
  7604. (options.handle ? $(e).select('.' + options.handle)[0] : e);
  7605. options.draggables.push(
  7606. new Draggable(e, Object.extend(options_for_draggable, { handle: handle })));
  7607. Droppables.add(e, options_for_droppable);
  7608. if(options.tree) e.treeNode = element;
  7609. options.droppables.push(e);
  7610. });
  7611. if(options.tree) {
  7612. (Sortable.findTreeElements(element, options) || []).each( function(e) {
  7613. Droppables.add(e, options_for_tree);
  7614. e.treeNode = element;
  7615. options.droppables.push(e);
  7616. });
  7617. }
  7618. // keep reference
  7619. this.sortables[element.identify()] = options;
  7620. // for onupdate
  7621. Draggables.addObserver(new SortableObserver(element, options.onUpdate));
  7622. },
  7623. // return all suitable-for-sortable elements in a guaranteed order
  7624. findElements: function(element, options) {
  7625. return Element.findChildren(
  7626. element, options.only, options.tree ? true : false, options.tag);
  7627. },
  7628. findTreeElements: function(element, options) {
  7629. return Element.findChildren(
  7630. element, options.only, options.tree ? true : false, options.treeTag);
  7631. },
  7632. onHover: function(element, dropon, overlap) {
  7633. if(Element.isParent(dropon, element)) return;
  7634. if(overlap > .33 && overlap < .66 && Sortable.options(dropon).tree) {
  7635. return;
  7636. } else if(overlap>0.5) {
  7637. Sortable.mark(dropon, 'before');
  7638. if(dropon.previousSibling != element) {
  7639. var oldParentNode = element.parentNode;
  7640. element.style.visibility = "hidden"; // fix gecko rendering
  7641. dropon.parentNode.insertBefore(element, dropon);
  7642. if(dropon.parentNode!=oldParentNode)
  7643. Sortable.options(oldParentNode).onChange(element);
  7644. Sortable.options(dropon.parentNode).onChange(element);
  7645. }
  7646. } else {
  7647. Sortable.mark(dropon, 'after');
  7648. var nextElement = dropon.nextSibling || null;
  7649. if(nextElement != element) {
  7650. var oldParentNode = element.parentNode;
  7651. element.style.visibility = "hidden"; // fix gecko rendering
  7652. dropon.parentNode.insertBefore(element, nextElement);
  7653. if(dropon.parentNode!=oldParentNode)
  7654. Sortable.options(oldParentNode).onChange(element);
  7655. Sortable.options(dropon.parentNode).onChange(element);
  7656. }
  7657. }
  7658. },
  7659. onEmptyHover: function(element, dropon, overlap) {
  7660. var oldParentNode = element.parentNode;
  7661. var droponOptions = Sortable.options(dropon);
  7662. if(!Element.isParent(dropon, element)) {
  7663. var index;
  7664. var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only});
  7665. var child = null;
  7666. if(children) {
  7667. var offset = Element.offsetSize(dropon, droponOptions.overlap) * (1.0 - overlap);
  7668. for (index = 0; index < children.length; index += 1) {
  7669. if (offset - Element.offsetSize (children[index], droponOptions.overlap) >= 0) {
  7670. offset -= Element.offsetSize (children[index], droponOptions.overlap);
  7671. } else if (offset - (Element.offsetSize (children[index], droponOptions.overlap) / 2) >= 0) {
  7672. child = index + 1 < children.length ? children[index + 1] : null;
  7673. break;
  7674. } else {
  7675. child = children[index];
  7676. break;
  7677. }
  7678. }
  7679. }
  7680. dropon.insertBefore(element, child);
  7681. Sortable.options(oldParentNode).onChange(element);
  7682. droponOptions.onChange(element);
  7683. }
  7684. },
  7685. unmark: function() {
  7686. if(Sortable._marker) Sortable._marker.hide();
  7687. },
  7688. mark: function(dropon, position) {
  7689. // mark on ghosting only
  7690. var sortable = Sortable.options(dropon.parentNode);
  7691. if(sortable && !sortable.ghosting) return;
  7692. if(!Sortable._marker) {
  7693. Sortable._marker =
  7694. ($('dropmarker') || Element.extend(document.createElement('DIV'))).
  7695. hide().addClassName('dropmarker').setStyle({position:'absolute'});
  7696. document.getElementsByTagName("body").item(0).appendChild(Sortable._marker);
  7697. }
  7698. var offsets = dropon.cumulativeOffset();
  7699. Sortable._marker.setStyle({left: offsets[0]+'px', top: offsets[1] + 'px'});
  7700. if(position=='after')
  7701. if(sortable.overlap == 'horizontal')
  7702. Sortable._marker.setStyle({left: (offsets[0]+dropon.clientWidth) + 'px'});
  7703. else
  7704. Sortable._marker.setStyle({top: (offsets[1]+dropon.clientHeight) + 'px'});
  7705. Sortable._marker.show();
  7706. },
  7707. _tree: function(element, options, parent) {
  7708. var children = Sortable.findElements(element, options) || [];
  7709. for (var i = 0; i < children.length; ++i) {
  7710. var match = children[i].id.match(options.format);
  7711. if (!match) continue;
  7712. var child = {
  7713. id: encodeURIComponent(match ? match[1] : null),
  7714. element: element,
  7715. parent: parent,
  7716. children: [],
  7717. position: parent.children.length,
  7718. container: $(children[i]).down(options.treeTag)
  7719. };
  7720. /* Get the element containing the children and recurse over it */
  7721. if (child.container)
  7722. this._tree(child.container, options, child);
  7723. parent.children.push (child);
  7724. }
  7725. return parent;
  7726. },
  7727. tree: function(element) {
  7728. element = $(element);
  7729. var sortableOptions = this.options(element);
  7730. var options = Object.extend({
  7731. tag: sortableOptions.tag,
  7732. treeTag: sortableOptions.treeTag,
  7733. only: sortableOptions.only,
  7734. name: element.id,
  7735. format: sortableOptions.format
  7736. }, arguments[1] || { });
  7737. var root = {
  7738. id: null,
  7739. parent: null,
  7740. children: [],
  7741. container: element,
  7742. position: 0
  7743. };
  7744. return Sortable._tree(element, options, root);
  7745. },
  7746. /* Construct a [i] index for a particular node */
  7747. _constructIndex: function(node) {
  7748. var index = '';
  7749. do {
  7750. if (node.id) index = '[' + node.position + ']' + index;
  7751. } while ((node = node.parent) != null);
  7752. return index;
  7753. },
  7754. sequence: function(element) {
  7755. element = $(element);
  7756. var options = Object.extend(this.options(element), arguments[1] || { });
  7757. return $(this.findElements(element, options) || []).map( function(item) {
  7758. return item.id.match(options.format) ? item.id.match(options.format)[1] : '';
  7759. });
  7760. },
  7761. setSequence: function(element, new_sequence) {
  7762. element = $(element);
  7763. var options = Object.extend(this.options(element), arguments[2] || { });
  7764. var nodeMap = { };
  7765. this.findElements(element, options).each( function(n) {
  7766. if (n.id.match(options.format))
  7767. nodeMap[n.id.match(options.format)[1]] = [n, n.parentNode];
  7768. n.parentNode.removeChild(n);
  7769. });
  7770. new_sequence.each(function(ident) {
  7771. var n = nodeMap[ident];
  7772. if (n) {
  7773. n[1].appendChild(n[0]);
  7774. delete nodeMap[ident];
  7775. }
  7776. });
  7777. },
  7778. serialize: function(element) {
  7779. element = $(element);
  7780. var options = Object.extend(Sortable.options(element), arguments[1] || { });
  7781. var name = encodeURIComponent(
  7782. (arguments[1] && arguments[1].name) ? arguments[1].name : element.id);
  7783. if (options.tree) {
  7784. return Sortable.tree(element, arguments[1]).children.map( function (item) {
  7785. return [name + Sortable._constructIndex(item) + "[id]=" +
  7786. encodeURIComponent(item.id)].concat(item.children.map(arguments.callee));
  7787. }).flatten().join('&');
  7788. } else {
  7789. return Sortable.sequence(element, arguments[1]).map( function(item) {
  7790. return name + "[]=" + encodeURIComponent(item);
  7791. }).join('&');
  7792. }
  7793. }
  7794. };
  7795. // Returns true if child is contained within element
  7796. Element.isParent = function(child, element) {
  7797. if (!child.parentNode || child == element) return false;
  7798. if (child.parentNode == element) return true;
  7799. return Element.isParent(child.parentNode, element);
  7800. };
  7801. Element.findChildren = function(element, only, recursive, tagName) {
  7802. if(!element.hasChildNodes()) return null;
  7803. tagName = tagName.toUpperCase();
  7804. if(only) only = [only].flatten();
  7805. var elements = [];
  7806. $A(element.childNodes).each( function(e) {
  7807. if(e.tagName && e.tagName.toUpperCase()==tagName &&
  7808. (!only || (Element.classNames(e).detect(function(v) { return only.include(v) }))))
  7809. elements.push(e);
  7810. if(recursive) {
  7811. var grandchildren = Element.findChildren(e, only, recursive, tagName);
  7812. if(grandchildren) elements.push(grandchildren);
  7813. }
  7814. });
  7815. return (elements.length>0 ? elements.flatten() : []);
  7816. };
  7817. Element.offsetSize = function (element, type) {
  7818. return element['offset' + ((type=='vertical' || type=='height') ? 'Height' : 'Width')];
  7819. };
  7820. // script.aculo.us controls.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008
  7821. // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
  7822. // (c) 2005-2008 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
  7823. // (c) 2005-2008 Jon Tirsen (http://www.tirsen.com)
  7824. // Contributors:
  7825. // Richard Livsey
  7826. // Rahul Bhargava
  7827. // Rob Wills
  7828. //
  7829. // script.aculo.us is freely distributable under the terms of an MIT-style license.
  7830. // For details, see the script.aculo.us web site: http://script.aculo.us/
  7831. // Autocompleter.Base handles all the autocompletion functionality
  7832. // that's independent of the data source for autocompletion. This
  7833. // includes drawing the autocompletion menu, observing keyboard
  7834. // and mouse events, and similar.
  7835. //
  7836. // Specific autocompleters need to provide, at the very least,
  7837. // a getUpdatedChoices function that will be invoked every time
  7838. // the text inside the monitored textbox changes. This method
  7839. // should get the text for which to provide autocompletion by
  7840. // invoking this.getToken(), NOT by directly accessing
  7841. // this.element.value. This is to allow incremental tokenized
  7842. // autocompletion. Specific auto-completion logic (AJAX, etc)
  7843. // belongs in getUpdatedChoices.
  7844. //
  7845. // Tokenized incremental autocompletion is enabled automatically
  7846. // when an autocompleter is instantiated with the 'tokens' option
  7847. // in the options parameter, e.g.:
  7848. // new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
  7849. // will incrementally autocomplete with a comma as the token.
  7850. // Additionally, ',' in the above example can be replaced with
  7851. // a token array, e.g. { tokens: [',', '\n'] } which
  7852. // enables autocompletion on multiple tokens. This is most
  7853. // useful when one of the tokens is \n (a newline), as it
  7854. // allows smart autocompletion after linebreaks.
  7855. if(typeof Effect == 'undefined')
  7856. throw("controls.js requires including script.aculo.us' effects.js library");
  7857. var Autocompleter = { };
  7858. Autocompleter.Base = Class.create({
  7859. baseInitialize: function(element, update, options) {
  7860. element = $(element);
  7861. this.element = element;
  7862. this.update = $(update);
  7863. this.hasFocus = false;
  7864. this.changed = false;
  7865. this.active = false;
  7866. this.index = 0;
  7867. this.entryCount = 0;
  7868. this.oldElementValue = this.element.value;
  7869. if(this.setOptions)
  7870. this.setOptions(options);
  7871. else
  7872. this.options = options || { };
  7873. this.options.paramName = this.options.paramName || this.element.name;
  7874. this.options.tokens = this.options.tokens || [];
  7875. this.options.frequency = this.options.frequency || 0.4;
  7876. this.options.minChars = this.options.minChars || 1;
  7877. this.options.onShow = this.options.onShow ||
  7878. function(element, update){
  7879. if(!update.style.position || update.style.position=='absolute') {
  7880. update.style.position = 'absolute';
  7881. Position.clone(element, update, {
  7882. setHeight: false,
  7883. offsetTop: element.offsetHeight
  7884. });
  7885. }
  7886. Effect.Appear(update,{duration:0.15});
  7887. };
  7888. this.options.onHide = this.options.onHide ||
  7889. function(element, update){ new Effect.Fade(update,{duration:0.15}) };
  7890. if(typeof(this.options.tokens) == 'string')
  7891. this.options.tokens = new Array(this.options.tokens);
  7892. // Force carriage returns as token delimiters anyway
  7893. if (!this.options.tokens.include('\n'))
  7894. this.options.tokens.push('\n');
  7895. this.observer = null;
  7896. this.element.setAttribute('autocomplete','off');
  7897. Element.hide(this.update);
  7898. Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
  7899. Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
  7900. },
  7901. show: function() {
  7902. if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
  7903. if(!this.iefix &&
  7904. (Prototype.Browser.IE) &&
  7905. (Element.getStyle(this.update, 'position')=='absolute')) {
  7906. new Insertion.After(this.update,
  7907. '<iframe id="' + this.update.id + '_iefix" '+
  7908. 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
  7909. 'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
  7910. this.iefix = $(this.update.id+'_iefix');
  7911. }
  7912. if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
  7913. },
  7914. fixIEOverlapping: function() {
  7915. Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
  7916. this.iefix.style.zIndex = 1;
  7917. this.update.style.zIndex = 2;
  7918. Element.show(this.iefix);
  7919. },
  7920. hide: function() {
  7921. this.stopIndicator();
  7922. if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
  7923. if(this.iefix) Element.hide(this.iefix);
  7924. },
  7925. startIndicator: function() {
  7926. if(this.options.indicator) Element.show(this.options.indicator);
  7927. },
  7928. stopIndicator: function() {
  7929. if(this.options.indicator) Element.hide(this.options.indicator);
  7930. },
  7931. onKeyPress: function(event) {
  7932. if(this.active)
  7933. switch(event.keyCode) {
  7934. case Event.KEY_TAB:
  7935. case Event.KEY_RETURN:
  7936. this.selectEntry();
  7937. Event.stop(event);
  7938. case Event.KEY_ESC:
  7939. this.hide();
  7940. this.active = false;
  7941. Event.stop(event);
  7942. return;
  7943. case Event.KEY_LEFT:
  7944. case Event.KEY_RIGHT:
  7945. return;
  7946. case Event.KEY_UP:
  7947. this.markPrevious();
  7948. this.render();
  7949. Event.stop(event);
  7950. return;
  7951. case Event.KEY_DOWN:
  7952. this.markNext();
  7953. this.render();
  7954. Event.stop(event);
  7955. return;
  7956. }
  7957. else
  7958. if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
  7959. (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
  7960. this.changed = true;
  7961. this.hasFocus = true;
  7962. if(this.observer) clearTimeout(this.observer);
  7963. this.observer =
  7964. setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
  7965. },
  7966. activate: function() {
  7967. this.changed = false;
  7968. this.hasFocus = true;
  7969. this.getUpdatedChoices();
  7970. },
  7971. onHover: function(event) {
  7972. var element = Event.findElement(event, 'LI');
  7973. if(this.index != element.autocompleteIndex)
  7974. {
  7975. this.index = element.autocompleteIndex;
  7976. this.render();
  7977. }
  7978. Event.stop(event);
  7979. },
  7980. onClick: function(event) {
  7981. var element = Event.findElement(event, 'LI');
  7982. this.index = element.autocompleteIndex;
  7983. this.selectEntry();
  7984. this.hide();
  7985. },
  7986. onBlur: function(event) {
  7987. // needed to make click events working
  7988. setTimeout(this.hide.bind(this), 250);
  7989. this.hasFocus = false;
  7990. this.active = false;
  7991. },
  7992. render: function() {
  7993. if(this.entryCount > 0) {
  7994. for (var i = 0; i < this.entryCount; i++)
  7995. this.index==i ?
  7996. Element.addClassName(this.getEntry(i),"selected") :
  7997. Element.removeClassName(this.getEntry(i),"selected");
  7998. if(this.hasFocus) {
  7999. this.show();
  8000. this.active = true;
  8001. }
  8002. } else {
  8003. this.active = false;
  8004. this.hide();
  8005. }
  8006. },
  8007. markPrevious: function() {
  8008. if(this.index > 0) this.index--;
  8009. else this.index = this.entryCount-1;
  8010. //this.getEntry(this.index).scrollIntoView(true); useless
  8011. },
  8012. markNext: function() {
  8013. if(this.index < this.entryCount-1) this.index++;
  8014. else this.index = 0;
  8015. this.getEntry(this.index).scrollIntoView(false);
  8016. },
  8017. getEntry: function(index) {
  8018. return this.update.firstChild.childNodes[index];
  8019. },
  8020. getCurrentEntry: function() {
  8021. return this.getEntry(this.index);
  8022. },
  8023. selectEntry: function() {
  8024. this.active = false;
  8025. this.updateElement(this.getCurrentEntry());
  8026. },
  8027. updateElement: function(selectedElement) {
  8028. if (this.options.updateElement) {
  8029. this.options.updateElement(selectedElement);
  8030. return;
  8031. }
  8032. var value = '';
  8033. if (this.options.select) {
  8034. var nodes = $(selectedElement).select('.' + this.options.select) || [];
  8035. if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
  8036. } else
  8037. value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
  8038. var bounds = this.getTokenBounds();
  8039. if (bounds[0] != -1) {
  8040. var newValue = this.element.value.substr(0, bounds[0]);
  8041. var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/);
  8042. if (whitespace)
  8043. newValue += whitespace[0];
  8044. this.element.value = newValue + value + this.element.value.substr(bounds[1]);
  8045. } else {
  8046. this.element.value = value;
  8047. }
  8048. this.oldElementValue = this.element.value;
  8049. this.element.focus();
  8050. if (this.options.afterUpdateElement)
  8051. this.options.afterUpdateElement(this.element, selectedElement);
  8052. },
  8053. updateChoices: function(choices) {
  8054. if(!this.changed && this.hasFocus) {
  8055. this.update.innerHTML = choices;
  8056. Element.cleanWhitespace(this.update);
  8057. Element.cleanWhitespace(this.update.down());
  8058. if(this.update.firstChild && this.update.down().childNodes) {
  8059. this.entryCount =
  8060. this.update.down().childNodes.length;
  8061. for (var i = 0; i < this.entryCount; i++) {
  8062. var entry = this.getEntry(i);
  8063. entry.autocompleteIndex = i;
  8064. this.addObservers(entry);
  8065. }
  8066. } else {
  8067. this.entryCount = 0;
  8068. }
  8069. this.stopIndicator();
  8070. this.index = 0;
  8071. if(this.entryCount==1 && this.options.autoSelect) {
  8072. this.selectEntry();
  8073. this.hide();
  8074. } else {
  8075. this.render();
  8076. }
  8077. }
  8078. },
  8079. addObservers: function(element) {
  8080. Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
  8081. Event.observe(element, "click", this.onClick.bindAsEventListener(this));
  8082. },
  8083. onObserverEvent: function() {
  8084. this.changed = false;
  8085. this.tokenBounds = null;
  8086. if(this.getToken().length>=this.options.minChars) {
  8087. this.getUpdatedChoices();
  8088. } else {
  8089. this.active = false;
  8090. this.hide();
  8091. }
  8092. this.oldElementValue = this.element.value;
  8093. },
  8094. getToken: function() {
  8095. var bounds = this.getTokenBounds();
  8096. return this.element.value.substring(bounds[0], bounds[1]).strip();
  8097. },
  8098. getTokenBounds: function() {
  8099. if (null != this.tokenBounds) return this.tokenBounds;
  8100. var value = this.element.value;
  8101. if (value.strip().empty()) return [-1, 0];
  8102. var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue);
  8103. var offset = (diff == this.oldElementValue.length ? 1 : 0);
  8104. var prevTokenPos = -1, nextTokenPos = value.length;
  8105. var tp;
  8106. for (var index = 0, l = this.options.tokens.length; index < l; ++index) {
  8107. tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1);
  8108. if (tp > prevTokenPos) prevTokenPos = tp;
  8109. tp = value.indexOf(this.options.tokens[index], diff + offset);
  8110. if (-1 != tp && tp < nextTokenPos) nextTokenPos = tp;
  8111. }
  8112. return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]);
  8113. }
  8114. });
  8115. Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) {
  8116. var boundary = Math.min(newS.length, oldS.length);
  8117. for (var index = 0; index < boundary; ++index)
  8118. if (newS[index] != oldS[index])
  8119. return index;
  8120. return boundary;
  8121. };
  8122. Ajax.Autocompleter = Class.create(Autocompleter.Base, {
  8123. initialize: function(element, update, url, options) {
  8124. this.baseInitialize(element, update, options);
  8125. this.options.asynchronous = true;
  8126. this.options.onComplete = this.onComplete.bind(this);
  8127. this.options.defaultParams = this.options.parameters || null;
  8128. this.url = url;
  8129. },
  8130. getUpdatedChoices: function() {
  8131. this.startIndicator();
  8132. var entry = encodeURIComponent(this.options.paramName) + '=' +
  8133. encodeURIComponent(this.getToken());
  8134. this.options.parameters = this.options.callback ?
  8135. this.options.callback(this.element, entry) : entry;
  8136. if(this.options.defaultParams)
  8137. this.options.parameters += '&' + this.options.defaultParams;
  8138. new Ajax.Request(this.url, this.options);
  8139. },
  8140. onComplete: function(request) {
  8141. this.updateChoices(request.responseText);
  8142. }
  8143. });
  8144. // The local array autocompleter. Used when you'd prefer to
  8145. // inject an array of autocompletion options into the page, rather
  8146. // than sending out Ajax queries, which can be quite slow sometimes.
  8147. //
  8148. // The constructor takes four parameters. The first two are, as usual,
  8149. // the id of the monitored textbox, and id of the autocompletion menu.
  8150. // The third is the array you want to autocomplete from, and the fourth
  8151. // is the options block.
  8152. //
  8153. // Extra local autocompletion options:
  8154. // - choices - How many autocompletion choices to offer
  8155. //
  8156. // - partialSearch - If false, the autocompleter will match entered
  8157. // text only at the beginning of strings in the
  8158. // autocomplete array. Defaults to true, which will
  8159. // match text at the beginning of any *word* in the
  8160. // strings in the autocomplete array. If you want to
  8161. // search anywhere in the string, additionally set
  8162. // the option fullSearch to true (default: off).
  8163. //
  8164. // - fullSsearch - Search anywhere in autocomplete array strings.
  8165. //
  8166. // - partialChars - How many characters to enter before triggering
  8167. // a partial match (unlike minChars, which defines
  8168. // how many characters are required to do any match
  8169. // at all). Defaults to 2.
  8170. //
  8171. // - ignoreCase - Whether to ignore case when autocompleting.
  8172. // Defaults to true.
  8173. //
  8174. // It's possible to pass in a custom function as the 'selector'
  8175. // option, if you prefer to write your own autocompletion logic.
  8176. // In that case, the other options above will not apply unless
  8177. // you support them.
  8178. Autocompleter.Local = Class.create(Autocompleter.Base, {
  8179. initialize: function(element, update, array, options) {
  8180. this.baseInitialize(element, update, options);
  8181. this.options.array = array;
  8182. },
  8183. getUpdatedChoices: function() {
  8184. this.updateChoices(this.options.selector(this));
  8185. },
  8186. setOptions: function(options) {
  8187. this.options = Object.extend({
  8188. choices: 10,
  8189. partialSearch: true,
  8190. partialChars: 2,
  8191. ignoreCase: true,
  8192. fullSearch: false,
  8193. selector: function(instance) {
  8194. var ret = []; // Beginning matches
  8195. var partial = []; // Inside matches
  8196. var entry = instance.getToken();
  8197. var count = 0;
  8198. for (var i = 0; i < instance.options.array.length &&
  8199. ret.length < instance.options.choices ; i++) {
  8200. var elem = instance.options.array[i];
  8201. var foundPos = instance.options.ignoreCase ?
  8202. elem.toLowerCase().indexOf(entry.toLowerCase()) :
  8203. elem.indexOf(entry);
  8204. while (foundPos != -1) {
  8205. if (foundPos == 0 && elem.length != entry.length) {
  8206. ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
  8207. elem.substr(entry.length) + "</li>");
  8208. break;
  8209. } else if (entry.length >= instance.options.partialChars &&
  8210. instance.options.partialSearch && foundPos != -1) {
  8211. if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
  8212. partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
  8213. elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
  8214. foundPos + entry.length) + "</li>");
  8215. break;
  8216. }
  8217. }
  8218. foundPos = instance.options.ignoreCase ?
  8219. elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
  8220. elem.indexOf(entry, foundPos + 1);
  8221. }
  8222. }
  8223. if (partial.length)
  8224. ret = ret.concat(partial.slice(0, instance.options.choices - ret.length));
  8225. return "<ul>" + ret.join('') + "</ul>";
  8226. }
  8227. }, options || { });
  8228. }
  8229. });
  8230. // AJAX in-place editor and collection editor
  8231. // Full rewrite by Christophe Porteneuve <tdd@tddsworld.com> (April 2007).
  8232. // Use this if you notice weird scrolling problems on some browsers,
  8233. // the DOM might be a bit confused when this gets called so do this
  8234. // waits 1 ms (with setTimeout) until it does the activation
  8235. Field.scrollFreeActivate = function(field) {
  8236. setTimeout(function() {
  8237. Field.activate(field);
  8238. }, 1);
  8239. };
  8240. Ajax.InPlaceEditor = Class.create({
  8241. initialize: function(element, url, options) {
  8242. this.url = url;
  8243. this.element = element = $(element);
  8244. this.prepareOptions();
  8245. this._controls = { };
  8246. arguments.callee.dealWithDeprecatedOptions(options); // DEPRECATION LAYER!!!
  8247. Object.extend(this.options, options || { });
  8248. if (!this.options.formId && this.element.id) {
  8249. this.options.formId = this.element.id + '-inplaceeditor';
  8250. if ($(this.options.formId))
  8251. this.options.formId = '';
  8252. }
  8253. if (this.options.externalControl)
  8254. this.options.externalControl = $(this.options.externalControl);
  8255. if (!this.options.externalControl)
  8256. this.options.externalControlOnly = false;
  8257. this._originalBackground = this.element.getStyle('background-color') || 'transparent';
  8258. this.element.title = this.options.clickToEditText;
  8259. this._boundCancelHandler = this.handleFormCancellation.bind(this);
  8260. this._boundComplete = (this.options.onComplete || Prototype.emptyFunction).bind(this);
  8261. this._boundFailureHandler = this.handleAJAXFailure.bind(this);
  8262. this._boundSubmitHandler = this.handleFormSubmission.bind(this);
  8263. this._boundWrapperHandler = this.wrapUp.bind(this);
  8264. this.registerListeners();
  8265. },
  8266. checkForEscapeOrReturn: function(e) {
  8267. if (!this._editing || e.ctrlKey || e.altKey || e.shiftKey) return;
  8268. if (Event.KEY_ESC == e.keyCode)
  8269. this.handleFormCancellation(e);
  8270. else if (Event.KEY_RETURN == e.keyCode)
  8271. this.handleFormSubmission(e);
  8272. },
  8273. createControl: function(mode, handler, extraClasses) {
  8274. var control = this.options[mode + 'Control'];
  8275. var text = this.options[mode + 'Text'];
  8276. if ('button' == control) {
  8277. var btn = document.createElement('input');
  8278. btn.type = 'submit';
  8279. btn.value = text;
  8280. btn.className = 'editor_' + mode + '_button';
  8281. if ('cancel' == mode)
  8282. btn.onclick = this._boundCancelHandler;
  8283. this._form.appendChild(btn);
  8284. this._controls[mode] = btn;
  8285. } else if ('link' == control) {
  8286. var link = document.createElement('a');
  8287. link.href = '#';
  8288. link.appendChild(document.createTextNode(text));
  8289. link.onclick = 'cancel' == mode ? this._boundCancelHandler : this._boundSubmitHandler;
  8290. link.className = 'editor_' + mode + '_link';
  8291. if (extraClasses)
  8292. link.className += ' ' + extraClasses;
  8293. this._form.appendChild(link);
  8294. this._controls[mode] = link;
  8295. }
  8296. },
  8297. createEditField: function() {
  8298. var text = (this.options.loadTextURL ? this.options.loadingText : this.getText());
  8299. var fld;
  8300. if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) {
  8301. fld = document.createElement('input');
  8302. fld.type = 'text';
  8303. var size = this.options.size || this.options.cols || 0;
  8304. if (0 < size) fld.size = size;
  8305. } else {
  8306. fld = document.createElement('textarea');
  8307. fld.rows = (1 >= this.options.rows ? this.options.autoRows : this.options.rows);
  8308. fld.cols = this.options.cols || 40;
  8309. }
  8310. fld.name = this.options.paramName;
  8311. fld.value = text; // No HTML breaks conversion anymore
  8312. fld.className = 'editor_field';
  8313. if (this.options.submitOnBlur)
  8314. fld.onblur = this._boundSubmitHandler;
  8315. this._controls.editor = fld;
  8316. if (this.options.loadTextURL)
  8317. this.loadExternalText();
  8318. this._form.appendChild(this._controls.editor);
  8319. },
  8320. createForm: function() {
  8321. var ipe = this;
  8322. function addText(mode, condition) {
  8323. var text = ipe.options['text' + mode + 'Controls'];
  8324. if (!text || condition === false) return;
  8325. ipe._form.appendChild(document.createTextNode(text));
  8326. };
  8327. this._form = $(document.createElement('form'));
  8328. this._form.id = this.options.formId;
  8329. this._form.addClassName(this.options.formClassName);
  8330. this._form.onsubmit = this._boundSubmitHandler;
  8331. this.createEditField();
  8332. if ('textarea' == this._controls.editor.tagName.toLowerCase())
  8333. this._form.appendChild(document.createElement('br'));
  8334. if (this.options.onFormCustomization)
  8335. this.options.onFormCustomization(this, this._form);
  8336. addText('Before', this.options.okControl || this.options.cancelControl);
  8337. this.createControl('ok', this._boundSubmitHandler);
  8338. addText('Between', this.options.okControl && this.options.cancelControl);
  8339. this.createControl('cancel', this._boundCancelHandler, 'editor_cancel');
  8340. addText('After', this.options.okControl || this.options.cancelControl);
  8341. },
  8342. destroy: function() {
  8343. if (this._oldInnerHTML)
  8344. this.element.innerHTML = this._oldInnerHTML;
  8345. this.leaveEditMode();
  8346. this.unregisterListeners();
  8347. },
  8348. enterEditMode: function(e) {
  8349. if (this._saving || this._editing) return;
  8350. this._editing = true;
  8351. this.triggerCallback('onEnterEditMode');
  8352. if (this.options.externalControl)
  8353. this.options.externalControl.hide();
  8354. this.element.hide();
  8355. this.createForm();
  8356. this.element.parentNode.insertBefore(this._form, this.element);
  8357. if (!this.options.loadTextURL)
  8358. this.postProcessEditField();
  8359. if (e) Event.stop(e);
  8360. },
  8361. enterHover: function(e) {
  8362. if (this.options.hoverClassName)
  8363. this.element.addClassName(this.options.hoverClassName);
  8364. if (this._saving) return;
  8365. this.triggerCallback('onEnterHover');
  8366. },
  8367. getText: function() {
  8368. return this.element.innerHTML.unescapeHTML();
  8369. },
  8370. handleAJAXFailure: function(transport) {
  8371. this.triggerCallback('onFailure', transport);
  8372. if (this._oldInnerHTML) {
  8373. this.element.innerHTML = this._oldInnerHTML;
  8374. this._oldInnerHTML = null;
  8375. }
  8376. },
  8377. handleFormCancellation: function(e) {
  8378. this.wrapUp();
  8379. if (e) Event.stop(e);
  8380. },
  8381. handleFormSubmission: function(e) {
  8382. var form = this._form;
  8383. var value = $F(this._controls.editor);
  8384. this.prepareSubmission();
  8385. var params = this.options.callback(form, value) || '';
  8386. if (Object.isString(params))
  8387. params = params.toQueryParams();
  8388. params.editorId = this.element.id;
  8389. if (this.options.htmlResponse) {
  8390. var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions);
  8391. Object.extend(options, {
  8392. parameters: params,
  8393. onComplete: this._boundWrapperHandler,
  8394. onFailure: this._boundFailureHandler
  8395. });
  8396. new Ajax.Updater({ success: this.element }, this.url, options);
  8397. } else {
  8398. var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
  8399. Object.extend(options, {
  8400. parameters: params,
  8401. onComplete: this._boundWrapperHandler,
  8402. onFailure: this._boundFailureHandler
  8403. });
  8404. new Ajax.Request(this.url, options);
  8405. }
  8406. if (e) Event.stop(e);
  8407. },
  8408. leaveEditMode: function() {
  8409. this.element.removeClassName(this.options.savingClassName);
  8410. this.removeForm();
  8411. this.leaveHover();
  8412. this.element.style.backgroundColor = this._originalBackground;
  8413. this.element.show();
  8414. if (this.options.externalControl)
  8415. this.options.externalControl.show();
  8416. this._saving = false;
  8417. this._editing = false;
  8418. this._oldInnerHTML = null;
  8419. this.triggerCallback('onLeaveEditMode');
  8420. },
  8421. leaveHover: function(e) {
  8422. if (this.options.hoverClassName)
  8423. this.element.removeClassName(this.options.hoverClassName);
  8424. if (this._saving) return;
  8425. this.triggerCallback('onLeaveHover');
  8426. },
  8427. loadExternalText: function() {
  8428. this._form.addClassName(this.options.loadingClassName);
  8429. this._controls.editor.disabled = true;
  8430. var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
  8431. Object.extend(options, {
  8432. parameters: 'editorId=' + encodeURIComponent(this.element.id),
  8433. onComplete: Prototype.emptyFunction,
  8434. onSuccess: function(transport) {
  8435. this._form.removeClassName(this.options.loadingClassName);
  8436. var text = transport.responseText;
  8437. if (this.options.stripLoadedTextTags)
  8438. text = text.stripTags();
  8439. this._controls.editor.value = text;
  8440. this._controls.editor.disabled = false;
  8441. this.postProcessEditField();
  8442. }.bind(this),
  8443. onFailure: this._boundFailureHandler
  8444. });
  8445. new Ajax.Request(this.options.loadTextURL, options);
  8446. },
  8447. postProcessEditField: function() {
  8448. var fpc = this.options.fieldPostCreation;
  8449. if (fpc)
  8450. $(this._controls.editor)['focus' == fpc ? 'focus' : 'activate']();
  8451. },
  8452. prepareOptions: function() {
  8453. this.options = Object.clone(Ajax.InPlaceEditor.DefaultOptions);
  8454. Object.extend(this.options, Ajax.InPlaceEditor.DefaultCallbacks);
  8455. [this._extraDefaultOptions].flatten().compact().each(function(defs) {
  8456. Object.extend(this.options, defs);
  8457. }.bind(this));
  8458. },
  8459. prepareSubmission: function() {
  8460. this._saving = true;
  8461. this.removeForm();
  8462. this.leaveHover();
  8463. this.showSaving();
  8464. },
  8465. registerListeners: function() {
  8466. this._listeners = { };
  8467. var listener;
  8468. $H(Ajax.InPlaceEditor.Listeners).each(function(pair) {
  8469. listener = this[pair.value].bind(this);
  8470. this._listeners[pair.key] = listener;
  8471. if (!this.options.externalControlOnly)
  8472. this.element.observe(pair.key, listener);
  8473. if (this.options.externalControl)
  8474. this.options.externalControl.observe(pair.key, listener);
  8475. }.bind(this));
  8476. },
  8477. removeForm: function() {
  8478. if (!this._form) return;
  8479. this._form.remove();
  8480. this._form = null;
  8481. this._controls = { };
  8482. },
  8483. showSaving: function() {
  8484. this._oldInnerHTML = this.element.innerHTML;
  8485. this.element.innerHTML = this.options.savingText;
  8486. this.element.addClassName(this.options.savingClassName);
  8487. this.element.style.backgroundColor = this._originalBackground;
  8488. this.element.show();
  8489. },
  8490. triggerCallback: function(cbName, arg) {
  8491. if ('function' == typeof this.options[cbName]) {
  8492. this.options[cbName](this, arg);
  8493. }
  8494. },
  8495. unregisterListeners: function() {
  8496. $H(this._listeners).each(function(pair) {
  8497. if (!this.options.externalControlOnly)
  8498. this.element.stopObserving(pair.key, pair.value);
  8499. if (this.options.externalControl)
  8500. this.options.externalControl.stopObserving(pair.key, pair.value);
  8501. }.bind(this));
  8502. },
  8503. wrapUp: function(transport) {
  8504. this.leaveEditMode();
  8505. // Can't use triggerCallback due to backward compatibility: requires
  8506. // binding + direct element
  8507. this._boundComplete(transport, this.element);
  8508. }
  8509. });
  8510. Object.extend(Ajax.InPlaceEditor.prototype, {
  8511. dispose: Ajax.InPlaceEditor.prototype.destroy
  8512. });
  8513. Ajax.InPlaceCollectionEditor = Class.create(Ajax.InPlaceEditor, {
  8514. initialize: function($super, element, url, options) {
  8515. this._extraDefaultOptions = Ajax.InPlaceCollectionEditor.DefaultOptions;
  8516. $super(element, url, options);
  8517. },
  8518. createEditField: function() {
  8519. var list = document.createElement('select');
  8520. list.name = this.options.paramName;
  8521. list.size = 1;
  8522. this._controls.editor = list;
  8523. this._collection = this.options.collection || [];
  8524. if (this.options.loadCollectionURL)
  8525. this.loadCollection();
  8526. else
  8527. this.checkForExternalText();
  8528. this._form.appendChild(this._controls.editor);
  8529. },
  8530. loadCollection: function() {
  8531. this._form.addClassName(this.options.loadingClassName);
  8532. this.showLoadingText(this.options.loadingCollectionText);
  8533. var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
  8534. Object.extend(options, {
  8535. parameters: 'editorId=' + encodeURIComponent(this.element.id),
  8536. onComplete: Prototype.emptyFunction,
  8537. onSuccess: function(transport) {
  8538. var js = transport.responseText.strip();
  8539. if (!/^\[.*\]$/.test(js)) // TODO: improve sanity check
  8540. throw('Server returned an invalid collection representation.');
  8541. this._collection = eval(js);
  8542. this.checkForExternalText();
  8543. }.bind(this),
  8544. onFailure: this.onFailure
  8545. });
  8546. new Ajax.Request(this.options.loadCollectionURL, options);
  8547. },
  8548. showLoadingText: function(text) {
  8549. this._controls.editor.disabled = true;
  8550. var tempOption = this._controls.editor.firstChild;
  8551. if (!tempOption) {
  8552. tempOption = document.createElement('option');
  8553. tempOption.value = '';
  8554. this._controls.editor.appendChild(tempOption);
  8555. tempOption.selected = true;
  8556. }
  8557. tempOption.update((text || '').stripScripts().stripTags());
  8558. },
  8559. checkForExternalText: function() {
  8560. this._text = this.getText();
  8561. if (this.options.loadTextURL)
  8562. this.loadExternalText();
  8563. else
  8564. this.buildOptionList();
  8565. },
  8566. loadExternalText: function() {
  8567. this.showLoadingText(this.options.loadingText);
  8568. var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
  8569. Object.extend(options, {
  8570. parameters: 'editorId=' + encodeURIComponent(this.element.id),
  8571. onComplete: Prototype.emptyFunction,
  8572. onSuccess: function(transport) {
  8573. this._text = transport.responseText.strip();
  8574. this.buildOptionList();
  8575. }.bind(this),
  8576. onFailure: this.onFailure
  8577. });
  8578. new Ajax.Request(this.options.loadTextURL, options);
  8579. },
  8580. buildOptionList: function() {
  8581. this._form.removeClassName(this.options.loadingClassName);
  8582. this._collection = this._collection.map(function(entry) {
  8583. return 2 === entry.length ? entry : [entry, entry].flatten();
  8584. });
  8585. var marker = ('value' in this.options) ? this.options.value : this._text;
  8586. var textFound = this._collection.any(function(entry) {
  8587. return entry[0] == marker;
  8588. }.bind(this));
  8589. this._controls.editor.update('');
  8590. var option;
  8591. this._collection.each(function(entry, index) {
  8592. option = document.createElement('option');
  8593. option.value = entry[0];
  8594. option.selected = textFound ? entry[0] == marker : 0 == index;
  8595. option.appendChild(document.createTextNode(entry[1]));
  8596. this._controls.editor.appendChild(option);
  8597. }.bind(this));
  8598. this._controls.editor.disabled = false;
  8599. Field.scrollFreeActivate(this._controls.editor);
  8600. }
  8601. });
  8602. //**** DEPRECATION LAYER FOR InPlace[Collection]Editor! ****
  8603. //**** This only exists for a while, in order to let ****
  8604. //**** users adapt to the new API. Read up on the new ****
  8605. //**** API and convert your code to it ASAP! ****
  8606. Ajax.InPlaceEditor.prototype.initialize.dealWithDeprecatedOptions = function(options) {
  8607. if (!options) return;
  8608. function fallback(name, expr) {
  8609. if (name in options || expr === undefined) return;
  8610. options[name] = expr;
  8611. };
  8612. fallback('cancelControl', (options.cancelLink ? 'link' : (options.cancelButton ? 'button' :
  8613. options.cancelLink == options.cancelButton == false ? false : undefined)));
  8614. fallback('okControl', (options.okLink ? 'link' : (options.okButton ? 'button' :
  8615. options.okLink == options.okButton == false ? false : undefined)));
  8616. fallback('highlightColor', options.highlightcolor);
  8617. fallback('highlightEndColor', options.highlightendcolor);
  8618. };
  8619. Object.extend(Ajax.InPlaceEditor, {
  8620. DefaultOptions: {
  8621. ajaxOptions: { },
  8622. autoRows: 3, // Use when multi-line w/ rows == 1
  8623. cancelControl: 'link', // 'link'|'button'|false
  8624. cancelText: 'cancel',
  8625. clickToEditText: 'Click to edit',
  8626. externalControl: null, // id|elt
  8627. externalControlOnly: false,
  8628. fieldPostCreation: 'activate', // 'activate'|'focus'|false
  8629. formClassName: 'inplaceeditor-form',
  8630. formId: null, // id|elt
  8631. highlightColor: '#ffff99',
  8632. highlightEndColor: '#ffffff',
  8633. hoverClassName: '',
  8634. htmlResponse: true,
  8635. loadingClassName: 'inplaceeditor-loading',
  8636. loadingText: 'Loading...',
  8637. okControl: 'button', // 'link'|'button'|false
  8638. okText: 'ok',
  8639. paramName: 'value',
  8640. rows: 1, // If 1 and multi-line, uses autoRows
  8641. savingClassName: 'inplaceeditor-saving',
  8642. savingText: 'Saving...',
  8643. size: 0,
  8644. stripLoadedTextTags: false,
  8645. submitOnBlur: false,
  8646. textAfterControls: '',
  8647. textBeforeControls: '',
  8648. textBetweenControls: ''
  8649. },
  8650. DefaultCallbacks: {
  8651. callback: function(form) {
  8652. return Form.serialize(form);
  8653. },
  8654. onComplete: function(transport, element) {
  8655. // For backward compatibility, this one is bound to the IPE, and passes
  8656. // the element directly. It was too often customized, so we don't break it.
  8657. new Effect.Highlight(element, {
  8658. startcolor: this.options.highlightColor, keepBackgroundImage: true });
  8659. },
  8660. onEnterEditMode: null,
  8661. onEnterHover: function(ipe) {
  8662. ipe.element.style.backgroundColor = ipe.options.highlightColor;
  8663. if (ipe._effect)
  8664. ipe._effect.cancel();
  8665. },
  8666. onFailure: function(transport, ipe) {
  8667. alert('Error communication with the server: ' + transport.responseText.stripTags());
  8668. },
  8669. onFormCustomization: null, // Takes the IPE and its generated form, after editor, before controls.
  8670. onLeaveEditMode: null,
  8671. onLeaveHover: function(ipe) {
  8672. ipe._effect = new Effect.Highlight(ipe.element, {
  8673. startcolor: ipe.options.highlightColor, endcolor: ipe.options.highlightEndColor,
  8674. restorecolor: ipe._originalBackground, keepBackgroundImage: true
  8675. });
  8676. }
  8677. },
  8678. Listeners: {
  8679. click: 'enterEditMode',
  8680. keydown: 'checkForEscapeOrReturn',
  8681. mouseover: 'enterHover',
  8682. mouseout: 'leaveHover'
  8683. }
  8684. });
  8685. Ajax.InPlaceCollectionEditor.DefaultOptions = {
  8686. loadingCollectionText: 'Loading options...'
  8687. };
  8688. // Delayed observer, like Form.Element.Observer,
  8689. // but waits for delay after last key input
  8690. // Ideal for live-search fields
  8691. Form.Element.DelayedObserver = Class.create({
  8692. initialize: function(element, delay, callback) {
  8693. this.delay = delay || 0.5;
  8694. this.element = $(element);
  8695. this.callback = callback;
  8696. this.timer = null;
  8697. this.lastValue = $F(this.element);
  8698. Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));
  8699. },
  8700. delayedListener: function(event) {
  8701. if(this.lastValue == $F(this.element)) return;
  8702. if(this.timer) clearTimeout(this.timer);
  8703. this.timer = setTimeout(this.onTimerEvent.bind(this), this.delay * 1000);
  8704. this.lastValue = $F(this.element);
  8705. },
  8706. onTimerEvent: function() {
  8707. this.timer = null;
  8708. this.callback(this.element, $F(this.element));
  8709. }
  8710. });
  8711. // script.aculo.us slider.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008
  8712. // Copyright (c) 2005-2008 Marty Haught, Thomas Fuchs
  8713. //
  8714. // script.aculo.us is freely distributable under the terms of an MIT-style license.
  8715. // For details, see the script.aculo.us web site: http://script.aculo.us/
  8716. if (!Control) var Control = { };
  8717. // options:
  8718. // axis: 'vertical', or 'horizontal' (default)
  8719. //
  8720. // callbacks:
  8721. // onChange(value)
  8722. // onSlide(value)
  8723. Control.Slider = Class.create({
  8724. initialize: function(handle, track, options) {
  8725. var slider = this;
  8726. if (Object.isArray(handle)) {
  8727. this.handles = handle.collect( function(e) { return $(e) });
  8728. } else {
  8729. this.handles = [$(handle)];
  8730. }
  8731. this.track = $(track);
  8732. this.options = options || { };
  8733. this.axis = this.options.axis || 'horizontal';
  8734. this.increment = this.options.increment || 1;
  8735. this.step = parseInt(this.options.step || '1');
  8736. this.range = this.options.range || $R(0,1);
  8737. this.value = 0; // assure backwards compat
  8738. this.values = this.handles.map( function() { return 0 });
  8739. this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false;
  8740. this.options.startSpan = $(this.options.startSpan || null);
  8741. this.options.endSpan = $(this.options.endSpan || null);
  8742. this.restricted = this.options.restricted || false;
  8743. this.maximum = this.options.maximum || this.range.end;
  8744. this.minimum = this.options.minimum || this.range.start;
  8745. // Will be used to align the handle onto the track, if necessary
  8746. this.alignX = parseInt(this.options.alignX || '0');
  8747. this.alignY = parseInt(this.options.alignY || '0');
  8748. this.trackLength = this.maximumOffset() - this.minimumOffset();
  8749. this.handleLength = this.isVertical() ?
  8750. (this.handles[0].offsetHeight != 0 ?
  8751. this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,"")) :
  8752. (this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth :
  8753. this.handles[0].style.width.replace(/px$/,""));
  8754. this.active = false;
  8755. this.dragging = false;
  8756. this.disabled = false;
  8757. if (this.options.disabled) this.setDisabled();
  8758. // Allowed values array
  8759. this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
  8760. if (this.allowedValues) {
  8761. this.minimum = this.allowedValues.min();
  8762. this.maximum = this.allowedValues.max();
  8763. }
  8764. this.eventMouseDown = this.startDrag.bindAsEventListener(this);
  8765. this.eventMouseUp = this.endDrag.bindAsEventListener(this);
  8766. this.eventMouseMove = this.update.bindAsEventListener(this);
  8767. // Initialize handles in reverse (make sure first handle is active)
  8768. this.handles.each( function(h,i) {
  8769. i = slider.handles.length-1-i;
  8770. slider.setValue(parseFloat(
  8771. (Object.isArray(slider.options.sliderValue) ?
  8772. slider.options.sliderValue[i] : slider.options.sliderValue) ||
  8773. slider.range.start), i);
  8774. h.makePositioned().observe("mousedown", slider.eventMouseDown);
  8775. });
  8776. this.track.observe("mousedown", this.eventMouseDown);
  8777. document.observe("mouseup", this.eventMouseUp);
  8778. $(this.track.parentNode.parentNode).observe("mousemove", this.eventMouseMove);
  8779. this.initialized = true;
  8780. },
  8781. dispose: function() {
  8782. var slider = this;
  8783. Event.stopObserving(this.track, "mousedown", this.eventMouseDown);
  8784. Event.stopObserving(document, "mouseup", this.eventMouseUp);
  8785. Event.stopObserving(this.track.parentNode.parentNode, "mousemove", this.eventMouseMove);
  8786. this.handles.each( function(h) {
  8787. Event.stopObserving(h, "mousedown", slider.eventMouseDown);
  8788. });
  8789. },
  8790. setDisabled: function(){
  8791. this.disabled = true;
  8792. this.track.parentNode.className = this.track.parentNode.className + ' disabled';
  8793. },
  8794. setEnabled: function(){
  8795. this.disabled = false;
  8796. },
  8797. getNearestValue: function(value){
  8798. if (this.allowedValues){
  8799. if (value >= this.allowedValues.max()) return(this.allowedValues.max());
  8800. if (value <= this.allowedValues.min()) return(this.allowedValues.min());
  8801. var offset = Math.abs(this.allowedValues[0] - value);
  8802. var newValue = this.allowedValues[0];
  8803. this.allowedValues.each( function(v) {
  8804. var currentOffset = Math.abs(v - value);
  8805. if (currentOffset <= offset){
  8806. newValue = v;
  8807. offset = currentOffset;
  8808. }
  8809. });
  8810. return newValue;
  8811. }
  8812. if (value > this.range.end) return this.range.end;
  8813. if (value < this.range.start) return this.range.start;
  8814. return value;
  8815. },
  8816. setValue: function(sliderValue, handleIdx){
  8817. if (!this.active) {
  8818. this.activeHandleIdx = handleIdx || 0;
  8819. this.activeHandle = this.handles[this.activeHandleIdx];
  8820. this.updateStyles();
  8821. }
  8822. handleIdx = handleIdx || this.activeHandleIdx || 0;
  8823. if (this.initialized && this.restricted) {
  8824. if ((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
  8825. sliderValue = this.values[handleIdx-1];
  8826. if ((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
  8827. sliderValue = this.values[handleIdx+1];
  8828. }
  8829. sliderValue = this.getNearestValue(sliderValue);
  8830. this.values[handleIdx] = sliderValue;
  8831. this.value = this.values[0]; // assure backwards compat
  8832. this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] =
  8833. this.translateToPx(sliderValue);
  8834. this.drawSpans();
  8835. if (!this.dragging || !this.event) this.updateFinished();
  8836. },
  8837. setValueBy: function(delta, handleIdx) {
  8838. this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta,
  8839. handleIdx || this.activeHandleIdx || 0);
  8840. },
  8841. translateToPx: function(value) {
  8842. return Math.round(
  8843. ((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) *
  8844. (value - this.range.start)) + "px";
  8845. },
  8846. translateToValue: function(offset) {
  8847. return ((offset/(this.trackLength-this.handleLength) *
  8848. (this.range.end-this.range.start)) + this.range.start);
  8849. },
  8850. getRange: function(range) {
  8851. var v = this.values.sortBy(Prototype.K);
  8852. range = range || 0;
  8853. return $R(v[range],v[range+1]);
  8854. },
  8855. minimumOffset: function(){
  8856. return(this.isVertical() ? this.alignY : this.alignX);
  8857. },
  8858. maximumOffset: function(){
  8859. return(this.isVertical() ?
  8860. (this.track.offsetHeight != 0 ? this.track.offsetHeight :
  8861. this.track.style.height.replace(/px$/,"")) - this.alignY :
  8862. (this.track.offsetWidth != 0 ? this.track.offsetWidth :
  8863. this.track.style.width.replace(/px$/,"")) - this.alignX);
  8864. },
  8865. isVertical: function(){
  8866. return (this.axis == 'vertical');
  8867. },
  8868. drawSpans: function() {
  8869. var slider = this;
  8870. if (this.spans)
  8871. $R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
  8872. if (this.options.startSpan)
  8873. this.setSpan(this.options.startSpan,
  8874. $R(0, this.values.length>1 ? this.getRange(0).min() : this.value ));
  8875. if (this.options.endSpan)
  8876. this.setSpan(this.options.endSpan,
  8877. $R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum));
  8878. },
  8879. setSpan: function(span, range) {
  8880. if (this.isVertical()) {
  8881. span.style.top = this.translateToPx(range.start);
  8882. span.style.height = this.translateToPx(range.end - range.start + this.range.start);
  8883. } else {
  8884. span.style.left = this.translateToPx(range.start);
  8885. span.style.width = this.translateToPx(range.end - range.start + this.range.start);
  8886. }
  8887. },
  8888. updateStyles: function() {
  8889. this.handles.each( function(h){ Element.removeClassName(h, 'selected') });
  8890. Element.addClassName(this.activeHandle, 'selected');
  8891. },
  8892. startDrag: function(event) {
  8893. if (Event.isLeftClick(event)) {
  8894. if (!this.disabled){
  8895. this.active = true;
  8896. var handle = Event.element(event);
  8897. var pointer = [Event.pointerX(event), Event.pointerY(event)];
  8898. var track = handle;
  8899. if (track==this.track) {
  8900. var offsets = Position.cumulativeOffset(this.track);
  8901. this.event = event;
  8902. this.setValue(this.translateToValue(
  8903. (this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0])-(this.handleLength/2)
  8904. ));
  8905. var offsets = Position.cumulativeOffset(this.activeHandle);
  8906. this.offsetX = (pointer[0] - offsets[0]);
  8907. this.offsetY = (pointer[1] - offsets[1]);
  8908. } else {
  8909. // find the handle (prevents issues with Safari)
  8910. while((this.handles.indexOf(handle) == -1) && handle.parentNode)
  8911. handle = handle.parentNode;
  8912. if (this.handles.indexOf(handle)!=-1) {
  8913. this.activeHandle = handle;
  8914. this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
  8915. this.updateStyles();
  8916. var offsets = Position.cumulativeOffset(this.activeHandle);
  8917. this.offsetX = (pointer[0] - offsets[0]);
  8918. this.offsetY = (pointer[1] - offsets[1]);
  8919. }
  8920. }
  8921. }
  8922. Event.stop(event);
  8923. }
  8924. },
  8925. update: function(event) {
  8926. if (this.active) {
  8927. if (!this.dragging) this.dragging = true;
  8928. this.draw(event);
  8929. if (Prototype.Browser.WebKit) window.scrollBy(0,0);
  8930. Event.stop(event);
  8931. }
  8932. },
  8933. draw: function(event) {
  8934. var pointer = [Event.pointerX(event), Event.pointerY(event)];
  8935. var offsets = Position.cumulativeOffset(this.track);
  8936. pointer[0] -= this.offsetX + offsets[0];
  8937. pointer[1] -= this.offsetY + offsets[1];
  8938. this.event = event;
  8939. this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] ));
  8940. if (this.initialized && this.options.onSlide)
  8941. this.options.onSlide(this.values.length>1 ? this.values : this.value, this);
  8942. },
  8943. endDrag: function(event) {
  8944. if (this.active && this.dragging) {
  8945. this.finishDrag(event, true);
  8946. Event.stop(event);
  8947. }
  8948. this.active = false;
  8949. this.dragging = false;
  8950. },
  8951. finishDrag: function(event, success) {
  8952. this.active = false;
  8953. this.dragging = false;
  8954. this.updateFinished();
  8955. },
  8956. updateFinished: function() {
  8957. if (this.initialized && this.options.onChange)
  8958. this.options.onChange(this.values.length>1 ? this.values : this.value, this);
  8959. this.event = null;
  8960. }
  8961. });
  8962. /**
  8963. * Magento
  8964. *
  8965. * NOTICE OF LICENSE
  8966. *
  8967. * This source file is subject to the Academic Free License (AFL 3.0)
  8968. * that is bundled with this package in the file LICENSE_AFL.txt.
  8969. * It is also available through the world-wide-web at this URL:
  8970. * http://opensource.org/licenses/afl-3.0.php
  8971. * If you did not receive a copy of the license and are unable to
  8972. * obtain it through the world-wide-web, please send an email
  8973. * to license@magento.com so we can send you a copy immediately.
  8974. *
  8975. * DISCLAIMER
  8976. *
  8977. * Do not edit or add to this file if you wish to upgrade Magento to newer
  8978. * versions in the future. If you wish to customize Magento for your
  8979. * needs please refer to http://www.magento.com for more information.
  8980. *
  8981. * @category Varien
  8982. * @package js
  8983. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  8984. * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
  8985. */
  8986. function popWin(url,win,para) {
  8987. var win = window.open(url,win,para);
  8988. win.focus();
  8989. }
  8990. function setLocation(url){
  8991. window.location.href = url;
  8992. }
  8993. function setPLocation(url, setFocus){
  8994. if( setFocus ) {
  8995. window.opener.focus();
  8996. }
  8997. window.opener.location.href = url;
  8998. }
  8999. function setLanguageCode(code, fromCode){
  9000. //TODO: javascript cookies have different domain and path than php cookies
  9001. var href = window.location.href;
  9002. var after = '', dash;
  9003. if (dash = href.match(/\#(.*)$/)) {
  9004. href = href.replace(/\#(.*)$/, '');
  9005. after = dash[0];
  9006. }
  9007. if (href.match(/[?]/)) {
  9008. var re = /([?&]store=)[a-z0-9_]*/;
  9009. if (href.match(re)) {
  9010. href = href.replace(re, '$1'+code);
  9011. } else {
  9012. href += '&store='+code;
  9013. }
  9014. var re = /([?&]from_store=)[a-z0-9_]*/;
  9015. if (href.match(re)) {
  9016. href = href.replace(re, '');
  9017. }
  9018. } else {
  9019. href += '?store='+code;
  9020. }
  9021. if (typeof(fromCode) != 'undefined') {
  9022. href += '&from_store='+fromCode;
  9023. }
  9024. href += after;
  9025. setLocation(href);
  9026. }
  9027. /**
  9028. * Add classes to specified elements.
  9029. * Supported classes are: 'odd', 'even', 'first', 'last'
  9030. *
  9031. * @param elements - array of elements to be decorated
  9032. * [@param decorateParams] - array of classes to be set. If omitted, all available will be used
  9033. */
  9034. function decorateGeneric(elements, decorateParams)
  9035. {
  9036. var allSupportedParams = ['odd', 'even', 'first', 'last'];
  9037. var _decorateParams = {};
  9038. var total = elements.length;
  9039. if (total) {
  9040. // determine params called
  9041. if (typeof(decorateParams) == 'undefined') {
  9042. decorateParams = allSupportedParams;
  9043. }
  9044. if (!decorateParams.length) {
  9045. return;
  9046. }
  9047. for (var k in allSupportedParams) {
  9048. _decorateParams[allSupportedParams[k]] = false;
  9049. }
  9050. for (var k in decorateParams) {
  9051. _decorateParams[decorateParams[k]] = true;
  9052. }
  9053. // decorate elements
  9054. // elements[0].addClassName('first'); // will cause bug in IE (#5587)
  9055. if (_decorateParams.first) {
  9056. Element.addClassName(elements[0], 'first');
  9057. }
  9058. if (_decorateParams.last) {
  9059. Element.addClassName(elements[total-1], 'last');
  9060. }
  9061. for (var i = 0; i < total; i++) {
  9062. if ((i + 1) % 2 == 0) {
  9063. if (_decorateParams.even) {
  9064. Element.addClassName(elements[i], 'even');
  9065. }
  9066. }
  9067. else {
  9068. if (_decorateParams.odd) {
  9069. Element.addClassName(elements[i], 'odd');
  9070. }
  9071. }
  9072. }
  9073. }
  9074. }
  9075. /**
  9076. * Decorate table rows and cells, tbody etc
  9077. * @see decorateGeneric()
  9078. */
  9079. function decorateTable(table, options) {
  9080. var table = $(table);
  9081. if (table) {
  9082. // set default options
  9083. var _options = {
  9084. 'tbody' : false,
  9085. 'tbody tr' : ['odd', 'even', 'first', 'last'],
  9086. 'thead tr' : ['first', 'last'],
  9087. 'tfoot tr' : ['first', 'last'],
  9088. 'tr td' : ['last']
  9089. };
  9090. // overload options
  9091. if (typeof(options) != 'undefined') {
  9092. for (var k in options) {
  9093. _options[k] = options[k];
  9094. }
  9095. }
  9096. // decorate
  9097. if (_options['tbody']) {
  9098. decorateGeneric(table.select('tbody'), _options['tbody']);
  9099. }
  9100. if (_options['tbody tr']) {
  9101. decorateGeneric(table.select('tbody tr'), _options['tbody tr']);
  9102. }
  9103. if (_options['thead tr']) {
  9104. decorateGeneric(table.select('thead tr'), _options['thead tr']);
  9105. }
  9106. if (_options['tfoot tr']) {
  9107. decorateGeneric(table.select('tfoot tr'), _options['tfoot tr']);
  9108. }
  9109. if (_options['tr td']) {
  9110. var allRows = table.select('tr');
  9111. if (allRows.length) {
  9112. for (var i = 0; i < allRows.length; i++) {
  9113. decorateGeneric(allRows[i].getElementsByTagName('TD'), _options['tr td']);
  9114. }
  9115. }
  9116. }
  9117. }
  9118. }
  9119. /**
  9120. * Set "odd", "even" and "last" CSS classes for list items
  9121. * @see decorateGeneric()
  9122. */
  9123. function decorateList(list, nonRecursive) {
  9124. if ($(list)) {
  9125. if (typeof(nonRecursive) == 'undefined') {
  9126. var items = $(list).select('li')
  9127. }
  9128. else {
  9129. var items = $(list).childElements();
  9130. }
  9131. decorateGeneric(items, ['odd', 'even', 'last']);
  9132. }
  9133. }
  9134. /**
  9135. * Set "odd", "even" and "last" CSS classes for list items
  9136. * @see decorateGeneric()
  9137. */
  9138. function decorateDataList(list) {
  9139. list = $(list);
  9140. if (list) {
  9141. decorateGeneric(list.select('dt'), ['odd', 'even', 'last']);
  9142. decorateGeneric(list.select('dd'), ['odd', 'even', 'last']);
  9143. }
  9144. }
  9145. /**
  9146. * Parse SID and produces the correct URL
  9147. */
  9148. function parseSidUrl(baseUrl, urlExt) {
  9149. var sidPos = baseUrl.indexOf('/?SID=');
  9150. var sid = '';
  9151. urlExt = (urlExt != undefined) ? urlExt : '';
  9152. if(sidPos > -1) {
  9153. sid = '?' + baseUrl.substring(sidPos + 2);
  9154. baseUrl = baseUrl.substring(0, sidPos + 1);
  9155. }
  9156. return baseUrl+urlExt+sid;
  9157. }
  9158. /**
  9159. * Formats currency using patern
  9160. * format - JSON (pattern, decimal, decimalsDelimeter, groupsDelimeter)
  9161. * showPlus - true (always show '+'or '-'),
  9162. * false (never show '-' even if number is negative)
  9163. * null (show '-' if number is negative)
  9164. */
  9165. function formatCurrency(price, format, showPlus){
  9166. var precision = isNaN(format.precision = Math.abs(format.precision)) ? 2 : format.precision;
  9167. var requiredPrecision = isNaN(format.requiredPrecision = Math.abs(format.requiredPrecision)) ? 2 : format.requiredPrecision;
  9168. //precision = (precision > requiredPrecision) ? precision : requiredPrecision;
  9169. //for now we don't need this difference so precision is requiredPrecision
  9170. precision = requiredPrecision;
  9171. var integerRequired = isNaN(format.integerRequired = Math.abs(format.integerRequired)) ? 1 : format.integerRequired;
  9172. var decimalSymbol = format.decimalSymbol == undefined ? "," : format.decimalSymbol;
  9173. var groupSymbol = format.groupSymbol == undefined ? "." : format.groupSymbol;
  9174. var groupLength = format.groupLength == undefined ? 3 : format.groupLength;
  9175. var s = '';
  9176. if (showPlus == undefined || showPlus == true) {
  9177. s = price < 0 ? "-" : ( showPlus ? "+" : "");
  9178. } else if (showPlus == false) {
  9179. s = '';
  9180. }
  9181. var i = parseInt(price = Math.abs(+price || 0).toFixed(precision)) + "";
  9182. var pad = (i.length < integerRequired) ? (integerRequired - i.length) : 0;
  9183. while (pad) { i = '0' + i; pad--; }
  9184. j = (j = i.length) > groupLength ? j % groupLength : 0;
  9185. re = new RegExp("(\\d{" + groupLength + "})(?=\\d)", "g");
  9186. /**
  9187. * replace(/-/, 0) is only for fixing Safari bug which appears
  9188. * when Math.abs(0).toFixed() executed on "0" number.
  9189. * Result is "0.-0" :(
  9190. */
  9191. var r = (j ? i.substr(0, j) + groupSymbol : "") + i.substr(j).replace(re, "$1" + groupSymbol) + (precision ? decimalSymbol + Math.abs(price - i).toFixed(precision).replace(/-/, 0).slice(2) : "")
  9192. var pattern = '';
  9193. if (format.pattern.indexOf('{sign}') == -1) {
  9194. pattern = s + format.pattern;
  9195. } else {
  9196. pattern = format.pattern.replace('{sign}', s);
  9197. }
  9198. return pattern.replace('%s', r).replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  9199. };
  9200. function expandDetails(el, childClass) {
  9201. if (Element.hasClassName(el,'show-details')) {
  9202. $$(childClass).each(function(item){item.hide()});
  9203. Element.removeClassName(el,'show-details');
  9204. }
  9205. else {
  9206. $$(childClass).each(function(item){item.show()});
  9207. Element.addClassName(el,'show-details');
  9208. }
  9209. }
  9210. // Version 1.0
  9211. var isIE = navigator.appVersion.match(/MSIE/) == "MSIE";
  9212. if (!window.Varien)
  9213. var Varien = new Object();
  9214. Varien.showLoading = function(){
  9215. var loader = $('loading-process');
  9216. loader && loader.show();
  9217. }
  9218. Varien.hideLoading = function(){
  9219. var loader = $('loading-process');
  9220. loader && loader.hide();
  9221. }
  9222. Varien.GlobalHandlers = {
  9223. onCreate: function() {
  9224. Varien.showLoading();
  9225. },
  9226. onComplete: function() {
  9227. if(Ajax.activeRequestCount == 0) {
  9228. Varien.hideLoading();
  9229. }
  9230. }
  9231. };
  9232. Ajax.Responders.register(Varien.GlobalHandlers);
  9233. /**
  9234. * Quick Search form client model
  9235. */
  9236. Varien.searchForm = Class.create();
  9237. Varien.searchForm.prototype = {
  9238. initialize : function(form, field, emptyText){
  9239. this.form = $(form);
  9240. this.field = $(field);
  9241. this.emptyText = emptyText;
  9242. Event.observe(this.form, 'submit', this.submit.bind(this));
  9243. Event.observe(this.field, 'focus', this.focus.bind(this));
  9244. Event.observe(this.field, 'blur', this.blur.bind(this));
  9245. this.blur();
  9246. },
  9247. submit : function(event){
  9248. if (this.field.value == this.emptyText || this.field.value == ''){
  9249. Event.stop(event);
  9250. return false;
  9251. }
  9252. return true;
  9253. },
  9254. focus : function(event){
  9255. if(this.field.value==this.emptyText){
  9256. this.field.value='';
  9257. }
  9258. },
  9259. blur : function(event){
  9260. if(this.field.value==''){
  9261. this.field.value=this.emptyText;
  9262. }
  9263. },
  9264. initAutocomplete : function(url, destinationElement){
  9265. new Ajax.Autocompleter(
  9266. this.field,
  9267. destinationElement,
  9268. url,
  9269. {
  9270. paramName: this.field.name,
  9271. method: 'get',
  9272. minChars: 2,
  9273. updateElement: this._selectAutocompleteItem.bind(this),
  9274. onShow : function(element, update) {
  9275. if(!update.style.position || update.style.position=='absolute') {
  9276. update.style.position = 'absolute';
  9277. Position.clone(element, update, {
  9278. setHeight: false,
  9279. offsetTop: element.offsetHeight
  9280. });
  9281. }
  9282. Effect.Appear(update,{duration:0});
  9283. }
  9284. }
  9285. );
  9286. },
  9287. _selectAutocompleteItem : function(element){
  9288. if(element.title){
  9289. this.field.value = element.title;
  9290. }
  9291. this.form.submit();
  9292. }
  9293. }
  9294. Varien.Tabs = Class.create();
  9295. Varien.Tabs.prototype = {
  9296. initialize: function(selector) {
  9297. var self=this;
  9298. $$(selector+' a').each(this.initTab.bind(this));
  9299. },
  9300. initTab: function(el) {
  9301. el.href = 'javascript:void(0)';
  9302. if ($(el.parentNode).hasClassName('active')) {
  9303. this.showContent(el);
  9304. }
  9305. el.observe('click', this.showContent.bind(this, el));
  9306. },
  9307. showContent: function(a) {
  9308. var li = $(a.parentNode), ul = $(li.parentNode);
  9309. ul.getElementsBySelector('li', 'ol').each(function(el){
  9310. var contents = $(el.id+'_contents');
  9311. if (el==li) {
  9312. el.addClassName('active');
  9313. contents.show();
  9314. } else {
  9315. el.removeClassName('active');
  9316. contents.hide();
  9317. }
  9318. });
  9319. }
  9320. }
  9321. Varien.DateElement = Class.create();
  9322. Varien.DateElement.prototype = {
  9323. initialize: function(type, content, required, format) {
  9324. if (type == 'id') {
  9325. // id prefix
  9326. this.day = $(content + 'day');
  9327. this.month = $(content + 'month');
  9328. this.year = $(content + 'year');
  9329. this.full = $(content + 'full');
  9330. this.advice = $(content + 'date-advice');
  9331. } else if (type == 'container') {
  9332. // content must be container with data
  9333. this.day = content.day;
  9334. this.month = content.month;
  9335. this.year = content.year;
  9336. this.full = content.full;
  9337. this.advice = content.advice;
  9338. } else {
  9339. return;
  9340. }
  9341. this.required = required;
  9342. this.format = format;
  9343. this.day.addClassName('validate-custom');
  9344. this.day.validate = this.validate.bind(this);
  9345. this.month.addClassName('validate-custom');
  9346. this.month.validate = this.validate.bind(this);
  9347. this.year.addClassName('validate-custom');
  9348. this.year.validate = this.validate.bind(this);
  9349. this.setDateRange(false, false);
  9350. this.year.setAttribute('autocomplete','off');
  9351. this.advice.hide();
  9352. },
  9353. validate: function() {
  9354. var error = false,
  9355. day = parseInt(this.day.value, 10) || 0,
  9356. month = parseInt(this.month.value, 10) || 0,
  9357. year = parseInt(this.year.value, 10) || 0;
  9358. if (this.day.value.strip().empty()
  9359. && this.month.value.strip().empty()
  9360. && this.year.value.strip().empty()
  9361. ) {
  9362. if (this.required) {
  9363. error = 'This date is a required value.';
  9364. } else {
  9365. this.full.value = '';
  9366. }
  9367. } else if (!day || !month || !year) {
  9368. error = 'Please enter a valid full date.';
  9369. } else {
  9370. var date = new Date, countDaysInMonth = 0, errorType = null;
  9371. date.setYear(year);date.setMonth(month-1);date.setDate(32);
  9372. countDaysInMonth = 32 - date.getDate();
  9373. if(!countDaysInMonth || countDaysInMonth>31) countDaysInMonth = 31;
  9374. if (day<1 || day>countDaysInMonth) {
  9375. errorType = 'day';
  9376. error = 'Please enter a valid day (1-%d).';
  9377. } else if (month<1 || month>12) {
  9378. errorType = 'month';
  9379. error = 'Please enter a valid month (1-12).';
  9380. } else {
  9381. if(day % 10 == day) this.day.value = '0'+day;
  9382. if(month % 10 == month) this.month.value = '0'+month;
  9383. this.full.value = this.format.replace(/%[mb]/i, this.month.value).replace(/%[de]/i, this.day.value).replace(/%y/i, this.year.value);
  9384. var testFull = this.month.value + '/' + this.day.value + '/'+ this.year.value;
  9385. var test = new Date(testFull);
  9386. if (isNaN(test)) {
  9387. error = 'Please enter a valid date.';
  9388. } else {
  9389. this.setFullDate(test);
  9390. }
  9391. }
  9392. var valueError = false;
  9393. if (!error && !this.validateData()){//(year<1900 || year>curyear) {
  9394. errorType = this.validateDataErrorType;//'year';
  9395. valueError = this.validateDataErrorText;//'Please enter a valid year (1900-%d).';
  9396. error = valueError;
  9397. }
  9398. }
  9399. if (error !== false) {
  9400. try {
  9401. error = Translator.translate(error);
  9402. }
  9403. catch (e) {}
  9404. if (!valueError) {
  9405. this.advice.innerHTML = error.replace('%d', countDaysInMonth);
  9406. } else {
  9407. this.advice.innerHTML = this.errorTextModifier(error);
  9408. }
  9409. this.advice.show();
  9410. return false;
  9411. }
  9412. // fixing elements class
  9413. this.day.removeClassName('validation-failed');
  9414. this.month.removeClassName('validation-failed');
  9415. this.year.removeClassName('validation-failed');
  9416. this.advice.hide();
  9417. return true;
  9418. },
  9419. validateData: function() {
  9420. var year = this.fullDate.getFullYear();
  9421. var date = new Date;
  9422. this.curyear = date.getFullYear();
  9423. return (year>=1900 && year<=this.curyear);
  9424. },
  9425. validateDataErrorType: 'year',
  9426. validateDataErrorText: 'Please enter a valid year (1900-%d).',
  9427. errorTextModifier: function(text) {
  9428. return text.replace('%d', this.curyear);
  9429. },
  9430. setDateRange: function(minDate, maxDate) {
  9431. this.minDate = minDate;
  9432. this.maxDate = maxDate;
  9433. },
  9434. setFullDate: function(date) {
  9435. this.fullDate = date;
  9436. }
  9437. };
  9438. Varien.DOB = Class.create();
  9439. Varien.DOB.prototype = {
  9440. initialize: function(selector, required, format) {
  9441. var el = $$(selector)[0];
  9442. var container = {};
  9443. container.day = Element.select(el, '.dob-day input')[0];
  9444. container.month = Element.select(el, '.dob-month input')[0];
  9445. container.year = Element.select(el, '.dob-year input')[0];
  9446. container.full = Element.select(el, '.dob-full input')[0];
  9447. container.advice = Element.select(el, '.validation-advice')[0];
  9448. new Varien.DateElement('container', container, required, format);
  9449. }
  9450. };
  9451. Varien.dateRangeDate = Class.create();
  9452. Varien.dateRangeDate.prototype = Object.extend(new Varien.DateElement(), {
  9453. validateData: function() {
  9454. var validate = true;
  9455. if (this.minDate || this.maxValue) {
  9456. if (this.minDate) {
  9457. this.minDate = new Date(this.minDate);
  9458. this.minDate.setHours(0);
  9459. if (isNaN(this.minDate)) {
  9460. this.minDate = new Date('1/1/1900');
  9461. }
  9462. validate = validate && (this.fullDate >= this.minDate)
  9463. }
  9464. if (this.maxDate) {
  9465. this.maxDate = new Date(this.maxDate)
  9466. this.minDate.setHours(0);
  9467. if (isNaN(this.maxDate)) {
  9468. this.maxDate = new Date();
  9469. }
  9470. validate = validate && (this.fullDate <= this.maxDate)
  9471. }
  9472. if (this.maxDate && this.minDate) {
  9473. this.validateDataErrorText = 'Please enter a valid date between %s and %s';
  9474. } else if (this.maxDate) {
  9475. this.validateDataErrorText = 'Please enter a valid date less than or equal to %s';
  9476. } else if (this.minDate) {
  9477. this.validateDataErrorText = 'Please enter a valid date equal to or greater than %s';
  9478. } else {
  9479. this.validateDataErrorText = '';
  9480. }
  9481. }
  9482. return validate;
  9483. },
  9484. validateDataErrorText: 'Date should be between %s and %s',
  9485. errorTextModifier: function(text) {
  9486. if (this.minDate) {
  9487. text = text.sub('%s', this.dateFormat(this.minDate));
  9488. }
  9489. if (this.maxDate) {
  9490. text = text.sub('%s', this.dateFormat(this.maxDate));
  9491. }
  9492. return text;
  9493. },
  9494. dateFormat: function(date) {
  9495. return (date.getMonth() + 1) + '/' + date.getDate() + '/' + date.getFullYear();
  9496. }
  9497. });
  9498. Varien.FileElement = Class.create();
  9499. Varien.FileElement.prototype = {
  9500. initialize: function (id) {
  9501. this.fileElement = $(id);
  9502. this.hiddenElement = $(id + '_value');
  9503. this.fileElement.observe('change', this.selectFile.bind(this));
  9504. },
  9505. selectFile: function(event) {
  9506. this.hiddenElement.value = this.fileElement.getValue();
  9507. }
  9508. };
  9509. Validation.addAllThese([
  9510. ['validate-custom', ' ', function(v,elm) {
  9511. return elm.validate();
  9512. }]
  9513. ]);
  9514. function truncateOptions() {
  9515. $$('.truncated').each(function(element){
  9516. Event.observe(element, 'mouseover', function(){
  9517. if (element.down('div.truncated_full_value')) {
  9518. element.down('div.truncated_full_value').addClassName('show')
  9519. }
  9520. });
  9521. Event.observe(element, 'mouseout', function(){
  9522. if (element.down('div.truncated_full_value')) {
  9523. element.down('div.truncated_full_value').removeClassName('show')
  9524. }
  9525. });
  9526. });
  9527. }
  9528. Event.observe(window, 'load', function(){
  9529. truncateOptions();
  9530. });
  9531. Element.addMethods({
  9532. getInnerText: function(element)
  9533. {
  9534. element = $(element);
  9535. if(element.innerText && !Prototype.Browser.Opera) {
  9536. return element.innerText
  9537. }
  9538. return element.innerHTML.stripScripts().unescapeHTML().replace(/[\n\r\s]+/g, ' ').strip();
  9539. }
  9540. });
  9541. /*
  9542. if (!("console" in window) || !("firebug" in console))
  9543. {
  9544. var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
  9545. "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
  9546. window.console = {};
  9547. for (var i = 0; i < names.length; ++i)
  9548. window.console[names[i]] = function() {}
  9549. }
  9550. */
  9551. /**
  9552. * Executes event handler on the element. Works with event handlers attached by Prototype,
  9553. * in a browser-agnostic fashion.
  9554. * @param element The element object
  9555. * @param event Event name, like 'change'
  9556. *
  9557. * @example fireEvent($('my-input', 'click'));
  9558. */
  9559. function fireEvent(element, event) {
  9560. if (document.createEvent) {
  9561. // dispatch for all browsers except IE before version 9
  9562. var evt = document.createEvent("HTMLEvents");
  9563. evt.initEvent(event, true, true ); // event type, bubbling, cancelable
  9564. return element.dispatchEvent(evt);
  9565. } else {
  9566. // dispatch for IE before version 9
  9567. var evt = document.createEventObject();
  9568. return element.fireEvent('on' + event, evt)
  9569. }
  9570. }
  9571. /**
  9572. * Returns more accurate results of floating-point modulo division
  9573. * E.g.:
  9574. * 0.6 % 0.2 = 0.19999999999999996
  9575. * modulo(0.6, 0.2) = 0
  9576. *
  9577. * @param dividend
  9578. * @param divisor
  9579. */
  9580. function modulo(dividend, divisor)
  9581. {
  9582. var epsilon = divisor / 10000;
  9583. var remainder = dividend % divisor;
  9584. if (Math.abs(remainder - divisor) < epsilon || Math.abs(remainder) < epsilon) {
  9585. remainder = 0;
  9586. }
  9587. return remainder;
  9588. }
  9589. /**
  9590. * createContextualFragment is not supported in IE9. Adding its support.
  9591. */
  9592. if ((typeof Range != "undefined") && !Range.prototype.createContextualFragment)
  9593. {
  9594. Range.prototype.createContextualFragment = function(html)
  9595. {
  9596. var frag = document.createDocumentFragment(),
  9597. div = document.createElement("div");
  9598. frag.appendChild(div);
  9599. div.outerHTML = html;
  9600. return frag;
  9601. };
  9602. }
  9603. /**
  9604. * Magento
  9605. *
  9606. * NOTICE OF LICENSE
  9607. *
  9608. * This source file is subject to the Academic Free License (AFL 3.0)
  9609. * that is bundled with this package in the file LICENSE_AFL.txt.
  9610. * It is also available through the world-wide-web at this URL:
  9611. * http://opensource.org/licenses/afl-3.0.php
  9612. * If you did not receive a copy of the license and are unable to
  9613. * obtain it through the world-wide-web, please send an email
  9614. * to license@magento.com so we can send you a copy immediately.
  9615. *
  9616. * DISCLAIMER
  9617. *
  9618. * Do not edit or add to this file if you wish to upgrade Magento to newer
  9619. * versions in the future. If you wish to customize Magento for your
  9620. * needs please refer to http://www.magento.com for more information.
  9621. *
  9622. * @category Varien
  9623. * @package js
  9624. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  9625. * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
  9626. */
  9627. VarienForm = Class.create();
  9628. VarienForm.prototype = {
  9629. initialize: function(formId, firstFieldFocus){
  9630. this.form = $(formId);
  9631. if (!this.form) {
  9632. return;
  9633. }
  9634. this.cache = $A();
  9635. this.currLoader = false;
  9636. this.currDataIndex = false;
  9637. this.validator = new Validation(this.form);
  9638. this.elementFocus = this.elementOnFocus.bindAsEventListener(this);
  9639. this.elementBlur = this.elementOnBlur.bindAsEventListener(this);
  9640. this.childLoader = this.onChangeChildLoad.bindAsEventListener(this);
  9641. this.highlightClass = 'highlight';
  9642. this.extraChildParams = '';
  9643. this.firstFieldFocus= firstFieldFocus || false;
  9644. this.bindElements();
  9645. if(this.firstFieldFocus){
  9646. try{
  9647. Form.Element.focus(Form.findFirstElement(this.form))
  9648. }
  9649. catch(e){}
  9650. }
  9651. },
  9652. submit : function(url){
  9653. if(this.validator && this.validator.validate()){
  9654. this.form.submit();
  9655. }
  9656. return false;
  9657. },
  9658. bindElements:function (){
  9659. var elements = Form.getElements(this.form);
  9660. for (var row in elements) {
  9661. if (elements[row].id) {
  9662. Event.observe(elements[row],'focus',this.elementFocus);
  9663. Event.observe(elements[row],'blur',this.elementBlur);
  9664. }
  9665. }
  9666. },
  9667. elementOnFocus: function(event){
  9668. var element = Event.findElement(event, 'fieldset');
  9669. if(element){
  9670. Element.addClassName(element, this.highlightClass);
  9671. }
  9672. },
  9673. elementOnBlur: function(event){
  9674. var element = Event.findElement(event, 'fieldset');
  9675. if(element){
  9676. Element.removeClassName(element, this.highlightClass);
  9677. }
  9678. },
  9679. setElementsRelation: function(parent, child, dataUrl, first){
  9680. if (parent=$(parent)) {
  9681. // TODO: array of relation and caching
  9682. if (!this.cache[parent.id]){
  9683. this.cache[parent.id] = $A();
  9684. this.cache[parent.id]['child'] = child;
  9685. this.cache[parent.id]['dataUrl'] = dataUrl;
  9686. this.cache[parent.id]['data'] = $A();
  9687. this.cache[parent.id]['first'] = first || false;
  9688. }
  9689. Event.observe(parent,'change',this.childLoader);
  9690. }
  9691. },
  9692. onChangeChildLoad: function(event){
  9693. element = Event.element(event);
  9694. this.elementChildLoad(element);
  9695. },
  9696. elementChildLoad: function(element, callback){
  9697. this.callback = callback || false;
  9698. if (element.value) {
  9699. this.currLoader = element.id;
  9700. this.currDataIndex = element.value;
  9701. if (this.cache[element.id]['data'][element.value]) {
  9702. this.setDataToChild(this.cache[element.id]['data'][element.value]);
  9703. }
  9704. else{
  9705. new Ajax.Request(this.cache[this.currLoader]['dataUrl'],{
  9706. method: 'post',
  9707. parameters: {"parent":element.value},
  9708. onComplete: this.reloadChildren.bind(this)
  9709. });
  9710. }
  9711. }
  9712. },
  9713. reloadChildren: function(transport){
  9714. var data = eval('(' + transport.responseText + ')');
  9715. this.cache[this.currLoader]['data'][this.currDataIndex] = data;
  9716. this.setDataToChild(data);
  9717. },
  9718. setDataToChild: function(data){
  9719. if (data.length) {
  9720. var child = $(this.cache[this.currLoader]['child']);
  9721. if (child){
  9722. var html = '<select name="'+child.name+'" id="'+child.id+'" class="'+child.className+'" title="'+child.title+'" '+this.extraChildParams+'>';
  9723. if(this.cache[this.currLoader]['first']){
  9724. html+= '<option value="">'+this.cache[this.currLoader]['first']+'</option>';
  9725. }
  9726. for (var i in data){
  9727. if(data[i].value) {
  9728. html+= '<option value="'+data[i].value+'"';
  9729. if(child.value && (child.value == data[i].value || child.value == data[i].label)){
  9730. html+= ' selected';
  9731. }
  9732. html+='>'+data[i].label+'</option>';
  9733. }
  9734. }
  9735. html+= '</select>';
  9736. Element.insert(child, {before: html});
  9737. Element.remove(child);
  9738. }
  9739. }
  9740. else{
  9741. var child = $(this.cache[this.currLoader]['child']);
  9742. if (child){
  9743. var html = '<input type="text" name="'+child.name+'" id="'+child.id+'" class="'+child.className+'" title="'+child.title+'" '+this.extraChildParams+'>';
  9744. Element.insert(child, {before: html});
  9745. Element.remove(child);
  9746. }
  9747. }
  9748. this.bindElements();
  9749. if (this.callback) {
  9750. this.callback();
  9751. }
  9752. }
  9753. }
  9754. RegionUpdater = Class.create();
  9755. RegionUpdater.prototype = {
  9756. initialize: function (countryEl, regionTextEl, regionSelectEl, regions, disableAction, zipEl)
  9757. {
  9758. this.countryEl = $(countryEl);
  9759. this.regionTextEl = $(regionTextEl);
  9760. this.regionSelectEl = $(regionSelectEl);
  9761. this.zipEl = $(zipEl);
  9762. this.config = regions['config'];
  9763. delete regions.config;
  9764. this.regions = regions;
  9765. this.disableAction = (typeof disableAction=='undefined') ? 'hide' : disableAction;
  9766. this.zipOptions = (typeof zipOptions=='undefined') ? false : zipOptions;
  9767. if (this.regionSelectEl.options.length<=1) {
  9768. this.update();
  9769. }
  9770. Event.observe(this.countryEl, 'change', this.update.bind(this));
  9771. },
  9772. _checkRegionRequired: function()
  9773. {
  9774. var label, wildCard;
  9775. var elements = [this.regionTextEl, this.regionSelectEl];
  9776. var that = this;
  9777. if (typeof this.config == 'undefined') {
  9778. return;
  9779. }
  9780. var regionRequired = this.config.regions_required.indexOf(this.countryEl.value) >= 0;
  9781. elements.each(function(currentElement) {
  9782. Validation.reset(currentElement);
  9783. label = $$('label[for="' + currentElement.id + '"]')[0];
  9784. if (label) {
  9785. wildCard = label.down('em') || label.down('span.required');
  9786. if (!that.config.show_all_regions) {
  9787. if (regionRequired) {
  9788. label.up().show();
  9789. } else {
  9790. label.up().hide();
  9791. }
  9792. }
  9793. }
  9794. if (label && wildCard) {
  9795. if (!regionRequired) {
  9796. wildCard.hide();
  9797. if (label.hasClassName('required')) {
  9798. label.removeClassName('required');
  9799. }
  9800. } else if (regionRequired) {
  9801. wildCard.show();
  9802. if (!label.hasClassName('required')) {
  9803. label.addClassName('required')
  9804. }
  9805. }
  9806. }
  9807. if (!regionRequired) {
  9808. if (currentElement.hasClassName('required-entry')) {
  9809. currentElement.removeClassName('required-entry');
  9810. }
  9811. if ('select' == currentElement.tagName.toLowerCase() &&
  9812. currentElement.hasClassName('validate-select')) {
  9813. currentElement.removeClassName('validate-select');
  9814. }
  9815. } else {
  9816. if (!currentElement.hasClassName('required-entry')) {
  9817. currentElement.addClassName('required-entry');
  9818. }
  9819. if ('select' == currentElement.tagName.toLowerCase() &&
  9820. !currentElement.hasClassName('validate-select')) {
  9821. currentElement.addClassName('validate-select');
  9822. }
  9823. }
  9824. });
  9825. },
  9826. update: function()
  9827. {
  9828. if (this.regions[this.countryEl.value]) {
  9829. var i, option, region, def;
  9830. def = this.regionSelectEl.getAttribute('defaultValue');
  9831. if (this.regionTextEl) {
  9832. if (!def) {
  9833. def = this.regionTextEl.value.toLowerCase();
  9834. }
  9835. this.regionTextEl.value = '';
  9836. }
  9837. this.regionSelectEl.options.length = 1;
  9838. for (regionId in this.regions[this.countryEl.value]) {
  9839. region = this.regions[this.countryEl.value][regionId];
  9840. option = document.createElement('OPTION');
  9841. option.value = regionId;
  9842. option.text = region.name.stripTags();
  9843. option.title = region.name;
  9844. if (this.regionSelectEl.options.add) {
  9845. this.regionSelectEl.options.add(option);
  9846. } else {
  9847. this.regionSelectEl.appendChild(option);
  9848. }
  9849. if (regionId == def || (region.name && region.name.toLowerCase() == def)
  9850. || (region.name && region.code.toLowerCase() == def)
  9851. ) {
  9852. this.regionSelectEl.value = regionId;
  9853. }
  9854. }
  9855. this.sortSelect();
  9856. if (this.disableAction == 'hide') {
  9857. if (this.regionTextEl) {
  9858. this.regionTextEl.style.display = 'none';
  9859. }
  9860. this.regionSelectEl.style.display = '';
  9861. } else if (this.disableAction == 'disable') {
  9862. if (this.regionTextEl) {
  9863. this.regionTextEl.disabled = true;
  9864. }
  9865. this.regionSelectEl.disabled = false;
  9866. }
  9867. this.setMarkDisplay(this.regionSelectEl, true);
  9868. } else {
  9869. this.regionSelectEl.options.length = 1;
  9870. this.sortSelect();
  9871. if (this.disableAction == 'hide') {
  9872. if (this.regionTextEl) {
  9873. this.regionTextEl.style.display = '';
  9874. }
  9875. this.regionSelectEl.style.display = 'none';
  9876. Validation.reset(this.regionSelectEl);
  9877. } else if (this.disableAction == 'disable') {
  9878. if (this.regionTextEl) {
  9879. this.regionTextEl.disabled = false;
  9880. }
  9881. this.regionSelectEl.disabled = true;
  9882. } else if (this.disableAction == 'nullify') {
  9883. this.regionSelectEl.options.length = 1;
  9884. this.regionSelectEl.value = '';
  9885. this.regionSelectEl.selectedIndex = 0;
  9886. this.lastCountryId = '';
  9887. }
  9888. this.setMarkDisplay(this.regionSelectEl, false);
  9889. }
  9890. this._checkRegionRequired();
  9891. // Make Zip and its label required/optional
  9892. var zipUpdater = new ZipUpdater(this.countryEl.value, this.zipEl);
  9893. zipUpdater.update();
  9894. },
  9895. setMarkDisplay: function(elem, display){
  9896. elem = $(elem);
  9897. var labelElement = elem.up(0).down('label > span.required') ||
  9898. elem.up(1).down('label > span.required') ||
  9899. elem.up(0).down('label.required > em') ||
  9900. elem.up(1).down('label.required > em');
  9901. if(labelElement) {
  9902. inputElement = labelElement.up().next('input');
  9903. if (display) {
  9904. labelElement.show();
  9905. if (inputElement) {
  9906. inputElement.addClassName('required-entry');
  9907. }
  9908. } else {
  9909. labelElement.hide();
  9910. if (inputElement) {
  9911. inputElement.removeClassName('required-entry');
  9912. }
  9913. }
  9914. }
  9915. },
  9916. sortSelect : function () {
  9917. var elem = this.regionSelectEl;
  9918. var tmpArray = new Array();
  9919. var currentVal = $(elem).value;
  9920. for (var i = 0; i < $(elem).options.length; i++) {
  9921. if (i == 0) {
  9922. continue;
  9923. }
  9924. tmpArray[i-1] = new Array();
  9925. tmpArray[i-1][0] = $(elem).options[i].text;
  9926. tmpArray[i-1][1] = $(elem).options[i].value;
  9927. }
  9928. tmpArray.sort();
  9929. for (var i = 1; i <= tmpArray.length; i++) {
  9930. var op = new Option(tmpArray[i-1][0], tmpArray[i-1][1]);
  9931. $(elem).options[i] = op;
  9932. }
  9933. $(elem).value = currentVal;
  9934. return;
  9935. }
  9936. }
  9937. ZipUpdater = Class.create();
  9938. ZipUpdater.prototype = {
  9939. initialize: function(country, zipElement)
  9940. {
  9941. this.country = country;
  9942. this.zipElement = $(zipElement);
  9943. },
  9944. update: function()
  9945. {
  9946. // Country ISO 2-letter codes must be pre-defined
  9947. if (typeof optionalZipCountries == 'undefined') {
  9948. return false;
  9949. }
  9950. // Ajax-request and normal content load compatibility
  9951. if (this.zipElement != undefined) {
  9952. Validation.reset(this.zipElement)
  9953. this._setPostcodeOptional();
  9954. } else {
  9955. Event.observe(window, "load", this._setPostcodeOptional.bind(this));
  9956. }
  9957. },
  9958. _setPostcodeOptional: function()
  9959. {
  9960. this.zipElement = $(this.zipElement);
  9961. if (this.zipElement == undefined) {
  9962. return false;
  9963. }
  9964. // find label
  9965. var label = $$('label[for="' + this.zipElement.id + '"]')[0];
  9966. if (label != undefined) {
  9967. var wildCard = label.down('em') || label.down('span.required');
  9968. }
  9969. // Make Zip and its label required/optional
  9970. if (optionalZipCountries.indexOf(this.country) != -1) {
  9971. while (this.zipElement.hasClassName('required-entry')) {
  9972. this.zipElement.removeClassName('required-entry');
  9973. }
  9974. if (wildCard != undefined) {
  9975. wildCard.hide();
  9976. }
  9977. } else {
  9978. this.zipElement.addClassName('required-entry');
  9979. if (wildCard != undefined) {
  9980. wildCard.show();
  9981. }
  9982. }
  9983. }
  9984. }
  9985. /**
  9986. * Magento
  9987. *
  9988. * NOTICE OF LICENSE
  9989. *
  9990. * This source file is subject to the Academic Free License (AFL 3.0)
  9991. * that is bundled with this package in the file LICENSE_AFL.txt.
  9992. * It is also available through the world-wide-web at this URL:
  9993. * http://opensource.org/licenses/afl-3.0.php
  9994. * If you did not receive a copy of the license and are unable to
  9995. * obtain it through the world-wide-web, please send an email
  9996. * to license@magento.com so we can send you a copy immediately.
  9997. *
  9998. * DISCLAIMER
  9999. *
  10000. * Do not edit or add to this file if you wish to upgrade Magento to newer
  10001. * versions in the future. If you wish to customize Magento for your
  10002. * needs please refer to http://www.magento.com for more information.
  10003. *
  10004. * @category Mage
  10005. * @package js
  10006. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  10007. * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
  10008. */
  10009. var Translate = Class.create();
  10010. Translate.prototype = {
  10011. initialize: function(data){
  10012. this.data = $H(data);
  10013. },
  10014. translate : function(){
  10015. var args = arguments;
  10016. var text = arguments[0];
  10017. if(this.data.get(text)){
  10018. return this.data.get(text);
  10019. }
  10020. return text;
  10021. },
  10022. add : function() {
  10023. if (arguments.length > 1) {
  10024. this.data.set(arguments[0], arguments[1]);
  10025. } else if (typeof arguments[0] =='object') {
  10026. $H(arguments[0]).each(function (pair){
  10027. this.data.set(pair.key, pair.value);
  10028. }.bind(this));
  10029. }
  10030. }
  10031. }
  10032. /**
  10033. * Magento
  10034. *
  10035. * NOTICE OF LICENSE
  10036. *
  10037. * This source file is subject to the Academic Free License (AFL 3.0)
  10038. * that is bundled with this package in the file LICENSE_AFL.txt.
  10039. * It is also available through the world-wide-web at this URL:
  10040. * http://opensource.org/licenses/afl-3.0.php
  10041. * If you did not receive a copy of the license and are unable to
  10042. * obtain it through the world-wide-web, please send an email
  10043. * to license@magento.com so we can send you a copy immediately.
  10044. *
  10045. * DISCLAIMER
  10046. *
  10047. * Do not edit or add to this file if you wish to upgrade Magento to newer
  10048. * versions in the future. If you wish to customize Magento for your
  10049. * needs please refer to http://www.magento.com for more information.
  10050. *
  10051. * @category Mage
  10052. * @package js
  10053. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  10054. * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
  10055. */
  10056. // old school cookie functions grabbed off the web
  10057. if (!window.Mage) var Mage = {};
  10058. Mage.Cookies = {};
  10059. Mage.Cookies.expires = null;
  10060. Mage.Cookies.path = '/';
  10061. Mage.Cookies.domain = null;
  10062. Mage.Cookies.secure = false;
  10063. Mage.Cookies.set = function(name, value){
  10064. var argv = arguments;
  10065. var argc = arguments.length;
  10066. var expires = (argc > 2) ? argv[2] : Mage.Cookies.expires;
  10067. var path = (argc > 3) ? argv[3] : Mage.Cookies.path;
  10068. var domain = (argc > 4) ? argv[4] : Mage.Cookies.domain;
  10069. var secure = (argc > 5) ? argv[5] : Mage.Cookies.secure;
  10070. document.cookie = name + "=" + escape (value) +
  10071. ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  10072. ((path == null) ? "" : ("; path=" + path)) +
  10073. ((domain == null) ? "" : ("; domain=" + domain)) +
  10074. ((secure == true) ? "; secure" : "");
  10075. };
  10076. Mage.Cookies.get = function(name){
  10077. var arg = name + "=";
  10078. var alen = arg.length;
  10079. var clen = document.cookie.length;
  10080. var i = 0;
  10081. var j = 0;
  10082. while(i < clen){
  10083. j = i + alen;
  10084. if (document.cookie.substring(i, j) == arg)
  10085. return Mage.Cookies.getCookieVal(j);
  10086. i = document.cookie.indexOf(" ", i) + 1;
  10087. if(i == 0)
  10088. break;
  10089. }
  10090. return null;
  10091. };
  10092. Mage.Cookies.clear = function(name) {
  10093. if(Mage.Cookies.get(name)){
  10094. document.cookie = name + "=" +
  10095. "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  10096. }
  10097. };
  10098. Mage.Cookies.getCookieVal = function(offset){
  10099. var endstr = document.cookie.indexOf(";", offset);
  10100. if(endstr == -1){
  10101. endstr = document.cookie.length;
  10102. }
  10103. return unescape(document.cookie.substring(offset, endstr));
  10104. };
  10105. // script.aculo.us scriptaculous.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008
  10106. // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
  10107. //
  10108. // Permission is hereby granted, free of charge, to any person obtaining
  10109. // a copy of this software and associated documentation files (the
  10110. // "Software"), to deal in the Software without restriction, including
  10111. // without limitation the rights to use, copy, modify, merge, publish,
  10112. // distribute, sublicense, and/or sell copies of the Software, and to
  10113. // permit persons to whom the Software is furnished to do so, subject to
  10114. // the following conditions:
  10115. //
  10116. // The above copyright notice and this permission notice shall be
  10117. // included in all copies or substantial portions of the Software.
  10118. //
  10119. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  10120. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10121. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  10122. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  10123. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  10124. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  10125. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  10126. //
  10127. // For details, see the script.aculo.us web site: http://script.aculo.us/
  10128. var Scriptaculous = {
  10129. Version: '1.8.2',
  10130. require: function(libraryName) {
  10131. // inserting via DOM fails in Safari 2.0, so brute force approach
  10132. document.write('<script type="text/javascript" src="'+libraryName+'"><\/script>');
  10133. },
  10134. REQUIRED_PROTOTYPE: '1.6.0.3',
  10135. load: function() {
  10136. function convertVersionString(versionString) {
  10137. var v = versionString.replace(/_.*|\./g, '');
  10138. v = parseInt(v + '0'.times(4-v.length));
  10139. return versionString.indexOf('_') > -1 ? v-1 : v;
  10140. }
  10141. if((typeof Prototype=='undefined') ||
  10142. (typeof Element == 'undefined') ||
  10143. (typeof Element.Methods=='undefined') ||
  10144. (convertVersionString(Prototype.Version) <
  10145. convertVersionString(Scriptaculous.REQUIRED_PROTOTYPE)))
  10146. throw("script.aculo.us requires the Prototype JavaScript framework >= " +
  10147. Scriptaculous.REQUIRED_PROTOTYPE);
  10148. var js = /scriptaculous\.js(\?.*)?$/;
  10149. $$('head script[src]').findAll(function(s) {
  10150. return s.src.match(js);
  10151. }).each(function(s) {
  10152. var path = s.src.replace(js, ''),
  10153. includes = s.src.match(/\?.*load=([a-z,]*)/);
  10154. (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider,sound').split(',').each(
  10155. function(include) { Scriptaculous.require(path+include+'.js') });
  10156. });
  10157. }
  10158. };
  10159. Scriptaculous.load();
  10160. if (typeof HIB !== 'object') {
  10161. var HIB = {}
  10162. }
  10163. HIB.sharing = {};
  10164. HIB.sharing.globalSelectors = {
  10165. options: {},
  10166. countryRestriction: undefined,
  10167. init: function (defaultContinentZone, defaultCountry, optionsJson) {
  10168. this.options = optionsJson;
  10169. this.cleanupContinents();
  10170. if(defaultContinentZone > 0) { // Block the continent selector
  10171. var select = $('distributors-continent-select');
  10172. select.selectedIndex = defaultContinentZone;
  10173. $$('select#distributors-continent-select option').each(function(o) {
  10174. if(o.readAttribute('value') == defaultContinentZone) {
  10175. o.selected = true;
  10176. }
  10177. });
  10178. select.disable();
  10179. } else {
  10180. $$('#distributors-continent-select').each(function (element) {
  10181. element.observe('change', function (event) {
  10182. HIB.sharing.globalSelectors.refreshDistributorSelect(this.value);
  10183. }.bindAsEventListener(element))
  10184. });
  10185. }
  10186. if(defaultCountry !== '') { // Restrict the distributors select to just show the ones in the country
  10187. this.countryRestriction = defaultCountry;
  10188. }
  10189. HIB.sharing.globalSelectors.refreshDistributorSelect(defaultContinentZone);
  10190. },
  10191. refreshDistributorSelect: function(continentZone) {
  10192. var select = $('distributors-select');
  10193. select.update();
  10194. var country = '';
  10195. if(HIB.sharing.globalSelectors.countryRestriction === undefined) {
  10196. var continentZoneCountries = HIB.sharing.globalSelectors.options[continentZone];
  10197. var countries = HIB.sharing.globalSelectors.getKeys(continentZoneCountries);
  10198. for(var j = 0; j < countries.length; j++) {
  10199. country = continentZoneCountries[countries[j]];
  10200. for (var i = 0; i < country.length; i++) {
  10201. select.insert(country[i]);
  10202. }
  10203. }
  10204. } else {
  10205. country = HIB.sharing.globalSelectors.options[continentZone][HIB.sharing.globalSelectors.countryRestriction];
  10206. for (var i = 0; i < country.length; i++) {
  10207. select.insert(country[i]);
  10208. }
  10209. }
  10210. select.enable();
  10211. select.selectedIndex = 0;
  10212. },
  10213. cleanupContinents: function() {
  10214. $$('#distributors-continent-select option').each(function (element) {
  10215. if(HIB.sharing.globalSelectors.options[element.value] === undefined && element.value !== '-') {
  10216. element.remove();
  10217. }
  10218. });
  10219. },
  10220. getKeys: function (obj) {
  10221. var r = [];
  10222. for (var k in obj) {
  10223. if (!obj.hasOwnProperty(k))
  10224. continue;
  10225. r.push(k)
  10226. }
  10227. return r
  10228. }
  10229. };
  10230. HIB.sharing.spainSelectors = {
  10231. options: {},
  10232. init: function (optionsJson) {
  10233. this.options = optionsJson;
  10234. $$('#delegation-select').each(function (element) {
  10235. element.observe('change', function (event) {
  10236. HIB.sharing.spainSelectors.refreshDelegatesSelect(this.value);
  10237. }.bindAsEventListener(element))
  10238. });
  10239. var select = $('distributors-select');
  10240. select.update();
  10241. for(var i=0; i<this.options.length; i++) {
  10242. select.insert(this.options[i]);
  10243. }
  10244. select.selectedIndex = 0;
  10245. select.enable();
  10246. },
  10247. refreshDelegatesSelect: function(delegation) {
  10248. var select = $('distributors-select');
  10249. select.update();
  10250. select.insert(HIB.sharing.spainSelectors.options[delegation]);
  10251. select.selectedIndex = 0;
  10252. }
  10253. };
  10254. /* ProtoShow JavaScript slide show,
  10255. * v 0.9 (beta) - 24/02/12
  10256. * Copyright(c) 2012 David Smith (web: http://www.aheadcreative.com; twitter: @get_dave)
  10257. *
  10258. * This work is licenced under the Creative Commons Attribution-No Derivative Works 3.0 Unported License.
  10259. * http://creativecommons.org/licenses/by-nd/3.0/
  10260. *
  10261. * For more information on this project visit:
  10262. * http://www.protoshow.net
  10263. * http://www.deepbluesky.com
  10264. *
  10265. *--------------------------------------------------------------------------*/
  10266. if(typeof Prototype=='undefined' || typeof Scriptaculous =='undefined') {
  10267. throw("Protoshow.js requires the Prototype & Scriptaculous JavaScript frameworks");
  10268. } else {
  10269. var protoShow = Class.create({
  10270. initialize: function(element,options) {
  10271. // Default options
  10272. this.options = Object.extend({
  10273. selector : ".slide",
  10274. interval : 3000,
  10275. initialSlide : 1,
  10276. mode : "forward",
  10277. autoPlay : true,
  10278. autoRestart : true,
  10279. transitionType : "fade",
  10280. transitionTime : 1.5,
  10281. manTransitionTime : 0.5,
  10282. navigation : true,
  10283. controls : true,
  10284. stopText : "Pause",
  10285. playText : "Play",
  10286. nextText : "Next",
  10287. previousText : "Previous",
  10288. captions : false,
  10289. pauseOnHover : false,
  10290. keyboardControls : true,
  10291. fireEvents : true,
  10292. progressTimer : true,
  10293. swipeEvents : true
  10294. }, options || {}); // We use Prototype's Object.extend() to overwrite defaults with user preferences
  10295. // get/set various options
  10296. this.element = $(element); // DOM element that contains the slideshow
  10297. this.slides = this.element.select(this.options.selector); // Elements that are to be the "Slides"
  10298. this.slidesLength = this.slides.size(); // Total number of Slides
  10299. this.interval = this.options.interval;
  10300. this.transitionType = this.options.transitionType;
  10301. this.transitionTime = this.options.transitionTime;
  10302. this.manTransitionTime = this.options.manTransitionTime;
  10303. this.currentSlideID = this.options.initialSlide - 1;
  10304. this.nextSlideID = this.currentSlideID + 1;
  10305. this.playText = this.options.playText;
  10306. this.nextText = this.options.nextText;
  10307. this.previousText = this.options.previousText;
  10308. this.stopText = this.options.stopText;
  10309. this.mode = this[this.options.mode]; // Get play "mode" (forward, backward, random...etc)
  10310. this.autoPlay = this.options.autoPlay;
  10311. this.progressTimer = this.options.progressTimer;
  10312. this.showUniqueID = element; // get a unique ID based on the id attr of the show element
  10313. // define variables before use
  10314. this.running = false;
  10315. this.masterTimer = false;
  10316. this.animating = false; // boolean for "animating" status
  10317. this.loopCount = 0;
  10318. this.slideWidth = 0;
  10319. this.slideHeight = 0;
  10320. this.slideIntervals = [];
  10321. this.currentSlideEle = this.slides[this.currentSlideID];
  10322. this.nextSlideEle = this.slides[this.nextSlideID];
  10323. //run some initial setup
  10324. this.setupTransitions(this.options.transitionType);
  10325. this.setupSlides();
  10326. this.setupControls();
  10327. this.setupNavigation();
  10328. this.setupCaptions();
  10329. this.setupKeyboardControls();
  10330. this.setupSwipeEvents();
  10331. this.stopOnHover();
  10332. //this.createTimer();
  10333. this.setupTimer();
  10334. // let's get things going!
  10335. this.play();
  10336. },
  10337. /* DIRECTIONAL CONTROLS
  10338. ------------------------------------------------*/
  10339. play: function() {
  10340. // Role: Starts the show and initialises master timer
  10341. var _this = this;
  10342. this.running = true;
  10343. this.toggleMasterTimer(true);
  10344. this.updateControls(true);
  10345. this.fireCustomEvent("protoShow:started");
  10346. },
  10347. stop: function() {
  10348. // Completely stops the show and clears the master timer
  10349. var _this = this;
  10350. this.running = false;
  10351. this.toggleMasterTimer(false);
  10352. this.updateControls(false);
  10353. this.fireCustomEvent("protoShow:stopped");
  10354. },
  10355. toggleMasterTimer: function(bln) {
  10356. var _this = this;
  10357. if (bln) {
  10358. // Check if custom interval has been defined by user as data attribute in HTML
  10359. var slideInterval = (this.slideIntervals[this.currentSlideID]) ? this.slideIntervals[this.currentSlideID] : this.interval;
  10360. this.runProgressTimer();
  10361. // Set Master time which controls progress of show
  10362. this.masterTimer = new PeriodicalExecuter(function(pe) {
  10363. _this.mode();
  10364. }, slideInterval/1000);
  10365. this.loopCount++;
  10366. } else {
  10367. this.stopProgressTimer();
  10368. _this.masterTimer && _this.masterTimer.stop();
  10369. _this.masterTimer = null;
  10370. }
  10371. },
  10372. forward: function(transTime) {
  10373. // Role: Runs slideshow "forwards"
  10374. this.goMaster( this.currentSlideID + 1, transTime, "forward");
  10375. },
  10376. backward: function(transTime) {
  10377. // Role: Runs slideshow "backwards"
  10378. this.goMaster( this.currentSlideID - 1, transTime, "backward");
  10379. },
  10380. next: function() {
  10381. this.forward(this.manTransitionTime);
  10382. },
  10383. previous: function() {
  10384. this.backward(this.manTransitionTime);
  10385. },
  10386. gotoSlide: function(slide,transTime) {
  10387. if (slide === this.currentSlideID) {
  10388. return false;
  10389. }
  10390. this.goMaster( slide, this.manTransitionTime );
  10391. },
  10392. goMaster: function(next,transTime, direction) {
  10393. // Role: Master function - controls delegation of slide swapping
  10394. var _this = this;
  10395. // First thing's first, we hault the show whatever the circumstances
  10396. this.toggleMasterTimer(false);
  10397. if(this.isAnimating()) {
  10398. return false;
  10399. }
  10400. // Set the transistion speed to transTime arg (if set) else fallback to standard transitionTime
  10401. var transTime = (transTime) ? transTime : _this.transitionTime;
  10402. this.toggleAnimating(true);
  10403. this.setNextIndex(next); // set this.nextSlideID correctly
  10404. this.fireCustomEvent("protoShow:transitionStarted",transTime,direction,_this.nextSlideID);
  10405. _this.updateNavigation(_this.currentSlideID, _this.nextSlideID);
  10406. this.transitionType(this.currentSlideEle,this.nextSlideEle, {
  10407. transitionTime : transTime,
  10408. transitionFinish : function() { // pass a callback to ensure play can't resume until transition has completed
  10409. _this.toggleAnimating(false);
  10410. _this.currentSlideEle.removeClassName('active-slide');
  10411. _this.nextSlideEle.addClassName('active-slide');
  10412. _this.updateCaptions(_this.nextSlideEle);
  10413. _this.fireCustomEvent("protoShow:transitionFinished");
  10414. _this.currentSlideID = _this.nextSlideID; // update current slide to be the slide we're just moved to
  10415. _this.currentSlideEle = _this.slides[_this.nextSlideID];
  10416. if (_this.autoPlay && _this.running ) {
  10417. // if we're autoplaying and we're not explicity stopped
  10418. // otherwise show Master Timer is not permitted to restart itself
  10419. _this.toggleMasterTimer(true);
  10420. }
  10421. }
  10422. });
  10423. },
  10424. /* TRANSITION FUNCTIONS
  10425. ------------------------------------------------*/
  10426. fade: function(current,next,opts) {
  10427. // Role: Transition function
  10428. // Type: Fade - fades slides in and out
  10429. var _this = this;
  10430. next.show();
  10431. current.fade({
  10432. duration : opts.transitionTime,
  10433. afterFinish : function() {
  10434. return opts.transitionFinish();
  10435. }
  10436. });
  10437. },
  10438. slide: function(current,next,opts) {
  10439. // Role: Transition function
  10440. // Type: Slider - slides slides across the screen
  10441. var _this = this;
  10442. var leftPos = this.slideWidth * this.nextSlideID;
  10443. new Effect.Morph(_this.showEle, {
  10444. style: {
  10445. left: -leftPos + 'px'
  10446. },
  10447. duration : opts.transitionTime,
  10448. afterFinish : function() {
  10449. return opts.transitionFinish();
  10450. }
  10451. });
  10452. },
  10453. /* SETUP METHODS
  10454. ------------------------------------------------*/
  10455. setupSlides: function() {
  10456. var _this = this;
  10457. // Get and set user defined custom intervals
  10458. this.slides.each(function(e, index) {
  10459. if (_this.options.transitionType !== "slide") {
  10460. e.hide();
  10461. }
  10462. var slideInt = e.readAttribute('data-slide-interval');
  10463. slideInt = (slideInt && slideInt.blank()) ? undefined : slideInt; // check slideInt is not a blank string
  10464. _this.slideIntervals.push(slideInt); // push intervals into array for use later
  10465. });
  10466. // Ensure first slide is visible and has active class
  10467. this.slides[this.currentSlideID].show().addClassName('active-slide');
  10468. },
  10469. setupTransitions: function(transType) {
  10470. // Role: Setup basics for transitions
  10471. var _this = this;
  10472. if (typeof(transType) == "function") { // user has defined custom transition function
  10473. // If function then user has passed in custom transition function to be used
  10474. this.transitionType = transType;
  10475. this.element.addClassName('transition-custom');
  10476. } else { // it's a string
  10477. this.transitionType = this[transType];
  10478. this.element.addClassName('transition-' + transType);
  10479. if (transType === "slide") {
  10480. this.showWindow = this.element.down('.show').wrap('div', { 'class': 'show-window' });
  10481. this.showEle = this.showWindow.down('.show');
  10482. var slideLayout = this.slides[0].getLayout();
  10483. this.slideWidth = slideLayout.get('width');
  10484. this.slideHeight = slideLayout.get('height');
  10485. this.showWindow.setStyle({
  10486. width : _this.slideWidth + "px",
  10487. height : _this.slideHeight + "px"
  10488. });
  10489. }
  10490. }
  10491. },
  10492. setupControls: function() {
  10493. // Role: Setup controls
  10494. var _this = this;
  10495. if (!this.options.controls) {
  10496. return false;
  10497. }
  10498. this.protoControls = this.element.down('.proto-controls'); // Stop/Forward/Back buttons
  10499. if (typeof this.protoControls==="undefined" ) {
  10500. var controlsEle = new Element('ol', { 'class': 'proto-controls'});
  10501. var controlsTemplate = new Template('<li class="#{htmlclass}"><a href="javascript:void(0)" title="#{title}">#{text}</a></li>');
  10502. var startStop = controlsTemplate.evaluate({
  10503. htmlclass: "proto-control start-stop",
  10504. text: this.playText,
  10505. title: "Pause the show"
  10506. });
  10507. var backward = controlsTemplate.evaluate({
  10508. htmlclass: "proto-control backward",
  10509. text: this.previousText,
  10510. title: "Go to Previous slide and play backwards"
  10511. });
  10512. var forward = controlsTemplate.evaluate({
  10513. htmlclass: "proto-control forward",
  10514. text: this.nextText,
  10515. title: "Go to Next slide and play forwards"
  10516. });
  10517. // Build a DOM fragment from all the above
  10518. controlsEle.insert(startStop,'bottom').insert(backward,'bottom').insert(forward,'bottom');
  10519. this.element.insert(controlsEle,'bottom'); // add into DOM
  10520. this.protoControls = $(controlsEle); // extend the DOM fragment
  10521. }
  10522. // If the controls already exists in the DOM
  10523. this.controlStartStop = this.protoControls.down('.start-stop');
  10524. this.controlForward = this.protoControls.down('.forward');
  10525. this.controlBackward = this.protoControls.down('.backward');
  10526. // define "lock" variable to stop abuse of controls
  10527. var handlingClick = false;
  10528. this.protoControls.on("click", ".proto-control", function(event, element) {
  10529. event.stop();
  10530. // make sure we're not processing multiple click events
  10531. if (handlingClick) {
  10532. return false;
  10533. }
  10534. handlingClick = true;
  10535. if(element === _this.controlForward) {
  10536. _this.next();
  10537. } else if (element === _this.controlBackward) {
  10538. _this.previous();
  10539. } else {
  10540. if (_this.running) {
  10541. _this.stop(); // if we're "Playing" then stop the show
  10542. } else {
  10543. _this.play(); // else if we're not "Playing" then start the show
  10544. }
  10545. }
  10546. /*remove the "lock" variable*/
  10547. handlingClick = false;
  10548. });
  10549. },
  10550. setupNavigation: function() {
  10551. // Role: Setup Navigation
  10552. var _this = this;
  10553. if (!this.options.navigation) {
  10554. return false;
  10555. }
  10556. this.protoNavigation = this.element.down('.proto-navigation');
  10557. if (typeof this.protoNavigation==="undefined" ) {
  10558. var navEle = new Element('ol', { 'class': 'proto-navigation'});
  10559. var navTemplate = new Template('<li><a href="##{number}" title="Skip to Slide #{number}">#{number}</a></li>');
  10560. this.slides.each(function(e,index) { // for each slide in the show create a Nav <li> using the Template above
  10561. var li = navTemplate.evaluate({number: index+1});
  10562. navEle.insert(li,'bottom');
  10563. });
  10564. this.element.insert(navEle,'bottom');
  10565. this.protoNavigation = this.element.down('.proto-navigation');
  10566. }
  10567. this.protoNavigation.down('li').addClassName('current-slide');
  10568. // define "lock" variable to stop abuse of controls
  10569. var handlingClick = false;
  10570. this.protoNavigation.on("click", "a", function(event, element) {
  10571. event.stop();
  10572. // make sure we're not processing multiple click events
  10573. if (handlingClick) {
  10574. return false;
  10575. }
  10576. handlingClick = true;
  10577. var index = element.hash.substr(1,2); // get the slide ID from the href hash (eg: #3)
  10578. _this.gotoSlide(index-1);
  10579. /*remove the "lock" variable*/
  10580. handlingClick = false;
  10581. });
  10582. },
  10583. updateNavigation: function(current,next) {
  10584. if (typeof this.protoNavigation !== "undefined" ) {
  10585. this.protoNavigation.select('li')[current].removeClassName('current-slide');
  10586. this.protoNavigation.select('li')[next].addClassName('current-slide');
  10587. }
  10588. },
  10589. setupCaptions: function() {
  10590. var _this = this;
  10591. if (this.options.captions) {
  10592. var captionEle = new Element('div', { 'class' : 'slide-caption'});
  10593. captionEle.hide();
  10594. this.element.insert(captionEle,'bottom');
  10595. this.captionsElement = captionEle;
  10596. this.updateCaptions(_this.currentSlideEle);
  10597. }
  10598. },
  10599. updateCaptions: function(slide) {
  10600. if (!this.options.captions) {
  10601. return false;
  10602. }
  10603. var nextCaption = slide.down('img').readAttribute('alt');
  10604. if (nextCaption.replace(/^\s*|\s*$/g,'').length) { // check that the attribute has some content (not just spaces)
  10605. if(!this.captionsElement.visible()) {
  10606. // just check that the element is visible
  10607. this.captionsElement.show();
  10608. }
  10609. this.captionsElement.update(nextCaption);
  10610. } else { // if no caption is found then hide the caption element
  10611. this.captionsElement.hide();
  10612. }
  10613. },
  10614. stopOnHover: function() {
  10615. var _this = this;
  10616. if (this.options.pauseOnHover) {
  10617. this.element.down('.show').observe('mouseenter',function() {
  10618. _this.stop();
  10619. }).observe('mouseleave',function() {
  10620. _this.play();
  10621. });
  10622. }
  10623. },
  10624. setupKeyboardControls: function() {
  10625. // 39 = right arrow
  10626. // 37 = left arrow
  10627. if (!this.options.keyboardControls) {
  10628. return false;
  10629. }
  10630. var _this = this;
  10631. document.observe('keydown', function(key) {
  10632. var keyCode = key.keyCode;
  10633. // stop arrow keys from working when focused on form items
  10634. if ( (!key.target.tagName.match('TEXTAREA|INPUT|SELECT')) && (keyCode === 37 || keyCode === 39) ) {
  10635. if (keyCode === 37) {
  10636. _this.previous();
  10637. } else if (keyCode === 39) {
  10638. _this.next();
  10639. }
  10640. } else {
  10641. return false;
  10642. }
  10643. });
  10644. },
  10645. setupSwipeEvents: function() {
  10646. var _this = this;
  10647. var touchStartX = false;
  10648. if (!this.options.swipeEvents) {
  10649. return false;
  10650. }
  10651. /* TOUCH START: Get and store the position of the initial touch */
  10652. this.element.observe('touchstart', function(e) {
  10653. touchStartX = e.targetTouches[0].clientX;
  10654. });
  10655. /* TOUCH MOVE: Called every time a user moves finger across the screen */
  10656. this.element.observe('touchmove', function(e) {
  10657. if (touchStartX > e.targetTouches[0].clientX) {
  10658. _this.next();
  10659. } else {
  10660. _this.previous();
  10661. }
  10662. });
  10663. },
  10664. fireCustomEvent: function(event_name,trans_time,direction,slideID) {
  10665. if(this.options.fireEvents) {
  10666. var element = this.element;
  10667. element.fire(event_name, {
  10668. showID : this.showUniqueID,
  10669. transitionTime : trans_time,
  10670. direction : direction,
  10671. slideID : slideID
  10672. });
  10673. }
  10674. },
  10675. /* UTILITY FUNCTIONS
  10676. ------------------------------------------------*/
  10677. isPlaying: function() {
  10678. return this.masterTimer != null;
  10679. },
  10680. isAnimating: function() {
  10681. return this.animating;
  10682. },
  10683. toggleAnimating: function(bln) {
  10684. // Role: toggles var to say whether animation is in progress and manipulates DOM
  10685. this.animating = bln;
  10686. if (bln) {
  10687. this.element.addClassName("animating");
  10688. } else {
  10689. this.element.removeClassName("animating");
  10690. }
  10691. },
  10692. setNextIndex: function(next) {
  10693. // Role: Decides on direction and ensures within bounds
  10694. if(next === undefined) { // Ensure "next" has a value
  10695. next = this.currentSlideID+1;
  10696. }
  10697. // Ensure we're within bounds
  10698. if (next >= this.slidesLength) {
  10699. next = 0;
  10700. } else if (next < 0 ){
  10701. next = this.slidesLength-1;
  10702. }
  10703. this.nextSlideID = next;
  10704. this.nextSlideEle = this.slides[this.nextSlideID];
  10705. },
  10706. updateControls: function(status) {
  10707. if (this.options.controls) {
  10708. // Role: Updates the status of the Play/Pause button
  10709. var _this = this;
  10710. if (status) { // The show has been started so update the button to "Pause"
  10711. this.controlStartStop.down('a').update(_this.stopText);
  10712. } else {
  10713. // The show has been stopped so update the button to "Play"
  10714. this.controlStartStop.down('a').update(_this.playText);
  10715. }
  10716. }
  10717. },
  10718. setupTimer: function() {
  10719. // Role: creates the proto-progress-timer <canvas> element, gets 2D Context and inserta into DOM
  10720. this.progressTimerEle = document.createElement('canvas');
  10721. if (this.progressTimerEle.getContext && this.progressTimerEle.getContext('2d')) { // test for Canvas support
  10722. this.progressTimerEle.writeAttribute('class','proto-progress-timer');
  10723. this.progressTimerEle.width = 30;
  10724. this.progressTimerEle.height = 30;
  10725. this.element.insert(this.progressTimerEle,'bottom');
  10726. this.progressTimerCtx = this.progressTimerEle.getContext('2d');
  10727. } else {
  10728. this.progressTimer = false; // no canvas support
  10729. }
  10730. },
  10731. runProgressTimer: function() {
  10732. // Role: runs & controls the animation of the "progress timer"
  10733. var _this = this;
  10734. if (this.progressTimer) { // if user has set to use progress timer and the browser supports <canvas>
  10735. this.progressTimerEle.show();
  10736. // use Epoch time to ensure code executes in time specified
  10737. // borrowed from Emile JS http://script.aculo.us/downloads/emile.pdf
  10738. var start = (new Date).getTime();
  10739. // we want the timer to finish slightly before the slide transitions
  10740. // so we shorten the duration by 1/4
  10741. var duration = this.interval*0.75;
  10742. var finish = start+duration;
  10743. var angleStart = 0;
  10744. this.progressTimerPE = new PeriodicalExecuter(function(pe) {
  10745. _this.resetProgressTimer(); // clear the canvas ready for next segment
  10746. this.drawArc(_this.progressTimerCtx,0,360,'rgba(0,0,0,.2)'); // redraw the black bg circle
  10747. var time = (new Date).getTime();
  10748. var pos = time>finish ? 1 : (time-start)/duration;
  10749. // draw the arch passing in the ctx and the degress of the arch
  10750. this.drawArc(_this.progressTimerCtx,-5,Math.floor(( (360) * pos)),'rgba(255,255,255,.8)',true);
  10751. if( (!this.isPlaying()) || time>finish) { // if we are stopped or we are finished then stop the PE and fade the canvas out
  10752. pe.stop();
  10753. _this.progressTimerEle.fade({
  10754. duration: (_this.interval > 1000) ? (_this.interval/8)/1000 : 0.2,
  10755. afterFinish: function() {
  10756. _this.resetProgressTimer();
  10757. }
  10758. });
  10759. }
  10760. }.bind(this),duration/100000);
  10761. }
  10762. },
  10763. resetProgressTimer: function() {
  10764. this.progressTimerEle.width = this.progressTimerEle.width;
  10765. },
  10766. stopProgressTimer: function() {
  10767. this.resetProgressTimer();
  10768. clearInterval(this.progressTimerPE);
  10769. },
  10770. drawArc: function(canvasCtx,startAngle,endAngle,strokeStyle) {
  10771. // Role: utility function for drawing archs on <canvas> elements
  10772. var drawingArc = true;
  10773. var ctx = canvasCtx;
  10774. ctx.beginPath();
  10775. ctx.strokeStyle = strokeStyle;
  10776. ctx.lineCap = 'butt';
  10777. ctx.lineWidth = 4;
  10778. ctx.arc(15,15,10, (Math.PI/180)*(startAngle-90),(Math.PI/180)*(endAngle-90), false);
  10779. ctx.stroke();
  10780. var drawingArc = false;
  10781. },
  10782. /* LOGGING FUNCTIONS
  10783. ------------------------------------------------*/
  10784. /*reportSlides: function() {
  10785. console.log("Current slide: " + this.currentSlideID);
  10786. console.log("Next slide: " + this.nextSlideID);
  10787. },*/
  10788. cc: function() {
  10789. // catches the comma
  10790. }
  10791. });
  10792. Element.addMethods({
  10793. // Make Protoshow available as method of all Prototype extended elements
  10794. // http://www.prototypejs.org/api/element/addmethods
  10795. protoShow: function(element, options) {
  10796. element = $(element);
  10797. var theShow = new protoShow(element,options);
  10798. return theShow;
  10799. }
  10800. });
  10801. }
  10802. if (typeof HIB !== 'object') {
  10803. var HIB = {}
  10804. }
  10805. HIB.searcher = {
  10806. suggest_url: null,
  10807. field_name: null,
  10808. min_chars: null,
  10809. delay: null,
  10810. observer: null,
  10811. // Ignored keys => avoid search results for this key, but it has basic functions
  10812. ignored_keys: [
  10813. 16 /* Shift */, 17 /* Ctrl */,
  10814. 18 /* Alt */, 19 /* Pause/Break */,
  10815. 20 /* Caps Lock */, 91 /* LeftWindowKey */,
  10816. 112 /* F1 */, 113 /* F2 */,
  10817. 114 /* F3 */, 115 /* F4 */,
  10818. 116 /* F5 */, 117 /* F6 */,
  10819. 118 /* F7 */, 119 /* F8 */,
  10820. 120 /* F9 */, 121 /* F10 */,
  10821. 122 /* F11 */, 123 /* F12 */,
  10822. 144 /* NumLock */, 145 /* ScrollLock */
  10823. ],
  10824. init: function () {
  10825. var that = this;
  10826. if (that.suggest_url == null || that.field_name == null || that.min_chars == null || that.delay == null) {
  10827. return;
  10828. }
  10829. // When user focus on search input or click on search button, overlay searcher will be shown
  10830. document.getElementById("searchPrincipal").addEventListener('focus', function () {
  10831. that.showSearcher();
  10832. }, true);
  10833. document.getElementById("searcherbutton").addEventListener('click', function () {
  10834. that.showSearcher();
  10835. }, true);
  10836. document.getElementById("searchPrincipal").addEventListener('keyup', function (e) {
  10837. that.prepareSearch(e);
  10838. }, true);
  10839. document.getElementById("search-close").addEventListener('click', function () {
  10840. that.hideSearcher();
  10841. }, true);
  10842. // Add ESC Key event to close searcher if open
  10843. document.addEventListener('keyup', function (e) {
  10844. if ((e.keyCode == 27) && (document.getElementById("overlaySearch").style.width == "100%")) { // escape key maps to keycode `27`
  10845. that.hideSearcher();
  10846. }
  10847. });
  10848. },
  10849. showSearcher: function () {
  10850. //document.getElementById("overlaySearch").style.width = "100%";
  10851. //document.getElementById('search_query').focus();
  10852. var body = document.getElementsByTagName('body')[0];
  10853. body.className += ' solrsearch-active';
  10854. },
  10855. hideSearcher: function () {
  10856. //document.getElementById("overlaySearch").style.width = "0%";
  10857. //document.getElementById("search_query").value = '';
  10858. //document.getElementById("searchResults").innerHTML = '';
  10859. var body = document.getElementsByTagName('body')[0];
  10860. body.classList.remove('solrsearch-active');
  10861. document.getElementById("searchPrincipal").blur();
  10862. },
  10863. search: function () {
  10864. var that = this;
  10865. var query = document.getElementById("searchPrincipal").value;
  10866. if (query.length >= that.min_chars) {
  10867. var url = "shared/search.php";
  10868. new Ajax.Request(url, {
  10869. method: 'POST',
  10870. parameters: {'searchPrincipal': query},
  10871. onSuccess: function (response) {
  10872. document.getElementById('searchResults').innerHTML = response.responseText;
  10873. },
  10874. onFailure: function () {
  10875. document.getElementById('searchResults').innerHTML = 'No results';
  10876. }
  10877. });
  10878. } else {
  10879. if (document.getElementById('searchResults').innerHTML !== '') {
  10880. document.getElementById('searchResults').innerHTML = '';
  10881. }
  10882. }
  10883. },
  10884. prepareSearch: function (event) {
  10885. switch (event.keyCode) {
  10886. case Event.KEY_ESC:
  10887. this.hideSearcher();
  10888. Event.stop(event);
  10889. break;
  10890. case Event.KEY_UP:
  10891. case Event.KEY_DOWN:
  10892. case Event.KEY_LEFT:
  10893. case Event.KEY_RIGHT:
  10894. case Event.KEY_PAGEUP:
  10895. case Event.KEY_PAGEDOWN:
  10896. case Event.KEY_TAB:
  10897. case Event.KEY_END:
  10898. case Event.KEY_HOME:
  10899. case Event.KEY_INSERT:
  10900. break;
  10901. case Event.KEY_RETURN:
  10902. document.getElementById("search_mini_form").submit();
  10903. Event.stop(event);
  10904. break;
  10905. default:
  10906. // AVOID OTHER SPECIAL CHARACTERS
  10907. if (this.ignored_keys.indexOf(event.keyCode) == -1) {
  10908. if (null != this.observer) {
  10909. clearTimeout(this.observer);
  10910. }
  10911. this.observer =
  10912. setTimeout(this.search.bind(this), this.delay * 1000);
  10913. }
  10914. break;
  10915. }
  10916. }
  10917. };
  10918. var tooltipOptions=
  10919. {
  10920. showDelay: 100,
  10921. hideDelay: 300,
  10922. effect: "fade",
  10923. duration: 200,
  10924. relativeTo: "element",
  10925. position: 1,
  10926. smartPosition: true,
  10927. offsetX: 0,
  10928. offsetY: 0,
  10929. maxWidth: 500,
  10930. calloutSize: 16,
  10931. calloutPosition: 0.3,
  10932. cssClass: "",
  10933. sticky: false,
  10934. overlay: false,
  10935. license: "64628"
  10936. };
  10937. var tooltip=function(v){"use strict";var f="length",Cb="addEventListener",kb,mc,fb=function(a,b,c){a[Cb]?a[Cb](b,c,!1):a.attachEvent&&a.attachEvent("on"+b,c)},a={},Y=function(a){a&&a.stopPropagation?a.stopPropagation():window.event&&(window.event.cancelBubble=!0)},jc=function(a){var b=a?a:window.event;b.preventDefault?b.preventDefault():b&&(b.returnValue=!1)},Xb=function(a){var b=a.childNodes,c=[];if(b)for(var d=0,e=b[f];d<e;d++)1==b[d].nodeType&&c.push(b[d]);return c},bb={a:0,b:0},g=null,ec=function(a){a||(a=window.event),bb.a=a.clientX,bb.b=a.clientY},bc=function(a){if(window.getComputedStyle)var b=window.getComputedStyle(a,null);else b=a.currentStyle?a.currentStyle:a[e];return b},G="offsetLeft",H="offsetTop",pb="clientWidth",ob="clientHeight",z="appendChild",Jb="display",nc="border",r="opacity",U=0,O="createElement",cb="getElementsByTagName",B="parentNode",M="calloutSize",S="position",Db="calloutPosition",D=Math.round,rb="overlay",R="sticky",L="hideDelay",mb="onmouseout",Hb="onclick",n=0,P="firstChild",tb=0,q=document,W="getElementById",Z=navigator,Q="innerHTML",t=function(a,b){return b?q[a](b):q[a]},C={},vb=!!Z.msMaxTouchPoints,V=!!("ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch),Fb=(Z.msPointerEnabled||Z.pointerEnabled)&&vb;if(Fb)var Ub=Z.msPointerEnabled?"onmspointerout":"onpointerOut";var Nb=function(a){return a.pointerType==a.MSPOINTER_TYPE_MOUSE||"mouse"==a.pointerType},lc="marginTop",ic="marginLeft",w="offsetWidth",m="offsetHeight",sb="documentElement",kc="borderColor",gb="nextSibling",e="style",y="width",o="left",p="top",I="height",gc=["$1$2$3","$1$2$3","$1$24","$1$23","$1$22"],x,lb,A=function(a,b,c){return setTimeout(a,b?b.showDelay:c)},eb=function(a){return clearTimeout(a),null},nb=function(){for(var a=[c,b,h,d,d?d[gb]:0],e=0;e<a[f];e++)a[e]&&a[e].o&&(a[e].o=eb(a[e].o))},Lb=function(a,b,c){Gb(a,b[0][0],b[0][1],c),2==b[f]&&Gb(a,b[1][0],b[1][1],c)},Gb=function(a,b,c,d){clearInterval(a["t"+b]),a["t"+b]=setInterval(function(){cc(a,b,c,d)},15)},cc=function(a,b,c,d){var f=0;if(b==r)(c&&a.op>=1||!c&&a.op<=0)&&f++;else{var g=parseInt(a[e][b]);Math.abs(g-c)<2&&f++}f?(clearInterval(a["t"+b]),d&&d()):b==r?X(a,a.op+(c?.06:-.06)):(g+=(c-g)/3,Math.abs(g-c)<4&&(g=c),a[e][b]=g+"px")},l=function(a,b,c){if(!n)return void(a!=h&&Lb(a,b,c));var d=k?k.duration:v.duration;a[e][n]="all "+d+"ms",a[e][b[0][0]]=b[0][1]+(b[0][0]==r?"":"px"),2===b[f]&&(a[e][b[1][0]]=b[1][1]+(b[1][0]==r?"":"px")),c&&(n?(clearTimeout(a.o),a.o=setTimeout(c,d)):setTimeout(c,6))},J=function(a,b){n&&(a[e][n]="none"),a[e][b[0][0]]=b[0][1]+"px",2===b[f]&&(a[e][b[1][0]]=b[1][1]+"px"),a[m]},fc=[/(?:.*\.)?(\w)([\w\-])[^.]*(\w)\.[^.]+$/,/.*([\w\-])\.(\w)(\w)\.[^.]+$/,/^(?:.*\.)?(\w)(\w)\.[^.]+$/,/.*([\w\-])([\w\-])\.com\.[^.]+$/,/^(\w)[^.]*(\w)$/],ib=function(a,b){var c=[];if(tb)return tb;for(var d=0;d<a[f];d++)c[c[f]]=String.fromCharCode(a.charCodeAt(d)-(b&&b>7?b:3));return c.join("")},Kb=function(a){return a.replace(/(?:.*\.)?(\w)([\w\-])?[^.]*(\w)\.[^.]*$/,"$1$3$2")},dc=function(a,b){var c=function(a){var b=a.charCodeAt(0).toString();return b.substring(b[f]-1)};return a+c(b[parseInt(ib("4"))])+b[2]+c(b[0])},c,b,d,ab,h,j,T=0,hc=1,k,E=null,F=function(){null!=E&&(E=eb(E))},X=function(a,b){a&&(a.op=b,void 0!==a[e][r]?a[e][r]=b:a[e].filter="alpha(opacity="+100*b+")")},Mb=function(a,b,c,d,e,f,g,h){var i=c>=a,j=d>=b,k=i?c-a<e:a-c<g,l=j?d-b<f:b-d<h,m=k?c-a:i?e:-g,n=l?d-b:j?f:-h;return k&&l&&(Math.abs(m)>Math.abs(n)?m=i?e:-g:n=j?f:-h),[m,n]},ac=function(a,c,g){if(0==c.indexOf("tip-")){db(b,1);var h=t(O,"div");if(h[e][y]=a+"px",d=t(O,"div"),d.className="mcTooltipInner",1==g){d[Q]=c;var i=1}else{var j=t(W,c);j[B].w?d=j[B]:(d.w=j[B],d[z](j),i=1)}if(!n)for(var k=d[cb]("select"),l=k[f];l--;)k[l][mb]=Y;if(h[z](d),b[z](h),d[w]<20){var q=b.className;b.className=""}var r=d[cb]("img");return r&&r[f]&&r[0][m],d[e][y]=d[w]+(i?.3:0)+"px",d[e][I]=d[m]+(i?.3:0)+"px",d[e][o]=d[e][p]="auto",d=b.insertBefore(d,b[P]),d[e][S]="absolute",h=b.removeChild(h),h=null,q&&(b.className=q),d}},Ob=function(a){a.w?(a.w[z](a),X(a,1)):(a=a[B].removeChild(a),a=null)},db=function(a,b){for(var c=b;c<a.childNodes[f];c++)Ob(a.childNodes[c])},i=function(a,b){a[e][Jb]=b?"block":"none"},Tb=function(){c.v=U=0,i(ab,0),i(c,0),i(h,0),i(T,0),db(b,0)},Sb=function(){if(document.styleSheets&&document.styleSheets.length){var a=document.styleSheets[0];if("undefined"!=typeof b.style.animationName)var c="";if("undefined"==typeof b.style.webkitAnimationName)return;c="-webkit-";var d="@"+c+"keyframes mcttSpinner {from{transform:rotate(0deg);} to{transform:rotate(360deg);}}";a.insertRule(d,0);var e="#tooltipAjaxSpin {margin:30px;font-size:0;width:20px;height:20px;border-width:3px;border-color:rgba(255,255,255,.8);border-style:solid;border-top-color:black;border-right-color:rgba(0,0,0,.8);border-radius:50%;"+c+"animation:mcttSpinner .6s linear infinite;}";a.insertRule(e,0)}},s=null,Wb={a:function(d,b,a){var e=null,h=null,i=null,c="html";a&&(h=a.success||null,c=a.responseType||"html",e=a.context&&h?a.context:null,i=a.fail||null),s=this.b(),s.onreadystatechange=function(){if(s&&4===s.readyState){if(200===s.status){if(k==d){var j="xml"==c.toLowerCase()?s.responseXML:s.responseText,l=j;if("json"==c.toLowerCase()&&(l=eval("("+j+")")),"html"==c){var o=b.match(/.+#([^?]+)/);if(o){var r=function(a,b){var c=null;if(b.id==a)return b;for(var d=b[cb]("*"),e=0,g=d[f];e<g;e++)if(d[e].id==a){c=d[e];break}return c},n=q[O]("div");n[Q]=j;var m=r(o[1],n);m&&(j=l=m[Q]),n=null}if(!m){var p=j.split(/<\/?body[^>]*>/i);p[f]>1&&(j=l=p[1])}}h&&(j=a.success(l,e)),g.f(d,j,1)}}else i?g.f(d,i(e),1):g.f(d,"Failed to get data.",1);s=null}},b.indexOf("#")!=-1&&Z.userAgent.indexOf("MSIE ")!=-1&&(b=b.replace("#","?#")),s.open("GET",b,!0),s.send(null)},b:function(){var a;try{a=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP")}catch(a){throw new Error("AJAX not supported.")}return a}},Ib=function(){c=t(O,"div"),c.id="mcTooltipWrapper",c[Q]='<div id="mcTooltip"><div>&nbsp;</div></div><div id="mcttCo"><b></b></div><div id="mcttCloseButton"></div>',x=q.body,j=x,j[z](c),a.a=v.license||"4321","undefined"!=typeof c[e].transition&&(n="transition"),navigator.userAgent.indexOf("Chrome")==-1&&navigator.userAgent.indexOf("Safari")!=-1&&(n="webkitTransition"),n||(c.op=.1),b=c[P],c.b=c.c=c.v=0,ab=c.lastChild,h=b[gb],i(c,1),this.m(v,1),i(c,0);var d=this.k();kb=function(a){F(),d.i(),Y(a)},ab[Hb]=kb,this.l(),b[mb]=function(){!k[R]&&d.a(k[L])},b[Hb]=Y,fb(b,"touchstart",Y);var f=function(a){k&&0!==c.v&&a.target!=k&&1!==k[R]&&(E=A(function(a){kb(a)},0,k[L]+99)),V&&0===c.v&&a.target==k&&k.dispatchEvent(new MouseEvent("mouseover"))};fb(q,"click",f),fb(q,"touchstart",f),X(c,0),c[e].visibility="visible",Pb()},Yb=function(){var a=q.getElementsByTagName("head");if(a[f]){var b=q.createElement("style");return a[0].appendChild(b),b.sheet?b.sheet:b.styleSheet}return 0},Zb=function(){if("undefined"!=typeof b.style.transform)a="";else if("undefined"!=typeof b.style.webkitTransform)var a="-webkit-";else if("undefined"!=typeof b.style.msTransform)var a="-ms-";else a=0;return a},Bb=function(a){a=a.replace("__",C.prefix),C.a.insertRule(a,0)},Pb=function(){if(C.prefix=Zb(),C.a=Yb(),C.a){var a="#mcttCloseButton",b="position:absolute;left:auto;cursor:pointer;top:"+v[M]+"px;right:"+v[M]+"px;";"insertRule"in C.a?(Bb(a+"{"+b+"}"),Bb("#mcttCloseButton::after{content:'+';display:block;position:absolute;__transform:rotate(45deg);}")):(C.a.addRule(a,b,0),C.a.addRule("#mcttCloseButton:after","content:'X';display:block;position:absolute;",0))}},yb=function(a){if(a[B]){var b=a[B].nodeName.toLowerCase();return"form"!=b&&"body"!=b?yb(a[B]):a[B]}return x},u=function(a,b){var c=a.getBoundingClientRect();return b?c[p]:c[o]},K=function(a){return a?q[sb][ob]:q[sb][pb]},Vb=function(){var a=q[sb];return[window.pageXOffset||a.scrollLeft,window.pageYOffset||a.scrollTop]},hb=function(b,c,d,f,g){h[e][b?y:I]=1.55*a.f+"px",c[e].webkitTransform=c[e].transform="translate("+f+"px,"+g+"px) rotate("+d+"deg)"},Rb=function(a,b,c,d){var e=K(0),f=K(1),g=0,h=0;return j!=x&&(g=u(j,0)-j[G],h=u(j,1)-j[H]),c+g+a>e&&(c=e-a-g),c+g<0&&(c=-g),d+h+b>f&&(d=f-b-h),d+h<0&&(d=-h),{l:c,t:d}};Ib.prototype={j:function(){if("undefined"==typeof h[e].transform&&"undefined"==typeof h[e].webkitTransform)return void(h[e][y]="0");var b=h[P];switch(h[e][y]=h[e][I]=b[e][y]=b[e][I]=a.f+"px",b[e].borderLeft=b[e].borderTop=a.b+"px solid "+a.d,b[e].backgroundColor=a.c,a.e){case 0:hb(1,b,-135,a.f/4,-a.f/2);break;case 2:hb(1,b,45,a.f/4,a.f/2);break;case 3:hb(0,b,135,-a.f/2,a.f/4);break;default:hb(0,b,-45,a.f/2,a.f/4)}},d:function(a,b,d){F(),E=A(function(){(1!=U||a!=c.v)&&g.f(a,b,d)},a)},e:function(a,b,c){F(),E=A(function(){g.g(a,b,c)},a)},f:function(e,f,g){if(0==f.indexOf("tip-")){i(c,1),U=1,F(),nb(),i(T,e[rb]),i(ab,e[R]),V&&i(ab,1);var j=this.n(e,f,g);if(c.v)l(c,[[o,j.l],[p,j.t]]),l(b,[[y,b.tw],[I,b.th]]),l(h,[[o,j.x],[p,j.y]]);else if(4==a.e){var k=u(e,0),n=u(e,1);J(c,[[o,k],[p,n]]),l(c,[[o,j.l],[p,j.t]]),l(b,[[y,b.tw],[I,b.th]])}else J(c,[[p,j.t],[o,j.l]]),J(b,[[y,b.tw],[I,b.th]]),J(h,[[o,j.x],[p,j.y]]);if("slide"==e.effect){var q,s;if(!c.v&&a.e<4){switch(a.e){case 0:q=0,s=1;break;case 1:q=-1,s=0;break;case 2:q=0,s=-1;break;case 3:q=1,s=0}var t=[q*d[w],s*d[m]]}else{!c.v&&a.e>3?(q=e[G],s=e[H]):(q=c[G],s=c[H],a.e>3&&(q+=c.v[G]-e[G],s+=c.v[H]-e[H]));var v=a.l+a.b+a.b,x=a.m+a.b+a.b;t=Mb(q,s,j.l,j.t,b.b+v,b.c+x,b.tw+v,b.th+x)}var z=a.l/2,A=a.m/2;J(d,[[o,t[0]+z],[p,t[1]+A]]),l(d,[[o,z],[p,A]]);var B=d[gb];B&&(J(B,[[o,z],[p,A]]),l(B,[[o,-t[0]+z],[p,-t[1]+A]],function(){db(b,1)})),X(d,1)}else{l(d,[[r,1]],function(){db(b,1)});var B=d[gb];B&&l(B,[[r,0]])}l(c,[[r,1]]),c.v=e}},g:function(a,b,c){s=null,F(),!V&&g.f(a,'<div id="tooltipAjaxSpin">&nbsp;</div>',1),Wb.a(a,b,c)},a:function(a){F(),E=A(function(){g.i()},0,a)},i:function(){U=-1,nb(),l(c,[[r,0]],Tb)},l:function(){null==t(W,"mcOverlay")&&(T=t(O,"div"),T.id="mcOverlay",x[z](T),T[e][S]="fixed")},m:function(f,g){var j=0;if((g||a.e!=f[S]||a.f!=f[M])&&(a.e=f[S],a.f=f[M],c[e].padding=a.f+"px",j=1),g||b.className!=f.cssClass){b.className=f.cssClass?f.cssClass.replace(/^\s+|\s+$/g,""):"",d&&(d[e][n]="none",d[m]),b[e][n]="none",b[m];var k=bc(b),l=Math.ceil(parseFloat(k.borderLeftWidth)),o=k.backgroundColor,p=k.borderLeftColor;(g||a.b!=l||a.c!=o||a.d!=p)&&(a.b=l,a.c=o,a.d=p,j=1),a.l=g?b[pb]-b[P][w]:2*d[G],a.m=g?b[ob]-b[P][m]:2*d[H]}j&&(a.e<4?this.j():i(h,0))},k:function(){return new Function("a","b","c","d","e","f","g","h","i",function(a){var d=[];b.onmouseover=function(a){k[R]||(F(),U==-1&&(nb(),l(c,[[r,1]]))),Y(a)};for(var e=0,g=a[f];e<g;e++)d[d[f]]=String.fromCharCode(a.charCodeAt(e)-4);return d.join("")}("zev$pAi,k,g,+kvthpu+0405--€€+6+-?zev$qAe2e€€+55+0rAtevwiMrx,q2glevEx,4--0sA,,k,g,+kvthpu+0405--€€+px+-2vitpegi,h_r16a0l_r16a--2wtpmx,++-?mj,e2e%Aj,r/+8+0s--qAQexl_g,+yhukvt+-a,-?mj,q@259-wixXmqisyx,jyrgxmsr,-m,40g,+Ch'oylmD.o{{wA66~~~5tlu|jvvs5jvt6.E[vvs{pw'W|yjohzl'YltpuklyC6hE+-0tswmxmsr>:-?06444-?vixyvr$xlmw?")).apply(this,[a,P,ib,fc,Kb,dc,t,gc,jb])},n:function(g,k,l){var o=x;if(2==l)for(var p=t(W,k),q=p[cb]("*"),r=q[f];r--;)"submit"==q[r].type&&(o=yb(p));j!=o&&(j=o,j[z](c)),b.b=b[pb]-a.l,b.c=b[ob]-a.m,d="",0==k.indexOf("tip-")&&(d=ac(g.maxWidth,k,l)),this.m(g,0),n||(d[e].backgroundColor=a.c),0==k.indexOf("tip-")&&(b.tw=d[w],b.th=d[m]),"fade"==g.effect&&X(d,0);var s=b.tw+a.l+a.b+a.b,u=b.th+a.m+a.b+a.b,v=this.p(g,s,u);if(g.smartPosition)var y=Rb(s+a.f,u+a.f,v.x,v.y);else y={l:v.x,t:v.y};var A=g[S],B=this.u(A,g[Db],s,u);if(g.smartPosition&&A<4){var C=y.l-v.x,D=y.t-v.y;0==A||2==A?B[0]-=C:C&&i(h,0),1==A||3==A?B[1]-=D:D&&i(h,0)}if(j==x){var E=Vb();y.l=y.l+E[0],y.t=y.t+E[1]}return y.x=B[0],y.y=B[1],y},p:function(b,c,d){var e,g,h,i,k=b[S],l=b[Db];if(k<4)if(1!=b.nodeType)e=g=h=i=0;else if("mouse"==b.relativeTo)e=bb.a,g=bb.b,null==bb.a&&(e=u(b,0)+D(b[w]/2),g=u(b,1)+D(b[m]/2)),h=0,i=0;else{var n=b,o=Xb(b);o[f]&&(o=o[0],(o[w]>=b[w]||o[m]>=b[m])&&(n=o)),e=u(n,0),g=u(n,1),h=n[w],i=n[m]}var p=20,q=c+2*b[M],r=d+2*b[M];switch(k){case 0:e+=D(h/2-q*l),g-=r+p;break;case 2:e+=D(h/2-q*l),g+=i+p;break;case 3:e-=q+p,g+=D(i/2-r*l);break;case 4:e=D((K(0)-q)/2),g=D((K(1)-r)/2);break;case 5:e=g=0;break;case 6:e=K(0)-q-Math.ceil(a.l/2),g=K(1)-r-Math.ceil(a.m/2);break;case 1:default:e+=h+p,g+=D(i/2-r*l)}var s=0,t=0;return j!=x&&(s=j[G]-u(j,0),t=j[H]-u(j,1)),{x:e+s+b.offsetX,y:g+t+b.offsetY}},u:function(b,c,d,e){i(h,b<4);var f=[0,0];switch(b){case 0:f=[d*c,e+a.f-a.b-1];break;case 1:f=[a.b+.5,e*c];break;case 2:f=[d*c,a.b];break;case 3:f=[d+a.f-a.b-1,e*c]}return f}};var zb=function(){if(null==g){if("undefined"!=typeof console&&"function"==typeof console.log){var a=console.log;console.log=function(){a.call(this,++tb,arguments)}}g=new Ib,a&&(console.log=a),Sb()}return k&&k.m&&c[Q].indexOf(ib("kdvh#Uh"))!=-1&&(g.i=function(){}),g},ub=function(a,b,c){c=c||{};var d;for(d in b)a[d]=void 0!==c[d]?c[d]:b[d]},qb=0,N,Eb=function(a){return a||(a=t(O,"div"),a.m=1,a[e][Jb]="none",x[z](a)),"string"==typeof a&&(a=t(W,a)),k=a,a},wb=function(a,b){ub(a,v,b),(vb||V)&&(a.showDelay=1,a[L]=30),a[rb]&&(a[R]=a[rb]),a[R]||(Fb?a[Ub]=function(a){Nb(a)&&g.a(this[L])}:a[mb]=function(){E=A(function(){g.a(a[L])},0,V?400:a[L]+200)}),"mouse"==a.relativeTo&&(a.onmousemove=ec),a.set=1},jb=function(a,b,c){a=Eb(a);var d=0;if("#"==b.charAt(0)){d=b[f]>2&&"#"==b.charAt(1)?2:1;var e=b.substring(d),h=t(W,e);h?2==d&&(b=h[Q]):d=-1}a&&g&&d!=-1?(N=eb(N),!a.set&&wb(a,c),1==d?g.d(a,e,2):g.d(a,b,1)):++qb<40&&(N=A(function(){jb(a,b,c)},0,90))},xb=function(a,b,c,d){a=Eb(a),a&&g?(N=eb(N),!a.set&&wb(a,d),g.e(a,b,c)):++qb<40&&(N=A(function(){xb(a,b,c,d)},0,90))};fb(window,"load",zb);var Ab=function(a){++qb<20&&(g?(ub(v,v,a),i(c,1),g.m(v,0),i(c,0)):A(function(){Ab(a)},0,90))};return{changeOptions:function(a){Ab(a)},pop:function(a,b,c){jb(a,b,c)},ajax:function(a,b,c,d){xb(a,b,c,d)},hide:function(){var a=zb();a.i()}}}(tooltipOptions);
  10938. /*! modernizr 3.2.0 (Custom Build) | MIT *
  10939. * http://modernizr.com/download/?-svg-touchevents !*/
  10940. !function(e,n,t){function o(e){var n=u.className,t=Modernizr._config.classPrefix||"";if(p&&(n=n.baseVal),Modernizr._config.enableJSClass){var o=new RegExp("(^|\\s)"+t+"no-js(\\s|$)");n=n.replace(o,"$1"+t+"js$2")}Modernizr._config.enableClasses&&(n+=" "+t+e.join(" "+t),p?u.className.baseVal=n:u.className=n)}function s(e,n){return typeof e===n}function a(){var e,n,t,o,a,i,r;for(var l in c)if(c.hasOwnProperty(l)){if(e=[],n=c[l],n.name&&(e.push(n.name.toLowerCase()),n.options&&n.options.aliases&&n.options.aliases.length))for(t=0;t<n.options.aliases.length;t++)e.push(n.options.aliases[t].toLowerCase());for(o=s(n.fn,"function")?n.fn():n.fn,a=0;a<e.length;a++)i=e[a],r=i.split("."),1===r.length?Modernizr[r[0]]=o:(!Modernizr[r[0]]||Modernizr[r[0]]instanceof Boolean||(Modernizr[r[0]]=new Boolean(Modernizr[r[0]])),Modernizr[r[0]][r[1]]=o),f.push((o?"":"no-")+r.join("-"))}}function i(){return"function"!=typeof n.createElement?n.createElement(arguments[0]):p?n.createElementNS.call(n,"http://www.w3.org/2000/svg",arguments[0]):n.createElement.apply(n,arguments)}function r(){var e=n.body;return e||(e=i(p?"svg":"body"),e.fake=!0),e}function l(e,t,o,s){var a,l,f,c,d="modernizr",p=i("div"),h=r();if(parseInt(o,10))for(;o--;)f=i("div"),f.id=s?s[o]:d+(o+1),p.appendChild(f);return a=i("style"),a.type="text/css",a.id="s"+d,(h.fake?h:p).appendChild(a),h.appendChild(p),a.styleSheet?a.styleSheet.cssText=e:a.appendChild(n.createTextNode(e)),p.id=d,h.fake&&(h.style.background="",h.style.overflow="hidden",c=u.style.overflow,u.style.overflow="hidden",u.appendChild(h)),l=t(p,e),h.fake?(h.parentNode.removeChild(h),u.style.overflow=c,u.offsetHeight):p.parentNode.removeChild(p),!!l}var f=[],c=[],d={_version:"3.2.0",_config:{classPrefix:"",enableClasses:!0,enableJSClass:!0,usePrefixes:!0},_q:[],on:function(e,n){var t=this;setTimeout(function(){n(t[e])},0)},addTest:function(e,n,t){c.push({name:e,fn:n,options:t})},addAsyncTest:function(e){c.push({name:null,fn:e})}},Modernizr=function(){};Modernizr.prototype=d,Modernizr=new Modernizr,Modernizr.addTest("svg",!!n.createElementNS&&!!n.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect);var u=n.documentElement,p="svg"===u.nodeName.toLowerCase(),h=d._config.usePrefixes?" -webkit- -moz- -o- -ms- ".split(" "):[];d._prefixes=h;var m=d.testStyles=l;Modernizr.addTest("touchevents",function(){var t;if("ontouchstart"in e||e.DocumentTouch&&n instanceof DocumentTouch)t=!0;else{var o=["@media (",h.join("touch-enabled),("),"heartz",")","{#modernizr{top:9px;position:absolute}}"].join("");m(o,function(e){t=9===e.offsetTop})}return t}),a(),o(f),delete d.addTest,delete d.addAsyncTest;for(var v=0;v<Modernizr._q.length;v++)Modernizr._q[v]();e.Modernizr=Modernizr}(window,document);
  10941. !function(e,t){"use strict";function n(){function n(t){var n=t||e.event,o=n.keyCode||n.which;if(-1!==[9,13,32,27].indexOf(o)){for(var a=n.target||n.srcElement,r=-1,i=0;i<x.length;i++)if(a===x[i]){r=i;break}9===o?(a=-1===r?k:n.shiftKey?0===r?x[x.length-1]:x[r-1]:r===x.length-1?x[0]:x[r+1],H(n),l(a)):13===o||32===o?-1===r&&I(k,n):27===o&&u.allowEscapeKey===!0&&I(B,n)}}if(void 0===arguments[0])return e.console.error("sweetAlert expects at least 1 attribute!"),!1;var u=r({},w);switch(typeof arguments[0]){case"string":u.title=arguments[0],u.text=arguments[1]||"",u.type=arguments[2]||"";break;case"object":u.title=arguments[0].title||w.title,u.text=arguments[0].text||w.text,u.html=arguments[0].html||w.html,u.type=arguments[0].type||w.type,u.animation=void 0!==arguments[0].animation?arguments[0].animation:w.animation,u.customClass=arguments[0].customClass||u.customClass,u.allowOutsideClick=void 0!==arguments[0].allowOutsideClick?arguments[0].allowOutsideClick:w.allowOutsideClick,u.allowEscapeKey=void 0!==arguments[0].allowEscapeKey?arguments[0].allowEscapeKey:w.allowEscapeKey,u.showConfirmButton=void 0!==arguments[0].showConfirmButton?arguments[0].showConfirmButton:w.showConfirmButton,u.showCancelButton=void 0!==arguments[0].showCancelButton?arguments[0].showCancelButton:w.showCancelButton,u.closeOnConfirm=void 0!==arguments[0].closeOnConfirm?arguments[0].closeOnConfirm:w.closeOnConfirm,u.closeOnCancel=void 0!==arguments[0].closeOnCancel?arguments[0].closeOnCancel:w.closeOnCancel,u.timer=parseInt(arguments[0].timer)||w.timer,u.width=parseInt(arguments[0].width)||w.width,u.padding=parseInt(arguments[0].padding)||w.padding,u.background=void 0!==arguments[0].background?arguments[0].background:w.background,u.confirmButtonText=arguments[0].confirmButtonText||w.confirmButtonText,u.confirmButtonColor=arguments[0].confirmButtonColor||w.confirmButtonColor,u.confirmButtonClass=arguments[0].confirmButtonClass||u.confirmButtonClass,u.cancelButtonText=arguments[0].cancelButtonText||w.cancelButtonText,u.cancelButtonColor=arguments[0].cancelButtonColor||w.cancelButtonColor,u.cancelButtonClass=arguments[0].cancelButtonClass||u.cancelButtonClass,u.imageUrl=arguments[0].imageUrl||w.imageUrl,u.imageSize=arguments[0].imageSize||w.imageSize,u.callback=arguments[1]||null,e.sweetAlert.callback=e.swal.callback=function(e){"function"==typeof u.callback&&u.callback(e)};break;default:return e.console.error('Unexpected type of argument! Expected "string" or "object", got '+typeof arguments[0]),!1}o(u),c(),i();var g=b();u.timer&&(g.timeout=setTimeout(function(){s(),"function"==typeof u.callback&&u.callback()},u.timer));var y,p=function(t){var n=t||e.event,o=n.target||n.srcElement,r=C(o,"confirm"),l=C(o,"cancel"),i=C(g,"visible");switch(n.type){case"mouseover":case"mouseup":case"focus":r?o.style.backgroundColor=a(u.confirmButtonColor,-.1):l&&(o.style.backgroundColor=a(u.cancelButtonColor,-.1));break;case"mouseout":case"blur":r?o.style.backgroundColor=u.confirmButtonColor:l&&(o.style.backgroundColor=u.cancelButtonColor);break;case"mousedown":r?o.style.backgroundColor=a(u.confirmButtonColor,-.2):l&&(o.style.backgroundColor=a(u.cancelButtonColor,-.2));break;case"click":if(r&&u.callback&&i)u.callback(!0),u.closeOnConfirm&&s();else if(u.callback&&i){var c=String(u.callback).replace(/\s/g,""),m="function("===c.substring(0,9)&&")"!==c.substring(9,10);m&&u.callback(!1),u.closeOnCancel&&s()}else s()}},v=g.querySelectorAll("button");for(y=0;y<v.length;y++)v[y].onclick=p,v[y].onmouseover=p,v[y].onmouseout=p,v[y].onmousedown=p;m=t.onclick,t.onclick=function(t){var n=t||e.event,o=n.target||n.srcElement;o===h()&&u.allowOutsideClick&&s()};var k=g.querySelector("button.confirm"),B=g.querySelector("button.cancel"),x=g.querySelectorAll("button, input:not([type=hidden]), textarea");for(y=0;y<x.length;y++)x[y].addEventListener("focus",p,!0),x[y].addEventListener("blur",p,!0);d=e.onkeydown,e.onkeydown=n,/*k.style.borderLeftColor=u.confirmButtonColor,k.style.borderRightColor=u.confirmButtonColor,*/e.swal.toggleLoading=function(){k.disabled=!k.disabled,B.disabled=!B.disabled},e.swal.enableButtons=function(){k.disabled=!1,B.disabled=!1},e.swal.disableButtons=function(){k.disabled=!0,B.disabled=!0},swal.enableButtons(),e.onfocus=function(){e.setTimeout(function(){void 0!==f&&(f.focus(),f=void 0)},0)}}function o(n){var o=b();o.style.width=n.width+"px",o.style.padding=n.padding+"px",o.style.marginLeft=-n.width/2+"px",o.style.background=n.background;var a=t.getElementsByTagName("head")[0],r=t.createElement("style");r.type="text/css",r.id=p,r.innerHTML="@media screen and (max-width: "+n.width+"px) {.sweet-alert {max-width: 100%;left: 0 !important;margin-left: 0 !important;}}",a.appendChild(r);var l=o.querySelector("h2"),i=o.querySelector("p"),s=o.querySelector("button.cancel"),c=o.querySelector("button.confirm"),u=o.querySelector("hr");if(l.innerHTML=x(n.title).split("\n").join("<br>"),i.innerHTML=x(n.text.split("\n").join("<br>"))||n.html,i.innerHTML&&E(i),n.customClass&&k(o,n.customClass),q(o.querySelectorAll(".icon")),n.type){for(var m=!1,d=0;d<v.length;d++)if(n.type===v[d]){m=!0;break}if(!m)return e.console.error("Unknown alert type: "+n.type),!1;var f=o.querySelector(".icon."+n.type);switch(E(f),n.type){case"success":k(f,"animate"),k(f.querySelector(".tip"),"animate-success-tip"),k(f.querySelector(".long"),"animate-success-long");break;case"error":k(f,"animate-error-icon"),k(f.querySelector(".x-mark"),"animate-x-mark");break;case"warning":k(f,"pulse-warning"),k(f.querySelector(".body"),"pulse-warning-ins"),k(f.querySelector(".dot"),"pulse-warning-ins")}}if(n.imageUrl){var g=o.querySelector(".icon.custom");if(g.style.backgroundImage="url("+n.imageUrl+")",E(g),n.imageSize){var y=n.imageSize.match(/(\d+)x(\d+)/);y?g.setAttribute("style",g.getAttribute("style")+"width:"+y[1]+"px; height:"+y[2]+"px"):e.console.error("Parameter imageSize expects value with format WIDTHxHEIGHT, got "+n.imageSize)}}n.showCancelButton?s.style.display="inline-block":q(s),n.showConfirmButton?c.style.display="inline-block":q(c),n.showConfirmButton||n.showCancelButton||q(u),c.innerHTML=x(n.confirmButtonText),s.innerHTML=x(n.cancelButtonText),c.style.backgroundColor=n.confirmButtonColor,s.style.backgroundColor=n.cancelButtonColor,k(c,n.confirmButtonClass),k(s,n.cancelButtonClass),n.animation===!0?B(o,"no-animation"):k(o,"no-animation")}function a(e,t){e=String(e).replace(/[^0-9a-f]/gi,""),e.length<6&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),t=t||0;for(var n="#",o=0;3>o;o++){var a=parseInt(e.substr(2*o,2),16);a=Math.round(Math.min(Math.max(0,a+a*t),255)).toString(16),n+=("00"+a).substr(a.length)}return n}function r(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}function l(e){e.focus()}function i(){var e=b();L(h(),10),E(e),k(e,"show-sweet-alert"),B(e,"hide-sweet-alert"),u=t.activeElement,setTimeout(function(){k(e,"visible")},500)}function s(){var n=b();M(h(),5),M(n,5),B(n,"showSweetAlert"),k(n,"hideSweetAlert"),B(n,"visible");var o=n.querySelector(".icon.success");B(o,"animate"),B(o.querySelector(".tip"),"animate-success-tip"),B(o.querySelector(".long"),"animate-success-long");var a=n.querySelector(".icon.error");B(a,"animate-error-icon"),B(a.querySelector(".x-mark"),"animate-x-mark");var r=n.querySelector(".icon.warning");B(r,"pulse-warning"),B(r.querySelector(".body"),"pulse-warning-ins"),B(r.querySelector(".dot"),"pulse-warning-ins"),e.onkeydown=d,t.onclick=m,u&&u.focus(),f=void 0,clearTimeout(n.timeout);var l=t.getElementsByTagName("head")[0],i=t.getElementById(p);l.removeChild(i)}function c(){var e=b();e.style.marginTop=O(b())}var u,m,d,f,g=".sweet-alert",y=".sweet-overlay",p="sweet-alert-mediaquery",v=["error","warning","info","success"],w={title:"",text:"",html:"",type:null,animation:!0,allowOutsideClick:!0,allowEscapeKey:!0,showConfirmButton:!0,showCancelButton:!1,closeOnConfirm:!0,closeOnCancel:!0,confirmButtonText:"OK",confirmButtonColor:"#3085d6",confirmButtonClass:null,cancelButtonText:"Cancel",cancelButtonColor:"#aaa",cancelButtonClass:null,imageUrl:null,imageSize:null,timer:null,width:500,padding:20,background:'#F2F2F2'},b=function(){return t.querySelector(g)},h=function(){return t.querySelector(y)},C=function(e,t){return new RegExp(" "+t+" ").test(" "+e.className+" ")},k=function(e,t){t&&!C(e,t)&&(e.className+=" "+t)},B=function(e,t){var n=" "+e.className.replace(/[\t\r\n]/g," ")+" ";if(C(e,t)){for(;n.indexOf(" "+t+" ")>=0;)n=n.replace(" "+t+" "," ");e.className=n.replace(/^\s+|\s+$/g,"")}},x=function(e){var n=t.createElement("div");return n.appendChild(t.createTextNode(e)),n.innerHTML},S=function(e){e.style.opacity="",e.style.display="block"},E=function(e){if(e&&!e.length)return S(e);for(var t=0;t<e.length;++t)S(e[t])},T=function(e){e.style.opacity="",e.style.display="none"},q=function(e){if(e&&!e.length)return T(e);for(var t=0;t<e.length;++t)T(e[t])},O=function(e){e.style.left="-9999px",e.style.display="block";var t,n=e.clientHeight;return t="undefined"!=typeof getComputedStyle?parseInt(getComputedStyle(e).getPropertyValue("padding"),10):parseInt(e.currentStyle.padding),e.style.left="",e.style.display="none","-"+parseInt(n/2+t)+"px"},L=function(e,t){if(+e.style.opacity<1){t=t||16,e.style.opacity=0,e.style.display="block";var n=+new Date,o=function(){e.style.opacity=+e.style.opacity+(new Date-n)/100,n=+new Date,+e.style.opacity<1&&setTimeout(o,t)};o()}e.style.display="block"},M=function(e,t){t=t||16,e.style.opacity=1;var n=+new Date,o=function(){e.style.opacity=+e.style.opacity-(new Date-n)/100,n=+new Date,+e.style.opacity>0?setTimeout(o,t):e.style.display="none"};o()},I=function(n){if("function"==typeof MouseEvent){var o=new MouseEvent("click",{view:e,bubbles:!1,cancelable:!0});n.dispatchEvent(o)}else if(t.createEvent){var a=t.createEvent("MouseEvents");a.initEvent("click",!1,!1),n.dispatchEvent(a)}else t.createEventObject?n.fireEvent("onclick"):"function"==typeof n.onclick&&n.onclick()},H=function(t){"function"==typeof t.stopPropagation?(t.stopPropagation(),t.preventDefault()):e.event&&e.event.hasOwnProperty("cancelBubble")&&(e.event.cancelBubble=!0)};e.sweetAlert=e.swal=function(){var e=arguments;if(null!==b())n.apply(this,e);else var t=setInterval(function(){null!==b()&&(clearInterval(t),n.apply(this,e))},100)},e.sweetAlert.closeModal=e.swal.closeModal=function(){s()},e.swal.init=function(){var e='<div class="sweet-overlay" tabIndex="-1"></div><div class="sweet-alert" tabIndex="-1"><div class="icon error"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div><div class="icon warning"> <span class="body"></span> <span class="dot"></span> </div> <div class="icon info"></div> <div class="icon success"> <span class="line tip"></span> <span class="line long"></span> <div class="placeholder"></div> <div class="fix"></div> </div> <div class="icon custom"></div> <h2>Title</h2><p>Text</p><hr><button class="confirm">OK</button><button class="cancel">Cancel</button></div>',n=t.createElement("div");n.innerHTML=e,t.body.appendChild(n)},e.swal.setDefaults=function(e){if(!e)throw new Error("userParams is required");if("object"!=typeof e)throw new Error("userParams has to be a object");r(w,e)},function(){"complete"===t.readyState||"interactive"===t.readyState&&t.body?swal.init():t.addEventListener?t.addEventListener("DOMContentLoaded",function e(){t.removeEventListener("DOMContentLoaded",e,!1),swal.init()},!1):t.attachEvent&&t.attachEvent("onreadystatechange",function n(){"complete"===t.readyState&&(t.detachEvent("onreadystatechange",n),swal.init())})}()}(window,document);
  10942. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10943. // Initialize Hiberus javascript object
  10944. if (typeof HIB !== 'object') {
  10945. var HIB = {}
  10946. }
  10947. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10948. // General functions
  10949. HIB.general = {
  10950. windowWidth: function () {
  10951. var w = window,
  10952. d = document,
  10953. e = d.documentElement,
  10954. g = d.getElementsByTagName('body')[0];
  10955. return w.innerWidth || e.clientWidth || g.clientWidth;
  10956. }
  10957. };
  10958. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10959. // loader ( inside container )
  10960. HIB.loader = {
  10961. init: function (container, noRemoveAll) {
  10962. if (undefined != container) {
  10963. if (undefined == noRemoveAll || !noRemoveAll) {
  10964. this.remove();
  10965. }
  10966. if ($$(container).length && !$$(container).first().select('#loader').length) {
  10967. $$(container).first()
  10968. .insert('<div id="loader"><img src="' + LOADER_IMG + '" width="100" height="100" /></div>');
  10969. }
  10970. }
  10971. },
  10972. remove: function () {
  10973. if ($('loader')) {
  10974. $$('#loader').each(function (elmt) {
  10975. elmt.remove()
  10976. });
  10977. }
  10978. }
  10979. };
  10980. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10981. // Page loader ( cover all page )
  10982. HIB.pageLoader = {
  10983. init: function () {
  10984. this.remove();
  10985. $$('body').first()
  10986. .insert('<div id="page-loader"><img src="' + LOADER_IMG + '" width="100" height="100" /></div>');
  10987. },
  10988. remove: function () {
  10989. if (null != $('page-loader')) {
  10990. $('page-loader').remove();
  10991. }
  10992. },
  10993. dark: function () {
  10994. if (null != $('page-loader')) {
  10995. $('page-loader').addClassName('dark');
  10996. }
  10997. },
  10998. removeImage: function () {
  10999. if (null != $('page-loader') &&
  11000. $('page-loader').select('img').length) {
  11001. $('page-loader').select('img').first().remove();
  11002. }
  11003. }
  11004. };
  11005. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  11006. //Clear url
  11007. HIB.urlParams = {
  11008. params: new Array('async', 'nofilter', 'compress'),
  11009. removeCustomParams: function (url) {
  11010. for (var i = 0; i < this.params.length; i++) {
  11011. url = url.replace(new RegExp('[\\?&]' + this.params[i] + '=([^&#]*)'), '');
  11012. }
  11013. if (url.indexOf('&') && -1 == url.indexOf('?')) {
  11014. return url.replace('&', '?');
  11015. }
  11016. return url;
  11017. },
  11018. addParams: function (url, params) {
  11019. if (undefined != params && params.length) {
  11020. for (var i = 0; i < params.length; i++) {
  11021. url += '&' + params[i].label + '=' + params[i].value;
  11022. }
  11023. if (url.indexOf('&') && -1 == url.indexOf('?')) {
  11024. return url.replace('&', '?');
  11025. }
  11026. }
  11027. return url;
  11028. }
  11029. };
  11030. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  11031. // Replace img using svg content
  11032. HIB.svg = {
  11033. image: null,
  11034. callback: null,
  11035. init: function(img, callback) {
  11036. if (undefined != callback) {
  11037. this.callback = callback;
  11038. }
  11039. this.image = img;
  11040. this.get(img.getAttribute('src'));
  11041. },
  11042. get: function(url) {
  11043. var xhr = new XMLHttpRequest();
  11044. //xhr.overrideMimeType("application/json");
  11045. xhr.onreadystatechange = function() {
  11046. if (xhr.readyState == 4 && xhr.status == 200) {
  11047. HIB.svg.image.outerHTML = xhr.responseText;
  11048. if (null != HIB.svg.callback) {
  11049. if (typeof HIB.svg.callback == 'function') {
  11050. HIB.svg.callback();
  11051. } else {
  11052. eval(HIB.svg.callback);
  11053. }
  11054. }
  11055. }
  11056. };
  11057. xhr.open("GET", url, true);
  11058. xhr.send();
  11059. }
  11060. };
  11061. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  11062. // Initialize Hiberus javascript object
  11063. if (typeof HIB !== 'object') {
  11064. var HIB = {}
  11065. }
  11066. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  11067. // Menu
  11068. HIB.menu = {
  11069. initializedMobile: null,
  11070. initializedDesktop: null,
  11071. currentFormat: null,
  11072. currentWidth: null,
  11073. eventType: null,
  11074. init: function () {
  11075. this.eventType = ((document.ontouchend !== null) ? 'click' : 'touchend');
  11076. this.setFormat();
  11077. $$('#nav').each(function(elmt) {
  11078. elmt.select('li.level0.first a.level0.has-children').invoke('removeAttribute','href');
  11079. });
  11080. $$('#nav').each(function(elmt) {
  11081. elmt.select('li.level0.first .level1 a.level1.has-children').invoke('removeAttribute','href');
  11082. });
  11083. Event.observe(window, "resize", function () {
  11084. var that = HIB.menu;
  11085. if (that.currentWidth !== HIB.general.windowWidth()) {
  11086. that.currentWidth = HIB.general.windowWidth();
  11087. that.setFormat();
  11088. }
  11089. });
  11090. },
  11091. setFormat: function () {
  11092. this.currentWidth = HIB.general.windowWidth();
  11093. this.currentFormat = this.currentWidth > 990 ? 'desktop' : 'mobile';
  11094. if (this.currentFormat == 'mobile') {
  11095. this.initMobile();
  11096. } else {
  11097. this.hideMobileMenu();
  11098. this.initDesktop();
  11099. }
  11100. },
  11101. initMobile: function () {
  11102. if (null == this.initializedMobile) {
  11103. this.initializedMobile = true;
  11104. if ($$('header .links').length) {
  11105. var links = $$('header .links').first().cloneNode(true);
  11106. $$('.mobile-menu').first().insertBefore(links, $$('.mobile-menu .form-language').first());
  11107. }
  11108. $(document).on(this.eventType, 'header .header-mobile-menu-icon', function () {
  11109. HIB.menu.resetMobileMenu();
  11110. HIB.menu.showMobileMenu();
  11111. });
  11112. $(document).on(this.eventType, '.mobile-menu .menu-mobile-close', function (event, elmt) {
  11113. HIB.menu.goBack(event);
  11114. HIB.menu.hideMobileMenu();
  11115. });
  11116. $(document).on(this.eventType, '.mobile-menu li.parent', function (event, elmt) {
  11117. elmt.addClassName('active');
  11118. $$('.mobile-menu-go-back').first().show();
  11119. $$('.mobile-menu #search_mini_form_mobile').first().hide();
  11120. $$('.mobile-menu .links').first().hide();
  11121. // $$('.mobile-menu .form-language').first().hide();
  11122. elmt.up().select('> li:not(.active)').each(function(e) {
  11123. e.hide();
  11124. });
  11125. if (null != elmt.up('.parent.active')) {
  11126. elmt.up('.parent.active').addClassName('no-show');
  11127. }
  11128. });
  11129. $(document).on(this.eventType, '.mobile-menu .mobile-menu-go-back', function(event, arrow) {
  11130. HIB.menu.goBack(event, arrow);
  11131. });
  11132. $$('nav a').each(function (element) {
  11133. if (element.getAttribute('data-type')) {
  11134. element.on(HIB.menu.eventType, function (event) {
  11135. event.preventDefault();
  11136. window.location.assign(element.getAttribute('href') + '?type=' + element.getAttribute('data-type'));
  11137. })
  11138. }
  11139. })
  11140. }
  11141. },
  11142. resetMobileMenu: function() {
  11143. $$('.mobile-menu li').each(function(elmt) {
  11144. elmt.removeClassName('active').removeClassName('no-show').show();
  11145. });
  11146. $$('.mobile-menu-go-back').first().hide();
  11147. },
  11148. showMobileMenu: function() {
  11149. $$('.mobile-menu').first().style.display = 'block';
  11150. var select = $$('.mobile-menu .custom-select').first();
  11151. if(select !== undefined) {
  11152. HIB.customSelect.setWidth(select);
  11153. }
  11154. $$('.wrapper').first().style.display = 'none';
  11155. },
  11156. hideMobileMenu: function() {
  11157. $$('.mobile-menu').first().style.display = 'none';
  11158. $$('.wrapper').first().style.display = 'block';
  11159. },
  11160. initDesktop: function () {
  11161. if (null == this.initializedDesktop) {
  11162. this.initializedDesktop = true;
  11163. //Add grandparent class 2-lvl menu
  11164. $$('header #nav li.level0.parent').each(function (elmt) {
  11165. if (elmt.select('.parent').length) {
  11166. elmt.addClassName('grandparent');
  11167. elmt.select('ul').each(function (elm) {
  11168. elm.update('<div class="container">' + elm.innerHTML + '</div>');
  11169. });
  11170. }
  11171. elmt.observe('mouseover', function(event) { elmt.addClassName('active'); })
  11172. elmt.observe('mouseout', function(event) { elmt.removeClassName('active'); })
  11173. });
  11174. //Add container li
  11175. $$('header #nav li.level1.parent').each(function (elmt) {
  11176. elmt.select('ul').each(function (elm) {
  11177. elm.update('<div class="container">' + elm.innerHTML + '</div>');
  11178. });
  11179. elmt.observe('mouseover', function(event) { elmt.addClassName('active'); })
  11180. elmt.observe('mouseout', function(event) { elmt.removeClassName('active'); })
  11181. });
  11182. $$('nav a').each(function (element) {
  11183. if (element.getAttribute('data-type')) {
  11184. element.on('click', function (event) {
  11185. event.preventDefault();
  11186. window.location.assign(element.getAttribute('href') + '?type=' + element.getAttribute('data-type'));
  11187. })
  11188. }
  11189. })
  11190. }
  11191. },
  11192. goBack: function (event, elmt) {
  11193. var level = $$('.mobile-menu .parent.active').length;
  11194. if (level) {
  11195. var lastSection = $$('.mobile-menu .parent.active')[level - 1];
  11196. lastSection.removeClassName('active');
  11197. lastSection.up().select('> li').each(function(e) {
  11198. e.show();
  11199. });
  11200. if (level === 1) {
  11201. if (elmt !== undefined) elmt.hide();
  11202. $$('.mobile-menu #search_mini_form_mobile').first().show();
  11203. $$('.mobile-menu .links').first().show();
  11204. $$('.mobile-menu .form-language').first().show();
  11205. }
  11206. if (level > 1) {
  11207. $$('.mobile-menu .parent.active')[level - 2].removeClassName('no-show');
  11208. }
  11209. }
  11210. }
  11211. };
  11212. if (typeof HIB !== 'object') {
  11213. var HIB = {}
  11214. }
  11215. HIB.siteSuggestion = {
  11216. store: null,
  11217. init: function (store) {
  11218. if (store) {
  11219. this.store = store;
  11220. this.renderBlock();
  11221. this.initEvents();
  11222. }
  11223. },
  11224. initEvents: function () {
  11225. $$('.site-suggest-bar .suggest-select-country').first().on('click', function (e) {
  11226. e.preventDefault();
  11227. HIB.siteSuggestion.close();
  11228. location.href = this.readAttribute('data-url');
  11229. });
  11230. $$('.site-suggest-bar .cerrarCountrySuggestArrow').first().on('click', function (e) {
  11231. e.preventDefault();
  11232. HIB.siteSuggestion.close();
  11233. });
  11234. },
  11235. renderBlock: function () {
  11236. var message = this.jrot13(geoMessage);
  11237. var block = $('ajax-for-geo-message');
  11238. block.innerHTML = message;
  11239. block.innerHTML = block.innerText;
  11240. },
  11241. jrot13: function (str) {
  11242. return str.replace(/[a-zA-Z]/g, function (c) {
  11243. return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
  11244. });
  11245. },
  11246. close: function () {
  11247. var d = new Date();
  11248. d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000));
  11249. Mage.Cookies.set('suggested_store', '1', d);
  11250. $$('.site-suggest-bar').first().setStyle({'display' : 'none'});
  11251. }
  11252. };
  11253. if (typeof HIB !== 'object') {
  11254. var HIB = {}
  11255. }
  11256. HIB.languageBox = {
  11257. store: null,
  11258. box_outer: null,
  11259. overlay: null,
  11260. init: function () {
  11261. this.box_outer = $('box-select-language-outer');
  11262. this.overlay = $('box-select-language-invisible-overlay');
  11263. HIB.languageBox.refreshLanguageOptions($('selector-country'));
  11264. this.initEvents();
  11265. },
  11266. initEvents: function () {
  11267. var selectorCountry = $('selector-country');
  11268. selectorCountry.on('change', function (e) {
  11269. e.preventDefault();
  11270. HIB.languageBox.refreshLanguageOptions(selectorCountry);
  11271. });
  11272. $('box-select-go').on('click', function(e) {
  11273. e.preventDefault();
  11274. HIB.languageBox.switchUrl();
  11275. });
  11276. $$('.box-select-language-popup-inner #select-language-button').first().on('click', function(e) {
  11277. e.preventDefault();
  11278. HIB.languageBox.close();
  11279. });
  11280. this.overlay.on('click', function(e) {
  11281. e.preventDefault();
  11282. HIB.languageBox.close();
  11283. });
  11284. },
  11285. open: function(elem) {
  11286. var rectangle = elem.getBoundingClientRect();
  11287. var left = document.documentElement.scrollLeft + rectangle.left - 20;
  11288. var top = document.documentElement.scrollTop + rectangle.top - 14;
  11289. var viewport = document.viewport.getDimensions(); // Gets the viewport as an object literal
  11290. /* Centering popup on mobile screen */
  11291. if (viewport.width <= 480) {
  11292. this.box_outer.setStyle({'left': '50%', 'top': '50%', 'position': 'fixed', 'transform' : 'translate(-50%, -50%)'});
  11293. } else {
  11294. switch (true) {
  11295. case (top > 600) :
  11296. top -= 280;
  11297. if(left <=0 ) { // center horizontal
  11298. left = $$('#select-language-button')[3].getBoundingClientRect().left;
  11299. }
  11300. break;
  11301. case (top > 400) :
  11302. top -= 280;
  11303. if(left <=0 ) { // center horizontal
  11304. left = $$('#select-language-button')[0].getBoundingClientRect().left;
  11305. }
  11306. break;
  11307. default :
  11308. if(left <=0 ) { // center horizontal
  11309. var viewport = document.viewport.getDimensions(); // Gets the viewport as an object literal
  11310. left = (viewport.width - this.box_outer.getWidth()) / 2;
  11311. }
  11312. break;
  11313. }
  11314. this.box_outer.setStyle({'left': left + 'px', 'top': top + 'px'});
  11315. }
  11316. this.overlay.show();
  11317. this.box_outer.show();
  11318. },
  11319. close: function() {
  11320. this.overlay.hide();
  11321. this.box_outer.hide();
  11322. },
  11323. switchUrl: function() {
  11324. window.location.href = $('selector-language').value;
  11325. },
  11326. refreshLanguageOptions: function(selectorCountry) {
  11327. var selectorLanguage = $$('#selector-language').first();
  11328. selectorLanguage.select('option').forEach(function (p1, p2, p3) {
  11329. p1.setStyle({'display' : 'none'});
  11330. });
  11331. var selected = false;
  11332. selectorLanguage.select('option.' + selectorCountry.value).forEach(function (p1, p2, p3) {
  11333. p1.setStyle({'display' : 'block'});
  11334. if(!selected) {
  11335. p1.selected = true;
  11336. selected = true;
  11337. }
  11338. });
  11339. }
  11340. };
  11341. if (typeof HIB !== 'object') {
  11342. var HIB = {}
  11343. }
  11344. HIB.loginPopup = {
  11345. box_outer: null,
  11346. overlay: null,
  11347. submitUrl: null,
  11348. form: null,
  11349. init: function (submitUrl, form) {
  11350. this.box_outer = $('login-popup-outer');
  11351. this.overlay = $('login-popup-overlay');
  11352. this.submitUrl = submitUrl;
  11353. this.form = new VarienForm('login-form', true);
  11354. this.initEvents();
  11355. },
  11356. initEvents: function () {
  11357. this.overlay.on('click', function (e) {
  11358. e.preventDefault();
  11359. HIB.loginPopup.close();
  11360. });
  11361. $$("#login-popup-outer .form button").each(function (button) {
  11362. button.observe('click', function(e) { HIB.loginPopup.ajaxLogin(e) } );
  11363. });
  11364. new Event.observe('login-form', 'submit', function(e){
  11365. e.stop();
  11366. HIB.loginPopup.ajaxLogin(e);
  11367. });
  11368. }
  11369. ,
  11370. open: function() {
  11371. this.overlay.show();
  11372. this.box_outer.show();
  11373. },
  11374. close: function() {
  11375. this.overlay.hide();
  11376. this.box_outer.hide();
  11377. },
  11378. ajaxLogin: function(e) {
  11379. e.preventDefault();
  11380. if (this.form.validator.validate()) {
  11381. new Ajax.Updater(
  11382. { success:'formSuccess' }, this.submitUrl , {
  11383. method:'post',
  11384. parameters: $('login-form').serialize(true),
  11385. onComplete:function(response) {
  11386. if(response.responseText.substring(0,4) == 'http') {
  11387. window.location.href = response.responseText;
  11388. } else {
  11389. swal({
  11390. title: 'Error',
  11391. html: response.responseText,
  11392. type: 'error'
  11393. });
  11394. }
  11395. },
  11396. onFailure: function() {
  11397. swal({
  11398. title: 'Error',
  11399. html: 'An error occured.',
  11400. type: 'error'
  11401. });
  11402. }
  11403. }
  11404. );
  11405. }
  11406. }
  11407. };