app.js.uncompressed.js 270 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. /*
  7. This is an optimized version of Dojo, built for deployment and not for
  8. development. To get sources and documentation, please visit:
  9. http://dojotoolkit.org
  10. */
  11. if(!dojo._hasResource["dojo.window"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  12. dojo._hasResource["dojo.window"] = true;
  13. dojo.provide("dojo.window");
  14. dojo.getObject("window", true, dojo);
  15. dojo.window.getBox = function(){
  16. // summary:
  17. // Returns the dimensions and scroll position of the viewable area of a browser window
  18. var scrollRoot = (dojo.doc.compatMode == 'BackCompat') ? dojo.body() : dojo.doc.documentElement;
  19. // get scroll position
  20. var scroll = dojo._docScroll(); // scrollRoot.scrollTop/Left should work
  21. return { w: scrollRoot.clientWidth, h: scrollRoot.clientHeight, l: scroll.x, t: scroll.y };
  22. };
  23. dojo.window.get = function(doc){
  24. // summary:
  25. // Get window object associated with document doc
  26. // In some IE versions (at least 6.0), document.parentWindow does not return a
  27. // reference to the real window object (maybe a copy), so we must fix it as well
  28. // We use IE specific execScript to attach the real window reference to
  29. // document._parentWindow for later use
  30. if(dojo.isIE && window !== document.parentWindow){
  31. /*
  32. In IE 6, only the variable "window" can be used to connect events (others
  33. may be only copies).
  34. */
  35. doc.parentWindow.execScript("document._parentWindow = window;", "Javascript");
  36. //to prevent memory leak, unset it after use
  37. //another possibility is to add an onUnload handler which seems overkill to me (liucougar)
  38. var win = doc._parentWindow;
  39. doc._parentWindow = null;
  40. return win; // Window
  41. }
  42. return doc.parentWindow || doc.defaultView; // Window
  43. };
  44. dojo.window.scrollIntoView = function(/*DomNode*/ node, /*Object?*/ pos){
  45. // summary:
  46. // Scroll the passed node into view using minimal movement, if it is not already.
  47. // Don't rely on node.scrollIntoView working just because the function is there since
  48. // it forces the node to the page's bottom or top (and left or right in IE) without consideration for the minimal movement.
  49. // WebKit's node.scrollIntoViewIfNeeded doesn't work either for inner scrollbars in right-to-left mode
  50. // and when there's a fixed position scrollable element
  51. node = dojo.byId(node);
  52. var body, doc = node.ownerDocument || dojo.doc;
  53. // has() functions but without has() support
  54. if(!("rtl_adjust_position_for_verticalScrollBar" in dojo.window)){
  55. body = dojo.body();
  56. var scrollable = dojo.create('div', {
  57. style: {overflow:'scroll', overflowX:'visible', direction:'rtl', visibility:'hidden', position:'absolute', left:'0', top:'0', width:'64px', height:'64px'}
  58. }, body, "last"),
  59. div = dojo.create('div', {
  60. style: {overflow:'hidden', direction:'ltr'}
  61. }, scrollable, "last");
  62. dojo.window.rtl_adjust_position_for_verticalScrollBar = dojo.position(div).x != 0;
  63. scrollable.removeChild(div);
  64. body.removeChild(scrollable);
  65. }
  66. if(!("position_fixed_support" in dojo.window)){
  67. // IE6, IE7+quirks, and some older mobile browsers don't support position:fixed
  68. body = dojo.body();
  69. var outer = dojo.create('span', {
  70. style: {visibility:'hidden', position:'fixed', left:'1px', top:'1px'}
  71. }, body, "last"),
  72. inner = dojo.create('span', {
  73. style: {position:'fixed', left:'0', top:'0'}
  74. }, outer, "last");
  75. dojo.window.position_fixed_support = dojo.position(inner).x != dojo.position(outer).x;
  76. outer.removeChild(inner);
  77. body.removeChild(outer);
  78. }
  79. try{ // catch unexpected/unrecreatable errors (#7808) since we can recover using a semi-acceptable native method
  80. body = doc.body || doc.getElementsByTagName("body")[0];
  81. var html = doc.documentElement || body.parentNode,
  82. isIE = dojo.isIE,
  83. isWK = dojo.isWebKit;
  84. // if an untested browser, then use the native method
  85. if(node == body || node == html){ return; }
  86. if(!(dojo.isMozilla || isIE || isWK || dojo.isOpera) && ("scrollIntoView" in node)){
  87. node.scrollIntoView(false); // short-circuit to native if possible
  88. return;
  89. }
  90. var backCompat = doc.compatMode == 'BackCompat',
  91. rootWidth = Math.min(body.clientWidth || html.clientWidth, html.clientWidth || body.clientWidth),
  92. rootHeight = Math.min(body.clientHeight || html.clientHeight, html.clientHeight || body.clientHeight),
  93. scrollRoot = (isWK || backCompat) ? body : html,
  94. nodePos = pos || dojo.position(node),
  95. el = node.parentNode,
  96. isFixed = function(el){
  97. return (isIE <= 6 || (isIE == 7 && backCompat))
  98. ? false
  99. : (dojo.window.position_fixed_support && (dojo.style(el, 'position').toLowerCase() == "fixed"));
  100. };
  101. if(isFixed(node)){ return; } // nothing to do
  102. while(el){
  103. if(el == body){ el = scrollRoot; }
  104. var elPos = dojo.position(el),
  105. fixedPos = isFixed(el),
  106. rtl = dojo.getComputedStyle(el).direction.toLowerCase() == "rtl";
  107. if(el == scrollRoot){
  108. elPos.w = rootWidth; elPos.h = rootHeight;
  109. if(scrollRoot == html && isIE && rtl){ elPos.x += scrollRoot.offsetWidth-elPos.w; } // IE workaround where scrollbar causes negative x
  110. if(elPos.x < 0 || !isIE || isIE >= 9){ elPos.x = 0; } // older IE can have values > 0
  111. if(elPos.y < 0 || !isIE || isIE >= 9){ elPos.y = 0; }
  112. }else{
  113. var pb = dojo._getPadBorderExtents(el);
  114. elPos.w -= pb.w; elPos.h -= pb.h; elPos.x += pb.l; elPos.y += pb.t;
  115. var clientSize = el.clientWidth,
  116. scrollBarSize = elPos.w - clientSize;
  117. if(clientSize > 0 && scrollBarSize > 0){
  118. if(rtl && dojo.window.rtl_adjust_position_for_verticalScrollBar){
  119. elPos.x += scrollBarSize;
  120. }
  121. elPos.w = clientSize;
  122. }
  123. clientSize = el.clientHeight;
  124. scrollBarSize = elPos.h - clientSize;
  125. if(clientSize > 0 && scrollBarSize > 0){
  126. elPos.h = clientSize;
  127. }
  128. }
  129. if(fixedPos){ // bounded by viewport, not parents
  130. if(elPos.y < 0){
  131. elPos.h += elPos.y; elPos.y = 0;
  132. }
  133. if(elPos.x < 0){
  134. elPos.w += elPos.x; elPos.x = 0;
  135. }
  136. if(elPos.y + elPos.h > rootHeight){
  137. elPos.h = rootHeight - elPos.y;
  138. }
  139. if(elPos.x + elPos.w > rootWidth){
  140. elPos.w = rootWidth - elPos.x;
  141. }
  142. }
  143. // calculate overflow in all 4 directions
  144. var l = nodePos.x - elPos.x, // beyond left: < 0
  145. // t = nodePos.y - Math.max(elPos.y, 0), // beyond top: < 0
  146. t = nodePos.y - elPos.y, // beyond top: < 0
  147. r = l + nodePos.w - elPos.w, // beyond right: > 0
  148. bot = t + nodePos.h - elPos.h; // beyond bottom: > 0
  149. var s, old;
  150. if(r * l > 0 && (!!el.scrollLeft || el == scrollRoot || el.scrollWidth > el.offsetHeight)){
  151. s = Math[l < 0? "max" : "min"](l, r);
  152. if(rtl && ((isIE == 8 && !backCompat) || isIE >= 9)){ s = -s; }
  153. old = el.scrollLeft;
  154. el.scrollLeft += s;
  155. s = el.scrollLeft - old;
  156. nodePos.x -= s;
  157. }
  158. if(bot * t > 0 && (!!el.scrollTop || el == scrollRoot || el.scrollHeight > el.offsetHeight)){
  159. s = Math.ceil(Math[t < 0? "max" : "min"](t, bot));
  160. old = el.scrollTop;
  161. el.scrollTop += s;
  162. s = el.scrollTop - old;
  163. nodePos.y -= s;
  164. }
  165. el = (el != scrollRoot) && !fixedPos && el.parentNode;
  166. }
  167. }catch(error){
  168. console.error('scrollIntoView: ' + error);
  169. node.scrollIntoView(false);
  170. }
  171. };
  172. }
  173. if(!dojo._hasResource["dijit._base.manager"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  174. dojo._hasResource["dijit._base.manager"] = true;
  175. dojo.provide("dijit._base.manager");
  176. dojo.declare("dijit.WidgetSet", null, {
  177. // summary:
  178. // A set of widgets indexed by id. A default instance of this class is
  179. // available as `dijit.registry`
  180. //
  181. // example:
  182. // Create a small list of widgets:
  183. // | var ws = new dijit.WidgetSet();
  184. // | ws.add(dijit.byId("one"));
  185. // | ws.add(dijit.byId("two"));
  186. // | // destroy both:
  187. // | ws.forEach(function(w){ w.destroy(); });
  188. //
  189. // example:
  190. // Using dijit.registry:
  191. // | dijit.registry.forEach(function(w){ /* do something */ });
  192. constructor: function(){
  193. this._hash = {};
  194. this.length = 0;
  195. },
  196. add: function(/*dijit._Widget*/ widget){
  197. // summary:
  198. // Add a widget to this list. If a duplicate ID is detected, a error is thrown.
  199. //
  200. // widget: dijit._Widget
  201. // Any dijit._Widget subclass.
  202. if(this._hash[widget.id]){
  203. throw new Error("Tried to register widget with id==" + widget.id + " but that id is already registered");
  204. }
  205. this._hash[widget.id] = widget;
  206. this.length++;
  207. },
  208. remove: function(/*String*/ id){
  209. // summary:
  210. // Remove a widget from this WidgetSet. Does not destroy the widget; simply
  211. // removes the reference.
  212. if(this._hash[id]){
  213. delete this._hash[id];
  214. this.length--;
  215. }
  216. },
  217. forEach: function(/*Function*/ func, /* Object? */thisObj){
  218. // summary:
  219. // Call specified function for each widget in this set.
  220. //
  221. // func:
  222. // A callback function to run for each item. Is passed the widget, the index
  223. // in the iteration, and the full hash, similar to `dojo.forEach`.
  224. //
  225. // thisObj:
  226. // An optional scope parameter
  227. //
  228. // example:
  229. // Using the default `dijit.registry` instance:
  230. // | dijit.registry.forEach(function(widget){
  231. // | console.log(widget.declaredClass);
  232. // | });
  233. //
  234. // returns:
  235. // Returns self, in order to allow for further chaining.
  236. thisObj = thisObj || dojo.global;
  237. var i = 0, id;
  238. for(id in this._hash){
  239. func.call(thisObj, this._hash[id], i++, this._hash);
  240. }
  241. return this; // dijit.WidgetSet
  242. },
  243. filter: function(/*Function*/ filter, /* Object? */thisObj){
  244. // summary:
  245. // Filter down this WidgetSet to a smaller new WidgetSet
  246. // Works the same as `dojo.filter` and `dojo.NodeList.filter`
  247. //
  248. // filter:
  249. // Callback function to test truthiness. Is passed the widget
  250. // reference and the pseudo-index in the object.
  251. //
  252. // thisObj: Object?
  253. // Option scope to use for the filter function.
  254. //
  255. // example:
  256. // Arbitrary: select the odd widgets in this list
  257. // | dijit.registry.filter(function(w, i){
  258. // | return i % 2 == 0;
  259. // | }).forEach(function(w){ /* odd ones */ });
  260. thisObj = thisObj || dojo.global;
  261. var res = new dijit.WidgetSet(), i = 0, id;
  262. for(id in this._hash){
  263. var w = this._hash[id];
  264. if(filter.call(thisObj, w, i++, this._hash)){
  265. res.add(w);
  266. }
  267. }
  268. return res; // dijit.WidgetSet
  269. },
  270. byId: function(/*String*/ id){
  271. // summary:
  272. // Find a widget in this list by it's id.
  273. // example:
  274. // Test if an id is in a particular WidgetSet
  275. // | var ws = new dijit.WidgetSet();
  276. // | ws.add(dijit.byId("bar"));
  277. // | var t = ws.byId("bar") // returns a widget
  278. // | var x = ws.byId("foo"); // returns undefined
  279. return this._hash[id]; // dijit._Widget
  280. },
  281. byClass: function(/*String*/ cls){
  282. // summary:
  283. // Reduce this widgetset to a new WidgetSet of a particular `declaredClass`
  284. //
  285. // cls: String
  286. // The Class to scan for. Full dot-notated string.
  287. //
  288. // example:
  289. // Find all `dijit.TitlePane`s in a page:
  290. // | dijit.registry.byClass("dijit.TitlePane").forEach(function(tp){ tp.close(); });
  291. var res = new dijit.WidgetSet(), id, widget;
  292. for(id in this._hash){
  293. widget = this._hash[id];
  294. if(widget.declaredClass == cls){
  295. res.add(widget);
  296. }
  297. }
  298. return res; // dijit.WidgetSet
  299. },
  300. toArray: function(){
  301. // summary:
  302. // Convert this WidgetSet into a true Array
  303. //
  304. // example:
  305. // Work with the widget .domNodes in a real Array
  306. // | dojo.map(dijit.registry.toArray(), function(w){ return w.domNode; });
  307. var ar = [];
  308. for(var id in this._hash){
  309. ar.push(this._hash[id]);
  310. }
  311. return ar; // dijit._Widget[]
  312. },
  313. map: function(/* Function */func, /* Object? */thisObj){
  314. // summary:
  315. // Create a new Array from this WidgetSet, following the same rules as `dojo.map`
  316. // example:
  317. // | var nodes = dijit.registry.map(function(w){ return w.domNode; });
  318. //
  319. // returns:
  320. // A new array of the returned values.
  321. return dojo.map(this.toArray(), func, thisObj); // Array
  322. },
  323. every: function(func, thisObj){
  324. // summary:
  325. // A synthetic clone of `dojo.every` acting explicitly on this WidgetSet
  326. //
  327. // func: Function
  328. // A callback function run for every widget in this list. Exits loop
  329. // when the first false return is encountered.
  330. //
  331. // thisObj: Object?
  332. // Optional scope parameter to use for the callback
  333. thisObj = thisObj || dojo.global;
  334. var x = 0, i;
  335. for(i in this._hash){
  336. if(!func.call(thisObj, this._hash[i], x++, this._hash)){
  337. return false; // Boolean
  338. }
  339. }
  340. return true; // Boolean
  341. },
  342. some: function(func, thisObj){
  343. // summary:
  344. // A synthetic clone of `dojo.some` acting explictly on this WidgetSet
  345. //
  346. // func: Function
  347. // A callback function run for every widget in this list. Exits loop
  348. // when the first true return is encountered.
  349. //
  350. // thisObj: Object?
  351. // Optional scope parameter to use for the callback
  352. thisObj = thisObj || dojo.global;
  353. var x = 0, i;
  354. for(i in this._hash){
  355. if(func.call(thisObj, this._hash[i], x++, this._hash)){
  356. return true; // Boolean
  357. }
  358. }
  359. return false; // Boolean
  360. }
  361. });
  362. (function(){
  363. /*=====
  364. dijit.registry = {
  365. // summary:
  366. // A list of widgets on a page.
  367. // description:
  368. // Is an instance of `dijit.WidgetSet`
  369. };
  370. =====*/
  371. dijit.registry = new dijit.WidgetSet();
  372. var hash = dijit.registry._hash,
  373. attr = dojo.attr,
  374. hasAttr = dojo.hasAttr,
  375. style = dojo.style;
  376. dijit.byId = function(/*String|dijit._Widget*/ id){
  377. // summary:
  378. // Returns a widget by it's id, or if passed a widget, no-op (like dojo.byId())
  379. return typeof id == "string" ? hash[id] : id; // dijit._Widget
  380. };
  381. var _widgetTypeCtr = {};
  382. dijit.getUniqueId = function(/*String*/widgetType){
  383. // summary:
  384. // Generates a unique id for a given widgetType
  385. var id;
  386. do{
  387. id = widgetType + "_" +
  388. (widgetType in _widgetTypeCtr ?
  389. ++_widgetTypeCtr[widgetType] : _widgetTypeCtr[widgetType] = 0);
  390. }while(hash[id]);
  391. return dijit._scopeName == "dijit" ? id : dijit._scopeName + "_" + id; // String
  392. };
  393. dijit.findWidgets = function(/*DomNode*/ root){
  394. // summary:
  395. // Search subtree under root returning widgets found.
  396. // Doesn't search for nested widgets (ie, widgets inside other widgets).
  397. var outAry = [];
  398. function getChildrenHelper(root){
  399. for(var node = root.firstChild; node; node = node.nextSibling){
  400. if(node.nodeType == 1){
  401. var widgetId = node.getAttribute("widgetId");
  402. if(widgetId){
  403. var widget = hash[widgetId];
  404. if(widget){ // may be null on page w/multiple dojo's loaded
  405. outAry.push(widget);
  406. }
  407. }else{
  408. getChildrenHelper(node);
  409. }
  410. }
  411. }
  412. }
  413. getChildrenHelper(root);
  414. return outAry;
  415. };
  416. dijit._destroyAll = function(){
  417. // summary:
  418. // Code to destroy all widgets and do other cleanup on page unload
  419. // Clean up focus manager lingering references to widgets and nodes
  420. dijit._curFocus = null;
  421. dijit._prevFocus = null;
  422. dijit._activeStack = [];
  423. // Destroy all the widgets, top down
  424. dojo.forEach(dijit.findWidgets(dojo.body()), function(widget){
  425. // Avoid double destroy of widgets like Menu that are attached to <body>
  426. // even though they are logically children of other widgets.
  427. if(!widget._destroyed){
  428. if(widget.destroyRecursive){
  429. widget.destroyRecursive();
  430. }else if(widget.destroy){
  431. widget.destroy();
  432. }
  433. }
  434. });
  435. };
  436. if(dojo.isIE){
  437. // Only run _destroyAll() for IE because we think it's only necessary in that case,
  438. // and because it causes problems on FF. See bug #3531 for details.
  439. dojo.addOnWindowUnload(function(){
  440. dijit._destroyAll();
  441. });
  442. }
  443. dijit.byNode = function(/*DOMNode*/ node){
  444. // summary:
  445. // Returns the widget corresponding to the given DOMNode
  446. return hash[node.getAttribute("widgetId")]; // dijit._Widget
  447. };
  448. dijit.getEnclosingWidget = function(/*DOMNode*/ node){
  449. // summary:
  450. // Returns the widget whose DOM tree contains the specified DOMNode, or null if
  451. // the node is not contained within the DOM tree of any widget
  452. while(node){
  453. var id = node.getAttribute && node.getAttribute("widgetId");
  454. if(id){
  455. return hash[id];
  456. }
  457. node = node.parentNode;
  458. }
  459. return null;
  460. };
  461. var shown = (dijit._isElementShown = function(/*Element*/ elem){
  462. var s = style(elem);
  463. return (s.visibility != "hidden")
  464. && (s.visibility != "collapsed")
  465. && (s.display != "none")
  466. && (attr(elem, "type") != "hidden");
  467. });
  468. dijit.hasDefaultTabStop = function(/*Element*/ elem){
  469. // summary:
  470. // Tests if element is tab-navigable even without an explicit tabIndex setting
  471. // No explicit tabIndex setting, need to investigate node type
  472. switch(elem.nodeName.toLowerCase()){
  473. case "a":
  474. // An <a> w/out a tabindex is only navigable if it has an href
  475. return hasAttr(elem, "href");
  476. case "area":
  477. case "button":
  478. case "input":
  479. case "object":
  480. case "select":
  481. case "textarea":
  482. // These are navigable by default
  483. return true;
  484. case "iframe":
  485. // If it's an editor <iframe> then it's tab navigable.
  486. var body;
  487. try{
  488. // non-IE
  489. var contentDocument = elem.contentDocument;
  490. if("designMode" in contentDocument && contentDocument.designMode == "on"){
  491. return true;
  492. }
  493. body = contentDocument.body;
  494. }catch(e1){
  495. // contentWindow.document isn't accessible within IE7/8
  496. // if the iframe.src points to a foreign url and this
  497. // page contains an element, that could get focus
  498. try{
  499. body = elem.contentWindow.document.body;
  500. }catch(e2){
  501. return false;
  502. }
  503. }
  504. return body.contentEditable == 'true' || (body.firstChild && body.firstChild.contentEditable == 'true');
  505. default:
  506. return elem.contentEditable == 'true';
  507. }
  508. };
  509. var isTabNavigable = (dijit.isTabNavigable = function(/*Element*/ elem){
  510. // summary:
  511. // Tests if an element is tab-navigable
  512. // TODO: convert (and rename method) to return effective tabIndex; will save time in _getTabNavigable()
  513. if(attr(elem, "disabled")){
  514. return false;
  515. }else if(hasAttr(elem, "tabIndex")){
  516. // Explicit tab index setting
  517. return attr(elem, "tabIndex") >= 0; // boolean
  518. }else{
  519. // No explicit tabIndex setting, so depends on node type
  520. return dijit.hasDefaultTabStop(elem);
  521. }
  522. });
  523. dijit._getTabNavigable = function(/*DOMNode*/ root){
  524. // summary:
  525. // Finds descendants of the specified root node.
  526. //
  527. // description:
  528. // Finds the following descendants of the specified root node:
  529. // * the first tab-navigable element in document order
  530. // without a tabIndex or with tabIndex="0"
  531. // * the last tab-navigable element in document order
  532. // without a tabIndex or with tabIndex="0"
  533. // * the first element in document order with the lowest
  534. // positive tabIndex value
  535. // * the last element in document order with the highest
  536. // positive tabIndex value
  537. var first, last, lowest, lowestTabindex, highest, highestTabindex, radioSelected = {};
  538. function radioName(node) {
  539. // If this element is part of a radio button group, return the name for that group.
  540. return node && node.tagName.toLowerCase() == "input" &&
  541. node.type && node.type.toLowerCase() == "radio" &&
  542. node.name && node.name.toLowerCase();
  543. }
  544. var walkTree = function(/*DOMNode*/parent){
  545. dojo.query("> *", parent).forEach(function(child){
  546. // Skip hidden elements, and also non-HTML elements (those in custom namespaces) in IE,
  547. // since show() invokes getAttribute("type"), which crash on VML nodes in IE.
  548. if((dojo.isIE <= 9 && child.scopeName !== "HTML") || !shown(child)){
  549. return;
  550. }
  551. if(isTabNavigable(child)){
  552. var tabindex = attr(child, "tabIndex");
  553. if(!hasAttr(child, "tabIndex") || tabindex == 0){
  554. if(!first){ first = child; }
  555. last = child;
  556. }else if(tabindex > 0){
  557. if(!lowest || tabindex < lowestTabindex){
  558. lowestTabindex = tabindex;
  559. lowest = child;
  560. }
  561. if(!highest || tabindex >= highestTabindex){
  562. highestTabindex = tabindex;
  563. highest = child;
  564. }
  565. }
  566. var rn = radioName(child);
  567. if(dojo.attr(child, "checked") && rn) {
  568. radioSelected[rn] = child;
  569. }
  570. }
  571. if(child.nodeName.toUpperCase() != 'SELECT'){
  572. walkTree(child);
  573. }
  574. });
  575. };
  576. if(shown(root)){ walkTree(root) }
  577. function rs(node) {
  578. // substitute checked radio button for unchecked one, if there is a checked one with the same name.
  579. return radioSelected[radioName(node)] || node;
  580. }
  581. return { first: rs(first), last: rs(last), lowest: rs(lowest), highest: rs(highest) };
  582. }
  583. dijit.getFirstInTabbingOrder = function(/*String|DOMNode*/ root){
  584. // summary:
  585. // Finds the descendant of the specified root node
  586. // that is first in the tabbing order
  587. var elems = dijit._getTabNavigable(dojo.byId(root));
  588. return elems.lowest ? elems.lowest : elems.first; // DomNode
  589. };
  590. dijit.getLastInTabbingOrder = function(/*String|DOMNode*/ root){
  591. // summary:
  592. // Finds the descendant of the specified root node
  593. // that is last in the tabbing order
  594. var elems = dijit._getTabNavigable(dojo.byId(root));
  595. return elems.last ? elems.last : elems.highest; // DomNode
  596. };
  597. /*=====
  598. dojo.mixin(dijit, {
  599. // defaultDuration: Integer
  600. // The default animation speed (in ms) to use for all Dijit
  601. // transitional animations, unless otherwise specified
  602. // on a per-instance basis. Defaults to 200, overrided by
  603. // `djConfig.defaultDuration`
  604. defaultDuration: 200
  605. });
  606. =====*/
  607. dijit.defaultDuration = dojo.config["defaultDuration"] || 200;
  608. })();
  609. }
  610. if(!dojo._hasResource["dijit._base.focus"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  611. dojo._hasResource["dijit._base.focus"] = true;
  612. dojo.provide("dijit._base.focus");
  613. // summary:
  614. // These functions are used to query or set the focus and selection.
  615. //
  616. // Also, they trace when widgets become activated/deactivated,
  617. // so that the widget can fire _onFocus/_onBlur events.
  618. // "Active" here means something similar to "focused", but
  619. // "focus" isn't quite the right word because we keep track of
  620. // a whole stack of "active" widgets. Example: ComboButton --> Menu -->
  621. // MenuItem. The onBlur event for ComboButton doesn't fire due to focusing
  622. // on the Menu or a MenuItem, since they are considered part of the
  623. // ComboButton widget. It only happens when focus is shifted
  624. // somewhere completely different.
  625. dojo.mixin(dijit, {
  626. // _curFocus: DomNode
  627. // Currently focused item on screen
  628. _curFocus: null,
  629. // _prevFocus: DomNode
  630. // Previously focused item on screen
  631. _prevFocus: null,
  632. isCollapsed: function(){
  633. // summary:
  634. // Returns true if there is no text selected
  635. return dijit.getBookmark().isCollapsed;
  636. },
  637. getBookmark: function(){
  638. // summary:
  639. // Retrieves a bookmark that can be used with moveToBookmark to return to the same range
  640. var bm, rg, tg, sel = dojo.doc.selection, cf = dijit._curFocus;
  641. if(dojo.global.getSelection){
  642. //W3C Range API for selections.
  643. sel = dojo.global.getSelection();
  644. if(sel){
  645. if(sel.isCollapsed){
  646. tg = cf? cf.tagName : "";
  647. if(tg){
  648. //Create a fake rangelike item to restore selections.
  649. tg = tg.toLowerCase();
  650. if(tg == "textarea" ||
  651. (tg == "input" && (!cf.type || cf.type.toLowerCase() == "text"))){
  652. sel = {
  653. start: cf.selectionStart,
  654. end: cf.selectionEnd,
  655. node: cf,
  656. pRange: true
  657. };
  658. return {isCollapsed: (sel.end <= sel.start), mark: sel}; //Object.
  659. }
  660. }
  661. bm = {isCollapsed:true};
  662. if(sel.rangeCount){
  663. bm.mark = sel.getRangeAt(0).cloneRange();
  664. }
  665. }else{
  666. rg = sel.getRangeAt(0);
  667. bm = {isCollapsed: false, mark: rg.cloneRange()};
  668. }
  669. }
  670. }else if(sel){
  671. // If the current focus was a input of some sort and no selection, don't bother saving
  672. // a native bookmark. This is because it causes issues with dialog/page selection restore.
  673. // So, we need to create psuedo bookmarks to work with.
  674. tg = cf ? cf.tagName : "";
  675. tg = tg.toLowerCase();
  676. if(cf && tg && (tg == "button" || tg == "textarea" || tg == "input")){
  677. if(sel.type && sel.type.toLowerCase() == "none"){
  678. return {
  679. isCollapsed: true,
  680. mark: null
  681. }
  682. }else{
  683. rg = sel.createRange();
  684. return {
  685. isCollapsed: rg.text && rg.text.length?false:true,
  686. mark: {
  687. range: rg,
  688. pRange: true
  689. }
  690. };
  691. }
  692. }
  693. bm = {};
  694. //'IE' way for selections.
  695. try{
  696. // createRange() throws exception when dojo in iframe
  697. //and nothing selected, see #9632
  698. rg = sel.createRange();
  699. bm.isCollapsed = !(sel.type == 'Text' ? rg.htmlText.length : rg.length);
  700. }catch(e){
  701. bm.isCollapsed = true;
  702. return bm;
  703. }
  704. if(sel.type.toUpperCase() == 'CONTROL'){
  705. if(rg.length){
  706. bm.mark=[];
  707. var i=0,len=rg.length;
  708. while(i<len){
  709. bm.mark.push(rg.item(i++));
  710. }
  711. }else{
  712. bm.isCollapsed = true;
  713. bm.mark = null;
  714. }
  715. }else{
  716. bm.mark = rg.getBookmark();
  717. }
  718. }else{
  719. console.warn("No idea how to store the current selection for this browser!");
  720. }
  721. return bm; // Object
  722. },
  723. moveToBookmark: function(/*Object*/bookmark){
  724. // summary:
  725. // Moves current selection to a bookmark
  726. // bookmark:
  727. // This should be a returned object from dijit.getBookmark()
  728. var _doc = dojo.doc,
  729. mark = bookmark.mark;
  730. if(mark){
  731. if(dojo.global.getSelection){
  732. //W3C Rangi API (FF, WebKit, Opera, etc)
  733. var sel = dojo.global.getSelection();
  734. if(sel && sel.removeAllRanges){
  735. if(mark.pRange){
  736. var r = mark;
  737. var n = r.node;
  738. n.selectionStart = r.start;
  739. n.selectionEnd = r.end;
  740. }else{
  741. sel.removeAllRanges();
  742. sel.addRange(mark);
  743. }
  744. }else{
  745. console.warn("No idea how to restore selection for this browser!");
  746. }
  747. }else if(_doc.selection && mark){
  748. //'IE' way.
  749. var rg;
  750. if(mark.pRange){
  751. rg = mark.range;
  752. }else if(dojo.isArray(mark)){
  753. rg = _doc.body.createControlRange();
  754. //rg.addElement does not have call/apply method, so can not call it directly
  755. //rg is not available in "range.addElement(item)", so can't use that either
  756. dojo.forEach(mark, function(n){
  757. rg.addElement(n);
  758. });
  759. }else{
  760. rg = _doc.body.createTextRange();
  761. rg.moveToBookmark(mark);
  762. }
  763. rg.select();
  764. }
  765. }
  766. },
  767. getFocus: function(/*Widget?*/ menu, /*Window?*/ openedForWindow){
  768. // summary:
  769. // Called as getFocus(), this returns an Object showing the current focus
  770. // and selected text.
  771. //
  772. // Called as getFocus(widget), where widget is a (widget representing) a button
  773. // that was just pressed, it returns where focus was before that button
  774. // was pressed. (Pressing the button may have either shifted focus to the button,
  775. // or removed focus altogether.) In this case the selected text is not returned,
  776. // since it can't be accurately determined.
  777. //
  778. // menu: dijit._Widget or {domNode: DomNode} structure
  779. // The button that was just pressed. If focus has disappeared or moved
  780. // to this button, returns the previous focus. In this case the bookmark
  781. // information is already lost, and null is returned.
  782. //
  783. // openedForWindow:
  784. // iframe in which menu was opened
  785. //
  786. // returns:
  787. // A handle to restore focus/selection, to be passed to `dijit.focus`
  788. var node = !dijit._curFocus || (menu && dojo.isDescendant(dijit._curFocus, menu.domNode)) ? dijit._prevFocus : dijit._curFocus;
  789. return {
  790. node: node,
  791. bookmark: (node == dijit._curFocus) && dojo.withGlobal(openedForWindow || dojo.global, dijit.getBookmark),
  792. openedForWindow: openedForWindow
  793. }; // Object
  794. },
  795. focus: function(/*Object || DomNode */ handle){
  796. // summary:
  797. // Sets the focused node and the selection according to argument.
  798. // To set focus to an iframe's content, pass in the iframe itself.
  799. // handle:
  800. // object returned by get(), or a DomNode
  801. if(!handle){ return; }
  802. var node = "node" in handle ? handle.node : handle, // because handle is either DomNode or a composite object
  803. bookmark = handle.bookmark,
  804. openedForWindow = handle.openedForWindow,
  805. collapsed = bookmark ? bookmark.isCollapsed : false;
  806. // Set the focus
  807. // Note that for iframe's we need to use the <iframe> to follow the parentNode chain,
  808. // but we need to set focus to iframe.contentWindow
  809. if(node){
  810. var focusNode = (node.tagName.toLowerCase() == "iframe") ? node.contentWindow : node;
  811. if(focusNode && focusNode.focus){
  812. try{
  813. // Gecko throws sometimes if setting focus is impossible,
  814. // node not displayed or something like that
  815. focusNode.focus();
  816. }catch(e){/*quiet*/}
  817. }
  818. dijit._onFocusNode(node);
  819. }
  820. // set the selection
  821. // do not need to restore if current selection is not empty
  822. // (use keyboard to select a menu item) or if previous selection was collapsed
  823. // as it may cause focus shift (Esp in IE).
  824. if(bookmark && dojo.withGlobal(openedForWindow || dojo.global, dijit.isCollapsed) && !collapsed){
  825. if(openedForWindow){
  826. openedForWindow.focus();
  827. }
  828. try{
  829. dojo.withGlobal(openedForWindow || dojo.global, dijit.moveToBookmark, null, [bookmark]);
  830. }catch(e2){
  831. /*squelch IE internal error, see http://trac.dojotoolkit.org/ticket/1984 */
  832. }
  833. }
  834. },
  835. // _activeStack: dijit._Widget[]
  836. // List of currently active widgets (focused widget and it's ancestors)
  837. _activeStack: [],
  838. registerIframe: function(/*DomNode*/ iframe){
  839. // summary:
  840. // Registers listeners on the specified iframe so that any click
  841. // or focus event on that iframe (or anything in it) is reported
  842. // as a focus/click event on the <iframe> itself.
  843. // description:
  844. // Currently only used by editor.
  845. // returns:
  846. // Handle to pass to unregisterIframe()
  847. return dijit.registerWin(iframe.contentWindow, iframe);
  848. },
  849. unregisterIframe: function(/*Object*/ handle){
  850. // summary:
  851. // Unregisters listeners on the specified iframe created by registerIframe.
  852. // After calling be sure to delete or null out the handle itself.
  853. // handle:
  854. // Handle returned by registerIframe()
  855. dijit.unregisterWin(handle);
  856. },
  857. registerWin: function(/*Window?*/targetWindow, /*DomNode?*/ effectiveNode){
  858. // summary:
  859. // Registers listeners on the specified window (either the main
  860. // window or an iframe's window) to detect when the user has clicked somewhere
  861. // or focused somewhere.
  862. // description:
  863. // Users should call registerIframe() instead of this method.
  864. // targetWindow:
  865. // If specified this is the window associated with the iframe,
  866. // i.e. iframe.contentWindow.
  867. // effectiveNode:
  868. // If specified, report any focus events inside targetWindow as
  869. // an event on effectiveNode, rather than on evt.target.
  870. // returns:
  871. // Handle to pass to unregisterWin()
  872. // TODO: make this function private in 2.0; Editor/users should call registerIframe(),
  873. var mousedownListener = function(evt){
  874. dijit._justMouseDowned = true;
  875. setTimeout(function(){ dijit._justMouseDowned = false; }, 0);
  876. // workaround weird IE bug where the click is on an orphaned node
  877. // (first time clicking a Select/DropDownButton inside a TooltipDialog)
  878. if(dojo.isIE && evt && evt.srcElement && evt.srcElement.parentNode == null){
  879. return;
  880. }
  881. dijit._onTouchNode(effectiveNode || evt.target || evt.srcElement, "mouse");
  882. };
  883. //dojo.connect(targetWindow, "onscroll", ???);
  884. // Listen for blur and focus events on targetWindow's document.
  885. // IIRC, I'm using attachEvent() rather than dojo.connect() because focus/blur events don't bubble
  886. // through dojo.connect(), and also maybe to catch the focus events early, before onfocus handlers
  887. // fire.
  888. // Connect to <html> (rather than document) on IE to avoid memory leaks, but document on other browsers because
  889. // (at least for FF) the focus event doesn't fire on <html> or <body>.
  890. var doc = dojo.isIE ? targetWindow.document.documentElement : targetWindow.document;
  891. if(doc){
  892. if(dojo.isIE){
  893. targetWindow.document.body.attachEvent('onmousedown', mousedownListener);
  894. var activateListener = function(evt){
  895. // IE reports that nodes like <body> have gotten focus, even though they have tabIndex=-1,
  896. // Should consider those more like a mouse-click than a focus....
  897. if(evt.srcElement.tagName.toLowerCase() != "#document" &&
  898. dijit.isTabNavigable(evt.srcElement)){
  899. dijit._onFocusNode(effectiveNode || evt.srcElement);
  900. }else{
  901. dijit._onTouchNode(effectiveNode || evt.srcElement);
  902. }
  903. };
  904. doc.attachEvent('onactivate', activateListener);
  905. var deactivateListener = function(evt){
  906. dijit._onBlurNode(effectiveNode || evt.srcElement);
  907. };
  908. doc.attachEvent('ondeactivate', deactivateListener);
  909. return function(){
  910. targetWindow.document.detachEvent('onmousedown', mousedownListener);
  911. doc.detachEvent('onactivate', activateListener);
  912. doc.detachEvent('ondeactivate', deactivateListener);
  913. doc = null; // prevent memory leak (apparent circular reference via closure)
  914. };
  915. }else{
  916. doc.body.addEventListener('mousedown', mousedownListener, true);
  917. var focusListener = function(evt){
  918. dijit._onFocusNode(effectiveNode || evt.target);
  919. };
  920. doc.addEventListener('focus', focusListener, true);
  921. var blurListener = function(evt){
  922. dijit._onBlurNode(effectiveNode || evt.target);
  923. };
  924. doc.addEventListener('blur', blurListener, true);
  925. return function(){
  926. doc.body.removeEventListener('mousedown', mousedownListener, true);
  927. doc.removeEventListener('focus', focusListener, true);
  928. doc.removeEventListener('blur', blurListener, true);
  929. doc = null; // prevent memory leak (apparent circular reference via closure)
  930. };
  931. }
  932. }
  933. },
  934. unregisterWin: function(/*Handle*/ handle){
  935. // summary:
  936. // Unregisters listeners on the specified window (either the main
  937. // window or an iframe's window) according to handle returned from registerWin().
  938. // After calling be sure to delete or null out the handle itself.
  939. // Currently our handle is actually a function
  940. handle && handle();
  941. },
  942. _onBlurNode: function(/*DomNode*/ node){
  943. // summary:
  944. // Called when focus leaves a node.
  945. // Usually ignored, _unless_ it *isn't* follwed by touching another node,
  946. // which indicates that we tabbed off the last field on the page,
  947. // in which case every widget is marked inactive
  948. dijit._prevFocus = dijit._curFocus;
  949. dijit._curFocus = null;
  950. if(dijit._justMouseDowned){
  951. // the mouse down caused a new widget to be marked as active; this blur event
  952. // is coming late, so ignore it.
  953. return;
  954. }
  955. // if the blur event isn't followed by a focus event then mark all widgets as inactive.
  956. if(dijit._clearActiveWidgetsTimer){
  957. clearTimeout(dijit._clearActiveWidgetsTimer);
  958. }
  959. dijit._clearActiveWidgetsTimer = setTimeout(function(){
  960. delete dijit._clearActiveWidgetsTimer;
  961. dijit._setStack([]);
  962. dijit._prevFocus = null;
  963. }, 100);
  964. },
  965. _onTouchNode: function(/*DomNode*/ node, /*String*/ by){
  966. // summary:
  967. // Callback when node is focused or mouse-downed
  968. // node:
  969. // The node that was touched.
  970. // by:
  971. // "mouse" if the focus/touch was caused by a mouse down event
  972. // ignore the recent blurNode event
  973. if(dijit._clearActiveWidgetsTimer){
  974. clearTimeout(dijit._clearActiveWidgetsTimer);
  975. delete dijit._clearActiveWidgetsTimer;
  976. }
  977. // compute stack of active widgets (ex: ComboButton --> Menu --> MenuItem)
  978. var newStack=[];
  979. try{
  980. while(node){
  981. var popupParent = dojo.attr(node, "dijitPopupParent");
  982. if(popupParent){
  983. node=dijit.byId(popupParent).domNode;
  984. }else if(node.tagName && node.tagName.toLowerCase() == "body"){
  985. // is this the root of the document or just the root of an iframe?
  986. if(node === dojo.body()){
  987. // node is the root of the main document
  988. break;
  989. }
  990. // otherwise, find the iframe this node refers to (can't access it via parentNode,
  991. // need to do this trick instead). window.frameElement is supported in IE/FF/Webkit
  992. node=dojo.window.get(node.ownerDocument).frameElement;
  993. }else{
  994. // if this node is the root node of a widget, then add widget id to stack,
  995. // except ignore clicks on disabled widgets (actually focusing a disabled widget still works,
  996. // to support MenuItem)
  997. var id = node.getAttribute && node.getAttribute("widgetId"),
  998. widget = id && dijit.byId(id);
  999. if(widget && !(by == "mouse" && widget.get("disabled"))){
  1000. newStack.unshift(id);
  1001. }
  1002. node=node.parentNode;
  1003. }
  1004. }
  1005. }catch(e){ /* squelch */ }
  1006. dijit._setStack(newStack, by);
  1007. },
  1008. _onFocusNode: function(/*DomNode*/ node){
  1009. // summary:
  1010. // Callback when node is focused
  1011. if(!node){
  1012. return;
  1013. }
  1014. if(node.nodeType == 9){
  1015. // Ignore focus events on the document itself. This is here so that
  1016. // (for example) clicking the up/down arrows of a spinner
  1017. // (which don't get focus) won't cause that widget to blur. (FF issue)
  1018. return;
  1019. }
  1020. dijit._onTouchNode(node);
  1021. if(node == dijit._curFocus){ return; }
  1022. if(dijit._curFocus){
  1023. dijit._prevFocus = dijit._curFocus;
  1024. }
  1025. dijit._curFocus = node;
  1026. dojo.publish("focusNode", [node]);
  1027. },
  1028. _setStack: function(/*String[]*/ newStack, /*String*/ by){
  1029. // summary:
  1030. // The stack of active widgets has changed. Send out appropriate events and records new stack.
  1031. // newStack:
  1032. // array of widget id's, starting from the top (outermost) widget
  1033. // by:
  1034. // "mouse" if the focus/touch was caused by a mouse down event
  1035. var oldStack = dijit._activeStack;
  1036. dijit._activeStack = newStack;
  1037. // compare old stack to new stack to see how many elements they have in common
  1038. for(var nCommon=0; nCommon<Math.min(oldStack.length, newStack.length); nCommon++){
  1039. if(oldStack[nCommon] != newStack[nCommon]){
  1040. break;
  1041. }
  1042. }
  1043. var widget;
  1044. // for all elements that have gone out of focus, send blur event
  1045. for(var i=oldStack.length-1; i>=nCommon; i--){
  1046. widget = dijit.byId(oldStack[i]);
  1047. if(widget){
  1048. widget._focused = false;
  1049. widget.set("focused", false);
  1050. widget._hasBeenBlurred = true;
  1051. if(widget._onBlur){
  1052. widget._onBlur(by);
  1053. }
  1054. dojo.publish("widgetBlur", [widget, by]);
  1055. }
  1056. }
  1057. // for all element that have come into focus, send focus event
  1058. for(i=nCommon; i<newStack.length; i++){
  1059. widget = dijit.byId(newStack[i]);
  1060. if(widget){
  1061. widget._focused = true;
  1062. widget.set("focused", true);
  1063. if(widget._onFocus){
  1064. widget._onFocus(by);
  1065. }
  1066. dojo.publish("widgetFocus", [widget, by]);
  1067. }
  1068. }
  1069. }
  1070. });
  1071. // register top window and all the iframes it contains
  1072. dojo.addOnLoad(function(){
  1073. var handle = dijit.registerWin(window);
  1074. if(dojo.isIE){
  1075. dojo.addOnWindowUnload(function(){
  1076. dijit.unregisterWin(handle);
  1077. handle = null;
  1078. })
  1079. }
  1080. });
  1081. }
  1082. if(!dojo._hasResource["dojo.AdapterRegistry"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1083. dojo._hasResource["dojo.AdapterRegistry"] = true;
  1084. dojo.provide("dojo.AdapterRegistry");
  1085. dojo.AdapterRegistry = function(/*Boolean?*/ returnWrappers){
  1086. // summary:
  1087. // A registry to make contextual calling/searching easier.
  1088. // description:
  1089. // Objects of this class keep list of arrays in the form [name, check,
  1090. // wrap, directReturn] that are used to determine what the contextual
  1091. // result of a set of checked arguments is. All check/wrap functions
  1092. // in this registry should be of the same arity.
  1093. // example:
  1094. // | // create a new registry
  1095. // | var reg = new dojo.AdapterRegistry();
  1096. // | reg.register("handleString",
  1097. // | dojo.isString,
  1098. // | function(str){
  1099. // | // do something with the string here
  1100. // | }
  1101. // | );
  1102. // | reg.register("handleArr",
  1103. // | dojo.isArray,
  1104. // | function(arr){
  1105. // | // do something with the array here
  1106. // | }
  1107. // | );
  1108. // |
  1109. // | // now we can pass reg.match() *either* an array or a string and
  1110. // | // the value we pass will get handled by the right function
  1111. // | reg.match("someValue"); // will call the first function
  1112. // | reg.match(["someValue"]); // will call the second
  1113. this.pairs = [];
  1114. this.returnWrappers = returnWrappers || false; // Boolean
  1115. };
  1116. dojo.extend(dojo.AdapterRegistry, {
  1117. register: function(/*String*/ name, /*Function*/ check, /*Function*/ wrap, /*Boolean?*/ directReturn, /*Boolean?*/ override){
  1118. // summary:
  1119. // register a check function to determine if the wrap function or
  1120. // object gets selected
  1121. // name:
  1122. // a way to identify this matcher.
  1123. // check:
  1124. // a function that arguments are passed to from the adapter's
  1125. // match() function. The check function should return true if the
  1126. // given arguments are appropriate for the wrap function.
  1127. // directReturn:
  1128. // If directReturn is true, the value passed in for wrap will be
  1129. // returned instead of being called. Alternately, the
  1130. // AdapterRegistry can be set globally to "return not call" using
  1131. // the returnWrappers property. Either way, this behavior allows
  1132. // the registry to act as a "search" function instead of a
  1133. // function interception library.
  1134. // override:
  1135. // If override is given and true, the check function will be given
  1136. // highest priority. Otherwise, it will be the lowest priority
  1137. // adapter.
  1138. this.pairs[((override) ? "unshift" : "push")]([name, check, wrap, directReturn]);
  1139. },
  1140. match: function(/* ... */){
  1141. // summary:
  1142. // Find an adapter for the given arguments. If no suitable adapter
  1143. // is found, throws an exception. match() accepts any number of
  1144. // arguments, all of which are passed to all matching functions
  1145. // from the registered pairs.
  1146. for(var i = 0; i < this.pairs.length; i++){
  1147. var pair = this.pairs[i];
  1148. if(pair[1].apply(this, arguments)){
  1149. if((pair[3])||(this.returnWrappers)){
  1150. return pair[2];
  1151. }else{
  1152. return pair[2].apply(this, arguments);
  1153. }
  1154. }
  1155. }
  1156. throw new Error("No match found");
  1157. },
  1158. unregister: function(name){
  1159. // summary: Remove a named adapter from the registry
  1160. // FIXME: this is kind of a dumb way to handle this. On a large
  1161. // registry this will be slow-ish and we can use the name as a lookup
  1162. // should we choose to trade memory for speed.
  1163. for(var i = 0; i < this.pairs.length; i++){
  1164. var pair = this.pairs[i];
  1165. if(pair[0] == name){
  1166. this.pairs.splice(i, 1);
  1167. return true;
  1168. }
  1169. }
  1170. return false;
  1171. }
  1172. });
  1173. }
  1174. if(!dojo._hasResource["dijit._base.place"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1175. dojo._hasResource["dijit._base.place"] = true;
  1176. dojo.provide("dijit._base.place");
  1177. dijit.getViewport = function(){
  1178. // summary:
  1179. // Returns the dimensions and scroll position of the viewable area of a browser window
  1180. return dojo.window.getBox();
  1181. };
  1182. /*=====
  1183. dijit.__Position = function(){
  1184. // x: Integer
  1185. // horizontal coordinate in pixels, relative to document body
  1186. // y: Integer
  1187. // vertical coordinate in pixels, relative to document body
  1188. thix.x = x;
  1189. this.y = y;
  1190. }
  1191. =====*/
  1192. dijit.placeOnScreen = function(
  1193. /* DomNode */ node,
  1194. /* dijit.__Position */ pos,
  1195. /* String[] */ corners,
  1196. /* dijit.__Position? */ padding){
  1197. // summary:
  1198. // Positions one of the node's corners at specified position
  1199. // such that node is fully visible in viewport.
  1200. // description:
  1201. // NOTE: node is assumed to be absolutely or relatively positioned.
  1202. // pos:
  1203. // Object like {x: 10, y: 20}
  1204. // corners:
  1205. // Array of Strings representing order to try corners in, like ["TR", "BL"].
  1206. // Possible values are:
  1207. // * "BL" - bottom left
  1208. // * "BR" - bottom right
  1209. // * "TL" - top left
  1210. // * "TR" - top right
  1211. // padding:
  1212. // set padding to put some buffer around the element you want to position.
  1213. // example:
  1214. // Try to place node's top right corner at (10,20).
  1215. // If that makes node go (partially) off screen, then try placing
  1216. // bottom left corner at (10,20).
  1217. // | placeOnScreen(node, {x: 10, y: 20}, ["TR", "BL"])
  1218. var choices = dojo.map(corners, function(corner){
  1219. var c = { corner: corner, pos: {x:pos.x,y:pos.y} };
  1220. if(padding){
  1221. c.pos.x += corner.charAt(1) == 'L' ? padding.x : -padding.x;
  1222. c.pos.y += corner.charAt(0) == 'T' ? padding.y : -padding.y;
  1223. }
  1224. return c;
  1225. });
  1226. return dijit._place(node, choices);
  1227. }
  1228. dijit._place = function(/*DomNode*/ node, choices, layoutNode, /*Object*/ aroundNodeCoords){
  1229. // summary:
  1230. // Given a list of spots to put node, put it at the first spot where it fits,
  1231. // of if it doesn't fit anywhere then the place with the least overflow
  1232. // choices: Array
  1233. // Array of elements like: {corner: 'TL', pos: {x: 10, y: 20} }
  1234. // Above example says to put the top-left corner of the node at (10,20)
  1235. // layoutNode: Function(node, aroundNodeCorner, nodeCorner, size)
  1236. // for things like tooltip, they are displayed differently (and have different dimensions)
  1237. // based on their orientation relative to the parent. This adjusts the popup based on orientation.
  1238. // It also passes in the available size for the popup, which is useful for tooltips to
  1239. // tell them that their width is limited to a certain amount. layoutNode() may return a value expressing
  1240. // how much the popup had to be modified to fit into the available space. This is used to determine
  1241. // what the best placement is.
  1242. // aroundNodeCoords: Object
  1243. // Size of aroundNode, ex: {w: 200, h: 50}
  1244. // get {x: 10, y: 10, w: 100, h:100} type obj representing position of
  1245. // viewport over document
  1246. var view = dojo.window.getBox();
  1247. // This won't work if the node is inside a <div style="position: relative">,
  1248. // so reattach it to dojo.doc.body. (Otherwise, the positioning will be wrong
  1249. // and also it might get cutoff)
  1250. if(!node.parentNode || String(node.parentNode.tagName).toLowerCase() != "body"){
  1251. dojo.body().appendChild(node);
  1252. }
  1253. var best = null;
  1254. dojo.some(choices, function(choice){
  1255. var corner = choice.corner;
  1256. var pos = choice.pos;
  1257. var overflow = 0;
  1258. // calculate amount of space available given specified position of node
  1259. var spaceAvailable = {
  1260. w: corner.charAt(1) == 'L' ? (view.l + view.w) - pos.x : pos.x - view.l,
  1261. h: corner.charAt(1) == 'T' ? (view.t + view.h) - pos.y : pos.y - view.t
  1262. };
  1263. // configure node to be displayed in given position relative to button
  1264. // (need to do this in order to get an accurate size for the node, because
  1265. // a tooltip's size changes based on position, due to triangle)
  1266. if(layoutNode){
  1267. var res = layoutNode(node, choice.aroundCorner, corner, spaceAvailable, aroundNodeCoords);
  1268. overflow = typeof res == "undefined" ? 0 : res;
  1269. }
  1270. // get node's size
  1271. var style = node.style;
  1272. var oldDisplay = style.display;
  1273. var oldVis = style.visibility;
  1274. style.visibility = "hidden";
  1275. style.display = "";
  1276. var mb = dojo.marginBox(node);
  1277. style.display = oldDisplay;
  1278. style.visibility = oldVis;
  1279. // coordinates and size of node with specified corner placed at pos,
  1280. // and clipped by viewport
  1281. var startX = Math.max(view.l, corner.charAt(1) == 'L' ? pos.x : (pos.x - mb.w)),
  1282. startY = Math.max(view.t, corner.charAt(0) == 'T' ? pos.y : (pos.y - mb.h)),
  1283. endX = Math.min(view.l + view.w, corner.charAt(1) == 'L' ? (startX + mb.w) : pos.x),
  1284. endY = Math.min(view.t + view.h, corner.charAt(0) == 'T' ? (startY + mb.h) : pos.y),
  1285. width = endX - startX,
  1286. height = endY - startY;
  1287. overflow += (mb.w - width) + (mb.h - height);
  1288. if(best == null || overflow < best.overflow){
  1289. best = {
  1290. corner: corner,
  1291. aroundCorner: choice.aroundCorner,
  1292. x: startX,
  1293. y: startY,
  1294. w: width,
  1295. h: height,
  1296. overflow: overflow,
  1297. spaceAvailable: spaceAvailable
  1298. };
  1299. }
  1300. return !overflow;
  1301. });
  1302. // In case the best position is not the last one we checked, need to call
  1303. // layoutNode() again.
  1304. if(best.overflow && layoutNode){
  1305. layoutNode(node, best.aroundCorner, best.corner, best.spaceAvailable, aroundNodeCoords);
  1306. }
  1307. // And then position the node. Do this last, after the layoutNode() above
  1308. // has sized the node, due to browser quirks when the viewport is scrolled
  1309. // (specifically that a Tooltip will shrink to fit as though the window was
  1310. // scrolled to the left).
  1311. //
  1312. // In RTL mode, set style.right rather than style.left so in the common case,
  1313. // window resizes move the popup along with the aroundNode.
  1314. var l = dojo._isBodyLtr(),
  1315. s = node.style;
  1316. s.top = best.y + "px";
  1317. s[l ? "left" : "right"] = (l ? best.x : view.w - best.x - best.w) + "px";
  1318. s[l ? "right" : "left"] = "auto"; // needed for FF or else tooltip goes to far left
  1319. return best;
  1320. }
  1321. dijit.placeOnScreenAroundNode = function(
  1322. /* DomNode */ node,
  1323. /* DomNode */ aroundNode,
  1324. /* Object */ aroundCorners,
  1325. /* Function? */ layoutNode){
  1326. // summary:
  1327. // Position node adjacent or kitty-corner to aroundNode
  1328. // such that it's fully visible in viewport.
  1329. //
  1330. // description:
  1331. // Place node such that corner of node touches a corner of
  1332. // aroundNode, and that node is fully visible.
  1333. //
  1334. // aroundCorners:
  1335. // Ordered list of pairs of corners to try matching up.
  1336. // Each pair of corners is represented as a key/value in the hash,
  1337. // where the key corresponds to the aroundNode's corner, and
  1338. // the value corresponds to the node's corner:
  1339. //
  1340. // | { aroundNodeCorner1: nodeCorner1, aroundNodeCorner2: nodeCorner2, ...}
  1341. //
  1342. // The following strings are used to represent the four corners:
  1343. // * "BL" - bottom left
  1344. // * "BR" - bottom right
  1345. // * "TL" - top left
  1346. // * "TR" - top right
  1347. //
  1348. // layoutNode: Function(node, aroundNodeCorner, nodeCorner)
  1349. // For things like tooltip, they are displayed differently (and have different dimensions)
  1350. // based on their orientation relative to the parent. This adjusts the popup based on orientation.
  1351. //
  1352. // example:
  1353. // | dijit.placeOnScreenAroundNode(node, aroundNode, {'BL':'TL', 'TR':'BR'});
  1354. // This will try to position node such that node's top-left corner is at the same position
  1355. // as the bottom left corner of the aroundNode (ie, put node below
  1356. // aroundNode, with left edges aligned). If that fails it will try to put
  1357. // the bottom-right corner of node where the top right corner of aroundNode is
  1358. // (ie, put node above aroundNode, with right edges aligned)
  1359. //
  1360. // get coordinates of aroundNode
  1361. aroundNode = dojo.byId(aroundNode);
  1362. var aroundNodePos = dojo.position(aroundNode, true);
  1363. // place the node around the calculated rectangle
  1364. return dijit._placeOnScreenAroundRect(node,
  1365. aroundNodePos.x, aroundNodePos.y, aroundNodePos.w, aroundNodePos.h, // rectangle
  1366. aroundCorners, layoutNode);
  1367. };
  1368. /*=====
  1369. dijit.__Rectangle = function(){
  1370. // x: Integer
  1371. // horizontal offset in pixels, relative to document body
  1372. // y: Integer
  1373. // vertical offset in pixels, relative to document body
  1374. // width: Integer
  1375. // width in pixels
  1376. // height: Integer
  1377. // height in pixels
  1378. this.x = x;
  1379. this.y = y;
  1380. this.width = width;
  1381. this.height = height;
  1382. }
  1383. =====*/
  1384. dijit.placeOnScreenAroundRectangle = function(
  1385. /* DomNode */ node,
  1386. /* dijit.__Rectangle */ aroundRect,
  1387. /* Object */ aroundCorners,
  1388. /* Function */ layoutNode){
  1389. // summary:
  1390. // Like dijit.placeOnScreenAroundNode(), except that the "around"
  1391. // parameter is an arbitrary rectangle on the screen (x, y, width, height)
  1392. // instead of a dom node.
  1393. return dijit._placeOnScreenAroundRect(node,
  1394. aroundRect.x, aroundRect.y, aroundRect.width, aroundRect.height, // rectangle
  1395. aroundCorners, layoutNode);
  1396. };
  1397. dijit._placeOnScreenAroundRect = function(
  1398. /* DomNode */ node,
  1399. /* Number */ x,
  1400. /* Number */ y,
  1401. /* Number */ width,
  1402. /* Number */ height,
  1403. /* Object */ aroundCorners,
  1404. /* Function */ layoutNode){
  1405. // summary:
  1406. // Like dijit.placeOnScreenAroundNode(), except it accepts coordinates
  1407. // of a rectangle to place node adjacent to.
  1408. // TODO: combine with placeOnScreenAroundRectangle()
  1409. // Generate list of possible positions for node
  1410. var choices = [];
  1411. for(var nodeCorner in aroundCorners){
  1412. choices.push( {
  1413. aroundCorner: nodeCorner,
  1414. corner: aroundCorners[nodeCorner],
  1415. pos: {
  1416. x: x + (nodeCorner.charAt(1) == 'L' ? 0 : width),
  1417. y: y + (nodeCorner.charAt(0) == 'T' ? 0 : height)
  1418. }
  1419. });
  1420. }
  1421. return dijit._place(node, choices, layoutNode, {w: width, h: height});
  1422. };
  1423. dijit.placementRegistry= new dojo.AdapterRegistry();
  1424. dijit.placementRegistry.register("node",
  1425. function(n, x){
  1426. return typeof x == "object" &&
  1427. typeof x.offsetWidth != "undefined" && typeof x.offsetHeight != "undefined";
  1428. },
  1429. dijit.placeOnScreenAroundNode);
  1430. dijit.placementRegistry.register("rect",
  1431. function(n, x){
  1432. return typeof x == "object" &&
  1433. "x" in x && "y" in x && "width" in x && "height" in x;
  1434. },
  1435. dijit.placeOnScreenAroundRectangle);
  1436. dijit.placeOnScreenAroundElement = function(
  1437. /* DomNode */ node,
  1438. /* Object */ aroundElement,
  1439. /* Object */ aroundCorners,
  1440. /* Function */ layoutNode){
  1441. // summary:
  1442. // Like dijit.placeOnScreenAroundNode(), except it accepts an arbitrary object
  1443. // for the "around" argument and finds a proper processor to place a node.
  1444. return dijit.placementRegistry.match.apply(dijit.placementRegistry, arguments);
  1445. };
  1446. dijit.getPopupAroundAlignment = function(/*Array*/ position, /*Boolean*/ leftToRight){
  1447. // summary:
  1448. // Transforms the passed array of preferred positions into a format suitable for passing as the aroundCorners argument to dijit.placeOnScreenAroundElement.
  1449. //
  1450. // position: String[]
  1451. // This variable controls the position of the drop down.
  1452. // It's an array of strings with the following values:
  1453. //
  1454. // * before: places drop down to the left of the target node/widget, or to the right in
  1455. // the case of RTL scripts like Hebrew and Arabic
  1456. // * after: places drop down to the right of the target node/widget, or to the left in
  1457. // the case of RTL scripts like Hebrew and Arabic
  1458. // * above: drop down goes above target node
  1459. // * below: drop down goes below target node
  1460. //
  1461. // The list is positions is tried, in order, until a position is found where the drop down fits
  1462. // within the viewport.
  1463. //
  1464. // leftToRight: Boolean
  1465. // Whether the popup will be displaying in leftToRight mode.
  1466. //
  1467. var align = {};
  1468. dojo.forEach(position, function(pos){
  1469. switch(pos){
  1470. case "after":
  1471. align[leftToRight ? "BR" : "BL"] = leftToRight ? "BL" : "BR";
  1472. break;
  1473. case "before":
  1474. align[leftToRight ? "BL" : "BR"] = leftToRight ? "BR" : "BL";
  1475. break;
  1476. case "below-alt":
  1477. leftToRight = !leftToRight;
  1478. // fall through
  1479. case "below":
  1480. // first try to align left borders, next try to align right borders (or reverse for RTL mode)
  1481. align[leftToRight ? "BL" : "BR"] = leftToRight ? "TL" : "TR";
  1482. align[leftToRight ? "BR" : "BL"] = leftToRight ? "TR" : "TL";
  1483. break;
  1484. case "above-alt":
  1485. leftToRight = !leftToRight;
  1486. // fall through
  1487. case "above":
  1488. default:
  1489. // first try to align left borders, next try to align right borders (or reverse for RTL mode)
  1490. align[leftToRight ? "TL" : "TR"] = leftToRight ? "BL" : "BR";
  1491. align[leftToRight ? "TR" : "TL"] = leftToRight ? "BR" : "BL";
  1492. break;
  1493. }
  1494. });
  1495. return align;
  1496. };
  1497. }
  1498. if(!dojo._hasResource["dijit._base.window"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1499. dojo._hasResource["dijit._base.window"] = true;
  1500. dojo.provide("dijit._base.window");
  1501. dijit.getDocumentWindow = function(doc){
  1502. return dojo.window.get(doc);
  1503. };
  1504. }
  1505. if(!dojo._hasResource["dijit._base.popup"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1506. dojo._hasResource["dijit._base.popup"] = true;
  1507. dojo.provide("dijit._base.popup");
  1508. /*=====
  1509. dijit.popup.__OpenArgs = function(){
  1510. // popup: Widget
  1511. // widget to display
  1512. // parent: Widget
  1513. // the button etc. that is displaying this popup
  1514. // around: DomNode
  1515. // DOM node (typically a button); place popup relative to this node. (Specify this *or* "x" and "y" parameters.)
  1516. // x: Integer
  1517. // Absolute horizontal position (in pixels) to place node at. (Specify this *or* "around" parameter.)
  1518. // y: Integer
  1519. // Absolute vertical position (in pixels) to place node at. (Specify this *or* "around" parameter.)
  1520. // orient: Object|String
  1521. // When the around parameter is specified, orient should be an
  1522. // ordered list of tuples of the form (around-node-corner, popup-node-corner).
  1523. // dijit.popup.open() tries to position the popup according to each tuple in the list, in order,
  1524. // until the popup appears fully within the viewport.
  1525. //
  1526. // The default value is {BL:'TL', TL:'BL'}, which represents a list of two tuples:
  1527. // 1. (BL, TL)
  1528. // 2. (TL, BL)
  1529. // where BL means "bottom left" and "TL" means "top left".
  1530. // So by default, it first tries putting the popup below the around node, left-aligning them,
  1531. // and then tries to put it above the around node, still left-aligning them. Note that the
  1532. // default is horizontally reversed when in RTL mode.
  1533. //
  1534. // When an (x,y) position is specified rather than an around node, orient is either
  1535. // "R" or "L". R (for right) means that it tries to put the popup to the right of the mouse,
  1536. // specifically positioning the popup's top-right corner at the mouse position, and if that doesn't
  1537. // fit in the viewport, then it tries, in order, the bottom-right corner, the top left corner,
  1538. // and the top-right corner.
  1539. // onCancel: Function
  1540. // callback when user has canceled the popup by
  1541. // 1. hitting ESC or
  1542. // 2. by using the popup widget's proprietary cancel mechanism (like a cancel button in a dialog);
  1543. // i.e. whenever popupWidget.onCancel() is called, args.onCancel is called
  1544. // onClose: Function
  1545. // callback whenever this popup is closed
  1546. // onExecute: Function
  1547. // callback when user "executed" on the popup/sub-popup by selecting a menu choice, etc. (top menu only)
  1548. // padding: dijit.__Position
  1549. // adding a buffer around the opening position. This is only useful when around is not set.
  1550. this.popup = popup;
  1551. this.parent = parent;
  1552. this.around = around;
  1553. this.x = x;
  1554. this.y = y;
  1555. this.orient = orient;
  1556. this.onCancel = onCancel;
  1557. this.onClose = onClose;
  1558. this.onExecute = onExecute;
  1559. this.padding = padding;
  1560. }
  1561. =====*/
  1562. dijit.popup = {
  1563. // summary:
  1564. // This singleton is used to show/hide widgets as popups.
  1565. // _stack: dijit._Widget[]
  1566. // Stack of currently popped up widgets.
  1567. // (someone opened _stack[0], and then it opened _stack[1], etc.)
  1568. _stack: [],
  1569. // _beginZIndex: Number
  1570. // Z-index of the first popup. (If first popup opens other
  1571. // popups they get a higher z-index.)
  1572. _beginZIndex: 1000,
  1573. _idGen: 1,
  1574. _createWrapper: function(/*Widget || DomNode*/ widget){
  1575. // summary:
  1576. // Initialization for widgets that will be used as popups.
  1577. // Puts widget inside a wrapper DIV (if not already in one),
  1578. // and returns pointer to that wrapper DIV.
  1579. var node = widget.domNode || widget,
  1580. wrapper = widget.declaredClass ? widget._popupWrapper :
  1581. node.parentNode && dojo.hasClass(node.parentNode, "dijitPopup") ? node.parentNode : null;
  1582. if(!wrapper){
  1583. // Create wrapper <div> for when this widget [in the future] will be used as a popup.
  1584. // This is done early because of IE bugs where creating/moving DOM nodes causes focus
  1585. // to go wonky, see tests/robot/Toolbar.html to reproduce
  1586. wrapper = dojo.create("div",{
  1587. "class":"dijitPopup",
  1588. style:{ display: "none"},
  1589. role: "presentation"
  1590. }, dojo.body());
  1591. wrapper.appendChild(node);
  1592. var s = node.style;
  1593. s.display = "";
  1594. s.visibility = "";
  1595. s.position = "";
  1596. s.top = "0px";
  1597. if(widget.declaredClass){ // TODO: in 2.0 change signature to always take widget, then remove if()
  1598. widget._popupWrapper = wrapper;
  1599. dojo.connect(widget, "destroy", function(){
  1600. dojo.destroy(wrapper);
  1601. delete widget._popupWrapper;
  1602. });
  1603. }
  1604. }
  1605. return wrapper; // DOMNode
  1606. },
  1607. moveOffScreen: function(/*Widget || DomNode*/ widget){
  1608. // summary:
  1609. // Moves the popup widget off-screen.
  1610. // Do not use this method to hide popups when not in use, because
  1611. // that will create an accessibility issue: the offscreen popup is
  1612. // still in the tabbing order.
  1613. // Create wrapper if not already there
  1614. var wrapper = this._createWrapper(widget);
  1615. dojo.style(wrapper, {
  1616. visibility: "hidden",
  1617. top: "-9999px", // prevent transient scrollbar causing misalign (#5776), and initial flash in upper left (#10111)
  1618. display: ""
  1619. });
  1620. },
  1621. hide: function(/*dijit._Widget*/ widget){
  1622. // summary:
  1623. // Hide this popup widget (until it is ready to be shown).
  1624. // Initialization for widgets that will be used as popups
  1625. //
  1626. // Also puts widget inside a wrapper DIV (if not already in one)
  1627. //
  1628. // If popup widget needs to layout it should
  1629. // do so when it is made visible, and popup._onShow() is called.
  1630. // Create wrapper if not already there
  1631. var wrapper = this._createWrapper(widget);
  1632. dojo.style(wrapper, "display", "none");
  1633. },
  1634. getTopPopup: function(){
  1635. // summary:
  1636. // Compute the closest ancestor popup that's *not* a child of another popup.
  1637. // Ex: For a TooltipDialog with a button that spawns a tree of menus, find the popup of the button.
  1638. var stack = this._stack;
  1639. for(var pi=stack.length-1; pi > 0 && stack[pi].parent === stack[pi-1].widget; pi--){
  1640. /* do nothing, just trying to get right value for pi */
  1641. }
  1642. return stack[pi];
  1643. },
  1644. open: function(/*dijit.popup.__OpenArgs*/ args){
  1645. // summary:
  1646. // Popup the widget at the specified position
  1647. //
  1648. // example:
  1649. // opening at the mouse position
  1650. // | dijit.popup.open({popup: menuWidget, x: evt.pageX, y: evt.pageY});
  1651. //
  1652. // example:
  1653. // opening the widget as a dropdown
  1654. // | dijit.popup.open({parent: this, popup: menuWidget, around: this.domNode, onClose: function(){...}});
  1655. //
  1656. // Note that whatever widget called dijit.popup.open() should also listen to its own _onBlur callback
  1657. // (fired from _base/focus.js) to know that focus has moved somewhere else and thus the popup should be closed.
  1658. var stack = this._stack,
  1659. widget = args.popup,
  1660. orient = args.orient || (
  1661. (args.parent ? args.parent.isLeftToRight() : dojo._isBodyLtr()) ?
  1662. {'BL':'TL', 'BR':'TR', 'TL':'BL', 'TR':'BR'} :
  1663. {'BR':'TR', 'BL':'TL', 'TR':'BR', 'TL':'BL'}
  1664. ),
  1665. around = args.around,
  1666. id = (args.around && args.around.id) ? (args.around.id+"_dropdown") : ("popup_"+this._idGen++);
  1667. // If we are opening a new popup that isn't a child of a currently opened popup, then
  1668. // close currently opened popup(s). This should happen automatically when the old popups
  1669. // gets the _onBlur() event, except that the _onBlur() event isn't reliable on IE, see [22198].
  1670. while(stack.length && (!args.parent || !dojo.isDescendant(args.parent.domNode, stack[stack.length-1].widget.domNode))){
  1671. dijit.popup.close(stack[stack.length-1].widget);
  1672. }
  1673. // Get pointer to popup wrapper, and create wrapper if it doesn't exist
  1674. var wrapper = this._createWrapper(widget);
  1675. dojo.attr(wrapper, {
  1676. id: id,
  1677. style: {
  1678. zIndex: this._beginZIndex + stack.length
  1679. },
  1680. "class": "dijitPopup " + (widget.baseClass || widget["class"] || "").split(" ")[0] +"Popup",
  1681. dijitPopupParent: args.parent ? args.parent.id : ""
  1682. });
  1683. if(dojo.isIE || dojo.isMoz){
  1684. if(!widget.bgIframe){
  1685. // setting widget.bgIframe triggers cleanup in _Widget.destroy()
  1686. widget.bgIframe = new dijit.BackgroundIframe(wrapper);
  1687. }
  1688. }
  1689. // position the wrapper node and make it visible
  1690. var best = around ?
  1691. dijit.placeOnScreenAroundElement(wrapper, around, orient, widget.orient ? dojo.hitch(widget, "orient") : null) :
  1692. dijit.placeOnScreen(wrapper, args, orient == 'R' ? ['TR','BR','TL','BL'] : ['TL','BL','TR','BR'], args.padding);
  1693. wrapper.style.display = "";
  1694. wrapper.style.visibility = "visible";
  1695. widget.domNode.style.visibility = "visible"; // counteract effects from _HasDropDown
  1696. var handlers = [];
  1697. // provide default escape and tab key handling
  1698. // (this will work for any widget, not just menu)
  1699. handlers.push(dojo.connect(wrapper, "onkeypress", this, function(evt){
  1700. if(evt.charOrCode == dojo.keys.ESCAPE && args.onCancel){
  1701. dojo.stopEvent(evt);
  1702. args.onCancel();
  1703. }else if(evt.charOrCode === dojo.keys.TAB){
  1704. dojo.stopEvent(evt);
  1705. var topPopup = this.getTopPopup();
  1706. if(topPopup && topPopup.onCancel){
  1707. topPopup.onCancel();
  1708. }
  1709. }
  1710. }));
  1711. // watch for cancel/execute events on the popup and notify the caller
  1712. // (for a menu, "execute" means clicking an item)
  1713. if(widget.onCancel){
  1714. handlers.push(dojo.connect(widget, "onCancel", args.onCancel));
  1715. }
  1716. handlers.push(dojo.connect(widget, widget.onExecute ? "onExecute" : "onChange", this, function(){
  1717. var topPopup = this.getTopPopup();
  1718. if(topPopup && topPopup.onExecute){
  1719. topPopup.onExecute();
  1720. }
  1721. }));
  1722. stack.push({
  1723. widget: widget,
  1724. parent: args.parent,
  1725. onExecute: args.onExecute,
  1726. onCancel: args.onCancel,
  1727. onClose: args.onClose,
  1728. handlers: handlers
  1729. });
  1730. if(widget.onOpen){
  1731. // TODO: in 2.0 standardize onShow() (used by StackContainer) and onOpen() (used here)
  1732. widget.onOpen(best);
  1733. }
  1734. return best;
  1735. },
  1736. close: function(/*dijit._Widget?*/ popup){
  1737. // summary:
  1738. // Close specified popup and any popups that it parented.
  1739. // If no popup is specified, closes all popups.
  1740. var stack = this._stack;
  1741. // Basically work backwards from the top of the stack closing popups
  1742. // until we hit the specified popup, but IIRC there was some issue where closing
  1743. // a popup would cause others to close too. Thus if we are trying to close B in [A,B,C]
  1744. // closing C might close B indirectly and then the while() condition will run where stack==[A]...
  1745. // so the while condition is constructed defensively.
  1746. while((popup && dojo.some(stack, function(elem){return elem.widget == popup;})) ||
  1747. (!popup && stack.length)){
  1748. var top = stack.pop(),
  1749. widget = top.widget,
  1750. onClose = top.onClose;
  1751. if(widget.onClose){
  1752. // TODO: in 2.0 standardize onHide() (used by StackContainer) and onClose() (used here)
  1753. widget.onClose();
  1754. }
  1755. dojo.forEach(top.handlers, dojo.disconnect);
  1756. // Hide the widget and it's wrapper unless it has already been destroyed in above onClose() etc.
  1757. if(widget && widget.domNode){
  1758. this.hide(widget);
  1759. }
  1760. if(onClose){
  1761. onClose();
  1762. }
  1763. }
  1764. }
  1765. };
  1766. // TODO: remove dijit._frames, it isn't being used much, since popups never release their
  1767. // iframes (see [22236])
  1768. dijit._frames = new function(){
  1769. // summary:
  1770. // cache of iframes
  1771. var queue = [];
  1772. this.pop = function(){
  1773. var iframe;
  1774. if(queue.length){
  1775. iframe = queue.pop();
  1776. iframe.style.display="";
  1777. }else{
  1778. if(dojo.isIE < 9){
  1779. var burl = dojo.config["dojoBlankHtmlUrl"] || (dojo.moduleUrl("dojo", "resources/blank.html")+"") || "javascript:\"\"";
  1780. var html="<iframe src='" + burl + "'"
  1781. + " style='position: absolute; left: 0px; top: 0px;"
  1782. + "z-index: -1; filter:Alpha(Opacity=\"0\");'>";
  1783. iframe = dojo.doc.createElement(html);
  1784. }else{
  1785. iframe = dojo.create("iframe");
  1786. iframe.src = 'javascript:""';
  1787. iframe.className = "dijitBackgroundIframe";
  1788. dojo.style(iframe, "opacity", 0.1);
  1789. }
  1790. iframe.tabIndex = -1; // Magic to prevent iframe from getting focus on tab keypress - as style didn't work.
  1791. dijit.setWaiRole(iframe,"presentation");
  1792. }
  1793. return iframe;
  1794. };
  1795. this.push = function(iframe){
  1796. iframe.style.display="none";
  1797. queue.push(iframe);
  1798. }
  1799. }();
  1800. dijit.BackgroundIframe = function(/*DomNode*/ node){
  1801. // summary:
  1802. // For IE/FF z-index schenanigans. id attribute is required.
  1803. //
  1804. // description:
  1805. // new dijit.BackgroundIframe(node)
  1806. // Makes a background iframe as a child of node, that fills
  1807. // area (and position) of node
  1808. if(!node.id){ throw new Error("no id"); }
  1809. if(dojo.isIE || dojo.isMoz){
  1810. var iframe = (this.iframe = dijit._frames.pop());
  1811. node.appendChild(iframe);
  1812. if(dojo.isIE<7 || dojo.isQuirks){
  1813. this.resize(node);
  1814. this._conn = dojo.connect(node, 'onresize', this, function(){
  1815. this.resize(node);
  1816. });
  1817. }else{
  1818. dojo.style(iframe, {
  1819. width: '100%',
  1820. height: '100%'
  1821. });
  1822. }
  1823. }
  1824. };
  1825. dojo.extend(dijit.BackgroundIframe, {
  1826. resize: function(node){
  1827. // summary:
  1828. // Resize the iframe so it's the same size as node.
  1829. // Needed on IE6 and IE/quirks because height:100% doesn't work right.
  1830. if(this.iframe){
  1831. dojo.style(this.iframe, {
  1832. width: node.offsetWidth + 'px',
  1833. height: node.offsetHeight + 'px'
  1834. });
  1835. }
  1836. },
  1837. destroy: function(){
  1838. // summary:
  1839. // destroy the iframe
  1840. if(this._conn){
  1841. dojo.disconnect(this._conn);
  1842. this._conn = null;
  1843. }
  1844. if(this.iframe){
  1845. dijit._frames.push(this.iframe);
  1846. delete this.iframe;
  1847. }
  1848. }
  1849. });
  1850. }
  1851. if(!dojo._hasResource["dijit._base.scroll"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1852. dojo._hasResource["dijit._base.scroll"] = true;
  1853. dojo.provide("dijit._base.scroll");
  1854. dijit.scrollIntoView = function(/*DomNode*/ node, /*Object?*/ pos){
  1855. // summary:
  1856. // Scroll the passed node into view, if it is not already.
  1857. // Deprecated, use `dojo.window.scrollIntoView` instead.
  1858. dojo.window.scrollIntoView(node, pos);
  1859. };
  1860. }
  1861. if(!dojo._hasResource["dojo.uacss"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1862. dojo._hasResource["dojo.uacss"] = true;
  1863. dojo.provide("dojo.uacss");
  1864. (function(){
  1865. // summary:
  1866. // Applies pre-set CSS classes to the top-level HTML node, based on:
  1867. // - browser (ex: dj_ie)
  1868. // - browser version (ex: dj_ie6)
  1869. // - box model (ex: dj_contentBox)
  1870. // - text direction (ex: dijitRtl)
  1871. //
  1872. // In addition, browser, browser version, and box model are
  1873. // combined with an RTL flag when browser text is RTL. ex: dj_ie-rtl.
  1874. var d = dojo,
  1875. html = d.doc.documentElement,
  1876. ie = d.isIE,
  1877. opera = d.isOpera,
  1878. maj = Math.floor,
  1879. ff = d.isFF,
  1880. boxModel = d.boxModel.replace(/-/,''),
  1881. classes = {
  1882. dj_quirks: d.isQuirks,
  1883. // NOTE: Opera not supported by dijit
  1884. dj_opera: opera,
  1885. dj_khtml: d.isKhtml,
  1886. dj_webkit: d.isWebKit,
  1887. dj_safari: d.isSafari,
  1888. dj_chrome: d.isChrome,
  1889. dj_gecko: d.isMozilla
  1890. }; // no dojo unsupported browsers
  1891. if(ie){
  1892. classes["dj_ie"] = true;
  1893. classes["dj_ie" + maj(ie)] = true;
  1894. classes["dj_iequirks"] = d.isQuirks;
  1895. }
  1896. if(ff){
  1897. classes["dj_ff" + maj(ff)] = true;
  1898. }
  1899. classes["dj_" + boxModel] = true;
  1900. // apply browser, browser version, and box model class names
  1901. var classStr = "";
  1902. for(var clz in classes){
  1903. if(classes[clz]){
  1904. classStr += clz + " ";
  1905. }
  1906. }
  1907. html.className = d.trim(html.className + " " + classStr);
  1908. // If RTL mode, then add dj_rtl flag plus repeat existing classes with -rtl extension.
  1909. // We can't run the code below until the <body> tag has loaded (so we can check for dir=rtl).
  1910. // Unshift() is to run sniff code before the parser.
  1911. dojo._loaders.unshift(function(){
  1912. if(!dojo._isBodyLtr()){
  1913. var rtlClassStr = "dj_rtl dijitRtl " + classStr.replace(/ /g, "-rtl ")
  1914. html.className = d.trim(html.className + " " + rtlClassStr);
  1915. }
  1916. });
  1917. })();
  1918. }
  1919. if(!dojo._hasResource["dijit._base.sniff"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1920. dojo._hasResource["dijit._base.sniff"] = true;
  1921. dojo.provide("dijit._base.sniff");
  1922. // summary:
  1923. // Applies pre-set CSS classes to the top-level HTML node, see
  1924. // `dojo.uacss` for details.
  1925. //
  1926. // Simply doing a require on this module will
  1927. // establish this CSS. Modified version of Morris' CSS hack.
  1928. }
  1929. if(!dojo._hasResource["dijit._base.typematic"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  1930. dojo._hasResource["dijit._base.typematic"] = true;
  1931. dojo.provide("dijit._base.typematic");
  1932. dijit.typematic = {
  1933. // summary:
  1934. // These functions are used to repetitively call a user specified callback
  1935. // method when a specific key or mouse click over a specific DOM node is
  1936. // held down for a specific amount of time.
  1937. // Only 1 such event is allowed to occur on the browser page at 1 time.
  1938. _fireEventAndReload: function(){
  1939. this._timer = null;
  1940. this._callback(++this._count, this._node, this._evt);
  1941. // Schedule next event, timer is at most minDelay (default 10ms) to avoid
  1942. // browser overload (particularly avoiding starving DOH robot so it never gets to send a mouseup)
  1943. this._currentTimeout = Math.max(
  1944. this._currentTimeout < 0 ? this._initialDelay :
  1945. (this._subsequentDelay > 1 ? this._subsequentDelay : Math.round(this._currentTimeout * this._subsequentDelay)),
  1946. this._minDelay);
  1947. this._timer = setTimeout(dojo.hitch(this, "_fireEventAndReload"), this._currentTimeout);
  1948. },
  1949. trigger: function(/*Event*/ evt, /*Object*/ _this, /*DOMNode*/ node, /*Function*/ callback, /*Object*/ obj, /*Number*/ subsequentDelay, /*Number*/ initialDelay, /*Number?*/ minDelay){
  1950. // summary:
  1951. // Start a timed, repeating callback sequence.
  1952. // If already started, the function call is ignored.
  1953. // This method is not normally called by the user but can be
  1954. // when the normal listener code is insufficient.
  1955. // evt:
  1956. // key or mouse event object to pass to the user callback
  1957. // _this:
  1958. // pointer to the user's widget space.
  1959. // node:
  1960. // the DOM node object to pass the the callback function
  1961. // callback:
  1962. // function to call until the sequence is stopped called with 3 parameters:
  1963. // count:
  1964. // integer representing number of repeated calls (0..n) with -1 indicating the iteration has stopped
  1965. // node:
  1966. // the DOM node object passed in
  1967. // evt:
  1968. // key or mouse event object
  1969. // obj:
  1970. // user space object used to uniquely identify each typematic sequence
  1971. // subsequentDelay (optional):
  1972. // if > 1, the number of milliseconds until the 3->n events occur
  1973. // or else the fractional time multiplier for the next event's delay, default=0.9
  1974. // initialDelay (optional):
  1975. // the number of milliseconds until the 2nd event occurs, default=500ms
  1976. // minDelay (optional):
  1977. // the maximum delay in milliseconds for event to fire, default=10ms
  1978. if(obj != this._obj){
  1979. this.stop();
  1980. this._initialDelay = initialDelay || 500;
  1981. this._subsequentDelay = subsequentDelay || 0.90;
  1982. this._minDelay = minDelay || 10;
  1983. this._obj = obj;
  1984. this._evt = evt;
  1985. this._node = node;
  1986. this._currentTimeout = -1;
  1987. this._count = -1;
  1988. this._callback = dojo.hitch(_this, callback);
  1989. this._fireEventAndReload();
  1990. this._evt = dojo.mixin({faux: true}, evt);
  1991. }
  1992. },
  1993. stop: function(){
  1994. // summary:
  1995. // Stop an ongoing timed, repeating callback sequence.
  1996. if(this._timer){
  1997. clearTimeout(this._timer);
  1998. this._timer = null;
  1999. }
  2000. if(this._obj){
  2001. this._callback(-1, this._node, this._evt);
  2002. this._obj = null;
  2003. }
  2004. },
  2005. addKeyListener: function(/*DOMNode*/ node, /*Object*/ keyObject, /*Object*/ _this, /*Function*/ callback, /*Number*/ subsequentDelay, /*Number*/ initialDelay, /*Number?*/ minDelay){
  2006. // summary:
  2007. // Start listening for a specific typematic key.
  2008. // See also the trigger method for other parameters.
  2009. // keyObject:
  2010. // an object defining the key to listen for:
  2011. // charOrCode:
  2012. // the printable character (string) or keyCode (number) to listen for.
  2013. // keyCode:
  2014. // (deprecated - use charOrCode) the keyCode (number) to listen for (implies charCode = 0).
  2015. // charCode:
  2016. // (deprecated - use charOrCode) the charCode (number) to listen for.
  2017. // ctrlKey:
  2018. // desired ctrl key state to initiate the callback sequence:
  2019. // - pressed (true)
  2020. // - released (false)
  2021. // - either (unspecified)
  2022. // altKey:
  2023. // same as ctrlKey but for the alt key
  2024. // shiftKey:
  2025. // same as ctrlKey but for the shift key
  2026. // returns:
  2027. // an array of dojo.connect handles
  2028. if(keyObject.keyCode){
  2029. keyObject.charOrCode = keyObject.keyCode;
  2030. dojo.deprecated("keyCode attribute parameter for dijit.typematic.addKeyListener is deprecated. Use charOrCode instead.", "", "2.0");
  2031. }else if(keyObject.charCode){
  2032. keyObject.charOrCode = String.fromCharCode(keyObject.charCode);
  2033. dojo.deprecated("charCode attribute parameter for dijit.typematic.addKeyListener is deprecated. Use charOrCode instead.", "", "2.0");
  2034. }
  2035. return [
  2036. dojo.connect(node, "onkeypress", this, function(evt){
  2037. if(evt.charOrCode == keyObject.charOrCode &&
  2038. (keyObject.ctrlKey === undefined || keyObject.ctrlKey == evt.ctrlKey) &&
  2039. (keyObject.altKey === undefined || keyObject.altKey == evt.altKey) &&
  2040. (keyObject.metaKey === undefined || keyObject.metaKey == (evt.metaKey || false)) && // IE doesn't even set metaKey
  2041. (keyObject.shiftKey === undefined || keyObject.shiftKey == evt.shiftKey)){
  2042. dojo.stopEvent(evt);
  2043. dijit.typematic.trigger(evt, _this, node, callback, keyObject, subsequentDelay, initialDelay, minDelay);
  2044. }else if(dijit.typematic._obj == keyObject){
  2045. dijit.typematic.stop();
  2046. }
  2047. }),
  2048. dojo.connect(node, "onkeyup", this, function(evt){
  2049. if(dijit.typematic._obj == keyObject){
  2050. dijit.typematic.stop();
  2051. }
  2052. })
  2053. ];
  2054. },
  2055. addMouseListener: function(/*DOMNode*/ node, /*Object*/ _this, /*Function*/ callback, /*Number*/ subsequentDelay, /*Number*/ initialDelay, /*Number?*/ minDelay){
  2056. // summary:
  2057. // Start listening for a typematic mouse click.
  2058. // See the trigger method for other parameters.
  2059. // returns:
  2060. // an array of dojo.connect handles
  2061. var dc = dojo.connect;
  2062. return [
  2063. dc(node, "mousedown", this, function(evt){
  2064. dojo.stopEvent(evt);
  2065. dijit.typematic.trigger(evt, _this, node, callback, node, subsequentDelay, initialDelay, minDelay);
  2066. }),
  2067. dc(node, "mouseup", this, function(evt){
  2068. dojo.stopEvent(evt);
  2069. dijit.typematic.stop();
  2070. }),
  2071. dc(node, "mouseout", this, function(evt){
  2072. dojo.stopEvent(evt);
  2073. dijit.typematic.stop();
  2074. }),
  2075. dc(node, "mousemove", this, function(evt){
  2076. evt.preventDefault();
  2077. }),
  2078. dc(node, "dblclick", this, function(evt){
  2079. dojo.stopEvent(evt);
  2080. if(dojo.isIE < 9){
  2081. dijit.typematic.trigger(evt, _this, node, callback, node, subsequentDelay, initialDelay, minDelay);
  2082. setTimeout(dojo.hitch(this, dijit.typematic.stop), 50);
  2083. }
  2084. })
  2085. ];
  2086. },
  2087. addListener: function(/*Node*/ mouseNode, /*Node*/ keyNode, /*Object*/ keyObject, /*Object*/ _this, /*Function*/ callback, /*Number*/ subsequentDelay, /*Number*/ initialDelay, /*Number?*/ minDelay){
  2088. // summary:
  2089. // Start listening for a specific typematic key and mouseclick.
  2090. // This is a thin wrapper to addKeyListener and addMouseListener.
  2091. // See the addMouseListener and addKeyListener methods for other parameters.
  2092. // mouseNode:
  2093. // the DOM node object to listen on for mouse events.
  2094. // keyNode:
  2095. // the DOM node object to listen on for key events.
  2096. // returns:
  2097. // an array of dojo.connect handles
  2098. return this.addKeyListener(keyNode, keyObject, _this, callback, subsequentDelay, initialDelay, minDelay).concat(
  2099. this.addMouseListener(mouseNode, _this, callback, subsequentDelay, initialDelay, minDelay));
  2100. }
  2101. };
  2102. }
  2103. if(!dojo._hasResource["dijit._base.wai"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  2104. dojo._hasResource["dijit._base.wai"] = true;
  2105. dojo.provide("dijit._base.wai");
  2106. dijit.wai = {
  2107. onload: function(){
  2108. // summary:
  2109. // Detects if we are in high-contrast mode or not
  2110. // This must be a named function and not an anonymous
  2111. // function, so that the widget parsing code can make sure it
  2112. // registers its onload function after this function.
  2113. // DO NOT USE "this" within this function.
  2114. // create div for testing if high contrast mode is on or images are turned off
  2115. var div = dojo.create("div",{
  2116. id: "a11yTestNode",
  2117. style:{
  2118. cssText:'border: 1px solid;'
  2119. + 'border-color:red green;'
  2120. + 'position: absolute;'
  2121. + 'height: 5px;'
  2122. + 'top: -999px;'
  2123. + 'background-image: url("' + (dojo.config.blankGif || dojo.moduleUrl("dojo", "resources/blank.gif")) + '");'
  2124. }
  2125. }, dojo.body());
  2126. // test it
  2127. var cs = dojo.getComputedStyle(div);
  2128. if(cs){
  2129. var bkImg = cs.backgroundImage;
  2130. var needsA11y = (cs.borderTopColor == cs.borderRightColor) || (bkImg != null && (bkImg == "none" || bkImg == "url(invalid-url:)" ));
  2131. dojo[needsA11y ? "addClass" : "removeClass"](dojo.body(), "dijit_a11y");
  2132. if(dojo.isIE){
  2133. div.outerHTML = ""; // prevent mixed-content warning, see http://support.microsoft.com/kb/925014
  2134. }else{
  2135. dojo.body().removeChild(div);
  2136. }
  2137. }
  2138. }
  2139. };
  2140. // Test if computer is in high contrast mode.
  2141. // Make sure the a11y test runs first, before widgets are instantiated.
  2142. if(dojo.isIE || dojo.isMoz){ // NOTE: checking in Safari messes things up
  2143. dojo._loaders.unshift(dijit.wai.onload);
  2144. }
  2145. dojo.mixin(dijit, {
  2146. hasWaiRole: function(/*Element*/ elem, /*String?*/ role){
  2147. // summary:
  2148. // Determines if an element has a particular role.
  2149. // returns:
  2150. // True if elem has the specific role attribute and false if not.
  2151. // For backwards compatibility if role parameter not provided,
  2152. // returns true if has a role
  2153. var waiRole = this.getWaiRole(elem);
  2154. return role ? (waiRole.indexOf(role) > -1) : (waiRole.length > 0);
  2155. },
  2156. getWaiRole: function(/*Element*/ elem){
  2157. // summary:
  2158. // Gets the role for an element (which should be a wai role).
  2159. // returns:
  2160. // The role of elem or an empty string if elem
  2161. // does not have a role.
  2162. return dojo.trim((dojo.attr(elem, "role") || "").replace("wairole:",""));
  2163. },
  2164. setWaiRole: function(/*Element*/ elem, /*String*/ role){
  2165. // summary:
  2166. // Sets the role on an element.
  2167. // description:
  2168. // Replace existing role attribute with new role.
  2169. dojo.attr(elem, "role", role);
  2170. },
  2171. removeWaiRole: function(/*Element*/ elem, /*String*/ role){
  2172. // summary:
  2173. // Removes the specified role from an element.
  2174. // Removes role attribute if no specific role provided (for backwards compat.)
  2175. var roleValue = dojo.attr(elem, "role");
  2176. if(!roleValue){ return; }
  2177. if(role){
  2178. var t = dojo.trim((" " + roleValue + " ").replace(" " + role + " ", " "));
  2179. dojo.attr(elem, "role", t);
  2180. }else{
  2181. elem.removeAttribute("role");
  2182. }
  2183. },
  2184. hasWaiState: function(/*Element*/ elem, /*String*/ state){
  2185. // summary:
  2186. // Determines if an element has a given state.
  2187. // description:
  2188. // Checks for an attribute called "aria-"+state.
  2189. // returns:
  2190. // true if elem has a value for the given state and
  2191. // false if it does not.
  2192. return elem.hasAttribute ? elem.hasAttribute("aria-"+state) : !!elem.getAttribute("aria-"+state);
  2193. },
  2194. getWaiState: function(/*Element*/ elem, /*String*/ state){
  2195. // summary:
  2196. // Gets the value of a state on an element.
  2197. // description:
  2198. // Checks for an attribute called "aria-"+state.
  2199. // returns:
  2200. // The value of the requested state on elem
  2201. // or an empty string if elem has no value for state.
  2202. return elem.getAttribute("aria-"+state) || "";
  2203. },
  2204. setWaiState: function(/*Element*/ elem, /*String*/ state, /*String*/ value){
  2205. // summary:
  2206. // Sets a state on an element.
  2207. // description:
  2208. // Sets an attribute called "aria-"+state.
  2209. elem.setAttribute("aria-"+state, value);
  2210. },
  2211. removeWaiState: function(/*Element*/ elem, /*String*/ state){
  2212. // summary:
  2213. // Removes a state from an element.
  2214. // description:
  2215. // Sets an attribute called "aria-"+state.
  2216. elem.removeAttribute("aria-"+state);
  2217. }
  2218. });
  2219. }
  2220. if(!dojo._hasResource["dijit._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  2221. dojo._hasResource["dijit._base"] = true;
  2222. dojo.provide("dijit._base");
  2223. }
  2224. if(!dojo._hasResource["dojo.Stateful"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  2225. dojo._hasResource["dojo.Stateful"] = true;
  2226. dojo.provide("dojo.Stateful");
  2227. dojo.declare("dojo.Stateful", null, {
  2228. // summary:
  2229. // Base class for objects that provide named properties with optional getter/setter
  2230. // control and the ability to watch for property changes
  2231. // example:
  2232. // | var obj = new dojo.Stateful();
  2233. // | obj.watch("foo", function(){
  2234. // | console.log("foo changed to " + this.get("foo"));
  2235. // | });
  2236. // | obj.set("foo","bar");
  2237. postscript: function(mixin){
  2238. if(mixin){
  2239. dojo.mixin(this, mixin);
  2240. }
  2241. },
  2242. get: function(/*String*/name){
  2243. // summary:
  2244. // Get a property on a Stateful instance.
  2245. // name:
  2246. // The property to get.
  2247. // description:
  2248. // Get a named property on a Stateful object. The property may
  2249. // potentially be retrieved via a getter method in subclasses. In the base class
  2250. // this just retrieves the object's property.
  2251. // For example:
  2252. // | stateful = new dojo.Stateful({foo: 3});
  2253. // | stateful.get("foo") // returns 3
  2254. // | stateful.foo // returns 3
  2255. return this[name];
  2256. },
  2257. set: function(/*String*/name, /*Object*/value){
  2258. // summary:
  2259. // Set a property on a Stateful instance
  2260. // name:
  2261. // The property to set.
  2262. // value:
  2263. // The value to set in the property.
  2264. // description:
  2265. // Sets named properties on a stateful object and notifies any watchers of
  2266. // the property. A programmatic setter may be defined in subclasses.
  2267. // For example:
  2268. // | stateful = new dojo.Stateful();
  2269. // | stateful.watch(function(name, oldValue, value){
  2270. // | // this will be called on the set below
  2271. // | }
  2272. // | stateful.set(foo, 5);
  2273. //
  2274. // set() may also be called with a hash of name/value pairs, ex:
  2275. // | myObj.set({
  2276. // | foo: "Howdy",
  2277. // | bar: 3
  2278. // | })
  2279. // This is equivalent to calling set(foo, "Howdy") and set(bar, 3)
  2280. if(typeof name === "object"){
  2281. for(var x in name){
  2282. this.set(x, name[x]);
  2283. }
  2284. return this;
  2285. }
  2286. var oldValue = this[name];
  2287. this[name] = value;
  2288. if(this._watchCallbacks){
  2289. this._watchCallbacks(name, oldValue, value);
  2290. }
  2291. return this;
  2292. },
  2293. watch: function(/*String?*/name, /*Function*/callback){
  2294. // summary:
  2295. // Watches a property for changes
  2296. // name:
  2297. // Indicates the property to watch. This is optional (the callback may be the
  2298. // only parameter), and if omitted, all the properties will be watched
  2299. // returns:
  2300. // An object handle for the watch. The unwatch method of this object
  2301. // can be used to discontinue watching this property:
  2302. // | var watchHandle = obj.watch("foo", callback);
  2303. // | watchHandle.unwatch(); // callback won't be called now
  2304. // callback:
  2305. // The function to execute when the property changes. This will be called after
  2306. // the property has been changed. The callback will be called with the |this|
  2307. // set to the instance, the first argument as the name of the property, the
  2308. // second argument as the old value and the third argument as the new value.
  2309. var callbacks = this._watchCallbacks;
  2310. if(!callbacks){
  2311. var self = this;
  2312. callbacks = this._watchCallbacks = function(name, oldValue, value, ignoreCatchall){
  2313. var notify = function(propertyCallbacks){
  2314. if(propertyCallbacks){
  2315. propertyCallbacks = propertyCallbacks.slice();
  2316. for(var i = 0, l = propertyCallbacks.length; i < l; i++){
  2317. try{
  2318. propertyCallbacks[i].call(self, name, oldValue, value);
  2319. }catch(e){
  2320. console.error(e);
  2321. }
  2322. }
  2323. }
  2324. };
  2325. notify(callbacks['_' + name]);
  2326. if(!ignoreCatchall){
  2327. notify(callbacks["*"]); // the catch-all
  2328. }
  2329. }; // we use a function instead of an object so it will be ignored by JSON conversion
  2330. }
  2331. if(!callback && typeof name === "function"){
  2332. callback = name;
  2333. name = "*";
  2334. }else{
  2335. // prepend with dash to prevent name conflicts with function (like "name" property)
  2336. name = '_' + name;
  2337. }
  2338. var propertyCallbacks = callbacks[name];
  2339. if(typeof propertyCallbacks !== "object"){
  2340. propertyCallbacks = callbacks[name] = [];
  2341. }
  2342. propertyCallbacks.push(callback);
  2343. return {
  2344. unwatch: function(){
  2345. propertyCallbacks.splice(dojo.indexOf(propertyCallbacks, callback), 1);
  2346. }
  2347. };
  2348. }
  2349. });
  2350. }
  2351. if(!dojo._hasResource["dijit._WidgetBase"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  2352. dojo._hasResource["dijit._WidgetBase"] = true;
  2353. dojo.provide("dijit._WidgetBase");
  2354. (function(){
  2355. function isEqual(a, b){
  2356. // summary:
  2357. // Function that determines whether two values are identical,
  2358. // taking into account that NaN is not normally equal to itself
  2359. // in JS.
  2360. return a === b || (/* a is NaN */ a !== a && /* b is NaN */ b !== b);
  2361. }
  2362. dojo.declare("dijit._WidgetBase", dojo.Stateful, {
  2363. // summary:
  2364. // Future base class for all Dijit widgets.
  2365. // _Widget extends this class adding support for various features needed by desktop.
  2366. // id: [const] String
  2367. // A unique, opaque ID string that can be assigned by users or by the
  2368. // system. If the developer passes an ID which is known not to be
  2369. // unique, the specified ID is ignored and the system-generated ID is
  2370. // used instead.
  2371. id: "",
  2372. // lang: [const] String
  2373. // Rarely used. Overrides the default Dojo locale used to render this widget,
  2374. // as defined by the [HTML LANG](http://www.w3.org/TR/html401/struct/dirlang.html#adef-lang) attribute.
  2375. // Value must be among the list of locales specified during by the Dojo bootstrap,
  2376. // formatted according to [RFC 3066](http://www.ietf.org/rfc/rfc3066.txt) (like en-us).
  2377. lang: "",
  2378. // dir: [const] String
  2379. // Bi-directional support, as defined by the [HTML DIR](http://www.w3.org/TR/html401/struct/dirlang.html#adef-dir)
  2380. // attribute. Either left-to-right "ltr" or right-to-left "rtl". If undefined, widgets renders in page's
  2381. // default direction.
  2382. dir: "",
  2383. // class: String
  2384. // HTML class attribute
  2385. "class": "",
  2386. // style: String||Object
  2387. // HTML style attributes as cssText string or name/value hash
  2388. style: "",
  2389. // title: String
  2390. // HTML title attribute.
  2391. //
  2392. // For form widgets this specifies a tooltip to display when hovering over
  2393. // the widget (just like the native HTML title attribute).
  2394. //
  2395. // For TitlePane or for when this widget is a child of a TabContainer, AccordionContainer,
  2396. // etc., it's used to specify the tab label, accordion pane title, etc.
  2397. title: "",
  2398. // tooltip: String
  2399. // When this widget's title attribute is used to for a tab label, accordion pane title, etc.,
  2400. // this specifies the tooltip to appear when the mouse is hovered over that text.
  2401. tooltip: "",
  2402. // baseClass: [protected] String
  2403. // Root CSS class of the widget (ex: dijitTextBox), used to construct CSS classes to indicate
  2404. // widget state.
  2405. baseClass: "",
  2406. // srcNodeRef: [readonly] DomNode
  2407. // pointer to original DOM node
  2408. srcNodeRef: null,
  2409. // domNode: [readonly] DomNode
  2410. // This is our visible representation of the widget! Other DOM
  2411. // Nodes may by assigned to other properties, usually through the
  2412. // template system's dojoAttachPoint syntax, but the domNode
  2413. // property is the canonical "top level" node in widget UI.
  2414. domNode: null,
  2415. // containerNode: [readonly] DomNode
  2416. // Designates where children of the source DOM node will be placed.
  2417. // "Children" in this case refers to both DOM nodes and widgets.
  2418. // For example, for myWidget:
  2419. //
  2420. // | <div dojoType=myWidget>
  2421. // | <b> here's a plain DOM node
  2422. // | <span dojoType=subWidget>and a widget</span>
  2423. // | <i> and another plain DOM node </i>
  2424. // | </div>
  2425. //
  2426. // containerNode would point to:
  2427. //
  2428. // | <b> here's a plain DOM node
  2429. // | <span dojoType=subWidget>and a widget</span>
  2430. // | <i> and another plain DOM node </i>
  2431. //
  2432. // In templated widgets, "containerNode" is set via a
  2433. // dojoAttachPoint assignment.
  2434. //
  2435. // containerNode must be defined for any widget that accepts innerHTML
  2436. // (like ContentPane or BorderContainer or even Button), and conversely
  2437. // is null for widgets that don't, like TextBox.
  2438. containerNode: null,
  2439. /*=====
  2440. // _started: Boolean
  2441. // startup() has completed.
  2442. _started: false,
  2443. =====*/
  2444. // attributeMap: [protected] Object
  2445. // attributeMap sets up a "binding" between attributes (aka properties)
  2446. // of the widget and the widget's DOM.
  2447. // Changes to widget attributes listed in attributeMap will be
  2448. // reflected into the DOM.
  2449. //
  2450. // For example, calling set('title', 'hello')
  2451. // on a TitlePane will automatically cause the TitlePane's DOM to update
  2452. // with the new title.
  2453. //
  2454. // attributeMap is a hash where the key is an attribute of the widget,
  2455. // and the value reflects a binding to a:
  2456. //
  2457. // - DOM node attribute
  2458. // | focus: {node: "focusNode", type: "attribute"}
  2459. // Maps this.focus to this.focusNode.focus
  2460. //
  2461. // - DOM node innerHTML
  2462. // | title: { node: "titleNode", type: "innerHTML" }
  2463. // Maps this.title to this.titleNode.innerHTML
  2464. //
  2465. // - DOM node innerText
  2466. // | title: { node: "titleNode", type: "innerText" }
  2467. // Maps this.title to this.titleNode.innerText
  2468. //
  2469. // - DOM node CSS class
  2470. // | myClass: { node: "domNode", type: "class" }
  2471. // Maps this.myClass to this.domNode.className
  2472. //
  2473. // If the value is an array, then each element in the array matches one of the
  2474. // formats of the above list.
  2475. //
  2476. // There are also some shorthands for backwards compatibility:
  2477. // - string --> { node: string, type: "attribute" }, for example:
  2478. // | "focusNode" ---> { node: "focusNode", type: "attribute" }
  2479. // - "" --> { node: "domNode", type: "attribute" }
  2480. attributeMap: {id:"", dir:"", lang:"", "class":"", style:"", title:""},
  2481. // _blankGif: [protected] String
  2482. // Path to a blank 1x1 image.
  2483. // Used by <img> nodes in templates that really get their image via CSS background-image.
  2484. _blankGif: (dojo.config.blankGif || dojo.moduleUrl("dojo", "resources/blank.gif")).toString(),
  2485. //////////// INITIALIZATION METHODS ///////////////////////////////////////
  2486. postscript: function(/*Object?*/params, /*DomNode|String*/srcNodeRef){
  2487. // summary:
  2488. // Kicks off widget instantiation. See create() for details.
  2489. // tags:
  2490. // private
  2491. this.create(params, srcNodeRef);
  2492. },
  2493. create: function(/*Object?*/params, /*DomNode|String?*/srcNodeRef){
  2494. // summary:
  2495. // Kick off the life-cycle of a widget
  2496. // params:
  2497. // Hash of initialization parameters for widget, including
  2498. // scalar values (like title, duration etc.) and functions,
  2499. // typically callbacks like onClick.
  2500. // srcNodeRef:
  2501. // If a srcNodeRef (DOM node) is specified:
  2502. // - use srcNodeRef.innerHTML as my contents
  2503. // - if this is a behavioral widget then apply behavior
  2504. // to that srcNodeRef
  2505. // - otherwise, replace srcNodeRef with my generated DOM
  2506. // tree
  2507. // description:
  2508. // Create calls a number of widget methods (postMixInProperties, buildRendering, postCreate,
  2509. // etc.), some of which of you'll want to override. See http://docs.dojocampus.org/dijit/_Widget
  2510. // for a discussion of the widget creation lifecycle.
  2511. //
  2512. // Of course, adventurous developers could override create entirely, but this should
  2513. // only be done as a last resort.
  2514. // tags:
  2515. // private
  2516. // store pointer to original DOM tree
  2517. this.srcNodeRef = dojo.byId(srcNodeRef);
  2518. // For garbage collection. An array of handles returned by Widget.connect()
  2519. // Each handle returned from Widget.connect() is an array of handles from dojo.connect()
  2520. this._connects = [];
  2521. // For garbage collection. An array of handles returned by Widget.subscribe()
  2522. // The handle returned from Widget.subscribe() is the handle returned from dojo.subscribe()
  2523. this._subscribes = [];
  2524. // mix in our passed parameters
  2525. if(this.srcNodeRef && (typeof this.srcNodeRef.id == "string")){ this.id = this.srcNodeRef.id; }
  2526. if(params){
  2527. this.params = params;
  2528. dojo._mixin(this, params);
  2529. }
  2530. this.postMixInProperties();
  2531. // generate an id for the widget if one wasn't specified
  2532. // (be sure to do this before buildRendering() because that function might
  2533. // expect the id to be there.)
  2534. if(!this.id){
  2535. this.id = dijit.getUniqueId(this.declaredClass.replace(/\./g,"_"));
  2536. }
  2537. dijit.registry.add(this);
  2538. this.buildRendering();
  2539. if(this.domNode){
  2540. // Copy attributes listed in attributeMap into the [newly created] DOM for the widget.
  2541. // Also calls custom setters for all attributes with custom setters.
  2542. this._applyAttributes();
  2543. // If srcNodeRef was specified, then swap out original srcNode for this widget's DOM tree.
  2544. // For 2.0, move this after postCreate(). postCreate() shouldn't depend on the
  2545. // widget being attached to the DOM since it isn't when a widget is created programmatically like
  2546. // new MyWidget({}). See #11635.
  2547. var source = this.srcNodeRef;
  2548. if(source && source.parentNode && this.domNode !== source){
  2549. source.parentNode.replaceChild(this.domNode, source);
  2550. }
  2551. }
  2552. if(this.domNode){
  2553. // Note: for 2.0 may want to rename widgetId to dojo._scopeName + "_widgetId",
  2554. // assuming that dojo._scopeName even exists in 2.0
  2555. this.domNode.setAttribute("widgetId", this.id);
  2556. }
  2557. this.postCreate();
  2558. // If srcNodeRef has been processed and removed from the DOM (e.g. TemplatedWidget) then delete it to allow GC.
  2559. if(this.srcNodeRef && !this.srcNodeRef.parentNode){
  2560. delete this.srcNodeRef;
  2561. }
  2562. this._created = true;
  2563. },
  2564. _applyAttributes: function(){
  2565. // summary:
  2566. // Step during widget creation to copy all widget attributes to the
  2567. // DOM as per attributeMap and _setXXXAttr functions.
  2568. // description:
  2569. // Skips over blank/false attribute values, unless they were explicitly specified
  2570. // as parameters to the widget, since those are the default anyway,
  2571. // and setting tabIndex="" is different than not setting tabIndex at all.
  2572. //
  2573. // It processes the attributes in the attribute map first, and then
  2574. // it goes through and processes the attributes for the _setXXXAttr
  2575. // functions that have been specified
  2576. // tags:
  2577. // private
  2578. var condAttrApply = function(attr, scope){
  2579. if((scope.params && attr in scope.params) || scope[attr]){
  2580. scope.set(attr, scope[attr]);
  2581. }
  2582. };
  2583. // Do the attributes in attributeMap
  2584. for(var attr in this.attributeMap){
  2585. condAttrApply(attr, this);
  2586. }
  2587. // And also any attributes with custom setters
  2588. dojo.forEach(this._getSetterAttributes(), function(a){
  2589. if(!(a in this.attributeMap)){
  2590. condAttrApply(a, this);
  2591. }
  2592. }, this);
  2593. },
  2594. _getSetterAttributes: function(){
  2595. // summary:
  2596. // Returns list of attributes with custom setters for this widget
  2597. var ctor = this.constructor;
  2598. if(!ctor._setterAttrs){
  2599. var r = (ctor._setterAttrs = []),
  2600. attrs,
  2601. proto = ctor.prototype;
  2602. for(var fxName in proto){
  2603. if(dojo.isFunction(proto[fxName]) && (attrs = fxName.match(/^_set([a-zA-Z]*)Attr$/)) && attrs[1]){
  2604. r.push(attrs[1].charAt(0).toLowerCase() + attrs[1].substr(1));
  2605. }
  2606. }
  2607. }
  2608. return ctor._setterAttrs; // String[]
  2609. },
  2610. postMixInProperties: function(){
  2611. // summary:
  2612. // Called after the parameters to the widget have been read-in,
  2613. // but before the widget template is instantiated. Especially
  2614. // useful to set properties that are referenced in the widget
  2615. // template.
  2616. // tags:
  2617. // protected
  2618. },
  2619. buildRendering: function(){
  2620. // summary:
  2621. // Construct the UI for this widget, setting this.domNode
  2622. // description:
  2623. // Most widgets will mixin `dijit._Templated`, which implements this
  2624. // method.
  2625. // tags:
  2626. // protected
  2627. if(!this.domNode){
  2628. // Create root node if it wasn't created by _Templated
  2629. this.domNode = this.srcNodeRef || dojo.create('div');
  2630. }
  2631. // baseClass is a single class name or occasionally a space-separated list of names.
  2632. // Add those classes to the DOMNode. If RTL mode then also add with Rtl suffix.
  2633. // TODO: make baseClass custom setter
  2634. if(this.baseClass){
  2635. var classes = this.baseClass.split(" ");
  2636. if(!this.isLeftToRight()){
  2637. classes = classes.concat( dojo.map(classes, function(name){ return name+"Rtl"; }));
  2638. }
  2639. dojo.addClass(this.domNode, classes);
  2640. }
  2641. },
  2642. postCreate: function(){
  2643. // summary:
  2644. // Processing after the DOM fragment is created
  2645. // description:
  2646. // Called after the DOM fragment has been created, but not necessarily
  2647. // added to the document. Do not include any operations which rely on
  2648. // node dimensions or placement.
  2649. // tags:
  2650. // protected
  2651. },
  2652. startup: function(){
  2653. // summary:
  2654. // Processing after the DOM fragment is added to the document
  2655. // description:
  2656. // Called after a widget and its children have been created and added to the page,
  2657. // and all related widgets have finished their create() cycle, up through postCreate().
  2658. // This is useful for composite widgets that need to control or layout sub-widgets.
  2659. // Many layout widgets can use this as a wiring phase.
  2660. this._started = true;
  2661. },
  2662. //////////// DESTROY FUNCTIONS ////////////////////////////////
  2663. destroyRecursive: function(/*Boolean?*/ preserveDom){
  2664. // summary:
  2665. // Destroy this widget and its descendants
  2666. // description:
  2667. // This is the generic "destructor" function that all widget users
  2668. // should call to cleanly discard with a widget. Once a widget is
  2669. // destroyed, it is removed from the manager object.
  2670. // preserveDom:
  2671. // If true, this method will leave the original DOM structure
  2672. // alone of descendant Widgets. Note: This will NOT work with
  2673. // dijit._Templated widgets.
  2674. this._beingDestroyed = true;
  2675. this.destroyDescendants(preserveDom);
  2676. this.destroy(preserveDom);
  2677. },
  2678. destroy: function(/*Boolean*/ preserveDom){
  2679. // summary:
  2680. // Destroy this widget, but not its descendants.
  2681. // This method will, however, destroy internal widgets such as those used within a template.
  2682. // preserveDom: Boolean
  2683. // If true, this method will leave the original DOM structure alone.
  2684. // Note: This will not yet work with _Templated widgets
  2685. this._beingDestroyed = true;
  2686. this.uninitialize();
  2687. var d = dojo,
  2688. dfe = d.forEach,
  2689. dun = d.unsubscribe;
  2690. dfe(this._connects, function(array){
  2691. dfe(array, d.disconnect);
  2692. });
  2693. dfe(this._subscribes, function(handle){
  2694. dun(handle);
  2695. });
  2696. // destroy widgets created as part of template, etc.
  2697. dfe(this._supportingWidgets || [], function(w){
  2698. if(w.destroyRecursive){
  2699. w.destroyRecursive();
  2700. }else if(w.destroy){
  2701. w.destroy();
  2702. }
  2703. });
  2704. this.destroyRendering(preserveDom);
  2705. dijit.registry.remove(this.id);
  2706. this._destroyed = true;
  2707. },
  2708. destroyRendering: function(/*Boolean?*/ preserveDom){
  2709. // summary:
  2710. // Destroys the DOM nodes associated with this widget
  2711. // preserveDom:
  2712. // If true, this method will leave the original DOM structure alone
  2713. // during tear-down. Note: this will not work with _Templated
  2714. // widgets yet.
  2715. // tags:
  2716. // protected
  2717. if(this.bgIframe){
  2718. this.bgIframe.destroy(preserveDom);
  2719. delete this.bgIframe;
  2720. }
  2721. if(this.domNode){
  2722. if(preserveDom){
  2723. dojo.removeAttr(this.domNode, "widgetId");
  2724. }else{
  2725. dojo.destroy(this.domNode);
  2726. }
  2727. delete this.domNode;
  2728. }
  2729. if(this.srcNodeRef){
  2730. if(!preserveDom){
  2731. dojo.destroy(this.srcNodeRef);
  2732. }
  2733. delete this.srcNodeRef;
  2734. }
  2735. },
  2736. destroyDescendants: function(/*Boolean?*/ preserveDom){
  2737. // summary:
  2738. // Recursively destroy the children of this widget and their
  2739. // descendants.
  2740. // preserveDom:
  2741. // If true, the preserveDom attribute is passed to all descendant
  2742. // widget's .destroy() method. Not for use with _Templated
  2743. // widgets.
  2744. // get all direct descendants and destroy them recursively
  2745. dojo.forEach(this.getChildren(), function(widget){
  2746. if(widget.destroyRecursive){
  2747. widget.destroyRecursive(preserveDom);
  2748. }
  2749. });
  2750. },
  2751. uninitialize: function(){
  2752. // summary:
  2753. // Stub function. Override to implement custom widget tear-down
  2754. // behavior.
  2755. // tags:
  2756. // protected
  2757. return false;
  2758. },
  2759. ////////////////// GET/SET, CUSTOM SETTERS, ETC. ///////////////////
  2760. _setClassAttr: function(/*String*/ value){
  2761. // summary:
  2762. // Custom setter for the CSS "class" attribute
  2763. // tags:
  2764. // protected
  2765. var mapNode = this[this.attributeMap["class"] || 'domNode'];
  2766. dojo.replaceClass(mapNode, value, this["class"]);
  2767. this._set("class", value);
  2768. },
  2769. _setStyleAttr: function(/*String||Object*/ value){
  2770. // summary:
  2771. // Sets the style attribute of the widget according to value,
  2772. // which is either a hash like {height: "5px", width: "3px"}
  2773. // or a plain string
  2774. // description:
  2775. // Determines which node to set the style on based on style setting
  2776. // in attributeMap.
  2777. // tags:
  2778. // protected
  2779. var mapNode = this[this.attributeMap.style || 'domNode'];
  2780. // Note: technically we should revert any style setting made in a previous call
  2781. // to his method, but that's difficult to keep track of.
  2782. if(dojo.isObject(value)){
  2783. dojo.style(mapNode, value);
  2784. }else{
  2785. if(mapNode.style.cssText){
  2786. mapNode.style.cssText += "; " + value;
  2787. }else{
  2788. mapNode.style.cssText = value;
  2789. }
  2790. }
  2791. this._set("style", value);
  2792. },
  2793. _attrToDom: function(/*String*/ attr, /*String*/ value){
  2794. // summary:
  2795. // Reflect a widget attribute (title, tabIndex, duration etc.) to
  2796. // the widget DOM, as specified in attributeMap.
  2797. // Note some attributes like "type"
  2798. // cannot be processed this way as they are not mutable.
  2799. //
  2800. // tags:
  2801. // private
  2802. var commands = this.attributeMap[attr];
  2803. dojo.forEach(dojo.isArray(commands) ? commands : [commands], function(command){
  2804. // Get target node and what we are doing to that node
  2805. var mapNode = this[command.node || command || "domNode"]; // DOM node
  2806. var type = command.type || "attribute"; // class, innerHTML, innerText, or attribute
  2807. switch(type){
  2808. case "attribute":
  2809. if(dojo.isFunction(value)){ // functions execute in the context of the widget
  2810. value = dojo.hitch(this, value);
  2811. }
  2812. // Get the name of the DOM node attribute; usually it's the same
  2813. // as the name of the attribute in the widget (attr), but can be overridden.
  2814. // Also maps handler names to lowercase, like onSubmit --> onsubmit
  2815. var attrName = command.attribute ? command.attribute :
  2816. (/^on[A-Z][a-zA-Z]*$/.test(attr) ? attr.toLowerCase() : attr);
  2817. dojo.attr(mapNode, attrName, value);
  2818. break;
  2819. case "innerText":
  2820. mapNode.innerHTML = "";
  2821. mapNode.appendChild(dojo.doc.createTextNode(value));
  2822. break;
  2823. case "innerHTML":
  2824. mapNode.innerHTML = value;
  2825. break;
  2826. case "class":
  2827. dojo.replaceClass(mapNode, value, this[attr]);
  2828. break;
  2829. }
  2830. }, this);
  2831. },
  2832. get: function(name){
  2833. // summary:
  2834. // Get a property from a widget.
  2835. // name:
  2836. // The property to get.
  2837. // description:
  2838. // Get a named property from a widget. The property may
  2839. // potentially be retrieved via a getter method. If no getter is defined, this
  2840. // just retrieves the object's property.
  2841. // For example, if the widget has a properties "foo"
  2842. // and "bar" and a method named "_getFooAttr", calling:
  2843. // | myWidget.get("foo");
  2844. // would be equivalent to writing:
  2845. // | widget._getFooAttr();
  2846. // and:
  2847. // | myWidget.get("bar");
  2848. // would be equivalent to writing:
  2849. // | widget.bar;
  2850. var names = this._getAttrNames(name);
  2851. return this[names.g] ? this[names.g]() : this[name];
  2852. },
  2853. set: function(name, value){
  2854. // summary:
  2855. // Set a property on a widget
  2856. // name:
  2857. // The property to set.
  2858. // value:
  2859. // The value to set in the property.
  2860. // description:
  2861. // Sets named properties on a widget which may potentially be handled by a
  2862. // setter in the widget.
  2863. // For example, if the widget has a properties "foo"
  2864. // and "bar" and a method named "_setFooAttr", calling:
  2865. // | myWidget.set("foo", "Howdy!");
  2866. // would be equivalent to writing:
  2867. // | widget._setFooAttr("Howdy!");
  2868. // and:
  2869. // | myWidget.set("bar", 3);
  2870. // would be equivalent to writing:
  2871. // | widget.bar = 3;
  2872. //
  2873. // set() may also be called with a hash of name/value pairs, ex:
  2874. // | myWidget.set({
  2875. // | foo: "Howdy",
  2876. // | bar: 3
  2877. // | })
  2878. // This is equivalent to calling set(foo, "Howdy") and set(bar, 3)
  2879. if(typeof name === "object"){
  2880. for(var x in name){
  2881. this.set(x, name[x]);
  2882. }
  2883. return this;
  2884. }
  2885. var names = this._getAttrNames(name);
  2886. if(this[names.s]){
  2887. // use the explicit setter
  2888. var result = this[names.s].apply(this, Array.prototype.slice.call(arguments, 1));
  2889. }else{
  2890. // if param is specified as DOM node attribute, copy it
  2891. if(name in this.attributeMap){
  2892. this._attrToDom(name, value);
  2893. }
  2894. this._set(name, value);
  2895. }
  2896. return result || this;
  2897. },
  2898. _attrPairNames: {}, // shared between all widgets
  2899. _getAttrNames: function(name){
  2900. // summary:
  2901. // Helper function for get() and set().
  2902. // Caches attribute name values so we don't do the string ops every time.
  2903. // tags:
  2904. // private
  2905. var apn = this._attrPairNames;
  2906. if(apn[name]){ return apn[name]; }
  2907. var uc = name.charAt(0).toUpperCase() + name.substr(1);
  2908. return (apn[name] = {
  2909. n: name+"Node",
  2910. s: "_set"+uc+"Attr",
  2911. g: "_get"+uc+"Attr"
  2912. });
  2913. },
  2914. _set: function(/*String*/ name, /*anything*/ value){
  2915. // summary:
  2916. // Helper function to set new value for specified attribute, and call handlers
  2917. // registered with watch() if the value has changed.
  2918. var oldValue = this[name];
  2919. this[name] = value;
  2920. if(this._watchCallbacks && this._created && !isEqual(value, oldValue)){
  2921. this._watchCallbacks(name, oldValue, value);
  2922. }
  2923. },
  2924. toString: function(){
  2925. // summary:
  2926. // Returns a string that represents the widget
  2927. // description:
  2928. // When a widget is cast to a string, this method will be used to generate the
  2929. // output. Currently, it does not implement any sort of reversible
  2930. // serialization.
  2931. return '[Widget ' + this.declaredClass + ', ' + (this.id || 'NO ID') + ']'; // String
  2932. },
  2933. getDescendants: function(){
  2934. // summary:
  2935. // Returns all the widgets contained by this, i.e., all widgets underneath this.containerNode.
  2936. // This method should generally be avoided as it returns widgets declared in templates, which are
  2937. // supposed to be internal/hidden, but it's left here for back-compat reasons.
  2938. return this.containerNode ? dojo.query('[widgetId]', this.containerNode).map(dijit.byNode) : []; // dijit._Widget[]
  2939. },
  2940. getChildren: function(){
  2941. // summary:
  2942. // Returns all the widgets contained by this, i.e., all widgets underneath this.containerNode.
  2943. // Does not return nested widgets, nor widgets that are part of this widget's template.
  2944. return this.containerNode ? dijit.findWidgets(this.containerNode) : []; // dijit._Widget[]
  2945. },
  2946. connect: function(
  2947. /*Object|null*/ obj,
  2948. /*String|Function*/ event,
  2949. /*String|Function*/ method){
  2950. // summary:
  2951. // Connects specified obj/event to specified method of this object
  2952. // and registers for disconnect() on widget destroy.
  2953. // description:
  2954. // Provide widget-specific analog to dojo.connect, except with the
  2955. // implicit use of this widget as the target object.
  2956. // Events connected with `this.connect` are disconnected upon
  2957. // destruction.
  2958. // returns:
  2959. // A handle that can be passed to `disconnect` in order to disconnect before
  2960. // the widget is destroyed.
  2961. // example:
  2962. // | var btn = new dijit.form.Button();
  2963. // | // when foo.bar() is called, call the listener we're going to
  2964. // | // provide in the scope of btn
  2965. // | btn.connect(foo, "bar", function(){
  2966. // | console.debug(this.toString());
  2967. // | });
  2968. // tags:
  2969. // protected
  2970. var handles = [dojo._connect(obj, event, this, method)];
  2971. this._connects.push(handles);
  2972. return handles; // _Widget.Handle
  2973. },
  2974. disconnect: function(/* _Widget.Handle */ handles){
  2975. // summary:
  2976. // Disconnects handle created by `connect`.
  2977. // Also removes handle from this widget's list of connects.
  2978. // tags:
  2979. // protected
  2980. for(var i=0; i<this._connects.length; i++){
  2981. if(this._connects[i] == handles){
  2982. dojo.forEach(handles, dojo.disconnect);
  2983. this._connects.splice(i, 1);
  2984. return;
  2985. }
  2986. }
  2987. },
  2988. subscribe: function(
  2989. /*String*/ topic,
  2990. /*String|Function*/ method){
  2991. // summary:
  2992. // Subscribes to the specified topic and calls the specified method
  2993. // of this object and registers for unsubscribe() on widget destroy.
  2994. // description:
  2995. // Provide widget-specific analog to dojo.subscribe, except with the
  2996. // implicit use of this widget as the target object.
  2997. // example:
  2998. // | var btn = new dijit.form.Button();
  2999. // | // when /my/topic is published, this button changes its label to
  3000. // | // be the parameter of the topic.
  3001. // | btn.subscribe("/my/topic", function(v){
  3002. // | this.set("label", v);
  3003. // | });
  3004. var handle = dojo.subscribe(topic, this, method);
  3005. // return handles for Any widget that may need them
  3006. this._subscribes.push(handle);
  3007. return handle;
  3008. },
  3009. unsubscribe: function(/*Object*/ handle){
  3010. // summary:
  3011. // Unsubscribes handle created by this.subscribe.
  3012. // Also removes handle from this widget's list of subscriptions
  3013. for(var i=0; i<this._subscribes.length; i++){
  3014. if(this._subscribes[i] == handle){
  3015. dojo.unsubscribe(handle);
  3016. this._subscribes.splice(i, 1);
  3017. return;
  3018. }
  3019. }
  3020. },
  3021. isLeftToRight: function(){
  3022. // summary:
  3023. // Return this widget's explicit or implicit orientation (true for LTR, false for RTL)
  3024. // tags:
  3025. // protected
  3026. return this.dir ? (this.dir == "ltr") : dojo._isBodyLtr(); //Boolean
  3027. },
  3028. placeAt: function(/* String|DomNode|_Widget */reference, /* String?|Int? */position){
  3029. // summary:
  3030. // Place this widget's domNode reference somewhere in the DOM based
  3031. // on standard dojo.place conventions, or passing a Widget reference that
  3032. // contains and addChild member.
  3033. //
  3034. // description:
  3035. // A convenience function provided in all _Widgets, providing a simple
  3036. // shorthand mechanism to put an existing (or newly created) Widget
  3037. // somewhere in the dom, and allow chaining.
  3038. //
  3039. // reference:
  3040. // The String id of a domNode, a domNode reference, or a reference to a Widget posessing
  3041. // an addChild method.
  3042. //
  3043. // position:
  3044. // If passed a string or domNode reference, the position argument
  3045. // accepts a string just as dojo.place does, one of: "first", "last",
  3046. // "before", or "after".
  3047. //
  3048. // If passed a _Widget reference, and that widget reference has an ".addChild" method,
  3049. // it will be called passing this widget instance into that method, supplying the optional
  3050. // position index passed.
  3051. //
  3052. // returns:
  3053. // dijit._Widget
  3054. // Provides a useful return of the newly created dijit._Widget instance so you
  3055. // can "chain" this function by instantiating, placing, then saving the return value
  3056. // to a variable.
  3057. //
  3058. // example:
  3059. // | // create a Button with no srcNodeRef, and place it in the body:
  3060. // | var button = new dijit.form.Button({ label:"click" }).placeAt(dojo.body());
  3061. // | // now, 'button' is still the widget reference to the newly created button
  3062. // | dojo.connect(button, "onClick", function(e){ console.log('click'); });
  3063. //
  3064. // example:
  3065. // | // create a button out of a node with id="src" and append it to id="wrapper":
  3066. // | var button = new dijit.form.Button({},"src").placeAt("wrapper");
  3067. //
  3068. // example:
  3069. // | // place a new button as the first element of some div
  3070. // | var button = new dijit.form.Button({ label:"click" }).placeAt("wrapper","first");
  3071. //
  3072. // example:
  3073. // | // create a contentpane and add it to a TabContainer
  3074. // | var tc = dijit.byId("myTabs");
  3075. // | new dijit.layout.ContentPane({ href:"foo.html", title:"Wow!" }).placeAt(tc)
  3076. if(reference.declaredClass && reference.addChild){
  3077. reference.addChild(this, position);
  3078. }else{
  3079. dojo.place(this.domNode, reference, position);
  3080. }
  3081. return this;
  3082. },
  3083. defer: function(fcn, delay){
  3084. // summary:
  3085. // Wrapper to setTimeout to avoid deferred functions executing
  3086. // after the originating widget has been destroyed.
  3087. // Returns an object handle with a remove method (that returns null) (replaces clearTimeout).
  3088. // fcn: function reference
  3089. // delay: Optional number (defaults to 0)
  3090. // tags:
  3091. // protected.
  3092. var timer = setTimeout(dojo.hitch(this,
  3093. function(){
  3094. timer = null;
  3095. if(!this._destroyed){
  3096. dojo.hitch(this, fcn)();
  3097. }
  3098. }),
  3099. delay || 0
  3100. );
  3101. return {
  3102. remove: function(){
  3103. if(timer){
  3104. clearTimeout(timer);
  3105. timer = null;
  3106. }
  3107. return null; // so this works well: handle = handle.remove();
  3108. }
  3109. };
  3110. }
  3111. });
  3112. })();
  3113. }
  3114. if(!dojo._hasResource["dojox.mobile._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  3115. dojo._hasResource["dojox.mobile._base"] = true;
  3116. dojo.provide("dojox.mobile._base");
  3117. dojo.isBB = (navigator.userAgent.indexOf("BlackBerry") != -1) && !dojo.isWebKit;
  3118. // summary:
  3119. // Mobile Widgets
  3120. // description:
  3121. // This module provides a number of widgets that can be used to build
  3122. // web-based applications for mobile devices such as iPhone or Android.
  3123. // These widgets work best with webkit-based browsers, such as Safari or
  3124. // Chrome, since webkit-specific CSS3 features are used.
  3125. // However, the widgets should work in a "graceful degradation" manner
  3126. // even on non-CSS3 browsers, such as IE or Firefox. In that case,
  3127. // fancy effects, such as animation, gradient color, or round corner
  3128. // rectangle, may not work, but you can still operate your application.
  3129. //
  3130. // Furthermore, as a separate file, a compatibility module,
  3131. // dojox.mobile.compat, is available that simulates some of CSS3 features
  3132. // used in this module. If you use the compatibility module, fancy visual
  3133. // effects work better even on non-CSS3 browsers.
  3134. //
  3135. // Note that use of dijit._Container, dijit._Contained, dijit._Templated,
  3136. // and dojo.query is intentionally avoided to reduce download code size.
  3137. dojo.declare(
  3138. "dojox.mobile.View",
  3139. dijit._WidgetBase,
  3140. {
  3141. // summary:
  3142. // A widget that represents a view that occupies the full screen
  3143. // description:
  3144. // View acts as a container for any HTML and/or widgets. An entire HTML page
  3145. // can have multiple View widgets and the user can navigate through
  3146. // the views back and forth without page transitions.
  3147. // selected: Boolean
  3148. // If true, the view is displayed at startup time.
  3149. selected: false,
  3150. // keepScrollPos: Boolean
  3151. // If true, the scroll position is kept between views.
  3152. keepScrollPos: true,
  3153. _started: false,
  3154. constructor: function(params, node){
  3155. if(node){
  3156. dojo.byId(node).style.visibility = "hidden";
  3157. }
  3158. },
  3159. buildRendering: function(){
  3160. this.domNode = this.containerNode = this.srcNodeRef || dojo.doc.createElement("DIV");
  3161. this.domNode.className = "mblView";
  3162. this.connect(this.domNode, "webkitAnimationEnd", "onAnimationEnd");
  3163. this.connect(this.domNode, "webkitAnimationStart", "onAnimationStart");
  3164. var id = location.href.match(/#(\w+)([^\w=]|$)/) ? RegExp.$1 : null;
  3165. this._visible = this.selected && !id || this.id == id;
  3166. if(this.selected){
  3167. dojox.mobile._defaultView = this;
  3168. }
  3169. },
  3170. startup: function(){
  3171. if(this._started){ return; }
  3172. var _this = this;
  3173. setTimeout(function(){
  3174. if(!_this._visible){
  3175. _this.domNode.style.display = "none";
  3176. }else{
  3177. dojox.mobile.currentView = _this;
  3178. _this.onStartView();
  3179. }
  3180. _this.domNode.style.visibility = "visible";
  3181. }, dojo.isIE?100:0); // give IE a little time to complete drawing
  3182. this._started = true;
  3183. },
  3184. onStartView: function(){
  3185. // Stub function to connect to from your application.
  3186. // Called only when this view is shown at startup time.
  3187. },
  3188. onBeforeTransitionIn: function(moveTo, dir, transition, context, method){
  3189. // Stub function to connect to from your application.
  3190. },
  3191. onAfterTransitionIn: function(moveTo, dir, transition, context, method){
  3192. // Stub function to connect to from your application.
  3193. },
  3194. onBeforeTransitionOut: function(moveTo, dir, transition, context, method){
  3195. // Stub function to connect to from your application.
  3196. },
  3197. onAfterTransitionOut: function(moveTo, dir, transition, context, method){
  3198. // Stub function to connect to from your application.
  3199. },
  3200. _saveState: function(moveTo, dir, transition, context, method){
  3201. this._context = context;
  3202. this._method = method;
  3203. if(transition == "none" || !dojo.isWebKit){
  3204. transition = null;
  3205. }
  3206. this._moveTo = moveTo;
  3207. this._dir = dir;
  3208. this._transition = transition;
  3209. this._arguments = [];
  3210. var i;
  3211. for(i = 0; i < arguments.length; i++){
  3212. this._arguments.push(arguments[i]);
  3213. }
  3214. this._args = [];
  3215. if(context || method){
  3216. for(i = 5; i < arguments.length; i++){
  3217. this._args.push(arguments[i]);
  3218. }
  3219. }
  3220. },
  3221. performTransition: function(/*String*/moveTo, /*Number*/dir, /*String*/transition,
  3222. /*Object|null*/context, /*String|Function*/method /*optional args*/){
  3223. // summary:
  3224. // Function to perform the various types of view transitions, such as fade, slide, and flip.
  3225. // moveTo: String
  3226. // The destination view id to transition the current view to.
  3227. // If null, transitions to a blank view.
  3228. // dir: Number
  3229. // The transition direction. If 1, transition forward. If -1, transition backward.
  3230. // For example, the slide transition slides the view from right to left when dir == 1,
  3231. // and from left to right when dir == -1.
  3232. // transision: String
  3233. // The type of transition to perform. "slide", "fade", or "flip"
  3234. // context: Object
  3235. // The object that the callback function will receive as "this".
  3236. // method: String|Function
  3237. // A callback function that is called when the transition has been finished.
  3238. // A function reference, or name of a function in context.
  3239. // tags:
  3240. // public
  3241. // example:
  3242. // Transitions to the blank view, and then opens another page.
  3243. // | performTransition(null, 1, "slide", null, function(){location.href = href;});
  3244. if(dojo.hash){
  3245. if(typeof(moveTo) == "string" && moveTo.charAt(0) == '#' && !dojox.mobile._params){
  3246. dojox.mobile._params = [];
  3247. for(var i = 0; i < arguments.length; i++){
  3248. dojox.mobile._params.push(arguments[i]);
  3249. }
  3250. dojo.hash(moveTo);
  3251. return;
  3252. }
  3253. }
  3254. this._saveState.apply(this, arguments);
  3255. var toNode;
  3256. if(moveTo){
  3257. if(typeof(moveTo) == "string"){
  3258. // removes a leading hash mark (#) and params if exists
  3259. // ex. "#bar&myParam=0003" -> "bar"
  3260. moveTo.match(/^#?([^&?]+)/);
  3261. toNode = RegExp.$1;
  3262. }else{
  3263. toNode = moveTo;
  3264. }
  3265. }else{
  3266. if(!this._dummyNode){
  3267. this._dummyNode = dojo.doc.createElement("DIV");
  3268. dojo.body().appendChild(this._dummyNode);
  3269. }
  3270. toNode = this._dummyNode;
  3271. }
  3272. var fromNode = this.domNode;
  3273. toNode = this.toNode = dojo.byId(toNode);
  3274. if(!toNode){ alert("dojox.mobile.View#performTransition: destination view not found: "+toNode); }
  3275. toNode.style.visibility = "hidden";
  3276. toNode.style.display = "";
  3277. this.onBeforeTransitionOut.apply(this, arguments);
  3278. var toWidget = dijit.byNode(toNode);
  3279. if(toWidget){
  3280. // perform view transition keeping the scroll position
  3281. if(this.keepScrollPos && !dijit.getEnclosingWidget(this.domNode.parentNode)){
  3282. var scrollTop = dojo.body().scrollTop || dojo.doc.documentElement.scrollTop || dojo.global.pageYOffset || 0;
  3283. if(dir == 1){
  3284. toNode.style.top = "0px";
  3285. if(scrollTop > 1){
  3286. fromNode.style.top = -scrollTop + "px";
  3287. if(dojo.config["mblHideAddressBar"] !== false){
  3288. setTimeout(function(){ // iPhone needs setTimeout
  3289. dojo.global.scrollTo(0, 1);
  3290. }, 0);
  3291. }
  3292. }
  3293. }else{
  3294. if(scrollTop > 1 || toNode.offsetTop !== 0){
  3295. var toTop = -toNode.offsetTop;
  3296. toNode.style.top = "0px";
  3297. fromNode.style.top = toTop - scrollTop + "px";
  3298. if(dojo.config["mblHideAddressBar"] !== false && toTop > 0){
  3299. setTimeout(function(){ // iPhone needs setTimeout
  3300. dojo.global.scrollTo(0, toTop + 1);
  3301. }, 0);
  3302. }
  3303. }
  3304. }
  3305. }else{
  3306. toNode.style.top = "0px";
  3307. }
  3308. toWidget.onBeforeTransitionIn.apply(toWidget, arguments);
  3309. }
  3310. toNode.style.display = "none";
  3311. toNode.style.visibility = "visible";
  3312. this._doTransition(fromNode, toNode, transition, dir);
  3313. },
  3314. _doTransition: function(fromNode, toNode, transition, dir){
  3315. var rev = (dir == -1) ? " reverse" : "";
  3316. toNode.style.display = "";
  3317. if(!transition || transition == "none"){
  3318. this.domNode.style.display = "none";
  3319. this.invokeCallback();
  3320. }else{
  3321. dojo.addClass(fromNode, transition + " out" + rev);
  3322. dojo.addClass(toNode, transition + " in" + rev);
  3323. }
  3324. },
  3325. onAnimationStart: function(e){
  3326. },
  3327. onAnimationEnd: function(e){
  3328. var isOut = false;
  3329. if(dojo.hasClass(this.domNode, "out")){
  3330. isOut = true;
  3331. this.domNode.style.display = "none";
  3332. dojo.forEach([this._transition,"in","out","reverse"], function(s){
  3333. dojo.removeClass(this.domNode, s);
  3334. }, this);
  3335. }
  3336. if(e.animationName.indexOf("shrink") === 0){
  3337. var li = e.target;
  3338. li.style.display = "none";
  3339. dojo.removeClass(li, "mblCloseContent");
  3340. }
  3341. if(isOut){
  3342. this.invokeCallback();
  3343. }
  3344. // this.domNode may be destroyed as a result of invoking the callback,
  3345. // so check for that before accessing it.
  3346. this.domNode && (this.domNode.className = "mblView");
  3347. },
  3348. invokeCallback: function(){
  3349. this.onAfterTransitionOut.apply(this, this._arguments);
  3350. var toWidget = dijit.byNode(this.toNode);
  3351. if(toWidget){
  3352. toWidget.onAfterTransitionIn.apply(toWidget, this._arguments);
  3353. }
  3354. dojox.mobile.currentView = toWidget;
  3355. var c = this._context, m = this._method;
  3356. if(!c && !m){ return; }
  3357. if(!m){
  3358. m = c;
  3359. c = null;
  3360. }
  3361. c = c || dojo.global;
  3362. if(typeof(m) == "string"){
  3363. c[m].apply(c, this._args);
  3364. }else{
  3365. m.apply(c, this._args);
  3366. }
  3367. },
  3368. getShowingView: function(){
  3369. // summary:
  3370. // Find the currently showing view from my sibling views.
  3371. // description:
  3372. // Note that dojox.mobile.currentView is the last shown view.
  3373. // If the page consists of a splitter, there are multiple showing views.
  3374. var nodes = this.domNode.parentNode.childNodes;
  3375. for(var i = 0; i < nodes.length; i++){
  3376. if(dojo.hasClass(nodes[i], "mblView") && dojo.style(nodes[i], "display") != "none"){
  3377. return dijit.byNode(nodes[i]);
  3378. }
  3379. }
  3380. },
  3381. show: function(){
  3382. // summary:
  3383. // Shows this view without a transition animation.
  3384. var fs = this.getShowingView().domNode.style; // from-style
  3385. var ts = this.domNode.style; // to-style
  3386. fs.display = "none";
  3387. ts.display = "";
  3388. dojox.mobile.currentView = this;
  3389. },
  3390. addChild: function(widget){
  3391. this.containerNode.appendChild(widget.domNode);
  3392. }
  3393. });
  3394. dojo.declare(
  3395. "dojox.mobile.Heading",
  3396. dijit._WidgetBase,
  3397. {
  3398. back: "",
  3399. href: "",
  3400. moveTo: "",
  3401. transition: "slide",
  3402. label: "",
  3403. iconBase: "",
  3404. buildRendering: function(){
  3405. this.domNode = this.containerNode = this.srcNodeRef || dojo.doc.createElement("H1");
  3406. this.domNode.className = "mblHeading";
  3407. this._view = dijit.getEnclosingWidget(this.domNode.parentNode); // parentNode is null if created programmatically
  3408. if(this.label){
  3409. this.domNode.appendChild(document.createTextNode(this.label));
  3410. }else{
  3411. this.label = "";
  3412. dojo.forEach(this.domNode.childNodes, function(n){
  3413. if(n.nodeType == 3){ this.label += n.nodeValue; }
  3414. }, this);
  3415. this.label = dojo.trim(this.label);
  3416. }
  3417. if(this.back){
  3418. var btn = dojo.create("DIV", {className:"mblArrowButton"}, this.domNode, "first");
  3419. var head = dojo.create("DIV", {className:"mblArrowButtonHead"}, btn);
  3420. var body = dojo.create("DIV", {className:"mblArrowButtonBody mblArrowButtonText"}, btn);
  3421. this._body = body;
  3422. this._head = head;
  3423. this._btn = btn;
  3424. body.innerHTML = this.back;
  3425. this.connect(body, "onclick", "onClick");
  3426. var neck = dojo.create("DIV", {className:"mblArrowButtonNeck"}, btn);
  3427. btn.style.width = body.offsetWidth + head.offsetWidth + "px";
  3428. this.setLabel(this.label);
  3429. }
  3430. },
  3431. startup: function(){
  3432. if(this._btn){
  3433. this._btn.style.width = this._body.offsetWidth + this._head.offsetWidth + "px";
  3434. }
  3435. },
  3436. onClick: function(e){
  3437. var h1 = this.domNode;
  3438. dojo.addClass(h1, "mblArrowButtonSelected");
  3439. setTimeout(function(){
  3440. dojo.removeClass(h1, "mblArrowButtonSelected");
  3441. }, 1000);
  3442. this.goTo(this.moveTo, this.href);
  3443. },
  3444. setLabel: function(label){
  3445. if(label != this.label){
  3446. this.label = label;
  3447. this.domNode.firstChild.nodeValue = label;
  3448. }
  3449. },
  3450. goTo: function(moveTo, href){
  3451. if(!this._view){
  3452. this._view = dijit.byNode(this.domNode.parentNode);
  3453. }
  3454. if(!this._view){ return; }
  3455. if(href){
  3456. this._view.performTransition(null, -1, this.transition, this, function(){location.href = href;});
  3457. }else{
  3458. if(dojox.mobile.app && dojox.mobile.app.STAGE_CONTROLLER_ACTIVE){
  3459. // If in a full mobile app, then use its mechanisms to move back a scene
  3460. dojo.publish("/dojox/mobile/app/goback");
  3461. }
  3462. else{
  3463. this._view.performTransition(moveTo, -1, this.transition);
  3464. }
  3465. }
  3466. }
  3467. });
  3468. dojo.declare(
  3469. "dojox.mobile.RoundRect",
  3470. dijit._WidgetBase,
  3471. {
  3472. shadow: false,
  3473. buildRendering: function(){
  3474. this.domNode = this.containerNode = this.srcNodeRef || dojo.doc.createElement("DIV");
  3475. this.domNode.className = this.shadow ? "mblRoundRect mblShadow" : "mblRoundRect";
  3476. }
  3477. });
  3478. dojo.declare(
  3479. "dojox.mobile.RoundRectCategory",
  3480. dijit._WidgetBase,
  3481. {
  3482. label: "",
  3483. buildRendering: function(){
  3484. this.domNode = this.containerNode = this.srcNodeRef || dojo.doc.createElement("H2");
  3485. this.domNode.className = "mblRoundRectCategory";
  3486. if(this.label){
  3487. this.domNode.innerHTML = this.label;
  3488. }else{
  3489. this.label = this.domNode.innerHTML;
  3490. }
  3491. }
  3492. });
  3493. dojo.declare(
  3494. "dojox.mobile.EdgeToEdgeCategory",
  3495. dojox.mobile.RoundRectCategory,
  3496. {
  3497. buildRendering: function(){
  3498. this.inherited(arguments);
  3499. this.domNode.className = "mblEdgeToEdgeCategory";
  3500. }
  3501. });
  3502. dojo.declare(
  3503. "dojox.mobile.RoundRectList",
  3504. dijit._WidgetBase,
  3505. {
  3506. transition: "slide",
  3507. iconBase: "",
  3508. iconPos: "",
  3509. buildRendering: function(){
  3510. this.domNode = this.containerNode = this.srcNodeRef || dojo.doc.createElement("UL");
  3511. this.domNode.className = "mblRoundRectList";
  3512. },
  3513. addChild: function(widget){
  3514. this.containerNode.appendChild(widget.domNode);
  3515. widget.inheritParams();
  3516. widget.setIcon();
  3517. }
  3518. });
  3519. dojo.declare(
  3520. "dojox.mobile.EdgeToEdgeList",
  3521. dojox.mobile.RoundRectList,
  3522. {
  3523. stateful: false, // keep the selection state or not
  3524. buildRendering: function(){
  3525. this.inherited(arguments);
  3526. this.domNode.className = "mblEdgeToEdgeList";
  3527. }
  3528. });
  3529. dojo.declare(
  3530. "dojox.mobile.AbstractItem",
  3531. dijit._WidgetBase,
  3532. {
  3533. icon: "",
  3534. iconPos: "", // top,left,width,height (ex. "0,0,29,29")
  3535. href: "",
  3536. hrefTarget: "",
  3537. moveTo: "",
  3538. scene: "",
  3539. clickable: false,
  3540. url: "",
  3541. urlTarget: "", // node id under which a new view is created
  3542. transition: "",
  3543. transitionDir: 1,
  3544. callback: null,
  3545. sync: true,
  3546. label: "",
  3547. toggle: false,
  3548. _duration: 800, // duration of selection, milliseconds
  3549. inheritParams: function(){
  3550. var parent = this.getParentWidget();
  3551. if(parent){
  3552. if(!this.transition){ this.transition = parent.transition; }
  3553. if(!this.icon){ this.icon = parent.iconBase; }
  3554. if(!this.iconPos){ this.iconPos = parent.iconPos; }
  3555. }
  3556. },
  3557. findCurrentView: function(moveTo){
  3558. var w;
  3559. if(moveTo){
  3560. w = dijit.byId(moveTo);
  3561. if(w){ return w.getShowingView(); }
  3562. }
  3563. var n = this.domNode.parentNode;
  3564. while(true){
  3565. w = dijit.getEnclosingWidget(n);
  3566. if(!w){ return null; }
  3567. if(w.performTransition){ break; }
  3568. n = w.domNode.parentNode;
  3569. }
  3570. return w;
  3571. },
  3572. transitionTo: function(moveTo, href, url, scene){
  3573. var w = this.findCurrentView(moveTo); // the current view widget
  3574. if(!w || moveTo && w === dijit.byId(moveTo)){ return; }
  3575. if(href){
  3576. if(this.hrefTarget){
  3577. dojox.mobile.openWindow(this.href, this.hrefTarget);
  3578. }else{
  3579. w.performTransition(null, this.transitionDir, this.transition, this, function(){location.href = href;});
  3580. }
  3581. return;
  3582. } else if(scene){
  3583. dojo.publish("/dojox/mobile/app/pushScene", [scene]);
  3584. return;
  3585. }
  3586. if(url){
  3587. var id;
  3588. if(dojox.mobile._viewMap && dojox.mobile._viewMap[url]){
  3589. // external view has already been loaded
  3590. id = dojox.mobile._viewMap[url];
  3591. }else{
  3592. // get the specified external view and append it to the <body>
  3593. var text = this._text;
  3594. if(!text){
  3595. if(this.sync){
  3596. text = dojo.trim(dojo._getText(url));
  3597. }else{
  3598. dojo["require"]("dojo._base.xhr");
  3599. var prog = dojox.mobile.ProgressIndicator.getInstance();
  3600. dojo.body().appendChild(prog.domNode);
  3601. prog.start();
  3602. var xhr = dojo.xhrGet({
  3603. url: url,
  3604. handleAs: "text"
  3605. });
  3606. xhr.addCallback(dojo.hitch(this, function(response, ioArgs){
  3607. prog.stop();
  3608. if(response){
  3609. this._text = response;
  3610. this.transitionTo(moveTo, href, url, scene);
  3611. }
  3612. }));
  3613. xhr.addErrback(function(error){
  3614. prog.stop();
  3615. alert("Failed to load "+url+"\n"+(error.description||error));
  3616. });
  3617. return;
  3618. }
  3619. }
  3620. this._text = null;
  3621. id = this._parse(text);
  3622. if(!dojox.mobile._viewMap){
  3623. dojox.mobile._viewMap = [];
  3624. }
  3625. dojox.mobile._viewMap[url] = id;
  3626. }
  3627. moveTo = id;
  3628. w = this.findCurrentView(moveTo) || w; // the current view widget
  3629. }
  3630. w.performTransition(moveTo, this.transitionDir, this.transition, this.callback && this, this.callback);
  3631. },
  3632. _parse: function(text){
  3633. var container = dojo.create("DIV");
  3634. var view;
  3635. var id = this.urlTarget;
  3636. var target = dijit.byId(id) && dijit.byId(id).containerNode ||
  3637. dojo.byId(id) ||
  3638. dojox.mobile.currentView && dojox.mobile.currentView.domNode.parentNode ||
  3639. dojo.body();
  3640. if(text.charAt(0) == "<"){ // html markup
  3641. container.innerHTML = text;
  3642. view = container.firstChild; // <div dojoType="dojox.mobile.View">
  3643. if(!view && view.nodeType != 1){
  3644. alert("dojox.mobile.AbstractItem#transitionTo: invalid view content");
  3645. return;
  3646. }
  3647. view.setAttribute("_started", "true"); // to avoid startup() is called
  3648. view.style.visibility = "hidden";
  3649. target.appendChild(container);
  3650. (dojox.mobile.parser || dojo.parser).parse(container);
  3651. target.appendChild(target.removeChild(container).firstChild); // reparent
  3652. }else if(text.charAt(0) == "{"){ // json
  3653. target.appendChild(container);
  3654. this._ws = [];
  3655. view = this._instantiate(eval('('+text+')'), container);
  3656. for(var i = 0; i < this._ws.length; i++){
  3657. var w = this._ws[i];
  3658. w.startup && !w._started && (!w.getParent || !w.getParent()) && w.startup();
  3659. }
  3660. this._ws = null;
  3661. }
  3662. view.style.display = "none";
  3663. view.style.visibility = "visible";
  3664. var id = view.id;
  3665. return dojo.hash ? "#" + id : id;
  3666. },
  3667. _instantiate: function(/*Object*/obj, /*DomNode*/node, /*Widget*/parent){
  3668. var widget;
  3669. for(var key in obj){
  3670. if(key.charAt(0) == "@"){ continue; }
  3671. var cls = dojo.getObject(key);
  3672. if(!cls){ continue; }
  3673. var params = {};
  3674. var proto = cls.prototype;
  3675. var objs = dojo.isArray(obj[key]) ? obj[key] : [obj[key]];
  3676. for(var i = 0; i < objs.length; i++){
  3677. for(var prop in objs[i]){
  3678. if(prop.charAt(0) == "@"){
  3679. var val = objs[i][prop];
  3680. prop = prop.substring(1);
  3681. if(typeof proto[prop] == "string"){
  3682. params[prop] = val;
  3683. }else if(typeof proto[prop] == "number"){
  3684. params[prop] = val - 0;
  3685. }else if(typeof proto[prop] == "boolean"){
  3686. params[prop] = (val != "false");
  3687. }else if(typeof proto[prop] == "object"){
  3688. params[prop] = eval("(" + val + ")");
  3689. }
  3690. }
  3691. }
  3692. widget = new cls(params, node);
  3693. if(!node){ // not to call View's startup()
  3694. this._ws.push(widget);
  3695. }
  3696. if(parent && parent.addChild){
  3697. parent.addChild(widget);
  3698. }
  3699. this._instantiate(objs[i], null, widget);
  3700. }
  3701. }
  3702. return widget && widget.domNode;
  3703. },
  3704. createDomButton: function(/*DomNode*/refNode, /*DomNode?*/toNode){
  3705. var s = refNode.className;
  3706. if(s.match(/mblDomButton\w+_(\d+)/)){
  3707. var nDiv = RegExp.$1 - 0;
  3708. for(var i = 0, p = (toNode||refNode); i < nDiv; i++){
  3709. p = dojo.create("DIV", null, p);
  3710. }
  3711. }
  3712. },
  3713. select: function(/*Boolean?*/deselect){
  3714. // subclass must implement
  3715. },
  3716. defaultClickAction: function(){
  3717. if(this.toggle){
  3718. this.select(this.selected);
  3719. }else if(!this.selected){
  3720. this.select();
  3721. if(!this.selectOne){
  3722. var _this = this;
  3723. setTimeout(function(){
  3724. _this.select(true);
  3725. }, this._duration);
  3726. }
  3727. if(this.moveTo || this.href || this.url || this.scene){
  3728. this.transitionTo(this.moveTo, this.href, this.url, this.scene);
  3729. }
  3730. }
  3731. },
  3732. getParentWidget: function(){
  3733. var ref = this.srcNodeRef || this.domNode;
  3734. return ref && ref.parentNode ? dijit.getEnclosingWidget(ref.parentNode) : null;
  3735. }
  3736. });
  3737. dojo.declare(
  3738. "dojox.mobile.ListItem",
  3739. dojox.mobile.AbstractItem,
  3740. {
  3741. rightText: "",
  3742. btnClass: "",
  3743. anchorLabel: false,
  3744. noArrow: false,
  3745. selected: false,
  3746. buildRendering: function(){
  3747. this.inheritParams();
  3748. var a = this.anchorNode = dojo.create("A");
  3749. a.className = "mblListItemAnchor";
  3750. var box = dojo.create("DIV");
  3751. box.className = "mblListItemTextBox";
  3752. if(this.anchorLabel){
  3753. box.style.cursor = "pointer";
  3754. }
  3755. var r = this.srcNodeRef;
  3756. if(r){
  3757. for(var i = 0, len = r.childNodes.length; i < len; i++){
  3758. box.appendChild(r.removeChild(r.firstChild));
  3759. }
  3760. }
  3761. if(this.label){
  3762. box.appendChild(dojo.doc.createTextNode(this.label));
  3763. }
  3764. a.appendChild(box);
  3765. if(this.rightText){
  3766. this._setRightTextAttr(this.rightText);
  3767. }
  3768. if(this.moveTo || this.href || this.url || this.clickable){
  3769. var parent = this.getParentWidget();
  3770. if(!this.noArrow && !(parent && parent.stateful)){
  3771. var arrow = dojo.create("DIV");
  3772. arrow.className = "mblArrow";
  3773. a.appendChild(arrow);
  3774. }
  3775. this.connect(a, "onclick", "onClick");
  3776. }else if(this.btnClass){
  3777. var div = this.btnNode = dojo.create("DIV");
  3778. div.className = this.btnClass+" mblRightButton";
  3779. div.appendChild(dojo.create("DIV"));
  3780. div.appendChild(dojo.create("P"));
  3781. var dummyDiv = dojo.create("DIV");
  3782. dummyDiv.className = "mblRightButtonContainer";
  3783. dummyDiv.appendChild(div);
  3784. a.appendChild(dummyDiv);
  3785. dojo.addClass(a, "mblListItemAnchorHasRightButton");
  3786. setTimeout(function(){
  3787. dummyDiv.style.width = div.offsetWidth + "px";
  3788. dummyDiv.style.height = div.offsetHeight + "px";
  3789. if(dojo.isIE){
  3790. // IE seems to ignore the height of LI without this..
  3791. a.parentNode.style.height = a.parentNode.offsetHeight + "px";
  3792. }
  3793. }, 0);
  3794. }
  3795. if(this.anchorLabel){
  3796. box.style.display = "inline"; // to narrow the text region
  3797. }
  3798. var li = this.domNode = this.containerNode = this.srcNodeRef || dojo.doc.createElement("LI");
  3799. li.className = "mblListItem" + (this.selected ? " mblItemSelected" : "");
  3800. li.appendChild(a);
  3801. this.setIcon();
  3802. },
  3803. setIcon: function(){
  3804. if(this.iconNode){ return; }
  3805. var a = this.anchorNode;
  3806. if(this.icon && this.icon != "none"){
  3807. var img = this.iconNode = dojo.create("IMG");
  3808. img.className = "mblListItemIcon";
  3809. img.src = this.icon;
  3810. this.domNode.insertBefore(img, a);
  3811. dojox.mobile.setupIcon(this.iconNode, this.iconPos);
  3812. dojo.removeClass(a, "mblListItemAnchorNoIcon");
  3813. }else{
  3814. dojo.addClass(a, "mblListItemAnchorNoIcon");
  3815. }
  3816. },
  3817. onClick: function(e){
  3818. var a = e.currentTarget;
  3819. var li = a.parentNode;
  3820. if(dojo.hasClass(li, "mblItemSelected")){ return; } // already selected
  3821. if(this.anchorLabel){
  3822. for(var p = e.target; p.tagName != "LI"; p = p.parentNode){
  3823. if(p.className == "mblListItemTextBox"){
  3824. dojo.addClass(p, "mblListItemTextBoxSelected");
  3825. setTimeout(function(){
  3826. dojo.removeClass(p, "mblListItemTextBoxSelected");
  3827. }, 1000);
  3828. this.onAnchorLabelClicked(e);
  3829. return;
  3830. }
  3831. }
  3832. }
  3833. if(this.getParentWidget().stateful){
  3834. for(var i = 0, c = li.parentNode.childNodes; i < c.length; i++){
  3835. dojo.removeClass(c[i], "mblItemSelected");
  3836. }
  3837. }else{
  3838. setTimeout(function(){
  3839. dojo.removeClass(li, "mblItemSelected");
  3840. }, 1000);
  3841. }
  3842. dojo.addClass(li, "mblItemSelected");
  3843. this.transitionTo(this.moveTo, this.href, this.url, this.scene);
  3844. },
  3845. onAnchorLabelClicked: function(e){
  3846. },
  3847. _setRightTextAttr: function(/*String*/text){
  3848. this.rightText = text;
  3849. if(!this._rightTextNode){
  3850. this._rightTextNode = dojo.create("DIV", {className:"mblRightText"}, this.anchorNode);
  3851. }
  3852. this._rightTextNode.innerHTML = text;
  3853. }
  3854. });
  3855. dojo.declare(
  3856. "dojox.mobile.Switch",
  3857. dijit._WidgetBase,
  3858. {
  3859. value: "on",
  3860. leftLabel: "ON",
  3861. rightLabel: "OFF",
  3862. _width: 53,
  3863. buildRendering: function(){
  3864. this.domNode = this.srcNodeRef || dojo.doc.createElement("DIV");
  3865. this.domNode.className = "mblSwitch";
  3866. this.domNode.innerHTML =
  3867. '<div class="mblSwitchInner">'
  3868. + '<div class="mblSwitchBg mblSwitchBgLeft">'
  3869. + '<div class="mblSwitchText mblSwitchTextLeft">'+this.leftLabel+'</div>'
  3870. + '</div>'
  3871. + '<div class="mblSwitchBg mblSwitchBgRight">'
  3872. + '<div class="mblSwitchText mblSwitchTextRight">'+this.rightLabel+'</div>'
  3873. + '</div>'
  3874. + '<div class="mblSwitchKnob"></div>'
  3875. + '</div>';
  3876. var n = this.inner = this.domNode.firstChild;
  3877. this.left = n.childNodes[0];
  3878. this.right = n.childNodes[1];
  3879. this.knob = n.childNodes[2];
  3880. dojo.addClass(this.domNode, (this.value == "on") ? "mblSwitchOn" : "mblSwitchOff");
  3881. this[this.value == "off" ? "left" : "right"].style.display = "none";
  3882. },
  3883. postCreate: function(){
  3884. this.connect(this.knob, "onclick", "onClick");
  3885. this.connect(this.knob, "touchstart", "onTouchStart");
  3886. this.connect(this.knob, "mousedown", "onTouchStart");
  3887. },
  3888. _changeState: function(/*String*/state){
  3889. this.inner.style.left = "";
  3890. dojo.addClass(this.domNode, "mblSwitchAnimation");
  3891. dojo.removeClass(this.domNode, (state == "on") ? "mblSwitchOff" : "mblSwitchOn");
  3892. dojo.addClass(this.domNode, (state == "on") ? "mblSwitchOn" : "mblSwitchOff");
  3893. var _this = this;
  3894. setTimeout(function(){
  3895. _this[state == "off" ? "left" : "right"].style.display = "none";
  3896. dojo.removeClass(_this.domNode, "mblSwitchAnimation");
  3897. }, 300);
  3898. },
  3899. onClick: function(e){
  3900. if(this._moved){ return; }
  3901. this.value = (this.value == "on") ? "off" : "on";
  3902. this._changeState(this.value);
  3903. this.onStateChanged(this.value);
  3904. },
  3905. onTouchStart: function(e){
  3906. this._moved = false;
  3907. this.innerStartX = this.inner.offsetLeft;
  3908. if(e.targetTouches){
  3909. this.touchStartX = e.targetTouches[0].clientX;
  3910. this._conn1 = dojo.connect(this.inner, "touchmove", this, "onTouchMove");
  3911. this._conn2 = dojo.connect(this.inner, "touchend", this, "onTouchEnd");
  3912. }
  3913. this.left.style.display = "block";
  3914. this.right.style.display = "block";
  3915. dojo.stopEvent(e);
  3916. },
  3917. onTouchMove: function(e){
  3918. e.preventDefault();
  3919. var dx;
  3920. if(e.targetTouches){
  3921. if(e.targetTouches.length != 1){ return false; }
  3922. dx = e.targetTouches[0].clientX - this.touchStartX;
  3923. }else{
  3924. dx = e.clientX - this.touchStartX;
  3925. }
  3926. var pos = this.innerStartX + dx;
  3927. var d = 10;
  3928. if(pos <= -(this._width-d)){ pos = -this._width; }
  3929. if(pos >= -d){ pos = 0; }
  3930. this.inner.style.left = pos + "px";
  3931. this._moved = true;
  3932. },
  3933. onTouchEnd: function(e){
  3934. dojo.disconnect(this._conn1);
  3935. dojo.disconnect(this._conn2);
  3936. if(this.innerStartX == this.inner.offsetLeft){
  3937. if(dojo.isWebKit){
  3938. var ev = dojo.doc.createEvent("MouseEvents");
  3939. ev.initEvent("click", true, true);
  3940. this.knob.dispatchEvent(ev);
  3941. }
  3942. return;
  3943. }
  3944. var newState = (this.inner.offsetLeft < -(this._width/2)) ? "off" : "on";
  3945. this._changeState(newState);
  3946. if(newState != this.value){
  3947. this.value = newState;
  3948. this.onStateChanged(this.value);
  3949. }
  3950. },
  3951. onStateChanged: function(/*String*/newState){
  3952. }
  3953. });
  3954. dojo.declare(
  3955. "dojox.mobile.Button",
  3956. dijit._WidgetBase,
  3957. {
  3958. btnClass: "mblBlueButton",
  3959. duration: 1000, // duration of selection, milliseconds
  3960. label: null,
  3961. buildRendering: function(){
  3962. this.domNode = this.containerNode = this.srcNodeRef || dojo.doc.createElement("BUTTON");
  3963. this.domNode.className = "mblButton "+this.btnClass;
  3964. if(this.label){
  3965. this.domNode.innerHTML = this.label;
  3966. }
  3967. this.connect(this.domNode, "onclick", "onClick");
  3968. },
  3969. onClick: function(e){
  3970. var button = this.domNode;
  3971. var c = "mblButtonSelected "+this.btnClass+"Selected";
  3972. dojo.addClass(button, c);
  3973. setTimeout(function(){
  3974. dojo.removeClass(button, c);
  3975. }, this.duration);
  3976. }
  3977. });
  3978. dojo.declare(
  3979. "dojox.mobile.ToolBarButton",
  3980. dojox.mobile.AbstractItem,
  3981. {
  3982. selected: false,
  3983. _defaultColor: "mblColorDefault",
  3984. _selColor: "mblColorDefaultSel",
  3985. buildRendering: function(){
  3986. this.inheritParams();
  3987. this.domNode = this.containerNode = this.srcNodeRef || dojo.doc.createElement("div");
  3988. dojo.addClass(this.domNode, "mblToolbarButton mblArrowButtonText");
  3989. var color;
  3990. if(this.selected){
  3991. color = this._selColor;
  3992. }else if(this.domNode.className.indexOf("mblColor") == -1){
  3993. color = this._defaultColor;
  3994. }
  3995. dojo.addClass(this.domNode, color);
  3996. if(this.label){
  3997. this.domNode.innerHTML = this.label;
  3998. }else{
  3999. this.label = this.domNode.innerHTML;
  4000. }
  4001. if(this.icon && this.icon != "none"){
  4002. var img;
  4003. if(this.iconPos){
  4004. var iconDiv = dojo.create("DIV", null, this.domNode);
  4005. img = dojo.create("IMG", null, iconDiv);
  4006. img.style.position = "absolute";
  4007. var arr = this.iconPos.split(/[ ,]/);
  4008. dojo.style(iconDiv, {
  4009. position: "relative",
  4010. width: arr[2] + "px",
  4011. height: arr[3] + "px"
  4012. });
  4013. }else{
  4014. img = dojo.create("IMG", null, this.domNode);
  4015. }
  4016. img.src = this.icon;
  4017. dojox.mobile.setupIcon(img, this.iconPos);
  4018. this.iconNode = img;
  4019. }
  4020. this.createDomButton(this.domNode);
  4021. this.connect(this.domNode, "onclick", "onClick");
  4022. },
  4023. select: function(/*Boolean?*/deselect){
  4024. dojo.toggleClass(this.domNode, this._selColor, !deselect);
  4025. this.selected = !deselect;
  4026. },
  4027. onClick: function(e){
  4028. this.defaultClickAction();
  4029. }
  4030. });
  4031. dojo.declare(
  4032. "dojox.mobile.ProgressIndicator",
  4033. null,
  4034. {
  4035. interval: 100, // milliseconds
  4036. colors: [
  4037. "#C0C0C0", "#C0C0C0", "#C0C0C0", "#C0C0C0",
  4038. "#C0C0C0", "#C0C0C0", "#B8B9B8", "#AEAFAE",
  4039. "#A4A5A4", "#9A9A9A", "#8E8E8E", "#838383"
  4040. ],
  4041. _bars: [],
  4042. constructor: function(){
  4043. this.domNode = dojo.create("DIV");
  4044. this.domNode.className = "mblProgContainer";
  4045. for(var i = 0; i < 12; i++){
  4046. var div = dojo.create("DIV");
  4047. div.className = "mblProg mblProg"+i;
  4048. this.domNode.appendChild(div);
  4049. this._bars.push(div);
  4050. }
  4051. },
  4052. start: function(){
  4053. var cntr = 0;
  4054. var _this = this;
  4055. this.timer = setInterval(function(){
  4056. cntr--;
  4057. cntr = cntr < 0 ? 11 : cntr;
  4058. var c = _this.colors;
  4059. for(var i = 0; i < 12; i++){
  4060. var idx = (cntr + i) % 12;
  4061. _this._bars[i].style.backgroundColor = c[idx];
  4062. }
  4063. }, this.interval);
  4064. },
  4065. stop: function(){
  4066. if(this.timer){
  4067. clearInterval(this.timer);
  4068. }
  4069. this.timer = null;
  4070. if(this.domNode.parentNode){
  4071. this.domNode.parentNode.removeChild(this.domNode);
  4072. }
  4073. }
  4074. });
  4075. dojox.mobile.ProgressIndicator._instance = null;
  4076. dojox.mobile.ProgressIndicator.getInstance = function(){
  4077. if(!dojox.mobile.ProgressIndicator._instance){
  4078. dojox.mobile.ProgressIndicator._instance = new dojox.mobile.ProgressIndicator();
  4079. }
  4080. return dojox.mobile.ProgressIndicator._instance;
  4081. };
  4082. dojox.mobile.addClass = function(){
  4083. // summary:
  4084. // Adds a theme class name to <body>.
  4085. // description:
  4086. // Finds the currently applied theme name, such as 'iphone' or 'android'
  4087. // from link elements, and adds it as a class name for the body element.
  4088. var elems = document.getElementsByTagName("link");
  4089. for(var i = 0, len = elems.length; i < len; i++){
  4090. if(elems[i].href.match(/dojox\/mobile\/themes\/(\w+)\//)){
  4091. dojox.mobile.theme = RegExp.$1;
  4092. dojo.addClass(dojo.body(), dojox.mobile.theme);
  4093. break;
  4094. }
  4095. }
  4096. };
  4097. dojox.mobile.setupIcon = function(/*DomNode*/iconNode, /*String*/iconPos){
  4098. if(iconNode && iconPos){
  4099. var arr = dojo.map(iconPos.split(/[ ,]/),
  4100. function(item){ return item - 0; });
  4101. var t = arr[0]; // top
  4102. var r = arr[1] + arr[2]; // right
  4103. var b = arr[0] + arr[3]; // bottom
  4104. var l = arr[1]; // left
  4105. iconNode.style.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
  4106. iconNode.style.top = dojo.style(iconNode, "top") - t + "px";
  4107. iconNode.style.left = dojo.style(iconNode.parentNode, "paddingLeft") - l + "px";
  4108. }
  4109. };
  4110. dojox.mobile.hideAddressBar = function(){
  4111. dojo.body().style.minHeight = "1000px"; // to ensure enough height for scrollTo to work
  4112. setTimeout(function(){ scrollTo(0, 1); }, 100);
  4113. setTimeout(function(){ scrollTo(0, 1); }, 400);
  4114. setTimeout(function(){
  4115. scrollTo(0, 1);
  4116. // re-define the min-height with the actual height
  4117. dojo.body().style.minHeight = (dojo.global.innerHeight||dojo.doc.documentElement.clientHeight) + "px";
  4118. }, 1000);
  4119. };
  4120. dojox.mobile.openWindow = function(url, target){
  4121. dojo.global.open(url, target || "_blank");
  4122. };
  4123. dojo._loaders.unshift(function(){
  4124. // avoid use of dojo.query
  4125. /*
  4126. var list = dojo.query('[lazy=true] [dojoType]', null);
  4127. list.forEach(function(node, index, nodeList){
  4128. node.setAttribute("__dojoType", node.getAttribute("dojoType"));
  4129. node.removeAttribute("dojoType");
  4130. });
  4131. */
  4132. var nodes = dojo.body().getElementsByTagName("*");
  4133. var i, len, s;
  4134. len = nodes.length;
  4135. for(i = 0; i < len; i++){
  4136. s = nodes[i].getAttribute("dojoType");
  4137. if(s){
  4138. if(nodes[i].parentNode.getAttribute("lazy") == "true"){
  4139. nodes[i].setAttribute("__dojoType", s);
  4140. nodes[i].removeAttribute("dojoType");
  4141. }
  4142. }
  4143. }
  4144. });
  4145. dojo.addOnLoad(function(){
  4146. dojox.mobile.addClass();
  4147. if(dojo.config["mblApplyPageStyles"] !== false){
  4148. dojo.addClass(dojo.doc.documentElement, "mobile");
  4149. }
  4150. // You can disable hiding the address bar with the following djConfig.
  4151. // var djConfig = { mblHideAddressBar: false };
  4152. if(dojo.config["mblHideAddressBar"] !== false){
  4153. dojox.mobile.hideAddressBar();
  4154. if(dojo.config["mblAlwaysHideAddressBar"] == true){
  4155. if(dojo.global.onorientationchange !== undefined){
  4156. dojo.connect(dojo.global, "onorientationchange", dojox.mobile.hideAddressBar);
  4157. }else{
  4158. dojo.connect(dojo.global, "onresize", dojox.mobile.hideAddressBar);
  4159. }
  4160. }
  4161. }
  4162. // avoid use of dojo.query
  4163. /*
  4164. var list = dojo.query('[__dojoType]', null);
  4165. list.forEach(function(node, index, nodeList){
  4166. node.setAttribute("dojoType", node.getAttribute("__dojoType"));
  4167. node.removeAttribute("__dojoType");
  4168. });
  4169. */
  4170. var nodes = dojo.body().getElementsByTagName("*");
  4171. var i, len = nodes.length, s;
  4172. for(i = 0; i < len; i++){
  4173. s = nodes[i].getAttribute("__dojoType");
  4174. if(s){
  4175. nodes[i].setAttribute("dojoType", s);
  4176. nodes[i].removeAttribute("__dojoType");
  4177. }
  4178. }
  4179. if(dojo.hash){
  4180. // find widgets under root recursively
  4181. var findWidgets = function(root){
  4182. var arr;
  4183. arr = dijit.findWidgets(root);
  4184. var widgets = arr;
  4185. for(var i = 0; i < widgets.length; i++){
  4186. arr = arr.concat(findWidgets(widgets[i].containerNode));
  4187. }
  4188. return arr;
  4189. };
  4190. dojo.subscribe("/dojo/hashchange", null, function(value){
  4191. var view = dojox.mobile.currentView;
  4192. if(!view){ return; }
  4193. var params = dojox.mobile._params;
  4194. if(!params){ // browser back/forward button was pressed
  4195. var moveTo = value ? value : dojox.mobile._defaultView.id;
  4196. var widgets = findWidgets(view.domNode);
  4197. var dir = 1, transition = "slide";
  4198. for(i = 0; i < widgets.length; i++){
  4199. var w = widgets[i];
  4200. if("#"+moveTo == w.moveTo){
  4201. // found a widget that has the given moveTo
  4202. transition = w.transition;
  4203. dir = (w instanceof dojox.mobile.Heading) ? -1 : 1;
  4204. break;
  4205. }
  4206. }
  4207. params = [ moveTo, dir, transition ];
  4208. }
  4209. view.performTransition.apply(view, params);
  4210. dojox.mobile._params = null;
  4211. });
  4212. }
  4213. dojo.body().style.visibility = "visible";
  4214. });
  4215. dijit.getEnclosingWidget = function(node){
  4216. while(node && node.tagName !== "BODY"){
  4217. if(node.getAttribute && node.getAttribute("widgetId")){
  4218. return dijit.registry.byId(node.getAttribute("widgetId"));
  4219. }
  4220. node = node._parentNode || node.parentNode;
  4221. }
  4222. return null;
  4223. };
  4224. }
  4225. if(!dojo._hasResource["dojox.mobile"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  4226. dojo._hasResource["dojox.mobile"] = true;
  4227. dojo.provide("dojox.mobile");
  4228. dojo.experimental("dojox.mobile");
  4229. }
  4230. if(!dojo._hasResource["dojox.mobile.parser"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  4231. dojo._hasResource["dojox.mobile.parser"] = true;
  4232. dojo.provide("dojox.mobile.parser");
  4233. dojo.provide("dojo.parser"); // not to load dojo.parser unexpectedly
  4234. dojox.mobile.parser = new function(){
  4235. this.instantiate = function(list, defaultParams){
  4236. // summary:
  4237. // Function for instantiating a list of widget nodes.
  4238. // list:
  4239. // The list of DOMNodes to walk and instantiate widgets on.
  4240. var ws = [];
  4241. if(list){
  4242. var i, len;
  4243. len = list.length;
  4244. for(i = 0; i < len; i++){
  4245. var node = list[i];
  4246. var cls = dojo.getObject(dojo.attr(node, "dojoType"));
  4247. var proto = cls.prototype;
  4248. var params = {};
  4249. if(defaultParams){
  4250. for(var name in defaultParams){
  4251. params[name] = defaultParams[name];
  4252. }
  4253. }
  4254. for(var prop in proto){
  4255. var val = dojo.attr(node, prop);
  4256. if(!val){ continue; }
  4257. if(typeof proto[prop] == "string"){
  4258. params[prop] = val;
  4259. }else if(typeof proto[prop] == "number"){
  4260. params[prop] = val - 0;
  4261. }else if(typeof proto[prop] == "boolean"){
  4262. params[prop] = (val != "false");
  4263. }else if(typeof proto[prop] == "object"){
  4264. params[prop] = eval("(" + val + ")");
  4265. }
  4266. }
  4267. params["class"] = node.className;
  4268. params["style"] = node.style && node.style.cssText;
  4269. var instance = new cls(params, node);
  4270. ws.push(instance);
  4271. var jsId = node.getAttribute("jsId");
  4272. if(jsId){
  4273. dojo.setObject(jsId, instance);
  4274. }
  4275. }
  4276. len = ws.length;
  4277. for(i = 0; i < len; i++){
  4278. var w = ws[i];
  4279. w.startup && !w._started && (!w.getParent || !w.getParent()) && w.startup();
  4280. }
  4281. }
  4282. return ws;
  4283. };
  4284. this.parse = function(rootNode, defaultParams){
  4285. // summary:
  4286. // Function to handle parsing for widgets in the current document.
  4287. // It is not as powerful as the full dojo parser, but it will handle basic
  4288. // use cases fine.
  4289. // rootNode:
  4290. // The root node in the document to parse from
  4291. if(!rootNode){
  4292. rootNode = dojo.body();
  4293. }else if(!defaultParams && rootNode.rootNode){
  4294. // Case where 'rootNode' is really a params object.
  4295. rootNode = rootNode.rootNode;
  4296. }
  4297. var nodes = rootNode.getElementsByTagName("*");
  4298. var list = [];
  4299. for(var i = 0, len = nodes.length; i < len; i++){
  4300. if(nodes[i].getAttribute("dojoType")){
  4301. list.push(nodes[i]);
  4302. }
  4303. }
  4304. return this.instantiate(list, defaultParams);
  4305. };
  4306. }();
  4307. dojo._loaders.unshift(function(){
  4308. if(dojo.config.parseOnLoad){
  4309. dojox.mobile.parser.parse();
  4310. }
  4311. });
  4312. }
  4313. if(!dojo._hasResource["dojox.mobile.app._event"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  4314. dojo._hasResource["dojox.mobile.app._event"] = true;
  4315. dojo.provide("dojox.mobile.app._event");
  4316. dojo.experimental("dojox.mobile.app._event.js");
  4317. dojo.mixin(dojox.mobile.app, {
  4318. eventMap: {},
  4319. connectFlick: function(target, context, method){
  4320. // summary:
  4321. // Listens for a flick event on a DOM node. If the mouse/touch
  4322. // moves more than 15 pixels in any given direction it is a flick.
  4323. // The synthetic event fired specifies the direction as
  4324. // <ul>
  4325. // <li><b>'ltr'</b> Left To Right</li>
  4326. // <li><b>'rtl'</b> Right To Left</li>
  4327. // <li><b>'ttb'</b> Top To Bottom</li>
  4328. // <li><b>'btt'</b> Bottom To Top</li>
  4329. // </ul>
  4330. // target: Node
  4331. // The DOM node to connect to
  4332. var startX;
  4333. var startY;
  4334. var isFlick = false;
  4335. var currentX;
  4336. var currentY;
  4337. var connMove;
  4338. var connUp;
  4339. var direction;
  4340. var time;
  4341. // Listen to to the mousedown/touchstart event
  4342. var connDown = dojo.connect("onmousedown", target, function(event){
  4343. isFlick = false;
  4344. startX = event.targetTouches ? event.targetTouches[0].clientX : event.clientX;
  4345. startY = event.targetTouches ? event.targetTouches[0].clientY : event.clientY;
  4346. time = (new Date()).getTime();
  4347. connMove = dojo.connect(target, "onmousemove", onMove);
  4348. connUp = dojo.connect(target, "onmouseup", onUp);
  4349. });
  4350. // The function that handles the mousemove/touchmove event
  4351. var onMove = function(event){
  4352. dojo.stopEvent(event);
  4353. currentX = event.targetTouches ? event.targetTouches[0].clientX : event.clientX;
  4354. currentY = event.targetTouches ? event.targetTouches[0].clientY : event.clientY;
  4355. if(Math.abs(Math.abs(currentX) - Math.abs(startX)) > 15){
  4356. isFlick = true;
  4357. direction = (currentX > startX) ? "ltr" : "rtl";
  4358. }else if(Math.abs(Math.abs(currentY) - Math.abs(startY)) > 15){
  4359. isFlick = true;
  4360. direction = (currentY > startY) ? "ttb" : "btt";
  4361. }
  4362. };
  4363. var onUp = function(event){
  4364. dojo.stopEvent(event);
  4365. connMove && dojo.disconnect(connMove);
  4366. connUp && dojo.disconnect(connUp);
  4367. if(isFlick){
  4368. var flickEvt = {
  4369. target: target,
  4370. direction: direction,
  4371. duration: (new Date()).getTime() - time
  4372. };
  4373. if(context && method){
  4374. context[method](flickEvt);
  4375. }else{
  4376. method(flickEvt);
  4377. }
  4378. }
  4379. };
  4380. }
  4381. });
  4382. dojox.mobile.app.isIPhone = (dojo.isSafari
  4383. && (navigator.userAgent.indexOf("iPhone") > -1 ||
  4384. navigator.userAgent.indexOf("iPod") > -1
  4385. ));
  4386. dojox.mobile.app.isWebOS = (navigator.userAgent.indexOf("webOS") > -1);
  4387. dojox.mobile.app.isAndroid = (navigator.userAgent.toLowerCase().indexOf("android") > -1);
  4388. if(dojox.mobile.app.isIPhone || dojox.mobile.app.isAndroid){
  4389. // We are touchable.
  4390. // Override the dojo._connect function to replace mouse events with touch events
  4391. dojox.mobile.app.eventMap = {
  4392. onmousedown: "ontouchstart",
  4393. mousedown: "ontouchstart",
  4394. onmouseup: "ontouchend",
  4395. mouseup: "ontouchend",
  4396. onmousemove: "ontouchmove",
  4397. mousemove: "ontouchmove"
  4398. };
  4399. }
  4400. dojo._oldConnect = dojo._connect;
  4401. dojo._connect = function(obj, event, context, method, dontFix){
  4402. event = dojox.mobile.app.eventMap[event] || event;
  4403. if(event == "flick" || event == "onflick"){
  4404. if(dojo.global["Mojo"]){
  4405. event = Mojo.Event.flick;
  4406. }else{
  4407. return dojox.mobile.app.connectFlick(obj, context, method);
  4408. }
  4409. }
  4410. return dojo._oldConnect(obj, event, context, method, dontFix);
  4411. }
  4412. }
  4413. if(!dojo._hasResource["dojox.mobile.app._Widget"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  4414. dojo._hasResource["dojox.mobile.app._Widget"] = true;
  4415. dojo.provide("dojox.mobile.app._Widget");
  4416. dojo.experimental("dojox.mobile.app._Widget");
  4417. dojo.declare("dojox.mobile.app._Widget", dijit._WidgetBase, {
  4418. // summary:
  4419. // The base mobile app widget.
  4420. getScroll: function(){
  4421. // summary:
  4422. // Returns the scroll position.
  4423. return {
  4424. x: dojo.global.scrollX,
  4425. y: dojo.global.scrollY
  4426. };
  4427. },
  4428. connect: function(target, event, fn){
  4429. if(event.toLowerCase() == "dblclick"
  4430. || event.toLowerCase() == "ondblclick"){
  4431. if(dojo.global["Mojo"]){
  4432. // Handle webOS tap event
  4433. return this.connect(target, Mojo.Event.tap, fn);
  4434. }
  4435. }
  4436. return this.inherited(arguments);
  4437. }
  4438. });
  4439. }
  4440. if(!dojo._hasResource["dojox.mobile.app.SceneController"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  4441. dojo._hasResource["dojox.mobile.app.SceneController"] = true;
  4442. dojo.provide("dojox.mobile.app.SceneController");
  4443. dojo.experimental("dojox.mobile.app.SceneController");
  4444. (function(){
  4445. var app = dojox.mobile.app;
  4446. var templates = {};
  4447. dojo.declare("dojox.mobile.app.SceneController", dojox.mobile.View, {
  4448. stageController: null,
  4449. keepScrollPos: false,
  4450. init: function(sceneName, params){
  4451. // summary:
  4452. // Initializes the scene by loading the HTML template and code, if it has
  4453. // not already been loaded
  4454. this.sceneName = sceneName;
  4455. this.params = params;
  4456. var templateUrl = app.resolveTemplate(sceneName);
  4457. this._deferredInit = new dojo.Deferred();
  4458. if(templates[sceneName]){
  4459. // If the template has been cached, do not load it again.
  4460. this._setContents(templates[sceneName]);
  4461. }else{
  4462. // Otherwise load the template
  4463. dojo.xhrGet({
  4464. url: templateUrl,
  4465. handleAs: "text"
  4466. }).addCallback(dojo.hitch(this, this._setContents));
  4467. }
  4468. return this._deferredInit;
  4469. },
  4470. _setContents: function(templateHtml){
  4471. // summary:
  4472. // Sets the content of the View, and invokes either the loading or
  4473. // initialization of the scene assistant.
  4474. templates[this.sceneName] = templateHtml;
  4475. this.domNode.innerHTML = "<div>" + templateHtml + "</div>";
  4476. var sceneAssistantName = "";
  4477. var nameParts = this.sceneName.split("-");
  4478. for(var i = 0; i < nameParts.length; i++){
  4479. sceneAssistantName += nameParts[i].substring(0, 1).toUpperCase()
  4480. + nameParts[i].substring(1);
  4481. }
  4482. sceneAssistantName += "Assistant";
  4483. this.sceneAssistantName = sceneAssistantName;
  4484. var _this = this;
  4485. dojox.mobile.app.loadResourcesForScene(this.sceneName, function(){
  4486. console.log("All resources for ",_this.sceneName," loaded");
  4487. var assistant;
  4488. if(typeof(dojo.global[sceneAssistantName]) != "undefined"){
  4489. _this._initAssistant();
  4490. }else{
  4491. var assistantUrl = app.resolveAssistant(_this.sceneName);
  4492. dojo.xhrGet({
  4493. url: assistantUrl,
  4494. handleAs: "text"
  4495. }).addCallback(function(text){
  4496. try{
  4497. dojo.eval(text);
  4498. }catch(e){
  4499. console.log("Error initializing code for scene " + _this.sceneName
  4500. + '. Please check for syntax errors');
  4501. throw e;
  4502. }
  4503. _this._initAssistant();
  4504. });
  4505. }
  4506. });
  4507. },
  4508. _initAssistant: function(){
  4509. // summary:
  4510. // Initializes the scene assistant. At this point, the View is
  4511. // populated with the HTML template, and the scene assistant type
  4512. // is declared.
  4513. console.log("Instantiating the scene assistant " + this.sceneAssistantName);
  4514. var cls = dojo.getObject(this.sceneAssistantName);
  4515. if(!cls){
  4516. throw Error("Unable to resolve scene assistant "
  4517. + this.sceneAssistantName);
  4518. }
  4519. this.assistant = new cls(this.params);
  4520. this.assistant.controller = this;
  4521. this.assistant.domNode = this.domNode.firstChild;
  4522. this.assistant.setup();
  4523. this._deferredInit.callback();
  4524. },
  4525. query: function(selector, node){
  4526. // summary:
  4527. // Queries for DOM nodes within either the node passed in as an argument
  4528. // or within this view.
  4529. return dojo.query(selector, node || this.domNode)
  4530. },
  4531. parse: function(node){
  4532. var widgets = this._widgets =
  4533. dojox.mobile.parser.parse(node || this.domNode, {
  4534. controller: this
  4535. });
  4536. // Tell all widgets what their controller is.
  4537. for(var i = 0; i < widgets.length; i++){
  4538. widgets[i].set("controller", this);
  4539. }
  4540. },
  4541. getWindowSize: function(){
  4542. // TODO, this needs cross browser testing
  4543. return {
  4544. w: dojo.global.innerWidth,
  4545. h: dojo.global.innerHeight
  4546. }
  4547. },
  4548. showAlertDialog: function(props){
  4549. var size = dojo.marginBox(this.assistant.domNode);
  4550. var dialog = new dojox.mobile.app.AlertDialog(
  4551. dojo.mixin(props, {controller: this}));
  4552. this.assistant.domNode.appendChild(dialog.domNode);
  4553. console.log("Appended " , dialog.domNode, " to ", this.assistant.domNode);
  4554. dialog.show();
  4555. },
  4556. popupSubMenu: function(info){
  4557. var widget = new dojox.mobile.app.ListSelector({
  4558. controller: this,
  4559. destroyOnHide: true,
  4560. onChoose: info.onChoose
  4561. });
  4562. this.assistant.domNode.appendChild(widget.domNode);
  4563. widget.set("data", info.choices);
  4564. widget.show(info.fromNode);
  4565. }
  4566. });
  4567. })();
  4568. }
  4569. if(!dojo._hasResource["dojox.mobile.app.StageController"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  4570. dojo._hasResource["dojox.mobile.app.StageController"] = true;
  4571. dojo.provide("dojox.mobile.app.StageController");
  4572. dojo.experimental("dojox.mobile.app.StageController");
  4573. dojo.declare("dojox.mobile.app.StageController", null,{
  4574. // scenes: Array
  4575. // The list of scenes currently in existance in the app.
  4576. scenes: null,
  4577. effect: "fade",
  4578. constructor: function(node){
  4579. this.domNode = node;
  4580. this.scenes = [];
  4581. if(dojo.config.mobileAnim){
  4582. this.effect = dojo.config.mobileAnim;
  4583. }
  4584. },
  4585. getActiveSceneController: function(){
  4586. return this.scenes[this.scenes.length - 1];
  4587. },
  4588. pushScene: function(sceneName, params){
  4589. if(this._opInProgress){
  4590. return;
  4591. }
  4592. this._opInProgress = true;
  4593. // Push new scenes as the first element on the page.
  4594. var node = dojo.create("div", {
  4595. "class": "scene-wrapper",
  4596. style: {
  4597. visibility: "hidden"
  4598. }
  4599. }, this.domNode);
  4600. var controller = new dojox.mobile.app.SceneController({}, node);
  4601. if(this.scenes.length > 0){
  4602. this.scenes[this.scenes.length -1].assistant.deactivate();
  4603. }
  4604. this.scenes.push(controller);
  4605. var _this = this;
  4606. dojo.forEach(this.scenes, this.setZIndex);
  4607. controller.stageController = this;
  4608. controller.init(sceneName, params).addCallback(function(){
  4609. if(_this.scenes.length == 1){
  4610. controller.domNode.style.visibility = "visible";
  4611. _this.scenes[_this.scenes.length - 1].assistant.activate(params);
  4612. _this._opInProgress = false;
  4613. }else{
  4614. _this.scenes[_this.scenes.length - 2]
  4615. .performTransition(
  4616. _this.scenes[_this.scenes.length - 1].domNode,
  4617. 1,
  4618. _this.effect,
  4619. null,
  4620. function(){
  4621. // When the scene is ready, activate it.
  4622. _this.scenes[_this.scenes.length - 1].assistant.activate(params);
  4623. _this._opInProgress = false;
  4624. });
  4625. }
  4626. });
  4627. },
  4628. setZIndex: function(controller, idx){
  4629. dojo.style(controller.domNode, "zIndex", idx + 1);
  4630. },
  4631. popScene: function(data){
  4632. // performTransition: function(/*String*/moveTo, /*Number*/dir, /*String*/transition,
  4633. // /*Object|null*/context, /*String|Function*/method /*optional args*/){
  4634. if(this._opInProgress){
  4635. return;
  4636. }
  4637. var _this = this;
  4638. if(this.scenes.length > 1){
  4639. this._opInProgress = true;
  4640. this.scenes[_this.scenes.length - 2].assistant.activate(data);
  4641. this.scenes[_this.scenes.length - 1]
  4642. .performTransition(
  4643. _this.scenes[this.scenes.length - 2].domNode,
  4644. -1,
  4645. this.effect,
  4646. null,
  4647. function(){
  4648. // When the scene is no longer visible, destroy it
  4649. _this._destroyScene(_this.scenes[_this.scenes.length - 1]);
  4650. _this.scenes.splice(_this.scenes.length - 1, 1);
  4651. _this._opInProgress = false;
  4652. });
  4653. }else{
  4654. console.log("cannot pop the scene if there is just one");
  4655. }
  4656. },
  4657. popScenesTo: function(sceneName, data){
  4658. if(this._opInProgress){
  4659. return;
  4660. }
  4661. while(this.scenes.length > 2 &&
  4662. this.scenes[this.scenes.length - 2].sceneName != sceneName){
  4663. this._destroyScene(this.scenes[this.scenes.length - 2]);
  4664. this.scenes.splice(this.scenes.length - 2, 1);
  4665. }
  4666. this.popScene(data);
  4667. },
  4668. _destroyScene: function(scene){
  4669. scene.assistant.deactivate();
  4670. scene.assistant.destroy();
  4671. scene.destroyRecursive();
  4672. }
  4673. });
  4674. }
  4675. if(!dojo._hasResource["dojox.mobile.app.SceneAssistant"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  4676. dojo._hasResource["dojox.mobile.app.SceneAssistant"] = true;
  4677. dojo.provide("dojox.mobile.app.SceneAssistant");
  4678. dojo.experimental("dojox.mobile.app.SceneAssistant");
  4679. dojo.declare("dojox.mobile.app.SceneAssistant", null, {
  4680. // summary:
  4681. // The base class for all scene assistants.
  4682. constructor: function(){
  4683. },
  4684. setup: function(){
  4685. // summary:
  4686. // Called to set up the widget. The UI is not visible at this time
  4687. },
  4688. activate: function(params){
  4689. // summary:
  4690. // Called each time the scene becomes visible. This can be as a result
  4691. // of a new scene being created, or a subsequent scene being destroyed
  4692. // and control transferring back to this scene assistant.
  4693. // params:
  4694. // Optional paramters, only passed when a subsequent scene pops itself
  4695. // off the stack and passes back data.
  4696. },
  4697. deactivate: function(){
  4698. // summary:
  4699. // Called each time the scene becomes invisible. This can be as a result
  4700. // of it being popped off the stack and destroyed,
  4701. // or another scene being created and pushed on top of it on the stack
  4702. },
  4703. destroy: function(){
  4704. var children =
  4705. dojo.query("> [widgetId]", this.containerNode).map(dijit.byNode);
  4706. dojo.forEach(children, function(child){ child.destroyRecursive(); });
  4707. this.disconnect();
  4708. },
  4709. connect: function(obj, method, callback){
  4710. if(!this._connects){
  4711. this._connects = [];
  4712. }
  4713. this._connects.push(dojo.connect(obj, method, callback));
  4714. },
  4715. disconnect: function(){
  4716. dojo.forEach(this._connects, dojo.disconnect);
  4717. this._connects = [];
  4718. }
  4719. });
  4720. }
  4721. if(!dojo._hasResource["dojox.mobile.app.AlertDialog"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  4722. dojo._hasResource["dojox.mobile.app.AlertDialog"] = true;
  4723. dojo.provide("dojox.mobile.app.AlertDialog");
  4724. dojo.experimental("dojox.mobile.app.AlertDialog");
  4725. dojo.declare("dojox.mobile.app.AlertDialog", dijit._WidgetBase, {
  4726. // title: String
  4727. // The title of the AlertDialog
  4728. title: "",
  4729. // text: String
  4730. // The text message displayed in the AlertDialog
  4731. text: "",
  4732. // controller: Object
  4733. // The SceneController for the currently active scene
  4734. controller: null,
  4735. // buttons: Array
  4736. buttons: null,
  4737. defaultButtonLabel: "OK",
  4738. // onChoose: Function
  4739. // The callback function that is invoked when a button is tapped.
  4740. // If the dialog is cancelled, no parameter is passed to this function.
  4741. onChoose: null,
  4742. constructor: function(){
  4743. this.onClick = dojo.hitch(this, this.onClick);
  4744. this._handleSelect = dojo.hitch(this, this._handleSelect);
  4745. },
  4746. buildRendering: function(){
  4747. this.domNode = dojo.create("div",{
  4748. "class": "alertDialog"
  4749. });
  4750. // Create the outer dialog body
  4751. var dlgBody = dojo.create("div", {"class": "alertDialogBody"}, this.domNode);
  4752. // Create the title
  4753. dojo.create("div", {"class": "alertTitle", innerHTML: this.title || ""}, dlgBody);
  4754. // Create the text
  4755. dojo.create("div", {"class": "alertText", innerHTML: this.text || ""}, dlgBody);
  4756. // Create the node that encapsulates all the buttons
  4757. var btnContainer = dojo.create("div", {"class": "alertBtns"}, dlgBody);
  4758. // If no buttons have been defined, default to a single button saying OK
  4759. if(!this.buttons || this.buttons.length == 0){
  4760. this.buttons = [{
  4761. label: this.defaultButtonLabel,
  4762. value: "ok",
  4763. "class": "affirmative"
  4764. }];
  4765. }
  4766. var _this = this;
  4767. // Create each of the buttons
  4768. dojo.forEach(this.buttons, function(btnInfo){
  4769. var btn = new dojox.mobile.Button({
  4770. btnClass: btnInfo["class"] || "",
  4771. label: btnInfo.label
  4772. });
  4773. btn._dialogValue = btnInfo.value;
  4774. dojo.place(btn.domNode, btnContainer);
  4775. _this.connect(btn, "onClick", _this._handleSelect);
  4776. });
  4777. var viewportSize = this.controller.getWindowSize();
  4778. // Create the mask that blocks out the rest of the screen
  4779. this.mask = dojo.create("div", {"class": "dialogUnderlayWrapper",
  4780. innerHTML: "<div class=\"dialogUnderlay\"></div>",
  4781. style: {
  4782. width: viewportSize.w + "px",
  4783. height: viewportSize.h + "px"
  4784. }
  4785. }, this.controller.assistant.domNode);
  4786. this.connect(this.mask, "onclick", function(){
  4787. _this.onChoose && _this.onChoose();
  4788. _this.hide();
  4789. });
  4790. },
  4791. postCreate: function(){
  4792. this.subscribe("/dojox/mobile/app/goback", this._handleSelect);
  4793. },
  4794. _handleSelect: function(event){
  4795. // summary:
  4796. // Handle the selection of a value
  4797. var node;
  4798. console.log("handleSelect");
  4799. if(event && event.target){
  4800. node = event.target;
  4801. // Find the widget that was tapped.
  4802. while(!dijit.byNode(node)){
  4803. node - node.parentNode;
  4804. }
  4805. }
  4806. // If an onChoose function was provided, tell it what button
  4807. // value was chosen
  4808. if(this.onChoose){
  4809. this.onChoose(node ? dijit.byNode(node)._dialogValue: undefined);
  4810. }
  4811. // Hide the dialog
  4812. this.hide();
  4813. },
  4814. show: function(){
  4815. // summary:
  4816. // Show the dialog
  4817. this._doTransition(1);
  4818. },
  4819. hide: function(){
  4820. // summary:
  4821. // Hide the dialog
  4822. this._doTransition(-1);
  4823. },
  4824. _doTransition: function(dir){
  4825. // summary:
  4826. // Either shows or hides the dialog.
  4827. // dir:
  4828. // An integer. If positive, the dialog is shown. If negative,
  4829. // the dialog is hidden.
  4830. // TODO: replace this with CSS transitions
  4831. var anim;
  4832. var h = dojo.marginBox(this.domNode.firstChild).h;
  4833. var bodyHeight = this.controller.getWindowSize().h;
  4834. console.log("dialog height = " + h, " body height = " + bodyHeight);
  4835. var high = bodyHeight - h;
  4836. var low = bodyHeight;
  4837. var anim1 = dojo.fx.slideTo({
  4838. node: this.domNode,
  4839. duration: 400,
  4840. top: {start: dir < 0 ? high : low, end: dir < 0 ? low: high}
  4841. });
  4842. var anim2 = dojo[dir < 0 ? "fadeOut" : "fadeIn"]({
  4843. node: this.mask,
  4844. duration: 400
  4845. });
  4846. var anim = dojo.fx.combine([anim1, anim2]);
  4847. var _this = this;
  4848. dojo.connect(anim, "onEnd", this, function(){
  4849. if(dir < 0){
  4850. _this.domNode.style.display = "none";
  4851. dojo.destroy(_this.domNode);
  4852. dojo.destroy(_this.mask);
  4853. }
  4854. });
  4855. anim.play();
  4856. },
  4857. destroy: function(){
  4858. this.inherited(arguments);
  4859. dojo.destroy(this.mask);
  4860. },
  4861. onClick: function(){
  4862. }
  4863. });
  4864. }
  4865. if(!dojo._hasResource["dojo.string"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  4866. dojo._hasResource["dojo.string"] = true;
  4867. dojo.provide("dojo.string");
  4868. dojo.getObject("string", true, dojo);
  4869. /*=====
  4870. dojo.string = {
  4871. // summary: String utilities for Dojo
  4872. };
  4873. =====*/
  4874. dojo.string.rep = function(/*String*/str, /*Integer*/num){
  4875. // summary:
  4876. // Efficiently replicate a string `n` times.
  4877. // str:
  4878. // the string to replicate
  4879. // num:
  4880. // number of times to replicate the string
  4881. if(num <= 0 || !str){ return ""; }
  4882. var buf = [];
  4883. for(;;){
  4884. if(num & 1){
  4885. buf.push(str);
  4886. }
  4887. if(!(num >>= 1)){ break; }
  4888. str += str;
  4889. }
  4890. return buf.join(""); // String
  4891. };
  4892. dojo.string.pad = function(/*String*/text, /*Integer*/size, /*String?*/ch, /*Boolean?*/end){
  4893. // summary:
  4894. // Pad a string to guarantee that it is at least `size` length by
  4895. // filling with the character `ch` at either the start or end of the
  4896. // string. Pads at the start, by default.
  4897. // text:
  4898. // the string to pad
  4899. // size:
  4900. // length to provide padding
  4901. // ch:
  4902. // character to pad, defaults to '0'
  4903. // end:
  4904. // adds padding at the end if true, otherwise pads at start
  4905. // example:
  4906. // | // Fill the string to length 10 with "+" characters on the right. Yields "Dojo++++++".
  4907. // | dojo.string.pad("Dojo", 10, "+", true);
  4908. if(!ch){
  4909. ch = '0';
  4910. }
  4911. var out = String(text),
  4912. pad = dojo.string.rep(ch, Math.ceil((size - out.length) / ch.length));
  4913. return end ? out + pad : pad + out; // String
  4914. };
  4915. dojo.string.substitute = function( /*String*/ template,
  4916. /*Object|Array*/map,
  4917. /*Function?*/ transform,
  4918. /*Object?*/ thisObject){
  4919. // summary:
  4920. // Performs parameterized substitutions on a string. Throws an
  4921. // exception if any parameter is unmatched.
  4922. // template:
  4923. // a string with expressions in the form `${key}` to be replaced or
  4924. // `${key:format}` which specifies a format function. keys are case-sensitive.
  4925. // map:
  4926. // hash to search for substitutions
  4927. // transform:
  4928. // a function to process all parameters before substitution takes
  4929. // place, e.g. mylib.encodeXML
  4930. // thisObject:
  4931. // where to look for optional format function; default to the global
  4932. // namespace
  4933. // example:
  4934. // Substitutes two expressions in a string from an Array or Object
  4935. // | // returns "File 'foo.html' is not found in directory '/temp'."
  4936. // | // by providing substitution data in an Array
  4937. // | dojo.string.substitute(
  4938. // | "File '${0}' is not found in directory '${1}'.",
  4939. // | ["foo.html","/temp"]
  4940. // | );
  4941. // |
  4942. // | // also returns "File 'foo.html' is not found in directory '/temp'."
  4943. // | // but provides substitution data in an Object structure. Dotted
  4944. // | // notation may be used to traverse the structure.
  4945. // | dojo.string.substitute(
  4946. // | "File '${name}' is not found in directory '${info.dir}'.",
  4947. // | { name: "foo.html", info: { dir: "/temp" } }
  4948. // | );
  4949. // example:
  4950. // Use a transform function to modify the values:
  4951. // | // returns "file 'foo.html' is not found in directory '/temp'."
  4952. // | dojo.string.substitute(
  4953. // | "${0} is not found in ${1}.",
  4954. // | ["foo.html","/temp"],
  4955. // | function(str){
  4956. // | // try to figure out the type
  4957. // | var prefix = (str.charAt(0) == "/") ? "directory": "file";
  4958. // | return prefix + " '" + str + "'";
  4959. // | }
  4960. // | );
  4961. // example:
  4962. // Use a formatter
  4963. // | // returns "thinger -- howdy"
  4964. // | dojo.string.substitute(
  4965. // | "${0:postfix}", ["thinger"], null, {
  4966. // | postfix: function(value, key){
  4967. // | return value + " -- howdy";
  4968. // | }
  4969. // | }
  4970. // | );
  4971. thisObject = thisObject || dojo.global;
  4972. transform = transform ?
  4973. dojo.hitch(thisObject, transform) : function(v){ return v; };
  4974. return template.replace(/\$\{([^\s\:\}]+)(?:\:([^\s\:\}]+))?\}/g,
  4975. function(match, key, format){
  4976. var value = dojo.getObject(key, false, map);
  4977. if(format){
  4978. value = dojo.getObject(format, false, thisObject).call(thisObject, value, key);
  4979. }
  4980. return transform(value, key).toString();
  4981. }); // String
  4982. };
  4983. /*=====
  4984. dojo.string.trim = function(str){
  4985. // summary:
  4986. // Trims whitespace from both sides of the string
  4987. // str: String
  4988. // String to be trimmed
  4989. // returns: String
  4990. // Returns the trimmed string
  4991. // description:
  4992. // This version of trim() was taken from [Steven Levithan's blog](http://blog.stevenlevithan.com/archives/faster-trim-javascript).
  4993. // The short yet performant version of this function is dojo.trim(),
  4994. // which is part of Dojo base. Uses String.prototype.trim instead, if available.
  4995. return ""; // String
  4996. }
  4997. =====*/
  4998. dojo.string.trim = String.prototype.trim ?
  4999. dojo.trim : // aliasing to the native function
  5000. function(str){
  5001. str = str.replace(/^\s+/, '');
  5002. for(var i = str.length - 1; i >= 0; i--){
  5003. if(/\S/.test(str.charAt(i))){
  5004. str = str.substring(0, i + 1);
  5005. break;
  5006. }
  5007. }
  5008. return str;
  5009. };
  5010. }
  5011. if(!dojo._hasResource["dojox.mobile.app.List"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  5012. dojo._hasResource["dojox.mobile.app.List"] = true;
  5013. dojo.provide("dojox.mobile.app.List");
  5014. dojo.experimental("dojox.mobile.app.List");
  5015. (function(){
  5016. var templateCache = {};
  5017. dojo.declare("dojox.mobile.app.List", dijit._WidgetBase, {
  5018. // summary:
  5019. // A templated list widget. Given a simple array of data objects
  5020. // and a HTML template, it renders a list of elements, with
  5021. // support for a swipe delete action. An optional template
  5022. // can be provided for when the list is empty.
  5023. // items: Array
  5024. // The array of data items that will be rendered.
  5025. items: null,
  5026. // itemTemplate: String
  5027. // The URL to the HTML file containing the markup for each individual
  5028. // data item.
  5029. itemTemplate: "",
  5030. // emptyTemplate: String
  5031. // The URL to the HTML file containing the HTML to display if there
  5032. // are no data items. This is optional.
  5033. emptyTemplate: "",
  5034. // dividerTemplate: String
  5035. // The URL to the HTML file containing the markup for the dividers
  5036. // between groups of list items
  5037. dividerTemplate: "",
  5038. // dividerFunction: Function
  5039. // Function to create divider elements. This should return a divider
  5040. // value for each item in the list
  5041. dividerFunction: null,
  5042. // labelDelete: String
  5043. // The label to display for the Delete button
  5044. labelDelete: "Delete",
  5045. // labelCancel: String
  5046. // The label to display for the Cancel button
  5047. labelCancel: "Cancel",
  5048. // controller: Object
  5049. //
  5050. controller: null,
  5051. // autoDelete: Boolean
  5052. autoDelete: true,
  5053. // enableDelete: Boolean
  5054. enableDelete: true,
  5055. // enableHold: Boolean
  5056. enableHold: true,
  5057. // formatters: Object
  5058. // A name/value map of functions used to format data for display
  5059. formatters: null,
  5060. // _templateLoadCount: Number
  5061. // The number of templates remaining to load before the list renders.
  5062. _templateLoadCount: 0,
  5063. // _mouseDownPos: Object
  5064. // The coordinates of where a mouseDown event was detected
  5065. _mouseDownPos: null,
  5066. baseClass: "list",
  5067. constructor: function(){
  5068. this._checkLoadComplete = dojo.hitch(this, this._checkLoadComplete);
  5069. this._replaceToken = dojo.hitch(this, this._replaceToken);
  5070. this._postDeleteAnim = dojo.hitch(this, this._postDeleteAnim);
  5071. },
  5072. postCreate: function(){
  5073. var _this = this;
  5074. if(this.emptyTemplate){
  5075. this._templateLoadCount++;
  5076. }
  5077. if(this.itemTemplate){
  5078. this._templateLoadCount++;
  5079. }
  5080. if(this.dividerTemplate){
  5081. this._templateLoadCount++;
  5082. }
  5083. this.connect(this.domNode, "onmousedown", function(event){
  5084. var touch = event;
  5085. if(event.targetTouches && event.targetTouches.length > 0){
  5086. touch = event.targetTouches[0];
  5087. }
  5088. // Find the node that was tapped/clicked
  5089. var rowNode = _this._getRowNode(event.target);
  5090. if(rowNode){
  5091. // Add the rows data to the event so it can be picked up
  5092. // by any listeners
  5093. _this._setDataInfo(rowNode, event);
  5094. // Select and highlight the row
  5095. _this._selectRow(rowNode);
  5096. // Record the position that was tapped
  5097. _this._mouseDownPos = {
  5098. x: touch.pageX,
  5099. y: touch.pageY
  5100. };
  5101. _this._dragThreshold = null;
  5102. }
  5103. });
  5104. this.connect(this.domNode, "onmouseup", function(event){
  5105. // When the mouse/finger comes off the list,
  5106. // call the onSelect function and deselect the row.
  5107. if(event.targetTouches && event.targetTouches.length > 0){
  5108. event = event.targetTouches[0];
  5109. }
  5110. var rowNode = _this._getRowNode(event.target);
  5111. if(rowNode){
  5112. _this._setDataInfo(rowNode, event);
  5113. if(_this._selectedRow){
  5114. _this.onSelect(rowNode._data, rowNode._idx, rowNode);
  5115. }
  5116. this._deselectRow();
  5117. }
  5118. });
  5119. // If swipe-to-delete is enabled, listen for the mouse moving
  5120. if(this.enableDelete){
  5121. this.connect(this.domNode, "mousemove", function(event){
  5122. dojo.stopEvent(event);
  5123. if(!_this._selectedRow){
  5124. return;
  5125. }
  5126. var rowNode = _this._getRowNode(event.target);
  5127. // Still check for enableDelete in case it's changed after
  5128. // this listener is added.
  5129. if(_this.enableDelete && rowNode && !_this._deleting){
  5130. _this.handleDrag(event);
  5131. }
  5132. });
  5133. }
  5134. // Put the data and index onto each onclick event.
  5135. this.connect(this.domNode, "onclick", function(event){
  5136. if(event.touches && event.touches.length > 0){
  5137. event = event.touches[0];
  5138. }
  5139. var rowNode = _this._getRowNode(event.target, true);
  5140. if(rowNode){
  5141. _this._setDataInfo(rowNode, event);
  5142. }
  5143. });
  5144. // If the mouse or finger moves off the selected row,
  5145. // deselect it.
  5146. this.connect(this.domNode, "mouseout", function(event){
  5147. if(event.touches && event.touches.length > 0){
  5148. event = event.touches[0];
  5149. }
  5150. if(event.target == _this._selectedRow){
  5151. _this._deselectRow();
  5152. }
  5153. });
  5154. // If no item template has been provided, it is an error.
  5155. if(!this.itemTemplate){
  5156. throw Error("An item template must be provided to " + this.declaredClass);
  5157. }
  5158. // Load the item template
  5159. this._loadTemplate(this.itemTemplate, "itemTemplate", this._checkLoadComplete);
  5160. if(this.emptyTemplate){
  5161. // If the optional empty template has been provided, load it.
  5162. this._loadTemplate(this.emptyTemplate, "emptyTemplate", this._checkLoadComplete);
  5163. }
  5164. if(this.dividerTemplate){
  5165. this._loadTemplate(this.dividerTemplate, "dividerTemplate", this._checkLoadComplete);
  5166. }
  5167. },
  5168. handleDrag: function(event){
  5169. // summary:
  5170. // Handles rows being swiped for deletion.
  5171. var touch = event;
  5172. if(event.targetTouches && event.targetTouches.length > 0){
  5173. touch = event.targetTouches[0];
  5174. }
  5175. // Get the distance that the mouse or finger has moved since
  5176. // beginning the swipe action.
  5177. var diff = touch.pageX - this._mouseDownPos.x;
  5178. var absDiff = Math.abs(diff);
  5179. if(absDiff > 10 && !this._dragThreshold){
  5180. // Make the user drag the row 60% of the width to remove it
  5181. this._dragThreshold = dojo.marginBox(this._selectedRow).w * 0.6;
  5182. if(!this.autoDelete){
  5183. this.createDeleteButtons(this._selectedRow);
  5184. }
  5185. }
  5186. this._selectedRow.style.left = (absDiff > 10 ? diff : 0) + "px";
  5187. // If the user has dragged the row more than the threshold, slide
  5188. // it off the screen in preparation for deletion.
  5189. if(this._dragThreshold && this._dragThreshold < absDiff){
  5190. this.preDelete(diff);
  5191. }
  5192. },
  5193. handleDragCancel: function(){
  5194. // summary:
  5195. // Handle a drag action being cancelled, for whatever reason.
  5196. // Reset handles, remove CSS classes etc.
  5197. if(this._deleting){
  5198. return;
  5199. }
  5200. dojo.removeClass(this._selectedRow, "hold");
  5201. this._selectedRow.style.left = 0;
  5202. this._mouseDownPos = null;
  5203. this._dragThreshold = null;
  5204. this._deleteBtns && dojo.style(this._deleteBtns, "display", "none");
  5205. },
  5206. preDelete: function(currentLeftPos){
  5207. // summary:
  5208. // Slides the row offscreen before it is deleted
  5209. // TODO: do this with CSS3!
  5210. var self = this;
  5211. this._deleting = true;
  5212. dojo.animateProperty({
  5213. node: this._selectedRow,
  5214. duration: 400,
  5215. properties: {
  5216. left: {
  5217. end: currentLeftPos +
  5218. ((currentLeftPos > 0 ? 1 : -1) * this._dragThreshold * 0.8)
  5219. }
  5220. },
  5221. onEnd: dojo.hitch(this, function(){
  5222. if(this.autoDelete){
  5223. this.deleteRow(this._selectedRow);
  5224. }
  5225. })
  5226. }).play();
  5227. },
  5228. deleteRow: function(row){
  5229. // First make the row invisible
  5230. // Put it back where it came from
  5231. dojo.style(row, {
  5232. visibility: "hidden",
  5233. minHeight: "0px"
  5234. });
  5235. dojo.removeClass(row, "hold");
  5236. this._deleteAnimConn =
  5237. this.connect(row, "webkitAnimationEnd", this._postDeleteAnim);
  5238. dojo.addClass(row, "collapsed");
  5239. },
  5240. _postDeleteAnim: function(event){
  5241. // summary:
  5242. // Completes the deletion of a row.
  5243. if(this._deleteAnimConn){
  5244. this.disconnect(this._deleteAnimConn);
  5245. this._deleteAnimConn = null;
  5246. }
  5247. var row = this._selectedRow;
  5248. var sibling = row.nextSibling;
  5249. var prevSibling = row.previousSibling;
  5250. // If the previous node is a divider and either this is
  5251. // the last element in the list, or the next node is
  5252. // also a divider, remove the divider for the deleted section.
  5253. if(prevSibling && prevSibling._isDivider){
  5254. if(!sibling || sibling._isDivider){
  5255. prevSibling.parentNode.removeChild(prevSibling);
  5256. }
  5257. }
  5258. row.parentNode.removeChild(row);
  5259. this.onDelete(row._data, row._idx, this.items);
  5260. // Decrement the index of each following row
  5261. while(sibling){
  5262. if(sibling._idx){
  5263. sibling._idx--;
  5264. }
  5265. sibling = sibling.nextSibling;
  5266. }
  5267. dojo.destroy(row);
  5268. // Fix up the 'first' and 'last' CSS classes on the rows
  5269. dojo.query("> *:not(.buttons)", this.domNode).forEach(this.applyClass);
  5270. this._deleting = false;
  5271. this._deselectRow();
  5272. },
  5273. createDeleteButtons: function(aroundNode){
  5274. // summary:
  5275. // Creates the two buttons displayed when confirmation is
  5276. // required before deletion of a row.
  5277. // aroundNode:
  5278. // The DOM node of the row about to be deleted.
  5279. var mb = dojo.marginBox(aroundNode);
  5280. var pos = dojo._abs(aroundNode, true);
  5281. if(!this._deleteBtns){
  5282. // Create the delete buttons.
  5283. this._deleteBtns = dojo.create("div",{
  5284. "class": "buttons"
  5285. }, this.domNode);
  5286. this.buttons = [];
  5287. this.buttons.push(new dojox.mobile.Button({
  5288. btnClass: "mblRedButton",
  5289. label: this.labelDelete
  5290. }));
  5291. this.buttons.push(new dojox.mobile.Button({
  5292. btnClass: "mblBlueButton",
  5293. label: this.labelCancel
  5294. }));
  5295. dojo.place(this.buttons[0].domNode, this._deleteBtns);
  5296. dojo.place(this.buttons[1].domNode, this._deleteBtns);
  5297. dojo.addClass(this.buttons[0].domNode, "deleteBtn");
  5298. dojo.addClass(this.buttons[1].domNode, "cancelBtn");
  5299. this._handleButtonClick = dojo.hitch(this._handleButtonClick);
  5300. this.connect(this._deleteBtns, "onclick", this._handleButtonClick);
  5301. }
  5302. dojo.removeClass(this._deleteBtns, "fade out fast");
  5303. dojo.style(this._deleteBtns, {
  5304. display: "",
  5305. width: mb.w + "px",
  5306. height: mb.h + "px",
  5307. top: (aroundNode.offsetTop) + "px",
  5308. left: "0px"
  5309. });
  5310. },
  5311. onDelete: function(data, index, array){
  5312. // summary:
  5313. // Called when a row is deleted
  5314. // data:
  5315. // The data related to the row being deleted
  5316. // index:
  5317. // The index of the data in the total array
  5318. // array:
  5319. // The array of data used.
  5320. array.splice(index, 1);
  5321. // If the data is empty, rerender in case an emptyTemplate has
  5322. // been provided
  5323. if(array.length < 1){
  5324. this.render();
  5325. }
  5326. },
  5327. cancelDelete: function(){
  5328. // summary:
  5329. // Cancels the deletion of a row.
  5330. this._deleting = false;
  5331. this.handleDragCancel();
  5332. },
  5333. _handleButtonClick: function(event){
  5334. // summary:
  5335. // Handles the click of one of the deletion buttons, either to
  5336. // delete the row or to cancel the deletion.
  5337. if(event.touches && event.touches.length > 0){
  5338. event = event.touches[0];
  5339. }
  5340. var node = event.target;
  5341. if(dojo.hasClass(node, "deleteBtn")){
  5342. this.deleteRow(this._selectedRow);
  5343. }else if(dojo.hasClass(node, "cancelBtn")){
  5344. this.cancelDelete();
  5345. }else{
  5346. return;
  5347. }
  5348. dojo.addClass(this._deleteBtns, "fade out");
  5349. },
  5350. applyClass: function(node, idx, array){
  5351. // summary:
  5352. // Applies the 'first' and 'last' CSS classes to the relevant
  5353. // rows.
  5354. dojo.removeClass(node, "first last");
  5355. if(idx == 0){
  5356. dojo.addClass(node, "first");
  5357. }
  5358. if(idx == array.length - 1){
  5359. dojo.addClass(node, "last");
  5360. }
  5361. },
  5362. _setDataInfo: function(rowNode, event){
  5363. // summary:
  5364. // Attaches the data item and index for each row to any event
  5365. // that occurs on that row.
  5366. event.item = rowNode._data;
  5367. event.index = rowNode._idx;
  5368. },
  5369. onSelect: function(data, index, rowNode){
  5370. // summary:
  5371. // Dummy function that is called when a row is tapped
  5372. },
  5373. _selectRow: function(row){
  5374. // summary:
  5375. // Selects a row, applies the relevant CSS classes.
  5376. if(this._deleting && this._selectedRow && row != this._selectedRow){
  5377. this.cancelDelete();
  5378. }
  5379. if(!dojo.hasClass(row, "row")){
  5380. return;
  5381. }
  5382. if(this.enableHold || this.enableDelete){
  5383. dojo.addClass(row, "hold");
  5384. }
  5385. this._selectedRow = row;
  5386. },
  5387. _deselectRow: function(){
  5388. // summary:
  5389. // Deselects a row, and cancels any drag actions that were
  5390. // occurring.
  5391. if(!this._selectedRow || this._deleting){
  5392. return;
  5393. }
  5394. this.handleDragCancel();
  5395. dojo.removeClass(this._selectedRow, "hold");
  5396. this._selectedRow = null;
  5397. },
  5398. _getRowNode: function(fromNode, ignoreNoClick){
  5399. // summary:
  5400. // Gets the DOM node of the row that is equal to or the parent
  5401. // of the node passed to this function.
  5402. while(fromNode && !fromNode._data && fromNode != this.domNode){
  5403. if(!ignoreNoClick && dojo.hasClass(fromNode, "noclick")){
  5404. return null;
  5405. }
  5406. fromNode = fromNode.parentNode;
  5407. }
  5408. return fromNode == this.domNode ? null : fromNode;
  5409. },
  5410. applyTemplate: function(template, data){
  5411. return dojo._toDom(dojo.string.substitute(
  5412. template, data, this._replaceToken, this.formatters || this));
  5413. },
  5414. render: function(){
  5415. // summary:
  5416. // Renders the list.
  5417. // Delete all existing nodes, except the deletion buttons.
  5418. dojo.query("> *:not(.buttons)", this.domNode).forEach(dojo.destroy);
  5419. // If there is no data, and an empty template has been provided,
  5420. // render it.
  5421. if(this.items.length < 1 && this.emptyTemplate){
  5422. dojo.place(dojo._toDom(this.emptyTemplate), this.domNode, "first");
  5423. }else{
  5424. this.domNode.appendChild(this._renderRange(0, this.items.length));
  5425. }
  5426. if(dojo.hasClass(this.domNode.parentNode, "mblRoundRect")){
  5427. dojo.addClass(this.domNode.parentNode, "mblRoundRectList")
  5428. }
  5429. var divs = dojo.query("> .row", this.domNode);
  5430. if(divs.length > 0){
  5431. dojo.addClass(divs[0], "first");
  5432. dojo.addClass(divs[divs.length - 1], "last");
  5433. }
  5434. },
  5435. _renderRange: function(startIdx, endIdx){
  5436. var rows = [];
  5437. var row, i;
  5438. var frag = document.createDocumentFragment();
  5439. startIdx = Math.max(0, startIdx);
  5440. endIdx = Math.min(endIdx, this.items.length);
  5441. for(i = startIdx; i < endIdx; i++){
  5442. // Create a document fragment containing the templated row
  5443. row = this.applyTemplate(this.itemTemplate, this.items[i]);
  5444. dojo.addClass(row, 'row');
  5445. row._data = this.items[i];
  5446. row._idx = i;
  5447. rows.push(row);
  5448. }
  5449. if(!this.dividerFunction || !this.dividerTemplate){
  5450. for(i = startIdx; i < endIdx; i++){
  5451. rows[i]._data = this.items[i];
  5452. rows[i]._idx = i;
  5453. frag.appendChild(rows[i]);
  5454. }
  5455. }else{
  5456. var prevDividerValue = null;
  5457. var dividerValue;
  5458. var divider;
  5459. for(i = startIdx; i < endIdx; i++){
  5460. rows[i]._data = this.items[i];
  5461. rows[i]._idx = i;
  5462. dividerValue = this.dividerFunction(this.items[i]);
  5463. if(dividerValue && dividerValue != prevDividerValue){
  5464. divider = this.applyTemplate(this.dividerTemplate, {
  5465. label: dividerValue,
  5466. item: this.items[i]
  5467. });
  5468. divider._isDivider = true;
  5469. frag.appendChild(divider);
  5470. prevDividerValue = dividerValue;
  5471. }
  5472. frag.appendChild(rows[i]);
  5473. }
  5474. }
  5475. return frag;
  5476. },
  5477. _replaceToken: function(value, key){
  5478. if(key.charAt(0) == '!'){ value = dojo.getObject(key.substr(1), false, _this); }
  5479. if(typeof value == "undefined"){ return ""; } // a debugging aide
  5480. if(value == null){ return ""; }
  5481. // Substitution keys beginning with ! will skip the transform step,
  5482. // in case a user wishes to insert unescaped markup, e.g. ${!foo}
  5483. return key.charAt(0) == "!" ? value :
  5484. // Safer substitution, see heading "Attribute values" in
  5485. // http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.3.2
  5486. value.toString().replace(/"/g,"&quot;"); //TODO: add &amp? use encodeXML method?
  5487. },
  5488. _checkLoadComplete: function(){
  5489. // summary:
  5490. // Checks if all templates have loaded
  5491. this._templateLoadCount--;
  5492. if(this._templateLoadCount < 1 && this.get("items")){
  5493. this.render();
  5494. }
  5495. },
  5496. _loadTemplate: function(url, thisAttr, callback){
  5497. // summary:
  5498. // Loads a template
  5499. if(!url){
  5500. callback();
  5501. return;
  5502. }
  5503. if(templateCache[url]){
  5504. this.set(thisAttr, templateCache[url]);
  5505. callback();
  5506. }else{
  5507. var _this = this;
  5508. dojo.xhrGet({
  5509. url: url,
  5510. sync: false,
  5511. handleAs: "text",
  5512. load: function(text){
  5513. templateCache[url] = dojo.trim(text);
  5514. _this.set(thisAttr, templateCache[url]);
  5515. callback();
  5516. }
  5517. });
  5518. }
  5519. },
  5520. _setFormattersAttr: function(formatters){
  5521. // summary:
  5522. // Sets the data items, and causes a rerender of the list
  5523. this.formatters = formatters;
  5524. },
  5525. _setItemsAttr: function(items){
  5526. // summary:
  5527. // Sets the data items, and causes a rerender of the list
  5528. this.items = items || [];
  5529. if(this._templateLoadCount < 1 && items){
  5530. this.render();
  5531. }
  5532. },
  5533. destroy: function(){
  5534. if(this.buttons){
  5535. dojo.forEach(this.buttons, function(button){
  5536. button.destroy();
  5537. });
  5538. this.buttons = null;
  5539. }
  5540. this.inherited(arguments);
  5541. }
  5542. });
  5543. })();
  5544. }
  5545. if(!dojo._hasResource["dojo.fx.Toggler"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  5546. dojo._hasResource["dojo.fx.Toggler"] = true;
  5547. dojo.provide("dojo.fx.Toggler");
  5548. dojo.declare("dojo.fx.Toggler", null, {
  5549. // summary:
  5550. // A simple `dojo.Animation` toggler API.
  5551. //
  5552. // description:
  5553. // class constructor for an animation toggler. It accepts a packed
  5554. // set of arguments about what type of animation to use in each
  5555. // direction, duration, etc. All available members are mixed into
  5556. // these animations from the constructor (for example, `node`,
  5557. // `showDuration`, `hideDuration`).
  5558. //
  5559. // example:
  5560. // | var t = new dojo.fx.Toggler({
  5561. // | node: "nodeId",
  5562. // | showDuration: 500,
  5563. // | // hideDuration will default to "200"
  5564. // | showFunc: dojo.fx.wipeIn,
  5565. // | // hideFunc will default to "fadeOut"
  5566. // | });
  5567. // | t.show(100); // delay showing for 100ms
  5568. // | // ...time passes...
  5569. // | t.hide();
  5570. // node: DomNode
  5571. // the node to target for the showing and hiding animations
  5572. node: null,
  5573. // showFunc: Function
  5574. // The function that returns the `dojo.Animation` to show the node
  5575. showFunc: dojo.fadeIn,
  5576. // hideFunc: Function
  5577. // The function that returns the `dojo.Animation` to hide the node
  5578. hideFunc: dojo.fadeOut,
  5579. // showDuration:
  5580. // Time in milliseconds to run the show Animation
  5581. showDuration: 200,
  5582. // hideDuration:
  5583. // Time in milliseconds to run the hide Animation
  5584. hideDuration: 200,
  5585. // FIXME: need a policy for where the toggler should "be" the next
  5586. // time show/hide are called if we're stopped somewhere in the
  5587. // middle.
  5588. // FIXME: also would be nice to specify individual showArgs/hideArgs mixed into
  5589. // each animation individually.
  5590. // FIXME: also would be nice to have events from the animations exposed/bridged
  5591. /*=====
  5592. _showArgs: null,
  5593. _showAnim: null,
  5594. _hideArgs: null,
  5595. _hideAnim: null,
  5596. _isShowing: false,
  5597. _isHiding: false,
  5598. =====*/
  5599. constructor: function(args){
  5600. var _t = this;
  5601. dojo.mixin(_t, args);
  5602. _t.node = args.node;
  5603. _t._showArgs = dojo.mixin({}, args);
  5604. _t._showArgs.node = _t.node;
  5605. _t._showArgs.duration = _t.showDuration;
  5606. _t.showAnim = _t.showFunc(_t._showArgs);
  5607. _t._hideArgs = dojo.mixin({}, args);
  5608. _t._hideArgs.node = _t.node;
  5609. _t._hideArgs.duration = _t.hideDuration;
  5610. _t.hideAnim = _t.hideFunc(_t._hideArgs);
  5611. dojo.connect(_t.showAnim, "beforeBegin", dojo.hitch(_t.hideAnim, "stop", true));
  5612. dojo.connect(_t.hideAnim, "beforeBegin", dojo.hitch(_t.showAnim, "stop", true));
  5613. },
  5614. show: function(delay){
  5615. // summary: Toggle the node to showing
  5616. // delay: Integer?
  5617. // Ammount of time to stall playing the show animation
  5618. return this.showAnim.play(delay || 0);
  5619. },
  5620. hide: function(delay){
  5621. // summary: Toggle the node to hidden
  5622. // delay: Integer?
  5623. // Ammount of time to stall playing the hide animation
  5624. return this.hideAnim.play(delay || 0);
  5625. }
  5626. });
  5627. }
  5628. if(!dojo._hasResource["dojo.fx"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  5629. dojo._hasResource["dojo.fx"] = true;
  5630. dojo.provide("dojo.fx");
  5631. /*=====
  5632. dojo.fx = {
  5633. // summary: Effects library on top of Base animations
  5634. };
  5635. =====*/
  5636. (function(){
  5637. var d = dojo,
  5638. _baseObj = {
  5639. _fire: function(evt, args){
  5640. if(this[evt]){
  5641. this[evt].apply(this, args||[]);
  5642. }
  5643. return this;
  5644. }
  5645. };
  5646. var _chain = function(animations){
  5647. this._index = -1;
  5648. this._animations = animations||[];
  5649. this._current = this._onAnimateCtx = this._onEndCtx = null;
  5650. this.duration = 0;
  5651. d.forEach(this._animations, function(a){
  5652. this.duration += a.duration;
  5653. if(a.delay){ this.duration += a.delay; }
  5654. }, this);
  5655. };
  5656. d.extend(_chain, {
  5657. _onAnimate: function(){
  5658. this._fire("onAnimate", arguments);
  5659. },
  5660. _onEnd: function(){
  5661. d.disconnect(this._onAnimateCtx);
  5662. d.disconnect(this._onEndCtx);
  5663. this._onAnimateCtx = this._onEndCtx = null;
  5664. if(this._index + 1 == this._animations.length){
  5665. this._fire("onEnd");
  5666. }else{
  5667. // switch animations
  5668. this._current = this._animations[++this._index];
  5669. this._onAnimateCtx = d.connect(this._current, "onAnimate", this, "_onAnimate");
  5670. this._onEndCtx = d.connect(this._current, "onEnd", this, "_onEnd");
  5671. this._current.play(0, true);
  5672. }
  5673. },
  5674. play: function(/*int?*/ delay, /*Boolean?*/ gotoStart){
  5675. if(!this._current){ this._current = this._animations[this._index = 0]; }
  5676. if(!gotoStart && this._current.status() == "playing"){ return this; }
  5677. var beforeBegin = d.connect(this._current, "beforeBegin", this, function(){
  5678. this._fire("beforeBegin");
  5679. }),
  5680. onBegin = d.connect(this._current, "onBegin", this, function(arg){
  5681. this._fire("onBegin", arguments);
  5682. }),
  5683. onPlay = d.connect(this._current, "onPlay", this, function(arg){
  5684. this._fire("onPlay", arguments);
  5685. d.disconnect(beforeBegin);
  5686. d.disconnect(onBegin);
  5687. d.disconnect(onPlay);
  5688. });
  5689. if(this._onAnimateCtx){
  5690. d.disconnect(this._onAnimateCtx);
  5691. }
  5692. this._onAnimateCtx = d.connect(this._current, "onAnimate", this, "_onAnimate");
  5693. if(this._onEndCtx){
  5694. d.disconnect(this._onEndCtx);
  5695. }
  5696. this._onEndCtx = d.connect(this._current, "onEnd", this, "_onEnd");
  5697. this._current.play.apply(this._current, arguments);
  5698. return this;
  5699. },
  5700. pause: function(){
  5701. if(this._current){
  5702. var e = d.connect(this._current, "onPause", this, function(arg){
  5703. this._fire("onPause", arguments);
  5704. d.disconnect(e);
  5705. });
  5706. this._current.pause();
  5707. }
  5708. return this;
  5709. },
  5710. gotoPercent: function(/*Decimal*/percent, /*Boolean?*/ andPlay){
  5711. this.pause();
  5712. var offset = this.duration * percent;
  5713. this._current = null;
  5714. d.some(this._animations, function(a){
  5715. if(a.duration <= offset){
  5716. this._current = a;
  5717. return true;
  5718. }
  5719. offset -= a.duration;
  5720. return false;
  5721. });
  5722. if(this._current){
  5723. this._current.gotoPercent(offset / this._current.duration, andPlay);
  5724. }
  5725. return this;
  5726. },
  5727. stop: function(/*boolean?*/ gotoEnd){
  5728. if(this._current){
  5729. if(gotoEnd){
  5730. for(; this._index + 1 < this._animations.length; ++this._index){
  5731. this._animations[this._index].stop(true);
  5732. }
  5733. this._current = this._animations[this._index];
  5734. }
  5735. var e = d.connect(this._current, "onStop", this, function(arg){
  5736. this._fire("onStop", arguments);
  5737. d.disconnect(e);
  5738. });
  5739. this._current.stop();
  5740. }
  5741. return this;
  5742. },
  5743. status: function(){
  5744. return this._current ? this._current.status() : "stopped";
  5745. },
  5746. destroy: function(){
  5747. if(this._onAnimateCtx){ d.disconnect(this._onAnimateCtx); }
  5748. if(this._onEndCtx){ d.disconnect(this._onEndCtx); }
  5749. }
  5750. });
  5751. d.extend(_chain, _baseObj);
  5752. dojo.fx.chain = function(/*dojo.Animation[]*/ animations){
  5753. // summary:
  5754. // Chain a list of `dojo.Animation`s to run in sequence
  5755. //
  5756. // description:
  5757. // Return a `dojo.Animation` which will play all passed
  5758. // `dojo.Animation` instances in sequence, firing its own
  5759. // synthesized events simulating a single animation. (eg:
  5760. // onEnd of this animation means the end of the chain,
  5761. // not the individual animations within)
  5762. //
  5763. // example:
  5764. // Once `node` is faded out, fade in `otherNode`
  5765. // | dojo.fx.chain([
  5766. // | dojo.fadeIn({ node:node }),
  5767. // | dojo.fadeOut({ node:otherNode })
  5768. // | ]).play();
  5769. //
  5770. return new _chain(animations) // dojo.Animation
  5771. };
  5772. var _combine = function(animations){
  5773. this._animations = animations||[];
  5774. this._connects = [];
  5775. this._finished = 0;
  5776. this.duration = 0;
  5777. d.forEach(animations, function(a){
  5778. var duration = a.duration;
  5779. if(a.delay){ duration += a.delay; }
  5780. if(this.duration < duration){ this.duration = duration; }
  5781. this._connects.push(d.connect(a, "onEnd", this, "_onEnd"));
  5782. }, this);
  5783. this._pseudoAnimation = new d.Animation({curve: [0, 1], duration: this.duration});
  5784. var self = this;
  5785. d.forEach(["beforeBegin", "onBegin", "onPlay", "onAnimate", "onPause", "onStop", "onEnd"],
  5786. function(evt){
  5787. self._connects.push(d.connect(self._pseudoAnimation, evt,
  5788. function(){ self._fire(evt, arguments); }
  5789. ));
  5790. }
  5791. );
  5792. };
  5793. d.extend(_combine, {
  5794. _doAction: function(action, args){
  5795. d.forEach(this._animations, function(a){
  5796. a[action].apply(a, args);
  5797. });
  5798. return this;
  5799. },
  5800. _onEnd: function(){
  5801. if(++this._finished > this._animations.length){
  5802. this._fire("onEnd");
  5803. }
  5804. },
  5805. _call: function(action, args){
  5806. var t = this._pseudoAnimation;
  5807. t[action].apply(t, args);
  5808. },
  5809. play: function(/*int?*/ delay, /*Boolean?*/ gotoStart){
  5810. this._finished = 0;
  5811. this._doAction("play", arguments);
  5812. this._call("play", arguments);
  5813. return this;
  5814. },
  5815. pause: function(){
  5816. this._doAction("pause", arguments);
  5817. this._call("pause", arguments);
  5818. return this;
  5819. },
  5820. gotoPercent: function(/*Decimal*/percent, /*Boolean?*/ andPlay){
  5821. var ms = this.duration * percent;
  5822. d.forEach(this._animations, function(a){
  5823. a.gotoPercent(a.duration < ms ? 1 : (ms / a.duration), andPlay);
  5824. });
  5825. this._call("gotoPercent", arguments);
  5826. return this;
  5827. },
  5828. stop: function(/*boolean?*/ gotoEnd){
  5829. this._doAction("stop", arguments);
  5830. this._call("stop", arguments);
  5831. return this;
  5832. },
  5833. status: function(){
  5834. return this._pseudoAnimation.status();
  5835. },
  5836. destroy: function(){
  5837. d.forEach(this._connects, dojo.disconnect);
  5838. }
  5839. });
  5840. d.extend(_combine, _baseObj);
  5841. dojo.fx.combine = function(/*dojo.Animation[]*/ animations){
  5842. // summary:
  5843. // Combine a list of `dojo.Animation`s to run in parallel
  5844. //
  5845. // description:
  5846. // Combine an array of `dojo.Animation`s to run in parallel,
  5847. // providing a new `dojo.Animation` instance encompasing each
  5848. // animation, firing standard animation events.
  5849. //
  5850. // example:
  5851. // Fade out `node` while fading in `otherNode` simultaneously
  5852. // | dojo.fx.combine([
  5853. // | dojo.fadeIn({ node:node }),
  5854. // | dojo.fadeOut({ node:otherNode })
  5855. // | ]).play();
  5856. //
  5857. // example:
  5858. // When the longest animation ends, execute a function:
  5859. // | var anim = dojo.fx.combine([
  5860. // | dojo.fadeIn({ node: n, duration:700 }),
  5861. // | dojo.fadeOut({ node: otherNode, duration: 300 })
  5862. // | ]);
  5863. // | dojo.connect(anim, "onEnd", function(){
  5864. // | // overall animation is done.
  5865. // | });
  5866. // | anim.play(); // play the animation
  5867. //
  5868. return new _combine(animations); // dojo.Animation
  5869. };
  5870. dojo.fx.wipeIn = function(/*Object*/ args){
  5871. // summary:
  5872. // Expand a node to it's natural height.
  5873. //
  5874. // description:
  5875. // Returns an animation that will expand the
  5876. // node defined in 'args' object from it's current height to
  5877. // it's natural height (with no scrollbar).
  5878. // Node must have no margin/border/padding.
  5879. //
  5880. // args: Object
  5881. // A hash-map of standard `dojo.Animation` constructor properties
  5882. // (such as easing: node: duration: and so on)
  5883. //
  5884. // example:
  5885. // | dojo.fx.wipeIn({
  5886. // | node:"someId"
  5887. // | }).play()
  5888. var node = args.node = d.byId(args.node), s = node.style, o;
  5889. var anim = d.animateProperty(d.mixin({
  5890. properties: {
  5891. height: {
  5892. // wrapped in functions so we wait till the last second to query (in case value has changed)
  5893. start: function(){
  5894. // start at current [computed] height, but use 1px rather than 0
  5895. // because 0 causes IE to display the whole panel
  5896. o = s.overflow;
  5897. s.overflow = "hidden";
  5898. if(s.visibility == "hidden" || s.display == "none"){
  5899. s.height = "1px";
  5900. s.display = "";
  5901. s.visibility = "";
  5902. return 1;
  5903. }else{
  5904. var height = d.style(node, "height");
  5905. return Math.max(height, 1);
  5906. }
  5907. },
  5908. end: function(){
  5909. return node.scrollHeight;
  5910. }
  5911. }
  5912. }
  5913. }, args));
  5914. d.connect(anim, "onEnd", function(){
  5915. s.height = "auto";
  5916. s.overflow = o;
  5917. });
  5918. return anim; // dojo.Animation
  5919. };
  5920. dojo.fx.wipeOut = function(/*Object*/ args){
  5921. // summary:
  5922. // Shrink a node to nothing and hide it.
  5923. //
  5924. // description:
  5925. // Returns an animation that will shrink node defined in "args"
  5926. // from it's current height to 1px, and then hide it.
  5927. //
  5928. // args: Object
  5929. // A hash-map of standard `dojo.Animation` constructor properties
  5930. // (such as easing: node: duration: and so on)
  5931. //
  5932. // example:
  5933. // | dojo.fx.wipeOut({ node:"someId" }).play()
  5934. var node = args.node = d.byId(args.node), s = node.style, o;
  5935. var anim = d.animateProperty(d.mixin({
  5936. properties: {
  5937. height: {
  5938. end: 1 // 0 causes IE to display the whole panel
  5939. }
  5940. }
  5941. }, args));
  5942. d.connect(anim, "beforeBegin", function(){
  5943. o = s.overflow;
  5944. s.overflow = "hidden";
  5945. s.display = "";
  5946. });
  5947. d.connect(anim, "onEnd", function(){
  5948. s.overflow = o;
  5949. s.height = "auto";
  5950. s.display = "none";
  5951. });
  5952. return anim; // dojo.Animation
  5953. };
  5954. dojo.fx.slideTo = function(/*Object*/ args){
  5955. // summary:
  5956. // Slide a node to a new top/left position
  5957. //
  5958. // description:
  5959. // Returns an animation that will slide "node"
  5960. // defined in args Object from its current position to
  5961. // the position defined by (args.left, args.top).
  5962. //
  5963. // args: Object
  5964. // A hash-map of standard `dojo.Animation` constructor properties
  5965. // (such as easing: node: duration: and so on). Special args members
  5966. // are `top` and `left`, which indicate the new position to slide to.
  5967. //
  5968. // example:
  5969. // | dojo.fx.slideTo({ node: node, left:"40", top:"50", units:"px" }).play()
  5970. var node = args.node = d.byId(args.node),
  5971. top = null, left = null;
  5972. var init = (function(n){
  5973. return function(){
  5974. var cs = d.getComputedStyle(n);
  5975. var pos = cs.position;
  5976. top = (pos == 'absolute' ? n.offsetTop : parseInt(cs.top) || 0);
  5977. left = (pos == 'absolute' ? n.offsetLeft : parseInt(cs.left) || 0);
  5978. if(pos != 'absolute' && pos != 'relative'){
  5979. var ret = d.position(n, true);
  5980. top = ret.y;
  5981. left = ret.x;
  5982. n.style.position="absolute";
  5983. n.style.top=top+"px";
  5984. n.style.left=left+"px";
  5985. }
  5986. };
  5987. })(node);
  5988. init();
  5989. var anim = d.animateProperty(d.mixin({
  5990. properties: {
  5991. top: args.top || 0,
  5992. left: args.left || 0
  5993. }
  5994. }, args));
  5995. d.connect(anim, "beforeBegin", anim, init);
  5996. return anim; // dojo.Animation
  5997. };
  5998. })();
  5999. }
  6000. if(!dojo._hasResource["dojox.mobile.app.ListSelector"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  6001. dojo._hasResource["dojox.mobile.app.ListSelector"] = true;
  6002. dojo.provide("dojox.mobile.app.ListSelector");
  6003. dojo.experimental("dojox.mobile.app.ListSelector");
  6004. dojo.declare("dojox.mobile.app.ListSelector", dojox.mobile.app._Widget, {
  6005. // data: Array
  6006. // The array of items to display. Each element in the array
  6007. // should have both a label and value attribute, e.g.
  6008. // [{label: "Open", value: 1} , {label: "Delete", value: 2}]
  6009. data: null,
  6010. // controller: Object
  6011. // The current SceneController widget.
  6012. controller: null,
  6013. // onChoose: Function
  6014. // The callback function for when an item is selected
  6015. onChoose: null,
  6016. destroyOnHide: false,
  6017. _setDataAttr: function(data){
  6018. this.data = data;
  6019. if(this.data){
  6020. this.render();
  6021. }
  6022. },
  6023. postCreate: function(){
  6024. dojo.addClass(this.domNode, "listSelector");
  6025. var _this = this;
  6026. this.connect(this.domNode, "onclick", function(event){
  6027. if(!dojo.hasClass(event.target, "listSelectorRow")){
  6028. return;
  6029. }
  6030. if(_this.onChoose){
  6031. _this.onChoose(_this.data[event.target._idx].value);
  6032. }
  6033. _this.hide();
  6034. });
  6035. this.connect(this.domNode, "onmousedown", function(event){
  6036. if(!dojo.hasClass(event.target, "listSelectorRow")){
  6037. return;
  6038. }
  6039. dojo.addClass(event.target, "listSelectorRow-selected");
  6040. });
  6041. this.connect(this.domNode, "onmouseup", function(event){
  6042. if(!dojo.hasClass(event.target, "listSelectorRow")){
  6043. return;
  6044. }
  6045. dojo.removeClass(event.target, "listSelectorRow-selected");
  6046. });
  6047. this.connect(this.domNode, "onmouseout", function(event){
  6048. if(!dojo.hasClass(event.target, "listSelectorRow")){
  6049. return;
  6050. }
  6051. dojo.removeClass(event.target, "listSelectorRow-selected");
  6052. });
  6053. var viewportSize = this.controller.getWindowSize();
  6054. this.mask = dojo.create("div", {"class": "dialogUnderlayWrapper",
  6055. innerHTML: "<div class=\"dialogUnderlay\"></div>"
  6056. }, this.controller.assistant.domNode);
  6057. this.connect(this.mask, "onclick", function(){
  6058. _this.onChoose && _this.onChoose();
  6059. _this.hide();
  6060. });
  6061. },
  6062. show: function(fromNode){
  6063. // Using dojo.fx here. Must figure out how to do this with CSS animations!!
  6064. var startPos;
  6065. var windowSize = this.controller.getWindowSize();
  6066. var fromNodePos;
  6067. if(fromNode){
  6068. fromNodePos = dojo._abs(fromNode);
  6069. startPos = fromNodePos;
  6070. }else{
  6071. startPos.x = windowSize.w / 2;
  6072. startPos.y = 200;
  6073. }
  6074. console.log("startPos = ", startPos);
  6075. dojo.style(this.domNode, {
  6076. opacity: 0,
  6077. display: "",
  6078. width: Math.floor(windowSize.w * 0.8) + "px"
  6079. });
  6080. var maxWidth = 0;
  6081. dojo.query(">", this.domNode).forEach(function(node){
  6082. dojo.style(node, {
  6083. "float": "left"
  6084. });
  6085. maxWidth = Math.max(maxWidth, dojo.marginBox(node).w);
  6086. dojo.style(node, {
  6087. "float": "none"
  6088. });
  6089. });
  6090. maxWidth = Math.min(maxWidth, Math.round(windowSize.w * 0.8))
  6091. + dojo.style(this.domNode, "paddingLeft")
  6092. + dojo.style(this.domNode, "paddingRight")
  6093. + 1;
  6094. dojo.style(this.domNode, "width", maxWidth + "px");
  6095. var targetHeight = dojo.marginBox(this.domNode).h;
  6096. var _this = this;
  6097. var targetY = fromNodePos ?
  6098. Math.max(30, fromNodePos.y - targetHeight - 10) :
  6099. this.getScroll().y + 30;
  6100. console.log("fromNodePos = ", fromNodePos, " targetHeight = ", targetHeight,
  6101. " targetY = " + targetY, " startPos ", startPos);
  6102. var anim1 = dojo.animateProperty({
  6103. node: this.domNode,
  6104. duration: 400,
  6105. properties: {
  6106. width: {start: 1, end: maxWidth},
  6107. height: {start: 1, end: targetHeight},
  6108. top: {start: startPos.y, end: targetY},
  6109. left: {start: startPos.x, end: (windowSize.w/2 - maxWidth/2)},
  6110. opacity: {start: 0, end: 1},
  6111. fontSize: {start: 1}
  6112. },
  6113. onEnd: function(){
  6114. dojo.style(_this.domNode, "width", "inherit");
  6115. }
  6116. });
  6117. var anim2 = dojo.fadeIn({
  6118. node: this.mask,
  6119. duration: 400
  6120. });
  6121. dojo.fx.combine([anim1, anim2]).play();
  6122. },
  6123. hide: function(){
  6124. // Using dojo.fx here. Must figure out how to do this with CSS animations!!
  6125. var _this = this;
  6126. var anim1 = dojo.animateProperty({
  6127. node: this.domNode,
  6128. duration: 500,
  6129. properties: {
  6130. width: {end: 1},
  6131. height: {end: 1},
  6132. opacity: {end: 0},
  6133. fontSize: {end: 1}
  6134. },
  6135. onEnd: function(){
  6136. if(_this.get("destroyOnHide")){
  6137. _this.destroy();
  6138. }
  6139. }
  6140. });
  6141. var anim2 = dojo.fadeOut({
  6142. node: this.mask,
  6143. duration: 400
  6144. });
  6145. dojo.fx.combine([anim1, anim2]).play();
  6146. },
  6147. render: function(){
  6148. // summary:
  6149. // Renders
  6150. dojo.empty(this.domNode);
  6151. dojo.style(this.domNode, "opacity", 0);
  6152. var row;
  6153. for(var i = 0; i < this.data.length; i++){
  6154. // Create each row and add any custom classes. Also set the _idx property.
  6155. row = dojo.create("div", {
  6156. "class": "listSelectorRow " + (this.data[i].className || ""),
  6157. innerHTML: this.data[i].label
  6158. }, this.domNode);
  6159. row._idx = i;
  6160. if(i == 0){
  6161. dojo.addClass(row, "first");
  6162. }
  6163. if(i == this.data.length - 1){
  6164. dojo.addClass(row, "last");
  6165. }
  6166. }
  6167. },
  6168. destroy: function(){
  6169. this.inherited(arguments);
  6170. dojo.destroy(this.mask);
  6171. }
  6172. });
  6173. }
  6174. if(!dojo._hasResource["dojox.mobile.app._FormWidget"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  6175. dojo._hasResource["dojox.mobile.app._FormWidget"] = true;
  6176. dojo.provide("dojox.mobile.app._FormWidget");
  6177. dojo.experimental("dojox.mobile.app._FormWidget");
  6178. dojo.declare("dojox.mobile.app._FormWidget", dijit._WidgetBase, {
  6179. // summary:
  6180. // Base class for widgets corresponding to native HTML elements such as <checkbox> or <button>,
  6181. // which can be children of a <form> node or a `dojox.mobile.app.Form` widget.
  6182. //
  6183. // description:
  6184. // Represents a single HTML element.
  6185. // All these widgets should have these attributes just like native HTML input elements.
  6186. // You can set them during widget construction or afterwards, via `dijit._WidgetBase.attr`.
  6187. //
  6188. // They also share some common methods.
  6189. // name: String
  6190. // Name used when submitting form; same as "name" attribute or plain HTML elements
  6191. name: "",
  6192. // alt: String
  6193. // Corresponds to the native HTML <input> element's attribute.
  6194. alt: "",
  6195. // value: String
  6196. // Corresponds to the native HTML <input> element's attribute.
  6197. value: "",
  6198. // type: String
  6199. // Corresponds to the native HTML <input> element's attribute.
  6200. type: "text",
  6201. // disabled: Boolean
  6202. // Should this widget respond to user input?
  6203. // In markup, this is specified as "disabled='disabled'", or just "disabled".
  6204. disabled: false,
  6205. // intermediateChanges: Boolean
  6206. // Fires onChange for each value change or only on demand
  6207. intermediateChanges: false,
  6208. // scrollOnFocus: Boolean
  6209. // On focus, should this widget scroll into view?
  6210. scrollOnFocus: false,
  6211. // These mixins assume that the focus node is an INPUT, as many but not all _FormWidgets are.
  6212. attributeMap: dojo.delegate(dijit._WidgetBase.prototype.attributeMap, {
  6213. value: "focusNode",
  6214. id: "focusNode",
  6215. alt: "focusNode",
  6216. title: "focusNode"
  6217. }),
  6218. postMixInProperties: function(){
  6219. // Setup name=foo string to be referenced from the template (but only if a name has been specified)
  6220. // Unfortunately we can't use attributeMap to set the name due to IE limitations, see #8660
  6221. // Regarding escaping, see heading "Attribute values" in
  6222. // http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.3.2
  6223. this.nameAttrSetting = this.name ? ('name="' + this.name.replace(/'/g, "&quot;") + '"') : '';
  6224. this.inherited(arguments);
  6225. },
  6226. postCreate: function(){
  6227. this.inherited(arguments);
  6228. this.connect(this.domNode, "onmousedown", "_onMouseDown");
  6229. },
  6230. _setDisabledAttr: function(/*Boolean*/ value){
  6231. this.disabled = value;
  6232. dojo.attr(this.focusNode, 'disabled', value);
  6233. if(this.valueNode){
  6234. dojo.attr(this.valueNode, 'disabled', value);
  6235. }
  6236. },
  6237. _onFocus: function(e){
  6238. if(this.scrollOnFocus){
  6239. dojo.window.scrollIntoView(this.domNode);
  6240. }
  6241. this.inherited(arguments);
  6242. },
  6243. isFocusable: function(){
  6244. // summary:
  6245. // Tells if this widget is focusable or not. Used internally by dijit.
  6246. // tags:
  6247. // protected
  6248. return !this.disabled && !this.readOnly
  6249. && this.focusNode && (dojo.style(this.domNode, "display") != "none");
  6250. },
  6251. focus: function(){
  6252. // summary:
  6253. // Put focus on this widget
  6254. this.focusNode.focus();
  6255. },
  6256. compare: function(/*anything*/val1, /*anything*/val2){
  6257. // summary:
  6258. // Compare 2 values (as returned by attr('value') for this widget).
  6259. // tags:
  6260. // protected
  6261. if(typeof val1 == "number" && typeof val2 == "number"){
  6262. return (isNaN(val1) && isNaN(val2)) ? 0 : val1 - val2;
  6263. }else if(val1 > val2){
  6264. return 1;
  6265. }else if(val1 < val2){
  6266. return -1;
  6267. }else{
  6268. return 0;
  6269. }
  6270. },
  6271. onChange: function(newValue){
  6272. // summary:
  6273. // Callback when this widget's value is changed.
  6274. // tags:
  6275. // callback
  6276. },
  6277. // _onChangeActive: [private] Boolean
  6278. // Indicates that changes to the value should call onChange() callback.
  6279. // This is false during widget initialization, to avoid calling onChange()
  6280. // when the initial value is set.
  6281. _onChangeActive: false,
  6282. _handleOnChange: function(/*anything*/ newValue, /* Boolean? */ priorityChange){
  6283. // summary:
  6284. // Called when the value of the widget is set. Calls onChange() if appropriate
  6285. // newValue:
  6286. // the new value
  6287. // priorityChange:
  6288. // For a slider, for example, dragging the slider is priorityChange==false,
  6289. // but on mouse up, it's priorityChange==true. If intermediateChanges==true,
  6290. // onChange is only called form priorityChange=true events.
  6291. // tags:
  6292. // private
  6293. this._lastValue = newValue;
  6294. if(this._lastValueReported == undefined && (priorityChange === null || !this._onChangeActive)){
  6295. // this block executes not for a change, but during initialization,
  6296. // and is used to store away the original value (or for ToggleButton, the original checked state)
  6297. this._resetValue = this._lastValueReported = newValue;
  6298. }
  6299. if((this.intermediateChanges || priorityChange || priorityChange === undefined) &&
  6300. ((typeof newValue != typeof this._lastValueReported) ||
  6301. this.compare(newValue, this._lastValueReported) != 0)){
  6302. this._lastValueReported = newValue;
  6303. if(this._onChangeActive){
  6304. if(this._onChangeHandle){
  6305. clearTimeout(this._onChangeHandle);
  6306. }
  6307. // setTimout allows hidden value processing to run and
  6308. // also the onChange handler can safely adjust focus, etc
  6309. this._onChangeHandle = setTimeout(dojo.hitch(this,
  6310. function(){
  6311. this._onChangeHandle = null;
  6312. this.onChange(newValue);
  6313. }), 0); // try to collapse multiple onChange's fired faster than can be processed
  6314. }
  6315. }
  6316. },
  6317. create: function(){
  6318. // Overrides _Widget.create()
  6319. this.inherited(arguments);
  6320. this._onChangeActive = true;
  6321. },
  6322. destroy: function(){
  6323. if(this._onChangeHandle){ // destroy called before last onChange has fired
  6324. clearTimeout(this._onChangeHandle);
  6325. this.onChange(this._lastValueReported);
  6326. }
  6327. this.inherited(arguments);
  6328. },
  6329. _onMouseDown: function(e){
  6330. // If user clicks on the button, even if the mouse is released outside of it,
  6331. // this button should get focus (to mimics native browser buttons).
  6332. // This is also needed on chrome because otherwise buttons won't get focus at all,
  6333. // which leads to bizarre focus restore on Dialog close etc.
  6334. if(this.isFocusable()){
  6335. // Set a global event to handle mouseup, so it fires properly
  6336. // even if the cursor leaves this.domNode before the mouse up event.
  6337. var mouseUpConnector = this.connect(dojo.body(), "onmouseup", function(){
  6338. if(this.isFocusable()){
  6339. this.focus();
  6340. }
  6341. this.disconnect(mouseUpConnector);
  6342. });
  6343. }
  6344. },
  6345. selectInputText: function(/*DomNode*/element, /*Number?*/ start, /*Number?*/ stop){
  6346. // summary:
  6347. // Select text in the input element argument, from start (default 0), to stop (default end).
  6348. // TODO: use functions in _editor/selection.js?
  6349. var _window = dojo.global;
  6350. var _document = dojo.doc;
  6351. element = dojo.byId(element);
  6352. if(isNaN(start)){ start = 0; }
  6353. if(isNaN(stop)){ stop = element.value ? element.value.length : 0; }
  6354. dijit.focus(element);
  6355. if(_window["getSelection"] && element.setSelectionRange){
  6356. element.setSelectionRange(start, stop);
  6357. }
  6358. }
  6359. });
  6360. dojo.declare("dojox.mobile.app._FormValueWidget", dojox.mobile.app._FormWidget,
  6361. {
  6362. // summary:
  6363. // Base class for widgets corresponding to native HTML elements such as <input> or <select> that have user changeable values.
  6364. // description:
  6365. // Each _FormValueWidget represents a single input value, and has a (possibly hidden) <input> element,
  6366. // to which it serializes it's input value, so that form submission (either normal submission or via FormBind?)
  6367. // works as expected.
  6368. // Don't attempt to mixin the 'type', 'name' attributes here programatically -- they must be declared
  6369. // directly in the template as read by the parser in order to function. IE is known to specifically
  6370. // require the 'name' attribute at element creation time. See #8484, #8660.
  6371. // TODO: unclear what that {value: ""} is for; FormWidget.attributeMap copies value to focusNode,
  6372. // so maybe {value: ""} is so the value *doesn't* get copied to focusNode?
  6373. // Seems like we really want value removed from attributeMap altogether
  6374. // (although there's no easy way to do that now)
  6375. // readOnly: Boolean
  6376. // Should this widget respond to user input?
  6377. // In markup, this is specified as "readOnly".
  6378. // Similar to disabled except readOnly form values are submitted.
  6379. readOnly: false,
  6380. attributeMap: dojo.delegate(dojox.mobile.app._FormWidget.prototype.attributeMap, {
  6381. value: "",
  6382. readOnly: "focusNode"
  6383. }),
  6384. _setReadOnlyAttr: function(/*Boolean*/ value){
  6385. this.readOnly = value;
  6386. dojo.attr(this.focusNode, 'readOnly', value);
  6387. },
  6388. postCreate: function(){
  6389. this.inherited(arguments);
  6390. // Update our reset value if it hasn't yet been set (because this.set()
  6391. // is only called when there *is* a value)
  6392. if(this._resetValue === undefined){
  6393. this._resetValue = this.value;
  6394. }
  6395. },
  6396. _setValueAttr: function(/*anything*/ newValue, /*Boolean, optional*/ priorityChange){
  6397. // summary:
  6398. // Hook so attr('value', value) works.
  6399. // description:
  6400. // Sets the value of the widget.
  6401. // If the value has changed, then fire onChange event, unless priorityChange
  6402. // is specified as null (or false?)
  6403. this.value = newValue;
  6404. this._handleOnChange(newValue, priorityChange);
  6405. },
  6406. _getValueAttr: function(){
  6407. // summary:
  6408. // Hook so attr('value') works.
  6409. return this._lastValue;
  6410. },
  6411. undo: function(){
  6412. // summary:
  6413. // Restore the value to the last value passed to onChange
  6414. this._setValueAttr(this._lastValueReported, false);
  6415. },
  6416. reset: function(){
  6417. // summary:
  6418. // Reset the widget's value to what it was at initialization time
  6419. this._hasBeenBlurred = false;
  6420. this._setValueAttr(this._resetValue, true);
  6421. }
  6422. });
  6423. }
  6424. if(!dojo._hasResource["dojox.mobile.app.TextBox"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  6425. dojo._hasResource["dojox.mobile.app.TextBox"] = true;
  6426. dojo.provide("dojox.mobile.app.TextBox");
  6427. dojo.experimental("dojox.mobile.app.TextBox");
  6428. dojo.declare(
  6429. "dojox.mobile.app.TextBox",
  6430. dojox.mobile.app._FormValueWidget, {
  6431. // summary:
  6432. // A base class for textbox form inputs
  6433. // trim: Boolean
  6434. // Removes leading and trailing whitespace if true. Default is false.
  6435. trim: false,
  6436. // uppercase: Boolean
  6437. // Converts all characters to uppercase if true. Default is false.
  6438. uppercase: false,
  6439. // lowercase: Boolean
  6440. // Converts all characters to lowercase if true. Default is false.
  6441. lowercase: false,
  6442. // propercase: Boolean
  6443. // Converts the first character of each word to uppercase if true.
  6444. propercase: false,
  6445. // maxLength: String
  6446. // HTML INPUT tag maxLength declaration.
  6447. maxLength: "",
  6448. // selectOnClick: [const] Boolean
  6449. // If true, all text will be selected when focused with mouse
  6450. selectOnClick: false,
  6451. // placeHolder: String
  6452. // Defines a hint to help users fill out the input field (as defined in HTML 5).
  6453. // This should only contain plain text (no html markup).
  6454. placeHolder: "",
  6455. baseClass: "mblTextBox",
  6456. attributeMap: dojo.delegate(dojox.mobile.app._FormValueWidget.prototype.attributeMap, {
  6457. maxLength: "focusNode"
  6458. }),
  6459. buildRendering: function(){
  6460. var node = this.srcNodeRef;
  6461. // If an input is used as the source node, wrap it in a div
  6462. if(!node || node.tagName != "INPUT"){
  6463. node = dojo.create("input", {});
  6464. }
  6465. dojo.attr(node, {
  6466. type: "text",
  6467. value: dojo.attr(node, "value") || "",
  6468. placeholder: this.placeHolder || null
  6469. });
  6470. this.domNode = this.textbox = this.focusNode = node;
  6471. },
  6472. _setPlaceHolderAttr: function(v){
  6473. this.placeHolder = v;
  6474. if(this.textbox){
  6475. dojo.attr(this.textbox, "placeholder", v);
  6476. }
  6477. },
  6478. _getValueAttr: function(){
  6479. // summary:
  6480. // Hook so attr('value') works as we like.
  6481. // description:
  6482. // For `dijit.form.TextBox` this basically returns the value of the <input>.
  6483. //
  6484. // For `dijit.form.MappedTextBox` subclasses, which have both
  6485. // a "displayed value" and a separate "submit value",
  6486. // This treats the "displayed value" as the master value, computing the
  6487. // submit value from it via this.parse().
  6488. return this.parse(this.get('displayedValue'), this.constraints);
  6489. },
  6490. _setValueAttr: function(value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
  6491. // summary:
  6492. // Hook so attr('value', ...) works.
  6493. //
  6494. // description:
  6495. // Sets the value of the widget to "value" which can be of
  6496. // any type as determined by the widget.
  6497. //
  6498. // value:
  6499. // The visual element value is also set to a corresponding,
  6500. // but not necessarily the same, value.
  6501. //
  6502. // formattedValue:
  6503. // If specified, used to set the visual element value,
  6504. // otherwise a computed visual value is used.
  6505. //
  6506. // priorityChange:
  6507. // If true, an onChange event is fired immediately instead of
  6508. // waiting for the next blur event.
  6509. var filteredValue;
  6510. if(value !== undefined){
  6511. // TODO: this is calling filter() on both the display value and the actual value.
  6512. // I added a comment to the filter() definition about this, but it should be changed.
  6513. filteredValue = this.filter(value);
  6514. if(typeof formattedValue != "string"){
  6515. if(filteredValue !== null
  6516. && ((typeof filteredValue != "number") || !isNaN(filteredValue))){
  6517. formattedValue = this.filter(this.format(filteredValue, this.constraints));
  6518. }else{ formattedValue = ''; }
  6519. }
  6520. }
  6521. if(formattedValue != null && formattedValue != undefined
  6522. && ((typeof formattedValue) != "number" || !isNaN(formattedValue))
  6523. && this.textbox.value != formattedValue){
  6524. this.textbox.value = formattedValue;
  6525. }
  6526. this.inherited(arguments, [filteredValue, priorityChange]);
  6527. },
  6528. // displayedValue: String
  6529. // For subclasses like ComboBox where the displayed value
  6530. // (ex: Kentucky) and the serialized value (ex: KY) are different,
  6531. // this represents the displayed value.
  6532. //
  6533. // Setting 'displayedValue' through attr('displayedValue', ...)
  6534. // updates 'value', and vice-versa. Otherwise 'value' is updated
  6535. // from 'displayedValue' periodically, like onBlur etc.
  6536. //
  6537. // TODO: move declaration to MappedTextBox?
  6538. // Problem is that ComboBox references displayedValue,
  6539. // for benefit of FilteringSelect.
  6540. displayedValue: "",
  6541. _getDisplayedValueAttr: function(){
  6542. // summary:
  6543. // Hook so attr('displayedValue') works.
  6544. // description:
  6545. // Returns the displayed value (what the user sees on the screen),
  6546. // after filtering (ie, trimming spaces etc.).
  6547. //
  6548. // For some subclasses of TextBox (like ComboBox), the displayed value
  6549. // is different from the serialized value that's actually
  6550. // sent to the server (see dijit.form.ValidationTextBox.serialize)
  6551. return this.filter(this.textbox.value);
  6552. },
  6553. _setDisplayedValueAttr: function(/*String*/value){
  6554. // summary:
  6555. // Hook so attr('displayedValue', ...) works.
  6556. // description:
  6557. // Sets the value of the visual element to the string "value".
  6558. // The widget value is also set to a corresponding,
  6559. // but not necessarily the same, value.
  6560. if(value === null || value === undefined){ value = '' }
  6561. else if(typeof value != "string"){ value = String(value) }
  6562. this.textbox.value = value;
  6563. this._setValueAttr(this.get('value'), undefined, value);
  6564. },
  6565. format: function(/* String */ value, /* Object */ constraints){
  6566. // summary:
  6567. // Replacable function to convert a value to a properly formatted string.
  6568. // tags:
  6569. // protected extension
  6570. return ((value == null || value == undefined) ? "" : (value.toString ? value.toString() : value));
  6571. },
  6572. parse: function(/* String */ value, /* Object */ constraints){
  6573. // summary:
  6574. // Replacable function to convert a formatted string to a value
  6575. // tags:
  6576. // protected extension
  6577. return value; // String
  6578. },
  6579. _refreshState: function(){
  6580. // summary:
  6581. // After the user types some characters, etc., this method is
  6582. // called to check the field for validity etc. The base method
  6583. // in `dijit.form.TextBox` does nothing, but subclasses override.
  6584. // tags:
  6585. // protected
  6586. },
  6587. _onInput: function(e){
  6588. if(e && e.type && /key/i.test(e.type) && e.keyCode){
  6589. switch(e.keyCode){
  6590. case dojo.keys.SHIFT:
  6591. case dojo.keys.ALT:
  6592. case dojo.keys.CTRL:
  6593. case dojo.keys.TAB:
  6594. return;
  6595. }
  6596. }
  6597. if(this.intermediateChanges){
  6598. var _this = this;
  6599. // the setTimeout allows the key to post to the widget input box
  6600. setTimeout(function(){ _this._handleOnChange(_this.get('value'), false); }, 0);
  6601. }
  6602. this._refreshState();
  6603. },
  6604. postCreate: function(){
  6605. // setting the value here is needed since value="" in the template causes "undefined"
  6606. // and setting in the DOM (instead of the JS object) helps with form reset actions
  6607. this.textbox.setAttribute("value", this.textbox.value); // DOM and JS values shuld be the same
  6608. this.inherited(arguments);
  6609. if(dojo.isMoz || dojo.isOpera){
  6610. this.connect(this.textbox, "oninput", this._onInput);
  6611. }else{
  6612. this.connect(this.textbox, "onkeydown", this._onInput);
  6613. this.connect(this.textbox, "onkeyup", this._onInput);
  6614. this.connect(this.textbox, "onpaste", this._onInput);
  6615. this.connect(this.textbox, "oncut", this._onInput);
  6616. }
  6617. },
  6618. _blankValue: '', // if the textbox is blank, what value should be reported
  6619. filter: function(val){
  6620. // summary:
  6621. // Auto-corrections (such as trimming) that are applied to textbox
  6622. // value on blur or form submit.
  6623. // description:
  6624. // For MappedTextBox subclasses, this is called twice
  6625. // - once with the display value
  6626. // - once the value as set/returned by attr('value', ...)
  6627. // and attr('value'), ex: a Number for NumberTextBox.
  6628. //
  6629. // In the latter case it does corrections like converting null to NaN. In
  6630. // the former case the NumberTextBox.filter() method calls this.inherited()
  6631. // to execute standard trimming code in TextBox.filter().
  6632. //
  6633. // TODO: break this into two methods in 2.0
  6634. //
  6635. // tags:
  6636. // protected extension
  6637. if(val === null){ return this._blankValue; }
  6638. if(typeof val != "string"){ return val; }
  6639. if(this.trim){
  6640. val = dojo.trim(val);
  6641. }
  6642. if(this.uppercase){
  6643. val = val.toUpperCase();
  6644. }
  6645. if(this.lowercase){
  6646. val = val.toLowerCase();
  6647. }
  6648. if(this.propercase){
  6649. val = val.replace(/[^\s]+/g, function(word){
  6650. return word.substring(0,1).toUpperCase() + word.substring(1);
  6651. });
  6652. }
  6653. return val;
  6654. },
  6655. _setBlurValue: function(){
  6656. this._setValueAttr(this.get('value'), true);
  6657. },
  6658. _onBlur: function(e){
  6659. if(this.disabled){ return; }
  6660. this._setBlurValue();
  6661. this.inherited(arguments);
  6662. if(this._selectOnClickHandle){
  6663. this.disconnect(this._selectOnClickHandle);
  6664. }
  6665. if(this.selectOnClick && dojo.isMoz){
  6666. this.textbox.selectionStart = this.textbox.selectionEnd = undefined; // clear selection so that the next mouse click doesn't reselect
  6667. }
  6668. },
  6669. _onFocus: function(/*String*/ by){
  6670. if(this.disabled || this.readOnly){ return; }
  6671. // Select all text on focus via click if nothing already selected.
  6672. // Since mouse-up will clear the selection need to defer selection until after mouse-up.
  6673. // Don't do anything on focus by tabbing into the widget since there's no associated mouse-up event.
  6674. if(this.selectOnClick && by == "mouse"){
  6675. this._selectOnClickHandle = this.connect(this.domNode, "onmouseup", function(){
  6676. // Only select all text on first click; otherwise users would have no way to clear
  6677. // the selection.
  6678. this.disconnect(this._selectOnClickHandle);
  6679. // Check if the user selected some text manually (mouse-down, mouse-move, mouse-up)
  6680. // and if not, then select all the text
  6681. var textIsNotSelected;
  6682. textIsNotSelected = this.textbox.selectionStart == this.textbox.selectionEnd;
  6683. if(textIsNotSelected){
  6684. this.selectInputText(this.textbox);
  6685. }
  6686. });
  6687. }
  6688. this._refreshState();
  6689. this.inherited(arguments);
  6690. },
  6691. reset: function(){
  6692. // Overrides dijit._FormWidget.reset().
  6693. // Additionally resets the displayed textbox value to ''
  6694. this.textbox.value = '';
  6695. this.inherited(arguments);
  6696. }
  6697. }
  6698. );
  6699. }
  6700. if(!dojo._hasResource["dojo.fx.easing"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  6701. dojo._hasResource["dojo.fx.easing"] = true;
  6702. dojo.provide("dojo.fx.easing");
  6703. dojo.getObject("fx.easing", true, dojo);
  6704. dojo.fx.easing = {
  6705. // summary:
  6706. // Collection of easing functions to use beyond the default
  6707. // `dojo._defaultEasing` function.
  6708. //
  6709. // description:
  6710. //
  6711. // Easing functions are used to manipulate the iteration through
  6712. // an `dojo.Animation`s _Line. _Line being the properties of an Animation,
  6713. // and the easing function progresses through that Line determing
  6714. // how quickly (or slowly) it should go. Or more accurately: modify
  6715. // the value of the _Line based on the percentage of animation completed.
  6716. //
  6717. // All functions follow a simple naming convention of "ease type" + "when".
  6718. // If the name of the function ends in Out, the easing described appears
  6719. // towards the end of the animation. "In" means during the beginning,
  6720. // and InOut means both ranges of the Animation will applied, both
  6721. // beginning and end.
  6722. //
  6723. // One does not call the easing function directly, it must be passed to
  6724. // the `easing` property of an animation.
  6725. //
  6726. // example:
  6727. // |
  6728. // | var anim = dojo.fadeOut({
  6729. // | node: 'node',
  6730. // | duration: 2000,
  6731. // | // note there is no ()
  6732. // | easing: dojo.fx.easing.quadIn
  6733. // | }).play();
  6734. //
  6735. linear: function(/* Decimal? */n){
  6736. // summary: A linear easing function
  6737. return n;
  6738. },
  6739. quadIn: function(/* Decimal? */n){
  6740. return Math.pow(n, 2);
  6741. },
  6742. quadOut: function(/* Decimal? */n){
  6743. return n * (n - 2) * -1;
  6744. },
  6745. quadInOut: function(/* Decimal? */n){
  6746. n = n * 2;
  6747. if(n < 1){ return Math.pow(n, 2) / 2; }
  6748. return -1 * ((--n) * (n - 2) - 1) / 2;
  6749. },
  6750. cubicIn: function(/* Decimal? */n){
  6751. return Math.pow(n, 3);
  6752. },
  6753. cubicOut: function(/* Decimal? */n){
  6754. return Math.pow(n - 1, 3) + 1;
  6755. },
  6756. cubicInOut: function(/* Decimal? */n){
  6757. n = n * 2;
  6758. if(n < 1){ return Math.pow(n, 3) / 2; }
  6759. n -= 2;
  6760. return (Math.pow(n, 3) + 2) / 2;
  6761. },
  6762. quartIn: function(/* Decimal? */n){
  6763. return Math.pow(n, 4);
  6764. },
  6765. quartOut: function(/* Decimal? */n){
  6766. return -1 * (Math.pow(n - 1, 4) - 1);
  6767. },
  6768. quartInOut: function(/* Decimal? */n){
  6769. n = n * 2;
  6770. if(n < 1){ return Math.pow(n, 4) / 2; }
  6771. n -= 2;
  6772. return -1 / 2 * (Math.pow(n, 4) - 2);
  6773. },
  6774. quintIn: function(/* Decimal? */n){
  6775. return Math.pow(n, 5);
  6776. },
  6777. quintOut: function(/* Decimal? */n){
  6778. return Math.pow(n - 1, 5) + 1;
  6779. },
  6780. quintInOut: function(/* Decimal? */n){
  6781. n = n * 2;
  6782. if(n < 1){ return Math.pow(n, 5) / 2; };
  6783. n -= 2;
  6784. return (Math.pow(n, 5) + 2) / 2;
  6785. },
  6786. sineIn: function(/* Decimal? */n){
  6787. return -1 * Math.cos(n * (Math.PI / 2)) + 1;
  6788. },
  6789. sineOut: function(/* Decimal? */n){
  6790. return Math.sin(n * (Math.PI / 2));
  6791. },
  6792. sineInOut: function(/* Decimal? */n){
  6793. return -1 * (Math.cos(Math.PI * n) - 1) / 2;
  6794. },
  6795. expoIn: function(/* Decimal? */n){
  6796. return (n == 0) ? 0 : Math.pow(2, 10 * (n - 1));
  6797. },
  6798. expoOut: function(/* Decimal? */n){
  6799. return (n == 1) ? 1 : (-1 * Math.pow(2, -10 * n) + 1);
  6800. },
  6801. expoInOut: function(/* Decimal? */n){
  6802. if(n == 0){ return 0; }
  6803. if(n == 1){ return 1; }
  6804. n = n * 2;
  6805. if(n < 1){ return Math.pow(2, 10 * (n - 1)) / 2; }
  6806. --n;
  6807. return (-1 * Math.pow(2, -10 * n) + 2) / 2;
  6808. },
  6809. circIn: function(/* Decimal? */n){
  6810. return -1 * (Math.sqrt(1 - Math.pow(n, 2)) - 1);
  6811. },
  6812. circOut: function(/* Decimal? */n){
  6813. n = n - 1;
  6814. return Math.sqrt(1 - Math.pow(n, 2));
  6815. },
  6816. circInOut: function(/* Decimal? */n){
  6817. n = n * 2;
  6818. if(n < 1){ return -1 / 2 * (Math.sqrt(1 - Math.pow(n, 2)) - 1); }
  6819. n -= 2;
  6820. return 1 / 2 * (Math.sqrt(1 - Math.pow(n, 2)) + 1);
  6821. },
  6822. backIn: function(/* Decimal? */n){
  6823. // summary:
  6824. // An easing function that starts away from the target,
  6825. // and quickly accelerates towards the end value.
  6826. //
  6827. // Use caution when the easing will cause values to become
  6828. // negative as some properties cannot be set to negative values.
  6829. var s = 1.70158;
  6830. return Math.pow(n, 2) * ((s + 1) * n - s);
  6831. },
  6832. backOut: function(/* Decimal? */n){
  6833. // summary:
  6834. // An easing function that pops past the range briefly, and slowly comes back.
  6835. //
  6836. // description:
  6837. // An easing function that pops past the range briefly, and slowly comes back.
  6838. //
  6839. // Use caution when the easing will cause values to become negative as some
  6840. // properties cannot be set to negative values.
  6841. n = n - 1;
  6842. var s = 1.70158;
  6843. return Math.pow(n, 2) * ((s + 1) * n + s) + 1;
  6844. },
  6845. backInOut: function(/* Decimal? */n){
  6846. // summary:
  6847. // An easing function combining the effects of `backIn` and `backOut`
  6848. //
  6849. // description:
  6850. // An easing function combining the effects of `backIn` and `backOut`.
  6851. // Use caution when the easing will cause values to become negative
  6852. // as some properties cannot be set to negative values.
  6853. var s = 1.70158 * 1.525;
  6854. n = n * 2;
  6855. if(n < 1){ return (Math.pow(n, 2) * ((s + 1) * n - s)) / 2; }
  6856. n-=2;
  6857. return (Math.pow(n, 2) * ((s + 1) * n + s) + 2) / 2;
  6858. },
  6859. elasticIn: function(/* Decimal? */n){
  6860. // summary:
  6861. // An easing function the elastically snaps from the start value
  6862. //
  6863. // description:
  6864. // An easing function the elastically snaps from the start value
  6865. //
  6866. // Use caution when the elasticity will cause values to become negative
  6867. // as some properties cannot be set to negative values.
  6868. if(n == 0 || n == 1){ return n; }
  6869. var p = .3;
  6870. var s = p / 4;
  6871. n = n - 1;
  6872. return -1 * Math.pow(2, 10 * n) * Math.sin((n - s) * (2 * Math.PI) / p);
  6873. },
  6874. elasticOut: function(/* Decimal? */n){
  6875. // summary:
  6876. // An easing function that elasticly snaps around the target value,
  6877. // near the end of the Animation
  6878. //
  6879. // description:
  6880. // An easing function that elasticly snaps around the target value,
  6881. // near the end of the Animation
  6882. //
  6883. // Use caution when the elasticity will cause values to become
  6884. // negative as some properties cannot be set to negative values.
  6885. if(n==0 || n == 1){ return n; }
  6886. var p = .3;
  6887. var s = p / 4;
  6888. return Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p) + 1;
  6889. },
  6890. elasticInOut: function(/* Decimal? */n){
  6891. // summary:
  6892. // An easing function that elasticly snaps around the value, near
  6893. // the beginning and end of the Animation.
  6894. //
  6895. // description:
  6896. // An easing function that elasticly snaps around the value, near
  6897. // the beginning and end of the Animation.
  6898. //
  6899. // Use caution when the elasticity will cause values to become
  6900. // negative as some properties cannot be set to negative values.
  6901. if(n == 0) return 0;
  6902. n = n * 2;
  6903. if(n == 2) return 1;
  6904. var p = .3 * 1.5;
  6905. var s = p / 4;
  6906. if(n < 1){
  6907. n -= 1;
  6908. return -.5 * (Math.pow(2, 10 * n) * Math.sin((n - s) * (2 * Math.PI) / p));
  6909. }
  6910. n -= 1;
  6911. return .5 * (Math.pow(2, -10 * n) * Math.sin((n - s) * (2 * Math.PI) / p)) + 1;
  6912. },
  6913. bounceIn: function(/* Decimal? */n){
  6914. // summary:
  6915. // An easing function that 'bounces' near the beginning of an Animation
  6916. return (1 - dojo.fx.easing.bounceOut(1 - n)); // Decimal
  6917. },
  6918. bounceOut: function(/* Decimal? */n){
  6919. // summary:
  6920. // An easing function that 'bounces' near the end of an Animation
  6921. var s = 7.5625;
  6922. var p = 2.75;
  6923. var l;
  6924. if(n < (1 / p)){
  6925. l = s * Math.pow(n, 2);
  6926. }else if(n < (2 / p)){
  6927. n -= (1.5 / p);
  6928. l = s * Math.pow(n, 2) + .75;
  6929. }else if(n < (2.5 / p)){
  6930. n -= (2.25 / p);
  6931. l = s * Math.pow(n, 2) + .9375;
  6932. }else{
  6933. n -= (2.625 / p);
  6934. l = s * Math.pow(n, 2) + .984375;
  6935. }
  6936. return l;
  6937. },
  6938. bounceInOut: function(/* Decimal? */n){
  6939. // summary:
  6940. // An easing function that 'bounces' at the beginning and end of the Animation
  6941. if(n < 0.5){ return dojo.fx.easing.bounceIn(n * 2) / 2; }
  6942. return (dojo.fx.easing.bounceOut(n * 2 - 1) / 2) + 0.5; // Decimal
  6943. }
  6944. };
  6945. }
  6946. if(!dojo._hasResource["dojox.mobile.app.ImageView"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  6947. dojo._hasResource["dojox.mobile.app.ImageView"] = true;
  6948. dojo.provide("dojox.mobile.app.ImageView");
  6949. dojo.experimental("dojox.mobile.app.ImageView");
  6950. dojo.declare("dojox.mobile.app.ImageView", dojox.mobile.app._Widget, {
  6951. // zoom: Number
  6952. // The current level of zoom. This should not be set manually.
  6953. zoom: 1,
  6954. // zoomCenterX: Number
  6955. // The X coordinate in the image where the zoom is focused
  6956. zoomCenterX: 0,
  6957. // zoomCenterY: Number
  6958. // The Y coordinate in the image where the zoom is focused
  6959. zoomCenterY: 0,
  6960. // maxZoom: Number
  6961. // The highest degree to which an image can be zoomed. For example,
  6962. // a maxZoom of 5 means that the image will be 5 times larger than normal
  6963. maxZoom: 5,
  6964. // autoZoomLevel: Number
  6965. // The degree to which the image is zoomed when auto zoom is invoked.
  6966. // The higher the number, the more the image is zoomed in.
  6967. autoZoomLevel: 3,
  6968. // disableAutoZoom: Boolean
  6969. // Disables auto zoom
  6970. disableAutoZoom: false,
  6971. // disableSwipe: Boolean
  6972. // Disables the users ability to swipe from one image to the next.
  6973. disableSwipe: false,
  6974. // autoZoomEvent: String
  6975. // Overrides the default event listened to which invokes auto zoom
  6976. autoZoomEvent: null,
  6977. // _leftImg: Node
  6978. // The full sized image to the left
  6979. _leftImg: null,
  6980. // _centerImg: Node
  6981. // The full sized image in the center
  6982. _centerImg: null,
  6983. // _rightImg: Node
  6984. // The full sized image to the right
  6985. _rightImg: null,
  6986. // _leftImg: Node
  6987. // The small sized image to the left
  6988. _leftSmallImg: null,
  6989. // _centerImg: Node
  6990. // The small sized image in the center
  6991. _centerSmallImg: null,
  6992. // _rightImg: Node
  6993. // The small sized image to the right
  6994. _rightSmallImg: null,
  6995. constructor: function(){
  6996. this.panX = 0;
  6997. this.panY = 0;
  6998. this.handleLoad = dojo.hitch(this, this.handleLoad);
  6999. this._updateAnimatedZoom = dojo.hitch(this, this._updateAnimatedZoom);
  7000. this._updateAnimatedPan = dojo.hitch(this, this._updateAnimatedPan);
  7001. this._onAnimPanEnd = dojo.hitch(this, this._onAnimPanEnd);
  7002. },
  7003. buildRendering: function(){
  7004. this.inherited(arguments);
  7005. this.canvas = dojo.create("canvas", {}, this.domNode);
  7006. dojo.addClass(this.domNode, "mblImageView");
  7007. },
  7008. postCreate: function(){
  7009. this.inherited(arguments);
  7010. this.size = dojo.marginBox(this.domNode);
  7011. dojo.style(this.canvas, {
  7012. width: this.size.w + "px",
  7013. height: this.size.h + "px"
  7014. });
  7015. this.canvas.height = this.size.h;
  7016. this.canvas.width = this.size.w;
  7017. var _this = this;
  7018. // Listen to the mousedown/touchstart event. Record the position
  7019. // so we can use it to pan the image.
  7020. this.connect(this.domNode, "onmousedown", function(event){
  7021. if(_this.isAnimating()){
  7022. return;
  7023. }
  7024. if(_this.panX){
  7025. _this.handleDragEnd();
  7026. }
  7027. _this.downX = event.targetTouches ? event.targetTouches[0].clientX : event.clientX;
  7028. _this.downY = event.targetTouches ? event.targetTouches[0].clientY : event.clientY;
  7029. });
  7030. // record the movement of the mouse.
  7031. this.connect(this.domNode, "onmousemove", function(event){
  7032. if(_this.isAnimating()){
  7033. return;
  7034. }
  7035. if((!_this.downX && _this.downX !== 0) || (!_this.downY && _this.downY !== 0)){
  7036. // If the touch didn't begin on this widget, ignore the movement
  7037. return;
  7038. }
  7039. if((!_this.disableSwipe && _this.zoom == 1)
  7040. || (!_this.disableAutoZoom && _this.zoom != 1)){
  7041. var x = event.targetTouches ?
  7042. event.targetTouches[0].clientX : event.pageX;
  7043. var y = event.targetTouches ?
  7044. event.targetTouches[0].clientY : event.pageY;
  7045. _this.panX = x - _this.downX;
  7046. _this.panY = y - _this.downY;
  7047. if(_this.zoom == 1){
  7048. // If not zoomed in, then try to move to the next or prev image
  7049. // but only if the mouse has moved more than 10 pixels
  7050. // in the X direction
  7051. if(Math.abs(_this.panX) > 10){
  7052. _this.render();
  7053. }
  7054. }else{
  7055. // If zoomed in, pan the image if the mouse has moved more
  7056. // than 10 pixels in either direction.
  7057. if(Math.abs(_this.panX) > 10 || Math.abs(_this.panY) > 10){
  7058. _this.render();
  7059. }
  7060. }
  7061. }
  7062. });
  7063. this.connect(this.domNode, "onmouseout", function(event){
  7064. if(!_this.isAnimating() && _this.panX){
  7065. _this.handleDragEnd();
  7066. }
  7067. });
  7068. this.connect(this.domNode, "onmouseover", function(event){
  7069. _this.downX = _this.downY = null;
  7070. });
  7071. // Set up AutoZoom, which zooms in a fixed amount when the user taps
  7072. // a part of the canvas
  7073. this.connect(this.domNode, "onclick", function(event){
  7074. if(_this.isAnimating()){
  7075. return;
  7076. }
  7077. if(_this.downX == null || _this.downY == null){
  7078. return;
  7079. }
  7080. var x = (event.targetTouches ?
  7081. event.targetTouches[0].clientX : event.pageX);
  7082. var y = (event.targetTouches ?
  7083. event.targetTouches[0].clientY : event.pageY);
  7084. // If the mouse/finger has moved more than 14 pixels from where it
  7085. // started, do not treat it as a click. It is a drag.
  7086. if(Math.abs(_this.panX) > 14 || Math.abs(_this.panY) > 14){
  7087. _this.downX = _this.downY = null;
  7088. _this.handleDragEnd();
  7089. return;
  7090. }
  7091. _this.downX = _this.downY = null;
  7092. if(!_this.disableAutoZoom){
  7093. if(!_this._centerImg || !_this._centerImg._loaded){
  7094. // Do nothing until the image is loaded
  7095. return;
  7096. }
  7097. if(_this.zoom != 1){
  7098. _this.set("animatedZoom", 1);
  7099. return;
  7100. }
  7101. var pos = dojo._abs(_this.domNode);
  7102. // Translate the clicked point to a point on the source image
  7103. var xRatio = _this.size.w / _this._centerImg.width;
  7104. var yRatio = _this.size.h / _this._centerImg.height;
  7105. // Do an animated zoom to the point which was clicked.
  7106. _this.zoomTo(
  7107. ((x - pos.x) / xRatio) - _this.panX,
  7108. ((y - pos.y) / yRatio) - _this.panY,
  7109. _this.autoZoomLevel);
  7110. }
  7111. });
  7112. // Listen for Flick events
  7113. dojo.connect(this.domNode, "flick", this, "handleFlick");
  7114. },
  7115. isAnimating: function(){
  7116. // summary:
  7117. // Returns true if an animation is in progress, false otherwise.
  7118. return this._anim && this._anim.status() == "playing";
  7119. },
  7120. handleDragEnd: function(){
  7121. // summary:
  7122. // Handles the end of a dragging event. If not zoomed in, it
  7123. // determines if the next or previous image should be transitioned
  7124. // to.
  7125. this.downX = this.downY = null;
  7126. console.log("handleDragEnd");
  7127. if(this.zoom == 1){
  7128. if(!this.panX){
  7129. return;
  7130. }
  7131. var leftLoaded = (this._leftImg && this._leftImg._loaded)
  7132. || (this._leftSmallImg && this._leftSmallImg._loaded);
  7133. var rightLoaded = (this._rightImg && this._rightImg._loaded)
  7134. || (this._rightSmallImg && this._rightSmallImg._loaded);
  7135. // Check if the drag has moved the image more than half its length.
  7136. // If so, move to either the previous or next image.
  7137. var doMove =
  7138. !(Math.abs(this.panX) < this._centerImg._baseWidth / 2) &&
  7139. (
  7140. (this.panX > 0 && leftLoaded ? 1 : 0) ||
  7141. (this.panX < 0 && rightLoaded ? 1 : 0)
  7142. );
  7143. if(!doMove){
  7144. // If not moving to another image, animate the sliding of the
  7145. // image back into place.
  7146. this._animPanTo(0, dojo.fx.easing.expoOut, 700);
  7147. }else{
  7148. // Move to another image.
  7149. this.moveTo(this.panX);
  7150. }
  7151. }else{
  7152. if(!this.panX && !this.panY){
  7153. return;
  7154. }
  7155. // Recenter the zoomed image based on where it was panned to
  7156. // previously
  7157. this.zoomCenterX -= (this.panX / this.zoom);
  7158. this.zoomCenterY -= (this.panY / this.zoom);
  7159. this.panX = this.panY = 0;
  7160. }
  7161. },
  7162. handleFlick: function(event){
  7163. // summary:
  7164. // Handle a flick event.
  7165. if(this.zoom == 1 && event.duration < 500){
  7166. // Only handle quick flicks here, less than 0.5 seconds
  7167. // If not zoomed in, then check if we should move to the next photo
  7168. // or not
  7169. if(event.direction == "ltr"){
  7170. this.moveTo(1);
  7171. }else if(event.direction == "rtl"){
  7172. this.moveTo(-1);
  7173. }
  7174. // If an up or down flick occurs, it means nothing so ignore it
  7175. this.downX = this.downY = null;
  7176. }
  7177. },
  7178. moveTo: function(direction){
  7179. direction = direction > 0 ? 1 : -1;
  7180. var toImg;
  7181. if(direction < 1){
  7182. if(this._rightImg && this._rightImg._loaded){
  7183. toImg = this._rightImg;
  7184. }else if(this._rightSmallImg && this._rightSmallImg._loaded){
  7185. toImg = this._rightSmallImg;
  7186. }
  7187. }else{
  7188. if(this._leftImg && this._leftImg._loaded){
  7189. toImg = this._leftImg;
  7190. }else if(this._leftSmallImg && this._leftSmallImg._loaded){
  7191. toImg = this._leftSmallImg;
  7192. }
  7193. }
  7194. this._moveDir = direction;
  7195. var _this = this;
  7196. if(toImg && toImg._loaded){
  7197. // If the image is loaded, make a linear animation to show it
  7198. this._animPanTo(this.size.w * direction, null, 500, function(){
  7199. _this.panX = 0;
  7200. _this.panY = 0;
  7201. if(direction < 0){
  7202. // Moving to show the right image
  7203. _this._switchImage("left", "right");
  7204. }else{
  7205. // Moving to show the left image
  7206. _this._switchImage("right", "left");
  7207. }
  7208. _this.render();
  7209. _this.onChange(direction * -1);
  7210. });
  7211. }else{
  7212. // If the next image is not loaded, make an animation to
  7213. // move the center image to half the width of the widget and back
  7214. // again
  7215. console.log("moveTo image not loaded!", toImg);
  7216. this._animPanTo(0, dojo.fx.easing.expoOut, 700);
  7217. }
  7218. },
  7219. _switchImage: function(toImg, fromImg){
  7220. var toSmallImgName = "_" + toImg + "SmallImg";
  7221. var toImgName = "_" + toImg + "Img";
  7222. var fromSmallImgName = "_" + fromImg + "SmallImg";
  7223. var fromImgName = "_" + fromImg + "Img";
  7224. this[toImgName] = this._centerImg;
  7225. this[toSmallImgName] = this._centerSmallImg;
  7226. this[toImgName]._type = toImg;
  7227. if(this[toSmallImgName]){
  7228. this[toSmallImgName]._type = toImg;
  7229. }
  7230. this._centerImg = this[fromImgName];
  7231. this._centerSmallImg = this[fromSmallImgName];
  7232. this._centerImg._type = "center";
  7233. if(this._centerSmallImg){
  7234. this._centerSmallImg._type = "center";
  7235. }
  7236. this[fromImgName] = this[fromSmallImgName] = null;
  7237. },
  7238. _animPanTo: function(to, easing, duration, callback){
  7239. this._animCallback = callback;
  7240. this._anim = new dojo.Animation({
  7241. curve: [this.panX, to],
  7242. onAnimate: this._updateAnimatedPan,
  7243. duration: duration || 500,
  7244. easing: easing,
  7245. onEnd: this._onAnimPanEnd
  7246. });
  7247. this._anim.play();
  7248. return this._anim;
  7249. },
  7250. onChange: function(direction){
  7251. // summary:
  7252. // Stub function that can be listened to in order to provide
  7253. // new images when the displayed image changes
  7254. },
  7255. _updateAnimatedPan: function(amount){
  7256. this.panX = amount;
  7257. this.render();
  7258. },
  7259. _onAnimPanEnd: function(){
  7260. this.panX = this.panY = 0;
  7261. if(this._animCallback){
  7262. this._animCallback();
  7263. }
  7264. },
  7265. zoomTo: function(centerX, centerY, zoom){
  7266. this.set("zoomCenterX", centerX);
  7267. this.set("zoomCenterY", centerY);
  7268. this.set("animatedZoom", zoom);
  7269. },
  7270. render: function(){
  7271. var cxt = this.canvas.getContext('2d');
  7272. cxt.clearRect(0, 0, this.canvas.width, this.canvas.height);
  7273. // Render the center image
  7274. this._renderImg(
  7275. this._centerSmallImg,
  7276. this._centerImg,
  7277. this.zoom == 1 ? (this.panX < 0 ? 1 : this.panX > 0 ? -1 : 0) : 0);
  7278. if(this.zoom == 1 && this.panX != 0){
  7279. if(this.panX > 0){
  7280. // Render the left image, showing the right side of it
  7281. this._renderImg(this._leftSmallImg, this._leftImg, 1);
  7282. }else{
  7283. // Render the right image, showing the left side of it
  7284. this._renderImg(this._rightSmallImg, this._rightImg, -1);
  7285. }
  7286. }
  7287. },
  7288. _renderImg: function(smallImg, largeImg, panDir){
  7289. // summary:
  7290. // Renders a single image
  7291. // If zoomed, we just display the center img
  7292. var img = (largeImg && largeImg._loaded) ? largeImg : smallImg;
  7293. if(!img || !img._loaded){
  7294. // If neither the large or small image is loaded, display nothing
  7295. return;
  7296. }
  7297. var cxt = this.canvas.getContext('2d');
  7298. var baseWidth = img._baseWidth;
  7299. var baseHeight = img._baseHeight;
  7300. // Calculate the size the image would be if there were no bounds
  7301. var desiredWidth = baseWidth * this.zoom;
  7302. var desiredHeight = baseHeight * this.zoom;
  7303. // Calculate the actual size of the viewable image
  7304. var destWidth = Math.min(this.size.w, desiredWidth);
  7305. var destHeight = Math.min(this.size.h, desiredHeight);
  7306. // Calculate the size of the window on the original image to use
  7307. var sourceWidth = this.dispWidth = img.width * (destWidth / desiredWidth);
  7308. var sourceHeight = this.dispHeight = img.height * (destHeight / desiredHeight);
  7309. var zoomCenterX = this.zoomCenterX - (this.panX / this.zoom);
  7310. var zoomCenterY = this.zoomCenterY - (this.panY / this.zoom);
  7311. // Calculate where the center of the view should be
  7312. var centerX = Math.floor(Math.max(sourceWidth / 2,
  7313. Math.min(img.width - sourceWidth / 2, zoomCenterX)));
  7314. var centerY = Math.floor(Math.max(sourceHeight / 2,
  7315. Math.min(img.height - sourceHeight / 2, zoomCenterY)));
  7316. var sourceX = Math.max(0,
  7317. Math.round((img.width - sourceWidth)/2 + (centerX - img._centerX)) );
  7318. var sourceY = Math.max(0,
  7319. Math.round((img.height - sourceHeight) / 2 + (centerY - img._centerY))
  7320. );
  7321. var destX = Math.round(Math.max(0, this.canvas.width - destWidth)/2);
  7322. var destY = Math.round(Math.max(0, this.canvas.height - destHeight)/2);
  7323. var oldDestWidth = destWidth;
  7324. var oldSourceWidth = sourceWidth;
  7325. if(this.zoom == 1 && panDir && this.panX){
  7326. if(this.panX < 0){
  7327. if(panDir > 0){
  7328. // If the touch is moving left, and the right side of the
  7329. // image should be shown, then reduce the destination width
  7330. // by the absolute value of panX
  7331. destWidth -= Math.abs(this.panX);
  7332. destX = 0;
  7333. }else if(panDir < 0){
  7334. // If the touch is moving left, and the left side of the
  7335. // image should be shown, then set the displayed width
  7336. // to the absolute value of panX, less some pixels for
  7337. // a padding between images
  7338. destWidth = Math.max(1, Math.abs(this.panX) - 5);
  7339. destX = this.size.w - destWidth;
  7340. }
  7341. }else{
  7342. if(panDir > 0){
  7343. // If the touch is moving right, and the right side of the
  7344. // image should be shown, then set the destination width
  7345. // to the absolute value of the pan, less some pixels for
  7346. // padding
  7347. destWidth = Math.max(1, Math.abs(this.panX) - 5);
  7348. destX = 0;
  7349. }else if(panDir < 0){
  7350. // If the touch is moving right, and the left side of the
  7351. // image should be shown, then reduce the destination width
  7352. // by the widget width minus the absolute value of panX
  7353. destWidth -= Math.abs(this.panX);
  7354. destX = this.size.w - destWidth;
  7355. }
  7356. }
  7357. sourceWidth = Math.max(1,
  7358. Math.floor(sourceWidth * (destWidth / oldDestWidth)));
  7359. if(panDir > 0){
  7360. // If the right side of the image should be displayed, move
  7361. // the sourceX to be the width of the image minus the difference
  7362. // between the original sourceWidth and the new sourceWidth
  7363. sourceX = (sourceX + oldSourceWidth) - (sourceWidth);
  7364. }
  7365. sourceX = Math.floor(sourceX);
  7366. }
  7367. try{
  7368. // See https://developer.mozilla.org/en/Canvas_tutorial/Using_images
  7369. cxt.drawImage(
  7370. img,
  7371. Math.max(0, sourceX),
  7372. sourceY,
  7373. Math.min(oldSourceWidth, sourceWidth),
  7374. sourceHeight,
  7375. destX, // Xpos
  7376. destY, // Ypos
  7377. Math.min(oldDestWidth, destWidth),
  7378. destHeight
  7379. );
  7380. }catch(e){
  7381. console.log("Caught Error",e,
  7382. "type=", img._type,
  7383. "oldDestWidth = ", oldDestWidth,
  7384. "destWidth", destWidth,
  7385. "destX", destX
  7386. , "oldSourceWidth=",oldSourceWidth,
  7387. "sourceWidth=", sourceWidth,
  7388. "sourceX = " + sourceX
  7389. );
  7390. }
  7391. },
  7392. _setZoomAttr: function(amount){
  7393. this.zoom = Math.min(this.maxZoom, Math.max(1, amount));
  7394. if(this.zoom == 1
  7395. && this._centerImg
  7396. && this._centerImg._loaded){
  7397. if(!this.isAnimating()){
  7398. this.zoomCenterX = this._centerImg.width / 2;
  7399. this.zoomCenterY = this._centerImg.height / 2;
  7400. }
  7401. this.panX = this.panY = 0;
  7402. }
  7403. this.render();
  7404. },
  7405. _setZoomCenterXAttr: function(value){
  7406. if(value != this.zoomCenterX){
  7407. if(this._centerImg && this._centerImg._loaded){
  7408. value = Math.min(this._centerImg.width, value);
  7409. }
  7410. this.zoomCenterX = Math.max(0, Math.round(value));
  7411. }
  7412. },
  7413. _setZoomCenterYAttr: function(value){
  7414. if(value != this.zoomCenterY){
  7415. if(this._centerImg && this._centerImg._loaded){
  7416. value = Math.min(this._centerImg.height, value);
  7417. }
  7418. this.zoomCenterY = Math.max(0, Math.round(value));
  7419. }
  7420. },
  7421. _setZoomCenterAttr: function(value){
  7422. if(value.x != this.zoomCenterX || value.y != this.zoomCenterY){
  7423. this.set("zoomCenterX", value.x);
  7424. this.set("zoomCenterY", value.y);
  7425. this.render();
  7426. }
  7427. },
  7428. _setAnimatedZoomAttr: function(amount){
  7429. if(this._anim && this._anim.status() == "playing"){
  7430. return;
  7431. }
  7432. this._anim = new dojo.Animation({
  7433. curve: [this.zoom, amount],
  7434. onAnimate: this._updateAnimatedZoom,
  7435. onEnd: this._onAnimEnd
  7436. });
  7437. this._anim.play();
  7438. },
  7439. _updateAnimatedZoom: function(amount){
  7440. this._setZoomAttr(amount);
  7441. },
  7442. _setCenterUrlAttr: function(urlOrObj){
  7443. this._setImage("center", urlOrObj);
  7444. },
  7445. _setLeftUrlAttr: function(urlOrObj){
  7446. this._setImage("left", urlOrObj);
  7447. },
  7448. _setRightUrlAttr: function(urlOrObj){
  7449. this._setImage("right", urlOrObj);
  7450. },
  7451. _setImage: function(name, urlOrObj){
  7452. var smallUrl = null;
  7453. var largeUrl = null;
  7454. if(dojo.isString(urlOrObj)){
  7455. // If the argument is a string, then just load the large url
  7456. largeUrl = urlOrObj;
  7457. }else{
  7458. largeUrl = urlOrObj.large;
  7459. smallUrl = urlOrObj.small;
  7460. }
  7461. if(this["_" + name + "Img"] && this["_" + name + "Img"]._src == largeUrl){
  7462. // Identical URL, ignore it
  7463. return;
  7464. }
  7465. // Just do the large image for now
  7466. var largeImg = this["_" + name + "Img"] = new Image();
  7467. largeImg._type = name;
  7468. largeImg._loaded = false;
  7469. largeImg._src = largeUrl;
  7470. largeImg._conn = dojo.connect(largeImg, "onload", this.handleLoad);
  7471. if(smallUrl){
  7472. // If a url to a small version of the image has been provided,
  7473. // load that image first.
  7474. var smallImg = this["_" + name + "SmallImg"] = new Image();
  7475. smallImg._type = name;
  7476. smallImg._loaded = false;
  7477. smallImg._conn = dojo.connect(smallImg, "onload", this.handleLoad);
  7478. smallImg._isSmall = true;
  7479. smallImg._src = smallUrl;
  7480. smallImg.src = smallUrl;
  7481. }
  7482. // It's important that the large url's src is set after the small image
  7483. // to ensure it's loaded second.
  7484. largeImg.src = largeUrl;
  7485. },
  7486. handleLoad: function(evt){
  7487. // summary:
  7488. // Handles the loading of an image, both the large and small
  7489. // versions. A render is triggered as a result of each image load.
  7490. var img = evt.target;
  7491. img._loaded = true;
  7492. dojo.disconnect(img._conn);
  7493. var type = img._type;
  7494. switch(type){
  7495. case "center":
  7496. this.zoomCenterX = img.width / 2;
  7497. this.zoomCenterY = img.height / 2;
  7498. break;
  7499. }
  7500. var height = img.height;
  7501. var width = img.width;
  7502. if(width / this.size.w < height / this.size.h){
  7503. // Fit the height to the height of the canvas
  7504. img._baseHeight = this.canvas.height;
  7505. img._baseWidth = width / (height / this.size.h);
  7506. }else{
  7507. // Fix the width to the width of the canvas
  7508. img._baseWidth = this.canvas.width;
  7509. img._baseHeight = height / (width / this.size.w);
  7510. }
  7511. img._centerX = width / 2;
  7512. img._centerY = height / 2;
  7513. this.render();
  7514. this.onLoad(img._type, img._src, img._isSmall);
  7515. },
  7516. onLoad: function(type, url, isSmall){
  7517. // summary:
  7518. // Dummy function that is called whenever an image loads.
  7519. // type: String
  7520. // The position of the image that has loaded, either
  7521. // "center", "left" or "right"
  7522. // url: String
  7523. // The src of the image
  7524. // isSmall: Boolean
  7525. // True if it is a small version of the image that has loaded,
  7526. // false otherwise.
  7527. }
  7528. });
  7529. }
  7530. if(!dojo._hasResource["dojox.mobile.app.ImageThumbView"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7531. dojo._hasResource["dojox.mobile.app.ImageThumbView"] = true;
  7532. dojo.provide("dojox.mobile.app.ImageThumbView");
  7533. dojo.experimental("dojox.mobile.app.ImageThumbView");
  7534. dojo.declare("dojox.mobile.app.ImageThumbView", dijit._WidgetBase, {
  7535. // summary:
  7536. // An image thumbnail gallery
  7537. // items: Array
  7538. // The data items from which the image urls are retrieved.
  7539. // If an item is a string, it is expected to be a URL. Otherwise
  7540. // by default it is expected to have a 'url' member. This can
  7541. // be configured using the 'urlParam' attribute on this widget.
  7542. items: [],
  7543. // urlParam: String
  7544. // The paramter name used to retrieve an image url from a JSON object
  7545. urlParam: "url",
  7546. labelParam: null,
  7547. itemTemplate: '<div class="mblThumbInner">' +
  7548. '<div class="mblThumbOverlay"></div>' +
  7549. '<div class="mblThumbMask">' +
  7550. '<div class="mblThumbSrc" style="background-image:url(${url})"></div>' +
  7551. '</div>' +
  7552. '</div>',
  7553. minPadding: 4,
  7554. maxPerRow: 3,
  7555. maxRows: -1,
  7556. baseClass: "mblImageThumbView",
  7557. thumbSize: "medium",
  7558. animationEnabled: true,
  7559. selectedIndex: -1,
  7560. cache: null,
  7561. cacheMustMatch: false,
  7562. clickEvent: "onclick",
  7563. cacheBust: false,
  7564. disableHide: false,
  7565. constructor: function(params, node){
  7566. },
  7567. postCreate: function(){
  7568. this.inherited(arguments);
  7569. var _this = this;
  7570. var hoverCls = "mblThumbHover";
  7571. this.addThumb = dojo.hitch(this, this.addThumb);
  7572. this.handleImgLoad = dojo.hitch(this, this.handleImgLoad);
  7573. this.hideCached = dojo.hitch(this, this.hideCached);
  7574. this._onLoadImages = {};
  7575. this.cache = [];
  7576. this.visibleImages = [];
  7577. this._cacheCounter = 0;
  7578. this.connect(this.domNode, this.clickEvent, function(event){
  7579. var itemNode = _this._getItemNodeFromEvent(event);
  7580. if(itemNode && !itemNode._cached){
  7581. _this.onSelect(itemNode._item, itemNode._index, _this.items);
  7582. dojo.query(".selected", this.domNode).removeClass("selected");
  7583. dojo.addClass(itemNode, "selected");
  7584. }
  7585. });
  7586. dojo.addClass(this.domNode, this.thumbSize);
  7587. this.resize();
  7588. this.render();
  7589. },
  7590. onSelect: function(item, index, items){
  7591. // summary:
  7592. // Dummy function that is triggered when an image is selected.
  7593. },
  7594. _setAnimationEnabledAttr: function(value){
  7595. this.animationEnabled = value;
  7596. dojo[value ? "addClass" : "removeClass"](this.domNode, "animated");
  7597. },
  7598. _setItemsAttr: function(items){
  7599. this.items = items || [];
  7600. var urls = {};
  7601. var i;
  7602. for(i = 0; i < this.items.length; i++){
  7603. urls[this.items[i][this.urlParam]] = 1;
  7604. }
  7605. var clearedUrls = [];
  7606. for(var url in this._onLoadImages){
  7607. if(!urls[url] && this._onLoadImages[url]._conn){
  7608. dojo.disconnect(this._onLoadImages[url]._conn);
  7609. this._onLoadImages[url].src = null;
  7610. clearedUrls.push(url);
  7611. }
  7612. }
  7613. for(i = 0; i < clearedUrls.length; i++){
  7614. delete this._onLoadImages[url];
  7615. }
  7616. this.render();
  7617. },
  7618. _getItemNode: function(node){
  7619. while(node && !dojo.hasClass(node, "mblThumb") && node != this.domNode){
  7620. node = node.parentNode;
  7621. }
  7622. return (node == this.domNode) ? null : node;
  7623. },
  7624. _getItemNodeFromEvent: function(event){
  7625. if(event.touches && event.touches.length > 0){
  7626. event = event.touches[0];
  7627. }
  7628. return this._getItemNode(event.target);
  7629. },
  7630. resize: function(){
  7631. this._thumbSize = null;
  7632. this._size = dojo.contentBox(this.domNode);
  7633. this.disableHide = true;
  7634. this.render();
  7635. this.disableHide = false;
  7636. },
  7637. hideCached: function(){
  7638. // summary:
  7639. // Hides all cached nodes, so that they're no invisible and overlaying
  7640. // other screen elements.
  7641. for(var i = 0; i < this.cache.length; i++){
  7642. if (this.cache[i]) {
  7643. dojo.style(this.cache[i], "display", "none");
  7644. }
  7645. }
  7646. },
  7647. render: function(){
  7648. var i;
  7649. var url;
  7650. var item;
  7651. var thumb;
  7652. while(this.visibleImages && this.visibleImages.length > 0){
  7653. thumb = this.visibleImages.pop();
  7654. this.cache.push(thumb);
  7655. if (!this.disableHide) {
  7656. dojo.addClass(thumb, "hidden");
  7657. }
  7658. thumb._cached = true;
  7659. }
  7660. if(this.cache && this.cache.length > 0){
  7661. setTimeout(this.hideCached, 1000);
  7662. }
  7663. if(!this.items || this.items.length == 0){
  7664. return;
  7665. }
  7666. for(i = 0; i < this.items.length; i++){
  7667. item = this.items[i];
  7668. url = (dojo.isString(item) ? item : item[this.urlParam]);
  7669. this.addThumb(item, url, i);
  7670. if(this.maxRows > 0 && (i + 1) / this.maxPerRow >= this.maxRows){
  7671. break;
  7672. }
  7673. }
  7674. if(!this._thumbSize){
  7675. return;
  7676. }
  7677. var column = 0;
  7678. var row = -1;
  7679. var totalThumbWidth = this._thumbSize.w + (this.padding * 2);
  7680. var totalThumbHeight = this._thumbSize.h + (this.padding * 2);
  7681. var nodes = this.thumbNodes =
  7682. dojo.query(".mblThumb", this.domNode);
  7683. var pos = 0;
  7684. nodes = this.visibleImages;
  7685. for(i = 0; i < nodes.length; i++){
  7686. if(nodes[i]._cached){
  7687. continue;
  7688. }
  7689. if(pos % this.maxPerRow == 0){
  7690. row ++;
  7691. }
  7692. column = pos % this.maxPerRow;
  7693. this.place(
  7694. nodes[i],
  7695. (column * totalThumbWidth) + this.padding, // x position
  7696. (row * totalThumbHeight) + this.padding // y position
  7697. );
  7698. if(!nodes[i]._loading){
  7699. dojo.removeClass(nodes[i], "hidden");
  7700. }
  7701. if(pos == this.selectedIndex){
  7702. dojo[pos == this.selectedIndex ? "addClass" : "removeClass"]
  7703. (nodes[i], "selected");
  7704. }
  7705. pos++;
  7706. }
  7707. var numRows = Math.ceil(pos / this.maxPerRow);
  7708. this._numRows = numRows;
  7709. this.setContainerHeight((numRows * (this._thumbSize.h + this.padding * 2)));
  7710. },
  7711. setContainerHeight: function(amount){
  7712. dojo.style(this.domNode, "height", amount + "px");
  7713. },
  7714. addThumb: function(item, url, index){
  7715. var thumbDiv;
  7716. var cacheHit = false;
  7717. if(this.cache.length > 0){
  7718. // Reuse a previously created node if possible
  7719. var found = false;
  7720. // Search for an image with the same url first
  7721. for(var i = 0; i < this.cache.length; i++){
  7722. if(this.cache[i]._url == url){
  7723. thumbDiv = this.cache.splice(i, 1)[0];
  7724. found = true;
  7725. break
  7726. }
  7727. }
  7728. // if no image with the same url is found, just take the last one
  7729. if(!thumbDiv && !this.cacheMustMatch){
  7730. thumbDiv = this.cache.pop();
  7731. dojo.removeClass(thumbDiv, "selected");
  7732. } else {
  7733. cacheHit = true;
  7734. }
  7735. }
  7736. if(!thumbDiv){
  7737. // Create a new thumb
  7738. thumbDiv = dojo.create("div", {
  7739. "class": "mblThumb hidden",
  7740. innerHTML: dojo.string.substitute(this.itemTemplate, {
  7741. url: url
  7742. }, null, this)
  7743. }, this.domNode);
  7744. }
  7745. if(this.labelParam) {
  7746. var labelNode = dojo.query(".mblThumbLabel", thumbDiv)[0];
  7747. if(!labelNode) {
  7748. labelNode = dojo.create("div", {
  7749. "class": "mblThumbLabel"
  7750. }, thumbDiv);
  7751. }
  7752. labelNode.innerHTML = item[this.labelParam] || "";
  7753. }
  7754. dojo.style(thumbDiv, "display", "");
  7755. if (!this.disableHide) {
  7756. dojo.addClass(thumbDiv, "hidden");
  7757. }
  7758. if (!cacheHit) {
  7759. var loader = dojo.create("img", {});
  7760. loader._thumbDiv = thumbDiv;
  7761. loader._conn = dojo.connect(loader, "onload", this.handleImgLoad);
  7762. loader._url = url;
  7763. thumbDiv._loading = true;
  7764. this._onLoadImages[url] = loader;
  7765. if (loader) {
  7766. loader.src = url;
  7767. }
  7768. }
  7769. this.visibleImages.push(thumbDiv);
  7770. thumbDiv._index = index;
  7771. thumbDiv._item = item;
  7772. thumbDiv._url = url;
  7773. thumbDiv._cached = false;
  7774. if(!this._thumbSize){
  7775. this._thumbSize = dojo.marginBox(thumbDiv);
  7776. if(this._thumbSize.h == 0){
  7777. this._thumbSize.h = 100;
  7778. this._thumbSize.w = 100;
  7779. }
  7780. if(this.labelParam){
  7781. this._thumbSize.h += 8;
  7782. }
  7783. this.calcPadding();
  7784. }
  7785. },
  7786. handleImgLoad: function(event){
  7787. var img = event.target;
  7788. dojo.disconnect(img._conn);
  7789. dojo.removeClass(img._thumbDiv, "hidden");
  7790. img._thumbDiv._loading = false;
  7791. img._conn = null;
  7792. var url = img._url;
  7793. if(this.cacheBust){
  7794. url += (url.indexOf("?") > -1 ? "&" : "?")
  7795. + "cacheBust=" + (new Date()).getTime() + "_" + (this._cacheCounter++);
  7796. }
  7797. dojo.query(".mblThumbSrc", img._thumbDiv)
  7798. .style("backgroundImage", "url(" + url + ")");
  7799. delete this._onLoadImages[img._url];
  7800. },
  7801. calcPadding: function(){
  7802. var width = this._size.w;
  7803. var thumbWidth = this._thumbSize.w;
  7804. var imgBounds = thumbWidth + this.minPadding;
  7805. this.maxPerRow = Math.floor(width / imgBounds);
  7806. this.padding = Math.floor((width - (thumbWidth * this.maxPerRow)) / (this.maxPerRow * 2));
  7807. },
  7808. place: function(node, x, y){
  7809. dojo.style(node, {
  7810. "-webkit-transform" :"translate(" + x + "px," + y + "px)"
  7811. });
  7812. },
  7813. destroy: function(){
  7814. // Stop the loading of any more images
  7815. var img;
  7816. var counter = 0;
  7817. for (var url in this._onLoadImages){
  7818. img = this._onLoadImages[url];
  7819. if (img) {
  7820. img.src = null;
  7821. counter++;
  7822. }
  7823. }
  7824. this.inherited(arguments);
  7825. }
  7826. });
  7827. }
  7828. if(!dojo._hasResource["dojox.mobile.app._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7829. dojo._hasResource["dojox.mobile.app._base"] = true;
  7830. dojo.provide("dojox.mobile.app._base");
  7831. dojo.experimental("dojox.mobile.app._base");
  7832. (function(){
  7833. var stageController;
  7834. var appInfo;
  7835. var jsDependencies = [
  7836. "dojox.mobile",
  7837. "dojox.mobile.parser"
  7838. ];
  7839. var loadedResources = {};
  7840. var loadingDependencies;
  7841. var rootNode;
  7842. var sceneResources = [];
  7843. // Load the required resources asynchronously, since not all mobile OSes
  7844. // support dojo.require and sync XHR
  7845. function loadResources(resources, callback){
  7846. // summary:
  7847. // Loads one or more JavaScript files asynchronously. When complete,
  7848. // the first scene is pushed onto the stack.
  7849. // resources:
  7850. // An array of module names, e.g. 'dojox.mobile.AlertDialog'
  7851. var resource;
  7852. var url;
  7853. do {
  7854. resource = resources.pop();
  7855. if (resource.source) {
  7856. url = resource.source;
  7857. }else if (resource.module) {
  7858. url = dojo.baseUrl + dojo._getModuleSymbols(resource.module).join("/") + '.js';
  7859. }else {
  7860. alert("Error: invalid JavaScript resource " + dojo.toJson(resource));
  7861. return;
  7862. }
  7863. }while (resources.length > 0 && loadedResources[url]);
  7864. if(resources.length < 1 && loadedResources[url]){
  7865. // All resources have already been loaded
  7866. callback();
  7867. return;
  7868. }
  7869. dojo.xhrGet({
  7870. url: url,
  7871. sync: false
  7872. }).addCallbacks(function(text){
  7873. dojo["eval"](text);
  7874. loadedResources[url] = true;
  7875. if(resources.length > 0){
  7876. loadResources(resources, callback);
  7877. }else{
  7878. callback();
  7879. }
  7880. },
  7881. function(){
  7882. alert("Failed to load resource " + url);
  7883. });
  7884. }
  7885. var pushFirstScene = function(){
  7886. // summary:
  7887. // Pushes the first scene onto the stack.
  7888. stageController = new dojox.mobile.app.StageController(rootNode);
  7889. var defaultInfo = {
  7890. id: "com.test.app",
  7891. version: "1.0.0",
  7892. initialScene: "main"
  7893. };
  7894. // If the application info has been defined, as it should be,
  7895. // use it.
  7896. if(dojo.global["appInfo"]){
  7897. dojo.mixin(defaultInfo, dojo.global["appInfo"]);
  7898. }
  7899. appInfo = dojox.mobile.app.info = defaultInfo;
  7900. // Set the document title from the app info title if it exists
  7901. if(appInfo.title){
  7902. var titleNode = dojo.query("head title")[0] ||
  7903. dojo.create("title", {},dojo.query("head")[0]);
  7904. document.title = appInfo.title;
  7905. }
  7906. stageController.pushScene(appInfo.initialScene);
  7907. };
  7908. var initBackButton = function(){
  7909. var hasNativeBack = false;
  7910. if(dojo.global.BackButton){
  7911. // Android phonegap support
  7912. BackButton.override();
  7913. dojo.connect(document, 'backKeyDown', function(e) {
  7914. dojo.publish("/dojox/mobile/app/goback");
  7915. });
  7916. hasNativeBack = true;
  7917. }else if(dojo.global.Mojo){
  7918. // TODO: add webOS support
  7919. }
  7920. if(hasNativeBack){
  7921. dojo.addClass(dojo.body(), "mblNativeBack");
  7922. }
  7923. };
  7924. dojo.mixin(dojox.mobile.app, {
  7925. init: function(node){
  7926. // summary:
  7927. // Initializes the mobile app. Creates the
  7928. rootNode = node || dojo.body();
  7929. dojox.mobile.app.STAGE_CONTROLLER_ACTIVE = true;
  7930. dojo.subscribe("/dojox/mobile/app/goback", function(){
  7931. stageController.popScene();
  7932. });
  7933. dojo.subscribe("/dojox/mobile/app/alert", function(params){
  7934. dojox.mobile.app.getActiveSceneController().showAlertDialog(params);
  7935. });
  7936. dojo.subscribe("/dojox/mobile/app/pushScene", function(sceneName, params){
  7937. stageController.pushScene(sceneName, params || {});
  7938. });
  7939. // Get the list of files to load per scene/view
  7940. dojo.xhrGet({
  7941. url: "view-resources.json",
  7942. load: function(data){
  7943. var resources = [];
  7944. if(data){
  7945. // Should be an array
  7946. sceneResources = data = dojo.fromJson(data);
  7947. // Get the list of files to load that have no scene
  7948. // specified, and therefore should be loaded on
  7949. // startup
  7950. for(var i = 0; i < data.length; i++){
  7951. if(!data[i].scene){
  7952. resources.push(data[i]);
  7953. }
  7954. }
  7955. }
  7956. if(resources.length > 0){
  7957. loadResources(resources, pushFirstScene);
  7958. }else{
  7959. pushFirstScene();
  7960. }
  7961. },
  7962. error: pushFirstScene
  7963. });
  7964. initBackButton();
  7965. },
  7966. getActiveSceneController: function(){
  7967. // summary:
  7968. // Gets the controller for the active scene.
  7969. return stageController.getActiveSceneController();
  7970. },
  7971. getStageController: function(){
  7972. // summary:
  7973. // Gets the stage controller.
  7974. return stageController;
  7975. },
  7976. loadResources: function(resources, callback){
  7977. loadResources(resources, callback);
  7978. },
  7979. loadResourcesForScene: function(sceneName, callback){
  7980. var resources = [];
  7981. // Get the list of files to load that have no scene
  7982. // specified, and therefore should be loaded on
  7983. // startup
  7984. for(var i = 0; i < sceneResources.length; i++){
  7985. if(sceneResources[i].scene == sceneName){
  7986. resources.push(sceneResources[i]);
  7987. }
  7988. }
  7989. if(resources.length > 0){
  7990. loadResources(resources, callback);
  7991. }else{
  7992. callback();
  7993. }
  7994. },
  7995. resolveTemplate: function(sceneName){
  7996. // summary:
  7997. // Given the name of a scene, returns the path to it's template
  7998. // file. For example, for a scene named 'main', the file
  7999. // returned is 'app/views/main/main-scene.html'
  8000. // This function can be overridden if it is desired to have
  8001. // a different name to file mapping.
  8002. return "app/views/" + sceneName + "/" + sceneName + "-scene.html";
  8003. },
  8004. resolveAssistant: function(sceneName){
  8005. // summary:
  8006. // Given the name of a scene, returns the path to it's assistant
  8007. // file. For example, for a scene named 'main', the file
  8008. // returned is 'app/assistants/main-assistant.js'
  8009. // This function can be overridden if it is desired to have
  8010. // a different name to file mapping.
  8011. return "app/assistants/" + sceneName + "-assistant.js";
  8012. }
  8013. });
  8014. })();
  8015. }
  8016. if(!dojo._hasResource["dojox.mobileApp"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  8017. dojo._hasResource["dojox.mobileApp"] = true;
  8018. dojo.provide("dojox.mobileApp");
  8019. }