jquery.mobile-1.2.0.js 287 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163
  1. /*
  2. * jQuery Mobile Framework Git Build: SHA1: b49cc06499abf8f987cf90f35349cfac0918c939 <> Date: Tue Oct 2 11:22:34 2012 -0700
  3. * http://jquerymobile.com
  4. *
  5. * Copyright 2012 jQuery Foundation and other contributors
  6. * Released under the MIT license.
  7. * http://jquery.org/license
  8. *
  9. */
  10. (function ( root, doc, factory ) {
  11. if ( typeof define === "function" && define.amd ) {
  12. // AMD. Register as an anonymous module.
  13. define( [ "jquery" ], function ( $ ) {
  14. factory( $, root, doc );
  15. return $.mobile;
  16. });
  17. } else {
  18. // Browser globals
  19. factory( root.jQuery, root, doc );
  20. }
  21. }( this, document, function ( jQuery, window, document, undefined ) {
  22. (function( $, window, undefined ) {
  23. var nsNormalizeDict = {};
  24. // jQuery.mobile configurable options
  25. $.mobile = $.extend( {}, {
  26. // Version of the jQuery Mobile Framework
  27. version: "1.2.0",
  28. // Namespace used framework-wide for data-attrs. Default is no namespace
  29. ns: "",
  30. // Define the url parameter used for referencing widget-generated sub-pages.
  31. // Translates to to example.html&ui-page=subpageIdentifier
  32. // hash segment before &ui-page= is used to make Ajax request
  33. subPageUrlKey: "ui-page",
  34. // Class assigned to page currently in view, and during transitions
  35. activePageClass: "ui-page-active",
  36. // Class used for "active" button state, from CSS framework
  37. activeBtnClass: "ui-btn-active",
  38. // Class used for "focus" form element state, from CSS framework
  39. focusClass: "ui-focus",
  40. // Automatically handle clicks and form submissions through Ajax, when same-domain
  41. ajaxEnabled: true,
  42. // Automatically load and show pages based on location.hash
  43. hashListeningEnabled: true,
  44. // disable to prevent jquery from bothering with links
  45. linkBindingEnabled: true,
  46. // Set default page transition - 'none' for no transitions
  47. defaultPageTransition: "fade",
  48. // Set maximum window width for transitions to apply - 'false' for no limit
  49. maxTransitionWidth: false,
  50. // Minimum scroll distance that will be remembered when returning to a page
  51. minScrollBack: 250,
  52. // DEPRECATED: the following property is no longer in use, but defined until 2.0 to prevent conflicts
  53. touchOverflowEnabled: false,
  54. // Set default dialog transition - 'none' for no transitions
  55. defaultDialogTransition: "pop",
  56. // Error response message - appears when an Ajax page request fails
  57. pageLoadErrorMessage: "Error Loading Page",
  58. // For error messages, which theme does the box uses?
  59. pageLoadErrorMessageTheme: "e",
  60. // replace calls to window.history.back with phonegaps navigation helper
  61. // where it is provided on the window object
  62. phonegapNavigationEnabled: false,
  63. //automatically initialize the DOM when it's ready
  64. autoInitializePage: true,
  65. pushStateEnabled: true,
  66. // allows users to opt in to ignoring content by marking a parent element as
  67. // data-ignored
  68. ignoreContentEnabled: false,
  69. // turn of binding to the native orientationchange due to android orientation behavior
  70. orientationChangeEnabled: true,
  71. buttonMarkup: {
  72. hoverDelay: 200
  73. },
  74. // TODO might be useful upstream in jquery itself ?
  75. keyCode: {
  76. ALT: 18,
  77. BACKSPACE: 8,
  78. CAPS_LOCK: 20,
  79. COMMA: 188,
  80. COMMAND: 91,
  81. COMMAND_LEFT: 91, // COMMAND
  82. COMMAND_RIGHT: 93,
  83. CONTROL: 17,
  84. DELETE: 46,
  85. DOWN: 40,
  86. END: 35,
  87. ENTER: 13,
  88. ESCAPE: 27,
  89. HOME: 36,
  90. INSERT: 45,
  91. LEFT: 37,
  92. MENU: 93, // COMMAND_RIGHT
  93. NUMPAD_ADD: 107,
  94. NUMPAD_DECIMAL: 110,
  95. NUMPAD_DIVIDE: 111,
  96. NUMPAD_ENTER: 108,
  97. NUMPAD_MULTIPLY: 106,
  98. NUMPAD_SUBTRACT: 109,
  99. PAGE_DOWN: 34,
  100. PAGE_UP: 33,
  101. PERIOD: 190,
  102. RIGHT: 39,
  103. SHIFT: 16,
  104. SPACE: 32,
  105. TAB: 9,
  106. UP: 38,
  107. WINDOWS: 91 // COMMAND
  108. },
  109. // Scroll page vertically: scroll to 0 to hide iOS address bar, or pass a Y value
  110. silentScroll: function( ypos ) {
  111. if ( $.type( ypos ) !== "number" ) {
  112. ypos = $.mobile.defaultHomeScroll;
  113. }
  114. // prevent scrollstart and scrollstop events
  115. $.event.special.scrollstart.enabled = false;
  116. setTimeout( function() {
  117. window.scrollTo( 0, ypos );
  118. $( document ).trigger( "silentscroll", { x: 0, y: ypos });
  119. }, 20 );
  120. setTimeout( function() {
  121. $.event.special.scrollstart.enabled = true;
  122. }, 150 );
  123. },
  124. // Expose our cache for testing purposes.
  125. nsNormalizeDict: nsNormalizeDict,
  126. // Take a data attribute property, prepend the namespace
  127. // and then camel case the attribute string. Add the result
  128. // to our nsNormalizeDict so we don't have to do this again.
  129. nsNormalize: function( prop ) {
  130. if ( !prop ) {
  131. return;
  132. }
  133. return nsNormalizeDict[ prop ] || ( nsNormalizeDict[ prop ] = $.camelCase( $.mobile.ns + prop ) );
  134. },
  135. // Find the closest parent with a theme class on it. Note that
  136. // we are not using $.fn.closest() on purpose here because this
  137. // method gets called quite a bit and we need it to be as fast
  138. // as possible.
  139. getInheritedTheme: function( el, defaultTheme ) {
  140. var e = el[ 0 ],
  141. ltr = "",
  142. re = /ui-(bar|body|overlay)-([a-z])\b/,
  143. c, m;
  144. while ( e ) {
  145. c = e.className || "";
  146. if ( c && ( m = re.exec( c ) ) && ( ltr = m[ 2 ] ) ) {
  147. // We found a parent with a theme class
  148. // on it so bail from this loop.
  149. break;
  150. }
  151. e = e.parentNode;
  152. }
  153. // Return the theme letter we found, if none, return the
  154. // specified default.
  155. return ltr || defaultTheme || "a";
  156. },
  157. // TODO the following $ and $.fn extensions can/probably should be moved into jquery.mobile.core.helpers
  158. //
  159. // Find the closest javascript page element to gather settings data jsperf test
  160. // http://jsperf.com/single-complex-selector-vs-many-complex-selectors/edit
  161. // possibly naive, but it shows that the parsing overhead for *just* the page selector vs
  162. // the page and dialog selector is negligable. This could probably be speed up by
  163. // doing a similar parent node traversal to the one found in the inherited theme code above
  164. closestPageData: function( $target ) {
  165. return $target
  166. .closest( ':jqmData(role="page"), :jqmData(role="dialog")' )
  167. .data( "page" );
  168. },
  169. enhanceable: function( $set ) {
  170. return this.haveParents( $set, "enhance" );
  171. },
  172. hijackable: function( $set ) {
  173. return this.haveParents( $set, "ajax" );
  174. },
  175. haveParents: function( $set, attr ) {
  176. if ( !$.mobile.ignoreContentEnabled ) {
  177. return $set;
  178. }
  179. var count = $set.length,
  180. $newSet = $(),
  181. e, $element, excluded;
  182. for ( var i = 0; i < count; i++ ) {
  183. $element = $set.eq( i );
  184. excluded = false;
  185. e = $set[ i ];
  186. while ( e ) {
  187. var c = e.getAttribute ? e.getAttribute( "data-" + $.mobile.ns + attr ) : "";
  188. if ( c === "false" ) {
  189. excluded = true;
  190. break;
  191. }
  192. e = e.parentNode;
  193. }
  194. if ( !excluded ) {
  195. $newSet = $newSet.add( $element );
  196. }
  197. }
  198. return $newSet;
  199. },
  200. getScreenHeight: function() {
  201. // Native innerHeight returns more accurate value for this across platforms,
  202. // jQuery version is here as a normalized fallback for platforms like Symbian
  203. return window.innerHeight || $( window ).height();
  204. }
  205. }, $.mobile );
  206. // Mobile version of data and removeData and hasData methods
  207. // ensures all data is set and retrieved using jQuery Mobile's data namespace
  208. $.fn.jqmData = function( prop, value ) {
  209. var result;
  210. if ( typeof prop !== "undefined" ) {
  211. if ( prop ) {
  212. prop = $.mobile.nsNormalize( prop );
  213. }
  214. // undefined is permitted as an explicit input for the second param
  215. // in this case it returns the value and does not set it to undefined
  216. if( arguments.length < 2 || value === undefined ){
  217. result = this.data( prop );
  218. } else {
  219. result = this.data( prop, value );
  220. }
  221. }
  222. return result;
  223. };
  224. $.jqmData = function( elem, prop, value ) {
  225. var result;
  226. if ( typeof prop !== "undefined" ) {
  227. result = $.data( elem, prop ? $.mobile.nsNormalize( prop ) : prop, value );
  228. }
  229. return result;
  230. };
  231. $.fn.jqmRemoveData = function( prop ) {
  232. return this.removeData( $.mobile.nsNormalize( prop ) );
  233. };
  234. $.jqmRemoveData = function( elem, prop ) {
  235. return $.removeData( elem, $.mobile.nsNormalize( prop ) );
  236. };
  237. $.fn.removeWithDependents = function() {
  238. $.removeWithDependents( this );
  239. };
  240. $.removeWithDependents = function( elem ) {
  241. var $elem = $( elem );
  242. ( $elem.jqmData( 'dependents' ) || $() ).remove();
  243. $elem.remove();
  244. };
  245. $.fn.addDependents = function( newDependents ) {
  246. $.addDependents( $( this ), newDependents );
  247. };
  248. $.addDependents = function( elem, newDependents ) {
  249. var dependents = $( elem ).jqmData( 'dependents' ) || $();
  250. $( elem ).jqmData( 'dependents', $.merge( dependents, newDependents ) );
  251. };
  252. // note that this helper doesn't attempt to handle the callback
  253. // or setting of an html elements text, its only purpose is
  254. // to return the html encoded version of the text in all cases. (thus the name)
  255. $.fn.getEncodedText = function() {
  256. return $( "<div/>" ).text( $( this ).text() ).html();
  257. };
  258. // fluent helper function for the mobile namespaced equivalent
  259. $.fn.jqmEnhanceable = function() {
  260. return $.mobile.enhanceable( this );
  261. };
  262. $.fn.jqmHijackable = function() {
  263. return $.mobile.hijackable( this );
  264. };
  265. // Monkey-patching Sizzle to filter the :jqmData selector
  266. var oldFind = $.find,
  267. jqmDataRE = /:jqmData\(([^)]*)\)/g;
  268. $.find = function( selector, context, ret, extra ) {
  269. selector = selector.replace( jqmDataRE, "[data-" + ( $.mobile.ns || "" ) + "$1]" );
  270. return oldFind.call( this, selector, context, ret, extra );
  271. };
  272. $.extend( $.find, oldFind );
  273. $.find.matches = function( expr, set ) {
  274. return $.find( expr, null, null, set );
  275. };
  276. $.find.matchesSelector = function( node, expr ) {
  277. return $.find( expr, null, null, [ node ] ).length > 0;
  278. };
  279. })( jQuery, this );
  280. /*!
  281. * jQuery UI Widget v1.9.0-beta.1
  282. *
  283. * Copyright 2012, https://github.com/jquery/jquery-ui/blob/1.9.0-beta.1/AUTHORS.txt (http://jqueryui.com/about)
  284. * Dual licensed under the MIT or GPL Version 2 licenses.
  285. * http://jquery.org/license
  286. *
  287. * http://docs.jquery.com/UI/Widget
  288. */
  289. (function( $, undefined ) {
  290. var uuid = 0,
  291. slice = Array.prototype.slice,
  292. _cleanData = $.cleanData;
  293. $.cleanData = function( elems ) {
  294. for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
  295. try {
  296. $( elem ).triggerHandler( "remove" );
  297. // http://bugs.jquery.com/ticket/8235
  298. } catch( e ) {}
  299. }
  300. _cleanData( elems );
  301. };
  302. $.widget = function( name, base, prototype ) {
  303. var fullName, existingConstructor, constructor, basePrototype,
  304. namespace = name.split( "." )[ 0 ];
  305. name = name.split( "." )[ 1 ];
  306. fullName = namespace + "-" + name;
  307. if ( !prototype ) {
  308. prototype = base;
  309. base = $.Widget;
  310. }
  311. // create selector for plugin
  312. $.expr[ ":" ][ fullName ] = function( elem ) {
  313. return !!$.data( elem, fullName );
  314. };
  315. $[ namespace ] = $[ namespace ] || {};
  316. existingConstructor = $[ namespace ][ name ];
  317. constructor = $[ namespace ][ name ] = function( options, element ) {
  318. // allow instantiation without "new" keyword
  319. if ( !this._createWidget ) {
  320. return new constructor( options, element );
  321. }
  322. // allow instantiation without initializing for simple inheritance
  323. // must use "new" keyword (the code above always passes args)
  324. if ( arguments.length ) {
  325. this._createWidget( options, element );
  326. }
  327. };
  328. // extend with the existing constructor to carry over any static properties
  329. $.extend( constructor, existingConstructor, {
  330. version: prototype.version,
  331. // copy the object used to create the prototype in case we need to
  332. // redefine the widget later
  333. _proto: $.extend( {}, prototype ),
  334. // track widgets that inherit from this widget in case this widget is
  335. // redefined after a widget inherits from it
  336. _childConstructors: []
  337. });
  338. basePrototype = new base();
  339. // we need to make the options hash a property directly on the new instance
  340. // otherwise we'll modify the options hash on the prototype that we're
  341. // inheriting from
  342. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  343. $.each( prototype, function( prop, value ) {
  344. if ( $.isFunction( value ) ) {
  345. prototype[ prop ] = (function() {
  346. var _super = function() {
  347. return base.prototype[ prop ].apply( this, arguments );
  348. },
  349. _superApply = function( args ) {
  350. return base.prototype[ prop ].apply( this, args );
  351. };
  352. return function() {
  353. var __super = this._super,
  354. __superApply = this._superApply,
  355. returnValue;
  356. this._super = _super;
  357. this._superApply = _superApply;
  358. returnValue = value.apply( this, arguments );
  359. this._super = __super;
  360. this._superApply = __superApply;
  361. return returnValue;
  362. };
  363. })();
  364. }
  365. });
  366. constructor.prototype = $.widget.extend( basePrototype, {
  367. // TODO: remove support for widgetEventPrefix
  368. // always use the name + a colon as the prefix, e.g., draggable:start
  369. // don't prefix for widgets that aren't DOM-based
  370. widgetEventPrefix: name
  371. }, prototype, {
  372. constructor: constructor,
  373. namespace: namespace,
  374. widgetName: name,
  375. // TODO remove widgetBaseClass, see #8155
  376. widgetBaseClass: fullName,
  377. widgetFullName: fullName
  378. });
  379. // If this widget is being redefined then we need to find all widgets that
  380. // are inheriting from it and redefine all of them so that they inherit from
  381. // the new version of this widget. We're essentially trying to replace one
  382. // level in the prototype chain.
  383. if ( existingConstructor ) {
  384. $.each( existingConstructor._childConstructors, function( i, child ) {
  385. var childPrototype = child.prototype;
  386. // redefine the child widget using the same prototype that was
  387. // originally used, but inherit from the new version of the base
  388. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
  389. });
  390. // remove the list of existing child constructors from the old constructor
  391. // so the old child constructors can be garbage collected
  392. delete existingConstructor._childConstructors;
  393. } else {
  394. base._childConstructors.push( constructor );
  395. }
  396. $.widget.bridge( name, constructor );
  397. };
  398. $.widget.extend = function( target ) {
  399. var input = slice.call( arguments, 1 ),
  400. inputIndex = 0,
  401. inputLength = input.length,
  402. key,
  403. value;
  404. for ( ; inputIndex < inputLength; inputIndex++ ) {
  405. for ( key in input[ inputIndex ] ) {
  406. value = input[ inputIndex ][ key ];
  407. if (input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  408. target[ key ] = $.isPlainObject( value ) ? $.widget.extend( {}, target[ key ], value ) : value;
  409. }
  410. }
  411. }
  412. return target;
  413. };
  414. $.widget.bridge = function( name, object ) {
  415. var fullName = object.prototype.widgetFullName;
  416. $.fn[ name ] = function( options ) {
  417. var isMethodCall = typeof options === "string",
  418. args = slice.call( arguments, 1 ),
  419. returnValue = this;
  420. // allow multiple hashes to be passed on init
  421. options = !isMethodCall && args.length ?
  422. $.widget.extend.apply( null, [ options ].concat(args) ) :
  423. options;
  424. if ( isMethodCall ) {
  425. this.each(function() {
  426. var methodValue,
  427. instance = $.data( this, fullName );
  428. if ( !instance ) {
  429. return $.error( "cannot call methods on " + name + " prior to initialization; " +
  430. "attempted to call method '" + options + "'" );
  431. }
  432. if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
  433. return $.error( "no such method '" + options + "' for " + name + " widget instance" );
  434. }
  435. methodValue = instance[ options ].apply( instance, args );
  436. if ( methodValue !== instance && methodValue !== undefined ) {
  437. returnValue = methodValue && methodValue.jquery ?
  438. returnValue.pushStack( methodValue.get() ) :
  439. methodValue;
  440. return false;
  441. }
  442. });
  443. } else {
  444. this.each(function() {
  445. var instance = $.data( this, fullName );
  446. if ( instance ) {
  447. instance.option( options || {} )._init();
  448. } else {
  449. new object( options, this );
  450. }
  451. });
  452. }
  453. return returnValue;
  454. };
  455. };
  456. $.Widget = function( options, element ) {};
  457. $.Widget._childConstructors = [];
  458. $.Widget.prototype = {
  459. widgetName: "widget",
  460. widgetEventPrefix: "",
  461. defaultElement: "<div>",
  462. options: {
  463. disabled: false,
  464. // callbacks
  465. create: null
  466. },
  467. _createWidget: function( options, element ) {
  468. element = $( element || this.defaultElement || this )[ 0 ];
  469. this.element = $( element );
  470. this.uuid = uuid++;
  471. this.eventNamespace = "." + this.widgetName + this.uuid;
  472. this.options = $.widget.extend( {},
  473. this.options,
  474. this._getCreateOptions(),
  475. options );
  476. this.bindings = $();
  477. this.hoverable = $();
  478. this.focusable = $();
  479. if ( element !== this ) {
  480. // 1.9 BC for #7810
  481. // TODO remove dual storage
  482. $.data( element, this.widgetName, this );
  483. $.data( element, this.widgetFullName, this );
  484. this._on({ remove: "destroy" });
  485. this.document = $( element.style ?
  486. // element within the document
  487. element.ownerDocument :
  488. // element is window or document
  489. element.document || element );
  490. this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
  491. }
  492. this._create();
  493. this._trigger( "create", null, this._getCreateEventData() );
  494. this._init();
  495. },
  496. _getCreateOptions: $.noop,
  497. _getCreateEventData: $.noop,
  498. _create: $.noop,
  499. _init: $.noop,
  500. destroy: function() {
  501. this._destroy();
  502. // we can probably remove the unbind calls in 2.0
  503. // all event bindings should go through this._on()
  504. this.element
  505. .unbind( this.eventNamespace )
  506. // 1.9 BC for #7810
  507. // TODO remove dual storage
  508. .removeData( this.widgetName )
  509. .removeData( this.widgetFullName )
  510. // support: jquery <1.6.3
  511. // http://bugs.jquery.com/ticket/9413
  512. .removeData( $.camelCase( this.widgetFullName ) );
  513. this.widget()
  514. .unbind( this.eventNamespace )
  515. .removeAttr( "aria-disabled" )
  516. .removeClass(
  517. this.widgetFullName + "-disabled " +
  518. "ui-state-disabled" );
  519. // clean up events and states
  520. this.bindings.unbind( this.eventNamespace );
  521. this.hoverable.removeClass( "ui-state-hover" );
  522. this.focusable.removeClass( "ui-state-focus" );
  523. },
  524. _destroy: $.noop,
  525. widget: function() {
  526. return this.element;
  527. },
  528. option: function( key, value ) {
  529. var options = key,
  530. parts,
  531. curOption,
  532. i;
  533. if ( arguments.length === 0 ) {
  534. // don't return a reference to the internal hash
  535. return $.widget.extend( {}, this.options );
  536. }
  537. if ( typeof key === "string" ) {
  538. // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  539. options = {};
  540. parts = key.split( "." );
  541. key = parts.shift();
  542. if ( parts.length ) {
  543. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  544. for ( i = 0; i < parts.length - 1; i++ ) {
  545. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  546. curOption = curOption[ parts[ i ] ];
  547. }
  548. key = parts.pop();
  549. if ( value === undefined ) {
  550. return curOption[ key ] === undefined ? null : curOption[ key ];
  551. }
  552. curOption[ key ] = value;
  553. } else {
  554. if ( value === undefined ) {
  555. return this.options[ key ] === undefined ? null : this.options[ key ];
  556. }
  557. options[ key ] = value;
  558. }
  559. }
  560. this._setOptions( options );
  561. return this;
  562. },
  563. _setOptions: function( options ) {
  564. var key;
  565. for ( key in options ) {
  566. this._setOption( key, options[ key ] );
  567. }
  568. return this;
  569. },
  570. _setOption: function( key, value ) {
  571. this.options[ key ] = value;
  572. if ( key === "disabled" ) {
  573. this.widget()
  574. .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
  575. .attr( "aria-disabled", value );
  576. this.hoverable.removeClass( "ui-state-hover" );
  577. this.focusable.removeClass( "ui-state-focus" );
  578. }
  579. return this;
  580. },
  581. enable: function() {
  582. return this._setOption( "disabled", false );
  583. },
  584. disable: function() {
  585. return this._setOption( "disabled", true );
  586. },
  587. _on: function( element, handlers ) {
  588. // no element argument, shuffle and use this.element
  589. if ( !handlers ) {
  590. handlers = element;
  591. element = this.element;
  592. } else {
  593. // accept selectors, DOM elements
  594. element = $( element );
  595. this.bindings = this.bindings.add( element );
  596. }
  597. var instance = this;
  598. $.each( handlers, function( event, handler ) {
  599. function handlerProxy() {
  600. // allow widgets to customize the disabled handling
  601. // - disabled as an array instead of boolean
  602. // - disabled class as method for disabling individual parts
  603. if ( instance.options.disabled === true ||
  604. $( this ).hasClass( "ui-state-disabled" ) ) {
  605. return;
  606. }
  607. return ( typeof handler === "string" ? instance[ handler ] : handler )
  608. .apply( instance, arguments );
  609. }
  610. // copy the guid so direct unbinding works
  611. if ( typeof handler !== "string" ) {
  612. handlerProxy.guid = handler.guid =
  613. handler.guid || handlerProxy.guid || $.guid++;
  614. }
  615. var match = event.match( /^(\w+)\s*(.*)$/ ),
  616. eventName = match[1] + instance.eventNamespace,
  617. selector = match[2];
  618. if ( selector ) {
  619. instance.widget().delegate( selector, eventName, handlerProxy );
  620. } else {
  621. element.bind( eventName, handlerProxy );
  622. }
  623. });
  624. },
  625. _off: function( element, eventName ) {
  626. eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
  627. element.unbind( eventName ).undelegate( eventName );
  628. },
  629. _delay: function( handler, delay ) {
  630. function handlerProxy() {
  631. return ( typeof handler === "string" ? instance[ handler ] : handler )
  632. .apply( instance, arguments );
  633. }
  634. var instance = this;
  635. return setTimeout( handlerProxy, delay || 0 );
  636. },
  637. _hoverable: function( element ) {
  638. this.hoverable = this.hoverable.add( element );
  639. this._on( element, {
  640. mouseenter: function( event ) {
  641. $( event.currentTarget ).addClass( "ui-state-hover" );
  642. },
  643. mouseleave: function( event ) {
  644. $( event.currentTarget ).removeClass( "ui-state-hover" );
  645. }
  646. });
  647. },
  648. _focusable: function( element ) {
  649. this.focusable = this.focusable.add( element );
  650. this._on( element, {
  651. focusin: function( event ) {
  652. $( event.currentTarget ).addClass( "ui-state-focus" );
  653. },
  654. focusout: function( event ) {
  655. $( event.currentTarget ).removeClass( "ui-state-focus" );
  656. }
  657. });
  658. },
  659. _trigger: function( type, event, data ) {
  660. var prop, orig,
  661. callback = this.options[ type ];
  662. data = data || {};
  663. event = $.Event( event );
  664. event.type = ( type === this.widgetEventPrefix ?
  665. type :
  666. this.widgetEventPrefix + type ).toLowerCase();
  667. // the original event may come from any element
  668. // so we need to reset the target on the new event
  669. event.target = this.element[ 0 ];
  670. // copy original event properties over to the new event
  671. orig = event.originalEvent;
  672. if ( orig ) {
  673. for ( prop in orig ) {
  674. if ( !( prop in event ) ) {
  675. event[ prop ] = orig[ prop ];
  676. }
  677. }
  678. }
  679. this.element.trigger( event, data );
  680. return !( $.isFunction( callback ) &&
  681. callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
  682. event.isDefaultPrevented() );
  683. }
  684. };
  685. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  686. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  687. if ( typeof options === "string" ) {
  688. options = { effect: options };
  689. }
  690. var hasOptions,
  691. effectName = !options ?
  692. method :
  693. options === true || typeof options === "number" ?
  694. defaultEffect :
  695. options.effect || defaultEffect;
  696. options = options || {};
  697. if ( typeof options === "number" ) {
  698. options = { duration: options };
  699. }
  700. hasOptions = !$.isEmptyObject( options );
  701. options.complete = callback;
  702. if ( options.delay ) {
  703. element.delay( options.delay );
  704. }
  705. if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ effectName ] ) ) {
  706. element[ method ]( options );
  707. } else if ( effectName !== method && element[ effectName ] ) {
  708. element[ effectName ]( options.duration, options.easing, callback );
  709. } else {
  710. element.queue(function( next ) {
  711. $( this )[ method ]();
  712. if ( callback ) {
  713. callback.call( element[ 0 ] );
  714. }
  715. next();
  716. });
  717. }
  718. };
  719. });
  720. // DEPRECATED
  721. if ( $.uiBackCompat !== false ) {
  722. $.Widget.prototype._getCreateOptions = function() {
  723. return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
  724. };
  725. }
  726. })( jQuery );
  727. (function( $, undefined ) {
  728. $.widget( "mobile.widget", {
  729. // decorate the parent _createWidget to trigger `widgetinit` for users
  730. // who wish to do post post `widgetcreate` alterations/additions
  731. //
  732. // TODO create a pull request for jquery ui to trigger this event
  733. // in the original _createWidget
  734. _createWidget: function() {
  735. $.Widget.prototype._createWidget.apply( this, arguments );
  736. this._trigger( 'init' );
  737. },
  738. _getCreateOptions: function() {
  739. var elem = this.element,
  740. options = {};
  741. $.each( this.options, function( option ) {
  742. var value = elem.jqmData( option.replace( /[A-Z]/g, function( c ) {
  743. return "-" + c.toLowerCase();
  744. })
  745. );
  746. if ( value !== undefined ) {
  747. options[ option ] = value;
  748. }
  749. });
  750. return options;
  751. },
  752. enhanceWithin: function( target, useKeepNative ) {
  753. this.enhance( $( this.options.initSelector, $( target )), useKeepNative );
  754. },
  755. enhance: function( targets, useKeepNative ) {
  756. var page, keepNative, $widgetElements = $( targets ), self = this;
  757. // if ignoreContentEnabled is set to true the framework should
  758. // only enhance the selected elements when they do NOT have a
  759. // parent with the data-namespace-ignore attribute
  760. $widgetElements = $.mobile.enhanceable( $widgetElements );
  761. if ( useKeepNative && $widgetElements.length ) {
  762. // TODO remove dependency on the page widget for the keepNative.
  763. // Currently the keepNative value is defined on the page prototype so
  764. // the method is as well
  765. page = $.mobile.closestPageData( $widgetElements );
  766. keepNative = ( page && page.keepNativeSelector()) || "";
  767. $widgetElements = $widgetElements.not( keepNative );
  768. }
  769. $widgetElements[ this.widgetName ]();
  770. },
  771. raise: function( msg ) {
  772. throw "Widget [" + this.widgetName + "]: " + msg;
  773. }
  774. });
  775. })( jQuery );
  776. (function( $, window ) {
  777. // DEPRECATED
  778. // NOTE global mobile object settings
  779. $.extend( $.mobile, {
  780. // DEPRECATED Should the text be visble in the loading message?
  781. loadingMessageTextVisible: undefined,
  782. // DEPRECATED When the text is visible, what theme does the loading box use?
  783. loadingMessageTheme: undefined,
  784. // DEPRECATED default message setting
  785. loadingMessage: undefined,
  786. // DEPRECATED
  787. // Turn on/off page loading message. Theme doubles as an object argument
  788. // with the following shape: { theme: '', text: '', html: '', textVisible: '' }
  789. // NOTE that the $.mobile.loading* settings and params past the first are deprecated
  790. showPageLoadingMsg: function( theme, msgText, textonly ) {
  791. $.mobile.loading( 'show', theme, msgText, textonly );
  792. },
  793. // DEPRECATED
  794. hidePageLoadingMsg: function() {
  795. $.mobile.loading( 'hide' );
  796. },
  797. loading: function() {
  798. this.loaderWidget.loader.apply( this.loaderWidget, arguments );
  799. }
  800. });
  801. // TODO move loader class down into the widget settings
  802. var loaderClass = "ui-loader", $html = $( "html" ), $window = $( window );
  803. $.widget( "mobile.loader", {
  804. // NOTE if the global config settings are defined they will override these
  805. // options
  806. options: {
  807. // the theme for the loading message
  808. theme: "a",
  809. // whether the text in the loading message is shown
  810. textVisible: false,
  811. // custom html for the inner content of the loading message
  812. html: "",
  813. // the text to be displayed when the popup is shown
  814. text: "loading"
  815. },
  816. defaultHtml: "<div class='" + loaderClass + "'>" +
  817. "<span class='ui-icon ui-icon-loading'></span>" +
  818. "<h1></h1>" +
  819. "</div>",
  820. // For non-fixed supportin browsers. Position at y center (if scrollTop supported), above the activeBtn (if defined), or just 100px from top
  821. fakeFixLoader: function() {
  822. var activeBtn = $( "." + $.mobile.activeBtnClass ).first();
  823. this.element
  824. .css({
  825. top: $.support.scrollTop && $window.scrollTop() + $window.height() / 2 ||
  826. activeBtn.length && activeBtn.offset().top || 100
  827. });
  828. },
  829. // check position of loader to see if it appears to be "fixed" to center
  830. // if not, use abs positioning
  831. checkLoaderPosition: function() {
  832. var offset = this.element.offset(),
  833. scrollTop = $window.scrollTop(),
  834. screenHeight = $.mobile.getScreenHeight();
  835. if ( offset.top < scrollTop || ( offset.top - scrollTop ) > screenHeight ) {
  836. this.element.addClass( "ui-loader-fakefix" );
  837. this.fakeFixLoader();
  838. $window
  839. .unbind( "scroll", this.checkLoaderPosition )
  840. .bind( "scroll", this.fakeFixLoader );
  841. }
  842. },
  843. resetHtml: function() {
  844. this.element.html( $( this.defaultHtml ).html() );
  845. },
  846. // Turn on/off page loading message. Theme doubles as an object argument
  847. // with the following shape: { theme: '', text: '', html: '', textVisible: '' }
  848. // NOTE that the $.mobile.loading* settings and params past the first are deprecated
  849. // TODO sweet jesus we need to break some of this out
  850. show: function( theme, msgText, textonly ) {
  851. var textVisible, message, $header, loadSettings;
  852. this.resetHtml();
  853. // use the prototype options so that people can set them globally at
  854. // mobile init. Consistency, it's what's for dinner
  855. if ( $.type(theme) === "object" ) {
  856. loadSettings = $.extend( {}, this.options, theme );
  857. // prefer object property from the param then the old theme setting
  858. theme = loadSettings.theme || $.mobile.loadingMessageTheme;
  859. } else {
  860. loadSettings = this.options;
  861. // here we prefer the them value passed as a string argument, then
  862. // we prefer the global option because we can't use undefined default
  863. // prototype options, then the prototype option
  864. theme = theme || $.mobile.loadingMessageTheme || loadSettings.theme;
  865. }
  866. // set the message text, prefer the param, then the settings object
  867. // then loading message
  868. message = msgText || $.mobile.loadingMessage || loadSettings.text;
  869. // prepare the dom
  870. $html.addClass( "ui-loading" );
  871. if ( $.mobile.loadingMessage !== false || loadSettings.html ) {
  872. // boolean values require a bit more work :P, supports object properties
  873. // and old settings
  874. if ( $.mobile.loadingMessageTextVisible !== undefined ) {
  875. textVisible = $.mobile.loadingMessageTextVisible;
  876. } else {
  877. textVisible = loadSettings.textVisible;
  878. }
  879. // add the proper css given the options (theme, text, etc)
  880. // Force text visibility if the second argument was supplied, or
  881. // if the text was explicitly set in the object args
  882. this.element.attr("class", loaderClass +
  883. " ui-corner-all ui-body-" + theme +
  884. " ui-loader-" + ( textVisible || msgText || theme.text ? "verbose" : "default" ) +
  885. ( loadSettings.textonly || textonly ? " ui-loader-textonly" : "" ) );
  886. // TODO verify that jquery.fn.html is ok to use in both cases here
  887. // this might be overly defensive in preventing unknowing xss
  888. // if the html attribute is defined on the loading settings, use that
  889. // otherwise use the fallbacks from above
  890. if ( loadSettings.html ) {
  891. this.element.html( loadSettings.html );
  892. } else {
  893. this.element.find( "h1" ).text( message );
  894. }
  895. // attach the loader to the DOM
  896. this.element.appendTo( $.mobile.pageContainer );
  897. // check that the loader is visible
  898. this.checkLoaderPosition();
  899. // on scroll check the loader position
  900. $window.bind( "scroll", $.proxy( this.checkLoaderPosition, this ) );
  901. }
  902. },
  903. hide: function() {
  904. $html.removeClass( "ui-loading" );
  905. if ( $.mobile.loadingMessage ) {
  906. this.element.removeClass( "ui-loader-fakefix" );
  907. }
  908. $( window ).unbind( "scroll", $.proxy( this.fakeFixLoader, this) );
  909. $( window ).unbind( "scroll", $.proxy( this.checkLoaderPosition, this ) );
  910. }
  911. });
  912. $window.bind( 'pagecontainercreate', function() {
  913. $.mobile.loaderWidget = $.mobile.loaderWidget || $( $.mobile.loader.prototype.defaultHtml ).loader();
  914. });
  915. })(jQuery, this);
  916. // This plugin is an experiment for abstracting away the touch and mouse
  917. // events so that developers don't have to worry about which method of input
  918. // the device their document is loaded on supports.
  919. //
  920. // The idea here is to allow the developer to register listeners for the
  921. // basic mouse events, such as mousedown, mousemove, mouseup, and click,
  922. // and the plugin will take care of registering the correct listeners
  923. // behind the scenes to invoke the listener at the fastest possible time
  924. // for that device, while still retaining the order of event firing in
  925. // the traditional mouse environment, should multiple handlers be registered
  926. // on the same element for different events.
  927. //
  928. // The current version exposes the following virtual events to jQuery bind methods:
  929. // "vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel"
  930. (function( $, window, document, undefined ) {
  931. var dataPropertyName = "virtualMouseBindings",
  932. touchTargetPropertyName = "virtualTouchID",
  933. virtualEventNames = "vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel".split( " " ),
  934. touchEventProps = "clientX clientY pageX pageY screenX screenY".split( " " ),
  935. mouseHookProps = $.event.mouseHooks ? $.event.mouseHooks.props : [],
  936. mouseEventProps = $.event.props.concat( mouseHookProps ),
  937. activeDocHandlers = {},
  938. resetTimerID = 0,
  939. startX = 0,
  940. startY = 0,
  941. didScroll = false,
  942. clickBlockList = [],
  943. blockMouseTriggers = false,
  944. blockTouchTriggers = false,
  945. eventCaptureSupported = "addEventListener" in document,
  946. $document = $( document ),
  947. nextTouchID = 1,
  948. lastTouchID = 0, threshold;
  949. $.vmouse = {
  950. moveDistanceThreshold: 10,
  951. clickDistanceThreshold: 10,
  952. resetTimerDuration: 1500
  953. };
  954. function getNativeEvent( event ) {
  955. while ( event && typeof event.originalEvent !== "undefined" ) {
  956. event = event.originalEvent;
  957. }
  958. return event;
  959. }
  960. function createVirtualEvent( event, eventType ) {
  961. var t = event.type,
  962. oe, props, ne, prop, ct, touch, i, j, len;
  963. event = $.Event( event );
  964. event.type = eventType;
  965. oe = event.originalEvent;
  966. props = $.event.props;
  967. // addresses separation of $.event.props in to $.event.mouseHook.props and Issue 3280
  968. // https://github.com/jquery/jquery-mobile/issues/3280
  969. if ( t.search( /^(mouse|click)/ ) > -1 ) {
  970. props = mouseEventProps;
  971. }
  972. // copy original event properties over to the new event
  973. // this would happen if we could call $.event.fix instead of $.Event
  974. // but we don't have a way to force an event to be fixed multiple times
  975. if ( oe ) {
  976. for ( i = props.length, prop; i; ) {
  977. prop = props[ --i ];
  978. event[ prop ] = oe[ prop ];
  979. }
  980. }
  981. // make sure that if the mouse and click virtual events are generated
  982. // without a .which one is defined
  983. if ( t.search(/mouse(down|up)|click/) > -1 && !event.which ) {
  984. event.which = 1;
  985. }
  986. if ( t.search(/^touch/) !== -1 ) {
  987. ne = getNativeEvent( oe );
  988. t = ne.touches;
  989. ct = ne.changedTouches;
  990. touch = ( t && t.length ) ? t[0] : ( ( ct && ct.length ) ? ct[ 0 ] : undefined );
  991. if ( touch ) {
  992. for ( j = 0, len = touchEventProps.length; j < len; j++) {
  993. prop = touchEventProps[ j ];
  994. event[ prop ] = touch[ prop ];
  995. }
  996. }
  997. }
  998. return event;
  999. }
  1000. function getVirtualBindingFlags( element ) {
  1001. var flags = {},
  1002. b, k;
  1003. while ( element ) {
  1004. b = $.data( element, dataPropertyName );
  1005. for ( k in b ) {
  1006. if ( b[ k ] ) {
  1007. flags[ k ] = flags.hasVirtualBinding = true;
  1008. }
  1009. }
  1010. element = element.parentNode;
  1011. }
  1012. return flags;
  1013. }
  1014. function getClosestElementWithVirtualBinding( element, eventType ) {
  1015. var b;
  1016. while ( element ) {
  1017. b = $.data( element, dataPropertyName );
  1018. if ( b && ( !eventType || b[ eventType ] ) ) {
  1019. return element;
  1020. }
  1021. element = element.parentNode;
  1022. }
  1023. return null;
  1024. }
  1025. function enableTouchBindings() {
  1026. blockTouchTriggers = false;
  1027. }
  1028. function disableTouchBindings() {
  1029. blockTouchTriggers = true;
  1030. }
  1031. function enableMouseBindings() {
  1032. lastTouchID = 0;
  1033. clickBlockList.length = 0;
  1034. blockMouseTriggers = false;
  1035. // When mouse bindings are enabled, our
  1036. // touch bindings are disabled.
  1037. disableTouchBindings();
  1038. }
  1039. function disableMouseBindings() {
  1040. // When mouse bindings are disabled, our
  1041. // touch bindings are enabled.
  1042. enableTouchBindings();
  1043. }
  1044. function startResetTimer() {
  1045. clearResetTimer();
  1046. resetTimerID = setTimeout( function() {
  1047. resetTimerID = 0;
  1048. enableMouseBindings();
  1049. }, $.vmouse.resetTimerDuration );
  1050. }
  1051. function clearResetTimer() {
  1052. if ( resetTimerID ) {
  1053. clearTimeout( resetTimerID );
  1054. resetTimerID = 0;
  1055. }
  1056. }
  1057. function triggerVirtualEvent( eventType, event, flags ) {
  1058. var ve;
  1059. if ( ( flags && flags[ eventType ] ) ||
  1060. ( !flags && getClosestElementWithVirtualBinding( event.target, eventType ) ) ) {
  1061. ve = createVirtualEvent( event, eventType );
  1062. $( event.target).trigger( ve );
  1063. }
  1064. return ve;
  1065. }
  1066. function mouseEventCallback( event ) {
  1067. var touchID = $.data( event.target, touchTargetPropertyName );
  1068. if ( !blockMouseTriggers && ( !lastTouchID || lastTouchID !== touchID ) ) {
  1069. var ve = triggerVirtualEvent( "v" + event.type, event );
  1070. if ( ve ) {
  1071. if ( ve.isDefaultPrevented() ) {
  1072. event.preventDefault();
  1073. }
  1074. if ( ve.isPropagationStopped() ) {
  1075. event.stopPropagation();
  1076. }
  1077. if ( ve.isImmediatePropagationStopped() ) {
  1078. event.stopImmediatePropagation();
  1079. }
  1080. }
  1081. }
  1082. }
  1083. function handleTouchStart( event ) {
  1084. var touches = getNativeEvent( event ).touches,
  1085. target, flags;
  1086. if ( touches && touches.length === 1 ) {
  1087. target = event.target;
  1088. flags = getVirtualBindingFlags( target );
  1089. if ( flags.hasVirtualBinding ) {
  1090. lastTouchID = nextTouchID++;
  1091. $.data( target, touchTargetPropertyName, lastTouchID );
  1092. clearResetTimer();
  1093. disableMouseBindings();
  1094. didScroll = false;
  1095. var t = getNativeEvent( event ).touches[ 0 ];
  1096. startX = t.pageX;
  1097. startY = t.pageY;
  1098. triggerVirtualEvent( "vmouseover", event, flags );
  1099. triggerVirtualEvent( "vmousedown", event, flags );
  1100. }
  1101. }
  1102. }
  1103. function handleScroll( event ) {
  1104. if ( blockTouchTriggers ) {
  1105. return;
  1106. }
  1107. if ( !didScroll ) {
  1108. triggerVirtualEvent( "vmousecancel", event, getVirtualBindingFlags( event.target ) );
  1109. }
  1110. didScroll = true;
  1111. startResetTimer();
  1112. }
  1113. function handleTouchMove( event ) {
  1114. if ( blockTouchTriggers ) {
  1115. return;
  1116. }
  1117. var t = getNativeEvent( event ).touches[ 0 ],
  1118. didCancel = didScroll,
  1119. moveThreshold = $.vmouse.moveDistanceThreshold,
  1120. flags = getVirtualBindingFlags( event.target );
  1121. didScroll = didScroll ||
  1122. ( Math.abs( t.pageX - startX ) > moveThreshold ||
  1123. Math.abs( t.pageY - startY ) > moveThreshold );
  1124. if ( didScroll && !didCancel ) {
  1125. triggerVirtualEvent( "vmousecancel", event, flags );
  1126. }
  1127. triggerVirtualEvent( "vmousemove", event, flags );
  1128. startResetTimer();
  1129. }
  1130. function handleTouchEnd( event ) {
  1131. if ( blockTouchTriggers ) {
  1132. return;
  1133. }
  1134. disableTouchBindings();
  1135. var flags = getVirtualBindingFlags( event.target ),
  1136. t;
  1137. triggerVirtualEvent( "vmouseup", event, flags );
  1138. if ( !didScroll ) {
  1139. var ve = triggerVirtualEvent( "vclick", event, flags );
  1140. if ( ve && ve.isDefaultPrevented() ) {
  1141. // The target of the mouse events that follow the touchend
  1142. // event don't necessarily match the target used during the
  1143. // touch. This means we need to rely on coordinates for blocking
  1144. // any click that is generated.
  1145. t = getNativeEvent( event ).changedTouches[ 0 ];
  1146. clickBlockList.push({
  1147. touchID: lastTouchID,
  1148. x: t.clientX,
  1149. y: t.clientY
  1150. });
  1151. // Prevent any mouse events that follow from triggering
  1152. // virtual event notifications.
  1153. blockMouseTriggers = true;
  1154. }
  1155. }
  1156. triggerVirtualEvent( "vmouseout", event, flags);
  1157. didScroll = false;
  1158. startResetTimer();
  1159. }
  1160. function hasVirtualBindings( ele ) {
  1161. var bindings = $.data( ele, dataPropertyName ),
  1162. k;
  1163. if ( bindings ) {
  1164. for ( k in bindings ) {
  1165. if ( bindings[ k ] ) {
  1166. return true;
  1167. }
  1168. }
  1169. }
  1170. return false;
  1171. }
  1172. function dummyMouseHandler() {}
  1173. function getSpecialEventObject( eventType ) {
  1174. var realType = eventType.substr( 1 );
  1175. return {
  1176. setup: function( data, namespace ) {
  1177. // If this is the first virtual mouse binding for this element,
  1178. // add a bindings object to its data.
  1179. if ( !hasVirtualBindings( this ) ) {
  1180. $.data( this, dataPropertyName, {} );
  1181. }
  1182. // If setup is called, we know it is the first binding for this
  1183. // eventType, so initialize the count for the eventType to zero.
  1184. var bindings = $.data( this, dataPropertyName );
  1185. bindings[ eventType ] = true;
  1186. // If this is the first virtual mouse event for this type,
  1187. // register a global handler on the document.
  1188. activeDocHandlers[ eventType ] = ( activeDocHandlers[ eventType ] || 0 ) + 1;
  1189. if ( activeDocHandlers[ eventType ] === 1 ) {
  1190. $document.bind( realType, mouseEventCallback );
  1191. }
  1192. // Some browsers, like Opera Mini, won't dispatch mouse/click events
  1193. // for elements unless they actually have handlers registered on them.
  1194. // To get around this, we register dummy handlers on the elements.
  1195. $( this ).bind( realType, dummyMouseHandler );
  1196. // For now, if event capture is not supported, we rely on mouse handlers.
  1197. if ( eventCaptureSupported ) {
  1198. // If this is the first virtual mouse binding for the document,
  1199. // register our touchstart handler on the document.
  1200. activeDocHandlers[ "touchstart" ] = ( activeDocHandlers[ "touchstart" ] || 0) + 1;
  1201. if ( activeDocHandlers[ "touchstart" ] === 1 ) {
  1202. $document.bind( "touchstart", handleTouchStart )
  1203. .bind( "touchend", handleTouchEnd )
  1204. // On touch platforms, touching the screen and then dragging your finger
  1205. // causes the window content to scroll after some distance threshold is
  1206. // exceeded. On these platforms, a scroll prevents a click event from being
  1207. // dispatched, and on some platforms, even the touchend is suppressed. To
  1208. // mimic the suppression of the click event, we need to watch for a scroll
  1209. // event. Unfortunately, some platforms like iOS don't dispatch scroll
  1210. // events until *AFTER* the user lifts their finger (touchend). This means
  1211. // we need to watch both scroll and touchmove events to figure out whether
  1212. // or not a scroll happenens before the touchend event is fired.
  1213. .bind( "touchmove", handleTouchMove )
  1214. .bind( "scroll", handleScroll );
  1215. }
  1216. }
  1217. },
  1218. teardown: function( data, namespace ) {
  1219. // If this is the last virtual binding for this eventType,
  1220. // remove its global handler from the document.
  1221. --activeDocHandlers[ eventType ];
  1222. if ( !activeDocHandlers[ eventType ] ) {
  1223. $document.unbind( realType, mouseEventCallback );
  1224. }
  1225. if ( eventCaptureSupported ) {
  1226. // If this is the last virtual mouse binding in existence,
  1227. // remove our document touchstart listener.
  1228. --activeDocHandlers[ "touchstart" ];
  1229. if ( !activeDocHandlers[ "touchstart" ] ) {
  1230. $document.unbind( "touchstart", handleTouchStart )
  1231. .unbind( "touchmove", handleTouchMove )
  1232. .unbind( "touchend", handleTouchEnd )
  1233. .unbind( "scroll", handleScroll );
  1234. }
  1235. }
  1236. var $this = $( this ),
  1237. bindings = $.data( this, dataPropertyName );
  1238. // teardown may be called when an element was
  1239. // removed from the DOM. If this is the case,
  1240. // jQuery core may have already stripped the element
  1241. // of any data bindings so we need to check it before
  1242. // using it.
  1243. if ( bindings ) {
  1244. bindings[ eventType ] = false;
  1245. }
  1246. // Unregister the dummy event handler.
  1247. $this.unbind( realType, dummyMouseHandler );
  1248. // If this is the last virtual mouse binding on the
  1249. // element, remove the binding data from the element.
  1250. if ( !hasVirtualBindings( this ) ) {
  1251. $this.removeData( dataPropertyName );
  1252. }
  1253. }
  1254. };
  1255. }
  1256. // Expose our custom events to the jQuery bind/unbind mechanism.
  1257. for ( var i = 0; i < virtualEventNames.length; i++ ) {
  1258. $.event.special[ virtualEventNames[ i ] ] = getSpecialEventObject( virtualEventNames[ i ] );
  1259. }
  1260. // Add a capture click handler to block clicks.
  1261. // Note that we require event capture support for this so if the device
  1262. // doesn't support it, we punt for now and rely solely on mouse events.
  1263. if ( eventCaptureSupported ) {
  1264. document.addEventListener( "click", function( e ) {
  1265. var cnt = clickBlockList.length,
  1266. target = e.target,
  1267. x, y, ele, i, o, touchID;
  1268. if ( cnt ) {
  1269. x = e.clientX;
  1270. y = e.clientY;
  1271. threshold = $.vmouse.clickDistanceThreshold;
  1272. // The idea here is to run through the clickBlockList to see if
  1273. // the current click event is in the proximity of one of our
  1274. // vclick events that had preventDefault() called on it. If we find
  1275. // one, then we block the click.
  1276. //
  1277. // Why do we have to rely on proximity?
  1278. //
  1279. // Because the target of the touch event that triggered the vclick
  1280. // can be different from the target of the click event synthesized
  1281. // by the browser. The target of a mouse/click event that is syntehsized
  1282. // from a touch event seems to be implementation specific. For example,
  1283. // some browsers will fire mouse/click events for a link that is near
  1284. // a touch event, even though the target of the touchstart/touchend event
  1285. // says the user touched outside the link. Also, it seems that with most
  1286. // browsers, the target of the mouse/click event is not calculated until the
  1287. // time it is dispatched, so if you replace an element that you touched
  1288. // with another element, the target of the mouse/click will be the new
  1289. // element underneath that point.
  1290. //
  1291. // Aside from proximity, we also check to see if the target and any
  1292. // of its ancestors were the ones that blocked a click. This is necessary
  1293. // because of the strange mouse/click target calculation done in the
  1294. // Android 2.1 browser, where if you click on an element, and there is a
  1295. // mouse/click handler on one of its ancestors, the target will be the
  1296. // innermost child of the touched element, even if that child is no where
  1297. // near the point of touch.
  1298. ele = target;
  1299. while ( ele ) {
  1300. for ( i = 0; i < cnt; i++ ) {
  1301. o = clickBlockList[ i ];
  1302. touchID = 0;
  1303. if ( ( ele === target && Math.abs( o.x - x ) < threshold && Math.abs( o.y - y ) < threshold ) ||
  1304. $.data( ele, touchTargetPropertyName ) === o.touchID ) {
  1305. // XXX: We may want to consider removing matches from the block list
  1306. // instead of waiting for the reset timer to fire.
  1307. e.preventDefault();
  1308. e.stopPropagation();
  1309. return;
  1310. }
  1311. }
  1312. ele = ele.parentNode;
  1313. }
  1314. }
  1315. }, true);
  1316. }
  1317. })( jQuery, window, document );
  1318. (function( $, undefined ) {
  1319. var support = {
  1320. touch: "ontouchend" in document
  1321. };
  1322. $.mobile = $.mobile || {};
  1323. $.mobile.support = $.mobile.support || {};
  1324. $.extend( $.support, support );
  1325. $.extend( $.mobile.support, support );
  1326. }( jQuery ));
  1327. (function( $, window, undefined ) {
  1328. // add new event shortcuts
  1329. $.each( ( "touchstart touchmove touchend " +
  1330. "tap taphold " +
  1331. "swipe swipeleft swiperight " +
  1332. "scrollstart scrollstop" ).split( " " ), function( i, name ) {
  1333. $.fn[ name ] = function( fn ) {
  1334. return fn ? this.bind( name, fn ) : this.trigger( name );
  1335. };
  1336. // jQuery < 1.8
  1337. if ( $.attrFn ) {
  1338. $.attrFn[ name ] = true;
  1339. }
  1340. });
  1341. var supportTouch = $.mobile.support.touch,
  1342. scrollEvent = "touchmove scroll",
  1343. touchStartEvent = supportTouch ? "touchstart" : "mousedown",
  1344. touchStopEvent = supportTouch ? "touchend" : "mouseup",
  1345. touchMoveEvent = supportTouch ? "touchmove" : "mousemove";
  1346. function triggerCustomEvent( obj, eventType, event ) {
  1347. var originalType = event.type;
  1348. event.type = eventType;
  1349. $.event.handle.call( obj, event );
  1350. event.type = originalType;
  1351. }
  1352. // also handles scrollstop
  1353. $.event.special.scrollstart = {
  1354. enabled: true,
  1355. setup: function() {
  1356. var thisObject = this,
  1357. $this = $( thisObject ),
  1358. scrolling,
  1359. timer;
  1360. function trigger( event, state ) {
  1361. scrolling = state;
  1362. triggerCustomEvent( thisObject, scrolling ? "scrollstart" : "scrollstop", event );
  1363. }
  1364. // iPhone triggers scroll after a small delay; use touchmove instead
  1365. $this.bind( scrollEvent, function( event ) {
  1366. if ( !$.event.special.scrollstart.enabled ) {
  1367. return;
  1368. }
  1369. if ( !scrolling ) {
  1370. trigger( event, true );
  1371. }
  1372. clearTimeout( timer );
  1373. timer = setTimeout( function() {
  1374. trigger( event, false );
  1375. }, 50 );
  1376. });
  1377. }
  1378. };
  1379. // also handles taphold
  1380. $.event.special.tap = {
  1381. tapholdThreshold: 750,
  1382. setup: function() {
  1383. var thisObject = this,
  1384. $this = $( thisObject );
  1385. $this.bind( "vmousedown", function( event ) {
  1386. if ( event.which && event.which !== 1 ) {
  1387. return false;
  1388. }
  1389. var origTarget = event.target,
  1390. origEvent = event.originalEvent,
  1391. timer;
  1392. function clearTapTimer() {
  1393. clearTimeout( timer );
  1394. }
  1395. function clearTapHandlers() {
  1396. clearTapTimer();
  1397. $this.unbind( "vclick", clickHandler )
  1398. .unbind( "vmouseup", clearTapTimer );
  1399. $( document ).unbind( "vmousecancel", clearTapHandlers );
  1400. }
  1401. function clickHandler( event ) {
  1402. clearTapHandlers();
  1403. // ONLY trigger a 'tap' event if the start target is
  1404. // the same as the stop target.
  1405. if ( origTarget === event.target ) {
  1406. triggerCustomEvent( thisObject, "tap", event );
  1407. }
  1408. }
  1409. $this.bind( "vmouseup", clearTapTimer )
  1410. .bind( "vclick", clickHandler );
  1411. $( document ).bind( "vmousecancel", clearTapHandlers );
  1412. timer = setTimeout( function() {
  1413. triggerCustomEvent( thisObject, "taphold", $.Event( "taphold", { target: origTarget } ) );
  1414. }, $.event.special.tap.tapholdThreshold );
  1415. });
  1416. }
  1417. };
  1418. // also handles swipeleft, swiperight
  1419. $.event.special.swipe = {
  1420. scrollSupressionThreshold: 30, // More than this horizontal displacement, and we will suppress scrolling.
  1421. durationThreshold: 1000, // More time than this, and it isn't a swipe.
  1422. horizontalDistanceThreshold: 30, // Swipe horizontal displacement must be more than this.
  1423. verticalDistanceThreshold: 75, // Swipe vertical displacement must be less than this.
  1424. setup: function() {
  1425. var thisObject = this,
  1426. $this = $( thisObject );
  1427. $this.bind( touchStartEvent, function( event ) {
  1428. var data = event.originalEvent.touches ?
  1429. event.originalEvent.touches[ 0 ] : event,
  1430. start = {
  1431. time: ( new Date() ).getTime(),
  1432. coords: [ data.pageX, data.pageY ],
  1433. origin: $( event.target )
  1434. },
  1435. stop;
  1436. function moveHandler( event ) {
  1437. if ( !start ) {
  1438. return;
  1439. }
  1440. var data = event.originalEvent.touches ?
  1441. event.originalEvent.touches[ 0 ] : event;
  1442. stop = {
  1443. time: ( new Date() ).getTime(),
  1444. coords: [ data.pageX, data.pageY ]
  1445. };
  1446. // prevent scrolling
  1447. if ( Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.scrollSupressionThreshold ) {
  1448. event.preventDefault();
  1449. }
  1450. }
  1451. $this.bind( touchMoveEvent, moveHandler )
  1452. .one( touchStopEvent, function( event ) {
  1453. $this.unbind( touchMoveEvent, moveHandler );
  1454. if ( start && stop ) {
  1455. if ( stop.time - start.time < $.event.special.swipe.durationThreshold &&
  1456. Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.horizontalDistanceThreshold &&
  1457. Math.abs( start.coords[ 1 ] - stop.coords[ 1 ] ) < $.event.special.swipe.verticalDistanceThreshold ) {
  1458. start.origin.trigger( "swipe" )
  1459. .trigger( start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight" );
  1460. }
  1461. }
  1462. start = stop = undefined;
  1463. });
  1464. });
  1465. }
  1466. };
  1467. $.each({
  1468. scrollstop: "scrollstart",
  1469. taphold: "tap",
  1470. swipeleft: "swipe",
  1471. swiperight: "swipe"
  1472. }, function( event, sourceEvent ) {
  1473. $.event.special[ event ] = {
  1474. setup: function() {
  1475. $( this ).bind( sourceEvent, $.noop );
  1476. }
  1477. };
  1478. });
  1479. })( jQuery, this );
  1480. (function( $, undefined ) {
  1481. $.extend( $.support, {
  1482. orientation: "orientation" in window && "onorientationchange" in window
  1483. });
  1484. }( jQuery ));
  1485. // throttled resize event
  1486. (function( $ ) {
  1487. $.event.special.throttledresize = {
  1488. setup: function() {
  1489. $( this ).bind( "resize", handler );
  1490. },
  1491. teardown: function() {
  1492. $( this ).unbind( "resize", handler );
  1493. }
  1494. };
  1495. var throttle = 250,
  1496. handler = function() {
  1497. curr = ( new Date() ).getTime();
  1498. diff = curr - lastCall;
  1499. if ( diff >= throttle ) {
  1500. lastCall = curr;
  1501. $( this ).trigger( "throttledresize" );
  1502. } else {
  1503. if ( heldCall ) {
  1504. clearTimeout( heldCall );
  1505. }
  1506. // Promise a held call will still execute
  1507. heldCall = setTimeout( handler, throttle - diff );
  1508. }
  1509. },
  1510. lastCall = 0,
  1511. heldCall,
  1512. curr,
  1513. diff;
  1514. })( jQuery );
  1515. (function( $, window ) {
  1516. var win = $( window ),
  1517. event_name = "orientationchange",
  1518. special_event,
  1519. get_orientation,
  1520. last_orientation,
  1521. initial_orientation_is_landscape,
  1522. initial_orientation_is_default,
  1523. portrait_map = { "0": true, "180": true };
  1524. // It seems that some device/browser vendors use window.orientation values 0 and 180 to
  1525. // denote the "default" orientation. For iOS devices, and most other smart-phones tested,
  1526. // the default orientation is always "portrait", but in some Android and RIM based tablets,
  1527. // the default orientation is "landscape". The following code attempts to use the window
  1528. // dimensions to figure out what the current orientation is, and then makes adjustments
  1529. // to the to the portrait_map if necessary, so that we can properly decode the
  1530. // window.orientation value whenever get_orientation() is called.
  1531. //
  1532. // Note that we used to use a media query to figure out what the orientation the browser
  1533. // thinks it is in:
  1534. //
  1535. // initial_orientation_is_landscape = $.mobile.media("all and (orientation: landscape)");
  1536. //
  1537. // but there was an iPhone/iPod Touch bug beginning with iOS 4.2, up through iOS 5.1,
  1538. // where the browser *ALWAYS* applied the landscape media query. This bug does not
  1539. // happen on iPad.
  1540. if ( $.support.orientation ) {
  1541. // Check the window width and height to figure out what the current orientation
  1542. // of the device is at this moment. Note that we've initialized the portrait map
  1543. // values to 0 and 180, *AND* we purposely check for landscape so that if we guess
  1544. // wrong, , we default to the assumption that portrait is the default orientation.
  1545. // We use a threshold check below because on some platforms like iOS, the iPhone
  1546. // form-factor can report a larger width than height if the user turns on the
  1547. // developer console. The actual threshold value is somewhat arbitrary, we just
  1548. // need to make sure it is large enough to exclude the developer console case.
  1549. var ww = window.innerWidth || $( window ).width(),
  1550. wh = window.innerHeight || $( window ).height(),
  1551. landscape_threshold = 50;
  1552. initial_orientation_is_landscape = ww > wh && ( ww - wh ) > landscape_threshold;
  1553. // Now check to see if the current window.orientation is 0 or 180.
  1554. initial_orientation_is_default = portrait_map[ window.orientation ];
  1555. // If the initial orientation is landscape, but window.orientation reports 0 or 180, *OR*
  1556. // if the initial orientation is portrait, but window.orientation reports 90 or -90, we
  1557. // need to flip our portrait_map values because landscape is the default orientation for
  1558. // this device/browser.
  1559. if ( ( initial_orientation_is_landscape && initial_orientation_is_default ) || ( !initial_orientation_is_landscape && !initial_orientation_is_default ) ) {
  1560. portrait_map = { "-90": true, "90": true };
  1561. }
  1562. }
  1563. $.event.special.orientationchange = $.extend( {}, $.event.special.orientationchange, {
  1564. setup: function() {
  1565. // If the event is supported natively, return false so that jQuery
  1566. // will bind to the event using DOM methods.
  1567. if ( $.support.orientation && !$.event.special.orientationchange.disabled ) {
  1568. return false;
  1569. }
  1570. // Get the current orientation to avoid initial double-triggering.
  1571. last_orientation = get_orientation();
  1572. // Because the orientationchange event doesn't exist, simulate the
  1573. // event by testing window dimensions on resize.
  1574. win.bind( "throttledresize", handler );
  1575. },
  1576. teardown: function() {
  1577. // If the event is not supported natively, return false so that
  1578. // jQuery will unbind the event using DOM methods.
  1579. if ( $.support.orientation && !$.event.special.orientationchange.disabled ) {
  1580. return false;
  1581. }
  1582. // Because the orientationchange event doesn't exist, unbind the
  1583. // resize event handler.
  1584. win.unbind( "throttledresize", handler );
  1585. },
  1586. add: function( handleObj ) {
  1587. // Save a reference to the bound event handler.
  1588. var old_handler = handleObj.handler;
  1589. handleObj.handler = function( event ) {
  1590. // Modify event object, adding the .orientation property.
  1591. event.orientation = get_orientation();
  1592. // Call the originally-bound event handler and return its result.
  1593. return old_handler.apply( this, arguments );
  1594. };
  1595. }
  1596. });
  1597. // If the event is not supported natively, this handler will be bound to
  1598. // the window resize event to simulate the orientationchange event.
  1599. function handler() {
  1600. // Get the current orientation.
  1601. var orientation = get_orientation();
  1602. if ( orientation !== last_orientation ) {
  1603. // The orientation has changed, so trigger the orientationchange event.
  1604. last_orientation = orientation;
  1605. win.trigger( event_name );
  1606. }
  1607. }
  1608. // Get the current page orientation. This method is exposed publicly, should it
  1609. // be needed, as jQuery.event.special.orientationchange.orientation()
  1610. $.event.special.orientationchange.orientation = get_orientation = function() {
  1611. var isPortrait = true, elem = document.documentElement;
  1612. // prefer window orientation to the calculation based on screensize as
  1613. // the actual screen resize takes place before or after the orientation change event
  1614. // has been fired depending on implementation (eg android 2.3 is before, iphone after).
  1615. // More testing is required to determine if a more reliable method of determining the new screensize
  1616. // is possible when orientationchange is fired. (eg, use media queries + element + opacity)
  1617. if ( $.support.orientation ) {
  1618. // if the window orientation registers as 0 or 180 degrees report
  1619. // portrait, otherwise landscape
  1620. isPortrait = portrait_map[ window.orientation ];
  1621. } else {
  1622. isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1;
  1623. }
  1624. return isPortrait ? "portrait" : "landscape";
  1625. };
  1626. $.fn[ event_name ] = function( fn ) {
  1627. return fn ? this.bind( event_name, fn ) : this.trigger( event_name );
  1628. };
  1629. // jQuery < 1.8
  1630. if ( $.attrFn ) {
  1631. $.attrFn[ event_name ] = true;
  1632. }
  1633. }( jQuery, this ));
  1634. (function( $, undefined ) {
  1635. var $window = $( window ),
  1636. $html = $( "html" );
  1637. /* $.mobile.media method: pass a CSS media type or query and get a bool return
  1638. note: this feature relies on actual media query support for media queries, though types will work most anywhere
  1639. examples:
  1640. $.mobile.media('screen') // tests for screen media type
  1641. $.mobile.media('screen and (min-width: 480px)') // tests for screen media type with window width > 480px
  1642. $.mobile.media('@media screen and (-webkit-min-device-pixel-ratio: 2)') // tests for webkit 2x pixel ratio (iPhone 4)
  1643. */
  1644. $.mobile.media = (function() {
  1645. // TODO: use window.matchMedia once at least one UA implements it
  1646. var cache = {},
  1647. testDiv = $( "<div id='jquery-mediatest'></div>" ),
  1648. fakeBody = $( "<body>" ).append( testDiv );
  1649. return function( query ) {
  1650. if ( !( query in cache ) ) {
  1651. var styleBlock = document.createElement( "style" ),
  1652. cssrule = "@media " + query + " { #jquery-mediatest { position:absolute; } }";
  1653. //must set type for IE!
  1654. styleBlock.type = "text/css";
  1655. if ( styleBlock.styleSheet ) {
  1656. styleBlock.styleSheet.cssText = cssrule;
  1657. } else {
  1658. styleBlock.appendChild( document.createTextNode(cssrule) );
  1659. }
  1660. $html.prepend( fakeBody ).prepend( styleBlock );
  1661. cache[ query ] = testDiv.css( "position" ) === "absolute";
  1662. fakeBody.add( styleBlock ).remove();
  1663. }
  1664. return cache[ query ];
  1665. };
  1666. })();
  1667. })(jQuery);
  1668. (function( $, undefined ) {
  1669. // thx Modernizr
  1670. function propExists( prop ) {
  1671. var uc_prop = prop.charAt( 0 ).toUpperCase() + prop.substr( 1 ),
  1672. props = ( prop + " " + vendors.join( uc_prop + " " ) + uc_prop ).split( " " );
  1673. for ( var v in props ) {
  1674. if ( fbCSS[ props[ v ] ] !== undefined ) {
  1675. return true;
  1676. }
  1677. }
  1678. }
  1679. var fakeBody = $( "<body>" ).prependTo( "html" ),
  1680. fbCSS = fakeBody[ 0 ].style,
  1681. vendors = [ "Webkit", "Moz", "O" ],
  1682. webos = "palmGetResource" in window, //only used to rule out scrollTop
  1683. opera = window.opera,
  1684. operamini = window.operamini && ({}).toString.call( window.operamini ) === "[object OperaMini]",
  1685. bb = window.blackberry && !propExists( "-webkit-transform" ); //only used to rule out box shadow, as it's filled opaque on BB 5 and lower
  1686. function validStyle( prop, value, check_vend ) {
  1687. var div = document.createElement( 'div' ),
  1688. uc = function( txt ) {
  1689. return txt.charAt( 0 ).toUpperCase() + txt.substr( 1 );
  1690. },
  1691. vend_pref = function( vend ) {
  1692. return "-" + vend.charAt( 0 ).toLowerCase() + vend.substr( 1 ) + "-";
  1693. },
  1694. check_style = function( vend ) {
  1695. var vend_prop = vend_pref( vend ) + prop + ": " + value + ";",
  1696. uc_vend = uc( vend ),
  1697. propStyle = uc_vend + uc( prop );
  1698. div.setAttribute( "style", vend_prop );
  1699. if ( !!div.style[ propStyle ] ) {
  1700. ret = true;
  1701. }
  1702. },
  1703. check_vends = check_vend ? [ check_vend ] : vendors,
  1704. ret;
  1705. for( var i = 0; i < check_vends.length; i++ ) {
  1706. check_style( check_vends[i] );
  1707. }
  1708. return !!ret;
  1709. }
  1710. // Thanks to Modernizr src for this test idea. `perspective` check is limited to Moz to prevent a false positive for 3D transforms on Android.
  1711. function transform3dTest() {
  1712. var prop = "transform-3d";
  1713. return validStyle( 'perspective', '10px', 'moz' ) || $.mobile.media( "(-" + vendors.join( "-" + prop + "),(-" ) + "-" + prop + "),(" + prop + ")" );
  1714. }
  1715. // Test for dynamic-updating base tag support ( allows us to avoid href,src attr rewriting )
  1716. function baseTagTest() {
  1717. var fauxBase = location.protocol + "//" + location.host + location.pathname + "ui-dir/",
  1718. base = $( "head base" ),
  1719. fauxEle = null,
  1720. href = "",
  1721. link, rebase;
  1722. if ( !base.length ) {
  1723. base = fauxEle = $( "<base>", { "href": fauxBase }).appendTo( "head" );
  1724. } else {
  1725. href = base.attr( "href" );
  1726. }
  1727. link = $( "<a href='testurl' />" ).prependTo( fakeBody );
  1728. rebase = link[ 0 ].href;
  1729. base[ 0 ].href = href || location.pathname;
  1730. if ( fauxEle ) {
  1731. fauxEle.remove();
  1732. }
  1733. return rebase.indexOf( fauxBase ) === 0;
  1734. }
  1735. // Thanks Modernizr
  1736. function cssPointerEventsTest() {
  1737. var element = document.createElement( 'x' ),
  1738. documentElement = document.documentElement,
  1739. getComputedStyle = window.getComputedStyle,
  1740. supports;
  1741. if ( !( 'pointerEvents' in element.style ) ) {
  1742. return false;
  1743. }
  1744. element.style.pointerEvents = 'auto';
  1745. element.style.pointerEvents = 'x';
  1746. documentElement.appendChild( element );
  1747. supports = getComputedStyle &&
  1748. getComputedStyle( element, '' ).pointerEvents === 'auto';
  1749. documentElement.removeChild( element );
  1750. return !!supports;
  1751. }
  1752. function boundingRect() {
  1753. var div = document.createElement( "div" );
  1754. return typeof div.getBoundingClientRect !== "undefined";
  1755. }
  1756. // non-UA-based IE version check by James Padolsey, modified by jdalton - from http://gist.github.com/527683
  1757. // allows for inclusion of IE 6+, including Windows Mobile 7
  1758. $.extend( $.mobile, { browser: {} } );
  1759. $.mobile.browser.ie = (function() {
  1760. var v = 3,
  1761. div = document.createElement( "div" ),
  1762. a = div.all || [];
  1763. do {
  1764. div.innerHTML = "<!--[if gt IE " + ( ++v ) + "]><br><![endif]-->";
  1765. } while( a[0] );
  1766. return v > 4 ? v : !v;
  1767. })();
  1768. $.extend( $.support, {
  1769. cssTransitions: "WebKitTransitionEvent" in window || validStyle( 'transition', 'height 100ms linear' ) && !opera,
  1770. pushState: "pushState" in history && "replaceState" in history,
  1771. mediaquery: $.mobile.media( "only all" ),
  1772. cssPseudoElement: !!propExists( "content" ),
  1773. touchOverflow: !!propExists( "overflowScrolling" ),
  1774. cssTransform3d: transform3dTest(),
  1775. boxShadow: !!propExists( "boxShadow" ) && !bb,
  1776. scrollTop: ( "pageXOffset" in window || "scrollTop" in document.documentElement || "scrollTop" in fakeBody[ 0 ] ) && !webos && !operamini,
  1777. dynamicBaseTag: baseTagTest(),
  1778. cssPointerEvents: cssPointerEventsTest(),
  1779. boundingRect: boundingRect()
  1780. });
  1781. fakeBody.remove();
  1782. // $.mobile.ajaxBlacklist is used to override ajaxEnabled on platforms that have known conflicts with hash history updates (BB5, Symbian)
  1783. // or that generally work better browsing in regular http for full page refreshes (Opera Mini)
  1784. // Note: This detection below is used as a last resort.
  1785. // We recommend only using these detection methods when all other more reliable/forward-looking approaches are not possible
  1786. var nokiaLTE7_3 = (function() {
  1787. var ua = window.navigator.userAgent;
  1788. //The following is an attempt to match Nokia browsers that are running Symbian/s60, with webkit, version 7.3 or older
  1789. return ua.indexOf( "Nokia" ) > -1 &&
  1790. ( ua.indexOf( "Symbian/3" ) > -1 || ua.indexOf( "Series60/5" ) > -1 ) &&
  1791. ua.indexOf( "AppleWebKit" ) > -1 &&
  1792. ua.match( /(BrowserNG|NokiaBrowser)\/7\.[0-3]/ );
  1793. })();
  1794. // Support conditions that must be met in order to proceed
  1795. // default enhanced qualifications are media query support OR IE 7+
  1796. $.mobile.gradeA = function() {
  1797. return ( $.support.mediaquery || $.mobile.browser.ie && $.mobile.browser.ie >= 7 ) && ( $.support.boundingRect || $.fn.jquery.match(/1\.[0-7+]\.[0-9+]?/) !== null );
  1798. };
  1799. $.mobile.ajaxBlacklist =
  1800. // BlackBerry browsers, pre-webkit
  1801. window.blackberry && !window.WebKitPoint ||
  1802. // Opera Mini
  1803. operamini ||
  1804. // Symbian webkits pre 7.3
  1805. nokiaLTE7_3;
  1806. // Lastly, this workaround is the only way we've found so far to get pre 7.3 Symbian webkit devices
  1807. // to render the stylesheets when they're referenced before this script, as we'd recommend doing.
  1808. // This simply reappends the CSS in place, which for some reason makes it apply
  1809. if ( nokiaLTE7_3 ) {
  1810. $(function() {
  1811. $( "head link[rel='stylesheet']" ).attr( "rel", "alternate stylesheet" ).attr( "rel", "stylesheet" );
  1812. });
  1813. }
  1814. // For ruling out shadows via css
  1815. if ( !$.support.boxShadow ) {
  1816. $( "html" ).addClass( "ui-mobile-nosupport-boxshadow" );
  1817. }
  1818. })( jQuery );
  1819. (function( $, undefined ) {
  1820. $.widget( "mobile.page", $.mobile.widget, {
  1821. options: {
  1822. theme: "c",
  1823. domCache: false,
  1824. keepNativeDefault: ":jqmData(role='none'), :jqmData(role='nojs')"
  1825. },
  1826. _create: function() {
  1827. var self = this;
  1828. // if false is returned by the callbacks do not create the page
  1829. if ( self._trigger( "beforecreate" ) === false ) {
  1830. return false;
  1831. }
  1832. self.element
  1833. .attr( "tabindex", "0" )
  1834. .addClass( "ui-page ui-body-" + self.options.theme )
  1835. .bind( "pagebeforehide", function() {
  1836. self.removeContainerBackground();
  1837. } )
  1838. .bind( "pagebeforeshow", function() {
  1839. self.setContainerBackground();
  1840. } );
  1841. },
  1842. removeContainerBackground: function() {
  1843. $.mobile.pageContainer.removeClass( "ui-overlay-" + $.mobile.getInheritedTheme( this.element.parent() ) );
  1844. },
  1845. // set the page container background to the page theme
  1846. setContainerBackground: function( theme ) {
  1847. if ( this.options.theme ) {
  1848. $.mobile.pageContainer.addClass( "ui-overlay-" + ( theme || this.options.theme ) );
  1849. }
  1850. },
  1851. keepNativeSelector: function() {
  1852. var options = this.options,
  1853. keepNativeDefined = options.keepNative && $.trim( options.keepNative );
  1854. if ( keepNativeDefined && options.keepNative !== options.keepNativeDefault ) {
  1855. return [options.keepNative, options.keepNativeDefault].join( ", " );
  1856. }
  1857. return options.keepNativeDefault;
  1858. }
  1859. });
  1860. })( jQuery );
  1861. // Script: jQuery hashchange event
  1862. //
  1863. // *Version: 1.3, Last updated: 7/21/2010*
  1864. //
  1865. // Project Home - http://benalman.com/projects/jquery-hashchange-plugin/
  1866. // GitHub - http://github.com/cowboy/jquery-hashchange/
  1867. // Source - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.js
  1868. // (Minified) - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.min.js (0.8kb gzipped)
  1869. //
  1870. // About: License
  1871. //
  1872. // Copyright (c) 2010 "Cowboy" Ben Alman,
  1873. // Dual licensed under the MIT and GPL licenses.
  1874. // http://benalman.com/about/license/
  1875. //
  1876. // About: Examples
  1877. //
  1878. // These working examples, complete with fully commented code, illustrate a few
  1879. // ways in which this plugin can be used.
  1880. //
  1881. // hashchange event - http://benalman.com/code/projects/jquery-hashchange/examples/hashchange/
  1882. // document.domain - http://benalman.com/code/projects/jquery-hashchange/examples/document_domain/
  1883. //
  1884. // About: Support and Testing
  1885. //
  1886. // Information about what version or versions of jQuery this plugin has been
  1887. // tested with, what browsers it has been tested in, and where the unit tests
  1888. // reside (so you can test it yourself).
  1889. //
  1890. // jQuery Versions - 1.2.6, 1.3.2, 1.4.1, 1.4.2
  1891. // Browsers Tested - Internet Explorer 6-8, Firefox 2-4, Chrome 5-6, Safari 3.2-5,
  1892. // Opera 9.6-10.60, iPhone 3.1, Android 1.6-2.2, BlackBerry 4.6-5.
  1893. // Unit Tests - http://benalman.com/code/projects/jquery-hashchange/unit/
  1894. //
  1895. // About: Known issues
  1896. //
  1897. // While this jQuery hashchange event implementation is quite stable and
  1898. // robust, there are a few unfortunate browser bugs surrounding expected
  1899. // hashchange event-based behaviors, independent of any JavaScript
  1900. // window.onhashchange abstraction. See the following examples for more
  1901. // information:
  1902. //
  1903. // Chrome: Back Button - http://benalman.com/code/projects/jquery-hashchange/examples/bug-chrome-back-button/
  1904. // Firefox: Remote XMLHttpRequest - http://benalman.com/code/projects/jquery-hashchange/examples/bug-firefox-remote-xhr/
  1905. // WebKit: Back Button in an Iframe - http://benalman.com/code/projects/jquery-hashchange/examples/bug-webkit-hash-iframe/
  1906. // Safari: Back Button from a different domain - http://benalman.com/code/projects/jquery-hashchange/examples/bug-safari-back-from-diff-domain/
  1907. //
  1908. // Also note that should a browser natively support the window.onhashchange
  1909. // event, but not report that it does, the fallback polling loop will be used.
  1910. //
  1911. // About: Release History
  1912. //
  1913. // 1.3 - (7/21/2010) Reorganized IE6/7 Iframe code to make it more
  1914. // "removable" for mobile-only development. Added IE6/7 document.title
  1915. // support. Attempted to make Iframe as hidden as possible by using
  1916. // techniques from http://www.paciellogroup.com/blog/?p=604. Added
  1917. // support for the "shortcut" format $(window).hashchange( fn ) and
  1918. // $(window).hashchange() like jQuery provides for built-in events.
  1919. // Renamed jQuery.hashchangeDelay to <jQuery.fn.hashchange.delay> and
  1920. // lowered its default value to 50. Added <jQuery.fn.hashchange.domain>
  1921. // and <jQuery.fn.hashchange.src> properties plus document-domain.html
  1922. // file to address access denied issues when setting document.domain in
  1923. // IE6/7.
  1924. // 1.2 - (2/11/2010) Fixed a bug where coming back to a page using this plugin
  1925. // from a page on another domain would cause an error in Safari 4. Also,
  1926. // IE6/7 Iframe is now inserted after the body (this actually works),
  1927. // which prevents the page from scrolling when the event is first bound.
  1928. // Event can also now be bound before DOM ready, but it won't be usable
  1929. // before then in IE6/7.
  1930. // 1.1 - (1/21/2010) Incorporated document.documentMode test to fix IE8 bug
  1931. // where browser version is incorrectly reported as 8.0, despite
  1932. // inclusion of the X-UA-Compatible IE=EmulateIE7 meta tag.
  1933. // 1.0 - (1/9/2010) Initial Release. Broke out the jQuery BBQ event.special
  1934. // window.onhashchange functionality into a separate plugin for users
  1935. // who want just the basic event & back button support, without all the
  1936. // extra awesomeness that BBQ provides. This plugin will be included as
  1937. // part of jQuery BBQ, but also be available separately.
  1938. (function( $, window, undefined ) {
  1939. // Reused string.
  1940. var str_hashchange = 'hashchange',
  1941. // Method / object references.
  1942. doc = document,
  1943. fake_onhashchange,
  1944. special = $.event.special,
  1945. // Does the browser support window.onhashchange? Note that IE8 running in
  1946. // IE7 compatibility mode reports true for 'onhashchange' in window, even
  1947. // though the event isn't supported, so also test document.documentMode.
  1948. doc_mode = doc.documentMode,
  1949. supports_onhashchange = 'on' + str_hashchange in window && ( doc_mode === undefined || doc_mode > 7 );
  1950. // Get location.hash (or what you'd expect location.hash to be) sans any
  1951. // leading #. Thanks for making this necessary, Firefox!
  1952. function get_fragment( url ) {
  1953. url = url || location.href;
  1954. return '#' + url.replace( /^[^#]*#?(.*)$/, '$1' );
  1955. };
  1956. // Method: jQuery.fn.hashchange
  1957. //
  1958. // Bind a handler to the window.onhashchange event or trigger all bound
  1959. // window.onhashchange event handlers. This behavior is consistent with
  1960. // jQuery's built-in event handlers.
  1961. //
  1962. // Usage:
  1963. //
  1964. // > jQuery(window).hashchange( [ handler ] );
  1965. //
  1966. // Arguments:
  1967. //
  1968. // handler - (Function) Optional handler to be bound to the hashchange
  1969. // event. This is a "shortcut" for the more verbose form:
  1970. // jQuery(window).bind( 'hashchange', handler ). If handler is omitted,
  1971. // all bound window.onhashchange event handlers will be triggered. This
  1972. // is a shortcut for the more verbose
  1973. // jQuery(window).trigger( 'hashchange' ). These forms are described in
  1974. // the <hashchange event> section.
  1975. //
  1976. // Returns:
  1977. //
  1978. // (jQuery) The initial jQuery collection of elements.
  1979. // Allow the "shortcut" format $(elem).hashchange( fn ) for binding and
  1980. // $(elem).hashchange() for triggering, like jQuery does for built-in events.
  1981. $.fn[ str_hashchange ] = function( fn ) {
  1982. return fn ? this.bind( str_hashchange, fn ) : this.trigger( str_hashchange );
  1983. };
  1984. // Property: jQuery.fn.hashchange.delay
  1985. //
  1986. // The numeric interval (in milliseconds) at which the <hashchange event>
  1987. // polling loop executes. Defaults to 50.
  1988. // Property: jQuery.fn.hashchange.domain
  1989. //
  1990. // If you're setting document.domain in your JavaScript, and you want hash
  1991. // history to work in IE6/7, not only must this property be set, but you must
  1992. // also set document.domain BEFORE jQuery is loaded into the page. This
  1993. // property is only applicable if you are supporting IE6/7 (or IE8 operating
  1994. // in "IE7 compatibility" mode).
  1995. //
  1996. // In addition, the <jQuery.fn.hashchange.src> property must be set to the
  1997. // path of the included "document-domain.html" file, which can be renamed or
  1998. // modified if necessary (note that the document.domain specified must be the
  1999. // same in both your main JavaScript as well as in this file).
  2000. //
  2001. // Usage:
  2002. //
  2003. // jQuery.fn.hashchange.domain = document.domain;
  2004. // Property: jQuery.fn.hashchange.src
  2005. //
  2006. // If, for some reason, you need to specify an Iframe src file (for example,
  2007. // when setting document.domain as in <jQuery.fn.hashchange.domain>), you can
  2008. // do so using this property. Note that when using this property, history
  2009. // won't be recorded in IE6/7 until the Iframe src file loads. This property
  2010. // is only applicable if you are supporting IE6/7 (or IE8 operating in "IE7
  2011. // compatibility" mode).
  2012. //
  2013. // Usage:
  2014. //
  2015. // jQuery.fn.hashchange.src = 'path/to/file.html';
  2016. $.fn[ str_hashchange ].delay = 50;
  2017. /*
  2018. $.fn[ str_hashchange ].domain = null;
  2019. $.fn[ str_hashchange ].src = null;
  2020. */
  2021. // Event: hashchange event
  2022. //
  2023. // Fired when location.hash changes. In browsers that support it, the native
  2024. // HTML5 window.onhashchange event is used, otherwise a polling loop is
  2025. // initialized, running every <jQuery.fn.hashchange.delay> milliseconds to
  2026. // see if the hash has changed. In IE6/7 (and IE8 operating in "IE7
  2027. // compatibility" mode), a hidden Iframe is created to allow the back button
  2028. // and hash-based history to work.
  2029. //
  2030. // Usage as described in <jQuery.fn.hashchange>:
  2031. //
  2032. // > // Bind an event handler.
  2033. // > jQuery(window).hashchange( function(e) {
  2034. // > var hash = location.hash;
  2035. // > ...
  2036. // > });
  2037. // >
  2038. // > // Manually trigger the event handler.
  2039. // > jQuery(window).hashchange();
  2040. //
  2041. // A more verbose usage that allows for event namespacing:
  2042. //
  2043. // > // Bind an event handler.
  2044. // > jQuery(window).bind( 'hashchange', function(e) {
  2045. // > var hash = location.hash;
  2046. // > ...
  2047. // > });
  2048. // >
  2049. // > // Manually trigger the event handler.
  2050. // > jQuery(window).trigger( 'hashchange' );
  2051. //
  2052. // Additional Notes:
  2053. //
  2054. // * The polling loop and Iframe are not created until at least one handler
  2055. // is actually bound to the 'hashchange' event.
  2056. // * If you need the bound handler(s) to execute immediately, in cases where
  2057. // a location.hash exists on page load, via bookmark or page refresh for
  2058. // example, use jQuery(window).hashchange() or the more verbose
  2059. // jQuery(window).trigger( 'hashchange' ).
  2060. // * The event can be bound before DOM ready, but since it won't be usable
  2061. // before then in IE6/7 (due to the necessary Iframe), recommended usage is
  2062. // to bind it inside a DOM ready handler.
  2063. // Override existing $.event.special.hashchange methods (allowing this plugin
  2064. // to be defined after jQuery BBQ in BBQ's source code).
  2065. special[ str_hashchange ] = $.extend( special[ str_hashchange ], {
  2066. // Called only when the first 'hashchange' event is bound to window.
  2067. setup: function() {
  2068. // If window.onhashchange is supported natively, there's nothing to do..
  2069. if ( supports_onhashchange ) { return false; }
  2070. // Otherwise, we need to create our own. And we don't want to call this
  2071. // until the user binds to the event, just in case they never do, since it
  2072. // will create a polling loop and possibly even a hidden Iframe.
  2073. $( fake_onhashchange.start );
  2074. },
  2075. // Called only when the last 'hashchange' event is unbound from window.
  2076. teardown: function() {
  2077. // If window.onhashchange is supported natively, there's nothing to do..
  2078. if ( supports_onhashchange ) { return false; }
  2079. // Otherwise, we need to stop ours (if possible).
  2080. $( fake_onhashchange.stop );
  2081. }
  2082. });
  2083. // fake_onhashchange does all the work of triggering the window.onhashchange
  2084. // event for browsers that don't natively support it, including creating a
  2085. // polling loop to watch for hash changes and in IE 6/7 creating a hidden
  2086. // Iframe to enable back and forward.
  2087. fake_onhashchange = (function() {
  2088. var self = {},
  2089. timeout_id,
  2090. // Remember the initial hash so it doesn't get triggered immediately.
  2091. last_hash = get_fragment(),
  2092. fn_retval = function( val ) { return val; },
  2093. history_set = fn_retval,
  2094. history_get = fn_retval;
  2095. // Start the polling loop.
  2096. self.start = function() {
  2097. timeout_id || poll();
  2098. };
  2099. // Stop the polling loop.
  2100. self.stop = function() {
  2101. timeout_id && clearTimeout( timeout_id );
  2102. timeout_id = undefined;
  2103. };
  2104. // This polling loop checks every $.fn.hashchange.delay milliseconds to see
  2105. // if location.hash has changed, and triggers the 'hashchange' event on
  2106. // window when necessary.
  2107. function poll() {
  2108. var hash = get_fragment(),
  2109. history_hash = history_get( last_hash );
  2110. if ( hash !== last_hash ) {
  2111. history_set( last_hash = hash, history_hash );
  2112. $(window).trigger( str_hashchange );
  2113. } else if ( history_hash !== last_hash ) {
  2114. location.href = location.href.replace( /#.*/, '' ) + history_hash;
  2115. }
  2116. timeout_id = setTimeout( poll, $.fn[ str_hashchange ].delay );
  2117. };
  2118. // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  2119. // vvvvvvvvvvvvvvvvvvv REMOVE IF NOT SUPPORTING IE6/7/8 vvvvvvvvvvvvvvvvvvv
  2120. // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  2121. $.browser.msie && !supports_onhashchange && (function() {
  2122. // Not only do IE6/7 need the "magical" Iframe treatment, but so does IE8
  2123. // when running in "IE7 compatibility" mode.
  2124. var iframe,
  2125. iframe_src;
  2126. // When the event is bound and polling starts in IE 6/7, create a hidden
  2127. // Iframe for history handling.
  2128. self.start = function() {
  2129. if ( !iframe ) {
  2130. iframe_src = $.fn[ str_hashchange ].src;
  2131. iframe_src = iframe_src && iframe_src + get_fragment();
  2132. // Create hidden Iframe. Attempt to make Iframe as hidden as possible
  2133. // by using techniques from http://www.paciellogroup.com/blog/?p=604.
  2134. iframe = $('<iframe tabindex="-1" title="empty"/>').hide()
  2135. // When Iframe has completely loaded, initialize the history and
  2136. // start polling.
  2137. .one( 'load', function() {
  2138. iframe_src || history_set( get_fragment() );
  2139. poll();
  2140. })
  2141. // Load Iframe src if specified, otherwise nothing.
  2142. .attr( 'src', iframe_src || 'javascript:0' )
  2143. // Append Iframe after the end of the body to prevent unnecessary
  2144. // initial page scrolling (yes, this works).
  2145. .insertAfter( 'body' )[0].contentWindow;
  2146. // Whenever `document.title` changes, update the Iframe's title to
  2147. // prettify the back/next history menu entries. Since IE sometimes
  2148. // errors with "Unspecified error" the very first time this is set
  2149. // (yes, very useful) wrap this with a try/catch block.
  2150. doc.onpropertychange = function() {
  2151. try {
  2152. if ( event.propertyName === 'title' ) {
  2153. iframe.document.title = doc.title;
  2154. }
  2155. } catch(e) {}
  2156. };
  2157. }
  2158. };
  2159. // Override the "stop" method since an IE6/7 Iframe was created. Even
  2160. // if there are no longer any bound event handlers, the polling loop
  2161. // is still necessary for back/next to work at all!
  2162. self.stop = fn_retval;
  2163. // Get history by looking at the hidden Iframe's location.hash.
  2164. history_get = function() {
  2165. return get_fragment( iframe.location.href );
  2166. };
  2167. // Set a new history item by opening and then closing the Iframe
  2168. // document, *then* setting its location.hash. If document.domain has
  2169. // been set, update that as well.
  2170. history_set = function( hash, history_hash ) {
  2171. var iframe_doc = iframe.document,
  2172. domain = $.fn[ str_hashchange ].domain;
  2173. if ( hash !== history_hash ) {
  2174. // Update Iframe with any initial `document.title` that might be set.
  2175. iframe_doc.title = doc.title;
  2176. // Opening the Iframe's document after it has been closed is what
  2177. // actually adds a history entry.
  2178. iframe_doc.open();
  2179. // Set document.domain for the Iframe document as well, if necessary.
  2180. domain && iframe_doc.write( '<script>document.domain="' + domain + '"</script>' );
  2181. iframe_doc.close();
  2182. // Update the Iframe's hash, for great justice.
  2183. iframe.location.hash = hash;
  2184. }
  2185. };
  2186. })();
  2187. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2188. // ^^^^^^^^^^^^^^^^^^^ REMOVE IF NOT SUPPORTING IE6/7/8 ^^^^^^^^^^^^^^^^^^^
  2189. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2190. return self;
  2191. })();
  2192. })(jQuery,this);
  2193. (function( $, window, undefined ) {
  2194. var createHandler = function( sequential ) {
  2195. // Default to sequential
  2196. if ( sequential === undefined ) {
  2197. sequential = true;
  2198. }
  2199. return function( name, reverse, $to, $from ) {
  2200. var deferred = new $.Deferred(),
  2201. reverseClass = reverse ? " reverse" : "",
  2202. active = $.mobile.urlHistory.getActive(),
  2203. toScroll = active.lastScroll || $.mobile.defaultHomeScroll,
  2204. screenHeight = $.mobile.getScreenHeight(),
  2205. maxTransitionOverride = $.mobile.maxTransitionWidth !== false && $( window ).width() > $.mobile.maxTransitionWidth,
  2206. none = !$.support.cssTransitions || maxTransitionOverride || !name || name === "none" || Math.max( $( window ).scrollTop(), toScroll ) > $.mobile.getMaxScrollForTransition(),
  2207. toPreClass = " ui-page-pre-in",
  2208. toggleViewportClass = function() {
  2209. $.mobile.pageContainer.toggleClass( "ui-mobile-viewport-transitioning viewport-" + name );
  2210. },
  2211. scrollPage = function() {
  2212. // By using scrollTo instead of silentScroll, we can keep things better in order
  2213. // Just to be precautios, disable scrollstart listening like silentScroll would
  2214. $.event.special.scrollstart.enabled = false;
  2215. window.scrollTo( 0, toScroll );
  2216. // reenable scrollstart listening like silentScroll would
  2217. setTimeout( function() {
  2218. $.event.special.scrollstart.enabled = true;
  2219. }, 150 );
  2220. },
  2221. cleanFrom = function() {
  2222. $from
  2223. .removeClass( $.mobile.activePageClass + " out in reverse " + name )
  2224. .height( "" );
  2225. },
  2226. startOut = function() {
  2227. // if it's not sequential, call the doneOut transition to start the TO page animating in simultaneously
  2228. if ( !sequential ) {
  2229. doneOut();
  2230. }
  2231. else {
  2232. $from.animationComplete( doneOut );
  2233. }
  2234. // Set the from page's height and start it transitioning out
  2235. // Note: setting an explicit height helps eliminate tiling in the transitions
  2236. $from
  2237. .height( screenHeight + $( window ).scrollTop() )
  2238. .addClass( name + " out" + reverseClass );
  2239. },
  2240. doneOut = function() {
  2241. if ( $from && sequential ) {
  2242. cleanFrom();
  2243. }
  2244. startIn();
  2245. },
  2246. startIn = function() {
  2247. // Prevent flickering in phonegap container: see comments at #4024 regarding iOS
  2248. $to.css( "z-index", -10 );
  2249. $to.addClass( $.mobile.activePageClass + toPreClass );
  2250. // Send focus to page as it is now display: block
  2251. $.mobile.focusPage( $to );
  2252. // Set to page height
  2253. $to.height( screenHeight + toScroll );
  2254. scrollPage();
  2255. // Restores visibility of the new page: added together with $to.css( "z-index", -10 );
  2256. $to.css( "z-index", "" );
  2257. if ( !none ) {
  2258. $to.animationComplete( doneIn );
  2259. }
  2260. $to
  2261. .removeClass( toPreClass )
  2262. .addClass( name + " in" + reverseClass );
  2263. if ( none ) {
  2264. doneIn();
  2265. }
  2266. },
  2267. doneIn = function() {
  2268. if ( !sequential ) {
  2269. if ( $from ) {
  2270. cleanFrom();
  2271. }
  2272. }
  2273. $to
  2274. .removeClass( "out in reverse " + name )
  2275. .height( "" );
  2276. toggleViewportClass();
  2277. // In some browsers (iOS5), 3D transitions block the ability to scroll to the desired location during transition
  2278. // This ensures we jump to that spot after the fact, if we aren't there already.
  2279. if ( $( window ).scrollTop() !== toScroll ) {
  2280. scrollPage();
  2281. }
  2282. deferred.resolve( name, reverse, $to, $from, true );
  2283. };
  2284. toggleViewportClass();
  2285. if ( $from && !none ) {
  2286. startOut();
  2287. }
  2288. else {
  2289. doneOut();
  2290. }
  2291. return deferred.promise();
  2292. };
  2293. };
  2294. // generate the handlers from the above
  2295. var sequentialHandler = createHandler(),
  2296. simultaneousHandler = createHandler( false ),
  2297. defaultGetMaxScrollForTransition = function() {
  2298. return $.mobile.getScreenHeight() * 3;
  2299. };
  2300. // Make our transition handler the public default.
  2301. $.mobile.defaultTransitionHandler = sequentialHandler;
  2302. //transition handler dictionary for 3rd party transitions
  2303. $.mobile.transitionHandlers = {
  2304. "default": $.mobile.defaultTransitionHandler,
  2305. "sequential": sequentialHandler,
  2306. "simultaneous": simultaneousHandler
  2307. };
  2308. $.mobile.transitionFallbacks = {};
  2309. // If transition is defined, check if css 3D transforms are supported, and if not, if a fallback is specified
  2310. $.mobile._maybeDegradeTransition = function( transition ) {
  2311. if ( transition && !$.support.cssTransform3d && $.mobile.transitionFallbacks[ transition ] ) {
  2312. transition = $.mobile.transitionFallbacks[ transition ];
  2313. }
  2314. return transition;
  2315. };
  2316. // Set the getMaxScrollForTransition to default if no implementation was set by user
  2317. $.mobile.getMaxScrollForTransition = $.mobile.getMaxScrollForTransition || defaultGetMaxScrollForTransition;
  2318. })( jQuery, this );
  2319. (function( $, undefined ) {
  2320. //define vars for interal use
  2321. var $window = $( window ),
  2322. $html = $( 'html' ),
  2323. $head = $( 'head' ),
  2324. //url path helpers for use in relative url management
  2325. path = {
  2326. // This scary looking regular expression parses an absolute URL or its relative
  2327. // variants (protocol, site, document, query, and hash), into the various
  2328. // components (protocol, host, path, query, fragment, etc that make up the
  2329. // URL as well as some other commonly used sub-parts. When used with RegExp.exec()
  2330. // or String.match, it parses the URL into a results array that looks like this:
  2331. //
  2332. // [0]: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content
  2333. // [1]: http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread
  2334. // [2]: http://jblas:password@mycompany.com:8080/mail/inbox
  2335. // [3]: http://jblas:password@mycompany.com:8080
  2336. // [4]: http:
  2337. // [5]: //
  2338. // [6]: jblas:password@mycompany.com:8080
  2339. // [7]: jblas:password
  2340. // [8]: jblas
  2341. // [9]: password
  2342. // [10]: mycompany.com:8080
  2343. // [11]: mycompany.com
  2344. // [12]: 8080
  2345. // [13]: /mail/inbox
  2346. // [14]: /mail/
  2347. // [15]: inbox
  2348. // [16]: ?msg=1234&type=unread
  2349. // [17]: #msg-content
  2350. //
  2351. urlParseRE: /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/,
  2352. // Abstraction to address xss (Issue #4787) by removing the authority in
  2353. // browsers that auto decode it. All references to location.href should be
  2354. // replaced with a call to this method so that it can be dealt with properly here
  2355. getLocation: function( url ) {
  2356. var uri = url ? this.parseUrl( url ) : location,
  2357. hash = this.parseUrl( url || location.href ).hash;
  2358. // mimic the browser with an empty string when the hash is empty
  2359. hash = hash === "#" ? "" : hash;
  2360. // Make sure to parse the url or the location object for the hash because using location.hash
  2361. // is autodecoded in firefox, the rest of the url should be from the object (location unless
  2362. // we're testing) to avoid the inclusion of the authority
  2363. return uri.protocol + "//" + uri.host + uri.pathname + uri.search + hash;
  2364. },
  2365. parseLocation: function() {
  2366. return this.parseUrl( this.getLocation() );
  2367. },
  2368. //Parse a URL into a structure that allows easy access to
  2369. //all of the URL components by name.
  2370. parseUrl: function( url ) {
  2371. // If we're passed an object, we'll assume that it is
  2372. // a parsed url object and just return it back to the caller.
  2373. if ( $.type( url ) === "object" ) {
  2374. return url;
  2375. }
  2376. var matches = path.urlParseRE.exec( url || "" ) || [];
  2377. // Create an object that allows the caller to access the sub-matches
  2378. // by name. Note that IE returns an empty string instead of undefined,
  2379. // like all other browsers do, so we normalize everything so its consistent
  2380. // no matter what browser we're running on.
  2381. return {
  2382. href: matches[ 0 ] || "",
  2383. hrefNoHash: matches[ 1 ] || "",
  2384. hrefNoSearch: matches[ 2 ] || "",
  2385. domain: matches[ 3 ] || "",
  2386. protocol: matches[ 4 ] || "",
  2387. doubleSlash: matches[ 5 ] || "",
  2388. authority: matches[ 6 ] || "",
  2389. username: matches[ 8 ] || "",
  2390. password: matches[ 9 ] || "",
  2391. host: matches[ 10 ] || "",
  2392. hostname: matches[ 11 ] || "",
  2393. port: matches[ 12 ] || "",
  2394. pathname: matches[ 13 ] || "",
  2395. directory: matches[ 14 ] || "",
  2396. filename: matches[ 15 ] || "",
  2397. search: matches[ 16 ] || "",
  2398. hash: matches[ 17 ] || ""
  2399. };
  2400. },
  2401. //Turn relPath into an asbolute path. absPath is
  2402. //an optional absolute path which describes what
  2403. //relPath is relative to.
  2404. makePathAbsolute: function( relPath, absPath ) {
  2405. if ( relPath && relPath.charAt( 0 ) === "/" ) {
  2406. return relPath;
  2407. }
  2408. relPath = relPath || "";
  2409. absPath = absPath ? absPath.replace( /^\/|(\/[^\/]*|[^\/]+)$/g, "" ) : "";
  2410. var absStack = absPath ? absPath.split( "/" ) : [],
  2411. relStack = relPath.split( "/" );
  2412. for ( var i = 0; i < relStack.length; i++ ) {
  2413. var d = relStack[ i ];
  2414. switch ( d ) {
  2415. case ".":
  2416. break;
  2417. case "..":
  2418. if ( absStack.length ) {
  2419. absStack.pop();
  2420. }
  2421. break;
  2422. default:
  2423. absStack.push( d );
  2424. break;
  2425. }
  2426. }
  2427. return "/" + absStack.join( "/" );
  2428. },
  2429. //Returns true if both urls have the same domain.
  2430. isSameDomain: function( absUrl1, absUrl2 ) {
  2431. return path.parseUrl( absUrl1 ).domain === path.parseUrl( absUrl2 ).domain;
  2432. },
  2433. //Returns true for any relative variant.
  2434. isRelativeUrl: function( url ) {
  2435. // All relative Url variants have one thing in common, no protocol.
  2436. return path.parseUrl( url ).protocol === "";
  2437. },
  2438. //Returns true for an absolute url.
  2439. isAbsoluteUrl: function( url ) {
  2440. return path.parseUrl( url ).protocol !== "";
  2441. },
  2442. //Turn the specified realtive URL into an absolute one. This function
  2443. //can handle all relative variants (protocol, site, document, query, fragment).
  2444. makeUrlAbsolute: function( relUrl, absUrl ) {
  2445. if ( !path.isRelativeUrl( relUrl ) ) {
  2446. return relUrl;
  2447. }
  2448. if ( absUrl === undefined ) {
  2449. absUrl = documentBase;
  2450. }
  2451. var relObj = path.parseUrl( relUrl ),
  2452. absObj = path.parseUrl( absUrl ),
  2453. protocol = relObj.protocol || absObj.protocol,
  2454. doubleSlash = relObj.protocol ? relObj.doubleSlash : ( relObj.doubleSlash || absObj.doubleSlash ),
  2455. authority = relObj.authority || absObj.authority,
  2456. hasPath = relObj.pathname !== "",
  2457. pathname = path.makePathAbsolute( relObj.pathname || absObj.filename, absObj.pathname ),
  2458. search = relObj.search || ( !hasPath && absObj.search ) || "",
  2459. hash = relObj.hash;
  2460. return protocol + doubleSlash + authority + pathname + search + hash;
  2461. },
  2462. //Add search (aka query) params to the specified url.
  2463. addSearchParams: function( url, params ) {
  2464. var u = path.parseUrl( url ),
  2465. p = ( typeof params === "object" ) ? $.param( params ) : params,
  2466. s = u.search || "?";
  2467. return u.hrefNoSearch + s + ( s.charAt( s.length - 1 ) !== "?" ? "&" : "" ) + p + ( u.hash || "" );
  2468. },
  2469. convertUrlToDataUrl: function( absUrl ) {
  2470. var u = path.parseUrl( absUrl );
  2471. if ( path.isEmbeddedPage( u ) ) {
  2472. // For embedded pages, remove the dialog hash key as in getFilePath(),
  2473. // otherwise the Data Url won't match the id of the embedded Page.
  2474. return u.hash.split( dialogHashKey )[0].replace( /^#/, "" );
  2475. } else if ( path.isSameDomain( u, documentBase ) ) {
  2476. return u.hrefNoHash.replace( documentBase.domain, "" ).split( dialogHashKey )[0];
  2477. }
  2478. return window.decodeURIComponent(absUrl);
  2479. },
  2480. //get path from current hash, or from a file path
  2481. get: function( newPath ) {
  2482. if ( newPath === undefined ) {
  2483. newPath = path.parseLocation().hash;
  2484. }
  2485. return path.stripHash( newPath ).replace( /[^\/]*\.[^\/*]+$/, '' );
  2486. },
  2487. //return the substring of a filepath before the sub-page key, for making a server request
  2488. getFilePath: function( path ) {
  2489. var splitkey = '&' + $.mobile.subPageUrlKey;
  2490. return path && path.split( splitkey )[0].split( dialogHashKey )[0];
  2491. },
  2492. //set location hash to path
  2493. set: function( path ) {
  2494. location.hash = path;
  2495. },
  2496. //test if a given url (string) is a path
  2497. //NOTE might be exceptionally naive
  2498. isPath: function( url ) {
  2499. return ( /\// ).test( url );
  2500. },
  2501. //return a url path with the window's location protocol/hostname/pathname removed
  2502. clean: function( url ) {
  2503. return url.replace( documentBase.domain, "" );
  2504. },
  2505. //just return the url without an initial #
  2506. stripHash: function( url ) {
  2507. return url.replace( /^#/, "" );
  2508. },
  2509. //remove the preceding hash, any query params, and dialog notations
  2510. cleanHash: function( hash ) {
  2511. return path.stripHash( hash.replace( /\?.*$/, "" ).replace( dialogHashKey, "" ) );
  2512. },
  2513. isHashValid: function( hash ) {
  2514. return ( /^#[^#]+$/ ).test( hash );
  2515. },
  2516. //check whether a url is referencing the same domain, or an external domain or different protocol
  2517. //could be mailto, etc
  2518. isExternal: function( url ) {
  2519. var u = path.parseUrl( url );
  2520. return u.protocol && u.domain !== documentUrl.domain ? true : false;
  2521. },
  2522. hasProtocol: function( url ) {
  2523. return ( /^(:?\w+:)/ ).test( url );
  2524. },
  2525. //check if the specified url refers to the first page in the main application document.
  2526. isFirstPageUrl: function( url ) {
  2527. // We only deal with absolute paths.
  2528. var u = path.parseUrl( path.makeUrlAbsolute( url, documentBase ) ),
  2529. // Does the url have the same path as the document?
  2530. samePath = u.hrefNoHash === documentUrl.hrefNoHash || ( documentBaseDiffers && u.hrefNoHash === documentBase.hrefNoHash ),
  2531. // Get the first page element.
  2532. fp = $.mobile.firstPage,
  2533. // Get the id of the first page element if it has one.
  2534. fpId = fp && fp[0] ? fp[0].id : undefined;
  2535. // The url refers to the first page if the path matches the document and
  2536. // it either has no hash value, or the hash is exactly equal to the id of the
  2537. // first page element.
  2538. return samePath && ( !u.hash || u.hash === "#" || ( fpId && u.hash.replace( /^#/, "" ) === fpId ) );
  2539. },
  2540. isEmbeddedPage: function( url ) {
  2541. var u = path.parseUrl( url );
  2542. //if the path is absolute, then we need to compare the url against
  2543. //both the documentUrl and the documentBase. The main reason for this
  2544. //is that links embedded within external documents will refer to the
  2545. //application document, whereas links embedded within the application
  2546. //document will be resolved against the document base.
  2547. if ( u.protocol !== "" ) {
  2548. return ( u.hash && ( u.hrefNoHash === documentUrl.hrefNoHash || ( documentBaseDiffers && u.hrefNoHash === documentBase.hrefNoHash ) ) );
  2549. }
  2550. return ( /^#/ ).test( u.href );
  2551. },
  2552. // Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR
  2553. // requests if the document doing the request was loaded via the file:// protocol.
  2554. // This is usually to allow the application to "phone home" and fetch app specific
  2555. // data. We normally let the browser handle external/cross-domain urls, but if the
  2556. // allowCrossDomainPages option is true, we will allow cross-domain http/https
  2557. // requests to go through our page loading logic.
  2558. isPermittedCrossDomainRequest: function( docUrl, reqUrl ) {
  2559. return $.mobile.allowCrossDomainPages &&
  2560. docUrl.protocol === "file:" &&
  2561. reqUrl.search( /^https?:/ ) !== -1;
  2562. }
  2563. },
  2564. //will be defined when a link is clicked and given an active class
  2565. $activeClickedLink = null,
  2566. //urlHistory is purely here to make guesses at whether the back or forward button was clicked
  2567. //and provide an appropriate transition
  2568. urlHistory = {
  2569. // Array of pages that are visited during a single page load.
  2570. // Each has a url and optional transition, title, and pageUrl (which represents the file path, in cases where URL is obscured, such as dialogs)
  2571. stack: [],
  2572. //maintain an index number for the active page in the stack
  2573. activeIndex: 0,
  2574. //get active
  2575. getActive: function() {
  2576. return urlHistory.stack[ urlHistory.activeIndex ];
  2577. },
  2578. getPrev: function() {
  2579. return urlHistory.stack[ urlHistory.activeIndex - 1 ];
  2580. },
  2581. getNext: function() {
  2582. return urlHistory.stack[ urlHistory.activeIndex + 1 ];
  2583. },
  2584. // addNew is used whenever a new page is added
  2585. addNew: function( url, transition, title, pageUrl, role ) {
  2586. //if there's forward history, wipe it
  2587. if ( urlHistory.getNext() ) {
  2588. urlHistory.clearForward();
  2589. }
  2590. urlHistory.stack.push( {url : url, transition: transition, title: title, pageUrl: pageUrl, role: role } );
  2591. urlHistory.activeIndex = urlHistory.stack.length - 1;
  2592. },
  2593. //wipe urls ahead of active index
  2594. clearForward: function() {
  2595. urlHistory.stack = urlHistory.stack.slice( 0, urlHistory.activeIndex + 1 );
  2596. },
  2597. directHashChange: function( opts ) {
  2598. var back , forward, newActiveIndex, prev = this.getActive();
  2599. // check if url is in history and if it's ahead or behind current page
  2600. $.each( urlHistory.stack, function( i, historyEntry ) {
  2601. //if the url is in the stack, it's a forward or a back
  2602. if ( decodeURIComponent( opts.currentUrl ) === decodeURIComponent( historyEntry.url ) ) {
  2603. //define back and forward by whether url is older or newer than current page
  2604. back = i < urlHistory.activeIndex;
  2605. forward = !back;
  2606. newActiveIndex = i;
  2607. }
  2608. });
  2609. // save new page index, null check to prevent falsey 0 result
  2610. this.activeIndex = newActiveIndex !== undefined ? newActiveIndex : this.activeIndex;
  2611. if ( back ) {
  2612. ( opts.either || opts.isBack )( true );
  2613. } else if ( forward ) {
  2614. ( opts.either || opts.isForward )( false );
  2615. }
  2616. },
  2617. //disable hashchange event listener internally to ignore one change
  2618. //toggled internally when location.hash is updated to match the url of a successful page load
  2619. ignoreNextHashChange: false
  2620. },
  2621. //define first selector to receive focus when a page is shown
  2622. focusable = "[tabindex],a,button:visible,select:visible,input",
  2623. //queue to hold simultanious page transitions
  2624. pageTransitionQueue = [],
  2625. //indicates whether or not page is in process of transitioning
  2626. isPageTransitioning = false,
  2627. //nonsense hash change key for dialogs, so they create a history entry
  2628. dialogHashKey = "&ui-state=dialog",
  2629. //existing base tag?
  2630. $base = $head.children( "base" ),
  2631. //tuck away the original document URL minus any fragment.
  2632. documentUrl = path.parseLocation(),
  2633. //if the document has an embedded base tag, documentBase is set to its
  2634. //initial value. If a base tag does not exist, then we default to the documentUrl.
  2635. documentBase = $base.length ? path.parseUrl( path.makeUrlAbsolute( $base.attr( "href" ), documentUrl.href ) ) : documentUrl,
  2636. //cache the comparison once.
  2637. documentBaseDiffers = ( documentUrl.hrefNoHash !== documentBase.hrefNoHash ),
  2638. getScreenHeight = $.mobile.getScreenHeight;
  2639. //base element management, defined depending on dynamic base tag support
  2640. var base = $.support.dynamicBaseTag ? {
  2641. //define base element, for use in routing asset urls that are referenced in Ajax-requested markup
  2642. element: ( $base.length ? $base : $( "<base>", { href: documentBase.hrefNoHash } ).prependTo( $head ) ),
  2643. //set the generated BASE element's href attribute to a new page's base path
  2644. set: function( href ) {
  2645. base.element.attr( "href", path.makeUrlAbsolute( href, documentBase ) );
  2646. },
  2647. //set the generated BASE element's href attribute to a new page's base path
  2648. reset: function() {
  2649. base.element.attr( "href", documentBase.hrefNoHash );
  2650. }
  2651. } : undefined;
  2652. /* internal utility functions */
  2653. // NOTE Issue #4950 Android phonegap doesn't navigate back properly
  2654. // when a full page refresh has taken place. It appears that hashchange
  2655. // and replacestate history alterations work fine but we need to support
  2656. // both forms of history traversal in our code that uses backward history
  2657. // movement
  2658. $.mobile.back = function() {
  2659. var nav = window.navigator;
  2660. // if the setting is on and the navigator object is
  2661. // available use the phonegap navigation capability
  2662. if( this.phonegapNavigationEnabled &&
  2663. nav &&
  2664. nav.app &&
  2665. nav.app.backHistory ){
  2666. nav.app.backHistory();
  2667. } else {
  2668. window.history.back();
  2669. }
  2670. };
  2671. //direct focus to the page title, or otherwise first focusable element
  2672. $.mobile.focusPage = function ( page ) {
  2673. var autofocus = page.find( "[autofocus]" ),
  2674. pageTitle = page.find( ".ui-title:eq(0)" );
  2675. if ( autofocus.length ) {
  2676. autofocus.focus();
  2677. return;
  2678. }
  2679. if ( pageTitle.length ) {
  2680. pageTitle.focus();
  2681. } else{
  2682. page.focus();
  2683. }
  2684. };
  2685. //remove active classes after page transition or error
  2686. function removeActiveLinkClass( forceRemoval ) {
  2687. if ( !!$activeClickedLink && ( !$activeClickedLink.closest( "." + $.mobile.activePageClass ).length || forceRemoval ) ) {
  2688. $activeClickedLink.removeClass( $.mobile.activeBtnClass );
  2689. }
  2690. $activeClickedLink = null;
  2691. }
  2692. function releasePageTransitionLock() {
  2693. isPageTransitioning = false;
  2694. if ( pageTransitionQueue.length > 0 ) {
  2695. $.mobile.changePage.apply( null, pageTransitionQueue.pop() );
  2696. }
  2697. }
  2698. // Save the last scroll distance per page, before it is hidden
  2699. var setLastScrollEnabled = true,
  2700. setLastScroll, delayedSetLastScroll;
  2701. setLastScroll = function() {
  2702. // this barrier prevents setting the scroll value based on the browser
  2703. // scrolling the window based on a hashchange
  2704. if ( !setLastScrollEnabled ) {
  2705. return;
  2706. }
  2707. var active = $.mobile.urlHistory.getActive();
  2708. if ( active ) {
  2709. var lastScroll = $window.scrollTop();
  2710. // Set active page's lastScroll prop.
  2711. // If the location we're scrolling to is less than minScrollBack, let it go.
  2712. active.lastScroll = lastScroll < $.mobile.minScrollBack ? $.mobile.defaultHomeScroll : lastScroll;
  2713. }
  2714. };
  2715. // bind to scrollstop to gather scroll position. The delay allows for the hashchange
  2716. // event to fire and disable scroll recording in the case where the browser scrolls
  2717. // to the hash targets location (sometimes the top of the page). once pagechange fires
  2718. // getLastScroll is again permitted to operate
  2719. delayedSetLastScroll = function() {
  2720. setTimeout( setLastScroll, 100 );
  2721. };
  2722. // disable an scroll setting when a hashchange has been fired, this only works
  2723. // because the recording of the scroll position is delayed for 100ms after
  2724. // the browser might have changed the position because of the hashchange
  2725. $window.bind( $.support.pushState ? "popstate" : "hashchange", function() {
  2726. setLastScrollEnabled = false;
  2727. });
  2728. // handle initial hashchange from chrome :(
  2729. $window.one( $.support.pushState ? "popstate" : "hashchange", function() {
  2730. setLastScrollEnabled = true;
  2731. });
  2732. // wait until the mobile page container has been determined to bind to pagechange
  2733. $window.one( "pagecontainercreate", function() {
  2734. // once the page has changed, re-enable the scroll recording
  2735. $.mobile.pageContainer.bind( "pagechange", function() {
  2736. setLastScrollEnabled = true;
  2737. // remove any binding that previously existed on the get scroll
  2738. // which may or may not be different than the scroll element determined for
  2739. // this page previously
  2740. $window.unbind( "scrollstop", delayedSetLastScroll );
  2741. // determine and bind to the current scoll element which may be the window
  2742. // or in the case of touch overflow the element with touch overflow
  2743. $window.bind( "scrollstop", delayedSetLastScroll );
  2744. });
  2745. });
  2746. // bind to scrollstop for the first page as "pagechange" won't be fired in that case
  2747. $window.bind( "scrollstop", delayedSetLastScroll );
  2748. // No-op implementation of transition degradation
  2749. $.mobile._maybeDegradeTransition = $.mobile._maybeDegradeTransition || function( transition ) {
  2750. return transition;
  2751. };
  2752. //function for transitioning between two existing pages
  2753. function transitionPages( toPage, fromPage, transition, reverse ) {
  2754. if ( fromPage ) {
  2755. //trigger before show/hide events
  2756. fromPage.data( "page" )._trigger( "beforehide", null, { nextPage: toPage } );
  2757. }
  2758. toPage.data( "page" )._trigger( "beforeshow", null, { prevPage: fromPage || $( "" ) } );
  2759. //clear page loader
  2760. $.mobile.hidePageLoadingMsg();
  2761. transition = $.mobile._maybeDegradeTransition( transition );
  2762. //find the transition handler for the specified transition. If there
  2763. //isn't one in our transitionHandlers dictionary, use the default one.
  2764. //call the handler immediately to kick-off the transition.
  2765. var th = $.mobile.transitionHandlers[ transition || "default" ] || $.mobile.defaultTransitionHandler,
  2766. promise = th( transition, reverse, toPage, fromPage );
  2767. promise.done(function() {
  2768. //trigger show/hide events
  2769. if ( fromPage ) {
  2770. fromPage.data( "page" )._trigger( "hide", null, { nextPage: toPage } );
  2771. }
  2772. //trigger pageshow, define prevPage as either fromPage or empty jQuery obj
  2773. toPage.data( "page" )._trigger( "show", null, { prevPage: fromPage || $( "" ) } );
  2774. });
  2775. return promise;
  2776. }
  2777. //simply set the active page's minimum height to screen height, depending on orientation
  2778. function resetActivePageHeight() {
  2779. var aPage = $( "." + $.mobile.activePageClass ),
  2780. aPagePadT = parseFloat( aPage.css( "padding-top" ) ),
  2781. aPagePadB = parseFloat( aPage.css( "padding-bottom" ) ),
  2782. aPageBorderT = parseFloat( aPage.css( "border-top-width" ) ),
  2783. aPageBorderB = parseFloat( aPage.css( "border-bottom-width" ) );
  2784. aPage.css( "min-height", getScreenHeight() - aPagePadT - aPagePadB - aPageBorderT - aPageBorderB );
  2785. }
  2786. //shared page enhancements
  2787. function enhancePage( $page, role ) {
  2788. // If a role was specified, make sure the data-role attribute
  2789. // on the page element is in sync.
  2790. if ( role ) {
  2791. $page.attr( "data-" + $.mobile.ns + "role", role );
  2792. }
  2793. //run page plugin
  2794. $page.page();
  2795. }
  2796. /* exposed $.mobile methods */
  2797. //animation complete callback
  2798. $.fn.animationComplete = function( callback ) {
  2799. if ( $.support.cssTransitions ) {
  2800. return $( this ).one( 'webkitAnimationEnd animationend', callback );
  2801. }
  2802. else{
  2803. // defer execution for consistency between webkit/non webkit
  2804. setTimeout( callback, 0 );
  2805. return $( this );
  2806. }
  2807. };
  2808. //expose path object on $.mobile
  2809. $.mobile.path = path;
  2810. //expose base object on $.mobile
  2811. $.mobile.base = base;
  2812. //history stack
  2813. $.mobile.urlHistory = urlHistory;
  2814. $.mobile.dialogHashKey = dialogHashKey;
  2815. //enable cross-domain page support
  2816. $.mobile.allowCrossDomainPages = false;
  2817. //return the original document url
  2818. $.mobile.getDocumentUrl = function( asParsedObject ) {
  2819. return asParsedObject ? $.extend( {}, documentUrl ) : documentUrl.href;
  2820. };
  2821. //return the original document base url
  2822. $.mobile.getDocumentBase = function( asParsedObject ) {
  2823. return asParsedObject ? $.extend( {}, documentBase ) : documentBase.href;
  2824. };
  2825. $.mobile._bindPageRemove = function() {
  2826. var page = $( this );
  2827. // when dom caching is not enabled or the page is embedded bind to remove the page on hide
  2828. if ( !page.data( "page" ).options.domCache &&
  2829. page.is( ":jqmData(external-page='true')" ) ) {
  2830. page.bind( 'pagehide.remove', function() {
  2831. var $this = $( this ),
  2832. prEvent = new $.Event( "pageremove" );
  2833. $this.trigger( prEvent );
  2834. if ( !prEvent.isDefaultPrevented() ) {
  2835. $this.removeWithDependents();
  2836. }
  2837. });
  2838. }
  2839. };
  2840. // Load a page into the DOM.
  2841. $.mobile.loadPage = function( url, options ) {
  2842. // This function uses deferred notifications to let callers
  2843. // know when the page is done loading, or if an error has occurred.
  2844. var deferred = $.Deferred(),
  2845. // The default loadPage options with overrides specified by
  2846. // the caller.
  2847. settings = $.extend( {}, $.mobile.loadPage.defaults, options ),
  2848. // The DOM element for the page after it has been loaded.
  2849. page = null,
  2850. // If the reloadPage option is true, and the page is already
  2851. // in the DOM, dupCachedPage will be set to the page element
  2852. // so that it can be removed after the new version of the
  2853. // page is loaded off the network.
  2854. dupCachedPage = null,
  2855. // determine the current base url
  2856. findBaseWithDefault = function() {
  2857. var closestBase = ( $.mobile.activePage && getClosestBaseUrl( $.mobile.activePage ) );
  2858. return closestBase || documentBase.hrefNoHash;
  2859. },
  2860. // The absolute version of the URL passed into the function. This
  2861. // version of the URL may contain dialog/subpage params in it.
  2862. absUrl = path.makeUrlAbsolute( url, findBaseWithDefault() );
  2863. // If the caller provided data, and we're using "get" request,
  2864. // append the data to the URL.
  2865. if ( settings.data && settings.type === "get" ) {
  2866. absUrl = path.addSearchParams( absUrl, settings.data );
  2867. settings.data = undefined;
  2868. }
  2869. // If the caller is using a "post" request, reloadPage must be true
  2870. if ( settings.data && settings.type === "post" ) {
  2871. settings.reloadPage = true;
  2872. }
  2873. // The absolute version of the URL minus any dialog/subpage params.
  2874. // In otherwords the real URL of the page to be loaded.
  2875. var fileUrl = path.getFilePath( absUrl ),
  2876. // The version of the Url actually stored in the data-url attribute of
  2877. // the page. For embedded pages, it is just the id of the page. For pages
  2878. // within the same domain as the document base, it is the site relative
  2879. // path. For cross-domain pages (Phone Gap only) the entire absolute Url
  2880. // used to load the page.
  2881. dataUrl = path.convertUrlToDataUrl( absUrl );
  2882. // Make sure we have a pageContainer to work with.
  2883. settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
  2884. // Check to see if the page already exists in the DOM.
  2885. // NOTE do _not_ use the :jqmData psuedo selector because parenthesis
  2886. // are a valid url char and it breaks on the first occurence
  2887. page = settings.pageContainer.children( "[data-" + $.mobile.ns +"url='" + dataUrl + "']" );
  2888. // If we failed to find the page, check to see if the url is a
  2889. // reference to an embedded page. If so, it may have been dynamically
  2890. // injected by a developer, in which case it would be lacking a data-url
  2891. // attribute and in need of enhancement.
  2892. if ( page.length === 0 && dataUrl && !path.isPath( dataUrl ) ) {
  2893. page = settings.pageContainer.children( "#" + dataUrl )
  2894. .attr( "data-" + $.mobile.ns + "url", dataUrl )
  2895. .jqmData( "url", dataUrl );
  2896. }
  2897. // If we failed to find a page in the DOM, check the URL to see if it
  2898. // refers to the first page in the application. If it isn't a reference
  2899. // to the first page and refers to non-existent embedded page, error out.
  2900. if ( page.length === 0 ) {
  2901. if ( $.mobile.firstPage && path.isFirstPageUrl( fileUrl ) ) {
  2902. // Check to make sure our cached-first-page is actually
  2903. // in the DOM. Some user deployed apps are pruning the first
  2904. // page from the DOM for various reasons, we check for this
  2905. // case here because we don't want a first-page with an id
  2906. // falling through to the non-existent embedded page error
  2907. // case. If the first-page is not in the DOM, then we let
  2908. // things fall through to the ajax loading code below so
  2909. // that it gets reloaded.
  2910. if ( $.mobile.firstPage.parent().length ) {
  2911. page = $( $.mobile.firstPage );
  2912. }
  2913. } else if ( path.isEmbeddedPage( fileUrl ) ) {
  2914. deferred.reject( absUrl, options );
  2915. return deferred.promise();
  2916. }
  2917. }
  2918. // If the page we are interested in is already in the DOM,
  2919. // and the caller did not indicate that we should force a
  2920. // reload of the file, we are done. Otherwise, track the
  2921. // existing page as a duplicated.
  2922. if ( page.length ) {
  2923. if ( !settings.reloadPage ) {
  2924. enhancePage( page, settings.role );
  2925. deferred.resolve( absUrl, options, page );
  2926. return deferred.promise();
  2927. }
  2928. dupCachedPage = page;
  2929. }
  2930. var mpc = settings.pageContainer,
  2931. pblEvent = new $.Event( "pagebeforeload" ),
  2932. triggerData = { url: url, absUrl: absUrl, dataUrl: dataUrl, deferred: deferred, options: settings };
  2933. // Let listeners know we're about to load a page.
  2934. mpc.trigger( pblEvent, triggerData );
  2935. // If the default behavior is prevented, stop here!
  2936. if ( pblEvent.isDefaultPrevented() ) {
  2937. return deferred.promise();
  2938. }
  2939. if ( settings.showLoadMsg ) {
  2940. // This configurable timeout allows cached pages a brief delay to load without showing a message
  2941. var loadMsgDelay = setTimeout(function() {
  2942. $.mobile.showPageLoadingMsg();
  2943. }, settings.loadMsgDelay ),
  2944. // Shared logic for clearing timeout and removing message.
  2945. hideMsg = function() {
  2946. // Stop message show timer
  2947. clearTimeout( loadMsgDelay );
  2948. // Hide loading message
  2949. $.mobile.hidePageLoadingMsg();
  2950. };
  2951. }
  2952. // Reset base to the default document base.
  2953. if ( base ) {
  2954. base.reset();
  2955. }
  2956. if ( !( $.mobile.allowCrossDomainPages || path.isSameDomain( documentUrl, absUrl ) ) ) {
  2957. deferred.reject( absUrl, options );
  2958. } else {
  2959. // Load the new page.
  2960. $.ajax({
  2961. url: fileUrl,
  2962. type: settings.type,
  2963. data: settings.data,
  2964. dataType: "html",
  2965. success: function( html, textStatus, xhr ) {
  2966. //pre-parse html to check for a data-url,
  2967. //use it as the new fileUrl, base path, etc
  2968. var all = $( "<div></div>" ),
  2969. //page title regexp
  2970. newPageTitle = html.match( /<title[^>]*>([^<]*)/ ) && RegExp.$1,
  2971. // TODO handle dialogs again
  2972. pageElemRegex = new RegExp( "(<[^>]+\\bdata-" + $.mobile.ns + "role=[\"']?page[\"']?[^>]*>)" ),
  2973. dataUrlRegex = new RegExp( "\\bdata-" + $.mobile.ns + "url=[\"']?([^\"'>]*)[\"']?" );
  2974. // data-url must be provided for the base tag so resource requests can be directed to the
  2975. // correct url. loading into a temprorary element makes these requests immediately
  2976. if ( pageElemRegex.test( html ) &&
  2977. RegExp.$1 &&
  2978. dataUrlRegex.test( RegExp.$1 ) &&
  2979. RegExp.$1 ) {
  2980. url = fileUrl = path.getFilePath( $( "<div>" + RegExp.$1 + "</div>" ).text() );
  2981. }
  2982. if ( base ) {
  2983. base.set( fileUrl );
  2984. }
  2985. //workaround to allow scripts to execute when included in page divs
  2986. all.get( 0 ).innerHTML = html;
  2987. page = all.find( ":jqmData(role='page'), :jqmData(role='dialog')" ).first();
  2988. //if page elem couldn't be found, create one and insert the body element's contents
  2989. if ( !page.length ) {
  2990. page = $( "<div data-" + $.mobile.ns + "role='page'>" + html.split( /<\/?body[^>]*>/gmi )[1] + "</div>" );
  2991. }
  2992. if ( newPageTitle && !page.jqmData( "title" ) ) {
  2993. if ( ~newPageTitle.indexOf( "&" ) ) {
  2994. newPageTitle = $( "<div>" + newPageTitle + "</div>" ).text();
  2995. }
  2996. page.jqmData( "title", newPageTitle );
  2997. }
  2998. //rewrite src and href attrs to use a base url
  2999. if ( !$.support.dynamicBaseTag ) {
  3000. var newPath = path.get( fileUrl );
  3001. page.find( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ).each(function() {
  3002. var thisAttr = $( this ).is( '[href]' ) ? 'href' :
  3003. $( this ).is( '[src]' ) ? 'src' : 'action',
  3004. thisUrl = $( this ).attr( thisAttr );
  3005. // XXX_jblas: We need to fix this so that it removes the document
  3006. // base URL, and then prepends with the new page URL.
  3007. //if full path exists and is same, chop it - helps IE out
  3008. thisUrl = thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );
  3009. if ( !/^(\w+:|#|\/)/.test( thisUrl ) ) {
  3010. $( this ).attr( thisAttr, newPath + thisUrl );
  3011. }
  3012. });
  3013. }
  3014. //append to page and enhance
  3015. // TODO taging a page with external to make sure that embedded pages aren't removed
  3016. // by the various page handling code is bad. Having page handling code in many
  3017. // places is bad. Solutions post 1.0
  3018. page
  3019. .attr( "data-" + $.mobile.ns + "url", path.convertUrlToDataUrl( fileUrl ) )
  3020. .attr( "data-" + $.mobile.ns + "external-page", true )
  3021. .appendTo( settings.pageContainer );
  3022. // wait for page creation to leverage options defined on widget
  3023. page.one( 'pagecreate', $.mobile._bindPageRemove );
  3024. enhancePage( page, settings.role );
  3025. // Enhancing the page may result in new dialogs/sub pages being inserted
  3026. // into the DOM. If the original absUrl refers to a sub-page, that is the
  3027. // real page we are interested in.
  3028. if ( absUrl.indexOf( "&" + $.mobile.subPageUrlKey ) > -1 ) {
  3029. page = settings.pageContainer.children( "[data-" + $.mobile.ns +"url='" + dataUrl + "']" );
  3030. }
  3031. //bind pageHide to removePage after it's hidden, if the page options specify to do so
  3032. // Remove loading message.
  3033. if ( settings.showLoadMsg ) {
  3034. hideMsg();
  3035. }
  3036. // Add the page reference and xhr to our triggerData.
  3037. triggerData.xhr = xhr;
  3038. triggerData.textStatus = textStatus;
  3039. triggerData.page = page;
  3040. // Let listeners know the page loaded successfully.
  3041. settings.pageContainer.trigger( "pageload", triggerData );
  3042. deferred.resolve( absUrl, options, page, dupCachedPage );
  3043. },
  3044. error: function( xhr, textStatus, errorThrown ) {
  3045. //set base back to current path
  3046. if ( base ) {
  3047. base.set( path.get() );
  3048. }
  3049. // Add error info to our triggerData.
  3050. triggerData.xhr = xhr;
  3051. triggerData.textStatus = textStatus;
  3052. triggerData.errorThrown = errorThrown;
  3053. var plfEvent = new $.Event( "pageloadfailed" );
  3054. // Let listeners know the page load failed.
  3055. settings.pageContainer.trigger( plfEvent, triggerData );
  3056. // If the default behavior is prevented, stop here!
  3057. // Note that it is the responsibility of the listener/handler
  3058. // that called preventDefault(), to resolve/reject the
  3059. // deferred object within the triggerData.
  3060. if ( plfEvent.isDefaultPrevented() ) {
  3061. return;
  3062. }
  3063. // Remove loading message.
  3064. if ( settings.showLoadMsg ) {
  3065. // Remove loading message.
  3066. hideMsg();
  3067. // show error message
  3068. $.mobile.showPageLoadingMsg( $.mobile.pageLoadErrorMessageTheme, $.mobile.pageLoadErrorMessage, true );
  3069. // hide after delay
  3070. setTimeout( $.mobile.hidePageLoadingMsg, 1500 );
  3071. }
  3072. deferred.reject( absUrl, options );
  3073. }
  3074. });
  3075. }
  3076. return deferred.promise();
  3077. };
  3078. $.mobile.loadPage.defaults = {
  3079. type: "get",
  3080. data: undefined,
  3081. reloadPage: false,
  3082. role: undefined, // By default we rely on the role defined by the @data-role attribute.
  3083. showLoadMsg: false,
  3084. pageContainer: undefined,
  3085. loadMsgDelay: 50 // This delay allows loads that pull from browser cache to occur without showing the loading message.
  3086. };
  3087. // Show a specific page in the page container.
  3088. $.mobile.changePage = function( toPage, options ) {
  3089. // If we are in the midst of a transition, queue the current request.
  3090. // We'll call changePage() once we're done with the current transition to
  3091. // service the request.
  3092. if ( isPageTransitioning ) {
  3093. pageTransitionQueue.unshift( arguments );
  3094. return;
  3095. }
  3096. var settings = $.extend( {}, $.mobile.changePage.defaults, options );
  3097. // Make sure we have a pageContainer to work with.
  3098. settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
  3099. // Make sure we have a fromPage.
  3100. settings.fromPage = settings.fromPage || $.mobile.activePage;
  3101. var mpc = settings.pageContainer,
  3102. pbcEvent = new $.Event( "pagebeforechange" ),
  3103. triggerData = { toPage: toPage, options: settings };
  3104. // Let listeners know we're about to change the current page.
  3105. mpc.trigger( pbcEvent, triggerData );
  3106. // If the default behavior is prevented, stop here!
  3107. if ( pbcEvent.isDefaultPrevented() ) {
  3108. return;
  3109. }
  3110. // We allow "pagebeforechange" observers to modify the toPage in the trigger
  3111. // data to allow for redirects. Make sure our toPage is updated.
  3112. toPage = triggerData.toPage;
  3113. // Set the isPageTransitioning flag to prevent any requests from
  3114. // entering this method while we are in the midst of loading a page
  3115. // or transitioning.
  3116. isPageTransitioning = true;
  3117. // If the caller passed us a url, call loadPage()
  3118. // to make sure it is loaded into the DOM. We'll listen
  3119. // to the promise object it returns so we know when
  3120. // it is done loading or if an error ocurred.
  3121. if ( typeof toPage === "string" ) {
  3122. $.mobile.loadPage( toPage, settings )
  3123. .done(function( url, options, newPage, dupCachedPage ) {
  3124. isPageTransitioning = false;
  3125. options.duplicateCachedPage = dupCachedPage;
  3126. $.mobile.changePage( newPage, options );
  3127. })
  3128. .fail(function( url, options ) {
  3129. isPageTransitioning = false;
  3130. //clear out the active button state
  3131. removeActiveLinkClass( true );
  3132. //release transition lock so navigation is free again
  3133. releasePageTransitionLock();
  3134. settings.pageContainer.trigger( "pagechangefailed", triggerData );
  3135. });
  3136. return;
  3137. }
  3138. // If we are going to the first-page of the application, we need to make
  3139. // sure settings.dataUrl is set to the application document url. This allows
  3140. // us to avoid generating a document url with an id hash in the case where the
  3141. // first-page of the document has an id attribute specified.
  3142. if ( toPage[ 0 ] === $.mobile.firstPage[ 0 ] && !settings.dataUrl ) {
  3143. settings.dataUrl = documentUrl.hrefNoHash;
  3144. }
  3145. // The caller passed us a real page DOM element. Update our
  3146. // internal state and then trigger a transition to the page.
  3147. var fromPage = settings.fromPage,
  3148. url = ( settings.dataUrl && path.convertUrlToDataUrl( settings.dataUrl ) ) || toPage.jqmData( "url" ),
  3149. // The pageUrl var is usually the same as url, except when url is obscured as a dialog url. pageUrl always contains the file path
  3150. pageUrl = url,
  3151. fileUrl = path.getFilePath( url ),
  3152. active = urlHistory.getActive(),
  3153. activeIsInitialPage = urlHistory.activeIndex === 0,
  3154. historyDir = 0,
  3155. pageTitle = document.title,
  3156. isDialog = settings.role === "dialog" || toPage.jqmData( "role" ) === "dialog";
  3157. // By default, we prevent changePage requests when the fromPage and toPage
  3158. // are the same element, but folks that generate content manually/dynamically
  3159. // and reuse pages want to be able to transition to the same page. To allow
  3160. // this, they will need to change the default value of allowSamePageTransition
  3161. // to true, *OR*, pass it in as an option when they manually call changePage().
  3162. // It should be noted that our default transition animations assume that the
  3163. // formPage and toPage are different elements, so they may behave unexpectedly.
  3164. // It is up to the developer that turns on the allowSamePageTransitiona option
  3165. // to either turn off transition animations, or make sure that an appropriate
  3166. // animation transition is used.
  3167. if ( fromPage && fromPage[0] === toPage[0] && !settings.allowSamePageTransition ) {
  3168. isPageTransitioning = false;
  3169. mpc.trigger( "pagechange", triggerData );
  3170. // Even if there is no page change to be done, we should keep the urlHistory in sync with the hash changes
  3171. if ( settings.fromHashChange ) {
  3172. urlHistory.directHashChange({
  3173. currentUrl: url,
  3174. isBack: function() {},
  3175. isForward: function() {}
  3176. });
  3177. }
  3178. return;
  3179. }
  3180. // We need to make sure the page we are given has already been enhanced.
  3181. enhancePage( toPage, settings.role );
  3182. // If the changePage request was sent from a hashChange event, check to see if the
  3183. // page is already within the urlHistory stack. If so, we'll assume the user hit
  3184. // the forward/back button and will try to match the transition accordingly.
  3185. if ( settings.fromHashChange ) {
  3186. urlHistory.directHashChange({
  3187. currentUrl: url,
  3188. isBack: function() { historyDir = -1; },
  3189. isForward: function() { historyDir = 1; }
  3190. });
  3191. }
  3192. // Kill the keyboard.
  3193. // XXX_jblas: We need to stop crawling the entire document to kill focus. Instead,
  3194. // we should be tracking focus with a delegate() handler so we already have
  3195. // the element in hand at this point.
  3196. // Wrap this in a try/catch block since IE9 throw "Unspecified error" if document.activeElement
  3197. // is undefined when we are in an IFrame.
  3198. try {
  3199. if ( document.activeElement && document.activeElement.nodeName.toLowerCase() !== 'body' ) {
  3200. $( document.activeElement ).blur();
  3201. } else {
  3202. $( "input:focus, textarea:focus, select:focus" ).blur();
  3203. }
  3204. } catch( e ) {}
  3205. // Record whether we are at a place in history where a dialog used to be - if so, do not add a new history entry and do not change the hash either
  3206. var alreadyThere = false;
  3207. // If we're displaying the page as a dialog, we don't want the url
  3208. // for the dialog content to be used in the hash. Instead, we want
  3209. // to append the dialogHashKey to the url of the current page.
  3210. if ( isDialog && active ) {
  3211. // on the initial page load active.url is undefined and in that case should
  3212. // be an empty string. Moving the undefined -> empty string back into
  3213. // urlHistory.addNew seemed imprudent given undefined better represents
  3214. // the url state
  3215. // If we are at a place in history that once belonged to a dialog, reuse
  3216. // this state without adding to urlHistory and without modifying the hash.
  3217. // However, if a dialog is already displayed at this point, and we're
  3218. // about to display another dialog, then we must add another hash and
  3219. // history entry on top so that one may navigate back to the original dialog
  3220. if ( active.url.indexOf( dialogHashKey ) > -1 && !$.mobile.activePage.is( ".ui-dialog" ) ) {
  3221. settings.changeHash = false;
  3222. alreadyThere = true;
  3223. }
  3224. // Normally, we tack on a dialog hash key, but if this is the location of a stale dialog,
  3225. // we reuse the URL from the entry
  3226. url = ( active.url || "" ) + ( alreadyThere ? "" : dialogHashKey );
  3227. // tack on another dialogHashKey if this is the same as the initial hash
  3228. // this makes sure that a history entry is created for this dialog
  3229. if ( urlHistory.activeIndex === 0 && url === urlHistory.initialDst ) {
  3230. url += dialogHashKey;
  3231. }
  3232. }
  3233. // Set the location hash.
  3234. if ( settings.changeHash !== false && url ) {
  3235. //disable hash listening temporarily
  3236. urlHistory.ignoreNextHashChange = true;
  3237. //update hash and history
  3238. path.set( url );
  3239. }
  3240. // if title element wasn't found, try the page div data attr too
  3241. // If this is a deep-link or a reload ( active === undefined ) then just use pageTitle
  3242. var newPageTitle = ( !active )? pageTitle : toPage.jqmData( "title" ) || toPage.children( ":jqmData(role='header')" ).find( ".ui-title" ).getEncodedText();
  3243. if ( !!newPageTitle && pageTitle === document.title ) {
  3244. pageTitle = newPageTitle;
  3245. }
  3246. if ( !toPage.jqmData( "title" ) ) {
  3247. toPage.jqmData( "title", pageTitle );
  3248. }
  3249. // Make sure we have a transition defined.
  3250. settings.transition = settings.transition ||
  3251. ( ( historyDir && !activeIsInitialPage ) ? active.transition : undefined ) ||
  3252. ( isDialog ? $.mobile.defaultDialogTransition : $.mobile.defaultPageTransition );
  3253. //add page to history stack if it's not back or forward
  3254. if ( !historyDir ) {
  3255. // Overwrite the current entry if it's a leftover from a dialog
  3256. if ( alreadyThere ) {
  3257. urlHistory.activeIndex = Math.max( 0, urlHistory.activeIndex - 1 );
  3258. }
  3259. urlHistory.addNew( url, settings.transition, pageTitle, pageUrl, settings.role );
  3260. }
  3261. //set page title
  3262. document.title = urlHistory.getActive().title;
  3263. //set "toPage" as activePage
  3264. $.mobile.activePage = toPage;
  3265. // If we're navigating back in the URL history, set reverse accordingly.
  3266. settings.reverse = settings.reverse || historyDir < 0;
  3267. transitionPages( toPage, fromPage, settings.transition, settings.reverse )
  3268. .done(function( name, reverse, $to, $from, alreadyFocused ) {
  3269. removeActiveLinkClass();
  3270. //if there's a duplicateCachedPage, remove it from the DOM now that it's hidden
  3271. if ( settings.duplicateCachedPage ) {
  3272. settings.duplicateCachedPage.remove();
  3273. }
  3274. // Send focus to the newly shown page. Moved from promise .done binding in transitionPages
  3275. // itself to avoid ie bug that reports offsetWidth as > 0 (core check for visibility)
  3276. // despite visibility: hidden addresses issue #2965
  3277. // https://github.com/jquery/jquery-mobile/issues/2965
  3278. if ( !alreadyFocused ) {
  3279. $.mobile.focusPage( toPage );
  3280. }
  3281. releasePageTransitionLock();
  3282. // Let listeners know we're all done changing the current page.
  3283. mpc.trigger( "pagechange", triggerData );
  3284. });
  3285. };
  3286. $.mobile.changePage.defaults = {
  3287. transition: undefined,
  3288. reverse: false,
  3289. changeHash: true,
  3290. fromHashChange: false,
  3291. role: undefined, // By default we rely on the role defined by the @data-role attribute.
  3292. duplicateCachedPage: undefined,
  3293. pageContainer: undefined,
  3294. showLoadMsg: true, //loading message shows by default when pages are being fetched during changePage
  3295. dataUrl: undefined,
  3296. fromPage: undefined,
  3297. allowSamePageTransition: false
  3298. };
  3299. /* Event Bindings - hashchange, submit, and click */
  3300. function findClosestLink( ele )
  3301. {
  3302. while ( ele ) {
  3303. // Look for the closest element with a nodeName of "a".
  3304. // Note that we are checking if we have a valid nodeName
  3305. // before attempting to access it. This is because the
  3306. // node we get called with could have originated from within
  3307. // an embedded SVG document where some symbol instance elements
  3308. // don't have nodeName defined on them, or strings are of type
  3309. // SVGAnimatedString.
  3310. if ( ( typeof ele.nodeName === "string" ) && ele.nodeName.toLowerCase() === "a" ) {
  3311. break;
  3312. }
  3313. ele = ele.parentNode;
  3314. }
  3315. return ele;
  3316. }
  3317. // The base URL for any given element depends on the page it resides in.
  3318. function getClosestBaseUrl( ele )
  3319. {
  3320. // Find the closest page and extract out its url.
  3321. var url = $( ele ).closest( ".ui-page" ).jqmData( "url" ),
  3322. base = documentBase.hrefNoHash;
  3323. if ( !url || !path.isPath( url ) ) {
  3324. url = base;
  3325. }
  3326. return path.makeUrlAbsolute( url, base);
  3327. }
  3328. //The following event bindings should be bound after mobileinit has been triggered
  3329. //the following deferred is resolved in the init file
  3330. $.mobile.navreadyDeferred = $.Deferred();
  3331. $.mobile.navreadyDeferred.done(function() {
  3332. //bind to form submit events, handle with Ajax
  3333. $( document ).delegate( "form", "submit", function( event ) {
  3334. var $this = $( this );
  3335. if ( !$.mobile.ajaxEnabled ||
  3336. // test that the form is, itself, ajax false
  3337. $this.is( ":jqmData(ajax='false')" ) ||
  3338. // test that $.mobile.ignoreContentEnabled is set and
  3339. // the form or one of it's parents is ajax=false
  3340. !$this.jqmHijackable().length ) {
  3341. return;
  3342. }
  3343. var type = $this.attr( "method" ),
  3344. target = $this.attr( "target" ),
  3345. url = $this.attr( "action" );
  3346. // If no action is specified, browsers default to using the
  3347. // URL of the document containing the form. Since we dynamically
  3348. // pull in pages from external documents, the form should submit
  3349. // to the URL for the source document of the page containing
  3350. // the form.
  3351. if ( !url ) {
  3352. // Get the @data-url for the page containing the form.
  3353. url = getClosestBaseUrl( $this );
  3354. if ( url === documentBase.hrefNoHash ) {
  3355. // The url we got back matches the document base,
  3356. // which means the page must be an internal/embedded page,
  3357. // so default to using the actual document url as a browser
  3358. // would.
  3359. url = documentUrl.hrefNoSearch;
  3360. }
  3361. }
  3362. url = path.makeUrlAbsolute( url, getClosestBaseUrl( $this ) );
  3363. if ( ( path.isExternal( url ) && !path.isPermittedCrossDomainRequest( documentUrl, url ) ) || target ) {
  3364. return;
  3365. }
  3366. $.mobile.changePage(
  3367. url,
  3368. {
  3369. type: type && type.length && type.toLowerCase() || "get",
  3370. data: $this.serialize(),
  3371. transition: $this.jqmData( "transition" ),
  3372. reverse: $this.jqmData( "direction" ) === "reverse",
  3373. reloadPage: true
  3374. }
  3375. );
  3376. event.preventDefault();
  3377. });
  3378. //add active state on vclick
  3379. $( document ).bind( "vclick", function( event ) {
  3380. // if this isn't a left click we don't care. Its important to note
  3381. // that when the virtual event is generated it will create the which attr
  3382. if ( event.which > 1 || !$.mobile.linkBindingEnabled ) {
  3383. return;
  3384. }
  3385. var link = findClosestLink( event.target );
  3386. // split from the previous return logic to avoid find closest where possible
  3387. // TODO teach $.mobile.hijackable to operate on raw dom elements so the link wrapping
  3388. // can be avoided
  3389. if ( !$( link ).jqmHijackable().length ) {
  3390. return;
  3391. }
  3392. if ( link ) {
  3393. if ( path.parseUrl( link.getAttribute( "href" ) || "#" ).hash !== "#" ) {
  3394. removeActiveLinkClass( true );
  3395. $activeClickedLink = $( link ).closest( ".ui-btn" ).not( ".ui-disabled" );
  3396. $activeClickedLink.addClass( $.mobile.activeBtnClass );
  3397. }
  3398. }
  3399. });
  3400. // click routing - direct to HTTP or Ajax, accordingly
  3401. $( document ).bind( "click", function( event ) {
  3402. if ( !$.mobile.linkBindingEnabled ) {
  3403. return;
  3404. }
  3405. var link = findClosestLink( event.target ), $link = $( link ), httpCleanup;
  3406. // If there is no link associated with the click or its not a left
  3407. // click we want to ignore the click
  3408. // TODO teach $.mobile.hijackable to operate on raw dom elements so the link wrapping
  3409. // can be avoided
  3410. if ( !link || event.which > 1 || !$link.jqmHijackable().length ) {
  3411. return;
  3412. }
  3413. //remove active link class if external (then it won't be there if you come back)
  3414. httpCleanup = function() {
  3415. window.setTimeout(function() { removeActiveLinkClass( true ); }, 200 );
  3416. };
  3417. //if there's a data-rel=back attr, go back in history
  3418. if ( $link.is( ":jqmData(rel='back')" ) ) {
  3419. $.mobile.back();
  3420. return false;
  3421. }
  3422. var baseUrl = getClosestBaseUrl( $link ),
  3423. //get href, if defined, otherwise default to empty hash
  3424. href = path.makeUrlAbsolute( $link.attr( "href" ) || "#", baseUrl );
  3425. //if ajax is disabled, exit early
  3426. if ( !$.mobile.ajaxEnabled && !path.isEmbeddedPage( href ) ) {
  3427. httpCleanup();
  3428. //use default click handling
  3429. return;
  3430. }
  3431. // XXX_jblas: Ideally links to application pages should be specified as
  3432. // an url to the application document with a hash that is either
  3433. // the site relative path or id to the page. But some of the
  3434. // internal code that dynamically generates sub-pages for nested
  3435. // lists and select dialogs, just write a hash in the link they
  3436. // create. This means the actual URL path is based on whatever
  3437. // the current value of the base tag is at the time this code
  3438. // is called. For now we are just assuming that any url with a
  3439. // hash in it is an application page reference.
  3440. if ( href.search( "#" ) !== -1 ) {
  3441. href = href.replace( /[^#]*#/, "" );
  3442. if ( !href ) {
  3443. //link was an empty hash meant purely
  3444. //for interaction, so we ignore it.
  3445. event.preventDefault();
  3446. return;
  3447. } else if ( path.isPath( href ) ) {
  3448. //we have apath so make it the href we want to load.
  3449. href = path.makeUrlAbsolute( href, baseUrl );
  3450. } else {
  3451. //we have a simple id so use the documentUrl as its base.
  3452. href = path.makeUrlAbsolute( "#" + href, documentUrl.hrefNoHash );
  3453. }
  3454. }
  3455. // Should we handle this link, or let the browser deal with it?
  3456. var useDefaultUrlHandling = $link.is( "[rel='external']" ) || $link.is( ":jqmData(ajax='false')" ) || $link.is( "[target]" ),
  3457. // Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR
  3458. // requests if the document doing the request was loaded via the file:// protocol.
  3459. // This is usually to allow the application to "phone home" and fetch app specific
  3460. // data. We normally let the browser handle external/cross-domain urls, but if the
  3461. // allowCrossDomainPages option is true, we will allow cross-domain http/https
  3462. // requests to go through our page loading logic.
  3463. //check for protocol or rel and its not an embedded page
  3464. //TODO overlap in logic from isExternal, rel=external check should be
  3465. // moved into more comprehensive isExternalLink
  3466. isExternal = useDefaultUrlHandling || ( path.isExternal( href ) && !path.isPermittedCrossDomainRequest( documentUrl, href ) );
  3467. if ( isExternal ) {
  3468. httpCleanup();
  3469. //use default click handling
  3470. return;
  3471. }
  3472. //use ajax
  3473. var transition = $link.jqmData( "transition" ),
  3474. reverse = $link.jqmData( "direction" ) === "reverse" ||
  3475. // deprecated - remove by 1.0
  3476. $link.jqmData( "back" ),
  3477. //this may need to be more specific as we use data-rel more
  3478. role = $link.attr( "data-" + $.mobile.ns + "rel" ) || undefined;
  3479. $.mobile.changePage( href, { transition: transition, reverse: reverse, role: role, link: $link } );
  3480. event.preventDefault();
  3481. });
  3482. //prefetch pages when anchors with data-prefetch are encountered
  3483. $( document ).delegate( ".ui-page", "pageshow.prefetch", function() {
  3484. var urls = [];
  3485. $( this ).find( "a:jqmData(prefetch)" ).each(function() {
  3486. var $link = $( this ),
  3487. url = $link.attr( "href" );
  3488. if ( url && $.inArray( url, urls ) === -1 ) {
  3489. urls.push( url );
  3490. $.mobile.loadPage( url, { role: $link.attr( "data-" + $.mobile.ns + "rel" ) } );
  3491. }
  3492. });
  3493. });
  3494. $.mobile._handleHashChange = function( hash ) {
  3495. //find first page via hash
  3496. var to = path.stripHash( hash ),
  3497. //transition is false if it's the first page, undefined otherwise (and may be overridden by default)
  3498. transition = $.mobile.urlHistory.stack.length === 0 ? "none" : undefined,
  3499. // "navigate" event fired to allow others to take advantage of the more robust hashchange handling
  3500. navEvent = new $.Event( "navigate" ),
  3501. // default options for the changPage calls made after examining the current state
  3502. // of the page and the hash
  3503. changePageOptions = {
  3504. transition: transition,
  3505. changeHash: false,
  3506. fromHashChange: true
  3507. };
  3508. if ( 0 === urlHistory.stack.length ) {
  3509. urlHistory.initialDst = to;
  3510. }
  3511. // We should probably fire the "navigate" event from those places that make calls to _handleHashChange,
  3512. // and have _handleHashChange hook into the "navigate" event instead of triggering it here
  3513. $.mobile.pageContainer.trigger( navEvent );
  3514. if ( navEvent.isDefaultPrevented() ) {
  3515. return;
  3516. }
  3517. //if listening is disabled (either globally or temporarily), or it's a dialog hash
  3518. if ( !$.mobile.hashListeningEnabled || urlHistory.ignoreNextHashChange ) {
  3519. urlHistory.ignoreNextHashChange = false;
  3520. return;
  3521. }
  3522. // special case for dialogs
  3523. if ( urlHistory.stack.length > 1 && to.indexOf( dialogHashKey ) > -1 && urlHistory.initialDst !== to ) {
  3524. // If current active page is not a dialog skip the dialog and continue
  3525. // in the same direction
  3526. if ( !$.mobile.activePage.is( ".ui-dialog" ) ) {
  3527. //determine if we're heading forward or backward and continue accordingly past
  3528. //the current dialog
  3529. urlHistory.directHashChange({
  3530. currentUrl: to,
  3531. isBack: function() { $.mobile.back(); },
  3532. isForward: function() { window.history.forward(); }
  3533. });
  3534. // prevent changePage()
  3535. return;
  3536. } else {
  3537. // if the current active page is a dialog and we're navigating
  3538. // to a dialog use the dialog objected saved in the stack
  3539. urlHistory.directHashChange({
  3540. currentUrl: to,
  3541. // regardless of the direction of the history change
  3542. // do the following
  3543. either: function( isBack ) {
  3544. var active = $.mobile.urlHistory.getActive();
  3545. to = active.pageUrl;
  3546. // make sure to set the role, transition and reversal
  3547. // as most of this is lost by the domCache cleaning
  3548. $.extend( changePageOptions, {
  3549. role: active.role,
  3550. transition: active.transition,
  3551. reverse: isBack
  3552. });
  3553. }
  3554. });
  3555. }
  3556. }
  3557. //if to is defined, load it
  3558. if ( to ) {
  3559. // At this point, 'to' can be one of 3 things, a cached page element from
  3560. // a history stack entry, an id, or site-relative/absolute URL. If 'to' is
  3561. // an id, we need to resolve it against the documentBase, not the location.href,
  3562. // since the hashchange could've been the result of a forward/backward navigation
  3563. // that crosses from an external page/dialog to an internal page/dialog.
  3564. to = ( typeof to === "string" && !path.isPath( to ) ) ? ( path.makeUrlAbsolute( '#' + to, documentBase ) ) : to;
  3565. // If we're about to go to an initial URL that contains a reference to a non-existent
  3566. // internal page, go to the first page instead. We know that the initial hash refers to a
  3567. // non-existent page, because the initial hash did not end up in the initial urlHistory entry
  3568. if ( to === path.makeUrlAbsolute( '#' + urlHistory.initialDst, documentBase ) &&
  3569. urlHistory.stack.length && urlHistory.stack[0].url !== urlHistory.initialDst.replace( dialogHashKey, "" ) ) {
  3570. to = $.mobile.firstPage;
  3571. }
  3572. $.mobile.changePage( to, changePageOptions );
  3573. } else {
  3574. //there's no hash, go to the first page in the dom
  3575. $.mobile.changePage( $.mobile.firstPage, changePageOptions );
  3576. }
  3577. };
  3578. //hashchange event handler
  3579. $window.bind( "hashchange", function( e, triggered ) {
  3580. // Firefox auto-escapes the location.hash as for v13 but
  3581. // leaves the href untouched
  3582. $.mobile._handleHashChange( path.parseLocation().hash );
  3583. });
  3584. //set page min-heights to be device specific
  3585. $( document ).bind( "pageshow", resetActivePageHeight );
  3586. $( window ).bind( "throttledresize", resetActivePageHeight );
  3587. });//navreadyDeferred done callback
  3588. })( jQuery );
  3589. (function( $, window ) {
  3590. // For now, let's Monkeypatch this onto the end of $.mobile._registerInternalEvents
  3591. // Scope self to pushStateHandler so we can reference it sanely within the
  3592. // methods handed off as event handlers
  3593. var pushStateHandler = {},
  3594. self = pushStateHandler,
  3595. $win = $( window ),
  3596. url = $.mobile.path.parseLocation(),
  3597. mobileinitDeferred = $.Deferred(),
  3598. domreadyDeferred = $.Deferred();
  3599. $( document ).ready( $.proxy( domreadyDeferred, "resolve" ) );
  3600. $( document ).one( "mobileinit", $.proxy( mobileinitDeferred, "resolve" ) );
  3601. $.extend( pushStateHandler, {
  3602. // TODO move to a path helper, this is rather common functionality
  3603. initialFilePath: (function() {
  3604. return url.pathname + url.search;
  3605. })(),
  3606. hashChangeTimeout: 200,
  3607. hashChangeEnableTimer: undefined,
  3608. initialHref: url.hrefNoHash,
  3609. state: function() {
  3610. return {
  3611. // firefox auto decodes the url when using location.hash but not href
  3612. hash: $.mobile.path.parseLocation().hash || "#" + self.initialFilePath,
  3613. title: document.title,
  3614. // persist across refresh
  3615. initialHref: self.initialHref
  3616. };
  3617. },
  3618. resetUIKeys: function( url ) {
  3619. var dialog = $.mobile.dialogHashKey,
  3620. subkey = "&" + $.mobile.subPageUrlKey,
  3621. dialogIndex = url.indexOf( dialog );
  3622. if ( dialogIndex > -1 ) {
  3623. url = url.slice( 0, dialogIndex ) + "#" + url.slice( dialogIndex );
  3624. } else if ( url.indexOf( subkey ) > -1 ) {
  3625. url = url.split( subkey ).join( "#" + subkey );
  3626. }
  3627. return url;
  3628. },
  3629. // TODO sort out a single barrier to hashchange functionality
  3630. nextHashChangePrevented: function( value ) {
  3631. $.mobile.urlHistory.ignoreNextHashChange = value;
  3632. self.onHashChangeDisabled = value;
  3633. },
  3634. // on hash change we want to clean up the url
  3635. // NOTE this takes place *after* the vanilla navigation hash change
  3636. // handling has taken place and set the state of the DOM
  3637. onHashChange: function( e ) {
  3638. // disable this hash change
  3639. if ( self.onHashChangeDisabled ) {
  3640. return;
  3641. }
  3642. var href, state,
  3643. // firefox auto decodes the url when using location.hash but not href
  3644. hash = $.mobile.path.parseLocation().hash,
  3645. isPath = $.mobile.path.isPath( hash ),
  3646. resolutionUrl = isPath ? $.mobile.path.getLocation() : $.mobile.getDocumentUrl();
  3647. hash = isPath ? hash.replace( "#", "" ) : hash;
  3648. // propulate the hash when its not available
  3649. state = self.state();
  3650. // make the hash abolute with the current href
  3651. href = $.mobile.path.makeUrlAbsolute( hash, resolutionUrl );
  3652. if ( isPath ) {
  3653. href = self.resetUIKeys( href );
  3654. }
  3655. // replace the current url with the new href and store the state
  3656. // Note that in some cases we might be replacing an url with the
  3657. // same url. We do this anyways because we need to make sure that
  3658. // all of our history entries have a state object associated with
  3659. // them. This allows us to work around the case where $.mobile.back()
  3660. // is called to transition from an external page to an embedded page.
  3661. // In that particular case, a hashchange event is *NOT* generated by the browser.
  3662. // Ensuring each history entry has a state object means that onPopState()
  3663. // will always trigger our hashchange callback even when a hashchange event
  3664. // is not fired.
  3665. history.replaceState( state, document.title, href );
  3666. },
  3667. // on popstate (ie back or forward) we need to replace the hash that was there previously
  3668. // cleaned up by the additional hash handling
  3669. onPopState: function( e ) {
  3670. var poppedState = e.originalEvent.state,
  3671. fromHash, toHash, hashChanged;
  3672. // if there's no state its not a popstate we care about, eg chrome's initial popstate
  3673. if ( poppedState ) {
  3674. // if we get two pop states in under this.hashChangeTimeout
  3675. // make sure to clear any timer set for the previous change
  3676. clearTimeout( self.hashChangeEnableTimer );
  3677. // make sure to enable hash handling for the the _handleHashChange call
  3678. self.nextHashChangePrevented( false );
  3679. // change the page based on the hash in the popped state
  3680. $.mobile._handleHashChange( poppedState.hash );
  3681. // prevent any hashchange in the next self.hashChangeTimeout
  3682. self.nextHashChangePrevented( true );
  3683. // re-enable hash change handling after swallowing a possible hash
  3684. // change event that comes on all popstates courtesy of browsers like Android
  3685. self.hashChangeEnableTimer = setTimeout( function() {
  3686. self.nextHashChangePrevented( false );
  3687. }, self.hashChangeTimeout );
  3688. }
  3689. },
  3690. init: function() {
  3691. $win.bind( "hashchange", self.onHashChange );
  3692. // Handle popstate events the occur through history changes
  3693. $win.bind( "popstate", self.onPopState );
  3694. // if there's no hash, we need to replacestate for returning to home
  3695. if ( location.hash === "" ) {
  3696. history.replaceState( self.state(), document.title, $.mobile.path.getLocation() );
  3697. }
  3698. }
  3699. });
  3700. // We need to init when "mobileinit", "domready", and "navready" have all happened
  3701. $.when( domreadyDeferred, mobileinitDeferred, $.mobile.navreadyDeferred ).done(function() {
  3702. if ( $.mobile.pushStateEnabled && $.support.pushState ) {
  3703. pushStateHandler.init();
  3704. }
  3705. });
  3706. })( jQuery, this );
  3707. /*
  3708. * fallback transition for flip in non-3D supporting browsers (which tend to handle complex transitions poorly in general
  3709. */
  3710. (function( $, window, undefined ) {
  3711. $.mobile.transitionFallbacks.flip = "fade";
  3712. })( jQuery, this );
  3713. /*
  3714. * fallback transition for flow in non-3D supporting browsers (which tend to handle complex transitions poorly in general
  3715. */
  3716. (function( $, window, undefined ) {
  3717. $.mobile.transitionFallbacks.flow = "fade";
  3718. })( jQuery, this );
  3719. /*
  3720. * fallback transition for pop in non-3D supporting browsers (which tend to handle complex transitions poorly in general
  3721. */
  3722. (function( $, window, undefined ) {
  3723. $.mobile.transitionFallbacks.pop = "fade";
  3724. })( jQuery, this );
  3725. /*
  3726. * fallback transition for slide in non-3D supporting browsers (which tend to handle complex transitions poorly in general
  3727. */
  3728. (function( $, window, undefined ) {
  3729. // Use the simultaneous transitions handler for slide transitions
  3730. $.mobile.transitionHandlers.slide = $.mobile.transitionHandlers.simultaneous;
  3731. // Set the slide transitions's fallback to "fade"
  3732. $.mobile.transitionFallbacks.slide = "fade";
  3733. })( jQuery, this );
  3734. /*
  3735. * fallback transition for slidedown in non-3D supporting browsers (which tend to handle complex transitions poorly in general
  3736. */
  3737. (function( $, window, undefined ) {
  3738. $.mobile.transitionFallbacks.slidedown = "fade";
  3739. })( jQuery, this );
  3740. /*
  3741. * fallback transition for slidefade in non-3D supporting browsers (which tend to handle complex transitions poorly in general
  3742. */
  3743. (function( $, window, undefined ) {
  3744. // Set the slide transitions's fallback to "fade"
  3745. $.mobile.transitionFallbacks.slidefade = "fade";
  3746. })( jQuery, this );
  3747. /*
  3748. * fallback transition for slideup in non-3D supporting browsers (which tend to handle complex transitions poorly in general
  3749. */
  3750. (function( $, window, undefined ) {
  3751. $.mobile.transitionFallbacks.slideup = "fade";
  3752. })( jQuery, this );
  3753. /*
  3754. * fallback transition for turn in non-3D supporting browsers (which tend to handle complex transitions poorly in general
  3755. */
  3756. (function( $, window, undefined ) {
  3757. $.mobile.transitionFallbacks.turn = "fade";
  3758. })( jQuery, this );
  3759. (function( $, undefined ) {
  3760. $.mobile.page.prototype.options.degradeInputs = {
  3761. color: false,
  3762. date: false,
  3763. datetime: false,
  3764. "datetime-local": false,
  3765. email: false,
  3766. month: false,
  3767. number: false,
  3768. range: "number",
  3769. search: "text",
  3770. tel: false,
  3771. time: false,
  3772. url: false,
  3773. week: false
  3774. };
  3775. //auto self-init widgets
  3776. $( document ).bind( "pagecreate create", function( e ) {
  3777. var page = $.mobile.closestPageData( $( e.target ) ), options;
  3778. if ( !page ) {
  3779. return;
  3780. }
  3781. options = page.options;
  3782. // degrade inputs to avoid poorly implemented native functionality
  3783. $( e.target ).find( "input" ).not( page.keepNativeSelector() ).each(function() {
  3784. var $this = $( this ),
  3785. type = this.getAttribute( "type" ),
  3786. optType = options.degradeInputs[ type ] || "text";
  3787. if ( options.degradeInputs[ type ] ) {
  3788. var html = $( "<div>" ).html( $this.clone() ).html(),
  3789. // In IE browsers, the type sometimes doesn't exist in the cloned markup, so we replace the closing tag instead
  3790. hasType = html.indexOf( " type=" ) > -1,
  3791. findstr = hasType ? /\s+type=["']?\w+['"]?/ : /\/?>/,
  3792. repstr = " type=\"" + optType + "\" data-" + $.mobile.ns + "type=\"" + type + "\"" + ( hasType ? "" : ">" );
  3793. $this.replaceWith( html.replace( findstr, repstr ) );
  3794. }
  3795. });
  3796. });
  3797. })( jQuery );
  3798. (function( $, window, undefined ) {
  3799. $.widget( "mobile.dialog", $.mobile.widget, {
  3800. options: {
  3801. closeBtnText: "Close",
  3802. overlayTheme: "a",
  3803. initSelector: ":jqmData(role='dialog')"
  3804. },
  3805. _create: function() {
  3806. var self = this,
  3807. $el = this.element,
  3808. headerCloseButton = $( "<a href='#' data-" + $.mobile.ns + "icon='delete' data-" + $.mobile.ns + "iconpos='notext'>"+ this.options.closeBtnText + "</a>" ),
  3809. dialogWrap = $( "<div/>", {
  3810. "role" : "dialog",
  3811. "class" : "ui-dialog-contain ui-corner-all ui-overlay-shadow"
  3812. });
  3813. $el.addClass( "ui-dialog ui-overlay-" + this.options.overlayTheme );
  3814. // Class the markup for dialog styling
  3815. // Set aria role
  3816. $el
  3817. .wrapInner( dialogWrap )
  3818. .children()
  3819. .find( ":jqmData(role='header')" )
  3820. .prepend( headerCloseButton )
  3821. .end()
  3822. .children( ':first-child')
  3823. .addClass( "ui-corner-top" )
  3824. .end()
  3825. .children( ":last-child" )
  3826. .addClass( "ui-corner-bottom" );
  3827. // this must be an anonymous function so that select menu dialogs can replace
  3828. // the close method. This is a change from previously just defining data-rel=back
  3829. // on the button and letting nav handle it
  3830. //
  3831. // Use click rather than vclick in order to prevent the possibility of unintentionally
  3832. // reopening the dialog if the dialog opening item was directly under the close button.
  3833. headerCloseButton.bind( "click", function() {
  3834. self.close();
  3835. });
  3836. /* bind events
  3837. - clicks and submits should use the closing transition that the dialog opened with
  3838. unless a data-transition is specified on the link/form
  3839. - if the click was on the close button, or the link has a data-rel="back" it'll go back in history naturally
  3840. */
  3841. $el.bind( "vclick submit", function( event ) {
  3842. var $target = $( event.target ).closest( event.type === "vclick" ? "a" : "form" ),
  3843. active;
  3844. if ( $target.length && !$target.jqmData( "transition" ) ) {
  3845. active = $.mobile.urlHistory.getActive() || {};
  3846. $target.attr( "data-" + $.mobile.ns + "transition", ( active.transition || $.mobile.defaultDialogTransition ) )
  3847. .attr( "data-" + $.mobile.ns + "direction", "reverse" );
  3848. }
  3849. })
  3850. .bind( "pagehide", function( e, ui ) {
  3851. $( this ).find( "." + $.mobile.activeBtnClass ).not( ".ui-slider-bg" ).removeClass( $.mobile.activeBtnClass );
  3852. })
  3853. // Override the theme set by the page plugin on pageshow
  3854. .bind( "pagebeforeshow", function() {
  3855. self._isCloseable = true;
  3856. if ( self.options.overlayTheme ) {
  3857. self.element
  3858. .page( "removeContainerBackground" )
  3859. .page( "setContainerBackground", self.options.overlayTheme );
  3860. }
  3861. });
  3862. },
  3863. // Close method goes back in history
  3864. close: function() {
  3865. var dst;
  3866. if ( this._isCloseable ) {
  3867. this._isCloseable = false;
  3868. if ( $.mobile.hashListeningEnabled ) {
  3869. $.mobile.back();
  3870. } else {
  3871. dst = $.mobile.urlHistory.getPrev().url;
  3872. if ( !$.mobile.path.isPath( dst ) ) {
  3873. dst = $.mobile.path.makeUrlAbsolute( "#" + dst );
  3874. }
  3875. $.mobile.changePage( dst, { changeHash: false, fromHashChange: true } );
  3876. }
  3877. }
  3878. }
  3879. });
  3880. //auto self-init widgets
  3881. $( document ).delegate( $.mobile.dialog.prototype.options.initSelector, "pagecreate", function() {
  3882. $.mobile.dialog.prototype.enhance( this );
  3883. });
  3884. })( jQuery, this );
  3885. (function( $, undefined ) {
  3886. $.mobile.page.prototype.options.backBtnText = "Back";
  3887. $.mobile.page.prototype.options.addBackBtn = false;
  3888. $.mobile.page.prototype.options.backBtnTheme = null;
  3889. $.mobile.page.prototype.options.headerTheme = "a";
  3890. $.mobile.page.prototype.options.footerTheme = "a";
  3891. $.mobile.page.prototype.options.contentTheme = null;
  3892. // NOTE bind used to force this binding to run before the buttonMarkup binding
  3893. // which expects .ui-footer top be applied in its gigantic selector
  3894. // TODO remove the buttonMarkup giant selector and move it to the various modules
  3895. // on which it depends
  3896. $( document ).bind( "pagecreate", function( e ) {
  3897. var $page = $( e.target ),
  3898. o = $page.data( "page" ).options,
  3899. pageRole = $page.jqmData( "role" ),
  3900. pageTheme = o.theme;
  3901. $( ":jqmData(role='header'), :jqmData(role='footer'), :jqmData(role='content')", $page )
  3902. .jqmEnhanceable()
  3903. .each(function() {
  3904. var $this = $( this ),
  3905. role = $this.jqmData( "role" ),
  3906. theme = $this.jqmData( "theme" ),
  3907. contentTheme = theme || o.contentTheme || ( pageRole === "dialog" && pageTheme ),
  3908. $headeranchors,
  3909. leftbtn,
  3910. rightbtn,
  3911. backBtn;
  3912. $this.addClass( "ui-" + role );
  3913. //apply theming and markup modifications to page,header,content,footer
  3914. if ( role === "header" || role === "footer" ) {
  3915. var thisTheme = theme || ( role === "header" ? o.headerTheme : o.footerTheme ) || pageTheme;
  3916. $this
  3917. //add theme class
  3918. .addClass( "ui-bar-" + thisTheme )
  3919. // Add ARIA role
  3920. .attr( "role", role === "header" ? "banner" : "contentinfo" );
  3921. if ( role === "header") {
  3922. // Right,left buttons
  3923. $headeranchors = $this.children( "a, button" );
  3924. leftbtn = $headeranchors.hasClass( "ui-btn-left" );
  3925. rightbtn = $headeranchors.hasClass( "ui-btn-right" );
  3926. leftbtn = leftbtn || $headeranchors.eq( 0 ).not( ".ui-btn-right" ).addClass( "ui-btn-left" ).length;
  3927. rightbtn = rightbtn || $headeranchors.eq( 1 ).addClass( "ui-btn-right" ).length;
  3928. }
  3929. // Auto-add back btn on pages beyond first view
  3930. if ( o.addBackBtn &&
  3931. role === "header" &&
  3932. $( ".ui-page" ).length > 1 &&
  3933. $page.jqmData( "url" ) !== $.mobile.path.stripHash( location.hash ) &&
  3934. !leftbtn ) {
  3935. backBtn = $( "<a href='javascript:void(0);' class='ui-btn-left' data-"+ $.mobile.ns +"rel='back' data-"+ $.mobile.ns +"icon='arrow-l'>"+ o.backBtnText +"</a>" )
  3936. // If theme is provided, override default inheritance
  3937. .attr( "data-"+ $.mobile.ns +"theme", o.backBtnTheme || thisTheme )
  3938. .prependTo( $this );
  3939. }
  3940. // Page title
  3941. $this.children( "h1, h2, h3, h4, h5, h6" )
  3942. .addClass( "ui-title" )
  3943. // Regardless of h element number in src, it becomes h1 for the enhanced page
  3944. .attr({
  3945. "role": "heading",
  3946. "aria-level": "1"
  3947. });
  3948. } else if ( role === "content" ) {
  3949. if ( contentTheme ) {
  3950. $this.addClass( "ui-body-" + ( contentTheme ) );
  3951. }
  3952. // Add ARIA role
  3953. $this.attr( "role", "main" );
  3954. }
  3955. });
  3956. });
  3957. })( jQuery );
  3958. (function( $, undefined ) {
  3959. // filter function removes whitespace between label and form element so we can use inline-block (nodeType 3 = text)
  3960. $.fn.fieldcontain = function( options ) {
  3961. return this
  3962. .addClass( "ui-field-contain ui-body ui-br" )
  3963. .contents().filter( function() {
  3964. return ( this.nodeType === 3 && !/\S/.test( this.nodeValue ) );
  3965. }).remove();
  3966. };
  3967. //auto self-init widgets
  3968. $( document ).bind( "pagecreate create", function( e ) {
  3969. $( ":jqmData(role='fieldcontain')", e.target ).jqmEnhanceable().fieldcontain();
  3970. });
  3971. })( jQuery );
  3972. (function( $, undefined ) {
  3973. $.fn.grid = function( options ) {
  3974. return this.each(function() {
  3975. var $this = $( this ),
  3976. o = $.extend({
  3977. grid: null
  3978. }, options ),
  3979. $kids = $this.children(),
  3980. gridCols = { solo:1, a:2, b:3, c:4, d:5 },
  3981. grid = o.grid,
  3982. iterator;
  3983. if ( !grid ) {
  3984. if ( $kids.length <= 5 ) {
  3985. for ( var letter in gridCols ) {
  3986. if ( gridCols[ letter ] === $kids.length ) {
  3987. grid = letter;
  3988. }
  3989. }
  3990. } else {
  3991. grid = "a";
  3992. $this.addClass( "ui-grid-duo" );
  3993. }
  3994. }
  3995. iterator = gridCols[grid];
  3996. $this.addClass( "ui-grid-" + grid );
  3997. $kids.filter( ":nth-child(" + iterator + "n+1)" ).addClass( "ui-block-a" );
  3998. if ( iterator > 1 ) {
  3999. $kids.filter( ":nth-child(" + iterator + "n+2)" ).addClass( "ui-block-b" );
  4000. }
  4001. if ( iterator > 2 ) {
  4002. $kids.filter( ":nth-child(" + iterator + "n+3)" ).addClass( "ui-block-c" );
  4003. }
  4004. if ( iterator > 3 ) {
  4005. $kids.filter( ":nth-child(" + iterator + "n+4)" ).addClass( "ui-block-d" );
  4006. }
  4007. if ( iterator > 4 ) {
  4008. $kids.filter( ":nth-child(" + iterator + "n+5)" ).addClass( "ui-block-e" );
  4009. }
  4010. });
  4011. };
  4012. })( jQuery );
  4013. (function( $, undefined ) {
  4014. $( document ).bind( "pagecreate create", function( e ) {
  4015. $( ":jqmData(role='nojs')", e.target ).addClass( "ui-nojs" );
  4016. });
  4017. })( jQuery );
  4018. (function( $, undefined ) {
  4019. $.fn.buttonMarkup = function( options ) {
  4020. var $workingSet = this,
  4021. mapToDataAttr = function( key, value ) {
  4022. e.setAttribute( "data-" + $.mobile.ns + key, value );
  4023. el.jqmData( key, value );
  4024. };
  4025. // Enforce options to be of type string
  4026. options = ( options && ( $.type( options ) === "object" ) )? options : {};
  4027. for ( var i = 0; i < $workingSet.length; i++ ) {
  4028. var el = $workingSet.eq( i ),
  4029. e = el[ 0 ],
  4030. o = $.extend( {}, $.fn.buttonMarkup.defaults, {
  4031. icon: options.icon !== undefined ? options.icon : el.jqmData( "icon" ),
  4032. iconpos: options.iconpos !== undefined ? options.iconpos : el.jqmData( "iconpos" ),
  4033. theme: options.theme !== undefined ? options.theme : el.jqmData( "theme" ) || $.mobile.getInheritedTheme( el, "c" ),
  4034. inline: options.inline !== undefined ? options.inline : el.jqmData( "inline" ),
  4035. shadow: options.shadow !== undefined ? options.shadow : el.jqmData( "shadow" ),
  4036. corners: options.corners !== undefined ? options.corners : el.jqmData( "corners" ),
  4037. iconshadow: options.iconshadow !== undefined ? options.iconshadow : el.jqmData( "iconshadow" ),
  4038. mini: options.mini !== undefined ? options.mini : el.jqmData( "mini" )
  4039. }, options ),
  4040. // Classes Defined
  4041. innerClass = "ui-btn-inner",
  4042. textClass = "ui-btn-text",
  4043. buttonClass, iconClass,
  4044. // Button inner markup
  4045. buttonInner,
  4046. buttonText,
  4047. buttonIcon,
  4048. buttonElements;
  4049. $.each( o, mapToDataAttr );
  4050. if ( el.jqmData( "rel" ) === "popup" && el.attr( "href" ) ) {
  4051. e.setAttribute( "aria-haspopup", true );
  4052. e.setAttribute( "aria-owns", e.getAttribute( "href" ) );
  4053. }
  4054. // Check if this element is already enhanced
  4055. buttonElements = $.data( ( ( e.tagName === "INPUT" || e.tagName === "BUTTON" ) ? e.parentNode : e ), "buttonElements" );
  4056. if ( buttonElements ) {
  4057. e = buttonElements.outer;
  4058. el = $( e );
  4059. buttonInner = buttonElements.inner;
  4060. buttonText = buttonElements.text;
  4061. // We will recreate this icon below
  4062. $( buttonElements.icon ).remove();
  4063. buttonElements.icon = null;
  4064. }
  4065. else {
  4066. buttonInner = document.createElement( o.wrapperEls );
  4067. buttonText = document.createElement( o.wrapperEls );
  4068. }
  4069. buttonIcon = o.icon ? document.createElement( "span" ) : null;
  4070. if ( attachEvents && !buttonElements ) {
  4071. attachEvents();
  4072. }
  4073. // if not, try to find closest theme container
  4074. if ( !o.theme ) {
  4075. o.theme = $.mobile.getInheritedTheme( el, "c" );
  4076. }
  4077. buttonClass = "ui-btn ui-btn-up-" + o.theme;
  4078. buttonClass += o.shadow ? " ui-shadow" : "";
  4079. buttonClass += o.corners ? " ui-btn-corner-all" : "";
  4080. if ( o.mini !== undefined ) {
  4081. // Used to control styling in headers/footers, where buttons default to `mini` style.
  4082. buttonClass += o.mini === true ? " ui-mini" : " ui-fullsize";
  4083. }
  4084. if ( o.inline !== undefined ) {
  4085. // Used to control styling in headers/footers, where buttons default to `inline` style.
  4086. buttonClass += o.inline === true ? " ui-btn-inline" : " ui-btn-block";
  4087. }
  4088. if ( o.icon ) {
  4089. o.icon = "ui-icon-" + o.icon;
  4090. o.iconpos = o.iconpos || "left";
  4091. iconClass = "ui-icon " + o.icon;
  4092. if ( o.iconshadow ) {
  4093. iconClass += " ui-icon-shadow";
  4094. }
  4095. }
  4096. if ( o.iconpos ) {
  4097. buttonClass += " ui-btn-icon-" + o.iconpos;
  4098. if ( o.iconpos === "notext" && !el.attr( "title" ) ) {
  4099. el.attr( "title", el.getEncodedText() );
  4100. }
  4101. }
  4102. innerClass += o.corners ? " ui-btn-corner-all" : "";
  4103. if ( o.iconpos && o.iconpos === "notext" && !el.attr( "title" ) ) {
  4104. el.attr( "title", el.getEncodedText() );
  4105. }
  4106. if ( buttonElements ) {
  4107. el.removeClass( buttonElements.bcls || "" );
  4108. }
  4109. el.removeClass( "ui-link" ).addClass( buttonClass );
  4110. buttonInner.className = innerClass;
  4111. buttonText.className = textClass;
  4112. if ( !buttonElements ) {
  4113. buttonInner.appendChild( buttonText );
  4114. }
  4115. if ( buttonIcon ) {
  4116. buttonIcon.className = iconClass;
  4117. if ( !( buttonElements && buttonElements.icon ) ) {
  4118. buttonIcon.innerHTML = "&#160;";
  4119. buttonInner.appendChild( buttonIcon );
  4120. }
  4121. }
  4122. while ( e.firstChild && !buttonElements ) {
  4123. buttonText.appendChild( e.firstChild );
  4124. }
  4125. if ( !buttonElements ) {
  4126. e.appendChild( buttonInner );
  4127. }
  4128. // Assign a structure containing the elements of this button to the elements of this button. This
  4129. // will allow us to recognize this as an already-enhanced button in future calls to buttonMarkup().
  4130. buttonElements = {
  4131. bcls : buttonClass,
  4132. outer : e,
  4133. inner : buttonInner,
  4134. text : buttonText,
  4135. icon : buttonIcon
  4136. };
  4137. $.data( e, 'buttonElements', buttonElements );
  4138. $.data( buttonInner, 'buttonElements', buttonElements );
  4139. $.data( buttonText, 'buttonElements', buttonElements );
  4140. if ( buttonIcon ) {
  4141. $.data( buttonIcon, 'buttonElements', buttonElements );
  4142. }
  4143. }
  4144. return this;
  4145. };
  4146. $.fn.buttonMarkup.defaults = {
  4147. corners: true,
  4148. shadow: true,
  4149. iconshadow: true,
  4150. wrapperEls: "span"
  4151. };
  4152. function closestEnabledButton( element ) {
  4153. var cname;
  4154. while ( element ) {
  4155. // Note that we check for typeof className below because the element we
  4156. // handed could be in an SVG DOM where className on SVG elements is defined to
  4157. // be of a different type (SVGAnimatedString). We only operate on HTML DOM
  4158. // elements, so we look for plain "string".
  4159. cname = ( typeof element.className === 'string' ) && ( element.className + ' ' );
  4160. if ( cname && cname.indexOf( "ui-btn " ) > -1 && cname.indexOf( "ui-disabled " ) < 0 ) {
  4161. break;
  4162. }
  4163. element = element.parentNode;
  4164. }
  4165. return element;
  4166. }
  4167. var attachEvents = function() {
  4168. var hoverDelay = $.mobile.buttonMarkup.hoverDelay, hov, foc;
  4169. $( document ).bind( {
  4170. "vmousedown vmousecancel vmouseup vmouseover vmouseout focus blur scrollstart": function( event ) {
  4171. var theme,
  4172. $btn = $( closestEnabledButton( event.target ) ),
  4173. isTouchEvent = event.originalEvent && /^touch/.test( event.originalEvent.type ),
  4174. evt = event.type;
  4175. if ( $btn.length ) {
  4176. theme = $btn.attr( "data-" + $.mobile.ns + "theme" );
  4177. if ( evt === "vmousedown" ) {
  4178. if ( isTouchEvent ) {
  4179. // Use a short delay to determine if the user is scrolling before highlighting
  4180. hov = setTimeout( function() {
  4181. $btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
  4182. }, hoverDelay );
  4183. } else {
  4184. $btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme );
  4185. }
  4186. } else if ( evt === "vmousecancel" || evt === "vmouseup" ) {
  4187. $btn.removeClass( "ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
  4188. } else if ( evt === "vmouseover" || evt === "focus" ) {
  4189. if ( isTouchEvent ) {
  4190. // Use a short delay to determine if the user is scrolling before highlighting
  4191. foc = setTimeout( function() {
  4192. $btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
  4193. }, hoverDelay );
  4194. } else {
  4195. $btn.removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme );
  4196. }
  4197. } else if ( evt === "vmouseout" || evt === "blur" || evt === "scrollstart" ) {
  4198. $btn.removeClass( "ui-btn-hover-" + theme + " ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme );
  4199. if ( hov ) {
  4200. clearTimeout( hov );
  4201. }
  4202. if ( foc ) {
  4203. clearTimeout( foc );
  4204. }
  4205. }
  4206. }
  4207. },
  4208. "focusin focus": function( event ) {
  4209. $( closestEnabledButton( event.target ) ).addClass( $.mobile.focusClass );
  4210. },
  4211. "focusout blur": function( event ) {
  4212. $( closestEnabledButton( event.target ) ).removeClass( $.mobile.focusClass );
  4213. }
  4214. });
  4215. attachEvents = null;
  4216. };
  4217. //links in bars, or those with data-role become buttons
  4218. //auto self-init widgets
  4219. $( document ).bind( "pagecreate create", function( e ) {
  4220. $( ":jqmData(role='button'), .ui-bar > a, .ui-header > a, .ui-footer > a, .ui-bar > :jqmData(role='controlgroup') > a", e.target )
  4221. .jqmEnhanceable()
  4222. .not( "button, input, .ui-btn, :jqmData(role='none'), :jqmData(role='nojs')" )
  4223. .buttonMarkup();
  4224. });
  4225. })( jQuery );
  4226. (function( $, undefined ) {
  4227. $.widget( "mobile.collapsible", $.mobile.widget, {
  4228. options: {
  4229. expandCueText: " click to expand contents",
  4230. collapseCueText: " click to collapse contents",
  4231. collapsed: true,
  4232. heading: "h1,h2,h3,h4,h5,h6,legend",
  4233. theme: null,
  4234. contentTheme: null,
  4235. inset: true,
  4236. mini: false,
  4237. initSelector: ":jqmData(role='collapsible')"
  4238. },
  4239. _create: function() {
  4240. var $el = this.element,
  4241. o = this.options,
  4242. collapsible = $el.addClass( "ui-collapsible" ),
  4243. collapsibleHeading = $el.children( o.heading ).first(),
  4244. collapsedIcon = $el.jqmData( "collapsed-icon" ) || o.collapsedIcon,
  4245. expandedIcon = $el.jqmData( "expanded-icon" ) || o.expandedIcon,
  4246. collapsibleContent = collapsible.wrapInner( "<div class='ui-collapsible-content'></div>" ).children( ".ui-collapsible-content" ),
  4247. collapsibleSet = $el.closest( ":jqmData(role='collapsible-set')" ).addClass( "ui-collapsible-set" );
  4248. // Replace collapsibleHeading if it's a legend
  4249. if ( collapsibleHeading.is( "legend" ) ) {
  4250. collapsibleHeading = $( "<div role='heading'>"+ collapsibleHeading.html() +"</div>" ).insertBefore( collapsibleHeading );
  4251. collapsibleHeading.next().remove();
  4252. }
  4253. // If we are in a collapsible set
  4254. if ( collapsibleSet.length ) {
  4255. // Inherit the theme from collapsible-set
  4256. if ( !o.theme ) {
  4257. o.theme = collapsibleSet.jqmData( "theme" ) || $.mobile.getInheritedTheme( collapsibleSet, "c" );
  4258. }
  4259. // Inherit the content-theme from collapsible-set
  4260. if ( !o.contentTheme ) {
  4261. o.contentTheme = collapsibleSet.jqmData( "content-theme" );
  4262. }
  4263. // Get the preference for collapsed icon in the set
  4264. if ( !o.collapsedIcon ) {
  4265. o.collapsedIcon = collapsibleSet.jqmData( "collapsed-icon" );
  4266. }
  4267. // Get the preference for expanded icon in the set
  4268. if ( !o.expandedIcon ) {
  4269. o.expandedIcon = collapsibleSet.jqmData( "expanded-icon" );
  4270. }
  4271. // Gets the preference icon position in the set
  4272. if ( !o.iconPos ) {
  4273. o.iconPos = collapsibleSet.jqmData( "iconpos" );
  4274. }
  4275. // Inherit the preference for inset from collapsible-set or set the default value to ensure equalty within a set
  4276. if ( collapsibleSet.jqmData( "inset" ) !== undefined ) {
  4277. o.inset = collapsibleSet.jqmData( "inset" );
  4278. } else {
  4279. o.inset = true;
  4280. }
  4281. // Gets the preference for mini in the set
  4282. if ( !o.mini ) {
  4283. o.mini = collapsibleSet.jqmData( "mini" );
  4284. }
  4285. } else {
  4286. // get inherited theme if not a set and no theme has been set
  4287. if ( !o.theme ) {
  4288. o.theme = $.mobile.getInheritedTheme( $el, "c" );
  4289. }
  4290. }
  4291. if ( !!o.inset ) {
  4292. collapsible.addClass( "ui-collapsible-inset" );
  4293. }
  4294. collapsibleContent.addClass( ( o.contentTheme ) ? ( "ui-body-" + o.contentTheme ) : "");
  4295. collapsedIcon = $el.jqmData( "collapsed-icon" ) || o.collapsedIcon || "plus";
  4296. expandedIcon = $el.jqmData( "expanded-icon" ) || o.expandedIcon || "minus";
  4297. collapsibleHeading
  4298. //drop heading in before content
  4299. .insertBefore( collapsibleContent )
  4300. //modify markup & attributes
  4301. .addClass( "ui-collapsible-heading" )
  4302. .append( "<span class='ui-collapsible-heading-status'></span>" )
  4303. .wrapInner( "<a href='#' class='ui-collapsible-heading-toggle'></a>" )
  4304. .find( "a" )
  4305. .first()
  4306. .buttonMarkup({
  4307. shadow: false,
  4308. corners: false,
  4309. iconpos: $el.jqmData( "iconpos" ) || o.iconPos || "left",
  4310. icon: collapsedIcon,
  4311. mini: o.mini,
  4312. theme: o.theme
  4313. });
  4314. if ( !!o.inset ) {
  4315. collapsibleHeading
  4316. .find( "a" ).first().add( ".ui-btn-inner", $el )
  4317. .addClass( "ui-corner-top ui-corner-bottom" );
  4318. }
  4319. //events
  4320. collapsible
  4321. .bind( "expand collapse", function( event ) {
  4322. if ( !event.isDefaultPrevented() ) {
  4323. var $this = $( this ),
  4324. isCollapse = ( event.type === "collapse" ),
  4325. contentTheme = o.contentTheme;
  4326. event.preventDefault();
  4327. collapsibleHeading
  4328. .toggleClass( "ui-collapsible-heading-collapsed", isCollapse )
  4329. .find( ".ui-collapsible-heading-status" )
  4330. .text( isCollapse ? o.expandCueText : o.collapseCueText )
  4331. .end()
  4332. .find( ".ui-icon" )
  4333. .toggleClass( "ui-icon-" + expandedIcon, !isCollapse )
  4334. // logic or cause same icon for expanded/collapsed state would remove the ui-icon-class
  4335. .toggleClass( "ui-icon-" + collapsedIcon, ( isCollapse || expandedIcon === collapsedIcon ) )
  4336. .end()
  4337. .find( "a" ).first().removeClass( $.mobile.activeBtnClass );
  4338. $this.toggleClass( "ui-collapsible-collapsed", isCollapse );
  4339. collapsibleContent.toggleClass( "ui-collapsible-content-collapsed", isCollapse ).attr( "aria-hidden", isCollapse );
  4340. if ( contentTheme && !!o.inset && ( !collapsibleSet.length || collapsible.jqmData( "collapsible-last" ) ) ) {
  4341. collapsibleHeading
  4342. .find( "a" ).first().add( collapsibleHeading.find( ".ui-btn-inner" ) )
  4343. .toggleClass( "ui-corner-bottom", isCollapse );
  4344. collapsibleContent.toggleClass( "ui-corner-bottom", !isCollapse );
  4345. }
  4346. collapsibleContent.trigger( "updatelayout" );
  4347. }
  4348. })
  4349. .trigger( o.collapsed ? "collapse" : "expand" );
  4350. collapsibleHeading
  4351. .bind( "tap", function( event ) {
  4352. collapsibleHeading.find( "a" ).first().addClass( $.mobile.activeBtnClass );
  4353. })
  4354. .bind( "click", function( event ) {
  4355. var type = collapsibleHeading.is( ".ui-collapsible-heading-collapsed" ) ? "expand" : "collapse";
  4356. collapsible.trigger( type );
  4357. event.preventDefault();
  4358. event.stopPropagation();
  4359. });
  4360. }
  4361. });
  4362. //auto self-init widgets
  4363. $( document ).bind( "pagecreate create", function( e ) {
  4364. $.mobile.collapsible.prototype.enhanceWithin( e.target );
  4365. });
  4366. })( jQuery );
  4367. (function( $, undefined ) {
  4368. $.widget( "mobile.collapsibleset", $.mobile.widget, {
  4369. options: {
  4370. initSelector: ":jqmData(role='collapsible-set')"
  4371. },
  4372. _create: function() {
  4373. var $el = this.element.addClass( "ui-collapsible-set" ),
  4374. o = this.options;
  4375. // Inherit the theme from collapsible-set
  4376. if ( !o.theme ) {
  4377. o.theme = $.mobile.getInheritedTheme( $el, "c" );
  4378. }
  4379. // Inherit the content-theme from collapsible-set
  4380. if ( !o.contentTheme ) {
  4381. o.contentTheme = $el.jqmData( "content-theme" );
  4382. }
  4383. if ( $el.jqmData( "inset" ) !== undefined ) {
  4384. o.inset = $el.jqmData( "inset" );
  4385. }
  4386. o.inset = o.inset !== undefined ? o.inset : true;
  4387. // Initialize the collapsible set if it's not already initialized
  4388. if ( !$el.jqmData( "collapsiblebound" ) ) {
  4389. $el
  4390. .jqmData( "collapsiblebound", true )
  4391. .bind( "expand collapse", function( event ) {
  4392. var isCollapse = ( event.type === "collapse" ),
  4393. collapsible = $( event.target ).closest( ".ui-collapsible" ),
  4394. widget = collapsible.data( "collapsible" );
  4395. if ( collapsible.jqmData( "collapsible-last" ) && !!o.inset ) {
  4396. collapsible.find( ".ui-collapsible-heading" ).first()
  4397. .find( "a" ).first()
  4398. .toggleClass( "ui-corner-bottom", isCollapse )
  4399. .find( ".ui-btn-inner" )
  4400. .toggleClass( "ui-corner-bottom", isCollapse );
  4401. collapsible.find( ".ui-collapsible-content" ).toggleClass( "ui-corner-bottom", !isCollapse );
  4402. }
  4403. })
  4404. .bind( "expand", function( event ) {
  4405. var closestCollapsible = $( event.target )
  4406. .closest( ".ui-collapsible" );
  4407. if ( closestCollapsible.parent().is( ":jqmData(role='collapsible-set')" ) ) {
  4408. closestCollapsible
  4409. .siblings( ".ui-collapsible" )
  4410. .trigger( "collapse" );
  4411. }
  4412. });
  4413. }
  4414. },
  4415. _init: function() {
  4416. var $el = this.element,
  4417. collapsiblesInSet = $el.children( ":jqmData(role='collapsible')" ),
  4418. expanded = collapsiblesInSet.filter( ":jqmData(collapsed='false')" );
  4419. this.refresh();
  4420. // Because the corners are handled by the collapsible itself and the default state is collapsed
  4421. // That was causing https://github.com/jquery/jquery-mobile/issues/4116
  4422. expanded.trigger( "expand" );
  4423. },
  4424. refresh: function() {
  4425. var $el = this.element,
  4426. o = this.options,
  4427. collapsiblesInSet = $el.children( ":jqmData(role='collapsible')" );
  4428. $.mobile.collapsible.prototype.enhance( collapsiblesInSet.not( ".ui-collapsible" ) );
  4429. // clean up borders
  4430. if ( !!o.inset ) {
  4431. collapsiblesInSet.each(function() {
  4432. $( this ).jqmRemoveData( "collapsible-last" )
  4433. .find( ".ui-collapsible-heading" )
  4434. .find( "a" ).first()
  4435. .removeClass( "ui-corner-top ui-corner-bottom" )
  4436. .find( ".ui-btn-inner" )
  4437. .removeClass( "ui-corner-top ui-corner-bottom" );
  4438. });
  4439. collapsiblesInSet.first()
  4440. .find( "a" )
  4441. .first()
  4442. .addClass( "ui-corner-top" )
  4443. .find( ".ui-btn-inner" )
  4444. .addClass( "ui-corner-top" );
  4445. collapsiblesInSet.last()
  4446. .jqmData( "collapsible-last", true )
  4447. .find( "a" )
  4448. .first()
  4449. .addClass( "ui-corner-bottom" )
  4450. .find( ".ui-btn-inner" )
  4451. .addClass( "ui-corner-bottom" );
  4452. }
  4453. }
  4454. });
  4455. //auto self-init widgets
  4456. $( document ).bind( "pagecreate create", function( e ) {
  4457. $.mobile.collapsibleset.prototype.enhanceWithin( e.target );
  4458. });
  4459. })( jQuery );
  4460. (function( $, undefined ) {
  4461. $.widget( "mobile.navbar", $.mobile.widget, {
  4462. options: {
  4463. iconpos: "top",
  4464. grid: null,
  4465. initSelector: ":jqmData(role='navbar')"
  4466. },
  4467. _create: function() {
  4468. var $navbar = this.element,
  4469. $navbtns = $navbar.find( "a" ),
  4470. iconpos = $navbtns.filter( ":jqmData(icon)" ).length ?
  4471. this.options.iconpos : undefined;
  4472. $navbar.addClass( "ui-navbar ui-mini" )
  4473. .attr( "role", "navigation" )
  4474. .find( "ul" )
  4475. .jqmEnhanceable()
  4476. .grid({ grid: this.options.grid });
  4477. $navbtns.buttonMarkup({
  4478. corners: false,
  4479. shadow: false,
  4480. inline: true,
  4481. iconpos: iconpos
  4482. });
  4483. $navbar.delegate( "a", "vclick", function( event ) {
  4484. if ( !$(event.target).hasClass( "ui-disabled" ) ) {
  4485. $navbtns.removeClass( $.mobile.activeBtnClass );
  4486. $( this ).addClass( $.mobile.activeBtnClass );
  4487. }
  4488. });
  4489. // Buttons in the navbar with ui-state-persist class should regain their active state before page show
  4490. $navbar.closest( ".ui-page" ).bind( "pagebeforeshow", function() {
  4491. $navbtns.filter( ".ui-state-persist" ).addClass( $.mobile.activeBtnClass );
  4492. });
  4493. }
  4494. });
  4495. //auto self-init widgets
  4496. $( document ).bind( "pagecreate create", function( e ) {
  4497. $.mobile.navbar.prototype.enhanceWithin( e.target );
  4498. });
  4499. })( jQuery );
  4500. (function( $, undefined ) {
  4501. //Keeps track of the number of lists per page UID
  4502. //This allows support for multiple nested list in the same page
  4503. //https://github.com/jquery/jquery-mobile/issues/1617
  4504. var listCountPerPage = {};
  4505. $.widget( "mobile.listview", $.mobile.widget, {
  4506. options: {
  4507. theme: null,
  4508. countTheme: "c",
  4509. headerTheme: "b",
  4510. dividerTheme: "b",
  4511. splitIcon: "arrow-r",
  4512. splitTheme: "b",
  4513. inset: false,
  4514. initSelector: ":jqmData(role='listview')"
  4515. },
  4516. _create: function() {
  4517. var t = this,
  4518. listviewClasses = "";
  4519. listviewClasses += t.options.inset ? " ui-listview-inset ui-corner-all ui-shadow " : "";
  4520. // create listview markup
  4521. t.element.addClass(function( i, orig ) {
  4522. return orig + " ui-listview " + listviewClasses;
  4523. });
  4524. t.refresh( true );
  4525. },
  4526. _removeCorners: function( li, which ) {
  4527. var top = "ui-corner-top ui-corner-tr ui-corner-tl",
  4528. bot = "ui-corner-bottom ui-corner-br ui-corner-bl";
  4529. li = li.add( li.find( ".ui-btn-inner, .ui-li-link-alt, .ui-li-thumb" ) );
  4530. if ( which === "top" ) {
  4531. li.removeClass( top );
  4532. } else if ( which === "bottom" ) {
  4533. li.removeClass( bot );
  4534. } else {
  4535. li.removeClass( top + " " + bot );
  4536. }
  4537. },
  4538. _refreshCorners: function( create ) {
  4539. var $li,
  4540. $visibleli,
  4541. $topli,
  4542. $bottomli;
  4543. $li = this.element.children( "li" );
  4544. // At create time and when autodividers calls refresh the li are not visible yet so we need to rely on .ui-screen-hidden
  4545. $visibleli = create || $li.filter( ":visible" ).length === 0 ? $li.not( ".ui-screen-hidden" ) : $li.filter( ":visible" );
  4546. // ui-li-last is used for setting border-bottom on the last li
  4547. $li.filter( ".ui-li-last" ).removeClass( "ui-li-last" );
  4548. if ( this.options.inset ) {
  4549. this._removeCorners( $li );
  4550. // Select the first visible li element
  4551. $topli = $visibleli.first()
  4552. .addClass( "ui-corner-top" );
  4553. $topli.add( $topli.find( ".ui-btn-inner" )
  4554. .not( ".ui-li-link-alt span:first-child" ) )
  4555. .addClass( "ui-corner-top" )
  4556. .end()
  4557. .find( ".ui-li-link-alt, .ui-li-link-alt span:first-child" )
  4558. .addClass( "ui-corner-tr" )
  4559. .end()
  4560. .find( ".ui-li-thumb" )
  4561. .not( ".ui-li-icon" )
  4562. .addClass( "ui-corner-tl" );
  4563. // Select the last visible li element
  4564. $bottomli = $visibleli.last()
  4565. .addClass( "ui-corner-bottom ui-li-last" );
  4566. $bottomli.add( $bottomli.find( ".ui-btn-inner" ) )
  4567. .find( ".ui-li-link-alt" )
  4568. .addClass( "ui-corner-br" )
  4569. .end()
  4570. .find( ".ui-li-thumb" )
  4571. .not( ".ui-li-icon" )
  4572. .addClass( "ui-corner-bl" );
  4573. } else {
  4574. $visibleli.last().addClass( "ui-li-last" );
  4575. }
  4576. if ( !create ) {
  4577. this.element.trigger( "updatelayout" );
  4578. }
  4579. },
  4580. // This is a generic utility method for finding the first
  4581. // node with a given nodeName. It uses basic DOM traversal
  4582. // to be fast and is meant to be a substitute for simple
  4583. // $.fn.closest() and $.fn.children() calls on a single
  4584. // element. Note that callers must pass both the lowerCase
  4585. // and upperCase version of the nodeName they are looking for.
  4586. // The main reason for this is that this function will be
  4587. // called many times and we want to avoid having to lowercase
  4588. // the nodeName from the element every time to ensure we have
  4589. // a match. Note that this function lives here for now, but may
  4590. // be moved into $.mobile if other components need a similar method.
  4591. _findFirstElementByTagName: function( ele, nextProp, lcName, ucName ) {
  4592. var dict = {};
  4593. dict[ lcName ] = dict[ ucName ] = true;
  4594. while ( ele ) {
  4595. if ( dict[ ele.nodeName ] ) {
  4596. return ele;
  4597. }
  4598. ele = ele[ nextProp ];
  4599. }
  4600. return null;
  4601. },
  4602. _getChildrenByTagName: function( ele, lcName, ucName ) {
  4603. var results = [],
  4604. dict = {};
  4605. dict[ lcName ] = dict[ ucName ] = true;
  4606. ele = ele.firstChild;
  4607. while ( ele ) {
  4608. if ( dict[ ele.nodeName ] ) {
  4609. results.push( ele );
  4610. }
  4611. ele = ele.nextSibling;
  4612. }
  4613. return $( results );
  4614. },
  4615. _addThumbClasses: function( containers ) {
  4616. var i, img, len = containers.length;
  4617. for ( i = 0; i < len; i++ ) {
  4618. img = $( this._findFirstElementByTagName( containers[ i ].firstChild, "nextSibling", "img", "IMG" ) );
  4619. if ( img.length ) {
  4620. img.addClass( "ui-li-thumb" );
  4621. $( this._findFirstElementByTagName( img[ 0 ].parentNode, "parentNode", "li", "LI" ) ).addClass( img.is( ".ui-li-icon" ) ? "ui-li-has-icon" : "ui-li-has-thumb" );
  4622. }
  4623. }
  4624. },
  4625. refresh: function( create ) {
  4626. this.parentPage = this.element.closest( ".ui-page" );
  4627. this._createSubPages();
  4628. var o = this.options,
  4629. $list = this.element,
  4630. self = this,
  4631. dividertheme = $list.jqmData( "dividertheme" ) || o.dividerTheme,
  4632. listsplittheme = $list.jqmData( "splittheme" ),
  4633. listspliticon = $list.jqmData( "spliticon" ),
  4634. li = this._getChildrenByTagName( $list[ 0 ], "li", "LI" ),
  4635. ol = !!$.nodeName( $list[ 0 ], "ol" ),
  4636. jsCount = !$.support.cssPseudoElement,
  4637. start = $list.attr( "start" ),
  4638. itemClassDict = {},
  4639. item, itemClass, itemTheme,
  4640. a, last, splittheme, counter, startCount, newStartCount, countParent, icon, imgParents, img, linkIcon;
  4641. if ( ol && jsCount ) {
  4642. $list.find( ".ui-li-dec" ).remove();
  4643. }
  4644. if ( ol ) {
  4645. // Check if a start attribute has been set while taking a value of 0 into account
  4646. if ( start || start === 0 ) {
  4647. if ( !jsCount ) {
  4648. startCount = parseFloat( start ) - 1;
  4649. $list.css( "counter-reset", "listnumbering " + startCount );
  4650. } else {
  4651. counter = parseFloat( start );
  4652. }
  4653. } else if ( jsCount ) {
  4654. counter = 1;
  4655. }
  4656. }
  4657. if ( !o.theme ) {
  4658. o.theme = $.mobile.getInheritedTheme( this.element, "c" );
  4659. }
  4660. for ( var pos = 0, numli = li.length; pos < numli; pos++ ) {
  4661. item = li.eq( pos );
  4662. itemClass = "ui-li";
  4663. // If we're creating the element, we update it regardless
  4664. if ( create || !item.hasClass( "ui-li" ) ) {
  4665. itemTheme = item.jqmData( "theme" ) || o.theme;
  4666. a = this._getChildrenByTagName( item[ 0 ], "a", "A" );
  4667. var isDivider = ( item.jqmData( "role" ) === "list-divider" );
  4668. if ( a.length && !isDivider ) {
  4669. icon = item.jqmData( "icon" );
  4670. item.buttonMarkup({
  4671. wrapperEls: "div",
  4672. shadow: false,
  4673. corners: false,
  4674. iconpos: "right",
  4675. icon: a.length > 1 || icon === false ? false : icon || "arrow-r",
  4676. theme: itemTheme
  4677. });
  4678. if ( ( icon !== false ) && ( a.length === 1 ) ) {
  4679. item.addClass( "ui-li-has-arrow" );
  4680. }
  4681. a.first().removeClass( "ui-link" ).addClass( "ui-link-inherit" );
  4682. if ( a.length > 1 ) {
  4683. itemClass += " ui-li-has-alt";
  4684. last = a.last();
  4685. splittheme = listsplittheme || last.jqmData( "theme" ) || o.splitTheme;
  4686. linkIcon = last.jqmData( "icon" );
  4687. last.appendTo( item )
  4688. .attr( "title", last.getEncodedText() )
  4689. .addClass( "ui-li-link-alt" )
  4690. .empty()
  4691. .buttonMarkup({
  4692. shadow: false,
  4693. corners: false,
  4694. theme: itemTheme,
  4695. icon: false,
  4696. iconpos: "notext"
  4697. })
  4698. .find( ".ui-btn-inner" )
  4699. .append(
  4700. $( document.createElement( "span" ) ).buttonMarkup({
  4701. shadow: true,
  4702. corners: true,
  4703. theme: splittheme,
  4704. iconpos: "notext",
  4705. // link icon overrides list item icon overrides ul element overrides options
  4706. icon: linkIcon || icon || listspliticon || o.splitIcon
  4707. })
  4708. );
  4709. }
  4710. } else if ( isDivider ) {
  4711. itemClass += " ui-li-divider ui-bar-" + dividertheme;
  4712. item.attr( "role", "heading" );
  4713. if ( ol ) {
  4714. //reset counter when a divider heading is encountered
  4715. if ( start || start === 0 ) {
  4716. if ( !jsCount ) {
  4717. newStartCount = parseFloat( start ) - 1;
  4718. item.css( "counter-reset", "listnumbering " + newStartCount );
  4719. } else {
  4720. counter = parseFloat( start );
  4721. }
  4722. } else if ( jsCount ) {
  4723. counter = 1;
  4724. }
  4725. }
  4726. } else {
  4727. itemClass += " ui-li-static ui-btn-up-" + itemTheme;
  4728. }
  4729. }
  4730. if ( ol && jsCount && itemClass.indexOf( "ui-li-divider" ) < 0 ) {
  4731. countParent = itemClass.indexOf( "ui-li-static" ) > 0 ? item : item.find( ".ui-link-inherit" );
  4732. countParent.addClass( "ui-li-jsnumbering" )
  4733. .prepend( "<span class='ui-li-dec'>" + ( counter++ ) + ". </span>" );
  4734. }
  4735. // Instead of setting item class directly on the list item and its
  4736. // btn-inner at this point in time, push the item into a dictionary
  4737. // that tells us what class to set on it so we can do this after this
  4738. // processing loop is finished.
  4739. if ( !itemClassDict[ itemClass ] ) {
  4740. itemClassDict[ itemClass ] = [];
  4741. }
  4742. itemClassDict[ itemClass ].push( item[ 0 ] );
  4743. }
  4744. // Set the appropriate listview item classes on each list item
  4745. // and their btn-inner elements. The main reason we didn't do this
  4746. // in the for-loop above is because we can eliminate per-item function overhead
  4747. // by calling addClass() and children() once or twice afterwards. This
  4748. // can give us a significant boost on platforms like WP7.5.
  4749. for ( itemClass in itemClassDict ) {
  4750. $( itemClassDict[ itemClass ] ).addClass( itemClass ).children( ".ui-btn-inner" ).addClass( itemClass );
  4751. }
  4752. $list.find( "h1, h2, h3, h4, h5, h6" ).addClass( "ui-li-heading" )
  4753. .end()
  4754. .find( "p, dl" ).addClass( "ui-li-desc" )
  4755. .end()
  4756. .find( ".ui-li-aside" ).each(function() {
  4757. var $this = $( this );
  4758. $this.prependTo( $this.parent() ); //shift aside to front for css float
  4759. })
  4760. .end()
  4761. .find( ".ui-li-count" ).each(function() {
  4762. $( this ).closest( "li" ).addClass( "ui-li-has-count" );
  4763. }).addClass( "ui-btn-up-" + ( $list.jqmData( "counttheme" ) || this.options.countTheme) + " ui-btn-corner-all" );
  4764. // The idea here is to look at the first image in the list item
  4765. // itself, and any .ui-link-inherit element it may contain, so we
  4766. // can place the appropriate classes on the image and list item.
  4767. // Note that we used to use something like:
  4768. //
  4769. // li.find(">img:eq(0), .ui-link-inherit>img:eq(0)").each( ... );
  4770. //
  4771. // But executing a find() like that on Windows Phone 7.5 took a
  4772. // really long time. Walking things manually with the code below
  4773. // allows the 400 listview item page to load in about 3 seconds as
  4774. // opposed to 30 seconds.
  4775. this._addThumbClasses( li );
  4776. this._addThumbClasses( $list.find( ".ui-link-inherit" ) );
  4777. this._refreshCorners( create );
  4778. // autodividers binds to this to redraw dividers after the listview refresh
  4779. this._trigger( "afterrefresh" );
  4780. },
  4781. //create a string for ID/subpage url creation
  4782. _idStringEscape: function( str ) {
  4783. return str.replace(/[^a-zA-Z0-9]/g, '-');
  4784. },
  4785. _createSubPages: function() {
  4786. var parentList = this.element,
  4787. parentPage = parentList.closest( ".ui-page" ),
  4788. parentUrl = parentPage.jqmData( "url" ),
  4789. parentId = parentUrl || parentPage[ 0 ][ $.expando ],
  4790. parentListId = parentList.attr( "id" ),
  4791. o = this.options,
  4792. dns = "data-" + $.mobile.ns,
  4793. self = this,
  4794. persistentFooterID = parentPage.find( ":jqmData(role='footer')" ).jqmData( "id" ),
  4795. hasSubPages;
  4796. if ( typeof listCountPerPage[ parentId ] === "undefined" ) {
  4797. listCountPerPage[ parentId ] = -1;
  4798. }
  4799. parentListId = parentListId || ++listCountPerPage[ parentId ];
  4800. $( parentList.find( "li>ul, li>ol" ).toArray().reverse() ).each(function( i ) {
  4801. var self = this,
  4802. list = $( this ),
  4803. listId = list.attr( "id" ) || parentListId + "-" + i,
  4804. parent = list.parent(),
  4805. nodeElsFull = $( list.prevAll().toArray().reverse() ),
  4806. nodeEls = nodeElsFull.length ? nodeElsFull : $( "<span>" + $.trim(parent.contents()[ 0 ].nodeValue) + "</span>" ),
  4807. title = nodeEls.first().getEncodedText(),//url limits to first 30 chars of text
  4808. id = ( parentUrl || "" ) + "&" + $.mobile.subPageUrlKey + "=" + listId,
  4809. theme = list.jqmData( "theme" ) || o.theme,
  4810. countTheme = list.jqmData( "counttheme" ) || parentList.jqmData( "counttheme" ) || o.countTheme,
  4811. newPage, anchor;
  4812. //define hasSubPages for use in later removal
  4813. hasSubPages = true;
  4814. newPage = list.detach()
  4815. .wrap( "<div " + dns + "role='page' " + dns + "url='" + id + "' " + dns + "theme='" + theme + "' " + dns + "count-theme='" + countTheme + "'><div " + dns + "role='content'></div></div>" )
  4816. .parent()
  4817. .before( "<div " + dns + "role='header' " + dns + "theme='" + o.headerTheme + "'><div class='ui-title'>" + title + "</div></div>" )
  4818. .after( persistentFooterID ? $( "<div " + dns + "role='footer' " + dns + "id='"+ persistentFooterID +"'>" ) : "" )
  4819. .parent()
  4820. .appendTo( $.mobile.pageContainer );
  4821. newPage.page();
  4822. anchor = parent.find( 'a:first' );
  4823. if ( !anchor.length ) {
  4824. anchor = $( "<a/>" ).html( nodeEls || title ).prependTo( parent.empty() );
  4825. }
  4826. anchor.attr( "href", "#" + id );
  4827. }).listview();
  4828. // on pagehide, remove any nested pages along with the parent page, as long as they aren't active
  4829. // and aren't embedded
  4830. if ( hasSubPages &&
  4831. parentPage.is( ":jqmData(external-page='true')" ) &&
  4832. parentPage.data( "page" ).options.domCache === false ) {
  4833. var newRemove = function( e, ui ) {
  4834. var nextPage = ui.nextPage, npURL,
  4835. prEvent = new $.Event( "pageremove" );
  4836. if ( ui.nextPage ) {
  4837. npURL = nextPage.jqmData( "url" );
  4838. if ( npURL.indexOf( parentUrl + "&" + $.mobile.subPageUrlKey ) !== 0 ) {
  4839. self.childPages().remove();
  4840. parentPage.trigger( prEvent );
  4841. if ( !prEvent.isDefaultPrevented() ) {
  4842. parentPage.removeWithDependents();
  4843. }
  4844. }
  4845. }
  4846. };
  4847. // unbind the original page remove and replace with our specialized version
  4848. parentPage
  4849. .unbind( "pagehide.remove" )
  4850. .bind( "pagehide.remove", newRemove);
  4851. }
  4852. },
  4853. // TODO sort out a better way to track sub pages of the listview this is brittle
  4854. childPages: function() {
  4855. var parentUrl = this.parentPage.jqmData( "url" );
  4856. return $( ":jqmData(url^='"+ parentUrl + "&" + $.mobile.subPageUrlKey + "')" );
  4857. }
  4858. });
  4859. //auto self-init widgets
  4860. $( document ).bind( "pagecreate create", function( e ) {
  4861. $.mobile.listview.prototype.enhanceWithin( e.target );
  4862. });
  4863. })( jQuery );
  4864. (function( $, undefined ) {
  4865. $.mobile.listview.prototype.options.autodividers = false;
  4866. $.mobile.listview.prototype.options.autodividersSelector = function( elt ) {
  4867. // look for the text in the given element
  4868. var text = elt.text() || null;
  4869. if ( !text ) {
  4870. return null;
  4871. }
  4872. // create the text for the divider (first uppercased letter)
  4873. text = text.slice( 0, 1 ).toUpperCase();
  4874. return text;
  4875. };
  4876. $( document ).delegate( "ul,ol", "listviewcreate", function() {
  4877. var list = $( this ),
  4878. listview = list.data( "listview" );
  4879. if ( !listview || !listview.options.autodividers ) {
  4880. return;
  4881. }
  4882. var replaceDividers = function () {
  4883. list.find( "li:jqmData(role='list-divider')" ).remove();
  4884. var lis = list.find( 'li' ),
  4885. lastDividerText = null, li, dividerText;
  4886. for ( var i = 0; i < lis.length ; i++ ) {
  4887. li = lis[i];
  4888. dividerText = listview.options.autodividersSelector( $( li ) );
  4889. if ( dividerText && lastDividerText !== dividerText ) {
  4890. var divider = document.createElement( 'li' );
  4891. divider.appendChild( document.createTextNode( dividerText ) );
  4892. divider.setAttribute( 'data-' + $.mobile.ns + 'role', 'list-divider' );
  4893. li.parentNode.insertBefore( divider, li );
  4894. }
  4895. lastDividerText = dividerText;
  4896. }
  4897. };
  4898. var afterListviewRefresh = function () {
  4899. list.unbind( 'listviewafterrefresh', afterListviewRefresh );
  4900. replaceDividers();
  4901. listview.refresh();
  4902. list.bind( 'listviewafterrefresh', afterListviewRefresh );
  4903. };
  4904. afterListviewRefresh();
  4905. });
  4906. })( jQuery );
  4907. /*
  4908. * "checkboxradio" plugin
  4909. */
  4910. (function( $, undefined ) {
  4911. $.widget( "mobile.checkboxradio", $.mobile.widget, {
  4912. options: {
  4913. theme: null,
  4914. initSelector: "input[type='checkbox'],input[type='radio']"
  4915. },
  4916. _create: function() {
  4917. var self = this,
  4918. input = this.element,
  4919. inheritAttr = function( input, dataAttr ) {
  4920. return input.jqmData( dataAttr ) || input.closest( "form, fieldset" ).jqmData( dataAttr );
  4921. },
  4922. // NOTE: Windows Phone could not find the label through a selector
  4923. // filter works though.
  4924. parentLabel = $( input ).closest( "label" ),
  4925. label = parentLabel.length ? parentLabel : $( input ).closest( "form, fieldset, :jqmData(role='page'), :jqmData(role='dialog')" ).find( "label" ).filter( "[for='" + input[0].id + "']" ).first(),
  4926. inputtype = input[0].type,
  4927. mini = inheritAttr( input, "mini" ),
  4928. checkedState = inputtype + "-on",
  4929. uncheckedState = inputtype + "-off",
  4930. icon = input.parents( ":jqmData(type='horizontal')" ).length ? undefined : uncheckedState,
  4931. iconpos = inheritAttr( input, "iconpos" ),
  4932. activeBtn = icon ? "" : " " + $.mobile.activeBtnClass,
  4933. checkedClass = "ui-" + checkedState + activeBtn,
  4934. uncheckedClass = "ui-" + uncheckedState,
  4935. checkedicon = "ui-icon-" + checkedState,
  4936. uncheckedicon = "ui-icon-" + uncheckedState;
  4937. if ( inputtype !== "checkbox" && inputtype !== "radio" ) {
  4938. return;
  4939. }
  4940. // Expose for other methods
  4941. $.extend( this, {
  4942. label: label,
  4943. inputtype: inputtype,
  4944. checkedClass: checkedClass,
  4945. uncheckedClass: uncheckedClass,
  4946. checkedicon: checkedicon,
  4947. uncheckedicon: uncheckedicon
  4948. });
  4949. // If there's no selected theme check the data attr
  4950. if ( !this.options.theme ) {
  4951. this.options.theme = $.mobile.getInheritedTheme( this.element, "c" );
  4952. }
  4953. label.buttonMarkup({
  4954. theme: this.options.theme,
  4955. icon: icon,
  4956. shadow: false,
  4957. mini: mini,
  4958. iconpos: iconpos
  4959. });
  4960. // Wrap the input + label in a div
  4961. var wrapper = document.createElement('div');
  4962. wrapper.className = 'ui-' + inputtype;
  4963. input.add( label ).wrapAll( wrapper );
  4964. label.bind({
  4965. vmouseover: function( event ) {
  4966. if ( $( this ).parent().is( ".ui-disabled" ) ) {
  4967. event.stopPropagation();
  4968. }
  4969. },
  4970. vclick: function( event ) {
  4971. if ( input.is( ":disabled" ) ) {
  4972. event.preventDefault();
  4973. return;
  4974. }
  4975. self._cacheVals();
  4976. input.prop( "checked", inputtype === "radio" && true || !input.prop( "checked" ) );
  4977. // trigger click handler's bound directly to the input as a substitute for
  4978. // how label clicks behave normally in the browsers
  4979. // TODO: it would be nice to let the browser's handle the clicks and pass them
  4980. // through to the associate input. we can swallow that click at the parent
  4981. // wrapper element level
  4982. input.triggerHandler( 'click' );
  4983. // Input set for common radio buttons will contain all the radio
  4984. // buttons, but will not for checkboxes. clearing the checked status
  4985. // of other radios ensures the active button state is applied properly
  4986. self._getInputSet().not( input ).prop( "checked", false );
  4987. self._updateAll();
  4988. return false;
  4989. }
  4990. });
  4991. input
  4992. .bind({
  4993. vmousedown: function() {
  4994. self._cacheVals();
  4995. },
  4996. vclick: function() {
  4997. var $this = $( this );
  4998. // Adds checked attribute to checked input when keyboard is used
  4999. if ( $this.is( ":checked" ) ) {
  5000. $this.prop( "checked", true);
  5001. self._getInputSet().not( $this ).prop( "checked", false );
  5002. } else {
  5003. $this.prop( "checked", false );
  5004. }
  5005. self._updateAll();
  5006. },
  5007. focus: function() {
  5008. label.addClass( $.mobile.focusClass );
  5009. },
  5010. blur: function() {
  5011. label.removeClass( $.mobile.focusClass );
  5012. }
  5013. });
  5014. this.refresh();
  5015. },
  5016. _cacheVals: function() {
  5017. this._getInputSet().each(function() {
  5018. $( this ).jqmData( "cacheVal", this.checked );
  5019. });
  5020. },
  5021. //returns either a set of radios with the same name attribute, or a single checkbox
  5022. _getInputSet: function() {
  5023. if ( this.inputtype === "checkbox" ) {
  5024. return this.element;
  5025. }
  5026. return this.element.closest( "form, fieldset, :jqmData(role='page'), :jqmData(role='dialog')" )
  5027. .find( "input[name='" + this.element[0].name + "'][type='" + this.inputtype + "']" );
  5028. },
  5029. _updateAll: function() {
  5030. var self = this;
  5031. this._getInputSet().each(function() {
  5032. var $this = $( this );
  5033. if ( this.checked || self.inputtype === "checkbox" ) {
  5034. $this.trigger( "change" );
  5035. }
  5036. })
  5037. .checkboxradio( "refresh" );
  5038. },
  5039. refresh: function() {
  5040. var input = this.element[0],
  5041. label = this.label,
  5042. icon = label.find( ".ui-icon" );
  5043. if ( input.checked ) {
  5044. label.addClass( this.checkedClass ).removeClass( this.uncheckedClass );
  5045. icon.addClass( this.checkedicon ).removeClass( this.uncheckedicon );
  5046. } else {
  5047. label.removeClass( this.checkedClass ).addClass( this.uncheckedClass );
  5048. icon.removeClass( this.checkedicon ).addClass( this.uncheckedicon );
  5049. }
  5050. if ( input.disabled ) {
  5051. this.disable();
  5052. } else {
  5053. this.enable();
  5054. }
  5055. },
  5056. disable: function() {
  5057. this.element.prop( "disabled", true ).parent().addClass( "ui-disabled" );
  5058. },
  5059. enable: function() {
  5060. this.element.prop( "disabled", false ).parent().removeClass( "ui-disabled" );
  5061. }
  5062. });
  5063. //auto self-init widgets
  5064. $( document ).bind( "pagecreate create", function( e ) {
  5065. $.mobile.checkboxradio.prototype.enhanceWithin( e.target, true );
  5066. });
  5067. })( jQuery );
  5068. (function( $, undefined ) {
  5069. $.widget( "mobile.button", $.mobile.widget, {
  5070. options: {
  5071. theme: null,
  5072. icon: null,
  5073. iconpos: null,
  5074. corners: true,
  5075. shadow: true,
  5076. iconshadow: true,
  5077. initSelector: "button, [type='button'], [type='submit'], [type='reset']"
  5078. },
  5079. _create: function() {
  5080. var $el = this.element,
  5081. $button,
  5082. o = this.options,
  5083. type,
  5084. name,
  5085. inline = o.inline || $el.jqmData( "inline" ),
  5086. mini = o.mini || $el.jqmData( "mini" ),
  5087. classes = "",
  5088. $buttonPlaceholder;
  5089. // if this is a link, check if it's been enhanced and, if not, use the right function
  5090. if ( $el[ 0 ].tagName === "A" ) {
  5091. if ( !$el.hasClass( "ui-btn" ) ) {
  5092. $el.buttonMarkup();
  5093. }
  5094. return;
  5095. }
  5096. // get the inherited theme
  5097. // TODO centralize for all widgets
  5098. if ( !this.options.theme ) {
  5099. this.options.theme = $.mobile.getInheritedTheme( this.element, "c" );
  5100. }
  5101. // TODO: Post 1.1--once we have time to test thoroughly--any classes manually applied to the original element should be carried over to the enhanced element, with an `-enhanced` suffix. See https://github.com/jquery/jquery-mobile/issues/3577
  5102. /* if ( $el[0].className.length ) {
  5103. classes = $el[0].className;
  5104. } */
  5105. if ( !!~$el[0].className.indexOf( "ui-btn-left" ) ) {
  5106. classes = "ui-btn-left";
  5107. }
  5108. if ( !!~$el[0].className.indexOf( "ui-btn-right" ) ) {
  5109. classes = "ui-btn-right";
  5110. }
  5111. if ( $el.attr( "type" ) === "submit" || $el.attr( "type" ) === "reset" ) {
  5112. classes ? classes += " ui-submit" : classes = "ui-submit";
  5113. }
  5114. $( "label[for='" + $el.attr( "id" ) + "']" ).addClass( "ui-submit" );
  5115. // Add ARIA role
  5116. this.button = $( "<div></div>" )
  5117. [ $el.html() ? "html" : "text" ]( $el.html() || $el.val() )
  5118. .insertBefore( $el )
  5119. .buttonMarkup({
  5120. theme: o.theme,
  5121. icon: o.icon,
  5122. iconpos: o.iconpos,
  5123. inline: inline,
  5124. corners: o.corners,
  5125. shadow: o.shadow,
  5126. iconshadow: o.iconshadow,
  5127. mini: mini
  5128. })
  5129. .addClass( classes )
  5130. .append( $el.addClass( "ui-btn-hidden" ) );
  5131. $button = this.button;
  5132. type = $el.attr( "type" );
  5133. name = $el.attr( "name" );
  5134. // Add hidden input during submit if input type="submit" has a name.
  5135. if ( type !== "button" && type !== "reset" && name ) {
  5136. $el.bind( "vclick", function() {
  5137. // Add hidden input if it doesn't already exist.
  5138. if ( $buttonPlaceholder === undefined ) {
  5139. $buttonPlaceholder = $( "<input>", {
  5140. type: "hidden",
  5141. name: $el.attr( "name" ),
  5142. value: $el.attr( "value" )
  5143. }).insertBefore( $el );
  5144. // Bind to doc to remove after submit handling
  5145. $( document ).one( "submit", function() {
  5146. $buttonPlaceholder.remove();
  5147. // reset the local var so that the hidden input
  5148. // will be re-added on subsequent clicks
  5149. $buttonPlaceholder = undefined;
  5150. });
  5151. }
  5152. });
  5153. }
  5154. $el.bind({
  5155. focus: function() {
  5156. $button.addClass( $.mobile.focusClass );
  5157. },
  5158. blur: function() {
  5159. $button.removeClass( $.mobile.focusClass );
  5160. }
  5161. });
  5162. this.refresh();
  5163. },
  5164. enable: function() {
  5165. this.element.attr( "disabled", false );
  5166. this.button.removeClass( "ui-disabled" ).attr( "aria-disabled", false );
  5167. return this._setOption( "disabled", false );
  5168. },
  5169. disable: function() {
  5170. this.element.attr( "disabled", true );
  5171. this.button.addClass( "ui-disabled" ).attr( "aria-disabled", true );
  5172. return this._setOption( "disabled", true );
  5173. },
  5174. refresh: function() {
  5175. var $el = this.element;
  5176. if ( $el.prop("disabled") ) {
  5177. this.disable();
  5178. } else {
  5179. this.enable();
  5180. }
  5181. // Grab the button's text element from its implementation-independent data item
  5182. $( this.button.data( 'buttonElements' ).text )[ $el.html() ? "html" : "text" ]( $el.html() || $el.val() );
  5183. }
  5184. });
  5185. //auto self-init widgets
  5186. $( document ).bind( "pagecreate create", function( e ) {
  5187. $.mobile.button.prototype.enhanceWithin( e.target, true );
  5188. });
  5189. })( jQuery );
  5190. (function( $, undefined ) {
  5191. $.fn.controlgroup = function( options ) {
  5192. function flipClasses( els, flCorners ) {
  5193. els.removeClass( "ui-btn-corner-all ui-corner-top ui-corner-bottom ui-corner-left ui-corner-right ui-controlgroup-last ui-shadow" )
  5194. .eq( 0 ).addClass( flCorners[ 0 ] )
  5195. .end()
  5196. .last().addClass( flCorners[ 1 ] ).addClass( "ui-controlgroup-last" );
  5197. }
  5198. return this.each(function() {
  5199. var $el = $( this ),
  5200. o = $.extend({
  5201. direction: $el.jqmData( "type" ) || "vertical",
  5202. shadow: false,
  5203. excludeInvisible: true,
  5204. mini: $el.jqmData( "mini" )
  5205. }, options ),
  5206. grouplegend = $el.children( "legend" ),
  5207. groupheading = $el.children( ".ui-controlgroup-label" ),
  5208. groupcontrols = $el.children( ".ui-controlgroup-controls" ),
  5209. flCorners = o.direction === "horizontal" ? [ "ui-corner-left", "ui-corner-right" ] : [ "ui-corner-top", "ui-corner-bottom" ],
  5210. type = $el.find( "input" ).first().attr( "type" );
  5211. // First unwrap the controls if the controlgroup was already enhanced
  5212. if ( groupcontrols.length ) {
  5213. groupcontrols.contents().unwrap();
  5214. }
  5215. $el.wrapInner( "<div class='ui-controlgroup-controls'></div>" );
  5216. if ( grouplegend.length ) {
  5217. // Replace legend with more stylable replacement div
  5218. $( "<div role='heading' class='ui-controlgroup-label'>" + grouplegend.html() + "</div>" ).insertBefore( $el.children( 0 ) );
  5219. grouplegend.remove();
  5220. } else if ( groupheading.length ) {
  5221. // Just move the heading if the controlgroup was already enhanced
  5222. $el.prepend( groupheading );
  5223. }
  5224. $el.addClass( "ui-corner-all ui-controlgroup ui-controlgroup-" + o.direction );
  5225. flipClasses( $el.find( ".ui-btn" + ( o.excludeInvisible ? ":visible" : "" ) ).not( '.ui-slider-handle' ), flCorners );
  5226. flipClasses( $el.find( ".ui-btn-inner" ), flCorners );
  5227. if ( o.shadow ) {
  5228. $el.addClass( "ui-shadow" );
  5229. }
  5230. if ( o.mini ) {
  5231. $el.addClass( "ui-mini" );
  5232. }
  5233. });
  5234. };
  5235. // The pagecreate handler for controlgroup is in jquery.mobile.init because of the soft-dependency on the wrapped widgets
  5236. })(jQuery);
  5237. (function( $, undefined ) {
  5238. $( document ).bind( "pagecreate create", function( e ) {
  5239. //links within content areas, tests included with page
  5240. $( e.target )
  5241. .find( "a" )
  5242. .jqmEnhanceable()
  5243. .not( ".ui-btn, .ui-link-inherit, :jqmData(role='none'), :jqmData(role='nojs')" )
  5244. .addClass( "ui-link" );
  5245. });
  5246. })( jQuery );
  5247. (function( $, undefined ) {
  5248. function fitSegmentInsideSegment( winSize, segSize, offset, desired ) {
  5249. var ret = desired;
  5250. if ( winSize < segSize ) {
  5251. // Center segment if it's bigger than the window
  5252. ret = offset + ( winSize - segSize ) / 2;
  5253. } else {
  5254. // Otherwise center it at the desired coordinate while keeping it completely inside the window
  5255. ret = Math.min( Math.max( offset, desired - segSize / 2 ), offset + winSize - segSize );
  5256. }
  5257. return ret;
  5258. }
  5259. function windowCoords() {
  5260. var $win = $( window );
  5261. return {
  5262. x: $win.scrollLeft(),
  5263. y: $win.scrollTop(),
  5264. cx: ( window.innerWidth || $win.width() ),
  5265. cy: ( window.innerHeight || $win.height() )
  5266. };
  5267. }
  5268. $.widget( "mobile.popup", $.mobile.widget, {
  5269. options: {
  5270. theme: null,
  5271. overlayTheme: null,
  5272. shadow: true,
  5273. corners: true,
  5274. transition: "none",
  5275. positionTo: "origin",
  5276. tolerance: null,
  5277. initSelector: ":jqmData(role='popup')",
  5278. closeLinkSelector: "a:jqmData(rel='back')",
  5279. closeLinkEvents: "click.popup",
  5280. navigateEvents: "navigate.popup",
  5281. closeEvents: "navigate.popup pagebeforechange.popup",
  5282. // NOTE Windows Phone 7 has a scroll position caching issue that
  5283. // requires us to disable popup history management by default
  5284. // https://github.com/jquery/jquery-mobile/issues/4784
  5285. //
  5286. // NOTE this option is modified in _create!
  5287. history: !$.mobile.browser.ie
  5288. },
  5289. _eatEventAndClose: function( e ) {
  5290. e.preventDefault();
  5291. e.stopImmediatePropagation();
  5292. this.close();
  5293. return false;
  5294. },
  5295. // Make sure the screen size is increased beyond the page height if the popup's causes the document to increase in height
  5296. _resizeScreen: function() {
  5297. var popupHeight = this._ui.container.outerHeight( true );
  5298. this._ui.screen.removeAttr( "style" );
  5299. if ( popupHeight > this._ui.screen.height() ) {
  5300. this._ui.screen.height( popupHeight );
  5301. }
  5302. },
  5303. _handleWindowKeyUp: function( e ) {
  5304. if ( this._isOpen && e.keyCode === $.mobile.keyCode.ESCAPE ) {
  5305. return this._eatEventAndClose( e );
  5306. }
  5307. },
  5308. _maybeRefreshTimeout: function() {
  5309. var winCoords = windowCoords();
  5310. if ( this._resizeData ) {
  5311. if ( winCoords.x === this._resizeData.winCoords.x &&
  5312. winCoords.y === this._resizeData.winCoords.y &&
  5313. winCoords.cx === this._resizeData.winCoords.cx &&
  5314. winCoords.cy === this._resizeData.winCoords.cy ) {
  5315. // timeout not refreshed
  5316. return false;
  5317. } else {
  5318. // clear existing timeout - it will be refreshed below
  5319. clearTimeout( this._resizeData.timeoutId );
  5320. }
  5321. }
  5322. this._resizeData = {
  5323. timeoutId: setTimeout( $.proxy( this, "_resizeTimeout" ), 200 ),
  5324. winCoords: winCoords
  5325. };
  5326. return true;
  5327. },
  5328. _resizeTimeout: function() {
  5329. if ( !this._maybeRefreshTimeout() ) {
  5330. // effectively rapid-open the popup while leaving the screen intact
  5331. this._trigger( "beforeposition" );
  5332. this._ui.container
  5333. .removeClass( "ui-selectmenu-hidden" )
  5334. .offset( this._placementCoords( this._desiredCoords( undefined, undefined, "window" ) ) );
  5335. this._resizeScreen();
  5336. this._resizeData = null;
  5337. this._orientationchangeInProgress = false;
  5338. }
  5339. },
  5340. _handleWindowResize: function( e ) {
  5341. if ( this._isOpen ) {
  5342. this._maybeRefreshTimeout();
  5343. }
  5344. },
  5345. _handleWindowOrientationchange: function( e ) {
  5346. if ( !this._orientationchangeInProgress ) {
  5347. // effectively rapid-close the popup while leaving the screen intact
  5348. this._ui.container
  5349. .addClass( "ui-selectmenu-hidden" )
  5350. .removeAttr( "style" );
  5351. this._orientationchangeInProgress = true;
  5352. }
  5353. },
  5354. _create: function() {
  5355. var ui = {
  5356. screen: $( "<div class='ui-screen-hidden ui-popup-screen'></div>" ),
  5357. placeholder: $( "<div style='display: none;'><!-- placeholder --></div>" ),
  5358. container: $( "<div class='ui-popup-container ui-selectmenu-hidden'></div>" )
  5359. },
  5360. thisPage = this.element.closest( ".ui-page" ),
  5361. myId = this.element.attr( "id" ),
  5362. self = this;
  5363. // We need to adjust the history option to be false if there's no AJAX nav.
  5364. // We can't do it in the option declarations because those are run before
  5365. // it is determined whether there shall be AJAX nav.
  5366. this.options.history = this.options.history && $.mobile.ajaxEnabled && $.mobile.hashListeningEnabled;
  5367. if ( thisPage.length === 0 ) {
  5368. thisPage = $( "body" );
  5369. }
  5370. // define the container for navigation event bindings
  5371. // TODO this would be nice at the the mobile widget level
  5372. this.options.container = this.options.container || $.mobile.pageContainer;
  5373. // Apply the proto
  5374. thisPage.append( ui.screen );
  5375. ui.container.insertAfter( ui.screen );
  5376. // Leave a placeholder where the element used to be
  5377. ui.placeholder.insertAfter( this.element );
  5378. if ( myId ) {
  5379. ui.screen.attr( "id", myId + "-screen" );
  5380. ui.container.attr( "id", myId + "-popup" );
  5381. ui.placeholder.html( "<!-- placeholder for " + myId + " -->" );
  5382. }
  5383. ui.container.append( this.element );
  5384. // Add class to popup element
  5385. this.element.addClass( "ui-popup" );
  5386. // Define instance variables
  5387. $.extend( this, {
  5388. _page: thisPage,
  5389. _ui: ui,
  5390. _fallbackTransition: "",
  5391. _currentTransition: false,
  5392. _prereqs: null,
  5393. _isOpen: false,
  5394. _tolerance: null,
  5395. _resizeData: null,
  5396. _orientationchangeInProgress: false,
  5397. _globalHandlers: [
  5398. {
  5399. src: $( window ),
  5400. handler: {
  5401. orientationchange: $.proxy( this, "_handleWindowOrientationchange" ),
  5402. resize: $.proxy( this, "_handleWindowResize" ),
  5403. keyup: $.proxy( this, "_handleWindowKeyUp" )
  5404. }
  5405. }
  5406. ]
  5407. });
  5408. $.each( this.options, function( key, value ) {
  5409. // Cause initial options to be applied by their handler by temporarily setting the option to undefined
  5410. // - the handler then sets it to the initial value
  5411. self.options[ key ] = undefined;
  5412. self._setOption( key, value, true );
  5413. });
  5414. ui.screen.bind( "vclick", $.proxy( this, "_eatEventAndClose" ) );
  5415. $.each( this._globalHandlers, function( idx, value ) {
  5416. value.src.bind( value.handler );
  5417. });
  5418. },
  5419. _applyTheme: function( dst, theme, prefix ) {
  5420. var classes = ( dst.attr( "class" ) || "").split( " " ),
  5421. alreadyAdded = true,
  5422. currentTheme = null,
  5423. matches,
  5424. themeStr = String( theme );
  5425. while ( classes.length > 0 ) {
  5426. currentTheme = classes.pop();
  5427. matches = ( new RegExp( "^ui-" + prefix + "-([a-z])$" ) ).exec( currentTheme );
  5428. if ( matches && matches.length > 1 ) {
  5429. currentTheme = matches[ 1 ];
  5430. break;
  5431. } else {
  5432. currentTheme = null;
  5433. }
  5434. }
  5435. if ( theme !== currentTheme ) {
  5436. dst.removeClass( "ui-" + prefix + "-" + currentTheme );
  5437. if ( ! ( theme === null || theme === "none" ) ) {
  5438. dst.addClass( "ui-" + prefix + "-" + themeStr );
  5439. }
  5440. }
  5441. },
  5442. _setTheme: function( value ) {
  5443. this._applyTheme( this.element, value, "body" );
  5444. },
  5445. _setOverlayTheme: function( value ) {
  5446. this._applyTheme( this._ui.screen, value, "overlay" );
  5447. if ( this._isOpen ) {
  5448. this._ui.screen.addClass( "in" );
  5449. }
  5450. },
  5451. _setShadow: function( value ) {
  5452. this.element.toggleClass( "ui-overlay-shadow", value );
  5453. },
  5454. _setCorners: function( value ) {
  5455. this.element.toggleClass( "ui-corner-all", value );
  5456. },
  5457. _applyTransition: function( value ) {
  5458. this._ui.container.removeClass( this._fallbackTransition );
  5459. if ( value && value !== "none" ) {
  5460. this._fallbackTransition = $.mobile._maybeDegradeTransition( value );
  5461. this._ui.container.addClass( this._fallbackTransition );
  5462. }
  5463. },
  5464. _setTransition: function( value ) {
  5465. if ( !this._currentTransition ) {
  5466. this._applyTransition( value );
  5467. }
  5468. },
  5469. _setTolerance: function( value ) {
  5470. var tol = { t: 30, r: 15, b: 30, l: 15 };
  5471. if ( value ) {
  5472. var ar = String( value ).split( "," );
  5473. $.each( ar, function( idx, val ) { ar[ idx ] = parseInt( val, 10 ); } );
  5474. switch( ar.length ) {
  5475. // All values are to be the same
  5476. case 1:
  5477. if ( !isNaN( ar[ 0 ] ) ) {
  5478. tol.t = tol.r = tol.b = tol.l = ar[ 0 ];
  5479. }
  5480. break;
  5481. // The first value denotes top/bottom tolerance, and the second value denotes left/right tolerance
  5482. case 2:
  5483. if ( !isNaN( ar[ 0 ] ) ) {
  5484. tol.t = tol.b = ar[ 0 ];
  5485. }
  5486. if ( !isNaN( ar[ 1 ] ) ) {
  5487. tol.l = tol.r = ar[ 1 ];
  5488. }
  5489. break;
  5490. // The array contains values in the order top, right, bottom, left
  5491. case 4:
  5492. if ( !isNaN( ar[ 0 ] ) ) {
  5493. tol.t = ar[ 0 ];
  5494. }
  5495. if ( !isNaN( ar[ 1 ] ) ) {
  5496. tol.r = ar[ 1 ];
  5497. }
  5498. if ( !isNaN( ar[ 2 ] ) ) {
  5499. tol.b = ar[ 2 ];
  5500. }
  5501. if ( !isNaN( ar[ 3 ] ) ) {
  5502. tol.l = ar[ 3 ];
  5503. }
  5504. break;
  5505. default:
  5506. break;
  5507. }
  5508. }
  5509. this._tolerance = tol;
  5510. },
  5511. _setOption: function( key, value ) {
  5512. var exclusions, setter = "_set" + key.charAt( 0 ).toUpperCase() + key.slice( 1 );
  5513. if ( this[ setter ] !== undefined ) {
  5514. this[ setter ]( value );
  5515. }
  5516. // TODO REMOVE FOR 1.2.1 by moving them out to a default options object
  5517. exclusions = [
  5518. "initSelector",
  5519. "closeLinkSelector",
  5520. "closeLinkEvents",
  5521. "navigateEvents",
  5522. "closeEvents",
  5523. "history",
  5524. "container"
  5525. ];
  5526. $.mobile.widget.prototype._setOption.apply( this, arguments );
  5527. if ( $.inArray( key, exclusions ) === -1 ) {
  5528. // Record the option change in the options and in the DOM data-* attributes
  5529. this.element.attr( "data-" + ( $.mobile.ns || "" ) + ( key.replace( /([A-Z])/, "-$1" ).toLowerCase() ), value );
  5530. }
  5531. },
  5532. // Try and center the overlay over the given coordinates
  5533. _placementCoords: function( desired ) {
  5534. // rectangle within which the popup must fit
  5535. var
  5536. winCoords = windowCoords(),
  5537. rc = {
  5538. x: this._tolerance.l,
  5539. y: winCoords.y + this._tolerance.t,
  5540. cx: winCoords.cx - this._tolerance.l - this._tolerance.r,
  5541. cy: winCoords.cy - this._tolerance.t - this._tolerance.b
  5542. },
  5543. menuSize, ret;
  5544. // Clamp the width of the menu before grabbing its size
  5545. this._ui.container.css( "max-width", rc.cx );
  5546. menuSize = {
  5547. cx: this._ui.container.outerWidth( true ),
  5548. cy: this._ui.container.outerHeight( true )
  5549. };
  5550. // Center the menu over the desired coordinates, while not going outside
  5551. // the window tolerances. This will center wrt. the window if the popup is too large.
  5552. ret = {
  5553. x: fitSegmentInsideSegment( rc.cx, menuSize.cx, rc.x, desired.x ),
  5554. y: fitSegmentInsideSegment( rc.cy, menuSize.cy, rc.y, desired.y )
  5555. };
  5556. // Make sure the top of the menu is visible
  5557. ret.y = Math.max( 0, ret.y );
  5558. // If the height of the menu is smaller than the height of the document
  5559. // align the bottom with the bottom of the document
  5560. // fix for $( document ).height() bug in core 1.7.2.
  5561. var docEl = document.documentElement, docBody = document.body,
  5562. docHeight = Math.max( docEl.clientHeight, docBody.scrollHeight, docBody.offsetHeight, docEl.scrollHeight, docEl.offsetHeight );
  5563. ret.y -= Math.min( ret.y, Math.max( 0, ret.y + menuSize.cy - docHeight ) );
  5564. return { left: ret.x, top: ret.y };
  5565. },
  5566. _createPrereqs: function( screenPrereq, containerPrereq, whenDone ) {
  5567. var self = this, prereqs;
  5568. // It is important to maintain both the local variable prereqs and self._prereqs. The local variable remains in
  5569. // the closure of the functions which call the callbacks passed in. The comparison between the local variable and
  5570. // self._prereqs is necessary, because once a function has been passed to .animationComplete() it will be called
  5571. // next time an animation completes, even if that's not the animation whose end the function was supposed to catch
  5572. // (for example, if an abort happens during the opening animation, the .animationComplete handler is not called for
  5573. // that animation anymore, but the handler remains attached, so it is called the next time the popup is opened
  5574. // - making it stale. Comparing the local variable prereqs to the widget-level variable self._prereqs ensures that
  5575. // callbacks triggered by a stale .animationComplete will be ignored.
  5576. prereqs = {
  5577. screen: $.Deferred(),
  5578. container: $.Deferred()
  5579. };
  5580. prereqs.screen.then( function() {
  5581. if ( prereqs === self._prereqs ) {
  5582. screenPrereq();
  5583. }
  5584. });
  5585. prereqs.container.then( function() {
  5586. if ( prereqs === self._prereqs ) {
  5587. containerPrereq();
  5588. }
  5589. });
  5590. $.when( prereqs.screen, prereqs.container ).done( function() {
  5591. if ( prereqs === self._prereqs ) {
  5592. self._prereqs = null;
  5593. whenDone();
  5594. }
  5595. });
  5596. self._prereqs = prereqs;
  5597. },
  5598. _animate: function( args ) {
  5599. // NOTE before removing the default animation of the screen
  5600. // this had an animate callback that would relove the deferred
  5601. // now the deferred is resolved immediately
  5602. // TODO remove the dependency on the screen deferred
  5603. this._ui.screen
  5604. .removeClass( args.classToRemove )
  5605. .addClass( args.screenClassToAdd );
  5606. args.prereqs.screen.resolve();
  5607. if ( args.transition && args.transition !== "none" ) {
  5608. if ( args.applyTransition ) {
  5609. this._applyTransition( args.transition );
  5610. }
  5611. this._ui.container
  5612. .animationComplete( $.proxy( args.prereqs.container, "resolve" ) )
  5613. .addClass( args.containerClassToAdd )
  5614. .removeClass( args.classToRemove );
  5615. } else {
  5616. args.prereqs.container.resolve();
  5617. }
  5618. },
  5619. // The desired coordinates passed in will be returned untouched if no reference element can be identified via
  5620. // desiredPosition.positionTo. Nevertheless, this function ensures that its return value always contains valid
  5621. // x and y coordinates by specifying the center middle of the window if the coordinates are absent.
  5622. _desiredCoords: function( x, y, positionTo ) {
  5623. var dst = null, offset, winCoords = windowCoords();
  5624. // Establish which element will serve as the reference
  5625. if ( positionTo && positionTo !== "origin" ) {
  5626. if ( positionTo === "window" ) {
  5627. x = winCoords.cx / 2 + winCoords.x;
  5628. y = winCoords.cy / 2 + winCoords.y;
  5629. } else {
  5630. try {
  5631. dst = $( positionTo );
  5632. } catch( e ) {
  5633. dst = null;
  5634. }
  5635. if ( dst ) {
  5636. dst.filter( ":visible" );
  5637. if ( dst.length === 0 ) {
  5638. dst = null;
  5639. }
  5640. }
  5641. }
  5642. }
  5643. // If an element was found, center over it
  5644. if ( dst ) {
  5645. offset = dst.offset();
  5646. x = offset.left + dst.outerWidth() / 2;
  5647. y = offset.top + dst.outerHeight() / 2;
  5648. }
  5649. // Make sure x and y are valid numbers - center over the window
  5650. if ( $.type( x ) !== "number" || isNaN( x ) ) {
  5651. x = winCoords.cx / 2 + winCoords.x;
  5652. }
  5653. if ( $.type( y ) !== "number" || isNaN( y ) ) {
  5654. y = winCoords.cy / 2 + winCoords.y;
  5655. }
  5656. return { x: x, y: y };
  5657. },
  5658. _openPrereqsComplete: function() {
  5659. var self = this;
  5660. self._ui.container.addClass( "ui-popup-active" );
  5661. self._isOpen = true;
  5662. self._resizeScreen();
  5663. // Android appears to trigger the animation complete before the popup
  5664. // is visible. Allowing the stack to unwind before applying focus prevents
  5665. // the "blue flash" of element focus in android 4.0
  5666. setTimeout(function(){
  5667. self._ui.container.attr( "tabindex", "0" ).focus();
  5668. self._trigger( "afteropen" );
  5669. });
  5670. },
  5671. _open: function( options ) {
  5672. var coords, transition,
  5673. androidBlacklist = ( function() {
  5674. var w = window,
  5675. ua = navigator.userAgent,
  5676. // Rendering engine is Webkit, and capture major version
  5677. wkmatch = ua.match( /AppleWebKit\/([0-9\.]+)/ ),
  5678. wkversion = !!wkmatch && wkmatch[ 1 ],
  5679. androidmatch = ua.match( /Android (\d+(?:\.\d+))/ ),
  5680. andversion = !!androidmatch && androidmatch[ 1 ],
  5681. chromematch = ua.indexOf( "Chrome" ) > -1;
  5682. // Platform is Android, WebKit version is greater than 534.13 ( Android 3.2.1 ) and not Chrome.
  5683. if( androidmatch !== null && andversion === "4.0" && wkversion && wkversion > 534.13 && !chromematch ) {
  5684. return true;
  5685. }
  5686. return false;
  5687. }());
  5688. // Make sure options is defined
  5689. options = ( options || {} );
  5690. // Copy out the transition, because we may be overwriting it later and we don't want to pass that change back to the caller
  5691. transition = options.transition || this.options.transition;
  5692. // Give applications a chance to modify the contents of the container before it appears
  5693. this._trigger( "beforeposition" );
  5694. coords = this._placementCoords( this._desiredCoords( options.x, options.y, options.positionTo || this.options.positionTo || "origin" ) );
  5695. // Count down to triggering "popupafteropen" - we have two prerequisites:
  5696. // 1. The popup window animation completes (container())
  5697. // 2. The screen opacity animation completes (screen())
  5698. this._createPrereqs(
  5699. $.noop,
  5700. $.noop,
  5701. $.proxy( this, "_openPrereqsComplete" ) );
  5702. if ( transition ) {
  5703. this._currentTransition = transition;
  5704. this._applyTransition( transition );
  5705. } else {
  5706. transition = this.options.transition;
  5707. }
  5708. if ( !this.options.theme ) {
  5709. this._setTheme( this._page.jqmData( "theme" ) || $.mobile.getInheritedTheme( this._page, "c" ) );
  5710. }
  5711. this._ui.screen.removeClass( "ui-screen-hidden" );
  5712. this._ui.container
  5713. .removeClass( "ui-selectmenu-hidden" )
  5714. .offset( coords );
  5715. if ( this.options.overlayTheme && androidBlacklist ) {
  5716. /* TODO:
  5717. The native browser on Android 4.0.X ("Ice Cream Sandwich") suffers from an issue where the popup overlay appears to be z-indexed
  5718. above the popup itself when certain other styles exist on the same page -- namely, any element set to `position: fixed` and certain
  5719. types of input. These issues are reminiscent of previously uncovered bugs in older versions of Android's native browser:
  5720. https://github.com/scottjehl/Device-Bugs/issues/3
  5721. This fix closes the following bugs ( I use "closes" with reluctance, and stress that this issue should be revisited as soon as possible ):
  5722. https://github.com/jquery/jquery-mobile/issues/4816
  5723. https://github.com/jquery/jquery-mobile/issues/4844
  5724. https://github.com/jquery/jquery-mobile/issues/4874
  5725. */
  5726. // TODO sort out why this._page isn't working
  5727. this.element.closest( ".ui-page" ).addClass( "ui-popup-open" );
  5728. }
  5729. this._animate({
  5730. additionalCondition: true,
  5731. transition: transition,
  5732. classToRemove: "",
  5733. screenClassToAdd: "in",
  5734. containerClassToAdd: "in",
  5735. applyTransition: false,
  5736. prereqs: this._prereqs
  5737. });
  5738. },
  5739. _closePrereqScreen: function() {
  5740. this._ui.screen
  5741. .removeClass( "out" )
  5742. .addClass( "ui-screen-hidden" );
  5743. },
  5744. _closePrereqContainer: function() {
  5745. this._ui.container
  5746. .removeClass( "reverse out" )
  5747. .addClass( "ui-selectmenu-hidden" )
  5748. .removeAttr( "style" );
  5749. },
  5750. _closePrereqsDone: function() {
  5751. var self = this, opts = self.options;
  5752. self._ui.container.removeAttr( "tabindex" );
  5753. // remove nav bindings if they are still present
  5754. opts.container.unbind( opts.closeEvents );
  5755. // unbind click handlers added when history is disabled
  5756. self.element.undelegate( opts.closeLinkSelector, opts.closeLinkEvents );
  5757. // remove the global mutex for popups
  5758. $.mobile.popup.active = undefined;
  5759. // alert users that the popup is closed
  5760. self._trigger( "afterclose" );
  5761. },
  5762. _close: function() {
  5763. this._ui.container.removeClass( "ui-popup-active" );
  5764. this._page.removeClass( "ui-popup-open" );
  5765. this._isOpen = false;
  5766. // Count down to triggering "popupafterclose" - we have two prerequisites:
  5767. // 1. The popup window reverse animation completes (container())
  5768. // 2. The screen opacity animation completes (screen())
  5769. this._createPrereqs(
  5770. $.proxy( this, "_closePrereqScreen" ),
  5771. $.proxy( this, "_closePrereqContainer" ),
  5772. $.proxy( this, "_closePrereqsDone" ) );
  5773. this._animate( {
  5774. additionalCondition: this._ui.screen.hasClass( "in" ),
  5775. transition: ( this._currentTransition || this.options.transition ),
  5776. classToRemove: "in",
  5777. screenClassToAdd: "out",
  5778. containerClassToAdd: "reverse out",
  5779. applyTransition: true,
  5780. prereqs: this._prereqs
  5781. });
  5782. },
  5783. _destroy: function() {
  5784. var self = this;
  5785. // hide and remove bindings
  5786. self._close();
  5787. // Put the element back to where the placeholder was and remove the "ui-popup" class
  5788. self._setTheme( "none" );
  5789. self.element
  5790. .insertAfter( self._ui.placeholder )
  5791. .removeClass( "ui-popup ui-overlay-shadow ui-corner-all" );
  5792. self._ui.screen.remove();
  5793. self._ui.container.remove();
  5794. self._ui.placeholder.remove();
  5795. // Unbind handlers that were bound to elements outside self.element (the window, in self case)
  5796. $.each( self._globalHandlers, function( idx, oneSrc ) {
  5797. $.each( oneSrc.handler, function( eventType, handler ) {
  5798. oneSrc.src.unbind( eventType, handler );
  5799. });
  5800. });
  5801. },
  5802. // any navigation event after a popup is opened should close the popup
  5803. // NOTE the pagebeforechange is bound to catch navigation events that don't
  5804. // alter the url (eg, dialogs from popups)
  5805. _bindContainerClose: function() {
  5806. var self = this;
  5807. self.options.container
  5808. .one( self.options.closeEvents, $.proxy( self._close, self ));
  5809. },
  5810. // TODO no clear deliniation of what should be here and
  5811. // what should be in _open. Seems to be "visual" vs "history" for now
  5812. open: function( options ) {
  5813. var self = this, opts = this.options, url, hashkey, activePage, currentIsDialog, hasHash, urlHistory;
  5814. // make sure open is idempotent
  5815. if( $.mobile.popup.active ) {
  5816. return;
  5817. }
  5818. // set the global popup mutex
  5819. $.mobile.popup.active = this;
  5820. // if history alteration is disabled close on navigate events
  5821. // and leave the url as is
  5822. if( !( opts.history ) ) {
  5823. self._open( options );
  5824. self._bindContainerClose();
  5825. // When histoy is disabled we have to grab the data-rel
  5826. // back link clicks so we can close the popup instead of
  5827. // relying on history to do it for us
  5828. self.element
  5829. .delegate( opts.closeLinkSelector, opts.closeLinkEvents, function( e ) {
  5830. self._close();
  5831. // NOTE prevent the browser and navigation handlers from
  5832. // working with the link's rel=back. This may cause
  5833. // issues for developers expecting the event to bubble
  5834. return false;
  5835. });
  5836. return;
  5837. }
  5838. // cache some values for min/readability
  5839. hashkey = $.mobile.dialogHashKey;
  5840. activePage = $.mobile.activePage;
  5841. currentIsDialog = activePage.is( ".ui-dialog" );
  5842. url = $.mobile.urlHistory.getActive().url;
  5843. hasHash = ( url.indexOf( hashkey ) > -1 ) && !currentIsDialog;
  5844. urlHistory = $.mobile.urlHistory;
  5845. if ( hasHash ) {
  5846. self._open( options );
  5847. self._bindContainerClose();
  5848. return;
  5849. }
  5850. // if the current url has no dialog hash key proceed as normal
  5851. // otherwise, if the page is a dialog simply tack on the hash key
  5852. if ( url.indexOf( hashkey ) === -1 && !currentIsDialog ){
  5853. url = url + hashkey;
  5854. } else {
  5855. url = $.mobile.path.parseLocation().hash + hashkey;
  5856. }
  5857. // Tack on an extra hashkey if this is the first page and we've just reconstructed the initial hash
  5858. if ( urlHistory.activeIndex === 0 && url === urlHistory.initialDst ) {
  5859. url += hashkey;
  5860. }
  5861. // swallow the the initial navigation event, and bind for the next
  5862. opts.container.one( opts.navigateEvents, function( e ) {
  5863. e.preventDefault();
  5864. self._open( options );
  5865. self._bindContainerClose();
  5866. });
  5867. urlHistory.ignoreNextHashChange = currentIsDialog;
  5868. // Gotta love methods with 1mm args :(
  5869. urlHistory.addNew( url, undefined, undefined, undefined, "dialog" );
  5870. // set the new url with (or without) the new dialog hash key
  5871. $.mobile.path.set( url );
  5872. },
  5873. close: function() {
  5874. // make sure close is idempotent
  5875. if( !$.mobile.popup.active ){
  5876. return;
  5877. }
  5878. if( this.options.history ) {
  5879. $.mobile.back();
  5880. } else {
  5881. this._close();
  5882. }
  5883. }
  5884. });
  5885. // TODO this can be moved inside the widget
  5886. $.mobile.popup.handleLink = function( $link ) {
  5887. var closestPage = $link.closest( ":jqmData(role='page')" ),
  5888. scope = ( ( closestPage.length === 0 ) ? $( "body" ) : closestPage ),
  5889. // NOTE make sure to get only the hash, ie7 (wp7) return the absolute href
  5890. // in this case ruining the element selection
  5891. popup = $( $.mobile.path.parseUrl($link.attr( "href" )).hash, scope[0] ),
  5892. offset;
  5893. if ( popup.data( "popup" ) ) {
  5894. offset = $link.offset();
  5895. popup.popup( "open", {
  5896. x: offset.left + $link.outerWidth() / 2,
  5897. y: offset.top + $link.outerHeight() / 2,
  5898. transition: $link.jqmData( "transition" ),
  5899. positionTo: $link.jqmData( "position-to" ),
  5900. link: $link
  5901. });
  5902. }
  5903. //remove after delay
  5904. setTimeout( function() {
  5905. $link.removeClass( $.mobile.activeBtnClass );
  5906. }, 300 );
  5907. };
  5908. // TODO move inside _create
  5909. $( document ).bind( "pagebeforechange", function( e, data ) {
  5910. if ( data.options.role === "popup" ) {
  5911. $.mobile.popup.handleLink( data.options.link );
  5912. e.preventDefault();
  5913. }
  5914. });
  5915. $( document ).bind( "pagecreate create", function( e ) {
  5916. $.mobile.popup.prototype.enhanceWithin( e.target, true );
  5917. });
  5918. })( jQuery );
  5919. (function( $ ) {
  5920. var meta = $( "meta[name=viewport]" ),
  5921. initialContent = meta.attr( "content" ),
  5922. disabledZoom = initialContent + ",maximum-scale=1, user-scalable=no",
  5923. enabledZoom = initialContent + ",maximum-scale=10, user-scalable=yes",
  5924. disabledInitially = /(user-scalable[\s]*=[\s]*no)|(maximum-scale[\s]*=[\s]*1)[$,\s]/.test( initialContent );
  5925. $.mobile.zoom = $.extend( {}, {
  5926. enabled: !disabledInitially,
  5927. locked: false,
  5928. disable: function( lock ) {
  5929. if ( !disabledInitially && !$.mobile.zoom.locked ) {
  5930. meta.attr( "content", disabledZoom );
  5931. $.mobile.zoom.enabled = false;
  5932. $.mobile.zoom.locked = lock || false;
  5933. }
  5934. },
  5935. enable: function( unlock ) {
  5936. if ( !disabledInitially && ( !$.mobile.zoom.locked || unlock === true ) ) {
  5937. meta.attr( "content", enabledZoom );
  5938. $.mobile.zoom.enabled = true;
  5939. $.mobile.zoom.locked = false;
  5940. }
  5941. },
  5942. restore: function() {
  5943. if ( !disabledInitially ) {
  5944. meta.attr( "content", initialContent );
  5945. $.mobile.zoom.enabled = true;
  5946. }
  5947. }
  5948. });
  5949. }( jQuery ));
  5950. (function( $, undefined ) {
  5951. $.widget( "mobile.textinput", $.mobile.widget, {
  5952. options: {
  5953. theme: null,
  5954. // This option defaults to true on iOS devices.
  5955. preventFocusZoom: /iPhone|iPad|iPod/.test( navigator.platform ) && navigator.userAgent.indexOf( "AppleWebKit" ) > -1,
  5956. 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])",
  5957. clearSearchButtonText: "clear text",
  5958. disabled: false
  5959. },
  5960. _create: function() {
  5961. var self = this,
  5962. input = this.element,
  5963. o = this.options,
  5964. theme = o.theme || $.mobile.getInheritedTheme( this.element, "c" ),
  5965. themeclass = " ui-body-" + theme,
  5966. mini = input.jqmData( "mini" ) === true,
  5967. miniclass = mini ? " ui-mini" : "",
  5968. focusedEl, clearbtn;
  5969. function toggleClear() {
  5970. setTimeout( function() {
  5971. clearbtn.toggleClass( "ui-input-clear-hidden", !input.val() );
  5972. }, 0 );
  5973. }
  5974. $( "label[for='" + input.attr( "id" ) + "']" ).addClass( "ui-input-text" );
  5975. focusedEl = input.addClass("ui-input-text ui-body-"+ theme );
  5976. // XXX: Temporary workaround for issue 785 (Apple bug 8910589).
  5977. // Turn off autocorrect and autocomplete on non-iOS 5 devices
  5978. // since the popup they use can't be dismissed by the user. Note
  5979. // that we test for the presence of the feature by looking for
  5980. // the autocorrect property on the input element. We currently
  5981. // have no test for iOS 5 or newer so we're temporarily using
  5982. // the touchOverflow support flag for jQM 1.0. Yes, I feel dirty. - jblas
  5983. if ( typeof input[0].autocorrect !== "undefined" && !$.support.touchOverflow ) {
  5984. // Set the attribute instead of the property just in case there
  5985. // is code that attempts to make modifications via HTML.
  5986. input[0].setAttribute( "autocorrect", "off" );
  5987. input[0].setAttribute( "autocomplete", "off" );
  5988. }
  5989. //"search" input widget
  5990. if ( input.is( "[type='search'],:jqmData(type='search')" ) ) {
  5991. focusedEl = input.wrap( "<div class='ui-input-search ui-shadow-inset ui-btn-corner-all ui-btn-shadow ui-icon-searchfield" + themeclass + miniclass + "'></div>" ).parent();
  5992. clearbtn = $( "<a href='#' class='ui-input-clear' title='" + o.clearSearchButtonText + "'>" + o.clearSearchButtonText + "</a>" )
  5993. .bind('click', function( event ) {
  5994. input
  5995. .val( "" )
  5996. .focus()
  5997. .trigger( "change" );
  5998. clearbtn.addClass( "ui-input-clear-hidden" );
  5999. event.preventDefault();
  6000. })
  6001. .appendTo( focusedEl )
  6002. .buttonMarkup({
  6003. icon: "delete",
  6004. iconpos: "notext",
  6005. corners: true,
  6006. shadow: true,
  6007. mini: mini
  6008. });
  6009. toggleClear();
  6010. input.bind( 'paste cut keyup focus change blur', toggleClear );
  6011. } else {
  6012. input.addClass( "ui-corner-all ui-shadow-inset" + themeclass + miniclass );
  6013. }
  6014. input.focus(function() {
  6015. focusedEl.addClass( $.mobile.focusClass );
  6016. })
  6017. .blur(function() {
  6018. focusedEl.removeClass( $.mobile.focusClass );
  6019. })
  6020. // In many situations, iOS will zoom into the select upon tap, this prevents that from happening
  6021. .bind( "focus", function() {
  6022. if ( o.preventFocusZoom ) {
  6023. $.mobile.zoom.disable( true );
  6024. }
  6025. })
  6026. .bind( "blur", function() {
  6027. if ( o.preventFocusZoom ) {
  6028. $.mobile.zoom.enable( true );
  6029. }
  6030. });
  6031. // Autogrow
  6032. if ( input.is( "textarea" ) ) {
  6033. var extraLineHeight = 15,
  6034. keyupTimeoutBuffer = 100,
  6035. keyupTimeout;
  6036. this._keyup = function() {
  6037. var scrollHeight = input[ 0 ].scrollHeight,
  6038. clientHeight = input[ 0 ].clientHeight;
  6039. if ( clientHeight < scrollHeight ) {
  6040. input.height(scrollHeight + extraLineHeight);
  6041. }
  6042. };
  6043. input.keyup(function() {
  6044. clearTimeout( keyupTimeout );
  6045. keyupTimeout = setTimeout( self._keyup, keyupTimeoutBuffer );
  6046. });
  6047. // binding to pagechange here ensures that for pages loaded via
  6048. // ajax the height is recalculated without user input
  6049. this._on( $(document), {"pagechange": "_keyup" });
  6050. // Issue 509: the browser is not providing scrollHeight properly until the styles load
  6051. if ( $.trim( input.val() ) ) {
  6052. // bind to the window load to make sure the height is calculated based on BOTH
  6053. // the DOM and CSS
  6054. this._on( $(window), {"load": "_keyup"});
  6055. }
  6056. }
  6057. if ( input.attr( "disabled" ) ) {
  6058. this.disable();
  6059. }
  6060. },
  6061. disable: function() {
  6062. var $el;
  6063. if ( this.element.attr( "disabled", true ).is( "[type='search'], :jqmData(type='search')" ) ) {
  6064. $el = this.element.parent();
  6065. } else {
  6066. $el = this.element;
  6067. }
  6068. $el.addClass( "ui-disabled" );
  6069. return this._setOption( "disabled", true );
  6070. },
  6071. enable: function() {
  6072. var $el;
  6073. // TODO using more than one line of code is acceptable ;)
  6074. if ( this.element.attr( "disabled", false ).is( "[type='search'], :jqmData(type='search')" ) ) {
  6075. $el = this.element.parent();
  6076. } else {
  6077. $el = this.element;
  6078. }
  6079. $el.removeClass( "ui-disabled" );
  6080. return this._setOption( "disabled", false );
  6081. }
  6082. });
  6083. //auto self-init widgets
  6084. $( document ).bind( "pagecreate create", function( e ) {
  6085. $.mobile.textinput.prototype.enhanceWithin( e.target, true );
  6086. });
  6087. })( jQuery );
  6088. (function( $, undefined ) {
  6089. $.mobile.listview.prototype.options.filter = false;
  6090. $.mobile.listview.prototype.options.filterPlaceholder = "Filter items...";
  6091. $.mobile.listview.prototype.options.filterTheme = "c";
  6092. // TODO rename callback/deprecate and default to the item itself as the first argument
  6093. var defaultFilterCallback = function( text, searchValue, item ) {
  6094. return text.toString().toLowerCase().indexOf( searchValue ) === -1;
  6095. };
  6096. $.mobile.listview.prototype.options.filterCallback = defaultFilterCallback;
  6097. $( document ).delegate( ":jqmData(role='listview')", "listviewcreate", function() {
  6098. var list = $( this ),
  6099. listview = list.data( "listview" );
  6100. if ( !listview.options.filter ) {
  6101. return;
  6102. }
  6103. var wrapper = $( "<form>", {
  6104. "class": "ui-listview-filter ui-bar-" + listview.options.filterTheme,
  6105. "role": "search"
  6106. }),
  6107. search = $( "<input>", {
  6108. placeholder: listview.options.filterPlaceholder
  6109. })
  6110. .attr( "data-" + $.mobile.ns + "type", "search" )
  6111. .jqmData( "lastval", "" )
  6112. .bind( "keyup change", function() {
  6113. var $this = $( this ),
  6114. val = this.value.toLowerCase(),
  6115. listItems = null,
  6116. lastval = $this.jqmData( "lastval" ) + "",
  6117. childItems = false,
  6118. itemtext = "",
  6119. item,
  6120. // Check if a custom filter callback applies
  6121. isCustomFilterCallback = listview.options.filterCallback !== defaultFilterCallback;
  6122. listview._trigger( "beforefilter", "beforefilter", { input: this } );
  6123. // Change val as lastval for next execution
  6124. $this.jqmData( "lastval" , val );
  6125. if ( isCustomFilterCallback || val.length < lastval.length || val.indexOf( lastval ) !== 0 ) {
  6126. // Custom filter callback applies or removed chars or pasted something totally different, check all items
  6127. listItems = list.children();
  6128. } else {
  6129. // Only chars added, not removed, only use visible subset
  6130. listItems = list.children( ":not(.ui-screen-hidden)" );
  6131. }
  6132. if ( val ) {
  6133. // This handles hiding regular rows without the text we search for
  6134. // and any list dividers without regular rows shown under it
  6135. for ( var i = listItems.length - 1; i >= 0; i-- ) {
  6136. item = $( listItems[ i ] );
  6137. itemtext = item.jqmData( "filtertext" ) || item.text();
  6138. if ( item.is( "li:jqmData(role=list-divider)" ) ) {
  6139. item.toggleClass( "ui-filter-hidequeue" , !childItems );
  6140. // New bucket!
  6141. childItems = false;
  6142. } else if ( listview.options.filterCallback( itemtext, val, item ) ) {
  6143. //mark to be hidden
  6144. item.toggleClass( "ui-filter-hidequeue" , true );
  6145. } else {
  6146. // There's a shown item in the bucket
  6147. childItems = true;
  6148. }
  6149. }
  6150. // Show items, not marked to be hidden
  6151. listItems
  6152. .filter( ":not(.ui-filter-hidequeue)" )
  6153. .toggleClass( "ui-screen-hidden", false );
  6154. // Hide items, marked to be hidden
  6155. listItems
  6156. .filter( ".ui-filter-hidequeue" )
  6157. .toggleClass( "ui-screen-hidden", true )
  6158. .toggleClass( "ui-filter-hidequeue", false );
  6159. } else {
  6160. //filtervalue is empty => show all
  6161. listItems.toggleClass( "ui-screen-hidden", false );
  6162. }
  6163. listview._refreshCorners();
  6164. })
  6165. .appendTo( wrapper )
  6166. .textinput();
  6167. if ( listview.options.inset ) {
  6168. wrapper.addClass( "ui-listview-filter-inset" );
  6169. }
  6170. wrapper.bind( "submit", function() {
  6171. return false;
  6172. })
  6173. .insertBefore( list );
  6174. });
  6175. })( jQuery );
  6176. (function( $, undefined ) {
  6177. $.widget( "mobile.slider", $.mobile.widget, {
  6178. widgetEventPrefix: "slide",
  6179. options: {
  6180. theme: null,
  6181. trackTheme: null,
  6182. disabled: false,
  6183. initSelector: "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')",
  6184. mini: false
  6185. },
  6186. _create: function() {
  6187. // TODO: Each of these should have comments explain what they're for
  6188. var self = this,
  6189. control = this.element,
  6190. parentTheme = $.mobile.getInheritedTheme( control, "c" ),
  6191. theme = this.options.theme || parentTheme,
  6192. trackTheme = this.options.trackTheme || parentTheme,
  6193. cType = control[ 0 ].nodeName.toLowerCase(),
  6194. selectClass = ( cType === "select" ) ? "ui-slider-switch" : "",
  6195. controlID = control.attr( "id" ),
  6196. $label = $( "[for='" + controlID + "']" ),
  6197. labelID = $label.attr( "id" ) || controlID + "-label",
  6198. label = $label.attr( "id", labelID ),
  6199. val = function() {
  6200. return cType === "input" ? parseFloat( control.val() ) : control[0].selectedIndex;
  6201. },
  6202. min = cType === "input" ? parseFloat( control.attr( "min" ) ) : 0,
  6203. max = cType === "input" ? parseFloat( control.attr( "max" ) ) : control.find( "option" ).length-1,
  6204. step = window.parseFloat( control.attr( "step" ) || 1 ),
  6205. inlineClass = ( this.options.inline || control.jqmData( "inline" ) === true ) ? " ui-slider-inline" : "",
  6206. miniClass = ( this.options.mini || control.jqmData( "mini" ) ) ? " ui-slider-mini" : "",
  6207. domHandle = document.createElement( 'a' ),
  6208. handle = $( domHandle ),
  6209. domSlider = document.createElement( 'div' ),
  6210. slider = $( domSlider ),
  6211. valuebg = control.jqmData( "highlight" ) && cType !== "select" ? (function() {
  6212. var bg = document.createElement('div');
  6213. bg.className = 'ui-slider-bg ' + $.mobile.activeBtnClass + ' ui-btn-corner-all';
  6214. return $( bg ).prependTo( slider );
  6215. })() : false,
  6216. options;
  6217. this._type = cType;
  6218. domHandle.setAttribute( 'href', "#" );
  6219. domSlider.setAttribute('role','application');
  6220. domSlider.className = ['ui-slider ',selectClass," ui-btn-down-",trackTheme,' ui-btn-corner-all', inlineClass, miniClass].join( "" );
  6221. domHandle.className = 'ui-slider-handle';
  6222. domSlider.appendChild( domHandle );
  6223. handle.buttonMarkup({ corners: true, theme: theme, shadow: true })
  6224. .attr({
  6225. "role": "slider",
  6226. "aria-valuemin": min,
  6227. "aria-valuemax": max,
  6228. "aria-valuenow": val(),
  6229. "aria-valuetext": val(),
  6230. "title": val(),
  6231. "aria-labelledby": labelID
  6232. });
  6233. $.extend( this, {
  6234. slider: slider,
  6235. handle: handle,
  6236. valuebg: valuebg,
  6237. dragging: false,
  6238. beforeStart: null,
  6239. userModified: false,
  6240. mouseMoved: false
  6241. });
  6242. if ( cType === "select" ) {
  6243. var wrapper = document.createElement('div');
  6244. wrapper.className = 'ui-slider-inneroffset';
  6245. for ( var j = 0,length = domSlider.childNodes.length;j < length;j++ ) {
  6246. wrapper.appendChild( domSlider.childNodes[j] );
  6247. }
  6248. domSlider.appendChild( wrapper );
  6249. // slider.wrapInner( "<div class='ui-slider-inneroffset'></div>" );
  6250. // make the handle move with a smooth transition
  6251. handle.addClass( "ui-slider-handle-snapping" );
  6252. options = control.find( "option" );
  6253. for ( var i = 0, optionsCount = options.length; i < optionsCount; i++ ) {
  6254. var side = !i ? "b" : "a",
  6255. sliderTheme = !i ? " ui-btn-down-" + trackTheme : ( " " + $.mobile.activeBtnClass ),
  6256. sliderLabel = document.createElement( 'div' ),
  6257. sliderImg = document.createElement( 'span' );
  6258. sliderImg.className = ['ui-slider-label ui-slider-label-',side,sliderTheme," ui-btn-corner-all"].join( "" );
  6259. sliderImg.setAttribute('role','img');
  6260. sliderImg.appendChild( document.createTextNode( options[i].innerHTML ) );
  6261. $(sliderImg).prependTo( slider );
  6262. }
  6263. self._labels = $( ".ui-slider-label", slider );
  6264. }
  6265. label.addClass( "ui-slider" );
  6266. // monitor the input for updated values
  6267. control.addClass( cType === "input" ? "ui-slider-input" : "ui-slider-switch" )
  6268. .change(function() {
  6269. // if the user dragged the handle, the "change" event was triggered from inside refresh(); don't call refresh() again
  6270. if ( !self.mouseMoved ) {
  6271. self.refresh( val(), true );
  6272. }
  6273. })
  6274. .keyup(function() { // necessary?
  6275. self.refresh( val(), true, true );
  6276. })
  6277. .blur(function() {
  6278. self.refresh( val(), true );
  6279. });
  6280. this._preventDocumentDrag = function( event ) {
  6281. // NOTE: we don't do this in refresh because we still want to
  6282. // support programmatic alteration of disabled inputs
  6283. if ( self.dragging && !self.options.disabled ) {
  6284. // self.mouseMoved must be updated before refresh() because it will be used in the control "change" event
  6285. self.mouseMoved = true;
  6286. if ( cType === "select" ) {
  6287. // make the handle move in sync with the mouse
  6288. handle.removeClass( "ui-slider-handle-snapping" );
  6289. }
  6290. self.refresh( event );
  6291. // only after refresh() you can calculate self.userModified
  6292. self.userModified = self.beforeStart !== control[0].selectedIndex;
  6293. return false;
  6294. }
  6295. }
  6296. this._on( $( document ), { "vmousemove": this._preventDocumentDrag });
  6297. // it appears the clicking the up and down buttons in chrome on
  6298. // range/number inputs doesn't trigger a change until the field is
  6299. // blurred. Here we check thif the value has changed and refresh
  6300. control.bind( "vmouseup", $.proxy( self._checkedRefresh, self));
  6301. slider.bind( "vmousedown", function( event ) {
  6302. // NOTE: we don't do this in refresh because we still want to
  6303. // support programmatic alteration of disabled inputs
  6304. if ( self.options.disabled ) {
  6305. return false;
  6306. }
  6307. self.dragging = true;
  6308. self.userModified = false;
  6309. self.mouseMoved = false;
  6310. if ( cType === "select" ) {
  6311. self.beforeStart = control[0].selectedIndex;
  6312. }
  6313. self.refresh( event );
  6314. self._trigger( "start" );
  6315. return false;
  6316. })
  6317. .bind( "vclick", false );
  6318. this._sliderMouseUp = function() {
  6319. if ( self.dragging ) {
  6320. self.dragging = false;
  6321. if ( cType === "select") {
  6322. // make the handle move with a smooth transition
  6323. handle.addClass( "ui-slider-handle-snapping" );
  6324. if ( self.mouseMoved ) {
  6325. // this is a drag, change the value only if user dragged enough
  6326. if ( self.userModified ) {
  6327. self.refresh( self.beforeStart === 0 ? 1 : 0 );
  6328. }
  6329. else {
  6330. self.refresh( self.beforeStart );
  6331. }
  6332. }
  6333. else {
  6334. // this is just a click, change the value
  6335. self.refresh( self.beforeStart === 0 ? 1 : 0 );
  6336. }
  6337. }
  6338. self.mouseMoved = false;
  6339. self._trigger( "stop" );
  6340. return false;
  6341. }
  6342. };
  6343. this._on( slider.add( document ), { "vmouseup": this._sliderMouseUp });
  6344. slider.insertAfter( control );
  6345. // Only add focus class to toggle switch, sliders get it automatically from ui-btn
  6346. if ( cType === 'select' ) {
  6347. this.handle.bind({
  6348. focus: function() {
  6349. slider.addClass( $.mobile.focusClass );
  6350. },
  6351. blur: function() {
  6352. slider.removeClass( $.mobile.focusClass );
  6353. }
  6354. });
  6355. }
  6356. this.handle.bind({
  6357. // NOTE force focus on handle
  6358. vmousedown: function() {
  6359. $( this ).focus();
  6360. },
  6361. vclick: false,
  6362. keydown: function( event ) {
  6363. var index = val();
  6364. if ( self.options.disabled ) {
  6365. return;
  6366. }
  6367. // In all cases prevent the default and mark the handle as active
  6368. switch ( event.keyCode ) {
  6369. case $.mobile.keyCode.HOME:
  6370. case $.mobile.keyCode.END:
  6371. case $.mobile.keyCode.PAGE_UP:
  6372. case $.mobile.keyCode.PAGE_DOWN:
  6373. case $.mobile.keyCode.UP:
  6374. case $.mobile.keyCode.RIGHT:
  6375. case $.mobile.keyCode.DOWN:
  6376. case $.mobile.keyCode.LEFT:
  6377. event.preventDefault();
  6378. if ( !self._keySliding ) {
  6379. self._keySliding = true;
  6380. $( this ).addClass( "ui-state-active" );
  6381. }
  6382. break;
  6383. }
  6384. // move the slider according to the keypress
  6385. switch ( event.keyCode ) {
  6386. case $.mobile.keyCode.HOME:
  6387. self.refresh( min );
  6388. break;
  6389. case $.mobile.keyCode.END:
  6390. self.refresh( max );
  6391. break;
  6392. case $.mobile.keyCode.PAGE_UP:
  6393. case $.mobile.keyCode.UP:
  6394. case $.mobile.keyCode.RIGHT:
  6395. self.refresh( index + step );
  6396. break;
  6397. case $.mobile.keyCode.PAGE_DOWN:
  6398. case $.mobile.keyCode.DOWN:
  6399. case $.mobile.keyCode.LEFT:
  6400. self.refresh( index - step );
  6401. break;
  6402. }
  6403. }, // remove active mark
  6404. keyup: function( event ) {
  6405. if ( self._keySliding ) {
  6406. self._keySliding = false;
  6407. $( this ).removeClass( "ui-state-active" );
  6408. }
  6409. }
  6410. });
  6411. this.refresh( undefined, undefined, true );
  6412. },
  6413. _checkedRefresh: function() {
  6414. if( this.value != this._value() ){
  6415. this.refresh( this._value() );
  6416. }
  6417. },
  6418. _value: function() {
  6419. return this._type === "input" ?
  6420. parseFloat( this.element.val() ) : this.element[0].selectedIndex;
  6421. },
  6422. refresh: function( val, isfromControl, preventInputUpdate ) {
  6423. // NOTE: we don't return here because we want to support programmatic
  6424. // alteration of the input value, which should still update the slider
  6425. if ( this.options.disabled || this.element.attr('disabled')) {
  6426. this.disable();
  6427. }
  6428. // set the stored value for comparison later
  6429. this.value = this._value();
  6430. var control = this.element, percent,
  6431. cType = control[0].nodeName.toLowerCase(),
  6432. min = cType === "input" ? parseFloat( control.attr( "min" ) ) : 0,
  6433. max = cType === "input" ? parseFloat( control.attr( "max" ) ) : control.find( "option" ).length - 1,
  6434. step = ( cType === "input" && parseFloat( control.attr( "step" ) ) > 0 ) ? parseFloat( control.attr( "step" ) ) : 1;
  6435. if ( typeof val === "object" ) {
  6436. var data = val,
  6437. // a slight tolerance helped get to the ends of the slider
  6438. tol = 8;
  6439. if ( !this.dragging ||
  6440. data.pageX < this.slider.offset().left - tol ||
  6441. data.pageX > this.slider.offset().left + this.slider.width() + tol ) {
  6442. return;
  6443. }
  6444. percent = Math.round( ( ( data.pageX - this.slider.offset().left ) / this.slider.width() ) * 100 );
  6445. } else {
  6446. if ( val == null ) {
  6447. val = cType === "input" ? parseFloat( control.val() || 0 ) : control[0].selectedIndex;
  6448. }
  6449. percent = ( parseFloat( val ) - min ) / ( max - min ) * 100;
  6450. }
  6451. if ( isNaN( percent ) ) {
  6452. return;
  6453. }
  6454. if ( percent < 0 ) {
  6455. percent = 0;
  6456. }
  6457. if ( percent > 100 ) {
  6458. percent = 100;
  6459. }
  6460. var newval = ( percent / 100 ) * ( max - min ) + min;
  6461. //from jQuery UI slider, the following source will round to the nearest step
  6462. var valModStep = ( newval - min ) % step;
  6463. var alignValue = newval - valModStep;
  6464. if ( Math.abs( valModStep ) * 2 >= step ) {
  6465. alignValue += ( valModStep > 0 ) ? step : ( -step );
  6466. }
  6467. // Since JavaScript has problems with large floats, round
  6468. // the final value to 5 digits after the decimal point (see jQueryUI: #4124)
  6469. newval = parseFloat( alignValue.toFixed(5) );
  6470. if ( newval < min ) {
  6471. newval = min;
  6472. }
  6473. if ( newval > max ) {
  6474. newval = max;
  6475. }
  6476. this.handle.css( "left", percent + "%" );
  6477. this.handle.attr( {
  6478. "aria-valuenow": cType === "input" ? newval : control.find( "option" ).eq( newval ).attr( "value" ),
  6479. "aria-valuetext": cType === "input" ? newval : control.find( "option" ).eq( newval ).getEncodedText(),
  6480. title: cType === "input" ? newval : control.find( "option" ).eq( newval ).getEncodedText()
  6481. });
  6482. if ( this.valuebg ) {
  6483. this.valuebg.css( "width", percent + "%" );
  6484. }
  6485. // drag the label widths
  6486. if ( this._labels ) {
  6487. var handlePercent = this.handle.width() / this.slider.width() * 100,
  6488. aPercent = percent && handlePercent + ( 100 - handlePercent ) * percent / 100,
  6489. bPercent = percent === 100 ? 0 : Math.min( handlePercent + 100 - aPercent, 100 );
  6490. this._labels.each(function() {
  6491. var ab = $( this ).is( ".ui-slider-label-a" );
  6492. $( this ).width( ( ab ? aPercent : bPercent ) + "%" );
  6493. });
  6494. }
  6495. if ( !preventInputUpdate ) {
  6496. var valueChanged = false;
  6497. // update control"s value
  6498. if ( cType === "input" ) {
  6499. valueChanged = control.val() !== newval;
  6500. control.val( newval );
  6501. } else {
  6502. valueChanged = control[ 0 ].selectedIndex !== newval;
  6503. control[ 0 ].selectedIndex = newval;
  6504. }
  6505. if ( !isfromControl && valueChanged ) {
  6506. control.trigger( "change" );
  6507. }
  6508. }
  6509. },
  6510. enable: function() {
  6511. this.element.attr( "disabled", false );
  6512. this.slider.removeClass( "ui-disabled" ).attr( "aria-disabled", false );
  6513. return this._setOption( "disabled", false );
  6514. },
  6515. disable: function() {
  6516. this.element.attr( "disabled", true );
  6517. this.slider.addClass( "ui-disabled" ).attr( "aria-disabled", true );
  6518. return this._setOption( "disabled", true );
  6519. }
  6520. });
  6521. //auto self-init widgets
  6522. $( document ).bind( "pagecreate create", function( e ) {
  6523. $.mobile.slider.prototype.enhanceWithin( e.target, true );
  6524. });
  6525. })( jQuery );
  6526. (function( $, undefined ) {
  6527. $.widget( "mobile.selectmenu", $.mobile.widget, {
  6528. options: {
  6529. theme: null,
  6530. disabled: false,
  6531. icon: "arrow-d",
  6532. iconpos: "right",
  6533. inline: false,
  6534. corners: true,
  6535. shadow: true,
  6536. iconshadow: true,
  6537. overlayTheme: "a",
  6538. hidePlaceholderMenuItems: true,
  6539. closeText: "Close",
  6540. nativeMenu: true,
  6541. // This option defaults to true on iOS devices.
  6542. preventFocusZoom: /iPhone|iPad|iPod/.test( navigator.platform ) && navigator.userAgent.indexOf( "AppleWebKit" ) > -1,
  6543. initSelector: "select:not( :jqmData(role='slider') )",
  6544. mini: false
  6545. },
  6546. _button: function() {
  6547. return $( "<div/>" );
  6548. },
  6549. _setDisabled: function( value ) {
  6550. this.element.attr( "disabled", value );
  6551. this.button.attr( "aria-disabled", value );
  6552. return this._setOption( "disabled", value );
  6553. },
  6554. _focusButton : function() {
  6555. var self = this;
  6556. setTimeout( function() {
  6557. self.button.focus();
  6558. }, 40);
  6559. },
  6560. _selectOptions: function() {
  6561. return this.select.find( "option" );
  6562. },
  6563. // setup items that are generally necessary for select menu extension
  6564. _preExtension: function() {
  6565. var classes = "";
  6566. // TODO: Post 1.1--once we have time to test thoroughly--any classes manually applied to the original element should be carried over to the enhanced element, with an `-enhanced` suffix. See https://github.com/jquery/jquery-mobile/issues/3577
  6567. /* if ( $el[0].className.length ) {
  6568. classes = $el[0].className;
  6569. } */
  6570. if ( !!~this.element[0].className.indexOf( "ui-btn-left" ) ) {
  6571. classes = " ui-btn-left";
  6572. }
  6573. if ( !!~this.element[0].className.indexOf( "ui-btn-right" ) ) {
  6574. classes = " ui-btn-right";
  6575. }
  6576. this.select = this.element.wrap( "<div class='ui-select" + classes + "'>" );
  6577. this.selectID = this.select.attr( "id" );
  6578. this.label = $( "label[for='"+ this.selectID +"']" ).addClass( "ui-select" );
  6579. this.isMultiple = this.select[ 0 ].multiple;
  6580. if ( !this.options.theme ) {
  6581. this.options.theme = $.mobile.getInheritedTheme( this.select, "c" );
  6582. }
  6583. },
  6584. _create: function() {
  6585. this._preExtension();
  6586. // Allows for extension of the native select for custom selects and other plugins
  6587. // see select.custom for example extension
  6588. // TODO explore plugin registration
  6589. this._trigger( "beforeCreate" );
  6590. this.button = this._button();
  6591. var self = this,
  6592. options = this.options,
  6593. inline = options.inline || this.select.jqmData( "inline" ),
  6594. mini = options.mini || this.select.jqmData( "mini" ),
  6595. iconpos = options.icon ? ( options.iconpos || this.select.jqmData( "iconpos" ) ) : false,
  6596. // IE throws an exception at options.item() function when
  6597. // there is no selected item
  6598. // select first in this case
  6599. selectedIndex = this.select[ 0 ].selectedIndex === -1 ? 0 : this.select[ 0 ].selectedIndex,
  6600. // TODO values buttonId and menuId are undefined here
  6601. button = this.button
  6602. .insertBefore( this.select )
  6603. .buttonMarkup( {
  6604. theme: options.theme,
  6605. icon: options.icon,
  6606. iconpos: iconpos,
  6607. inline: inline,
  6608. corners: options.corners,
  6609. shadow: options.shadow,
  6610. iconshadow: options.iconshadow,
  6611. mini: mini
  6612. });
  6613. this.setButtonText();
  6614. // Opera does not properly support opacity on select elements
  6615. // In Mini, it hides the element, but not its text
  6616. // On the desktop,it seems to do the opposite
  6617. // for these reasons, using the nativeMenu option results in a full native select in Opera
  6618. if ( options.nativeMenu && window.opera && window.opera.version ) {
  6619. button.addClass( "ui-select-nativeonly" );
  6620. }
  6621. // Add counter for multi selects
  6622. if ( this.isMultiple ) {
  6623. this.buttonCount = $( "<span>" )
  6624. .addClass( "ui-li-count ui-btn-up-c ui-btn-corner-all" )
  6625. .hide()
  6626. .appendTo( button.addClass('ui-li-has-count') );
  6627. }
  6628. // Disable if specified
  6629. if ( options.disabled || this.element.attr('disabled')) {
  6630. this.disable();
  6631. }
  6632. // Events on native select
  6633. this.select.change(function() {
  6634. self.refresh();
  6635. });
  6636. this.build();
  6637. },
  6638. build: function() {
  6639. var self = this;
  6640. this.select
  6641. .appendTo( self.button )
  6642. .bind( "vmousedown", function() {
  6643. // Add active class to button
  6644. self.button.addClass( $.mobile.activeBtnClass );
  6645. })
  6646. .bind( "focus", function() {
  6647. self.button.addClass( $.mobile.focusClass );
  6648. })
  6649. .bind( "blur", function() {
  6650. self.button.removeClass( $.mobile.focusClass );
  6651. })
  6652. .bind( "focus vmouseover", function() {
  6653. self.button.trigger( "vmouseover" );
  6654. })
  6655. .bind( "vmousemove", function() {
  6656. // Remove active class on scroll/touchmove
  6657. self.button.removeClass( $.mobile.activeBtnClass );
  6658. })
  6659. .bind( "change blur vmouseout", function() {
  6660. self.button.trigger( "vmouseout" )
  6661. .removeClass( $.mobile.activeBtnClass );
  6662. })
  6663. .bind( "change blur", function() {
  6664. self.button.removeClass( "ui-btn-down-" + self.options.theme );
  6665. });
  6666. // In many situations, iOS will zoom into the select upon tap, this prevents that from happening
  6667. self.button.bind( "vmousedown", function() {
  6668. if ( self.options.preventFocusZoom ) {
  6669. $.mobile.zoom.disable( true );
  6670. }
  6671. }).bind( "mouseup", function() {
  6672. if ( self.options.preventFocusZoom ) {
  6673. setTimeout(function() {
  6674. $.mobile.zoom.enable( true );
  6675. }, 0);
  6676. }
  6677. });
  6678. },
  6679. selected: function() {
  6680. return this._selectOptions().filter( ":selected" );
  6681. },
  6682. selectedIndices: function() {
  6683. var self = this;
  6684. return this.selected().map(function() {
  6685. return self._selectOptions().index( this );
  6686. }).get();
  6687. },
  6688. setButtonText: function() {
  6689. var self = this,
  6690. selected = this.selected(),
  6691. text = this.placeholder,
  6692. span = $( document.createElement( "span" ) );
  6693. this.button.find( ".ui-btn-text" ).html(function() {
  6694. if ( selected.length ) {
  6695. text = selected.map(function() {
  6696. return $( this ).text();
  6697. }).get().join( ", " );
  6698. } else {
  6699. text = self.placeholder;
  6700. }
  6701. // TODO possibly aggregate multiple select option classes
  6702. return span.text( text )
  6703. .addClass( self.select.attr( "class" ) )
  6704. .addClass( selected.attr( "class" ) );
  6705. });
  6706. },
  6707. setButtonCount: function() {
  6708. var selected = this.selected();
  6709. // multiple count inside button
  6710. if ( this.isMultiple ) {
  6711. this.buttonCount[ selected.length > 1 ? "show" : "hide" ]().text( selected.length );
  6712. }
  6713. },
  6714. refresh: function() {
  6715. this.setButtonText();
  6716. this.setButtonCount();
  6717. },
  6718. // open and close preserved in native selects
  6719. // to simplify users code when looping over selects
  6720. open: $.noop,
  6721. close: $.noop,
  6722. disable: function() {
  6723. this._setDisabled( true );
  6724. this.button.addClass( "ui-disabled" );
  6725. },
  6726. enable: function() {
  6727. this._setDisabled( false );
  6728. this.button.removeClass( "ui-disabled" );
  6729. }
  6730. });
  6731. //auto self-init widgets
  6732. $( document ).bind( "pagecreate create", function( e ) {
  6733. $.mobile.selectmenu.prototype.enhanceWithin( e.target, true );
  6734. });
  6735. })( jQuery );
  6736. /*
  6737. * custom "selectmenu" plugin
  6738. */
  6739. (function( $, undefined ) {
  6740. var extendSelect = function( widget ) {
  6741. var select = widget.select,
  6742. selectID = widget.selectID,
  6743. label = widget.label,
  6744. thisPage = widget.select.closest( ".ui-page" ),
  6745. selectOptions = widget._selectOptions(),
  6746. isMultiple = widget.isMultiple = widget.select[ 0 ].multiple,
  6747. buttonId = selectID + "-button",
  6748. menuId = selectID + "-menu",
  6749. menuPage = $( "<div data-" + $.mobile.ns + "role='dialog' data-" +$.mobile.ns + "theme='"+ widget.options.theme +"' data-" +$.mobile.ns + "overlay-theme='"+ widget.options.overlayTheme +"'>" +
  6750. "<div data-" + $.mobile.ns + "role='header'>" +
  6751. "<div class='ui-title'>" + label.getEncodedText() + "</div>"+
  6752. "</div>"+
  6753. "<div data-" + $.mobile.ns + "role='content'></div>"+
  6754. "</div>" ),
  6755. listbox = $( "<div>", { "class": "ui-selectmenu" } ).insertAfter( widget.select ).popup( { theme: "a" } ),
  6756. list = $( "<ul>", {
  6757. "class": "ui-selectmenu-list",
  6758. "id": menuId,
  6759. "role": "listbox",
  6760. "aria-labelledby": buttonId
  6761. }).attr( "data-" + $.mobile.ns + "theme", widget.options.theme ).appendTo( listbox ),
  6762. header = $( "<div>", {
  6763. "class": "ui-header ui-bar-" + widget.options.theme
  6764. }).prependTo( listbox ),
  6765. headerTitle = $( "<h1>", {
  6766. "class": "ui-title"
  6767. }).appendTo( header ),
  6768. menuPageContent,
  6769. menuPageClose,
  6770. headerClose;
  6771. if ( widget.isMultiple ) {
  6772. headerClose = $( "<a>", {
  6773. "text": widget.options.closeText,
  6774. "href": "#",
  6775. "class": "ui-btn-left"
  6776. }).attr( "data-" + $.mobile.ns + "iconpos", "notext" ).attr( "data-" + $.mobile.ns + "icon", "delete" ).appendTo( header ).buttonMarkup();
  6777. }
  6778. $.extend( widget, {
  6779. select: widget.select,
  6780. selectID: selectID,
  6781. buttonId: buttonId,
  6782. menuId: menuId,
  6783. thisPage: thisPage,
  6784. menuPage: menuPage,
  6785. label: label,
  6786. selectOptions: selectOptions,
  6787. isMultiple: isMultiple,
  6788. theme: widget.options.theme,
  6789. listbox: listbox,
  6790. list: list,
  6791. header: header,
  6792. headerTitle: headerTitle,
  6793. headerClose: headerClose,
  6794. menuPageContent: menuPageContent,
  6795. menuPageClose: menuPageClose,
  6796. placeholder: "",
  6797. build: function() {
  6798. var self = this;
  6799. // Create list from select, update state
  6800. self.refresh();
  6801. self.select.attr( "tabindex", "-1" ).focus(function() {
  6802. $( this ).blur();
  6803. self.button.focus();
  6804. });
  6805. // Button events
  6806. self.button.bind( "vclick keydown" , function( event ) {
  6807. if (event.type === "vclick" ||
  6808. event.keyCode && (event.keyCode === $.mobile.keyCode.ENTER ||
  6809. event.keyCode === $.mobile.keyCode.SPACE)) {
  6810. self.open();
  6811. event.preventDefault();
  6812. }
  6813. });
  6814. // Events for list items
  6815. self.list.attr( "role", "listbox" )
  6816. .bind( "focusin", function( e ) {
  6817. $( e.target )
  6818. .attr( "tabindex", "0" )
  6819. .trigger( "vmouseover" );
  6820. })
  6821. .bind( "focusout", function( e ) {
  6822. $( e.target )
  6823. .attr( "tabindex", "-1" )
  6824. .trigger( "vmouseout" );
  6825. })
  6826. .delegate( "li:not(.ui-disabled, .ui-li-divider)", "click", function( event ) {
  6827. // index of option tag to be selected
  6828. var oldIndex = self.select[ 0 ].selectedIndex,
  6829. newIndex = self.list.find( "li:not(.ui-li-divider)" ).index( this ),
  6830. option = self._selectOptions().eq( newIndex )[ 0 ];
  6831. // toggle selected status on the tag for multi selects
  6832. option.selected = self.isMultiple ? !option.selected : true;
  6833. // toggle checkbox class for multiple selects
  6834. if ( self.isMultiple ) {
  6835. $( this ).find( ".ui-icon" )
  6836. .toggleClass( "ui-icon-checkbox-on", option.selected )
  6837. .toggleClass( "ui-icon-checkbox-off", !option.selected );
  6838. }
  6839. // trigger change if value changed
  6840. if ( self.isMultiple || oldIndex !== newIndex ) {
  6841. self.select.trigger( "change" );
  6842. }
  6843. // hide custom select for single selects only - otherwise focus clicked item
  6844. // We need to grab the clicked item the hard way, because the list may have been rebuilt
  6845. if ( self.isMultiple ) {
  6846. self.list.find( "li:not(.ui-li-divider)" ).eq( newIndex )
  6847. .addClass( "ui-btn-down-" + widget.options.theme ).find( "a" ).first().focus();
  6848. }
  6849. else {
  6850. self.close();
  6851. }
  6852. event.preventDefault();
  6853. })
  6854. .keydown(function( event ) { //keyboard events for menu items
  6855. var target = $( event.target ),
  6856. li = target.closest( "li" ),
  6857. prev, next;
  6858. // switch logic based on which key was pressed
  6859. switch ( event.keyCode ) {
  6860. // up or left arrow keys
  6861. case 38:
  6862. prev = li.prev().not( ".ui-selectmenu-placeholder" );
  6863. if ( prev.is( ".ui-li-divider" ) ) {
  6864. prev = prev.prev();
  6865. }
  6866. // if there's a previous option, focus it
  6867. if ( prev.length ) {
  6868. target
  6869. .blur()
  6870. .attr( "tabindex", "-1" );
  6871. prev.addClass( "ui-btn-down-" + widget.options.theme ).find( "a" ).first().focus();
  6872. }
  6873. return false;
  6874. // down or right arrow keys
  6875. case 40:
  6876. next = li.next();
  6877. if ( next.is( ".ui-li-divider" ) ) {
  6878. next = next.next();
  6879. }
  6880. // if there's a next option, focus it
  6881. if ( next.length ) {
  6882. target
  6883. .blur()
  6884. .attr( "tabindex", "-1" );
  6885. next.addClass( "ui-btn-down-" + widget.options.theme ).find( "a" ).first().focus();
  6886. }
  6887. return false;
  6888. // If enter or space is pressed, trigger click
  6889. case 13:
  6890. case 32:
  6891. target.trigger( "click" );
  6892. return false;
  6893. }
  6894. });
  6895. // button refocus ensures proper height calculation
  6896. // by removing the inline style and ensuring page inclusion
  6897. self.menuPage.bind( "pagehide", function() {
  6898. self.list.appendTo( self.listbox );
  6899. self._focusButton();
  6900. // TODO centralize page removal binding / handling in the page plugin.
  6901. // Suggestion from @jblas to do refcounting
  6902. //
  6903. // TODO extremely confusing dependency on the open method where the pagehide.remove
  6904. // bindings are stripped to prevent the parent page from disappearing. The way
  6905. // we're keeping pages in the DOM right now sucks
  6906. //
  6907. // rebind the page remove that was unbound in the open function
  6908. // to allow for the parent page removal from actions other than the use
  6909. // of a dialog sized custom select
  6910. //
  6911. // doing this here provides for the back button on the custom select dialog
  6912. $.mobile._bindPageRemove.call( self.thisPage );
  6913. });
  6914. // Events on the popup
  6915. self.listbox.bind( "popupafterclose", function( event ) {
  6916. self.close();
  6917. });
  6918. // Close button on small overlays
  6919. if ( self.isMultiple ) {
  6920. self.headerClose.click(function() {
  6921. if ( self.menuType === "overlay" ) {
  6922. self.close();
  6923. return false;
  6924. }
  6925. });
  6926. }
  6927. // track this dependency so that when the parent page
  6928. // is removed on pagehide it will also remove the menupage
  6929. self.thisPage.addDependents( this.menuPage );
  6930. },
  6931. _isRebuildRequired: function() {
  6932. var list = this.list.find( "li" ),
  6933. options = this._selectOptions();
  6934. // TODO exceedingly naive method to determine difference
  6935. // ignores value changes etc in favor of a forcedRebuild
  6936. // from the user in the refresh method
  6937. return options.text() !== list.text();
  6938. },
  6939. selected: function() {
  6940. return this._selectOptions().filter( ":selected:not( :jqmData(placeholder='true') )" );
  6941. },
  6942. refresh: function( forceRebuild , foo ) {
  6943. var self = this,
  6944. select = this.element,
  6945. isMultiple = this.isMultiple,
  6946. indicies;
  6947. if ( forceRebuild || this._isRebuildRequired() ) {
  6948. self._buildList();
  6949. }
  6950. indicies = this.selectedIndices();
  6951. self.setButtonText();
  6952. self.setButtonCount();
  6953. self.list.find( "li:not(.ui-li-divider)" )
  6954. .removeClass( $.mobile.activeBtnClass )
  6955. .attr( "aria-selected", false )
  6956. .each(function( i ) {
  6957. if ( $.inArray( i, indicies ) > -1 ) {
  6958. var item = $( this );
  6959. // Aria selected attr
  6960. item.attr( "aria-selected", true );
  6961. // Multiple selects: add the "on" checkbox state to the icon
  6962. if ( self.isMultiple ) {
  6963. item.find( ".ui-icon" ).removeClass( "ui-icon-checkbox-off" ).addClass( "ui-icon-checkbox-on" );
  6964. } else {
  6965. if ( item.is( ".ui-selectmenu-placeholder" ) ) {
  6966. item.next().addClass( $.mobile.activeBtnClass );
  6967. } else {
  6968. item.addClass( $.mobile.activeBtnClass );
  6969. }
  6970. }
  6971. }
  6972. });
  6973. },
  6974. close: function() {
  6975. if ( this.options.disabled || !this.isOpen ) {
  6976. return;
  6977. }
  6978. var self = this;
  6979. if ( self.menuType === "page" ) {
  6980. // doesn't solve the possible issue with calling change page
  6981. // where the objects don't define data urls which prevents dialog key
  6982. // stripping - changePage has incoming refactor
  6983. $.mobile.back();
  6984. } else {
  6985. self.listbox.popup( "close" );
  6986. self.list.appendTo( self.listbox );
  6987. self._focusButton();
  6988. }
  6989. // allow the dialog to be closed again
  6990. self.isOpen = false;
  6991. },
  6992. open: function() {
  6993. if ( this.options.disabled ) {
  6994. return;
  6995. }
  6996. var self = this,
  6997. $window = $( window ),
  6998. selfListParent = self.list.parent(),
  6999. menuHeight = selfListParent.outerHeight(),
  7000. menuWidth = selfListParent.outerWidth(),
  7001. activePage = $( "." + $.mobile.activePageClass ),
  7002. scrollTop = $window.scrollTop(),
  7003. btnOffset = self.button.offset().top,
  7004. screenHeight = $window.height(),
  7005. screenWidth = $window.width();
  7006. //add active class to button
  7007. self.button.addClass( $.mobile.activeBtnClass );
  7008. //remove after delay
  7009. setTimeout( function() {
  7010. self.button.removeClass( $.mobile.activeBtnClass );
  7011. }, 300);
  7012. function focusMenuItem() {
  7013. var selector = self.list.find( "." + $.mobile.activeBtnClass + " a" );
  7014. if ( selector.length === 0 ) {
  7015. selector = self.list.find( "li.ui-btn:not( :jqmData(placeholder='true') ) a" );
  7016. }
  7017. selector.first().focus().closest( "li" ).addClass( "ui-btn-down-" + widget.options.theme );
  7018. }
  7019. if ( menuHeight > screenHeight - 80 || !$.support.scrollTop ) {
  7020. self.menuPage.appendTo( $.mobile.pageContainer ).page();
  7021. self.menuPageContent = menuPage.find( ".ui-content" );
  7022. self.menuPageClose = menuPage.find( ".ui-header a" );
  7023. // prevent the parent page from being removed from the DOM,
  7024. // otherwise the results of selecting a list item in the dialog
  7025. // fall into a black hole
  7026. self.thisPage.unbind( "pagehide.remove" );
  7027. //for WebOS/Opera Mini (set lastscroll using button offset)
  7028. if ( scrollTop === 0 && btnOffset > screenHeight ) {
  7029. self.thisPage.one( "pagehide", function() {
  7030. $( this ).jqmData( "lastScroll", btnOffset );
  7031. });
  7032. }
  7033. self.menuPage.one( "pageshow", function() {
  7034. focusMenuItem();
  7035. self.isOpen = true;
  7036. });
  7037. self.menuType = "page";
  7038. self.menuPageContent.append( self.list );
  7039. self.menuPage.find("div .ui-title").text(self.label.text());
  7040. $.mobile.changePage( self.menuPage, {
  7041. transition: $.mobile.defaultDialogTransition
  7042. });
  7043. } else {
  7044. self.menuType = "overlay";
  7045. self.listbox
  7046. .one( "popupafteropen", focusMenuItem )
  7047. .popup( "open", {
  7048. x: self.button.offset().left + self.button.outerWidth() / 2,
  7049. y: self.button.offset().top + self.button.outerHeight() / 2
  7050. });
  7051. // duplicate with value set in page show for dialog sized selects
  7052. self.isOpen = true;
  7053. }
  7054. },
  7055. _buildList: function() {
  7056. var self = this,
  7057. o = this.options,
  7058. placeholder = this.placeholder,
  7059. needPlaceholder = true,
  7060. optgroups = [],
  7061. lis = [],
  7062. dataIcon = self.isMultiple ? "checkbox-off" : "false";
  7063. self.list.empty().filter( ".ui-listview" ).listview( "destroy" );
  7064. var $options = self.select.find( "option" ),
  7065. numOptions = $options.length,
  7066. select = this.select[ 0 ],
  7067. dataPrefix = 'data-' + $.mobile.ns,
  7068. dataIndexAttr = dataPrefix + 'option-index',
  7069. dataIconAttr = dataPrefix + 'icon',
  7070. dataRoleAttr = dataPrefix + 'role',
  7071. dataPlaceholderAttr = dataPrefix + 'placeholder',
  7072. fragment = document.createDocumentFragment(),
  7073. isPlaceholderItem = false,
  7074. optGroup;
  7075. for (var i = 0; i < numOptions;i++, isPlaceholderItem = false) {
  7076. var option = $options[i],
  7077. $option = $( option ),
  7078. parent = option.parentNode,
  7079. text = $option.text(),
  7080. anchor = document.createElement( 'a' ),
  7081. classes = [];
  7082. anchor.setAttribute( 'href', '#' );
  7083. anchor.appendChild( document.createTextNode( text ) );
  7084. // Are we inside an optgroup?
  7085. if ( parent !== select && parent.nodeName.toLowerCase() === "optgroup" ) {
  7086. var optLabel = parent.getAttribute( 'label' );
  7087. if ( optLabel !== optGroup ) {
  7088. var divider = document.createElement( 'li' );
  7089. divider.setAttribute( dataRoleAttr, 'list-divider' );
  7090. divider.setAttribute( 'role', 'option' );
  7091. divider.setAttribute( 'tabindex', '-1' );
  7092. divider.appendChild( document.createTextNode( optLabel ) );
  7093. fragment.appendChild( divider );
  7094. optGroup = optLabel;
  7095. }
  7096. }
  7097. if ( needPlaceholder && ( !option.getAttribute( "value" ) || text.length === 0 || $option.jqmData( "placeholder" ) ) ) {
  7098. needPlaceholder = false;
  7099. isPlaceholderItem = true;
  7100. // If we have identified a placeholder, mark it retroactively in the select as well
  7101. option.setAttribute( dataPlaceholderAttr, true );
  7102. if ( o.hidePlaceholderMenuItems ) {
  7103. classes.push( "ui-selectmenu-placeholder" );
  7104. }
  7105. if (!placeholder) {
  7106. placeholder = self.placeholder = text;
  7107. }
  7108. }
  7109. var item = document.createElement('li');
  7110. if ( option.disabled ) {
  7111. classes.push( "ui-disabled" );
  7112. item.setAttribute('aria-disabled',true);
  7113. }
  7114. item.setAttribute( dataIndexAttr,i );
  7115. item.setAttribute( dataIconAttr, dataIcon );
  7116. if ( isPlaceholderItem ) {
  7117. item.setAttribute( dataPlaceholderAttr, true );
  7118. }
  7119. item.className = classes.join( " " );
  7120. item.setAttribute( 'role', 'option' );
  7121. anchor.setAttribute( 'tabindex', '-1' );
  7122. item.appendChild( anchor );
  7123. fragment.appendChild( item );
  7124. }
  7125. self.list[0].appendChild( fragment );
  7126. // Hide header if it's not a multiselect and there's no placeholder
  7127. if ( !this.isMultiple && !placeholder.length ) {
  7128. this.header.hide();
  7129. } else {
  7130. this.headerTitle.text( this.placeholder );
  7131. }
  7132. // Now populated, create listview
  7133. self.list.listview();
  7134. },
  7135. _button: function() {
  7136. return $( "<a>", {
  7137. "href": "#",
  7138. "role": "button",
  7139. // TODO value is undefined at creation
  7140. "id": this.buttonId,
  7141. "aria-haspopup": "true",
  7142. // TODO value is undefined at creation
  7143. "aria-owns": this.menuId
  7144. });
  7145. }
  7146. });
  7147. };
  7148. // issue #3894 - core doesn't trigger events on disabled delegates
  7149. $( document ).bind( "selectmenubeforecreate", function( event ) {
  7150. var selectmenuWidget = $( event.target ).data( "selectmenu" );
  7151. if ( !selectmenuWidget.options.nativeMenu &&
  7152. selectmenuWidget.element.parents( ":jqmData(role='popup')" ).length === 0 ) {
  7153. extendSelect( selectmenuWidget );
  7154. }
  7155. });
  7156. })( jQuery );
  7157. (function( $, undefined ) {
  7158. $.widget( "mobile.fixedtoolbar", $.mobile.widget, {
  7159. options: {
  7160. visibleOnPageShow: true,
  7161. disablePageZoom: true,
  7162. transition: "slide", //can be none, fade, slide (slide maps to slideup or slidedown)
  7163. fullscreen: false,
  7164. tapToggle: true,
  7165. tapToggleBlacklist: "a, button, input, select, textarea, .ui-header-fixed, .ui-footer-fixed, .ui-popup",
  7166. hideDuringFocus: "input, textarea, select",
  7167. updatePagePadding: true,
  7168. trackPersistentToolbars: true,
  7169. // Browser detection! Weeee, here we go...
  7170. // Unfortunately, position:fixed is costly, not to mention probably impossible, to feature-detect accurately.
  7171. // Some tests exist, but they currently return false results in critical devices and browsers, which could lead to a broken experience.
  7172. // Testing fixed positioning is also pretty obtrusive to page load, requiring injected elements and scrolling the window
  7173. // The following function serves to rule out some popular browsers with known fixed-positioning issues
  7174. // This is a plugin option like any other, so feel free to improve or overwrite it
  7175. supportBlacklist: function() {
  7176. var w = window,
  7177. ua = navigator.userAgent,
  7178. platform = navigator.platform,
  7179. // Rendering engine is Webkit, and capture major version
  7180. wkmatch = ua.match( /AppleWebKit\/([0-9]+)/ ),
  7181. wkversion = !!wkmatch && wkmatch[ 1 ],
  7182. ffmatch = ua.match( /Fennec\/([0-9]+)/ ),
  7183. ffversion = !!ffmatch && ffmatch[ 1 ],
  7184. operammobilematch = ua.match( /Opera Mobi\/([0-9]+)/ ),
  7185. omversion = !!operammobilematch && operammobilematch[ 1 ];
  7186. if(
  7187. // iOS 4.3 and older : Platform is iPhone/Pad/Touch and Webkit version is less than 534 (ios5)
  7188. ( ( platform.indexOf( "iPhone" ) > -1 || platform.indexOf( "iPad" ) > -1 || platform.indexOf( "iPod" ) > -1 ) && wkversion && wkversion < 534 ) ||
  7189. // Opera Mini
  7190. ( w.operamini && ({}).toString.call( w.operamini ) === "[object OperaMini]" ) ||
  7191. ( operammobilematch && omversion < 7458 ) ||
  7192. //Android lte 2.1: Platform is Android and Webkit version is less than 533 (Android 2.2)
  7193. ( ua.indexOf( "Android" ) > -1 && wkversion && wkversion < 533 ) ||
  7194. // Firefox Mobile before 6.0 -
  7195. ( ffversion && ffversion < 6 ) ||
  7196. // WebOS less than 3
  7197. ( "palmGetResource" in window && wkversion && wkversion < 534 ) ||
  7198. // MeeGo
  7199. ( ua.indexOf( "MeeGo" ) > -1 && ua.indexOf( "NokiaBrowser/8.5.0" ) > -1 ) ) {
  7200. return true;
  7201. }
  7202. return false;
  7203. },
  7204. initSelector: ":jqmData(position='fixed')"
  7205. },
  7206. _create: function() {
  7207. var self = this,
  7208. o = self.options,
  7209. $el = self.element,
  7210. tbtype = $el.is( ":jqmData(role='header')" ) ? "header" : "footer",
  7211. $page = $el.closest( ".ui-page" );
  7212. // Feature detecting support for
  7213. if ( o.supportBlacklist() ) {
  7214. self.destroy();
  7215. return;
  7216. }
  7217. $el.addClass( "ui-"+ tbtype +"-fixed" );
  7218. // "fullscreen" overlay positioning
  7219. if ( o.fullscreen ) {
  7220. $el.addClass( "ui-"+ tbtype +"-fullscreen" );
  7221. $page.addClass( "ui-page-" + tbtype + "-fullscreen" );
  7222. }
  7223. // If not fullscreen, add class to page to set top or bottom padding
  7224. else{
  7225. $page.addClass( "ui-page-" + tbtype + "-fixed" );
  7226. }
  7227. self._addTransitionClass();
  7228. self._bindPageEvents();
  7229. self._bindToggleHandlers();
  7230. },
  7231. _addTransitionClass: function() {
  7232. var tclass = this.options.transition;
  7233. if ( tclass && tclass !== "none" ) {
  7234. // use appropriate slide for header or footer
  7235. if ( tclass === "slide" ) {
  7236. tclass = this.element.is( ".ui-header" ) ? "slidedown" : "slideup";
  7237. }
  7238. this.element.addClass( tclass );
  7239. }
  7240. },
  7241. _bindPageEvents: function() {
  7242. var self = this,
  7243. o = self.options,
  7244. $el = self.element;
  7245. //page event bindings
  7246. // Fixed toolbars require page zoom to be disabled, otherwise usability issues crop up
  7247. // This method is meant to disable zoom while a fixed-positioned toolbar page is visible
  7248. $el.closest( ".ui-page" )
  7249. .bind( "pagebeforeshow", function() {
  7250. if ( o.disablePageZoom ) {
  7251. $.mobile.zoom.disable( true );
  7252. }
  7253. if ( !o.visibleOnPageShow ) {
  7254. self.hide( true );
  7255. }
  7256. } )
  7257. .bind( "webkitAnimationStart animationstart updatelayout", function() {
  7258. var thisPage = this;
  7259. if ( o.updatePagePadding ) {
  7260. self.updatePagePadding( thisPage );
  7261. }
  7262. })
  7263. .bind( "pageshow", function() {
  7264. var thisPage = this;
  7265. self.updatePagePadding( thisPage );
  7266. if ( o.updatePagePadding ) {
  7267. $( window ).bind( "throttledresize." + self.widgetName, function() {
  7268. self.updatePagePadding( thisPage );
  7269. });
  7270. }
  7271. })
  7272. .bind( "pagebeforehide", function( e, ui ) {
  7273. if ( o.disablePageZoom ) {
  7274. $.mobile.zoom.enable( true );
  7275. }
  7276. if ( o.updatePagePadding ) {
  7277. $( window ).unbind( "throttledresize." + self.widgetName );
  7278. }
  7279. if ( o.trackPersistentToolbars ) {
  7280. var thisFooter = $( ".ui-footer-fixed:jqmData(id)", this ),
  7281. thisHeader = $( ".ui-header-fixed:jqmData(id)", this ),
  7282. nextFooter = thisFooter.length && ui.nextPage && $( ".ui-footer-fixed:jqmData(id='" + thisFooter.jqmData( "id" ) + "')", ui.nextPage ) || $(),
  7283. nextHeader = thisHeader.length && ui.nextPage && $( ".ui-header-fixed:jqmData(id='" + thisHeader.jqmData( "id" ) + "')", ui.nextPage ) || $();
  7284. if ( nextFooter.length || nextHeader.length ) {
  7285. nextFooter.add( nextHeader ).appendTo( $.mobile.pageContainer );
  7286. ui.nextPage.one( "pageshow", function() {
  7287. nextFooter.add( nextHeader ).appendTo( this );
  7288. });
  7289. }
  7290. }
  7291. });
  7292. },
  7293. _visible: true,
  7294. // This will set the content element's top or bottom padding equal to the toolbar's height
  7295. updatePagePadding: function( tbPage ) {
  7296. var $el = this.element,
  7297. header = $el.is( ".ui-header" );
  7298. // This behavior only applies to "fixed", not "fullscreen"
  7299. if ( this.options.fullscreen ) { return; }
  7300. tbPage = tbPage || $el.closest( ".ui-page" );
  7301. $( tbPage ).css( "padding-" + ( header ? "top" : "bottom" ), $el.outerHeight() );
  7302. },
  7303. _useTransition: function( notransition ) {
  7304. var $win = $( window ),
  7305. $el = this.element,
  7306. scroll = $win.scrollTop(),
  7307. elHeight = $el.height(),
  7308. pHeight = $el.closest( ".ui-page" ).height(),
  7309. viewportHeight = $.mobile.getScreenHeight(),
  7310. tbtype = $el.is( ":jqmData(role='header')" ) ? "header" : "footer";
  7311. return !notransition &&
  7312. ( this.options.transition && this.options.transition !== "none" &&
  7313. (
  7314. ( tbtype === "header" && !this.options.fullscreen && scroll > elHeight ) ||
  7315. ( tbtype === "footer" && !this.options.fullscreen && scroll + viewportHeight < pHeight - elHeight )
  7316. ) || this.options.fullscreen
  7317. );
  7318. },
  7319. show: function( notransition ) {
  7320. var hideClass = "ui-fixed-hidden",
  7321. $el = this.element;
  7322. if ( this._useTransition( notransition ) ) {
  7323. $el
  7324. .removeClass( "out " + hideClass )
  7325. .addClass( "in" );
  7326. }
  7327. else {
  7328. $el.removeClass( hideClass );
  7329. }
  7330. this._visible = true;
  7331. },
  7332. hide: function( notransition ) {
  7333. var hideClass = "ui-fixed-hidden",
  7334. $el = this.element,
  7335. // if it's a slide transition, our new transitions need the reverse class as well to slide outward
  7336. outclass = "out" + ( this.options.transition === "slide" ? " reverse" : "" );
  7337. if( this._useTransition( notransition ) ) {
  7338. $el
  7339. .addClass( outclass )
  7340. .removeClass( "in" )
  7341. .animationComplete(function() {
  7342. $el.addClass( hideClass ).removeClass( outclass );
  7343. });
  7344. }
  7345. else {
  7346. $el.addClass( hideClass ).removeClass( outclass );
  7347. }
  7348. this._visible = false;
  7349. },
  7350. toggle: function() {
  7351. this[ this._visible ? "hide" : "show" ]();
  7352. },
  7353. _bindToggleHandlers: function() {
  7354. var self = this,
  7355. o = self.options,
  7356. $el = self.element;
  7357. // tap toggle
  7358. $el.closest( ".ui-page" )
  7359. .bind( "vclick", function( e ) {
  7360. if ( o.tapToggle && !$( e.target ).closest( o.tapToggleBlacklist ).length ) {
  7361. self.toggle();
  7362. }
  7363. })
  7364. .bind( "focusin focusout", function( e ) {
  7365. if ( screen.width < 500 && $( e.target ).is( o.hideDuringFocus ) && !$( e.target ).closest( ".ui-header-fixed, .ui-footer-fixed" ).length ) {
  7366. self[ ( e.type === "focusin" && self._visible ) ? "hide" : "show" ]();
  7367. }
  7368. });
  7369. },
  7370. destroy: function() {
  7371. this.element.removeClass( "ui-header-fixed ui-footer-fixed ui-header-fullscreen ui-footer-fullscreen in out fade slidedown slideup ui-fixed-hidden" );
  7372. this.element.closest( ".ui-page" ).removeClass( "ui-page-header-fixed ui-page-footer-fixed ui-page-header-fullscreen ui-page-footer-fullscreen" );
  7373. }
  7374. });
  7375. //auto self-init widgets
  7376. $( document )
  7377. .bind( "pagecreate create", function( e ) {
  7378. // DEPRECATED in 1.1: support for data-fullscreen=true|false on the page element.
  7379. // This line ensures it still works, but we recommend moving the attribute to the toolbars themselves.
  7380. if ( $( e.target ).jqmData( "fullscreen" ) ) {
  7381. $( $.mobile.fixedtoolbar.prototype.options.initSelector, e.target ).not( ":jqmData(fullscreen)" ).jqmData( "fullscreen", true );
  7382. }
  7383. $.mobile.fixedtoolbar.prototype.enhanceWithin( e.target );
  7384. });
  7385. })( jQuery );
  7386. (function( $, window ) {
  7387. // This fix addresses an iOS bug, so return early if the UA claims it's something else.
  7388. if ( !(/iPhone|iPad|iPod/.test( navigator.platform ) && navigator.userAgent.indexOf( "AppleWebKit" ) > -1 ) ) {
  7389. return;
  7390. }
  7391. var zoom = $.mobile.zoom,
  7392. evt, x, y, z, aig;
  7393. function checkTilt( e ) {
  7394. evt = e.originalEvent;
  7395. aig = evt.accelerationIncludingGravity;
  7396. x = Math.abs( aig.x );
  7397. y = Math.abs( aig.y );
  7398. z = Math.abs( aig.z );
  7399. // If portrait orientation and in one of the danger zones
  7400. if ( !window.orientation && ( x > 7 || ( ( z > 6 && y < 8 || z < 8 && y > 6 ) && x > 5 ) ) ) {
  7401. if ( zoom.enabled ) {
  7402. zoom.disable();
  7403. }
  7404. } else if ( !zoom.enabled ) {
  7405. zoom.enable();
  7406. }
  7407. }
  7408. $( window )
  7409. .bind( "orientationchange.iosorientationfix", zoom.enable )
  7410. .bind( "devicemotion.iosorientationfix", checkTilt );
  7411. }( jQuery, this ));
  7412. (function( $, window, undefined ) {
  7413. var $html = $( "html" ),
  7414. $head = $( "head" ),
  7415. $window = $( window );
  7416. //remove initial build class (only present on first pageshow)
  7417. function hideRenderingClass() {
  7418. $html.removeClass( "ui-mobile-rendering" );
  7419. }
  7420. // trigger mobileinit event - useful hook for configuring $.mobile settings before they're used
  7421. $( window.document ).trigger( "mobileinit" );
  7422. // support conditions
  7423. // if device support condition(s) aren't met, leave things as they are -> a basic, usable experience,
  7424. // otherwise, proceed with the enhancements
  7425. if ( !$.mobile.gradeA() ) {
  7426. return;
  7427. }
  7428. // override ajaxEnabled on platforms that have known conflicts with hash history updates
  7429. // or generally work better browsing in regular http for full page refreshes (BB5, Opera Mini)
  7430. if ( $.mobile.ajaxBlacklist ) {
  7431. $.mobile.ajaxEnabled = false;
  7432. }
  7433. // Add mobile, initial load "rendering" classes to docEl
  7434. $html.addClass( "ui-mobile ui-mobile-rendering" );
  7435. // This is a fallback. If anything goes wrong (JS errors, etc), or events don't fire,
  7436. // this ensures the rendering class is removed after 5 seconds, so content is visible and accessible
  7437. setTimeout( hideRenderingClass, 5000 );
  7438. $.extend( $.mobile, {
  7439. // find and enhance the pages in the dom and transition to the first page.
  7440. initializePage: function() {
  7441. // find present pages
  7442. var $pages = $( ":jqmData(role='page'), :jqmData(role='dialog')" ),
  7443. hash = $.mobile.path.parseLocation().hash.replace("#", ""),
  7444. hashPage = document.getElementById( hash );
  7445. // if no pages are found, create one with body's inner html
  7446. if ( !$pages.length ) {
  7447. $pages = $( "body" ).wrapInner( "<div data-" + $.mobile.ns + "role='page'></div>" ).children( 0 );
  7448. }
  7449. // add dialogs, set data-url attrs
  7450. $pages.each(function() {
  7451. var $this = $( this );
  7452. // unless the data url is already set set it to the pathname
  7453. if ( !$this.jqmData( "url" ) ) {
  7454. $this.attr( "data-" + $.mobile.ns + "url", $this.attr( "id" ) || location.pathname + location.search );
  7455. }
  7456. });
  7457. // define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback)
  7458. $.mobile.firstPage = $pages.first();
  7459. // define page container
  7460. $.mobile.pageContainer = $pages.first().parent().addClass( "ui-mobile-viewport" );
  7461. // alert listeners that the pagecontainer has been determined for binding
  7462. // to events triggered on it
  7463. $window.trigger( "pagecontainercreate" );
  7464. // cue page loading message
  7465. $.mobile.showPageLoadingMsg();
  7466. //remove initial build class (only present on first pageshow)
  7467. hideRenderingClass();
  7468. // if hashchange listening is disabled, there's no hash deeplink,
  7469. // the hash is not valid (contains more than one # or does not start with #)
  7470. // or there is no page with that hash, change to the first page in the DOM
  7471. // Remember, however, that the hash can also be a path!
  7472. if ( ! ( $.mobile.hashListeningEnabled &&
  7473. $.mobile.path.isHashValid( location.hash ) &&
  7474. ( $( hashPage ).is( ':jqmData(role="page")' ) ||
  7475. $.mobile.path.isPath( hash ) ||
  7476. hash === $.mobile.dialogHashKey ) ) ) {
  7477. // Store the initial destination
  7478. if ( $.mobile.path.isHashValid( location.hash ) ) {
  7479. $.mobile.urlHistory.initialDst = hash.replace( "#", "" );
  7480. }
  7481. $.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
  7482. }
  7483. // otherwise, trigger a hashchange to load a deeplink
  7484. else {
  7485. $window.trigger( "hashchange", [ true ] );
  7486. }
  7487. }
  7488. });
  7489. // initialize events now, after mobileinit has occurred
  7490. $.mobile.navreadyDeferred.resolve();
  7491. // check which scrollTop value should be used by scrolling to 1 immediately at domready
  7492. // then check what the scroll top is. Android will report 0... others 1
  7493. // note that this initial scroll won't hide the address bar. It's just for the check.
  7494. $(function() {
  7495. window.scrollTo( 0, 1 );
  7496. // if defaultHomeScroll hasn't been set yet, see if scrollTop is 1
  7497. // it should be 1 in most browsers, but android treats 1 as 0 (for hiding addr bar)
  7498. // so if it's 1, use 0 from now on
  7499. $.mobile.defaultHomeScroll = ( !$.support.scrollTop || $( window ).scrollTop() === 1 ) ? 0 : 1;
  7500. // TODO: Implement a proper registration mechanism with dependency handling in order to not have exceptions like the one below
  7501. //auto self-init widgets for those widgets that have a soft dependency on others
  7502. if ( $.fn.controlgroup ) {
  7503. $( document ).bind( "pagecreate create", function( e ) {
  7504. $( ":jqmData(role='controlgroup')", e.target )
  7505. .jqmEnhanceable()
  7506. .controlgroup({ excludeInvisible: false });
  7507. });
  7508. }
  7509. //dom-ready inits
  7510. if ( $.mobile.autoInitializePage ) {
  7511. $.mobile.initializePage();
  7512. }
  7513. // window load event
  7514. // hide iOS browser chrome on load
  7515. $window.load( $.mobile.silentScroll );
  7516. if ( !$.support.cssPointerEvents ) {
  7517. // IE and Opera don't support CSS pointer-events: none that we use to disable link-based buttons
  7518. // by adding the 'ui-disabled' class to them. Using a JavaScript workaround for those browser.
  7519. // https://github.com/jquery/jquery-mobile/issues/3558
  7520. $( document ).delegate( ".ui-disabled", "vclick",
  7521. function( e ) {
  7522. e.preventDefault();
  7523. e.stopImmediatePropagation();
  7524. }
  7525. );
  7526. }
  7527. });
  7528. }( jQuery, this ));
  7529. }));