jquery.mobile-1.0.1.js 216 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076
  1. /*
  2. * jQuery Mobile Framework 1.0.1
  3. * http://jquerymobile.com
  4. *
  5. * Copyright 2011-2012 (c) jQuery Project
  6. * Dual licensed under the MIT or GPL Version 2 licenses.
  7. * http://jquery.org/license
  8. *
  9. */
  10. /*!
  11. * jQuery UI Widget @VERSION
  12. *
  13. * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
  14. * Dual licensed under the MIT or GPL Version 2 licenses.
  15. * http://jquery.org/license
  16. *
  17. * http://docs.jquery.com/UI/Widget
  18. */
  19. (function( $, undefined ) {
  20. // jQuery 1.4+
  21. if ( $.cleanData ) {
  22. var _cleanData = $.cleanData;
  23. $.cleanData = function( elems ) {
  24. for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
  25. $( elem ).triggerHandler( "remove" );
  26. }
  27. _cleanData( elems );
  28. };
  29. } else {
  30. var _remove = $.fn.remove;
  31. $.fn.remove = function( selector, keepData ) {
  32. return this.each(function() {
  33. if ( !keepData ) {
  34. if ( !selector || $.filter( selector, [ this ] ).length ) {
  35. $( "*", this ).add( [ this ] ).each(function() {
  36. $( this ).triggerHandler( "remove" );
  37. });
  38. }
  39. }
  40. return _remove.call( $(this), selector, keepData );
  41. });
  42. };
  43. }
  44. $.widget = function( name, base, prototype ) {
  45. var namespace = name.split( "." )[ 0 ],
  46. fullName;
  47. name = name.split( "." )[ 1 ];
  48. fullName = namespace + "-" + name;
  49. if ( !prototype ) {
  50. prototype = base;
  51. base = $.Widget;
  52. }
  53. // create selector for plugin
  54. $.expr[ ":" ][ fullName ] = function( elem ) {
  55. return !!$.data( elem, name );
  56. };
  57. $[ namespace ] = $[ namespace ] || {};
  58. $[ namespace ][ name ] = function( options, element ) {
  59. // allow instantiation without initializing for simple inheritance
  60. if ( arguments.length ) {
  61. this._createWidget( options, element );
  62. }
  63. };
  64. var basePrototype = new base();
  65. // we need to make the options hash a property directly on the new instance
  66. // otherwise we'll modify the options hash on the prototype that we're
  67. // inheriting from
  68. // $.each( basePrototype, function( key, val ) {
  69. // if ( $.isPlainObject(val) ) {
  70. // basePrototype[ key ] = $.extend( {}, val );
  71. // }
  72. // });
  73. basePrototype.options = $.extend( true, {}, basePrototype.options );
  74. $[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
  75. namespace: namespace,
  76. widgetName: name,
  77. widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
  78. widgetBaseClass: fullName
  79. }, prototype );
  80. $.widget.bridge( name, $[ namespace ][ name ] );
  81. };
  82. $.widget.bridge = function( name, object ) {
  83. $.fn[ name ] = function( options ) {
  84. var isMethodCall = typeof options === "string",
  85. args = Array.prototype.slice.call( arguments, 1 ),
  86. returnValue = this;
  87. // allow multiple hashes to be passed on init
  88. options = !isMethodCall && args.length ?
  89. $.extend.apply( null, [ true, options ].concat(args) ) :
  90. options;
  91. // prevent calls to internal methods
  92. if ( isMethodCall && options.charAt( 0 ) === "_" ) {
  93. return returnValue;
  94. }
  95. if ( isMethodCall ) {
  96. this.each(function() {
  97. var instance = $.data( this, name );
  98. if ( !instance ) {
  99. throw "cannot call methods on " + name + " prior to initialization; " +
  100. "attempted to call method '" + options + "'";
  101. }
  102. if ( !$.isFunction( instance[options] ) ) {
  103. throw "no such method '" + options + "' for " + name + " widget instance";
  104. }
  105. var methodValue = instance[ options ].apply( instance, args );
  106. if ( methodValue !== instance && methodValue !== undefined ) {
  107. returnValue = methodValue;
  108. return false;
  109. }
  110. });
  111. } else {
  112. this.each(function() {
  113. var instance = $.data( this, name );
  114. if ( instance ) {
  115. instance.option( options || {} )._init();
  116. } else {
  117. $.data( this, name, new object( options, this ) );
  118. }
  119. });
  120. }
  121. return returnValue;
  122. };
  123. };
  124. $.Widget = function( options, element ) {
  125. // allow instantiation without initializing for simple inheritance
  126. if ( arguments.length ) {
  127. this._createWidget( options, element );
  128. }
  129. };
  130. $.Widget.prototype = {
  131. widgetName: "widget",
  132. widgetEventPrefix: "",
  133. options: {
  134. disabled: false
  135. },
  136. _createWidget: function( options, element ) {
  137. // $.widget.bridge stores the plugin instance, but we do it anyway
  138. // so that it's stored even before the _create function runs
  139. $.data( element, this.widgetName, this );
  140. this.element = $( element );
  141. this.options = $.extend( true, {},
  142. this.options,
  143. this._getCreateOptions(),
  144. options );
  145. var self = this;
  146. this.element.bind( "remove." + this.widgetName, function() {
  147. self.destroy();
  148. });
  149. this._create();
  150. this._trigger( "create" );
  151. this._init();
  152. },
  153. _getCreateOptions: function() {
  154. var options = {};
  155. if ( $.metadata ) {
  156. options = $.metadata.get( element )[ this.widgetName ];
  157. }
  158. return options;
  159. },
  160. _create: function() {},
  161. _init: function() {},
  162. destroy: function() {
  163. this.element
  164. .unbind( "." + this.widgetName )
  165. .removeData( this.widgetName );
  166. this.widget()
  167. .unbind( "." + this.widgetName )
  168. .removeAttr( "aria-disabled" )
  169. .removeClass(
  170. this.widgetBaseClass + "-disabled " +
  171. "ui-state-disabled" );
  172. },
  173. widget: function() {
  174. return this.element;
  175. },
  176. option: function( key, value ) {
  177. var options = key;
  178. if ( arguments.length === 0 ) {
  179. // don't return a reference to the internal hash
  180. return $.extend( {}, this.options );
  181. }
  182. if (typeof key === "string" ) {
  183. if ( value === undefined ) {
  184. return this.options[ key ];
  185. }
  186. options = {};
  187. options[ key ] = value;
  188. }
  189. this._setOptions( options );
  190. return this;
  191. },
  192. _setOptions: function( options ) {
  193. var self = this;
  194. $.each( options, function( key, value ) {
  195. self._setOption( key, value );
  196. });
  197. return this;
  198. },
  199. _setOption: function( key, value ) {
  200. this.options[ key ] = value;
  201. if ( key === "disabled" ) {
  202. this.widget()
  203. [ value ? "addClass" : "removeClass"](
  204. this.widgetBaseClass + "-disabled" + " " +
  205. "ui-state-disabled" )
  206. .attr( "aria-disabled", value );
  207. }
  208. return this;
  209. },
  210. enable: function() {
  211. return this._setOption( "disabled", false );
  212. },
  213. disable: function() {
  214. return this._setOption( "disabled", true );
  215. },
  216. _trigger: function( type, event, data ) {
  217. var callback = this.options[ type ];
  218. event = $.Event( event );
  219. event.type = ( type === this.widgetEventPrefix ?
  220. type :
  221. this.widgetEventPrefix + type ).toLowerCase();
  222. data = data || {};
  223. // copy original event properties over to the new event
  224. // this would happen if we could call $.event.fix instead of $.Event
  225. // but we don't have a way to force an event to be fixed multiple times
  226. if ( event.originalEvent ) {
  227. for ( var i = $.event.props.length, prop; i; ) {
  228. prop = $.event.props[ --i ];
  229. event[ prop ] = event.originalEvent[ prop ];
  230. }
  231. }
  232. this.element.trigger( event, data );
  233. return !( $.isFunction(callback) &&
  234. callback.call( this.element[0], event, data ) === false ||
  235. event.isDefaultPrevented() );
  236. }
  237. };
  238. })( jQuery );
  239. /*
  240. * widget factory extentions for mobile
  241. */
  242. (function( $, undefined ) {
  243. $.widget( "mobile.widget", {
  244. // decorate the parent _createWidget to trigger `widgetinit` for users
  245. // who wish to do post post `widgetcreate` alterations/additions
  246. //
  247. // TODO create a pull request for jquery ui to trigger this event
  248. // in the original _createWidget
  249. _createWidget: function() {
  250. $.Widget.prototype._createWidget.apply( this, arguments );
  251. this._trigger( 'init' );
  252. },
  253. _getCreateOptions: function() {
  254. var elem = this.element,
  255. options = {};
  256. $.each( this.options, function( option ) {
  257. var value = elem.jqmData( option.replace( /[A-Z]/g, function( c ) {
  258. return "-" + c.toLowerCase();
  259. })
  260. );
  261. if ( value !== undefined ) {
  262. options[ option ] = value;
  263. }
  264. });
  265. return options;
  266. },
  267. enhanceWithin: function( target ) {
  268. // TODO remove dependency on the page widget for the keepNative.
  269. // Currently the keepNative value is defined on the page prototype so
  270. // the method is as well
  271. var page = $.mobile.closestPageData( $(target) ),
  272. keepNative = (page && page.keepNativeSelector()) || "";
  273. $( this.options.initSelector, target ).not( keepNative )[ this.widgetName ]();
  274. }
  275. });
  276. })( jQuery );
  277. /*
  278. * a workaround for window.matchMedia
  279. */
  280. (function( $, undefined ) {
  281. var $window = $( window ),
  282. $html = $( "html" );
  283. /* $.mobile.media method: pass a CSS media type or query and get a bool return
  284. note: this feature relies on actual media query support for media queries, though types will work most anywhere
  285. examples:
  286. $.mobile.media('screen') //>> tests for screen media type
  287. $.mobile.media('screen and (min-width: 480px)') //>> tests for screen media type with window width > 480px
  288. $.mobile.media('@media screen and (-webkit-min-device-pixel-ratio: 2)') //>> tests for webkit 2x pixel ratio (iPhone 4)
  289. */
  290. $.mobile.media = (function() {
  291. // TODO: use window.matchMedia once at least one UA implements it
  292. var cache = {},
  293. testDiv = $( "<div id='jquery-mediatest'>" ),
  294. fakeBody = $( "<body>" ).append( testDiv );
  295. return function( query ) {
  296. if ( !( query in cache ) ) {
  297. var styleBlock = document.createElement( "style" ),
  298. cssrule = "@media " + query + " { #jquery-mediatest { position:absolute; } }";
  299. //must set type for IE!
  300. styleBlock.type = "text/css";
  301. if ( styleBlock.styleSheet ){
  302. styleBlock.styleSheet.cssText = cssrule;
  303. } else {
  304. styleBlock.appendChild( document.createTextNode(cssrule) );
  305. }
  306. $html.prepend( fakeBody ).prepend( styleBlock );
  307. cache[ query ] = testDiv.css( "position" ) === "absolute";
  308. fakeBody.add( styleBlock ).remove();
  309. }
  310. return cache[ query ];
  311. };
  312. })();
  313. })(jQuery);
  314. /*
  315. * support tests
  316. */
  317. (function( $, undefined ) {
  318. var fakeBody = $( "<body>" ).prependTo( "html" ),
  319. fbCSS = fakeBody[ 0 ].style,
  320. vendors = [ "Webkit", "Moz", "O" ],
  321. webos = "palmGetResource" in window, //only used to rule out scrollTop
  322. operamini = window.operamini && ({}).toString.call( window.operamini ) === "[object OperaMini]",
  323. bb = window.blackberry; //only used to rule out box shadow, as it's filled opaque on BB
  324. // thx Modernizr
  325. function propExists( prop ) {
  326. var uc_prop = prop.charAt( 0 ).toUpperCase() + prop.substr( 1 ),
  327. props = ( prop + " " + vendors.join( uc_prop + " " ) + uc_prop ).split( " " );
  328. for ( var v in props ){
  329. if ( fbCSS[ props[ v ] ] !== undefined ) {
  330. return true;
  331. }
  332. }
  333. }
  334. // Test for dynamic-updating base tag support ( allows us to avoid href,src attr rewriting )
  335. function baseTagTest() {
  336. var fauxBase = location.protocol + "//" + location.host + location.pathname + "ui-dir/",
  337. base = $( "head base" ),
  338. fauxEle = null,
  339. href = "",
  340. link, rebase;
  341. if ( !base.length ) {
  342. base = fauxEle = $( "<base>", { "href": fauxBase }).appendTo( "head" );
  343. } else {
  344. href = base.attr( "href" );
  345. }
  346. link = $( "<a href='testurl' />" ).prependTo( fakeBody );
  347. rebase = link[ 0 ].href;
  348. base[ 0 ].href = href || location.pathname;
  349. if ( fauxEle ) {
  350. fauxEle.remove();
  351. }
  352. return rebase.indexOf( fauxBase ) === 0;
  353. }
  354. // non-UA-based IE version check by James Padolsey, modified by jdalton - from http://gist.github.com/527683
  355. // allows for inclusion of IE 6+, including Windows Mobile 7
  356. $.mobile.browser = {};
  357. $.mobile.browser.ie = (function() {
  358. var v = 3,
  359. div = document.createElement( "div" ),
  360. a = div.all || [];
  361. // added {} to silence closure compiler warnings. registering my dislike of all things
  362. // overly clever here for future reference
  363. while ( div.innerHTML = "<!--[if gt IE " + ( ++v ) + "]><br><![endif]-->", a[ 0 ] ){};
  364. return v > 4 ? v : !v;
  365. })();
  366. $.extend( $.support, {
  367. orientation: "orientation" in window && "onorientationchange" in window,
  368. touch: "ontouchend" in document,
  369. cssTransitions: "WebKitTransitionEvent" in window,
  370. pushState: "pushState" in history && "replaceState" in history,
  371. mediaquery: $.mobile.media( "only all" ),
  372. cssPseudoElement: !!propExists( "content" ),
  373. touchOverflow: !!propExists( "overflowScrolling" ),
  374. boxShadow: !!propExists( "boxShadow" ) && !bb,
  375. scrollTop: ( "pageXOffset" in window || "scrollTop" in document.documentElement || "scrollTop" in fakeBody[ 0 ] ) && !webos && !operamini,
  376. dynamicBaseTag: baseTagTest()
  377. });
  378. fakeBody.remove();
  379. // $.mobile.ajaxBlacklist is used to override ajaxEnabled on platforms that have known conflicts with hash history updates (BB5, Symbian)
  380. // or that generally work better browsing in regular http for full page refreshes (Opera Mini)
  381. // Note: This detection below is used as a last resort.
  382. // We recommend only using these detection methods when all other more reliable/forward-looking approaches are not possible
  383. var nokiaLTE7_3 = (function(){
  384. var ua = window.navigator.userAgent;
  385. //The following is an attempt to match Nokia browsers that are running Symbian/s60, with webkit, version 7.3 or older
  386. return ua.indexOf( "Nokia" ) > -1 &&
  387. ( ua.indexOf( "Symbian/3" ) > -1 || ua.indexOf( "Series60/5" ) > -1 ) &&
  388. ua.indexOf( "AppleWebKit" ) > -1 &&
  389. ua.match( /(BrowserNG|NokiaBrowser)\/7\.[0-3]/ );
  390. })();
  391. $.mobile.ajaxBlacklist =
  392. // BlackBerry browsers, pre-webkit
  393. window.blackberry && !window.WebKitPoint ||
  394. // Opera Mini
  395. operamini ||
  396. // Symbian webkits pre 7.3
  397. nokiaLTE7_3;
  398. // Lastly, this workaround is the only way we've found so far to get pre 7.3 Symbian webkit devices
  399. // to render the stylesheets when they're referenced before this script, as we'd recommend doing.
  400. // This simply reappends the CSS in place, which for some reason makes it apply
  401. if ( nokiaLTE7_3 ) {
  402. $(function() {
  403. $( "head link[rel='stylesheet']" ).attr( "rel", "alternate stylesheet" ).attr( "rel", "stylesheet" );
  404. });
  405. }
  406. // For ruling out shadows via css
  407. if ( !$.support.boxShadow ) {
  408. $( "html" ).addClass( "ui-mobile-nosupport-boxshadow" );
  409. }
  410. })( jQuery );
  411. /*
  412. * "mouse" plugin
  413. */
  414. // This plugin is an experiment for abstracting away the touch and mouse
  415. // events so that developers don't have to worry about which method of input
  416. // the device their document is loaded on supports.
  417. //
  418. // The idea here is to allow the developer to register listeners for the
  419. // basic mouse events, such as mousedown, mousemove, mouseup, and click,
  420. // and the plugin will take care of registering the correct listeners
  421. // behind the scenes to invoke the listener at the fastest possible time
  422. // for that device, while still retaining the order of event firing in
  423. // the traditional mouse environment, should multiple handlers be registered
  424. // on the same element for different events.
  425. //
  426. // The current version exposes the following virtual events to jQuery bind methods:
  427. // "vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel"
  428. (function( $, window, document, undefined ) {
  429. var dataPropertyName = "virtualMouseBindings",
  430. touchTargetPropertyName = "virtualTouchID",
  431. virtualEventNames = "vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel".split( " " ),
  432. touchEventProps = "clientX clientY pageX pageY screenX screenY".split( " " ),
  433. activeDocHandlers = {},
  434. resetTimerID = 0,
  435. startX = 0,
  436. startY = 0,
  437. didScroll = false,
  438. clickBlockList = [],
  439. blockMouseTriggers = false,
  440. blockTouchTriggers = false,
  441. eventCaptureSupported = "addEventListener" in document,
  442. $document = $( document ),
  443. nextTouchID = 1,
  444. lastTouchID = 0;
  445. $.vmouse = {
  446. moveDistanceThreshold: 10,
  447. clickDistanceThreshold: 10,
  448. resetTimerDuration: 1500
  449. };
  450. function getNativeEvent( event ) {
  451. while ( event && typeof event.originalEvent !== "undefined" ) {
  452. event = event.originalEvent;
  453. }
  454. return event;
  455. }
  456. function createVirtualEvent( event, eventType ) {
  457. var t = event.type,
  458. oe, props, ne, prop, ct, touch, i, j;
  459. event = $.Event(event);
  460. event.type = eventType;
  461. oe = event.originalEvent;
  462. props = $.event.props;
  463. // copy original event properties over to the new event
  464. // this would happen if we could call $.event.fix instead of $.Event
  465. // but we don't have a way to force an event to be fixed multiple times
  466. if ( oe ) {
  467. for ( i = props.length, prop; i; ) {
  468. prop = props[ --i ];
  469. event[ prop ] = oe[ prop ];
  470. }
  471. }
  472. // make sure that if the mouse and click virtual events are generated
  473. // without a .which one is defined
  474. if ( t.search(/mouse(down|up)|click/) > -1 && !event.which ){
  475. event.which = 1;
  476. }
  477. if ( t.search(/^touch/) !== -1 ) {
  478. ne = getNativeEvent( oe );
  479. t = ne.touches;
  480. ct = ne.changedTouches;
  481. touch = ( t && t.length ) ? t[0] : ( (ct && ct.length) ? ct[ 0 ] : undefined );
  482. if ( touch ) {
  483. for ( j = 0, len = touchEventProps.length; j < len; j++){
  484. prop = touchEventProps[ j ];
  485. event[ prop ] = touch[ prop ];
  486. }
  487. }
  488. }
  489. return event;
  490. }
  491. function getVirtualBindingFlags( element ) {
  492. var flags = {},
  493. b, k;
  494. while ( element ) {
  495. b = $.data( element, dataPropertyName );
  496. for ( k in b ) {
  497. if ( b[ k ] ) {
  498. flags[ k ] = flags.hasVirtualBinding = true;
  499. }
  500. }
  501. element = element.parentNode;
  502. }
  503. return flags;
  504. }
  505. function getClosestElementWithVirtualBinding( element, eventType ) {
  506. var b;
  507. while ( element ) {
  508. b = $.data( element, dataPropertyName );
  509. if ( b && ( !eventType || b[ eventType ] ) ) {
  510. return element;
  511. }
  512. element = element.parentNode;
  513. }
  514. return null;
  515. }
  516. function enableTouchBindings() {
  517. blockTouchTriggers = false;
  518. }
  519. function disableTouchBindings() {
  520. blockTouchTriggers = true;
  521. }
  522. function enableMouseBindings() {
  523. lastTouchID = 0;
  524. clickBlockList.length = 0;
  525. blockMouseTriggers = false;
  526. // When mouse bindings are enabled, our
  527. // touch bindings are disabled.
  528. disableTouchBindings();
  529. }
  530. function disableMouseBindings() {
  531. // When mouse bindings are disabled, our
  532. // touch bindings are enabled.
  533. enableTouchBindings();
  534. }
  535. function startResetTimer() {
  536. clearResetTimer();
  537. resetTimerID = setTimeout(function(){
  538. resetTimerID = 0;
  539. enableMouseBindings();
  540. }, $.vmouse.resetTimerDuration );
  541. }
  542. function clearResetTimer() {
  543. if ( resetTimerID ){
  544. clearTimeout( resetTimerID );
  545. resetTimerID = 0;
  546. }
  547. }
  548. function triggerVirtualEvent( eventType, event, flags ) {
  549. var ve;
  550. if ( ( flags && flags[ eventType ] ) ||
  551. ( !flags && getClosestElementWithVirtualBinding( event.target, eventType ) ) ) {
  552. ve = createVirtualEvent( event, eventType );
  553. $( event.target).trigger( ve );
  554. }
  555. return ve;
  556. }
  557. function mouseEventCallback( event ) {
  558. var touchID = $.data(event.target, touchTargetPropertyName);
  559. if ( !blockMouseTriggers && ( !lastTouchID || lastTouchID !== touchID ) ){
  560. var ve = triggerVirtualEvent( "v" + event.type, event );
  561. if ( ve ) {
  562. if ( ve.isDefaultPrevented() ) {
  563. event.preventDefault();
  564. }
  565. if ( ve.isPropagationStopped() ) {
  566. event.stopPropagation();
  567. }
  568. if ( ve.isImmediatePropagationStopped() ) {
  569. event.stopImmediatePropagation();
  570. }
  571. }
  572. }
  573. }
  574. function handleTouchStart( event ) {
  575. var touches = getNativeEvent( event ).touches,
  576. target, flags;
  577. if ( touches && touches.length === 1 ) {
  578. target = event.target;
  579. flags = getVirtualBindingFlags( target );
  580. if ( flags.hasVirtualBinding ) {
  581. lastTouchID = nextTouchID++;
  582. $.data( target, touchTargetPropertyName, lastTouchID );
  583. clearResetTimer();
  584. disableMouseBindings();
  585. didScroll = false;
  586. var t = getNativeEvent( event ).touches[ 0 ];
  587. startX = t.pageX;
  588. startY = t.pageY;
  589. triggerVirtualEvent( "vmouseover", event, flags );
  590. triggerVirtualEvent( "vmousedown", event, flags );
  591. }
  592. }
  593. }
  594. function handleScroll( event ) {
  595. if ( blockTouchTriggers ) {
  596. return;
  597. }
  598. if ( !didScroll ) {
  599. triggerVirtualEvent( "vmousecancel", event, getVirtualBindingFlags( event.target ) );
  600. }
  601. didScroll = true;
  602. startResetTimer();
  603. }
  604. function handleTouchMove( event ) {
  605. if ( blockTouchTriggers ) {
  606. return;
  607. }
  608. var t = getNativeEvent( event ).touches[ 0 ],
  609. didCancel = didScroll,
  610. moveThreshold = $.vmouse.moveDistanceThreshold;
  611. didScroll = didScroll ||
  612. ( Math.abs(t.pageX - startX) > moveThreshold ||
  613. Math.abs(t.pageY - startY) > moveThreshold ),
  614. flags = getVirtualBindingFlags( event.target );
  615. if ( didScroll && !didCancel ) {
  616. triggerVirtualEvent( "vmousecancel", event, flags );
  617. }
  618. triggerVirtualEvent( "vmousemove", event, flags );
  619. startResetTimer();
  620. }
  621. function handleTouchEnd( event ) {
  622. if ( blockTouchTriggers ) {
  623. return;
  624. }
  625. disableTouchBindings();
  626. var flags = getVirtualBindingFlags( event.target ),
  627. t;
  628. triggerVirtualEvent( "vmouseup", event, flags );
  629. if ( !didScroll ) {
  630. var ve = triggerVirtualEvent( "vclick", event, flags );
  631. if ( ve && ve.isDefaultPrevented() ) {
  632. // The target of the mouse events that follow the touchend
  633. // event don't necessarily match the target used during the
  634. // touch. This means we need to rely on coordinates for blocking
  635. // any click that is generated.
  636. t = getNativeEvent( event ).changedTouches[ 0 ];
  637. clickBlockList.push({
  638. touchID: lastTouchID,
  639. x: t.clientX,
  640. y: t.clientY
  641. });
  642. // Prevent any mouse events that follow from triggering
  643. // virtual event notifications.
  644. blockMouseTriggers = true;
  645. }
  646. }
  647. triggerVirtualEvent( "vmouseout", event, flags);
  648. didScroll = false;
  649. startResetTimer();
  650. }
  651. function hasVirtualBindings( ele ) {
  652. var bindings = $.data( ele, dataPropertyName ),
  653. k;
  654. if ( bindings ) {
  655. for ( k in bindings ) {
  656. if ( bindings[ k ] ) {
  657. return true;
  658. }
  659. }
  660. }
  661. return false;
  662. }
  663. function dummyMouseHandler(){}
  664. function getSpecialEventObject( eventType ) {
  665. var realType = eventType.substr( 1 );
  666. return {
  667. setup: function( data, namespace ) {
  668. // If this is the first virtual mouse binding for this element,
  669. // add a bindings object to its data.
  670. if ( !hasVirtualBindings( this ) ) {
  671. $.data( this, dataPropertyName, {});
  672. }
  673. // If setup is called, we know it is the first binding for this
  674. // eventType, so initialize the count for the eventType to zero.
  675. var bindings = $.data( this, dataPropertyName );
  676. bindings[ eventType ] = true;
  677. // If this is the first virtual mouse event for this type,
  678. // register a global handler on the document.
  679. activeDocHandlers[ eventType ] = ( activeDocHandlers[ eventType ] || 0 ) + 1;
  680. if ( activeDocHandlers[ eventType ] === 1 ) {
  681. $document.bind( realType, mouseEventCallback );
  682. }
  683. // Some browsers, like Opera Mini, won't dispatch mouse/click events
  684. // for elements unless they actually have handlers registered on them.
  685. // To get around this, we register dummy handlers on the elements.
  686. $( this ).bind( realType, dummyMouseHandler );
  687. // For now, if event capture is not supported, we rely on mouse handlers.
  688. if ( eventCaptureSupported ) {
  689. // If this is the first virtual mouse binding for the document,
  690. // register our touchstart handler on the document.
  691. activeDocHandlers[ "touchstart" ] = ( activeDocHandlers[ "touchstart" ] || 0) + 1;
  692. if (activeDocHandlers[ "touchstart" ] === 1) {
  693. $document.bind( "touchstart", handleTouchStart )
  694. .bind( "touchend", handleTouchEnd )
  695. // On touch platforms, touching the screen and then dragging your finger
  696. // causes the window content to scroll after some distance threshold is
  697. // exceeded. On these platforms, a scroll prevents a click event from being
  698. // dispatched, and on some platforms, even the touchend is suppressed. To
  699. // mimic the suppression of the click event, we need to watch for a scroll
  700. // event. Unfortunately, some platforms like iOS don't dispatch scroll
  701. // events until *AFTER* the user lifts their finger (touchend). This means
  702. // we need to watch both scroll and touchmove events to figure out whether
  703. // or not a scroll happenens before the touchend event is fired.
  704. .bind( "touchmove", handleTouchMove )
  705. .bind( "scroll", handleScroll );
  706. }
  707. }
  708. },
  709. teardown: function( data, namespace ) {
  710. // If this is the last virtual binding for this eventType,
  711. // remove its global handler from the document.
  712. --activeDocHandlers[ eventType ];
  713. if ( !activeDocHandlers[ eventType ] ) {
  714. $document.unbind( realType, mouseEventCallback );
  715. }
  716. if ( eventCaptureSupported ) {
  717. // If this is the last virtual mouse binding in existence,
  718. // remove our document touchstart listener.
  719. --activeDocHandlers[ "touchstart" ];
  720. if ( !activeDocHandlers[ "touchstart" ] ) {
  721. $document.unbind( "touchstart", handleTouchStart )
  722. .unbind( "touchmove", handleTouchMove )
  723. .unbind( "touchend", handleTouchEnd )
  724. .unbind( "scroll", handleScroll );
  725. }
  726. }
  727. var $this = $( this ),
  728. bindings = $.data( this, dataPropertyName );
  729. // teardown may be called when an element was
  730. // removed from the DOM. If this is the case,
  731. // jQuery core may have already stripped the element
  732. // of any data bindings so we need to check it before
  733. // using it.
  734. if ( bindings ) {
  735. bindings[ eventType ] = false;
  736. }
  737. // Unregister the dummy event handler.
  738. $this.unbind( realType, dummyMouseHandler );
  739. // If this is the last virtual mouse binding on the
  740. // element, remove the binding data from the element.
  741. if ( !hasVirtualBindings( this ) ) {
  742. $this.removeData( dataPropertyName );
  743. }
  744. }
  745. };
  746. }
  747. // Expose our custom events to the jQuery bind/unbind mechanism.
  748. for ( var i = 0; i < virtualEventNames.length; i++ ){
  749. $.event.special[ virtualEventNames[ i ] ] = getSpecialEventObject( virtualEventNames[ i ] );
  750. }
  751. // Add a capture click handler to block clicks.
  752. // Note that we require event capture support for this so if the device
  753. // doesn't support it, we punt for now and rely solely on mouse events.
  754. if ( eventCaptureSupported ) {
  755. document.addEventListener( "click", function( e ){
  756. var cnt = clickBlockList.length,
  757. target = e.target,
  758. x, y, ele, i, o, touchID;
  759. if ( cnt ) {
  760. x = e.clientX;
  761. y = e.clientY;
  762. threshold = $.vmouse.clickDistanceThreshold;
  763. // The idea here is to run through the clickBlockList to see if
  764. // the current click event is in the proximity of one of our
  765. // vclick events that had preventDefault() called on it. If we find
  766. // one, then we block the click.
  767. //
  768. // Why do we have to rely on proximity?
  769. //
  770. // Because the target of the touch event that triggered the vclick
  771. // can be different from the target of the click event synthesized
  772. // by the browser. The target of a mouse/click event that is syntehsized
  773. // from a touch event seems to be implementation specific. For example,
  774. // some browsers will fire mouse/click events for a link that is near
  775. // a touch event, even though the target of the touchstart/touchend event
  776. // says the user touched outside the link. Also, it seems that with most
  777. // browsers, the target of the mouse/click event is not calculated until the
  778. // time it is dispatched, so if you replace an element that you touched
  779. // with another element, the target of the mouse/click will be the new
  780. // element underneath that point.
  781. //
  782. // Aside from proximity, we also check to see if the target and any
  783. // of its ancestors were the ones that blocked a click. This is necessary
  784. // because of the strange mouse/click target calculation done in the
  785. // Android 2.1 browser, where if you click on an element, and there is a
  786. // mouse/click handler on one of its ancestors, the target will be the
  787. // innermost child of the touched element, even if that child is no where
  788. // near the point of touch.
  789. ele = target;
  790. while ( ele ) {
  791. for ( i = 0; i < cnt; i++ ) {
  792. o = clickBlockList[ i ];
  793. touchID = 0;
  794. if ( ( ele === target && Math.abs( o.x - x ) < threshold && Math.abs( o.y - y ) < threshold ) ||
  795. $.data( ele, touchTargetPropertyName ) === o.touchID ) {
  796. // XXX: We may want to consider removing matches from the block list
  797. // instead of waiting for the reset timer to fire.
  798. e.preventDefault();
  799. e.stopPropagation();
  800. return;
  801. }
  802. }
  803. ele = ele.parentNode;
  804. }
  805. }
  806. }, true);
  807. }
  808. })( jQuery, window, document );
  809. /*
  810. * "events" plugin - Handles events
  811. */
  812. (function( $, window, undefined ) {
  813. // add new event shortcuts
  814. $.each( ( "touchstart touchmove touchend orientationchange throttledresize " +
  815. "tap taphold swipe swipeleft swiperight scrollstart scrollstop" ).split( " " ), function( i, name ) {
  816. $.fn[ name ] = function( fn ) {
  817. return fn ? this.bind( name, fn ) : this.trigger( name );
  818. };
  819. $.attrFn[ name ] = true;
  820. });
  821. var supportTouch = $.support.touch,
  822. scrollEvent = "touchmove scroll",
  823. touchStartEvent = supportTouch ? "touchstart" : "mousedown",
  824. touchStopEvent = supportTouch ? "touchend" : "mouseup",
  825. touchMoveEvent = supportTouch ? "touchmove" : "mousemove";
  826. function triggerCustomEvent( obj, eventType, event ) {
  827. var originalType = event.type;
  828. event.type = eventType;
  829. $.event.handle.call( obj, event );
  830. event.type = originalType;
  831. }
  832. // also handles scrollstop
  833. $.event.special.scrollstart = {
  834. enabled: true,
  835. setup: function() {
  836. var thisObject = this,
  837. $this = $( thisObject ),
  838. scrolling,
  839. timer;
  840. function trigger( event, state ) {
  841. scrolling = state;
  842. triggerCustomEvent( thisObject, scrolling ? "scrollstart" : "scrollstop", event );
  843. }
  844. // iPhone triggers scroll after a small delay; use touchmove instead
  845. $this.bind( scrollEvent, function( event ) {
  846. if ( !$.event.special.scrollstart.enabled ) {
  847. return;
  848. }
  849. if ( !scrolling ) {
  850. trigger( event, true );
  851. }
  852. clearTimeout( timer );
  853. timer = setTimeout(function() {
  854. trigger( event, false );
  855. }, 50 );
  856. });
  857. }
  858. };
  859. // also handles taphold
  860. $.event.special.tap = {
  861. setup: function() {
  862. var thisObject = this,
  863. $this = $( thisObject );
  864. $this.bind( "vmousedown", function( event ) {
  865. if ( event.which && event.which !== 1 ) {
  866. return false;
  867. }
  868. var origTarget = event.target,
  869. origEvent = event.originalEvent,
  870. timer;
  871. function clearTapTimer() {
  872. clearTimeout( timer );
  873. }
  874. function clearTapHandlers() {
  875. clearTapTimer();
  876. $this.unbind( "vclick", clickHandler )
  877. .unbind( "vmouseup", clearTapTimer )
  878. .unbind( "vmousecancel", clearTapHandlers );
  879. }
  880. function clickHandler(event) {
  881. clearTapHandlers();
  882. // ONLY trigger a 'tap' event if the start target is
  883. // the same as the stop target.
  884. if ( origTarget == event.target ) {
  885. triggerCustomEvent( thisObject, "tap", event );
  886. }
  887. }
  888. $this.bind( "vmousecancel", clearTapHandlers )
  889. .bind( "vmouseup", clearTapTimer )
  890. .bind( "vclick", clickHandler );
  891. timer = setTimeout(function() {
  892. triggerCustomEvent( thisObject, "taphold", $.Event( "taphold" ) );
  893. }, 750 );
  894. });
  895. }
  896. };
  897. // also handles swipeleft, swiperight
  898. $.event.special.swipe = {
  899. scrollSupressionThreshold: 10, // More than this horizontal displacement, and we will suppress scrolling.
  900. durationThreshold: 1000, // More time than this, and it isn't a swipe.
  901. horizontalDistanceThreshold: 30, // Swipe horizontal displacement must be more than this.
  902. verticalDistanceThreshold: 75, // Swipe vertical displacement must be less than this.
  903. setup: function() {
  904. var thisObject = this,
  905. $this = $( thisObject );
  906. $this.bind( touchStartEvent, function( event ) {
  907. var data = event.originalEvent.touches ?
  908. event.originalEvent.touches[ 0 ] : event,
  909. start = {
  910. time: ( new Date() ).getTime(),
  911. coords: [ data.pageX, data.pageY ],
  912. origin: $( event.target )
  913. },
  914. stop;
  915. function moveHandler( event ) {
  916. if ( !start ) {
  917. return;
  918. }
  919. var data = event.originalEvent.touches ?
  920. event.originalEvent.touches[ 0 ] : event;
  921. stop = {
  922. time: ( new Date() ).getTime(),
  923. coords: [ data.pageX, data.pageY ]
  924. };
  925. // prevent scrolling
  926. if ( Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.scrollSupressionThreshold ) {
  927. event.preventDefault();
  928. }
  929. }
  930. $this.bind( touchMoveEvent, moveHandler )
  931. .one( touchStopEvent, function( event ) {
  932. $this.unbind( touchMoveEvent, moveHandler );
  933. if ( start && stop ) {
  934. if ( stop.time - start.time < $.event.special.swipe.durationThreshold &&
  935. Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.horizontalDistanceThreshold &&
  936. Math.abs( start.coords[ 1 ] - stop.coords[ 1 ] ) < $.event.special.swipe.verticalDistanceThreshold ) {
  937. start.origin.trigger( "swipe" )
  938. .trigger( start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight" );
  939. }
  940. }
  941. start = stop = undefined;
  942. });
  943. });
  944. }
  945. };
  946. (function( $, window ) {
  947. // "Cowboy" Ben Alman
  948. var win = $( window ),
  949. special_event,
  950. get_orientation,
  951. last_orientation,
  952. initial_orientation_is_landscape,
  953. initial_orientation_is_default,
  954. portrait_map = { "0": true, "180": true };
  955. // It seems that some device/browser vendors use window.orientation values 0 and 180 to
  956. // denote the "default" orientation. For iOS devices, and most other smart-phones tested,
  957. // the default orientation is always "portrait", but in some Android and RIM based tablets,
  958. // the default orientation is "landscape". The following code injects a landscape orientation
  959. // media query into the document to figure out what the current orientation is, and then
  960. // makes adjustments to the portrait_map if necessary, so that we can properly
  961. // decode the window.orientation value whenever get_orientation() is called.
  962. if ( $.support.orientation ) {
  963. // Use a media query to figure out the true orientation of the device at this moment.
  964. // Note that we've initialized the portrait map values to 0 and 180, *AND* we purposely
  965. // use a landscape media query so that if the device/browser does not support this particular
  966. // media query, we default to the assumption that portrait is the default orientation.
  967. initial_orientation_is_landscape = $.mobile.media("all and (orientation: landscape)");
  968. // Now check to see if the current window.orientation is 0 or 180.
  969. initial_orientation_is_default = portrait_map[ window.orientation ];
  970. // If the initial orientation is landscape, but window.orientation reports 0 or 180, *OR*
  971. // if the initial orientation is portrait, but window.orientation reports 90 or -90, we
  972. // need to flip our portrait_map values because landscape is the default orientation for
  973. // this device/browser.
  974. if ( ( initial_orientation_is_landscape && initial_orientation_is_default ) || ( !initial_orientation_is_landscape && !initial_orientation_is_default ) ) {
  975. portrait_map = { "-90": true, "90": true };
  976. }
  977. }
  978. $.event.special.orientationchange = special_event = {
  979. setup: function() {
  980. // If the event is supported natively, return false so that jQuery
  981. // will bind to the event using DOM methods.
  982. if ( $.support.orientation && $.mobile.orientationChangeEnabled ) {
  983. return false;
  984. }
  985. // Get the current orientation to avoid initial double-triggering.
  986. last_orientation = get_orientation();
  987. // Because the orientationchange event doesn't exist, simulate the
  988. // event by testing window dimensions on resize.
  989. win.bind( "throttledresize", handler );
  990. },
  991. teardown: function(){
  992. // If the event is not supported natively, return false so that
  993. // jQuery will unbind the event using DOM methods.
  994. if ( $.support.orientation && $.mobile.orientationChangeEnabled ) {
  995. return false;
  996. }
  997. // Because the orientationchange event doesn't exist, unbind the
  998. // resize event handler.
  999. win.unbind( "throttledresize", handler );
  1000. },
  1001. add: function( handleObj ) {
  1002. // Save a reference to the bound event handler.
  1003. var old_handler = handleObj.handler;
  1004. handleObj.handler = function( event ) {
  1005. // Modify event object, adding the .orientation property.
  1006. event.orientation = get_orientation();
  1007. // Call the originally-bound event handler and return its result.
  1008. return old_handler.apply( this, arguments );
  1009. };
  1010. }
  1011. };
  1012. // If the event is not supported natively, this handler will be bound to
  1013. // the window resize event to simulate the orientationchange event.
  1014. function handler() {
  1015. // Get the current orientation.
  1016. var orientation = get_orientation();
  1017. if ( orientation !== last_orientation ) {
  1018. // The orientation has changed, so trigger the orientationchange event.
  1019. last_orientation = orientation;
  1020. win.trigger( "orientationchange" );
  1021. }
  1022. }
  1023. // Get the current page orientation. This method is exposed publicly, should it
  1024. // be needed, as jQuery.event.special.orientationchange.orientation()
  1025. $.event.special.orientationchange.orientation = get_orientation = function() {
  1026. var isPortrait = true, elem = document.documentElement;
  1027. // prefer window orientation to the calculation based on screensize as
  1028. // the actual screen resize takes place before or after the orientation change event
  1029. // has been fired depending on implementation (eg android 2.3 is before, iphone after).
  1030. // More testing is required to determine if a more reliable method of determining the new screensize
  1031. // is possible when orientationchange is fired. (eg, use media queries + element + opacity)
  1032. if ( $.support.orientation ) {
  1033. // if the window orientation registers as 0 or 180 degrees report
  1034. // portrait, otherwise landscape
  1035. isPortrait = portrait_map[ window.orientation ];
  1036. } else {
  1037. isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
  1038. }
  1039. return isPortrait ? "portrait" : "landscape";
  1040. };
  1041. })( jQuery, window );
  1042. // throttled resize event
  1043. (function() {
  1044. $.event.special.throttledresize = {
  1045. setup: function() {
  1046. $( this ).bind( "resize", handler );
  1047. },
  1048. teardown: function(){
  1049. $( this ).unbind( "resize", handler );
  1050. }
  1051. };
  1052. var throttle = 250,
  1053. handler = function() {
  1054. curr = ( new Date() ).getTime();
  1055. diff = curr - lastCall;
  1056. if ( diff >= throttle ) {
  1057. lastCall = curr;
  1058. $( this ).trigger( "throttledresize" );
  1059. } else {
  1060. if ( heldCall ) {
  1061. clearTimeout( heldCall );
  1062. }
  1063. // Promise a held call will still execute
  1064. heldCall = setTimeout( handler, throttle - diff );
  1065. }
  1066. },
  1067. lastCall = 0,
  1068. heldCall,
  1069. curr,
  1070. diff;
  1071. })();
  1072. $.each({
  1073. scrollstop: "scrollstart",
  1074. taphold: "tap",
  1075. swipeleft: "swipe",
  1076. swiperight: "swipe"
  1077. }, function( event, sourceEvent ) {
  1078. $.event.special[ event ] = {
  1079. setup: function() {
  1080. $( this ).bind( sourceEvent, $.noop );
  1081. }
  1082. };
  1083. });
  1084. })( jQuery, this );
  1085. // Script: jQuery hashchange event
  1086. //
  1087. // *Version: 1.3, Last updated: 7/21/2010*
  1088. //
  1089. // Project Home - http://benalman.com/projects/jquery-hashchange-plugin/
  1090. // GitHub - http://github.com/cowboy/jquery-hashchange/
  1091. // Source - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.js
  1092. // (Minified) - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.min.js (0.8kb gzipped)
  1093. //
  1094. // About: License
  1095. //
  1096. // Copyright (c) 2010 "Cowboy" Ben Alman,
  1097. // Dual licensed under the MIT and GPL licenses.
  1098. // http://benalman.com/about/license/
  1099. //
  1100. // About: Examples
  1101. //
  1102. // These working examples, complete with fully commented code, illustrate a few
  1103. // ways in which this plugin can be used.
  1104. //
  1105. // hashchange event - http://benalman.com/code/projects/jquery-hashchange/examples/hashchange/
  1106. // document.domain - http://benalman.com/code/projects/jquery-hashchange/examples/document_domain/
  1107. //
  1108. // About: Support and Testing
  1109. //
  1110. // Information about what version or versions of jQuery this plugin has been
  1111. // tested with, what browsers it has been tested in, and where the unit tests
  1112. // reside (so you can test it yourself).
  1113. //
  1114. // jQuery Versions - 1.2.6, 1.3.2, 1.4.1, 1.4.2
  1115. // Browsers Tested - Internet Explorer 6-8, Firefox 2-4, Chrome 5-6, Safari 3.2-5,
  1116. // Opera 9.6-10.60, iPhone 3.1, Android 1.6-2.2, BlackBerry 4.6-5.
  1117. // Unit Tests - http://benalman.com/code/projects/jquery-hashchange/unit/
  1118. //
  1119. // About: Known issues
  1120. //
  1121. // While this jQuery hashchange event implementation is quite stable and
  1122. // robust, there are a few unfortunate browser bugs surrounding expected
  1123. // hashchange event-based behaviors, independent of any JavaScript
  1124. // window.onhashchange abstraction. See the following examples for more
  1125. // information:
  1126. //
  1127. // Chrome: Back Button - http://benalman.com/code/projects/jquery-hashchange/examples/bug-chrome-back-button/
  1128. // Firefox: Remote XMLHttpRequest - http://benalman.com/code/projects/jquery-hashchange/examples/bug-firefox-remote-xhr/
  1129. // WebKit: Back Button in an Iframe - http://benalman.com/code/projects/jquery-hashchange/examples/bug-webkit-hash-iframe/
  1130. // Safari: Back Button from a different domain - http://benalman.com/code/projects/jquery-hashchange/examples/bug-safari-back-from-diff-domain/
  1131. //
  1132. // Also note that should a browser natively support the window.onhashchange
  1133. // event, but not report that it does, the fallback polling loop will be used.
  1134. //
  1135. // About: Release History
  1136. //
  1137. // 1.3 - (7/21/2010) Reorganized IE6/7 Iframe code to make it more
  1138. // "removable" for mobile-only development. Added IE6/7 document.title
  1139. // support. Attempted to make Iframe as hidden as possible by using
  1140. // techniques from http://www.paciellogroup.com/blog/?p=604. Added
  1141. // support for the "shortcut" format $(window).hashchange( fn ) and
  1142. // $(window).hashchange() like jQuery provides for built-in events.
  1143. // Renamed jQuery.hashchangeDelay to <jQuery.fn.hashchange.delay> and
  1144. // lowered its default value to 50. Added <jQuery.fn.hashchange.domain>
  1145. // and <jQuery.fn.hashchange.src> properties plus document-domain.html
  1146. // file to address access denied issues when setting document.domain in
  1147. // IE6/7.
  1148. // 1.2 - (2/11/2010) Fixed a bug where coming back to a page using this plugin
  1149. // from a page on another domain would cause an error in Safari 4. Also,
  1150. // IE6/7 Iframe is now inserted after the body (this actually works),
  1151. // which prevents the page from scrolling when the event is first bound.
  1152. // Event can also now be bound before DOM ready, but it won't be usable
  1153. // before then in IE6/7.
  1154. // 1.1 - (1/21/2010) Incorporated document.documentMode test to fix IE8 bug
  1155. // where browser version is incorrectly reported as 8.0, despite
  1156. // inclusion of the X-UA-Compatible IE=EmulateIE7 meta tag.
  1157. // 1.0 - (1/9/2010) Initial Release. Broke out the jQuery BBQ event.special
  1158. // window.onhashchange functionality into a separate plugin for users
  1159. // who want just the basic event & back button support, without all the
  1160. // extra awesomeness that BBQ provides. This plugin will be included as
  1161. // part of jQuery BBQ, but also be available separately.
  1162. (function($,window,undefined){
  1163. // Reused string.
  1164. var str_hashchange = 'hashchange',
  1165. // Method / object references.
  1166. doc = document,
  1167. fake_onhashchange,
  1168. special = $.event.special,
  1169. // Does the browser support window.onhashchange? Note that IE8 running in
  1170. // IE7 compatibility mode reports true for 'onhashchange' in window, even
  1171. // though the event isn't supported, so also test document.documentMode.
  1172. doc_mode = doc.documentMode,
  1173. supports_onhashchange = 'on' + str_hashchange in window && ( doc_mode === undefined || doc_mode > 7 );
  1174. // Get location.hash (or what you'd expect location.hash to be) sans any
  1175. // leading #. Thanks for making this necessary, Firefox!
  1176. function get_fragment( url ) {
  1177. url = url || location.href;
  1178. return '#' + url.replace( /^[^#]*#?(.*)$/, '$1' );
  1179. };
  1180. // Method: jQuery.fn.hashchange
  1181. //
  1182. // Bind a handler to the window.onhashchange event or trigger all bound
  1183. // window.onhashchange event handlers. This behavior is consistent with
  1184. // jQuery's built-in event handlers.
  1185. //
  1186. // Usage:
  1187. //
  1188. // > jQuery(window).hashchange( [ handler ] );
  1189. //
  1190. // Arguments:
  1191. //
  1192. // handler - (Function) Optional handler to be bound to the hashchange
  1193. // event. This is a "shortcut" for the more verbose form:
  1194. // jQuery(window).bind( 'hashchange', handler ). If handler is omitted,
  1195. // all bound window.onhashchange event handlers will be triggered. This
  1196. // is a shortcut for the more verbose
  1197. // jQuery(window).trigger( 'hashchange' ). These forms are described in
  1198. // the <hashchange event> section.
  1199. //
  1200. // Returns:
  1201. //
  1202. // (jQuery) The initial jQuery collection of elements.
  1203. // Allow the "shortcut" format $(elem).hashchange( fn ) for binding and
  1204. // $(elem).hashchange() for triggering, like jQuery does for built-in events.
  1205. $.fn[ str_hashchange ] = function( fn ) {
  1206. return fn ? this.bind( str_hashchange, fn ) : this.trigger( str_hashchange );
  1207. };
  1208. // Property: jQuery.fn.hashchange.delay
  1209. //
  1210. // The numeric interval (in milliseconds) at which the <hashchange event>
  1211. // polling loop executes. Defaults to 50.
  1212. // Property: jQuery.fn.hashchange.domain
  1213. //
  1214. // If you're setting document.domain in your JavaScript, and you want hash
  1215. // history to work in IE6/7, not only must this property be set, but you must
  1216. // also set document.domain BEFORE jQuery is loaded into the page. This
  1217. // property is only applicable if you are supporting IE6/7 (or IE8 operating
  1218. // in "IE7 compatibility" mode).
  1219. //
  1220. // In addition, the <jQuery.fn.hashchange.src> property must be set to the
  1221. // path of the included "document-domain.html" file, which can be renamed or
  1222. // modified if necessary (note that the document.domain specified must be the
  1223. // same in both your main JavaScript as well as in this file).
  1224. //
  1225. // Usage:
  1226. //
  1227. // jQuery.fn.hashchange.domain = document.domain;
  1228. // Property: jQuery.fn.hashchange.src
  1229. //
  1230. // If, for some reason, you need to specify an Iframe src file (for example,
  1231. // when setting document.domain as in <jQuery.fn.hashchange.domain>), you can
  1232. // do so using this property. Note that when using this property, history
  1233. // won't be recorded in IE6/7 until the Iframe src file loads. This property
  1234. // is only applicable if you are supporting IE6/7 (or IE8 operating in "IE7
  1235. // compatibility" mode).
  1236. //
  1237. // Usage:
  1238. //
  1239. // jQuery.fn.hashchange.src = 'path/to/file.html';
  1240. $.fn[ str_hashchange ].delay = 50;
  1241. /*
  1242. $.fn[ str_hashchange ].domain = null;
  1243. $.fn[ str_hashchange ].src = null;
  1244. */
  1245. // Event: hashchange event
  1246. //
  1247. // Fired when location.hash changes. In browsers that support it, the native
  1248. // HTML5 window.onhashchange event is used, otherwise a polling loop is
  1249. // initialized, running every <jQuery.fn.hashchange.delay> milliseconds to
  1250. // see if the hash has changed. In IE6/7 (and IE8 operating in "IE7
  1251. // compatibility" mode), a hidden Iframe is created to allow the back button
  1252. // and hash-based history to work.
  1253. //
  1254. // Usage as described in <jQuery.fn.hashchange>:
  1255. //
  1256. // > // Bind an event handler.
  1257. // > jQuery(window).hashchange( function(e) {
  1258. // > var hash = location.hash;
  1259. // > ...
  1260. // > });
  1261. // >
  1262. // > // Manually trigger the event handler.
  1263. // > jQuery(window).hashchange();
  1264. //
  1265. // A more verbose usage that allows for event namespacing:
  1266. //
  1267. // > // Bind an event handler.
  1268. // > jQuery(window).bind( 'hashchange', function(e) {
  1269. // > var hash = location.hash;
  1270. // > ...
  1271. // > });
  1272. // >
  1273. // > // Manually trigger the event handler.
  1274. // > jQuery(window).trigger( 'hashchange' );
  1275. //
  1276. // Additional Notes:
  1277. //
  1278. // * The polling loop and Iframe are not created until at least one handler
  1279. // is actually bound to the 'hashchange' event.
  1280. // * If you need the bound handler(s) to execute immediately, in cases where
  1281. // a location.hash exists on page load, via bookmark or page refresh for
  1282. // example, use jQuery(window).hashchange() or the more verbose
  1283. // jQuery(window).trigger( 'hashchange' ).
  1284. // * The event can be bound before DOM ready, but since it won't be usable
  1285. // before then in IE6/7 (due to the necessary Iframe), recommended usage is
  1286. // to bind it inside a DOM ready handler.
  1287. // Override existing $.event.special.hashchange methods (allowing this plugin
  1288. // to be defined after jQuery BBQ in BBQ's source code).
  1289. special[ str_hashchange ] = $.extend( special[ str_hashchange ], {
  1290. // Called only when the first 'hashchange' event is bound to window.
  1291. setup: function() {
  1292. // If window.onhashchange is supported natively, there's nothing to do..
  1293. if ( supports_onhashchange ) { return false; }
  1294. // Otherwise, we need to create our own. And we don't want to call this
  1295. // until the user binds to the event, just in case they never do, since it
  1296. // will create a polling loop and possibly even a hidden Iframe.
  1297. $( fake_onhashchange.start );
  1298. },
  1299. // Called only when the last 'hashchange' event is unbound from window.
  1300. teardown: function() {
  1301. // If window.onhashchange is supported natively, there's nothing to do..
  1302. if ( supports_onhashchange ) { return false; }
  1303. // Otherwise, we need to stop ours (if possible).
  1304. $( fake_onhashchange.stop );
  1305. }
  1306. });
  1307. // fake_onhashchange does all the work of triggering the window.onhashchange
  1308. // event for browsers that don't natively support it, including creating a
  1309. // polling loop to watch for hash changes and in IE 6/7 creating a hidden
  1310. // Iframe to enable back and forward.
  1311. fake_onhashchange = (function(){
  1312. var self = {},
  1313. timeout_id,
  1314. // Remember the initial hash so it doesn't get triggered immediately.
  1315. last_hash = get_fragment(),
  1316. fn_retval = function(val){ return val; },
  1317. history_set = fn_retval,
  1318. history_get = fn_retval;
  1319. // Start the polling loop.
  1320. self.start = function() {
  1321. timeout_id || poll();
  1322. };
  1323. // Stop the polling loop.
  1324. self.stop = function() {
  1325. timeout_id && clearTimeout( timeout_id );
  1326. timeout_id = undefined;
  1327. };
  1328. // This polling loop checks every $.fn.hashchange.delay milliseconds to see
  1329. // if location.hash has changed, and triggers the 'hashchange' event on
  1330. // window when necessary.
  1331. function poll() {
  1332. var hash = get_fragment(),
  1333. history_hash = history_get( last_hash );
  1334. if ( hash !== last_hash ) {
  1335. history_set( last_hash = hash, history_hash );
  1336. $(window).trigger( str_hashchange );
  1337. } else if ( history_hash !== last_hash ) {
  1338. location.href = location.href.replace( /#.*/, '' ) + history_hash;
  1339. }
  1340. timeout_id = setTimeout( poll, $.fn[ str_hashchange ].delay );
  1341. };
  1342. // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  1343. // vvvvvvvvvvvvvvvvvvv REMOVE IF NOT SUPPORTING IE6/7/8 vvvvvvvvvvvvvvvvvvv
  1344. // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  1345. $.browser.msie && !supports_onhashchange && (function(){
  1346. // Not only do IE6/7 need the "magical" Iframe treatment, but so does IE8
  1347. // when running in "IE7 compatibility" mode.
  1348. var iframe,
  1349. iframe_src;
  1350. // When the event is bound and polling starts in IE 6/7, create a hidden
  1351. // Iframe for history handling.
  1352. self.start = function(){
  1353. if ( !iframe ) {
  1354. iframe_src = $.fn[ str_hashchange ].src;
  1355. iframe_src = iframe_src && iframe_src + get_fragment();
  1356. // Create hidden Iframe. Attempt to make Iframe as hidden as possible
  1357. // by using techniques from http://www.paciellogroup.com/blog/?p=604.
  1358. iframe = $('<iframe tabindex="-1" title="empty"/>').hide()
  1359. // When Iframe has completely loaded, initialize the history and
  1360. // start polling.
  1361. .one( 'load', function(){
  1362. iframe_src || history_set( get_fragment() );
  1363. poll();
  1364. })
  1365. // Load Iframe src if specified, otherwise nothing.
  1366. .attr( 'src', iframe_src || 'javascript:0' )
  1367. // Append Iframe after the end of the body to prevent unnecessary
  1368. // initial page scrolling (yes, this works).
  1369. .insertAfter( 'body' )[0].contentWindow;
  1370. // Whenever `document.title` changes, update the Iframe's title to
  1371. // prettify the back/next history menu entries. Since IE sometimes
  1372. // errors with "Unspecified error" the very first time this is set
  1373. // (yes, very useful) wrap this with a try/catch block.
  1374. doc.onpropertychange = function(){
  1375. try {
  1376. if ( event.propertyName === 'title' ) {
  1377. iframe.document.title = doc.title;
  1378. }
  1379. } catch(e) {}
  1380. };
  1381. }
  1382. };
  1383. // Override the "stop" method since an IE6/7 Iframe was created. Even
  1384. // if there are no longer any bound event handlers, the polling loop
  1385. // is still necessary for back/next to work at all!
  1386. self.stop = fn_retval;
  1387. // Get history by looking at the hidden Iframe's location.hash.
  1388. history_get = function() {
  1389. return get_fragment( iframe.location.href );
  1390. };
  1391. // Set a new history item by opening and then closing the Iframe
  1392. // document, *then* setting its location.hash. If document.domain has
  1393. // been set, update that as well.
  1394. history_set = function( hash, history_hash ) {
  1395. var iframe_doc = iframe.document,
  1396. domain = $.fn[ str_hashchange ].domain;
  1397. if ( hash !== history_hash ) {
  1398. // Update Iframe with any initial `document.title` that might be set.
  1399. iframe_doc.title = doc.title;
  1400. // Opening the Iframe's document after it has been closed is what
  1401. // actually adds a history entry.
  1402. iframe_doc.open();
  1403. // Set document.domain for the Iframe document as well, if necessary.
  1404. domain && iframe_doc.write( '<script>document.domain="' + domain + '"</script>' );
  1405. iframe_doc.close();
  1406. // Update the Iframe's hash, for great justice.
  1407. iframe.location.hash = hash;
  1408. }
  1409. };
  1410. })();
  1411. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1412. // ^^^^^^^^^^^^^^^^^^^ REMOVE IF NOT SUPPORTING IE6/7/8 ^^^^^^^^^^^^^^^^^^^
  1413. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1414. return self;
  1415. })();
  1416. })(jQuery,this);
  1417. /*
  1418. * "page" plugin
  1419. */
  1420. (function( $, undefined ) {
  1421. $.widget( "mobile.page", $.mobile.widget, {
  1422. options: {
  1423. theme: "c",
  1424. domCache: false,
  1425. keepNativeDefault: ":jqmData(role='none'), :jqmData(role='nojs')"
  1426. },
  1427. _create: function() {
  1428. this._trigger( "beforecreate" );
  1429. this.element
  1430. .attr( "tabindex", "0" )
  1431. .addClass( "ui-page ui-body-" + this.options.theme );
  1432. },
  1433. keepNativeSelector: function() {
  1434. var options = this.options,
  1435. keepNativeDefined = options.keepNative && $.trim(options.keepNative);
  1436. if( keepNativeDefined && options.keepNative !== options.keepNativeDefault ){
  1437. return [options.keepNative, options.keepNativeDefault].join(", ");
  1438. }
  1439. return options.keepNativeDefault;
  1440. }
  1441. });
  1442. })( jQuery );
  1443. /*
  1444. * "core" - The base file for jQm
  1445. */
  1446. (function( $, window, undefined ) {
  1447. var nsNormalizeDict = {};
  1448. // jQuery.mobile configurable options
  1449. $.extend( $.mobile, {
  1450. // Namespace used framework-wide for data-attrs. Default is no namespace
  1451. ns: "",
  1452. // Define the url parameter used for referencing widget-generated sub-pages.
  1453. // Translates to to example.html&ui-page=subpageIdentifier
  1454. // hash segment before &ui-page= is used to make Ajax request
  1455. subPageUrlKey: "ui-page",
  1456. // Class assigned to page currently in view, and during transitions
  1457. activePageClass: "ui-page-active",
  1458. // Class used for "active" button state, from CSS framework
  1459. activeBtnClass: "ui-btn-active",
  1460. // Automatically handle clicks and form submissions through Ajax, when same-domain
  1461. ajaxEnabled: true,
  1462. // Automatically load and show pages based on location.hash
  1463. hashListeningEnabled: true,
  1464. // disable to prevent jquery from bothering with links
  1465. linkBindingEnabled: true,
  1466. // Set default page transition - 'none' for no transitions
  1467. defaultPageTransition: "slide",
  1468. // Minimum scroll distance that will be remembered when returning to a page
  1469. minScrollBack: 250,
  1470. // Set default dialog transition - 'none' for no transitions
  1471. defaultDialogTransition: "pop",
  1472. // Show loading message during Ajax requests
  1473. // if false, message will not appear, but loading classes will still be toggled on html el
  1474. loadingMessage: "loading",
  1475. // Error response message - appears when an Ajax page request fails
  1476. pageLoadErrorMessage: "Error Loading Page",
  1477. //automatically initialize the DOM when it's ready
  1478. autoInitializePage: true,
  1479. pushStateEnabled: true,
  1480. // turn of binding to the native orientationchange due to android orientation behavior
  1481. orientationChangeEnabled: true,
  1482. // Support conditions that must be met in order to proceed
  1483. // default enhanced qualifications are media query support OR IE 7+
  1484. gradeA: function(){
  1485. return $.support.mediaquery || $.mobile.browser.ie && $.mobile.browser.ie >= 7;
  1486. },
  1487. // TODO might be useful upstream in jquery itself ?
  1488. keyCode: {
  1489. ALT: 18,
  1490. BACKSPACE: 8,
  1491. CAPS_LOCK: 20,
  1492. COMMA: 188,
  1493. COMMAND: 91,
  1494. COMMAND_LEFT: 91, // COMMAND
  1495. COMMAND_RIGHT: 93,
  1496. CONTROL: 17,
  1497. DELETE: 46,
  1498. DOWN: 40,
  1499. END: 35,
  1500. ENTER: 13,
  1501. ESCAPE: 27,
  1502. HOME: 36,
  1503. INSERT: 45,
  1504. LEFT: 37,
  1505. MENU: 93, // COMMAND_RIGHT
  1506. NUMPAD_ADD: 107,
  1507. NUMPAD_DECIMAL: 110,
  1508. NUMPAD_DIVIDE: 111,
  1509. NUMPAD_ENTER: 108,
  1510. NUMPAD_MULTIPLY: 106,
  1511. NUMPAD_SUBTRACT: 109,
  1512. PAGE_DOWN: 34,
  1513. PAGE_UP: 33,
  1514. PERIOD: 190,
  1515. RIGHT: 39,
  1516. SHIFT: 16,
  1517. SPACE: 32,
  1518. TAB: 9,
  1519. UP: 38,
  1520. WINDOWS: 91 // COMMAND
  1521. },
  1522. // Scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
  1523. silentScroll: function( ypos ) {
  1524. if ( $.type( ypos ) !== "number" ) {
  1525. ypos = $.mobile.defaultHomeScroll;
  1526. }
  1527. // prevent scrollstart and scrollstop events
  1528. $.event.special.scrollstart.enabled = false;
  1529. setTimeout(function() {
  1530. window.scrollTo( 0, ypos );
  1531. $( document ).trigger( "silentscroll", { x: 0, y: ypos });
  1532. }, 20 );
  1533. setTimeout(function() {
  1534. $.event.special.scrollstart.enabled = true;
  1535. }, 150 );
  1536. },
  1537. // Expose our cache for testing purposes.
  1538. nsNormalizeDict: nsNormalizeDict,
  1539. // Take a data attribute property, prepend the namespace
  1540. // and then camel case the attribute string. Add the result
  1541. // to our nsNormalizeDict so we don't have to do this again.
  1542. nsNormalize: function( prop ) {
  1543. if ( !prop ) {
  1544. return;
  1545. }
  1546. return nsNormalizeDict[ prop ] || ( nsNormalizeDict[ prop ] = $.camelCase( $.mobile.ns + prop ) );
  1547. },
  1548. getInheritedTheme: function( el, defaultTheme ) {
  1549. // Find the closest parent with a theme class on it. Note that
  1550. // we are not using $.fn.closest() on purpose here because this
  1551. // method gets called quite a bit and we need it to be as fast
  1552. // as possible.
  1553. var e = el[ 0 ],
  1554. ltr = "",
  1555. re = /ui-(bar|body)-([a-z])\b/,
  1556. c, m;
  1557. while ( e ) {
  1558. var c = e.className || "";
  1559. if ( ( m = re.exec( c ) ) && ( ltr = m[ 2 ] ) ) {
  1560. // We found a parent with a theme class
  1561. // on it so bail from this loop.
  1562. break;
  1563. }
  1564. e = e.parentNode;
  1565. }
  1566. // Return the theme letter we found, if none, return the
  1567. // specified default.
  1568. return ltr || defaultTheme || "a";
  1569. },
  1570. // TODO the following $ and $.fn extensions can/probably should be moved into jquery.mobile.core.helpers
  1571. //
  1572. // Find the closest javascript page element to gather settings data jsperf test
  1573. // http://jsperf.com/single-complex-selector-vs-many-complex-selectors/edit
  1574. // possibly naive, but it shows that the parsing overhead for *just* the page selector vs
  1575. // the page and dialog selector is negligable. This could probably be speed up by
  1576. // doing a similar parent node traversal to the one found in the inherited theme code above
  1577. closestPageData: function( $target ) {
  1578. return $target
  1579. .closest(':jqmData(role="page"), :jqmData(role="dialog")')
  1580. .data("page");
  1581. }
  1582. });
  1583. // Mobile version of data and removeData and hasData methods
  1584. // ensures all data is set and retrieved using jQuery Mobile's data namespace
  1585. $.fn.jqmData = function( prop, value ) {
  1586. var result;
  1587. if ( typeof prop != "undefined" ) {
  1588. result = this.data( prop ? $.mobile.nsNormalize( prop ) : prop, value );
  1589. }
  1590. return result;
  1591. };
  1592. $.jqmData = function( elem, prop, value ) {
  1593. var result;
  1594. if ( typeof prop != "undefined" ) {
  1595. result = $.data( elem, prop ? $.mobile.nsNormalize( prop ) : prop, value );
  1596. }
  1597. return result;
  1598. };
  1599. $.fn.jqmRemoveData = function( prop ) {
  1600. return this.removeData( $.mobile.nsNormalize( prop ) );
  1601. };
  1602. $.jqmRemoveData = function( elem, prop ) {
  1603. return $.removeData( elem, $.mobile.nsNormalize( prop ) );
  1604. };
  1605. $.fn.removeWithDependents = function() {
  1606. $.removeWithDependents( this );
  1607. };
  1608. $.removeWithDependents = function( elem ) {
  1609. var $elem = $( elem );
  1610. ( $elem.jqmData('dependents') || $() ).remove();
  1611. $elem.remove();
  1612. };
  1613. $.fn.addDependents = function( newDependents ) {
  1614. $.addDependents( $(this), newDependents );
  1615. };
  1616. $.addDependents = function( elem, newDependents ) {
  1617. var dependents = $(elem).jqmData( 'dependents' ) || $();
  1618. $(elem).jqmData( 'dependents', $.merge(dependents, newDependents) );
  1619. };
  1620. // note that this helper doesn't attempt to handle the callback
  1621. // or setting of an html elements text, its only purpose is
  1622. // to return the html encoded version of the text in all cases. (thus the name)
  1623. $.fn.getEncodedText = function() {
  1624. return $( "<div/>" ).text( $(this).text() ).html();
  1625. };
  1626. // Monkey-patching Sizzle to filter the :jqmData selector
  1627. var oldFind = $.find,
  1628. jqmDataRE = /:jqmData\(([^)]*)\)/g;
  1629. $.find = function( selector, context, ret, extra ) {
  1630. selector = selector.replace( jqmDataRE, "[data-" + ( $.mobile.ns || "" ) + "$1]" );
  1631. return oldFind.call( this, selector, context, ret, extra );
  1632. };
  1633. $.extend( $.find, oldFind );
  1634. $.find.matches = function( expr, set ) {
  1635. return $.find( expr, null, null, set );
  1636. };
  1637. $.find.matchesSelector = function( node, expr ) {
  1638. return $.find( expr, null, null, [ node ] ).length > 0;
  1639. };
  1640. })( jQuery, this );
  1641. /*
  1642. * core utilities for auto ajax navigation, base tag mgmt,
  1643. */
  1644. ( function( $, undefined ) {
  1645. //define vars for interal use
  1646. var $window = $( window ),
  1647. $html = $( 'html' ),
  1648. $head = $( 'head' ),
  1649. //url path helpers for use in relative url management
  1650. path = {
  1651. // This scary looking regular expression parses an absolute URL or its relative
  1652. // variants (protocol, site, document, query, and hash), into the various
  1653. // components (protocol, host, path, query, fragment, etc that make up the
  1654. // URL as well as some other commonly used sub-parts. When used with RegExp.exec()
  1655. // or String.match, it parses the URL into a results array that looks like this:
  1656. //
  1657. // [0]: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content
  1658. // [1]: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread
  1659. // [2]: http://jblas:password@mycompany.com:8080/mail/inbox
  1660. // [3]: http://jblas:password@mycompany.com:8080
  1661. // [4]: http:
  1662. // [5]: //
  1663. // [6]: jblas:password@mycompany.com:8080
  1664. // [7]: jblas:password
  1665. // [8]: jblas
  1666. // [9]: password
  1667. // [10]: mycompany.com:8080
  1668. // [11]: mycompany.com
  1669. // [12]: 8080
  1670. // [13]: /mail/inbox
  1671. // [14]: /mail/
  1672. // [15]: inbox
  1673. // [16]: ?msg=1234&type=unread
  1674. // [17]: #msg-content
  1675. //
  1676. urlParseRE: /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/,
  1677. //Parse a URL into a structure that allows easy access to
  1678. //all of the URL components by name.
  1679. parseUrl: function( url ) {
  1680. // If we're passed an object, we'll assume that it is
  1681. // a parsed url object and just return it back to the caller.
  1682. if ( $.type( url ) === "object" ) {
  1683. return url;
  1684. }
  1685. var matches = path.urlParseRE.exec( url || "" ) || [];
  1686. // Create an object that allows the caller to access the sub-matches
  1687. // by name. Note that IE returns an empty string instead of undefined,
  1688. // like all other browsers do, so we normalize everything so its consistent
  1689. // no matter what browser we're running on.
  1690. return {
  1691. href: matches[ 0 ] || "",
  1692. hrefNoHash: matches[ 1 ] || "",
  1693. hrefNoSearch: matches[ 2 ] || "",
  1694. domain: matches[ 3 ] || "",
  1695. protocol: matches[ 4 ] || "",
  1696. doubleSlash: matches[ 5 ] || "",
  1697. authority: matches[ 6 ] || "",
  1698. username: matches[ 8 ] || "",
  1699. password: matches[ 9 ] || "",
  1700. host: matches[ 10 ] || "",
  1701. hostname: matches[ 11 ] || "",
  1702. port: matches[ 12 ] || "",
  1703. pathname: matches[ 13 ] || "",
  1704. directory: matches[ 14 ] || "",
  1705. filename: matches[ 15 ] || "",
  1706. search: matches[ 16 ] || "",
  1707. hash: matches[ 17 ] || ""
  1708. };
  1709. },
  1710. //Turn relPath into an asbolute path. absPath is
  1711. //an optional absolute path which describes what
  1712. //relPath is relative to.
  1713. makePathAbsolute: function( relPath, absPath ) {
  1714. if ( relPath && relPath.charAt( 0 ) === "/" ) {
  1715. return relPath;
  1716. }
  1717. relPath = relPath || "";
  1718. absPath = absPath ? absPath.replace( /^\/|(\/[^\/]*|[^\/]+)$/g, "" ) : "";
  1719. var absStack = absPath ? absPath.split( "/" ) : [],
  1720. relStack = relPath.split( "/" );
  1721. for ( var i = 0; i < relStack.length; i++ ) {
  1722. var d = relStack[ i ];
  1723. switch ( d ) {
  1724. case ".":
  1725. break;
  1726. case "..":
  1727. if ( absStack.length ) {
  1728. absStack.pop();
  1729. }
  1730. break;
  1731. default:
  1732. absStack.push( d );
  1733. break;
  1734. }
  1735. }
  1736. return "/" + absStack.join( "/" );
  1737. },
  1738. //Returns true if both urls have the same domain.
  1739. isSameDomain: function( absUrl1, absUrl2 ) {
  1740. return path.parseUrl( absUrl1 ).domain === path.parseUrl( absUrl2 ).domain;
  1741. },
  1742. //Returns true for any relative variant.
  1743. isRelativeUrl: function( url ) {
  1744. // All relative Url variants have one thing in common, no protocol.
  1745. return path.parseUrl( url ).protocol === "";
  1746. },
  1747. //Returns true for an absolute url.
  1748. isAbsoluteUrl: function( url ) {
  1749. return path.parseUrl( url ).protocol !== "";
  1750. },
  1751. //Turn the specified realtive URL into an absolute one. This function
  1752. //can handle all relative variants (protocol, site, document, query, fragment).
  1753. makeUrlAbsolute: function( relUrl, absUrl ) {
  1754. if ( !path.isRelativeUrl( relUrl ) ) {
  1755. return relUrl;
  1756. }
  1757. var relObj = path.parseUrl( relUrl ),
  1758. absObj = path.parseUrl( absUrl ),
  1759. protocol = relObj.protocol || absObj.protocol,
  1760. doubleSlash = relObj.protocol ? relObj.doubleSlash : ( relObj.doubleSlash || absObj.doubleSlash ),
  1761. authority = relObj.authority || absObj.authority,
  1762. hasPath = relObj.pathname !== "",
  1763. pathname = path.makePathAbsolute( relObj.pathname || absObj.filename, absObj.pathname ),
  1764. search = relObj.search || ( !hasPath && absObj.search ) || "",
  1765. hash = relObj.hash;
  1766. return protocol + doubleSlash + authority + pathname + search + hash;
  1767. },
  1768. //Add search (aka query) params to the specified url.
  1769. addSearchParams: function( url, params ) {
  1770. var u = path.parseUrl( url ),
  1771. p = ( typeof params === "object" ) ? $.param( params ) : params,
  1772. s = u.search || "?";
  1773. return u.hrefNoSearch + s + ( s.charAt( s.length - 1 ) !== "?" ? "&" : "" ) + p + ( u.hash || "" );
  1774. },
  1775. convertUrlToDataUrl: function( absUrl ) {
  1776. var u = path.parseUrl( absUrl );
  1777. if ( path.isEmbeddedPage( u ) ) {
  1778. // For embedded pages, remove the dialog hash key as in getFilePath(),
  1779. // otherwise the Data Url won't match the id of the embedded Page.
  1780. return u.hash.split( dialogHashKey )[0].replace( /^#/, "" );
  1781. } else if ( path.isSameDomain( u, documentBase ) ) {
  1782. return u.hrefNoHash.replace( documentBase.domain, "" );
  1783. }
  1784. return absUrl;
  1785. },
  1786. //get path from current hash, or from a file path
  1787. get: function( newPath ) {
  1788. if( newPath === undefined ) {
  1789. newPath = location.hash;
  1790. }
  1791. return path.stripHash( newPath ).replace( /[^\/]*\.[^\/*]+$/, '' );
  1792. },
  1793. //return the substring of a filepath before the sub-page key, for making a server request
  1794. getFilePath: function( path ) {
  1795. var splitkey = '&' + $.mobile.subPageUrlKey;
  1796. return path && path.split( splitkey )[0].split( dialogHashKey )[0];
  1797. },
  1798. //set location hash to path
  1799. set: function( path ) {
  1800. location.hash = path;
  1801. },
  1802. //test if a given url (string) is a path
  1803. //NOTE might be exceptionally naive
  1804. isPath: function( url ) {
  1805. return ( /\// ).test( url );
  1806. },
  1807. //return a url path with the window's location protocol/hostname/pathname removed
  1808. clean: function( url ) {
  1809. return url.replace( documentBase.domain, "" );
  1810. },
  1811. //just return the url without an initial #
  1812. stripHash: function( url ) {
  1813. return url.replace( /^#/, "" );
  1814. },
  1815. //remove the preceding hash, any query params, and dialog notations
  1816. cleanHash: function( hash ) {
  1817. return path.stripHash( hash.replace( /\?.*$/, "" ).replace( dialogHashKey, "" ) );
  1818. },
  1819. //check whether a url is referencing the same domain, or an external domain or different protocol
  1820. //could be mailto, etc
  1821. isExternal: function( url ) {
  1822. var u = path.parseUrl( url );
  1823. return u.protocol && u.domain !== documentUrl.domain ? true : false;
  1824. },
  1825. hasProtocol: function( url ) {
  1826. return ( /^(:?\w+:)/ ).test( url );
  1827. },
  1828. //check if the specified url refers to the first page in the main application document.
  1829. isFirstPageUrl: function( url ) {
  1830. // We only deal with absolute paths.
  1831. var u = path.parseUrl( path.makeUrlAbsolute( url, documentBase ) ),
  1832. // Does the url have the same path as the document?
  1833. samePath = u.hrefNoHash === documentUrl.hrefNoHash || ( documentBaseDiffers && u.hrefNoHash === documentBase.hrefNoHash ),
  1834. // Get the first page element.
  1835. fp = $.mobile.firstPage,
  1836. // Get the id of the first page element if it has one.
  1837. fpId = fp && fp[0] ? fp[0].id : undefined;
  1838. // The url refers to the first page if the path matches the document and
  1839. // it either has no hash value, or the hash is exactly equal to the id of the
  1840. // first page element.
  1841. return samePath && ( !u.hash || u.hash === "#" || ( fpId && u.hash.replace( /^#/, "" ) === fpId ) );
  1842. },
  1843. isEmbeddedPage: function( url ) {
  1844. var u = path.parseUrl( url );
  1845. //if the path is absolute, then we need to compare the url against
  1846. //both the documentUrl and the documentBase. The main reason for this
  1847. //is that links embedded within external documents will refer to the
  1848. //application document, whereas links embedded within the application
  1849. //document will be resolved against the document base.
  1850. if ( u.protocol !== "" ) {
  1851. return ( u.hash && ( u.hrefNoHash === documentUrl.hrefNoHash || ( documentBaseDiffers && u.hrefNoHash === documentBase.hrefNoHash ) ) );
  1852. }
  1853. return (/^#/).test( u.href );
  1854. },
  1855. // Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR
  1856. // requests if the document doing the request was loaded via the file:// protocol.
  1857. // This is usually to allow the application to "phone home" and fetch app specific
  1858. // data. We normally let the browser handle external/cross-domain urls, but if the
  1859. // allowCrossDomainPages option is true, we will allow cross-domain http/https
  1860. // requests to go through our page loading logic.
  1861. isPermittedCrossDomainRequest: function( docUrl, reqUrl ) {
  1862. return $.mobile.allowCrossDomainPages
  1863. && docUrl.protocol === "file:"
  1864. && reqUrl.search( /^https?:/ ) != -1;
  1865. }
  1866. },
  1867. //will be defined when a link is clicked and given an active class
  1868. $activeClickedLink = null,
  1869. //urlHistory is purely here to make guesses at whether the back or forward button was clicked
  1870. //and provide an appropriate transition
  1871. urlHistory = {
  1872. // Array of pages that are visited during a single page load.
  1873. // Each has a url and optional transition, title, and pageUrl (which represents the file path, in cases where URL is obscured, such as dialogs)
  1874. stack: [],
  1875. //maintain an index number for the active page in the stack
  1876. activeIndex: 0,
  1877. //get active
  1878. getActive: function() {
  1879. return urlHistory.stack[ urlHistory.activeIndex ];
  1880. },
  1881. getPrev: function() {
  1882. return urlHistory.stack[ urlHistory.activeIndex - 1 ];
  1883. },
  1884. getNext: function() {
  1885. return urlHistory.stack[ urlHistory.activeIndex + 1 ];
  1886. },
  1887. // addNew is used whenever a new page is added
  1888. addNew: function( url, transition, title, pageUrl, role ) {
  1889. //if there's forward history, wipe it
  1890. if( urlHistory.getNext() ) {
  1891. urlHistory.clearForward();
  1892. }
  1893. urlHistory.stack.push( {url : url, transition: transition, title: title, pageUrl: pageUrl, role: role } );
  1894. urlHistory.activeIndex = urlHistory.stack.length - 1;
  1895. },
  1896. //wipe urls ahead of active index
  1897. clearForward: function() {
  1898. urlHistory.stack = urlHistory.stack.slice( 0, urlHistory.activeIndex + 1 );
  1899. },
  1900. directHashChange: function( opts ) {
  1901. var back , forward, newActiveIndex, prev = this.getActive();
  1902. // check if url isp in history and if it's ahead or behind current page
  1903. $.each( urlHistory.stack, function( i, historyEntry ) {
  1904. //if the url is in the stack, it's a forward or a back
  1905. if( opts.currentUrl === historyEntry.url ) {
  1906. //define back and forward by whether url is older or newer than current page
  1907. back = i < urlHistory.activeIndex;
  1908. forward = !back;
  1909. newActiveIndex = i;
  1910. }
  1911. });
  1912. // save new page index, null check to prevent falsey 0 result
  1913. this.activeIndex = newActiveIndex !== undefined ? newActiveIndex : this.activeIndex;
  1914. if( back ) {
  1915. ( opts.either || opts.isBack )( true );
  1916. } else if( forward ) {
  1917. ( opts.either || opts.isForward )( false );
  1918. }
  1919. },
  1920. //disable hashchange event listener internally to ignore one change
  1921. //toggled internally when location.hash is updated to match the url of a successful page load
  1922. ignoreNextHashChange: false
  1923. },
  1924. //define first selector to receive focus when a page is shown
  1925. focusable = "[tabindex],a,button:visible,select:visible,input",
  1926. //queue to hold simultanious page transitions
  1927. pageTransitionQueue = [],
  1928. //indicates whether or not page is in process of transitioning
  1929. isPageTransitioning = false,
  1930. //nonsense hash change key for dialogs, so they create a history entry
  1931. dialogHashKey = "&ui-state=dialog",
  1932. //existing base tag?
  1933. $base = $head.children( "base" ),
  1934. //tuck away the original document URL minus any fragment.
  1935. documentUrl = path.parseUrl( location.href ),
  1936. //if the document has an embedded base tag, documentBase is set to its
  1937. //initial value. If a base tag does not exist, then we default to the documentUrl.
  1938. documentBase = $base.length ? path.parseUrl( path.makeUrlAbsolute( $base.attr( "href" ), documentUrl.href ) ) : documentUrl,
  1939. //cache the comparison once.
  1940. documentBaseDiffers = ( documentUrl.hrefNoHash !== documentBase.hrefNoHash );
  1941. //base element management, defined depending on dynamic base tag support
  1942. var base = $.support.dynamicBaseTag ? {
  1943. //define base element, for use in routing asset urls that are referenced in Ajax-requested markup
  1944. element: ( $base.length ? $base : $( "<base>", { href: documentBase.hrefNoHash } ).prependTo( $head ) ),
  1945. //set the generated BASE element's href attribute to a new page's base path
  1946. set: function( href ) {
  1947. base.element.attr( "href", path.makeUrlAbsolute( href, documentBase ) );
  1948. },
  1949. //set the generated BASE element's href attribute to a new page's base path
  1950. reset: function() {
  1951. base.element.attr( "href", documentBase.hrefNoHash );
  1952. }
  1953. } : undefined;
  1954. /*
  1955. internal utility functions
  1956. --------------------------------------*/
  1957. //direct focus to the page title, or otherwise first focusable element
  1958. function reFocus( page ) {
  1959. var pageTitle = page.find( ".ui-title:eq(0)" );
  1960. if( pageTitle.length ) {
  1961. pageTitle.focus();
  1962. }
  1963. else{
  1964. page.focus();
  1965. }
  1966. }
  1967. //remove active classes after page transition or error
  1968. function removeActiveLinkClass( forceRemoval ) {
  1969. if( !!$activeClickedLink && ( !$activeClickedLink.closest( '.ui-page-active' ).length || forceRemoval ) ) {
  1970. $activeClickedLink.removeClass( $.mobile.activeBtnClass );
  1971. }
  1972. $activeClickedLink = null;
  1973. }
  1974. function releasePageTransitionLock() {
  1975. isPageTransitioning = false;
  1976. if( pageTransitionQueue.length > 0 ) {
  1977. $.mobile.changePage.apply( null, pageTransitionQueue.pop() );
  1978. }
  1979. }
  1980. // Save the last scroll distance per page, before it is hidden
  1981. var setLastScrollEnabled = true,
  1982. firstScrollElem, getScrollElem, setLastScroll, delayedSetLastScroll;
  1983. getScrollElem = function() {
  1984. var scrollElem = $window, activePage,
  1985. touchOverflow = $.support.touchOverflow && $.mobile.touchOverflowEnabled;
  1986. if( touchOverflow ){
  1987. activePage = $( ".ui-page-active" );
  1988. scrollElem = activePage.is( ".ui-native-fixed" ) ? activePage.find( ".ui-content" ) : activePage;
  1989. }
  1990. return scrollElem;
  1991. };
  1992. setLastScroll = function( scrollElem ) {
  1993. // this barrier prevents setting the scroll value based on the browser
  1994. // scrolling the window based on a hashchange
  1995. if( !setLastScrollEnabled ) {
  1996. return;
  1997. }
  1998. var active = $.mobile.urlHistory.getActive();
  1999. if( active ) {
  2000. var lastScroll = scrollElem && scrollElem.scrollTop();
  2001. // Set active page's lastScroll prop.
  2002. // If the location we're scrolling to is less than minScrollBack, let it go.
  2003. active.lastScroll = lastScroll < $.mobile.minScrollBack ? $.mobile.defaultHomeScroll : lastScroll;
  2004. }
  2005. };
  2006. // bind to scrollstop to gather scroll position. The delay allows for the hashchange
  2007. // event to fire and disable scroll recording in the case where the browser scrolls
  2008. // to the hash targets location (sometimes the top of the page). once pagechange fires
  2009. // getLastScroll is again permitted to operate
  2010. delayedSetLastScroll = function() {
  2011. setTimeout( setLastScroll, 100, $(this) );
  2012. };
  2013. // disable an scroll setting when a hashchange has been fired, this only works
  2014. // because the recording of the scroll position is delayed for 100ms after
  2015. // the browser might have changed the position because of the hashchange
  2016. $window.bind( $.support.pushState ? "popstate" : "hashchange", function() {
  2017. setLastScrollEnabled = false;
  2018. });
  2019. // handle initial hashchange from chrome :(
  2020. $window.one( $.support.pushState ? "popstate" : "hashchange", function() {
  2021. setLastScrollEnabled = true;
  2022. });
  2023. // wait until the mobile page container has been determined to bind to pagechange
  2024. $window.one( "pagecontainercreate", function(){
  2025. // once the page has changed, re-enable the scroll recording
  2026. $.mobile.pageContainer.bind( "pagechange", function() {
  2027. var scrollElem = getScrollElem();
  2028. setLastScrollEnabled = true;
  2029. // remove any binding that previously existed on the get scroll
  2030. // which may or may not be different than the scroll element determined for
  2031. // this page previously
  2032. scrollElem.unbind( "scrollstop", delayedSetLastScroll );
  2033. // determine and bind to the current scoll element which may be the window
  2034. // or in the case of touch overflow the element with touch overflow
  2035. scrollElem.bind( "scrollstop", delayedSetLastScroll );
  2036. });
  2037. });
  2038. // bind to scrollstop for the first page as "pagechange" won't be fired in that case
  2039. getScrollElem().bind( "scrollstop", delayedSetLastScroll );
  2040. // Make the iOS clock quick-scroll work again if we're using native overflow scrolling
  2041. /*
  2042. if( $.support.touchOverflow ){
  2043. if( $.mobile.touchOverflowEnabled ){
  2044. $( window ).bind( "scrollstop", function(){
  2045. if( $( this ).scrollTop() === 0 ){
  2046. $.mobile.activePage.scrollTop( 0 );
  2047. }
  2048. });
  2049. }
  2050. }
  2051. */
  2052. //function for transitioning between two existing pages
  2053. function transitionPages( toPage, fromPage, transition, reverse ) {
  2054. //get current scroll distance
  2055. var active = $.mobile.urlHistory.getActive(),
  2056. touchOverflow = $.support.touchOverflow && $.mobile.touchOverflowEnabled,
  2057. toScroll = active.lastScroll || ( touchOverflow ? 0 : $.mobile.defaultHomeScroll ),
  2058. screenHeight = getScreenHeight();
  2059. // Scroll to top, hide addr bar
  2060. window.scrollTo( 0, $.mobile.defaultHomeScroll );
  2061. if( fromPage ) {
  2062. //trigger before show/hide events
  2063. fromPage.data( "page" )._trigger( "beforehide", null, { nextPage: toPage } );
  2064. }
  2065. if( !touchOverflow){
  2066. toPage.height( screenHeight + toScroll );
  2067. }
  2068. toPage.data( "page" )._trigger( "beforeshow", null, { prevPage: fromPage || $( "" ) } );
  2069. //clear page loader
  2070. $.mobile.hidePageLoadingMsg();
  2071. if( touchOverflow && toScroll ){
  2072. toPage.addClass( "ui-mobile-pre-transition" );
  2073. // Send focus to page as it is now display: block
  2074. reFocus( toPage );
  2075. //set page's scrollTop to remembered distance
  2076. if( toPage.is( ".ui-native-fixed" ) ){
  2077. toPage.find( ".ui-content" ).scrollTop( toScroll );
  2078. }
  2079. else{
  2080. toPage.scrollTop( toScroll );
  2081. }
  2082. }
  2083. //find the transition handler for the specified transition. If there
  2084. //isn't one in our transitionHandlers dictionary, use the default one.
  2085. //call the handler immediately to kick-off the transition.
  2086. var th = $.mobile.transitionHandlers[transition || "none"] || $.mobile.defaultTransitionHandler,
  2087. promise = th( transition, reverse, toPage, fromPage );
  2088. promise.done(function() {
  2089. //reset toPage height back
  2090. if( !touchOverflow ){
  2091. toPage.height( "" );
  2092. // Send focus to the newly shown page
  2093. reFocus( toPage );
  2094. }
  2095. // Jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
  2096. if( !touchOverflow ){
  2097. $.mobile.silentScroll( toScroll );
  2098. }
  2099. //trigger show/hide events
  2100. if( fromPage ) {
  2101. if( !touchOverflow ){
  2102. fromPage.height( "" );
  2103. }
  2104. fromPage.data( "page" )._trigger( "hide", null, { nextPage: toPage } );
  2105. }
  2106. //trigger pageshow, define prevPage as either fromPage or empty jQuery obj
  2107. toPage.data( "page" )._trigger( "show", null, { prevPage: fromPage || $( "" ) } );
  2108. });
  2109. return promise;
  2110. }
  2111. //simply set the active page's minimum height to screen height, depending on orientation
  2112. function getScreenHeight(){
  2113. var orientation = $.event.special.orientationchange.orientation(),
  2114. port = orientation === "portrait",
  2115. winMin = port ? 480 : 320,
  2116. screenHeight = port ? screen.availHeight : screen.availWidth,
  2117. winHeight = Math.max( winMin, $( window ).height() ),
  2118. pageMin = Math.min( screenHeight, winHeight );
  2119. return pageMin;
  2120. }
  2121. $.mobile.getScreenHeight = getScreenHeight;
  2122. //simply set the active page's minimum height to screen height, depending on orientation
  2123. function resetActivePageHeight(){
  2124. // Don't apply this height in touch overflow enabled mode
  2125. if( $.support.touchOverflow && $.mobile.touchOverflowEnabled ){
  2126. return;
  2127. }
  2128. $( "." + $.mobile.activePageClass ).css( "min-height", getScreenHeight() );
  2129. }
  2130. //shared page enhancements
  2131. function enhancePage( $page, role ) {
  2132. // If a role was specified, make sure the data-role attribute
  2133. // on the page element is in sync.
  2134. if( role ) {
  2135. $page.attr( "data-" + $.mobile.ns + "role", role );
  2136. }
  2137. //run page plugin
  2138. $page.page();
  2139. }
  2140. /* exposed $.mobile methods */
  2141. //animation complete callback
  2142. $.fn.animationComplete = function( callback ) {
  2143. if( $.support.cssTransitions ) {
  2144. return $( this ).one( 'webkitAnimationEnd', callback );
  2145. }
  2146. else{
  2147. // defer execution for consistency between webkit/non webkit
  2148. setTimeout( callback, 0 );
  2149. return $( this );
  2150. }
  2151. };
  2152. //expose path object on $.mobile
  2153. $.mobile.path = path;
  2154. //expose base object on $.mobile
  2155. $.mobile.base = base;
  2156. //history stack
  2157. $.mobile.urlHistory = urlHistory;
  2158. $.mobile.dialogHashKey = dialogHashKey;
  2159. //default non-animation transition handler
  2160. $.mobile.noneTransitionHandler = function( name, reverse, $toPage, $fromPage ) {
  2161. if ( $fromPage ) {
  2162. $fromPage.removeClass( $.mobile.activePageClass );
  2163. }
  2164. $toPage.addClass( $.mobile.activePageClass );
  2165. return $.Deferred().resolve( name, reverse, $toPage, $fromPage ).promise();
  2166. };
  2167. //default handler for unknown transitions
  2168. $.mobile.defaultTransitionHandler = $.mobile.noneTransitionHandler;
  2169. //transition handler dictionary for 3rd party transitions
  2170. $.mobile.transitionHandlers = {
  2171. none: $.mobile.defaultTransitionHandler
  2172. };
  2173. //enable cross-domain page support
  2174. $.mobile.allowCrossDomainPages = false;
  2175. //return the original document url
  2176. $.mobile.getDocumentUrl = function(asParsedObject) {
  2177. return asParsedObject ? $.extend( {}, documentUrl ) : documentUrl.href;
  2178. };
  2179. //return the original document base url
  2180. $.mobile.getDocumentBase = function(asParsedObject) {
  2181. return asParsedObject ? $.extend( {}, documentBase ) : documentBase.href;
  2182. };
  2183. $.mobile._bindPageRemove = function() {
  2184. var page = $(this);
  2185. // when dom caching is not enabled or the page is embedded bind to remove the page on hide
  2186. if( !page.data("page").options.domCache
  2187. && page.is(":jqmData(external-page='true')") ) {
  2188. page.bind( 'pagehide.remove', function() {
  2189. var $this = $( this ),
  2190. prEvent = new $.Event( "pageremove" );
  2191. $this.trigger( prEvent );
  2192. if( !prEvent.isDefaultPrevented() ){
  2193. $this.removeWithDependents();
  2194. }
  2195. });
  2196. }
  2197. };
  2198. // Load a page into the DOM.
  2199. $.mobile.loadPage = function( url, options ) {
  2200. // This function uses deferred notifications to let callers
  2201. // know when the page is done loading, or if an error has occurred.
  2202. var deferred = $.Deferred(),
  2203. // The default loadPage options with overrides specified by
  2204. // the caller.
  2205. settings = $.extend( {}, $.mobile.loadPage.defaults, options ),
  2206. // The DOM element for the page after it has been loaded.
  2207. page = null,
  2208. // If the reloadPage option is true, and the page is already
  2209. // in the DOM, dupCachedPage will be set to the page element
  2210. // so that it can be removed after the new version of the
  2211. // page is loaded off the network.
  2212. dupCachedPage = null,
  2213. // determine the current base url
  2214. findBaseWithDefault = function(){
  2215. var closestBase = ( $.mobile.activePage && getClosestBaseUrl( $.mobile.activePage ) );
  2216. return closestBase || documentBase.hrefNoHash;
  2217. },
  2218. // The absolute version of the URL passed into the function. This
  2219. // version of the URL may contain dialog/subpage params in it.
  2220. absUrl = path.makeUrlAbsolute( url, findBaseWithDefault() );
  2221. // If the caller provided data, and we're using "get" request,
  2222. // append the data to the URL.
  2223. if ( settings.data && settings.type === "get" ) {
  2224. absUrl = path.addSearchParams( absUrl, settings.data );
  2225. settings.data = undefined;
  2226. }
  2227. // If the caller is using a "post" request, reloadPage must be true
  2228. if( settings.data && settings.type === "post" ){
  2229. settings.reloadPage = true;
  2230. }
  2231. // The absolute version of the URL minus any dialog/subpage params.
  2232. // In otherwords the real URL of the page to be loaded.
  2233. var fileUrl = path.getFilePath( absUrl ),
  2234. // The version of the Url actually stored in the data-url attribute of
  2235. // the page. For embedded pages, it is just the id of the page. For pages
  2236. // within the same domain as the document base, it is the site relative
  2237. // path. For cross-domain pages (Phone Gap only) the entire absolute Url
  2238. // used to load the page.
  2239. dataUrl = path.convertUrlToDataUrl( absUrl );
  2240. // Make sure we have a pageContainer to work with.
  2241. settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
  2242. // Check to see if the page already exists in the DOM.
  2243. page = settings.pageContainer.children( ":jqmData(url='" + dataUrl + "')" );
  2244. // If we failed to find the page, check to see if the url is a
  2245. // reference to an embedded page. If so, it may have been dynamically
  2246. // injected by a developer, in which case it would be lacking a data-url
  2247. // attribute and in need of enhancement.
  2248. if ( page.length === 0 && dataUrl && !path.isPath( dataUrl ) ) {
  2249. page = settings.pageContainer.children( "#" + dataUrl )
  2250. .attr( "data-" + $.mobile.ns + "url", dataUrl );
  2251. }
  2252. // If we failed to find a page in the DOM, check the URL to see if it
  2253. // refers to the first page in the application. If it isn't a reference
  2254. // to the first page and refers to non-existent embedded page, error out.
  2255. if ( page.length === 0 ) {
  2256. if ( $.mobile.firstPage && path.isFirstPageUrl( fileUrl ) ) {
  2257. // Check to make sure our cached-first-page is actually
  2258. // in the DOM. Some user deployed apps are pruning the first
  2259. // page from the DOM for various reasons, we check for this
  2260. // case here because we don't want a first-page with an id
  2261. // falling through to the non-existent embedded page error
  2262. // case. If the first-page is not in the DOM, then we let
  2263. // things fall through to the ajax loading code below so
  2264. // that it gets reloaded.
  2265. if ( $.mobile.firstPage.parent().length ) {
  2266. page = $( $.mobile.firstPage );
  2267. }
  2268. } else if ( path.isEmbeddedPage( fileUrl ) ) {
  2269. deferred.reject( absUrl, options );
  2270. return deferred.promise();
  2271. }
  2272. }
  2273. // Reset base to the default document base.
  2274. if ( base ) {
  2275. base.reset();
  2276. }
  2277. // If the page we are interested in is already in the DOM,
  2278. // and the caller did not indicate that we should force a
  2279. // reload of the file, we are done. Otherwise, track the
  2280. // existing page as a duplicated.
  2281. if ( page.length ) {
  2282. if ( !settings.reloadPage ) {
  2283. enhancePage( page, settings.role );
  2284. deferred.resolve( absUrl, options, page );
  2285. return deferred.promise();
  2286. }
  2287. dupCachedPage = page;
  2288. }
  2289. var mpc = settings.pageContainer,
  2290. pblEvent = new $.Event( "pagebeforeload" ),
  2291. triggerData = { url: url, absUrl: absUrl, dataUrl: dataUrl, deferred: deferred, options: settings };
  2292. // Let listeners know we're about to load a page.
  2293. mpc.trigger( pblEvent, triggerData );
  2294. // If the default behavior is prevented, stop here!
  2295. if( pblEvent.isDefaultPrevented() ){
  2296. return deferred.promise();
  2297. }
  2298. if ( settings.showLoadMsg ) {
  2299. // This configurable timeout allows cached pages a brief delay to load without showing a message
  2300. var loadMsgDelay = setTimeout(function(){
  2301. $.mobile.showPageLoadingMsg();
  2302. }, settings.loadMsgDelay ),
  2303. // Shared logic for clearing timeout and removing message.
  2304. hideMsg = function(){
  2305. // Stop message show timer
  2306. clearTimeout( loadMsgDelay );
  2307. // Hide loading message
  2308. $.mobile.hidePageLoadingMsg();
  2309. };
  2310. }
  2311. if ( !( $.mobile.allowCrossDomainPages || path.isSameDomain( documentUrl, absUrl ) ) ) {
  2312. deferred.reject( absUrl, options );
  2313. } else {
  2314. // Load the new page.
  2315. $.ajax({
  2316. url: fileUrl,
  2317. type: settings.type,
  2318. data: settings.data,
  2319. dataType: "html",
  2320. success: function( html, textStatus, xhr ) {
  2321. //pre-parse html to check for a data-url,
  2322. //use it as the new fileUrl, base path, etc
  2323. var all = $( "<div></div>" ),
  2324. //page title regexp
  2325. newPageTitle = html.match( /<title[^>]*>([^<]*)/ ) && RegExp.$1,
  2326. // TODO handle dialogs again
  2327. pageElemRegex = new RegExp( "(<[^>]+\\bdata-" + $.mobile.ns + "role=[\"']?page[\"']?[^>]*>)" ),
  2328. dataUrlRegex = new RegExp( "\\bdata-" + $.mobile.ns + "url=[\"']?([^\"'>]*)[\"']?" );
  2329. // data-url must be provided for the base tag so resource requests can be directed to the
  2330. // correct url. loading into a temprorary element makes these requests immediately
  2331. if( pageElemRegex.test( html )
  2332. && RegExp.$1
  2333. && dataUrlRegex.test( RegExp.$1 )
  2334. && RegExp.$1 ) {
  2335. url = fileUrl = path.getFilePath( RegExp.$1 );
  2336. }
  2337. if ( base ) {
  2338. base.set( fileUrl );
  2339. }
  2340. //workaround to allow scripts to execute when included in page divs
  2341. all.get( 0 ).innerHTML = html;
  2342. page = all.find( ":jqmData(role='page'), :jqmData(role='dialog')" ).first();
  2343. //if page elem couldn't be found, create one and insert the body element's contents
  2344. if( !page.length ){
  2345. page = $( "<div data-" + $.mobile.ns + "role='page'>" + html.split( /<\/?body[^>]*>/gmi )[1] + "</div>" );
  2346. }
  2347. if ( newPageTitle && !page.jqmData( "title" ) ) {
  2348. if ( ~newPageTitle.indexOf( "&" ) ) {
  2349. newPageTitle = $( "<div>" + newPageTitle + "</div>" ).text();
  2350. }
  2351. page.jqmData( "title", newPageTitle );
  2352. }
  2353. //rewrite src and href attrs to use a base url
  2354. if( !$.support.dynamicBaseTag ) {
  2355. var newPath = path.get( fileUrl );
  2356. page.find( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ).each(function() {
  2357. var thisAttr = $( this ).is( '[href]' ) ? 'href' :
  2358. $(this).is('[src]') ? 'src' : 'action',
  2359. thisUrl = $( this ).attr( thisAttr );
  2360. // XXX_jblas: We need to fix this so that it removes the document
  2361. // base URL, and then prepends with the new page URL.
  2362. //if full path exists and is same, chop it - helps IE out
  2363. thisUrl = thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );
  2364. if( !/^(\w+:|#|\/)/.test( thisUrl ) ) {
  2365. $( this ).attr( thisAttr, newPath + thisUrl );
  2366. }
  2367. });
  2368. }
  2369. //append to page and enhance
  2370. // TODO taging a page with external to make sure that embedded pages aren't removed
  2371. // by the various page handling code is bad. Having page handling code in many
  2372. // places is bad. Solutions post 1.0
  2373. page
  2374. .attr( "data-" + $.mobile.ns + "url", path.convertUrlToDataUrl( fileUrl ) )
  2375. .attr( "data-" + $.mobile.ns + "external-page", true )
  2376. .appendTo( settings.pageContainer );
  2377. // wait for page creation to leverage options defined on widget
  2378. page.one( 'pagecreate', $.mobile._bindPageRemove );
  2379. enhancePage( page, settings.role );
  2380. // Enhancing the page may result in new dialogs/sub pages being inserted
  2381. // into the DOM. If the original absUrl refers to a sub-page, that is the
  2382. // real page we are interested in.
  2383. if ( absUrl.indexOf( "&" + $.mobile.subPageUrlKey ) > -1 ) {
  2384. page = settings.pageContainer.children( ":jqmData(url='" + dataUrl + "')" );
  2385. }
  2386. //bind pageHide to removePage after it's hidden, if the page options specify to do so
  2387. // Remove loading message.
  2388. if ( settings.showLoadMsg ) {
  2389. hideMsg();
  2390. }
  2391. // Add the page reference and xhr to our triggerData.
  2392. triggerData.xhr = xhr;
  2393. triggerData.textStatus = textStatus;
  2394. triggerData.page = page;
  2395. // Let listeners know the page loaded successfully.
  2396. settings.pageContainer.trigger( "pageload", triggerData );
  2397. deferred.resolve( absUrl, options, page, dupCachedPage );
  2398. },
  2399. error: function( xhr, textStatus, errorThrown ) {
  2400. //set base back to current path
  2401. if( base ) {
  2402. base.set( path.get() );
  2403. }
  2404. // Add error info to our triggerData.
  2405. triggerData.xhr = xhr;
  2406. triggerData.textStatus = textStatus;
  2407. triggerData.errorThrown = errorThrown;
  2408. var plfEvent = new $.Event( "pageloadfailed" );
  2409. // Let listeners know the page load failed.
  2410. settings.pageContainer.trigger( plfEvent, triggerData );
  2411. // If the default behavior is prevented, stop here!
  2412. // Note that it is the responsibility of the listener/handler
  2413. // that called preventDefault(), to resolve/reject the
  2414. // deferred object within the triggerData.
  2415. if( plfEvent.isDefaultPrevented() ){
  2416. return;
  2417. }
  2418. // Remove loading message.
  2419. if ( settings.showLoadMsg ) {
  2420. // Remove loading message.
  2421. hideMsg();
  2422. //show error message
  2423. $( "<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h1>"+ $.mobile.pageLoadErrorMessage +"</h1></div>" )
  2424. .css({ "display": "block", "opacity": 0.96, "top": $window.scrollTop() + 100 })
  2425. .appendTo( settings.pageContainer )
  2426. .delay( 800 )
  2427. .fadeOut( 400, function() {
  2428. $( this ).remove();
  2429. });
  2430. }
  2431. deferred.reject( absUrl, options );
  2432. }
  2433. });
  2434. }
  2435. return deferred.promise();
  2436. };
  2437. $.mobile.loadPage.defaults = {
  2438. type: "get",
  2439. data: undefined,
  2440. reloadPage: false,
  2441. role: undefined, // By default we rely on the role defined by the @data-role attribute.
  2442. showLoadMsg: false,
  2443. pageContainer: undefined,
  2444. loadMsgDelay: 50 // This delay allows loads that pull from browser cache to occur without showing the loading message.
  2445. };
  2446. // Show a specific page in the page container.
  2447. $.mobile.changePage = function( toPage, options ) {
  2448. // If we are in the midst of a transition, queue the current request.
  2449. // We'll call changePage() once we're done with the current transition to
  2450. // service the request.
  2451. if( isPageTransitioning ) {
  2452. pageTransitionQueue.unshift( arguments );
  2453. return;
  2454. }
  2455. var settings = $.extend( {}, $.mobile.changePage.defaults, options );
  2456. // Make sure we have a pageContainer to work with.
  2457. settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
  2458. // Make sure we have a fromPage.
  2459. settings.fromPage = settings.fromPage || $.mobile.activePage;
  2460. var mpc = settings.pageContainer,
  2461. pbcEvent = new $.Event( "pagebeforechange" ),
  2462. triggerData = { toPage: toPage, options: settings };
  2463. // Let listeners know we're about to change the current page.
  2464. mpc.trigger( pbcEvent, triggerData );
  2465. // If the default behavior is prevented, stop here!
  2466. if( pbcEvent.isDefaultPrevented() ){
  2467. return;
  2468. }
  2469. // We allow "pagebeforechange" observers to modify the toPage in the trigger
  2470. // data to allow for redirects. Make sure our toPage is updated.
  2471. toPage = triggerData.toPage;
  2472. // Set the isPageTransitioning flag to prevent any requests from
  2473. // entering this method while we are in the midst of loading a page
  2474. // or transitioning.
  2475. isPageTransitioning = true;
  2476. // If the caller passed us a url, call loadPage()
  2477. // to make sure it is loaded into the DOM. We'll listen
  2478. // to the promise object it returns so we know when
  2479. // it is done loading or if an error ocurred.
  2480. if ( typeof toPage == "string" ) {
  2481. $.mobile.loadPage( toPage, settings )
  2482. .done(function( url, options, newPage, dupCachedPage ) {
  2483. isPageTransitioning = false;
  2484. options.duplicateCachedPage = dupCachedPage;
  2485. $.mobile.changePage( newPage, options );
  2486. })
  2487. .fail(function( url, options ) {
  2488. isPageTransitioning = false;
  2489. //clear out the active button state
  2490. removeActiveLinkClass( true );
  2491. //release transition lock so navigation is free again
  2492. releasePageTransitionLock();
  2493. settings.pageContainer.trigger( "pagechangefailed", triggerData );
  2494. });
  2495. return;
  2496. }
  2497. // If we are going to the first-page of the application, we need to make
  2498. // sure settings.dataUrl is set to the application document url. This allows
  2499. // us to avoid generating a document url with an id hash in the case where the
  2500. // first-page of the document has an id attribute specified.
  2501. if ( toPage[ 0 ] === $.mobile.firstPage[ 0 ] && !settings.dataUrl ) {
  2502. settings.dataUrl = documentUrl.hrefNoHash;
  2503. }
  2504. // The caller passed us a real page DOM element. Update our
  2505. // internal state and then trigger a transition to the page.
  2506. var fromPage = settings.fromPage,
  2507. url = ( settings.dataUrl && path.convertUrlToDataUrl( settings.dataUrl ) ) || toPage.jqmData( "url" ),
  2508. // The pageUrl var is usually the same as url, except when url is obscured as a dialog url. pageUrl always contains the file path
  2509. pageUrl = url,
  2510. fileUrl = path.getFilePath( url ),
  2511. active = urlHistory.getActive(),
  2512. activeIsInitialPage = urlHistory.activeIndex === 0,
  2513. historyDir = 0,
  2514. pageTitle = document.title,
  2515. isDialog = settings.role === "dialog" || toPage.jqmData( "role" ) === "dialog";
  2516. // By default, we prevent changePage requests when the fromPage and toPage
  2517. // are the same element, but folks that generate content manually/dynamically
  2518. // and reuse pages want to be able to transition to the same page. To allow
  2519. // this, they will need to change the default value of allowSamePageTransition
  2520. // to true, *OR*, pass it in as an option when they manually call changePage().
  2521. // It should be noted that our default transition animations assume that the
  2522. // formPage and toPage are different elements, so they may behave unexpectedly.
  2523. // It is up to the developer that turns on the allowSamePageTransitiona option
  2524. // to either turn off transition animations, or make sure that an appropriate
  2525. // animation transition is used.
  2526. if( fromPage && fromPage[0] === toPage[0] && !settings.allowSamePageTransition ) {
  2527. isPageTransitioning = false;
  2528. mpc.trigger( "pagechange", triggerData );
  2529. return;
  2530. }
  2531. // We need to make sure the page we are given has already been enhanced.
  2532. enhancePage( toPage, settings.role );
  2533. // If the changePage request was sent from a hashChange event, check to see if the
  2534. // page is already within the urlHistory stack. If so, we'll assume the user hit
  2535. // the forward/back button and will try to match the transition accordingly.
  2536. if( settings.fromHashChange ) {
  2537. urlHistory.directHashChange({
  2538. currentUrl: url,
  2539. isBack: function() { historyDir = -1; },
  2540. isForward: function() { historyDir = 1; }
  2541. });
  2542. }
  2543. // Kill the keyboard.
  2544. // XXX_jblas: We need to stop crawling the entire document to kill focus. Instead,
  2545. // we should be tracking focus with a delegate() handler so we already have
  2546. // the element in hand at this point.
  2547. // Wrap this in a try/catch block since IE9 throw "Unspecified error" if document.activeElement
  2548. // is undefined when we are in an IFrame.
  2549. try {
  2550. if(document.activeElement && document.activeElement.nodeName.toLowerCase() != 'body') {
  2551. $(document.activeElement).blur();
  2552. } else {
  2553. $( "input:focus, textarea:focus, select:focus" ).blur();
  2554. }
  2555. } catch(e) {}
  2556. // If we're displaying the page as a dialog, we don't want the url
  2557. // for the dialog content to be used in the hash. Instead, we want
  2558. // to append the dialogHashKey to the url of the current page.
  2559. if ( isDialog && active ) {
  2560. // on the initial page load active.url is undefined and in that case should
  2561. // be an empty string. Moving the undefined -> empty string back into
  2562. // urlHistory.addNew seemed imprudent given undefined better represents
  2563. // the url state
  2564. url = ( active.url || "" ) + dialogHashKey;
  2565. }
  2566. // Set the location hash.
  2567. if( settings.changeHash !== false && url ) {
  2568. //disable hash listening temporarily
  2569. urlHistory.ignoreNextHashChange = true;
  2570. //update hash and history
  2571. path.set( url );
  2572. }
  2573. // if title element wasn't found, try the page div data attr too
  2574. // If this is a deep-link or a reload ( active === undefined ) then just use pageTitle
  2575. var newPageTitle = ( !active )? pageTitle : toPage.jqmData( "title" ) || toPage.children(":jqmData(role='header')").find(".ui-title" ).getEncodedText();
  2576. if( !!newPageTitle && pageTitle == document.title ) {
  2577. pageTitle = newPageTitle;
  2578. }
  2579. if ( !toPage.jqmData( "title" ) ) {
  2580. toPage.jqmData( "title", pageTitle );
  2581. }
  2582. // Make sure we have a transition defined.
  2583. settings.transition = settings.transition
  2584. || ( ( historyDir && !activeIsInitialPage ) ? active.transition : undefined )
  2585. || ( isDialog ? $.mobile.defaultDialogTransition : $.mobile.defaultPageTransition );
  2586. //add page to history stack if it's not back or forward
  2587. if( !historyDir ) {
  2588. urlHistory.addNew( url, settings.transition, pageTitle, pageUrl, settings.role );
  2589. }
  2590. //set page title
  2591. document.title = urlHistory.getActive().title;
  2592. //set "toPage" as activePage
  2593. $.mobile.activePage = toPage;
  2594. // If we're navigating back in the URL history, set reverse accordingly.
  2595. settings.reverse = settings.reverse || historyDir < 0;
  2596. transitionPages( toPage, fromPage, settings.transition, settings.reverse )
  2597. .done(function() {
  2598. removeActiveLinkClass();
  2599. //if there's a duplicateCachedPage, remove it from the DOM now that it's hidden
  2600. if ( settings.duplicateCachedPage ) {
  2601. settings.duplicateCachedPage.remove();
  2602. }
  2603. //remove initial build class (only present on first pageshow)
  2604. $html.removeClass( "ui-mobile-rendering" );
  2605. releasePageTransitionLock();
  2606. // Let listeners know we're all done changing the current page.
  2607. mpc.trigger( "pagechange", triggerData );
  2608. });
  2609. };
  2610. $.mobile.changePage.defaults = {
  2611. transition: undefined,
  2612. reverse: false,
  2613. changeHash: true,
  2614. fromHashChange: false,
  2615. role: undefined, // By default we rely on the role defined by the @data-role attribute.
  2616. duplicateCachedPage: undefined,
  2617. pageContainer: undefined,
  2618. showLoadMsg: true, //loading message shows by default when pages are being fetched during changePage
  2619. dataUrl: undefined,
  2620. fromPage: undefined,
  2621. allowSamePageTransition: false
  2622. };
  2623. /* Event Bindings - hashchange, submit, and click */
  2624. function findClosestLink( ele )
  2625. {
  2626. while ( ele ) {
  2627. // Look for the closest element with a nodeName of "a".
  2628. // Note that we are checking if we have a valid nodeName
  2629. // before attempting to access it. This is because the
  2630. // node we get called with could have originated from within
  2631. // an embedded SVG document where some symbol instance elements
  2632. // don't have nodeName defined on them, or strings are of type
  2633. // SVGAnimatedString.
  2634. if ( ( typeof ele.nodeName === "string" ) && ele.nodeName.toLowerCase() == "a" ) {
  2635. break;
  2636. }
  2637. ele = ele.parentNode;
  2638. }
  2639. return ele;
  2640. }
  2641. // The base URL for any given element depends on the page it resides in.
  2642. function getClosestBaseUrl( ele )
  2643. {
  2644. // Find the closest page and extract out its url.
  2645. var url = $( ele ).closest( ".ui-page" ).jqmData( "url" ),
  2646. base = documentBase.hrefNoHash;
  2647. if ( !url || !path.isPath( url ) ) {
  2648. url = base;
  2649. }
  2650. return path.makeUrlAbsolute( url, base);
  2651. }
  2652. //The following event bindings should be bound after mobileinit has been triggered
  2653. //the following function is called in the init file
  2654. $.mobile._registerInternalEvents = function(){
  2655. //bind to form submit events, handle with Ajax
  2656. $( document ).delegate( "form", "submit", function( event ) {
  2657. var $this = $( this );
  2658. if( !$.mobile.ajaxEnabled ||
  2659. $this.is( ":jqmData(ajax='false')" ) ) {
  2660. return;
  2661. }
  2662. var type = $this.attr( "method" ),
  2663. target = $this.attr( "target" ),
  2664. url = $this.attr( "action" );
  2665. // If no action is specified, browsers default to using the
  2666. // URL of the document containing the form. Since we dynamically
  2667. // pull in pages from external documents, the form should submit
  2668. // to the URL for the source document of the page containing
  2669. // the form.
  2670. if ( !url ) {
  2671. // Get the @data-url for the page containing the form.
  2672. url = getClosestBaseUrl( $this );
  2673. if ( url === documentBase.hrefNoHash ) {
  2674. // The url we got back matches the document base,
  2675. // which means the page must be an internal/embedded page,
  2676. // so default to using the actual document url as a browser
  2677. // would.
  2678. url = documentUrl.hrefNoSearch;
  2679. }
  2680. }
  2681. url = path.makeUrlAbsolute( url, getClosestBaseUrl($this) );
  2682. if(( path.isExternal( url ) && !path.isPermittedCrossDomainRequest(documentUrl, url)) || target ) {
  2683. return;
  2684. }
  2685. $.mobile.changePage(
  2686. url,
  2687. {
  2688. type: type && type.length && type.toLowerCase() || "get",
  2689. data: $this.serialize(),
  2690. transition: $this.jqmData( "transition" ),
  2691. direction: $this.jqmData( "direction" ),
  2692. reloadPage: true
  2693. }
  2694. );
  2695. event.preventDefault();
  2696. });
  2697. //add active state on vclick
  2698. $( document ).bind( "vclick", function( event ) {
  2699. // if this isn't a left click we don't care. Its important to note
  2700. // that when the virtual event is generated it will create
  2701. if ( event.which > 1 || !$.mobile.linkBindingEnabled ){
  2702. return;
  2703. }
  2704. var link = findClosestLink( event.target );
  2705. if ( link ) {
  2706. if ( path.parseUrl( link.getAttribute( "href" ) || "#" ).hash !== "#" ) {
  2707. removeActiveLinkClass( true );
  2708. $activeClickedLink = $( link ).closest( ".ui-btn" ).not( ".ui-disabled" );
  2709. $activeClickedLink.addClass( $.mobile.activeBtnClass );
  2710. $( "." + $.mobile.activePageClass + " .ui-btn" ).not( link ).blur();
  2711. }
  2712. }
  2713. });
  2714. // click routing - direct to HTTP or Ajax, accordingly
  2715. $( document ).bind( "click", function( event ) {
  2716. if( !$.mobile.linkBindingEnabled ){
  2717. return;
  2718. }
  2719. var link = findClosestLink( event.target );
  2720. // If there is no link associated with the click or its not a left
  2721. // click we want to ignore the click
  2722. if ( !link || event.which > 1) {
  2723. return;
  2724. }
  2725. var $link = $( link ),
  2726. //remove active link class if external (then it won't be there if you come back)
  2727. httpCleanup = function(){
  2728. window.setTimeout( function() { removeActiveLinkClass( true ); }, 200 );
  2729. };
  2730. //if there's a data-rel=back attr, go back in history
  2731. if( $link.is( ":jqmData(rel='back')" ) ) {
  2732. window.history.back();
  2733. return false;
  2734. }
  2735. var baseUrl = getClosestBaseUrl( $link ),
  2736. //get href, if defined, otherwise default to empty hash
  2737. href = path.makeUrlAbsolute( $link.attr( "href" ) || "#", baseUrl );
  2738. //if ajax is disabled, exit early
  2739. if( !$.mobile.ajaxEnabled && !path.isEmbeddedPage( href ) ){
  2740. httpCleanup();
  2741. //use default click handling
  2742. return;
  2743. }
  2744. // XXX_jblas: Ideally links to application pages should be specified as
  2745. // an url to the application document with a hash that is either
  2746. // the site relative path or id to the page. But some of the
  2747. // internal code that dynamically generates sub-pages for nested
  2748. // lists and select dialogs, just write a hash in the link they
  2749. // create. This means the actual URL path is based on whatever
  2750. // the current value of the base tag is at the time this code
  2751. // is called. For now we are just assuming that any url with a
  2752. // hash in it is an application page reference.
  2753. if ( href.search( "#" ) != -1 ) {
  2754. href = href.replace( /[^#]*#/, "" );
  2755. if ( !href ) {
  2756. //link was an empty hash meant purely
  2757. //for interaction, so we ignore it.
  2758. event.preventDefault();
  2759. return;
  2760. } else if ( path.isPath( href ) ) {
  2761. //we have apath so make it the href we want to load.
  2762. href = path.makeUrlAbsolute( href, baseUrl );
  2763. } else {
  2764. //we have a simple id so use the documentUrl as its base.
  2765. href = path.makeUrlAbsolute( "#" + href, documentUrl.hrefNoHash );
  2766. }
  2767. }
  2768. // Should we handle this link, or let the browser deal with it?
  2769. var useDefaultUrlHandling = $link.is( "[rel='external']" ) || $link.is( ":jqmData(ajax='false')" ) || $link.is( "[target]" ),
  2770. // Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR
  2771. // requests if the document doing the request was loaded via the file:// protocol.
  2772. // This is usually to allow the application to "phone home" and fetch app specific
  2773. // data. We normally let the browser handle external/cross-domain urls, but if the
  2774. // allowCrossDomainPages option is true, we will allow cross-domain http/https
  2775. // requests to go through our page loading logic.
  2776. //check for protocol or rel and its not an embedded page
  2777. //TODO overlap in logic from isExternal, rel=external check should be
  2778. // moved into more comprehensive isExternalLink
  2779. isExternal = useDefaultUrlHandling || ( path.isExternal( href ) && !path.isPermittedCrossDomainRequest(documentUrl, href) );
  2780. if( isExternal ) {
  2781. httpCleanup();
  2782. //use default click handling
  2783. return;
  2784. }
  2785. //use ajax
  2786. var transition = $link.jqmData( "transition" ),
  2787. direction = $link.jqmData( "direction" ),
  2788. reverse = ( direction && direction === "reverse" ) ||
  2789. // deprecated - remove by 1.0
  2790. $link.jqmData( "back" ),
  2791. //this may need to be more specific as we use data-rel more
  2792. role = $link.attr( "data-" + $.mobile.ns + "rel" ) || undefined;
  2793. $.mobile.changePage( href, { transition: transition, reverse: reverse, role: role } );
  2794. event.preventDefault();
  2795. });
  2796. //prefetch pages when anchors with data-prefetch are encountered
  2797. $( document ).delegate( ".ui-page", "pageshow.prefetch", function() {
  2798. var urls = [];
  2799. $( this ).find( "a:jqmData(prefetch)" ).each(function(){
  2800. var $link = $(this),
  2801. url = $link.attr( "href" );
  2802. if ( url && $.inArray( url, urls ) === -1 ) {
  2803. urls.push( url );
  2804. $.mobile.loadPage( url, {role: $link.attr("data-" + $.mobile.ns + "rel")} );
  2805. }
  2806. });
  2807. });
  2808. $.mobile._handleHashChange = function( hash ) {
  2809. //find first page via hash
  2810. var to = path.stripHash( hash ),
  2811. //transition is false if it's the first page, undefined otherwise (and may be overridden by default)
  2812. transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined,
  2813. // default options for the changPage calls made after examining the current state
  2814. // of the page and the hash
  2815. changePageOptions = {
  2816. transition: transition,
  2817. changeHash: false,
  2818. fromHashChange: true
  2819. };
  2820. //if listening is disabled (either globally or temporarily), or it's a dialog hash
  2821. if( !$.mobile.hashListeningEnabled || urlHistory.ignoreNextHashChange ) {
  2822. urlHistory.ignoreNextHashChange = false;
  2823. return;
  2824. }
  2825. // special case for dialogs
  2826. if( urlHistory.stack.length > 1 && to.indexOf( dialogHashKey ) > -1 ) {
  2827. // If current active page is not a dialog skip the dialog and continue
  2828. // in the same direction
  2829. if(!$.mobile.activePage.is( ".ui-dialog" )) {
  2830. //determine if we're heading forward or backward and continue accordingly past
  2831. //the current dialog
  2832. urlHistory.directHashChange({
  2833. currentUrl: to,
  2834. isBack: function() { window.history.back(); },
  2835. isForward: function() { window.history.forward(); }
  2836. });
  2837. // prevent changePage()
  2838. return;
  2839. } else {
  2840. // if the current active page is a dialog and we're navigating
  2841. // to a dialog use the dialog objected saved in the stack
  2842. urlHistory.directHashChange({
  2843. currentUrl: to,
  2844. // regardless of the direction of the history change
  2845. // do the following
  2846. either: function( isBack ) {
  2847. var active = $.mobile.urlHistory.getActive();
  2848. to = active.pageUrl;
  2849. // make sure to set the role, transition and reversal
  2850. // as most of this is lost by the domCache cleaning
  2851. $.extend( changePageOptions, {
  2852. role: active.role,
  2853. transition: active.transition,
  2854. reverse: isBack
  2855. });
  2856. }
  2857. });
  2858. }
  2859. }
  2860. //if to is defined, load it
  2861. if ( to ) {
  2862. // At this point, 'to' can be one of 3 things, a cached page element from
  2863. // a history stack entry, an id, or site-relative/absolute URL. If 'to' is
  2864. // an id, we need to resolve it against the documentBase, not the location.href,
  2865. // since the hashchange could've been the result of a forward/backward navigation
  2866. // that crosses from an external page/dialog to an internal page/dialog.
  2867. to = ( typeof to === "string" && !path.isPath( to ) ) ? ( path.makeUrlAbsolute( '#' + to, documentBase ) ) : to;
  2868. $.mobile.changePage( to, changePageOptions );
  2869. } else {
  2870. //there's no hash, go to the first page in the dom
  2871. $.mobile.changePage( $.mobile.firstPage, changePageOptions );
  2872. }
  2873. };
  2874. //hashchange event handler
  2875. $window.bind( "hashchange", function( e, triggered ) {
  2876. $.mobile._handleHashChange( location.hash );
  2877. });
  2878. //set page min-heights to be device specific
  2879. $( document ).bind( "pageshow", resetActivePageHeight );
  2880. $( window ).bind( "throttledresize", resetActivePageHeight );
  2881. };//_registerInternalEvents callback
  2882. })( jQuery );
  2883. /*
  2884. * history.pushState support, layered on top of hashchange
  2885. */
  2886. ( function( $, window ) {
  2887. // For now, let's Monkeypatch this onto the end of $.mobile._registerInternalEvents
  2888. // Scope self to pushStateHandler so we can reference it sanely within the
  2889. // methods handed off as event handlers
  2890. var pushStateHandler = {},
  2891. self = pushStateHandler,
  2892. $win = $( window ),
  2893. url = $.mobile.path.parseUrl( location.href );
  2894. $.extend( pushStateHandler, {
  2895. // TODO move to a path helper, this is rather common functionality
  2896. initialFilePath: (function() {
  2897. return url.pathname + url.search;
  2898. })(),
  2899. initialHref: url.hrefNoHash,
  2900. // Flag for tracking if a Hashchange naturally occurs after each popstate + replace
  2901. hashchangeFired: false,
  2902. state: function() {
  2903. return {
  2904. hash: location.hash || "#" + self.initialFilePath,
  2905. title: document.title,
  2906. // persist across refresh
  2907. initialHref: self.initialHref
  2908. };
  2909. },
  2910. resetUIKeys: function( url ) {
  2911. var dialog = $.mobile.dialogHashKey,
  2912. subkey = "&" + $.mobile.subPageUrlKey,
  2913. dialogIndex = url.indexOf( dialog );
  2914. if( dialogIndex > -1 ) {
  2915. url = url.slice( 0, dialogIndex ) + "#" + url.slice( dialogIndex );
  2916. } else if( url.indexOf( subkey ) > -1 ) {
  2917. url = url.split( subkey ).join( "#" + subkey );
  2918. }
  2919. return url;
  2920. },
  2921. // TODO sort out a single barrier to hashchange functionality
  2922. nextHashChangePrevented: function( value ) {
  2923. $.mobile.urlHistory.ignoreNextHashChange = value;
  2924. self.onHashChangeDisabled = value;
  2925. },
  2926. // on hash change we want to clean up the url
  2927. // NOTE this takes place *after* the vanilla navigation hash change
  2928. // handling has taken place and set the state of the DOM
  2929. onHashChange: function( e ) {
  2930. // disable this hash change
  2931. if( self.onHashChangeDisabled ){
  2932. return;
  2933. }
  2934. var href, state,
  2935. hash = location.hash,
  2936. isPath = $.mobile.path.isPath( hash ),
  2937. resolutionUrl = isPath ? location.href : $.mobile.getDocumentUrl();
  2938. hash = isPath ? hash.replace( "#", "" ) : hash;
  2939. // propulate the hash when its not available
  2940. state = self.state();
  2941. // make the hash abolute with the current href
  2942. href = $.mobile.path.makeUrlAbsolute( hash, resolutionUrl );
  2943. if ( isPath ) {
  2944. href = self.resetUIKeys( href );
  2945. }
  2946. // replace the current url with the new href and store the state
  2947. // Note that in some cases we might be replacing an url with the
  2948. // same url. We do this anyways because we need to make sure that
  2949. // all of our history entries have a state object associated with
  2950. // them. This allows us to work around the case where window.history.back()
  2951. // is called to transition from an external page to an embedded page.
  2952. // In that particular case, a hashchange event is *NOT* generated by the browser.
  2953. // Ensuring each history entry has a state object means that onPopState()
  2954. // will always trigger our hashchange callback even when a hashchange event
  2955. // is not fired.
  2956. history.replaceState( state, document.title, href );
  2957. },
  2958. // on popstate (ie back or forward) we need to replace the hash that was there previously
  2959. // cleaned up by the additional hash handling
  2960. onPopState: function( e ) {
  2961. var poppedState = e.originalEvent.state, holdnexthashchange = false;
  2962. // if there's no state its not a popstate we care about, ie chrome's initial popstate
  2963. // or forward popstate
  2964. if( poppedState ) {
  2965. // disable any hashchange triggered by the browser
  2966. self.nextHashChangePrevented( true );
  2967. // defer our manual hashchange until after the browser fired
  2968. // version has come and gone
  2969. setTimeout(function() {
  2970. // make sure that the manual hash handling takes place
  2971. self.nextHashChangePrevented( false );
  2972. // change the page based on the hash
  2973. $.mobile._handleHashChange( poppedState.hash );
  2974. }, 100);
  2975. }
  2976. },
  2977. init: function() {
  2978. $win.bind( "hashchange", self.onHashChange );
  2979. // Handle popstate events the occur through history changes
  2980. $win.bind( "popstate", self.onPopState );
  2981. // if there's no hash, we need to replacestate for returning to home
  2982. if ( location.hash === "" ) {
  2983. history.replaceState( self.state(), document.title, location.href );
  2984. }
  2985. }
  2986. });
  2987. $( function() {
  2988. if( $.mobile.pushStateEnabled && $.support.pushState ){
  2989. pushStateHandler.init();
  2990. }
  2991. });
  2992. })( jQuery, this );
  2993. /*
  2994. * "transitions" plugin - Page change tranistions
  2995. */
  2996. (function( $, window, undefined ) {
  2997. function css3TransitionHandler( name, reverse, $to, $from ) {
  2998. var deferred = new $.Deferred(),
  2999. reverseClass = reverse ? " reverse" : "",
  3000. viewportClass = "ui-mobile-viewport-transitioning viewport-" + name,
  3001. doneFunc = function() {
  3002. $to.add( $from ).removeClass( "out in reverse " + name );
  3003. if ( $from && $from[ 0 ] !== $to[ 0 ] ) {
  3004. $from.removeClass( $.mobile.activePageClass );
  3005. }
  3006. $to.parent().removeClass( viewportClass );
  3007. deferred.resolve( name, reverse, $to, $from );
  3008. };
  3009. $to.animationComplete( doneFunc );
  3010. $to.parent().addClass( viewportClass );
  3011. if ( $from ) {
  3012. $from.addClass( name + " out" + reverseClass );
  3013. }
  3014. $to.addClass( $.mobile.activePageClass + " " + name + " in" + reverseClass );
  3015. return deferred.promise();
  3016. }
  3017. // Make our transition handler public.
  3018. $.mobile.css3TransitionHandler = css3TransitionHandler;
  3019. // If the default transition handler is the 'none' handler, replace it with our handler.
  3020. if ( $.mobile.defaultTransitionHandler === $.mobile.noneTransitionHandler ) {
  3021. $.mobile.defaultTransitionHandler = css3TransitionHandler;
  3022. }
  3023. })( jQuery, this );
  3024. /*
  3025. * "degradeInputs" plugin - degrades inputs to another type after custom enhancements are made.
  3026. */
  3027. (function( $, undefined ) {
  3028. $.mobile.page.prototype.options.degradeInputs = {
  3029. color: false,
  3030. date: false,
  3031. datetime: false,
  3032. "datetime-local": false,
  3033. email: false,
  3034. month: false,
  3035. number: false,
  3036. range: "number",
  3037. search: "text",
  3038. tel: false,
  3039. time: false,
  3040. url: false,
  3041. week: false
  3042. };
  3043. //auto self-init widgets
  3044. $( document ).bind( "pagecreate create", function( e ){
  3045. var page = $.mobile.closestPageData( $(e.target) );
  3046. if( !page ) {
  3047. return;
  3048. }
  3049. options = page.options;
  3050. // degrade inputs to avoid poorly implemented native functionality
  3051. $( e.target ).find( "input" ).not( page.keepNativeSelector() ).each(function() {
  3052. var $this = $( this ),
  3053. type = this.getAttribute( "type" ),
  3054. optType = options.degradeInputs[ type ] || "text";
  3055. if ( options.degradeInputs[ type ] ) {
  3056. var html = $( "<div>" ).html( $this.clone() ).html(),
  3057. // In IE browsers, the type sometimes doesn't exist in the cloned markup, so we replace the closing tag instead
  3058. hasType = html.indexOf( " type=" ) > -1,
  3059. findstr = hasType ? /\s+type=["']?\w+['"]?/ : /\/?>/,
  3060. repstr = " type=\"" + optType + "\" data-" + $.mobile.ns + "type=\"" + type + "\"" + ( hasType ? "" : ">" );
  3061. $this.replaceWith( html.replace( findstr, repstr ) );
  3062. }
  3063. });
  3064. });
  3065. })( jQuery );/*
  3066. * "dialog" plugin.
  3067. */
  3068. (function( $, window, undefined ) {
  3069. $.widget( "mobile.dialog", $.mobile.widget, {
  3070. options: {
  3071. closeBtnText : "Close",
  3072. overlayTheme : "a",
  3073. initSelector : ":jqmData(role='dialog')"
  3074. },
  3075. _create: function() {
  3076. var self = this,
  3077. $el = this.element,
  3078. headerCloseButton = $( "<a href='#' data-" + $.mobile.ns + "icon='delete' data-" + $.mobile.ns + "iconpos='notext'>"+ this.options.closeBtnText + "</a>" );
  3079. $el.addClass( "ui-overlay-" + this.options.overlayTheme );
  3080. // Class the markup for dialog styling
  3081. // Set aria role
  3082. $el.attr( "role", "dialog" )
  3083. .addClass( "ui-dialog" )
  3084. .find( ":jqmData(role='header')" )
  3085. .addClass( "ui-corner-top ui-overlay-shadow" )
  3086. .prepend( headerCloseButton )
  3087. .end()
  3088. .find( ":jqmData(role='content'),:jqmData(role='footer')" )
  3089. .addClass( "ui-overlay-shadow" )
  3090. .last()
  3091. .addClass( "ui-corner-bottom" );
  3092. // this must be an anonymous function so that select menu dialogs can replace
  3093. // the close method. This is a change from previously just defining data-rel=back
  3094. // on the button and letting nav handle it
  3095. //
  3096. // Use click rather than vclick in order to prevent the possibility of unintentionally
  3097. // reopening the dialog if the dialog opening item was directly under the close button.
  3098. headerCloseButton.bind( "click", function() {
  3099. self.close();
  3100. });
  3101. /* bind events
  3102. - clicks and submits should use the closing transition that the dialog opened with
  3103. unless a data-transition is specified on the link/form
  3104. - if the click was on the close button, or the link has a data-rel="back" it'll go back in history naturally
  3105. */
  3106. $el.bind( "vclick submit", function( event ) {
  3107. var $target = $( event.target ).closest( event.type === "vclick" ? "a" : "form" ),
  3108. active;
  3109. if ( $target.length && !$target.jqmData( "transition" ) ) {
  3110. active = $.mobile.urlHistory.getActive() || {};
  3111. $target.attr( "data-" + $.mobile.ns + "transition", ( active.transition || $.mobile.defaultDialogTransition ) )
  3112. .attr( "data-" + $.mobile.ns + "direction", "reverse" );
  3113. }
  3114. })
  3115. .bind( "pagehide", function() {
  3116. $( this ).find( "." + $.mobile.activeBtnClass ).removeClass( $.mobile.activeBtnClass );
  3117. });
  3118. },
  3119. // Close method goes back in history
  3120. close: function() {
  3121. window.history.back();
  3122. }
  3123. });
  3124. //auto self-init widgets
  3125. $( document ).delegate( $.mobile.dialog.prototype.options.initSelector, "pagecreate", function(){
  3126. $( this ).dialog();
  3127. });
  3128. })( jQuery, this );
  3129. /*
  3130. * This plugin handles theming and layout of headers, footers, and content areas
  3131. */
  3132. (function( $, undefined ) {
  3133. $.mobile.page.prototype.options.backBtnText = "Back";
  3134. $.mobile.page.prototype.options.addBackBtn = false;
  3135. $.mobile.page.prototype.options.backBtnTheme = null;
  3136. $.mobile.page.prototype.options.headerTheme = "a";
  3137. $.mobile.page.prototype.options.footerTheme = "a";
  3138. $.mobile.page.prototype.options.contentTheme = null;
  3139. $( document ).delegate( ":jqmData(role='page'), :jqmData(role='dialog')", "pagecreate", function( e ) {
  3140. var $page = $( this ),
  3141. o = $page.data( "page" ).options,
  3142. pageRole = $page.jqmData( "role" ),
  3143. pageTheme = o.theme;
  3144. $( ":jqmData(role='header'), :jqmData(role='footer'), :jqmData(role='content')", this ).each(function() {
  3145. var $this = $( this ),
  3146. role = $this.jqmData( "role" ),
  3147. theme = $this.jqmData( "theme" ),
  3148. contentTheme = theme || o.contentTheme || ( pageRole === "dialog" && pageTheme ),
  3149. $headeranchors,
  3150. leftbtn,
  3151. rightbtn,
  3152. backBtn;
  3153. $this.addClass( "ui-" + role );
  3154. //apply theming and markup modifications to page,header,content,footer
  3155. if ( role === "header" || role === "footer" ) {
  3156. var thisTheme = theme || ( role === "header" ? o.headerTheme : o.footerTheme ) || pageTheme;
  3157. $this
  3158. //add theme class
  3159. .addClass( "ui-bar-" + thisTheme )
  3160. // Add ARIA role
  3161. .attr( "role", role === "header" ? "banner" : "contentinfo" );
  3162. // Right,left buttons
  3163. $headeranchors = $this.children( "a" );
  3164. leftbtn = $headeranchors.hasClass( "ui-btn-left" );
  3165. rightbtn = $headeranchors.hasClass( "ui-btn-right" );
  3166. leftbtn = leftbtn || $headeranchors.eq( 0 ).not( ".ui-btn-right" ).addClass( "ui-btn-left" ).length;
  3167. rightbtn = rightbtn || $headeranchors.eq( 1 ).addClass( "ui-btn-right" ).length;
  3168. // Auto-add back btn on pages beyond first view
  3169. if ( o.addBackBtn &&
  3170. role === "header" &&
  3171. $( ".ui-page" ).length > 1 &&
  3172. $this.jqmData( "url" ) !== $.mobile.path.stripHash( location.hash ) &&
  3173. !leftbtn ) {
  3174. backBtn = $( "<a href='#' class='ui-btn-left' data-"+ $.mobile.ns +"rel='back' data-"+ $.mobile.ns +"icon='arrow-l'>"+ o.backBtnText +"</a>" )
  3175. // If theme is provided, override default inheritance
  3176. .attr( "data-"+ $.mobile.ns +"theme", o.backBtnTheme || thisTheme )
  3177. .prependTo( $this );
  3178. }
  3179. // Page title
  3180. $this.children( "h1, h2, h3, h4, h5, h6" )
  3181. .addClass( "ui-title" )
  3182. // Regardless of h element number in src, it becomes h1 for the enhanced page
  3183. .attr({
  3184. "tabindex": "0",
  3185. "role": "heading",
  3186. "aria-level": "1"
  3187. });
  3188. } else if ( role === "content" ) {
  3189. if ( contentTheme ) {
  3190. $this.addClass( "ui-body-" + ( contentTheme ) );
  3191. }
  3192. // Add ARIA role
  3193. $this.attr( "role", "main" );
  3194. }
  3195. });
  3196. });
  3197. })( jQuery );/*
  3198. * "collapsible" plugin
  3199. */
  3200. (function( $, undefined ) {
  3201. $.widget( "mobile.collapsible", $.mobile.widget, {
  3202. options: {
  3203. expandCueText: " click to expand contents",
  3204. collapseCueText: " click to collapse contents",
  3205. collapsed: true,
  3206. heading: "h1,h2,h3,h4,h5,h6,legend",
  3207. theme: null,
  3208. contentTheme: null,
  3209. iconTheme: "d",
  3210. initSelector: ":jqmData(role='collapsible')"
  3211. },
  3212. _create: function() {
  3213. var $el = this.element,
  3214. o = this.options,
  3215. collapsible = $el.addClass( "ui-collapsible" ),
  3216. collapsibleHeading = $el.children( o.heading ).first(),
  3217. collapsibleContent = collapsible.wrapInner( "<div class='ui-collapsible-content'></div>" ).find( ".ui-collapsible-content" ),
  3218. collapsibleSet = $el.closest( ":jqmData(role='collapsible-set')" ).addClass( "ui-collapsible-set" );
  3219. // Replace collapsibleHeading if it's a legend
  3220. if ( collapsibleHeading.is( "legend" ) ) {
  3221. collapsibleHeading = $( "<div role='heading'>"+ collapsibleHeading.html() +"</div>" ).insertBefore( collapsibleHeading );
  3222. collapsibleHeading.next().remove();
  3223. }
  3224. // If we are in a collapsible set
  3225. if ( collapsibleSet.length ) {
  3226. // Inherit the theme from collapsible-set
  3227. if ( !o.theme ) {
  3228. o.theme = collapsibleSet.jqmData( "theme" );
  3229. }
  3230. // Inherit the content-theme from collapsible-set
  3231. if ( !o.contentTheme ) {
  3232. o.contentTheme = collapsibleSet.jqmData( "content-theme" );
  3233. }
  3234. }
  3235. collapsibleContent.addClass( ( o.contentTheme ) ? ( "ui-body-" + o.contentTheme ) : "");
  3236. collapsibleHeading
  3237. //drop heading in before content
  3238. .insertBefore( collapsibleContent )
  3239. //modify markup & attributes
  3240. .addClass( "ui-collapsible-heading" )
  3241. .append( "<span class='ui-collapsible-heading-status'></span>" )
  3242. .wrapInner( "<a href='#' class='ui-collapsible-heading-toggle'></a>" )
  3243. .find( "a" )
  3244. .first()
  3245. .buttonMarkup({
  3246. shadow: false,
  3247. corners: false,
  3248. iconPos: "left",
  3249. icon: "plus",
  3250. theme: o.theme
  3251. })
  3252. .add( ".ui-btn-inner" )
  3253. .addClass( "ui-corner-top ui-corner-bottom" );
  3254. //events
  3255. collapsible
  3256. .bind( "expand collapse", function( event ) {
  3257. if ( !event.isDefaultPrevented() ) {
  3258. event.preventDefault();
  3259. var $this = $( this ),
  3260. isCollapse = ( event.type === "collapse" ),
  3261. contentTheme = o.contentTheme;
  3262. collapsibleHeading
  3263. .toggleClass( "ui-collapsible-heading-collapsed", isCollapse)
  3264. .find( ".ui-collapsible-heading-status" )
  3265. .text( isCollapse ? o.expandCueText : o.collapseCueText )
  3266. .end()
  3267. .find( ".ui-icon" )
  3268. .toggleClass( "ui-icon-minus", !isCollapse )
  3269. .toggleClass( "ui-icon-plus", isCollapse );
  3270. $this.toggleClass( "ui-collapsible-collapsed", isCollapse );
  3271. collapsibleContent.toggleClass( "ui-collapsible-content-collapsed", isCollapse ).attr( "aria-hidden", isCollapse );
  3272. if ( contentTheme && ( !collapsibleSet.length || collapsible.jqmData( "collapsible-last" ) ) ) {
  3273. collapsibleHeading
  3274. .find( "a" ).first().add( collapsibleHeading.find( ".ui-btn-inner" ) )
  3275. .toggleClass( "ui-corner-bottom", isCollapse );
  3276. collapsibleContent.toggleClass( "ui-corner-bottom", !isCollapse );
  3277. }
  3278. collapsibleContent.trigger( "updatelayout" );
  3279. }
  3280. })
  3281. .trigger( o.collapsed ? "collapse" : "expand" );
  3282. collapsibleHeading
  3283. .bind( "click", function( event ) {
  3284. var type = collapsibleHeading.is( ".ui-collapsible-heading-collapsed" ) ?
  3285. "expand" : "collapse";
  3286. collapsible.trigger( type );
  3287. event.preventDefault();
  3288. });
  3289. }
  3290. });
  3291. //auto self-init widgets
  3292. $( document ).bind( "pagecreate create", function( e ){
  3293. $( $.mobile.collapsible.prototype.options.initSelector, e.target ).collapsible();
  3294. });
  3295. })( jQuery );
  3296. /*
  3297. * "collapsibleset" plugin
  3298. */
  3299. (function( $, undefined ) {
  3300. $.widget( "mobile.collapsibleset", $.mobile.widget, {
  3301. options: {
  3302. initSelector: ":jqmData(role='collapsible-set')"
  3303. },
  3304. _create: function() {
  3305. var $el = this.element.addClass( "ui-collapsible-set" ),
  3306. o = this.options,
  3307. collapsiblesInSet = $el.children( ":jqmData(role='collapsible')" );
  3308. // Inherit the theme from collapsible-set
  3309. if ( !o.theme ) {
  3310. o.theme = $el.jqmData( "theme" );
  3311. }
  3312. // Inherit the content-theme from collapsible-set
  3313. if ( !o.contentTheme ) {
  3314. o.contentTheme = $el.jqmData( "content-theme" );
  3315. }
  3316. // Initialize the collapsible set if it's not already initialized
  3317. if ( !$el.jqmData( "collapsiblebound" ) ) {
  3318. $el
  3319. .jqmData( "collapsiblebound", true )
  3320. .bind( "expand collapse", function( event ) {
  3321. var isCollapse = ( event.type === "collapse" ),
  3322. collapsible = $( event.target ).closest( ".ui-collapsible" ),
  3323. widget = collapsible.data( "collapsible" ),
  3324. contentTheme = widget.options.contentTheme;
  3325. if ( contentTheme && collapsible.jqmData( "collapsible-last" ) ) {
  3326. collapsible.find( widget.options.heading ).first()
  3327. .find( "a" ).first()
  3328. .add( ".ui-btn-inner" )
  3329. .toggleClass( "ui-corner-bottom", isCollapse );
  3330. collapsible.find( ".ui-collapsible-content" ).toggleClass( "ui-corner-bottom", !isCollapse );
  3331. }
  3332. })
  3333. .bind( "expand", function( event ) {
  3334. $( event.target )
  3335. .closest( ".ui-collapsible" )
  3336. .siblings( ".ui-collapsible" )
  3337. .trigger( "collapse" );
  3338. });
  3339. // clean up borders
  3340. collapsiblesInSet.each( function() {
  3341. $( this ).find( $.mobile.collapsible.prototype.options.heading )
  3342. .find( "a" ).first()
  3343. .add( ".ui-btn-inner" )
  3344. .removeClass( "ui-corner-top ui-corner-bottom" );
  3345. });
  3346. collapsiblesInSet.first()
  3347. .find( "a" )
  3348. .first()
  3349. .addClass( "ui-corner-top" )
  3350. .find( ".ui-btn-inner" )
  3351. .addClass( "ui-corner-top" );
  3352. collapsiblesInSet.last()
  3353. .jqmData( "collapsible-last", true )
  3354. .find( "a" )
  3355. .first()
  3356. .addClass( "ui-corner-bottom" )
  3357. .find( ".ui-btn-inner" )
  3358. .addClass( "ui-corner-bottom" );
  3359. }
  3360. }
  3361. });
  3362. //auto self-init widgets
  3363. $( document ).bind( "pagecreate create", function( e ){
  3364. $( $.mobile.collapsibleset.prototype.options.initSelector, e.target ).collapsibleset();
  3365. });
  3366. })( jQuery );
  3367. /*
  3368. * "fieldcontain" plugin - simple class additions to make form row separators
  3369. */
  3370. (function( $, undefined ) {
  3371. $.fn.fieldcontain = function( options ) {
  3372. return this.addClass( "ui-field-contain ui-body ui-br" );
  3373. };
  3374. //auto self-init widgets
  3375. $( document ).bind( "pagecreate create", function( e ){
  3376. $( ":jqmData(role='fieldcontain')", e.target ).fieldcontain();
  3377. });
  3378. })( jQuery );/*
  3379. * plugin for creating CSS grids
  3380. */
  3381. (function( $, undefined ) {
  3382. $.fn.grid = function( options ) {
  3383. return this.each(function() {
  3384. var $this = $( this ),
  3385. o = $.extend({
  3386. grid: null
  3387. },options),
  3388. $kids = $this.children(),
  3389. gridCols = {solo:1, a:2, b:3, c:4, d:5},
  3390. grid = o.grid,
  3391. iterator;
  3392. if ( !grid ) {
  3393. if ( $kids.length <= 5 ) {
  3394. for ( var letter in gridCols ) {
  3395. if ( gridCols[ letter ] === $kids.length ) {
  3396. grid = letter;
  3397. }
  3398. }
  3399. } else {
  3400. grid = "a";
  3401. }
  3402. }
  3403. iterator = gridCols[grid];
  3404. $this.addClass( "ui-grid-" + grid );
  3405. $kids.filter( ":nth-child(" + iterator + "n+1)" ).addClass( "ui-block-a" );
  3406. if ( iterator > 1 ) {
  3407. $kids.filter( ":nth-child(" + iterator + "n+2)" ).addClass( "ui-block-b" );
  3408. }
  3409. if ( iterator > 2 ) {
  3410. $kids.filter( ":nth-child(3n+3)" ).addClass( "ui-block-c" );
  3411. }
  3412. if ( iterator > 3 ) {
  3413. $kids.filter( ":nth-child(4n+4)" ).addClass( "ui-block-d" );
  3414. }
  3415. if ( iterator > 4 ) {
  3416. $kids.filter( ":nth-child(5n+5)" ).addClass( "ui-block-e" );
  3417. }
  3418. });
  3419. };
  3420. })( jQuery );/*
  3421. * "navbar" plugin
  3422. */
  3423. (function( $, undefined ) {
  3424. $.widget( "mobile.navbar", $.mobile.widget, {
  3425. options: {
  3426. iconpos: "top",
  3427. grid: null,
  3428. initSelector: ":jqmData(role='navbar')"
  3429. },
  3430. _create: function(){
  3431. var $navbar = this.element,
  3432. $navbtns = $navbar.find( "a" ),
  3433. iconpos = $navbtns.filter( ":jqmData(icon)" ).length ?
  3434. this.options.iconpos : undefined;
  3435. $navbar.addClass( "ui-navbar" )
  3436. .attr( "role","navigation" )
  3437. .find( "ul" )
  3438. .grid({ grid: this.options.grid });
  3439. if ( !iconpos ) {
  3440. $navbar.addClass( "ui-navbar-noicons" );
  3441. }
  3442. $navbtns.buttonMarkup({
  3443. corners: false,
  3444. shadow: false,
  3445. iconpos: iconpos
  3446. });
  3447. $navbar.delegate( "a", "vclick", function( event ) {
  3448. if( !$(event.target).hasClass("ui-disabled") ) {
  3449. $navbtns.not( ".ui-state-persist" ).removeClass( $.mobile.activeBtnClass );
  3450. $( this ).addClass( $.mobile.activeBtnClass );
  3451. }
  3452. });
  3453. }
  3454. });
  3455. //auto self-init widgets
  3456. $( document ).bind( "pagecreate create", function( e ){
  3457. $( $.mobile.navbar.prototype.options.initSelector, e.target ).navbar();
  3458. });
  3459. })( jQuery );
  3460. /*
  3461. * "listview" plugin
  3462. */
  3463. (function( $, undefined ) {
  3464. //Keeps track of the number of lists per page UID
  3465. //This allows support for multiple nested list in the same page
  3466. //https://github.com/jquery/jquery-mobile/issues/1617
  3467. var listCountPerPage = {};
  3468. $.widget( "mobile.listview", $.mobile.widget, {
  3469. options: {
  3470. theme: null,
  3471. countTheme: "c",
  3472. headerTheme: "b",
  3473. dividerTheme: "b",
  3474. splitIcon: "arrow-r",
  3475. splitTheme: "b",
  3476. inset: false,
  3477. initSelector: ":jqmData(role='listview')"
  3478. },
  3479. _create: function() {
  3480. var t = this;
  3481. // create listview markup
  3482. t.element.addClass(function( i, orig ) {
  3483. return orig + " ui-listview " + ( t.options.inset ? " ui-listview-inset ui-corner-all ui-shadow " : "" );
  3484. });
  3485. t.refresh( true );
  3486. },
  3487. _removeCorners: function( li, which ) {
  3488. var top = "ui-corner-top ui-corner-tr ui-corner-tl",
  3489. bot = "ui-corner-bottom ui-corner-br ui-corner-bl";
  3490. li = li.add( li.find( ".ui-btn-inner, .ui-li-link-alt, .ui-li-thumb" ) );
  3491. if ( which === "top" ) {
  3492. li.removeClass( top );
  3493. } else if ( which === "bottom" ) {
  3494. li.removeClass( bot );
  3495. } else {
  3496. li.removeClass( top + " " + bot );
  3497. }
  3498. },
  3499. _refreshCorners: function( create ) {
  3500. var $li,
  3501. $visibleli,
  3502. $topli,
  3503. $bottomli;
  3504. if ( this.options.inset ) {
  3505. $li = this.element.children( "li" );
  3506. // at create time the li are not visible yet so we need to rely on .ui-screen-hidden
  3507. $visibleli = create?$li.not( ".ui-screen-hidden" ):$li.filter( ":visible" );
  3508. this._removeCorners( $li );
  3509. // Select the first visible li element
  3510. $topli = $visibleli.first()
  3511. .addClass( "ui-corner-top" );
  3512. $topli.add( $topli.find( ".ui-btn-inner" )
  3513. .not( ".ui-li-link-alt span:first-child" ) )
  3514. .addClass( "ui-corner-top" )
  3515. .end()
  3516. .find( ".ui-li-link-alt, .ui-li-link-alt span:first-child" )
  3517. .addClass( "ui-corner-tr" )
  3518. .end()
  3519. .find( ".ui-li-thumb" )
  3520. .not(".ui-li-icon")
  3521. .addClass( "ui-corner-tl" );
  3522. // Select the last visible li element
  3523. $bottomli = $visibleli.last()
  3524. .addClass( "ui-corner-bottom" );
  3525. $bottomli.add( $bottomli.find( ".ui-btn-inner" ) )
  3526. .find( ".ui-li-link-alt" )
  3527. .addClass( "ui-corner-br" )
  3528. .end()
  3529. .find( ".ui-li-thumb" )
  3530. .not(".ui-li-icon")
  3531. .addClass( "ui-corner-bl" );
  3532. }
  3533. if ( !create ) {
  3534. this.element.trigger( "updatelayout" );
  3535. }
  3536. },
  3537. // This is a generic utility method for finding the first
  3538. // node with a given nodeName. It uses basic DOM traversal
  3539. // to be fast and is meant to be a substitute for simple
  3540. // $.fn.closest() and $.fn.children() calls on a single
  3541. // element. Note that callers must pass both the lowerCase
  3542. // and upperCase version of the nodeName they are looking for.
  3543. // The main reason for this is that this function will be
  3544. // called many times and we want to avoid having to lowercase
  3545. // the nodeName from the element every time to ensure we have
  3546. // a match. Note that this function lives here for now, but may
  3547. // be moved into $.mobile if other components need a similar method.
  3548. _findFirstElementByTagName: function( ele, nextProp, lcName, ucName )
  3549. {
  3550. var dict = {};
  3551. dict[ lcName ] = dict[ ucName ] = true;
  3552. while ( ele ) {
  3553. if ( dict[ ele.nodeName ] ) {
  3554. return ele;
  3555. }
  3556. ele = ele[ nextProp ];
  3557. }
  3558. return null;
  3559. },
  3560. _getChildrenByTagName: function( ele, lcName, ucName )
  3561. {
  3562. var results = [],
  3563. dict = {};
  3564. dict[ lcName ] = dict[ ucName ] = true;
  3565. ele = ele.firstChild;
  3566. while ( ele ) {
  3567. if ( dict[ ele.nodeName ] ) {
  3568. results.push( ele );
  3569. }
  3570. ele = ele.nextSibling;
  3571. }
  3572. return $( results );
  3573. },
  3574. _addThumbClasses: function( containers )
  3575. {
  3576. var i, img, len = containers.length;
  3577. for ( i = 0; i < len; i++ ) {
  3578. img = $( this._findFirstElementByTagName( containers[ i ].firstChild, "nextSibling", "img", "IMG" ) );
  3579. if ( img.length ) {
  3580. img.addClass( "ui-li-thumb" );
  3581. $( this._findFirstElementByTagName( img[ 0 ].parentNode, "parentNode", "li", "LI" ) ).addClass( img.is( ".ui-li-icon" ) ? "ui-li-has-icon" : "ui-li-has-thumb" );
  3582. }
  3583. }
  3584. },
  3585. refresh: function( create ) {
  3586. this.parentPage = this.element.closest( ".ui-page" );
  3587. this._createSubPages();
  3588. var o = this.options,
  3589. $list = this.element,
  3590. self = this,
  3591. dividertheme = $list.jqmData( "dividertheme" ) || o.dividerTheme,
  3592. listsplittheme = $list.jqmData( "splittheme" ),
  3593. listspliticon = $list.jqmData( "spliticon" ),
  3594. li = this._getChildrenByTagName( $list[ 0 ], "li", "LI" ),
  3595. counter = $.support.cssPseudoElement || !$.nodeName( $list[ 0 ], "ol" ) ? 0 : 1,
  3596. itemClassDict = {},
  3597. item, itemClass, itemTheme,
  3598. a, last, splittheme, countParent, icon, imgParents, img;
  3599. if ( counter ) {
  3600. $list.find( ".ui-li-dec" ).remove();
  3601. }
  3602. if ( !o.theme ) {
  3603. o.theme = $.mobile.getInheritedTheme( this.element, "c" );
  3604. }
  3605. for ( var pos = 0, numli = li.length; pos < numli; pos++ ) {
  3606. item = li.eq( pos );
  3607. itemClass = "ui-li";
  3608. // If we're creating the element, we update it regardless
  3609. if ( create || !item.hasClass( "ui-li" ) ) {
  3610. itemTheme = item.jqmData("theme") || o.theme;
  3611. a = this._getChildrenByTagName( item[ 0 ], "a", "A" );
  3612. if ( a.length ) {
  3613. icon = item.jqmData("icon");
  3614. item.buttonMarkup({
  3615. wrapperEls: "div",
  3616. shadow: false,
  3617. corners: false,
  3618. iconpos: "right",
  3619. icon: a.length > 1 || icon === false ? false : icon || "arrow-r",
  3620. theme: itemTheme
  3621. });
  3622. if ( ( icon != false ) && ( a.length == 1 ) ) {
  3623. item.addClass( "ui-li-has-arrow" );
  3624. }
  3625. a.first().addClass( "ui-link-inherit" );
  3626. if ( a.length > 1 ) {
  3627. itemClass += " ui-li-has-alt";
  3628. last = a.last();
  3629. splittheme = listsplittheme || last.jqmData( "theme" ) || o.splitTheme;
  3630. last.appendTo(item)
  3631. .attr( "title", last.getEncodedText() )
  3632. .addClass( "ui-li-link-alt" )
  3633. .empty()
  3634. .buttonMarkup({
  3635. shadow: false,
  3636. corners: false,
  3637. theme: itemTheme,
  3638. icon: false,
  3639. iconpos: false
  3640. })
  3641. .find( ".ui-btn-inner" )
  3642. .append(
  3643. $( document.createElement( "span" ) ).buttonMarkup({
  3644. shadow: true,
  3645. corners: true,
  3646. theme: splittheme,
  3647. iconpos: "notext",
  3648. icon: listspliticon || last.jqmData( "icon" ) || o.splitIcon
  3649. })
  3650. );
  3651. }
  3652. } else if ( item.jqmData( "role" ) === "list-divider" ) {
  3653. itemClass += " ui-li-divider ui-btn ui-bar-" + dividertheme;
  3654. item.attr( "role", "heading" );
  3655. //reset counter when a divider heading is encountered
  3656. if ( counter ) {
  3657. counter = 1;
  3658. }
  3659. } else {
  3660. itemClass += " ui-li-static ui-body-" + itemTheme;
  3661. }
  3662. }
  3663. if ( counter && itemClass.indexOf( "ui-li-divider" ) < 0 ) {
  3664. countParent = item.is( ".ui-li-static:first" ) ? item : item.find( ".ui-link-inherit" );
  3665. countParent.addClass( "ui-li-jsnumbering" )
  3666. .prepend( "<span class='ui-li-dec'>" + (counter++) + ". </span>" );
  3667. }
  3668. // Instead of setting item class directly on the list item and its
  3669. // btn-inner at this point in time, push the item into a dictionary
  3670. // that tells us what class to set on it so we can do this after this
  3671. // processing loop is finished.
  3672. if ( !itemClassDict[ itemClass ] ) {
  3673. itemClassDict[ itemClass ] = [];
  3674. }
  3675. itemClassDict[ itemClass ].push( item[ 0 ] );
  3676. }
  3677. // Set the appropriate listview item classes on each list item
  3678. // and their btn-inner elements. The main reason we didn't do this
  3679. // in the for-loop above is because we can eliminate per-item function overhead
  3680. // by calling addClass() and children() once or twice afterwards. This
  3681. // can give us a significant boost on platforms like WP7.5.
  3682. for ( itemClass in itemClassDict ) {
  3683. $( itemClassDict[ itemClass ] ).addClass( itemClass ).children( ".ui-btn-inner" ).addClass( itemClass );
  3684. }
  3685. $list.find( "h1, h2, h3, h4, h5, h6" ).addClass( "ui-li-heading" )
  3686. .end()
  3687. .find( "p, dl" ).addClass( "ui-li-desc" )
  3688. .end()
  3689. .find( ".ui-li-aside" ).each(function() {
  3690. var $this = $(this);
  3691. $this.prependTo( $this.parent() ); //shift aside to front for css float
  3692. })
  3693. .end()
  3694. .find( ".ui-li-count" ).each( function() {
  3695. $( this ).closest( "li" ).addClass( "ui-li-has-count" );
  3696. }).addClass( "ui-btn-up-" + ( $list.jqmData( "counttheme" ) || this.options.countTheme) + " ui-btn-corner-all" );
  3697. // The idea here is to look at the first image in the list item
  3698. // itself, and any .ui-link-inherit element it may contain, so we
  3699. // can place the appropriate classes on the image and list item.
  3700. // Note that we used to use something like:
  3701. //
  3702. // li.find(">img:eq(0), .ui-link-inherit>img:eq(0)").each( ... );
  3703. //
  3704. // But executing a find() like that on Windows Phone 7.5 took a
  3705. // really long time. Walking things manually with the code below
  3706. // allows the 400 listview item page to load in about 3 seconds as
  3707. // opposed to 30 seconds.
  3708. this._addThumbClasses( li );
  3709. this._addThumbClasses( $list.find( ".ui-link-inherit" ) );
  3710. this._refreshCorners( create );
  3711. },
  3712. //create a string for ID/subpage url creation
  3713. _idStringEscape: function( str ) {
  3714. return str.replace(/[^a-zA-Z0-9]/g, '-');
  3715. },
  3716. _createSubPages: function() {
  3717. var parentList = this.element,
  3718. parentPage = parentList.closest( ".ui-page" ),
  3719. parentUrl = parentPage.jqmData( "url" ),
  3720. parentId = parentUrl || parentPage[ 0 ][ $.expando ],
  3721. parentListId = parentList.attr( "id" ),
  3722. o = this.options,
  3723. dns = "data-" + $.mobile.ns,
  3724. self = this,
  3725. persistentFooterID = parentPage.find( ":jqmData(role='footer')" ).jqmData( "id" ),
  3726. hasSubPages;
  3727. if ( typeof listCountPerPage[ parentId ] === "undefined" ) {
  3728. listCountPerPage[ parentId ] = -1;
  3729. }
  3730. parentListId = parentListId || ++listCountPerPage[ parentId ];
  3731. $( parentList.find( "li>ul, li>ol" ).toArray().reverse() ).each(function( i ) {
  3732. var self = this,
  3733. list = $( this ),
  3734. listId = list.attr( "id" ) || parentListId + "-" + i,
  3735. parent = list.parent(),
  3736. nodeEls = $( list.prevAll().toArray().reverse() ),
  3737. nodeEls = nodeEls.length ? nodeEls : $( "<span>" + $.trim(parent.contents()[ 0 ].nodeValue) + "</span>" ),
  3738. title = nodeEls.first().getEncodedText(),//url limits to first 30 chars of text
  3739. id = ( parentUrl || "" ) + "&" + $.mobile.subPageUrlKey + "=" + listId,
  3740. theme = list.jqmData( "theme" ) || o.theme,
  3741. countTheme = list.jqmData( "counttheme" ) || parentList.jqmData( "counttheme" ) || o.countTheme,
  3742. newPage, anchor;
  3743. //define hasSubPages for use in later removal
  3744. hasSubPages = true;
  3745. newPage = list.detach()
  3746. .wrap( "<div " + dns + "role='page' " + dns + "url='" + id + "' " + dns + "theme='" + theme + "' " + dns + "count-theme='" + countTheme + "'><div " + dns + "role='content'></div></div>" )
  3747. .parent()
  3748. .before( "<div " + dns + "role='header' " + dns + "theme='" + o.headerTheme + "'><div class='ui-title'>" + title + "</div></div>" )
  3749. .after( persistentFooterID ? $( "<div " + dns + "role='footer' " + dns + "id='"+ persistentFooterID +"'>") : "" )
  3750. .parent()
  3751. .appendTo( $.mobile.pageContainer );
  3752. newPage.page();
  3753. anchor = parent.find('a:first');
  3754. if ( !anchor.length ) {
  3755. anchor = $( "<a/>" ).html( nodeEls || title ).prependTo( parent.empty() );
  3756. }
  3757. anchor.attr( "href", "#" + id );
  3758. }).listview();
  3759. // on pagehide, remove any nested pages along with the parent page, as long as they aren't active
  3760. // and aren't embedded
  3761. if( hasSubPages &&
  3762. parentPage.is( ":jqmData(external-page='true')" ) &&
  3763. parentPage.data("page").options.domCache === false ) {
  3764. var newRemove = function( e, ui ){
  3765. var nextPage = ui.nextPage, npURL;
  3766. if( ui.nextPage ){
  3767. npURL = nextPage.jqmData( "url" );
  3768. if( npURL.indexOf( parentUrl + "&" + $.mobile.subPageUrlKey ) !== 0 ){
  3769. self.childPages().remove();
  3770. parentPage.remove();
  3771. }
  3772. }
  3773. };
  3774. // unbind the original page remove and replace with our specialized version
  3775. parentPage
  3776. .unbind( "pagehide.remove" )
  3777. .bind( "pagehide.remove", newRemove);
  3778. }
  3779. },
  3780. // TODO sort out a better way to track sub pages of the listview this is brittle
  3781. childPages: function(){
  3782. var parentUrl = this.parentPage.jqmData( "url" );
  3783. return $( ":jqmData(url^='"+ parentUrl + "&" + $.mobile.subPageUrlKey +"')");
  3784. }
  3785. });
  3786. //auto self-init widgets
  3787. $( document ).bind( "pagecreate create", function( e ){
  3788. $( $.mobile.listview.prototype.options.initSelector, e.target ).listview();
  3789. });
  3790. })( jQuery );
  3791. /*
  3792. * "listview" filter extension
  3793. */
  3794. (function( $, undefined ) {
  3795. $.mobile.listview.prototype.options.filter = false;
  3796. $.mobile.listview.prototype.options.filterPlaceholder = "Filter items...";
  3797. $.mobile.listview.prototype.options.filterTheme = "c";
  3798. $.mobile.listview.prototype.options.filterCallback = function( text, searchValue ){
  3799. return text.toLowerCase().indexOf( searchValue ) === -1;
  3800. };
  3801. $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function() {
  3802. var list = $( this ),
  3803. listview = list.data( "listview" );
  3804. if ( !listview.options.filter ) {
  3805. return;
  3806. }
  3807. var wrapper = $( "<form>", {
  3808. "class": "ui-listview-filter ui-bar-" + listview.options.filterTheme,
  3809. "role": "search"
  3810. }),
  3811. search = $( "<input>", {
  3812. placeholder: listview.options.filterPlaceholder
  3813. })
  3814. .attr( "data-" + $.mobile.ns + "type", "search" )
  3815. .jqmData( "lastval", "" )
  3816. .bind( "keyup change", function() {
  3817. var $this = $(this),
  3818. val = this.value.toLowerCase(),
  3819. listItems = null,
  3820. lastval = $this.jqmData( "lastval" ) + "",
  3821. childItems = false,
  3822. itemtext = "",
  3823. item;
  3824. // Change val as lastval for next execution
  3825. $this.jqmData( "lastval" , val );
  3826. if ( val.length < lastval.length || val.indexOf(lastval) !== 0 ) {
  3827. // Removed chars or pasted something totally different, check all items
  3828. listItems = list.children();
  3829. } else {
  3830. // Only chars added, not removed, only use visible subset
  3831. listItems = list.children( ":not(.ui-screen-hidden)" );
  3832. }
  3833. if ( val ) {
  3834. // This handles hiding regular rows without the text we search for
  3835. // and any list dividers without regular rows shown under it
  3836. for ( var i = listItems.length - 1; i >= 0; i-- ) {
  3837. item = $( listItems[ i ] );
  3838. itemtext = item.jqmData( "filtertext" ) || item.text();
  3839. if ( item.is( "li:jqmData(role=list-divider)" ) ) {
  3840. item.toggleClass( "ui-filter-hidequeue" , !childItems );
  3841. // New bucket!
  3842. childItems = false;
  3843. } else if ( listview.options.filterCallback( itemtext, val ) ) {
  3844. //mark to be hidden
  3845. item.toggleClass( "ui-filter-hidequeue" , true );
  3846. } else {
  3847. // There's a shown item in the bucket
  3848. childItems = true;
  3849. }
  3850. }
  3851. // Show items, not marked to be hidden
  3852. listItems
  3853. .filter( ":not(.ui-filter-hidequeue)" )
  3854. .toggleClass( "ui-screen-hidden", false );
  3855. // Hide items, marked to be hidden
  3856. listItems
  3857. .filter( ".ui-filter-hidequeue" )
  3858. .toggleClass( "ui-screen-hidden", true )
  3859. .toggleClass( "ui-filter-hidequeue", false );
  3860. } else {
  3861. //filtervalue is empty => show all
  3862. listItems.toggleClass( "ui-screen-hidden", false );
  3863. }
  3864. listview._refreshCorners();
  3865. })
  3866. .appendTo( wrapper )
  3867. .textinput();
  3868. if ( $( this ).jqmData( "inset" ) ) {
  3869. wrapper.addClass( "ui-listview-filter-inset" );
  3870. }
  3871. wrapper.bind( "submit", function() {
  3872. return false;
  3873. })
  3874. .insertBefore( list );
  3875. });
  3876. })( jQuery );/*
  3877. * "nojs" plugin - class to make elements hidden to A grade browsers
  3878. */
  3879. (function( $, undefined ) {
  3880. $( document ).bind( "pagecreate create", function( e ){
  3881. $( ":jqmData(role='nojs')", e.target ).addClass( "ui-nojs" );
  3882. });
  3883. })( jQuery );/*
  3884. * "checkboxradio" plugin
  3885. */
  3886. (function( $, undefined ) {
  3887. $.widget( "mobile.checkboxradio", $.mobile.widget, {
  3888. options: {
  3889. theme: null,
  3890. initSelector: "input[type='checkbox'],input[type='radio']"
  3891. },
  3892. _create: function() {
  3893. var self = this,
  3894. input = this.element,
  3895. // NOTE: Windows Phone could not find the label through a selector
  3896. // filter works though.
  3897. label = input.closest( "form,fieldset,:jqmData(role='page')" ).find( "label" ).filter( "[for='" + input[ 0 ].id + "']" ),
  3898. inputtype = input.attr( "type" ),
  3899. checkedState = inputtype + "-on",
  3900. uncheckedState = inputtype + "-off",
  3901. icon = input.parents( ":jqmData(type='horizontal')" ).length ? undefined : uncheckedState,
  3902. activeBtn = icon ? "" : " " + $.mobile.activeBtnClass,
  3903. checkedClass = "ui-" + checkedState + activeBtn,
  3904. uncheckedClass = "ui-" + uncheckedState,
  3905. checkedicon = "ui-icon-" + checkedState,
  3906. uncheckedicon = "ui-icon-" + uncheckedState;
  3907. if ( inputtype !== "checkbox" && inputtype !== "radio" ) {
  3908. return;
  3909. }
  3910. // Expose for other methods
  3911. $.extend( this, {
  3912. label: label,
  3913. inputtype: inputtype,
  3914. checkedClass: checkedClass,
  3915. uncheckedClass: uncheckedClass,
  3916. checkedicon: checkedicon,
  3917. uncheckedicon: uncheckedicon
  3918. });
  3919. // If there's no selected theme...
  3920. if( !this.options.theme ) {
  3921. this.options.theme = this.element.jqmData( "theme" );
  3922. }
  3923. label.buttonMarkup({
  3924. theme: this.options.theme,
  3925. icon: icon,
  3926. shadow: false
  3927. });
  3928. // Wrap the input + label in a div
  3929. input.add( label )
  3930. .wrapAll( "<div class='ui-" + inputtype + "'></div>" );
  3931. label.bind({
  3932. vmouseover: function( event ) {
  3933. if ( $( this ).parent().is( ".ui-disabled" ) ) {
  3934. event.stopPropagation();
  3935. }
  3936. },
  3937. vclick: function( event ) {
  3938. if ( input.is( ":disabled" ) ) {
  3939. event.preventDefault();
  3940. return;
  3941. }
  3942. self._cacheVals();
  3943. input.prop( "checked", inputtype === "radio" && true || !input.prop( "checked" ) );
  3944. // trigger click handler's bound directly to the input as a substitute for
  3945. // how label clicks behave normally in the browsers
  3946. // TODO: it would be nice to let the browser's handle the clicks and pass them
  3947. // through to the associate input. we can swallow that click at the parent
  3948. // wrapper element level
  3949. input.triggerHandler( 'click' );
  3950. // Input set for common radio buttons will contain all the radio
  3951. // buttons, but will not for checkboxes. clearing the checked status
  3952. // of other radios ensures the active button state is applied properly
  3953. self._getInputSet().not( input ).prop( "checked", false );
  3954. self._updateAll();
  3955. return false;
  3956. }
  3957. });
  3958. input
  3959. .bind({
  3960. vmousedown: function() {
  3961. self._cacheVals();
  3962. },
  3963. vclick: function() {
  3964. var $this = $(this);
  3965. // Adds checked attribute to checked input when keyboard is used
  3966. if ( $this.is( ":checked" ) ) {
  3967. $this.prop( "checked", true);
  3968. self._getInputSet().not($this).prop( "checked", false );
  3969. } else {
  3970. $this.prop( "checked", false );
  3971. }
  3972. self._updateAll();
  3973. },
  3974. focus: function() {
  3975. label.addClass( "ui-focus" );
  3976. },
  3977. blur: function() {
  3978. label.removeClass( "ui-focus" );
  3979. }
  3980. });
  3981. this.refresh();
  3982. },
  3983. _cacheVals: function() {
  3984. this._getInputSet().each(function() {
  3985. var $this = $(this);
  3986. $this.jqmData( "cacheVal", $this.is( ":checked" ) );
  3987. });
  3988. },
  3989. //returns either a set of radios with the same name attribute, or a single checkbox
  3990. _getInputSet: function(){
  3991. if(this.inputtype == "checkbox") {
  3992. return this.element;
  3993. }
  3994. return this.element.closest( "form,fieldset,:jqmData(role='page')" )
  3995. .find( "input[name='"+ this.element.attr( "name" ) +"'][type='"+ this.inputtype +"']" );
  3996. },
  3997. _updateAll: function() {
  3998. var self = this;
  3999. this._getInputSet().each(function() {
  4000. var $this = $(this);
  4001. if ( $this.is( ":checked" ) || self.inputtype === "checkbox" ) {
  4002. $this.trigger( "change" );
  4003. }
  4004. })
  4005. .checkboxradio( "refresh" );
  4006. },
  4007. refresh: function() {
  4008. var input = this.element,
  4009. label = this.label,
  4010. icon = label.find( ".ui-icon" );
  4011. // input[0].checked expando doesn't always report the proper value
  4012. // for checked='checked'
  4013. if ( $( input[ 0 ] ).prop( "checked" ) ) {
  4014. label.addClass( this.checkedClass ).removeClass( this.uncheckedClass );
  4015. icon.addClass( this.checkedicon ).removeClass( this.uncheckedicon );
  4016. } else {
  4017. label.removeClass( this.checkedClass ).addClass( this.uncheckedClass );
  4018. icon.removeClass( this.checkedicon ).addClass( this.uncheckedicon );
  4019. }
  4020. if ( input.is( ":disabled" ) ) {
  4021. this.disable();
  4022. } else {
  4023. this.enable();
  4024. }
  4025. },
  4026. disable: function() {
  4027. this.element.prop( "disabled", true ).parent().addClass( "ui-disabled" );
  4028. },
  4029. enable: function() {
  4030. this.element.prop( "disabled", false ).parent().removeClass( "ui-disabled" );
  4031. }
  4032. });
  4033. //auto self-init widgets
  4034. $( document ).bind( "pagecreate create", function( e ){
  4035. $.mobile.checkboxradio.prototype.enhanceWithin( e.target );
  4036. });
  4037. })( jQuery );
  4038. /*
  4039. * "button" plugin - links that proxy to native input/buttons
  4040. */
  4041. (function( $, undefined ) {
  4042. $.widget( "mobile.button", $.mobile.widget, {
  4043. options: {
  4044. theme: null,
  4045. icon: null,
  4046. iconpos: null,
  4047. inline: null,
  4048. corners: true,
  4049. shadow: true,
  4050. iconshadow: true,
  4051. initSelector: "button, [type='button'], [type='submit'], [type='reset'], [type='image']"
  4052. },
  4053. _create: function() {
  4054. var $el = this.element,
  4055. o = this.options,
  4056. type,
  4057. name,
  4058. $buttonPlaceholder;
  4059. // if this is a link, check if it's been enhanced and, if not, use the right function
  4060. if( $el[ 0 ].tagName === "A" ) {
  4061. if ( !$el.hasClass( "ui-btn" ) ) $el.buttonMarkup();
  4062. return;
  4063. }
  4064. // Add ARIA role
  4065. this.button = $( "<div></div>" )
  4066. .text( $el.text() || $el.val() )
  4067. .insertBefore( $el )
  4068. .buttonMarkup({
  4069. theme: o.theme,
  4070. icon: o.icon,
  4071. iconpos: o.iconpos,
  4072. inline: o.inline,
  4073. corners: o.corners,
  4074. shadow: o.shadow,
  4075. iconshadow: o.iconshadow
  4076. })
  4077. .append( $el.addClass( "ui-btn-hidden" ) );
  4078. type = $el.attr( "type" );
  4079. name = $el.attr( "name" );
  4080. // Add hidden input during submit if input type="submit" has a name.
  4081. if ( type !== "button" && type !== "reset" && name ) {
  4082. $el.bind( "vclick", function() {
  4083. // Add hidden input if it doesn’t already exist.
  4084. if( $buttonPlaceholder === undefined ) {
  4085. $buttonPlaceholder = $( "<input>", {
  4086. type: "hidden",
  4087. name: $el.attr( "name" ),
  4088. value: $el.attr( "value" )
  4089. }).insertBefore( $el );
  4090. // Bind to doc to remove after submit handling
  4091. $( document ).one("submit", function(){
  4092. $buttonPlaceholder.remove();
  4093. // reset the local var so that the hidden input
  4094. // will be re-added on subsequent clicks
  4095. $buttonPlaceholder = undefined;
  4096. });
  4097. }
  4098. });
  4099. }
  4100. this.refresh();
  4101. },
  4102. enable: function() {
  4103. this.element.attr( "disabled", false );
  4104. this.button.removeClass( "ui-disabled" ).attr( "aria-disabled", false );
  4105. return this._setOption( "disabled", false );
  4106. },
  4107. disable: function() {
  4108. this.element.attr( "disabled", true );
  4109. this.button.addClass( "ui-disabled" ).attr( "aria-disabled", true );
  4110. return this._setOption( "disabled", true );
  4111. },
  4112. refresh: function() {
  4113. var $el = this.element;
  4114. if ( $el.prop("disabled") ) {
  4115. this.disable();
  4116. } else {
  4117. this.enable();
  4118. }
  4119. // the textWrapper is stored as a data element on the button object
  4120. // to prevent referencing by it's implementation details (eg 'class')
  4121. this.button.data( 'textWrapper' ).text( $el.text() || $el.val() );
  4122. }
  4123. });
  4124. //auto self-init widgets
  4125. $( document ).bind( "pagecreate create", function( e ){
  4126. $.mobile.button.prototype.enhanceWithin( e.target );
  4127. });
  4128. })( jQuery );/*
  4129. * "slider" plugin
  4130. */
  4131. ( function( $, undefined ) {
  4132. $.widget( "mobile.slider", $.mobile.widget, {
  4133. options: {
  4134. theme: null,
  4135. trackTheme: null,
  4136. disabled: false,
  4137. initSelector: "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')"
  4138. },
  4139. _create: function() {
  4140. // TODO: Each of these should have comments explain what they're for
  4141. var self = this,
  4142. control = this.element,
  4143. parentTheme = $.mobile.getInheritedTheme( control, "c" ),
  4144. theme = this.options.theme || parentTheme,
  4145. trackTheme = this.options.trackTheme || parentTheme,
  4146. cType = control[ 0 ].nodeName.toLowerCase(),
  4147. selectClass = ( cType == "select" ) ? "ui-slider-switch" : "",
  4148. controlID = control.attr( "id" ),
  4149. labelID = controlID + "-label",
  4150. label = $( "[for='"+ controlID +"']" ).attr( "id", labelID ),
  4151. val = function() {
  4152. return cType == "input" ? parseFloat( control.val() ) : control[0].selectedIndex;
  4153. },
  4154. min = cType == "input" ? parseFloat( control.attr( "min" ) ) : 0,
  4155. max = cType == "input" ? parseFloat( control.attr( "max" ) ) : control.find( "option" ).length-1,
  4156. step = window.parseFloat( control.attr( "step" ) || 1 ),
  4157. slider = $( "<div class='ui-slider " + selectClass + " ui-btn-down-" + trackTheme +
  4158. " ui-btn-corner-all' role='application'></div>" ),
  4159. handle = $( "<a href='#' class='ui-slider-handle'></a>" )
  4160. .appendTo( slider )
  4161. .buttonMarkup({ corners: true, theme: theme, shadow: true })
  4162. .attr({
  4163. "role": "slider",
  4164. "aria-valuemin": min,
  4165. "aria-valuemax": max,
  4166. "aria-valuenow": val(),
  4167. "aria-valuetext": val(),
  4168. "title": val(),
  4169. "aria-labelledby": labelID
  4170. }),
  4171. options;
  4172. $.extend( this, {
  4173. slider: slider,
  4174. handle: handle,
  4175. dragging: false,
  4176. beforeStart: null,
  4177. userModified: false,
  4178. mouseMoved: false
  4179. });
  4180. if ( cType == "select" ) {
  4181. slider.wrapInner( "<div class='ui-slider-inneroffset'></div>" );
  4182. // make the handle move with a smooth transition
  4183. handle.addClass( "ui-slider-handle-snapping" );
  4184. options = control.find( "option" );
  4185. control.find( "option" ).each(function( i ) {
  4186. var side = !i ? "b":"a",
  4187. corners = !i ? "right" :"left",
  4188. theme = !i ? " ui-btn-down-" + trackTheme :( " " + $.mobile.activeBtnClass );
  4189. $( "<div class='ui-slider-labelbg ui-slider-labelbg-" + side + theme + " ui-btn-corner-" + corners + "'></div>" )
  4190. .prependTo( slider );
  4191. $( "<span class='ui-slider-label ui-slider-label-" + side + theme + " ui-btn-corner-" + corners + "' role='img'>" + $( this ).getEncodedText() + "</span>" )
  4192. .prependTo( handle );
  4193. });
  4194. }
  4195. label.addClass( "ui-slider" );
  4196. // monitor the input for updated values
  4197. control.addClass( cType === "input" ? "ui-slider-input" : "ui-slider-switch" )
  4198. .change( function() {
  4199. // if the user dragged the handle, the "change" event was triggered from inside refresh(); don't call refresh() again
  4200. if (!self.mouseMoved) {
  4201. self.refresh( val(), true );
  4202. }
  4203. })
  4204. .keyup( function() { // necessary?
  4205. self.refresh( val(), true, true );
  4206. })
  4207. .blur( function() {
  4208. self.refresh( val(), true );
  4209. });
  4210. // prevent screen drag when slider activated
  4211. $( document ).bind( "vmousemove", function( event ) {
  4212. if ( self.dragging ) {
  4213. // self.mouseMoved must be updated before refresh() because it will be used in the control "change" event
  4214. self.mouseMoved = true;
  4215. if ( cType === "select" ) {
  4216. // make the handle move in sync with the mouse
  4217. handle.removeClass( "ui-slider-handle-snapping" );
  4218. }
  4219. self.refresh( event );
  4220. // only after refresh() you can calculate self.userModified
  4221. self.userModified = self.beforeStart !== control[0].selectedIndex;
  4222. return false;
  4223. }
  4224. });
  4225. slider.bind( "vmousedown", function( event ) {
  4226. self.dragging = true;
  4227. self.userModified = false;
  4228. self.mouseMoved = false;
  4229. if ( cType === "select" ) {
  4230. self.beforeStart = control[0].selectedIndex;
  4231. }
  4232. self.refresh( event );
  4233. return false;
  4234. });
  4235. slider.add( document )
  4236. .bind( "vmouseup", function() {
  4237. if ( self.dragging ) {
  4238. self.dragging = false;
  4239. if ( cType === "select") {
  4240. // make the handle move with a smooth transition
  4241. handle.addClass( "ui-slider-handle-snapping" );
  4242. if ( self.mouseMoved ) {
  4243. // this is a drag, change the value only if user dragged enough
  4244. if ( self.userModified ) {
  4245. self.refresh( self.beforeStart == 0 ? 1 : 0 );
  4246. }
  4247. else {
  4248. self.refresh( self.beforeStart );
  4249. }
  4250. }
  4251. else {
  4252. // this is just a click, change the value
  4253. self.refresh( self.beforeStart == 0 ? 1 : 0 );
  4254. }
  4255. }
  4256. self.mouseMoved = false;
  4257. return false;
  4258. }
  4259. });
  4260. slider.insertAfter( control );
  4261. // NOTE force focus on handle
  4262. this.handle
  4263. .bind( "vmousedown", function() {
  4264. $( this ).focus();
  4265. })
  4266. .bind( "vclick", false );
  4267. this.handle
  4268. .bind( "keydown", function( event ) {
  4269. var index = val();
  4270. if ( self.options.disabled ) {
  4271. return;
  4272. }
  4273. // In all cases prevent the default and mark the handle as active
  4274. switch ( event.keyCode ) {
  4275. case $.mobile.keyCode.HOME:
  4276. case $.mobile.keyCode.END:
  4277. case $.mobile.keyCode.PAGE_UP:
  4278. case $.mobile.keyCode.PAGE_DOWN:
  4279. case $.mobile.keyCode.UP:
  4280. case $.mobile.keyCode.RIGHT:
  4281. case $.mobile.keyCode.DOWN:
  4282. case $.mobile.keyCode.LEFT:
  4283. event.preventDefault();
  4284. if ( !self._keySliding ) {
  4285. self._keySliding = true;
  4286. $( this ).addClass( "ui-state-active" );
  4287. }
  4288. break;
  4289. }
  4290. // move the slider according to the keypress
  4291. switch ( event.keyCode ) {
  4292. case $.mobile.keyCode.HOME:
  4293. self.refresh( min );
  4294. break;
  4295. case $.mobile.keyCode.END:
  4296. self.refresh( max );
  4297. break;
  4298. case $.mobile.keyCode.PAGE_UP:
  4299. case $.mobile.keyCode.UP:
  4300. case $.mobile.keyCode.RIGHT:
  4301. self.refresh( index + step );
  4302. break;
  4303. case $.mobile.keyCode.PAGE_DOWN:
  4304. case $.mobile.keyCode.DOWN:
  4305. case $.mobile.keyCode.LEFT:
  4306. self.refresh( index - step );
  4307. break;
  4308. }
  4309. }) // remove active mark
  4310. .keyup( function( event ) {
  4311. if ( self._keySliding ) {
  4312. self._keySliding = false;
  4313. $( this ).removeClass( "ui-state-active" );
  4314. }
  4315. });
  4316. this.refresh(undefined, undefined, true);
  4317. },
  4318. refresh: function( val, isfromControl, preventInputUpdate ) {
  4319. if ( this.options.disabled || this.element.attr('disabled')) {
  4320. this.disable();
  4321. }
  4322. var control = this.element, percent,
  4323. cType = control[0].nodeName.toLowerCase(),
  4324. min = cType === "input" ? parseFloat( control.attr( "min" ) ) : 0,
  4325. max = cType === "input" ? parseFloat( control.attr( "max" ) ) : control.find( "option" ).length - 1,
  4326. step = (cType === "input" && parseFloat( control.attr( "step" ) ) > 0) ? parseFloat(control.attr("step")) : 1;
  4327. if ( typeof val === "object" ) {
  4328. var data = val,
  4329. // a slight tolerance helped get to the ends of the slider
  4330. tol = 8;
  4331. if ( !this.dragging ||
  4332. data.pageX < this.slider.offset().left - tol ||
  4333. data.pageX > this.slider.offset().left + this.slider.width() + tol ) {
  4334. return;
  4335. }
  4336. percent = Math.round( ( ( data.pageX - this.slider.offset().left ) / this.slider.width() ) * 100 );
  4337. } else {
  4338. if ( val == null ) {
  4339. val = cType === "input" ? parseFloat( control.val() || 0 ) : control[0].selectedIndex;
  4340. }
  4341. percent = ( parseFloat( val ) - min ) / ( max - min ) * 100;
  4342. }
  4343. if ( isNaN( percent ) ) {
  4344. return;
  4345. }
  4346. if ( percent < 0 ) {
  4347. percent = 0;
  4348. }
  4349. if ( percent > 100 ) {
  4350. percent = 100;
  4351. }
  4352. var newval = ( percent / 100 ) * ( max - min ) + min;
  4353. //from jQuery UI slider, the following source will round to the nearest step
  4354. var valModStep = ( newval - min ) % step;
  4355. var alignValue = newval - valModStep;
  4356. if ( Math.abs( valModStep ) * 2 >= step ) {
  4357. alignValue += ( valModStep > 0 ) ? step : ( -step );
  4358. }
  4359. // Since JavaScript has problems with large floats, round
  4360. // the final value to 5 digits after the decimal point (see jQueryUI: #4124)
  4361. newval = parseFloat( alignValue.toFixed(5) );
  4362. if ( newval < min ) {
  4363. newval = min;
  4364. }
  4365. if ( newval > max ) {
  4366. newval = max;
  4367. }
  4368. this.handle.css( "left", percent + "%" );
  4369. this.handle.attr( {
  4370. "aria-valuenow": cType === "input" ? newval : control.find( "option" ).eq( newval ).attr( "value" ),
  4371. "aria-valuetext": cType === "input" ? newval : control.find( "option" ).eq( newval ).getEncodedText(),
  4372. title: cType === "input" ? newval : control.find( "option" ).eq( newval ).getEncodedText()
  4373. });
  4374. // add/remove classes for flip toggle switch
  4375. if ( cType === "select" ) {
  4376. if ( newval === 0 ) {
  4377. this.slider.addClass( "ui-slider-switch-a" )
  4378. .removeClass( "ui-slider-switch-b" );
  4379. } else {
  4380. this.slider.addClass( "ui-slider-switch-b" )
  4381. .removeClass( "ui-slider-switch-a" );
  4382. }
  4383. }
  4384. if ( !preventInputUpdate ) {
  4385. var valueChanged = false;
  4386. // update control"s value
  4387. if ( cType === "input" ) {
  4388. valueChanged = control.val() !== newval;
  4389. control.val( newval );
  4390. } else {
  4391. valueChanged = control[ 0 ].selectedIndex !== newval;
  4392. control[ 0 ].selectedIndex = newval;
  4393. }
  4394. if ( !isfromControl && valueChanged ) {
  4395. control.trigger( "change" );
  4396. }
  4397. }
  4398. },
  4399. enable: function() {
  4400. this.element.attr( "disabled", false );
  4401. this.slider.removeClass( "ui-disabled" ).attr( "aria-disabled", false );
  4402. return this._setOption( "disabled", false );
  4403. },
  4404. disable: function() {
  4405. this.element.attr( "disabled", true );
  4406. this.slider.addClass( "ui-disabled" ).attr( "aria-disabled", true );
  4407. return this._setOption( "disabled", true );
  4408. }
  4409. });
  4410. //auto self-init widgets
  4411. $( document ).bind( "pagecreate create", function( e ){
  4412. $.mobile.slider.prototype.enhanceWithin( e.target );
  4413. });
  4414. })( jQuery );
  4415. /*
  4416. * "textinput" plugin for text inputs, textareas
  4417. */
  4418. (function( $, undefined ) {
  4419. $.widget( "mobile.textinput", $.mobile.widget, {
  4420. options: {
  4421. theme: null,
  4422. initSelector: "input[type='text'], input[type='search'], :jqmData(type='search'), input[type='number'], :jqmData(type='number'), input[type='password'], input[type='email'], input[type='url'], input[type='tel'], textarea, input[type='time'], input[type='date'], input[type='month'], input[type='week'], input[type='datetime'], input[type='datetime-local'], input[type='color'], input:not([type])"
  4423. },
  4424. _create: function() {
  4425. var input = this.element,
  4426. o = this.options,
  4427. theme = o.theme || $.mobile.getInheritedTheme( this.element, "c" ),
  4428. themeclass = " ui-body-" + theme,
  4429. focusedEl, clearbtn;
  4430. $( "label[for='" + input.attr( "id" ) + "']" ).addClass( "ui-input-text" );
  4431. focusedEl = input.addClass("ui-input-text ui-body-"+ theme );
  4432. // XXX: Temporary workaround for issue 785 (Apple bug 8910589).
  4433. // Turn off autocorrect and autocomplete on non-iOS 5 devices
  4434. // since the popup they use can't be dismissed by the user. Note
  4435. // that we test for the presence of the feature by looking for
  4436. // the autocorrect property on the input element. We currently
  4437. // have no test for iOS 5 or newer so we're temporarily using
  4438. // the touchOverflow support flag for jQM 1.0. Yes, I feel dirty. - jblas
  4439. if ( typeof input[0].autocorrect !== "undefined" && !$.support.touchOverflow ) {
  4440. // Set the attribute instead of the property just in case there
  4441. // is code that attempts to make modifications via HTML.
  4442. input[0].setAttribute( "autocorrect", "off" );
  4443. input[0].setAttribute( "autocomplete", "off" );
  4444. }
  4445. //"search" input widget
  4446. if ( input.is( "[type='search'],:jqmData(type='search')" ) ) {
  4447. focusedEl = input.wrap( "<div class='ui-input-search ui-shadow-inset ui-btn-corner-all ui-btn-shadow ui-icon-searchfield" + themeclass + "'></div>" ).parent();
  4448. clearbtn = $( "<a href='#' class='ui-input-clear' title='clear text'>clear text</a>" )
  4449. .tap(function( event ) {
  4450. input.val( "" ).focus();
  4451. input.trigger( "change" );
  4452. clearbtn.addClass( "ui-input-clear-hidden" );
  4453. event.preventDefault();
  4454. })
  4455. .appendTo( focusedEl )
  4456. .buttonMarkup({
  4457. icon: "delete",
  4458. iconpos: "notext",
  4459. corners: true,
  4460. shadow: true
  4461. });
  4462. function toggleClear() {
  4463. setTimeout(function() {
  4464. clearbtn.toggleClass( "ui-input-clear-hidden", !input.val() );
  4465. }, 0);
  4466. }
  4467. toggleClear();
  4468. input.bind('paste cut keyup focus change blur', toggleClear);
  4469. } else {
  4470. input.addClass( "ui-corner-all ui-shadow-inset" + themeclass );
  4471. }
  4472. input.focus(function() {
  4473. focusedEl.addClass( "ui-focus" );
  4474. })
  4475. .blur(function(){
  4476. focusedEl.removeClass( "ui-focus" );
  4477. });
  4478. // Autogrow
  4479. if ( input.is( "textarea" ) ) {
  4480. var extraLineHeight = 15,
  4481. keyupTimeoutBuffer = 100,
  4482. keyup = function() {
  4483. var scrollHeight = input[ 0 ].scrollHeight,
  4484. clientHeight = input[ 0 ].clientHeight;
  4485. if ( clientHeight < scrollHeight ) {
  4486. input.height(scrollHeight + extraLineHeight);
  4487. }
  4488. },
  4489. keyupTimeout;
  4490. input.keyup(function() {
  4491. clearTimeout( keyupTimeout );
  4492. keyupTimeout = setTimeout( keyup, keyupTimeoutBuffer );
  4493. });
  4494. // binding to pagechange here ensures that for pages loaded via
  4495. // ajax the height is recalculated without user input
  4496. $( document ).one( "pagechange", keyup );
  4497. // Issue 509: the browser is not providing scrollHeight properly until the styles load
  4498. if ( $.trim( input.val() ) ) {
  4499. // bind to the window load to make sure the height is calculated based on BOTH
  4500. // the DOM and CSS
  4501. $( window ).load( keyup );
  4502. }
  4503. }
  4504. },
  4505. disable: function(){
  4506. ( this.element.attr( "disabled", true ).is( "[type='search'],:jqmData(type='search')" ) ?
  4507. this.element.parent() : this.element ).addClass( "ui-disabled" );
  4508. },
  4509. enable: function(){
  4510. ( this.element.attr( "disabled", false).is( "[type='search'],:jqmData(type='search')" ) ?
  4511. this.element.parent() : this.element ).removeClass( "ui-disabled" );
  4512. }
  4513. });
  4514. //auto self-init widgets
  4515. $( document ).bind( "pagecreate create", function( e ){
  4516. $.mobile.textinput.prototype.enhanceWithin( e.target );
  4517. });
  4518. })( jQuery );
  4519. /*
  4520. * custom "selectmenu" plugin
  4521. */
  4522. (function( $, undefined ) {
  4523. var extendSelect = function( widget ){
  4524. var select = widget.select,
  4525. selectID = widget.selectID,
  4526. label = widget.label,
  4527. thisPage = widget.select.closest( ".ui-page" ),
  4528. screen = $( "<div>", {"class": "ui-selectmenu-screen ui-screen-hidden"} ).appendTo( thisPage ),
  4529. selectOptions = widget._selectOptions(),
  4530. isMultiple = widget.isMultiple = widget.select[ 0 ].multiple,
  4531. buttonId = selectID + "-button",
  4532. menuId = selectID + "-menu",
  4533. menuPage = $( "<div data-" + $.mobile.ns + "role='dialog' data-" +$.mobile.ns + "theme='"+ widget.options.theme +"' data-" +$.mobile.ns + "overlay-theme='"+ widget.options.overlayTheme +"'>" +
  4534. "<div data-" + $.mobile.ns + "role='header'>" +
  4535. "<div class='ui-title'>" + label.getEncodedText() + "</div>"+
  4536. "</div>"+
  4537. "<div data-" + $.mobile.ns + "role='content'></div>"+
  4538. "</div>" ).appendTo( $.mobile.pageContainer ).page(),
  4539. listbox = $("<div>", { "class": "ui-selectmenu ui-selectmenu-hidden ui-overlay-shadow ui-corner-all ui-body-" + widget.options.overlayTheme + " " + $.mobile.defaultDialogTransition } ).insertAfter(screen),
  4540. list = $( "<ul>", {
  4541. "class": "ui-selectmenu-list",
  4542. "id": menuId,
  4543. "role": "listbox",
  4544. "aria-labelledby": buttonId
  4545. }).attr( "data-" + $.mobile.ns + "theme", widget.options.theme ).appendTo( listbox ),
  4546. header = $( "<div>", {
  4547. "class": "ui-header ui-bar-" + widget.options.theme
  4548. }).prependTo( listbox ),
  4549. headerTitle = $( "<h1>", {
  4550. "class": "ui-title"
  4551. }).appendTo( header ),
  4552. headerClose = $( "<a>", {
  4553. "text": widget.options.closeText,
  4554. "href": "#",
  4555. "class": "ui-btn-left"
  4556. }).attr( "data-" + $.mobile.ns + "iconpos", "notext" ).attr( "data-" + $.mobile.ns + "icon", "delete" ).appendTo( header ).buttonMarkup(),
  4557. menuPageContent = menuPage.find( ".ui-content" ),
  4558. menuPageClose = menuPage.find( ".ui-header a" );
  4559. $.extend( widget, {
  4560. select: widget.select,
  4561. selectID: selectID,
  4562. buttonId: buttonId,
  4563. menuId: menuId,
  4564. thisPage: thisPage,
  4565. menuPage: menuPage,
  4566. label: label,
  4567. screen: screen,
  4568. selectOptions: selectOptions,
  4569. isMultiple: isMultiple,
  4570. theme: widget.options.theme,
  4571. listbox: listbox,
  4572. list: list,
  4573. header: header,
  4574. headerTitle: headerTitle,
  4575. headerClose: headerClose,
  4576. menuPageContent: menuPageContent,
  4577. menuPageClose: menuPageClose,
  4578. placeholder: "",
  4579. build: function() {
  4580. var self = this;
  4581. // Create list from select, update state
  4582. self.refresh();
  4583. self.select.attr( "tabindex", "-1" ).focus(function() {
  4584. $( this ).blur();
  4585. self.button.focus();
  4586. });
  4587. // Button events
  4588. self.button.bind( "vclick keydown" , function( event ) {
  4589. if ( event.type == "vclick" ||
  4590. event.keyCode && ( event.keyCode === $.mobile.keyCode.ENTER ||
  4591. event.keyCode === $.mobile.keyCode.SPACE ) ) {
  4592. self.open();
  4593. event.preventDefault();
  4594. }
  4595. });
  4596. // Events for list items
  4597. self.list.attr( "role", "listbox" )
  4598. .delegate( ".ui-li>a", "focusin", function() {
  4599. $( this ).attr( "tabindex", "0" );
  4600. })
  4601. .delegate( ".ui-li>a", "focusout", function() {
  4602. $( this ).attr( "tabindex", "-1" );
  4603. })
  4604. .delegate( "li:not(.ui-disabled, .ui-li-divider)", "click", function( event ) {
  4605. // index of option tag to be selected
  4606. var oldIndex = self.select[ 0 ].selectedIndex,
  4607. newIndex = self.list.find( "li:not(.ui-li-divider)" ).index( this ),
  4608. option = self._selectOptions().eq( newIndex )[ 0 ];
  4609. // toggle selected status on the tag for multi selects
  4610. option.selected = self.isMultiple ? !option.selected : true;
  4611. // toggle checkbox class for multiple selects
  4612. if ( self.isMultiple ) {
  4613. $( this ).find( ".ui-icon" )
  4614. .toggleClass( "ui-icon-checkbox-on", option.selected )
  4615. .toggleClass( "ui-icon-checkbox-off", !option.selected );
  4616. }
  4617. // trigger change if value changed
  4618. if ( self.isMultiple || oldIndex !== newIndex ) {
  4619. self.select.trigger( "change" );
  4620. }
  4621. //hide custom select for single selects only
  4622. if ( !self.isMultiple ) {
  4623. self.close();
  4624. }
  4625. event.preventDefault();
  4626. })
  4627. .keydown(function( event ) { //keyboard events for menu items
  4628. var target = $( event.target ),
  4629. li = target.closest( "li" ),
  4630. prev, next;
  4631. // switch logic based on which key was pressed
  4632. switch ( event.keyCode ) {
  4633. // up or left arrow keys
  4634. case 38:
  4635. prev = li.prev();
  4636. // if there's a previous option, focus it
  4637. if ( prev.length ) {
  4638. target
  4639. .blur()
  4640. .attr( "tabindex", "-1" );
  4641. prev.find( "a" ).first().focus();
  4642. }
  4643. return false;
  4644. break;
  4645. // down or right arrow keys
  4646. case 40:
  4647. next = li.next();
  4648. // if there's a next option, focus it
  4649. if ( next.length ) {
  4650. target
  4651. .blur()
  4652. .attr( "tabindex", "-1" );
  4653. next.find( "a" ).first().focus();
  4654. }
  4655. return false;
  4656. break;
  4657. // If enter or space is pressed, trigger click
  4658. case 13:
  4659. case 32:
  4660. target.trigger( "click" );
  4661. return false;
  4662. break;
  4663. }
  4664. });
  4665. // button refocus ensures proper height calculation
  4666. // by removing the inline style and ensuring page inclusion
  4667. self.menuPage.bind( "pagehide", function() {
  4668. self.list.appendTo( self.listbox );
  4669. self._focusButton();
  4670. // TODO centralize page removal binding / handling in the page plugin.
  4671. // Suggestion from @jblas to do refcounting
  4672. //
  4673. // TODO extremely confusing dependency on the open method where the pagehide.remove
  4674. // bindings are stripped to prevent the parent page from disappearing. The way
  4675. // we're keeping pages in the DOM right now sucks
  4676. //
  4677. // rebind the page remove that was unbound in the open function
  4678. // to allow for the parent page removal from actions other than the use
  4679. // of a dialog sized custom select
  4680. //
  4681. // doing this here provides for the back button on the custom select dialog
  4682. $.mobile._bindPageRemove.call( self.thisPage );
  4683. });
  4684. // Events on "screen" overlay
  4685. self.screen.bind( "vclick", function( event ) {
  4686. self.close();
  4687. });
  4688. // Close button on small overlays
  4689. self.headerClose.click( function() {
  4690. if ( self.menuType == "overlay" ) {
  4691. self.close();
  4692. return false;
  4693. }
  4694. });
  4695. // track this dependency so that when the parent page
  4696. // is removed on pagehide it will also remove the menupage
  4697. self.thisPage.addDependents( this.menuPage );
  4698. },
  4699. _isRebuildRequired: function() {
  4700. var list = this.list.find( "li" ),
  4701. options = this._selectOptions();
  4702. // TODO exceedingly naive method to determine difference
  4703. // ignores value changes etc in favor of a forcedRebuild
  4704. // from the user in the refresh method
  4705. return options.text() !== list.text();
  4706. },
  4707. refresh: function( forceRebuild , foo ){
  4708. var self = this,
  4709. select = this.element,
  4710. isMultiple = this.isMultiple,
  4711. options = this._selectOptions(),
  4712. selected = this.selected(),
  4713. // return an array of all selected index's
  4714. indicies = this.selectedIndices();
  4715. if ( forceRebuild || this._isRebuildRequired() ) {
  4716. self._buildList();
  4717. }
  4718. self.setButtonText();
  4719. self.setButtonCount();
  4720. self.list.find( "li:not(.ui-li-divider)" )
  4721. .removeClass( $.mobile.activeBtnClass )
  4722. .attr( "aria-selected", false )
  4723. .each(function( i ) {
  4724. if ( $.inArray( i, indicies ) > -1 ) {
  4725. var item = $( this );
  4726. // Aria selected attr
  4727. item.attr( "aria-selected", true );
  4728. // Multiple selects: add the "on" checkbox state to the icon
  4729. if ( self.isMultiple ) {
  4730. item.find( ".ui-icon" ).removeClass( "ui-icon-checkbox-off" ).addClass( "ui-icon-checkbox-on" );
  4731. } else {
  4732. item.addClass( $.mobile.activeBtnClass );
  4733. }
  4734. }
  4735. });
  4736. },
  4737. close: function() {
  4738. if ( this.options.disabled || !this.isOpen ) {
  4739. return;
  4740. }
  4741. var self = this;
  4742. if ( self.menuType == "page" ) {
  4743. // doesn't solve the possible issue with calling change page
  4744. // where the objects don't define data urls which prevents dialog key
  4745. // stripping - changePage has incoming refactor
  4746. window.history.back();
  4747. } else {
  4748. self.screen.addClass( "ui-screen-hidden" );
  4749. self.listbox.addClass( "ui-selectmenu-hidden" ).removeAttr( "style" ).removeClass( "in" );
  4750. self.list.appendTo( self.listbox );
  4751. self._focusButton();
  4752. }
  4753. // allow the dialog to be closed again
  4754. self.isOpen = false;
  4755. },
  4756. open: function() {
  4757. if ( this.options.disabled ) {
  4758. return;
  4759. }
  4760. var self = this,
  4761. menuHeight = self.list.parent().outerHeight(),
  4762. menuWidth = self.list.parent().outerWidth(),
  4763. activePage = $( ".ui-page-active" ),
  4764. tOverflow = $.support.touchOverflow && $.mobile.touchOverflowEnabled,
  4765. tScrollElem = activePage.is( ".ui-native-fixed" ) ? activePage.find( ".ui-content" ) : activePage,
  4766. scrollTop = tOverflow ? tScrollElem.scrollTop() : $( window ).scrollTop(),
  4767. btnOffset = self.button.offset().top,
  4768. screenHeight = $(window).height(),
  4769. screenWidth = $(window).width();
  4770. //add active class to button
  4771. self.button.addClass( $.mobile.activeBtnClass );
  4772. //remove after delay
  4773. setTimeout( function() {
  4774. self.button.removeClass( $.mobile.activeBtnClass );
  4775. }, 300);
  4776. function focusMenuItem() {
  4777. self.list.find( $.mobile.activeBtnClass ).focus();
  4778. }
  4779. if ( menuHeight > screenHeight - 80 || !$.support.scrollTop ) {
  4780. // prevent the parent page from being removed from the DOM,
  4781. // otherwise the results of selecting a list item in the dialog
  4782. // fall into a black hole
  4783. self.thisPage.unbind( "pagehide.remove" );
  4784. //for WebOS/Opera Mini (set lastscroll using button offset)
  4785. if ( scrollTop == 0 && btnOffset > screenHeight ) {
  4786. self.thisPage.one( "pagehide", function() {
  4787. $( this ).jqmData( "lastScroll", btnOffset );
  4788. });
  4789. }
  4790. self.menuPage.one( "pageshow", function() {
  4791. // silentScroll() is called whenever a page is shown to restore
  4792. // any previous scroll position the page may have had. We need to
  4793. // wait for the "silentscroll" event before setting focus to avoid
  4794. // the browser"s "feature" which offsets rendering to make sure
  4795. // whatever has focus is in view.
  4796. $( window ).one( "silentscroll", function() {
  4797. focusMenuItem();
  4798. });
  4799. self.isOpen = true;
  4800. });
  4801. self.menuType = "page";
  4802. self.menuPageContent.append( self.list );
  4803. self.menuPage.find("div .ui-title").text(self.label.text());
  4804. $.mobile.changePage( self.menuPage, {
  4805. transition: $.mobile.defaultDialogTransition
  4806. });
  4807. } else {
  4808. self.menuType = "overlay";
  4809. self.screen.height( $(document).height() )
  4810. .removeClass( "ui-screen-hidden" );
  4811. // Try and center the overlay over the button
  4812. var roomtop = btnOffset - scrollTop,
  4813. roombot = scrollTop + screenHeight - btnOffset,
  4814. halfheight = menuHeight / 2,
  4815. maxwidth = parseFloat( self.list.parent().css( "max-width" ) ),
  4816. newtop, newleft;
  4817. if ( roomtop > menuHeight / 2 && roombot > menuHeight / 2 ) {
  4818. newtop = btnOffset + ( self.button.outerHeight() / 2 ) - halfheight;
  4819. } else {
  4820. // 30px tolerance off the edges
  4821. newtop = roomtop > roombot ? scrollTop + screenHeight - menuHeight - 30 : scrollTop + 30;
  4822. }
  4823. // If the menuwidth is smaller than the screen center is
  4824. if ( menuWidth < maxwidth ) {
  4825. newleft = ( screenWidth - menuWidth ) / 2;
  4826. } else {
  4827. //otherwise insure a >= 30px offset from the left
  4828. newleft = self.button.offset().left + self.button.outerWidth() / 2 - menuWidth / 2;
  4829. // 30px tolerance off the edges
  4830. if ( newleft < 30 ) {
  4831. newleft = 30;
  4832. } else if ( (newleft + menuWidth) > screenWidth ) {
  4833. newleft = screenWidth - menuWidth - 30;
  4834. }
  4835. }
  4836. self.listbox.append( self.list )
  4837. .removeClass( "ui-selectmenu-hidden" )
  4838. .css({
  4839. top: newtop,
  4840. left: newleft
  4841. })
  4842. .addClass( "in" );
  4843. focusMenuItem();
  4844. // duplicate with value set in page show for dialog sized selects
  4845. self.isOpen = true;
  4846. }
  4847. },
  4848. _buildList: function() {
  4849. var self = this,
  4850. o = this.options,
  4851. placeholder = this.placeholder,
  4852. optgroups = [],
  4853. lis = [],
  4854. dataIcon = self.isMultiple ? "checkbox-off" : "false";
  4855. self.list.empty().filter( ".ui-listview" ).listview( "destroy" );
  4856. // Populate menu with options from select element
  4857. self.select.find( "option" ).each( function( i ) {
  4858. var $this = $( this ),
  4859. $parent = $this.parent(),
  4860. text = $this.getEncodedText(),
  4861. anchor = "<a href='#'>"+ text +"</a>",
  4862. classes = [],
  4863. extraAttrs = [];
  4864. // Are we inside an optgroup?
  4865. if ( $parent.is( "optgroup" ) ) {
  4866. var optLabel = $parent.attr( "label" );
  4867. // has this optgroup already been built yet?
  4868. if ( $.inArray( optLabel, optgroups ) === -1 ) {
  4869. lis.push( "<li data-" + $.mobile.ns + "role='list-divider'>"+ optLabel +"</li>" );
  4870. optgroups.push( optLabel );
  4871. }
  4872. }
  4873. // Find placeholder text
  4874. // TODO: Are you sure you want to use getAttribute? ^RW
  4875. if ( !this.getAttribute( "value" ) || text.length == 0 || $this.jqmData( "placeholder" ) ) {
  4876. if ( o.hidePlaceholderMenuItems ) {
  4877. classes.push( "ui-selectmenu-placeholder" );
  4878. }
  4879. placeholder = self.placeholder = text;
  4880. }
  4881. // support disabled option tags
  4882. if ( this.disabled ) {
  4883. classes.push( "ui-disabled" );
  4884. extraAttrs.push( "aria-disabled='true'" );
  4885. }
  4886. lis.push( "<li data-" + $.mobile.ns + "option-index='" + i + "' data-" + $.mobile.ns + "icon='"+ dataIcon +"' class='"+ classes.join(" ") + "' " + extraAttrs.join(" ") +">"+ anchor +"</li>" );
  4887. });
  4888. self.list.html( lis.join(" ") );
  4889. self.list.find( "li" )
  4890. .attr({ "role": "option", "tabindex": "-1" })
  4891. .first().attr( "tabindex", "0" );
  4892. // Hide header close link for single selects
  4893. if ( !this.isMultiple ) {
  4894. this.headerClose.hide();
  4895. }
  4896. // Hide header if it's not a multiselect and there's no placeholder
  4897. if ( !this.isMultiple && !placeholder.length ) {
  4898. this.header.hide();
  4899. } else {
  4900. this.headerTitle.text( this.placeholder );
  4901. }
  4902. // Now populated, create listview
  4903. self.list.listview();
  4904. },
  4905. _button: function(){
  4906. return $( "<a>", {
  4907. "href": "#",
  4908. "role": "button",
  4909. // TODO value is undefined at creation
  4910. "id": this.buttonId,
  4911. "aria-haspopup": "true",
  4912. // TODO value is undefined at creation
  4913. "aria-owns": this.menuId
  4914. });
  4915. }
  4916. });
  4917. };
  4918. $( document ).delegate( "select", "selectmenubeforecreate", function(){
  4919. var selectmenuWidget = $( this ).data( "selectmenu" );
  4920. if( !selectmenuWidget.options.nativeMenu ){
  4921. extendSelect( selectmenuWidget );
  4922. }
  4923. });
  4924. })( jQuery );
  4925. /*
  4926. * "selectmenu" plugin
  4927. */
  4928. (function( $, undefined ) {
  4929. $.widget( "mobile.selectmenu", $.mobile.widget, {
  4930. options: {
  4931. theme: null,
  4932. disabled: false,
  4933. icon: "arrow-d",
  4934. iconpos: "right",
  4935. inline: null,
  4936. corners: true,
  4937. shadow: true,
  4938. iconshadow: true,
  4939. menuPageTheme: "b",
  4940. overlayTheme: "a",
  4941. hidePlaceholderMenuItems: true,
  4942. closeText: "Close",
  4943. nativeMenu: true,
  4944. initSelector: "select:not(:jqmData(role='slider'))"
  4945. },
  4946. _button: function(){
  4947. return $( "<div/>" );
  4948. },
  4949. _setDisabled: function( value ) {
  4950. this.element.attr( "disabled", value );
  4951. this.button.attr( "aria-disabled", value );
  4952. return this._setOption( "disabled", value );
  4953. },
  4954. _focusButton : function() {
  4955. var self = this;
  4956. setTimeout( function() {
  4957. self.button.focus();
  4958. }, 40);
  4959. },
  4960. _selectOptions: function() {
  4961. return this.select.find( "option" );
  4962. },
  4963. // setup items that are generally necessary for select menu extension
  4964. _preExtension: function(){
  4965. this.select = this.element.wrap( "<div class='ui-select'>" );
  4966. this.selectID = this.select.attr( "id" );
  4967. this.label = $( "label[for='"+ this.selectID +"']" ).addClass( "ui-select" );
  4968. this.isMultiple = this.select[ 0 ].multiple;
  4969. if ( !this.options.theme ) {
  4970. this.options.theme = $.mobile.getInheritedTheme( this.select, "c" );
  4971. }
  4972. },
  4973. _create: function() {
  4974. this._preExtension();
  4975. // Allows for extension of the native select for custom selects and other plugins
  4976. // see select.custom for example extension
  4977. // TODO explore plugin registration
  4978. this._trigger( "beforeCreate" );
  4979. this.button = this._button();
  4980. var self = this,
  4981. options = this.options,
  4982. // IE throws an exception at options.item() function when
  4983. // there is no selected item
  4984. // select first in this case
  4985. selectedIndex = this.select[ 0 ].selectedIndex == -1 ? 0 : this.select[ 0 ].selectedIndex,
  4986. // TODO values buttonId and menuId are undefined here
  4987. button = this.button
  4988. .text( $( this.select[ 0 ].options.item( selectedIndex ) ).text() )
  4989. .insertBefore( this.select )
  4990. .buttonMarkup( {
  4991. theme: options.theme,
  4992. icon: options.icon,
  4993. iconpos: options.iconpos,
  4994. inline: options.inline,
  4995. corners: options.corners,
  4996. shadow: options.shadow,
  4997. iconshadow: options.iconshadow
  4998. });
  4999. // Opera does not properly support opacity on select elements
  5000. // In Mini, it hides the element, but not its text
  5001. // On the desktop,it seems to do the opposite
  5002. // for these reasons, using the nativeMenu option results in a full native select in Opera
  5003. if ( options.nativeMenu && window.opera && window.opera.version ) {
  5004. this.select.addClass( "ui-select-nativeonly" );
  5005. }
  5006. // Add counter for multi selects
  5007. if ( this.isMultiple ) {
  5008. this.buttonCount = $( "<span>" )
  5009. .addClass( "ui-li-count ui-btn-up-c ui-btn-corner-all" )
  5010. .hide()
  5011. .appendTo( button.addClass('ui-li-has-count') );
  5012. }
  5013. // Disable if specified
  5014. if ( options.disabled || this.element.attr('disabled')) {
  5015. this.disable();
  5016. }
  5017. // Events on native select
  5018. this.select.change( function() {
  5019. self.refresh();
  5020. });
  5021. this.build();
  5022. },
  5023. build: function() {
  5024. var self = this;
  5025. this.select
  5026. .appendTo( self.button )
  5027. .bind( "vmousedown", function() {
  5028. // Add active class to button
  5029. self.button.addClass( $.mobile.activeBtnClass );
  5030. })
  5031. .bind( "focus vmouseover", function() {
  5032. self.button.trigger( "vmouseover" );
  5033. })
  5034. .bind( "vmousemove", function() {
  5035. // Remove active class on scroll/touchmove
  5036. self.button.removeClass( $.mobile.activeBtnClass );
  5037. })
  5038. .bind( "change blur vmouseout", function() {
  5039. self.button.trigger( "vmouseout" )
  5040. .removeClass( $.mobile.activeBtnClass );
  5041. })
  5042. .bind( "change blur", function() {
  5043. self.button.removeClass( "ui-btn-down-" + self.options.theme );
  5044. });
  5045. },
  5046. selected: function() {
  5047. return this._selectOptions().filter( ":selected" );
  5048. },
  5049. selectedIndices: function() {
  5050. var self = this;
  5051. return this.selected().map( function() {
  5052. return self._selectOptions().index( this );
  5053. }).get();
  5054. },
  5055. setButtonText: function() {
  5056. var self = this, selected = this.selected();
  5057. this.button.find( ".ui-btn-text" ).text( function() {
  5058. if ( !self.isMultiple ) {
  5059. return selected.text();
  5060. }
  5061. return selected.length ? selected.map( function() {
  5062. return $( this ).text();
  5063. }).get().join( ", " ) : self.placeholder;
  5064. });
  5065. },
  5066. setButtonCount: function() {
  5067. var selected = this.selected();
  5068. // multiple count inside button
  5069. if ( this.isMultiple ) {
  5070. this.buttonCount[ selected.length > 1 ? "show" : "hide" ]().text( selected.length );
  5071. }
  5072. },
  5073. refresh: function() {
  5074. this.setButtonText();
  5075. this.setButtonCount();
  5076. },
  5077. // open and close preserved in native selects
  5078. // to simplify users code when looping over selects
  5079. open: $.noop,
  5080. close: $.noop,
  5081. disable: function() {
  5082. this._setDisabled( true );
  5083. this.button.addClass( "ui-disabled" );
  5084. },
  5085. enable: function() {
  5086. this._setDisabled( false );
  5087. this.button.removeClass( "ui-disabled" );
  5088. }
  5089. });
  5090. //auto self-init widgets
  5091. $( document ).bind( "pagecreate create", function( e ){
  5092. $.mobile.selectmenu.prototype.enhanceWithin( e.target );
  5093. });
  5094. })( jQuery );
  5095. /*
  5096. * "buttons" plugin - for making button-like links
  5097. */
  5098. ( function( $, undefined ) {
  5099. $.fn.buttonMarkup = function( options ) {
  5100. options = options || {};
  5101. for ( var i = 0; i < this.length; i++ ) {
  5102. var el = this.eq( i ),
  5103. e = el[ 0 ],
  5104. o = $.extend( {}, $.fn.buttonMarkup.defaults, {
  5105. icon: options.icon !== undefined ? options.icon : el.jqmData( "icon" ),
  5106. iconpos: options.iconpos !== undefined ? options.iconpos : el.jqmData( "iconpos" ),
  5107. theme: options.theme !== undefined ? options.theme : el.jqmData( "theme" ),
  5108. inline: options.inline !== undefined ? options.inline : el.jqmData( "inline" ),
  5109. shadow: options.shadow !== undefined ? options.shadow : el.jqmData( "shadow" ),
  5110. corners: options.corners !== undefined ? options.corners : el.jqmData( "corners" ),
  5111. iconshadow: options.iconshadow !== undefined ? options.iconshadow : el.jqmData( "iconshadow" )
  5112. }, options ),
  5113. // Classes Defined
  5114. innerClass = "ui-btn-inner",
  5115. textClass = "ui-btn-text",
  5116. buttonClass, iconClass,
  5117. // Button inner markup
  5118. buttonInner = document.createElement( o.wrapperEls ),
  5119. buttonText = document.createElement( o.wrapperEls ),
  5120. buttonIcon = o.icon ? document.createElement( "span" ) : null;
  5121. // if so, prevent double enhancement, and continue with rest of the elements.
  5122. if( e.tagName === "INPUT" && el.jqmData('role') === "button" ) continue;
  5123. // if this is a button, check if it's been enhanced and, if not, use the right function
  5124. if( e.tagName === "BUTTON" ) {
  5125. if ( !$( e.parentNode ).hasClass( "ui-btn" ) ) $( e ).button();
  5126. continue;
  5127. }
  5128. if ( attachEvents ) {
  5129. attachEvents();
  5130. }
  5131. // if not, try to find closest theme container
  5132. if ( !o.theme ) {
  5133. o.theme = $.mobile.getInheritedTheme( el, "c" );
  5134. }
  5135. buttonClass = "ui-btn ui-btn-up-" + o.theme;
  5136. if ( o.inline ) {
  5137. buttonClass += " ui-btn-inline";
  5138. }
  5139. if ( o.icon ) {
  5140. o.icon = "ui-icon-" + o.icon;
  5141. o.iconpos = o.iconpos || "left";
  5142. iconClass = "ui-icon " + o.icon;
  5143. if ( o.iconshadow ) {
  5144. iconClass += " ui-icon-shadow";
  5145. }
  5146. }
  5147. if ( o.iconpos ) {
  5148. buttonClass += " ui-btn-icon-" + o.iconpos;
  5149. if ( o.iconpos == "notext" && !el.attr( "title" ) ) {
  5150. el.attr( "title", el.getEncodedText() );
  5151. }
  5152. }
  5153. if ( o.corners ) {
  5154. buttonClass += " ui-btn-corner-all";
  5155. innerClass += " ui-btn-corner-all";
  5156. }
  5157. if ( o.shadow ) {
  5158. buttonClass += " ui-shadow";
  5159. }
  5160. e.setAttribute( "data-" + $.mobile.ns + "theme", o.theme );
  5161. el.addClass( buttonClass );
  5162. buttonInner.className = innerClass;
  5163. buttonText.className = textClass;
  5164. buttonInner.appendChild( buttonText );
  5165. if ( buttonIcon ) {
  5166. buttonIcon.className = iconClass;
  5167. buttonInner.appendChild( buttonIcon );
  5168. }
  5169. while ( e.firstChild ) {
  5170. buttonText.appendChild( e.firstChild );
  5171. }
  5172. e.appendChild( buttonInner );
  5173. // TODO obviously it would be nice to pull this element out instead of
  5174. // retrieving it from the DOM again, but this change is much less obtrusive
  5175. // and 1.0 draws nigh
  5176. $.data( e, 'textWrapper', $( buttonText ) );
  5177. }
  5178. return this;
  5179. };
  5180. $.fn.buttonMarkup.defaults = {
  5181. corners: true,
  5182. shadow: true,
  5183. iconshadow: true,
  5184. inline: false,
  5185. wrapperEls: "span"
  5186. };
  5187. function closestEnabledButton( element ) {
  5188. var cname;
  5189. while ( element ) {
  5190. // Note that we check for typeof className below because the element we
  5191. // handed could be in an SVG DOM where className on SVG elements is defined to
  5192. // be of a different type (SVGAnimatedString). We only operate on HTML DOM
  5193. // elements, so we look for plain "string".
  5194. cname = ( typeof element.className === 'string' ) && (element.className + ' ');
  5195. if ( cname && cname.indexOf("ui-btn ") > -1 && cname.indexOf("ui-disabled ") < 0 ) {
  5196. break;
  5197. }
  5198. element = element.parentNode;
  5199. }
  5200. return element;
  5201. }
  5202. var attachEvents = function() {
  5203. $( document ).bind( {
  5204. "vmousedown": function( event ) {
  5205. var btn = closestEnabledButton( event.target ),
  5206. $btn, theme;
  5207. if ( btn ) {
  5208. $btn = $( btn );
  5209. theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
  5210. $btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
  5211. }
  5212. },
  5213. "vmousecancel vmouseup": function( event ) {
  5214. var btn = closestEnabledButton( event.target ),
  5215. $btn, theme;
  5216. if ( btn ) {
  5217. $btn = $( btn );
  5218. theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
  5219. $btn.removeClass( "ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
  5220. }
  5221. },
  5222. "vmouseover focus": function( event ) {
  5223. var btn = closestEnabledButton( event.target ),
  5224. $btn, theme;
  5225. if ( btn ) {
  5226. $btn = $( btn );
  5227. theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
  5228. $btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
  5229. }
  5230. },
  5231. "vmouseout blur": function( event ) {
  5232. var btn = closestEnabledButton( event.target ),
  5233. $btn, theme;
  5234. if ( btn ) {
  5235. $btn = $( btn );
  5236. theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
  5237. $btn.removeClass( "ui-btn-hover-" + theme + " ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
  5238. }
  5239. }
  5240. });
  5241. attachEvents = null;
  5242. };
  5243. //links in bars, or those with data-role become buttons
  5244. //auto self-init widgets
  5245. $( document ).bind( "pagecreate create", function( e ){
  5246. $( ":jqmData(role='button'), .ui-bar > a, .ui-header > a, .ui-footer > a, .ui-bar > :jqmData(role='controlgroup') > a", e.target )
  5247. .not( ".ui-btn, :jqmData(role='none'), :jqmData(role='nojs')" )
  5248. .buttonMarkup();
  5249. });
  5250. })( jQuery );
  5251. /*
  5252. * "controlgroup" plugin - corner-rounding for groups of buttons, checks, radios, etc
  5253. */
  5254. (function( $, undefined ) {
  5255. $.fn.controlgroup = function( options ) {
  5256. return this.each(function() {
  5257. var $el = $( this ),
  5258. o = $.extend({
  5259. direction: $el.jqmData( "type" ) || "vertical",
  5260. shadow: false,
  5261. excludeInvisible: true
  5262. }, options ),
  5263. groupheading = $el.children( "legend" ),
  5264. flCorners = o.direction == "horizontal" ? [ "ui-corner-left", "ui-corner-right" ] : [ "ui-corner-top", "ui-corner-bottom" ],
  5265. type = $el.find( "input" ).first().attr( "type" );
  5266. // Replace legend with more stylable replacement div
  5267. if ( groupheading.length ) {
  5268. $el.wrapInner( "<div class='ui-controlgroup-controls'></div>" );
  5269. $( "<div role='heading' class='ui-controlgroup-label'>" + groupheading.html() + "</div>" ).insertBefore( $el.children(0) );
  5270. groupheading.remove();
  5271. }
  5272. $el.addClass( "ui-corner-all ui-controlgroup ui-controlgroup-" + o.direction );
  5273. // TODO: This should be moved out to the closure
  5274. // otherwise it is redefined each time controlgroup() is called
  5275. function flipClasses( els ) {
  5276. els.removeClass( "ui-btn-corner-all ui-shadow" )
  5277. .eq( 0 ).addClass( flCorners[ 0 ] )
  5278. .end()
  5279. .last().addClass( flCorners[ 1 ] ).addClass( "ui-controlgroup-last" );
  5280. }
  5281. flipClasses( $el.find( ".ui-btn" + ( o.excludeInvisible ? ":visible" : "" ) ) );
  5282. flipClasses( $el.find( ".ui-btn-inner" ) );
  5283. if ( o.shadow ) {
  5284. $el.addClass( "ui-shadow" );
  5285. }
  5286. });
  5287. };
  5288. //auto self-init widgets
  5289. $( document ).bind( "pagecreate create", function( e ){
  5290. $( ":jqmData(role='controlgroup')", e.target ).controlgroup({ excludeInvisible: false });
  5291. });
  5292. })(jQuery);/*
  5293. * "links" plugin - simple class additions for links
  5294. */
  5295. (function( $, undefined ) {
  5296. $( document ).bind( "pagecreate create", function( e ){
  5297. //links within content areas
  5298. $( e.target )
  5299. .find( "a" )
  5300. .not( ".ui-btn, .ui-link-inherit, :jqmData(role='none'), :jqmData(role='nojs')" )
  5301. .addClass( "ui-link" );
  5302. });
  5303. })( jQuery );/*
  5304. * "fixHeaderFooter" plugin - on-demand positioning for headers,footers
  5305. */
  5306. (function( $, undefined ) {
  5307. var slideDownClass = "ui-header-fixed ui-fixed-inline fade",
  5308. slideUpClass = "ui-footer-fixed ui-fixed-inline fade",
  5309. slideDownSelector = ".ui-header:jqmData(position='fixed')",
  5310. slideUpSelector = ".ui-footer:jqmData(position='fixed')";
  5311. $.fn.fixHeaderFooter = function( options ) {
  5312. if ( !$.support.scrollTop || ( $.support.touchOverflow && $.mobile.touchOverflowEnabled ) ) {
  5313. return this;
  5314. }
  5315. return this.each(function() {
  5316. var $this = $( this );
  5317. if ( $this.jqmData( "fullscreen" ) ) {
  5318. $this.addClass( "ui-page-fullscreen" );
  5319. }
  5320. // Should be slidedown
  5321. $this.find( slideDownSelector ).addClass( slideDownClass );
  5322. // Should be slideup
  5323. $this.find( slideUpSelector ).addClass( slideUpClass );
  5324. });
  5325. };
  5326. // single controller for all showing,hiding,toggling
  5327. $.mobile.fixedToolbars = (function() {
  5328. if ( !$.support.scrollTop || ( $.support.touchOverflow && $.mobile.touchOverflowEnabled ) ) {
  5329. return;
  5330. }
  5331. var stickyFooter, delayTimer,
  5332. currentstate = "inline",
  5333. autoHideMode = false,
  5334. showDelay = 100,
  5335. ignoreTargets = "a,input,textarea,select,button,label,.ui-header-fixed,.ui-footer-fixed",
  5336. toolbarSelector = ".ui-header-fixed:first, .ui-footer-fixed:not(.ui-footer-duplicate):last",
  5337. // for storing quick references to duplicate footers
  5338. supportTouch = $.support.touch,
  5339. touchStartEvent = supportTouch ? "touchstart" : "mousedown",
  5340. touchStopEvent = supportTouch ? "touchend" : "mouseup",
  5341. stateBefore = null,
  5342. scrollTriggered = false,
  5343. touchToggleEnabled = true;
  5344. function showEventCallback( event ) {
  5345. // An event that affects the dimensions of the visual viewport has
  5346. // been triggered. If the header and/or footer for the current page are in overlay
  5347. // mode, we want to hide them, and then fire off a timer to show them at a later
  5348. // point. Events like a resize can be triggered continuously during a scroll, on
  5349. // some platforms, so the timer is used to delay the actual positioning until the
  5350. // flood of events have subsided.
  5351. //
  5352. // If we are in autoHideMode, we don't do anything because we know the scroll
  5353. // callbacks for the plugin will fire off a show when the scrolling has stopped.
  5354. if ( !autoHideMode && currentstate === "overlay" ) {
  5355. if ( !delayTimer ) {
  5356. $.mobile.fixedToolbars.hide( true );
  5357. }
  5358. $.mobile.fixedToolbars.startShowTimer();
  5359. }
  5360. }
  5361. $(function() {
  5362. var $document = $( document ),
  5363. $window = $( window );
  5364. $document
  5365. .bind( "vmousedown", function( event ) {
  5366. if ( touchToggleEnabled ) {
  5367. stateBefore = currentstate;
  5368. }
  5369. })
  5370. .bind( "vclick", function( event ) {
  5371. if ( touchToggleEnabled ) {
  5372. if ( $(event.target).closest( ignoreTargets ).length ) {
  5373. return;
  5374. }
  5375. if ( !scrollTriggered ) {
  5376. $.mobile.fixedToolbars.toggle( stateBefore );
  5377. stateBefore = null;
  5378. }
  5379. }
  5380. })
  5381. .bind( "silentscroll", showEventCallback );
  5382. // The below checks first for a $(document).scrollTop() value, and if zero, binds scroll events to $(window) instead.
  5383. // If the scrollTop value is actually zero, both will return zero anyway.
  5384. //
  5385. // Works with $(document), not $(window) : Opera Mobile (WinMO phone; kinda broken anyway)
  5386. // Works with $(window), not $(document) : IE 7/8
  5387. // Works with either $(window) or $(document) : Chrome, FF 3.6/4, Android 1.6/2.1, iOS
  5388. // Needs work either way : BB5, Opera Mobile (iOS)
  5389. ( ( $document.scrollTop() === 0 ) ? $window : $document )
  5390. .bind( "scrollstart", function( event ) {
  5391. scrollTriggered = true;
  5392. if ( stateBefore === null ) {
  5393. stateBefore = currentstate;
  5394. }
  5395. // We only enter autoHideMode if the headers/footers are in
  5396. // an overlay state or the show timer was started. If the
  5397. // show timer is set, clear it so the headers/footers don't
  5398. // show up until after we're done scrolling.
  5399. var isOverlayState = stateBefore == "overlay";
  5400. autoHideMode = isOverlayState || !!delayTimer;
  5401. if ( autoHideMode ) {
  5402. $.mobile.fixedToolbars.clearShowTimer();
  5403. if ( isOverlayState ) {
  5404. $.mobile.fixedToolbars.hide( true );
  5405. }
  5406. }
  5407. })
  5408. .bind( "scrollstop", function( event ) {
  5409. if ( $( event.target ).closest( ignoreTargets ).length ) {
  5410. return;
  5411. }
  5412. scrollTriggered = false;
  5413. if ( autoHideMode ) {
  5414. $.mobile.fixedToolbars.startShowTimer();
  5415. autoHideMode = false;
  5416. }
  5417. stateBefore = null;
  5418. });
  5419. $window.bind( "resize updatelayout", showEventCallback );
  5420. });
  5421. // 1. Before page is shown, check for duplicate footer
  5422. // 2. After page is shown, append footer to new page
  5423. $( document ).delegate( ".ui-page", "pagebeforeshow", function( event, ui ) {
  5424. var page = $( event.target ),
  5425. footer = page.find( ":jqmData(role='footer')" ),
  5426. id = footer.data( "id" ),
  5427. prevPage = ui.prevPage,
  5428. prevFooter = prevPage && prevPage.find( ":jqmData(role='footer')" ),
  5429. prevFooterMatches = prevFooter.length && prevFooter.jqmData( "id" ) === id;
  5430. if ( id && prevFooterMatches ) {
  5431. stickyFooter = footer;
  5432. setTop( stickyFooter.removeClass( "fade in out" ).appendTo( $.mobile.pageContainer ) );
  5433. }
  5434. })
  5435. .delegate( ".ui-page", "pageshow", function( event, ui ) {
  5436. var $this = $( this );
  5437. if ( stickyFooter && stickyFooter.length ) {
  5438. setTimeout(function() {
  5439. setTop( stickyFooter.appendTo( $this ).addClass( "fade" ) );
  5440. stickyFooter = null;
  5441. }, 500);
  5442. }
  5443. $.mobile.fixedToolbars.show( true, this );
  5444. });
  5445. // When a collapsible is hidden or shown we need to trigger the fixed toolbar to reposition itself (#1635)
  5446. $( document ).delegate( ".ui-collapsible-contain", "collapse expand", showEventCallback );
  5447. // element.getBoundingClientRect() is broken in iOS 3.2.1 on the iPad. The
  5448. // coordinates inside of the rect it returns don't have the page scroll position
  5449. // factored out of it like the other platforms do. To get around this,
  5450. // we'll just calculate the top offset the old fashioned way until core has
  5451. // a chance to figure out how to handle this situation.
  5452. //
  5453. // TODO: We'll need to get rid of getOffsetTop() once a fix gets folded into core.
  5454. function getOffsetTop( ele ) {
  5455. var top = 0,
  5456. op, body;
  5457. if ( ele ) {
  5458. body = document.body;
  5459. op = ele.offsetParent;
  5460. top = ele.offsetTop;
  5461. while ( ele && ele != body ) {
  5462. top += ele.scrollTop || 0;
  5463. if ( ele == op ) {
  5464. top += op.offsetTop;
  5465. op = ele.offsetParent;
  5466. }
  5467. ele = ele.parentNode;
  5468. }
  5469. }
  5470. return top;
  5471. }
  5472. function setTop( el ) {
  5473. var fromTop = $(window).scrollTop(),
  5474. thisTop = getOffsetTop( el[ 0 ] ), // el.offset().top returns the wrong value on iPad iOS 3.2.1, call our workaround instead.
  5475. thisCSStop = el.css( "top" ) == "auto" ? 0 : parseFloat(el.css( "top" )),
  5476. screenHeight = window.innerHeight,
  5477. thisHeight = el.outerHeight(),
  5478. useRelative = el.parents( ".ui-page:not(.ui-page-fullscreen)" ).length,
  5479. relval;
  5480. if ( el.is( ".ui-header-fixed" ) ) {
  5481. relval = fromTop - thisTop + thisCSStop;
  5482. if ( relval < thisTop ) {
  5483. relval = 0;
  5484. }
  5485. return el.css( "top", useRelative ? relval : fromTop );
  5486. } else {
  5487. // relval = -1 * (thisTop - (fromTop + screenHeight) + thisCSStop + thisHeight);
  5488. // if ( relval > thisTop ) { relval = 0; }
  5489. relval = fromTop + screenHeight - thisHeight - (thisTop - thisCSStop );
  5490. return el.css( "top", useRelative ? relval : fromTop + screenHeight - thisHeight );
  5491. }
  5492. }
  5493. // Exposed methods
  5494. return {
  5495. show: function( immediately, page ) {
  5496. $.mobile.fixedToolbars.clearShowTimer();
  5497. currentstate = "overlay";
  5498. var $ap = page ? $( page ) :
  5499. ( $.mobile.activePage ? $.mobile.activePage :
  5500. $( ".ui-page-active" ) );
  5501. return $ap.children( toolbarSelector ).each(function() {
  5502. var el = $( this ),
  5503. fromTop = $( window ).scrollTop(),
  5504. // el.offset().top returns the wrong value on iPad iOS 3.2.1, call our workaround instead.
  5505. thisTop = getOffsetTop( el[ 0 ] ),
  5506. screenHeight = window.innerHeight,
  5507. thisHeight = el.outerHeight(),
  5508. alreadyVisible = ( el.is( ".ui-header-fixed" ) && fromTop <= thisTop + thisHeight ) ||
  5509. ( el.is( ".ui-footer-fixed" ) && thisTop <= fromTop + screenHeight );
  5510. // Add state class
  5511. el.addClass( "ui-fixed-overlay" ).removeClass( "ui-fixed-inline" );
  5512. if ( !alreadyVisible && !immediately ) {
  5513. el.animationComplete(function() {
  5514. el.removeClass( "in" );
  5515. }).addClass( "in" );
  5516. }
  5517. setTop(el);
  5518. });
  5519. },
  5520. hide: function( immediately ) {
  5521. currentstate = "inline";
  5522. var $ap = $.mobile.activePage ? $.mobile.activePage :
  5523. $( ".ui-page-active" );
  5524. return $ap.children( toolbarSelector ).each(function() {
  5525. var el = $(this),
  5526. thisCSStop = el.css( "top" ),
  5527. classes;
  5528. thisCSStop = thisCSStop == "auto" ? 0 :
  5529. parseFloat(thisCSStop);
  5530. // Add state class
  5531. el.addClass( "ui-fixed-inline" ).removeClass( "ui-fixed-overlay" );
  5532. if ( thisCSStop < 0 || ( el.is( ".ui-header-fixed" ) && thisCSStop !== 0 ) ) {
  5533. if ( immediately ) {
  5534. el.css( "top", 0);
  5535. } else {
  5536. if ( el.css( "top" ) !== "auto" && parseFloat( el.css( "top" ) ) !== 0 ) {
  5537. classes = "out reverse";
  5538. el.animationComplete(function() {
  5539. el.removeClass( classes ).css( "top", 0 );
  5540. }).addClass( classes );
  5541. }
  5542. }
  5543. }
  5544. });
  5545. },
  5546. startShowTimer: function() {
  5547. $.mobile.fixedToolbars.clearShowTimer();
  5548. var args = [].slice.call( arguments );
  5549. delayTimer = setTimeout(function() {
  5550. delayTimer = undefined;
  5551. $.mobile.fixedToolbars.show.apply( null, args );
  5552. }, showDelay);
  5553. },
  5554. clearShowTimer: function() {
  5555. if ( delayTimer ) {
  5556. clearTimeout( delayTimer );
  5557. }
  5558. delayTimer = undefined;
  5559. },
  5560. toggle: function( from ) {
  5561. if ( from ) {
  5562. currentstate = from;
  5563. }
  5564. return ( currentstate === "overlay" ) ? $.mobile.fixedToolbars.hide() :
  5565. $.mobile.fixedToolbars.show();
  5566. },
  5567. setTouchToggleEnabled: function( enabled ) {
  5568. touchToggleEnabled = enabled;
  5569. }
  5570. };
  5571. })();
  5572. //auto self-init widgets
  5573. $( document ).bind( "pagecreate create", function( event ) {
  5574. if ( $( ":jqmData(position='fixed')", event.target ).length ) {
  5575. $( event.target ).each(function() {
  5576. if ( !$.support.scrollTop || ( $.support.touchOverflow && $.mobile.touchOverflowEnabled ) ) {
  5577. return this;
  5578. }
  5579. var $this = $( this );
  5580. if ( $this.jqmData( "fullscreen" ) ) {
  5581. $this.addClass( "ui-page-fullscreen" );
  5582. }
  5583. // Should be slidedown
  5584. $this.find( slideDownSelector ).addClass( slideDownClass );
  5585. // Should be slideup
  5586. $this.find( slideUpSelector ).addClass( slideUpClass );
  5587. })
  5588. }
  5589. });
  5590. })( jQuery );
  5591. /*
  5592. * "fixHeaderFooter" native plugin - Behavior for "fixed" headers,footers, and scrolling inner content
  5593. */
  5594. (function( $, undefined ) {
  5595. // Enable touch overflow scrolling when it's natively supported
  5596. $.mobile.touchOverflowEnabled = false;
  5597. // Enabled zoom when touch overflow is enabled. Can cause usability issues, unfortunately
  5598. $.mobile.touchOverflowZoomEnabled = false;
  5599. $( document ).bind( "pagecreate", function( event ) {
  5600. if( $.support.touchOverflow && $.mobile.touchOverflowEnabled ){
  5601. var $target = $( event.target ),
  5602. scrollStartY = 0;
  5603. if( $target.is( ":jqmData(role='page')" ) ){
  5604. $target.each(function() {
  5605. var $page = $( this ),
  5606. $fixies = $page.find( ":jqmData(role='header'), :jqmData(role='footer')" ).filter( ":jqmData(position='fixed')" ),
  5607. fullScreen = $page.jqmData( "fullscreen" ),
  5608. $scrollElem = $fixies.length ? $page.find( ".ui-content" ) : $page;
  5609. $page.addClass( "ui-mobile-touch-overflow" );
  5610. $scrollElem.bind( "scrollstop", function(){
  5611. if( $scrollElem.scrollTop() > 0 ){
  5612. window.scrollTo( 0, $.mobile.defaultHomeScroll );
  5613. }
  5614. });
  5615. if( $fixies.length ){
  5616. $page.addClass( "ui-native-fixed" );
  5617. if( fullScreen ){
  5618. $page.addClass( "ui-native-fullscreen" );
  5619. $fixies.addClass( "fade in" );
  5620. $( document ).bind( "vclick", function(){
  5621. $fixies
  5622. .removeClass( "ui-native-bars-hidden" )
  5623. .toggleClass( "in out" )
  5624. .animationComplete(function(){
  5625. $(this).not( ".in" ).addClass( "ui-native-bars-hidden" );
  5626. });
  5627. });
  5628. }
  5629. }
  5630. });
  5631. }
  5632. }
  5633. });
  5634. })( jQuery );
  5635. /*
  5636. * "init" - Initialize the framework
  5637. */
  5638. (function( $, window, undefined ) {
  5639. var $html = $( "html" ),
  5640. $head = $( "head" ),
  5641. $window = $( window );
  5642. // trigger mobileinit event - useful hook for configuring $.mobile settings before they're used
  5643. $( window.document ).trigger( "mobileinit" );
  5644. // support conditions
  5645. // if device support condition(s) aren't met, leave things as they are -> a basic, usable experience,
  5646. // otherwise, proceed with the enhancements
  5647. if ( !$.mobile.gradeA() ) {
  5648. return;
  5649. }
  5650. // override ajaxEnabled on platforms that have known conflicts with hash history updates
  5651. // or generally work better browsing in regular http for full page refreshes (BB5, Opera Mini)
  5652. if ( $.mobile.ajaxBlacklist ) {
  5653. $.mobile.ajaxEnabled = false;
  5654. }
  5655. // add mobile, initial load "rendering" classes to docEl
  5656. $html.addClass( "ui-mobile ui-mobile-rendering" );
  5657. // loading div which appears during Ajax requests
  5658. // will not appear if $.mobile.loadingMessage is false
  5659. var $loader = $( "<div class='ui-loader ui-body-a ui-corner-all'><span class='ui-icon ui-icon-loading spin'></span><h1></h1></div>" );
  5660. $.extend($.mobile, {
  5661. // turn on/off page loading message.
  5662. showPageLoadingMsg: function() {
  5663. if ( $.mobile.loadingMessage ) {
  5664. var activeBtn = $( "." + $.mobile.activeBtnClass ).first();
  5665. $loader
  5666. .find( "h1" )
  5667. .text( $.mobile.loadingMessage )
  5668. .end()
  5669. .appendTo( $.mobile.pageContainer )
  5670. // position at y center (if scrollTop supported), above the activeBtn (if defined), or just 100px from top
  5671. .css({
  5672. top: $.support.scrollTop && $window.scrollTop() + $window.height() / 2 ||
  5673. activeBtn.length && activeBtn.offset().top || 100
  5674. });
  5675. }
  5676. $html.addClass( "ui-loading" );
  5677. },
  5678. hidePageLoadingMsg: function() {
  5679. $html.removeClass( "ui-loading" );
  5680. },
  5681. // find and enhance the pages in the dom and transition to the first page.
  5682. initializePage: function() {
  5683. // find present pages
  5684. var $dialogs, $pages = $( ":jqmData(role='page')" );
  5685. // if no pages are found, check for dialogs or create one with body's inner html
  5686. if ( !$pages.length ) {
  5687. $dialogs = $( ":jqmData(role='dialog')" );
  5688. // if there are no pages but a dialog is present, load it as a page
  5689. if( $dialogs.length ) {
  5690. // alter the attribute so it will be treated as a page unpon enhancement
  5691. // TODO allow for the loading of a dialog as the first page (many considerations)
  5692. $dialogs.first().attr( "data-" + $.mobile.ns + "role", "page" );
  5693. // remove the first dialog from the set of dialogs since it's now a page
  5694. // add it to the empty set of pages to be loaded by the initial changepage
  5695. $pages = $pages.add( $dialogs.get().shift() );
  5696. } else {
  5697. $pages = $( "body" ).wrapInner( "<div data-" + $.mobile.ns + "role='page'></div>" ).children( 0 );
  5698. }
  5699. }
  5700. // add dialogs, set data-url attrs
  5701. $pages.add( ":jqmData(role='dialog')" ).each(function() {
  5702. var $this = $(this);
  5703. // unless the data url is already set set it to the pathname
  5704. if ( !$this.jqmData("url") ) {
  5705. $this.attr( "data-" + $.mobile.ns + "url", $this.attr( "id" ) || location.pathname + location.search );
  5706. }
  5707. });
  5708. // define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback)
  5709. $.mobile.firstPage = $pages.first();
  5710. // define page container
  5711. $.mobile.pageContainer = $pages.first().parent().addClass( "ui-mobile-viewport" );
  5712. // alert listeners that the pagecontainer has been determined for binding
  5713. // to events triggered on it
  5714. $window.trigger( "pagecontainercreate" );
  5715. // cue page loading message
  5716. $.mobile.showPageLoadingMsg();
  5717. // if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM
  5718. if ( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ) {
  5719. $.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
  5720. }
  5721. // otherwise, trigger a hashchange to load a deeplink
  5722. else {
  5723. $window.trigger( "hashchange", [ true ] );
  5724. }
  5725. }
  5726. });
  5727. // This function injects a meta viewport tag to prevent scaling. Off by default, on by default when touchOverflow scrolling is enabled
  5728. function disableZoom() {
  5729. var cont = "user-scalable=no",
  5730. meta = $( "meta[name='viewport']" );
  5731. if( meta.length ){
  5732. meta.attr( "content", meta.attr( "content" ) + ", " + cont );
  5733. }
  5734. else{
  5735. $( "head" ).prepend( "<meta>", { "name": "viewport", "content": cont } );
  5736. }
  5737. }
  5738. // if touch-overflow is enabled, disable user scaling, as it creates usability issues
  5739. if( $.support.touchOverflow && $.mobile.touchOverflowEnabled && !$.mobile.touchOverflowZoomEnabled ){
  5740. disableZoom();
  5741. }
  5742. // initialize events now, after mobileinit has occurred
  5743. $.mobile._registerInternalEvents();
  5744. // check which scrollTop value should be used by scrolling to 1 immediately at domready
  5745. // then check what the scroll top is. Android will report 0... others 1
  5746. // note that this initial scroll won't hide the address bar. It's just for the check.
  5747. $(function() {
  5748. window.scrollTo( 0, 1 );
  5749. // if defaultHomeScroll hasn't been set yet, see if scrollTop is 1
  5750. // it should be 1 in most browsers, but android treats 1 as 0 (for hiding addr bar)
  5751. // so if it's 1, use 0 from now on
  5752. $.mobile.defaultHomeScroll = ( !$.support.scrollTop || $(window).scrollTop() === 1 ) ? 0 : 1;
  5753. //dom-ready inits
  5754. if( $.mobile.autoInitializePage ){
  5755. $.mobile.initializePage();
  5756. }
  5757. // window load event
  5758. // hide iOS browser chrome on load
  5759. $window.load( $.mobile.silentScroll );
  5760. });
  5761. })( jQuery, this );