angular-material.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704
  1. /*!
  2. * AngularJS Material Design
  3. * https://github.com/angular/material
  4. * @license MIT
  5. * v1.1.8-master-aba7b2b
  6. */
  7. (function( window, angular, undefined ){
  8. "use strict";
  9. (function(){
  10. "use strict";
  11. angular.module('ngMaterial', ["ng","ngAnimate","ngAria","material.core","material.core.gestures","material.core.interaction","material.core.layout","material.core.meta","material.core.theming.palette","material.core.theming","material.core.animate","material.components.autocomplete","material.components.backdrop","material.components.bottomSheet","material.components.button","material.components.card","material.components.checkbox","material.components.chips","material.components.colors","material.components.content","material.components.datepicker","material.components.dialog","material.components.divider","material.components.fabActions","material.components.fabShared","material.components.fabSpeedDial","material.components.fabToolbar","material.components.gridList","material.components.icon","material.components.input","material.components.list","material.components.menu","material.components.menuBar","material.components.navBar","material.components.panel","material.components.progressCircular","material.components.progressLinear","material.components.radioButton","material.components.select","material.components.showHide","material.components.sidenav","material.components.slider","material.components.sticky","material.components.subheader","material.components.swipe","material.components.switch","material.components.tabs","material.components.toast","material.components.toolbar","material.components.tooltip","material.components.truncate","material.components.virtualRepeat","material.components.whiteframe"]);
  12. })();
  13. (function(){
  14. "use strict";
  15. /**
  16. * Initialization function that validates environment
  17. * requirements.
  18. */
  19. DetectNgTouch.$inject = ["$log", "$injector"];
  20. MdCoreConfigure.$inject = ["$provide", "$mdThemingProvider"];
  21. rAFDecorator.$inject = ["$delegate"];
  22. qDecorator.$inject = ["$delegate"];
  23. angular
  24. .module('material.core', [
  25. 'ngAnimate',
  26. 'material.core.animate',
  27. 'material.core.layout',
  28. 'material.core.interaction',
  29. 'material.core.gestures',
  30. 'material.core.theming'
  31. ])
  32. .config(MdCoreConfigure)
  33. .run(DetectNgTouch);
  34. /**
  35. * Detect if the ng-Touch module is also being used.
  36. * Warn if detected.
  37. * @ngInject
  38. */
  39. function DetectNgTouch($log, $injector) {
  40. if ( $injector.has('$swipe') ) {
  41. var msg = "" +
  42. "You are using the ngTouch module. \n" +
  43. "AngularJS Material already has mobile click, tap, and swipe support... \n" +
  44. "ngTouch is not supported with AngularJS Material!";
  45. $log.warn(msg);
  46. }
  47. }
  48. /**
  49. * @ngInject
  50. */
  51. function MdCoreConfigure($provide, $mdThemingProvider) {
  52. $provide.decorator('$$rAF', ['$delegate', rAFDecorator]);
  53. $provide.decorator('$q', ['$delegate', qDecorator]);
  54. $mdThemingProvider.theme('default')
  55. .primaryPalette('indigo')
  56. .accentPalette('pink')
  57. .warnPalette('deep-orange')
  58. .backgroundPalette('grey');
  59. }
  60. /**
  61. * @ngInject
  62. */
  63. function rAFDecorator($delegate) {
  64. /**
  65. * Use this to throttle events that come in often.
  66. * The throttled function will always use the *last* invocation before the
  67. * coming frame.
  68. *
  69. * For example, window resize events that fire many times a second:
  70. * If we set to use an raf-throttled callback on window resize, then
  71. * our callback will only be fired once per frame, with the last resize
  72. * event that happened before that frame.
  73. *
  74. * @param {function} callback function to debounce
  75. */
  76. $delegate.throttle = function(cb) {
  77. var queuedArgs, alreadyQueued, queueCb, context;
  78. return function debounced() {
  79. queuedArgs = arguments;
  80. context = this;
  81. queueCb = cb;
  82. if (!alreadyQueued) {
  83. alreadyQueued = true;
  84. $delegate(function() {
  85. queueCb.apply(context, Array.prototype.slice.call(queuedArgs));
  86. alreadyQueued = false;
  87. });
  88. }
  89. };
  90. };
  91. return $delegate;
  92. }
  93. /**
  94. * @ngInject
  95. */
  96. function qDecorator($delegate) {
  97. /**
  98. * Adds a shim for $q.resolve for AngularJS version that don't have it,
  99. * so we don't have to think about it.
  100. *
  101. * via https://github.com/angular/angular.js/pull/11987
  102. */
  103. // TODO(crisbeto): this won't be necessary once we drop AngularJS 1.3
  104. if (!$delegate.resolve) {
  105. $delegate.resolve = $delegate.when;
  106. }
  107. return $delegate;
  108. }
  109. })();
  110. (function(){
  111. "use strict";
  112. MdAutofocusDirective.$inject = ["$parse"];angular.module('material.core')
  113. .directive('mdAutofocus', MdAutofocusDirective)
  114. // Support the deprecated md-auto-focus and md-sidenav-focus as well
  115. .directive('mdAutoFocus', MdAutofocusDirective)
  116. .directive('mdSidenavFocus', MdAutofocusDirective);
  117. /**
  118. * @ngdoc directive
  119. * @name mdAutofocus
  120. * @module material.core.util
  121. *
  122. * @description
  123. *
  124. * `[md-autofocus]` provides an optional way to identify the focused element when a `$mdDialog`,
  125. * `$mdBottomSheet`, `$mdMenu` or `$mdSidenav` opens or upon page load for input-like elements.
  126. *
  127. * When one of these opens, it will find the first nested element with the `[md-autofocus]`
  128. * attribute directive and optional expression. An expression may be specified as the directive
  129. * value to enable conditional activation of the autofocus.
  130. *
  131. * @usage
  132. *
  133. * ### Dialog
  134. * <hljs lang="html">
  135. * <md-dialog>
  136. * <form>
  137. * <md-input-container>
  138. * <label for="testInput">Label</label>
  139. * <input id="testInput" type="text" md-autofocus>
  140. * </md-input-container>
  141. * </form>
  142. * </md-dialog>
  143. * </hljs>
  144. *
  145. * ### Bottomsheet
  146. * <hljs lang="html">
  147. * <md-bottom-sheet class="md-list md-has-header">
  148. * <md-subheader>Comment Actions</md-subheader>
  149. * <md-list>
  150. * <md-list-item ng-repeat="item in items">
  151. *
  152. * <md-button md-autofocus="$index == 2">
  153. * <md-icon md-svg-src="{{item.icon}}"></md-icon>
  154. * <span class="md-inline-list-icon-label">{{ item.name }}</span>
  155. * </md-button>
  156. *
  157. * </md-list-item>
  158. * </md-list>
  159. * </md-bottom-sheet>
  160. * </hljs>
  161. *
  162. * ### Autocomplete
  163. * <hljs lang="html">
  164. * <md-autocomplete
  165. * md-autofocus
  166. * md-selected-item="selectedItem"
  167. * md-search-text="searchText"
  168. * md-items="item in getMatches(searchText)"
  169. * md-item-text="item.display">
  170. * <span md-highlight-text="searchText">{{item.display}}</span>
  171. * </md-autocomplete>
  172. * </hljs>
  173. *
  174. * ### Sidenav
  175. * <hljs lang="html">
  176. * <div layout="row" ng-controller="MyController">
  177. * <md-sidenav md-component-id="left" class="md-sidenav-left">
  178. * Left Nav!
  179. * </md-sidenav>
  180. *
  181. * <md-content>
  182. * Center Content
  183. * <md-button ng-click="openLeftMenu()">
  184. * Open Left Menu
  185. * </md-button>
  186. * </md-content>
  187. *
  188. * <md-sidenav md-component-id="right"
  189. * md-is-locked-open="$mdMedia('min-width: 333px')"
  190. * class="md-sidenav-right">
  191. * <form>
  192. * <md-input-container>
  193. * <label for="testInput">Test input</label>
  194. * <input id="testInput" type="text"
  195. * ng-model="data" md-autofocus>
  196. * </md-input-container>
  197. * </form>
  198. * </md-sidenav>
  199. * </div>
  200. * </hljs>
  201. **/
  202. function MdAutofocusDirective($parse) {
  203. return {
  204. restrict: 'A',
  205. link: {
  206. pre: preLink
  207. }
  208. };
  209. function preLink(scope, element, attr) {
  210. var attrExp = attr.mdAutoFocus || attr.mdAutofocus || attr.mdSidenavFocus;
  211. // Initially update the expression by manually parsing the expression as per $watch source.
  212. updateExpression($parse(attrExp)(scope));
  213. // Only watch the expression if it is not empty.
  214. if (attrExp) {
  215. scope.$watch(attrExp, updateExpression);
  216. }
  217. /**
  218. * Updates the autofocus class which is used to determine whether the attribute
  219. * expression evaluates to true or false.
  220. * @param {string|boolean} value Attribute Value
  221. */
  222. function updateExpression(value) {
  223. // Rather than passing undefined to the jqLite toggle class function we explicitly set the
  224. // value to true. Otherwise the class will be just toggled instead of being forced.
  225. if (angular.isUndefined(value)) {
  226. value = true;
  227. }
  228. element.toggleClass('md-autofocus', !!value);
  229. }
  230. }
  231. }
  232. })();
  233. (function(){
  234. "use strict";
  235. /**
  236. * @ngdoc module
  237. * @name material.core.colorUtil
  238. * @description
  239. * Color Util
  240. */
  241. angular
  242. .module('material.core')
  243. .factory('$mdColorUtil', ColorUtilFactory);
  244. function ColorUtilFactory() {
  245. /**
  246. * Converts hex value to RGBA string
  247. * @param color {string}
  248. * @returns {string}
  249. */
  250. function hexToRgba (color) {
  251. var hex = color[ 0 ] === '#' ? color.substr(1) : color,
  252. dig = hex.length / 3,
  253. red = hex.substr(0, dig),
  254. green = hex.substr(dig, dig),
  255. blue = hex.substr(dig * 2);
  256. if (dig === 1) {
  257. red += red;
  258. green += green;
  259. blue += blue;
  260. }
  261. return 'rgba(' + parseInt(red, 16) + ',' + parseInt(green, 16) + ',' + parseInt(blue, 16) + ',0.1)';
  262. }
  263. /**
  264. * Converts rgba value to hex string
  265. * @param color {string}
  266. * @returns {string}
  267. */
  268. function rgbaToHex(color) {
  269. color = color.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
  270. var hex = (color && color.length === 4) ? "#" +
  271. ("0" + parseInt(color[1],10).toString(16)).slice(-2) +
  272. ("0" + parseInt(color[2],10).toString(16)).slice(-2) +
  273. ("0" + parseInt(color[3],10).toString(16)).slice(-2) : '';
  274. return hex.toUpperCase();
  275. }
  276. /**
  277. * Converts an RGB color to RGBA
  278. * @param color {string}
  279. * @returns {string}
  280. */
  281. function rgbToRgba (color) {
  282. return color.replace(')', ', 0.1)').replace('(', 'a(');
  283. }
  284. /**
  285. * Converts an RGBA color to RGB
  286. * @param color {string}
  287. * @returns {string}
  288. */
  289. function rgbaToRgb (color) {
  290. return color
  291. ? color.replace('rgba', 'rgb').replace(/,[^),]+\)/, ')')
  292. : 'rgb(0,0,0)';
  293. }
  294. return {
  295. rgbaToHex: rgbaToHex,
  296. hexToRgba: hexToRgba,
  297. rgbToRgba: rgbToRgba,
  298. rgbaToRgb: rgbaToRgb
  299. };
  300. }
  301. })();
  302. (function(){
  303. "use strict";
  304. angular.module('material.core')
  305. .factory('$mdConstant', MdConstantFactory);
  306. /**
  307. * Factory function that creates the grab-bag $mdConstant service.
  308. * @ngInject
  309. */
  310. function MdConstantFactory() {
  311. var prefixTestEl = document.createElement('div');
  312. var vendorPrefix = getVendorPrefix(prefixTestEl);
  313. var isWebkit = /webkit/i.test(vendorPrefix);
  314. var SPECIAL_CHARS_REGEXP = /([:\-_]+(.))/g;
  315. function vendorProperty(name) {
  316. // Add a dash between the prefix and name, to be able to transform the string into camelcase.
  317. var prefixedName = vendorPrefix + '-' + name;
  318. var ucPrefix = camelCase(prefixedName);
  319. var lcPrefix = ucPrefix.charAt(0).toLowerCase() + ucPrefix.substring(1);
  320. return hasStyleProperty(prefixTestEl, name) ? name : // The current browser supports the un-prefixed property
  321. hasStyleProperty(prefixTestEl, ucPrefix) ? ucPrefix : // The current browser only supports the prefixed property.
  322. hasStyleProperty(prefixTestEl, lcPrefix) ? lcPrefix : name; // Some browsers are only supporting the prefix in lowercase.
  323. }
  324. function hasStyleProperty(testElement, property) {
  325. return angular.isDefined(testElement.style[property]);
  326. }
  327. function camelCase(input) {
  328. return input.replace(SPECIAL_CHARS_REGEXP, function(matches, separator, letter, offset) {
  329. return offset ? letter.toUpperCase() : letter;
  330. });
  331. }
  332. function getVendorPrefix(testElement) {
  333. var prop, match;
  334. var vendorRegex = /^(Moz|webkit|ms)(?=[A-Z])/;
  335. for (prop in testElement.style) {
  336. if (match = vendorRegex.exec(prop)) {
  337. return match[0];
  338. }
  339. }
  340. }
  341. var self = {
  342. isInputKey : function(e) { return (e.keyCode >= 31 && e.keyCode <= 90); },
  343. isNumPadKey : function(e) { return (3 === e.location && e.keyCode >= 97 && e.keyCode <= 105); },
  344. isMetaKey: function(e) { return (e.keyCode >= 91 && e.keyCode <= 93); },
  345. isFnLockKey: function(e) { return (e.keyCode >= 112 && e.keyCode <= 145); },
  346. isNavigationKey : function(e) {
  347. var kc = self.KEY_CODE, NAVIGATION_KEYS = [kc.SPACE, kc.ENTER, kc.UP_ARROW, kc.DOWN_ARROW];
  348. return (NAVIGATION_KEYS.indexOf(e.keyCode) != -1);
  349. },
  350. hasModifierKey: function(e) {
  351. return e.ctrlKey || e.metaKey || e.altKey;
  352. },
  353. /**
  354. * Maximum size, in pixels, that can be explicitly set to an element. The actual value varies
  355. * between browsers, but IE11 has the very lowest size at a mere 1,533,917px. Ideally we could
  356. * compute this value, but Firefox always reports an element to have a size of zero if it
  357. * goes over the max, meaning that we'd have to binary search for the value.
  358. */
  359. ELEMENT_MAX_PIXELS: 1533917,
  360. /**
  361. * Priority for a directive that should run before the directives from ngAria.
  362. */
  363. BEFORE_NG_ARIA: 210,
  364. /**
  365. * Common Keyboard actions and their associated keycode.
  366. */
  367. KEY_CODE: {
  368. COMMA: 188,
  369. SEMICOLON : 186,
  370. ENTER: 13,
  371. ESCAPE: 27,
  372. SPACE: 32,
  373. PAGE_UP: 33,
  374. PAGE_DOWN: 34,
  375. END: 35,
  376. HOME: 36,
  377. LEFT_ARROW : 37,
  378. UP_ARROW : 38,
  379. RIGHT_ARROW : 39,
  380. DOWN_ARROW : 40,
  381. TAB : 9,
  382. BACKSPACE: 8,
  383. DELETE: 46
  384. },
  385. /**
  386. * Vendor prefixed CSS properties to be used to support the given functionality in older browsers
  387. * as well.
  388. */
  389. CSS: {
  390. /* Constants */
  391. TRANSITIONEND: 'transitionend' + (isWebkit ? ' webkitTransitionEnd' : ''),
  392. ANIMATIONEND: 'animationend' + (isWebkit ? ' webkitAnimationEnd' : ''),
  393. TRANSFORM: vendorProperty('transform'),
  394. TRANSFORM_ORIGIN: vendorProperty('transformOrigin'),
  395. TRANSITION: vendorProperty('transition'),
  396. TRANSITION_DURATION: vendorProperty('transitionDuration'),
  397. ANIMATION_PLAY_STATE: vendorProperty('animationPlayState'),
  398. ANIMATION_DURATION: vendorProperty('animationDuration'),
  399. ANIMATION_NAME: vendorProperty('animationName'),
  400. ANIMATION_TIMING: vendorProperty('animationTimingFunction'),
  401. ANIMATION_DIRECTION: vendorProperty('animationDirection')
  402. },
  403. /**
  404. * As defined in core/style/variables.scss
  405. *
  406. * $layout-breakpoint-xs: 600px !default;
  407. * $layout-breakpoint-sm: 960px !default;
  408. * $layout-breakpoint-md: 1280px !default;
  409. * $layout-breakpoint-lg: 1920px !default;
  410. *
  411. */
  412. MEDIA: {
  413. 'xs' : '(max-width: 599px)' ,
  414. 'gt-xs' : '(min-width: 600px)' ,
  415. 'sm' : '(min-width: 600px) and (max-width: 959px)' ,
  416. 'gt-sm' : '(min-width: 960px)' ,
  417. 'md' : '(min-width: 960px) and (max-width: 1279px)' ,
  418. 'gt-md' : '(min-width: 1280px)' ,
  419. 'lg' : '(min-width: 1280px) and (max-width: 1919px)',
  420. 'gt-lg' : '(min-width: 1920px)' ,
  421. 'xl' : '(min-width: 1920px)' ,
  422. 'landscape' : '(orientation: landscape)' ,
  423. 'portrait' : '(orientation: portrait)' ,
  424. 'print' : 'print'
  425. },
  426. MEDIA_PRIORITY: [
  427. 'xl',
  428. 'gt-lg',
  429. 'lg',
  430. 'gt-md',
  431. 'md',
  432. 'gt-sm',
  433. 'sm',
  434. 'gt-xs',
  435. 'xs',
  436. 'landscape',
  437. 'portrait',
  438. 'print'
  439. ]
  440. };
  441. return self;
  442. }
  443. })();
  444. (function(){
  445. "use strict";
  446. angular
  447. .module('material.core')
  448. .config( ["$provide", function($provide){
  449. $provide.decorator('$mdUtil', ['$delegate', function ($delegate){
  450. /**
  451. * Inject the iterator facade to easily support iteration and accessors
  452. * @see iterator below
  453. */
  454. $delegate.iterator = MdIterator;
  455. return $delegate;
  456. }
  457. ]);
  458. }]);
  459. /**
  460. * iterator is a list facade to easily support iteration and accessors
  461. *
  462. * @param items Array list which this iterator will enumerate
  463. * @param reloop Boolean enables iterator to consider the list as an endless reloop
  464. */
  465. function MdIterator(items, reloop) {
  466. var trueFn = function() { return true; };
  467. if (items && !angular.isArray(items)) {
  468. items = Array.prototype.slice.call(items);
  469. }
  470. reloop = !!reloop;
  471. var _items = items || [ ];
  472. // Published API
  473. return {
  474. items: getItems,
  475. count: count,
  476. inRange: inRange,
  477. contains: contains,
  478. indexOf: indexOf,
  479. itemAt: itemAt,
  480. findBy: findBy,
  481. add: add,
  482. remove: remove,
  483. first: first,
  484. last: last,
  485. next: angular.bind(null, findSubsequentItem, false),
  486. previous: angular.bind(null, findSubsequentItem, true),
  487. hasPrevious: hasPrevious,
  488. hasNext: hasNext
  489. };
  490. /**
  491. * Publish copy of the enumerable set
  492. * @returns {Array|*}
  493. */
  494. function getItems() {
  495. return [].concat(_items);
  496. }
  497. /**
  498. * Determine length of the list
  499. * @returns {Array.length|*|number}
  500. */
  501. function count() {
  502. return _items.length;
  503. }
  504. /**
  505. * Is the index specified valid
  506. * @param index
  507. * @returns {Array.length|*|number|boolean}
  508. */
  509. function inRange(index) {
  510. return _items.length && ( index > -1 ) && (index < _items.length );
  511. }
  512. /**
  513. * Can the iterator proceed to the next item in the list; relative to
  514. * the specified item.
  515. *
  516. * @param item
  517. * @returns {Array.length|*|number|boolean}
  518. */
  519. function hasNext(item) {
  520. return item ? inRange(indexOf(item) + 1) : false;
  521. }
  522. /**
  523. * Can the iterator proceed to the previous item in the list; relative to
  524. * the specified item.
  525. *
  526. * @param item
  527. * @returns {Array.length|*|number|boolean}
  528. */
  529. function hasPrevious(item) {
  530. return item ? inRange(indexOf(item) - 1) : false;
  531. }
  532. /**
  533. * Get item at specified index/position
  534. * @param index
  535. * @returns {*}
  536. */
  537. function itemAt(index) {
  538. return inRange(index) ? _items[index] : null;
  539. }
  540. /**
  541. * Find all elements matching the key/value pair
  542. * otherwise return null
  543. *
  544. * @param val
  545. * @param key
  546. *
  547. * @return array
  548. */
  549. function findBy(key, val) {
  550. return _items.filter(function(item) {
  551. return item[key] === val;
  552. });
  553. }
  554. /**
  555. * Add item to list
  556. * @param item
  557. * @param index
  558. * @returns {*}
  559. */
  560. function add(item, index) {
  561. if ( !item ) return -1;
  562. if (!angular.isNumber(index)) {
  563. index = _items.length;
  564. }
  565. _items.splice(index, 0, item);
  566. return indexOf(item);
  567. }
  568. /**
  569. * Remove item from list...
  570. * @param item
  571. */
  572. function remove(item) {
  573. if ( contains(item) ){
  574. _items.splice(indexOf(item), 1);
  575. }
  576. }
  577. /**
  578. * Get the zero-based index of the target item
  579. * @param item
  580. * @returns {*}
  581. */
  582. function indexOf(item) {
  583. return _items.indexOf(item);
  584. }
  585. /**
  586. * Boolean existence check
  587. * @param item
  588. * @returns {boolean}
  589. */
  590. function contains(item) {
  591. return item && (indexOf(item) > -1);
  592. }
  593. /**
  594. * Return first item in the list
  595. * @returns {*}
  596. */
  597. function first() {
  598. return _items.length ? _items[0] : null;
  599. }
  600. /**
  601. * Return last item in the list...
  602. * @returns {*}
  603. */
  604. function last() {
  605. return _items.length ? _items[_items.length - 1] : null;
  606. }
  607. /**
  608. * Find the next item. If reloop is true and at the end of the list, it will go back to the
  609. * first item. If given, the `validate` callback will be used to determine whether the next item
  610. * is valid. If not valid, it will try to find the next item again.
  611. *
  612. * @param {boolean} backwards Specifies the direction of searching (forwards/backwards)
  613. * @param {*} item The item whose subsequent item we are looking for
  614. * @param {Function=} validate The `validate` function
  615. * @param {integer=} limit The recursion limit
  616. *
  617. * @returns {*} The subsequent item or null
  618. */
  619. function findSubsequentItem(backwards, item, validate, limit) {
  620. validate = validate || trueFn;
  621. var curIndex = indexOf(item);
  622. while (true) {
  623. if (!inRange(curIndex)) return null;
  624. var nextIndex = curIndex + (backwards ? -1 : 1);
  625. var foundItem = null;
  626. if (inRange(nextIndex)) {
  627. foundItem = _items[nextIndex];
  628. } else if (reloop) {
  629. foundItem = backwards ? last() : first();
  630. nextIndex = indexOf(foundItem);
  631. }
  632. if ((foundItem === null) || (nextIndex === limit)) return null;
  633. if (validate(foundItem)) return foundItem;
  634. if (angular.isUndefined(limit)) limit = nextIndex;
  635. curIndex = nextIndex;
  636. }
  637. }
  638. }
  639. })();
  640. (function(){
  641. "use strict";
  642. mdMediaFactory.$inject = ["$mdConstant", "$rootScope", "$window"];angular.module('material.core')
  643. .factory('$mdMedia', mdMediaFactory);
  644. /**
  645. * @ngdoc service
  646. * @name $mdMedia
  647. * @module material.core
  648. *
  649. * @description
  650. * `$mdMedia` is used to evaluate whether a given media query is true or false given the
  651. * current device's screen / window size. The media query will be re-evaluated on resize, allowing
  652. * you to register a watch.
  653. *
  654. * `$mdMedia` also has pre-programmed support for media queries that match the layout breakpoints:
  655. *
  656. * <table class="md-api-table">
  657. * <thead>
  658. * <tr>
  659. * <th>Breakpoint</th>
  660. * <th>mediaQuery</th>
  661. * </tr>
  662. * </thead>
  663. * <tbody>
  664. * <tr>
  665. * <td>xs</td>
  666. * <td>(max-width: 599px)</td>
  667. * </tr>
  668. * <tr>
  669. * <td>gt-xs</td>
  670. * <td>(min-width: 600px)</td>
  671. * </tr>
  672. * <tr>
  673. * <td>sm</td>
  674. * <td>(min-width: 600px) and (max-width: 959px)</td>
  675. * </tr>
  676. * <tr>
  677. * <td>gt-sm</td>
  678. * <td>(min-width: 960px)</td>
  679. * </tr>
  680. * <tr>
  681. * <td>md</td>
  682. * <td>(min-width: 960px) and (max-width: 1279px)</td>
  683. * </tr>
  684. * <tr>
  685. * <td>gt-md</td>
  686. * <td>(min-width: 1280px)</td>
  687. * </tr>
  688. * <tr>
  689. * <td>lg</td>
  690. * <td>(min-width: 1280px) and (max-width: 1919px)</td>
  691. * </tr>
  692. * <tr>
  693. * <td>gt-lg</td>
  694. * <td>(min-width: 1920px)</td>
  695. * </tr>
  696. * <tr>
  697. * <td>xl</td>
  698. * <td>(min-width: 1920px)</td>
  699. * </tr>
  700. * <tr>
  701. * <td>landscape</td>
  702. * <td>landscape</td>
  703. * </tr>
  704. * <tr>
  705. * <td>portrait</td>
  706. * <td>portrait</td>
  707. * </tr>
  708. * <tr>
  709. * <td>print</td>
  710. * <td>print</td>
  711. * </tr>
  712. * </tbody>
  713. * </table>
  714. *
  715. * See Material Design's <a href="https://material.google.com/layout/responsive-ui.html">Layout - Adaptive UI</a> for more details.
  716. *
  717. * <a href="https://www.google.com/design/spec/layout/adaptive-ui.html">
  718. * <img src="https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B8olV15J7abPSGFxemFiQVRtb1k/layout_adaptive_breakpoints_01.png" width="100%" height="100%"></img>
  719. * </a>
  720. *
  721. * @returns {boolean} a boolean representing whether or not the given media query is true or false.
  722. *
  723. * @usage
  724. * <hljs lang="js">
  725. * app.controller('MyController', function($mdMedia, $scope) {
  726. * $scope.$watch(function() { return $mdMedia('lg'); }, function(big) {
  727. * $scope.bigScreen = big;
  728. * });
  729. *
  730. * $scope.screenIsSmall = $mdMedia('sm');
  731. * $scope.customQuery = $mdMedia('(min-width: 1234px)');
  732. * $scope.anotherCustom = $mdMedia('max-width: 300px');
  733. * });
  734. * </hljs>
  735. */
  736. /* @ngInject */
  737. function mdMediaFactory($mdConstant, $rootScope, $window) {
  738. var queries = {};
  739. var mqls = {};
  740. var results = {};
  741. var normalizeCache = {};
  742. $mdMedia.getResponsiveAttribute = getResponsiveAttribute;
  743. $mdMedia.getQuery = getQuery;
  744. $mdMedia.watchResponsiveAttributes = watchResponsiveAttributes;
  745. return $mdMedia;
  746. function $mdMedia(query) {
  747. var validated = queries[query];
  748. if (angular.isUndefined(validated)) {
  749. validated = queries[query] = validate(query);
  750. }
  751. var result = results[validated];
  752. if (angular.isUndefined(result)) {
  753. result = add(validated);
  754. }
  755. return result;
  756. }
  757. function validate(query) {
  758. return $mdConstant.MEDIA[query] ||
  759. ((query.charAt(0) !== '(') ? ('(' + query + ')') : query);
  760. }
  761. function add(query) {
  762. var result = mqls[query];
  763. if ( !result ) {
  764. result = mqls[query] = $window.matchMedia(query);
  765. }
  766. result.addListener(onQueryChange);
  767. return (results[result.media] = !!result.matches);
  768. }
  769. function onQueryChange(query) {
  770. $rootScope.$evalAsync(function() {
  771. results[query.media] = !!query.matches;
  772. });
  773. }
  774. function getQuery(name) {
  775. return mqls[name];
  776. }
  777. function getResponsiveAttribute(attrs, attrName) {
  778. for (var i = 0; i < $mdConstant.MEDIA_PRIORITY.length; i++) {
  779. var mediaName = $mdConstant.MEDIA_PRIORITY[i];
  780. if (!mqls[queries[mediaName]].matches) {
  781. continue;
  782. }
  783. var normalizedName = getNormalizedName(attrs, attrName + '-' + mediaName);
  784. if (attrs[normalizedName]) {
  785. return attrs[normalizedName];
  786. }
  787. }
  788. // fallback on unprefixed
  789. return attrs[getNormalizedName(attrs, attrName)];
  790. }
  791. function watchResponsiveAttributes(attrNames, attrs, watchFn) {
  792. var unwatchFns = [];
  793. attrNames.forEach(function(attrName) {
  794. var normalizedName = getNormalizedName(attrs, attrName);
  795. if (angular.isDefined(attrs[normalizedName])) {
  796. unwatchFns.push(
  797. attrs.$observe(normalizedName, angular.bind(void 0, watchFn, null)));
  798. }
  799. for (var mediaName in $mdConstant.MEDIA) {
  800. normalizedName = getNormalizedName(attrs, attrName + '-' + mediaName);
  801. if (angular.isDefined(attrs[normalizedName])) {
  802. unwatchFns.push(
  803. attrs.$observe(normalizedName, angular.bind(void 0, watchFn, mediaName)));
  804. }
  805. }
  806. });
  807. return function unwatch() {
  808. unwatchFns.forEach(function(fn) { fn(); });
  809. };
  810. }
  811. // Improves performance dramatically
  812. function getNormalizedName(attrs, attrName) {
  813. return normalizeCache[attrName] ||
  814. (normalizeCache[attrName] = attrs.$normalize(attrName));
  815. }
  816. }
  817. })();
  818. (function(){
  819. "use strict";
  820. angular
  821. .module('material.core')
  822. .config( ["$provide", function($provide) {
  823. $provide.decorator('$mdUtil', ['$delegate', function ($delegate) {
  824. // Inject the prefixer into our original $mdUtil service.
  825. $delegate.prefixer = MdPrefixer;
  826. return $delegate;
  827. }]);
  828. }]);
  829. function MdPrefixer(initialAttributes, buildSelector) {
  830. var PREFIXES = ['data', 'x'];
  831. if (initialAttributes) {
  832. // The prefixer also accepts attributes as a parameter, and immediately builds a list or selector for
  833. // the specified attributes.
  834. return buildSelector ? _buildSelector(initialAttributes) : _buildList(initialAttributes);
  835. }
  836. return {
  837. buildList: _buildList,
  838. buildSelector: _buildSelector,
  839. hasAttribute: _hasAttribute,
  840. removeAttribute: _removeAttribute
  841. };
  842. function _buildList(attributes) {
  843. attributes = angular.isArray(attributes) ? attributes : [attributes];
  844. attributes.forEach(function(item) {
  845. PREFIXES.forEach(function(prefix) {
  846. attributes.push(prefix + '-' + item);
  847. });
  848. });
  849. return attributes;
  850. }
  851. function _buildSelector(attributes) {
  852. attributes = angular.isArray(attributes) ? attributes : [attributes];
  853. return _buildList(attributes)
  854. .map(function(item) {
  855. return '[' + item + ']';
  856. })
  857. .join(',');
  858. }
  859. function _hasAttribute(element, attribute) {
  860. element = _getNativeElement(element);
  861. if (!element) {
  862. return false;
  863. }
  864. var prefixedAttrs = _buildList(attribute);
  865. for (var i = 0; i < prefixedAttrs.length; i++) {
  866. if (element.hasAttribute(prefixedAttrs[i])) {
  867. return true;
  868. }
  869. }
  870. return false;
  871. }
  872. function _removeAttribute(element, attribute) {
  873. element = _getNativeElement(element);
  874. if (!element) {
  875. return;
  876. }
  877. _buildList(attribute).forEach(function(prefixedAttribute) {
  878. element.removeAttribute(prefixedAttribute);
  879. });
  880. }
  881. /**
  882. * Transforms a jqLite or DOM element into a HTML element.
  883. * This is useful when supporting jqLite elements and DOM elements at
  884. * same time.
  885. * @param element {JQLite|Element} Element to be parsed
  886. * @returns {HTMLElement} Parsed HTMLElement
  887. */
  888. function _getNativeElement(element) {
  889. element = element[0] || element;
  890. if (element.nodeType) {
  891. return element;
  892. }
  893. }
  894. }
  895. })();
  896. (function(){
  897. "use strict";
  898. /*
  899. * This var has to be outside the angular factory, otherwise when
  900. * there are multiple material apps on the same page, each app
  901. * will create its own instance of this array and the app's IDs
  902. * will not be unique.
  903. */
  904. UtilFactory.$inject = ["$document", "$timeout", "$compile", "$rootScope", "$$mdAnimate", "$interpolate", "$log", "$rootElement", "$window", "$$rAF"];
  905. var nextUniqueId = 0;
  906. /**
  907. * @ngdoc module
  908. * @name material.core.util
  909. * @description
  910. * Util
  911. */
  912. angular
  913. .module('material.core')
  914. .factory('$mdUtil', UtilFactory);
  915. /**
  916. * @ngInject
  917. */
  918. function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $interpolate, $log, $rootElement, $window, $$rAF) {
  919. // Setup some core variables for the processTemplate method
  920. var startSymbol = $interpolate.startSymbol(),
  921. endSymbol = $interpolate.endSymbol(),
  922. usesStandardSymbols = ((startSymbol === '{{') && (endSymbol === '}}'));
  923. /**
  924. * Checks if the target element has the requested style by key
  925. * @param {DOMElement|JQLite} target Target element
  926. * @param {string} key Style key
  927. * @param {string=} expectedVal Optional expected value
  928. * @returns {boolean} Whether the target element has the style or not
  929. */
  930. var hasComputedStyle = function (target, key, expectedVal) {
  931. var hasValue = false;
  932. if ( target && target.length ) {
  933. var computedStyles = $window.getComputedStyle(target[0]);
  934. hasValue = angular.isDefined(computedStyles[key]) && (expectedVal ? computedStyles[key] == expectedVal : true);
  935. }
  936. return hasValue;
  937. };
  938. function validateCssValue(value) {
  939. return !value ? '0' :
  940. hasPx(value) || hasPercent(value) ? value : value + 'px';
  941. }
  942. function hasPx(value) {
  943. return String(value).indexOf('px') > -1;
  944. }
  945. function hasPercent(value) {
  946. return String(value).indexOf('%') > -1;
  947. }
  948. var $mdUtil = {
  949. dom: {},
  950. now: window.performance && window.performance.now ?
  951. angular.bind(window.performance, window.performance.now) : Date.now || function() {
  952. return new Date().getTime();
  953. },
  954. /**
  955. * Cross-version compatibility method to retrieve an option of a ngModel controller,
  956. * which supports the breaking changes in the AngularJS snapshot (SHA 87a2ff76af5d0a9268d8eb84db5755077d27c84c).
  957. * @param {!angular.ngModelCtrl} ngModelCtrl
  958. * @param {!string} optionName
  959. * @returns {Object|undefined}
  960. */
  961. getModelOption: function (ngModelCtrl, optionName) {
  962. if (!ngModelCtrl.$options) {
  963. return;
  964. }
  965. var $options = ngModelCtrl.$options;
  966. // The newer versions of AngularJS introduced a `getOption function and made the option values no longer
  967. // visible on the $options object.
  968. return $options.getOption ? $options.getOption(optionName) : $options[optionName];
  969. },
  970. /**
  971. * Bi-directional accessor/mutator used to easily update an element's
  972. * property based on the current 'dir'ectional value.
  973. */
  974. bidi : function(element, property, lValue, rValue) {
  975. var ltr = !($document[0].dir == 'rtl' || $document[0].body.dir == 'rtl');
  976. // If accessor
  977. if ( arguments.length == 0 ) return ltr ? 'ltr' : 'rtl';
  978. // If mutator
  979. var elem = angular.element(element);
  980. if ( ltr && angular.isDefined(lValue)) {
  981. elem.css(property, validateCssValue(lValue));
  982. }
  983. else if ( !ltr && angular.isDefined(rValue)) {
  984. elem.css(property, validateCssValue(rValue) );
  985. }
  986. },
  987. bidiProperty: function (element, lProperty, rProperty, value) {
  988. var ltr = !($document[0].dir == 'rtl' || $document[0].body.dir == 'rtl');
  989. var elem = angular.element(element);
  990. if ( ltr && angular.isDefined(lProperty)) {
  991. elem.css(lProperty, validateCssValue(value));
  992. elem.css(rProperty, '');
  993. }
  994. else if ( !ltr && angular.isDefined(rProperty)) {
  995. elem.css(rProperty, validateCssValue(value) );
  996. elem.css(lProperty, '');
  997. }
  998. },
  999. clientRect: function(element, offsetParent, isOffsetRect) {
  1000. var node = getNode(element);
  1001. offsetParent = getNode(offsetParent || node.offsetParent || document.body);
  1002. var nodeRect = node.getBoundingClientRect();
  1003. // The user can ask for an offsetRect: a rect relative to the offsetParent,
  1004. // or a clientRect: a rect relative to the page
  1005. var offsetRect = isOffsetRect ?
  1006. offsetParent.getBoundingClientRect() :
  1007. {left: 0, top: 0, width: 0, height: 0};
  1008. return {
  1009. left: nodeRect.left - offsetRect.left,
  1010. top: nodeRect.top - offsetRect.top,
  1011. width: nodeRect.width,
  1012. height: nodeRect.height
  1013. };
  1014. },
  1015. offsetRect: function(element, offsetParent) {
  1016. return $mdUtil.clientRect(element, offsetParent, true);
  1017. },
  1018. // Annoying method to copy nodes to an array, thanks to IE
  1019. nodesToArray: function(nodes) {
  1020. nodes = nodes || [];
  1021. var results = [];
  1022. for (var i = 0; i < nodes.length; ++i) {
  1023. results.push(nodes.item(i));
  1024. }
  1025. return results;
  1026. },
  1027. /**
  1028. * Determines the absolute position of the viewport.
  1029. * Useful when making client rectangles absolute.
  1030. * @returns {number}
  1031. */
  1032. getViewportTop: function() {
  1033. return window.scrollY || window.pageYOffset || 0;
  1034. },
  1035. /**
  1036. * Finds the proper focus target by searching the DOM.
  1037. *
  1038. * @param containerEl
  1039. * @param attributeVal
  1040. * @returns {*}
  1041. */
  1042. findFocusTarget: function(containerEl, attributeVal) {
  1043. var AUTO_FOCUS = this.prefixer('md-autofocus', true);
  1044. var elToFocus;
  1045. elToFocus = scanForFocusable(containerEl, attributeVal || AUTO_FOCUS);
  1046. if ( !elToFocus && attributeVal != AUTO_FOCUS) {
  1047. // Scan for deprecated attribute
  1048. elToFocus = scanForFocusable(containerEl, this.prefixer('md-auto-focus', true));
  1049. if ( !elToFocus ) {
  1050. // Scan for fallback to 'universal' API
  1051. elToFocus = scanForFocusable(containerEl, AUTO_FOCUS);
  1052. }
  1053. }
  1054. return elToFocus;
  1055. /**
  1056. * Can target and nested children for specified Selector (attribute)
  1057. * whose value may be an expression that evaluates to True/False.
  1058. */
  1059. function scanForFocusable(target, selector) {
  1060. var elFound, items = target[0].querySelectorAll(selector);
  1061. // Find the last child element with the focus attribute
  1062. if ( items && items.length ){
  1063. items.length && angular.forEach(items, function(it) {
  1064. it = angular.element(it);
  1065. // Check the element for the md-autofocus class to ensure any associated expression
  1066. // evaluated to true.
  1067. var isFocusable = it.hasClass('md-autofocus');
  1068. if (isFocusable) elFound = it;
  1069. });
  1070. }
  1071. return elFound;
  1072. }
  1073. },
  1074. /**
  1075. * Disables scroll around the passed parent element.
  1076. * @param element Unused
  1077. * @param {!Element|!angular.JQLite} parent Element to disable scrolling within.
  1078. * Defaults to body if none supplied.
  1079. * @param options Object of options to modify functionality
  1080. * - disableScrollMask Boolean of whether or not to create a scroll mask element or
  1081. * use the passed parent element.
  1082. */
  1083. disableScrollAround: function(element, parent, options) {
  1084. options = options || {};
  1085. $mdUtil.disableScrollAround._count = Math.max(0, $mdUtil.disableScrollAround._count || 0);
  1086. $mdUtil.disableScrollAround._count++;
  1087. if ($mdUtil.disableScrollAround._restoreScroll) {
  1088. return $mdUtil.disableScrollAround._restoreScroll;
  1089. }
  1090. var body = $document[0].body;
  1091. var restoreBody = disableBodyScroll();
  1092. var restoreElement = disableElementScroll(parent);
  1093. return $mdUtil.disableScrollAround._restoreScroll = function() {
  1094. if (--$mdUtil.disableScrollAround._count <= 0) {
  1095. restoreBody();
  1096. restoreElement();
  1097. delete $mdUtil.disableScrollAround._restoreScroll;
  1098. }
  1099. };
  1100. /**
  1101. * Creates a virtual scrolling mask to prevent touchmove, keyboard, scrollbar clicking,
  1102. * and wheel events
  1103. */
  1104. function disableElementScroll(element) {
  1105. element = angular.element(element || body);
  1106. var scrollMask;
  1107. if (options.disableScrollMask) {
  1108. scrollMask = element;
  1109. } else {
  1110. scrollMask = angular.element(
  1111. '<div class="md-scroll-mask">' +
  1112. ' <div class="md-scroll-mask-bar"></div>' +
  1113. '</div>');
  1114. element.append(scrollMask);
  1115. }
  1116. scrollMask.on('wheel', preventDefault);
  1117. scrollMask.on('touchmove', preventDefault);
  1118. return function restoreElementScroll() {
  1119. scrollMask.off('wheel');
  1120. scrollMask.off('touchmove');
  1121. if (!options.disableScrollMask && scrollMask[0].parentNode ) {
  1122. scrollMask[0].parentNode.removeChild(scrollMask[0]);
  1123. }
  1124. };
  1125. function preventDefault(e) {
  1126. e.preventDefault();
  1127. }
  1128. }
  1129. // Converts the body to a position fixed block and translate it to the proper scroll position
  1130. function disableBodyScroll() {
  1131. var documentElement = $document[0].documentElement;
  1132. var prevDocumentStyle = documentElement.style.cssText || '';
  1133. var prevBodyStyle = body.style.cssText || '';
  1134. var viewportTop = $mdUtil.getViewportTop();
  1135. var clientWidth = body.clientWidth;
  1136. var hasVerticalScrollbar = body.scrollHeight > body.clientHeight + 1;
  1137. // Scroll may be set on <html> element (for example by overflow-y: scroll)
  1138. // but Chrome is reporting the scrollTop position always on <body>.
  1139. // scrollElement will allow to restore the scrollTop position to proper target.
  1140. var scrollElement = documentElement.scrollTop > 0 ? documentElement : body;
  1141. if (hasVerticalScrollbar) {
  1142. angular.element(body).css({
  1143. position: 'fixed',
  1144. width: '100%',
  1145. top: -viewportTop + 'px'
  1146. });
  1147. }
  1148. if (body.clientWidth < clientWidth) {
  1149. body.style.overflow = 'hidden';
  1150. }
  1151. // This should be applied after the manipulation to the body, because
  1152. // adding a scrollbar can potentially resize it, causing the measurement
  1153. // to change.
  1154. if (hasVerticalScrollbar) {
  1155. documentElement.style.overflowY = 'scroll';
  1156. }
  1157. return function restoreScroll() {
  1158. // Reset the inline style CSS to the previous.
  1159. body.style.cssText = prevBodyStyle;
  1160. documentElement.style.cssText = prevDocumentStyle;
  1161. // The scroll position while being fixed
  1162. scrollElement.scrollTop = viewportTop;
  1163. };
  1164. }
  1165. },
  1166. enableScrolling: function() {
  1167. var restoreFn = this.disableScrollAround._restoreScroll;
  1168. restoreFn && restoreFn();
  1169. },
  1170. floatingScrollbars: function() {
  1171. if (this.floatingScrollbars.cached === undefined) {
  1172. var tempNode = angular.element('<div><div></div></div>').css({
  1173. width: '100%',
  1174. 'z-index': -1,
  1175. position: 'absolute',
  1176. height: '35px',
  1177. 'overflow-y': 'scroll'
  1178. });
  1179. tempNode.children().css('height', '60px');
  1180. $document[0].body.appendChild(tempNode[0]);
  1181. this.floatingScrollbars.cached = (tempNode[0].offsetWidth == tempNode[0].childNodes[0].offsetWidth);
  1182. tempNode.remove();
  1183. }
  1184. return this.floatingScrollbars.cached;
  1185. },
  1186. // Mobile safari only allows you to set focus in click event listeners...
  1187. forceFocus: function(element) {
  1188. var node = element[0] || element;
  1189. document.addEventListener('click', function focusOnClick(ev) {
  1190. if (ev.target === node && ev.$focus) {
  1191. node.focus();
  1192. ev.stopImmediatePropagation();
  1193. ev.preventDefault();
  1194. node.removeEventListener('click', focusOnClick);
  1195. }
  1196. }, true);
  1197. var newEvent = document.createEvent('MouseEvents');
  1198. newEvent.initMouseEvent('click', false, true, window, {}, 0, 0, 0, 0,
  1199. false, false, false, false, 0, null);
  1200. newEvent.$material = true;
  1201. newEvent.$focus = true;
  1202. node.dispatchEvent(newEvent);
  1203. },
  1204. /**
  1205. * facade to build md-backdrop element with desired styles
  1206. * NOTE: Use $compile to trigger backdrop postLink function
  1207. */
  1208. createBackdrop: function(scope, addClass) {
  1209. return $compile($mdUtil.supplant('<md-backdrop class="{0}">', [addClass]))(scope);
  1210. },
  1211. /**
  1212. * supplant() method from Crockford's `Remedial Javascript`
  1213. * Equivalent to use of $interpolate; without dependency on
  1214. * interpolation symbols and scope. Note: the '{<token>}' can
  1215. * be property names, property chains, or array indices.
  1216. */
  1217. supplant: function(template, values, pattern) {
  1218. pattern = pattern || /\{([^{}]*)\}/g;
  1219. return template.replace(pattern, function(a, b) {
  1220. var p = b.split('.'),
  1221. r = values;
  1222. try {
  1223. for (var s in p) {
  1224. if (p.hasOwnProperty(s) ) {
  1225. r = r[p[s]];
  1226. }
  1227. }
  1228. } catch (e) {
  1229. r = a;
  1230. }
  1231. return (typeof r === 'string' || typeof r === 'number') ? r : a;
  1232. });
  1233. },
  1234. fakeNgModel: function() {
  1235. return {
  1236. $fake: true,
  1237. $setTouched: angular.noop,
  1238. $setViewValue: function(value) {
  1239. this.$viewValue = value;
  1240. this.$render(value);
  1241. this.$viewChangeListeners.forEach(function(cb) {
  1242. cb();
  1243. });
  1244. },
  1245. $isEmpty: function(value) {
  1246. return ('' + value).length === 0;
  1247. },
  1248. $parsers: [],
  1249. $formatters: [],
  1250. $viewChangeListeners: [],
  1251. $render: angular.noop
  1252. };
  1253. },
  1254. // Returns a function, that, as long as it continues to be invoked, will not
  1255. // be triggered. The function will be called after it stops being called for
  1256. // N milliseconds.
  1257. // @param wait Integer value of msecs to delay (since last debounce reset); default value 10 msecs
  1258. // @param invokeApply should the $timeout trigger $digest() dirty checking
  1259. debounce: function(func, wait, scope, invokeApply) {
  1260. var timer;
  1261. return function debounced() {
  1262. var context = scope,
  1263. args = Array.prototype.slice.call(arguments);
  1264. $timeout.cancel(timer);
  1265. timer = $timeout(function() {
  1266. timer = undefined;
  1267. func.apply(context, args);
  1268. }, wait || 10, invokeApply);
  1269. };
  1270. },
  1271. // Returns a function that can only be triggered every `delay` milliseconds.
  1272. // In other words, the function will not be called unless it has been more
  1273. // than `delay` milliseconds since the last call.
  1274. throttle: function throttle(func, delay) {
  1275. var recent;
  1276. return function throttled() {
  1277. var context = this;
  1278. var args = arguments;
  1279. var now = $mdUtil.now();
  1280. if (!recent || (now - recent > delay)) {
  1281. func.apply(context, args);
  1282. recent = now;
  1283. }
  1284. };
  1285. },
  1286. /**
  1287. * Measures the number of milliseconds taken to run the provided callback
  1288. * function. Uses a high-precision timer if available.
  1289. */
  1290. time: function time(cb) {
  1291. var start = $mdUtil.now();
  1292. cb();
  1293. return $mdUtil.now() - start;
  1294. },
  1295. /**
  1296. * Create an implicit getter that caches its `getter()`
  1297. * lookup value
  1298. */
  1299. valueOnUse : function (scope, key, getter) {
  1300. var value = null, args = Array.prototype.slice.call(arguments);
  1301. var params = (args.length > 3) ? args.slice(3) : [ ];
  1302. Object.defineProperty(scope, key, {
  1303. get: function () {
  1304. if (value === null) value = getter.apply(scope, params);
  1305. return value;
  1306. }
  1307. });
  1308. },
  1309. /**
  1310. * Get a unique ID.
  1311. *
  1312. * @returns {string} an unique numeric string
  1313. */
  1314. nextUid: function() {
  1315. return '' + nextUniqueId++;
  1316. },
  1317. // Stop watchers and events from firing on a scope without destroying it,
  1318. // by disconnecting it from its parent and its siblings' linked lists.
  1319. disconnectScope: function disconnectScope(scope) {
  1320. if (!scope) return;
  1321. // we can't destroy the root scope or a scope that has been already destroyed
  1322. if (scope.$root === scope) return;
  1323. if (scope.$$destroyed) return;
  1324. var parent = scope.$parent;
  1325. scope.$$disconnected = true;
  1326. // See Scope.$destroy
  1327. if (parent.$$childHead === scope) parent.$$childHead = scope.$$nextSibling;
  1328. if (parent.$$childTail === scope) parent.$$childTail = scope.$$prevSibling;
  1329. if (scope.$$prevSibling) scope.$$prevSibling.$$nextSibling = scope.$$nextSibling;
  1330. if (scope.$$nextSibling) scope.$$nextSibling.$$prevSibling = scope.$$prevSibling;
  1331. scope.$$nextSibling = scope.$$prevSibling = null;
  1332. },
  1333. // Undo the effects of disconnectScope above.
  1334. reconnectScope: function reconnectScope(scope) {
  1335. if (!scope) return;
  1336. // we can't disconnect the root node or scope already disconnected
  1337. if (scope.$root === scope) return;
  1338. if (!scope.$$disconnected) return;
  1339. var child = scope;
  1340. var parent = child.$parent;
  1341. child.$$disconnected = false;
  1342. // See Scope.$new for this logic...
  1343. child.$$prevSibling = parent.$$childTail;
  1344. if (parent.$$childHead) {
  1345. parent.$$childTail.$$nextSibling = child;
  1346. parent.$$childTail = child;
  1347. } else {
  1348. parent.$$childHead = parent.$$childTail = child;
  1349. }
  1350. },
  1351. /*
  1352. * getClosest replicates jQuery.closest() to walk up the DOM tree until it finds a matching nodeName
  1353. *
  1354. * @param el Element to start walking the DOM from
  1355. * @param check Either a string or a function. If a string is passed, it will be evaluated against
  1356. * each of the parent nodes' tag name. If a function is passed, the loop will call it with each of
  1357. * the parents and will use the return value to determine whether the node is a match.
  1358. * @param onlyParent Only start checking from the parent element, not `el`.
  1359. */
  1360. getClosest: function getClosest(el, validateWith, onlyParent) {
  1361. if ( angular.isString(validateWith) ) {
  1362. var tagName = validateWith.toUpperCase();
  1363. validateWith = function(el) {
  1364. return el.nodeName.toUpperCase() === tagName;
  1365. };
  1366. }
  1367. if (el instanceof angular.element) el = el[0];
  1368. if (onlyParent) el = el.parentNode;
  1369. if (!el) return null;
  1370. do {
  1371. if (validateWith(el)) {
  1372. return el;
  1373. }
  1374. } while (el = el.parentNode);
  1375. return null;
  1376. },
  1377. /**
  1378. * Build polyfill for the Node.contains feature (if needed)
  1379. */
  1380. elementContains: function(node, child) {
  1381. var hasContains = (window.Node && window.Node.prototype && Node.prototype.contains);
  1382. var findFn = hasContains ? angular.bind(node, node.contains) : angular.bind(node, function(arg) {
  1383. // compares the positions of two nodes and returns a bitmask
  1384. return (node === child) || !!(this.compareDocumentPosition(arg) & 16);
  1385. });
  1386. return findFn(child);
  1387. },
  1388. /**
  1389. * Functional equivalent for $element.filter(‘md-bottom-sheet’)
  1390. * useful with interimElements where the element and its container are important...
  1391. *
  1392. * @param {[]} elements to scan
  1393. * @param {string} name of node to find (e.g. 'md-dialog')
  1394. * @param {boolean=} optional flag to allow deep scans; defaults to 'false'.
  1395. * @param {boolean=} optional flag to enable log warnings; defaults to false
  1396. */
  1397. extractElementByName: function(element, nodeName, scanDeep, warnNotFound) {
  1398. var found = scanTree(element);
  1399. if (!found && !!warnNotFound) {
  1400. $log.warn( $mdUtil.supplant("Unable to find node '{0}' in element '{1}'.",[nodeName, element[0].outerHTML]) );
  1401. }
  1402. return angular.element(found || element);
  1403. /**
  1404. * Breadth-First tree scan for element with matching `nodeName`
  1405. */
  1406. function scanTree(element) {
  1407. return scanLevel(element) || (scanDeep ? scanChildren(element) : null);
  1408. }
  1409. /**
  1410. * Case-insensitive scan of current elements only (do not descend).
  1411. */
  1412. function scanLevel(element) {
  1413. if ( element ) {
  1414. for (var i = 0, len = element.length; i < len; i++) {
  1415. if (element[i].nodeName.toLowerCase() === nodeName) {
  1416. return element[i];
  1417. }
  1418. }
  1419. }
  1420. return null;
  1421. }
  1422. /**
  1423. * Scan children of specified node
  1424. */
  1425. function scanChildren(element) {
  1426. var found;
  1427. if ( element ) {
  1428. for (var i = 0, len = element.length; i < len; i++) {
  1429. var target = element[i];
  1430. if ( !found ) {
  1431. for (var j = 0, numChild = target.childNodes.length; j < numChild; j++) {
  1432. found = found || scanTree([target.childNodes[j]]);
  1433. }
  1434. }
  1435. }
  1436. }
  1437. return found;
  1438. }
  1439. },
  1440. /**
  1441. * Give optional properties with no value a boolean true if attr provided or false otherwise
  1442. */
  1443. initOptionalProperties: function(scope, attr, defaults) {
  1444. defaults = defaults || {};
  1445. angular.forEach(scope.$$isolateBindings, function(binding, key) {
  1446. if (binding.optional && angular.isUndefined(scope[key])) {
  1447. var attrIsDefined = angular.isDefined(attr[binding.attrName]);
  1448. scope[key] = angular.isDefined(defaults[key]) ? defaults[key] : attrIsDefined;
  1449. }
  1450. });
  1451. },
  1452. /**
  1453. * Alternative to $timeout calls with 0 delay.
  1454. * nextTick() coalesces all calls within a single frame
  1455. * to minimize $digest thrashing
  1456. *
  1457. * @param callback
  1458. * @param digest
  1459. * @returns {*}
  1460. */
  1461. nextTick: function(callback, digest, scope) {
  1462. //-- grab function reference for storing state details
  1463. var nextTick = $mdUtil.nextTick;
  1464. var timeout = nextTick.timeout;
  1465. var queue = nextTick.queue || [];
  1466. //-- add callback to the queue
  1467. queue.push({scope: scope, callback: callback});
  1468. //-- set default value for digest
  1469. if (digest == null) digest = true;
  1470. //-- store updated digest/queue values
  1471. nextTick.digest = nextTick.digest || digest;
  1472. nextTick.queue = queue;
  1473. //-- either return existing timeout or create a new one
  1474. return timeout || (nextTick.timeout = $timeout(processQueue, 0, false));
  1475. /**
  1476. * Grab a copy of the current queue
  1477. * Clear the queue for future use
  1478. * Process the existing queue
  1479. * Trigger digest if necessary
  1480. */
  1481. function processQueue() {
  1482. var queue = nextTick.queue;
  1483. var digest = nextTick.digest;
  1484. nextTick.queue = [];
  1485. nextTick.timeout = null;
  1486. nextTick.digest = false;
  1487. queue.forEach(function(queueItem) {
  1488. var skip = queueItem.scope && queueItem.scope.$$destroyed;
  1489. if (!skip) {
  1490. queueItem.callback();
  1491. }
  1492. });
  1493. if (digest) $rootScope.$digest();
  1494. }
  1495. },
  1496. /**
  1497. * Processes a template and replaces the start/end symbols if the application has
  1498. * overriden them.
  1499. *
  1500. * @param template The template to process whose start/end tags may be replaced.
  1501. * @returns {*}
  1502. */
  1503. processTemplate: function(template) {
  1504. if (usesStandardSymbols) {
  1505. return template;
  1506. } else {
  1507. if (!template || !angular.isString(template)) return template;
  1508. return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);
  1509. }
  1510. },
  1511. /**
  1512. * Scan up dom hierarchy for enabled parent;
  1513. */
  1514. getParentWithPointerEvents: function (element) {
  1515. var parent = element.parent();
  1516. // jqLite might return a non-null, but still empty, parent; so check for parent and length
  1517. while (hasComputedStyle(parent, 'pointer-events', 'none')) {
  1518. parent = parent.parent();
  1519. }
  1520. return parent;
  1521. },
  1522. getNearestContentElement: function (element) {
  1523. var current = element.parent()[0];
  1524. // Look for the nearest parent md-content, stopping at the rootElement.
  1525. while (current && current !== $rootElement[0] && current !== document.body && current.nodeName.toUpperCase() !== 'MD-CONTENT') {
  1526. current = current.parentNode;
  1527. }
  1528. return current;
  1529. },
  1530. /**
  1531. * Checks if the current browser is natively supporting the `sticky` position.
  1532. * @returns {string} supported sticky property name
  1533. */
  1534. checkStickySupport: function() {
  1535. var stickyProp;
  1536. var testEl = angular.element('<div>');
  1537. $document[0].body.appendChild(testEl[0]);
  1538. var stickyProps = ['sticky', '-webkit-sticky'];
  1539. for (var i = 0; i < stickyProps.length; ++i) {
  1540. testEl.css({
  1541. position: stickyProps[i],
  1542. top: 0,
  1543. 'z-index': 2
  1544. });
  1545. if (testEl.css('position') == stickyProps[i]) {
  1546. stickyProp = stickyProps[i];
  1547. break;
  1548. }
  1549. }
  1550. testEl.remove();
  1551. return stickyProp;
  1552. },
  1553. /**
  1554. * Parses an attribute value, mostly a string.
  1555. * By default checks for negated values and returns `false´ if present.
  1556. * Negated values are: (native falsy) and negative strings like:
  1557. * `false` or `0`.
  1558. * @param value Attribute value which should be parsed.
  1559. * @param negatedCheck When set to false, won't check for negated values.
  1560. * @returns {boolean}
  1561. */
  1562. parseAttributeBoolean: function(value, negatedCheck) {
  1563. return value === '' || !!value && (negatedCheck === false || value !== 'false' && value !== '0');
  1564. },
  1565. hasComputedStyle: hasComputedStyle,
  1566. /**
  1567. * Returns true if the parent form of the element has been submitted.
  1568. *
  1569. * @param element An AngularJS or HTML5 element.
  1570. *
  1571. * @returns {boolean}
  1572. */
  1573. isParentFormSubmitted: function(element) {
  1574. var parent = $mdUtil.getClosest(element, 'form');
  1575. var form = parent ? angular.element(parent).controller('form') : null;
  1576. return form ? form.$submitted : false;
  1577. },
  1578. /**
  1579. * Animate the requested element's scrollTop to the requested scrollPosition with basic easing.
  1580. *
  1581. * @param {!HTMLElement} element The element to scroll.
  1582. * @param {number} scrollEnd The new/final scroll position.
  1583. * @param {number=} duration Duration of the scroll. Default is 1000ms.
  1584. */
  1585. animateScrollTo: function(element, scrollEnd, duration) {
  1586. var scrollStart = element.scrollTop;
  1587. var scrollChange = scrollEnd - scrollStart;
  1588. var scrollingDown = scrollStart < scrollEnd;
  1589. var startTime = $mdUtil.now();
  1590. $$rAF(scrollChunk);
  1591. function scrollChunk() {
  1592. var newPosition = calculateNewPosition();
  1593. element.scrollTop = newPosition;
  1594. if (scrollingDown ? newPosition < scrollEnd : newPosition > scrollEnd) {
  1595. $$rAF(scrollChunk);
  1596. }
  1597. }
  1598. function calculateNewPosition() {
  1599. var easeDuration = duration || 1000;
  1600. var currentTime = $mdUtil.now() - startTime;
  1601. return ease(currentTime, scrollStart, scrollChange, easeDuration);
  1602. }
  1603. function ease(currentTime, start, change, duration) {
  1604. // If the duration has passed (which can occur if our app loses focus due to $$rAF), jump
  1605. // straight to the proper position
  1606. if (currentTime > duration) {
  1607. return start + change;
  1608. }
  1609. var ts = (currentTime /= duration) * currentTime;
  1610. var tc = ts * currentTime;
  1611. return start + change * (-2 * tc + 3 * ts);
  1612. }
  1613. },
  1614. /**
  1615. * Provides an easy mechanism for removing duplicates from an array.
  1616. *
  1617. * var myArray = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4];
  1618. *
  1619. * $mdUtil.uniq(myArray) => [1, 2, 3, 4]
  1620. *
  1621. * @param {array} array The array whose unique values should be returned.
  1622. *
  1623. * @returns {array} A copy of the array containing only unique values.
  1624. */
  1625. uniq: function(array) {
  1626. if (!array) { return; }
  1627. return array.filter(function(value, index, self) {
  1628. return self.indexOf(value) === index;
  1629. });
  1630. }
  1631. };
  1632. // Instantiate other namespace utility methods
  1633. $mdUtil.dom.animator = $$mdAnimate($mdUtil);
  1634. return $mdUtil;
  1635. function getNode(el) {
  1636. return el[0] || el;
  1637. }
  1638. }
  1639. /*
  1640. * Since removing jQuery from the demos, some code that uses `element.focus()` is broken.
  1641. * We need to add `element.focus()`, because it's testable unlike `element[0].focus`.
  1642. */
  1643. angular.element.prototype.focus = angular.element.prototype.focus || function() {
  1644. if (this.length) {
  1645. this[0].focus();
  1646. }
  1647. return this;
  1648. };
  1649. angular.element.prototype.blur = angular.element.prototype.blur || function() {
  1650. if (this.length) {
  1651. this[0].blur();
  1652. }
  1653. return this;
  1654. };
  1655. })();
  1656. (function(){
  1657. "use strict";
  1658. /**
  1659. * @ngdoc module
  1660. * @name material.core.aria
  1661. * @description
  1662. * Aria Expectations for AngularJS Material components.
  1663. */
  1664. MdAriaService.$inject = ["$$rAF", "$log", "$window", "$interpolate"];
  1665. angular
  1666. .module('material.core')
  1667. .provider('$mdAria', MdAriaProvider);
  1668. /**
  1669. * @ngdoc service
  1670. * @name $mdAriaProvider
  1671. * @module material.core.aria
  1672. *
  1673. * @description
  1674. *
  1675. * Modify options of the `$mdAria` service, which will be used by most of the AngularJS Material
  1676. * components.
  1677. *
  1678. * You are able to disable `$mdAria` warnings, by using the following markup.
  1679. *
  1680. * <hljs lang="js">
  1681. * app.config(function($mdAriaProvider) {
  1682. * // Globally disables all ARIA warnings.
  1683. * $mdAriaProvider.disableWarnings();
  1684. * });
  1685. * </hljs>
  1686. *
  1687. */
  1688. function MdAriaProvider() {
  1689. var config = {
  1690. /** Whether we should show ARIA warnings in the console if labels are missing on the element */
  1691. showWarnings: true
  1692. };
  1693. return {
  1694. disableWarnings: disableWarnings,
  1695. $get: ["$$rAF", "$log", "$window", "$interpolate", function($$rAF, $log, $window, $interpolate) {
  1696. return MdAriaService.apply(config, arguments);
  1697. }]
  1698. };
  1699. /**
  1700. * @ngdoc method
  1701. * @name $mdAriaProvider#disableWarnings
  1702. * @description Disables all ARIA warnings generated by AngularJS Material.
  1703. */
  1704. function disableWarnings() {
  1705. config.showWarnings = false;
  1706. }
  1707. }
  1708. /*
  1709. * @ngInject
  1710. */
  1711. function MdAriaService($$rAF, $log, $window, $interpolate) {
  1712. // Load the showWarnings option from the current context and store it inside of a scope variable,
  1713. // because the context will be probably lost in some function calls.
  1714. var showWarnings = this.showWarnings;
  1715. return {
  1716. expect: expect,
  1717. expectAsync: expectAsync,
  1718. expectWithText: expectWithText,
  1719. expectWithoutText: expectWithoutText,
  1720. getText: getText,
  1721. hasAriaLabel: hasAriaLabel,
  1722. parentHasAriaLabel: parentHasAriaLabel
  1723. };
  1724. /**
  1725. * Check if expected attribute has been specified on the target element or child
  1726. * @param element
  1727. * @param attrName
  1728. * @param {optional} defaultValue What to set the attr to if no value is found
  1729. */
  1730. function expect(element, attrName, defaultValue) {
  1731. var node = angular.element(element)[0] || element;
  1732. // if node exists and neither it nor its children have the attribute
  1733. if (node &&
  1734. ((!node.hasAttribute(attrName) ||
  1735. node.getAttribute(attrName).length === 0) &&
  1736. !childHasAttribute(node, attrName))) {
  1737. defaultValue = angular.isString(defaultValue) ? defaultValue.trim() : '';
  1738. if (defaultValue.length) {
  1739. element.attr(attrName, defaultValue);
  1740. } else if (showWarnings) {
  1741. $log.warn('ARIA: Attribute "', attrName, '", required for accessibility, is missing on node:', node);
  1742. }
  1743. }
  1744. }
  1745. function expectAsync(element, attrName, defaultValueGetter) {
  1746. // Problem: when retrieving the element's contents synchronously to find the label,
  1747. // the text may not be defined yet in the case of a binding.
  1748. // There is a higher chance that a binding will be defined if we wait one frame.
  1749. $$rAF(function() {
  1750. expect(element, attrName, defaultValueGetter());
  1751. });
  1752. }
  1753. function expectWithText(element, attrName) {
  1754. var content = getText(element) || "";
  1755. var hasBinding = content.indexOf($interpolate.startSymbol()) > -1;
  1756. if (hasBinding) {
  1757. expectAsync(element, attrName, function() {
  1758. return getText(element);
  1759. });
  1760. } else {
  1761. expect(element, attrName, content);
  1762. }
  1763. }
  1764. function expectWithoutText(element, attrName) {
  1765. var content = getText(element);
  1766. var hasBinding = content.indexOf($interpolate.startSymbol()) > -1;
  1767. if ( !hasBinding && !content) {
  1768. expect(element, attrName, content);
  1769. }
  1770. }
  1771. function getText(element) {
  1772. element = element[0] || element;
  1773. var walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, null, false);
  1774. var text = '';
  1775. var node;
  1776. while (node = walker.nextNode()) {
  1777. if (!isAriaHiddenNode(node)) {
  1778. text += node.textContent;
  1779. }
  1780. }
  1781. return text.trim() || '';
  1782. function isAriaHiddenNode(node) {
  1783. while (node.parentNode && (node = node.parentNode) !== element) {
  1784. if (node.getAttribute && node.getAttribute('aria-hidden') === 'true') {
  1785. return true;
  1786. }
  1787. }
  1788. }
  1789. }
  1790. function childHasAttribute(node, attrName) {
  1791. var hasChildren = node.hasChildNodes(),
  1792. hasAttr = false;
  1793. function isHidden(el) {
  1794. var style = el.currentStyle ? el.currentStyle : $window.getComputedStyle(el);
  1795. return (style.display === 'none');
  1796. }
  1797. if (hasChildren) {
  1798. var children = node.childNodes;
  1799. for (var i=0; i < children.length; i++) {
  1800. var child = children[i];
  1801. if (child.nodeType === 1 && child.hasAttribute(attrName)) {
  1802. if (!isHidden(child)) {
  1803. hasAttr = true;
  1804. }
  1805. }
  1806. }
  1807. }
  1808. return hasAttr;
  1809. }
  1810. /**
  1811. * Check if expected element has aria label attribute
  1812. * @param element
  1813. */
  1814. function hasAriaLabel(element) {
  1815. var node = angular.element(element)[0] || element;
  1816. /* Check if compatible node type (ie: not HTML Document node) */
  1817. if (!node.hasAttribute) {
  1818. return false;
  1819. }
  1820. /* Check label or description attributes */
  1821. return node.hasAttribute('aria-label') || node.hasAttribute('aria-labelledby') || node.hasAttribute('aria-describedby');
  1822. }
  1823. /**
  1824. * Check if expected element's parent has aria label attribute and has valid role and tagName
  1825. * @param element
  1826. * @param {optional} level Number of levels deep search should be performed
  1827. */
  1828. function parentHasAriaLabel(element, level) {
  1829. level = level || 1;
  1830. var node = angular.element(element)[0] || element;
  1831. if (!node.parentNode) {
  1832. return false;
  1833. }
  1834. if (performCheck(node.parentNode)) {
  1835. return true;
  1836. }
  1837. level--;
  1838. if (level) {
  1839. return parentHasAriaLabel(node.parentNode, level);
  1840. }
  1841. return false;
  1842. function performCheck(parentNode) {
  1843. if (!hasAriaLabel(parentNode)) {
  1844. return false;
  1845. }
  1846. /* Perform role blacklist check */
  1847. if (parentNode.hasAttribute('role')) {
  1848. switch(parentNode.getAttribute('role').toLowerCase()) {
  1849. case 'command':
  1850. case 'definition':
  1851. case 'directory':
  1852. case 'grid':
  1853. case 'list':
  1854. case 'listitem':
  1855. case 'log':
  1856. case 'marquee':
  1857. case 'menu':
  1858. case 'menubar':
  1859. case 'note':
  1860. case 'presentation':
  1861. case 'separator':
  1862. case 'scrollbar':
  1863. case 'status':
  1864. case 'tablist':
  1865. return false;
  1866. }
  1867. }
  1868. /* Perform tagName blacklist check */
  1869. switch(parentNode.tagName.toLowerCase()) {
  1870. case 'abbr':
  1871. case 'acronym':
  1872. case 'address':
  1873. case 'applet':
  1874. case 'audio':
  1875. case 'b':
  1876. case 'bdi':
  1877. case 'bdo':
  1878. case 'big':
  1879. case 'blockquote':
  1880. case 'br':
  1881. case 'canvas':
  1882. case 'caption':
  1883. case 'center':
  1884. case 'cite':
  1885. case 'code':
  1886. case 'col':
  1887. case 'data':
  1888. case 'dd':
  1889. case 'del':
  1890. case 'dfn':
  1891. case 'dir':
  1892. case 'div':
  1893. case 'dl':
  1894. case 'em':
  1895. case 'embed':
  1896. case 'fieldset':
  1897. case 'figcaption':
  1898. case 'font':
  1899. case 'h1':
  1900. case 'h2':
  1901. case 'h3':
  1902. case 'h4':
  1903. case 'h5':
  1904. case 'h6':
  1905. case 'hgroup':
  1906. case 'html':
  1907. case 'i':
  1908. case 'ins':
  1909. case 'isindex':
  1910. case 'kbd':
  1911. case 'keygen':
  1912. case 'label':
  1913. case 'legend':
  1914. case 'li':
  1915. case 'map':
  1916. case 'mark':
  1917. case 'menu':
  1918. case 'object':
  1919. case 'ol':
  1920. case 'output':
  1921. case 'pre':
  1922. case 'presentation':
  1923. case 'q':
  1924. case 'rt':
  1925. case 'ruby':
  1926. case 'samp':
  1927. case 'small':
  1928. case 'source':
  1929. case 'span':
  1930. case 'status':
  1931. case 'strike':
  1932. case 'strong':
  1933. case 'sub':
  1934. case 'sup':
  1935. case 'svg':
  1936. case 'tbody':
  1937. case 'td':
  1938. case 'th':
  1939. case 'thead':
  1940. case 'time':
  1941. case 'tr':
  1942. case 'track':
  1943. case 'tt':
  1944. case 'ul':
  1945. case 'var':
  1946. return false;
  1947. }
  1948. return true;
  1949. }
  1950. }
  1951. }
  1952. })();
  1953. (function(){
  1954. "use strict";
  1955. /**
  1956. * @ngdoc module
  1957. * @name material.core.compiler
  1958. * @description
  1959. * AngularJS Material template and element compiler.
  1960. */
  1961. angular
  1962. .module('material.core')
  1963. .provider('$mdCompiler', MdCompilerProvider);
  1964. /**
  1965. * @ngdoc service
  1966. * @name $mdCompiler
  1967. * @module material.core.compiler
  1968. * @description
  1969. * The $mdCompiler service is an abstraction of AngularJS's compiler, that allows developers
  1970. * to easily compile an element with options like in a Directive Definition Object.
  1971. *
  1972. * > The compiler powers a lot of components inside of AngularJS Material.
  1973. * > Like the `$mdPanel` or `$mdDialog`.
  1974. *
  1975. * @usage
  1976. *
  1977. * Basic Usage with a template
  1978. *
  1979. * <hljs lang="js">
  1980. * $mdCompiler.compile({
  1981. * templateUrl: 'modal.html',
  1982. * controller: 'ModalCtrl',
  1983. * locals: {
  1984. * modal: myModalInstance;
  1985. * }
  1986. * }).then(function (compileData) {
  1987. * compileData.element; // Compiled DOM element
  1988. * compileData.link(myScope); // Instantiate controller and link element to scope.
  1989. * });
  1990. * </hljs>
  1991. *
  1992. * Example with a content element
  1993. *
  1994. * <hljs lang="js">
  1995. *
  1996. * // Create a virtual element and link it manually.
  1997. * // The compiler doesn't need to recompile the element each time.
  1998. * var myElement = $compile('<span>Test</span>')(myScope);
  1999. *
  2000. * $mdCompiler.compile({
  2001. * contentElement: myElement
  2002. * }).then(function (compileData) {
  2003. * compileData.element // Content Element (same as above)
  2004. * compileData.link // This does nothing when using a contentElement.
  2005. * });
  2006. * </hljs>
  2007. *
  2008. * > Content Element is a significant performance improvement when the developer already knows that the
  2009. * > compiled element will be always the same and the scope will not change either.
  2010. *
  2011. * The `contentElement` option also supports DOM elements which will be temporary removed and restored
  2012. * at its old position.
  2013. *
  2014. * <hljs lang="js">
  2015. * var domElement = document.querySelector('#myElement');
  2016. *
  2017. * $mdCompiler.compile({
  2018. * contentElement: myElement
  2019. * }).then(function (compileData) {
  2020. * compileData.element // Content Element (same as above)
  2021. * compileData.link // This does nothing when using a contentElement.
  2022. * });
  2023. * </hljs>
  2024. *
  2025. * The `$mdCompiler` can also query for the element in the DOM itself.
  2026. *
  2027. * <hljs lang="js">
  2028. * $mdCompiler.compile({
  2029. * contentElement: '#myElement'
  2030. * }).then(function (compileData) {
  2031. * compileData.element // Content Element (same as above)
  2032. * compileData.link // This does nothing when using a contentElement.
  2033. * });
  2034. * </hljs>
  2035. *
  2036. */
  2037. MdCompilerProvider.$inject = ['$compileProvider'];
  2038. function MdCompilerProvider($compileProvider) {
  2039. var provider = this;
  2040. /**
  2041. * @name $mdCompilerProvider#respectPreAssignBindingsEnabled
  2042. *
  2043. * @param {boolean=} respected update the respectPreAssignBindingsEnabled state if provided, otherwise just return
  2044. * the current Material preAssignBindingsEnabled state
  2045. * @returns {*} current value if used as getter or itself (chaining) if used as setter
  2046. *
  2047. * @description
  2048. * Call this method to enable/disable whether Material-specific (dialogs/toasts) controllers respect the AngularJS
  2049. * `$compile.preAssignBindingsEnabled` flag. Note that this doesn't affect directives/components created via
  2050. * regular AngularJS methods which constitute most Material & user-created components.
  2051. *
  2052. * @see [AngularJS documentation for `$compile.preAssignBindingsEnabled`
  2053. * ](https://code.angularjs.org/1.6.4/docs/api/ng/provider/$compileProvider#preAssignBindingsEnabled)
  2054. * for more information.
  2055. *
  2056. * If disabled (false), the compiler assigns the value of each of the bindings to the
  2057. * properties of the controller object before the constructor of this object is called.
  2058. *
  2059. * If enabled (true) the behavior depends on the AngularJS version used:
  2060. *
  2061. * - `<1.5.10` - bindings are pre-assigned
  2062. * - `>=1.5.10 <1.7` - behaves like set to whatever `$compileProvider.preAssignBindingsEnabled()` reports; if
  2063. * the `$compileProvider` flag wasn't set manually, it defaults to pre-assigning bindings
  2064. * with AngularJS `1.5.x` & to calling the constructor first with AngularJS `1.6.x`.
  2065. * - `>=1.7` - the compiler calls the constructor first before assigning bindings
  2066. *
  2067. * The default value is `false` but will change to `true` in AngularJS Material 1.2.
  2068. *
  2069. * It is recommended to set this flag to `true` in AngularJS Material 1.1.x; the only reason it's not set that way
  2070. * by default is backwards compatibility. Not setting the flag to `true` when
  2071. * `$compileProvider.preAssignBindingsEnabled()` is set to `false` (i.e. default behavior in AngularJS 1.6.0 or newer)
  2072. * makes it hard to unit test Material Dialog/Toast controllers using the `$controller` helper as it always follows
  2073. * the `$compileProvider.preAssignBindingsEnabled()` value.
  2074. */
  2075. // TODO change it to `true` in Material 1.2.
  2076. var respectPreAssignBindingsEnabled = false;
  2077. this.respectPreAssignBindingsEnabled = function(respected) {
  2078. if (angular.isDefined(respected)) {
  2079. respectPreAssignBindingsEnabled = respected;
  2080. return this;
  2081. }
  2082. return respectPreAssignBindingsEnabled;
  2083. };
  2084. /**
  2085. * @description
  2086. * This function returns `true` if Material-specific (dialogs/toasts) controllers have bindings pre-assigned in
  2087. * controller constructors and `false` otherwise.
  2088. *
  2089. * Note that this doesn't affect directives/components created via regular AngularJS methods which constitute most
  2090. * Material & user-created components; their behavior can be checked via `$compileProvider.preAssignBindingsEnabled()`
  2091. * in AngularJS `>=1.5.10 <1.7.0`.
  2092. *
  2093. * @returns {*} current preAssignBindingsEnabled state
  2094. */
  2095. function getPreAssignBindingsEnabled() {
  2096. if (!respectPreAssignBindingsEnabled) {
  2097. // respectPreAssignBindingsEnabled === false
  2098. // We're ignoring the AngularJS `$compileProvider.preAssignBindingsEnabled()` value in this case.
  2099. return true;
  2100. }
  2101. // respectPreAssignBindingsEnabled === true
  2102. if (typeof $compileProvider.preAssignBindingsEnabled === 'function') {
  2103. return $compileProvider.preAssignBindingsEnabled();
  2104. }
  2105. // Flag respected but not present => apply logic based on AngularJS version used.
  2106. if (angular.version.major === 1 && angular.version.minor < 6) {
  2107. // AngularJS <1.5.10
  2108. return true;
  2109. }
  2110. // AngularJS >=1.7.0
  2111. return false;
  2112. }
  2113. this.$get = ["$q", "$templateRequest", "$injector", "$compile", "$controller",
  2114. function($q, $templateRequest, $injector, $compile, $controller) {
  2115. return new MdCompilerService($q, $templateRequest, $injector, $compile, $controller);
  2116. }];
  2117. function MdCompilerService($q, $templateRequest, $injector, $compile, $controller) {
  2118. /** @private @const {!angular.$q} */
  2119. this.$q = $q;
  2120. /** @private @const {!angular.$templateRequest} */
  2121. this.$templateRequest = $templateRequest;
  2122. /** @private @const {!angular.$injector} */
  2123. this.$injector = $injector;
  2124. /** @private @const {!angular.$compile} */
  2125. this.$compile = $compile;
  2126. /** @private @const {!angular.$controller} */
  2127. this.$controller = $controller;
  2128. }
  2129. /**
  2130. * @ngdoc method
  2131. * @name $mdCompiler#compile
  2132. * @description
  2133. *
  2134. * A method to compile a HTML template with the AngularJS compiler.
  2135. * The `$mdCompiler` is wrapper around the AngularJS compiler and provides extra functionality
  2136. * like controller instantiation or async resolves.
  2137. *
  2138. * @param {!Object} options An options object, with the following properties:
  2139. *
  2140. * - `controller` - `{string|Function}` Controller fn that should be associated with
  2141. * newly created scope or the name of a registered controller if passed as a string.
  2142. * - `controllerAs` - `{string=}` A controller alias name. If present the controller will be
  2143. * published to scope under the `controllerAs` name.
  2144. * - `contentElement` - `{string|Element}`: Instead of using a template, which will be
  2145. * compiled each time, you can also use a DOM element.<br/>
  2146. * - `template` - `{string=}` An html template as a string.
  2147. * - `templateUrl` - `{string=}` A path to an html template.
  2148. * - `transformTemplate` - `{function(template)=}` A function which transforms the template after
  2149. * it is loaded. It will be given the template string as a parameter, and should
  2150. * return a a new string representing the transformed template.
  2151. * - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should
  2152. * be injected into the controller. If any of these dependencies are promises, the compiler
  2153. * will wait for them all to be resolved, or if one is rejected before the controller is
  2154. * instantiated `compile()` will fail..
  2155. * * `key` - `{string}`: a name of a dependency to be injected into the controller.
  2156. * * `factory` - `{string|function}`: If `string` then it is an alias for a service.
  2157. * Otherwise if function, then it is injected and the return value is treated as the
  2158. * dependency. If the result is a promise, it is resolved before its value is
  2159. * injected into the controller.
  2160. *
  2161. * @returns {Object} promise A promise, which will be resolved with a `compileData` object.
  2162. * `compileData` has the following properties:
  2163. *
  2164. * - `element` - `{element}`: an uncompiled element matching the provided template.
  2165. * - `link` - `{function(scope)}`: A link function, which, when called, will compile
  2166. * the element and instantiate the provided controller (if given).
  2167. * - `locals` - `{object}`: The locals which will be passed into the controller once `link` is
  2168. * called. If `bindToController` is true, they will be coppied to the ctrl instead
  2169. *
  2170. */
  2171. MdCompilerService.prototype.compile = function(options) {
  2172. if (options.contentElement) {
  2173. return this._prepareContentElement(options);
  2174. } else {
  2175. return this._compileTemplate(options);
  2176. }
  2177. };
  2178. /**
  2179. * Instead of compiling any template, the compiler just fetches an existing HTML element from the DOM and
  2180. * provides a restore function to put the element back it old DOM position.
  2181. * @param {!Object} options Options to be used for the compiler.
  2182. */
  2183. MdCompilerService.prototype._prepareContentElement = function(options) {
  2184. var contentElement = this._fetchContentElement(options);
  2185. return this.$q.resolve({
  2186. element: contentElement.element,
  2187. cleanup: contentElement.restore,
  2188. locals: {},
  2189. link: function() {
  2190. return contentElement.element;
  2191. }
  2192. });
  2193. };
  2194. /**
  2195. * Compiles a template by considering all options and waiting for all resolves to be ready.
  2196. * @param {!Object} options Compile options
  2197. * @returns {!Object} Compile data with link function.
  2198. */
  2199. MdCompilerService.prototype._compileTemplate = function(options) {
  2200. var self = this;
  2201. var templateUrl = options.templateUrl;
  2202. var template = options.template || '';
  2203. var resolve = angular.extend({}, options.resolve);
  2204. var locals = angular.extend({}, options.locals);
  2205. var transformTemplate = options.transformTemplate || angular.identity;
  2206. // Take resolve values and invoke them.
  2207. // Resolves can either be a string (value: 'MyRegisteredAngularConst'),
  2208. // or an invokable 'factory' of sorts: (value: function ValueGetter($dependency) {})
  2209. angular.forEach(resolve, function(value, key) {
  2210. if (angular.isString(value)) {
  2211. resolve[key] = self.$injector.get(value);
  2212. } else {
  2213. resolve[key] = self.$injector.invoke(value);
  2214. }
  2215. });
  2216. // Add the locals, which are just straight values to inject
  2217. // eg locals: { three: 3 }, will inject three into the controller
  2218. angular.extend(resolve, locals);
  2219. if (templateUrl) {
  2220. resolve.$$ngTemplate = this.$templateRequest(templateUrl);
  2221. } else {
  2222. resolve.$$ngTemplate = this.$q.when(template);
  2223. }
  2224. // Wait for all the resolves to finish if they are promises
  2225. return this.$q.all(resolve).then(function(locals) {
  2226. var template = transformTemplate(locals.$$ngTemplate, options);
  2227. var element = options.element || angular.element('<div>').html(template.trim()).contents();
  2228. return self._compileElement(locals, element, options);
  2229. });
  2230. };
  2231. /**
  2232. * Method to compile an element with the given options.
  2233. * @param {!Object} locals Locals to be injected to the controller if present
  2234. * @param {!JQLite} element Element to be compiled and linked
  2235. * @param {!Object} options Options to be used for linking.
  2236. * @returns {!Object} Compile data with link function.
  2237. */
  2238. MdCompilerService.prototype._compileElement = function(locals, element, options) {
  2239. var self = this;
  2240. var ngLinkFn = this.$compile(element);
  2241. var compileData = {
  2242. element: element,
  2243. cleanup: element.remove.bind(element),
  2244. locals: locals,
  2245. link: linkFn
  2246. };
  2247. function linkFn(scope) {
  2248. locals.$scope = scope;
  2249. // Instantiate controller if the developer provided one.
  2250. if (options.controller) {
  2251. var injectLocals = angular.extend({}, locals, {
  2252. $element: element
  2253. });
  2254. // Create the specified controller instance.
  2255. var ctrl = self._createController(options, injectLocals, locals);
  2256. // Unique identifier for AngularJS Route ngView controllers.
  2257. element.data('$ngControllerController', ctrl);
  2258. element.children().data('$ngControllerController', ctrl);
  2259. // Expose the instantiated controller to the compile data
  2260. compileData.controller = ctrl;
  2261. }
  2262. // Invoke the AngularJS $compile link function.
  2263. return ngLinkFn(scope);
  2264. }
  2265. return compileData;
  2266. };
  2267. /**
  2268. * Creates and instantiates a new controller with the specified options.
  2269. * @param {!Object} options Options that include the controller
  2270. * @param {!Object} injectLocals Locals to to be provided in the controller DI.
  2271. * @param {!Object} locals Locals to be injected to the controller.
  2272. * @returns {!Object} Created controller instance.
  2273. */
  2274. MdCompilerService.prototype._createController = function(options, injectLocals, locals) {
  2275. // The third and fourth arguments to $controller are considered private and are undocumented:
  2276. // https://github.com/angular/angular.js/blob/master/src/ng/controller.js#L86
  2277. // Passing `true` as the third argument causes `$controller` to return a function that
  2278. // gets the controller instance instead returning of the instance directly. When the
  2279. // controller is defined as a function, `invokeCtrl.instance` is the *same instance* as
  2280. // `invokeCtrl()`. However, then the controller is an ES6 class, `invokeCtrl.instance` is a
  2281. // *different instance* from `invokeCtrl()`.
  2282. var invokeCtrl = this.$controller(options.controller, injectLocals, true, options.controllerAs);
  2283. if (getPreAssignBindingsEnabled() && options.bindToController) {
  2284. angular.extend(invokeCtrl.instance, locals);
  2285. }
  2286. // Instantiate and initialize the specified controller.
  2287. var ctrl = invokeCtrl();
  2288. if (!getPreAssignBindingsEnabled() && options.bindToController) {
  2289. angular.extend(ctrl, locals);
  2290. }
  2291. // Call the $onInit hook if it's present on the controller.
  2292. angular.isFunction(ctrl.$onInit) && ctrl.$onInit();
  2293. return ctrl;
  2294. };
  2295. /**
  2296. * Fetches an element removing it from the DOM and using it temporary for the compiler.
  2297. * Elements which were fetched will be restored after use.
  2298. * @param {!Object} options Options to be used for the compilation.
  2299. * @returns {{element: !JQLite, restore: !Function}}
  2300. */
  2301. MdCompilerService.prototype._fetchContentElement = function(options) {
  2302. var contentEl = options.contentElement;
  2303. var restoreFn = null;
  2304. if (angular.isString(contentEl)) {
  2305. contentEl = document.querySelector(contentEl);
  2306. restoreFn = createRestoreFn(contentEl);
  2307. } else {
  2308. contentEl = contentEl[0] || contentEl;
  2309. // When the element is visible in the DOM, then we restore it at close of the dialog.
  2310. // Otherwise it will be removed from the DOM after close.
  2311. if (document.contains(contentEl)) {
  2312. restoreFn = createRestoreFn(contentEl);
  2313. } else {
  2314. restoreFn = function() {
  2315. if (contentEl.parentNode) {
  2316. contentEl.parentNode.removeChild(contentEl);
  2317. }
  2318. };
  2319. }
  2320. }
  2321. return {
  2322. element: angular.element(contentEl),
  2323. restore: restoreFn
  2324. };
  2325. function createRestoreFn(element) {
  2326. var parent = element.parentNode;
  2327. var nextSibling = element.nextElementSibling;
  2328. return function() {
  2329. if (!nextSibling) {
  2330. // When the element didn't had any sibling, then it can be simply appended to the
  2331. // parent, because it plays no role, which index it had before.
  2332. parent.appendChild(element);
  2333. } else {
  2334. // When the element had a sibling, which marks the previous position of the element
  2335. // in the DOM, we insert it correctly before the sibling, to have the same index as
  2336. // before.
  2337. parent.insertBefore(element, nextSibling);
  2338. }
  2339. };
  2340. }
  2341. };
  2342. }
  2343. })();
  2344. (function(){
  2345. "use strict";
  2346. MdGesture.$inject = ["$$MdGestureHandler", "$$rAF", "$timeout"];
  2347. attachToDocument.$inject = ["$mdGesture", "$$MdGestureHandler"];var HANDLERS = {};
  2348. /**
  2349. * The state of the current 'pointer'. The pointer represents the state of the current touch.
  2350. * It contains normalized x and y coordinates from DOM events,
  2351. * as well as other information abstracted from the DOM.
  2352. */
  2353. var pointer, lastPointer, forceSkipClickHijack = false, maxClickDistance = 6;
  2354. /**
  2355. * The position of the most recent click if that click was on a label element.
  2356. * @type {{x: number, y: number}|null}
  2357. */
  2358. var lastLabelClickPos = null;
  2359. // Used to attach event listeners once when multiple ng-apps are running.
  2360. var isInitialized = false;
  2361. /**
  2362. * @ngdoc module
  2363. * @name material.core.gestures
  2364. * @description
  2365. * AngularJS Material Gesture handling for touch devices. This module replaced the usage of the hammerjs library.
  2366. */
  2367. angular
  2368. .module('material.core.gestures', [ ])
  2369. .provider('$mdGesture', MdGestureProvider)
  2370. .factory('$$MdGestureHandler', MdGestureHandler)
  2371. .run(attachToDocument);
  2372. /**
  2373. * @ngdoc service
  2374. * @name $mdGestureProvider
  2375. * @module material.core.gestures
  2376. *
  2377. * @description
  2378. * In some scenarios on mobile devices (without jQuery), the click events should NOT be hijacked.
  2379. * `$mdGestureProvider` is used to configure the Gesture module to ignore or skip click hijacking on mobile
  2380. * devices.
  2381. *
  2382. * You can also change the max click distance, `6px` by default, if you have issues on some touch screens.
  2383. *
  2384. * <hljs lang="js">
  2385. * app.config(function($mdGestureProvider) {
  2386. *
  2387. * // For mobile devices without jQuery loaded, do not
  2388. * // intercept click events during the capture phase.
  2389. * $mdGestureProvider.skipClickHijack();
  2390. *
  2391. * // If hijacking clicks, you may want to change the default click distance
  2392. * $mdGestureProvider.setMaxClickDistance(12);
  2393. * });
  2394. * </hljs>
  2395. *
  2396. */
  2397. function MdGestureProvider() { }
  2398. MdGestureProvider.prototype = {
  2399. // Publish access to setter to configure a variable BEFORE the
  2400. // $mdGesture service is instantiated...
  2401. /**
  2402. * @ngdoc method
  2403. * @name $mdGestureProvider#skipClickHijack
  2404. *
  2405. * @description
  2406. * Tell the AngularJS Material Gesture module to skip (or ignore) click hijacking on mobile devices.
  2407. */
  2408. skipClickHijack: function() {
  2409. return forceSkipClickHijack = true;
  2410. },
  2411. /**
  2412. * @ngdoc method
  2413. * @name $mdGestureProvider#setMaxClickDistance
  2414. * @param clickDistance {string} Distance in pixels. I.e. `12px`.
  2415. * @description
  2416. * Set the max distance from the origin of the touch event to trigger touch handlers.
  2417. */
  2418. setMaxClickDistance: function(clickDistance) {
  2419. maxClickDistance = parseInt(clickDistance);
  2420. },
  2421. /**
  2422. * $get is used to build an instance of $mdGesture
  2423. * @ngInject
  2424. */
  2425. $get : ["$$MdGestureHandler", "$$rAF", "$timeout", function($$MdGestureHandler, $$rAF, $timeout) {
  2426. return new MdGesture($$MdGestureHandler, $$rAF, $timeout);
  2427. }]
  2428. };
  2429. /**
  2430. * MdGesture factory construction function
  2431. * @ngInject
  2432. */
  2433. function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
  2434. var userAgent = navigator.userAgent || navigator.vendor || window.opera;
  2435. var isIos = userAgent.match(/ipad|iphone|ipod/i);
  2436. var isAndroid = userAgent.match(/android/i);
  2437. var touchActionProperty = getTouchAction();
  2438. var hasJQuery = (typeof window.jQuery !== 'undefined') && (angular.element === window.jQuery);
  2439. var self = {
  2440. handler: addHandler,
  2441. register: register,
  2442. isAndroid: isAndroid,
  2443. isIos: isIos,
  2444. // On mobile w/out jQuery, we normally intercept clicks. Should we skip that?
  2445. isHijackingClicks: (isIos || isAndroid) && !hasJQuery && !forceSkipClickHijack
  2446. };
  2447. if (self.isHijackingClicks) {
  2448. self.handler('click', {
  2449. options: {
  2450. maxDistance: maxClickDistance
  2451. },
  2452. onEnd: checkDistanceAndEmit('click')
  2453. });
  2454. self.handler('focus', {
  2455. options: {
  2456. maxDistance: maxClickDistance
  2457. },
  2458. onEnd: function(ev, pointer) {
  2459. if (pointer.distance < this.state.options.maxDistance && canFocus(ev.target)) {
  2460. this.dispatchEvent(ev, 'focus', pointer);
  2461. ev.target.focus();
  2462. }
  2463. }
  2464. });
  2465. self.handler('mouseup', {
  2466. options: {
  2467. maxDistance: maxClickDistance
  2468. },
  2469. onEnd: checkDistanceAndEmit('mouseup')
  2470. });
  2471. self.handler('mousedown', {
  2472. onStart: function(ev) {
  2473. this.dispatchEvent(ev, 'mousedown');
  2474. }
  2475. });
  2476. }
  2477. function checkDistanceAndEmit(eventName) {
  2478. return function(ev, pointer) {
  2479. if (pointer.distance < this.state.options.maxDistance) {
  2480. this.dispatchEvent(ev, eventName, pointer);
  2481. }
  2482. };
  2483. }
  2484. /**
  2485. * Register an element to listen for a handler.
  2486. * This allows an element to override the default options for a handler.
  2487. * Additionally, some handlers like drag and hold only dispatch events if
  2488. * the domEvent happens inside an element that's registered to listen for these events.
  2489. *
  2490. * @see GestureHandler for how overriding of default options works.
  2491. * @example $mdGesture.register(myElement, 'drag', { minDistance: 20, horizontal: false })
  2492. */
  2493. function register(element, handlerName, options) {
  2494. var handler = HANDLERS[handlerName.replace(/^\$md./, '')];
  2495. if (!handler) {
  2496. throw new Error('Failed to register element with handler ' + handlerName + '. ' +
  2497. 'Available handlers: ' + Object.keys(HANDLERS).join(', '));
  2498. }
  2499. return handler.registerElement(element, options);
  2500. }
  2501. /*
  2502. * add a handler to $mdGesture. see below.
  2503. */
  2504. function addHandler(name, definition) {
  2505. var handler = new $$MdGestureHandler(name);
  2506. angular.extend(handler, definition);
  2507. HANDLERS[name] = handler;
  2508. return self;
  2509. }
  2510. /**
  2511. * Register handlers. These listen to touch/start/move events, interpret them,
  2512. * and dispatch gesture events depending on options & conditions. These are all
  2513. * instances of GestureHandler.
  2514. * @see GestureHandler
  2515. */
  2516. return self
  2517. /*
  2518. * The press handler dispatches an event on touchdown/touchend.
  2519. * It's a simple abstraction of touch/mouse/pointer start and end.
  2520. */
  2521. .handler('press', {
  2522. onStart: function (ev, pointer) {
  2523. this.dispatchEvent(ev, '$md.pressdown');
  2524. },
  2525. onEnd: function (ev, pointer) {
  2526. this.dispatchEvent(ev, '$md.pressup');
  2527. }
  2528. })
  2529. /*
  2530. * The hold handler dispatches an event if the user keeps their finger within
  2531. * the same <maxDistance> area for <delay> ms.
  2532. * The hold handler will only run if a parent of the touch target is registered
  2533. * to listen for hold events through $mdGesture.register()
  2534. */
  2535. .handler('hold', {
  2536. options: {
  2537. maxDistance: 6,
  2538. delay: 500
  2539. },
  2540. onCancel: function () {
  2541. $timeout.cancel(this.state.timeout);
  2542. },
  2543. onStart: function (ev, pointer) {
  2544. // For hold, require a parent to be registered with $mdGesture.register()
  2545. // Because we prevent scroll events, this is necessary.
  2546. if (!this.state.registeredParent) return this.cancel();
  2547. this.state.pos = {x: pointer.x, y: pointer.y};
  2548. this.state.timeout = $timeout(angular.bind(this, function holdDelayFn() {
  2549. this.dispatchEvent(ev, '$md.hold');
  2550. this.cancel(); //we're done!
  2551. }), this.state.options.delay, false);
  2552. },
  2553. onMove: function (ev, pointer) {
  2554. // Don't scroll while waiting for hold.
  2555. // If we don't preventDefault touchmove events here, Android will assume we don't
  2556. // want to listen to anymore touch events. It will start scrolling and stop sending
  2557. // touchmove events.
  2558. if (!touchActionProperty && ev.type === 'touchmove') ev.preventDefault();
  2559. // If the user moves greater than <maxDistance> pixels, stop the hold timer
  2560. // set in onStart
  2561. var dx = this.state.pos.x - pointer.x;
  2562. var dy = this.state.pos.y - pointer.y;
  2563. if (Math.sqrt(dx * dx + dy * dy) > this.options.maxDistance) {
  2564. this.cancel();
  2565. }
  2566. },
  2567. onEnd: function () {
  2568. this.onCancel();
  2569. }
  2570. })
  2571. /*
  2572. * The drag handler dispatches a drag event if the user holds and moves his finger greater than
  2573. * <minDistance> px in the x or y direction, depending on options.horizontal.
  2574. * The drag will be cancelled if the user moves his finger greater than <minDistance>*<cancelMultiplier> in
  2575. * the perpendicular direction. Eg if the drag is horizontal and the user moves his finger <minDistance>*<cancelMultiplier>
  2576. * pixels vertically, this handler won't consider the move part of a drag.
  2577. */
  2578. .handler('drag', {
  2579. options: {
  2580. minDistance: 6,
  2581. horizontal: true,
  2582. cancelMultiplier: 1.5
  2583. },
  2584. onSetup: function(element, options) {
  2585. if (touchActionProperty) {
  2586. // We check for horizontal to be false, because otherwise we would overwrite the default opts.
  2587. this.oldTouchAction = element[0].style[touchActionProperty];
  2588. element[0].style[touchActionProperty] = options.horizontal ? 'pan-y' : 'pan-x';
  2589. }
  2590. },
  2591. onCleanup: function(element) {
  2592. if (this.oldTouchAction) {
  2593. element[0].style[touchActionProperty] = this.oldTouchAction;
  2594. }
  2595. },
  2596. onStart: function (ev) {
  2597. // For drag, require a parent to be registered with $mdGesture.register()
  2598. if (!this.state.registeredParent) this.cancel();
  2599. },
  2600. onMove: function (ev, pointer) {
  2601. var shouldStartDrag, shouldCancel;
  2602. // Don't scroll while deciding if this touchmove qualifies as a drag event.
  2603. // If we don't preventDefault touchmove events here, Android will assume we don't
  2604. // want to listen to anymore touch events. It will start scrolling and stop sending
  2605. // touchmove events.
  2606. if (!touchActionProperty && ev.type === 'touchmove') ev.preventDefault();
  2607. if (!this.state.dragPointer) {
  2608. if (this.state.options.horizontal) {
  2609. shouldStartDrag = Math.abs(pointer.distanceX) > this.state.options.minDistance;
  2610. shouldCancel = Math.abs(pointer.distanceY) > this.state.options.minDistance * this.state.options.cancelMultiplier;
  2611. } else {
  2612. shouldStartDrag = Math.abs(pointer.distanceY) > this.state.options.minDistance;
  2613. shouldCancel = Math.abs(pointer.distanceX) > this.state.options.minDistance * this.state.options.cancelMultiplier;
  2614. }
  2615. if (shouldStartDrag) {
  2616. // Create a new pointer representing this drag, starting at this point where the drag started.
  2617. this.state.dragPointer = makeStartPointer(ev);
  2618. updatePointerState(ev, this.state.dragPointer);
  2619. this.dispatchEvent(ev, '$md.dragstart', this.state.dragPointer);
  2620. } else if (shouldCancel) {
  2621. this.cancel();
  2622. }
  2623. } else {
  2624. this.dispatchDragMove(ev);
  2625. }
  2626. },
  2627. // Only dispatch dragmove events every frame; any more is unnecessary
  2628. dispatchDragMove: $$rAF.throttle(function (ev) {
  2629. // Make sure the drag didn't stop while waiting for the next frame
  2630. if (this.state.isRunning) {
  2631. updatePointerState(ev, this.state.dragPointer);
  2632. this.dispatchEvent(ev, '$md.drag', this.state.dragPointer);
  2633. }
  2634. }),
  2635. onEnd: function (ev, pointer) {
  2636. if (this.state.dragPointer) {
  2637. updatePointerState(ev, this.state.dragPointer);
  2638. this.dispatchEvent(ev, '$md.dragend', this.state.dragPointer);
  2639. }
  2640. }
  2641. })
  2642. /*
  2643. * The swipe handler will dispatch a swipe event if, on the end of a touch,
  2644. * the velocity and distance were high enough.
  2645. */
  2646. .handler('swipe', {
  2647. options: {
  2648. minVelocity: 0.65,
  2649. minDistance: 10
  2650. },
  2651. onEnd: function (ev, pointer) {
  2652. var eventType;
  2653. if (Math.abs(pointer.velocityX) > this.state.options.minVelocity &&
  2654. Math.abs(pointer.distanceX) > this.state.options.minDistance) {
  2655. eventType = pointer.directionX == 'left' ? '$md.swipeleft' : '$md.swiperight';
  2656. this.dispatchEvent(ev, eventType);
  2657. }
  2658. else if (Math.abs(pointer.velocityY) > this.state.options.minVelocity &&
  2659. Math.abs(pointer.distanceY) > this.state.options.minDistance) {
  2660. eventType = pointer.directionY == 'up' ? '$md.swipeup' : '$md.swipedown';
  2661. this.dispatchEvent(ev, eventType);
  2662. }
  2663. }
  2664. });
  2665. function getTouchAction() {
  2666. var testEl = document.createElement('div');
  2667. var vendorPrefixes = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
  2668. for (var i = 0; i < vendorPrefixes.length; i++) {
  2669. var prefix = vendorPrefixes[i];
  2670. var property = prefix ? prefix + 'TouchAction' : 'touchAction';
  2671. if (angular.isDefined(testEl.style[property])) {
  2672. return property;
  2673. }
  2674. }
  2675. }
  2676. }
  2677. /**
  2678. * MdGestureHandler
  2679. * A GestureHandler is an object which is able to dispatch custom dom events
  2680. * based on native dom {touch,pointer,mouse}{start,move,end} events.
  2681. *
  2682. * A gesture will manage its lifecycle through the start,move,end, and cancel
  2683. * functions, which are called by native dom events.
  2684. *
  2685. * A gesture has the concept of 'options' (eg a swipe's required velocity), which can be
  2686. * overridden by elements registering through $mdGesture.register()
  2687. */
  2688. function GestureHandler (name) {
  2689. this.name = name;
  2690. this.state = {};
  2691. }
  2692. function MdGestureHandler() {
  2693. var hasJQuery = (typeof window.jQuery !== 'undefined') && (angular.element === window.jQuery);
  2694. GestureHandler.prototype = {
  2695. options: {},
  2696. // jQuery listeners don't work with custom DOMEvents, so we have to dispatch events
  2697. // differently when jQuery is loaded
  2698. dispatchEvent: hasJQuery ? jQueryDispatchEvent : nativeDispatchEvent,
  2699. // These are overridden by the registered handler
  2700. onSetup: angular.noop,
  2701. onCleanup: angular.noop,
  2702. onStart: angular.noop,
  2703. onMove: angular.noop,
  2704. onEnd: angular.noop,
  2705. onCancel: angular.noop,
  2706. // onStart sets up a new state for the handler, which includes options from the
  2707. // nearest registered parent element of ev.target.
  2708. start: function (ev, pointer) {
  2709. if (this.state.isRunning) return;
  2710. var parentTarget = this.getNearestParent(ev.target);
  2711. // Get the options from the nearest registered parent
  2712. var parentTargetOptions = parentTarget && parentTarget.$mdGesture[this.name] || {};
  2713. this.state = {
  2714. isRunning: true,
  2715. // Override the default options with the nearest registered parent's options
  2716. options: angular.extend({}, this.options, parentTargetOptions),
  2717. // Pass in the registered parent node to the state so the onStart listener can use
  2718. registeredParent: parentTarget
  2719. };
  2720. this.onStart(ev, pointer);
  2721. },
  2722. move: function (ev, pointer) {
  2723. if (!this.state.isRunning) return;
  2724. this.onMove(ev, pointer);
  2725. },
  2726. end: function (ev, pointer) {
  2727. if (!this.state.isRunning) return;
  2728. this.onEnd(ev, pointer);
  2729. this.state.isRunning = false;
  2730. },
  2731. cancel: function (ev, pointer) {
  2732. this.onCancel(ev, pointer);
  2733. this.state = {};
  2734. },
  2735. // Find and return the nearest parent element that has been registered to
  2736. // listen for this handler via $mdGesture.register(element, 'handlerName').
  2737. getNearestParent: function (node) {
  2738. var current = node;
  2739. while (current) {
  2740. if ((current.$mdGesture || {})[this.name]) {
  2741. return current;
  2742. }
  2743. current = current.parentNode;
  2744. }
  2745. return null;
  2746. },
  2747. // Called from $mdGesture.register when an element registers itself with a handler.
  2748. // Store the options the user gave on the DOMElement itself. These options will
  2749. // be retrieved with getNearestParent when the handler starts.
  2750. registerElement: function (element, options) {
  2751. var self = this;
  2752. element[0].$mdGesture = element[0].$mdGesture || {};
  2753. element[0].$mdGesture[this.name] = options || {};
  2754. element.on('$destroy', onDestroy);
  2755. self.onSetup(element, options || {});
  2756. return onDestroy;
  2757. function onDestroy() {
  2758. delete element[0].$mdGesture[self.name];
  2759. element.off('$destroy', onDestroy);
  2760. self.onCleanup(element, options || {});
  2761. }
  2762. }
  2763. };
  2764. return GestureHandler;
  2765. /*
  2766. * Dispatch an event with jQuery
  2767. * TODO: Make sure this sends bubbling events
  2768. *
  2769. * @param srcEvent the original DOM touch event that started this.
  2770. * @param eventType the name of the custom event to send (eg 'click' or '$md.drag')
  2771. * @param eventPointer the pointer object that matches this event.
  2772. */
  2773. function jQueryDispatchEvent(srcEvent, eventType, eventPointer) {
  2774. eventPointer = eventPointer || pointer;
  2775. var eventObj = new angular.element.Event(eventType);
  2776. eventObj.$material = true;
  2777. eventObj.pointer = eventPointer;
  2778. eventObj.srcEvent = srcEvent;
  2779. angular.extend(eventObj, {
  2780. clientX: eventPointer.x,
  2781. clientY: eventPointer.y,
  2782. screenX: eventPointer.x,
  2783. screenY: eventPointer.y,
  2784. pageX: eventPointer.x,
  2785. pageY: eventPointer.y,
  2786. ctrlKey: srcEvent.ctrlKey,
  2787. altKey: srcEvent.altKey,
  2788. shiftKey: srcEvent.shiftKey,
  2789. metaKey: srcEvent.metaKey
  2790. });
  2791. angular.element(eventPointer.target).trigger(eventObj);
  2792. }
  2793. /**
  2794. * NOTE: nativeDispatchEvent is very performance sensitive.
  2795. * @param srcEvent the original DOM touch event that started this.
  2796. * @param eventType the name of the custom event to send (eg 'click' or '$md.drag')
  2797. * @param eventPointer the pointer object that matches this event.
  2798. */
  2799. function nativeDispatchEvent(srcEvent, eventType, eventPointer) {
  2800. eventPointer = eventPointer || pointer;
  2801. var eventObj;
  2802. if (eventType === 'click' || eventType === 'mouseup' || eventType === 'mousedown' ) {
  2803. eventObj = document.createEvent('MouseEvents');
  2804. eventObj.initMouseEvent(
  2805. eventType, true, true, window, srcEvent.detail,
  2806. eventPointer.x, eventPointer.y, eventPointer.x, eventPointer.y,
  2807. srcEvent.ctrlKey, srcEvent.altKey, srcEvent.shiftKey, srcEvent.metaKey,
  2808. srcEvent.button, srcEvent.relatedTarget || null
  2809. );
  2810. } else {
  2811. eventObj = document.createEvent('CustomEvent');
  2812. eventObj.initCustomEvent(eventType, true, true, {});
  2813. }
  2814. eventObj.$material = true;
  2815. eventObj.pointer = eventPointer;
  2816. eventObj.srcEvent = srcEvent;
  2817. eventPointer.target.dispatchEvent(eventObj);
  2818. }
  2819. }
  2820. /**
  2821. * Attach Gestures: hook document and check shouldHijack clicks
  2822. * @ngInject
  2823. */
  2824. function attachToDocument( $mdGesture, $$MdGestureHandler ) {
  2825. // Polyfill document.contains for IE11.
  2826. // TODO: move to util
  2827. document.contains || (document.contains = function (node) {
  2828. return document.body.contains(node);
  2829. });
  2830. if (!isInitialized && $mdGesture.isHijackingClicks ) {
  2831. /*
  2832. * If hijack clicks is true, we preventDefault any click that wasn't
  2833. * sent by AngularJS Material. This is because on older Android & iOS, a false, or 'ghost',
  2834. * click event will be sent ~400ms after a touchend event happens.
  2835. * The only way to know if this click is real is to prevent any normal
  2836. * click events, and add a flag to events sent by material so we know not to prevent those.
  2837. *
  2838. * Two exceptions to click events that should be prevented are:
  2839. * - click events sent by the keyboard (eg form submit)
  2840. * - events that originate from an Ionic app
  2841. */
  2842. document.addEventListener('click' , clickHijacker , true);
  2843. document.addEventListener('mouseup' , mouseInputHijacker, true);
  2844. document.addEventListener('mousedown', mouseInputHijacker, true);
  2845. document.addEventListener('focus' , mouseInputHijacker, true);
  2846. isInitialized = true;
  2847. }
  2848. function mouseInputHijacker(ev) {
  2849. var isKeyClick = !ev.clientX && !ev.clientY;
  2850. if (
  2851. !isKeyClick &&
  2852. !ev.$material &&
  2853. !ev.isIonicTap &&
  2854. !isInputEventFromLabelClick(ev) &&
  2855. (ev.type !== 'mousedown' || (!canFocus(ev.target) && !canFocus(document.activeElement)))
  2856. ) {
  2857. ev.preventDefault();
  2858. ev.stopPropagation();
  2859. }
  2860. }
  2861. function clickHijacker(ev) {
  2862. var isKeyClick = ev.clientX === 0 && ev.clientY === 0;
  2863. var isSubmitEvent = ev.target && ev.target.type === 'submit';
  2864. if (!isKeyClick && !ev.$material && !ev.isIonicTap
  2865. && !isInputEventFromLabelClick(ev)
  2866. && !isSubmitEvent) {
  2867. ev.preventDefault();
  2868. ev.stopPropagation();
  2869. lastLabelClickPos = null;
  2870. } else {
  2871. lastLabelClickPos = null;
  2872. if (ev.target.tagName.toLowerCase() == 'label') {
  2873. lastLabelClickPos = {x: ev.x, y: ev.y};
  2874. }
  2875. }
  2876. }
  2877. // Listen to all events to cover all platforms.
  2878. var START_EVENTS = 'mousedown touchstart pointerdown';
  2879. var MOVE_EVENTS = 'mousemove touchmove pointermove';
  2880. var END_EVENTS = 'mouseup mouseleave touchend touchcancel pointerup pointercancel';
  2881. angular.element(document)
  2882. .on(START_EVENTS, gestureStart)
  2883. .on(MOVE_EVENTS, gestureMove)
  2884. .on(END_EVENTS, gestureEnd)
  2885. // For testing
  2886. .on('$$mdGestureReset', function gestureClearCache () {
  2887. lastPointer = pointer = null;
  2888. });
  2889. /*
  2890. * When a DOM event happens, run all registered gesture handlers' lifecycle
  2891. * methods which match the DOM event.
  2892. * Eg when a 'touchstart' event happens, runHandlers('start') will call and
  2893. * run `handler.cancel()` and `handler.start()` on all registered handlers.
  2894. */
  2895. function runHandlers(handlerEvent, event) {
  2896. var handler;
  2897. for (var name in HANDLERS) {
  2898. handler = HANDLERS[name];
  2899. if( handler instanceof $$MdGestureHandler ) {
  2900. if (handlerEvent === 'start') {
  2901. // Run cancel to reset any handlers' state
  2902. handler.cancel();
  2903. }
  2904. handler[handlerEvent](event, pointer);
  2905. }
  2906. }
  2907. }
  2908. /*
  2909. * gestureStart vets if a start event is legitimate (and not part of a 'ghost click' from iOS/Android)
  2910. * If it is legitimate, we initiate the pointer state and mark the current pointer's type
  2911. * For example, for a touchstart event, mark the current pointer as a 'touch' pointer, so mouse events
  2912. * won't effect it.
  2913. */
  2914. function gestureStart(ev) {
  2915. // If we're already touched down, abort
  2916. if (pointer) return;
  2917. var now = +Date.now();
  2918. // iOS & old android bug: after a touch event, a click event is sent 350 ms later.
  2919. // If <400ms have passed, don't allow an event of a different type than the previous event
  2920. if (lastPointer && !typesMatch(ev, lastPointer) && (now - lastPointer.endTime < 1500)) {
  2921. return;
  2922. }
  2923. pointer = makeStartPointer(ev);
  2924. runHandlers('start', ev);
  2925. }
  2926. /*
  2927. * If a move event happens of the right type, update the pointer and run all the move handlers.
  2928. * "of the right type": if a mousemove happens but our pointer started with a touch event, do nothing.
  2929. */
  2930. function gestureMove(ev) {
  2931. if (!pointer || !typesMatch(ev, pointer)) return;
  2932. updatePointerState(ev, pointer);
  2933. runHandlers('move', ev);
  2934. }
  2935. /*
  2936. * If an end event happens of the right type, update the pointer, run endHandlers, and save the pointer as 'lastPointer'
  2937. */
  2938. function gestureEnd(ev) {
  2939. if (!pointer || !typesMatch(ev, pointer)) return;
  2940. updatePointerState(ev, pointer);
  2941. pointer.endTime = +Date.now();
  2942. if (ev.type !== 'pointercancel') {
  2943. runHandlers('end', ev);
  2944. }
  2945. lastPointer = pointer;
  2946. pointer = null;
  2947. }
  2948. }
  2949. // ********************
  2950. // Module Functions
  2951. // ********************
  2952. /*
  2953. * Initiate the pointer. x, y, and the pointer's type.
  2954. */
  2955. function makeStartPointer(ev) {
  2956. var point = getEventPoint(ev);
  2957. var startPointer = {
  2958. startTime: +Date.now(),
  2959. target: ev.target,
  2960. // 'p' for pointer events, 'm' for mouse, 't' for touch
  2961. type: ev.type.charAt(0)
  2962. };
  2963. startPointer.startX = startPointer.x = point.pageX;
  2964. startPointer.startY = startPointer.y = point.pageY;
  2965. return startPointer;
  2966. }
  2967. /*
  2968. * return whether the pointer's type matches the event's type.
  2969. * Eg if a touch event happens but the pointer has a mouse type, return false.
  2970. */
  2971. function typesMatch(ev, pointer) {
  2972. return ev && pointer && ev.type.charAt(0) === pointer.type;
  2973. }
  2974. /**
  2975. * Gets whether the given event is an input event that was caused by clicking on an
  2976. * associated label element.
  2977. *
  2978. * This is necessary because the browser will, upon clicking on a label element, fire an
  2979. * *extra* click event on its associated input (if any). mdGesture is able to flag the label
  2980. * click as with `$material` correctly, but not the second input click.
  2981. *
  2982. * In order to determine whether an input event is from a label click, we compare the (x, y) for
  2983. * the event to the (x, y) for the most recent label click (which is cleared whenever a non-label
  2984. * click occurs). Unfortunately, there are no event properties that tie the input and the label
  2985. * together (such as relatedTarget).
  2986. *
  2987. * @param {MouseEvent} event
  2988. * @returns {boolean}
  2989. */
  2990. function isInputEventFromLabelClick(event) {
  2991. return lastLabelClickPos
  2992. && lastLabelClickPos.x == event.x
  2993. && lastLabelClickPos.y == event.y;
  2994. }
  2995. /*
  2996. * Update the given pointer based upon the given DOMEvent.
  2997. * Distance, velocity, direction, duration, etc
  2998. */
  2999. function updatePointerState(ev, pointer) {
  3000. var point = getEventPoint(ev);
  3001. var x = pointer.x = point.pageX;
  3002. var y = pointer.y = point.pageY;
  3003. pointer.distanceX = x - pointer.startX;
  3004. pointer.distanceY = y - pointer.startY;
  3005. pointer.distance = Math.sqrt(
  3006. pointer.distanceX * pointer.distanceX + pointer.distanceY * pointer.distanceY
  3007. );
  3008. pointer.directionX = pointer.distanceX > 0 ? 'right' : pointer.distanceX < 0 ? 'left' : '';
  3009. pointer.directionY = pointer.distanceY > 0 ? 'down' : pointer.distanceY < 0 ? 'up' : '';
  3010. pointer.duration = +Date.now() - pointer.startTime;
  3011. pointer.velocityX = pointer.distanceX / pointer.duration;
  3012. pointer.velocityY = pointer.distanceY / pointer.duration;
  3013. }
  3014. /**
  3015. * Normalize the point where the DOM event happened whether it's touch or mouse.
  3016. * @returns point event obj with pageX and pageY on it.
  3017. */
  3018. function getEventPoint(ev) {
  3019. ev = ev.originalEvent || ev; // support jQuery events
  3020. return (ev.touches && ev.touches[0]) ||
  3021. (ev.changedTouches && ev.changedTouches[0]) ||
  3022. ev;
  3023. }
  3024. /** Checks whether an element can be focused. */
  3025. function canFocus(element) {
  3026. return (
  3027. !!element &&
  3028. element.getAttribute('tabindex') !== '-1' &&
  3029. !element.hasAttribute('disabled') &&
  3030. (
  3031. element.hasAttribute('tabindex') ||
  3032. element.hasAttribute('href') ||
  3033. element.isContentEditable ||
  3034. ['INPUT', 'SELECT', 'BUTTON', 'TEXTAREA', 'VIDEO', 'AUDIO'].indexOf(element.nodeName) !== -1
  3035. )
  3036. );
  3037. }
  3038. })();
  3039. (function(){
  3040. "use strict";
  3041. /**
  3042. * @ngdoc module
  3043. * @name material.core.interaction
  3044. * @description
  3045. * User interaction detection to provide proper accessibility.
  3046. */
  3047. MdInteractionService.$inject = ["$timeout", "$mdUtil"];
  3048. angular
  3049. .module('material.core.interaction', [])
  3050. .service('$mdInteraction', MdInteractionService);
  3051. /**
  3052. * @ngdoc service
  3053. * @name $mdInteraction
  3054. * @module material.core.interaction
  3055. *
  3056. * @description
  3057. *
  3058. * Service which keeps track of the last interaction type and validates them for several browsers.
  3059. * The service hooks into the document's body and listens for touch, mouse and keyboard events.
  3060. *
  3061. * The most recent interaction type can be retrieved by calling the `getLastInteractionType` method.
  3062. *
  3063. * Here is an example markup for using the interaction service.
  3064. *
  3065. * <hljs lang="js">
  3066. * var lastType = $mdInteraction.getLastInteractionType();
  3067. *
  3068. * if (lastType === 'keyboard') {
  3069. * // We only restore the focus for keyboard users.
  3070. * restoreFocus();
  3071. * }
  3072. * </hljs>
  3073. *
  3074. */
  3075. function MdInteractionService($timeout, $mdUtil) {
  3076. this.$timeout = $timeout;
  3077. this.$mdUtil = $mdUtil;
  3078. this.bodyElement = angular.element(document.body);
  3079. this.isBuffering = false;
  3080. this.bufferTimeout = null;
  3081. this.lastInteractionType = null;
  3082. this.lastInteractionTime = null;
  3083. // Type Mappings for the different events
  3084. // There will be three three interaction types
  3085. // `keyboard`, `mouse` and `touch`
  3086. // type `pointer` will be evaluated in `pointerMap` for IE Browser events
  3087. this.inputEventMap = {
  3088. 'keydown': 'keyboard',
  3089. 'mousedown': 'mouse',
  3090. 'mouseenter': 'mouse',
  3091. 'touchstart': 'touch',
  3092. 'pointerdown': 'pointer',
  3093. 'MSPointerDown': 'pointer'
  3094. };
  3095. // IE PointerDown events will be validated in `touch` or `mouse`
  3096. // Index numbers referenced here: https://msdn.microsoft.com/library/windows/apps/hh466130.aspx
  3097. this.iePointerMap = {
  3098. 2: 'touch',
  3099. 3: 'touch',
  3100. 4: 'mouse'
  3101. };
  3102. this.initializeEvents();
  3103. }
  3104. /**
  3105. * Initializes the interaction service, by registering all interaction events to the
  3106. * body element.
  3107. */
  3108. MdInteractionService.prototype.initializeEvents = function() {
  3109. // IE browsers can also trigger pointer events, which also leads to an interaction.
  3110. var pointerEvent = 'MSPointerEvent' in window ? 'MSPointerDown' : 'PointerEvent' in window ? 'pointerdown' : null;
  3111. this.bodyElement.on('keydown mousedown', this.onInputEvent.bind(this));
  3112. if ('ontouchstart' in document.documentElement) {
  3113. this.bodyElement.on('touchstart', this.onBufferInputEvent.bind(this));
  3114. }
  3115. if (pointerEvent) {
  3116. this.bodyElement.on(pointerEvent, this.onInputEvent.bind(this));
  3117. }
  3118. };
  3119. /**
  3120. * Event listener for normal interaction events, which should be tracked.
  3121. * @param event {MouseEvent|KeyboardEvent|PointerEvent|TouchEvent}
  3122. */
  3123. MdInteractionService.prototype.onInputEvent = function(event) {
  3124. if (this.isBuffering) {
  3125. return;
  3126. }
  3127. var type = this.inputEventMap[event.type];
  3128. if (type === 'pointer') {
  3129. type = this.iePointerMap[event.pointerType] || event.pointerType;
  3130. }
  3131. this.lastInteractionType = type;
  3132. this.lastInteractionTime = this.$mdUtil.now();
  3133. };
  3134. /**
  3135. * Event listener for interaction events which should be buffered (touch events).
  3136. * @param event {TouchEvent}
  3137. */
  3138. MdInteractionService.prototype.onBufferInputEvent = function(event) {
  3139. this.$timeout.cancel(this.bufferTimeout);
  3140. this.onInputEvent(event);
  3141. this.isBuffering = true;
  3142. // The timeout of 650ms is needed to delay the touchstart, because otherwise the touch will call
  3143. // the `onInput` function multiple times.
  3144. this.bufferTimeout = this.$timeout(function() {
  3145. this.isBuffering = false;
  3146. }.bind(this), 650, false);
  3147. };
  3148. /**
  3149. * @ngdoc method
  3150. * @name $mdInteraction#getLastInteractionType
  3151. * @description Retrieves the last interaction type triggered in body.
  3152. * @returns {string|null} Last interaction type.
  3153. */
  3154. MdInteractionService.prototype.getLastInteractionType = function() {
  3155. return this.lastInteractionType;
  3156. };
  3157. /**
  3158. * @ngdoc method
  3159. * @name $mdInteraction#isUserInvoked
  3160. * @description Method to detect whether any interaction happened recently or not.
  3161. * @param {number=} checkDelay Time to check for any interaction to have been triggered.
  3162. * @returns {boolean} Whether there was any interaction or not.
  3163. */
  3164. MdInteractionService.prototype.isUserInvoked = function(checkDelay) {
  3165. var delay = angular.isNumber(checkDelay) ? checkDelay : 15;
  3166. // Check for any interaction to be within the specified check time.
  3167. return this.lastInteractionTime >= this.$mdUtil.now() - delay;
  3168. };
  3169. })();
  3170. (function(){
  3171. "use strict";
  3172. angular.module('material.core')
  3173. .provider('$$interimElement', InterimElementProvider);
  3174. /*
  3175. * @ngdoc service
  3176. * @name $$interimElement
  3177. * @module material.core
  3178. *
  3179. * @description
  3180. *
  3181. * Factory that contructs `$$interimElement.$service` services.
  3182. * Used internally in material design for elements that appear on screen temporarily.
  3183. * The service provides a promise-like API for interacting with the temporary
  3184. * elements.
  3185. *
  3186. * ```js
  3187. * app.service('$mdToast', function($$interimElement) {
  3188. * var $mdToast = $$interimElement(toastDefaultOptions);
  3189. * return $mdToast;
  3190. * });
  3191. * ```
  3192. * @param {object=} defaultOptions Options used by default for the `show` method on the service.
  3193. *
  3194. * @returns {$$interimElement.$service}
  3195. *
  3196. */
  3197. function InterimElementProvider() {
  3198. InterimElementFactory.$inject = ["$document", "$q", "$rootScope", "$timeout", "$rootElement", "$animate", "$mdUtil", "$mdCompiler", "$mdTheming", "$injector", "$exceptionHandler"];
  3199. createInterimElementProvider.$get = InterimElementFactory;
  3200. return createInterimElementProvider;
  3201. /**
  3202. * Returns a new provider which allows configuration of a new interimElement
  3203. * service. Allows configuration of default options & methods for options,
  3204. * as well as configuration of 'preset' methods (eg dialog.basic(): basic is a preset method)
  3205. */
  3206. function createInterimElementProvider(interimFactoryName) {
  3207. factory.$inject = ["$$interimElement", "$injector"];
  3208. var EXPOSED_METHODS = ['onHide', 'onShow', 'onRemove'];
  3209. var customMethods = {};
  3210. var providerConfig = {
  3211. presets: {}
  3212. };
  3213. var provider = {
  3214. setDefaults: setDefaults,
  3215. addPreset: addPreset,
  3216. addMethod: addMethod,
  3217. $get: factory
  3218. };
  3219. /**
  3220. * all interim elements will come with the 'build' preset
  3221. */
  3222. provider.addPreset('build', {
  3223. methods: ['controller', 'controllerAs', 'resolve', 'multiple',
  3224. 'template', 'templateUrl', 'themable', 'transformTemplate', 'parent', 'contentElement']
  3225. });
  3226. return provider;
  3227. /**
  3228. * Save the configured defaults to be used when the factory is instantiated
  3229. */
  3230. function setDefaults(definition) {
  3231. providerConfig.optionsFactory = definition.options;
  3232. providerConfig.methods = (definition.methods || []).concat(EXPOSED_METHODS);
  3233. return provider;
  3234. }
  3235. /**
  3236. * Add a method to the factory that isn't specific to any interim element operations
  3237. */
  3238. function addMethod(name, fn) {
  3239. customMethods[name] = fn;
  3240. return provider;
  3241. }
  3242. /**
  3243. * Save the configured preset to be used when the factory is instantiated
  3244. */
  3245. function addPreset(name, definition) {
  3246. definition = definition || {};
  3247. definition.methods = definition.methods || [];
  3248. definition.options = definition.options || function() { return {}; };
  3249. if (/^cancel|hide|show$/.test(name)) {
  3250. throw new Error("Preset '" + name + "' in " + interimFactoryName + " is reserved!");
  3251. }
  3252. if (definition.methods.indexOf('_options') > -1) {
  3253. throw new Error("Method '_options' in " + interimFactoryName + " is reserved!");
  3254. }
  3255. providerConfig.presets[name] = {
  3256. methods: definition.methods.concat(EXPOSED_METHODS),
  3257. optionsFactory: definition.options,
  3258. argOption: definition.argOption
  3259. };
  3260. return provider;
  3261. }
  3262. function addPresetMethod(presetName, methodName, method) {
  3263. providerConfig.presets[presetName][methodName] = method;
  3264. }
  3265. /**
  3266. * Create a factory that has the given methods & defaults implementing interimElement
  3267. */
  3268. /* @ngInject */
  3269. function factory($$interimElement, $injector) {
  3270. var defaultMethods;
  3271. var defaultOptions;
  3272. var interimElementService = $$interimElement();
  3273. /*
  3274. * publicService is what the developer will be using.
  3275. * It has methods hide(), cancel(), show(), build(), and any other
  3276. * presets which were set during the config phase.
  3277. */
  3278. var publicService = {
  3279. hide: interimElementService.hide,
  3280. cancel: interimElementService.cancel,
  3281. show: showInterimElement,
  3282. // Special internal method to destroy an interim element without animations
  3283. // used when navigation changes causes a $scope.$destroy() action
  3284. destroy : destroyInterimElement
  3285. };
  3286. defaultMethods = providerConfig.methods || [];
  3287. // This must be invoked after the publicService is initialized
  3288. defaultOptions = invokeFactory(providerConfig.optionsFactory, {});
  3289. // Copy over the simple custom methods
  3290. angular.forEach(customMethods, function(fn, name) {
  3291. publicService[name] = fn;
  3292. });
  3293. angular.forEach(providerConfig.presets, function(definition, name) {
  3294. var presetDefaults = invokeFactory(definition.optionsFactory, {});
  3295. var presetMethods = (definition.methods || []).concat(defaultMethods);
  3296. // Every interimElement built with a preset has a field called `$type`,
  3297. // which matches the name of the preset.
  3298. // Eg in preset 'confirm', options.$type === 'confirm'
  3299. angular.extend(presetDefaults, { $type: name });
  3300. // This creates a preset class which has setter methods for every
  3301. // method given in the `.addPreset()` function, as well as every
  3302. // method given in the `.setDefaults()` function.
  3303. //
  3304. // @example
  3305. // .setDefaults({
  3306. // methods: ['hasBackdrop', 'clickOutsideToClose', 'escapeToClose', 'targetEvent'],
  3307. // options: dialogDefaultOptions
  3308. // })
  3309. // .addPreset('alert', {
  3310. // methods: ['title', 'ok'],
  3311. // options: alertDialogOptions
  3312. // })
  3313. //
  3314. // Set values will be passed to the options when interimElement.show() is called.
  3315. function Preset(opts) {
  3316. this._options = angular.extend({}, presetDefaults, opts);
  3317. }
  3318. angular.forEach(presetMethods, function(name) {
  3319. Preset.prototype[name] = function(value) {
  3320. this._options[name] = value;
  3321. return this;
  3322. };
  3323. });
  3324. // Create shortcut method for one-linear methods
  3325. if (definition.argOption) {
  3326. var methodName = 'show' + name.charAt(0).toUpperCase() + name.slice(1);
  3327. publicService[methodName] = function(arg) {
  3328. var config = publicService[name](arg);
  3329. return publicService.show(config);
  3330. };
  3331. }
  3332. // eg $mdDialog.alert() will return a new alert preset
  3333. publicService[name] = function(arg) {
  3334. // If argOption is supplied, eg `argOption: 'content'`, then we assume
  3335. // if the argument is not an options object then it is the `argOption` option.
  3336. //
  3337. // @example `$mdToast.simple('hello')` // sets options.content to hello
  3338. // // because argOption === 'content'
  3339. if (arguments.length && definition.argOption &&
  3340. !angular.isObject(arg) && !angular.isArray(arg)) {
  3341. return (new Preset())[definition.argOption](arg);
  3342. } else {
  3343. return new Preset(arg);
  3344. }
  3345. };
  3346. });
  3347. return publicService;
  3348. /**
  3349. *
  3350. */
  3351. function showInterimElement(opts) {
  3352. // opts is either a preset which stores its options on an _options field,
  3353. // or just an object made up of options
  3354. opts = opts || { };
  3355. if (opts._options) opts = opts._options;
  3356. return interimElementService.show(
  3357. angular.extend({}, defaultOptions, opts)
  3358. );
  3359. }
  3360. /**
  3361. * Special method to hide and destroy an interimElement WITHOUT
  3362. * any 'leave` or hide animations ( an immediate force hide/remove )
  3363. *
  3364. * NOTE: This calls the onRemove() subclass method for each component...
  3365. * which must have code to respond to `options.$destroy == true`
  3366. */
  3367. function destroyInterimElement(opts) {
  3368. return interimElementService.destroy(opts);
  3369. }
  3370. /**
  3371. * Helper to call $injector.invoke with a local of the factory name for
  3372. * this provider.
  3373. * If an $mdDialog is providing options for a dialog and tries to inject
  3374. * $mdDialog, a circular dependency error will happen.
  3375. * We get around that by manually injecting $mdDialog as a local.
  3376. */
  3377. function invokeFactory(factory, defaultVal) {
  3378. var locals = {};
  3379. locals[interimFactoryName] = publicService;
  3380. return $injector.invoke(factory || function() { return defaultVal; }, {}, locals);
  3381. }
  3382. }
  3383. }
  3384. /* @ngInject */
  3385. function InterimElementFactory($document, $q, $rootScope, $timeout, $rootElement, $animate,
  3386. $mdUtil, $mdCompiler, $mdTheming, $injector, $exceptionHandler) {
  3387. return function createInterimElementService() {
  3388. var SHOW_CANCELLED = false;
  3389. /*
  3390. * @ngdoc service
  3391. * @name $$interimElement.$service
  3392. *
  3393. * @description
  3394. * A service used to control inserting and removing an element into the DOM.
  3395. *
  3396. */
  3397. var service;
  3398. var showPromises = []; // Promises for the interim's which are currently opening.
  3399. var hidePromises = []; // Promises for the interim's which are currently hiding.
  3400. var showingInterims = []; // Interim elements which are currently showing up.
  3401. // Publish instance $$interimElement service;
  3402. // ... used as $mdDialog, $mdToast, $mdMenu, and $mdSelect
  3403. return service = {
  3404. show: show,
  3405. hide: waitForInterim(hide),
  3406. cancel: waitForInterim(cancel),
  3407. destroy : destroy,
  3408. $injector_: $injector
  3409. };
  3410. /*
  3411. * @ngdoc method
  3412. * @name $$interimElement.$service#show
  3413. * @kind function
  3414. *
  3415. * @description
  3416. * Adds the `$interimElement` to the DOM and returns a special promise that will be resolved or rejected
  3417. * with hide or cancel, respectively. To external cancel/hide, developers should use the
  3418. *
  3419. * @param {*} options is hashMap of settings
  3420. * @returns a Promise
  3421. *
  3422. */
  3423. function show(options) {
  3424. options = options || {};
  3425. var interimElement = new InterimElement(options || {});
  3426. // When an interim element is currently showing, we have to cancel it.
  3427. // Just hiding it, will resolve the InterimElement's promise, the promise should be
  3428. // rejected instead.
  3429. var hideAction = options.multiple ? $q.resolve() : $q.all(showPromises);
  3430. if (!options.multiple) {
  3431. // Wait for all opening interim's to finish their transition.
  3432. hideAction = hideAction.then(function() {
  3433. // Wait for all closing and showing interim's to be completely closed.
  3434. var promiseArray = hidePromises.concat(showingInterims.map(service.cancel));
  3435. return $q.all(promiseArray);
  3436. });
  3437. }
  3438. var showAction = hideAction.then(function() {
  3439. return interimElement
  3440. .show()
  3441. .catch(function(reason) { return reason; })
  3442. .finally(function() {
  3443. showPromises.splice(showPromises.indexOf(showAction), 1);
  3444. showingInterims.push(interimElement);
  3445. });
  3446. });
  3447. showPromises.push(showAction);
  3448. // In AngularJS 1.6+, exceptions inside promises will cause a rejection. We need to handle
  3449. // the rejection and only log it if it's an error.
  3450. interimElement.deferred.promise.catch(function(fault) {
  3451. if (fault instanceof Error) {
  3452. $exceptionHandler(fault);
  3453. }
  3454. return fault;
  3455. });
  3456. // Return a promise that will be resolved when the interim
  3457. // element is hidden or cancelled...
  3458. return interimElement.deferred.promise;
  3459. }
  3460. /*
  3461. * @ngdoc method
  3462. * @name $$interimElement.$service#hide
  3463. * @kind function
  3464. *
  3465. * @description
  3466. * Removes the `$interimElement` from the DOM and resolves the promise returned from `show`
  3467. *
  3468. * @param {*} resolveParam Data to resolve the promise with
  3469. * @returns a Promise that will be resolved after the element has been removed.
  3470. *
  3471. */
  3472. function hide(reason, options) {
  3473. options = options || {};
  3474. if (options.closeAll) {
  3475. // We have to make a shallow copy of the array, because otherwise the map will break.
  3476. return $q.all(showingInterims.slice().reverse().map(closeElement));
  3477. } else if (options.closeTo !== undefined) {
  3478. return $q.all(showingInterims.slice(options.closeTo).map(closeElement));
  3479. }
  3480. // Hide the latest showing interim element.
  3481. return closeElement(showingInterims[showingInterims.length - 1]);
  3482. function closeElement(interim) {
  3483. var hideAction = interim
  3484. .remove(reason, false, options || { })
  3485. .catch(function(reason) { return reason; })
  3486. .finally(function() {
  3487. hidePromises.splice(hidePromises.indexOf(hideAction), 1);
  3488. });
  3489. showingInterims.splice(showingInterims.indexOf(interim), 1);
  3490. hidePromises.push(hideAction);
  3491. return interim.deferred.promise;
  3492. }
  3493. }
  3494. /*
  3495. * @ngdoc method
  3496. * @name $$interimElement.$service#cancel
  3497. * @kind function
  3498. *
  3499. * @description
  3500. * Removes the `$interimElement` from the DOM and rejects the promise returned from `show`
  3501. *
  3502. * @param {*} reason Data to reject the promise with
  3503. * @returns Promise that will be resolved after the element has been removed.
  3504. *
  3505. */
  3506. function cancel(reason, options) {
  3507. var interim = showingInterims.pop();
  3508. if (!interim) {
  3509. return $q.when(reason);
  3510. }
  3511. var cancelAction = interim
  3512. .remove(reason, true, options || {})
  3513. .catch(function(reason) { return reason; })
  3514. .finally(function() {
  3515. hidePromises.splice(hidePromises.indexOf(cancelAction), 1);
  3516. });
  3517. hidePromises.push(cancelAction);
  3518. // Since AngularJS 1.6.7, promises will be logged to $exceptionHandler when the promise
  3519. // is not handling the rejection. We create a pseudo catch handler, which will prevent the
  3520. // promise from being logged to the $exceptionHandler.
  3521. return interim.deferred.promise.catch(angular.noop);
  3522. }
  3523. /**
  3524. * Creates a function to wait for at least one interim element to be available.
  3525. * @param callbackFn Function to be used as callback
  3526. * @returns {Function}
  3527. */
  3528. function waitForInterim(callbackFn) {
  3529. return function() {
  3530. var fnArguments = arguments;
  3531. if (!showingInterims.length) {
  3532. // When there are still interim's opening, then wait for the first interim element to
  3533. // finish its open animation.
  3534. if (showPromises.length) {
  3535. return showPromises[0].finally(function () {
  3536. return callbackFn.apply(service, fnArguments);
  3537. });
  3538. }
  3539. return $q.when("No interim elements currently showing up.");
  3540. }
  3541. return callbackFn.apply(service, fnArguments);
  3542. };
  3543. }
  3544. /*
  3545. * Special method to quick-remove the interim element without animations
  3546. * Note: interim elements are in "interim containers"
  3547. */
  3548. function destroy(targetEl) {
  3549. var interim = !targetEl ? showingInterims.shift() : null;
  3550. var parentEl = angular.element(targetEl).length && angular.element(targetEl)[0].parentNode;
  3551. if (parentEl) {
  3552. // Try to find the interim in the stack which corresponds to the supplied DOM element.
  3553. var filtered = showingInterims.filter(function(entry) {
  3554. return entry.options.element[0] === parentEl;
  3555. });
  3556. // Note: This function might be called when the element already has been removed,
  3557. // in which case we won't find any matches.
  3558. if (filtered.length) {
  3559. interim = filtered[0];
  3560. showingInterims.splice(showingInterims.indexOf(interim), 1);
  3561. }
  3562. }
  3563. return interim ? interim.remove(SHOW_CANCELLED, false, { '$destroy': true }) :
  3564. $q.when(SHOW_CANCELLED);
  3565. }
  3566. /*
  3567. * Internal Interim Element Object
  3568. * Used internally to manage the DOM element and related data
  3569. */
  3570. function InterimElement(options) {
  3571. var self, element, showAction = $q.when(true);
  3572. options = configureScopeAndTransitions(options);
  3573. return self = {
  3574. options : options,
  3575. deferred: $q.defer(),
  3576. show : createAndTransitionIn,
  3577. remove : transitionOutAndRemove
  3578. };
  3579. /**
  3580. * Compile, link, and show this interim element
  3581. * Use optional autoHided and transition-in effects
  3582. */
  3583. function createAndTransitionIn() {
  3584. return $q(function(resolve, reject) {
  3585. // Trigger onCompiling callback before the compilation starts.
  3586. // This is useful, when modifying options, which can be influenced by developers.
  3587. options.onCompiling && options.onCompiling(options);
  3588. compileElement(options)
  3589. .then(function( compiledData ) {
  3590. element = linkElement( compiledData, options );
  3591. // Expose the cleanup function from the compiler.
  3592. options.cleanupElement = compiledData.cleanup;
  3593. showAction = showElement(element, options, compiledData.controller)
  3594. .then(resolve, rejectAll);
  3595. }).catch(rejectAll);
  3596. function rejectAll(fault) {
  3597. // Force the '$md<xxx>.show()' promise to reject
  3598. self.deferred.reject(fault);
  3599. // Continue rejection propagation
  3600. reject(fault);
  3601. }
  3602. });
  3603. }
  3604. /**
  3605. * After the show process has finished/rejected:
  3606. * - announce 'removing',
  3607. * - perform the transition-out, and
  3608. * - perform optional clean up scope.
  3609. */
  3610. function transitionOutAndRemove(response, isCancelled, opts) {
  3611. // abort if the show() and compile failed
  3612. if ( !element ) return $q.when(false);
  3613. options = angular.extend(options || {}, opts || {});
  3614. options.cancelAutoHide && options.cancelAutoHide();
  3615. options.element.triggerHandler('$mdInterimElementRemove');
  3616. if ( options.$destroy === true ) {
  3617. return hideElement(options.element, options).then(function(){
  3618. (isCancelled && rejectAll(response)) || resolveAll(response);
  3619. });
  3620. } else {
  3621. $q.when(showAction).finally(function() {
  3622. hideElement(options.element, options).then(function() {
  3623. isCancelled ? rejectAll(response) : resolveAll(response);
  3624. }, rejectAll);
  3625. });
  3626. return self.deferred.promise;
  3627. }
  3628. /**
  3629. * The `show()` returns a promise that will be resolved when the interim
  3630. * element is hidden or cancelled...
  3631. */
  3632. function resolveAll(response) {
  3633. self.deferred.resolve(response);
  3634. }
  3635. /**
  3636. * Force the '$md<xxx>.show()' promise to reject
  3637. */
  3638. function rejectAll(fault) {
  3639. self.deferred.reject(fault);
  3640. }
  3641. }
  3642. /**
  3643. * Prepare optional isolated scope and prepare $animate with default enter and leave
  3644. * transitions for the new element instance.
  3645. */
  3646. function configureScopeAndTransitions(options) {
  3647. options = options || { };
  3648. if ( options.template ) {
  3649. options.template = $mdUtil.processTemplate(options.template);
  3650. }
  3651. return angular.extend({
  3652. preserveScope: false,
  3653. cancelAutoHide : angular.noop,
  3654. scope: options.scope || $rootScope.$new(options.isolateScope),
  3655. /**
  3656. * Default usage to enable $animate to transition-in; can be easily overridden via 'options'
  3657. */
  3658. onShow: function transitionIn(scope, element, options) {
  3659. return $animate.enter(element, options.parent);
  3660. },
  3661. /**
  3662. * Default usage to enable $animate to transition-out; can be easily overridden via 'options'
  3663. */
  3664. onRemove: function transitionOut(scope, element) {
  3665. // Element could be undefined if a new element is shown before
  3666. // the old one finishes compiling.
  3667. return element && $animate.leave(element) || $q.when();
  3668. }
  3669. }, options );
  3670. }
  3671. /**
  3672. * Compile an element with a templateUrl, controller, and locals
  3673. */
  3674. function compileElement(options) {
  3675. var compiled = !options.skipCompile ? $mdCompiler.compile(options) : null;
  3676. return compiled || $q(function (resolve) {
  3677. resolve({
  3678. locals: {},
  3679. link: function () {
  3680. return options.element;
  3681. }
  3682. });
  3683. });
  3684. }
  3685. /**
  3686. * Link an element with compiled configuration
  3687. */
  3688. function linkElement(compileData, options){
  3689. angular.extend(compileData.locals, options);
  3690. var element = compileData.link(options.scope);
  3691. // Search for parent at insertion time, if not specified
  3692. options.element = element;
  3693. options.parent = findParent(element, options);
  3694. if (options.themable) $mdTheming(element);
  3695. return element;
  3696. }
  3697. /**
  3698. * Search for parent at insertion time, if not specified
  3699. */
  3700. function findParent(element, options) {
  3701. var parent = options.parent;
  3702. // Search for parent at insertion time, if not specified
  3703. if (angular.isFunction(parent)) {
  3704. parent = parent(options.scope, element, options);
  3705. } else if (angular.isString(parent)) {
  3706. parent = angular.element($document[0].querySelector(parent));
  3707. } else {
  3708. parent = angular.element(parent);
  3709. }
  3710. // If parent querySelector/getter function fails, or it's just null,
  3711. // find a default.
  3712. if (!(parent || {}).length) {
  3713. var el;
  3714. if ($rootElement[0] && $rootElement[0].querySelector) {
  3715. el = $rootElement[0].querySelector(':not(svg) > body');
  3716. }
  3717. if (!el) el = $rootElement[0];
  3718. if (el.nodeName == '#comment') {
  3719. el = $document[0].body;
  3720. }
  3721. return angular.element(el);
  3722. }
  3723. return parent;
  3724. }
  3725. /**
  3726. * If auto-hide is enabled, start timer and prepare cancel function
  3727. */
  3728. function startAutoHide() {
  3729. var autoHideTimer, cancelAutoHide = angular.noop;
  3730. if (options.hideDelay) {
  3731. autoHideTimer = $timeout(service.hide, options.hideDelay) ;
  3732. cancelAutoHide = function() {
  3733. $timeout.cancel(autoHideTimer);
  3734. };
  3735. }
  3736. // Cache for subsequent use
  3737. options.cancelAutoHide = function() {
  3738. cancelAutoHide();
  3739. options.cancelAutoHide = undefined;
  3740. };
  3741. }
  3742. /**
  3743. * Show the element ( with transitions), notify complete and start
  3744. * optional auto-Hide
  3745. */
  3746. function showElement(element, options, controller) {
  3747. // Trigger onShowing callback before the `show()` starts
  3748. var notifyShowing = options.onShowing || angular.noop;
  3749. // Trigger onComplete callback when the `show()` finishes
  3750. var notifyComplete = options.onComplete || angular.noop;
  3751. // Necessary for consistency between AngularJS 1.5 and 1.6.
  3752. try {
  3753. notifyShowing(options.scope, element, options, controller);
  3754. } catch (e) {
  3755. return $q.reject(e);
  3756. }
  3757. return $q(function (resolve, reject) {
  3758. try {
  3759. // Start transitionIn
  3760. $q.when(options.onShow(options.scope, element, options, controller))
  3761. .then(function () {
  3762. notifyComplete(options.scope, element, options);
  3763. startAutoHide();
  3764. resolve(element);
  3765. }, reject);
  3766. } catch (e) {
  3767. reject(e.message);
  3768. }
  3769. });
  3770. }
  3771. function hideElement(element, options) {
  3772. var announceRemoving = options.onRemoving || angular.noop;
  3773. return $q(function (resolve, reject) {
  3774. try {
  3775. // Start transitionIn
  3776. var action = $q.when( options.onRemove(options.scope, element, options) || true );
  3777. // Trigger callback *before* the remove operation starts
  3778. announceRemoving(element, action);
  3779. if (options.$destroy) {
  3780. // For $destroy, onRemove should be synchronous
  3781. resolve(element);
  3782. if (!options.preserveScope && options.scope ) {
  3783. // scope destroy should still be be done after the current digest is done
  3784. action.then( function() { options.scope.$destroy(); });
  3785. }
  3786. } else {
  3787. // Wait until transition-out is done
  3788. action.then(function () {
  3789. if (!options.preserveScope && options.scope ) {
  3790. options.scope.$destroy();
  3791. }
  3792. resolve(element);
  3793. }, reject);
  3794. }
  3795. } catch (e) {
  3796. reject(e.message);
  3797. }
  3798. });
  3799. }
  3800. }
  3801. };
  3802. }
  3803. }
  3804. })();
  3805. (function(){
  3806. "use strict";
  3807. (function() {
  3808. 'use strict';
  3809. var $mdUtil, $interpolate, $log;
  3810. var SUFFIXES = /(-gt)?-(sm|md|lg|print)/g;
  3811. var WHITESPACE = /\s+/g;
  3812. var FLEX_OPTIONS = ['grow', 'initial', 'auto', 'none', 'noshrink', 'nogrow' ];
  3813. var LAYOUT_OPTIONS = ['row', 'column'];
  3814. var ALIGNMENT_MAIN_AXIS= [ "", "start", "center", "end", "stretch", "space-around", "space-between" ];
  3815. var ALIGNMENT_CROSS_AXIS= [ "", "start", "center", "end", "stretch" ];
  3816. var config = {
  3817. /**
  3818. * Enable directive attribute-to-class conversions
  3819. * Developers can use `<body md-layout-css />` to quickly
  3820. * disable the Layout directives and prohibit the injection of Layout classNames
  3821. */
  3822. enabled: true,
  3823. /**
  3824. * List of mediaQuery breakpoints and associated suffixes
  3825. *
  3826. * [
  3827. * { suffix: "sm", mediaQuery: "screen and (max-width: 599px)" },
  3828. * { suffix: "md", mediaQuery: "screen and (min-width: 600px) and (max-width: 959px)" }
  3829. * ]
  3830. */
  3831. breakpoints: []
  3832. };
  3833. registerLayoutAPI( angular.module('material.core.layout', ['ng']) );
  3834. /**
  3835. * registerLayoutAPI()
  3836. *
  3837. * The original AngularJS Material Layout solution used attribute selectors and CSS.
  3838. *
  3839. * ```html
  3840. * <div layout="column"> My Content </div>
  3841. * ```
  3842. *
  3843. * ```css
  3844. * [layout] {
  3845. * box-sizing: border-box;
  3846. * display:flex;
  3847. * }
  3848. * [layout=column] {
  3849. * flex-direction : column
  3850. * }
  3851. * ```
  3852. *
  3853. * Use of attribute selectors creates significant performance impacts in some
  3854. * browsers... mainly IE.
  3855. *
  3856. * This module registers directives that allow the same layout attributes to be
  3857. * interpreted and converted to class selectors. The directive will add equivalent classes to each element that
  3858. * contains a Layout directive.
  3859. *
  3860. * ```html
  3861. * <div layout="column" class="layout layout-column"> My Content </div>
  3862. *```
  3863. *
  3864. * ```css
  3865. * .layout {
  3866. * box-sizing: border-box;
  3867. * display:flex;
  3868. * }
  3869. * .layout-column {
  3870. * flex-direction : column
  3871. * }
  3872. * ```
  3873. */
  3874. function registerLayoutAPI(module){
  3875. var PREFIX_REGEXP = /^((?:x|data)[:\-_])/i;
  3876. var SPECIAL_CHARS_REGEXP = /([:\-_]+(.))/g;
  3877. // NOTE: these are also defined in constants::MEDIA_PRIORITY and constants::MEDIA
  3878. var BREAKPOINTS = [ "", "xs", "gt-xs", "sm", "gt-sm", "md", "gt-md", "lg", "gt-lg", "xl", "print" ];
  3879. var API_WITH_VALUES = [ "layout", "flex", "flex-order", "flex-offset", "layout-align" ];
  3880. var API_NO_VALUES = [ "show", "hide", "layout-padding", "layout-margin" ];
  3881. // Build directive registration functions for the standard Layout API... for all breakpoints.
  3882. angular.forEach(BREAKPOINTS, function(mqb) {
  3883. // Attribute directives with expected, observable value(s)
  3884. angular.forEach( API_WITH_VALUES, function(name){
  3885. var fullName = mqb ? name + "-" + mqb : name;
  3886. module.directive( directiveNormalize(fullName), attributeWithObserve(fullName));
  3887. });
  3888. // Attribute directives with no expected value(s)
  3889. angular.forEach( API_NO_VALUES, function(name){
  3890. var fullName = mqb ? name + "-" + mqb : name;
  3891. module.directive( directiveNormalize(fullName), attributeWithoutValue(fullName));
  3892. });
  3893. });
  3894. // Register other, special directive functions for the Layout features:
  3895. module
  3896. .provider('$$mdLayout' , function() {
  3897. // Publish internal service for Layouts
  3898. return {
  3899. $get : angular.noop,
  3900. validateAttributeValue : validateAttributeValue,
  3901. validateAttributeUsage : validateAttributeUsage,
  3902. /**
  3903. * Easy way to disable/enable the Layout API.
  3904. * When disabled, this stops all attribute-to-classname generations
  3905. */
  3906. disableLayouts : function(isDisabled) {
  3907. config.enabled = (isDisabled !== true);
  3908. }
  3909. };
  3910. })
  3911. .directive('mdLayoutCss' , disableLayoutDirective )
  3912. .directive('ngCloak' , buildCloakInterceptor('ng-cloak'))
  3913. .directive('layoutWrap' , attributeWithoutValue('layout-wrap'))
  3914. .directive('layoutNowrap' , attributeWithoutValue('layout-nowrap'))
  3915. .directive('layoutNoWrap' , attributeWithoutValue('layout-no-wrap'))
  3916. .directive('layoutFill' , attributeWithoutValue('layout-fill'))
  3917. // !! Deprecated attributes: use the `-lt` (aka less-than) notations
  3918. .directive('layoutLtMd' , warnAttrNotSupported('layout-lt-md', true))
  3919. .directive('layoutLtLg' , warnAttrNotSupported('layout-lt-lg', true))
  3920. .directive('flexLtMd' , warnAttrNotSupported('flex-lt-md', true))
  3921. .directive('flexLtLg' , warnAttrNotSupported('flex-lt-lg', true))
  3922. .directive('layoutAlignLtMd', warnAttrNotSupported('layout-align-lt-md'))
  3923. .directive('layoutAlignLtLg', warnAttrNotSupported('layout-align-lt-lg'))
  3924. .directive('flexOrderLtMd' , warnAttrNotSupported('flex-order-lt-md'))
  3925. .directive('flexOrderLtLg' , warnAttrNotSupported('flex-order-lt-lg'))
  3926. .directive('offsetLtMd' , warnAttrNotSupported('flex-offset-lt-md'))
  3927. .directive('offsetLtLg' , warnAttrNotSupported('flex-offset-lt-lg'))
  3928. .directive('hideLtMd' , warnAttrNotSupported('hide-lt-md'))
  3929. .directive('hideLtLg' , warnAttrNotSupported('hide-lt-lg'))
  3930. .directive('showLtMd' , warnAttrNotSupported('show-lt-md'))
  3931. .directive('showLtLg' , warnAttrNotSupported('show-lt-lg'))
  3932. // Determine if
  3933. .config( detectDisabledLayouts );
  3934. /**
  3935. * Converts snake_case to camelCase.
  3936. * Also there is special case for Moz prefix starting with upper case letter.
  3937. * @param name Name to normalize
  3938. */
  3939. function directiveNormalize(name) {
  3940. return name
  3941. .replace(PREFIX_REGEXP, '')
  3942. .replace(SPECIAL_CHARS_REGEXP, function(_, separator, letter, offset) {
  3943. return offset ? letter.toUpperCase() : letter;
  3944. });
  3945. }
  3946. }
  3947. /**
  3948. * Detect if any of the HTML tags has a [md-layouts-disabled] attribute;
  3949. * If yes, then immediately disable all layout API features
  3950. *
  3951. * Note: this attribute should be specified on either the HTML or BODY tags
  3952. */
  3953. /**
  3954. * @ngInject
  3955. */
  3956. function detectDisabledLayouts() {
  3957. var isDisabled = !!document.querySelector('[md-layouts-disabled]');
  3958. config.enabled = !isDisabled;
  3959. }
  3960. /**
  3961. * Special directive that will disable ALL Layout conversions of layout
  3962. * attribute(s) to classname(s).
  3963. *
  3964. * <link rel="stylesheet" href="angular-material.min.css">
  3965. * <link rel="stylesheet" href="angular-material.layout.css">
  3966. *
  3967. * <body md-layout-css>
  3968. * ...
  3969. * </body>
  3970. *
  3971. * Note: Using md-layout-css directive requires the developer to load the Material
  3972. * Layout Attribute stylesheet (which only uses attribute selectors):
  3973. *
  3974. * `angular-material.layout.css`
  3975. *
  3976. * Another option is to use the LayoutProvider to configure and disable the attribute
  3977. * conversions; this would obviate the use of the `md-layout-css` directive
  3978. *
  3979. */
  3980. function disableLayoutDirective() {
  3981. // Return a 1x-only, first-match attribute directive
  3982. config.enabled = false;
  3983. return {
  3984. restrict : 'A',
  3985. priority : '900'
  3986. };
  3987. }
  3988. /**
  3989. * Tail-hook ngCloak to delay the uncloaking while Layout transformers
  3990. * finish processing. Eliminates flicker with Material.Layouts
  3991. */
  3992. function buildCloakInterceptor(className) {
  3993. return [ '$timeout', function($timeout){
  3994. return {
  3995. restrict : 'A',
  3996. priority : -10, // run after normal ng-cloak
  3997. compile : function( element ) {
  3998. if (!config.enabled) return angular.noop;
  3999. // Re-add the cloak
  4000. element.addClass(className);
  4001. return function( scope, element ) {
  4002. // Wait while layout injectors configure, then uncloak
  4003. // NOTE: $rAF does not delay enough... and this is a 1x-only event,
  4004. // $timeout is acceptable.
  4005. $timeout( function(){
  4006. element.removeClass(className);
  4007. }, 10, false);
  4008. };
  4009. }
  4010. };
  4011. }];
  4012. }
  4013. // *********************************************************************************
  4014. //
  4015. // These functions create registration functions for AngularJS Material Layout attribute directives
  4016. // This provides easy translation to switch AngularJS Material attribute selectors to
  4017. // CLASS selectors and directives; which has huge performance implications
  4018. // for IE Browsers
  4019. //
  4020. // *********************************************************************************
  4021. /**
  4022. * Creates a directive registration function where a possible dynamic attribute
  4023. * value will be observed/watched.
  4024. * @param {string} className attribute name; eg `layout-gt-md` with value ="row"
  4025. */
  4026. function attributeWithObserve(className) {
  4027. return ['$mdUtil', '$interpolate', "$log", function(_$mdUtil_, _$interpolate_, _$log_) {
  4028. $mdUtil = _$mdUtil_;
  4029. $interpolate = _$interpolate_;
  4030. $log = _$log_;
  4031. return {
  4032. restrict: 'A',
  4033. compile: function(element, attr) {
  4034. var linkFn;
  4035. if (config.enabled) {
  4036. // immediately replace static (non-interpolated) invalid values...
  4037. validateAttributeUsage(className, attr, element, $log);
  4038. validateAttributeValue( className,
  4039. getNormalizedAttrValue(className, attr, ""),
  4040. buildUpdateFn(element, className, attr)
  4041. );
  4042. linkFn = translateWithValueToCssClass;
  4043. }
  4044. // Use for postLink to account for transforms after ng-transclude.
  4045. return linkFn || angular.noop;
  4046. }
  4047. };
  4048. }];
  4049. /**
  4050. * Add as transformed class selector(s), then
  4051. * remove the deprecated attribute selector
  4052. */
  4053. function translateWithValueToCssClass(scope, element, attrs) {
  4054. var updateFn = updateClassWithValue(element, className, attrs);
  4055. var unwatch = attrs.$observe(attrs.$normalize(className), updateFn);
  4056. updateFn(getNormalizedAttrValue(className, attrs, ""));
  4057. scope.$on("$destroy", function() { unwatch(); });
  4058. }
  4059. }
  4060. /**
  4061. * Creates a registration function for AngularJS Material Layout attribute directive.
  4062. * This is a `simple` transpose of attribute usage to class usage; where we ignore
  4063. * any attribute value
  4064. */
  4065. function attributeWithoutValue(className) {
  4066. return ['$mdUtil', '$interpolate', "$log", function(_$mdUtil_, _$interpolate_, _$log_) {
  4067. $mdUtil = _$mdUtil_;
  4068. $interpolate = _$interpolate_;
  4069. $log = _$log_;
  4070. return {
  4071. restrict: 'A',
  4072. compile: function(element, attr) {
  4073. var linkFn;
  4074. if (config.enabled) {
  4075. // immediately replace static (non-interpolated) invalid values...
  4076. validateAttributeValue( className,
  4077. getNormalizedAttrValue(className, attr, ""),
  4078. buildUpdateFn(element, className, attr)
  4079. );
  4080. translateToCssClass(null, element);
  4081. // Use for postLink to account for transforms after ng-transclude.
  4082. linkFn = translateToCssClass;
  4083. }
  4084. return linkFn || angular.noop;
  4085. }
  4086. };
  4087. }];
  4088. /**
  4089. * Add as transformed class selector, then
  4090. * remove the deprecated attribute selector
  4091. */
  4092. function translateToCssClass(scope, element) {
  4093. element.addClass(className);
  4094. }
  4095. }
  4096. /**
  4097. * After link-phase, do NOT remove deprecated layout attribute selector.
  4098. * Instead watch the attribute so interpolated data-bindings to layout
  4099. * selectors will continue to be supported.
  4100. *
  4101. * $observe() the className and update with new class (after removing the last one)
  4102. *
  4103. * e.g. `layout="{{layoutDemo.direction}}"` will update...
  4104. *
  4105. * NOTE: The value must match one of the specified styles in the CSS.
  4106. * For example `flex-gt-md="{{size}}` where `scope.size == 47` will NOT work since
  4107. * only breakpoints for 0, 5, 10, 15... 100, 33, 34, 66, 67 are defined.
  4108. *
  4109. */
  4110. function updateClassWithValue(element, className) {
  4111. var lastClass;
  4112. return function updateClassFn(newValue) {
  4113. var value = validateAttributeValue(className, newValue || "");
  4114. if ( angular.isDefined(value) ) {
  4115. if (lastClass) element.removeClass(lastClass);
  4116. lastClass = !value ? className : className + "-" + value.trim().replace(WHITESPACE, "-");
  4117. element.addClass(lastClass);
  4118. }
  4119. };
  4120. }
  4121. /**
  4122. * Provide console warning that this layout attribute has been deprecated
  4123. *
  4124. */
  4125. function warnAttrNotSupported(className) {
  4126. var parts = className.split("-");
  4127. return ["$log", function($log) {
  4128. $log.warn(className + "has been deprecated. Please use a `" + parts[0] + "-gt-<xxx>` variant.");
  4129. return angular.noop;
  4130. }];
  4131. }
  4132. /**
  4133. * Centralize warnings for known flexbox issues (especially IE-related issues)
  4134. */
  4135. function validateAttributeUsage(className, attr, element, $log){
  4136. var message, usage, url;
  4137. var nodeName = element[0].nodeName.toLowerCase();
  4138. switch(className.replace(SUFFIXES,"")) {
  4139. case "flex":
  4140. if ((nodeName == "md-button") || (nodeName == "fieldset")){
  4141. // @see https://github.com/philipwalton/flexbugs#9-some-html-elements-cant-be-flex-containers
  4142. // Use <div flex> wrapper inside (preferred) or outside
  4143. usage = "<" + nodeName + " " + className + "></" + nodeName + ">";
  4144. url = "https://github.com/philipwalton/flexbugs#9-some-html-elements-cant-be-flex-containers";
  4145. message = "Markup '{0}' may not work as expected in IE Browsers. Consult '{1}' for details.";
  4146. $log.warn( $mdUtil.supplant(message, [usage, url]) );
  4147. }
  4148. }
  4149. }
  4150. /**
  4151. * For the Layout attribute value, validate or replace with default
  4152. * fallback value
  4153. */
  4154. function validateAttributeValue(className, value, updateFn) {
  4155. var origValue;
  4156. if (!needsInterpolation(value)) {
  4157. switch (className.replace(SUFFIXES,"")) {
  4158. case 'layout' :
  4159. if ( !findIn(value, LAYOUT_OPTIONS) ) {
  4160. value = LAYOUT_OPTIONS[0]; // 'row';
  4161. }
  4162. break;
  4163. case 'flex' :
  4164. if (!findIn(value, FLEX_OPTIONS)) {
  4165. if (isNaN(value)) {
  4166. value = '';
  4167. }
  4168. }
  4169. break;
  4170. case 'flex-offset' :
  4171. case 'flex-order' :
  4172. if (!value || isNaN(+value)) {
  4173. value = '0';
  4174. }
  4175. break;
  4176. case 'layout-align' :
  4177. var axis = extractAlignAxis(value);
  4178. value = $mdUtil.supplant("{main}-{cross}",axis);
  4179. break;
  4180. case 'layout-padding' :
  4181. case 'layout-margin' :
  4182. case 'layout-fill' :
  4183. case 'layout-wrap' :
  4184. case 'layout-nowrap' :
  4185. value = '';
  4186. break;
  4187. }
  4188. if (value != origValue) {
  4189. (updateFn || angular.noop)(value);
  4190. }
  4191. }
  4192. return value ? value.trim() : "";
  4193. }
  4194. /**
  4195. * Replace current attribute value with fallback value
  4196. */
  4197. function buildUpdateFn(element, className, attrs) {
  4198. return function updateAttrValue(fallback) {
  4199. if (!needsInterpolation(fallback)) {
  4200. // Do not modify the element's attribute value; so
  4201. // uses '<ui-layout layout="/api/sidebar.html" />' will not
  4202. // be affected. Just update the attrs value.
  4203. attrs[attrs.$normalize(className)] = fallback;
  4204. }
  4205. };
  4206. }
  4207. /**
  4208. * See if the original value has interpolation symbols:
  4209. * e.g. flex-gt-md="{{triggerPoint}}"
  4210. */
  4211. function needsInterpolation(value) {
  4212. return (value || "").indexOf($interpolate.startSymbol()) > -1;
  4213. }
  4214. function getNormalizedAttrValue(className, attrs, defaultVal) {
  4215. var normalizedAttr = attrs.$normalize(className);
  4216. return attrs[normalizedAttr] ? attrs[normalizedAttr].trim().replace(WHITESPACE, "-") : defaultVal || null;
  4217. }
  4218. function findIn(item, list, replaceWith) {
  4219. item = replaceWith && item ? item.replace(WHITESPACE, replaceWith) : item;
  4220. var found = false;
  4221. if (item) {
  4222. list.forEach(function(it) {
  4223. it = replaceWith ? it.replace(WHITESPACE, replaceWith) : it;
  4224. found = found || (it === item);
  4225. });
  4226. }
  4227. return found;
  4228. }
  4229. function extractAlignAxis(attrValue) {
  4230. var axis = {
  4231. main : "start",
  4232. cross: "stretch"
  4233. }, values;
  4234. attrValue = (attrValue || "");
  4235. if ( attrValue.indexOf("-") === 0 || attrValue.indexOf(" ") === 0) {
  4236. // For missing main-axis values
  4237. attrValue = "none" + attrValue;
  4238. }
  4239. values = attrValue.toLowerCase().trim().replace(WHITESPACE, "-").split("-");
  4240. if ( values.length && (values[0] === "space") ) {
  4241. // for main-axis values of "space-around" or "space-between"
  4242. values = [ values[0]+"-"+values[1],values[2] ];
  4243. }
  4244. if ( values.length > 0 ) axis.main = values[0] || axis.main;
  4245. if ( values.length > 1 ) axis.cross = values[1] || axis.cross;
  4246. if ( ALIGNMENT_MAIN_AXIS.indexOf(axis.main) < 0 ) axis.main = "start";
  4247. if ( ALIGNMENT_CROSS_AXIS.indexOf(axis.cross) < 0 ) axis.cross = "stretch";
  4248. return axis;
  4249. }
  4250. })();
  4251. })();
  4252. (function(){
  4253. "use strict";
  4254. /**
  4255. * @ngdoc module
  4256. * @name material.core.liveannouncer
  4257. * @description
  4258. * AngularJS Material Live Announcer to provide accessibility for Voice Readers.
  4259. */
  4260. MdLiveAnnouncer.$inject = ["$timeout"];
  4261. angular
  4262. .module('material.core')
  4263. .service('$mdLiveAnnouncer', MdLiveAnnouncer);
  4264. /**
  4265. * @ngdoc service
  4266. * @name $mdLiveAnnouncer
  4267. * @module material.core.liveannouncer
  4268. *
  4269. * @description
  4270. *
  4271. * Service to announce messages to supported screenreaders.
  4272. *
  4273. * > The `$mdLiveAnnouncer` service is internally used for components to provide proper accessibility.
  4274. *
  4275. * <hljs lang="js">
  4276. * module.controller('AppCtrl', function($mdLiveAnnouncer) {
  4277. * // Basic announcement (Polite Mode)
  4278. * $mdLiveAnnouncer.announce('Hey Google');
  4279. *
  4280. * // Custom announcement (Assertive Mode)
  4281. * $mdLiveAnnouncer.announce('Hey Google', 'assertive');
  4282. * });
  4283. * </hljs>
  4284. *
  4285. */
  4286. function MdLiveAnnouncer($timeout) {
  4287. /** @private @const @type {!angular.$timeout} */
  4288. this._$timeout = $timeout;
  4289. /** @private @const @type {!HTMLElement} */
  4290. this._liveElement = this._createLiveElement();
  4291. /** @private @const @type {!number} */
  4292. this._announceTimeout = 100;
  4293. }
  4294. /**
  4295. * @ngdoc method
  4296. * @name $mdLiveAnnouncer#announce
  4297. * @description Announces messages to supported screenreaders.
  4298. * @param {string} message Message to be announced to the screenreader
  4299. * @param {'off'|'polite'|'assertive'} politeness The politeness of the announcer element.
  4300. */
  4301. MdLiveAnnouncer.prototype.announce = function(message, politeness) {
  4302. if (!politeness) {
  4303. politeness = 'polite';
  4304. }
  4305. var self = this;
  4306. self._liveElement.textContent = '';
  4307. self._liveElement.setAttribute('aria-live', politeness);
  4308. // This 100ms timeout is necessary for some browser + screen-reader combinations:
  4309. // - Both JAWS and NVDA over IE11 will not announce anything without a non-zero timeout.
  4310. // - With Chrome and IE11 with NVDA or JAWS, a repeated (identical) message won't be read a
  4311. // second time without clearing and then using a non-zero delay.
  4312. // (using JAWS 17 at time of this writing).
  4313. self._$timeout(function() {
  4314. self._liveElement.textContent = message;
  4315. }, self._announceTimeout, false);
  4316. };
  4317. /**
  4318. * Creates a live announcer element, which listens for DOM changes and announces them
  4319. * to the screenreaders.
  4320. * @returns {!HTMLElement}
  4321. * @private
  4322. */
  4323. MdLiveAnnouncer.prototype._createLiveElement = function() {
  4324. var liveEl = document.createElement('div');
  4325. liveEl.classList.add('md-visually-hidden');
  4326. liveEl.setAttribute('role', 'status');
  4327. liveEl.setAttribute('aria-atomic', 'true');
  4328. liveEl.setAttribute('aria-live', 'polite');
  4329. document.body.appendChild(liveEl);
  4330. return liveEl;
  4331. };
  4332. })();
  4333. (function(){
  4334. "use strict";
  4335. /**
  4336. * @ngdoc service
  4337. * @name $$mdMeta
  4338. * @module material.core.meta
  4339. *
  4340. * @description
  4341. *
  4342. * A provider and a service that simplifies meta tags access
  4343. *
  4344. * Note: This is intended only for use with dynamic meta tags such as browser color and title.
  4345. * Tags that are only processed when the page is rendered (such as `charset`, and `http-equiv`)
  4346. * will not work since `$$mdMeta` adds the tags after the page has already been loaded.
  4347. *
  4348. * ```js
  4349. * app.config(function($$mdMetaProvider) {
  4350. * var removeMeta = $$mdMetaProvider.setMeta('meta-name', 'content');
  4351. * var metaValue = $$mdMetaProvider.getMeta('meta-name'); // -> 'content'
  4352. *
  4353. * removeMeta();
  4354. * });
  4355. *
  4356. * app.controller('myController', function($$mdMeta) {
  4357. * var removeMeta = $$mdMeta.setMeta('meta-name', 'content');
  4358. * var metaValue = $$mdMeta.getMeta('meta-name'); // -> 'content'
  4359. *
  4360. * removeMeta();
  4361. * });
  4362. * ```
  4363. *
  4364. * @returns {$$mdMeta.$service}
  4365. *
  4366. */
  4367. angular.module('material.core.meta', [])
  4368. .provider('$$mdMeta', function () {
  4369. var head = angular.element(document.head);
  4370. var metaElements = {};
  4371. /**
  4372. * Checks if the requested element was written manually and maps it
  4373. *
  4374. * @param {string} name meta tag 'name' attribute value
  4375. * @returns {boolean} returns true if there is an element with the requested name
  4376. */
  4377. function mapExistingElement(name) {
  4378. if (metaElements[name]) {
  4379. return true;
  4380. }
  4381. var element = document.getElementsByName(name)[0];
  4382. if (!element) {
  4383. return false;
  4384. }
  4385. metaElements[name] = angular.element(element);
  4386. return true;
  4387. }
  4388. /**
  4389. * @ngdoc method
  4390. * @name $$mdMeta#setMeta
  4391. *
  4392. * @description
  4393. * Creates meta element with the 'name' and 'content' attributes,
  4394. * if the meta tag is already created than we replace the 'content' value
  4395. *
  4396. * @param {string} name meta tag 'name' attribute value
  4397. * @param {string} content meta tag 'content' attribute value
  4398. * @returns {function} remove function
  4399. *
  4400. */
  4401. function setMeta(name, content) {
  4402. mapExistingElement(name);
  4403. if (!metaElements[name]) {
  4404. var newMeta = angular.element('<meta name="' + name + '" content="' + content + '"/>');
  4405. head.append(newMeta);
  4406. metaElements[name] = newMeta;
  4407. }
  4408. else {
  4409. metaElements[name].attr('content', content);
  4410. }
  4411. return function () {
  4412. metaElements[name].attr('content', '');
  4413. metaElements[name].remove();
  4414. delete metaElements[name];
  4415. };
  4416. }
  4417. /**
  4418. * @ngdoc method
  4419. * @name $$mdMeta#getMeta
  4420. *
  4421. * @description
  4422. * Gets the 'content' attribute value of the wanted meta element
  4423. *
  4424. * @param {string} name meta tag 'name' attribute value
  4425. * @returns {string} content attribute value
  4426. */
  4427. function getMeta(name) {
  4428. if (!mapExistingElement(name)) {
  4429. throw Error('$$mdMeta: could not find a meta tag with the name \'' + name + '\'');
  4430. }
  4431. return metaElements[name].attr('content');
  4432. }
  4433. var module = {
  4434. setMeta: setMeta,
  4435. getMeta: getMeta
  4436. };
  4437. return angular.extend({}, module, {
  4438. $get: function () {
  4439. return module;
  4440. }
  4441. });
  4442. });
  4443. })();
  4444. (function(){
  4445. "use strict";
  4446. /**
  4447. * @ngdoc module
  4448. * @name material.core.componentRegistry
  4449. *
  4450. * @description
  4451. * A component instance registration service.
  4452. * Note: currently this as a private service in the SideNav component.
  4453. */
  4454. ComponentRegistry.$inject = ["$log", "$q"];
  4455. angular.module('material.core')
  4456. .factory('$mdComponentRegistry', ComponentRegistry);
  4457. /*
  4458. * @private
  4459. * @ngdoc factory
  4460. * @name ComponentRegistry
  4461. * @module material.core.componentRegistry
  4462. *
  4463. */
  4464. function ComponentRegistry($log, $q) {
  4465. var self;
  4466. var instances = [ ];
  4467. var pendings = { };
  4468. return self = {
  4469. /**
  4470. * Used to print an error when an instance for a handle isn't found.
  4471. */
  4472. notFoundError: function(handle, msgContext) {
  4473. $log.error( (msgContext || "") + 'No instance found for handle', handle);
  4474. },
  4475. /**
  4476. * Return all registered instances as an array.
  4477. */
  4478. getInstances: function() {
  4479. return instances;
  4480. },
  4481. /**
  4482. * Get a registered instance.
  4483. * @param handle the String handle to look up for a registered instance.
  4484. */
  4485. get: function(handle) {
  4486. if ( !isValidID(handle) ) return null;
  4487. var i, j, instance;
  4488. for(i = 0, j = instances.length; i < j; i++) {
  4489. instance = instances[i];
  4490. if(instance.$$mdHandle === handle) {
  4491. return instance;
  4492. }
  4493. }
  4494. return null;
  4495. },
  4496. /**
  4497. * Register an instance.
  4498. * @param instance the instance to register
  4499. * @param handle the handle to identify the instance under.
  4500. */
  4501. register: function(instance, handle) {
  4502. if ( !handle ) return angular.noop;
  4503. instance.$$mdHandle = handle;
  4504. instances.push(instance);
  4505. resolveWhen();
  4506. return deregister;
  4507. /**
  4508. * Remove registration for an instance
  4509. */
  4510. function deregister() {
  4511. var index = instances.indexOf(instance);
  4512. if (index !== -1) {
  4513. instances.splice(index, 1);
  4514. }
  4515. }
  4516. /**
  4517. * Resolve any pending promises for this instance
  4518. */
  4519. function resolveWhen() {
  4520. var dfd = pendings[handle];
  4521. if ( dfd ) {
  4522. dfd.forEach(function (promise) {
  4523. promise.resolve(instance);
  4524. });
  4525. delete pendings[handle];
  4526. }
  4527. }
  4528. },
  4529. /**
  4530. * Async accessor to registered component instance
  4531. * If not available then a promise is created to notify
  4532. * all listeners when the instance is registered.
  4533. */
  4534. when : function(handle) {
  4535. if ( isValidID(handle) ) {
  4536. var deferred = $q.defer();
  4537. var instance = self.get(handle);
  4538. if ( instance ) {
  4539. deferred.resolve( instance );
  4540. } else {
  4541. if (pendings[handle] === undefined) {
  4542. pendings[handle] = [];
  4543. }
  4544. pendings[handle].push(deferred);
  4545. }
  4546. return deferred.promise;
  4547. }
  4548. return $q.reject("Invalid `md-component-id` value.");
  4549. }
  4550. };
  4551. function isValidID(handle){
  4552. return handle && (handle !== "");
  4553. }
  4554. }
  4555. })();
  4556. (function(){
  4557. "use strict";
  4558. (function() {
  4559. 'use strict';
  4560. /**
  4561. * @ngdoc service
  4562. * @name $mdButtonInkRipple
  4563. * @module material.core
  4564. *
  4565. * @description
  4566. * Provides ripple effects for md-button. See $mdInkRipple service for all possible configuration options.
  4567. *
  4568. * @param {object=} scope Scope within the current context
  4569. * @param {object=} element The element the ripple effect should be applied to
  4570. * @param {object=} options (Optional) Configuration options to override the default ripple configuration
  4571. */
  4572. MdButtonInkRipple.$inject = ["$mdInkRipple"];
  4573. angular.module('material.core')
  4574. .factory('$mdButtonInkRipple', MdButtonInkRipple);
  4575. function MdButtonInkRipple($mdInkRipple) {
  4576. return {
  4577. attach: function attachRipple(scope, element, options) {
  4578. options = angular.extend(optionsForElement(element), options);
  4579. return $mdInkRipple.attach(scope, element, options);
  4580. }
  4581. };
  4582. function optionsForElement(element) {
  4583. if (element.hasClass('md-icon-button')) {
  4584. return {
  4585. isMenuItem: element.hasClass('md-menu-item'),
  4586. fitRipple: true,
  4587. center: true
  4588. };
  4589. } else {
  4590. return {
  4591. isMenuItem: element.hasClass('md-menu-item'),
  4592. dimBackground: true
  4593. };
  4594. }
  4595. }
  4596. }
  4597. })();
  4598. })();
  4599. (function(){
  4600. "use strict";
  4601. (function() {
  4602. 'use strict';
  4603. /**
  4604. * @ngdoc service
  4605. * @name $mdCheckboxInkRipple
  4606. * @module material.core
  4607. *
  4608. * @description
  4609. * Provides ripple effects for md-checkbox. See $mdInkRipple service for all possible configuration options.
  4610. *
  4611. * @param {object=} scope Scope within the current context
  4612. * @param {object=} element The element the ripple effect should be applied to
  4613. * @param {object=} options (Optional) Configuration options to override the defaultripple configuration
  4614. */
  4615. MdCheckboxInkRipple.$inject = ["$mdInkRipple"];
  4616. angular.module('material.core')
  4617. .factory('$mdCheckboxInkRipple', MdCheckboxInkRipple);
  4618. function MdCheckboxInkRipple($mdInkRipple) {
  4619. return {
  4620. attach: attach
  4621. };
  4622. function attach(scope, element, options) {
  4623. return $mdInkRipple.attach(scope, element, angular.extend({
  4624. center: true,
  4625. dimBackground: false,
  4626. fitRipple: true
  4627. }, options));
  4628. }
  4629. }
  4630. })();
  4631. })();
  4632. (function(){
  4633. "use strict";
  4634. (function() {
  4635. 'use strict';
  4636. /**
  4637. * @ngdoc service
  4638. * @name $mdListInkRipple
  4639. * @module material.core
  4640. *
  4641. * @description
  4642. * Provides ripple effects for md-list. See $mdInkRipple service for all possible configuration options.
  4643. *
  4644. * @param {object=} scope Scope within the current context
  4645. * @param {object=} element The element the ripple effect should be applied to
  4646. * @param {object=} options (Optional) Configuration options to override the defaultripple configuration
  4647. */
  4648. MdListInkRipple.$inject = ["$mdInkRipple"];
  4649. angular.module('material.core')
  4650. .factory('$mdListInkRipple', MdListInkRipple);
  4651. function MdListInkRipple($mdInkRipple) {
  4652. return {
  4653. attach: attach
  4654. };
  4655. function attach(scope, element, options) {
  4656. return $mdInkRipple.attach(scope, element, angular.extend({
  4657. center: false,
  4658. dimBackground: true,
  4659. outline: false,
  4660. rippleSize: 'full'
  4661. }, options));
  4662. }
  4663. }
  4664. })();
  4665. })();
  4666. (function(){
  4667. "use strict";
  4668. /**
  4669. * @ngdoc module
  4670. * @name material.core.ripple
  4671. * @description
  4672. * Ripple
  4673. */
  4674. InkRippleCtrl.$inject = ["$scope", "$element", "rippleOptions", "$window", "$timeout", "$mdUtil", "$mdColorUtil"];
  4675. InkRippleDirective.$inject = ["$mdButtonInkRipple", "$mdCheckboxInkRipple"];
  4676. angular.module('material.core')
  4677. .provider('$mdInkRipple', InkRippleProvider)
  4678. .directive('mdInkRipple', InkRippleDirective)
  4679. .directive('mdNoInk', attrNoDirective)
  4680. .directive('mdNoBar', attrNoDirective)
  4681. .directive('mdNoStretch', attrNoDirective);
  4682. var DURATION = 450;
  4683. /**
  4684. * @ngdoc directive
  4685. * @name mdInkRipple
  4686. * @module material.core.ripple
  4687. *
  4688. * @description
  4689. * The `md-ink-ripple` directive allows you to specify the ripple color or if a ripple is allowed.
  4690. *
  4691. * @param {string|boolean} md-ink-ripple A color string `#FF0000` or boolean (`false` or `0`) for preventing ripple
  4692. *
  4693. * @usage
  4694. * ### String values
  4695. * <hljs lang="html">
  4696. * <ANY md-ink-ripple="#FF0000">
  4697. * Ripples in red
  4698. * </ANY>
  4699. *
  4700. * <ANY md-ink-ripple="false">
  4701. * Not rippling
  4702. * </ANY>
  4703. * </hljs>
  4704. *
  4705. * ### Interpolated values
  4706. * <hljs lang="html">
  4707. * <ANY md-ink-ripple="{{ randomColor() }}">
  4708. * Ripples with the return value of 'randomColor' function
  4709. * </ANY>
  4710. *
  4711. * <ANY md-ink-ripple="{{ canRipple() }}">
  4712. * Ripples if 'canRipple' function return value is not 'false' or '0'
  4713. * </ANY>
  4714. * </hljs>
  4715. */
  4716. function InkRippleDirective ($mdButtonInkRipple, $mdCheckboxInkRipple) {
  4717. return {
  4718. controller: angular.noop,
  4719. link: function (scope, element, attr) {
  4720. attr.hasOwnProperty('mdInkRippleCheckbox')
  4721. ? $mdCheckboxInkRipple.attach(scope, element)
  4722. : $mdButtonInkRipple.attach(scope, element);
  4723. }
  4724. };
  4725. }
  4726. /**
  4727. * @ngdoc service
  4728. * @name $mdInkRipple
  4729. * @module material.core.ripple
  4730. *
  4731. * @description
  4732. * `$mdInkRipple` is a service for adding ripples to any element
  4733. *
  4734. * @usage
  4735. * <hljs lang="js">
  4736. * app.factory('$myElementInkRipple', function($mdInkRipple) {
  4737. * return {
  4738. * attach: function (scope, element, options) {
  4739. * return $mdInkRipple.attach(scope, element, angular.extend({
  4740. * center: false,
  4741. * dimBackground: true
  4742. * }, options));
  4743. * }
  4744. * };
  4745. * });
  4746. *
  4747. * app.controller('myController', function ($scope, $element, $myElementInkRipple) {
  4748. * $scope.onClick = function (ev) {
  4749. * $myElementInkRipple.attach($scope, angular.element(ev.target), { center: true });
  4750. * }
  4751. * });
  4752. * </hljs>
  4753. *
  4754. * ### Disabling ripples globally
  4755. * If you want to disable ink ripples globally, for all components, you can call the
  4756. * `disableInkRipple` method in your app's config.
  4757. *
  4758. * <hljs lang="js">
  4759. * app.config(function ($mdInkRippleProvider) {
  4760. * $mdInkRippleProvider.disableInkRipple();
  4761. * });
  4762. */
  4763. function InkRippleProvider () {
  4764. var isDisabledGlobally = false;
  4765. return {
  4766. disableInkRipple: disableInkRipple,
  4767. $get: ["$injector", function($injector) {
  4768. return { attach: attach };
  4769. /**
  4770. * @ngdoc method
  4771. * @name $mdInkRipple#attach
  4772. *
  4773. * @description
  4774. * Attaching given scope, element and options to inkRipple controller
  4775. *
  4776. * @param {object=} scope Scope within the current context
  4777. * @param {object=} element The element the ripple effect should be applied to
  4778. * @param {object=} options (Optional) Configuration options to override the defaultRipple configuration
  4779. * * `center` - Whether the ripple should start from the center of the container element
  4780. * * `dimBackground` - Whether the background should be dimmed with the ripple color
  4781. * * `colorElement` - The element the ripple should take its color from, defined by css property `color`
  4782. * * `fitRipple` - Whether the ripple should fill the element
  4783. */
  4784. function attach (scope, element, options) {
  4785. if (isDisabledGlobally || element.controller('mdNoInk')) return angular.noop;
  4786. return $injector.instantiate(InkRippleCtrl, {
  4787. $scope: scope,
  4788. $element: element,
  4789. rippleOptions: options
  4790. });
  4791. }
  4792. }]
  4793. };
  4794. /**
  4795. * @ngdoc method
  4796. * @name $mdInkRipple#disableInkRipple
  4797. *
  4798. * @description
  4799. * A config-time method that, when called, disables ripples globally.
  4800. */
  4801. function disableInkRipple () {
  4802. isDisabledGlobally = true;
  4803. }
  4804. }
  4805. /**
  4806. * Controller used by the ripple service in order to apply ripples
  4807. * @ngInject
  4808. */
  4809. function InkRippleCtrl ($scope, $element, rippleOptions, $window, $timeout, $mdUtil, $mdColorUtil) {
  4810. this.$window = $window;
  4811. this.$timeout = $timeout;
  4812. this.$mdUtil = $mdUtil;
  4813. this.$mdColorUtil = $mdColorUtil;
  4814. this.$scope = $scope;
  4815. this.$element = $element;
  4816. this.options = rippleOptions;
  4817. this.mousedown = false;
  4818. this.ripples = [];
  4819. this.timeout = null; // Stores a reference to the most-recent ripple timeout
  4820. this.lastRipple = null;
  4821. $mdUtil.valueOnUse(this, 'container', this.createContainer);
  4822. this.$element.addClass('md-ink-ripple');
  4823. // attach method for unit tests
  4824. ($element.controller('mdInkRipple') || {}).createRipple = angular.bind(this, this.createRipple);
  4825. ($element.controller('mdInkRipple') || {}).setColor = angular.bind(this, this.color);
  4826. this.bindEvents();
  4827. }
  4828. /**
  4829. * Either remove or unlock any remaining ripples when the user mouses off of the element (either by
  4830. * mouseup or mouseleave event)
  4831. */
  4832. function autoCleanup (self, cleanupFn) {
  4833. if ( self.mousedown || self.lastRipple ) {
  4834. self.mousedown = false;
  4835. self.$mdUtil.nextTick( angular.bind(self, cleanupFn), false);
  4836. }
  4837. }
  4838. /**
  4839. * Returns the color that the ripple should be (either based on CSS or hard-coded)
  4840. * @returns {string}
  4841. */
  4842. InkRippleCtrl.prototype.color = function (value) {
  4843. var self = this;
  4844. // If assigning a color value, apply it to background and the ripple color
  4845. if (angular.isDefined(value)) {
  4846. self._color = self._parseColor(value);
  4847. }
  4848. // If color lookup, use assigned, defined, or inherited
  4849. return self._color || self._parseColor( self.inkRipple() ) || self._parseColor( getElementColor() );
  4850. /**
  4851. * Finds the color element and returns its text color for use as default ripple color
  4852. * @returns {string}
  4853. */
  4854. function getElementColor () {
  4855. var items = self.options && self.options.colorElement ? self.options.colorElement : [];
  4856. var elem = items.length ? items[ 0 ] : self.$element[ 0 ];
  4857. return elem ? self.$window.getComputedStyle(elem).color : 'rgb(0,0,0)';
  4858. }
  4859. };
  4860. /**
  4861. * Updating the ripple colors based on the current inkRipple value
  4862. * or the element's computed style color
  4863. */
  4864. InkRippleCtrl.prototype.calculateColor = function () {
  4865. return this.color();
  4866. };
  4867. /**
  4868. * Takes a string color and converts it to RGBA format
  4869. * @param color {string}
  4870. * @param [multiplier] {int}
  4871. * @returns {string}
  4872. */
  4873. InkRippleCtrl.prototype._parseColor = function parseColor (color, multiplier) {
  4874. multiplier = multiplier || 1;
  4875. var colorUtil = this.$mdColorUtil;
  4876. if (!color) return;
  4877. if (color.indexOf('rgba') === 0) return color.replace(/\d?\.?\d*\s*\)\s*$/, (0.1 * multiplier).toString() + ')');
  4878. if (color.indexOf('rgb') === 0) return colorUtil.rgbToRgba(color);
  4879. if (color.indexOf('#') === 0) return colorUtil.hexToRgba(color);
  4880. };
  4881. /**
  4882. * Binds events to the root element for
  4883. */
  4884. InkRippleCtrl.prototype.bindEvents = function () {
  4885. this.$element.on('mousedown', angular.bind(this, this.handleMousedown));
  4886. this.$element.on('mouseup touchend', angular.bind(this, this.handleMouseup));
  4887. this.$element.on('mouseleave', angular.bind(this, this.handleMouseup));
  4888. this.$element.on('touchmove', angular.bind(this, this.handleTouchmove));
  4889. };
  4890. /**
  4891. * Create a new ripple on every mousedown event from the root element
  4892. * @param event {MouseEvent}
  4893. */
  4894. InkRippleCtrl.prototype.handleMousedown = function (event) {
  4895. if ( this.mousedown ) return;
  4896. // When jQuery is loaded, we have to get the original event
  4897. if (event.hasOwnProperty('originalEvent')) event = event.originalEvent;
  4898. this.mousedown = true;
  4899. if (this.options.center) {
  4900. this.createRipple(this.container.prop('clientWidth') / 2, this.container.prop('clientWidth') / 2);
  4901. } else {
  4902. // We need to calculate the relative coordinates if the target is a sublayer of the ripple element
  4903. if (event.srcElement !== this.$element[0]) {
  4904. var layerRect = this.$element[0].getBoundingClientRect();
  4905. var layerX = event.clientX - layerRect.left;
  4906. var layerY = event.clientY - layerRect.top;
  4907. this.createRipple(layerX, layerY);
  4908. } else {
  4909. this.createRipple(event.offsetX, event.offsetY);
  4910. }
  4911. }
  4912. };
  4913. /**
  4914. * Either remove or unlock any remaining ripples when the user mouses off of the element (either by
  4915. * mouseup, touchend or mouseleave event)
  4916. */
  4917. InkRippleCtrl.prototype.handleMouseup = function () {
  4918. autoCleanup(this, this.clearRipples);
  4919. };
  4920. /**
  4921. * Either remove or unlock any remaining ripples when the user mouses off of the element (by
  4922. * touchmove)
  4923. */
  4924. InkRippleCtrl.prototype.handleTouchmove = function () {
  4925. autoCleanup(this, this.deleteRipples);
  4926. };
  4927. /**
  4928. * Cycles through all ripples and attempts to remove them.
  4929. */
  4930. InkRippleCtrl.prototype.deleteRipples = function () {
  4931. for (var i = 0; i < this.ripples.length; i++) {
  4932. this.ripples[ i ].remove();
  4933. }
  4934. };
  4935. /**
  4936. * Cycles through all ripples and attempts to remove them with fade.
  4937. * Depending on logic within `fadeInComplete`, some removals will be postponed.
  4938. */
  4939. InkRippleCtrl.prototype.clearRipples = function () {
  4940. for (var i = 0; i < this.ripples.length; i++) {
  4941. this.fadeInComplete(this.ripples[ i ]);
  4942. }
  4943. };
  4944. /**
  4945. * Creates the ripple container element
  4946. * @returns {*}
  4947. */
  4948. InkRippleCtrl.prototype.createContainer = function () {
  4949. var container = angular.element('<div class="md-ripple-container"></div>');
  4950. this.$element.append(container);
  4951. return container;
  4952. };
  4953. InkRippleCtrl.prototype.clearTimeout = function () {
  4954. if (this.timeout) {
  4955. this.$timeout.cancel(this.timeout);
  4956. this.timeout = null;
  4957. }
  4958. };
  4959. InkRippleCtrl.prototype.isRippleAllowed = function () {
  4960. var element = this.$element[0];
  4961. do {
  4962. if (!element.tagName || element.tagName === 'BODY') break;
  4963. if (element && angular.isFunction(element.hasAttribute)) {
  4964. if (element.hasAttribute('disabled')) return false;
  4965. if (this.inkRipple() === 'false' || this.inkRipple() === '0') return false;
  4966. }
  4967. } while (element = element.parentNode);
  4968. return true;
  4969. };
  4970. /**
  4971. * The attribute `md-ink-ripple` may be a static or interpolated
  4972. * color value OR a boolean indicator (used to disable ripples)
  4973. */
  4974. InkRippleCtrl.prototype.inkRipple = function () {
  4975. return this.$element.attr('md-ink-ripple');
  4976. };
  4977. /**
  4978. * Creates a new ripple and adds it to the container. Also tracks ripple in `this.ripples`.
  4979. * @param left
  4980. * @param top
  4981. */
  4982. InkRippleCtrl.prototype.createRipple = function (left, top) {
  4983. if (!this.isRippleAllowed()) return;
  4984. var ctrl = this;
  4985. var colorUtil = ctrl.$mdColorUtil;
  4986. var ripple = angular.element('<div class="md-ripple"></div>');
  4987. var width = this.$element.prop('clientWidth');
  4988. var height = this.$element.prop('clientHeight');
  4989. var x = Math.max(Math.abs(width - left), left) * 2;
  4990. var y = Math.max(Math.abs(height - top), top) * 2;
  4991. var size = getSize(this.options.fitRipple, x, y);
  4992. var color = this.calculateColor();
  4993. ripple.css({
  4994. left: left + 'px',
  4995. top: top + 'px',
  4996. background: 'black',
  4997. width: size + 'px',
  4998. height: size + 'px',
  4999. backgroundColor: colorUtil.rgbaToRgb(color),
  5000. borderColor: colorUtil.rgbaToRgb(color)
  5001. });
  5002. this.lastRipple = ripple;
  5003. // we only want one timeout to be running at a time
  5004. this.clearTimeout();
  5005. this.timeout = this.$timeout(function () {
  5006. ctrl.clearTimeout();
  5007. if (!ctrl.mousedown) ctrl.fadeInComplete(ripple);
  5008. }, DURATION * 0.35, false);
  5009. if (this.options.dimBackground) this.container.css({ backgroundColor: color });
  5010. this.container.append(ripple);
  5011. this.ripples.push(ripple);
  5012. ripple.addClass('md-ripple-placed');
  5013. this.$mdUtil.nextTick(function () {
  5014. ripple.addClass('md-ripple-scaled md-ripple-active');
  5015. ctrl.$timeout(function () {
  5016. ctrl.clearRipples();
  5017. }, DURATION, false);
  5018. }, false);
  5019. function getSize (fit, x, y) {
  5020. return fit
  5021. ? Math.max(x, y)
  5022. : Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
  5023. }
  5024. };
  5025. /**
  5026. * After fadeIn finishes, either kicks off the fade-out animation or queues the element for removal on mouseup
  5027. * @param ripple
  5028. */
  5029. InkRippleCtrl.prototype.fadeInComplete = function (ripple) {
  5030. if (this.lastRipple === ripple) {
  5031. if (!this.timeout && !this.mousedown) {
  5032. this.removeRipple(ripple);
  5033. }
  5034. } else {
  5035. this.removeRipple(ripple);
  5036. }
  5037. };
  5038. /**
  5039. * Kicks off the animation for removing a ripple
  5040. * @param ripple {Element}
  5041. */
  5042. InkRippleCtrl.prototype.removeRipple = function (ripple) {
  5043. var ctrl = this;
  5044. var index = this.ripples.indexOf(ripple);
  5045. if (index < 0) return;
  5046. this.ripples.splice(this.ripples.indexOf(ripple), 1);
  5047. ripple.removeClass('md-ripple-active');
  5048. ripple.addClass('md-ripple-remove');
  5049. if (this.ripples.length === 0) this.container.css({ backgroundColor: '' });
  5050. // use a 2-second timeout in order to allow for the animation to finish
  5051. // we don't actually care how long the animation takes
  5052. this.$timeout(function () {
  5053. ctrl.fadeOutComplete(ripple);
  5054. }, DURATION, false);
  5055. };
  5056. /**
  5057. * Removes the provided ripple from the DOM
  5058. * @param ripple
  5059. */
  5060. InkRippleCtrl.prototype.fadeOutComplete = function (ripple) {
  5061. ripple.remove();
  5062. this.lastRipple = null;
  5063. };
  5064. /**
  5065. * Used to create an empty directive. This is used to track flag-directives whose children may have
  5066. * functionality based on them.
  5067. *
  5068. * Example: `md-no-ink` will potentially be used by all child directives.
  5069. */
  5070. function attrNoDirective () {
  5071. return { controller: angular.noop };
  5072. }
  5073. })();
  5074. (function(){
  5075. "use strict";
  5076. (function() {
  5077. 'use strict';
  5078. /**
  5079. * @ngdoc service
  5080. * @name $mdTabInkRipple
  5081. * @module material.core
  5082. *
  5083. * @description
  5084. * Provides ripple effects for md-tabs. See $mdInkRipple service for all possible configuration options.
  5085. *
  5086. * @param {object=} scope Scope within the current context
  5087. * @param {object=} element The element the ripple effect should be applied to
  5088. * @param {object=} options (Optional) Configuration options to override the defaultripple configuration
  5089. */
  5090. MdTabInkRipple.$inject = ["$mdInkRipple"];
  5091. angular.module('material.core')
  5092. .factory('$mdTabInkRipple', MdTabInkRipple);
  5093. function MdTabInkRipple($mdInkRipple) {
  5094. return {
  5095. attach: attach
  5096. };
  5097. function attach(scope, element, options) {
  5098. return $mdInkRipple.attach(scope, element, angular.extend({
  5099. center: false,
  5100. dimBackground: true,
  5101. outline: false,
  5102. rippleSize: 'full'
  5103. }, options));
  5104. }
  5105. }
  5106. })();
  5107. })();
  5108. (function(){
  5109. "use strict";
  5110. angular.module('material.core.theming.palette', [])
  5111. .constant('$mdColorPalette', {
  5112. 'red': {
  5113. '50': '#ffebee',
  5114. '100': '#ffcdd2',
  5115. '200': '#ef9a9a',
  5116. '300': '#e57373',
  5117. '400': '#ef5350',
  5118. '500': '#f44336',
  5119. '600': '#e53935',
  5120. '700': '#d32f2f',
  5121. '800': '#c62828',
  5122. '900': '#b71c1c',
  5123. 'A100': '#ff8a80',
  5124. 'A200': '#ff5252',
  5125. 'A400': '#ff1744',
  5126. 'A700': '#d50000',
  5127. 'contrastDefaultColor': 'light',
  5128. 'contrastDarkColors': '50 100 200 300 A100',
  5129. 'contrastStrongLightColors': '400 500 600 700 A200 A400 A700'
  5130. },
  5131. 'pink': {
  5132. '50': '#fce4ec',
  5133. '100': '#f8bbd0',
  5134. '200': '#f48fb1',
  5135. '300': '#f06292',
  5136. '400': '#ec407a',
  5137. '500': '#e91e63',
  5138. '600': '#d81b60',
  5139. '700': '#c2185b',
  5140. '800': '#ad1457',
  5141. '900': '#880e4f',
  5142. 'A100': '#ff80ab',
  5143. 'A200': '#ff4081',
  5144. 'A400': '#f50057',
  5145. 'A700': '#c51162',
  5146. 'contrastDefaultColor': 'light',
  5147. 'contrastDarkColors': '50 100 200 A100',
  5148. 'contrastStrongLightColors': '500 600 A200 A400 A700'
  5149. },
  5150. 'purple': {
  5151. '50': '#f3e5f5',
  5152. '100': '#e1bee7',
  5153. '200': '#ce93d8',
  5154. '300': '#ba68c8',
  5155. '400': '#ab47bc',
  5156. '500': '#9c27b0',
  5157. '600': '#8e24aa',
  5158. '700': '#7b1fa2',
  5159. '800': '#6a1b9a',
  5160. '900': '#4a148c',
  5161. 'A100': '#ea80fc',
  5162. 'A200': '#e040fb',
  5163. 'A400': '#d500f9',
  5164. 'A700': '#aa00ff',
  5165. 'contrastDefaultColor': 'light',
  5166. 'contrastDarkColors': '50 100 200 A100',
  5167. 'contrastStrongLightColors': '300 400 A200 A400 A700'
  5168. },
  5169. 'deep-purple': {
  5170. '50': '#ede7f6',
  5171. '100': '#d1c4e9',
  5172. '200': '#b39ddb',
  5173. '300': '#9575cd',
  5174. '400': '#7e57c2',
  5175. '500': '#673ab7',
  5176. '600': '#5e35b1',
  5177. '700': '#512da8',
  5178. '800': '#4527a0',
  5179. '900': '#311b92',
  5180. 'A100': '#b388ff',
  5181. 'A200': '#7c4dff',
  5182. 'A400': '#651fff',
  5183. 'A700': '#6200ea',
  5184. 'contrastDefaultColor': 'light',
  5185. 'contrastDarkColors': '50 100 200 A100',
  5186. 'contrastStrongLightColors': '300 400 A200'
  5187. },
  5188. 'indigo': {
  5189. '50': '#e8eaf6',
  5190. '100': '#c5cae9',
  5191. '200': '#9fa8da',
  5192. '300': '#7986cb',
  5193. '400': '#5c6bc0',
  5194. '500': '#3f51b5',
  5195. '600': '#3949ab',
  5196. '700': '#303f9f',
  5197. '800': '#283593',
  5198. '900': '#1a237e',
  5199. 'A100': '#8c9eff',
  5200. 'A200': '#536dfe',
  5201. 'A400': '#3d5afe',
  5202. 'A700': '#304ffe',
  5203. 'contrastDefaultColor': 'light',
  5204. 'contrastDarkColors': '50 100 200 A100',
  5205. 'contrastStrongLightColors': '300 400 A200 A400'
  5206. },
  5207. 'blue': {
  5208. '50': '#e3f2fd',
  5209. '100': '#bbdefb',
  5210. '200': '#90caf9',
  5211. '300': '#64b5f6',
  5212. '400': '#42a5f5',
  5213. '500': '#2196f3',
  5214. '600': '#1e88e5',
  5215. '700': '#1976d2',
  5216. '800': '#1565c0',
  5217. '900': '#0d47a1',
  5218. 'A100': '#82b1ff',
  5219. 'A200': '#448aff',
  5220. 'A400': '#2979ff',
  5221. 'A700': '#2962ff',
  5222. 'contrastDefaultColor': 'light',
  5223. 'contrastDarkColors': '50 100 200 300 400 A100',
  5224. 'contrastStrongLightColors': '500 600 700 A200 A400 A700'
  5225. },
  5226. 'light-blue': {
  5227. '50': '#e1f5fe',
  5228. '100': '#b3e5fc',
  5229. '200': '#81d4fa',
  5230. '300': '#4fc3f7',
  5231. '400': '#29b6f6',
  5232. '500': '#03a9f4',
  5233. '600': '#039be5',
  5234. '700': '#0288d1',
  5235. '800': '#0277bd',
  5236. '900': '#01579b',
  5237. 'A100': '#80d8ff',
  5238. 'A200': '#40c4ff',
  5239. 'A400': '#00b0ff',
  5240. 'A700': '#0091ea',
  5241. 'contrastDefaultColor': 'dark',
  5242. 'contrastLightColors': '600 700 800 900 A700',
  5243. 'contrastStrongLightColors': '600 700 800 A700'
  5244. },
  5245. 'cyan': {
  5246. '50': '#e0f7fa',
  5247. '100': '#b2ebf2',
  5248. '200': '#80deea',
  5249. '300': '#4dd0e1',
  5250. '400': '#26c6da',
  5251. '500': '#00bcd4',
  5252. '600': '#00acc1',
  5253. '700': '#0097a7',
  5254. '800': '#00838f',
  5255. '900': '#006064',
  5256. 'A100': '#84ffff',
  5257. 'A200': '#18ffff',
  5258. 'A400': '#00e5ff',
  5259. 'A700': '#00b8d4',
  5260. 'contrastDefaultColor': 'dark',
  5261. 'contrastLightColors': '700 800 900',
  5262. 'contrastStrongLightColors': '700 800 900'
  5263. },
  5264. 'teal': {
  5265. '50': '#e0f2f1',
  5266. '100': '#b2dfdb',
  5267. '200': '#80cbc4',
  5268. '300': '#4db6ac',
  5269. '400': '#26a69a',
  5270. '500': '#009688',
  5271. '600': '#00897b',
  5272. '700': '#00796b',
  5273. '800': '#00695c',
  5274. '900': '#004d40',
  5275. 'A100': '#a7ffeb',
  5276. 'A200': '#64ffda',
  5277. 'A400': '#1de9b6',
  5278. 'A700': '#00bfa5',
  5279. 'contrastDefaultColor': 'dark',
  5280. 'contrastLightColors': '500 600 700 800 900',
  5281. 'contrastStrongLightColors': '500 600 700'
  5282. },
  5283. 'green': {
  5284. '50': '#e8f5e9',
  5285. '100': '#c8e6c9',
  5286. '200': '#a5d6a7',
  5287. '300': '#81c784',
  5288. '400': '#66bb6a',
  5289. '500': '#4caf50',
  5290. '600': '#43a047',
  5291. '700': '#388e3c',
  5292. '800': '#2e7d32',
  5293. '900': '#1b5e20',
  5294. 'A100': '#b9f6ca',
  5295. 'A200': '#69f0ae',
  5296. 'A400': '#00e676',
  5297. 'A700': '#00c853',
  5298. 'contrastDefaultColor': 'dark',
  5299. 'contrastLightColors': '500 600 700 800 900',
  5300. 'contrastStrongLightColors': '500 600 700'
  5301. },
  5302. 'light-green': {
  5303. '50': '#f1f8e9',
  5304. '100': '#dcedc8',
  5305. '200': '#c5e1a5',
  5306. '300': '#aed581',
  5307. '400': '#9ccc65',
  5308. '500': '#8bc34a',
  5309. '600': '#7cb342',
  5310. '700': '#689f38',
  5311. '800': '#558b2f',
  5312. '900': '#33691e',
  5313. 'A100': '#ccff90',
  5314. 'A200': '#b2ff59',
  5315. 'A400': '#76ff03',
  5316. 'A700': '#64dd17',
  5317. 'contrastDefaultColor': 'dark',
  5318. 'contrastLightColors': '700 800 900',
  5319. 'contrastStrongLightColors': '700 800 900'
  5320. },
  5321. 'lime': {
  5322. '50': '#f9fbe7',
  5323. '100': '#f0f4c3',
  5324. '200': '#e6ee9c',
  5325. '300': '#dce775',
  5326. '400': '#d4e157',
  5327. '500': '#cddc39',
  5328. '600': '#c0ca33',
  5329. '700': '#afb42b',
  5330. '800': '#9e9d24',
  5331. '900': '#827717',
  5332. 'A100': '#f4ff81',
  5333. 'A200': '#eeff41',
  5334. 'A400': '#c6ff00',
  5335. 'A700': '#aeea00',
  5336. 'contrastDefaultColor': 'dark',
  5337. 'contrastLightColors': '900',
  5338. 'contrastStrongLightColors': '900'
  5339. },
  5340. 'yellow': {
  5341. '50': '#fffde7',
  5342. '100': '#fff9c4',
  5343. '200': '#fff59d',
  5344. '300': '#fff176',
  5345. '400': '#ffee58',
  5346. '500': '#ffeb3b',
  5347. '600': '#fdd835',
  5348. '700': '#fbc02d',
  5349. '800': '#f9a825',
  5350. '900': '#f57f17',
  5351. 'A100': '#ffff8d',
  5352. 'A200': '#ffff00',
  5353. 'A400': '#ffea00',
  5354. 'A700': '#ffd600',
  5355. 'contrastDefaultColor': 'dark'
  5356. },
  5357. 'amber': {
  5358. '50': '#fff8e1',
  5359. '100': '#ffecb3',
  5360. '200': '#ffe082',
  5361. '300': '#ffd54f',
  5362. '400': '#ffca28',
  5363. '500': '#ffc107',
  5364. '600': '#ffb300',
  5365. '700': '#ffa000',
  5366. '800': '#ff8f00',
  5367. '900': '#ff6f00',
  5368. 'A100': '#ffe57f',
  5369. 'A200': '#ffd740',
  5370. 'A400': '#ffc400',
  5371. 'A700': '#ffab00',
  5372. 'contrastDefaultColor': 'dark'
  5373. },
  5374. 'orange': {
  5375. '50': '#fff3e0',
  5376. '100': '#ffe0b2',
  5377. '200': '#ffcc80',
  5378. '300': '#ffb74d',
  5379. '400': '#ffa726',
  5380. '500': '#ff9800',
  5381. '600': '#fb8c00',
  5382. '700': '#f57c00',
  5383. '800': '#ef6c00',
  5384. '900': '#e65100',
  5385. 'A100': '#ffd180',
  5386. 'A200': '#ffab40',
  5387. 'A400': '#ff9100',
  5388. 'A700': '#ff6d00',
  5389. 'contrastDefaultColor': 'dark',
  5390. 'contrastLightColors': '800 900',
  5391. 'contrastStrongLightColors': '800 900'
  5392. },
  5393. 'deep-orange': {
  5394. '50': '#fbe9e7',
  5395. '100': '#ffccbc',
  5396. '200': '#ffab91',
  5397. '300': '#ff8a65',
  5398. '400': '#ff7043',
  5399. '500': '#ff5722',
  5400. '600': '#f4511e',
  5401. '700': '#e64a19',
  5402. '800': '#d84315',
  5403. '900': '#bf360c',
  5404. 'A100': '#ff9e80',
  5405. 'A200': '#ff6e40',
  5406. 'A400': '#ff3d00',
  5407. 'A700': '#dd2c00',
  5408. 'contrastDefaultColor': 'light',
  5409. 'contrastDarkColors': '50 100 200 300 400 A100 A200',
  5410. 'contrastStrongLightColors': '500 600 700 800 900 A400 A700'
  5411. },
  5412. 'brown': {
  5413. '50': '#efebe9',
  5414. '100': '#d7ccc8',
  5415. '200': '#bcaaa4',
  5416. '300': '#a1887f',
  5417. '400': '#8d6e63',
  5418. '500': '#795548',
  5419. '600': '#6d4c41',
  5420. '700': '#5d4037',
  5421. '800': '#4e342e',
  5422. '900': '#3e2723',
  5423. 'A100': '#d7ccc8',
  5424. 'A200': '#bcaaa4',
  5425. 'A400': '#8d6e63',
  5426. 'A700': '#5d4037',
  5427. 'contrastDefaultColor': 'light',
  5428. 'contrastDarkColors': '50 100 200 A100 A200',
  5429. 'contrastStrongLightColors': '300 400'
  5430. },
  5431. 'grey': {
  5432. '50': '#fafafa',
  5433. '100': '#f5f5f5',
  5434. '200': '#eeeeee',
  5435. '300': '#e0e0e0',
  5436. '400': '#bdbdbd',
  5437. '500': '#9e9e9e',
  5438. '600': '#757575',
  5439. '700': '#616161',
  5440. '800': '#424242',
  5441. '900': '#212121',
  5442. 'A100': '#ffffff',
  5443. 'A200': '#000000',
  5444. 'A400': '#303030',
  5445. 'A700': '#616161',
  5446. 'contrastDefaultColor': 'dark',
  5447. 'contrastLightColors': '600 700 800 900 A200 A400 A700'
  5448. },
  5449. 'blue-grey': {
  5450. '50': '#eceff1',
  5451. '100': '#cfd8dc',
  5452. '200': '#b0bec5',
  5453. '300': '#90a4ae',
  5454. '400': '#78909c',
  5455. '500': '#607d8b',
  5456. '600': '#546e7a',
  5457. '700': '#455a64',
  5458. '800': '#37474f',
  5459. '900': '#263238',
  5460. 'A100': '#cfd8dc',
  5461. 'A200': '#b0bec5',
  5462. 'A400': '#78909c',
  5463. 'A700': '#455a64',
  5464. 'contrastDefaultColor': 'light',
  5465. 'contrastDarkColors': '50 100 200 300 A100 A200',
  5466. 'contrastStrongLightColors': '400 500 700'
  5467. }
  5468. });
  5469. })();
  5470. (function(){
  5471. "use strict";
  5472. (function(angular) {
  5473. 'use strict';
  5474. /**
  5475. * @ngdoc module
  5476. * @name material.core.theming
  5477. * @description
  5478. * Theming
  5479. */
  5480. detectDisabledThemes.$inject = ["$mdThemingProvider"];
  5481. ThemingDirective.$inject = ["$mdTheming", "$interpolate", "$parse", "$mdUtil", "$q", "$log"];
  5482. ThemableDirective.$inject = ["$mdTheming"];
  5483. ThemingProvider.$inject = ["$mdColorPalette", "$$mdMetaProvider"];
  5484. generateAllThemes.$inject = ["$injector", "$mdTheming"];
  5485. angular.module('material.core.theming', ['material.core.theming.palette', 'material.core.meta'])
  5486. .directive('mdTheme', ThemingDirective)
  5487. .directive('mdThemable', ThemableDirective)
  5488. .directive('mdThemesDisabled', disableThemesDirective )
  5489. .provider('$mdTheming', ThemingProvider)
  5490. .config( detectDisabledThemes )
  5491. .run(generateAllThemes);
  5492. /**
  5493. * Detect if the HTML or the BODY tags has a [md-themes-disabled] attribute
  5494. * If yes, then immediately disable all theme stylesheet generation and DOM injection
  5495. */
  5496. /**
  5497. * @ngInject
  5498. */
  5499. function detectDisabledThemes($mdThemingProvider) {
  5500. var isDisabled = !!document.querySelector('[md-themes-disabled]');
  5501. $mdThemingProvider.disableTheming(isDisabled);
  5502. }
  5503. /**
  5504. * @ngdoc service
  5505. * @name $mdThemingProvider
  5506. * @module material.core.theming
  5507. *
  5508. * @description Provider to configure the `$mdTheming` service.
  5509. *
  5510. * ### Default Theme
  5511. * The `$mdThemingProvider` uses by default the following theme configuration:
  5512. *
  5513. * - Primary Palette: `Blue`
  5514. * - Accent Palette: `Pink`
  5515. * - Warn Palette: `Deep-Orange`
  5516. * - Background Palette: `Grey`
  5517. *
  5518. * If you don't want to use the `md-theme` directive on the elements itself, you may want to overwrite
  5519. * the default theme.<br/>
  5520. * This can be done by using the following markup.
  5521. *
  5522. * <hljs lang="js">
  5523. * myAppModule.config(function($mdThemingProvider) {
  5524. * $mdThemingProvider
  5525. * .theme('default')
  5526. * .primaryPalette('blue')
  5527. * .accentPalette('teal')
  5528. * .warnPalette('red')
  5529. * .backgroundPalette('grey');
  5530. * });
  5531. * </hljs>
  5532. *
  5533. * ### Dynamic Themes
  5534. *
  5535. * By default, if you change a theme at runtime, the `$mdTheming` service will not detect those changes.<br/>
  5536. * If you have an application, which changes its theme on runtime, you have to enable theme watching.
  5537. *
  5538. * <hljs lang="js">
  5539. * myAppModule.config(function($mdThemingProvider) {
  5540. * // Enable theme watching.
  5541. * $mdThemingProvider.alwaysWatchTheme(true);
  5542. * });
  5543. * </hljs>
  5544. *
  5545. * ### Custom Theme Styles
  5546. *
  5547. * Sometimes you may want to use your own theme styles for some custom components.<br/>
  5548. * You are able to register your own styles by using the following markup.
  5549. *
  5550. * <hljs lang="js">
  5551. * myAppModule.config(function($mdThemingProvider) {
  5552. * // Register our custom stylesheet into the theming provider.
  5553. * $mdThemingProvider.registerStyles(STYLESHEET);
  5554. * });
  5555. * </hljs>
  5556. *
  5557. * The `registerStyles` method only accepts strings as value, so you're actually not able to load an external
  5558. * stylesheet file into the `$mdThemingProvider`.
  5559. *
  5560. * If it's necessary to load an external stylesheet, we suggest using a bundler, which supports including raw content,
  5561. * like [raw-loader](https://github.com/webpack/raw-loader) for `webpack`.
  5562. *
  5563. * <hljs lang="js">
  5564. * myAppModule.config(function($mdThemingProvider) {
  5565. * // Register your custom stylesheet into the theming provider.
  5566. * $mdThemingProvider.registerStyles(require('../styles/my-component.theme.css'));
  5567. * });
  5568. * </hljs>
  5569. *
  5570. * ### Browser color
  5571. *
  5572. * Enables browser header coloring
  5573. * for more info please visit:
  5574. * https://developers.google.com/web/fundamentals/design-and-ui/browser-customization/theme-color
  5575. *
  5576. * Options parameter: <br/>
  5577. * `theme` - A defined theme via `$mdThemeProvider` to use the palettes from. Default is `default` theme. <br/>
  5578. * `palette` - Can be any one of the basic material design palettes, extended defined palettes and 'primary',
  5579. * 'accent', 'background' and 'warn'. Default is `primary`. <br/>
  5580. * `hue` - The hue from the selected palette. Default is `800`<br/>
  5581. *
  5582. * <hljs lang="js">
  5583. * myAppModule.config(function($mdThemingProvider) {
  5584. * // Enable browser color
  5585. * $mdThemingProvider.enableBrowserColor({
  5586. * theme: 'myTheme', // Default is 'default'
  5587. * palette: 'accent', // Default is 'primary', any basic material palette and extended palettes are available
  5588. * hue: '200' // Default is '800'
  5589. * });
  5590. * });
  5591. * </hljs>
  5592. */
  5593. /**
  5594. * Some Example Valid Theming Expressions
  5595. * =======================================
  5596. *
  5597. * Intention group expansion: (valid for primary, accent, warn, background)
  5598. *
  5599. * {{primary-100}} - grab shade 100 from the primary palette
  5600. * {{primary-100-0.7}} - grab shade 100, apply opacity of 0.7
  5601. * {{primary-100-contrast}} - grab shade 100's contrast color
  5602. * {{primary-hue-1}} - grab the shade assigned to hue-1 from the primary palette
  5603. * {{primary-hue-1-0.7}} - apply 0.7 opacity to primary-hue-1
  5604. * {{primary-color}} - Generates .md-hue-1, .md-hue-2, .md-hue-3 with configured shades set for each hue
  5605. * {{primary-color-0.7}} - Apply 0.7 opacity to each of the above rules
  5606. * {{primary-contrast}} - Generates .md-hue-1, .md-hue-2, .md-hue-3 with configured contrast (ie. text) color shades set for each hue
  5607. * {{primary-contrast-0.7}} - Apply 0.7 opacity to each of the above rules
  5608. *
  5609. * Foreground expansion: Applies rgba to black/white foreground text
  5610. *
  5611. * {{foreground-1}} - used for primary text
  5612. * {{foreground-2}} - used for secondary text/divider
  5613. * {{foreground-3}} - used for disabled text
  5614. * {{foreground-4}} - used for dividers
  5615. */
  5616. // In memory generated CSS rules; registered by theme.name
  5617. var GENERATED = { };
  5618. // In memory storage of defined themes and color palettes (both loaded by CSS, and user specified)
  5619. var PALETTES;
  5620. // Text Colors on light and dark backgrounds
  5621. // @see https://www.google.com/design/spec/style/color.html#color-text-background-colors
  5622. var DARK_FOREGROUND = {
  5623. name: 'dark',
  5624. '1': 'rgba(0,0,0,0.87)',
  5625. '2': 'rgba(0,0,0,0.54)',
  5626. '3': 'rgba(0,0,0,0.38)',
  5627. '4': 'rgba(0,0,0,0.12)'
  5628. };
  5629. var LIGHT_FOREGROUND = {
  5630. name: 'light',
  5631. '1': 'rgba(255,255,255,1.0)',
  5632. '2': 'rgba(255,255,255,0.7)',
  5633. '3': 'rgba(255,255,255,0.5)',
  5634. '4': 'rgba(255,255,255,0.12)'
  5635. };
  5636. var DARK_SHADOW = '1px 1px 0px rgba(0,0,0,0.4), -1px -1px 0px rgba(0,0,0,0.4)';
  5637. var LIGHT_SHADOW = '';
  5638. var DARK_CONTRAST_COLOR = colorToRgbaArray('rgba(0,0,0,0.87)');
  5639. var LIGHT_CONTRAST_COLOR = colorToRgbaArray('rgba(255,255,255,0.87)');
  5640. var STRONG_LIGHT_CONTRAST_COLOR = colorToRgbaArray('rgb(255,255,255)');
  5641. var THEME_COLOR_TYPES = ['primary', 'accent', 'warn', 'background'];
  5642. var DEFAULT_COLOR_TYPE = 'primary';
  5643. // A color in a theme will use these hues by default, if not specified by user.
  5644. var LIGHT_DEFAULT_HUES = {
  5645. 'accent': {
  5646. 'default': 'A200',
  5647. 'hue-1': 'A100',
  5648. 'hue-2': 'A400',
  5649. 'hue-3': 'A700'
  5650. },
  5651. 'background': {
  5652. 'default': '50',
  5653. 'hue-1': 'A100',
  5654. 'hue-2': '100',
  5655. 'hue-3': '300'
  5656. }
  5657. };
  5658. var DARK_DEFAULT_HUES = {
  5659. 'background': {
  5660. 'default': 'A400',
  5661. 'hue-1': '800',
  5662. 'hue-2': '900',
  5663. 'hue-3': 'A200'
  5664. }
  5665. };
  5666. THEME_COLOR_TYPES.forEach(function(colorType) {
  5667. // Color types with unspecified default hues will use these default hue values
  5668. var defaultDefaultHues = {
  5669. 'default': '500',
  5670. 'hue-1': '300',
  5671. 'hue-2': '800',
  5672. 'hue-3': 'A100'
  5673. };
  5674. if (!LIGHT_DEFAULT_HUES[colorType]) LIGHT_DEFAULT_HUES[colorType] = defaultDefaultHues;
  5675. if (!DARK_DEFAULT_HUES[colorType]) DARK_DEFAULT_HUES[colorType] = defaultDefaultHues;
  5676. });
  5677. var VALID_HUE_VALUES = [
  5678. '50', '100', '200', '300', '400', '500', '600',
  5679. '700', '800', '900', 'A100', 'A200', 'A400', 'A700'
  5680. ];
  5681. var themeConfig = {
  5682. disableTheming : false, // Generate our themes at run time; also disable stylesheet DOM injection
  5683. generateOnDemand : false, // Whether or not themes are to be generated on-demand (vs. eagerly).
  5684. registeredStyles : [], // Custom styles registered to be used in the theming of custom components.
  5685. nonce : null // Nonce to be added as an attribute to the generated themes style tags.
  5686. };
  5687. /**
  5688. *
  5689. */
  5690. function ThemingProvider($mdColorPalette, $$mdMetaProvider) {
  5691. ThemingService.$inject = ["$rootScope", "$mdUtil", "$q", "$log"];
  5692. PALETTES = { };
  5693. var THEMES = { };
  5694. var themingProvider;
  5695. var alwaysWatchTheme = false;
  5696. var defaultTheme = 'default';
  5697. // Load JS Defined Palettes
  5698. angular.extend(PALETTES, $mdColorPalette);
  5699. // Default theme defined in core.js
  5700. /**
  5701. * Adds `theme-color` and `msapplication-navbutton-color` meta tags with the color parameter
  5702. * @param {string} color Hex value of the wanted browser color
  5703. * @returns {function} Remove function of the meta tags
  5704. */
  5705. var setBrowserColor = function (color) {
  5706. // Chrome, Firefox OS and Opera
  5707. var removeChrome = $$mdMetaProvider.setMeta('theme-color', color);
  5708. // Windows Phone
  5709. var removeWindows = $$mdMetaProvider.setMeta('msapplication-navbutton-color', color);
  5710. return function () {
  5711. removeChrome();
  5712. removeWindows();
  5713. };
  5714. };
  5715. /**
  5716. * @ngdoc method
  5717. * @name $mdThemingProvider#enableBrowserColor
  5718. * @description
  5719. * Enables browser header coloring. For more info please visit
  5720. * <a href="https://developers.google.com/web/fundamentals/design-and-ui/browser-customization/theme-color">
  5721. * Web Fundamentals</a>.
  5722. * @param {object=} options Options for the browser color, which include:<br/>
  5723. * - `theme` - `{string}`: A defined theme via `$mdThemeProvider` to use the palettes from. Default is `default` theme. <br/>
  5724. * - `palette` - `{string}`: Can be any one of the basic material design palettes, extended defined palettes, or `primary`,
  5725. * `accent`, `background`, and `warn`. Default is `primary`.<br/>
  5726. * - `hue` - `{string}`: The hue from the selected palette. Default is `800`.<br/>
  5727. * @returns {function} Function that removes the browser coloring when called.
  5728. */
  5729. var enableBrowserColor = function (options) {
  5730. options = angular.isObject(options) ? options : {};
  5731. var theme = options.theme || 'default';
  5732. var hue = options.hue || '800';
  5733. var palette = PALETTES[options.palette] ||
  5734. PALETTES[THEMES[theme].colors[options.palette || 'primary'].name];
  5735. var color = angular.isObject(palette[hue]) ? palette[hue].hex : palette[hue];
  5736. return setBrowserColor(color);
  5737. };
  5738. return themingProvider = {
  5739. definePalette: definePalette,
  5740. extendPalette: extendPalette,
  5741. theme: registerTheme,
  5742. /**
  5743. * return a read-only clone of the current theme configuration
  5744. */
  5745. configuration : function() {
  5746. return angular.extend( { }, themeConfig, {
  5747. defaultTheme : defaultTheme,
  5748. alwaysWatchTheme : alwaysWatchTheme,
  5749. registeredStyles : [].concat(themeConfig.registeredStyles)
  5750. });
  5751. },
  5752. /**
  5753. * @ngdoc method
  5754. * @name $mdThemingProvider#disableTheming
  5755. * @description
  5756. * An easier way to disable theming without having to use `.constant("$MD_THEME_CSS","");`.
  5757. * This disables all dynamic theme style sheet generations and injections.
  5758. * @param {boolean=} isDisabled Disable all dynamic theme style sheet generations and injections
  5759. * if `true` or `undefined`.
  5760. */
  5761. disableTheming: function(isDisabled) {
  5762. themeConfig.disableTheming = angular.isUndefined(isDisabled) || !!isDisabled;
  5763. },
  5764. /**
  5765. * @ngdoc method
  5766. * @name $mdThemingProvider#registerStyles
  5767. * @param {string} styles The styles to be appended to AngularJS Material's built in theme CSS.
  5768. */
  5769. registerStyles: function(styles) {
  5770. themeConfig.registeredStyles.push(styles);
  5771. },
  5772. /**
  5773. * @ngdoc method
  5774. * @name $mdThemingProvider#setNonce
  5775. * @param {string} nonceValue The nonce to be added as an attribute to the theme style tags.
  5776. * Setting a value allows the use of CSP policy without using the unsafe-inline directive.
  5777. */
  5778. setNonce: function(nonceValue) {
  5779. themeConfig.nonce = nonceValue;
  5780. },
  5781. generateThemesOnDemand: function(onDemand) {
  5782. themeConfig.generateOnDemand = onDemand;
  5783. },
  5784. /**
  5785. * @ngdoc method
  5786. * @name $mdThemingProvider#setDefaultTheme
  5787. * @param {string} theme Default theme name to be applied to elements. Default value is `default`.
  5788. */
  5789. setDefaultTheme: function(theme) {
  5790. defaultTheme = theme;
  5791. },
  5792. /**
  5793. * @ngdoc method
  5794. * @name $mdThemingProvider#alwaysWatchTheme
  5795. * @param {boolean} alwaysWatch Whether or not to always watch themes for changes and re-apply
  5796. * classes when they change. Default is `false`. Enabling can reduce performance.
  5797. */
  5798. alwaysWatchTheme: function(alwaysWatch) {
  5799. alwaysWatchTheme = alwaysWatch;
  5800. },
  5801. enableBrowserColor: enableBrowserColor,
  5802. $get: ThemingService,
  5803. _LIGHT_DEFAULT_HUES: LIGHT_DEFAULT_HUES,
  5804. _DARK_DEFAULT_HUES: DARK_DEFAULT_HUES,
  5805. _PALETTES: PALETTES,
  5806. _THEMES: THEMES,
  5807. _parseRules: parseRules,
  5808. _rgba: rgba
  5809. };
  5810. /**
  5811. * @ngdoc method
  5812. * @name $mdThemingProvider#definePalette
  5813. * @description
  5814. * In the event that you need to define a custom color palette, you can use this function to
  5815. * make it available to your theme for use in its intention groups.<br>
  5816. * Note that you must specify all hues in the definition map.
  5817. * @param {string} name Name of palette being defined
  5818. * @param {object} map Palette definition that includes hue definitions and contrast colors:
  5819. * - `'50'` - `{string}`: HEX color
  5820. * - `'100'` - `{string}`: HEX color
  5821. * - `'200'` - `{string}`: HEX color
  5822. * - `'300'` - `{string}`: HEX color
  5823. * - `'400'` - `{string}`: HEX color
  5824. * - `'500'` - `{string}`: HEX color
  5825. * - `'600'` - `{string}`: HEX color
  5826. * - `'700'` - `{string}`: HEX color
  5827. * - `'800'` - `{string}`: HEX color
  5828. * - `'900'` - `{string}`: HEX color
  5829. * - `'A100'` - `{string}`: HEX color
  5830. * - `'A200'` - `{string}`: HEX color
  5831. * - `'A400'` - `{string}`: HEX color
  5832. * - `'A700'` - `{string}`: HEX color
  5833. * - `'contrastDefaultColor'` - `{string}`: `light` or `dark`
  5834. * - `'contrastDarkColors'` - `{string[]}`: Hues which should use dark contrast colors (i.e. raised button text).
  5835. * For example: `['50', '100', '200', '300', '400', 'A100']`.
  5836. * - `'contrastLightColors'` - `{string[]}`: Hues which should use light contrast colors (i.e. raised button text).
  5837. * For example: `['500', '600', '700', '800', '900', 'A200', 'A400', 'A700']`.
  5838. */
  5839. function definePalette(name, map) {
  5840. map = map || {};
  5841. PALETTES[name] = checkPaletteValid(name, map);
  5842. return themingProvider;
  5843. }
  5844. /**
  5845. * @ngdoc method
  5846. * @name $mdThemingProvider#extendPalette
  5847. * @description
  5848. * Sometimes it is easier to extend an existing color palette and then change a few properties,
  5849. * rather than defining a whole new palette.
  5850. * @param {string} name Name of palette being extended
  5851. * @param {object} map Palette definition that includes optional hue definitions and contrast colors:
  5852. * - `'50'` - `{string}`: HEX color
  5853. * - `'100'` - `{string}`: HEX color
  5854. * - `'200'` - `{string}`: HEX color
  5855. * - `'300'` - `{string}`: HEX color
  5856. * - `'400'` - `{string}`: HEX color
  5857. * - `'500'` - `{string}`: HEX color
  5858. * - `'600'` - `{string}`: HEX color
  5859. * - `'700'` - `{string}`: HEX color
  5860. * - `'800'` - `{string}`: HEX color
  5861. * - `'900'` - `{string}`: HEX color
  5862. * - `'A100'` - `{string}`: HEX color
  5863. * - `'A200'` - `{string}`: HEX color
  5864. * - `'A400'` - `{string}`: HEX color
  5865. * - `'A700'` - `{string}`: HEX color
  5866. * - `'contrastDefaultColor'` - `{string}`: `light` or `dark`
  5867. * - `'contrastDarkColors'` - `{string[]}`: Hues which should use dark contrast colors (i.e. raised button text).
  5868. * For example: `['50', '100', '200', '300', '400', 'A100']`.
  5869. * - `'contrastLightColors'` - `{string[]}`: Hues which should use light contrast colors (i.e. raised button text).
  5870. * For example: `['500', '600', '700', '800', '900', 'A200', 'A400', 'A700']`.
  5871. * @returns {object} A new object which is a copy of the given palette, `name`,
  5872. * with variables from `map` overwritten.
  5873. */
  5874. function extendPalette(name, map) {
  5875. return checkPaletteValid(name, angular.extend({}, PALETTES[name] || {}, map) );
  5876. }
  5877. // Make sure that palette has all required hues
  5878. function checkPaletteValid(name, map) {
  5879. var missingColors = VALID_HUE_VALUES.filter(function(field) {
  5880. return !map[field];
  5881. });
  5882. if (missingColors.length) {
  5883. throw new Error("Missing colors %1 in palette %2!"
  5884. .replace('%1', missingColors.join(', '))
  5885. .replace('%2', name));
  5886. }
  5887. return map;
  5888. }
  5889. /**
  5890. * @ngdoc method
  5891. * @name $mdThemingProvider#theme
  5892. * @description
  5893. * Register a theme (which is a collection of color palettes); i.e. `warn`, `accent`,
  5894. * `background`, and `primary`.<br>
  5895. * Optionally inherit from an existing theme.
  5896. * @param {string} name Name of theme being registered
  5897. * @param {string=} inheritFrom Existing theme name to inherit from
  5898. */
  5899. function registerTheme(name, inheritFrom) {
  5900. if (THEMES[name]) return THEMES[name];
  5901. inheritFrom = inheritFrom || 'default';
  5902. var parentTheme = typeof inheritFrom === 'string' ? THEMES[inheritFrom] : inheritFrom;
  5903. var theme = new Theme(name);
  5904. if (parentTheme) {
  5905. angular.forEach(parentTheme.colors, function(color, colorType) {
  5906. theme.colors[colorType] = {
  5907. name: color.name,
  5908. // Make sure a COPY of the hues is given to the child color,
  5909. // not the same reference.
  5910. hues: angular.extend({}, color.hues)
  5911. };
  5912. });
  5913. }
  5914. THEMES[name] = theme;
  5915. return theme;
  5916. }
  5917. function Theme(name) {
  5918. var self = this;
  5919. self.name = name;
  5920. self.colors = {};
  5921. self.dark = setDark;
  5922. setDark(false);
  5923. function setDark(isDark) {
  5924. isDark = arguments.length === 0 ? true : !!isDark;
  5925. // If no change, abort
  5926. if (isDark === self.isDark) return;
  5927. self.isDark = isDark;
  5928. self.foregroundPalette = self.isDark ? LIGHT_FOREGROUND : DARK_FOREGROUND;
  5929. self.foregroundShadow = self.isDark ? DARK_SHADOW : LIGHT_SHADOW;
  5930. // Light and dark themes have different default hues.
  5931. // Go through each existing color type for this theme, and for every
  5932. // hue value that is still the default hue value from the previous light/dark setting,
  5933. // set it to the default hue value from the new light/dark setting.
  5934. var newDefaultHues = self.isDark ? DARK_DEFAULT_HUES : LIGHT_DEFAULT_HUES;
  5935. var oldDefaultHues = self.isDark ? LIGHT_DEFAULT_HUES : DARK_DEFAULT_HUES;
  5936. angular.forEach(newDefaultHues, function(newDefaults, colorType) {
  5937. var color = self.colors[colorType];
  5938. var oldDefaults = oldDefaultHues[colorType];
  5939. if (color) {
  5940. for (var hueName in color.hues) {
  5941. if (color.hues[hueName] === oldDefaults[hueName]) {
  5942. color.hues[hueName] = newDefaults[hueName];
  5943. }
  5944. }
  5945. }
  5946. });
  5947. return self;
  5948. }
  5949. THEME_COLOR_TYPES.forEach(function(colorType) {
  5950. var defaultHues = (self.isDark ? DARK_DEFAULT_HUES : LIGHT_DEFAULT_HUES)[colorType];
  5951. self[colorType + 'Palette'] = function setPaletteType(paletteName, hues) {
  5952. var color = self.colors[colorType] = {
  5953. name: paletteName,
  5954. hues: angular.extend({}, defaultHues, hues)
  5955. };
  5956. Object.keys(color.hues).forEach(function(name) {
  5957. if (!defaultHues[name]) {
  5958. throw new Error("Invalid hue name '%1' in theme %2's %3 color %4. Available hue names: %4"
  5959. .replace('%1', name)
  5960. .replace('%2', self.name)
  5961. .replace('%3', paletteName)
  5962. .replace('%4', Object.keys(defaultHues).join(', '))
  5963. );
  5964. }
  5965. });
  5966. Object.keys(color.hues).map(function(key) {
  5967. return color.hues[key];
  5968. }).forEach(function(hueValue) {
  5969. if (VALID_HUE_VALUES.indexOf(hueValue) == -1) {
  5970. throw new Error("Invalid hue value '%1' in theme %2's %3 color %4. Available hue values: %5"
  5971. .replace('%1', hueValue)
  5972. .replace('%2', self.name)
  5973. .replace('%3', colorType)
  5974. .replace('%4', paletteName)
  5975. .replace('%5', VALID_HUE_VALUES.join(', '))
  5976. );
  5977. }
  5978. });
  5979. return self;
  5980. };
  5981. self[colorType + 'Color'] = function() {
  5982. var args = Array.prototype.slice.call(arguments);
  5983. // eslint-disable-next-line no-console
  5984. console.warn('$mdThemingProviderTheme.' + colorType + 'Color() has been deprecated. ' +
  5985. 'Use $mdThemingProviderTheme.' + colorType + 'Palette() instead.');
  5986. return self[colorType + 'Palette'].apply(self, args);
  5987. };
  5988. });
  5989. }
  5990. /**
  5991. * @ngdoc service
  5992. * @name $mdTheming
  5993. * @module material.core.theming
  5994. * @description
  5995. * Service that makes an element apply theming related <b>classes</b> to itself.
  5996. *
  5997. * <hljs lang="js">
  5998. * // Example component directive that we want to apply theming classes to.
  5999. * app.directive('myFancyDirective', function($mdTheming) {
  6000. * return {
  6001. * restrict: 'AE',
  6002. * link: function(scope, element, attrs) {
  6003. * // Initialize the service using our directive's element
  6004. * $mdTheming(element);
  6005. *
  6006. * $mdTheming.defineTheme('myTheme', {
  6007. * primary: 'blue',
  6008. * accent: 'pink',
  6009. * dark: true
  6010. * });
  6011. * // Your directive's custom code here.
  6012. * }
  6013. * };
  6014. * });
  6015. * </hljs>
  6016. * @param {element=} element Element that will have theming classes applied to it.
  6017. */
  6018. /**
  6019. * @ngdoc property
  6020. * @name $mdTheming#THEMES
  6021. * @description
  6022. * Property to get all the themes defined
  6023. * @returns {object} All the themes defined with their properties.
  6024. */
  6025. /**
  6026. * @ngdoc property
  6027. * @name $mdTheming#PALETTES
  6028. * @description
  6029. * Property to get all the palettes defined
  6030. * @returns {object} All the palettes defined with their colors.
  6031. */
  6032. /**
  6033. * @ngdoc method
  6034. * @name $mdTheming#registered
  6035. * @description
  6036. * Determine is specified theme name is a valid, registered theme
  6037. * @param {string} themeName the theme to check if registered
  6038. * @returns {boolean} whether the theme is registered or not
  6039. */
  6040. /**
  6041. * @ngdoc method
  6042. * @name $mdTheming#defaultTheme
  6043. * @description
  6044. * Returns the default theme
  6045. * @returns {string} The default theme
  6046. */
  6047. /**
  6048. * @ngdoc method
  6049. * @name $mdTheming#generateTheme
  6050. * @description
  6051. * Lazy generate themes - by default, every theme is generated when defined.
  6052. * You can disable this in the configuration section using the
  6053. * `$mdThemingProvider.generateThemesOnDemand(true);`
  6054. *
  6055. * The theme name that is passed in must match the name of the theme that was defined as part of the configuration block.
  6056. *
  6057. * @param name {string} theme name to generate
  6058. */
  6059. /**
  6060. * @ngdoc method
  6061. * @name $mdTheming#setBrowserColor
  6062. * @description
  6063. * Enables browser header coloring. For more info please visit
  6064. * <a href="https://developers.google.com/web/fundamentals/design-and-ui/browser-customization/theme-color">
  6065. * Web Fundamentals</a>.
  6066. * @param {object=} options Options for the browser color, which include:<br/>
  6067. * - `theme` - `{string}`: A defined theme via `$mdThemeProvider` to use the palettes from. Default is `default` theme. <br/>
  6068. * - `palette` - `{string}`: Can be any one of the basic material design palettes, extended defined palettes, or `primary`,
  6069. * `accent`, `background`, and `warn`. Default is `primary`.<br/>
  6070. * - `hue` - `{string}`: The hue from the selected palette. Default is `800`.<br/>
  6071. * @returns {function} Function that removes the browser coloring when called.
  6072. */
  6073. /**
  6074. * @ngdoc method
  6075. * @name $mdTheming#defineTheme
  6076. * @description
  6077. * Dynamically define a theme by using an options object that contains palette names.
  6078. *
  6079. * @param {string} name Theme name to define
  6080. * @param {object} options Theme definition options
  6081. * Options are:<br/>
  6082. * - `primary` - `{string}`: The name of the primary palette to use in the theme.<br/>
  6083. * - `accent` - `{string}`: The name of the accent palette to use in the theme.<br/>
  6084. * - `warn` - `{string}`: The name of the warn palette to use in the theme.<br/>
  6085. * - `background` - `{string}`: The name of the background palette to use in the theme.<br/>
  6086. * - `dark` - `{boolean}`: Indicates if it's a dark theme.<br/>
  6087. * @returns {Promise<string>} A resolved promise with the new theme name.
  6088. */
  6089. /* @ngInject */
  6090. function ThemingService($rootScope, $mdUtil, $q, $log) {
  6091. // Allow us to be invoked via a linking function signature.
  6092. var applyTheme = function (scope, el) {
  6093. if (el === undefined) { el = scope; scope = undefined; }
  6094. if (scope === undefined) { scope = $rootScope; }
  6095. applyTheme.inherit(el, el);
  6096. };
  6097. Object.defineProperty(applyTheme, 'THEMES', {
  6098. get: function () {
  6099. return angular.extend({}, THEMES);
  6100. }
  6101. });
  6102. Object.defineProperty(applyTheme, 'PALETTES', {
  6103. get: function () {
  6104. return angular.extend({}, PALETTES);
  6105. }
  6106. });
  6107. Object.defineProperty(applyTheme, 'ALWAYS_WATCH', {
  6108. get: function () {
  6109. return alwaysWatchTheme;
  6110. }
  6111. });
  6112. applyTheme.inherit = inheritTheme;
  6113. applyTheme.registered = registered;
  6114. applyTheme.defaultTheme = function() { return defaultTheme; };
  6115. applyTheme.generateTheme = function(name) { generateTheme(THEMES[name], name, themeConfig.nonce); };
  6116. applyTheme.defineTheme = function(name, options) {
  6117. options = options || {};
  6118. var theme = registerTheme(name);
  6119. if (options.primary) {
  6120. theme.primaryPalette(options.primary);
  6121. }
  6122. if (options.accent) {
  6123. theme.accentPalette(options.accent);
  6124. }
  6125. if (options.warn) {
  6126. theme.warnPalette(options.warn);
  6127. }
  6128. if (options.background) {
  6129. theme.backgroundPalette(options.background);
  6130. }
  6131. if (options.dark){
  6132. theme.dark();
  6133. }
  6134. this.generateTheme(name);
  6135. return $q.resolve(name);
  6136. };
  6137. applyTheme.setBrowserColor = enableBrowserColor;
  6138. return applyTheme;
  6139. /**
  6140. * Determine is specified theme name is a valid, registered theme
  6141. */
  6142. function registered(themeName) {
  6143. if (themeName === undefined || themeName === '') return true;
  6144. return applyTheme.THEMES[themeName] !== undefined;
  6145. }
  6146. /**
  6147. * Get theme name for the element, then update with Theme CSS class
  6148. */
  6149. function inheritTheme (el, parent) {
  6150. var ctrl = parent.controller('mdTheme') || el.data('$mdThemeController');
  6151. updateThemeClass(lookupThemeName());
  6152. if (ctrl) {
  6153. var watchTheme = alwaysWatchTheme ||
  6154. ctrl.$shouldWatch ||
  6155. $mdUtil.parseAttributeBoolean(el.attr('md-theme-watch'));
  6156. var unwatch = ctrl.registerChanges(function (name) {
  6157. updateThemeClass(name);
  6158. if (!watchTheme) {
  6159. unwatch();
  6160. }
  6161. else {
  6162. el.on('$destroy', unwatch);
  6163. }
  6164. });
  6165. }
  6166. /**
  6167. * Find the theme name from the parent controller or element data
  6168. */
  6169. function lookupThemeName() {
  6170. // As a few components (dialog) add their controllers later, we should also watch for a controller init.
  6171. return ctrl && ctrl.$mdTheme || (defaultTheme == 'default' ? '' : defaultTheme);
  6172. }
  6173. /**
  6174. * Remove old theme class and apply a new one
  6175. * NOTE: if not a valid theme name, then the current name is not changed
  6176. */
  6177. function updateThemeClass(theme) {
  6178. if (!theme) return;
  6179. if (!registered(theme)) {
  6180. $log.warn('Attempted to use unregistered theme \'' + theme + '\'. ' +
  6181. 'Register it with $mdThemingProvider.theme().');
  6182. }
  6183. var oldTheme = el.data('$mdThemeName');
  6184. if (oldTheme) el.removeClass('md-' + oldTheme +'-theme');
  6185. el.addClass('md-' + theme + '-theme');
  6186. el.data('$mdThemeName', theme);
  6187. if (ctrl) {
  6188. el.data('$mdThemeController', ctrl);
  6189. }
  6190. }
  6191. }
  6192. }
  6193. }
  6194. function ThemingDirective($mdTheming, $interpolate, $parse, $mdUtil, $q, $log) {
  6195. return {
  6196. priority: 101, // has to be more than 100 to be before interpolation (issue on IE)
  6197. link: {
  6198. pre: function(scope, el, attrs) {
  6199. var registeredCallbacks = [];
  6200. var startSymbol = $interpolate.startSymbol();
  6201. var endSymbol = $interpolate.endSymbol();
  6202. var theme = attrs.mdTheme.trim();
  6203. var hasInterpolation =
  6204. theme.substr(0, startSymbol.length) === startSymbol &&
  6205. theme.lastIndexOf(endSymbol) === theme.length - endSymbol.length;
  6206. var oneTimeOperator = '::';
  6207. var oneTimeBind = attrs.mdTheme
  6208. .split(startSymbol).join('')
  6209. .split(endSymbol).join('')
  6210. .trim()
  6211. .substr(0, oneTimeOperator.length) === oneTimeOperator;
  6212. var ctrl = {
  6213. registerChanges: function (cb, context) {
  6214. if (context) {
  6215. cb = angular.bind(context, cb);
  6216. }
  6217. registeredCallbacks.push(cb);
  6218. return function () {
  6219. var index = registeredCallbacks.indexOf(cb);
  6220. if (index > -1) {
  6221. registeredCallbacks.splice(index, 1);
  6222. }
  6223. };
  6224. },
  6225. $setTheme: function (theme) {
  6226. if (!$mdTheming.registered(theme)) {
  6227. $log.warn('attempted to use unregistered theme \'' + theme + '\'');
  6228. }
  6229. ctrl.$mdTheme = theme;
  6230. // Iterating backwards to support unregistering during iteration
  6231. // http://stackoverflow.com/a/9882349/890293
  6232. // we don't use `reverse()` of array because it mutates the array and we don't want it to get re-indexed
  6233. for (var i = registeredCallbacks.length; i--;) {
  6234. registeredCallbacks[i](theme);
  6235. }
  6236. },
  6237. $shouldWatch: $mdUtil.parseAttributeBoolean(el.attr('md-theme-watch')) ||
  6238. $mdTheming.ALWAYS_WATCH ||
  6239. (hasInterpolation && !oneTimeBind)
  6240. };
  6241. el.data('$mdThemeController', ctrl);
  6242. var getTheme = function () {
  6243. var interpolation = $interpolate(attrs.mdTheme)(scope);
  6244. return $parse(interpolation)(scope) || interpolation;
  6245. };
  6246. var setParsedTheme = function (theme) {
  6247. if (typeof theme === 'string') {
  6248. return ctrl.$setTheme(theme);
  6249. }
  6250. $q.when( angular.isFunction(theme) ? theme() : theme )
  6251. .then(function(name){
  6252. ctrl.$setTheme(name);
  6253. });
  6254. };
  6255. setParsedTheme(getTheme());
  6256. var unwatch = scope.$watch(getTheme, function(theme) {
  6257. if (theme) {
  6258. setParsedTheme(theme);
  6259. if (!ctrl.$shouldWatch) {
  6260. unwatch();
  6261. }
  6262. }
  6263. });
  6264. }
  6265. }
  6266. };
  6267. }
  6268. /**
  6269. * Special directive that will disable ALL runtime Theme style generation and DOM injection
  6270. *
  6271. * <link rel="stylesheet" href="angular-material.min.css">
  6272. * <link rel="stylesheet" href="angular-material.themes.css">
  6273. *
  6274. * <body md-themes-disabled>
  6275. * ...
  6276. * </body>
  6277. *
  6278. * Note: Using md-themes-css directive requires the developer to load external
  6279. * theme stylesheets; e.g. custom themes from Material-Tools:
  6280. *
  6281. * `angular-material.themes.css`
  6282. *
  6283. * Another option is to use the ThemingProvider to configure and disable the attribute
  6284. * conversions; this would obviate the use of the `md-themes-css` directive
  6285. *
  6286. */
  6287. function disableThemesDirective() {
  6288. themeConfig.disableTheming = true;
  6289. // Return a 1x-only, first-match attribute directive
  6290. return {
  6291. restrict : 'A',
  6292. priority : '900'
  6293. };
  6294. }
  6295. function ThemableDirective($mdTheming) {
  6296. return $mdTheming;
  6297. }
  6298. function parseRules(theme, colorType, rules) {
  6299. checkValidPalette(theme, colorType);
  6300. rules = rules.replace(/THEME_NAME/g, theme.name);
  6301. var themeNameRegex = new RegExp('\\.md-' + theme.name + '-theme', 'g');
  6302. var simpleVariableRegex = /'?"?\{\{\s*([a-zA-Z]+)-(A?\d+|hue-[0-3]|shadow|default)-?(\d\.?\d*)?(contrast)?\s*\}\}'?"?/g;
  6303. // find and replace simple variables where we use a specific hue, not an entire palette
  6304. // eg. "{{primary-100}}"
  6305. //\(' + THEME_COLOR_TYPES.join('\|') + '\)'
  6306. rules = rules.replace(simpleVariableRegex, function(match, colorType, hue, opacity, contrast) {
  6307. if (colorType === 'foreground') {
  6308. if (hue == 'shadow') {
  6309. return theme.foregroundShadow;
  6310. } else {
  6311. return theme.foregroundPalette[hue] || theme.foregroundPalette['1'];
  6312. }
  6313. }
  6314. // `default` is also accepted as a hue-value, because the background palettes are
  6315. // using it as a name for the default hue.
  6316. if (hue.indexOf('hue') === 0 || hue === 'default') {
  6317. hue = theme.colors[colorType].hues[hue];
  6318. }
  6319. return rgba( (PALETTES[ theme.colors[colorType].name ][hue] || '')[contrast ? 'contrast' : 'value'], opacity );
  6320. });
  6321. // Matches '{{ primary-color }}', etc
  6322. var hueRegex = new RegExp('(\'|")?{{\\s*([a-zA-Z]+)-(color|contrast)-?(\\d\\.?\\d*)?\\s*}}("|\')?','g');
  6323. var generatedRules = [];
  6324. // For each type, generate rules for each hue (ie. default, md-hue-1, md-hue-2, md-hue-3)
  6325. angular.forEach(['default', 'hue-1', 'hue-2', 'hue-3'], function(hueName) {
  6326. var newRule = rules
  6327. .replace(hueRegex, function(match, _, matchedColorType, hueType, opacity) {
  6328. var color = theme.colors[matchedColorType];
  6329. var palette = PALETTES[color.name];
  6330. var hueValue = color.hues[hueName];
  6331. return rgba(palette[hueValue][hueType === 'color' ? 'value' : 'contrast'], opacity);
  6332. });
  6333. if (hueName !== 'default') {
  6334. newRule = newRule.replace(themeNameRegex, '.md-' + theme.name + '-theme.md-' + hueName);
  6335. }
  6336. // Don't apply a selector rule to the default theme, making it easier to override
  6337. // styles of the base-component
  6338. if (theme.name == 'default') {
  6339. var themeRuleRegex = /((?:\s|>|\.|\w|-|:|\(|\)|\[|\]|"|'|=)*)\.md-default-theme((?:\s|>|\.|\w|-|:|\(|\)|\[|\]|"|'|=)*)/g;
  6340. newRule = newRule.replace(themeRuleRegex, function(match, start, end) {
  6341. return match + ', ' + start + end;
  6342. });
  6343. }
  6344. generatedRules.push(newRule);
  6345. });
  6346. return generatedRules;
  6347. }
  6348. var rulesByType = {};
  6349. // Generate our themes at run time given the state of THEMES and PALETTES
  6350. function generateAllThemes($injector, $mdTheming) {
  6351. var head = document.head;
  6352. var firstChild = head ? head.firstElementChild : null;
  6353. var themeCss = !themeConfig.disableTheming && $injector.has('$MD_THEME_CSS') ? $injector.get('$MD_THEME_CSS') : '';
  6354. // Append our custom registered styles to the theme stylesheet.
  6355. themeCss += themeConfig.registeredStyles.join('');
  6356. if ( !firstChild ) return;
  6357. if (themeCss.length === 0) return; // no rules, so no point in running this expensive task
  6358. // Expose contrast colors for palettes to ensure that text is always readable
  6359. angular.forEach(PALETTES, sanitizePalette);
  6360. // MD_THEME_CSS is a string generated by the build process that includes all the themable
  6361. // components as templates
  6362. // Break the CSS into individual rules
  6363. var rules = themeCss
  6364. .split(/\}(?!(\}|'|"|;))/)
  6365. .filter(function(rule) { return rule && rule.trim().length; })
  6366. .map(function(rule) { return rule.trim() + '}'; });
  6367. THEME_COLOR_TYPES.forEach(function(type) {
  6368. rulesByType[type] = '';
  6369. });
  6370. // Sort the rules based on type, allowing us to do color substitution on a per-type basis
  6371. rules.forEach(function(rule) {
  6372. // First: test that if the rule has '.md-accent', it goes into the accent set of rules
  6373. for (var i = 0, type; type = THEME_COLOR_TYPES[i]; i++) {
  6374. if (rule.indexOf('.md-' + type) > -1) {
  6375. return rulesByType[type] += rule;
  6376. }
  6377. }
  6378. // If no eg 'md-accent' class is found, try to just find 'accent' in the rule and guess from
  6379. // there
  6380. for (i = 0; type = THEME_COLOR_TYPES[i]; i++) {
  6381. if (rule.indexOf(type) > -1) {
  6382. return rulesByType[type] += rule;
  6383. }
  6384. }
  6385. // Default to the primary array
  6386. return rulesByType[DEFAULT_COLOR_TYPE] += rule;
  6387. });
  6388. // If themes are being generated on-demand, quit here. The user will later manually
  6389. // call generateTheme to do this on a theme-by-theme basis.
  6390. if (themeConfig.generateOnDemand) return;
  6391. angular.forEach($mdTheming.THEMES, function(theme) {
  6392. if (!GENERATED[theme.name] && !($mdTheming.defaultTheme() !== 'default' && theme.name === 'default')) {
  6393. generateTheme(theme, theme.name, themeConfig.nonce);
  6394. }
  6395. });
  6396. // *************************
  6397. // Internal functions
  6398. // *************************
  6399. // The user specifies a 'default' contrast color as either light or dark,
  6400. // then explicitly lists which hues are the opposite contrast (eg. A100 has dark, A200 has light)
  6401. function sanitizePalette(palette, name) {
  6402. var defaultContrast = palette.contrastDefaultColor;
  6403. var lightColors = palette.contrastLightColors || [];
  6404. var strongLightColors = palette.contrastStrongLightColors || [];
  6405. var darkColors = palette.contrastDarkColors || [];
  6406. // These colors are provided as space-separated lists
  6407. if (typeof lightColors === 'string') lightColors = lightColors.split(' ');
  6408. if (typeof strongLightColors === 'string') strongLightColors = strongLightColors.split(' ');
  6409. if (typeof darkColors === 'string') darkColors = darkColors.split(' ');
  6410. // Cleanup after ourselves
  6411. delete palette.contrastDefaultColor;
  6412. delete palette.contrastLightColors;
  6413. delete palette.contrastStrongLightColors;
  6414. delete palette.contrastDarkColors;
  6415. // Change { 'A100': '#fffeee' } to { 'A100': { value: '#fffeee', contrast:DARK_CONTRAST_COLOR }
  6416. angular.forEach(palette, function(hueValue, hueName) {
  6417. if (angular.isObject(hueValue)) return; // Already converted
  6418. // Map everything to rgb colors
  6419. var rgbValue = colorToRgbaArray(hueValue);
  6420. if (!rgbValue) {
  6421. throw new Error("Color %1, in palette %2's hue %3, is invalid. Hex or rgb(a) color expected."
  6422. .replace('%1', hueValue)
  6423. .replace('%2', palette.name)
  6424. .replace('%3', hueName));
  6425. }
  6426. palette[hueName] = {
  6427. hex: palette[hueName],
  6428. value: rgbValue,
  6429. contrast: getContrastColor()
  6430. };
  6431. function getContrastColor() {
  6432. if (defaultContrast === 'light') {
  6433. if (darkColors.indexOf(hueName) > -1) {
  6434. return DARK_CONTRAST_COLOR;
  6435. } else {
  6436. return strongLightColors.indexOf(hueName) > -1 ? STRONG_LIGHT_CONTRAST_COLOR
  6437. : LIGHT_CONTRAST_COLOR;
  6438. }
  6439. } else {
  6440. if (lightColors.indexOf(hueName) > -1) {
  6441. return strongLightColors.indexOf(hueName) > -1 ? STRONG_LIGHT_CONTRAST_COLOR
  6442. : LIGHT_CONTRAST_COLOR;
  6443. } else {
  6444. return DARK_CONTRAST_COLOR;
  6445. }
  6446. }
  6447. }
  6448. });
  6449. }
  6450. }
  6451. function generateTheme(theme, name, nonce) {
  6452. var head = document.head;
  6453. var firstChild = head ? head.firstElementChild : null;
  6454. if (!GENERATED[name]) {
  6455. // For each theme, use the color palettes specified for
  6456. // `primary`, `warn` and `accent` to generate CSS rules.
  6457. THEME_COLOR_TYPES.forEach(function(colorType) {
  6458. var styleStrings = parseRules(theme, colorType, rulesByType[colorType]);
  6459. while (styleStrings.length) {
  6460. var styleContent = styleStrings.shift();
  6461. if (styleContent) {
  6462. var style = document.createElement('style');
  6463. style.setAttribute('md-theme-style', '');
  6464. if (nonce) {
  6465. style.setAttribute('nonce', nonce);
  6466. }
  6467. style.appendChild(document.createTextNode(styleContent));
  6468. head.insertBefore(style, firstChild);
  6469. }
  6470. }
  6471. });
  6472. GENERATED[theme.name] = true;
  6473. }
  6474. }
  6475. function checkValidPalette(theme, colorType) {
  6476. // If theme attempts to use a palette that doesnt exist, throw error
  6477. if (!PALETTES[ (theme.colors[colorType] || {}).name ]) {
  6478. throw new Error(
  6479. "You supplied an invalid color palette for theme %1's %2 palette. Available palettes: %3"
  6480. .replace('%1', theme.name)
  6481. .replace('%2', colorType)
  6482. .replace('%3', Object.keys(PALETTES).join(', '))
  6483. );
  6484. }
  6485. }
  6486. function colorToRgbaArray(clr) {
  6487. if (angular.isArray(clr) && clr.length == 3) return clr;
  6488. if (/^rgb/.test(clr)) {
  6489. return clr.replace(/(^\s*rgba?\(|\)\s*$)/g, '').split(',').map(function(value, i) {
  6490. return i == 3 ? parseFloat(value, 10) : parseInt(value, 10);
  6491. });
  6492. }
  6493. if (clr.charAt(0) == '#') clr = clr.substring(1);
  6494. if (!/^([a-fA-F0-9]{3}){1,2}$/g.test(clr)) return;
  6495. var dig = clr.length / 3;
  6496. var red = clr.substr(0, dig);
  6497. var grn = clr.substr(dig, dig);
  6498. var blu = clr.substr(dig * 2);
  6499. if (dig === 1) {
  6500. red += red;
  6501. grn += grn;
  6502. blu += blu;
  6503. }
  6504. return [parseInt(red, 16), parseInt(grn, 16), parseInt(blu, 16)];
  6505. }
  6506. function rgba(rgbArray, opacity) {
  6507. if ( !rgbArray ) return "rgb('0,0,0')";
  6508. if (rgbArray.length == 4) {
  6509. rgbArray = angular.copy(rgbArray);
  6510. opacity ? rgbArray.pop() : opacity = rgbArray.pop();
  6511. }
  6512. return opacity && (typeof opacity == 'number' || (typeof opacity == 'string' && opacity.length)) ?
  6513. 'rgba(' + rgbArray.join(',') + ',' + opacity + ')' :
  6514. 'rgb(' + rgbArray.join(',') + ')';
  6515. }
  6516. })(window.angular);
  6517. })();
  6518. (function(){
  6519. "use strict";
  6520. // Polyfill angular < 1.4 (provide $animateCss)
  6521. angular
  6522. .module('material.core')
  6523. .factory('$$mdAnimate', ["$q", "$timeout", "$mdConstant", "$animateCss", function($q, $timeout, $mdConstant, $animateCss){
  6524. // Since $$mdAnimate is injected into $mdUtil... use a wrapper function
  6525. // to subsequently inject $mdUtil as an argument to the AnimateDomUtils
  6526. return function($mdUtil) {
  6527. return AnimateDomUtils( $mdUtil, $q, $timeout, $mdConstant, $animateCss);
  6528. };
  6529. }]);
  6530. /**
  6531. * Factory function that requires special injections
  6532. */
  6533. function AnimateDomUtils($mdUtil, $q, $timeout, $mdConstant, $animateCss) {
  6534. var self;
  6535. return self = {
  6536. /**
  6537. *
  6538. */
  6539. translate3d : function( target, from, to, options ) {
  6540. return $animateCss(target, {
  6541. from: from,
  6542. to: to,
  6543. addClass: options.transitionInClass,
  6544. removeClass: options.transitionOutClass,
  6545. duration: options.duration
  6546. })
  6547. .start()
  6548. .then(function(){
  6549. // Resolve with reverser function...
  6550. return reverseTranslate;
  6551. });
  6552. /**
  6553. * Specific reversal of the request translate animation above...
  6554. */
  6555. function reverseTranslate (newFrom) {
  6556. return $animateCss(target, {
  6557. to: newFrom || from,
  6558. addClass: options.transitionOutClass,
  6559. removeClass: options.transitionInClass,
  6560. duration: options.duration
  6561. }).start();
  6562. }
  6563. },
  6564. /**
  6565. * Listen for transitionEnd event (with optional timeout)
  6566. * Announce completion or failure via promise handlers
  6567. */
  6568. waitTransitionEnd: function (element, opts) {
  6569. var TIMEOUT = 3000; // fallback is 3 secs
  6570. return $q(function(resolve, reject){
  6571. opts = opts || { };
  6572. // If there is no transition is found, resolve immediately
  6573. //
  6574. // NOTE: using $mdUtil.nextTick() causes delays/issues
  6575. if (noTransitionFound(opts.cachedTransitionStyles)) {
  6576. TIMEOUT = 0;
  6577. }
  6578. var timer = $timeout(finished, opts.timeout || TIMEOUT);
  6579. element.on($mdConstant.CSS.TRANSITIONEND, finished);
  6580. /**
  6581. * Upon timeout or transitionEnd, reject or resolve (respectively) this promise.
  6582. * NOTE: Make sure this transitionEnd didn't bubble up from a child
  6583. */
  6584. function finished(ev) {
  6585. if ( ev && ev.target !== element[0]) return;
  6586. if ( ev ) $timeout.cancel(timer);
  6587. element.off($mdConstant.CSS.TRANSITIONEND, finished);
  6588. // Never reject since ngAnimate may cause timeouts due missed transitionEnd events
  6589. resolve();
  6590. }
  6591. /**
  6592. * Checks whether or not there is a transition.
  6593. *
  6594. * @param styles The cached styles to use for the calculation. If null, getComputedStyle()
  6595. * will be used.
  6596. *
  6597. * @returns {boolean} True if there is no transition/duration; false otherwise.
  6598. */
  6599. function noTransitionFound(styles) {
  6600. styles = styles || window.getComputedStyle(element[0]);
  6601. return styles.transitionDuration == '0s' || (!styles.transition && !styles.transitionProperty);
  6602. }
  6603. });
  6604. },
  6605. calculateTransformValues: function (element, originator) {
  6606. var origin = originator.element;
  6607. var bounds = originator.bounds;
  6608. if (origin || bounds) {
  6609. var originBnds = origin ? self.clientRect(origin) || currentBounds() : self.copyRect(bounds);
  6610. var dialogRect = self.copyRect(element[0].getBoundingClientRect());
  6611. var dialogCenterPt = self.centerPointFor(dialogRect);
  6612. var originCenterPt = self.centerPointFor(originBnds);
  6613. return {
  6614. centerX: originCenterPt.x - dialogCenterPt.x,
  6615. centerY: originCenterPt.y - dialogCenterPt.y,
  6616. scaleX: Math.round(100 * Math.min(0.5, originBnds.width / dialogRect.width)) / 100,
  6617. scaleY: Math.round(100 * Math.min(0.5, originBnds.height / dialogRect.height)) / 100
  6618. };
  6619. }
  6620. return {centerX: 0, centerY: 0, scaleX: 0.5, scaleY: 0.5};
  6621. /**
  6622. * This is a fallback if the origin information is no longer valid, then the
  6623. * origin bounds simply becomes the current bounds for the dialogContainer's parent
  6624. */
  6625. function currentBounds() {
  6626. var cntr = element ? element.parent() : null;
  6627. var parent = cntr ? cntr.parent() : null;
  6628. return parent ? self.clientRect(parent) : null;
  6629. }
  6630. },
  6631. /**
  6632. * Calculate the zoom transform from dialog to origin.
  6633. *
  6634. * We use this to set the dialog position immediately;
  6635. * then the md-transition-in actually translates back to
  6636. * `translate3d(0,0,0) scale(1.0)`...
  6637. *
  6638. * NOTE: all values are rounded to the nearest integer
  6639. */
  6640. calculateZoomToOrigin: function (element, originator) {
  6641. var zoomTemplate = "translate3d( {centerX}px, {centerY}px, 0 ) scale( {scaleX}, {scaleY} )";
  6642. var buildZoom = angular.bind(null, $mdUtil.supplant, zoomTemplate);
  6643. return buildZoom(self.calculateTransformValues(element, originator));
  6644. },
  6645. /**
  6646. * Calculate the slide transform from panel to origin.
  6647. * NOTE: all values are rounded to the nearest integer
  6648. */
  6649. calculateSlideToOrigin: function (element, originator) {
  6650. var slideTemplate = "translate3d( {centerX}px, {centerY}px, 0 )";
  6651. var buildSlide = angular.bind(null, $mdUtil.supplant, slideTemplate);
  6652. return buildSlide(self.calculateTransformValues(element, originator));
  6653. },
  6654. /**
  6655. * Enhance raw values to represent valid css stylings...
  6656. */
  6657. toCss : function( raw ) {
  6658. var css = { };
  6659. var lookups = 'left top right bottom width height x y min-width min-height max-width max-height';
  6660. angular.forEach(raw, function(value,key) {
  6661. if ( angular.isUndefined(value) ) return;
  6662. if ( lookups.indexOf(key) >= 0 ) {
  6663. css[key] = value + 'px';
  6664. } else {
  6665. switch (key) {
  6666. case 'transition':
  6667. convertToVendor(key, $mdConstant.CSS.TRANSITION, value);
  6668. break;
  6669. case 'transform':
  6670. convertToVendor(key, $mdConstant.CSS.TRANSFORM, value);
  6671. break;
  6672. case 'transformOrigin':
  6673. convertToVendor(key, $mdConstant.CSS.TRANSFORM_ORIGIN, value);
  6674. break;
  6675. case 'font-size':
  6676. css['font-size'] = value; // font sizes aren't always in px
  6677. break;
  6678. }
  6679. }
  6680. });
  6681. return css;
  6682. function convertToVendor(key, vendor, value) {
  6683. angular.forEach(vendor.split(' '), function (key) {
  6684. css[key] = value;
  6685. });
  6686. }
  6687. },
  6688. /**
  6689. * Convert the translate CSS value to key/value pair(s).
  6690. */
  6691. toTransformCss: function (transform, addTransition, transition) {
  6692. var css = {};
  6693. angular.forEach($mdConstant.CSS.TRANSFORM.split(' '), function (key) {
  6694. css[key] = transform;
  6695. });
  6696. if (addTransition) {
  6697. transition = transition || "all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) !important";
  6698. css.transition = transition;
  6699. }
  6700. return css;
  6701. },
  6702. /**
  6703. * Clone the Rect and calculate the height/width if needed
  6704. */
  6705. copyRect: function (source, destination) {
  6706. if (!source) return null;
  6707. destination = destination || {};
  6708. angular.forEach('left top right bottom width height'.split(' '), function (key) {
  6709. destination[key] = Math.round(source[key]);
  6710. });
  6711. destination.width = destination.width || (destination.right - destination.left);
  6712. destination.height = destination.height || (destination.bottom - destination.top);
  6713. return destination;
  6714. },
  6715. /**
  6716. * Calculate ClientRect of element; return null if hidden or zero size
  6717. */
  6718. clientRect: function (element) {
  6719. var bounds = angular.element(element)[0].getBoundingClientRect();
  6720. var isPositiveSizeClientRect = function (rect) {
  6721. return rect && (rect.width > 0) && (rect.height > 0);
  6722. };
  6723. // If the event origin element has zero size, it has probably been hidden.
  6724. return isPositiveSizeClientRect(bounds) ? self.copyRect(bounds) : null;
  6725. },
  6726. /**
  6727. * Calculate 'rounded' center point of Rect
  6728. */
  6729. centerPointFor: function (targetRect) {
  6730. return targetRect ? {
  6731. x: Math.round(targetRect.left + (targetRect.width / 2)),
  6732. y: Math.round(targetRect.top + (targetRect.height / 2))
  6733. } : { x : 0, y : 0 };
  6734. }
  6735. };
  6736. }
  6737. })();
  6738. (function(){
  6739. "use strict";
  6740. if (angular.version.minor >= 4) {
  6741. angular.module('material.core.animate', []);
  6742. } else {
  6743. (function() {
  6744. "use strict";
  6745. var forEach = angular.forEach;
  6746. var WEBKIT = angular.isDefined(document.documentElement.style.WebkitAppearance);
  6747. var TRANSITION_PROP = WEBKIT ? 'WebkitTransition' : 'transition';
  6748. var ANIMATION_PROP = WEBKIT ? 'WebkitAnimation' : 'animation';
  6749. var PREFIX = WEBKIT ? '-webkit-' : '';
  6750. var TRANSITION_EVENTS = (WEBKIT ? 'webkitTransitionEnd ' : '') + 'transitionend';
  6751. var ANIMATION_EVENTS = (WEBKIT ? 'webkitAnimationEnd ' : '') + 'animationend';
  6752. var $$ForceReflowFactory = ['$document', function($document) {
  6753. return function() {
  6754. return $document[0].body.clientWidth + 1;
  6755. };
  6756. }];
  6757. var $$rAFMutexFactory = ['$$rAF', function($$rAF) {
  6758. return function() {
  6759. var passed = false;
  6760. $$rAF(function() {
  6761. passed = true;
  6762. });
  6763. return function(fn) {
  6764. passed ? fn() : $$rAF(fn);
  6765. };
  6766. };
  6767. }];
  6768. var $$AnimateRunnerFactory = ['$q', '$$rAFMutex', function($q, $$rAFMutex) {
  6769. var INITIAL_STATE = 0;
  6770. var DONE_PENDING_STATE = 1;
  6771. var DONE_COMPLETE_STATE = 2;
  6772. function AnimateRunner(host) {
  6773. this.setHost(host);
  6774. this._doneCallbacks = [];
  6775. this._runInAnimationFrame = $$rAFMutex();
  6776. this._state = 0;
  6777. }
  6778. AnimateRunner.prototype = {
  6779. setHost: function(host) {
  6780. this.host = host || {};
  6781. },
  6782. done: function(fn) {
  6783. if (this._state === DONE_COMPLETE_STATE) {
  6784. fn();
  6785. } else {
  6786. this._doneCallbacks.push(fn);
  6787. }
  6788. },
  6789. progress: angular.noop,
  6790. getPromise: function() {
  6791. if (!this.promise) {
  6792. var self = this;
  6793. this.promise = $q(function(resolve, reject) {
  6794. self.done(function(status) {
  6795. status === false ? reject() : resolve();
  6796. });
  6797. });
  6798. }
  6799. return this.promise;
  6800. },
  6801. then: function(resolveHandler, rejectHandler) {
  6802. return this.getPromise().then(resolveHandler, rejectHandler);
  6803. },
  6804. 'catch': function(handler) {
  6805. return this.getPromise()['catch'](handler);
  6806. },
  6807. 'finally': function(handler) {
  6808. return this.getPromise()['finally'](handler);
  6809. },
  6810. pause: function() {
  6811. if (this.host.pause) {
  6812. this.host.pause();
  6813. }
  6814. },
  6815. resume: function() {
  6816. if (this.host.resume) {
  6817. this.host.resume();
  6818. }
  6819. },
  6820. end: function() {
  6821. if (this.host.end) {
  6822. this.host.end();
  6823. }
  6824. this._resolve(true);
  6825. },
  6826. cancel: function() {
  6827. if (this.host.cancel) {
  6828. this.host.cancel();
  6829. }
  6830. this._resolve(false);
  6831. },
  6832. complete: function(response) {
  6833. var self = this;
  6834. if (self._state === INITIAL_STATE) {
  6835. self._state = DONE_PENDING_STATE;
  6836. self._runInAnimationFrame(function() {
  6837. self._resolve(response);
  6838. });
  6839. }
  6840. },
  6841. _resolve: function(response) {
  6842. if (this._state !== DONE_COMPLETE_STATE) {
  6843. forEach(this._doneCallbacks, function(fn) {
  6844. fn(response);
  6845. });
  6846. this._doneCallbacks.length = 0;
  6847. this._state = DONE_COMPLETE_STATE;
  6848. }
  6849. }
  6850. };
  6851. // Polyfill AnimateRunner.all which is used by input animations
  6852. AnimateRunner.all = function(runners, callback) {
  6853. var count = 0;
  6854. var status = true;
  6855. forEach(runners, function(runner) {
  6856. runner.done(onProgress);
  6857. });
  6858. function onProgress(response) {
  6859. status = status && response;
  6860. if (++count === runners.length) {
  6861. callback(status);
  6862. }
  6863. }
  6864. };
  6865. return AnimateRunner;
  6866. }];
  6867. angular
  6868. .module('material.core.animate', [])
  6869. .factory('$$forceReflow', $$ForceReflowFactory)
  6870. .factory('$$AnimateRunner', $$AnimateRunnerFactory)
  6871. .factory('$$rAFMutex', $$rAFMutexFactory)
  6872. .factory('$animateCss', ['$window', '$$rAF', '$$AnimateRunner', '$$forceReflow', '$$jqLite', '$timeout', '$animate',
  6873. function($window, $$rAF, $$AnimateRunner, $$forceReflow, $$jqLite, $timeout, $animate) {
  6874. function init(element, options) {
  6875. var temporaryStyles = [];
  6876. var node = getDomNode(element);
  6877. var areAnimationsAllowed = node && $animate.enabled();
  6878. var hasCompleteStyles = false;
  6879. var hasCompleteClasses = false;
  6880. if (areAnimationsAllowed) {
  6881. if (options.transitionStyle) {
  6882. temporaryStyles.push([PREFIX + 'transition', options.transitionStyle]);
  6883. }
  6884. if (options.keyframeStyle) {
  6885. temporaryStyles.push([PREFIX + 'animation', options.keyframeStyle]);
  6886. }
  6887. if (options.delay) {
  6888. temporaryStyles.push([PREFIX + 'transition-delay', options.delay + 's']);
  6889. }
  6890. if (options.duration) {
  6891. temporaryStyles.push([PREFIX + 'transition-duration', options.duration + 's']);
  6892. }
  6893. hasCompleteStyles = options.keyframeStyle ||
  6894. (options.to && (options.duration > 0 || options.transitionStyle));
  6895. hasCompleteClasses = !!options.addClass || !!options.removeClass;
  6896. blockTransition(element, true);
  6897. }
  6898. var hasCompleteAnimation = areAnimationsAllowed && (hasCompleteStyles || hasCompleteClasses);
  6899. applyAnimationFromStyles(element, options);
  6900. var animationClosed = false;
  6901. var events, eventFn;
  6902. return {
  6903. close: $window.close,
  6904. start: function() {
  6905. var runner = new $$AnimateRunner();
  6906. waitUntilQuiet(function() {
  6907. blockTransition(element, false);
  6908. if (!hasCompleteAnimation) {
  6909. return close();
  6910. }
  6911. forEach(temporaryStyles, function(entry) {
  6912. var key = entry[0];
  6913. var value = entry[1];
  6914. node.style[camelCase(key)] = value;
  6915. });
  6916. applyClasses(element, options);
  6917. var timings = computeTimings(element);
  6918. if (timings.duration === 0) {
  6919. return close();
  6920. }
  6921. var moreStyles = [];
  6922. if (options.easing) {
  6923. if (timings.transitionDuration) {
  6924. moreStyles.push([PREFIX + 'transition-timing-function', options.easing]);
  6925. }
  6926. if (timings.animationDuration) {
  6927. moreStyles.push([PREFIX + 'animation-timing-function', options.easing]);
  6928. }
  6929. }
  6930. if (options.delay && timings.animationDelay) {
  6931. moreStyles.push([PREFIX + 'animation-delay', options.delay + 's']);
  6932. }
  6933. if (options.duration && timings.animationDuration) {
  6934. moreStyles.push([PREFIX + 'animation-duration', options.duration + 's']);
  6935. }
  6936. forEach(moreStyles, function(entry) {
  6937. var key = entry[0];
  6938. var value = entry[1];
  6939. node.style[camelCase(key)] = value;
  6940. temporaryStyles.push(entry);
  6941. });
  6942. var maxDelay = timings.delay;
  6943. var maxDelayTime = maxDelay * 1000;
  6944. var maxDuration = timings.duration;
  6945. var maxDurationTime = maxDuration * 1000;
  6946. var startTime = Date.now();
  6947. events = [];
  6948. if (timings.transitionDuration) {
  6949. events.push(TRANSITION_EVENTS);
  6950. }
  6951. if (timings.animationDuration) {
  6952. events.push(ANIMATION_EVENTS);
  6953. }
  6954. events = events.join(' ');
  6955. eventFn = function(event) {
  6956. event.stopPropagation();
  6957. var ev = event.originalEvent || event;
  6958. var timeStamp = ev.timeStamp || Date.now();
  6959. var elapsedTime = parseFloat(ev.elapsedTime.toFixed(3));
  6960. if (Math.max(timeStamp - startTime, 0) >= maxDelayTime && elapsedTime >= maxDuration) {
  6961. close();
  6962. }
  6963. };
  6964. element.on(events, eventFn);
  6965. applyAnimationToStyles(element, options);
  6966. $timeout(close, maxDelayTime + maxDurationTime * 1.5, false);
  6967. });
  6968. return runner;
  6969. function close() {
  6970. if (animationClosed) return;
  6971. animationClosed = true;
  6972. if (events && eventFn) {
  6973. element.off(events, eventFn);
  6974. }
  6975. applyClasses(element, options);
  6976. applyAnimationStyles(element, options);
  6977. forEach(temporaryStyles, function(entry) {
  6978. node.style[camelCase(entry[0])] = '';
  6979. });
  6980. runner.complete(true);
  6981. return runner;
  6982. }
  6983. }
  6984. };
  6985. }
  6986. function applyClasses(element, options) {
  6987. if (options.addClass) {
  6988. $$jqLite.addClass(element, options.addClass);
  6989. options.addClass = null;
  6990. }
  6991. if (options.removeClass) {
  6992. $$jqLite.removeClass(element, options.removeClass);
  6993. options.removeClass = null;
  6994. }
  6995. }
  6996. function computeTimings(element) {
  6997. var node = getDomNode(element);
  6998. var cs = $window.getComputedStyle(node);
  6999. var tdr = parseMaxTime(cs[prop('transitionDuration')]);
  7000. var adr = parseMaxTime(cs[prop('animationDuration')]);
  7001. var tdy = parseMaxTime(cs[prop('transitionDelay')]);
  7002. var ady = parseMaxTime(cs[prop('animationDelay')]);
  7003. adr *= (parseInt(cs[prop('animationIterationCount')], 10) || 1);
  7004. var duration = Math.max(adr, tdr);
  7005. var delay = Math.max(ady, tdy);
  7006. return {
  7007. duration: duration,
  7008. delay: delay,
  7009. animationDuration: adr,
  7010. transitionDuration: tdr,
  7011. animationDelay: ady,
  7012. transitionDelay: tdy
  7013. };
  7014. function prop(key) {
  7015. return WEBKIT ? 'Webkit' + key.charAt(0).toUpperCase() + key.substr(1)
  7016. : key;
  7017. }
  7018. }
  7019. function parseMaxTime(str) {
  7020. var maxValue = 0;
  7021. var values = (str || "").split(/\s*,\s*/);
  7022. forEach(values, function(value) {
  7023. // it's always safe to consider only second values and omit `ms` values since
  7024. // getComputedStyle will always handle the conversion for us
  7025. if (value.charAt(value.length - 1) == 's') {
  7026. value = value.substring(0, value.length - 1);
  7027. }
  7028. value = parseFloat(value) || 0;
  7029. maxValue = maxValue ? Math.max(value, maxValue) : value;
  7030. });
  7031. return maxValue;
  7032. }
  7033. var cancelLastRAFRequest;
  7034. var rafWaitQueue = [];
  7035. function waitUntilQuiet(callback) {
  7036. if (cancelLastRAFRequest) {
  7037. cancelLastRAFRequest(); //cancels the request
  7038. }
  7039. rafWaitQueue.push(callback);
  7040. cancelLastRAFRequest = $$rAF(function() {
  7041. cancelLastRAFRequest = null;
  7042. // DO NOT REMOVE THIS LINE OR REFACTOR OUT THE `pageWidth` variable.
  7043. // PLEASE EXAMINE THE `$$forceReflow` service to understand why.
  7044. var pageWidth = $$forceReflow();
  7045. // we use a for loop to ensure that if the queue is changed
  7046. // during this looping then it will consider new requests
  7047. for (var i = 0; i < rafWaitQueue.length; i++) {
  7048. rafWaitQueue[i](pageWidth);
  7049. }
  7050. rafWaitQueue.length = 0;
  7051. });
  7052. }
  7053. function applyAnimationStyles(element, options) {
  7054. applyAnimationFromStyles(element, options);
  7055. applyAnimationToStyles(element, options);
  7056. }
  7057. function applyAnimationFromStyles(element, options) {
  7058. if (options.from) {
  7059. element.css(options.from);
  7060. options.from = null;
  7061. }
  7062. }
  7063. function applyAnimationToStyles(element, options) {
  7064. if (options.to) {
  7065. element.css(options.to);
  7066. options.to = null;
  7067. }
  7068. }
  7069. function getDomNode(element) {
  7070. for (var i = 0; i < element.length; i++) {
  7071. if (element[i].nodeType === 1) return element[i];
  7072. }
  7073. }
  7074. function blockTransition(element, bool) {
  7075. var node = getDomNode(element);
  7076. var key = camelCase(PREFIX + 'transition-delay');
  7077. node.style[key] = bool ? '-9999s' : '';
  7078. }
  7079. return init;
  7080. }]);
  7081. /**
  7082. * Older browsers [FF31] expect camelCase
  7083. * property keys.
  7084. * e.g.
  7085. * animation-duration --> animationDuration
  7086. */
  7087. function camelCase(str) {
  7088. return str.replace(/-[a-z]/g, function(str) {
  7089. return str.charAt(1).toUpperCase();
  7090. });
  7091. }
  7092. })();
  7093. }
  7094. })();
  7095. (function(){
  7096. "use strict";
  7097. /**
  7098. * @ngdoc module
  7099. * @name material.components.autocomplete
  7100. */
  7101. /*
  7102. * @see js folder for autocomplete implementation
  7103. */
  7104. angular.module('material.components.autocomplete', [
  7105. 'material.core',
  7106. 'material.components.icon',
  7107. 'material.components.virtualRepeat'
  7108. ]);
  7109. })();
  7110. (function(){
  7111. "use strict";
  7112. /*
  7113. * @ngdoc module
  7114. * @name material.components.backdrop
  7115. * @description Backdrop
  7116. */
  7117. /**
  7118. * @ngdoc directive
  7119. * @name mdBackdrop
  7120. * @module material.components.backdrop
  7121. *
  7122. * @restrict E
  7123. *
  7124. * @description
  7125. * `<md-backdrop>` is a backdrop element used by other components, such as dialog and bottom sheet.
  7126. * Apply class `opaque` to make the backdrop use the theme backdrop color.
  7127. *
  7128. */
  7129. angular
  7130. .module('material.components.backdrop', ['material.core'])
  7131. .directive('mdBackdrop', ["$mdTheming", "$mdUtil", "$animate", "$rootElement", "$window", "$log", "$$rAF", "$document", function BackdropDirective($mdTheming, $mdUtil, $animate, $rootElement, $window, $log, $$rAF, $document) {
  7132. var ERROR_CSS_POSITION = '<md-backdrop> may not work properly in a scrolled, static-positioned parent container.';
  7133. return {
  7134. restrict: 'E',
  7135. link: postLink
  7136. };
  7137. function postLink(scope, element, attrs) {
  7138. // backdrop may be outside the $rootElement, tell ngAnimate to animate regardless
  7139. if ($animate.pin) $animate.pin(element, $rootElement);
  7140. var bodyStyles;
  7141. $$rAF(function() {
  7142. // If body scrolling has been disabled using mdUtil.disableBodyScroll(),
  7143. // adjust the 'backdrop' height to account for the fixed 'body' top offset.
  7144. // Note that this can be pretty expensive and is better done inside the $$rAF.
  7145. bodyStyles = $window.getComputedStyle($document[0].body);
  7146. if (bodyStyles.position === 'fixed') {
  7147. var resizeHandler = $mdUtil.debounce(function(){
  7148. bodyStyles = $window.getComputedStyle($document[0].body);
  7149. resize();
  7150. }, 60, null, false);
  7151. resize();
  7152. angular.element($window).on('resize', resizeHandler);
  7153. scope.$on('$destroy', function() {
  7154. angular.element($window).off('resize', resizeHandler);
  7155. });
  7156. }
  7157. // Often $animate.enter() is used to append the backDrop element
  7158. // so let's wait until $animate is done...
  7159. var parent = element.parent();
  7160. if (parent.length) {
  7161. if (parent[0].nodeName === 'BODY') {
  7162. element.css('position', 'fixed');
  7163. }
  7164. var styles = $window.getComputedStyle(parent[0]);
  7165. if (styles.position === 'static') {
  7166. // backdrop uses position:absolute and will not work properly with parent position:static (default)
  7167. $log.warn(ERROR_CSS_POSITION);
  7168. }
  7169. // Only inherit the parent if the backdrop has a parent.
  7170. $mdTheming.inherit(element, parent);
  7171. }
  7172. });
  7173. function resize() {
  7174. var viewportHeight = parseInt(bodyStyles.height, 10) + Math.abs(parseInt(bodyStyles.top, 10));
  7175. element.css('height', viewportHeight + 'px');
  7176. }
  7177. }
  7178. }]);
  7179. })();
  7180. (function(){
  7181. "use strict";
  7182. /**
  7183. * @ngdoc module
  7184. * @name material.components.bottomSheet
  7185. * @description
  7186. * BottomSheet
  7187. */
  7188. MdBottomSheetDirective.$inject = ["$mdBottomSheet"];
  7189. MdBottomSheetProvider.$inject = ["$$interimElementProvider"];
  7190. angular
  7191. .module('material.components.bottomSheet', [
  7192. 'material.core',
  7193. 'material.components.backdrop'
  7194. ])
  7195. .directive('mdBottomSheet', MdBottomSheetDirective)
  7196. .provider('$mdBottomSheet', MdBottomSheetProvider);
  7197. /* @ngInject */
  7198. function MdBottomSheetDirective($mdBottomSheet) {
  7199. return {
  7200. restrict: 'E',
  7201. link : function postLink(scope, element) {
  7202. element.addClass('_md'); // private md component indicator for styling
  7203. // When navigation force destroys an interimElement, then
  7204. // listen and $destroy() that interim instance...
  7205. scope.$on('$destroy', function() {
  7206. $mdBottomSheet.destroy();
  7207. });
  7208. }
  7209. };
  7210. }
  7211. /**
  7212. * @ngdoc service
  7213. * @name $mdBottomSheet
  7214. * @module material.components.bottomSheet
  7215. *
  7216. * @description
  7217. * `$mdBottomSheet` opens a bottom sheet over the app and provides a simple promise API.
  7218. *
  7219. * ## Restrictions
  7220. *
  7221. * - The bottom sheet's template must have an outer `<md-bottom-sheet>` element.
  7222. * - Add the `md-grid` class to the bottom sheet for a grid layout.
  7223. * - Add the `md-list` class to the bottom sheet for a list layout.
  7224. *
  7225. * @usage
  7226. * <hljs lang="html">
  7227. * <div ng-controller="MyController">
  7228. * <md-button ng-click="openBottomSheet()">
  7229. * Open a Bottom Sheet!
  7230. * </md-button>
  7231. * </div>
  7232. * </hljs>
  7233. * <hljs lang="js">
  7234. * var app = angular.module('app', ['ngMaterial']);
  7235. * app.controller('MyController', function($scope, $mdBottomSheet) {
  7236. * $scope.openBottomSheet = function() {
  7237. * $mdBottomSheet.show({
  7238. * template: '<md-bottom-sheet>' +
  7239. * 'Hello! <md-button ng-click="closeBottomSheet()">Close</md-button>' +
  7240. * '</md-bottom-sheet>'
  7241. * })
  7242. *
  7243. * // Fires when the hide() method is used
  7244. * .then(function() {
  7245. * console.log('You clicked the button to close the bottom sheet!');
  7246. * })
  7247. *
  7248. * // Fires when the cancel() method is used
  7249. * .catch(function() {
  7250. * console.log('You hit escape or clicked the backdrop to close.');
  7251. * });
  7252. * };
  7253. *
  7254. * $scope.closeBottomSheet = function($scope, $mdBottomSheet) {
  7255. * $mdBottomSheet.hide();
  7256. * }
  7257. *
  7258. * });
  7259. * </hljs>
  7260. *
  7261. * ### Custom Presets
  7262. * Developers are also able to create their own preset, which can be easily used without repeating
  7263. * their options each time.
  7264. *
  7265. * <hljs lang="js">
  7266. * $mdBottomSheetProvider.addPreset('testPreset', {
  7267. * options: function() {
  7268. * return {
  7269. * template:
  7270. * '<md-bottom-sheet>' +
  7271. * 'This is a custom preset' +
  7272. * '</md-bottom-sheet>',
  7273. * controllerAs: 'bottomSheet',
  7274. * bindToController: true,
  7275. * clickOutsideToClose: true,
  7276. * escapeToClose: true
  7277. * };
  7278. * }
  7279. * });
  7280. * </hljs>
  7281. *
  7282. * After you create your preset during the config phase, you can easily access it.
  7283. *
  7284. * <hljs lang="js">
  7285. * $mdBottomSheet.show(
  7286. * $mdBottomSheet.testPreset()
  7287. * );
  7288. * </hljs>
  7289. */
  7290. /**
  7291. * @ngdoc method
  7292. * @name $mdBottomSheet#show
  7293. *
  7294. * @description
  7295. * Show a bottom sheet with the specified options.
  7296. *
  7297. * <em><b>Note:</b> You should <b>always</b> provide a `.catch()` method in case the user hits the
  7298. * `esc` key or clicks the background to close. In this case, the `cancel()` method will
  7299. * automatically be called on the bottom sheet which will `reject()` the promise. See the @usage
  7300. * section above for an example.
  7301. *
  7302. * Newer versions of Angular will throw a `Possibly unhandled rejection` exception if you forget
  7303. * this.</em>
  7304. *
  7305. * @param {object} optionsOrPreset Either provide an `$mdBottomSheetPreset` defined during the config phase or
  7306. * an options object, with the following properties:
  7307. *
  7308. * - `templateUrl` - `{string=}`: The url of an html template file that will
  7309. * be used as the content of the bottom sheet. Restrictions: the template must
  7310. * have an outer `md-bottom-sheet` element.
  7311. * - `template` - `{string=}`: Same as templateUrl, except this is an actual
  7312. * template string.
  7313. * - `scope` - `{object=}`: the scope to link the template / controller to. If none is specified, it will create a new child scope.
  7314. * This scope will be destroyed when the bottom sheet is removed unless `preserveScope` is set to true.
  7315. * - `preserveScope` - `{boolean=}`: whether to preserve the scope when the element is removed. Default is false
  7316. * - `controller` - `{string=}`: The controller to associate with this bottom sheet.
  7317. * - `locals` - `{string=}`: An object containing key/value pairs. The keys will
  7318. * be used as names of values to inject into the controller. For example,
  7319. * `locals: {three: 3}` would inject `three` into the controller with the value
  7320. * of 3.
  7321. * - `clickOutsideToClose` - `{boolean=}`: Whether the user can click outside the bottom sheet to
  7322. * close it. Default true.
  7323. * - `bindToController` - `{boolean=}`: When set to true, the locals will be bound to the controller instance.
  7324. * - `disableBackdrop` - `{boolean=}`: When set to true, the bottomsheet will not show a backdrop.
  7325. * - `escapeToClose` - `{boolean=}`: Whether the user can press escape to close the bottom sheet.
  7326. * Default true.
  7327. * - `isLockedOpen` - `{boolean=}`: Disables all default ways of closing the bottom sheet. **Note:** this will override
  7328. * the `clickOutsideToClose` and `escapeToClose` options, leaving only the `hide` and `cancel`
  7329. * methods as ways of closing the bottom sheet. Defaults to false.
  7330. * - `resolve` - `{object=}`: Similar to locals, except it takes promises as values
  7331. * and the bottom sheet will not open until the promises resolve.
  7332. * - `controllerAs` - `{string=}`: An alias to assign the controller to on the scope.
  7333. * - `parent` - `{element=}`: The element to append the bottom sheet to. The `parent` may be a `function`, `string`,
  7334. * `object`, or null. Defaults to appending to the body of the root element (or the root element) of the application.
  7335. * e.g. angular.element(document.getElementById('content')) or "#content"
  7336. * - `disableParentScroll` - `{boolean=}`: Whether to disable scrolling while the bottom sheet is open.
  7337. * Default true.
  7338. *
  7339. * @returns {promise} A promise that can be resolved with `$mdBottomSheet.hide()` or
  7340. * rejected with `$mdBottomSheet.cancel()`.
  7341. */
  7342. /**
  7343. * @ngdoc method
  7344. * @name $mdBottomSheet#hide
  7345. *
  7346. * @description
  7347. * Hide the existing bottom sheet and resolve the promise returned from
  7348. * `$mdBottomSheet.show()`. This call will close the most recently opened/current bottomsheet (if
  7349. * any).
  7350. *
  7351. * <em><b>Note:</b> Use a `.then()` on your `.show()` to handle this callback.</em>
  7352. *
  7353. * @param {*=} response An argument for the resolved promise.
  7354. *
  7355. */
  7356. /**
  7357. * @ngdoc method
  7358. * @name $mdBottomSheet#cancel
  7359. *
  7360. * @description
  7361. * Hide the existing bottom sheet and reject the promise returned from
  7362. * `$mdBottomSheet.show()`.
  7363. *
  7364. * <em><b>Note:</b> Use a `.catch()` on your `.show()` to handle this callback.</em>
  7365. *
  7366. * @param {*=} response An argument for the rejected promise.
  7367. *
  7368. */
  7369. function MdBottomSheetProvider($$interimElementProvider) {
  7370. // how fast we need to flick down to close the sheet, pixels/ms
  7371. bottomSheetDefaults.$inject = ["$animate", "$mdConstant", "$mdUtil", "$mdTheming", "$mdBottomSheet", "$rootElement", "$mdGesture", "$log"];
  7372. var CLOSING_VELOCITY = 0.5;
  7373. var PADDING = 80; // same as css
  7374. return $$interimElementProvider('$mdBottomSheet')
  7375. .setDefaults({
  7376. methods: ['disableParentScroll', 'escapeToClose', 'clickOutsideToClose'],
  7377. options: bottomSheetDefaults
  7378. });
  7379. /* @ngInject */
  7380. function bottomSheetDefaults($animate, $mdConstant, $mdUtil, $mdTheming, $mdBottomSheet, $rootElement,
  7381. $mdGesture, $log) {
  7382. var backdrop;
  7383. return {
  7384. themable: true,
  7385. onShow: onShow,
  7386. onRemove: onRemove,
  7387. disableBackdrop: false,
  7388. escapeToClose: true,
  7389. clickOutsideToClose: true,
  7390. disableParentScroll: true,
  7391. isLockedOpen: false
  7392. };
  7393. function onShow(scope, element, options, controller) {
  7394. element = $mdUtil.extractElementByName(element, 'md-bottom-sheet');
  7395. // prevent tab focus or click focus on the bottom-sheet container
  7396. element.attr('tabindex', '-1');
  7397. // Once the md-bottom-sheet has `ng-cloak` applied on his template the opening animation will not work properly.
  7398. // This is a very common problem, so we have to notify the developer about this.
  7399. if (element.hasClass('ng-cloak')) {
  7400. var message = '$mdBottomSheet: using `<md-bottom-sheet ng-cloak>` will affect the bottom-sheet opening animations.';
  7401. $log.warn( message, element[0] );
  7402. }
  7403. if (options.isLockedOpen) {
  7404. options.clickOutsideToClose = false;
  7405. options.escapeToClose = false;
  7406. } else {
  7407. options.cleanupGestures = registerGestures(element, options.parent);
  7408. }
  7409. if (!options.disableBackdrop) {
  7410. // Add a backdrop that will close on click
  7411. backdrop = $mdUtil.createBackdrop(scope, "md-bottom-sheet-backdrop md-opaque");
  7412. // Prevent mouse focus on backdrop; ONLY programatic focus allowed.
  7413. // This allows clicks on backdrop to propogate to the $rootElement and
  7414. // ESC key events to be detected properly.
  7415. backdrop[0].tabIndex = -1;
  7416. if (options.clickOutsideToClose) {
  7417. backdrop.on('click', function() {
  7418. $mdUtil.nextTick($mdBottomSheet.cancel,true);
  7419. });
  7420. }
  7421. $mdTheming.inherit(backdrop, options.parent);
  7422. $animate.enter(backdrop, options.parent, null);
  7423. }
  7424. $mdTheming.inherit(element, options.parent);
  7425. if (options.disableParentScroll) {
  7426. options.restoreScroll = $mdUtil.disableScrollAround(element, options.parent);
  7427. }
  7428. return $animate.enter(element, options.parent, backdrop)
  7429. .then(function() {
  7430. var focusable = $mdUtil.findFocusTarget(element) || angular.element(
  7431. element[0].querySelector('button') ||
  7432. element[0].querySelector('a') ||
  7433. element[0].querySelector($mdUtil.prefixer('ng-click', true))
  7434. ) || backdrop;
  7435. if (options.escapeToClose) {
  7436. options.rootElementKeyupCallback = function(e) {
  7437. if (e.keyCode === $mdConstant.KEY_CODE.ESCAPE) {
  7438. $mdUtil.nextTick($mdBottomSheet.cancel,true);
  7439. }
  7440. };
  7441. $rootElement.on('keyup', options.rootElementKeyupCallback);
  7442. focusable && focusable.focus();
  7443. }
  7444. });
  7445. }
  7446. function onRemove(scope, element, options) {
  7447. if (!options.disableBackdrop) $animate.leave(backdrop);
  7448. return $animate.leave(element).then(function() {
  7449. if (options.disableParentScroll) {
  7450. options.restoreScroll();
  7451. delete options.restoreScroll;
  7452. }
  7453. options.cleanupGestures && options.cleanupGestures();
  7454. });
  7455. }
  7456. /**
  7457. * Adds the drag gestures to the bottom sheet.
  7458. */
  7459. function registerGestures(element, parent) {
  7460. var deregister = $mdGesture.register(parent, 'drag', { horizontal: false });
  7461. parent.on('$md.dragstart', onDragStart)
  7462. .on('$md.drag', onDrag)
  7463. .on('$md.dragend', onDragEnd);
  7464. return function cleanupGestures() {
  7465. deregister();
  7466. parent.off('$md.dragstart', onDragStart);
  7467. parent.off('$md.drag', onDrag);
  7468. parent.off('$md.dragend', onDragEnd);
  7469. };
  7470. function onDragStart() {
  7471. // Disable transitions on transform so that it feels fast
  7472. element.css($mdConstant.CSS.TRANSITION_DURATION, '0ms');
  7473. }
  7474. function onDrag(ev) {
  7475. var transform = ev.pointer.distanceY;
  7476. if (transform < 5) {
  7477. // Slow down drag when trying to drag up, and stop after PADDING
  7478. transform = Math.max(-PADDING, transform / 2);
  7479. }
  7480. element.css($mdConstant.CSS.TRANSFORM, 'translate3d(0,' + (PADDING + transform) + 'px,0)');
  7481. }
  7482. function onDragEnd(ev) {
  7483. if (ev.pointer.distanceY > 0 &&
  7484. (ev.pointer.distanceY > 20 || Math.abs(ev.pointer.velocityY) > CLOSING_VELOCITY)) {
  7485. var distanceRemaining = element.prop('offsetHeight') - ev.pointer.distanceY;
  7486. var transitionDuration = Math.min(distanceRemaining / ev.pointer.velocityY * 0.75, 500);
  7487. element.css($mdConstant.CSS.TRANSITION_DURATION, transitionDuration + 'ms');
  7488. $mdUtil.nextTick($mdBottomSheet.cancel,true);
  7489. } else {
  7490. element.css($mdConstant.CSS.TRANSITION_DURATION, '');
  7491. element.css($mdConstant.CSS.TRANSFORM, '');
  7492. }
  7493. }
  7494. }
  7495. }
  7496. }
  7497. })();
  7498. (function(){
  7499. "use strict";
  7500. /**
  7501. * @ngdoc module
  7502. * @name material.components.button
  7503. * @description
  7504. *
  7505. * Button
  7506. */
  7507. MdButtonDirective.$inject = ["$mdButtonInkRipple", "$mdTheming", "$mdAria", "$mdInteraction"];
  7508. MdAnchorDirective.$inject = ["$mdTheming"];
  7509. angular
  7510. .module('material.components.button', [ 'material.core' ])
  7511. .directive('mdButton', MdButtonDirective)
  7512. .directive('a', MdAnchorDirective);
  7513. /**
  7514. * @private
  7515. * @restrict E
  7516. *
  7517. * @description
  7518. * `a` is an anchor directive used to inherit theme colors for md-primary, md-accent, etc.
  7519. *
  7520. * @usage
  7521. *
  7522. * <hljs lang="html">
  7523. * <md-content md-theme="myTheme">
  7524. * <a href="#chapter1" class="md-accent"></a>
  7525. * </md-content>
  7526. * </hljs>
  7527. */
  7528. function MdAnchorDirective($mdTheming) {
  7529. return {
  7530. restrict : 'E',
  7531. link : function postLink(scope, element) {
  7532. // Make sure to inherit theme so stand-alone anchors
  7533. // support theme colors for md-primary, md-accent, etc.
  7534. $mdTheming(element);
  7535. }
  7536. };
  7537. }
  7538. /**
  7539. * @ngdoc directive
  7540. * @name mdButton
  7541. * @module material.components.button
  7542. *
  7543. * @restrict E
  7544. *
  7545. * @description
  7546. * `<md-button>` is a button directive with optional ink ripples (default enabled).
  7547. *
  7548. * If you supply a `href` or `ng-href` attribute, it will become an `<a>` element. Otherwise, it
  7549. * will become a `<button>` element. As per the
  7550. * [Material Design specifications](https://material.google.com/style/color.html#color-color-palette)
  7551. * the FAB button background is filled with the accent color [by default]. The primary color palette
  7552. * may be used with the `md-primary` class.
  7553. *
  7554. * Developers can also change the color palette of the button, by using the following classes
  7555. * - `md-primary`
  7556. * - `md-accent`
  7557. * - `md-warn`
  7558. *
  7559. * See for example
  7560. *
  7561. * <hljs lang="html">
  7562. * <md-button class="md-primary">Primary Button</md-button>
  7563. * </hljs>
  7564. *
  7565. * Button can be also raised, which means that they will use the current color palette to fill the button.
  7566. *
  7567. * <hljs lang="html">
  7568. * <md-button class="md-accent md-raised">Raised and Accent Button</md-button>
  7569. * </hljs>
  7570. *
  7571. * It is also possible to disable the focus effect on the button, by using the following markup.
  7572. *
  7573. * <hljs lang="html">
  7574. * <md-button class="md-no-focus">No Focus Style</md-button>
  7575. * </hljs>
  7576. *
  7577. * @param {string=} aria-label Adds alternative text to button for accessibility, useful for icon buttons.
  7578. * If no default text is found, a warning will be logged.
  7579. * @param {boolean=} md-no-ink If present, disable ink ripple effects.
  7580. * @param {string=} md-ripple-size Overrides the default ripple size logic. Options: `full`, `partial`, `auto`.
  7581. * @param {expression=} ng-disabled Disable the button when the expression is truthy.
  7582. * @param {expression=} ng-blur Expression evaluated when focus is removed from the button.
  7583. *
  7584. * @usage
  7585. *
  7586. * Regular buttons:
  7587. *
  7588. * <hljs lang="html">
  7589. * <md-button> Flat Button </md-button>
  7590. * <md-button href="http://google.com"> Flat link </md-button>
  7591. * <md-button class="md-raised"> Raised Button </md-button>
  7592. * <md-button ng-disabled="true"> Disabled Button </md-button>
  7593. * <md-button>
  7594. * <md-icon md-svg-src="your/icon.svg"></md-icon>
  7595. * Register Now
  7596. * </md-button>
  7597. * </hljs>
  7598. *
  7599. * FAB buttons:
  7600. *
  7601. * <hljs lang="html">
  7602. * <md-button class="md-fab" aria-label="FAB">
  7603. * <md-icon md-svg-src="your/icon.svg"></md-icon>
  7604. * </md-button>
  7605. * <!-- mini-FAB -->
  7606. * <md-button class="md-fab md-mini" aria-label="Mini FAB">
  7607. * <md-icon md-svg-src="your/icon.svg"></md-icon>
  7608. * </md-button>
  7609. * <!-- Button with SVG Icon -->
  7610. * <md-button class="md-icon-button" aria-label="Custom Icon Button">
  7611. * <md-icon md-svg-icon="path/to/your.svg"></md-icon>
  7612. * </md-button>
  7613. * </hljs>
  7614. */
  7615. function MdButtonDirective($mdButtonInkRipple, $mdTheming, $mdAria, $mdInteraction) {
  7616. return {
  7617. restrict: 'EA',
  7618. replace: true,
  7619. transclude: true,
  7620. template: getTemplate,
  7621. link: postLink
  7622. };
  7623. function isAnchor(attr) {
  7624. return angular.isDefined(attr.href) || angular.isDefined(attr.ngHref) || angular.isDefined(attr.ngLink) || angular.isDefined(attr.uiSref);
  7625. }
  7626. function getTemplate(element, attr) {
  7627. if (isAnchor(attr)) {
  7628. return '<a class="md-button" ng-transclude></a>';
  7629. } else {
  7630. //If buttons don't have type="button", they will submit forms automatically.
  7631. var btnType = (typeof attr.type === 'undefined') ? 'button' : attr.type;
  7632. return '<button class="md-button" type="' + btnType + '" ng-transclude></button>';
  7633. }
  7634. }
  7635. function postLink(scope, element, attr) {
  7636. $mdTheming(element);
  7637. $mdButtonInkRipple.attach(scope, element);
  7638. // Use async expect to support possible bindings in the button label
  7639. $mdAria.expectWithoutText(element, 'aria-label');
  7640. // For anchor elements, we have to set tabindex manually when the
  7641. // element is disabled
  7642. if (isAnchor(attr) && angular.isDefined(attr.ngDisabled) ) {
  7643. scope.$watch(attr.ngDisabled, function(isDisabled) {
  7644. element.attr('tabindex', isDisabled ? -1 : 0);
  7645. });
  7646. }
  7647. // disabling click event when disabled is true
  7648. element.on('click', function(e){
  7649. if (attr.disabled === true) {
  7650. e.preventDefault();
  7651. e.stopImmediatePropagation();
  7652. }
  7653. });
  7654. if (!element.hasClass('md-no-focus')) {
  7655. element.on('focus', function() {
  7656. // Only show the focus effect when being focused through keyboard interaction or programmatically
  7657. if (!$mdInteraction.isUserInvoked() || $mdInteraction.getLastInteractionType() === 'keyboard') {
  7658. element.addClass('md-focused');
  7659. }
  7660. });
  7661. element.on('blur', function() {
  7662. element.removeClass('md-focused');
  7663. });
  7664. }
  7665. }
  7666. }
  7667. })();
  7668. (function(){
  7669. "use strict";
  7670. /**
  7671. * @ngdoc module
  7672. * @name material.components.card
  7673. *
  7674. * @description
  7675. * Card components.
  7676. */
  7677. mdCardDirective.$inject = ["$mdTheming"];
  7678. angular.module('material.components.card', [
  7679. 'material.core'
  7680. ])
  7681. .directive('mdCard', mdCardDirective);
  7682. /**
  7683. * @ngdoc directive
  7684. * @name mdCard
  7685. * @module material.components.card
  7686. *
  7687. * @restrict E
  7688. *
  7689. * @description
  7690. * The `<md-card>` directive is a container element used within `<md-content>` containers.
  7691. *
  7692. * An image included as a direct descendant will fill the card's width. If you want to avoid this,
  7693. * you can add the `md-image-no-fill` class to the parent element. The `<md-card-content>`
  7694. * container will wrap text content and provide padding. An `<md-card-footer>` element can be
  7695. * optionally included to put content flush against the bottom edge of the card.
  7696. *
  7697. * Action buttons can be included in an `<md-card-actions>` element, similar to `<md-dialog-actions>`.
  7698. * You can then position buttons using layout attributes.
  7699. *
  7700. * Card is built with:
  7701. * * `<md-card-header>` - Header for the card, holds avatar, text and squared image
  7702. * - `<md-card-avatar>` - Card avatar
  7703. * - `md-user-avatar` - Class for user image
  7704. * - `<md-icon>`
  7705. * - `<md-card-header-text>` - Contains elements for the card description
  7706. * - `md-title` - Class for the card title
  7707. * - `md-subhead` - Class for the card sub header
  7708. * * `<img>` - Image for the card
  7709. * * `<md-card-title>` - Card content title
  7710. * - `<md-card-title-text>`
  7711. * - `md-headline` - Class for the card content title
  7712. * - `md-subhead` - Class for the card content sub header
  7713. * - `<md-card-title-media>` - Squared image within the title
  7714. * - `md-media-sm` - Class for small image
  7715. * - `md-media-md` - Class for medium image
  7716. * - `md-media-lg` - Class for large image
  7717. * - `md-media-xl` - Class for extra large image
  7718. * * `<md-card-content>` - Card content
  7719. * * `<md-card-actions>` - Card actions
  7720. * - `<md-card-icon-actions>` - Icon actions
  7721. *
  7722. * Cards have constant width and variable heights; where the maximum height is limited to what can
  7723. * fit within a single view on a platform, but it can temporarily expand as needed.
  7724. *
  7725. * @usage
  7726. * ### Card with optional footer
  7727. * <hljs lang="html">
  7728. * <md-card>
  7729. * <img src="card-image.png" class="md-card-image" alt="image caption">
  7730. * <md-card-content>
  7731. * <h2>Card headline</h2>
  7732. * <p>Card content</p>
  7733. * </md-card-content>
  7734. * <md-card-footer>
  7735. * Card footer
  7736. * </md-card-footer>
  7737. * </md-card>
  7738. * </hljs>
  7739. *
  7740. * ### Card with actions
  7741. * <hljs lang="html">
  7742. * <md-card>
  7743. * <img src="card-image.png" class="md-card-image" alt="image caption">
  7744. * <md-card-content>
  7745. * <h2>Card headline</h2>
  7746. * <p>Card content</p>
  7747. * </md-card-content>
  7748. * <md-card-actions layout="row" layout-align="end center">
  7749. * <md-button>Action 1</md-button>
  7750. * <md-button>Action 2</md-button>
  7751. * </md-card-actions>
  7752. * </md-card>
  7753. * </hljs>
  7754. *
  7755. * ### Card with header, image, title actions and content
  7756. * <hljs lang="html">
  7757. * <md-card>
  7758. * <md-card-header>
  7759. * <md-card-avatar>
  7760. * <img class="md-user-avatar" src="avatar.png"/>
  7761. * </md-card-avatar>
  7762. * <md-card-header-text>
  7763. * <span class="md-title">Title</span>
  7764. * <span class="md-subhead">Sub header</span>
  7765. * </md-card-header-text>
  7766. * </md-card-header>
  7767. * <img ng-src="card-image.png" class="md-card-image" alt="image caption">
  7768. * <md-card-title>
  7769. * <md-card-title-text>
  7770. * <span class="md-headline">Card headline</span>
  7771. * <span class="md-subhead">Card subheader</span>
  7772. * </md-card-title-text>
  7773. * </md-card-title>
  7774. * <md-card-actions layout="row" layout-align="start center">
  7775. * <md-button>Action 1</md-button>
  7776. * <md-button>Action 2</md-button>
  7777. * <md-card-icon-actions>
  7778. * <md-button class="md-icon-button" aria-label="icon">
  7779. * <md-icon md-svg-icon="icon"></md-icon>
  7780. * </md-button>
  7781. * </md-card-icon-actions>
  7782. * </md-card-actions>
  7783. * <md-card-content>
  7784. * <p>
  7785. * Card content
  7786. * </p>
  7787. * </md-card-content>
  7788. * </md-card>
  7789. * </hljs>
  7790. */
  7791. function mdCardDirective($mdTheming) {
  7792. return {
  7793. restrict: 'E',
  7794. link: function ($scope, $element, attr) {
  7795. $element.addClass('_md'); // private md component indicator for styling
  7796. $mdTheming($element);
  7797. }
  7798. };
  7799. }
  7800. })();
  7801. (function(){
  7802. "use strict";
  7803. /**
  7804. * @ngdoc module
  7805. * @name material.components.checkbox
  7806. * @description Checkbox module!
  7807. */
  7808. MdCheckboxDirective.$inject = ["inputDirective", "$mdAria", "$mdConstant", "$mdTheming", "$mdUtil", "$mdInteraction"];
  7809. angular
  7810. .module('material.components.checkbox', ['material.core'])
  7811. .directive('mdCheckbox', MdCheckboxDirective);
  7812. /**
  7813. * @ngdoc directive
  7814. * @name mdCheckbox
  7815. * @module material.components.checkbox
  7816. * @restrict E
  7817. *
  7818. * @description
  7819. * The checkbox directive is used like the normal [angular checkbox](https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D).
  7820. *
  7821. * As per the [material design spec](http://www.google.com/design/spec/style/color.html#color-color-schemes)
  7822. * the checkbox is in the accent color by default. The primary color palette may be used with
  7823. * the `md-primary` class.
  7824. *
  7825. * @param {expression} ng-model Assignable angular expression to data-bind to.
  7826. * @param {string=} name Property name of the form under which the control is published.
  7827. * @param {expression=} ng-true-value The value to which the expression should be set when selected.
  7828. * @param {expression=} ng-false-value The value to which the expression should be set when not selected.
  7829. * @param {expression=} ng-change Expression to be executed when the model value changes.
  7830. * @param {boolean=} md-no-ink Use of attribute indicates use of ripple ink effects
  7831. * @param {string=} aria-label Adds label to checkbox for accessibility.
  7832. * Defaults to checkbox's text. If no default text is found, a warning will be logged.
  7833. * @param {expression=} md-indeterminate This determines when the checkbox should be rendered as 'indeterminate'.
  7834. * If a truthy expression or no value is passed in the checkbox renders in the md-indeterminate state.
  7835. * If falsy expression is passed in it just looks like a normal unchecked checkbox.
  7836. * The indeterminate, checked, and unchecked states are mutually exclusive. A box cannot be in any two states at the same time.
  7837. * Adding the 'md-indeterminate' attribute overrides any checked/unchecked rendering logic.
  7838. * When using the 'md-indeterminate' attribute use 'ng-checked' to define rendering logic instead of using 'ng-model'.
  7839. * @param {expression=} ng-checked If this expression evaluates as truthy, the 'md-checked' css class is added to the checkbox and it
  7840. * will appear checked.
  7841. *
  7842. * @usage
  7843. * <hljs lang="html">
  7844. * <md-checkbox ng-model="isChecked" aria-label="Finished?">
  7845. * Finished ?
  7846. * </md-checkbox>
  7847. *
  7848. * <md-checkbox md-no-ink ng-model="hasInk" aria-label="No Ink Effects">
  7849. * No Ink Effects
  7850. * </md-checkbox>
  7851. *
  7852. * <md-checkbox ng-disabled="true" ng-model="isDisabled" aria-label="Disabled">
  7853. * Disabled
  7854. * </md-checkbox>
  7855. *
  7856. * </hljs>
  7857. *
  7858. */
  7859. function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $mdUtil, $mdInteraction) {
  7860. inputDirective = inputDirective[0];
  7861. return {
  7862. restrict: 'E',
  7863. transclude: true,
  7864. require: ['^?mdInputContainer', '?ngModel', '?^form'],
  7865. priority: $mdConstant.BEFORE_NG_ARIA,
  7866. template:
  7867. '<div class="md-container" md-ink-ripple md-ink-ripple-checkbox>' +
  7868. '<div class="md-icon"></div>' +
  7869. '</div>' +
  7870. '<div ng-transclude class="md-label"></div>',
  7871. compile: compile
  7872. };
  7873. // **********************************************************
  7874. // Private Methods
  7875. // **********************************************************
  7876. function compile (tElement, tAttrs) {
  7877. tAttrs.$set('tabindex', tAttrs.tabindex || '0');
  7878. tAttrs.$set('type', 'checkbox');
  7879. tAttrs.$set('role', tAttrs.type);
  7880. return {
  7881. pre: function(scope, element) {
  7882. // Attach a click handler during preLink, in order to immediately stop propagation
  7883. // (especially for ng-click) when the checkbox is disabled.
  7884. element.on('click', function(e) {
  7885. if (this.hasAttribute('disabled')) {
  7886. e.stopImmediatePropagation();
  7887. }
  7888. });
  7889. },
  7890. post: postLink
  7891. };
  7892. function postLink(scope, element, attr, ctrls) {
  7893. var isIndeterminate;
  7894. var containerCtrl = ctrls[0];
  7895. var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel();
  7896. var formCtrl = ctrls[2];
  7897. if (containerCtrl) {
  7898. var isErrorGetter = containerCtrl.isErrorGetter || function() {
  7899. return ngModelCtrl.$invalid && (ngModelCtrl.$touched || (formCtrl && formCtrl.$submitted));
  7900. };
  7901. containerCtrl.input = element;
  7902. scope.$watch(isErrorGetter, containerCtrl.setInvalid);
  7903. }
  7904. $mdTheming(element);
  7905. // Redirect focus events to the root element, because IE11 is always focusing the container element instead
  7906. // of the md-checkbox element. This causes issues when using ngModelOptions: `updateOnBlur`
  7907. element.children().on('focus', function() {
  7908. element.focus();
  7909. });
  7910. if ($mdUtil.parseAttributeBoolean(attr.mdIndeterminate)) {
  7911. setIndeterminateState();
  7912. scope.$watch(attr.mdIndeterminate, setIndeterminateState);
  7913. }
  7914. if (attr.ngChecked) {
  7915. scope.$watch(scope.$eval.bind(scope, attr.ngChecked), function(value) {
  7916. ngModelCtrl.$setViewValue(value);
  7917. ngModelCtrl.$render();
  7918. });
  7919. }
  7920. $$watchExpr('ngDisabled', 'tabindex', {
  7921. true: '-1',
  7922. false: attr.tabindex
  7923. });
  7924. $mdAria.expectWithText(element, 'aria-label');
  7925. // Reuse the original input[type=checkbox] directive from AngularJS core.
  7926. // This is a bit hacky as we need our own event listener and own render
  7927. // function.
  7928. inputDirective.link.pre(scope, {
  7929. on: angular.noop,
  7930. 0: {}
  7931. }, attr, [ngModelCtrl]);
  7932. element.on('click', listener)
  7933. .on('keypress', keypressHandler)
  7934. .on('focus', function() {
  7935. if ($mdInteraction.getLastInteractionType() === 'keyboard') {
  7936. element.addClass('md-focused');
  7937. }
  7938. })
  7939. .on('blur', function() {
  7940. element.removeClass('md-focused');
  7941. });
  7942. ngModelCtrl.$render = render;
  7943. function $$watchExpr(expr, htmlAttr, valueOpts) {
  7944. if (attr[expr]) {
  7945. scope.$watch(attr[expr], function(val) {
  7946. if (valueOpts[val]) {
  7947. element.attr(htmlAttr, valueOpts[val]);
  7948. }
  7949. });
  7950. }
  7951. }
  7952. function keypressHandler(ev) {
  7953. var keyCode = ev.which || ev.keyCode;
  7954. if (keyCode === $mdConstant.KEY_CODE.SPACE || keyCode === $mdConstant.KEY_CODE.ENTER) {
  7955. ev.preventDefault();
  7956. element.addClass('md-focused');
  7957. listener(ev);
  7958. }
  7959. }
  7960. function listener(ev) {
  7961. // skipToggle boolean is used by the switch directive to prevent the click event
  7962. // when releasing the drag. There will be always a click if releasing the drag over the checkbox
  7963. if (element[0].hasAttribute('disabled') || scope.skipToggle) {
  7964. return;
  7965. }
  7966. scope.$apply(function() {
  7967. // Toggle the checkbox value...
  7968. var viewValue = attr.ngChecked && attr.ngClick ? attr.checked : !ngModelCtrl.$viewValue;
  7969. ngModelCtrl.$setViewValue(viewValue, ev && ev.type);
  7970. ngModelCtrl.$render();
  7971. });
  7972. }
  7973. function render() {
  7974. // Cast the $viewValue to a boolean since it could be undefined
  7975. element.toggleClass('md-checked', !!ngModelCtrl.$viewValue && !isIndeterminate);
  7976. }
  7977. function setIndeterminateState(newValue) {
  7978. isIndeterminate = newValue !== false;
  7979. if (isIndeterminate) {
  7980. element.attr('aria-checked', 'mixed');
  7981. }
  7982. element.toggleClass('md-indeterminate', isIndeterminate);
  7983. }
  7984. }
  7985. }
  7986. }
  7987. })();
  7988. (function(){
  7989. "use strict";
  7990. /**
  7991. * @ngdoc module
  7992. * @name material.components.chips
  7993. */
  7994. /*
  7995. * @see js folder for chips implementation
  7996. */
  7997. angular.module('material.components.chips', [
  7998. 'material.core',
  7999. 'material.components.autocomplete'
  8000. ]);
  8001. })();
  8002. (function(){
  8003. "use strict";
  8004. (function () {
  8005. "use strict";
  8006. /**
  8007. * Use a RegExp to check if the `md-colors="<expression>"` is static string
  8008. * or one that should be observed and dynamically interpolated.
  8009. */
  8010. MdColorsDirective.$inject = ["$mdColors", "$mdUtil", "$log", "$parse"];
  8011. MdColorsService.$inject = ["$mdTheming", "$mdUtil", "$log"];
  8012. var STATIC_COLOR_EXPRESSION = /^{((\s|,)*?["'a-zA-Z-]+?\s*?:\s*?('|")[a-zA-Z0-9-.]*('|"))+\s*}$/;
  8013. var colorPalettes = null;
  8014. /**
  8015. * @ngdoc module
  8016. * @name material.components.colors
  8017. *
  8018. * @description
  8019. * Define $mdColors service and a `md-colors=""` attribute directive
  8020. */
  8021. angular
  8022. .module('material.components.colors', ['material.core'])
  8023. .directive('mdColors', MdColorsDirective)
  8024. .service('$mdColors', MdColorsService);
  8025. /**
  8026. * @ngdoc service
  8027. * @name $mdColors
  8028. * @module material.components.colors
  8029. *
  8030. * @description
  8031. * With only defining themes, one couldn't get non AngularJS Material elements colored with Material colors,
  8032. * `$mdColors` service is used by the md-color directive to convert the 1..n color expressions to RGBA values and will apply
  8033. * those values to element as CSS property values.
  8034. *
  8035. * @usage
  8036. * <hljs lang="js">
  8037. * angular.controller('myCtrl', function ($mdColors) {
  8038. * var color = $mdColors.getThemeColor('myTheme-red-200-0.5');
  8039. * ...
  8040. * });
  8041. * </hljs>
  8042. *
  8043. */
  8044. function MdColorsService($mdTheming, $mdUtil, $log) {
  8045. colorPalettes = colorPalettes || Object.keys($mdTheming.PALETTES);
  8046. // Publish service instance
  8047. return {
  8048. applyThemeColors: applyThemeColors,
  8049. getThemeColor: getThemeColor,
  8050. hasTheme: hasTheme
  8051. };
  8052. // ********************************************
  8053. // Internal Methods
  8054. // ********************************************
  8055. /**
  8056. * @ngdoc method
  8057. * @name $mdColors#applyThemeColors
  8058. *
  8059. * @description
  8060. * Gets a color json object, keys are css properties and values are string of the wanted color
  8061. * Then calculate the rgba() values based on the theme color parts
  8062. *
  8063. * @param {DOMElement} element the element to apply the styles on.
  8064. * @param {object} colorExpression json object, keys are css properties and values are string of the wanted color,
  8065. * for example: `{color: 'red-A200-0.3'}`.
  8066. *
  8067. * @usage
  8068. * <hljs lang="js">
  8069. * app.directive('myDirective', function($mdColors) {
  8070. * return {
  8071. * ...
  8072. * link: function (scope, elem) {
  8073. * $mdColors.applyThemeColors(elem, {color: 'red'});
  8074. * }
  8075. * }
  8076. * });
  8077. * </hljs>
  8078. */
  8079. function applyThemeColors(element, colorExpression) {
  8080. try {
  8081. if (colorExpression) {
  8082. // Assign the calculate RGBA color values directly as inline CSS
  8083. element.css(interpolateColors(colorExpression));
  8084. }
  8085. } catch (e) {
  8086. $log.error(e.message);
  8087. }
  8088. }
  8089. /**
  8090. * @ngdoc method
  8091. * @name $mdColors#getThemeColor
  8092. *
  8093. * @description
  8094. * Get parsed color from expression
  8095. *
  8096. * @param {string} expression string of a color expression (for instance `'red-700-0.8'`)
  8097. *
  8098. * @returns {string} a css color expression (for instance `rgba(211, 47, 47, 0.8)`)
  8099. *
  8100. * @usage
  8101. * <hljs lang="js">
  8102. * angular.controller('myCtrl', function ($mdColors) {
  8103. * var color = $mdColors.getThemeColor('myTheme-red-200-0.5');
  8104. * ...
  8105. * });
  8106. * </hljs>
  8107. */
  8108. function getThemeColor(expression) {
  8109. var color = extractColorOptions(expression);
  8110. return parseColor(color);
  8111. }
  8112. /**
  8113. * Return the parsed color
  8114. * @param color hashmap of color definitions
  8115. * @param contrast whether use contrast color for foreground
  8116. * @returns rgba color string
  8117. */
  8118. function parseColor(color, contrast) {
  8119. contrast = contrast || false;
  8120. var rgbValues = $mdTheming.PALETTES[color.palette][color.hue];
  8121. rgbValues = contrast ? rgbValues.contrast : rgbValues.value;
  8122. return $mdUtil.supplant('rgba({0}, {1}, {2}, {3})',
  8123. [rgbValues[0], rgbValues[1], rgbValues[2], rgbValues[3] || color.opacity]
  8124. );
  8125. }
  8126. /**
  8127. * Convert the color expression into an object with scope-interpolated values
  8128. * Then calculate the rgba() values based on the theme color parts
  8129. *
  8130. * @results Hashmap of CSS properties with associated `rgba( )` string vales
  8131. *
  8132. *
  8133. */
  8134. function interpolateColors(themeColors) {
  8135. var rgbColors = {};
  8136. var hasColorProperty = themeColors.hasOwnProperty('color');
  8137. angular.forEach(themeColors, function (value, key) {
  8138. var color = extractColorOptions(value);
  8139. var hasBackground = key.indexOf('background') > -1;
  8140. rgbColors[key] = parseColor(color);
  8141. if (hasBackground && !hasColorProperty) {
  8142. rgbColors.color = parseColor(color, true);
  8143. }
  8144. });
  8145. return rgbColors;
  8146. }
  8147. /**
  8148. * Check if expression has defined theme
  8149. * e.g.
  8150. * 'myTheme-primary' => true
  8151. * 'red-800' => false
  8152. */
  8153. function hasTheme(expression) {
  8154. return angular.isDefined($mdTheming.THEMES[expression.split('-')[0]]);
  8155. }
  8156. /**
  8157. * For the evaluated expression, extract the color parts into a hash map
  8158. */
  8159. function extractColorOptions(expression) {
  8160. var parts = expression.split('-');
  8161. var hasTheme = angular.isDefined($mdTheming.THEMES[parts[0]]);
  8162. var theme = hasTheme ? parts.splice(0, 1)[0] : $mdTheming.defaultTheme();
  8163. return {
  8164. theme: theme,
  8165. palette: extractPalette(parts, theme),
  8166. hue: extractHue(parts, theme),
  8167. opacity: parts[2] || 1
  8168. };
  8169. }
  8170. /**
  8171. * Calculate the theme palette name
  8172. */
  8173. function extractPalette(parts, theme) {
  8174. // If the next section is one of the palettes we assume it's a two word palette
  8175. // Two word palette can be also written in camelCase, forming camelCase to dash-case
  8176. var isTwoWord = parts.length > 1 && colorPalettes.indexOf(parts[1]) !== -1;
  8177. var palette = parts[0].replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  8178. if (isTwoWord) palette = parts[0] + '-' + parts.splice(1, 1);
  8179. if (colorPalettes.indexOf(palette) === -1) {
  8180. // If the palette is not in the palette list it's one of primary/accent/warn/background
  8181. var scheme = $mdTheming.THEMES[theme].colors[palette];
  8182. if (!scheme) {
  8183. throw new Error($mdUtil.supplant('mdColors: couldn\'t find \'{palette}\' in the palettes.', {palette: palette}));
  8184. }
  8185. palette = scheme.name;
  8186. }
  8187. return palette;
  8188. }
  8189. function extractHue(parts, theme) {
  8190. var themeColors = $mdTheming.THEMES[theme].colors;
  8191. if (parts[1] === 'hue') {
  8192. var hueNumber = parseInt(parts.splice(2, 1)[0], 10);
  8193. if (hueNumber < 1 || hueNumber > 3) {
  8194. throw new Error($mdUtil.supplant('mdColors: \'hue-{hueNumber}\' is not a valid hue, can be only \'hue-1\', \'hue-2\' and \'hue-3\'', {hueNumber: hueNumber}));
  8195. }
  8196. parts[1] = 'hue-' + hueNumber;
  8197. if (!(parts[0] in themeColors)) {
  8198. throw new Error($mdUtil.supplant('mdColors: \'hue-x\' can only be used with [{availableThemes}], but was used with \'{usedTheme}\'', {
  8199. availableThemes: Object.keys(themeColors).join(', '),
  8200. usedTheme: parts[0]
  8201. }));
  8202. }
  8203. return themeColors[parts[0]].hues[parts[1]];
  8204. }
  8205. return parts[1] || themeColors[parts[0] in themeColors ? parts[0] : 'primary'].hues['default'];
  8206. }
  8207. }
  8208. /**
  8209. * @ngdoc directive
  8210. * @name mdColors
  8211. * @module material.components.colors
  8212. *
  8213. * @restrict A
  8214. *
  8215. * @description
  8216. * `mdColors` directive will apply the theme-based color expression as RGBA CSS style values.
  8217. *
  8218. * The format will be similar to our color defining in the scss files:
  8219. *
  8220. * ## `[?theme]-[palette]-[?hue]-[?opacity]`
  8221. * - [theme] - default value is the default theme
  8222. * - [palette] - can be either palette name or primary/accent/warn/background
  8223. * - [hue] - default is 500 (hue-x can be used with primary/accent/warn/background)
  8224. * - [opacity] - default is 1
  8225. *
  8226. * > `?` indicates optional parameter
  8227. *
  8228. * @usage
  8229. * <hljs lang="html">
  8230. * <div md-colors="{background: 'myTheme-accent-900-0.43'}">
  8231. * <div md-colors="{color: 'red-A100', 'border-color': 'primary-600'}">
  8232. * <span>Color demo</span>
  8233. * </div>
  8234. * </div>
  8235. * </hljs>
  8236. *
  8237. * `mdColors` directive will automatically watch for changes in the expression if it recognizes an interpolation
  8238. * expression or a function. For performance options, you can use `::` prefix to the `md-colors` expression
  8239. * to indicate a one-time data binding.
  8240. * <hljs lang="html">
  8241. * <md-card md-colors="::{background: '{{theme}}-primary-700'}">
  8242. * </md-card>
  8243. * </hljs>
  8244. *
  8245. */
  8246. function MdColorsDirective($mdColors, $mdUtil, $log, $parse) {
  8247. return {
  8248. restrict: 'A',
  8249. require: ['^?mdTheme'],
  8250. compile: function (tElem, tAttrs) {
  8251. var shouldWatch = shouldColorsWatch();
  8252. return function (scope, element, attrs, ctrl) {
  8253. var mdThemeController = ctrl[0];
  8254. var lastColors = {};
  8255. var parseColors = function (theme) {
  8256. if (typeof theme !== 'string') {
  8257. theme = '';
  8258. }
  8259. if (!attrs.mdColors) {
  8260. attrs.mdColors = '{}';
  8261. }
  8262. /**
  8263. * Json.parse() does not work because the keys are not quoted;
  8264. * use $parse to convert to a hash map
  8265. */
  8266. var colors = $parse(attrs.mdColors)(scope);
  8267. /**
  8268. * If mdTheme is defined up the DOM tree
  8269. * we add mdTheme theme to colors who doesn't specified a theme
  8270. *
  8271. * # example
  8272. * <hljs lang="html">
  8273. * <div md-theme="myTheme">
  8274. * <div md-colors="{background: 'primary-600'}">
  8275. * <span md-colors="{background: 'mySecondTheme-accent-200'}">Color demo</span>
  8276. * </div>
  8277. * </div>
  8278. * </hljs>
  8279. *
  8280. * 'primary-600' will be 'myTheme-primary-600',
  8281. * but 'mySecondTheme-accent-200' will stay the same cause it has a theme prefix
  8282. */
  8283. if (mdThemeController) {
  8284. Object.keys(colors).forEach(function (prop) {
  8285. var color = colors[prop];
  8286. if (!$mdColors.hasTheme(color)) {
  8287. colors[prop] = (theme || mdThemeController.$mdTheme) + '-' + color;
  8288. }
  8289. });
  8290. }
  8291. cleanElement(colors);
  8292. return colors;
  8293. };
  8294. var cleanElement = function (colors) {
  8295. if (!angular.equals(colors, lastColors)) {
  8296. var keys = Object.keys(lastColors);
  8297. if (lastColors.background && !keys.color) {
  8298. keys.push('color');
  8299. }
  8300. keys.forEach(function (key) {
  8301. element.css(key, '');
  8302. });
  8303. }
  8304. lastColors = colors;
  8305. };
  8306. /**
  8307. * Registering for mgTheme changes and asking mdTheme controller run our callback whenever a theme changes
  8308. */
  8309. var unregisterChanges = angular.noop;
  8310. if (mdThemeController) {
  8311. unregisterChanges = mdThemeController.registerChanges(function (theme) {
  8312. $mdColors.applyThemeColors(element, parseColors(theme));
  8313. });
  8314. }
  8315. scope.$on('$destroy', function () {
  8316. unregisterChanges();
  8317. });
  8318. try {
  8319. if (shouldWatch) {
  8320. scope.$watch(parseColors, angular.bind(this,
  8321. $mdColors.applyThemeColors, element
  8322. ), true);
  8323. }
  8324. else {
  8325. $mdColors.applyThemeColors(element, parseColors());
  8326. }
  8327. }
  8328. catch (e) {
  8329. $log.error(e.message);
  8330. }
  8331. };
  8332. function shouldColorsWatch() {
  8333. // Simulate 1x binding and mark mdColorsWatch == false
  8334. var rawColorExpression = tAttrs.mdColors;
  8335. var bindOnce = rawColorExpression.indexOf('::') > -1;
  8336. var isStatic = bindOnce ? true : STATIC_COLOR_EXPRESSION.test(tAttrs.mdColors);
  8337. // Remove it for the postLink...
  8338. tAttrs.mdColors = rawColorExpression.replace('::', '');
  8339. var hasWatchAttr = angular.isDefined(tAttrs.mdColorsWatch);
  8340. return (bindOnce || isStatic) ? false :
  8341. hasWatchAttr ? $mdUtil.parseAttributeBoolean(tAttrs.mdColorsWatch) : true;
  8342. }
  8343. }
  8344. };
  8345. }
  8346. })();
  8347. })();
  8348. (function(){
  8349. "use strict";
  8350. /**
  8351. * @ngdoc module
  8352. * @name material.components.content
  8353. *
  8354. * @description
  8355. * Scrollable content
  8356. */
  8357. mdContentDirective.$inject = ["$mdTheming"];
  8358. angular.module('material.components.content', [
  8359. 'material.core'
  8360. ])
  8361. .directive('mdContent', mdContentDirective);
  8362. /**
  8363. * @ngdoc directive
  8364. * @name mdContent
  8365. * @module material.components.content
  8366. *
  8367. * @restrict E
  8368. *
  8369. * @description
  8370. *
  8371. * The `<md-content>` directive is a container element useful for scrollable content. It achieves
  8372. * this by setting the CSS `overflow` property to `auto` so that content can properly scroll.
  8373. *
  8374. * In general, `<md-content>` components are not designed to be nested inside one another. If
  8375. * possible, it is better to make them siblings. This often results in a better user experience as
  8376. * having nested scrollbars may confuse the user.
  8377. *
  8378. * ## Troubleshooting
  8379. *
  8380. * In some cases, you may wish to apply the `md-no-momentum` class to ensure that Safari's
  8381. * momentum scrolling is disabled. Momentum scrolling can cause flickering issues while scrolling
  8382. * SVG icons and some other components.
  8383. *
  8384. * Additionally, we now also offer the `md-no-flicker` class which can be applied to any element
  8385. * and uses a Webkit-specific filter of `blur(0px)` that forces GPU rendering of all elements
  8386. * inside (which eliminates the flicker on iOS devices).
  8387. *
  8388. * _<b>Note:</b> Forcing an element to render on the GPU can have unintended side-effects, especially
  8389. * related to the z-index of elements. Please use with caution and only on the elements needed._
  8390. *
  8391. * @usage
  8392. *
  8393. * Add the `[layout-padding]` attribute to make the content padded.
  8394. *
  8395. * <hljs lang="html">
  8396. * <md-content layout-padding>
  8397. * Lorem ipsum dolor sit amet, ne quod novum mei.
  8398. * </md-content>
  8399. * </hljs>
  8400. */
  8401. function mdContentDirective($mdTheming) {
  8402. return {
  8403. restrict: 'E',
  8404. controller: ['$scope', '$element', ContentController],
  8405. link: function(scope, element) {
  8406. element.addClass('_md'); // private md component indicator for styling
  8407. $mdTheming(element);
  8408. scope.$broadcast('$mdContentLoaded', element);
  8409. iosScrollFix(element[0]);
  8410. }
  8411. };
  8412. function ContentController($scope, $element) {
  8413. this.$scope = $scope;
  8414. this.$element = $element;
  8415. }
  8416. }
  8417. function iosScrollFix(node) {
  8418. // IOS FIX:
  8419. // If we scroll where there is no more room for the webview to scroll,
  8420. // by default the webview itself will scroll up and down, this looks really
  8421. // bad. So if we are scrolling to the very top or bottom, add/subtract one
  8422. angular.element(node).on('$md.pressdown', function(ev) {
  8423. // Only touch events
  8424. if (ev.pointer.type !== 't') return;
  8425. // Don't let a child content's touchstart ruin it for us.
  8426. if (ev.$materialScrollFixed) return;
  8427. ev.$materialScrollFixed = true;
  8428. if (node.scrollTop === 0) {
  8429. node.scrollTop = 1;
  8430. } else if (node.scrollHeight === node.scrollTop + node.offsetHeight) {
  8431. node.scrollTop -= 1;
  8432. }
  8433. });
  8434. }
  8435. })();
  8436. (function(){
  8437. "use strict";
  8438. /**
  8439. * @ngdoc module
  8440. * @name material.components.datepicker
  8441. * @description Module for the datepicker component.
  8442. */
  8443. angular.module('material.components.datepicker', [
  8444. 'material.core',
  8445. 'material.components.icon',
  8446. 'material.components.virtualRepeat'
  8447. ]);
  8448. })();
  8449. (function(){
  8450. "use strict";
  8451. /**
  8452. * @ngdoc module
  8453. * @name material.components.dialog
  8454. */
  8455. MdDialogDirective.$inject = ["$$rAF", "$mdTheming", "$mdDialog"];
  8456. MdDialogProvider.$inject = ["$$interimElementProvider"];
  8457. angular
  8458. .module('material.components.dialog', [
  8459. 'material.core',
  8460. 'material.components.backdrop'
  8461. ])
  8462. .directive('mdDialog', MdDialogDirective)
  8463. .provider('$mdDialog', MdDialogProvider);
  8464. /**
  8465. * @ngdoc directive
  8466. * @name mdDialog
  8467. * @module material.components.dialog
  8468. *
  8469. * @restrict E
  8470. *
  8471. * @description
  8472. * `<md-dialog>` - The dialog's template must be inside this element.
  8473. *
  8474. * Inside, use an `<md-dialog-content>` element for the dialog's content, and use
  8475. * an `<md-dialog-actions>` element for the dialog's actions.
  8476. *
  8477. * ## CSS
  8478. * - `.md-dialog-content` - class that sets the padding on the content as the spec file
  8479. *
  8480. * ## Notes
  8481. * - If you specify an `id` for the `<md-dialog>`, the `<md-dialog-content>` will have the same `id`
  8482. * prefixed with `dialogContent_`.
  8483. *
  8484. * @usage
  8485. * ### Dialog template
  8486. * <hljs lang="html">
  8487. * <md-dialog aria-label="List dialog">
  8488. * <md-dialog-content>
  8489. * <md-list>
  8490. * <md-list-item ng-repeat="item in items">
  8491. * <p>Number {{item}}</p>
  8492. * </md-list-item>
  8493. * </md-list>
  8494. * </md-dialog-content>
  8495. * <md-dialog-actions>
  8496. * <md-button ng-click="closeDialog()" class="md-primary">Close Dialog</md-button>
  8497. * </md-dialog-actions>
  8498. * </md-dialog>
  8499. * </hljs>
  8500. */
  8501. function MdDialogDirective($$rAF, $mdTheming, $mdDialog) {
  8502. return {
  8503. restrict: 'E',
  8504. link: function(scope, element) {
  8505. element.addClass('_md'); // private md component indicator for styling
  8506. $mdTheming(element);
  8507. $$rAF(function() {
  8508. var images;
  8509. var content = element[0].querySelector('md-dialog-content');
  8510. if (content) {
  8511. images = content.getElementsByTagName('img');
  8512. addOverflowClass();
  8513. //-- delayed image loading may impact scroll height, check after images are loaded
  8514. angular.element(images).on('load', addOverflowClass);
  8515. }
  8516. scope.$on('$destroy', function() {
  8517. $mdDialog.destroy(element);
  8518. });
  8519. /**
  8520. *
  8521. */
  8522. function addOverflowClass() {
  8523. element.toggleClass('md-content-overflow', content.scrollHeight > content.clientHeight);
  8524. }
  8525. });
  8526. }
  8527. };
  8528. }
  8529. /**
  8530. * @ngdoc service
  8531. * @name $mdDialog
  8532. * @module material.components.dialog
  8533. *
  8534. * @description
  8535. * `$mdDialog` opens a dialog over the app to inform users about critical information or require
  8536. * them to make decisions. There are two approaches for setup: a simple promise API
  8537. * and regular object syntax.
  8538. *
  8539. * ## Restrictions
  8540. *
  8541. * - The dialog is always given an isolate scope.
  8542. * - The dialog's template must have an outer `<md-dialog>` element.
  8543. * Inside, use an `<md-dialog-content>` element for the dialog's content, and use
  8544. * an `<md-dialog-actions>` element for the dialog's actions.
  8545. * - Dialogs must cover the entire application to keep interactions inside of them.
  8546. * Use the `parent` option to change where dialogs are appended.
  8547. *
  8548. * ## Sizing
  8549. * - Complex dialogs can be sized with `flex="percentage"`, i.e. `flex="66"`.
  8550. * - Default max-width is 80% of the `rootElement` or `parent`.
  8551. *
  8552. * ## CSS
  8553. * - `.md-dialog-content` - class that sets the padding on the content as the spec file
  8554. *
  8555. * @usage
  8556. * <hljs lang="html">
  8557. * <div ng-app="demoApp" ng-controller="EmployeeController">
  8558. * <div>
  8559. * <md-button ng-click="showAlert()" class="md-raised md-warn">
  8560. * Employee Alert!
  8561. * </md-button>
  8562. * </div>
  8563. * <div>
  8564. * <md-button ng-click="showDialog($event)" class="md-raised">
  8565. * Custom Dialog
  8566. * </md-button>
  8567. * </div>
  8568. * <div>
  8569. * <md-button ng-click="closeAlert()" ng-disabled="!hasAlert()" class="md-raised">
  8570. * Close Alert
  8571. * </md-button>
  8572. * </div>
  8573. * <div>
  8574. * <md-button ng-click="showGreeting($event)" class="md-raised md-primary" >
  8575. * Greet Employee
  8576. * </md-button>
  8577. * </div>
  8578. * </div>
  8579. * </hljs>
  8580. *
  8581. * ### JavaScript: object syntax
  8582. * <hljs lang="js">
  8583. * (function(angular, undefined){
  8584. * "use strict";
  8585. *
  8586. * angular
  8587. * .module('demoApp', ['ngMaterial'])
  8588. * .controller('AppCtrl', AppController);
  8589. *
  8590. * function AppController($scope, $mdDialog) {
  8591. * var alert;
  8592. * $scope.showAlert = showAlert;
  8593. * $scope.showDialog = showDialog;
  8594. * $scope.items = [1, 2, 3];
  8595. *
  8596. * // Internal method
  8597. * function showAlert() {
  8598. * alert = $mdDialog.alert({
  8599. * title: 'Attention',
  8600. * textContent: 'This is an example of how easy dialogs can be!',
  8601. * ok: 'Close'
  8602. * });
  8603. *
  8604. * $mdDialog
  8605. * .show( alert )
  8606. * .finally(function() {
  8607. * alert = undefined;
  8608. * });
  8609. * }
  8610. *
  8611. * function showDialog($event) {
  8612. * var parentEl = angular.element(document.body);
  8613. * $mdDialog.show({
  8614. * parent: parentEl,
  8615. * targetEvent: $event,
  8616. * template:
  8617. * '<md-dialog aria-label="List dialog">' +
  8618. * ' <md-dialog-content>'+
  8619. * ' <md-list>'+
  8620. * ' <md-list-item ng-repeat="item in items">'+
  8621. * ' <p>Number {{item}}</p>' +
  8622. * ' </md-item>'+
  8623. * ' </md-list>'+
  8624. * ' </md-dialog-content>' +
  8625. * ' <md-dialog-actions>' +
  8626. * ' <md-button ng-click="closeDialog()" class="md-primary">' +
  8627. * ' Close Dialog' +
  8628. * ' </md-button>' +
  8629. * ' </md-dialog-actions>' +
  8630. * '</md-dialog>',
  8631. * locals: {
  8632. * items: $scope.items
  8633. * },
  8634. * controller: DialogController
  8635. * });
  8636. * function DialogController($scope, $mdDialog, items) {
  8637. * $scope.items = items;
  8638. * $scope.closeDialog = function() {
  8639. * $mdDialog.hide();
  8640. * }
  8641. * }
  8642. * }
  8643. * }
  8644. * })(angular);
  8645. * </hljs>
  8646. *
  8647. * ### Multiple Dialogs
  8648. * Using the `multiple` option for the `$mdDialog` service allows developers to show multiple dialogs
  8649. * at the same time.
  8650. *
  8651. * <hljs lang="js">
  8652. * // From plain options
  8653. * $mdDialog.show({
  8654. * multiple: true
  8655. * });
  8656. *
  8657. * // From a dialog preset
  8658. * $mdDialog.show(
  8659. * $mdDialog
  8660. * .alert()
  8661. * .multiple(true)
  8662. * );
  8663. *
  8664. * </hljs>
  8665. *
  8666. * ### Pre-Rendered Dialogs
  8667. * By using the `contentElement` option, it is possible to use an already existing element in the DOM.
  8668. *
  8669. * > Pre-rendered dialogs will be not linked to any scope and will not instantiate any new controller.<br/>
  8670. * > You can manually link the elements to a scope or instantiate a controller from the template (`ng-controller`)
  8671. *
  8672. * <hljs lang="js">
  8673. * $scope.showPrerenderedDialog = function() {
  8674. * $mdDialog.show({
  8675. * contentElement: '#myStaticDialog',
  8676. * parent: angular.element(document.body)
  8677. * });
  8678. * };
  8679. * </hljs>
  8680. *
  8681. * When using a string as value, `$mdDialog` will automatically query the DOM for the specified CSS selector.
  8682. *
  8683. * <hljs lang="html">
  8684. * <div style="visibility: hidden">
  8685. * <div class="md-dialog-container" id="myStaticDialog">
  8686. * <md-dialog>
  8687. * This is a pre-rendered dialog.
  8688. * </md-dialog>
  8689. * </div>
  8690. * </div>
  8691. * </hljs>
  8692. *
  8693. * **Notice**: It is important, to use the `.md-dialog-container` as the content element, otherwise the dialog
  8694. * will not show up.
  8695. *
  8696. * It also possible to use a DOM element for the `contentElement` option.
  8697. * - `contentElement: document.querySelector('#myStaticDialog')`
  8698. * - `contentElement: angular.element(TEMPLATE)`
  8699. *
  8700. * When using a `template` as content element, it will be not compiled upon open.
  8701. * This allows you to compile the element yourself and use it each time the dialog opens.
  8702. *
  8703. * ### Custom Presets
  8704. * Developers are also able to create their own preset, which can be easily used without repeating
  8705. * their options each time.
  8706. *
  8707. * <hljs lang="js">
  8708. * $mdDialogProvider.addPreset('testPreset', {
  8709. * options: function() {
  8710. * return {
  8711. * template:
  8712. * '<md-dialog>' +
  8713. * 'This is a custom preset' +
  8714. * '</md-dialog>',
  8715. * controllerAs: 'dialog',
  8716. * bindToController: true,
  8717. * clickOutsideToClose: true,
  8718. * escapeToClose: true
  8719. * };
  8720. * }
  8721. * });
  8722. * </hljs>
  8723. *
  8724. * After you created your preset at config phase, you can easily access it.
  8725. *
  8726. * <hljs lang="js">
  8727. * $mdDialog.show(
  8728. * $mdDialog.testPreset()
  8729. * );
  8730. * </hljs>
  8731. *
  8732. * ### JavaScript: promise API syntax, custom dialog template
  8733. * <hljs lang="js">
  8734. * (function(angular, undefined){
  8735. * "use strict";
  8736. *
  8737. * angular
  8738. * .module('demoApp', ['ngMaterial'])
  8739. * .controller('EmployeeController', EmployeeEditor)
  8740. * .controller('GreetingController', GreetingController);
  8741. *
  8742. * // Fictitious Employee Editor to show how to use simple and complex dialogs.
  8743. *
  8744. * function EmployeeEditor($scope, $mdDialog) {
  8745. * var alert;
  8746. *
  8747. * $scope.showAlert = showAlert;
  8748. * $scope.closeAlert = closeAlert;
  8749. * $scope.showGreeting = showCustomGreeting;
  8750. *
  8751. * $scope.hasAlert = function() { return !!alert };
  8752. * $scope.userName = $scope.userName || 'Bobby';
  8753. *
  8754. * // Dialog #1 - Show simple alert dialog and cache
  8755. * // reference to dialog instance
  8756. *
  8757. * function showAlert() {
  8758. * alert = $mdDialog.alert()
  8759. * .title('Attention, ' + $scope.userName)
  8760. * .textContent('This is an example of how easy dialogs can be!')
  8761. * .ok('Close');
  8762. *
  8763. * $mdDialog
  8764. * .show( alert )
  8765. * .finally(function() {
  8766. * alert = undefined;
  8767. * });
  8768. * }
  8769. *
  8770. * // Close the specified dialog instance and resolve with 'finished' flag
  8771. * // Normally this is not needed, just use '$mdDialog.hide()' to close
  8772. * // the most recent dialog popup.
  8773. *
  8774. * function closeAlert() {
  8775. * $mdDialog.hide( alert, "finished" );
  8776. * alert = undefined;
  8777. * }
  8778. *
  8779. * // Dialog #2 - Demonstrate more complex dialogs construction and popup.
  8780. *
  8781. * function showCustomGreeting($event) {
  8782. * $mdDialog.show({
  8783. * targetEvent: $event,
  8784. * template:
  8785. * '<md-dialog>' +
  8786. *
  8787. * ' <md-dialog-content>Hello {{ employee }}!</md-dialog-content>' +
  8788. *
  8789. * ' <md-dialog-actions>' +
  8790. * ' <md-button ng-click="closeDialog()" class="md-primary">' +
  8791. * ' Close Greeting' +
  8792. * ' </md-button>' +
  8793. * ' </md-dialog-actions>' +
  8794. * '</md-dialog>',
  8795. * controller: 'GreetingController',
  8796. * onComplete: afterShowAnimation,
  8797. * locals: { employee: $scope.userName }
  8798. * });
  8799. *
  8800. * // When the 'enter' animation finishes...
  8801. *
  8802. * function afterShowAnimation(scope, element, options) {
  8803. * // post-show code here: DOM element focus, etc.
  8804. * }
  8805. * }
  8806. *
  8807. * // Dialog #3 - Demonstrate use of ControllerAs and passing $scope to dialog
  8808. * // Here we used ng-controller="GreetingController as vm" and
  8809. * // $scope.vm === <controller instance>
  8810. *
  8811. * function showCustomGreeting() {
  8812. *
  8813. * $mdDialog.show({
  8814. * clickOutsideToClose: true,
  8815. *
  8816. * scope: $scope, // use parent scope in template
  8817. * preserveScope: true, // do not forget this if use parent scope
  8818. * // Since GreetingController is instantiated with ControllerAs syntax
  8819. * // AND we are passing the parent '$scope' to the dialog, we MUST
  8820. * // use 'vm.<xxx>' in the template markup
  8821. *
  8822. * template: '<md-dialog>' +
  8823. * ' <md-dialog-content>' +
  8824. * ' Hi There {{vm.employee}}' +
  8825. * ' </md-dialog-content>' +
  8826. * '</md-dialog>',
  8827. *
  8828. * controller: function DialogController($scope, $mdDialog) {
  8829. * $scope.closeDialog = function() {
  8830. * $mdDialog.hide();
  8831. * }
  8832. * }
  8833. * });
  8834. * }
  8835. *
  8836. * }
  8837. *
  8838. * // Greeting controller used with the more complex 'showCustomGreeting()' custom dialog
  8839. *
  8840. * function GreetingController($scope, $mdDialog, employee) {
  8841. * // Assigned from construction <code>locals</code> options...
  8842. * $scope.employee = employee;
  8843. *
  8844. * $scope.closeDialog = function() {
  8845. * // Easily hides most recent dialog shown...
  8846. * // no specific instance reference is needed.
  8847. * $mdDialog.hide();
  8848. * };
  8849. * }
  8850. *
  8851. * })(angular);
  8852. * </hljs>
  8853. */
  8854. /**
  8855. * @ngdoc method
  8856. * @name $mdDialog#alert
  8857. *
  8858. * @description
  8859. * Builds a preconfigured dialog with the specified message.
  8860. *
  8861. * @returns {obj} an `$mdDialogPreset` with the chainable configuration methods:
  8862. *
  8863. * - $mdDialogPreset#title(string) - Sets the alert title.
  8864. * - $mdDialogPreset#textContent(string) - Sets the alert message.
  8865. * - $mdDialogPreset#htmlContent(string) - Sets the alert message as HTML. Requires ngSanitize
  8866. * module to be loaded. HTML is not run through Angular's compiler.
  8867. * - $mdDialogPreset#ok(string) - Sets the alert "Okay" button text.
  8868. * - $mdDialogPreset#theme(string) - Sets the theme of the alert dialog.
  8869. * - $mdDialogPreset#targetEvent(DOMClickEvent=) - A click's event object. When passed in as an option,
  8870. * the location of the click will be used as the starting point for the opening animation
  8871. * of the the dialog.
  8872. *
  8873. */
  8874. /**
  8875. * @ngdoc method
  8876. * @name $mdDialog#confirm
  8877. *
  8878. * @description
  8879. * Builds a preconfigured dialog with the specified message. You can call show and the promise returned
  8880. * will be resolved only if the user clicks the confirm action on the dialog.
  8881. *
  8882. * @returns {obj} an `$mdDialogPreset` with the chainable configuration methods:
  8883. *
  8884. * Additionally, it supports the following methods:
  8885. *
  8886. * - $mdDialogPreset#title(string) - Sets the confirm title.
  8887. * - $mdDialogPreset#textContent(string) - Sets the confirm message.
  8888. * - $mdDialogPreset#htmlContent(string) - Sets the confirm message as HTML. Requires ngSanitize
  8889. * module to be loaded. HTML is not run through Angular's compiler.
  8890. * - $mdDialogPreset#ok(string) - Sets the confirm "Okay" button text.
  8891. * - $mdDialogPreset#cancel(string) - Sets the confirm "Cancel" button text.
  8892. * - $mdDialogPreset#theme(string) - Sets the theme of the confirm dialog.
  8893. * - $mdDialogPreset#targetEvent(DOMClickEvent=) - A click's event object. When passed in as an option,
  8894. * the location of the click will be used as the starting point for the opening animation
  8895. * of the the dialog.
  8896. *
  8897. */
  8898. /**
  8899. * @ngdoc method
  8900. * @name $mdDialog#prompt
  8901. *
  8902. * @description
  8903. * Builds a preconfigured dialog with the specified message and input box. You can call show and the promise returned
  8904. * will be resolved only if the user clicks the prompt action on the dialog, passing the input value as the first argument.
  8905. *
  8906. * @returns {obj} an `$mdDialogPreset` with the chainable configuration methods:
  8907. *
  8908. * Additionally, it supports the following methods:
  8909. *
  8910. * - $mdDialogPreset#title(string) - Sets the prompt title.
  8911. * - $mdDialogPreset#textContent(string) - Sets the prompt message.
  8912. * - $mdDialogPreset#htmlContent(string) - Sets the prompt message as HTML. Requires ngSanitize
  8913. * module to be loaded. HTML is not run through Angular's compiler.
  8914. * - $mdDialogPreset#placeholder(string) - Sets the placeholder text for the input.
  8915. * - $mdDialogPreset#required(boolean) - Sets the input required value.
  8916. * - $mdDialogPreset#initialValue(string) - Sets the initial value for the prompt input.
  8917. * - $mdDialogPreset#ok(string) - Sets the prompt "Okay" button text.
  8918. * - $mdDialogPreset#cancel(string) - Sets the prompt "Cancel" button text.
  8919. * - $mdDialogPreset#theme(string) - Sets the theme of the prompt dialog.
  8920. * - $mdDialogPreset#targetEvent(DOMClickEvent=) - A click's event object. When passed in as an option,
  8921. * the location of the click will be used as the starting point for the opening animation
  8922. * of the the dialog.
  8923. *
  8924. */
  8925. /**
  8926. * @ngdoc method
  8927. * @name $mdDialog#show
  8928. *
  8929. * @description
  8930. * Show a dialog with the specified options.
  8931. *
  8932. * @param {object} optionsOrPreset Either provide an `$mdDialogPreset` returned from `alert()`, and
  8933. * `confirm()`, or an options object with the following properties:
  8934. * - `templateUrl` - `{string=}`: The url of a template that will be used as the content
  8935. * of the dialog.
  8936. * - `template` - `{string=}`: HTML template to show in the dialog. This **must** be trusted HTML
  8937. * with respect to Angular's [$sce service](https://docs.angularjs.org/api/ng/service/$sce).
  8938. * This template should **never** be constructed with any kind of user input or user data.
  8939. * - `contentElement` - `{string|Element}`: Instead of using a template, which will be compiled each time a
  8940. * dialog opens, you can also use a DOM element.<br/>
  8941. * * When specifying an element, which is present on the DOM, `$mdDialog` will temporary fetch the element into
  8942. * the dialog and restores it at the old DOM position upon close.
  8943. * * When specifying a string, the string be used as a CSS selector, to lookup for the element in the DOM.
  8944. * - `autoWrap` - `{boolean=}`: Whether or not to automatically wrap the template with a
  8945. * `<md-dialog>` tag if one is not provided. Defaults to true. Can be disabled if you provide a
  8946. * custom dialog directive.
  8947. * - `targetEvent` - `{DOMClickEvent=}`: A click's event object. When passed in as an option,
  8948. * the location of the click will be used as the starting point for the opening animation
  8949. * of the the dialog.
  8950. * - `openFrom` - `{string|Element|object}`: The query selector, DOM element or the Rect object
  8951. * that is used to determine the bounds (top, left, height, width) from which the Dialog will
  8952. * originate.
  8953. * - `closeTo` - `{string|Element|object}`: The query selector, DOM element or the Rect object
  8954. * that is used to determine the bounds (top, left, height, width) to which the Dialog will
  8955. * target.
  8956. * - `scope` - `{object=}`: the scope to link the template / controller to. If none is specified,
  8957. * it will create a new isolate scope.
  8958. * This scope will be destroyed when the dialog is removed unless `preserveScope` is set to true.
  8959. * - `preserveScope` - `{boolean=}`: whether to preserve the scope when the element is removed. Default is false
  8960. * - `disableParentScroll` - `{boolean=}`: Whether to disable scrolling while the dialog is open.
  8961. * Default true.
  8962. * - `hasBackdrop` - `{boolean=}`: Whether there should be an opaque backdrop behind the dialog.
  8963. * Default true.
  8964. * - `clickOutsideToClose` - `{boolean=}`: Whether the user can click outside the dialog to
  8965. * close it. Default false.
  8966. * - `escapeToClose` - `{boolean=}`: Whether the user can press escape to close the dialog.
  8967. * Default true.
  8968. * - `focusOnOpen` - `{boolean=}`: An option to override focus behavior on open. Only disable if
  8969. * focusing some other way, as focus management is required for dialogs to be accessible.
  8970. * Defaults to true.
  8971. * - `controller` - `{function|string=}`: The controller to associate with the dialog. The controller
  8972. * will be injected with the local `$mdDialog`, which passes along a scope for the dialog.
  8973. * - `locals` - `{object=}`: An object containing key/value pairs. The keys will be used as names
  8974. * of values to inject into the controller. For example, `locals: {three: 3}` would inject
  8975. * `three` into the controller, with the value 3. If `bindToController` is true, they will be
  8976. * copied to the controller instead.
  8977. * - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in.
  8978. * - `resolve` - `{function=}`: Similar to locals, except it takes as values functions that return promises, and the
  8979. * dialog will not open until all of the promises resolve.
  8980. * - `controllerAs` - `{string=}`: An alias to assign the controller to on the scope.
  8981. * - `parent` - `{element=}`: The element to append the dialog to. Defaults to appending
  8982. * to the root element of the application.
  8983. * - `onShowing` - `function(scope, element)`: Callback function used to announce the show() action is
  8984. * starting.
  8985. * - `onComplete` - `function(scope, element)`: Callback function used to announce when the show() action is
  8986. * finished.
  8987. * - `onRemoving` - `function(element, removePromise)`: Callback function used to announce the
  8988. * close/hide() action is starting. This allows developers to run custom animations
  8989. * in parallel with the close animations.
  8990. * - `fullscreen` `{boolean=}`: An option to toggle whether the dialog should show in fullscreen
  8991. * or not. Defaults to `false`.
  8992. * - `multiple` `{boolean=}`: An option to allow this dialog to display over one that's currently open.
  8993. * @returns {promise} A promise that can be resolved with `$mdDialog.hide()` or
  8994. * rejected with `$mdDialog.cancel()`.
  8995. */
  8996. /**
  8997. * @ngdoc method
  8998. * @name $mdDialog#hide
  8999. *
  9000. * @description
  9001. * Hide an existing dialog and resolve the promise returned from `$mdDialog.show()`.
  9002. *
  9003. * @param {*=} response An argument for the resolved promise.
  9004. *
  9005. * @returns {promise} A promise that is resolved when the dialog has been closed.
  9006. */
  9007. /**
  9008. * @ngdoc method
  9009. * @name $mdDialog#cancel
  9010. *
  9011. * @description
  9012. * Hide an existing dialog and reject the promise returned from `$mdDialog.show()`.
  9013. *
  9014. * @param {*=} response An argument for the rejected promise.
  9015. *
  9016. * @returns {promise} A promise that is resolved when the dialog has been closed.
  9017. */
  9018. function MdDialogProvider($$interimElementProvider) {
  9019. // Elements to capture and redirect focus when the user presses tab at the dialog boundary.
  9020. MdDialogController.$inject = ["$mdDialog", "$mdConstant"];
  9021. dialogDefaultOptions.$inject = ["$mdDialog", "$mdAria", "$mdUtil", "$mdConstant", "$animate", "$document", "$window", "$rootElement", "$log", "$injector", "$mdTheming", "$interpolate", "$mdInteraction"];
  9022. var topFocusTrap, bottomFocusTrap;
  9023. return $$interimElementProvider('$mdDialog')
  9024. .setDefaults({
  9025. methods: ['disableParentScroll', 'hasBackdrop', 'clickOutsideToClose', 'escapeToClose',
  9026. 'targetEvent', 'closeTo', 'openFrom', 'parent', 'fullscreen', 'multiple'],
  9027. options: dialogDefaultOptions
  9028. })
  9029. .addPreset('alert', {
  9030. methods: ['title', 'htmlContent', 'textContent', 'content', 'ariaLabel', 'ok', 'theme',
  9031. 'css'],
  9032. options: advancedDialogOptions
  9033. })
  9034. .addPreset('confirm', {
  9035. methods: ['title', 'htmlContent', 'textContent', 'content', 'ariaLabel', 'ok', 'cancel',
  9036. 'theme', 'css'],
  9037. options: advancedDialogOptions
  9038. })
  9039. .addPreset('prompt', {
  9040. methods: ['title', 'htmlContent', 'textContent', 'initialValue', 'content', 'placeholder', 'ariaLabel',
  9041. 'ok', 'cancel', 'theme', 'css', 'required'],
  9042. options: advancedDialogOptions
  9043. });
  9044. /* @ngInject */
  9045. function advancedDialogOptions() {
  9046. return {
  9047. template: [
  9048. '<md-dialog md-theme="{{ dialog.theme || dialog.defaultTheme }}" aria-label="{{ dialog.ariaLabel }}" ng-class="dialog.css">',
  9049. ' <md-dialog-content class="md-dialog-content" role="document" tabIndex="-1">',
  9050. ' <h2 class="md-title">{{ dialog.title }}</h2>',
  9051. ' <div ng-if="::dialog.mdHtmlContent" class="md-dialog-content-body" ',
  9052. ' ng-bind-html="::dialog.mdHtmlContent"></div>',
  9053. ' <div ng-if="::!dialog.mdHtmlContent" class="md-dialog-content-body">',
  9054. ' <p>{{::dialog.mdTextContent}}</p>',
  9055. ' </div>',
  9056. ' <md-input-container md-no-float ng-if="::dialog.$type == \'prompt\'" class="md-prompt-input-container">',
  9057. ' <input ng-keypress="dialog.keypress($event)" md-autofocus ng-model="dialog.result" ' +
  9058. ' placeholder="{{::dialog.placeholder}}" ng-required="dialog.required">',
  9059. ' </md-input-container>',
  9060. ' </md-dialog-content>',
  9061. ' <md-dialog-actions>',
  9062. ' <md-button ng-if="dialog.$type === \'confirm\' || dialog.$type === \'prompt\'"' +
  9063. ' ng-click="dialog.abort()" class="md-primary md-cancel-button">',
  9064. ' {{ dialog.cancel }}',
  9065. ' </md-button>',
  9066. ' <md-button ng-click="dialog.hide()" class="md-primary md-confirm-button" md-autofocus="dialog.$type===\'alert\'"' +
  9067. ' ng-disabled="dialog.required && !dialog.result">',
  9068. ' {{ dialog.ok }}',
  9069. ' </md-button>',
  9070. ' </md-dialog-actions>',
  9071. '</md-dialog>'
  9072. ].join('').replace(/\s\s+/g, ''),
  9073. controller: MdDialogController,
  9074. controllerAs: 'dialog',
  9075. bindToController: true,
  9076. };
  9077. }
  9078. /**
  9079. * Controller for the md-dialog interim elements
  9080. * @ngInject
  9081. */
  9082. function MdDialogController($mdDialog, $mdConstant) {
  9083. // For compatibility with AngularJS 1.6+, we should always use the $onInit hook in
  9084. // interimElements. The $mdCompiler simulates the $onInit hook for all versions.
  9085. this.$onInit = function() {
  9086. var isPrompt = this.$type == 'prompt';
  9087. if (isPrompt && this.initialValue) {
  9088. this.result = this.initialValue;
  9089. }
  9090. this.hide = function() {
  9091. $mdDialog.hide(isPrompt ? this.result : true);
  9092. };
  9093. this.abort = function() {
  9094. $mdDialog.cancel();
  9095. };
  9096. this.keypress = function($event) {
  9097. var invalidPrompt = isPrompt && this.required && !angular.isDefined(this.result);
  9098. if ($event.keyCode === $mdConstant.KEY_CODE.ENTER && !invalidPrompt) {
  9099. $mdDialog.hide(this.result);
  9100. }
  9101. };
  9102. };
  9103. }
  9104. /* @ngInject */
  9105. function dialogDefaultOptions($mdDialog, $mdAria, $mdUtil, $mdConstant, $animate, $document, $window, $rootElement,
  9106. $log, $injector, $mdTheming, $interpolate, $mdInteraction) {
  9107. return {
  9108. hasBackdrop: true,
  9109. isolateScope: true,
  9110. onCompiling: beforeCompile,
  9111. onShow: onShow,
  9112. onShowing: beforeShow,
  9113. onRemove: onRemove,
  9114. clickOutsideToClose: false,
  9115. escapeToClose: true,
  9116. targetEvent: null,
  9117. closeTo: null,
  9118. openFrom: null,
  9119. focusOnOpen: true,
  9120. disableParentScroll: true,
  9121. autoWrap: true,
  9122. fullscreen: false,
  9123. transformTemplate: function(template, options) {
  9124. // Make the dialog container focusable, because otherwise the focus will be always redirected to
  9125. // an element outside of the container, and the focus trap won't work probably..
  9126. // Also the tabindex is needed for the `escapeToClose` functionality, because
  9127. // the keyDown event can't be triggered when the focus is outside of the container.
  9128. var startSymbol = $interpolate.startSymbol();
  9129. var endSymbol = $interpolate.endSymbol();
  9130. var theme = startSymbol + (options.themeWatch ? '' : '::') + 'theme' + endSymbol;
  9131. var themeAttr = (options.hasTheme) ? 'md-theme="'+theme+'"': '';
  9132. return '<div class="md-dialog-container" tabindex="-1" ' + themeAttr + '>' + validatedTemplate(template) + '</div>';
  9133. /**
  9134. * The specified template should contain a <md-dialog> wrapper element....
  9135. */
  9136. function validatedTemplate(template) {
  9137. if (options.autoWrap && !/<\/md-dialog>/g.test(template)) {
  9138. return '<md-dialog>' + (template || '') + '</md-dialog>';
  9139. } else {
  9140. return template || '';
  9141. }
  9142. }
  9143. }
  9144. };
  9145. function beforeCompile(options) {
  9146. // Automatically apply the theme, if the user didn't specify a theme explicitly.
  9147. // Those option changes need to be done, before the compilation has started, because otherwise
  9148. // the option changes will be not available in the $mdCompilers locales.
  9149. options.defaultTheme = $mdTheming.defaultTheme();
  9150. detectTheming(options);
  9151. }
  9152. function beforeShow(scope, element, options, controller) {
  9153. if (controller) {
  9154. var mdHtmlContent = controller.htmlContent || options.htmlContent || '';
  9155. var mdTextContent = controller.textContent || options.textContent ||
  9156. controller.content || options.content || '';
  9157. if (mdHtmlContent && !$injector.has('$sanitize')) {
  9158. throw Error('The ngSanitize module must be loaded in order to use htmlContent.');
  9159. }
  9160. if (mdHtmlContent && mdTextContent) {
  9161. throw Error('md-dialog cannot have both `htmlContent` and `textContent`');
  9162. }
  9163. // Only assign the content if nothing throws, otherwise it'll still be compiled.
  9164. controller.mdHtmlContent = mdHtmlContent;
  9165. controller.mdTextContent = mdTextContent;
  9166. }
  9167. }
  9168. /** Show method for dialogs */
  9169. function onShow(scope, element, options, controller) {
  9170. angular.element($document[0].body).addClass('md-dialog-is-showing');
  9171. var dialogElement = element.find('md-dialog');
  9172. // Once a dialog has `ng-cloak` applied on his template the dialog animation will not work properly.
  9173. // This is a very common problem, so we have to notify the developer about this.
  9174. if (dialogElement.hasClass('ng-cloak')) {
  9175. var message = '$mdDialog: using `<md-dialog ng-cloak>` will affect the dialog opening animations.';
  9176. $log.warn( message, element[0] );
  9177. }
  9178. captureParentAndFromToElements(options);
  9179. configureAria(dialogElement, options);
  9180. showBackdrop(scope, element, options);
  9181. activateListeners(element, options);
  9182. return dialogPopIn(element, options)
  9183. .then(function() {
  9184. lockScreenReader(element, options);
  9185. warnDeprecatedActions();
  9186. focusOnOpen();
  9187. });
  9188. /**
  9189. * Check to see if they used the deprecated .md-actions class and log a warning
  9190. */
  9191. function warnDeprecatedActions() {
  9192. if (element[0].querySelector('.md-actions')) {
  9193. $log.warn('Using a class of md-actions is deprecated, please use <md-dialog-actions>.');
  9194. }
  9195. }
  9196. /**
  9197. * For alerts, focus on content... otherwise focus on
  9198. * the close button (or equivalent)
  9199. */
  9200. function focusOnOpen() {
  9201. if (options.focusOnOpen) {
  9202. var target = $mdUtil.findFocusTarget(element) || findCloseButton() || dialogElement;
  9203. target.focus();
  9204. }
  9205. /**
  9206. * If no element with class dialog-close, try to find the last
  9207. * button child in md-actions and assume it is a close button.
  9208. *
  9209. * If we find no actions at all, log a warning to the console.
  9210. */
  9211. function findCloseButton() {
  9212. return element[0].querySelector('.dialog-close, md-dialog-actions button:last-child');
  9213. }
  9214. }
  9215. }
  9216. /**
  9217. * Remove function for all dialogs
  9218. */
  9219. function onRemove(scope, element, options) {
  9220. options.deactivateListeners();
  9221. options.unlockScreenReader();
  9222. options.hideBackdrop(options.$destroy);
  9223. // Remove the focus traps that we added earlier for keeping focus within the dialog.
  9224. if (topFocusTrap && topFocusTrap.parentNode) {
  9225. topFocusTrap.parentNode.removeChild(topFocusTrap);
  9226. }
  9227. if (bottomFocusTrap && bottomFocusTrap.parentNode) {
  9228. bottomFocusTrap.parentNode.removeChild(bottomFocusTrap);
  9229. }
  9230. // For navigation $destroy events, do a quick, non-animated removal,
  9231. // but for normal closes (from clicks, etc) animate the removal
  9232. return options.$destroy ? detachAndClean() : animateRemoval().then( detachAndClean );
  9233. /**
  9234. * For normal closes, animate the removal.
  9235. * For forced closes (like $destroy events), skip the animations
  9236. */
  9237. function animateRemoval() {
  9238. return dialogPopOut(element, options);
  9239. }
  9240. /**
  9241. * Detach the element
  9242. */
  9243. function detachAndClean() {
  9244. angular.element($document[0].body).removeClass('md-dialog-is-showing');
  9245. // Reverse the container stretch if using a content element.
  9246. if (options.contentElement) {
  9247. options.reverseContainerStretch();
  9248. }
  9249. // Exposed cleanup function from the $mdCompiler.
  9250. options.cleanupElement();
  9251. // Restores the focus to the origin element if the last interaction upon opening was a keyboard.
  9252. if (!options.$destroy && options.originInteraction === 'keyboard') {
  9253. options.origin.focus();
  9254. }
  9255. }
  9256. }
  9257. function detectTheming(options) {
  9258. // Once the user specifies a targetEvent, we will automatically try to find the correct
  9259. // nested theme.
  9260. var targetEl;
  9261. if (options.targetEvent && options.targetEvent.target) {
  9262. targetEl = angular.element(options.targetEvent.target);
  9263. }
  9264. var themeCtrl = targetEl && targetEl.controller('mdTheme');
  9265. options.hasTheme = (!!themeCtrl);
  9266. if (!options.hasTheme) {
  9267. return;
  9268. }
  9269. options.themeWatch = themeCtrl.$shouldWatch;
  9270. var theme = options.theme || themeCtrl.$mdTheme;
  9271. if (theme) {
  9272. options.scope.theme = theme;
  9273. }
  9274. var unwatch = themeCtrl.registerChanges(function (newTheme) {
  9275. options.scope.theme = newTheme;
  9276. if (!options.themeWatch) {
  9277. unwatch();
  9278. }
  9279. });
  9280. }
  9281. /**
  9282. * Capture originator/trigger/from/to element information (if available)
  9283. * and the parent container for the dialog; defaults to the $rootElement
  9284. * unless overridden in the options.parent
  9285. */
  9286. function captureParentAndFromToElements(options) {
  9287. options.origin = angular.extend({
  9288. element: null,
  9289. bounds: null,
  9290. focus: angular.noop
  9291. }, options.origin || {});
  9292. options.parent = getDomElement(options.parent, $rootElement);
  9293. options.closeTo = getBoundingClientRect(getDomElement(options.closeTo));
  9294. options.openFrom = getBoundingClientRect(getDomElement(options.openFrom));
  9295. if ( options.targetEvent ) {
  9296. options.origin = getBoundingClientRect(options.targetEvent.target, options.origin);
  9297. options.originInteraction = $mdInteraction.getLastInteractionType();
  9298. }
  9299. /**
  9300. * Identify the bounding RECT for the target element
  9301. *
  9302. */
  9303. function getBoundingClientRect (element, orig) {
  9304. var source = angular.element((element || {}));
  9305. if (source && source.length) {
  9306. // Compute and save the target element's bounding rect, so that if the
  9307. // element is hidden when the dialog closes, we can shrink the dialog
  9308. // back to the same position it expanded from.
  9309. //
  9310. // Checking if the source is a rect object or a DOM element
  9311. var bounds = {top:0,left:0,height:0,width:0};
  9312. var hasFn = angular.isFunction(source[0].getBoundingClientRect);
  9313. return angular.extend(orig || {}, {
  9314. element : hasFn ? source : undefined,
  9315. bounds : hasFn ? source[0].getBoundingClientRect() : angular.extend({}, bounds, source[0]),
  9316. focus : angular.bind(source, source.focus),
  9317. });
  9318. }
  9319. }
  9320. /**
  9321. * If the specifier is a simple string selector, then query for
  9322. * the DOM element.
  9323. */
  9324. function getDomElement(element, defaultElement) {
  9325. if (angular.isString(element)) {
  9326. element = $document[0].querySelector(element);
  9327. }
  9328. // If we have a reference to a raw dom element, always wrap it in jqLite
  9329. return angular.element(element || defaultElement);
  9330. }
  9331. }
  9332. /**
  9333. * Listen for escape keys and outside clicks to auto close
  9334. */
  9335. function activateListeners(element, options) {
  9336. var window = angular.element($window);
  9337. var onWindowResize = $mdUtil.debounce(function() {
  9338. stretchDialogContainerToViewport(element, options);
  9339. }, 60);
  9340. var removeListeners = [];
  9341. var smartClose = function() {
  9342. // Only 'confirm' dialogs have a cancel button... escape/clickOutside will
  9343. // cancel or fallback to hide.
  9344. var closeFn = ( options.$type == 'alert' ) ? $mdDialog.hide : $mdDialog.cancel;
  9345. $mdUtil.nextTick(closeFn, true);
  9346. };
  9347. if (options.escapeToClose) {
  9348. var parentTarget = options.parent;
  9349. var keyHandlerFn = function(ev) {
  9350. if (ev.keyCode === $mdConstant.KEY_CODE.ESCAPE) {
  9351. ev.stopPropagation();
  9352. ev.preventDefault();
  9353. smartClose();
  9354. }
  9355. };
  9356. // Add keydown listeners
  9357. element.on('keydown', keyHandlerFn);
  9358. parentTarget.on('keydown', keyHandlerFn);
  9359. // Queue remove listeners function
  9360. removeListeners.push(function() {
  9361. element.off('keydown', keyHandlerFn);
  9362. parentTarget.off('keydown', keyHandlerFn);
  9363. });
  9364. }
  9365. // Register listener to update dialog on window resize
  9366. window.on('resize', onWindowResize);
  9367. removeListeners.push(function() {
  9368. window.off('resize', onWindowResize);
  9369. });
  9370. if (options.clickOutsideToClose) {
  9371. var target = element;
  9372. var sourceElem;
  9373. // Keep track of the element on which the mouse originally went down
  9374. // so that we can only close the backdrop when the 'click' started on it.
  9375. // A simple 'click' handler does not work,
  9376. // it sets the target object as the element the mouse went down on.
  9377. var mousedownHandler = function(ev) {
  9378. sourceElem = ev.target;
  9379. };
  9380. // We check if our original element and the target is the backdrop
  9381. // because if the original was the backdrop and the target was inside the dialog
  9382. // we don't want to dialog to close.
  9383. var mouseupHandler = function(ev) {
  9384. if (sourceElem === target[0] && ev.target === target[0]) {
  9385. ev.stopPropagation();
  9386. ev.preventDefault();
  9387. smartClose();
  9388. }
  9389. };
  9390. // Add listeners
  9391. target.on('mousedown', mousedownHandler);
  9392. target.on('mouseup', mouseupHandler);
  9393. // Queue remove listeners function
  9394. removeListeners.push(function() {
  9395. target.off('mousedown', mousedownHandler);
  9396. target.off('mouseup', mouseupHandler);
  9397. });
  9398. }
  9399. // Attach specific `remove` listener handler
  9400. options.deactivateListeners = function() {
  9401. removeListeners.forEach(function(removeFn) {
  9402. removeFn();
  9403. });
  9404. options.deactivateListeners = null;
  9405. };
  9406. }
  9407. /**
  9408. * Show modal backdrop element...
  9409. */
  9410. function showBackdrop(scope, element, options) {
  9411. if (options.disableParentScroll) {
  9412. // !! DO this before creating the backdrop; since disableScrollAround()
  9413. // configures the scroll offset; which is used by mdBackDrop postLink()
  9414. options.restoreScroll = $mdUtil.disableScrollAround(element, options.parent);
  9415. }
  9416. if (options.hasBackdrop) {
  9417. options.backdrop = $mdUtil.createBackdrop(scope, "md-dialog-backdrop md-opaque");
  9418. $animate.enter(options.backdrop, options.parent);
  9419. }
  9420. /**
  9421. * Hide modal backdrop element...
  9422. */
  9423. options.hideBackdrop = function hideBackdrop($destroy) {
  9424. if (options.backdrop) {
  9425. if ( $destroy ) options.backdrop.remove();
  9426. else $animate.leave(options.backdrop);
  9427. }
  9428. if (options.disableParentScroll) {
  9429. options.restoreScroll && options.restoreScroll();
  9430. delete options.restoreScroll;
  9431. }
  9432. options.hideBackdrop = null;
  9433. };
  9434. }
  9435. /**
  9436. * Inject ARIA-specific attributes appropriate for Dialogs
  9437. */
  9438. function configureAria(element, options) {
  9439. var role = (options.$type === 'alert') ? 'alertdialog' : 'dialog';
  9440. var dialogContent = element.find('md-dialog-content');
  9441. var existingDialogId = element.attr('id');
  9442. var dialogContentId = 'dialogContent_' + (existingDialogId || $mdUtil.nextUid());
  9443. element.attr({
  9444. 'role': role,
  9445. 'tabIndex': '-1'
  9446. });
  9447. if (dialogContent.length === 0) {
  9448. dialogContent = element;
  9449. // If the dialog element already had an ID, don't clobber it.
  9450. if (existingDialogId) {
  9451. dialogContentId = existingDialogId;
  9452. }
  9453. }
  9454. dialogContent.attr('id', dialogContentId);
  9455. element.attr('aria-describedby', dialogContentId);
  9456. if (options.ariaLabel) {
  9457. $mdAria.expect(element, 'aria-label', options.ariaLabel);
  9458. }
  9459. else {
  9460. $mdAria.expectAsync(element, 'aria-label', function() {
  9461. // If dialog title is specified, set aria-label with it
  9462. // See https://github.com/angular/material/issues/10582
  9463. if (options.title) {
  9464. return options.title;
  9465. } else {
  9466. var words = dialogContent.text().split(/\s+/);
  9467. if (words.length > 3) words = words.slice(0, 3).concat('...');
  9468. return words.join(' ');
  9469. }
  9470. });
  9471. }
  9472. // Set up elements before and after the dialog content to capture focus and
  9473. // redirect back into the dialog.
  9474. topFocusTrap = document.createElement('div');
  9475. topFocusTrap.classList.add('md-dialog-focus-trap');
  9476. topFocusTrap.tabIndex = 0;
  9477. bottomFocusTrap = topFocusTrap.cloneNode(false);
  9478. // When focus is about to move out of the dialog, we want to intercept it and redirect it
  9479. // back to the dialog element.
  9480. var focusHandler = function() {
  9481. element.focus();
  9482. };
  9483. topFocusTrap.addEventListener('focus', focusHandler);
  9484. bottomFocusTrap.addEventListener('focus', focusHandler);
  9485. // The top focus trap inserted immeidately before the md-dialog element (as a sibling).
  9486. // The bottom focus trap is inserted at the very end of the md-dialog element (as a child).
  9487. element[0].parentNode.insertBefore(topFocusTrap, element[0]);
  9488. element.after(bottomFocusTrap);
  9489. }
  9490. /**
  9491. * Prevents screen reader interaction behind modal window
  9492. * on swipe interfaces
  9493. */
  9494. function lockScreenReader(element, options) {
  9495. var isHidden = true;
  9496. // get raw DOM node
  9497. walkDOM(element[0]);
  9498. options.unlockScreenReader = function () {
  9499. isHidden = false;
  9500. walkDOM(element[0]);
  9501. options.unlockScreenReader = null;
  9502. };
  9503. /**
  9504. * Get all of an element's parent elements up the DOM tree
  9505. * @return {Array} The parent elements
  9506. */
  9507. function getParents(element) {
  9508. var parents = [];
  9509. while (element.parentNode) {
  9510. if (element === document.body) {
  9511. return parents;
  9512. }
  9513. var children = element.parentNode.children;
  9514. for (var i = 0; i < children.length; i++) {
  9515. // skip over child if it is an ascendant of the dialog
  9516. // a script or style tag, or a live region.
  9517. if (element !== children[i] &&
  9518. !isNodeOneOf(children[i], ['SCRIPT', 'STYLE']) &&
  9519. !children[i].hasAttribute('aria-live')) {
  9520. parents.push(children[i]);
  9521. }
  9522. }
  9523. element = element.parentNode;
  9524. }
  9525. return parents;
  9526. }
  9527. /**
  9528. * Walk DOM to apply or remove aria-hidden on sibling nodes
  9529. * and parent sibling nodes
  9530. */
  9531. function walkDOM(element) {
  9532. var elements = getParents(element);
  9533. for (var i = 0; i < elements.length; i++) {
  9534. elements[i].setAttribute('aria-hidden', isHidden);
  9535. }
  9536. }
  9537. }
  9538. /**
  9539. * Ensure the dialog container fill-stretches to the viewport
  9540. */
  9541. function stretchDialogContainerToViewport(container, options) {
  9542. var isFixed = $window.getComputedStyle($document[0].body).position == 'fixed';
  9543. var backdrop = options.backdrop ? $window.getComputedStyle(options.backdrop[0]) : null;
  9544. var height = backdrop ? Math.min($document[0].body.clientHeight, Math.ceil(Math.abs(parseInt(backdrop.height, 10)))) : 0;
  9545. var previousStyles = {
  9546. top: container.css('top'),
  9547. height: container.css('height')
  9548. };
  9549. // If the body is fixed, determine the distance to the viewport in relative from the parent.
  9550. var parentTop = Math.abs(options.parent[0].getBoundingClientRect().top);
  9551. container.css({
  9552. top: (isFixed ? parentTop : 0) + 'px',
  9553. height: height ? height + 'px' : '100%'
  9554. });
  9555. return function() {
  9556. // Reverts the modified styles back to the previous values.
  9557. // This is needed for contentElements, which should have the same styles after close
  9558. // as before.
  9559. container.css(previousStyles);
  9560. };
  9561. }
  9562. /**
  9563. * Dialog open and pop-in animation
  9564. */
  9565. function dialogPopIn(container, options) {
  9566. // Add the `md-dialog-container` to the DOM
  9567. options.parent.append(container);
  9568. options.reverseContainerStretch = stretchDialogContainerToViewport(container, options);
  9569. var dialogEl = container.find('md-dialog');
  9570. var animator = $mdUtil.dom.animator;
  9571. var buildTranslateToOrigin = animator.calculateZoomToOrigin;
  9572. var translateOptions = {transitionInClass: 'md-transition-in', transitionOutClass: 'md-transition-out'};
  9573. var from = animator.toTransformCss(buildTranslateToOrigin(dialogEl, options.openFrom || options.origin));
  9574. var to = animator.toTransformCss(""); // defaults to center display (or parent or $rootElement)
  9575. dialogEl.toggleClass('md-dialog-fullscreen', !!options.fullscreen);
  9576. return animator
  9577. .translate3d(dialogEl, from, to, translateOptions)
  9578. .then(function(animateReversal) {
  9579. // Build a reversal translate function synced to this translation...
  9580. options.reverseAnimate = function() {
  9581. delete options.reverseAnimate;
  9582. if (options.closeTo) {
  9583. // Using the opposite classes to create a close animation to the closeTo element
  9584. translateOptions = {transitionInClass: 'md-transition-out', transitionOutClass: 'md-transition-in'};
  9585. from = to;
  9586. to = animator.toTransformCss(buildTranslateToOrigin(dialogEl, options.closeTo));
  9587. return animator
  9588. .translate3d(dialogEl, from, to,translateOptions);
  9589. }
  9590. return animateReversal(
  9591. to = animator.toTransformCss(
  9592. // in case the origin element has moved or is hidden,
  9593. // let's recalculate the translateCSS
  9594. buildTranslateToOrigin(dialogEl, options.origin)
  9595. )
  9596. );
  9597. };
  9598. // Function to revert the generated animation styles on the dialog element.
  9599. // Useful when using a contentElement instead of a template.
  9600. options.clearAnimate = function() {
  9601. delete options.clearAnimate;
  9602. // Remove the transition classes, added from $animateCSS, since those can't be removed
  9603. // by reversely running the animator.
  9604. dialogEl.removeClass([
  9605. translateOptions.transitionOutClass,
  9606. translateOptions.transitionInClass
  9607. ].join(' '));
  9608. // Run the animation reversely to remove the previous added animation styles.
  9609. return animator.translate3d(dialogEl, to, animator.toTransformCss(''), {});
  9610. };
  9611. return true;
  9612. });
  9613. }
  9614. /**
  9615. * Dialog close and pop-out animation
  9616. */
  9617. function dialogPopOut(container, options) {
  9618. return options.reverseAnimate().then(function() {
  9619. if (options.contentElement) {
  9620. // When we use a contentElement, we want the element to be the same as before.
  9621. // That means, that we have to clear all the animation properties, like transform.
  9622. options.clearAnimate();
  9623. }
  9624. });
  9625. }
  9626. /**
  9627. * Utility function to filter out raw DOM nodes
  9628. */
  9629. function isNodeOneOf(elem, nodeTypeArray) {
  9630. if (nodeTypeArray.indexOf(elem.nodeName) !== -1) {
  9631. return true;
  9632. }
  9633. }
  9634. }
  9635. }
  9636. })();
  9637. (function(){
  9638. "use strict";
  9639. /**
  9640. * @ngdoc module
  9641. * @name material.components.divider
  9642. * @description Divider module!
  9643. */
  9644. MdDividerDirective.$inject = ["$mdTheming"];
  9645. angular.module('material.components.divider', [
  9646. 'material.core'
  9647. ])
  9648. .directive('mdDivider', MdDividerDirective);
  9649. /**
  9650. * @ngdoc directive
  9651. * @name mdDivider
  9652. * @module material.components.divider
  9653. * @restrict E
  9654. *
  9655. * @description
  9656. * Dividers group and separate content within lists and page layouts using strong visual and spatial distinctions. This divider is a thin rule, lightweight enough to not distract the user from content.
  9657. *
  9658. * @param {boolean=} md-inset Add this attribute to activate the inset divider style.
  9659. * @usage
  9660. * <hljs lang="html">
  9661. * <md-divider></md-divider>
  9662. *
  9663. * <md-divider md-inset></md-divider>
  9664. * </hljs>
  9665. *
  9666. */
  9667. function MdDividerDirective($mdTheming) {
  9668. return {
  9669. restrict: 'E',
  9670. link: $mdTheming
  9671. };
  9672. }
  9673. })();
  9674. (function(){
  9675. "use strict";
  9676. (function() {
  9677. 'use strict';
  9678. /**
  9679. * @ngdoc module
  9680. * @name material.components.fabActions
  9681. */
  9682. MdFabActionsDirective.$inject = ["$mdUtil"];
  9683. angular
  9684. .module('material.components.fabActions', ['material.core'])
  9685. .directive('mdFabActions', MdFabActionsDirective);
  9686. /**
  9687. * @ngdoc directive
  9688. * @name mdFabActions
  9689. * @module material.components.fabActions
  9690. *
  9691. * @restrict E
  9692. *
  9693. * @description
  9694. * The `<md-fab-actions>` directive is used inside of a `<md-fab-speed-dial>` or
  9695. * `<md-fab-toolbar>` directive to mark an element (or elements) as the actions and setup the
  9696. * proper event listeners.
  9697. *
  9698. * @usage
  9699. * See the `<md-fab-speed-dial>` or `<md-fab-toolbar>` directives for example usage.
  9700. */
  9701. function MdFabActionsDirective($mdUtil) {
  9702. return {
  9703. restrict: 'E',
  9704. require: ['^?mdFabSpeedDial', '^?mdFabToolbar'],
  9705. compile: function(element, attributes) {
  9706. var children = element.children();
  9707. var hasNgRepeat = $mdUtil.prefixer().hasAttribute(children, 'ng-repeat');
  9708. // Support both ng-repeat and static content
  9709. if (hasNgRepeat) {
  9710. children.addClass('md-fab-action-item');
  9711. } else {
  9712. // Wrap every child in a new div and add a class that we can scale/fling independently
  9713. children.wrap('<div class="md-fab-action-item">');
  9714. }
  9715. }
  9716. };
  9717. }
  9718. })();
  9719. })();
  9720. (function(){
  9721. "use strict";
  9722. (function() {
  9723. 'use strict';
  9724. MdFabController.$inject = ["$scope", "$element", "$animate", "$mdUtil", "$mdConstant", "$timeout"];
  9725. angular.module('material.components.fabShared', ['material.core'])
  9726. .controller('MdFabController', MdFabController);
  9727. function MdFabController($scope, $element, $animate, $mdUtil, $mdConstant, $timeout) {
  9728. var vm = this;
  9729. var initialAnimationAttempts = 0;
  9730. // NOTE: We use async eval(s) below to avoid conflicts with any existing digest loops
  9731. vm.open = function() {
  9732. $scope.$evalAsync("vm.isOpen = true");
  9733. };
  9734. vm.close = function() {
  9735. // Async eval to avoid conflicts with existing digest loops
  9736. $scope.$evalAsync("vm.isOpen = false");
  9737. // Focus the trigger when the element closes so users can still tab to the next item
  9738. $element.find('md-fab-trigger')[0].focus();
  9739. };
  9740. // Toggle the open/close state when the trigger is clicked
  9741. vm.toggle = function() {
  9742. $scope.$evalAsync("vm.isOpen = !vm.isOpen");
  9743. };
  9744. /*
  9745. * AngularJS Lifecycle hook for newer AngularJS versions.
  9746. * Bindings are not guaranteed to have been assigned in the controller, but they are in the $onInit hook.
  9747. */
  9748. vm.$onInit = function() {
  9749. setupDefaults();
  9750. setupListeners();
  9751. setupWatchers();
  9752. fireInitialAnimations();
  9753. };
  9754. // For AngularJS 1.4 and older, where there are no lifecycle hooks but bindings are pre-assigned,
  9755. // manually call the $onInit hook.
  9756. if (angular.version.major === 1 && angular.version.minor <= 4) {
  9757. this.$onInit();
  9758. }
  9759. function setupDefaults() {
  9760. // Set the default direction to 'down' if none is specified
  9761. vm.direction = vm.direction || 'down';
  9762. // Set the default to be closed
  9763. vm.isOpen = vm.isOpen || false;
  9764. // Start the keyboard interaction at the first action
  9765. resetActionIndex();
  9766. // Add an animations waiting class so we know not to run
  9767. $element.addClass('md-animations-waiting');
  9768. }
  9769. function setupListeners() {
  9770. var eventTypes = [
  9771. 'click', 'focusin', 'focusout'
  9772. ];
  9773. // Add our listeners
  9774. angular.forEach(eventTypes, function(eventType) {
  9775. $element.on(eventType, parseEvents);
  9776. });
  9777. // Remove our listeners when destroyed
  9778. $scope.$on('$destroy', function() {
  9779. angular.forEach(eventTypes, function(eventType) {
  9780. $element.off(eventType, parseEvents);
  9781. });
  9782. // remove any attached keyboard handlers in case element is removed while
  9783. // speed dial is open
  9784. disableKeyboard();
  9785. });
  9786. }
  9787. var closeTimeout;
  9788. function parseEvents(event) {
  9789. // If the event is a click, just handle it
  9790. if (event.type == 'click') {
  9791. handleItemClick(event);
  9792. }
  9793. // If we focusout, set a timeout to close the element
  9794. if (event.type == 'focusout' && !closeTimeout) {
  9795. closeTimeout = $timeout(function() {
  9796. vm.close();
  9797. }, 100, false);
  9798. }
  9799. // If we see a focusin and there is a timeout about to run, cancel it so we stay open
  9800. if (event.type == 'focusin' && closeTimeout) {
  9801. $timeout.cancel(closeTimeout);
  9802. closeTimeout = null;
  9803. }
  9804. }
  9805. function resetActionIndex() {
  9806. vm.currentActionIndex = -1;
  9807. }
  9808. function setupWatchers() {
  9809. // Watch for changes to the direction and update classes/attributes
  9810. $scope.$watch('vm.direction', function(newDir, oldDir) {
  9811. // Add the appropriate classes so we can target the direction in the CSS
  9812. $animate.removeClass($element, 'md-' + oldDir);
  9813. $animate.addClass($element, 'md-' + newDir);
  9814. // Reset the action index since it may have changed
  9815. resetActionIndex();
  9816. });
  9817. var trigger, actions;
  9818. // Watch for changes to md-open
  9819. $scope.$watch('vm.isOpen', function(isOpen) {
  9820. // Reset the action index since it may have changed
  9821. resetActionIndex();
  9822. // We can't get the trigger/actions outside of the watch because the component hasn't been
  9823. // linked yet, so we wait until the first watch fires to cache them.
  9824. if (!trigger || !actions) {
  9825. trigger = getTriggerElement();
  9826. actions = getActionsElement();
  9827. }
  9828. if (isOpen) {
  9829. enableKeyboard();
  9830. } else {
  9831. disableKeyboard();
  9832. }
  9833. var toAdd = isOpen ? 'md-is-open' : '';
  9834. var toRemove = isOpen ? '' : 'md-is-open';
  9835. // Set the proper ARIA attributes
  9836. trigger.attr('aria-haspopup', true);
  9837. trigger.attr('aria-expanded', isOpen);
  9838. actions.attr('aria-hidden', !isOpen);
  9839. // Animate the CSS classes
  9840. $animate.setClass($element, toAdd, toRemove);
  9841. });
  9842. }
  9843. function fireInitialAnimations() {
  9844. // If the element is actually visible on the screen
  9845. if ($element[0].scrollHeight > 0) {
  9846. // Fire our animation
  9847. $animate.addClass($element, '_md-animations-ready').then(function() {
  9848. // Remove the waiting class
  9849. $element.removeClass('md-animations-waiting');
  9850. });
  9851. }
  9852. // Otherwise, try for up to 1 second before giving up
  9853. else if (initialAnimationAttempts < 10) {
  9854. $timeout(fireInitialAnimations, 100);
  9855. // Increment our counter
  9856. initialAnimationAttempts = initialAnimationAttempts + 1;
  9857. }
  9858. }
  9859. function enableKeyboard() {
  9860. $element.on('keydown', keyPressed);
  9861. // On the next tick, setup a check for outside clicks; we do this on the next tick to avoid
  9862. // clicks/touches that result in the isOpen attribute changing (e.g. a bound radio button)
  9863. $mdUtil.nextTick(function() {
  9864. angular.element(document).on('click touchend', checkForOutsideClick);
  9865. });
  9866. // TODO: On desktop, we should be able to reset the indexes so you cannot tab through, but
  9867. // this breaks accessibility, especially on mobile, since you have no arrow keys to press
  9868. //resetActionTabIndexes();
  9869. }
  9870. function disableKeyboard() {
  9871. $element.off('keydown', keyPressed);
  9872. angular.element(document).off('click touchend', checkForOutsideClick);
  9873. }
  9874. function checkForOutsideClick(event) {
  9875. if (event.target) {
  9876. var closestTrigger = $mdUtil.getClosest(event.target, 'md-fab-trigger');
  9877. var closestActions = $mdUtil.getClosest(event.target, 'md-fab-actions');
  9878. if (!closestTrigger && !closestActions) {
  9879. vm.close();
  9880. }
  9881. }
  9882. }
  9883. function keyPressed(event) {
  9884. switch (event.which) {
  9885. case $mdConstant.KEY_CODE.ESCAPE: vm.close(); event.preventDefault(); return false;
  9886. case $mdConstant.KEY_CODE.LEFT_ARROW: doKeyLeft(event); return false;
  9887. case $mdConstant.KEY_CODE.UP_ARROW: doKeyUp(event); return false;
  9888. case $mdConstant.KEY_CODE.RIGHT_ARROW: doKeyRight(event); return false;
  9889. case $mdConstant.KEY_CODE.DOWN_ARROW: doKeyDown(event); return false;
  9890. }
  9891. }
  9892. function doActionPrev(event) {
  9893. focusAction(event, -1);
  9894. }
  9895. function doActionNext(event) {
  9896. focusAction(event, 1);
  9897. }
  9898. function focusAction(event, direction) {
  9899. var actions = resetActionTabIndexes();
  9900. // Increment/decrement the counter with restrictions
  9901. vm.currentActionIndex = vm.currentActionIndex + direction;
  9902. vm.currentActionIndex = Math.min(actions.length - 1, vm.currentActionIndex);
  9903. vm.currentActionIndex = Math.max(0, vm.currentActionIndex);
  9904. // Focus the element
  9905. var focusElement = angular.element(actions[vm.currentActionIndex]).children()[0];
  9906. angular.element(focusElement).attr('tabindex', 0);
  9907. focusElement.focus();
  9908. // Make sure the event doesn't bubble and cause something else
  9909. event.preventDefault();
  9910. event.stopImmediatePropagation();
  9911. }
  9912. function resetActionTabIndexes() {
  9913. // Grab all of the actions
  9914. var actions = getActionsElement()[0].querySelectorAll('.md-fab-action-item');
  9915. // Disable all other actions for tabbing
  9916. angular.forEach(actions, function(action) {
  9917. angular.element(angular.element(action).children()[0]).attr('tabindex', -1);
  9918. });
  9919. return actions;
  9920. }
  9921. function doKeyLeft(event) {
  9922. if (vm.direction === 'left') {
  9923. doActionNext(event);
  9924. } else {
  9925. doActionPrev(event);
  9926. }
  9927. }
  9928. function doKeyUp(event) {
  9929. if (vm.direction === 'down') {
  9930. doActionPrev(event);
  9931. } else {
  9932. doActionNext(event);
  9933. }
  9934. }
  9935. function doKeyRight(event) {
  9936. if (vm.direction === 'left') {
  9937. doActionPrev(event);
  9938. } else {
  9939. doActionNext(event);
  9940. }
  9941. }
  9942. function doKeyDown(event) {
  9943. if (vm.direction === 'up') {
  9944. doActionPrev(event);
  9945. } else {
  9946. doActionNext(event);
  9947. }
  9948. }
  9949. function isTrigger(element) {
  9950. return $mdUtil.getClosest(element, 'md-fab-trigger');
  9951. }
  9952. function isAction(element) {
  9953. return $mdUtil.getClosest(element, 'md-fab-actions');
  9954. }
  9955. function handleItemClick(event) {
  9956. if (isTrigger(event.target)) {
  9957. vm.toggle();
  9958. }
  9959. if (isAction(event.target)) {
  9960. vm.close();
  9961. }
  9962. }
  9963. function getTriggerElement() {
  9964. return $element.find('md-fab-trigger');
  9965. }
  9966. function getActionsElement() {
  9967. return $element.find('md-fab-actions');
  9968. }
  9969. }
  9970. })();
  9971. })();
  9972. (function(){
  9973. "use strict";
  9974. (function() {
  9975. 'use strict';
  9976. /**
  9977. * The duration of the CSS animation in milliseconds.
  9978. *
  9979. * @type {number}
  9980. */
  9981. MdFabSpeedDialFlingAnimation.$inject = ["$timeout"];
  9982. MdFabSpeedDialScaleAnimation.$inject = ["$timeout"];
  9983. var cssAnimationDuration = 300;
  9984. /**
  9985. * @ngdoc module
  9986. * @name material.components.fabSpeedDial
  9987. */
  9988. angular
  9989. // Declare our module
  9990. .module('material.components.fabSpeedDial', [
  9991. 'material.core',
  9992. 'material.components.fabShared',
  9993. 'material.components.fabActions'
  9994. ])
  9995. // Register our directive
  9996. .directive('mdFabSpeedDial', MdFabSpeedDialDirective)
  9997. // Register our custom animations
  9998. .animation('.md-fling', MdFabSpeedDialFlingAnimation)
  9999. .animation('.md-scale', MdFabSpeedDialScaleAnimation)
  10000. // Register a service for each animation so that we can easily inject them into unit tests
  10001. .service('mdFabSpeedDialFlingAnimation', MdFabSpeedDialFlingAnimation)
  10002. .service('mdFabSpeedDialScaleAnimation', MdFabSpeedDialScaleAnimation);
  10003. /**
  10004. * @ngdoc directive
  10005. * @name mdFabSpeedDial
  10006. * @module material.components.fabSpeedDial
  10007. *
  10008. * @restrict E
  10009. *
  10010. * @description
  10011. * The `<md-fab-speed-dial>` directive is used to present a series of popup elements (usually
  10012. * `<md-button>`s) for quick access to common actions.
  10013. *
  10014. * There are currently two animations available by applying one of the following classes to
  10015. * the component:
  10016. *
  10017. * - `md-fling` - The speed dial items appear from underneath the trigger and move into their
  10018. * appropriate positions.
  10019. * - `md-scale` - The speed dial items appear in their proper places by scaling from 0% to 100%.
  10020. *
  10021. * You may also easily position the trigger by applying one one of the following classes to the
  10022. * `<md-fab-speed-dial>` element:
  10023. * - `md-fab-top-left`
  10024. * - `md-fab-top-right`
  10025. * - `md-fab-bottom-left`
  10026. * - `md-fab-bottom-right`
  10027. *
  10028. * These CSS classes use `position: absolute`, so you need to ensure that the container element
  10029. * also uses `position: absolute` or `position: relative` in order for them to work.
  10030. *
  10031. * Additionally, you may use the standard `ng-mouseenter` and `ng-mouseleave` directives to
  10032. * open or close the speed dial. However, if you wish to allow users to hover over the empty
  10033. * space where the actions will appear, you must also add the `md-hover-full` class to the speed
  10034. * dial element. Without this, the hover effect will only occur on top of the trigger.
  10035. *
  10036. * See the demos for more information.
  10037. *
  10038. * ## Troubleshooting
  10039. *
  10040. * If your speed dial shows the closing animation upon launch, you may need to use `ng-cloak` on
  10041. * the parent container to ensure that it is only visible once ready. We have plans to remove this
  10042. * necessity in the future.
  10043. *
  10044. * @usage
  10045. * <hljs lang="html">
  10046. * <md-fab-speed-dial md-direction="up" class="md-fling">
  10047. * <md-fab-trigger>
  10048. * <md-button aria-label="Add..."><md-icon md-svg-src="/img/icons/plus.svg"></md-icon></md-button>
  10049. * </md-fab-trigger>
  10050. *
  10051. * <md-fab-actions>
  10052. * <md-button aria-label="Add User">
  10053. * <md-icon md-svg-src="/img/icons/user.svg"></md-icon>
  10054. * </md-button>
  10055. *
  10056. * <md-button aria-label="Add Group">
  10057. * <md-icon md-svg-src="/img/icons/group.svg"></md-icon>
  10058. * </md-button>
  10059. * </md-fab-actions>
  10060. * </md-fab-speed-dial>
  10061. * </hljs>
  10062. *
  10063. * @param {string} md-direction From which direction you would like the speed dial to appear
  10064. * relative to the trigger element.
  10065. * @param {expression=} md-open Programmatically control whether or not the speed-dial is visible.
  10066. */
  10067. function MdFabSpeedDialDirective() {
  10068. return {
  10069. restrict: 'E',
  10070. scope: {
  10071. direction: '@?mdDirection',
  10072. isOpen: '=?mdOpen'
  10073. },
  10074. bindToController: true,
  10075. controller: 'MdFabController',
  10076. controllerAs: 'vm',
  10077. link: FabSpeedDialLink
  10078. };
  10079. function FabSpeedDialLink(scope, element) {
  10080. // Prepend an element to hold our CSS variables so we can use them in the animations below
  10081. element.prepend('<div class="_md-css-variables"></div>');
  10082. }
  10083. }
  10084. function MdFabSpeedDialFlingAnimation($timeout) {
  10085. function delayDone(done) { $timeout(done, cssAnimationDuration, false); }
  10086. function runAnimation(element) {
  10087. // Don't run if we are still waiting and we are not ready
  10088. if (element.hasClass('md-animations-waiting') && !element.hasClass('_md-animations-ready')) {
  10089. return;
  10090. }
  10091. var el = element[0];
  10092. var ctrl = element.controller('mdFabSpeedDial');
  10093. var items = el.querySelectorAll('.md-fab-action-item');
  10094. // Grab our trigger element
  10095. var triggerElement = el.querySelector('md-fab-trigger');
  10096. // Grab our element which stores CSS variables
  10097. var variablesElement = el.querySelector('._md-css-variables');
  10098. // Setup JS variables based on our CSS variables
  10099. var startZIndex = parseInt(window.getComputedStyle(variablesElement).zIndex);
  10100. // Always reset the items to their natural position/state
  10101. angular.forEach(items, function(item, index) {
  10102. var styles = item.style;
  10103. styles.transform = styles.webkitTransform = '';
  10104. styles.transitionDelay = '';
  10105. styles.opacity = 1;
  10106. // Make the items closest to the trigger have the highest z-index
  10107. styles.zIndex = (items.length - index) + startZIndex;
  10108. });
  10109. // Set the trigger to be above all of the actions so they disappear behind it.
  10110. triggerElement.style.zIndex = startZIndex + items.length + 1;
  10111. // If the control is closed, hide the items behind the trigger
  10112. if (!ctrl.isOpen) {
  10113. angular.forEach(items, function(item, index) {
  10114. var newPosition, axis;
  10115. var styles = item.style;
  10116. // Make sure to account for differences in the dimensions of the trigger verses the items
  10117. // so that we can properly center everything; this helps hide the item's shadows behind
  10118. // the trigger.
  10119. var triggerItemHeightOffset = (triggerElement.clientHeight - item.clientHeight) / 2;
  10120. var triggerItemWidthOffset = (triggerElement.clientWidth - item.clientWidth) / 2;
  10121. switch (ctrl.direction) {
  10122. case 'up':
  10123. newPosition = (item.scrollHeight * (index + 1) + triggerItemHeightOffset);
  10124. axis = 'Y';
  10125. break;
  10126. case 'down':
  10127. newPosition = -(item.scrollHeight * (index + 1) + triggerItemHeightOffset);
  10128. axis = 'Y';
  10129. break;
  10130. case 'left':
  10131. newPosition = (item.scrollWidth * (index + 1) + triggerItemWidthOffset);
  10132. axis = 'X';
  10133. break;
  10134. case 'right':
  10135. newPosition = -(item.scrollWidth * (index + 1) + triggerItemWidthOffset);
  10136. axis = 'X';
  10137. break;
  10138. }
  10139. var newTranslate = 'translate' + axis + '(' + newPosition + 'px)';
  10140. styles.transform = styles.webkitTransform = newTranslate;
  10141. });
  10142. }
  10143. }
  10144. return {
  10145. addClass: function(element, className, done) {
  10146. if (element.hasClass('md-fling')) {
  10147. runAnimation(element);
  10148. delayDone(done);
  10149. } else {
  10150. done();
  10151. }
  10152. },
  10153. removeClass: function(element, className, done) {
  10154. runAnimation(element);
  10155. delayDone(done);
  10156. }
  10157. };
  10158. }
  10159. function MdFabSpeedDialScaleAnimation($timeout) {
  10160. function delayDone(done) { $timeout(done, cssAnimationDuration, false); }
  10161. var delay = 65;
  10162. function runAnimation(element) {
  10163. var el = element[0];
  10164. var ctrl = element.controller('mdFabSpeedDial');
  10165. var items = el.querySelectorAll('.md-fab-action-item');
  10166. // Grab our element which stores CSS variables
  10167. var variablesElement = el.querySelector('._md-css-variables');
  10168. // Setup JS variables based on our CSS variables
  10169. var startZIndex = parseInt(window.getComputedStyle(variablesElement).zIndex);
  10170. // Always reset the items to their natural position/state
  10171. angular.forEach(items, function(item, index) {
  10172. var styles = item.style,
  10173. offsetDelay = index * delay;
  10174. styles.opacity = ctrl.isOpen ? 1 : 0;
  10175. styles.transform = styles.webkitTransform = ctrl.isOpen ? 'scale(1)' : 'scale(0)';
  10176. styles.transitionDelay = (ctrl.isOpen ? offsetDelay : (items.length - offsetDelay)) + 'ms';
  10177. // Make the items closest to the trigger have the highest z-index
  10178. styles.zIndex = (items.length - index) + startZIndex;
  10179. });
  10180. }
  10181. return {
  10182. addClass: function(element, className, done) {
  10183. runAnimation(element);
  10184. delayDone(done);
  10185. },
  10186. removeClass: function(element, className, done) {
  10187. runAnimation(element);
  10188. delayDone(done);
  10189. }
  10190. };
  10191. }
  10192. })();
  10193. })();
  10194. (function(){
  10195. "use strict";
  10196. (function() {
  10197. 'use strict';
  10198. /**
  10199. * @ngdoc module
  10200. * @name material.components.fabToolbar
  10201. */
  10202. angular
  10203. // Declare our module
  10204. .module('material.components.fabToolbar', [
  10205. 'material.core',
  10206. 'material.components.fabShared',
  10207. 'material.components.fabActions'
  10208. ])
  10209. // Register our directive
  10210. .directive('mdFabToolbar', MdFabToolbarDirective)
  10211. // Register our custom animations
  10212. .animation('.md-fab-toolbar', MdFabToolbarAnimation)
  10213. // Register a service for the animation so that we can easily inject it into unit tests
  10214. .service('mdFabToolbarAnimation', MdFabToolbarAnimation);
  10215. /**
  10216. * @ngdoc directive
  10217. * @name mdFabToolbar
  10218. * @module material.components.fabToolbar
  10219. *
  10220. * @restrict E
  10221. *
  10222. * @description
  10223. *
  10224. * The `<md-fab-toolbar>` directive is used to present a toolbar of elements (usually `<md-button>`s)
  10225. * for quick access to common actions when a floating action button is activated (via click or
  10226. * keyboard navigation).
  10227. *
  10228. * You may also easily position the trigger by applying one one of the following classes to the
  10229. * `<md-fab-toolbar>` element:
  10230. * - `md-fab-top-left`
  10231. * - `md-fab-top-right`
  10232. * - `md-fab-bottom-left`
  10233. * - `md-fab-bottom-right`
  10234. *
  10235. * These CSS classes use `position: absolute`, so you need to ensure that the container element
  10236. * also uses `position: absolute` or `position: relative` in order for them to work.
  10237. *
  10238. * @usage
  10239. *
  10240. * <hljs lang="html">
  10241. * <md-fab-toolbar md-direction='left'>
  10242. * <md-fab-trigger>
  10243. * <md-button aria-label="Add..."><md-icon md-svg-src="/img/icons/plus.svg"></md-icon></md-button>
  10244. * </md-fab-trigger>
  10245. *
  10246. * <md-toolbar>
  10247. * <md-fab-actions>
  10248. * <md-button aria-label="Add User">
  10249. * <md-icon md-svg-src="/img/icons/user.svg"></md-icon>
  10250. * </md-button>
  10251. *
  10252. * <md-button aria-label="Add Group">
  10253. * <md-icon md-svg-src="/img/icons/group.svg"></md-icon>
  10254. * </md-button>
  10255. * </md-fab-actions>
  10256. * </md-toolbar>
  10257. * </md-fab-toolbar>
  10258. * </hljs>
  10259. *
  10260. * @param {string} md-direction From which direction you would like the toolbar items to appear
  10261. * relative to the trigger element. Supports `left` and `right` directions.
  10262. * @param {expression=} md-open Programmatically control whether or not the toolbar is visible.
  10263. */
  10264. function MdFabToolbarDirective() {
  10265. return {
  10266. restrict: 'E',
  10267. transclude: true,
  10268. template: '<div class="md-fab-toolbar-wrapper">' +
  10269. ' <div class="md-fab-toolbar-content" ng-transclude></div>' +
  10270. '</div>',
  10271. scope: {
  10272. direction: '@?mdDirection',
  10273. isOpen: '=?mdOpen'
  10274. },
  10275. bindToController: true,
  10276. controller: 'MdFabController',
  10277. controllerAs: 'vm',
  10278. link: link
  10279. };
  10280. function link(scope, element, attributes) {
  10281. // Add the base class for animations
  10282. element.addClass('md-fab-toolbar');
  10283. // Prepend the background element to the trigger's button
  10284. element.find('md-fab-trigger').find('button')
  10285. .prepend('<div class="md-fab-toolbar-background"></div>');
  10286. }
  10287. }
  10288. function MdFabToolbarAnimation() {
  10289. function runAnimation(element, className, done) {
  10290. // If no className was specified, don't do anything
  10291. if (!className) {
  10292. return;
  10293. }
  10294. var el = element[0];
  10295. var ctrl = element.controller('mdFabToolbar');
  10296. // Grab the relevant child elements
  10297. var backgroundElement = el.querySelector('.md-fab-toolbar-background');
  10298. var triggerElement = el.querySelector('md-fab-trigger button');
  10299. var toolbarElement = el.querySelector('md-toolbar');
  10300. var iconElement = el.querySelector('md-fab-trigger button md-icon');
  10301. var actions = element.find('md-fab-actions').children();
  10302. // If we have both elements, use them to position the new background
  10303. if (triggerElement && backgroundElement) {
  10304. // Get our variables
  10305. var color = window.getComputedStyle(triggerElement).getPropertyValue('background-color');
  10306. var width = el.offsetWidth;
  10307. var height = el.offsetHeight;
  10308. // Make it twice as big as it should be since we scale from the center
  10309. var scale = 2 * (width / triggerElement.offsetWidth);
  10310. // Set some basic styles no matter what animation we're doing
  10311. backgroundElement.style.backgroundColor = color;
  10312. backgroundElement.style.borderRadius = width + 'px';
  10313. // If we're open
  10314. if (ctrl.isOpen) {
  10315. // Turn on toolbar pointer events when closed
  10316. toolbarElement.style.pointerEvents = 'inherit';
  10317. backgroundElement.style.width = triggerElement.offsetWidth + 'px';
  10318. backgroundElement.style.height = triggerElement.offsetHeight + 'px';
  10319. backgroundElement.style.transform = 'scale(' + scale + ')';
  10320. // Set the next close animation to have the proper delays
  10321. backgroundElement.style.transitionDelay = '0ms';
  10322. iconElement && (iconElement.style.transitionDelay = '.3s');
  10323. // Apply a transition delay to actions
  10324. angular.forEach(actions, function(action, index) {
  10325. action.style.transitionDelay = (actions.length - index) * 25 + 'ms';
  10326. });
  10327. } else {
  10328. // Turn off toolbar pointer events when closed
  10329. toolbarElement.style.pointerEvents = 'none';
  10330. // Scale it back down to the trigger's size
  10331. backgroundElement.style.transform = 'scale(1)';
  10332. // Reset the position
  10333. backgroundElement.style.top = '0';
  10334. if (element.hasClass('md-right')) {
  10335. backgroundElement.style.left = '0';
  10336. backgroundElement.style.right = null;
  10337. }
  10338. if (element.hasClass('md-left')) {
  10339. backgroundElement.style.right = '0';
  10340. backgroundElement.style.left = null;
  10341. }
  10342. // Set the next open animation to have the proper delays
  10343. backgroundElement.style.transitionDelay = '200ms';
  10344. iconElement && (iconElement.style.transitionDelay = '0ms');
  10345. // Apply a transition delay to actions
  10346. angular.forEach(actions, function(action, index) {
  10347. action.style.transitionDelay = 200 + (index * 25) + 'ms';
  10348. });
  10349. }
  10350. }
  10351. }
  10352. return {
  10353. addClass: function(element, className, done) {
  10354. runAnimation(element, className, done);
  10355. done();
  10356. },
  10357. removeClass: function(element, className, done) {
  10358. runAnimation(element, className, done);
  10359. done();
  10360. }
  10361. };
  10362. }
  10363. })();
  10364. })();
  10365. (function(){
  10366. "use strict";
  10367. /**
  10368. * @ngdoc module
  10369. * @name material.components.gridList
  10370. */
  10371. GridListController.$inject = ["$mdUtil"];
  10372. GridLayoutFactory.$inject = ["$mdUtil"];
  10373. GridListDirective.$inject = ["$interpolate", "$mdConstant", "$mdGridLayout", "$mdMedia"];
  10374. GridTileDirective.$inject = ["$mdMedia"];
  10375. angular.module('material.components.gridList', ['material.core'])
  10376. .directive('mdGridList', GridListDirective)
  10377. .directive('mdGridTile', GridTileDirective)
  10378. .directive('mdGridTileFooter', GridTileCaptionDirective)
  10379. .directive('mdGridTileHeader', GridTileCaptionDirective)
  10380. .factory('$mdGridLayout', GridLayoutFactory);
  10381. /**
  10382. * @ngdoc directive
  10383. * @name mdGridList
  10384. * @module material.components.gridList
  10385. * @restrict E
  10386. * @description
  10387. * Grid lists are an alternative to standard list views. Grid lists are distinct
  10388. * from grids used for layouts and other visual presentations.
  10389. *
  10390. * A grid list is best suited to presenting a homogenous data type, typically
  10391. * images, and is optimized for visual comprehension and differentiating between
  10392. * like data types.
  10393. *
  10394. * A grid list is a continuous element consisting of tessellated, regular
  10395. * subdivisions called cells that contain tiles (`md-grid-tile`).
  10396. *
  10397. * <img src="//material-design.storage.googleapis.com/publish/v_2/material_ext_publish/0Bx4BSt6jniD7OVlEaXZ5YmU1Xzg/components_grids_usage2.png"
  10398. * style="width: 300px; height: auto; margin-right: 16px;" alt="Concept of grid explained visually">
  10399. * <img src="//material-design.storage.googleapis.com/publish/v_2/material_ext_publish/0Bx4BSt6jniD7VGhsOE5idWlJWXM/components_grids_usage3.png"
  10400. * style="width: 300px; height: auto;" alt="Grid concepts legend">
  10401. *
  10402. * Cells are arrayed vertically and horizontally within the grid.
  10403. *
  10404. * Tiles hold content and can span one or more cells vertically or horizontally.
  10405. *
  10406. * ### Responsive Attributes
  10407. *
  10408. * The `md-grid-list` directive supports "responsive" attributes, which allow
  10409. * different `md-cols`, `md-gutter` and `md-row-height` values depending on the
  10410. * currently matching media query.
  10411. *
  10412. * In order to set a responsive attribute, first define the fallback value with
  10413. * the standard attribute name, then add additional attributes with the
  10414. * following convention: `{base-attribute-name}-{media-query-name}="{value}"`
  10415. * (ie. `md-cols-lg="8"`)
  10416. *
  10417. * @param {number} md-cols Number of columns in the grid.
  10418. * @param {string} md-row-height One of
  10419. * <ul>
  10420. * <li>CSS length - Fixed height rows (eg. `8px` or `1rem`)</li>
  10421. * <li>`{width}:{height}` - Ratio of width to height (eg.
  10422. * `md-row-height="16:9"`)</li>
  10423. * <li>`"fit"` - Height will be determined by subdividing the available
  10424. * height by the number of rows</li>
  10425. * </ul>
  10426. * @param {string=} md-gutter The amount of space between tiles in CSS units
  10427. * (default 1px)
  10428. * @param {expression=} md-on-layout Expression to evaluate after layout. Event
  10429. * object is available as `$event`, and contains performance information.
  10430. *
  10431. * @usage
  10432. * Basic:
  10433. * <hljs lang="html">
  10434. * <md-grid-list md-cols="5" md-gutter="1em" md-row-height="4:3">
  10435. * <md-grid-tile></md-grid-tile>
  10436. * </md-grid-list>
  10437. * </hljs>
  10438. *
  10439. * Fixed-height rows:
  10440. * <hljs lang="html">
  10441. * <md-grid-list md-cols="4" md-row-height="200px" ...>
  10442. * <md-grid-tile></md-grid-tile>
  10443. * </md-grid-list>
  10444. * </hljs>
  10445. *
  10446. * Fit rows:
  10447. * <hljs lang="html">
  10448. * <md-grid-list md-cols="4" md-row-height="fit" style="height: 400px;" ...>
  10449. * <md-grid-tile></md-grid-tile>
  10450. * </md-grid-list>
  10451. * </hljs>
  10452. *
  10453. * Using responsive attributes:
  10454. * <hljs lang="html">
  10455. * <md-grid-list
  10456. * md-cols-sm="2"
  10457. * md-cols-md="4"
  10458. * md-cols-lg="8"
  10459. * md-cols-gt-lg="12"
  10460. * ...>
  10461. * <md-grid-tile></md-grid-tile>
  10462. * </md-grid-list>
  10463. * </hljs>
  10464. */
  10465. function GridListDirective($interpolate, $mdConstant, $mdGridLayout, $mdMedia) {
  10466. return {
  10467. restrict: 'E',
  10468. controller: GridListController,
  10469. scope: {
  10470. mdOnLayout: '&'
  10471. },
  10472. link: postLink
  10473. };
  10474. function postLink(scope, element, attrs, ctrl) {
  10475. element.addClass('_md'); // private md component indicator for styling
  10476. // Apply semantics
  10477. element.attr('role', 'list');
  10478. // Provide the controller with a way to trigger layouts.
  10479. ctrl.layoutDelegate = layoutDelegate;
  10480. var invalidateLayout = angular.bind(ctrl, ctrl.invalidateLayout),
  10481. unwatchAttrs = watchMedia();
  10482. scope.$on('$destroy', unwatchMedia);
  10483. /**
  10484. * Watches for changes in media, invalidating layout as necessary.
  10485. */
  10486. function watchMedia() {
  10487. for (var mediaName in $mdConstant.MEDIA) {
  10488. $mdMedia(mediaName); // initialize
  10489. $mdMedia.getQuery($mdConstant.MEDIA[mediaName])
  10490. .addListener(invalidateLayout);
  10491. }
  10492. return $mdMedia.watchResponsiveAttributes(
  10493. ['md-cols', 'md-row-height', 'md-gutter'], attrs, layoutIfMediaMatch);
  10494. }
  10495. function unwatchMedia() {
  10496. ctrl.layoutDelegate = angular.noop;
  10497. unwatchAttrs();
  10498. for (var mediaName in $mdConstant.MEDIA) {
  10499. $mdMedia.getQuery($mdConstant.MEDIA[mediaName])
  10500. .removeListener(invalidateLayout);
  10501. }
  10502. }
  10503. /**
  10504. * Performs grid layout if the provided mediaName matches the currently
  10505. * active media type.
  10506. */
  10507. function layoutIfMediaMatch(mediaName) {
  10508. if (mediaName == null) {
  10509. // TODO(shyndman): It would be nice to only layout if we have
  10510. // instances of attributes using this media type
  10511. ctrl.invalidateLayout();
  10512. } else if ($mdMedia(mediaName)) {
  10513. ctrl.invalidateLayout();
  10514. }
  10515. }
  10516. var lastLayoutProps;
  10517. /**
  10518. * Invokes the layout engine, and uses its results to lay out our
  10519. * tile elements.
  10520. *
  10521. * @param {boolean} tilesInvalidated Whether tiles have been
  10522. * added/removed/moved since the last layout. This is to avoid situations
  10523. * where tiles are replaced with properties identical to their removed
  10524. * counterparts.
  10525. */
  10526. function layoutDelegate(tilesInvalidated) {
  10527. var tiles = getTileElements();
  10528. var props = {
  10529. tileSpans: getTileSpans(tiles),
  10530. colCount: getColumnCount(),
  10531. rowMode: getRowMode(),
  10532. rowHeight: getRowHeight(),
  10533. gutter: getGutter()
  10534. };
  10535. if (!tilesInvalidated && angular.equals(props, lastLayoutProps)) {
  10536. return;
  10537. }
  10538. var performance =
  10539. $mdGridLayout(props.colCount, props.tileSpans, tiles)
  10540. .map(function(tilePositions, rowCount) {
  10541. return {
  10542. grid: {
  10543. element: element,
  10544. style: getGridStyle(props.colCount, rowCount,
  10545. props.gutter, props.rowMode, props.rowHeight)
  10546. },
  10547. tiles: tilePositions.map(function(ps, i) {
  10548. return {
  10549. element: angular.element(tiles[i]),
  10550. style: getTileStyle(ps.position, ps.spans,
  10551. props.colCount, rowCount,
  10552. props.gutter, props.rowMode, props.rowHeight)
  10553. };
  10554. })
  10555. };
  10556. })
  10557. .reflow()
  10558. .performance();
  10559. // Report layout
  10560. scope.mdOnLayout({
  10561. $event: {
  10562. performance: performance
  10563. }
  10564. });
  10565. lastLayoutProps = props;
  10566. }
  10567. // Use $interpolate to do some simple string interpolation as a convenience.
  10568. var startSymbol = $interpolate.startSymbol();
  10569. var endSymbol = $interpolate.endSymbol();
  10570. // Returns an expression wrapped in the interpolator's start and end symbols.
  10571. function expr(exprStr) {
  10572. return startSymbol + exprStr + endSymbol;
  10573. }
  10574. // The amount of space a single 1x1 tile would take up (either width or height), used as
  10575. // a basis for other calculations. This consists of taking the base size percent (as would be
  10576. // if evenly dividing the size between cells), and then subtracting the size of one gutter.
  10577. // However, since there are no gutters on the edges, each tile only uses a fration
  10578. // (gutterShare = numGutters / numCells) of the gutter size. (Imagine having one gutter per
  10579. // tile, and then breaking up the extra gutter on the edge evenly among the cells).
  10580. var UNIT = $interpolate(expr('share') + '% - (' + expr('gutter') + ' * ' + expr('gutterShare') + ')');
  10581. // The horizontal or vertical position of a tile, e.g., the 'top' or 'left' property value.
  10582. // The position comes the size of a 1x1 tile plus gutter for each previous tile in the
  10583. // row/column (offset).
  10584. var POSITION = $interpolate('calc((' + expr('unit') + ' + ' + expr('gutter') + ') * ' + expr('offset') + ')');
  10585. // The actual size of a tile, e.g., width or height, taking rowSpan or colSpan into account.
  10586. // This is computed by multiplying the base unit by the rowSpan/colSpan, and then adding back
  10587. // in the space that the gutter would normally have used (which was already accounted for in
  10588. // the base unit calculation).
  10589. var DIMENSION = $interpolate('calc((' + expr('unit') + ') * ' + expr('span') + ' + (' + expr('span') + ' - 1) * ' + expr('gutter') + ')');
  10590. /**
  10591. * Gets the styles applied to a tile element described by the given parameters.
  10592. * @param {{row: number, col: number}} position The row and column indices of the tile.
  10593. * @param {{row: number, col: number}} spans The rowSpan and colSpan of the tile.
  10594. * @param {number} colCount The number of columns.
  10595. * @param {number} rowCount The number of rows.
  10596. * @param {string} gutter The amount of space between tiles. This will be something like
  10597. * '5px' or '2em'.
  10598. * @param {string} rowMode The row height mode. Can be one of:
  10599. * 'fixed': all rows have a fixed size, given by rowHeight,
  10600. * 'ratio': row height defined as a ratio to width, or
  10601. * 'fit': fit to the grid-list element height, divinding evenly among rows.
  10602. * @param {string|number} rowHeight The height of a row. This is only used for 'fixed' mode and
  10603. * for 'ratio' mode. For 'ratio' mode, this is the *ratio* of width-to-height (e.g., 0.75).
  10604. * @returns {Object} Map of CSS properties to be applied to the style element. Will define
  10605. * values for top, left, width, height, marginTop, and paddingTop.
  10606. */
  10607. function getTileStyle(position, spans, colCount, rowCount, gutter, rowMode, rowHeight) {
  10608. // TODO(shyndman): There are style caching opportunities here.
  10609. // Percent of the available horizontal space that one column takes up.
  10610. var hShare = (1 / colCount) * 100;
  10611. // Fraction of the gutter size that each column takes up.
  10612. var hGutterShare = (colCount - 1) / colCount;
  10613. // Base horizontal size of a column.
  10614. var hUnit = UNIT({share: hShare, gutterShare: hGutterShare, gutter: gutter});
  10615. // The width and horizontal position of each tile is always calculated the same way, but the
  10616. // height and vertical position depends on the rowMode.
  10617. var ltr = document.dir != 'rtl' && document.body.dir != 'rtl';
  10618. var style = ltr ? {
  10619. left: POSITION({ unit: hUnit, offset: position.col, gutter: gutter }),
  10620. width: DIMENSION({ unit: hUnit, span: spans.col, gutter: gutter }),
  10621. // resets
  10622. paddingTop: '',
  10623. marginTop: '',
  10624. top: '',
  10625. height: ''
  10626. } : {
  10627. right: POSITION({ unit: hUnit, offset: position.col, gutter: gutter }),
  10628. width: DIMENSION({ unit: hUnit, span: spans.col, gutter: gutter }),
  10629. // resets
  10630. paddingTop: '',
  10631. marginTop: '',
  10632. top: '',
  10633. height: ''
  10634. };
  10635. switch (rowMode) {
  10636. case 'fixed':
  10637. // In fixed mode, simply use the given rowHeight.
  10638. style.top = POSITION({ unit: rowHeight, offset: position.row, gutter: gutter });
  10639. style.height = DIMENSION({ unit: rowHeight, span: spans.row, gutter: gutter });
  10640. break;
  10641. case 'ratio':
  10642. // Percent of the available vertical space that one row takes up. Here, rowHeight holds
  10643. // the ratio value. For example, if the width:height ratio is 4:3, rowHeight = 1.333.
  10644. var vShare = hShare / rowHeight;
  10645. // Base veritcal size of a row.
  10646. var vUnit = UNIT({ share: vShare, gutterShare: hGutterShare, gutter: gutter });
  10647. // padidngTop and marginTop are used to maintain the given aspect ratio, as
  10648. // a percentage-based value for these properties is applied to the *width* of the
  10649. // containing block. See http://www.w3.org/TR/CSS2/box.html#margin-properties
  10650. style.paddingTop = DIMENSION({ unit: vUnit, span: spans.row, gutter: gutter});
  10651. style.marginTop = POSITION({ unit: vUnit, offset: position.row, gutter: gutter });
  10652. break;
  10653. case 'fit':
  10654. // Fraction of the gutter size that each column takes up.
  10655. var vGutterShare = (rowCount - 1) / rowCount;
  10656. // Percent of the available vertical space that one row takes up.
  10657. vShare = (1 / rowCount) * 100;
  10658. // Base vertical size of a row.
  10659. vUnit = UNIT({share: vShare, gutterShare: vGutterShare, gutter: gutter});
  10660. style.top = POSITION({unit: vUnit, offset: position.row, gutter: gutter});
  10661. style.height = DIMENSION({unit: vUnit, span: spans.row, gutter: gutter});
  10662. break;
  10663. }
  10664. return style;
  10665. }
  10666. function getGridStyle(colCount, rowCount, gutter, rowMode, rowHeight) {
  10667. var style = {};
  10668. switch(rowMode) {
  10669. case 'fixed':
  10670. style.height = DIMENSION({ unit: rowHeight, span: rowCount, gutter: gutter });
  10671. style.paddingBottom = '';
  10672. break;
  10673. case 'ratio':
  10674. // rowHeight is width / height
  10675. var hGutterShare = colCount === 1 ? 0 : (colCount - 1) / colCount,
  10676. hShare = (1 / colCount) * 100,
  10677. vShare = hShare * (1 / rowHeight),
  10678. vUnit = UNIT({ share: vShare, gutterShare: hGutterShare, gutter: gutter });
  10679. style.height = '';
  10680. style.paddingBottom = DIMENSION({ unit: vUnit, span: rowCount, gutter: gutter});
  10681. break;
  10682. case 'fit':
  10683. // noop, as the height is user set
  10684. break;
  10685. }
  10686. return style;
  10687. }
  10688. function getTileElements() {
  10689. return [].filter.call(element.children(), function(ele) {
  10690. return ele.tagName == 'MD-GRID-TILE' && !ele.$$mdDestroyed;
  10691. });
  10692. }
  10693. /**
  10694. * Gets an array of objects containing the rowspan and colspan for each tile.
  10695. * @returns {Array<{row: number, col: number}>}
  10696. */
  10697. function getTileSpans(tileElements) {
  10698. return [].map.call(tileElements, function(ele) {
  10699. var ctrl = angular.element(ele).controller('mdGridTile');
  10700. return {
  10701. row: parseInt(
  10702. $mdMedia.getResponsiveAttribute(ctrl.$attrs, 'md-rowspan'), 10) || 1,
  10703. col: parseInt(
  10704. $mdMedia.getResponsiveAttribute(ctrl.$attrs, 'md-colspan'), 10) || 1
  10705. };
  10706. });
  10707. }
  10708. function getColumnCount() {
  10709. var colCount = parseInt($mdMedia.getResponsiveAttribute(attrs, 'md-cols'), 10);
  10710. if (isNaN(colCount)) {
  10711. throw 'md-grid-list: md-cols attribute was not found, or contained a non-numeric value';
  10712. }
  10713. return colCount;
  10714. }
  10715. function getGutter() {
  10716. return applyDefaultUnit($mdMedia.getResponsiveAttribute(attrs, 'md-gutter') || 1);
  10717. }
  10718. function getRowHeight() {
  10719. var rowHeight = $mdMedia.getResponsiveAttribute(attrs, 'md-row-height');
  10720. if (!rowHeight) {
  10721. throw 'md-grid-list: md-row-height attribute was not found';
  10722. }
  10723. switch (getRowMode()) {
  10724. case 'fixed':
  10725. return applyDefaultUnit(rowHeight);
  10726. case 'ratio':
  10727. var whRatio = rowHeight.split(':');
  10728. return parseFloat(whRatio[0]) / parseFloat(whRatio[1]);
  10729. case 'fit':
  10730. return 0; // N/A
  10731. }
  10732. }
  10733. function getRowMode() {
  10734. var rowHeight = $mdMedia.getResponsiveAttribute(attrs, 'md-row-height');
  10735. if (!rowHeight) {
  10736. throw 'md-grid-list: md-row-height attribute was not found';
  10737. }
  10738. if (rowHeight == 'fit') {
  10739. return 'fit';
  10740. } else if (rowHeight.indexOf(':') !== -1) {
  10741. return 'ratio';
  10742. } else {
  10743. return 'fixed';
  10744. }
  10745. }
  10746. function applyDefaultUnit(val) {
  10747. return /\D$/.test(val) ? val : val + 'px';
  10748. }
  10749. }
  10750. }
  10751. /* @ngInject */
  10752. function GridListController($mdUtil) {
  10753. this.layoutInvalidated = false;
  10754. this.tilesInvalidated = false;
  10755. this.$timeout_ = $mdUtil.nextTick;
  10756. this.layoutDelegate = angular.noop;
  10757. }
  10758. GridListController.prototype = {
  10759. invalidateTiles: function() {
  10760. this.tilesInvalidated = true;
  10761. this.invalidateLayout();
  10762. },
  10763. invalidateLayout: function() {
  10764. if (this.layoutInvalidated) {
  10765. return;
  10766. }
  10767. this.layoutInvalidated = true;
  10768. this.$timeout_(angular.bind(this, this.layout));
  10769. },
  10770. layout: function() {
  10771. try {
  10772. this.layoutDelegate(this.tilesInvalidated);
  10773. } finally {
  10774. this.layoutInvalidated = false;
  10775. this.tilesInvalidated = false;
  10776. }
  10777. }
  10778. };
  10779. /* @ngInject */
  10780. function GridLayoutFactory($mdUtil) {
  10781. var defaultAnimator = GridTileAnimator;
  10782. /**
  10783. * Set the reflow animator callback
  10784. */
  10785. GridLayout.animateWith = function(customAnimator) {
  10786. defaultAnimator = !angular.isFunction(customAnimator) ? GridTileAnimator : customAnimator;
  10787. };
  10788. return GridLayout;
  10789. /**
  10790. * Publish layout function
  10791. */
  10792. function GridLayout(colCount, tileSpans) {
  10793. var self, layoutInfo, gridStyles, layoutTime, mapTime, reflowTime;
  10794. layoutTime = $mdUtil.time(function() {
  10795. layoutInfo = calculateGridFor(colCount, tileSpans);
  10796. });
  10797. return self = {
  10798. /**
  10799. * An array of objects describing each tile's position in the grid.
  10800. */
  10801. layoutInfo: function() {
  10802. return layoutInfo;
  10803. },
  10804. /**
  10805. * Maps grid positioning to an element and a set of styles using the
  10806. * provided updateFn.
  10807. */
  10808. map: function(updateFn) {
  10809. mapTime = $mdUtil.time(function() {
  10810. var info = self.layoutInfo();
  10811. gridStyles = updateFn(info.positioning, info.rowCount);
  10812. });
  10813. return self;
  10814. },
  10815. /**
  10816. * Default animator simply sets the element.css( <styles> ). An alternate
  10817. * animator can be provided as an argument. The function has the following
  10818. * signature:
  10819. *
  10820. * function({grid: {element: JQLite, style: Object}, tiles: Array<{element: JQLite, style: Object}>)
  10821. */
  10822. reflow: function(animatorFn) {
  10823. reflowTime = $mdUtil.time(function() {
  10824. var animator = animatorFn || defaultAnimator;
  10825. animator(gridStyles.grid, gridStyles.tiles);
  10826. });
  10827. return self;
  10828. },
  10829. /**
  10830. * Timing for the most recent layout run.
  10831. */
  10832. performance: function() {
  10833. return {
  10834. tileCount: tileSpans.length,
  10835. layoutTime: layoutTime,
  10836. mapTime: mapTime,
  10837. reflowTime: reflowTime,
  10838. totalTime: layoutTime + mapTime + reflowTime
  10839. };
  10840. }
  10841. };
  10842. }
  10843. /**
  10844. * Default Gridlist animator simple sets the css for each element;
  10845. * NOTE: any transitions effects must be manually set in the CSS.
  10846. * e.g.
  10847. *
  10848. * md-grid-tile {
  10849. * transition: all 700ms ease-out 50ms;
  10850. * }
  10851. *
  10852. */
  10853. function GridTileAnimator(grid, tiles) {
  10854. grid.element.css(grid.style);
  10855. tiles.forEach(function(t) {
  10856. t.element.css(t.style);
  10857. });
  10858. }
  10859. /**
  10860. * Calculates the positions of tiles.
  10861. *
  10862. * The algorithm works as follows:
  10863. * An Array<Number> with length colCount (spaceTracker) keeps track of
  10864. * available tiling positions, where elements of value 0 represents an
  10865. * empty position. Space for a tile is reserved by finding a sequence of
  10866. * 0s with length <= than the tile's colspan. When such a space has been
  10867. * found, the occupied tile positions are incremented by the tile's
  10868. * rowspan value, as these positions have become unavailable for that
  10869. * many rows.
  10870. *
  10871. * If the end of a row has been reached without finding space for the
  10872. * tile, spaceTracker's elements are each decremented by 1 to a minimum
  10873. * of 0. Rows are searched in this fashion until space is found.
  10874. */
  10875. function calculateGridFor(colCount, tileSpans) {
  10876. var curCol = 0,
  10877. curRow = 0,
  10878. spaceTracker = newSpaceTracker();
  10879. return {
  10880. positioning: tileSpans.map(function(spans, i) {
  10881. return {
  10882. spans: spans,
  10883. position: reserveSpace(spans, i)
  10884. };
  10885. }),
  10886. rowCount: curRow + Math.max.apply(Math, spaceTracker)
  10887. };
  10888. function reserveSpace(spans, i) {
  10889. if (spans.col > colCount) {
  10890. throw 'md-grid-list: Tile at position ' + i + ' has a colspan ' +
  10891. '(' + spans.col + ') that exceeds the column count ' +
  10892. '(' + colCount + ')';
  10893. }
  10894. var start = 0,
  10895. end = 0;
  10896. // TODO(shyndman): This loop isn't strictly necessary if you can
  10897. // determine the minimum number of rows before a space opens up. To do
  10898. // this, recognize that you've iterated across an entire row looking for
  10899. // space, and if so fast-forward by the minimum rowSpan count. Repeat
  10900. // until the required space opens up.
  10901. while (end - start < spans.col) {
  10902. if (curCol >= colCount) {
  10903. nextRow();
  10904. continue;
  10905. }
  10906. start = spaceTracker.indexOf(0, curCol);
  10907. if (start === -1 || (end = findEnd(start + 1)) === -1) {
  10908. start = end = 0;
  10909. nextRow();
  10910. continue;
  10911. }
  10912. curCol = end + 1;
  10913. }
  10914. adjustRow(start, spans.col, spans.row);
  10915. curCol = start + spans.col;
  10916. return {
  10917. col: start,
  10918. row: curRow
  10919. };
  10920. }
  10921. function nextRow() {
  10922. curCol = 0;
  10923. curRow++;
  10924. adjustRow(0, colCount, -1); // Decrement row spans by one
  10925. }
  10926. function adjustRow(from, cols, by) {
  10927. for (var i = from; i < from + cols; i++) {
  10928. spaceTracker[i] = Math.max(spaceTracker[i] + by, 0);
  10929. }
  10930. }
  10931. function findEnd(start) {
  10932. var i;
  10933. for (i = start; i < spaceTracker.length; i++) {
  10934. if (spaceTracker[i] !== 0) {
  10935. return i;
  10936. }
  10937. }
  10938. if (i === spaceTracker.length) {
  10939. return i;
  10940. }
  10941. }
  10942. function newSpaceTracker() {
  10943. var tracker = [];
  10944. for (var i = 0; i < colCount; i++) {
  10945. tracker.push(0);
  10946. }
  10947. return tracker;
  10948. }
  10949. }
  10950. }
  10951. /**
  10952. * @ngdoc directive
  10953. * @name mdGridTile
  10954. * @module material.components.gridList
  10955. * @restrict E
  10956. * @description
  10957. * Tiles contain the content of an `md-grid-list`. They span one or more grid
  10958. * cells vertically or horizontally, and use `md-grid-tile-{footer,header}` to
  10959. * display secondary content.
  10960. *
  10961. * ### Responsive Attributes
  10962. *
  10963. * The `md-grid-tile` directive supports "responsive" attributes, which allow
  10964. * different `md-rowspan` and `md-colspan` values depending on the currently
  10965. * matching media query.
  10966. *
  10967. * In order to set a responsive attribute, first define the fallback value with
  10968. * the standard attribute name, then add additional attributes with the
  10969. * following convention: `{base-attribute-name}-{media-query-name}="{value}"`
  10970. * (ie. `md-colspan-sm="4"`)
  10971. *
  10972. * @param {number=} md-colspan The number of columns to span (default 1). Cannot
  10973. * exceed the number of columns in the grid. Supports interpolation.
  10974. * @param {number=} md-rowspan The number of rows to span (default 1). Supports
  10975. * interpolation.
  10976. *
  10977. * @usage
  10978. * With header:
  10979. * <hljs lang="html">
  10980. * <md-grid-tile>
  10981. * <md-grid-tile-header>
  10982. * <h3>This is a header</h3>
  10983. * </md-grid-tile-header>
  10984. * </md-grid-tile>
  10985. * </hljs>
  10986. *
  10987. * With footer:
  10988. * <hljs lang="html">
  10989. * <md-grid-tile>
  10990. * <md-grid-tile-footer>
  10991. * <h3>This is a footer</h3>
  10992. * </md-grid-tile-footer>
  10993. * </md-grid-tile>
  10994. * </hljs>
  10995. *
  10996. * Spanning multiple rows/columns:
  10997. * <hljs lang="html">
  10998. * <md-grid-tile md-colspan="2" md-rowspan="3">
  10999. * </md-grid-tile>
  11000. * </hljs>
  11001. *
  11002. * Responsive attributes:
  11003. * <hljs lang="html">
  11004. * <md-grid-tile md-colspan="1" md-colspan-sm="3" md-colspan-md="5">
  11005. * </md-grid-tile>
  11006. * </hljs>
  11007. */
  11008. function GridTileDirective($mdMedia) {
  11009. return {
  11010. restrict: 'E',
  11011. require: '^mdGridList',
  11012. template: '<figure ng-transclude></figure>',
  11013. transclude: true,
  11014. scope: {},
  11015. // Simple controller that exposes attributes to the grid directive
  11016. controller: ["$attrs", function($attrs) {
  11017. this.$attrs = $attrs;
  11018. }],
  11019. link: postLink
  11020. };
  11021. function postLink(scope, element, attrs, gridCtrl) {
  11022. // Apply semantics
  11023. element.attr('role', 'listitem');
  11024. // If our colspan or rowspan changes, trigger a layout
  11025. var unwatchAttrs = $mdMedia.watchResponsiveAttributes(['md-colspan', 'md-rowspan'],
  11026. attrs, angular.bind(gridCtrl, gridCtrl.invalidateLayout));
  11027. // Tile registration/deregistration
  11028. gridCtrl.invalidateTiles();
  11029. scope.$on('$destroy', function() {
  11030. // Mark the tile as destroyed so it is no longer considered in layout,
  11031. // even if the DOM element sticks around (like during a leave animation)
  11032. element[0].$$mdDestroyed = true;
  11033. unwatchAttrs();
  11034. gridCtrl.invalidateLayout();
  11035. });
  11036. if (angular.isDefined(scope.$parent.$index)) {
  11037. scope.$watch(function() { return scope.$parent.$index; },
  11038. function indexChanged(newIdx, oldIdx) {
  11039. if (newIdx === oldIdx) {
  11040. return;
  11041. }
  11042. gridCtrl.invalidateTiles();
  11043. });
  11044. }
  11045. }
  11046. }
  11047. function GridTileCaptionDirective() {
  11048. return {
  11049. template: '<figcaption ng-transclude></figcaption>',
  11050. transclude: true
  11051. };
  11052. }
  11053. })();
  11054. (function(){
  11055. "use strict";
  11056. /**
  11057. * @ngdoc module
  11058. * @name material.components.icon
  11059. * @description
  11060. * Icon
  11061. */
  11062. angular.module('material.components.icon', ['material.core']);
  11063. })();
  11064. (function(){
  11065. "use strict";
  11066. /**
  11067. * @ngdoc module
  11068. * @name material.components.input
  11069. */
  11070. mdInputContainerDirective.$inject = ["$mdTheming", "$parse"];
  11071. inputTextareaDirective.$inject = ["$mdUtil", "$window", "$mdAria", "$timeout", "$mdGesture"];
  11072. mdMaxlengthDirective.$inject = ["$animate", "$mdUtil"];
  11073. placeholderDirective.$inject = ["$compile"];
  11074. ngMessageDirective.$inject = ["$mdUtil"];
  11075. mdSelectOnFocusDirective.$inject = ["$document", "$timeout"];
  11076. mdInputInvalidMessagesAnimation.$inject = ["$$AnimateRunner", "$animateCss", "$mdUtil", "$log"];
  11077. ngMessagesAnimation.$inject = ["$$AnimateRunner", "$animateCss", "$mdUtil", "$log"];
  11078. ngMessageAnimation.$inject = ["$$AnimateRunner", "$animateCss", "$mdUtil", "$log"];
  11079. var inputModule = angular.module('material.components.input', [
  11080. 'material.core'
  11081. ])
  11082. .directive('mdInputContainer', mdInputContainerDirective)
  11083. .directive('label', labelDirective)
  11084. .directive('input', inputTextareaDirective)
  11085. .directive('textarea', inputTextareaDirective)
  11086. .directive('mdMaxlength', mdMaxlengthDirective)
  11087. .directive('placeholder', placeholderDirective)
  11088. .directive('ngMessages', ngMessagesDirective)
  11089. .directive('ngMessage', ngMessageDirective)
  11090. .directive('ngMessageExp', ngMessageDirective)
  11091. .directive('mdSelectOnFocus', mdSelectOnFocusDirective)
  11092. .animation('.md-input-invalid', mdInputInvalidMessagesAnimation)
  11093. .animation('.md-input-messages-animation', ngMessagesAnimation)
  11094. .animation('.md-input-message-animation', ngMessageAnimation);
  11095. // If we are running inside of tests; expose some extra services so that we can test them
  11096. if (window._mdMocksIncluded) {
  11097. inputModule.service('$$mdInput', function() {
  11098. return {
  11099. // special accessor to internals... useful for testing
  11100. messages: {
  11101. show : showInputMessages,
  11102. hide : hideInputMessages,
  11103. getElement : getMessagesElement
  11104. }
  11105. };
  11106. })
  11107. // Register a service for each animation so that we can easily inject them into unit tests
  11108. .service('mdInputInvalidAnimation', mdInputInvalidMessagesAnimation)
  11109. .service('mdInputMessagesAnimation', ngMessagesAnimation)
  11110. .service('mdInputMessageAnimation', ngMessageAnimation);
  11111. }
  11112. /**
  11113. * @ngdoc directive
  11114. * @name mdInputContainer
  11115. * @module material.components.input
  11116. *
  11117. * @restrict E
  11118. *
  11119. * @description
  11120. * `<md-input-container>` is the parent of any input or textarea element.
  11121. *
  11122. * Input and textarea elements will not behave properly unless the md-input-container
  11123. * parent is provided.
  11124. *
  11125. * A single `<md-input-container>` should contain only one `<input>` element, otherwise it will throw an error.
  11126. *
  11127. * <b>Exception:</b> Hidden inputs (`<input type="hidden" />`) are ignored and will not throw an error, so
  11128. * you may combine these with other inputs.
  11129. *
  11130. * <b>Note:</b> When using `ngMessages` with your input element, make sure the message and container elements
  11131. * are *block* elements, otherwise animations applied to the messages will not look as intended. Either use a `div` and
  11132. * apply the `ng-message` and `ng-messages` classes respectively, or use the `md-block` class on your element.
  11133. *
  11134. * @param md-is-error {expression=} When the given expression evaluates to true, the input container
  11135. * will go into error state. Defaults to erroring if the input has been touched and is invalid.
  11136. * @param md-no-float {boolean=} When present, `placeholder` attributes on the input will not be converted to floating
  11137. * labels.
  11138. *
  11139. * @usage
  11140. * <hljs lang="html">
  11141. *
  11142. * <md-input-container>
  11143. * <label>Username</label>
  11144. * <input type="text" ng-model="user.name">
  11145. * </md-input-container>
  11146. *
  11147. * <md-input-container>
  11148. * <label>Description</label>
  11149. * <textarea ng-model="user.description"></textarea>
  11150. * </md-input-container>
  11151. *
  11152. * </hljs>
  11153. *
  11154. * <h3>When disabling floating labels</h3>
  11155. * <hljs lang="html">
  11156. *
  11157. * <md-input-container md-no-float>
  11158. * <input type="text" placeholder="Non-Floating Label">
  11159. * </md-input-container>
  11160. *
  11161. * </hljs>
  11162. */
  11163. function mdInputContainerDirective($mdTheming, $parse) {
  11164. ContainerCtrl.$inject = ["$scope", "$element", "$attrs", "$animate"];
  11165. var INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT', 'MD-SELECT'];
  11166. var LEFT_SELECTORS = INPUT_TAGS.reduce(function(selectors, isel) {
  11167. return selectors.concat(['md-icon ~ ' + isel, '.md-icon ~ ' + isel]);
  11168. }, []).join(",");
  11169. var RIGHT_SELECTORS = INPUT_TAGS.reduce(function(selectors, isel) {
  11170. return selectors.concat([isel + ' ~ md-icon', isel + ' ~ .md-icon']);
  11171. }, []).join(",");
  11172. return {
  11173. restrict: 'E',
  11174. compile: compile,
  11175. controller: ContainerCtrl
  11176. };
  11177. function compile(tElement) {
  11178. // Check for both a left & right icon
  11179. var leftIcon = tElement[0].querySelector(LEFT_SELECTORS);
  11180. var rightIcon = tElement[0].querySelector(RIGHT_SELECTORS);
  11181. if (leftIcon) { tElement.addClass('md-icon-left'); }
  11182. if (rightIcon) { tElement.addClass('md-icon-right'); }
  11183. return function postLink(scope, element) {
  11184. $mdTheming(element);
  11185. };
  11186. }
  11187. function ContainerCtrl($scope, $element, $attrs, $animate) {
  11188. var self = this;
  11189. self.isErrorGetter = $attrs.mdIsError && $parse($attrs.mdIsError);
  11190. self.delegateClick = function() {
  11191. self.input.focus();
  11192. };
  11193. self.element = $element;
  11194. self.setFocused = function(isFocused) {
  11195. $element.toggleClass('md-input-focused', !!isFocused);
  11196. };
  11197. self.setHasValue = function(hasValue) {
  11198. $element.toggleClass('md-input-has-value', !!hasValue);
  11199. };
  11200. self.setHasPlaceholder = function(hasPlaceholder) {
  11201. $element.toggleClass('md-input-has-placeholder', !!hasPlaceholder);
  11202. };
  11203. self.setInvalid = function(isInvalid) {
  11204. if (isInvalid) {
  11205. $animate.addClass($element, 'md-input-invalid');
  11206. } else {
  11207. $animate.removeClass($element, 'md-input-invalid');
  11208. }
  11209. };
  11210. $scope.$watch(function() {
  11211. return self.label && self.input;
  11212. }, function(hasLabelAndInput) {
  11213. if (hasLabelAndInput && !self.label.attr('for')) {
  11214. self.label.attr('for', self.input.attr('id'));
  11215. }
  11216. });
  11217. }
  11218. }
  11219. function labelDirective() {
  11220. return {
  11221. restrict: 'E',
  11222. require: '^?mdInputContainer',
  11223. link: function(scope, element, attr, containerCtrl) {
  11224. if (!containerCtrl || attr.mdNoFloat || element.hasClass('md-container-ignore')) return;
  11225. containerCtrl.label = element;
  11226. scope.$on('$destroy', function() {
  11227. containerCtrl.label = null;
  11228. });
  11229. }
  11230. };
  11231. }
  11232. /**
  11233. * @ngdoc directive
  11234. * @name mdInput
  11235. * @restrict E
  11236. * @module material.components.input
  11237. *
  11238. * @description
  11239. * You can use any `<input>` or `<textarea>` element as a child of an `<md-input-container>`. This
  11240. * allows you to build complex forms for data entry.
  11241. *
  11242. * When the input is required and uses a floating label, then the label will automatically contain
  11243. * an asterisk (`*`).<br/>
  11244. * This behavior can be disabled by using the `md-no-asterisk` attribute.
  11245. *
  11246. * @param {number=} md-maxlength The maximum number of characters allowed in this input. If this is
  11247. * specified, a character counter will be shown underneath the input.<br/><br/>
  11248. * The purpose of **`md-maxlength`** is exactly to show the max length counter text. If you don't
  11249. * want the counter text and only need "plain" validation, you can use the "simple" `ng-maxlength`
  11250. * or maxlength attributes.<br/><br/>
  11251. * **Note:** Only valid for text/string inputs (not numeric).
  11252. *
  11253. * @param {string=} aria-label Aria-label is required when no label is present. A warning message
  11254. * will be logged in the console if not present.
  11255. * @param {string=} placeholder An alternative approach to using aria-label when the label is not
  11256. * PRESENT. The placeholder text is copied to the aria-label attribute.
  11257. * @param md-no-autogrow {boolean=} When present, textareas will not grow automatically.
  11258. * @param md-no-asterisk {boolean=} When present, an asterisk will not be appended to the inputs floating label
  11259. * @param md-no-resize {boolean=} Disables the textarea resize handle.
  11260. * @param {number=} max-rows The maximum amount of rows for a textarea.
  11261. * @param md-detect-hidden {boolean=} When present, textareas will be sized properly when they are
  11262. * revealed after being hidden. This is off by default for performance reasons because it
  11263. * guarantees a reflow every digest cycle.
  11264. *
  11265. * @usage
  11266. * <hljs lang="html">
  11267. * <md-input-container>
  11268. * <label>Color</label>
  11269. * <input type="text" ng-model="color" required md-maxlength="10">
  11270. * </md-input-container>
  11271. * </hljs>
  11272. *
  11273. * <h3>With Errors</h3>
  11274. *
  11275. * `md-input-container` also supports errors using the standard `ng-messages` directives and
  11276. * animates the messages when they become visible using from the `ngEnter`/`ngLeave` events or
  11277. * the `ngShow`/`ngHide` events.
  11278. *
  11279. * By default, the messages will be hidden until the input is in an error state. This is based off
  11280. * of the `md-is-error` expression of the `md-input-container`. This gives the user a chance to
  11281. * fill out the form before the errors become visible.
  11282. *
  11283. * <hljs lang="html">
  11284. * <form name="colorForm">
  11285. * <md-input-container>
  11286. * <label>Favorite Color</label>
  11287. * <input name="favoriteColor" ng-model="favoriteColor" required>
  11288. * <div ng-messages="colorForm.favoriteColor.$error">
  11289. * <div ng-message="required">This is required!</div>
  11290. * </div>
  11291. * </md-input-container>
  11292. * </form>
  11293. * </hljs>
  11294. *
  11295. * We automatically disable this auto-hiding functionality if you provide any of the following
  11296. * visibility directives on the `ng-messages` container:
  11297. *
  11298. * - `ng-if`
  11299. * - `ng-show`/`ng-hide`
  11300. * - `ng-switch-when`/`ng-switch-default`
  11301. *
  11302. * You can also disable this functionality manually by adding the `md-auto-hide="false"` expression
  11303. * to the `ng-messages` container. This may be helpful if you always want to see the error messages
  11304. * or if you are building your own visibilty directive.
  11305. *
  11306. * _<b>Note:</b> The `md-auto-hide` attribute is a static string that is only checked upon
  11307. * initialization of the `ng-messages` directive to see if it equals the string `false`._
  11308. *
  11309. * <hljs lang="html">
  11310. * <form name="userForm">
  11311. * <md-input-container>
  11312. * <label>Last Name</label>
  11313. * <input name="lastName" ng-model="lastName" required md-maxlength="10" minlength="4">
  11314. * <div ng-messages="userForm.lastName.$error" ng-show="userForm.lastName.$dirty">
  11315. * <div ng-message="required">This is required!</div>
  11316. * <div ng-message="md-maxlength">That's too long!</div>
  11317. * <div ng-message="minlength">That's too short!</div>
  11318. * </div>
  11319. * </md-input-container>
  11320. * <md-input-container>
  11321. * <label>Biography</label>
  11322. * <textarea name="bio" ng-model="biography" required md-maxlength="150"></textarea>
  11323. * <div ng-messages="userForm.bio.$error" ng-show="userForm.bio.$dirty">
  11324. * <div ng-message="required">This is required!</div>
  11325. * <div ng-message="md-maxlength">That's too long!</div>
  11326. * </div>
  11327. * </md-input-container>
  11328. * <md-input-container>
  11329. * <input aria-label='title' ng-model='title'>
  11330. * </md-input-container>
  11331. * <md-input-container>
  11332. * <input placeholder='title' ng-model='title'>
  11333. * </md-input-container>
  11334. * </form>
  11335. * </hljs>
  11336. *
  11337. * <h3>Notes</h3>
  11338. *
  11339. * - Requires [ngMessages](https://docs.angularjs.org/api/ngMessages).
  11340. * - Behaves like the [AngularJS input directive](https://docs.angularjs.org/api/ng/directive/input).
  11341. *
  11342. * The `md-input` and `md-input-container` directives use very specific positioning to achieve the
  11343. * error animation effects. Therefore, it is *not* advised to use the Layout system inside of the
  11344. * `<md-input-container>` tags. Instead, use relative or absolute positioning.
  11345. *
  11346. *
  11347. * <h3>Textarea directive</h3>
  11348. * The `textarea` element within a `md-input-container` has the following specific behavior:
  11349. * - By default the `textarea` grows as the user types. This can be disabled via the `md-no-autogrow`
  11350. * attribute.
  11351. * - If a `textarea` has the `rows` attribute, it will treat the `rows` as the minimum height and will
  11352. * continue growing as the user types. For example a textarea with `rows="3"` will be 3 lines of text
  11353. * high initially. If no rows are specified, the directive defaults to 1.
  11354. * - The textarea's height gets set on initialization, as well as while the user is typing. In certain situations
  11355. * (e.g. while animating) the directive might have been initialized, before the element got it's final height. In
  11356. * those cases, you can trigger a resize manually by broadcasting a `md-resize-textarea` event on the scope.
  11357. * - If you want a `textarea` to stop growing at a certain point, you can specify the `max-rows` attribute.
  11358. * - The textarea's bottom border acts as a handle which users can drag, in order to resize the element vertically.
  11359. * Once the user has resized a `textarea`, the autogrowing functionality becomes disabled. If you don't want a
  11360. * `textarea` to be resizeable by the user, you can add the `md-no-resize` attribute.
  11361. */
  11362. function inputTextareaDirective($mdUtil, $window, $mdAria, $timeout, $mdGesture) {
  11363. return {
  11364. restrict: 'E',
  11365. require: ['^?mdInputContainer', '?ngModel', '?^form'],
  11366. link: postLink
  11367. };
  11368. function postLink(scope, element, attr, ctrls) {
  11369. var containerCtrl = ctrls[0];
  11370. var hasNgModel = !!ctrls[1];
  11371. var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel();
  11372. var parentForm = ctrls[2];
  11373. var isReadonly = angular.isDefined(attr.readonly);
  11374. var mdNoAsterisk = $mdUtil.parseAttributeBoolean(attr.mdNoAsterisk);
  11375. var tagName = element[0].tagName.toLowerCase();
  11376. if (!containerCtrl) return;
  11377. if (attr.type === 'hidden') {
  11378. element.attr('aria-hidden', 'true');
  11379. return;
  11380. } else if (containerCtrl.input) {
  11381. if (containerCtrl.input[0].contains(element[0])) {
  11382. return;
  11383. } else {
  11384. throw new Error("<md-input-container> can only have *one* <input>, <textarea> or <md-select> child element!");
  11385. }
  11386. }
  11387. containerCtrl.input = element;
  11388. setupAttributeWatchers();
  11389. // Add an error spacer div after our input to provide space for the char counter and any ng-messages
  11390. var errorsSpacer = angular.element('<div class="md-errors-spacer">');
  11391. element.after(errorsSpacer);
  11392. var placeholderText = angular.isString(attr.placeholder) ? attr.placeholder.trim() : '';
  11393. if (!containerCtrl.label && !placeholderText.length) {
  11394. $mdAria.expect(element, 'aria-label');
  11395. }
  11396. element.addClass('md-input');
  11397. if (!element.attr('id')) {
  11398. element.attr('id', 'input_' + $mdUtil.nextUid());
  11399. }
  11400. // This works around a Webkit issue where number inputs, placed in a flexbox, that have
  11401. // a `min` and `max` will collapse to about 1/3 of their proper width. Please check #7349
  11402. // for more info. Also note that we don't override the `step` if the user has specified it,
  11403. // in order to prevent some unexpected behaviour.
  11404. if (tagName === 'input' && attr.type === 'number' && attr.min && attr.max && !attr.step) {
  11405. element.attr('step', 'any');
  11406. } else if (tagName === 'textarea') {
  11407. setupTextarea();
  11408. }
  11409. // If the input doesn't have an ngModel, it may have a static value. For that case,
  11410. // we have to do one initial check to determine if the container should be in the
  11411. // "has a value" state.
  11412. if (!hasNgModel) {
  11413. inputCheckValue();
  11414. }
  11415. var isErrorGetter = containerCtrl.isErrorGetter || function() {
  11416. return ngModelCtrl.$invalid && (ngModelCtrl.$touched || (parentForm && parentForm.$submitted));
  11417. };
  11418. scope.$watch(isErrorGetter, containerCtrl.setInvalid);
  11419. // When the developer uses the ngValue directive for the input, we have to observe the attribute, because
  11420. // AngularJS's ngValue directive is just setting the `value` attribute.
  11421. if (attr.ngValue) {
  11422. attr.$observe('value', inputCheckValue);
  11423. }
  11424. ngModelCtrl.$parsers.push(ngModelPipelineCheckValue);
  11425. ngModelCtrl.$formatters.push(ngModelPipelineCheckValue);
  11426. element.on('input', inputCheckValue);
  11427. if (!isReadonly) {
  11428. element
  11429. .on('focus', function(ev) {
  11430. $mdUtil.nextTick(function() {
  11431. containerCtrl.setFocused(true);
  11432. });
  11433. })
  11434. .on('blur', function(ev) {
  11435. $mdUtil.nextTick(function() {
  11436. containerCtrl.setFocused(false);
  11437. inputCheckValue();
  11438. });
  11439. });
  11440. }
  11441. scope.$on('$destroy', function() {
  11442. containerCtrl.setFocused(false);
  11443. containerCtrl.setHasValue(false);
  11444. containerCtrl.input = null;
  11445. });
  11446. /** Gets run through ngModel's pipeline and set the `has-value` class on the container. */
  11447. function ngModelPipelineCheckValue(arg) {
  11448. containerCtrl.setHasValue(!ngModelCtrl.$isEmpty(arg));
  11449. return arg;
  11450. }
  11451. function setupAttributeWatchers() {
  11452. if (containerCtrl.label) {
  11453. attr.$observe('required', function (value) {
  11454. // We don't need to parse the required value, it's always a boolean because of angular's
  11455. // required directive.
  11456. containerCtrl.label.toggleClass('md-required', value && !mdNoAsterisk);
  11457. });
  11458. }
  11459. }
  11460. function inputCheckValue() {
  11461. // An input's value counts if its length > 0,
  11462. // or if the input's validity state says it has bad input (eg string in a number input)
  11463. containerCtrl.setHasValue(element.val().length > 0 || (element[0].validity || {}).badInput);
  11464. }
  11465. function setupTextarea() {
  11466. var isAutogrowing = !attr.hasOwnProperty('mdNoAutogrow');
  11467. attachResizeHandle();
  11468. if (!isAutogrowing) return;
  11469. // Can't check if height was or not explicity set,
  11470. // so rows attribute will take precedence if present
  11471. var minRows = attr.hasOwnProperty('rows') ? parseInt(attr.rows) : NaN;
  11472. var maxRows = attr.hasOwnProperty('maxRows') ? parseInt(attr.maxRows) : NaN;
  11473. var scopeResizeListener = scope.$on('md-resize-textarea', growTextarea);
  11474. var lineHeight = null;
  11475. var node = element[0];
  11476. // This timeout is necessary, because the browser needs a little bit
  11477. // of time to calculate the `clientHeight` and `scrollHeight`.
  11478. $timeout(function() {
  11479. $mdUtil.nextTick(growTextarea);
  11480. }, 10, false);
  11481. // We could leverage ngModel's $parsers here, however it
  11482. // isn't reliable, because AngularJS trims the input by default,
  11483. // which means that growTextarea won't fire when newlines and
  11484. // spaces are added.
  11485. element.on('input', growTextarea);
  11486. // We should still use the $formatters, because they fire when
  11487. // the value was changed from outside the textarea.
  11488. if (hasNgModel) {
  11489. ngModelCtrl.$formatters.push(formattersListener);
  11490. }
  11491. if (!minRows) {
  11492. element.attr('rows', 1);
  11493. }
  11494. angular.element($window).on('resize', growTextarea);
  11495. scope.$on('$destroy', disableAutogrow);
  11496. function growTextarea() {
  11497. // temporarily disables element's flex so its height 'runs free'
  11498. element
  11499. .attr('rows', 1)
  11500. .css('height', 'auto')
  11501. .addClass('md-no-flex');
  11502. var height = getHeight();
  11503. if (!lineHeight) {
  11504. // offsetHeight includes padding which can throw off our value
  11505. var originalPadding = element[0].style.padding || '';
  11506. lineHeight = element.css('padding', 0).prop('offsetHeight');
  11507. element[0].style.padding = originalPadding;
  11508. }
  11509. if (minRows && lineHeight) {
  11510. height = Math.max(height, lineHeight * minRows);
  11511. }
  11512. if (maxRows && lineHeight) {
  11513. var maxHeight = lineHeight * maxRows;
  11514. if (maxHeight < height) {
  11515. element.attr('md-no-autogrow', '');
  11516. height = maxHeight;
  11517. } else {
  11518. element.removeAttr('md-no-autogrow');
  11519. }
  11520. }
  11521. if (lineHeight) {
  11522. element.attr('rows', Math.round(height / lineHeight));
  11523. }
  11524. element
  11525. .css('height', height + 'px')
  11526. .removeClass('md-no-flex');
  11527. }
  11528. function getHeight() {
  11529. var offsetHeight = node.offsetHeight;
  11530. var line = node.scrollHeight - offsetHeight;
  11531. return offsetHeight + Math.max(line, 0);
  11532. }
  11533. function formattersListener(value) {
  11534. $mdUtil.nextTick(growTextarea);
  11535. return value;
  11536. }
  11537. function disableAutogrow() {
  11538. if (!isAutogrowing) return;
  11539. isAutogrowing = false;
  11540. angular.element($window).off('resize', growTextarea);
  11541. scopeResizeListener && scopeResizeListener();
  11542. element
  11543. .attr('md-no-autogrow', '')
  11544. .off('input', growTextarea);
  11545. if (hasNgModel) {
  11546. var listenerIndex = ngModelCtrl.$formatters.indexOf(formattersListener);
  11547. if (listenerIndex > -1) {
  11548. ngModelCtrl.$formatters.splice(listenerIndex, 1);
  11549. }
  11550. }
  11551. }
  11552. function attachResizeHandle() {
  11553. if (attr.hasOwnProperty('mdNoResize')) return;
  11554. var handle = angular.element('<div class="md-resize-handle"></div>');
  11555. var isDragging = false;
  11556. var dragStart = null;
  11557. var startHeight = 0;
  11558. var container = containerCtrl.element;
  11559. var dragGestureHandler = $mdGesture.register(handle, 'drag', { horizontal: false });
  11560. element.wrap('<div class="md-resize-wrapper">').after(handle);
  11561. handle.on('mousedown', onMouseDown);
  11562. container
  11563. .on('$md.dragstart', onDragStart)
  11564. .on('$md.drag', onDrag)
  11565. .on('$md.dragend', onDragEnd);
  11566. scope.$on('$destroy', function() {
  11567. handle
  11568. .off('mousedown', onMouseDown)
  11569. .remove();
  11570. container
  11571. .off('$md.dragstart', onDragStart)
  11572. .off('$md.drag', onDrag)
  11573. .off('$md.dragend', onDragEnd);
  11574. dragGestureHandler();
  11575. handle = null;
  11576. container = null;
  11577. dragGestureHandler = null;
  11578. });
  11579. function onMouseDown(ev) {
  11580. ev.preventDefault();
  11581. isDragging = true;
  11582. dragStart = ev.clientY;
  11583. startHeight = parseFloat(element.css('height')) || element.prop('offsetHeight');
  11584. }
  11585. function onDragStart(ev) {
  11586. if (!isDragging) return;
  11587. ev.preventDefault();
  11588. disableAutogrow();
  11589. container.addClass('md-input-resized');
  11590. }
  11591. function onDrag(ev) {
  11592. if (!isDragging) return;
  11593. element.css('height', (startHeight + ev.pointer.distanceY) + 'px');
  11594. }
  11595. function onDragEnd(ev) {
  11596. if (!isDragging) return;
  11597. isDragging = false;
  11598. container.removeClass('md-input-resized');
  11599. }
  11600. }
  11601. // Attach a watcher to detect when the textarea gets shown.
  11602. if (attr.hasOwnProperty('mdDetectHidden')) {
  11603. var handleHiddenChange = function() {
  11604. var wasHidden = false;
  11605. return function() {
  11606. var isHidden = node.offsetHeight === 0;
  11607. if (isHidden === false && wasHidden === true) {
  11608. growTextarea();
  11609. }
  11610. wasHidden = isHidden;
  11611. };
  11612. }();
  11613. // Check every digest cycle whether the visibility of the textarea has changed.
  11614. // Queue up to run after the digest cycle is complete.
  11615. scope.$watch(function() {
  11616. $mdUtil.nextTick(handleHiddenChange, false);
  11617. return true;
  11618. });
  11619. }
  11620. }
  11621. }
  11622. }
  11623. function mdMaxlengthDirective($animate, $mdUtil) {
  11624. return {
  11625. restrict: 'A',
  11626. require: ['ngModel', '^mdInputContainer'],
  11627. link: postLink
  11628. };
  11629. function postLink(scope, element, attr, ctrls) {
  11630. var maxlength = parseInt(attr.mdMaxlength);
  11631. if (isNaN(maxlength)) maxlength = -1;
  11632. var ngModelCtrl = ctrls[0];
  11633. var containerCtrl = ctrls[1];
  11634. var charCountEl, errorsSpacer;
  11635. ngModelCtrl.$validators['md-maxlength'] = function(modelValue, viewValue) {
  11636. if (!angular.isNumber(maxlength) || maxlength < 0) {
  11637. return true;
  11638. }
  11639. // We always update the char count, when the modelValue has changed.
  11640. // Using the $validators for triggering the update works very well.
  11641. renderCharCount();
  11642. return ( modelValue || element.val() || viewValue || '' ).length <= maxlength;
  11643. };
  11644. // Wait until the next tick to ensure that the input has setup the errors spacer where we will
  11645. // append our counter
  11646. $mdUtil.nextTick(function() {
  11647. errorsSpacer = angular.element(containerCtrl.element[0].querySelector('.md-errors-spacer'));
  11648. charCountEl = angular.element('<div class="md-char-counter">');
  11649. // Append our character counter inside the errors spacer
  11650. errorsSpacer.append(charCountEl);
  11651. // Stop model from trimming. This makes it so whitespace
  11652. // over the maxlength still counts as invalid.
  11653. attr.$set('ngTrim', 'false');
  11654. scope.$watch(attr.mdMaxlength, function(value) {
  11655. maxlength = value;
  11656. if (angular.isNumber(value) && value > 0) {
  11657. if (!charCountEl.parent().length) {
  11658. $animate.enter(charCountEl, errorsSpacer);
  11659. }
  11660. renderCharCount();
  11661. } else {
  11662. $animate.leave(charCountEl);
  11663. }
  11664. });
  11665. });
  11666. function renderCharCount(value) {
  11667. // If we have not been initialized or appended to the body yet; do not render
  11668. if (!charCountEl || !charCountEl.parent) {
  11669. return value;
  11670. }
  11671. // Force the value into a string since it may be a number,
  11672. // which does not have a length property.
  11673. charCountEl.text(String(element.val() || value || '').length + ' / ' + maxlength);
  11674. return value;
  11675. }
  11676. }
  11677. }
  11678. function placeholderDirective($compile) {
  11679. return {
  11680. restrict: 'A',
  11681. require: '^^?mdInputContainer',
  11682. priority: 200,
  11683. link: {
  11684. // Note that we need to do this in the pre-link, as opposed to the post link, if we want to
  11685. // support data bindings in the placeholder. This is necessary, because we have a case where
  11686. // we transfer the placeholder value to the `<label>` and we remove it from the original `<input>`.
  11687. // If we did this in the post-link, AngularJS would have set up the observers already and would be
  11688. // re-adding the attribute, even though we removed it from the element.
  11689. pre: preLink
  11690. }
  11691. };
  11692. function preLink(scope, element, attr, inputContainer) {
  11693. // If there is no input container, just return
  11694. if (!inputContainer) return;
  11695. var label = inputContainer.element.find('label');
  11696. var noFloat = inputContainer.element.attr('md-no-float');
  11697. // If we have a label, or they specify the md-no-float attribute, just return
  11698. if ((label && label.length) || noFloat === '' || scope.$eval(noFloat)) {
  11699. // Add a placeholder class so we can target it in the CSS
  11700. inputContainer.setHasPlaceholder(true);
  11701. return;
  11702. }
  11703. // md-select handles placeholders on it's own
  11704. if (element[0].nodeName != 'MD-SELECT') {
  11705. // Move the placeholder expression to the label
  11706. var newLabel = angular.element('<label ng-click="delegateClick()" tabindex="-1">' + attr.placeholder + '</label>');
  11707. // Note that we unset it via `attr`, in order to get AngularJS
  11708. // to remove any observers that it might have set up. Otherwise
  11709. // the attribute will be added on the next digest.
  11710. attr.$set('placeholder', null);
  11711. // We need to compile the label manually in case it has any bindings.
  11712. // A gotcha here is that we first add the element to the DOM and we compile
  11713. // it later. This is necessary, because if we compile the element beforehand,
  11714. // it won't be able to find the `mdInputContainer` controller.
  11715. inputContainer.element
  11716. .addClass('md-icon-float')
  11717. .prepend(newLabel);
  11718. $compile(newLabel)(scope);
  11719. }
  11720. }
  11721. }
  11722. /**
  11723. * @ngdoc directive
  11724. * @name mdSelectOnFocus
  11725. * @module material.components.input
  11726. *
  11727. * @restrict A
  11728. *
  11729. * @description
  11730. * The `md-select-on-focus` directive allows you to automatically select the element's input text on focus.
  11731. *
  11732. * <h3>Notes</h3>
  11733. * - The use of `md-select-on-focus` is restricted to `<input>` and `<textarea>` elements.
  11734. *
  11735. * @usage
  11736. * <h3>Using with an Input</h3>
  11737. * <hljs lang="html">
  11738. *
  11739. * <md-input-container>
  11740. * <label>Auto Select</label>
  11741. * <input type="text" md-select-on-focus>
  11742. * </md-input-container>
  11743. * </hljs>
  11744. *
  11745. * <h3>Using with a Textarea</h3>
  11746. * <hljs lang="html">
  11747. *
  11748. * <md-input-container>
  11749. * <label>Auto Select</label>
  11750. * <textarea md-select-on-focus>This text will be selected on focus.</textarea>
  11751. * </md-input-container>
  11752. *
  11753. * </hljs>
  11754. */
  11755. function mdSelectOnFocusDirective($document, $timeout) {
  11756. return {
  11757. restrict: 'A',
  11758. link: postLink
  11759. };
  11760. function postLink(scope, element, attr) {
  11761. if (element[0].nodeName !== 'INPUT' && element[0].nodeName !== "TEXTAREA") return;
  11762. var preventMouseUp = false;
  11763. element
  11764. .on('focus', onFocus)
  11765. .on('mouseup', onMouseUp);
  11766. scope.$on('$destroy', function() {
  11767. element
  11768. .off('focus', onFocus)
  11769. .off('mouseup', onMouseUp);
  11770. });
  11771. function onFocus() {
  11772. preventMouseUp = true;
  11773. $timeout(function() {
  11774. // Use HTMLInputElement#select to fix firefox select issues.
  11775. // The debounce is here for Edge's sake, otherwise the selection doesn't work.
  11776. // Since focus may already have been lost on the input (and because `select()`
  11777. // will re-focus), make sure the element is still active before applying.
  11778. if($document[0].activeElement === element[0]) {
  11779. element[0].select();
  11780. }
  11781. // This should be reset from inside the `focus`, because the event might
  11782. // have originated from something different than a click, e.g. a keyboard event.
  11783. preventMouseUp = false;
  11784. }, 1, false);
  11785. }
  11786. // Prevents the default action of the first `mouseup` after a focus.
  11787. // This is necessary, because browsers fire a `mouseup` right after the element
  11788. // has been focused. In some browsers (Firefox in particular) this can clear the
  11789. // selection. There are examples of the problem in issue #7487.
  11790. function onMouseUp(event) {
  11791. if (preventMouseUp) {
  11792. event.preventDefault();
  11793. }
  11794. }
  11795. }
  11796. }
  11797. var visibilityDirectives = ['ngIf', 'ngShow', 'ngHide', 'ngSwitchWhen', 'ngSwitchDefault'];
  11798. function ngMessagesDirective() {
  11799. return {
  11800. restrict: 'EA',
  11801. link: postLink,
  11802. // This is optional because we don't want target *all* ngMessage instances, just those inside of
  11803. // mdInputContainer.
  11804. require: '^^?mdInputContainer'
  11805. };
  11806. function postLink(scope, element, attrs, inputContainer) {
  11807. // If we are not a child of an input container, don't do anything
  11808. if (!inputContainer) return;
  11809. // Add our animation class
  11810. element.toggleClass('md-input-messages-animation', true);
  11811. // Add our md-auto-hide class to automatically hide/show messages when container is invalid
  11812. element.toggleClass('md-auto-hide', true);
  11813. // If we see some known visibility directives, remove the md-auto-hide class
  11814. if (attrs.mdAutoHide == 'false' || hasVisibiltyDirective(attrs)) {
  11815. element.toggleClass('md-auto-hide', false);
  11816. }
  11817. }
  11818. function hasVisibiltyDirective(attrs) {
  11819. return visibilityDirectives.some(function(attr) {
  11820. return attrs[attr];
  11821. });
  11822. }
  11823. }
  11824. function ngMessageDirective($mdUtil) {
  11825. return {
  11826. restrict: 'EA',
  11827. compile: compile,
  11828. priority: 100
  11829. };
  11830. function compile(tElement) {
  11831. if (!isInsideInputContainer(tElement)) {
  11832. // When the current element is inside of a document fragment, then we need to check for an input-container
  11833. // in the postLink, because the element will be later added to the DOM and is currently just in a temporary
  11834. // fragment, which causes the input-container check to fail.
  11835. if (isInsideFragment()) {
  11836. return function (scope, element) {
  11837. if (isInsideInputContainer(element)) {
  11838. // Inside of the postLink function, a ngMessage directive will be a comment element, because it's
  11839. // currently hidden. To access the shown element, we need to use the element from the compile function.
  11840. initMessageElement(tElement);
  11841. }
  11842. };
  11843. }
  11844. } else {
  11845. initMessageElement(tElement);
  11846. }
  11847. function isInsideFragment() {
  11848. var nextNode = tElement[0];
  11849. while (nextNode = nextNode.parentNode) {
  11850. if (nextNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
  11851. return true;
  11852. }
  11853. }
  11854. return false;
  11855. }
  11856. function isInsideInputContainer(element) {
  11857. return !!$mdUtil.getClosest(element, "md-input-container");
  11858. }
  11859. function initMessageElement(element) {
  11860. // Add our animation class
  11861. element.toggleClass('md-input-message-animation', true);
  11862. }
  11863. }
  11864. }
  11865. var $$AnimateRunner, $animateCss, $mdUtil, $log;
  11866. function mdInputInvalidMessagesAnimation($$AnimateRunner, $animateCss, $mdUtil, $log) {
  11867. saveSharedServices($$AnimateRunner, $animateCss, $mdUtil, $log);
  11868. return {
  11869. addClass: function(element, className, done) {
  11870. showInputMessages(element, done);
  11871. }
  11872. // NOTE: We do not need the removeClass method, because the message ng-leave animation will fire
  11873. };
  11874. }
  11875. function ngMessagesAnimation($$AnimateRunner, $animateCss, $mdUtil, $log) {
  11876. saveSharedServices($$AnimateRunner, $animateCss, $mdUtil, $log);
  11877. return {
  11878. enter: function(element, done) {
  11879. showInputMessages(element, done);
  11880. },
  11881. leave: function(element, done) {
  11882. hideInputMessages(element, done);
  11883. },
  11884. addClass: function(element, className, done) {
  11885. if (className == "ng-hide") {
  11886. hideInputMessages(element, done);
  11887. } else {
  11888. done();
  11889. }
  11890. },
  11891. removeClass: function(element, className, done) {
  11892. if (className == "ng-hide") {
  11893. showInputMessages(element, done);
  11894. } else {
  11895. done();
  11896. }
  11897. }
  11898. };
  11899. }
  11900. function ngMessageAnimation($$AnimateRunner, $animateCss, $mdUtil, $log) {
  11901. saveSharedServices($$AnimateRunner, $animateCss, $mdUtil, $log);
  11902. return {
  11903. enter: function(element, done) {
  11904. var animator = showMessage(element);
  11905. animator.start().done(done);
  11906. },
  11907. leave: function(element, done) {
  11908. var animator = hideMessage(element);
  11909. animator.start().done(done);
  11910. }
  11911. };
  11912. }
  11913. function showInputMessages(element, done) {
  11914. var animators = [], animator;
  11915. var messages = getMessagesElement(element);
  11916. var children = messages.children();
  11917. if (messages.length == 0 || children.length == 0) {
  11918. $log.warn('mdInput messages show animation called on invalid messages element: ', element);
  11919. done();
  11920. return;
  11921. }
  11922. angular.forEach(children, function(child) {
  11923. animator = showMessage(angular.element(child));
  11924. animators.push(animator.start());
  11925. });
  11926. $$AnimateRunner.all(animators, done);
  11927. }
  11928. function hideInputMessages(element, done) {
  11929. var animators = [], animator;
  11930. var messages = getMessagesElement(element);
  11931. var children = messages.children();
  11932. if (messages.length == 0 || children.length == 0) {
  11933. $log.warn('mdInput messages hide animation called on invalid messages element: ', element);
  11934. done();
  11935. return;
  11936. }
  11937. angular.forEach(children, function(child) {
  11938. animator = hideMessage(angular.element(child));
  11939. animators.push(animator.start());
  11940. });
  11941. $$AnimateRunner.all(animators, done);
  11942. }
  11943. function showMessage(element) {
  11944. var height = parseInt(window.getComputedStyle(element[0]).height);
  11945. var topMargin = parseInt(window.getComputedStyle(element[0]).marginTop);
  11946. var messages = getMessagesElement(element);
  11947. var container = getInputElement(element);
  11948. // Check to see if the message is already visible so we can skip
  11949. var alreadyVisible = (topMargin > -height);
  11950. // If we have the md-auto-hide class, the md-input-invalid animation will fire, so we can skip
  11951. if (alreadyVisible || (messages.hasClass('md-auto-hide') && !container.hasClass('md-input-invalid'))) {
  11952. return $animateCss(element, {});
  11953. }
  11954. return $animateCss(element, {
  11955. event: 'enter',
  11956. structural: true,
  11957. from: {"opacity": 0, "margin-top": -height + "px"},
  11958. to: {"opacity": 1, "margin-top": "0"},
  11959. duration: 0.3
  11960. });
  11961. }
  11962. function hideMessage(element) {
  11963. var height = element[0].offsetHeight;
  11964. var styles = window.getComputedStyle(element[0]);
  11965. // If we are already hidden, just return an empty animation
  11966. if (parseInt(styles.opacity) === 0) {
  11967. return $animateCss(element, {});
  11968. }
  11969. // Otherwise, animate
  11970. return $animateCss(element, {
  11971. event: 'leave',
  11972. structural: true,
  11973. from: {"opacity": 1, "margin-top": 0},
  11974. to: {"opacity": 0, "margin-top": -height + "px"},
  11975. duration: 0.3
  11976. });
  11977. }
  11978. function getInputElement(element) {
  11979. var inputContainer = element.controller('mdInputContainer');
  11980. return inputContainer.element;
  11981. }
  11982. function getMessagesElement(element) {
  11983. // If we ARE the messages element, just return ourself
  11984. if (element.hasClass('md-input-messages-animation')) {
  11985. return element;
  11986. }
  11987. // If we are a ng-message element, we need to traverse up the DOM tree
  11988. if (element.hasClass('md-input-message-animation')) {
  11989. return angular.element($mdUtil.getClosest(element, function(node) {
  11990. return node.classList.contains('md-input-messages-animation');
  11991. }));
  11992. }
  11993. // Otherwise, we can traverse down
  11994. return angular.element(element[0].querySelector('.md-input-messages-animation'));
  11995. }
  11996. function saveSharedServices(_$$AnimateRunner_, _$animateCss_, _$mdUtil_, _$log_) {
  11997. $$AnimateRunner = _$$AnimateRunner_;
  11998. $animateCss = _$animateCss_;
  11999. $mdUtil = _$mdUtil_;
  12000. $log = _$log_;
  12001. }
  12002. })();
  12003. (function(){
  12004. "use strict";
  12005. /**
  12006. * @ngdoc module
  12007. * @name material.components.list
  12008. * @description
  12009. * List module
  12010. */
  12011. MdListController.$inject = ["$scope", "$element", "$mdListInkRipple"];
  12012. mdListDirective.$inject = ["$mdTheming"];
  12013. mdListItemDirective.$inject = ["$mdAria", "$mdConstant", "$mdUtil", "$timeout"];
  12014. angular.module('material.components.list', [
  12015. 'material.core'
  12016. ])
  12017. .controller('MdListController', MdListController)
  12018. .directive('mdList', mdListDirective)
  12019. .directive('mdListItem', mdListItemDirective);
  12020. /**
  12021. * @ngdoc directive
  12022. * @name mdList
  12023. * @module material.components.list
  12024. *
  12025. * @restrict E
  12026. *
  12027. * @description
  12028. * The `<md-list>` directive is a list container for 1..n `<md-list-item>` tags.
  12029. *
  12030. * @usage
  12031. * <hljs lang="html">
  12032. * <md-list>
  12033. * <md-list-item class="md-2-line" ng-repeat="item in todos">
  12034. * <md-checkbox ng-model="item.done"></md-checkbox>
  12035. * <div class="md-list-item-text">
  12036. * <h3>{{item.title}}</h3>
  12037. * <p>{{item.description}}</p>
  12038. * </div>
  12039. * </md-list-item>
  12040. * </md-list>
  12041. * </hljs>
  12042. */
  12043. function mdListDirective($mdTheming) {
  12044. return {
  12045. restrict: 'E',
  12046. compile: function(tEl) {
  12047. tEl[0].setAttribute('role', 'list');
  12048. return $mdTheming;
  12049. }
  12050. };
  12051. }
  12052. /**
  12053. * @ngdoc directive
  12054. * @name mdListItem
  12055. * @module material.components.list
  12056. *
  12057. * @restrict E
  12058. *
  12059. * @description
  12060. * A `md-list-item` element can be used to represent some information in a row.<br/>
  12061. *
  12062. * @usage
  12063. * ### Single Row Item
  12064. * <hljs lang="html">
  12065. * <md-list-item>
  12066. * <span>Single Row Item</span>
  12067. * </md-list-item>
  12068. * </hljs>
  12069. *
  12070. * ### Multiple Lines
  12071. * By using the following markup, you will be able to have two lines inside of one `md-list-item`.
  12072. *
  12073. * <hljs lang="html">
  12074. * <md-list-item class="md-2-line">
  12075. * <div class="md-list-item-text" layout="column">
  12076. * <p>First Line</p>
  12077. * <p>Second Line</p>
  12078. * </div>
  12079. * </md-list-item>
  12080. * </hljs>
  12081. *
  12082. * It is also possible to have three lines inside of one list item.
  12083. *
  12084. * <hljs lang="html">
  12085. * <md-list-item class="md-3-line">
  12086. * <div class="md-list-item-text" layout="column">
  12087. * <p>First Line</p>
  12088. * <p>Second Line</p>
  12089. * <p>Third Line</p>
  12090. * </div>
  12091. * </md-list-item>
  12092. * </hljs>
  12093. *
  12094. * ### Secondary Items
  12095. * Secondary items are elements which will be aligned at the end of the `md-list-item`.
  12096. *
  12097. * <hljs lang="html">
  12098. * <md-list-item>
  12099. * <span>Single Row Item</span>
  12100. * <md-button class="md-secondary">
  12101. * Secondary Button
  12102. * </md-button>
  12103. * </md-list-item>
  12104. * </hljs>
  12105. *
  12106. * It also possible to have multiple secondary items inside of one `md-list-item`.
  12107. *
  12108. * <hljs lang="html">
  12109. * <md-list-item>
  12110. * <span>Single Row Item</span>
  12111. * <md-button class="md-secondary">First Button</md-button>
  12112. * <md-button class="md-secondary">Second Button</md-button>
  12113. * </md-list-item>
  12114. * </hljs>
  12115. *
  12116. * ### Proxy Item
  12117. * Proxies are elements, which will execute their specific action on click<br/>
  12118. * Currently supported proxy items are
  12119. * - `md-checkbox` (Toggle)
  12120. * - `md-switch` (Toggle)
  12121. * - `md-menu` (Open)
  12122. *
  12123. * This means, when using a supported proxy item inside of `md-list-item`, the list item will
  12124. * automatically become clickable and executes the associated action of the proxy element on click.
  12125. *
  12126. * It is possible to disable this behavior by applying the `md-no-proxy` class to the list item.
  12127. *
  12128. * <hljs lang="html">
  12129. * <md-list-item class="md-no-proxy">
  12130. * <span>No Proxy List</span>
  12131. * <md-checkbox class="md-secondary"></md-checkbox>
  12132. * </md-list-item>
  12133. * </hljs>
  12134. *
  12135. * Here are a few examples of proxy elements inside of a list item.
  12136. *
  12137. * <hljs lang="html">
  12138. * <md-list-item>
  12139. * <span>First Line</span>
  12140. * <md-checkbox class="md-secondary"></md-checkbox>
  12141. * </md-list-item>
  12142. * </hljs>
  12143. *
  12144. * The `md-checkbox` element will be automatically detected as a proxy element and will toggle on click.
  12145. *
  12146. * <hljs lang="html">
  12147. * <md-list-item>
  12148. * <span>First Line</span>
  12149. * <md-switch class="md-secondary"></md-switch>
  12150. * </md-list-item>
  12151. * </hljs>
  12152. *
  12153. * The recognized `md-switch` will toggle its state, when the user clicks on the `md-list-item`.
  12154. *
  12155. * It is also possible to have a `md-menu` inside of a `md-list-item`.
  12156. * <hljs lang="html">
  12157. * <md-list-item>
  12158. * <p>Click anywhere to fire the secondary action</p>
  12159. * <md-menu class="md-secondary">
  12160. * <md-button class="md-icon-button">
  12161. * <md-icon md-svg-icon="communication:message"></md-icon>
  12162. * </md-button>
  12163. * <md-menu-content width="4">
  12164. * <md-menu-item>
  12165. * <md-button>
  12166. * Redial
  12167. * </md-button>
  12168. * </md-menu-item>
  12169. * <md-menu-item>
  12170. * <md-button>
  12171. * Check voicemail
  12172. * </md-button>
  12173. * </md-menu-item>
  12174. * <md-menu-divider></md-menu-divider>
  12175. * <md-menu-item>
  12176. * <md-button>
  12177. * Notifications
  12178. * </md-button>
  12179. * </md-menu-item>
  12180. * </md-menu-content>
  12181. * </md-menu>
  12182. * </md-list-item>
  12183. * </hljs>
  12184. *
  12185. * The menu will automatically open, when the users clicks on the `md-list-item`.<br/>
  12186. *
  12187. * If the developer didn't specify any position mode on the menu, the `md-list-item` will automatically detect the
  12188. * position mode and applies it to the `md-menu`.
  12189. *
  12190. * ### Avatars
  12191. * Sometimes you may want to have some avatars inside of the `md-list-item `.<br/>
  12192. * You are able to create a optimized icon for the list item, by applying the `.md-avatar` class on the `<img>` element.
  12193. *
  12194. * <hljs lang="html">
  12195. * <md-list-item>
  12196. * <img src="my-avatar.png" class="md-avatar">
  12197. * <span>Alan Turing</span>
  12198. * </hljs>
  12199. *
  12200. * When using `<md-icon>` for an avatar, you have to use the `.md-avatar-icon` class.
  12201. * <hljs lang="html">
  12202. * <md-list-item>
  12203. * <md-icon class="md-avatar-icon" md-svg-icon="avatars:timothy"></md-icon>
  12204. * <span>Timothy Kopra</span>
  12205. * </md-list-item>
  12206. * </hljs>
  12207. *
  12208. * In cases, you have a `md-list-item`, which doesn't have any avatar,
  12209. * but you want to align it with the other avatar items, you have to use the `.md-offset` class.
  12210. *
  12211. * <hljs lang="html">
  12212. * <md-list-item class="md-offset">
  12213. * <span>Jon Doe</span>
  12214. * </md-list-item>
  12215. * </hljs>
  12216. *
  12217. * ### DOM modification
  12218. * The `md-list-item` component automatically detects if the list item should be clickable.
  12219. *
  12220. * ---
  12221. * If the `md-list-item` is clickable, we wrap all content inside of a `<div>` and create
  12222. * an overlaying button, which will will execute the given actions (like `ng-href`, `ng-click`)
  12223. *
  12224. * We create an overlaying button, instead of wrapping all content inside of the button,
  12225. * because otherwise some elements may not be clickable inside of the button.
  12226. *
  12227. * ---
  12228. * When using a secondary item inside of your list item, the `md-list-item` component will automatically create
  12229. * a secondary container at the end of the `md-list-item`, which contains all secondary items.
  12230. *
  12231. * The secondary item container is not static, because otherwise the overflow will not work properly on the
  12232. * list item.
  12233. *
  12234. */
  12235. function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
  12236. var proxiedTypes = ['md-checkbox', 'md-switch', 'md-menu'];
  12237. return {
  12238. restrict: 'E',
  12239. controller: 'MdListController',
  12240. compile: function(tEl, tAttrs) {
  12241. // Check for proxy controls (no ng-click on parent, and a control inside)
  12242. var secondaryItems = tEl[0].querySelectorAll('.md-secondary');
  12243. var hasProxiedElement;
  12244. var proxyElement;
  12245. var itemContainer = tEl;
  12246. tEl[0].setAttribute('role', 'listitem');
  12247. if (tAttrs.ngClick || tAttrs.ngDblclick || tAttrs.ngHref || tAttrs.href || tAttrs.uiSref || tAttrs.ngAttrUiSref) {
  12248. wrapIn('button');
  12249. } else if (!tEl.hasClass('md-no-proxy')) {
  12250. for (var i = 0, type; type = proxiedTypes[i]; ++i) {
  12251. if (proxyElement = tEl[0].querySelector(type)) {
  12252. hasProxiedElement = true;
  12253. break;
  12254. }
  12255. }
  12256. if (hasProxiedElement) {
  12257. wrapIn('div');
  12258. } else {
  12259. tEl.addClass('md-no-proxy');
  12260. }
  12261. }
  12262. wrapSecondaryItems();
  12263. setupToggleAria();
  12264. if (hasProxiedElement && proxyElement.nodeName === "MD-MENU") {
  12265. setupProxiedMenu();
  12266. }
  12267. function setupToggleAria() {
  12268. var toggleTypes = ['md-switch', 'md-checkbox'];
  12269. var toggle;
  12270. for (var i = 0, toggleType; toggleType = toggleTypes[i]; ++i) {
  12271. if (toggle = tEl.find(toggleType)[0]) {
  12272. if (!toggle.hasAttribute('aria-label')) {
  12273. var p = tEl.find('p')[0];
  12274. if (!p) return;
  12275. toggle.setAttribute('aria-label', 'Toggle ' + p.textContent);
  12276. }
  12277. }
  12278. }
  12279. }
  12280. function setupProxiedMenu() {
  12281. var menuEl = angular.element(proxyElement);
  12282. var isEndAligned = menuEl.parent().hasClass('md-secondary-container') ||
  12283. proxyElement.parentNode.firstElementChild !== proxyElement;
  12284. var xAxisPosition = 'left';
  12285. if (isEndAligned) {
  12286. // When the proxy item is aligned at the end of the list, we have to set the origin to the end.
  12287. xAxisPosition = 'right';
  12288. }
  12289. // Set the position mode / origin of the proxied menu.
  12290. if (!menuEl.attr('md-position-mode')) {
  12291. menuEl.attr('md-position-mode', xAxisPosition + ' target');
  12292. }
  12293. // Apply menu open binding to menu button
  12294. var menuOpenButton = menuEl.children().eq(0);
  12295. if (!hasClickEvent(menuOpenButton[0])) {
  12296. menuOpenButton.attr('ng-click', '$mdMenu.open($event)');
  12297. }
  12298. if (!menuOpenButton.attr('aria-label')) {
  12299. menuOpenButton.attr('aria-label', 'Open List Menu');
  12300. }
  12301. }
  12302. function wrapIn(type) {
  12303. if (type == 'div') {
  12304. itemContainer = angular.element('<div class="md-no-style md-list-item-inner">');
  12305. itemContainer.append(tEl.contents());
  12306. tEl.addClass('md-proxy-focus');
  12307. } else {
  12308. // Element which holds the default list-item content.
  12309. itemContainer = angular.element(
  12310. '<div class="md-button md-no-style">'+
  12311. ' <div class="md-list-item-inner"></div>'+
  12312. '</div>'
  12313. );
  12314. // Button which shows ripple and executes primary action.
  12315. var buttonWrap = angular.element(
  12316. '<md-button class="md-no-style"></md-button>'
  12317. );
  12318. copyAttributes(tEl[0], buttonWrap[0]);
  12319. // If there is no aria-label set on the button (previously copied over if present)
  12320. // we determine the label from the content and copy it to the button.
  12321. if (!buttonWrap.attr('aria-label')) {
  12322. buttonWrap.attr('aria-label', $mdAria.getText(tEl));
  12323. }
  12324. // We allow developers to specify the `md-no-focus` class, to disable the focus style
  12325. // on the button executor. Once more classes should be forwarded, we should probably make the
  12326. // class forward more generic.
  12327. if (tEl.hasClass('md-no-focus')) {
  12328. buttonWrap.addClass('md-no-focus');
  12329. }
  12330. // Append the button wrap before our list-item content, because it will overlay in relative.
  12331. itemContainer.prepend(buttonWrap);
  12332. itemContainer.children().eq(1).append(tEl.contents());
  12333. tEl.addClass('_md-button-wrap');
  12334. }
  12335. tEl[0].setAttribute('tabindex', '-1');
  12336. tEl.append(itemContainer);
  12337. }
  12338. function wrapSecondaryItems() {
  12339. var secondaryItemsWrapper = angular.element('<div class="md-secondary-container">');
  12340. angular.forEach(secondaryItems, function(secondaryItem) {
  12341. wrapSecondaryItem(secondaryItem, secondaryItemsWrapper);
  12342. });
  12343. itemContainer.append(secondaryItemsWrapper);
  12344. }
  12345. function wrapSecondaryItem(secondaryItem, container) {
  12346. // If the current secondary item is not a button, but contains a ng-click attribute,
  12347. // the secondary item will be automatically wrapped inside of a button.
  12348. if (secondaryItem && !isButton(secondaryItem) && secondaryItem.hasAttribute('ng-click')) {
  12349. $mdAria.expect(secondaryItem, 'aria-label');
  12350. var buttonWrapper = angular.element('<md-button class="md-secondary md-icon-button">');
  12351. // Copy the attributes from the secondary item to the generated button.
  12352. // We also support some additional attributes from the secondary item,
  12353. // because some developers may use a ngIf, ngHide, ngShow on their item.
  12354. copyAttributes(secondaryItem, buttonWrapper[0], ['ng-if', 'ng-hide', 'ng-show']);
  12355. secondaryItem.setAttribute('tabindex', '-1');
  12356. buttonWrapper.append(secondaryItem);
  12357. secondaryItem = buttonWrapper[0];
  12358. }
  12359. if (secondaryItem && (!hasClickEvent(secondaryItem) || (!tAttrs.ngClick && isProxiedElement(secondaryItem)))) {
  12360. // In this case we remove the secondary class, so we can identify it later, when we searching for the
  12361. // proxy items.
  12362. angular.element(secondaryItem).removeClass('md-secondary');
  12363. }
  12364. tEl.addClass('md-with-secondary');
  12365. container.append(secondaryItem);
  12366. }
  12367. /**
  12368. * Copies attributes from a source element to the destination element
  12369. * By default the function will copy the most necessary attributes, supported
  12370. * by the button executor for clickable list items.
  12371. * @param source Element with the specified attributes
  12372. * @param destination Element which will retrieve the attributes
  12373. * @param extraAttrs Additional attributes, which will be copied over.
  12374. */
  12375. function copyAttributes(source, destination, extraAttrs) {
  12376. var copiedAttrs = $mdUtil.prefixer([
  12377. 'ng-if', 'ng-click', 'ng-dblclick', 'aria-label', 'ng-disabled', 'ui-sref',
  12378. 'href', 'ng-href', 'rel', 'target', 'ng-attr-ui-sref', 'ui-sref-opts', 'download'
  12379. ]);
  12380. if (extraAttrs) {
  12381. copiedAttrs = copiedAttrs.concat($mdUtil.prefixer(extraAttrs));
  12382. }
  12383. angular.forEach(copiedAttrs, function(attr) {
  12384. if (source.hasAttribute(attr)) {
  12385. destination.setAttribute(attr, source.getAttribute(attr));
  12386. source.removeAttribute(attr);
  12387. }
  12388. });
  12389. }
  12390. function isProxiedElement(el) {
  12391. return proxiedTypes.indexOf(el.nodeName.toLowerCase()) != -1;
  12392. }
  12393. function isButton(el) {
  12394. var nodeName = el.nodeName.toUpperCase();
  12395. return nodeName == "MD-BUTTON" || nodeName == "BUTTON";
  12396. }
  12397. function hasClickEvent (element) {
  12398. var attr = element.attributes;
  12399. for (var i = 0; i < attr.length; i++) {
  12400. if (tAttrs.$normalize(attr[i].name) === 'ngClick') return true;
  12401. }
  12402. return false;
  12403. }
  12404. return postLink;
  12405. function postLink($scope, $element, $attr, ctrl) {
  12406. $element.addClass('_md'); // private md component indicator for styling
  12407. var proxies = [],
  12408. firstElement = $element[0].firstElementChild,
  12409. isButtonWrap = $element.hasClass('_md-button-wrap'),
  12410. clickChild = isButtonWrap ? firstElement.firstElementChild : firstElement,
  12411. hasClick = clickChild && hasClickEvent(clickChild),
  12412. noProxies = $element.hasClass('md-no-proxy');
  12413. computeProxies();
  12414. computeClickable();
  12415. if (proxies.length) {
  12416. angular.forEach(proxies, function(proxy) {
  12417. proxy = angular.element(proxy);
  12418. $scope.mouseActive = false;
  12419. proxy.on('mousedown', function() {
  12420. $scope.mouseActive = true;
  12421. $timeout(function(){
  12422. $scope.mouseActive = false;
  12423. }, 100);
  12424. })
  12425. .on('focus', function() {
  12426. if ($scope.mouseActive === false) { $element.addClass('md-focused'); }
  12427. proxy.on('blur', function proxyOnBlur() {
  12428. $element.removeClass('md-focused');
  12429. proxy.off('blur', proxyOnBlur);
  12430. });
  12431. });
  12432. });
  12433. }
  12434. function computeProxies() {
  12435. if (firstElement && firstElement.children && !hasClick && !noProxies) {
  12436. angular.forEach(proxiedTypes, function(type) {
  12437. // All elements which are not capable for being used a proxy have the .md-secondary class
  12438. // applied. These items had been sorted out in the secondary wrap function.
  12439. angular.forEach(firstElement.querySelectorAll(type + ':not(.md-secondary)'), function(child) {
  12440. proxies.push(child);
  12441. });
  12442. });
  12443. }
  12444. }
  12445. function computeClickable() {
  12446. if (proxies.length == 1 || hasClick) {
  12447. $element.addClass('md-clickable');
  12448. if (!hasClick) {
  12449. ctrl.attachRipple($scope, angular.element($element[0].querySelector('.md-no-style')));
  12450. }
  12451. }
  12452. }
  12453. function isEventFromControl(event) {
  12454. var forbiddenControls = ['md-slider'];
  12455. // If there is no path property in the event, then we can assume that the event was not bubbled.
  12456. if (!event.path) {
  12457. return forbiddenControls.indexOf(event.target.tagName.toLowerCase()) !== -1;
  12458. }
  12459. // We iterate the event path up and check for a possible component.
  12460. // Our maximum index to search, is the list item root.
  12461. var maxPath = event.path.indexOf($element.children()[0]);
  12462. for (var i = 0; i < maxPath; i++) {
  12463. if (forbiddenControls.indexOf(event.path[i].tagName.toLowerCase()) !== -1) {
  12464. return true;
  12465. }
  12466. }
  12467. }
  12468. var clickChildKeypressListener = function(e) {
  12469. if (e.target.nodeName != 'INPUT' && e.target.nodeName != 'TEXTAREA' && !e.target.isContentEditable) {
  12470. var keyCode = e.which || e.keyCode;
  12471. if (keyCode == $mdConstant.KEY_CODE.SPACE) {
  12472. if (clickChild) {
  12473. clickChild.click();
  12474. e.preventDefault();
  12475. e.stopPropagation();
  12476. }
  12477. }
  12478. }
  12479. };
  12480. if (!hasClick && !proxies.length) {
  12481. clickChild && clickChild.addEventListener('keypress', clickChildKeypressListener);
  12482. }
  12483. $element.off('click');
  12484. $element.off('keypress');
  12485. if (proxies.length == 1 && clickChild) {
  12486. $element.children().eq(0).on('click', function(e) {
  12487. // When the event is coming from an control and it should not trigger the proxied element
  12488. // then we are skipping.
  12489. if (isEventFromControl(e)) return;
  12490. var parentButton = $mdUtil.getClosest(e.target, 'BUTTON');
  12491. if (!parentButton && clickChild.contains(e.target)) {
  12492. angular.forEach(proxies, function(proxy) {
  12493. if (e.target !== proxy && !proxy.contains(e.target)) {
  12494. if (proxy.nodeName === 'MD-MENU') {
  12495. proxy = proxy.children[0];
  12496. }
  12497. angular.element(proxy).triggerHandler('click');
  12498. }
  12499. });
  12500. }
  12501. });
  12502. }
  12503. $scope.$on('$destroy', function () {
  12504. clickChild && clickChild.removeEventListener('keypress', clickChildKeypressListener);
  12505. });
  12506. }
  12507. }
  12508. };
  12509. }
  12510. /*
  12511. * @private
  12512. * @ngdoc controller
  12513. * @name MdListController
  12514. * @module material.components.list
  12515. *
  12516. */
  12517. function MdListController($scope, $element, $mdListInkRipple) {
  12518. var ctrl = this;
  12519. ctrl.attachRipple = attachRipple;
  12520. function attachRipple (scope, element) {
  12521. var options = {};
  12522. $mdListInkRipple.attach(scope, element, options);
  12523. }
  12524. }
  12525. })();
  12526. (function(){
  12527. "use strict";
  12528. /**
  12529. * @ngdoc module
  12530. * @name material.components.menu
  12531. */
  12532. angular.module('material.components.menu', [
  12533. 'material.core',
  12534. 'material.components.backdrop'
  12535. ]);
  12536. })();
  12537. (function(){
  12538. "use strict";
  12539. /**
  12540. * @ngdoc module
  12541. * @name material.components.menuBar
  12542. */
  12543. angular.module('material.components.menuBar', [
  12544. 'material.core',
  12545. 'material.components.icon',
  12546. 'material.components.menu'
  12547. ]);
  12548. })();
  12549. (function(){
  12550. "use strict";
  12551. /**
  12552. * @ngdoc module
  12553. * @name material.components.navBar
  12554. */
  12555. MdNavBarController.$inject = ["$element", "$scope", "$timeout", "$mdConstant"];
  12556. MdNavItem.$inject = ["$mdAria", "$$rAF", "$mdUtil", "$window"];
  12557. MdNavItemController.$inject = ["$element"];
  12558. MdNavBar.$inject = ["$mdAria", "$mdTheming"];
  12559. angular.module('material.components.navBar', ['material.core'])
  12560. .controller('MdNavBarController', MdNavBarController)
  12561. .directive('mdNavBar', MdNavBar)
  12562. .controller('MdNavItemController', MdNavItemController)
  12563. .directive('mdNavItem', MdNavItem);
  12564. /*****************************************************************************
  12565. * PUBLIC DOCUMENTATION *
  12566. *****************************************************************************/
  12567. /**
  12568. * @ngdoc directive
  12569. * @name mdNavBar
  12570. * @module material.components.navBar
  12571. *
  12572. * @restrict E
  12573. *
  12574. * @description
  12575. * The `<md-nav-bar>` directive renders a list of material tabs that can be used
  12576. * for top-level page navigation. Unlike `<md-tabs>`, it has no concept of a tab
  12577. * body and no bar pagination.
  12578. *
  12579. * Because it deals with page navigation, certain routing concepts are built-in.
  12580. * Route changes via `ng-href`, `ui-sref`, or `ng-click` events are supported.
  12581. * Alternatively, the user could simply watch the value of `md-selected-nav-item`
  12582. * (`currentNavItem` in the below example) for changes.
  12583. *
  12584. * Accessibility functionality is implemented as a site navigator with a
  12585. * listbox, according to the
  12586. * <a href="https://www.w3.org/TR/2016/WD-wai-aria-practices-1.1-20160317/#Site_Navigator_Tabbed_Style">
  12587. * WAI-ARIA Authoring Practices 1.1 Working Draft from March 2016</a>.
  12588. * We've kept the `role="navigation"` on the `<nav>`, for backwards compatibility, even though
  12589. * it is not required in the
  12590. * <a href="https://www.w3.org/TR/wai-aria-practices/#aria_lh_navigation">
  12591. * latest Working Group Note from December 2017</a>.
  12592. *
  12593. * @param {string=} md-selected-nav-item The name of the current tab; this must
  12594. * match the `name` attribute of `<md-nav-item>`.
  12595. * @param {boolean=} md-no-ink-bar If set to true, the ink bar will be hidden.
  12596. * @param {string=} nav-bar-aria-label An `aria-label` applied to the `md-nav-bar`'s listbox
  12597. * for accessibility.
  12598. *
  12599. * @usage
  12600. * <hljs lang="html">
  12601. * <md-nav-bar md-selected-nav-item="currentNavItem">
  12602. * <md-nav-item md-nav-click="goto('page1')" name="page1">
  12603. * Page One
  12604. * </md-nav-item>
  12605. * <md-nav-item md-nav-href="#page2" name="page3">Page Two</md-nav-item>
  12606. * <md-nav-item md-nav-sref="page3" name="page2">Page Three</md-nav-item>
  12607. * <md-nav-item
  12608. * md-nav-sref="app.page4"
  12609. * sref-opts="{reload: true, notify: true}"
  12610. * name="page4">
  12611. * Page Four
  12612. * </md-nav-item>
  12613. * </md-nav-bar>
  12614. *</hljs>
  12615. * <hljs lang="js">
  12616. * (function() {
  12617. * 'use strict';
  12618. *
  12619. * $rootScope.$on('$routeChangeSuccess', function(event, current) {
  12620. * $scope.currentLink = getCurrentLinkFromRoute(current);
  12621. * });
  12622. * });
  12623. * </hljs>
  12624. */
  12625. /*****************************************************************************
  12626. * mdNavItem
  12627. *****************************************************************************/
  12628. /**
  12629. * @ngdoc directive
  12630. * @name mdNavItem
  12631. * @module material.components.navBar
  12632. *
  12633. * @restrict E
  12634. *
  12635. * @description
  12636. * `<md-nav-item>` describes a page navigation link within the `<md-nav-bar>` component.
  12637. * It renders an `<md-button>` as the actual link.
  12638. *
  12639. * Exactly one of the `md-nav-click`, `md-nav-href`, or `md-nav-sref` attributes are required
  12640. * to be specified.
  12641. *
  12642. * @param {string=} aria-label Adds alternative text for accessibility.
  12643. * @param {expression=} md-nav-click Expression which will be evaluated when the
  12644. * link is clicked to change the page. Renders as an `ng-click`.
  12645. * @param {string=} md-nav-href url to transition to when this link is clicked.
  12646. * Renders as an `ng-href`.
  12647. * @param {string=} md-nav-sref UI-Router state to transition to when this link is
  12648. * clicked. Renders as a `ui-sref`.
  12649. * @param {string=} name The name of this link. Used by the nav bar to know
  12650. * which link is currently selected.
  12651. * @param {!object=} sref-opts UI-Router options that are passed to the
  12652. * `$state.go()` function. See the [UI-Router documentation for details]
  12653. * (https://ui-router.github.io/docs/latest/interfaces/transition.transitionoptions.html).
  12654. *
  12655. * @usage
  12656. * See `<md-nav-bar>` for usage.
  12657. */
  12658. /*****************************************************************************
  12659. * IMPLEMENTATION *
  12660. *****************************************************************************/
  12661. function MdNavBar($mdAria, $mdTheming) {
  12662. return {
  12663. restrict: 'E',
  12664. transclude: true,
  12665. controller: MdNavBarController,
  12666. controllerAs: 'ctrl',
  12667. bindToController: true,
  12668. scope: {
  12669. 'mdSelectedNavItem': '=?',
  12670. 'mdNoInkBar': '=?',
  12671. 'navBarAriaLabel': '@?',
  12672. },
  12673. template:
  12674. '<div class="md-nav-bar">' +
  12675. '<nav role="navigation">' +
  12676. '<ul class="_md-nav-bar-list" ng-transclude role="listbox" ' +
  12677. 'tabindex="0" ' +
  12678. 'ng-focus="ctrl.onFocus()" ' +
  12679. 'ng-keydown="ctrl.onKeydown($event)" ' +
  12680. 'aria-label="{{ctrl.navBarAriaLabel}}">' +
  12681. '</ul>' +
  12682. '</nav>' +
  12683. '<md-nav-ink-bar ng-hide="ctrl.mdNoInkBar"></md-nav-ink-bar>' +
  12684. '</div>',
  12685. link: function(scope, element, attrs, ctrl) {
  12686. $mdTheming(element);
  12687. if (!ctrl.navBarAriaLabel) {
  12688. $mdAria.expectAsync(element, 'aria-label', angular.noop);
  12689. }
  12690. },
  12691. };
  12692. }
  12693. /**
  12694. * Controller for the nav-bar component.
  12695. *
  12696. * Accessibility functionality is implemented as a site navigator with a
  12697. * listbox, according to
  12698. * https://www.w3.org/TR/wai-aria-practices/#Site_Navigator_Tabbed_Style
  12699. * @param {!angular.JQLite} $element
  12700. * @param {!angular.Scope} $scope
  12701. * @param {!angular.Timeout} $timeout
  12702. * @param {!Object} $mdConstant
  12703. * @constructor
  12704. * @final
  12705. * @ngInject
  12706. */
  12707. function MdNavBarController($element, $scope, $timeout, $mdConstant) {
  12708. // Injected variables
  12709. /** @private @const {!angular.Timeout} */
  12710. this._$timeout = $timeout;
  12711. /** @private @const {!angular.Scope} */
  12712. this._$scope = $scope;
  12713. /** @private @const {!Object} */
  12714. this._$mdConstant = $mdConstant;
  12715. // Data-bound variables.
  12716. /** @type {string} */
  12717. this.mdSelectedNavItem;
  12718. /** @type {string} */
  12719. this.navBarAriaLabel;
  12720. // State variables.
  12721. /** @type {?angular.JQLite} */
  12722. this._navBarEl = $element[0];
  12723. /** @type {?angular.JQLite} */
  12724. this._inkbar;
  12725. var self = this;
  12726. // need to wait for transcluded content to be available
  12727. var deregisterTabWatch = this._$scope.$watch(function() {
  12728. return self._navBarEl.querySelectorAll('._md-nav-button').length;
  12729. },
  12730. function(newLength) {
  12731. if (newLength > 0) {
  12732. self._initTabs();
  12733. deregisterTabWatch();
  12734. }
  12735. });
  12736. }
  12737. /**
  12738. * Initializes the tab components once they exist.
  12739. * @private
  12740. */
  12741. MdNavBarController.prototype._initTabs = function() {
  12742. this._inkbar = angular.element(this._navBarEl.querySelector('md-nav-ink-bar'));
  12743. var self = this;
  12744. this._$timeout(function() {
  12745. self._updateTabs(self.mdSelectedNavItem, undefined);
  12746. });
  12747. this._$scope.$watch('ctrl.mdSelectedNavItem', function(newValue, oldValue) {
  12748. // Wait a digest before update tabs for products doing
  12749. // anything dynamic in the template.
  12750. self._$timeout(function() {
  12751. self._updateTabs(newValue, oldValue);
  12752. });
  12753. });
  12754. };
  12755. /**
  12756. * Set the current tab to be selected.
  12757. * @param {string|undefined} newValue New current tab name.
  12758. * @param {string|undefined} oldValue Previous tab name.
  12759. * @private
  12760. */
  12761. MdNavBarController.prototype._updateTabs = function(newValue, oldValue) {
  12762. var self = this;
  12763. var tabs = this._getTabs();
  12764. // this._getTabs can return null if nav-bar has not yet been initialized
  12765. if(!tabs)
  12766. return;
  12767. var oldIndex = -1;
  12768. var newIndex = -1;
  12769. var newTab = this._getTabByName(newValue);
  12770. var oldTab = this._getTabByName(oldValue);
  12771. if (oldTab) {
  12772. oldTab.setSelected(false);
  12773. oldIndex = tabs.indexOf(oldTab);
  12774. }
  12775. if (newTab) {
  12776. newTab.setSelected(true);
  12777. newIndex = tabs.indexOf(newTab);
  12778. }
  12779. this._$timeout(function() {
  12780. self._updateInkBarStyles(newTab, newIndex, oldIndex);
  12781. });
  12782. };
  12783. /**
  12784. * Repositions the ink bar to the selected tab.
  12785. * @private
  12786. */
  12787. MdNavBarController.prototype._updateInkBarStyles = function(tab, newIndex, oldIndex) {
  12788. this._inkbar.toggleClass('_md-left', newIndex < oldIndex)
  12789. .toggleClass('_md-right', newIndex > oldIndex);
  12790. this._inkbar.css({display: newIndex < 0 ? 'none' : ''});
  12791. if (tab) {
  12792. var tabEl = tab.getButtonEl();
  12793. var left = tabEl.offsetLeft;
  12794. this._inkbar.css({left: left + 'px', width: tabEl.offsetWidth + 'px'});
  12795. }
  12796. };
  12797. /**
  12798. * Returns an array of the current tabs.
  12799. * @return {!Array<!NavItemController>}
  12800. * @private
  12801. */
  12802. MdNavBarController.prototype._getTabs = function() {
  12803. var controllers = Array.prototype.slice.call(
  12804. this._navBarEl.querySelectorAll('.md-nav-item'))
  12805. .map(function(el) {
  12806. return angular.element(el).controller('mdNavItem');
  12807. });
  12808. return controllers.indexOf(undefined) ? controllers : null;
  12809. };
  12810. /**
  12811. * Returns the tab with the specified name.
  12812. * @param {string} name The name of the tab, found in its name attribute.
  12813. * @return {!NavItemController|undefined}
  12814. * @private
  12815. */
  12816. MdNavBarController.prototype._getTabByName = function(name) {
  12817. return this._findTab(function(tab) {
  12818. return tab.getName() == name;
  12819. });
  12820. };
  12821. /**
  12822. * Returns the selected tab.
  12823. * @return {!NavItemController|undefined}
  12824. * @private
  12825. */
  12826. MdNavBarController.prototype._getSelectedTab = function() {
  12827. return this._findTab(function(tab) {
  12828. return tab.isSelected();
  12829. });
  12830. };
  12831. /**
  12832. * Returns the focused tab.
  12833. * @return {!NavItemController|undefined}
  12834. */
  12835. MdNavBarController.prototype.getFocusedTab = function() {
  12836. return this._findTab(function(tab) {
  12837. return tab.hasFocus();
  12838. });
  12839. };
  12840. /**
  12841. * Find a tab that matches the specified function.
  12842. * @private
  12843. */
  12844. MdNavBarController.prototype._findTab = function(fn) {
  12845. var tabs = this._getTabs();
  12846. for (var i = 0; i < tabs.length; i++) {
  12847. if (fn(tabs[i])) {
  12848. return tabs[i];
  12849. }
  12850. }
  12851. return null;
  12852. };
  12853. /**
  12854. * Direct focus to the selected tab when focus enters the nav bar.
  12855. */
  12856. MdNavBarController.prototype.onFocus = function() {
  12857. var tab = this._getSelectedTab();
  12858. if (tab) {
  12859. tab.setFocused(true);
  12860. }
  12861. };
  12862. /**
  12863. * Move focus from oldTab to newTab.
  12864. * @param {!NavItemController} oldTab
  12865. * @param {!NavItemController} newTab
  12866. * @private
  12867. */
  12868. MdNavBarController.prototype._moveFocus = function(oldTab, newTab) {
  12869. oldTab.setFocused(false);
  12870. newTab.setFocused(true);
  12871. };
  12872. /**
  12873. * Responds to keypress events.
  12874. * @param {!Event} e
  12875. */
  12876. MdNavBarController.prototype.onKeydown = function(e) {
  12877. var keyCodes = this._$mdConstant.KEY_CODE;
  12878. var tabs = this._getTabs();
  12879. var focusedTab = this.getFocusedTab();
  12880. if (!focusedTab) return;
  12881. var focusedTabIndex = tabs.indexOf(focusedTab);
  12882. // use arrow keys to navigate between tabs
  12883. switch (e.keyCode) {
  12884. case keyCodes.UP_ARROW:
  12885. case keyCodes.LEFT_ARROW:
  12886. if (focusedTabIndex > 0) {
  12887. this._moveFocus(focusedTab, tabs[focusedTabIndex - 1]);
  12888. }
  12889. break;
  12890. case keyCodes.DOWN_ARROW:
  12891. case keyCodes.RIGHT_ARROW:
  12892. if (focusedTabIndex < tabs.length - 1) {
  12893. this._moveFocus(focusedTab, tabs[focusedTabIndex + 1]);
  12894. }
  12895. break;
  12896. case keyCodes.SPACE:
  12897. case keyCodes.ENTER:
  12898. // timeout to avoid a "digest already in progress" console error
  12899. this._$timeout(function() {
  12900. focusedTab.getButtonEl().click();
  12901. });
  12902. break;
  12903. }
  12904. };
  12905. /**
  12906. * @ngInject
  12907. */
  12908. function MdNavItem($mdAria, $$rAF, $mdUtil, $window) {
  12909. return {
  12910. restrict: 'E',
  12911. require: ['mdNavItem', '^mdNavBar'],
  12912. controller: MdNavItemController,
  12913. bindToController: true,
  12914. controllerAs: 'ctrl',
  12915. replace: true,
  12916. transclude: true,
  12917. template: function(tElement, tAttrs) {
  12918. var hasNavClick = tAttrs.mdNavClick;
  12919. var hasNavHref = tAttrs.mdNavHref;
  12920. var hasNavSref = tAttrs.mdNavSref;
  12921. var hasSrefOpts = tAttrs.srefOpts;
  12922. var navigationAttribute;
  12923. var navigationOptions;
  12924. var buttonTemplate;
  12925. // Cannot specify more than one nav attribute
  12926. if ((hasNavClick ? 1:0) + (hasNavHref ? 1:0) + (hasNavSref ? 1:0) > 1) {
  12927. throw Error(
  12928. 'Must not specify more than one of the md-nav-click, md-nav-href, ' +
  12929. 'or md-nav-sref attributes per nav-item directive.'
  12930. );
  12931. }
  12932. if (hasNavClick) {
  12933. navigationAttribute = 'ng-click="ctrl.mdNavClick()"';
  12934. } else if (hasNavHref) {
  12935. navigationAttribute = 'ng-href="{{ctrl.mdNavHref}}"';
  12936. } else if (hasNavSref) {
  12937. navigationAttribute = 'ui-sref="{{ctrl.mdNavSref}}"';
  12938. }
  12939. navigationOptions = hasSrefOpts ? 'ui-sref-opts="{{ctrl.srefOpts}}" ' : '';
  12940. if (navigationAttribute) {
  12941. buttonTemplate = '' +
  12942. '<md-button class="_md-nav-button md-accent" ' +
  12943. 'ng-class="ctrl.getNgClassMap()" ' +
  12944. 'ng-blur="ctrl.setFocused(false)" ' +
  12945. 'ng-disabled="ctrl.disabled" ' +
  12946. 'tabindex="-1" ' +
  12947. navigationOptions +
  12948. navigationAttribute + '>' +
  12949. '<span ng-transclude class="_md-nav-button-text"></span>' +
  12950. '</md-button>';
  12951. }
  12952. return '' +
  12953. '<li class="md-nav-item" ' +
  12954. 'role="option" ' +
  12955. 'aria-selected="{{ctrl.isSelected()}}">' +
  12956. (buttonTemplate || '') +
  12957. '</li>';
  12958. },
  12959. scope: {
  12960. 'mdNavClick': '&?',
  12961. 'mdNavHref': '@?',
  12962. 'mdNavSref': '@?',
  12963. 'srefOpts': '=?',
  12964. 'name': '@',
  12965. },
  12966. link: function(scope, element, attrs, controllers) {
  12967. var disconnect;
  12968. // When accessing the element's contents synchronously, they
  12969. // may not be defined yet because of transclusion. There is a higher
  12970. // chance that it will be accessible if we wait one frame.
  12971. $$rAF(function() {
  12972. var mdNavItem = controllers[0];
  12973. var mdNavBar = controllers[1];
  12974. var navButton = angular.element(element[0].querySelector('._md-nav-button'));
  12975. if (!mdNavItem.name) {
  12976. mdNavItem.name = angular.element(element[0]
  12977. .querySelector('._md-nav-button-text')).text().trim();
  12978. }
  12979. navButton.on('click', function() {
  12980. mdNavBar.mdSelectedNavItem = mdNavItem.name;
  12981. scope.$apply();
  12982. });
  12983. // Get the disabled attribute value first, then setup observing of value changes
  12984. mdNavItem.disabled = $mdUtil.parseAttributeBoolean(attrs['disabled'], false);
  12985. if ('MutationObserver' in $window) {
  12986. var config = {attributes: true, attributeFilter: ['disabled']};
  12987. var targetNode = element[0];
  12988. var mutationCallback = function(mutationList) {
  12989. $mdUtil.nextTick(function() {
  12990. mdNavItem.disabled = $mdUtil.parseAttributeBoolean(attrs[mutationList[0].attributeName], false);
  12991. });
  12992. };
  12993. var observer = new MutationObserver(mutationCallback);
  12994. observer.observe(targetNode, config);
  12995. disconnect = observer.disconnect.bind(observer);
  12996. } else {
  12997. attrs.$observe('disabled', function (value) {
  12998. mdNavItem.disabled = $mdUtil.parseAttributeBoolean(value, false);
  12999. });
  13000. }
  13001. $mdAria.expectWithText(element, 'aria-label');
  13002. });
  13003. scope.$on('destroy', function() {
  13004. disconnect();
  13005. })
  13006. }
  13007. };
  13008. }
  13009. /**
  13010. * Controller for the nav-item component.
  13011. * @param {!angular.JQLite} $element
  13012. * @constructor
  13013. * @final
  13014. * @ngInject
  13015. */
  13016. function MdNavItemController($element) {
  13017. /** @private @const {!angular.JQLite} */
  13018. this._$element = $element;
  13019. // Data-bound variables
  13020. /** @const {?Function} */
  13021. this.mdNavClick;
  13022. /** @const {?string} */
  13023. this.mdNavHref;
  13024. /** @const {?string} */
  13025. this.mdNavSref;
  13026. /** @const {?Object} */
  13027. this.srefOpts;
  13028. /** @const {?string} */
  13029. this.name;
  13030. // State variables
  13031. /** @private {boolean} */
  13032. this._selected = false;
  13033. /** @private {boolean} */
  13034. this._focused = false;
  13035. }
  13036. /**
  13037. * Returns a map of class names and values for use by ng-class.
  13038. * @return {!Object<string,boolean>}
  13039. */
  13040. MdNavItemController.prototype.getNgClassMap = function() {
  13041. return {
  13042. 'md-active': this._selected,
  13043. 'md-primary': this._selected,
  13044. 'md-unselected': !this._selected,
  13045. 'md-focused': this._focused,
  13046. };
  13047. };
  13048. /**
  13049. * Get the name attribute of the tab.
  13050. * @return {string}
  13051. */
  13052. MdNavItemController.prototype.getName = function() {
  13053. return this.name;
  13054. };
  13055. /**
  13056. * Get the button element associated with the tab.
  13057. * @return {!Element}
  13058. */
  13059. MdNavItemController.prototype.getButtonEl = function() {
  13060. return this._$element[0].querySelector('._md-nav-button');
  13061. };
  13062. /**
  13063. * Set the selected state of the tab.
  13064. * @param {boolean} isSelected
  13065. */
  13066. MdNavItemController.prototype.setSelected = function(isSelected) {
  13067. this._selected = isSelected;
  13068. };
  13069. /**
  13070. * @return {boolean}
  13071. */
  13072. MdNavItemController.prototype.isSelected = function() {
  13073. return this._selected;
  13074. };
  13075. /**
  13076. * Set the focused state of the tab.
  13077. * @param {boolean} isFocused
  13078. */
  13079. MdNavItemController.prototype.setFocused = function(isFocused) {
  13080. this._focused = isFocused;
  13081. if (isFocused) {
  13082. this.getButtonEl().focus();
  13083. }
  13084. };
  13085. /**
  13086. * @return {boolean}
  13087. */
  13088. MdNavItemController.prototype.hasFocus = function() {
  13089. return this._focused;
  13090. };
  13091. })();
  13092. (function(){
  13093. "use strict";
  13094. /**
  13095. * @ngdoc module
  13096. * @name material.components.panel
  13097. */
  13098. MdPanelService.$inject = ["presets", "$rootElement", "$rootScope", "$injector", "$window"];
  13099. angular
  13100. .module('material.components.panel', [
  13101. 'material.core',
  13102. 'material.components.backdrop'
  13103. ])
  13104. .provider('$mdPanel', MdPanelProvider);
  13105. /*****************************************************************************
  13106. * PUBLIC DOCUMENTATION *
  13107. *****************************************************************************/
  13108. /**
  13109. * @ngdoc service
  13110. * @name $mdPanelProvider
  13111. * @module material.components.panel
  13112. *
  13113. * @description
  13114. * `$mdPanelProvider` allows users to create configuration presets that will be
  13115. * stored within a cached presets object. When the configuration is needed, the
  13116. * user can request the preset by passing it as the first parameter in the
  13117. * `$mdPanel.create` or `$mdPanel.open` methods.
  13118. *
  13119. * @usage
  13120. * <hljs lang="js">
  13121. * (function(angular, undefined) {
  13122. * 'use strict';
  13123. *
  13124. * angular
  13125. * .module('demoApp', ['ngMaterial'])
  13126. * .config(DemoConfig)
  13127. * .controller('DemoCtrl', DemoCtrl)
  13128. * .controller('DemoMenuCtrl', DemoMenuCtrl);
  13129. *
  13130. * function DemoConfig($mdPanelProvider) {
  13131. * $mdPanelProvider.definePreset('demoPreset', {
  13132. * attachTo: angular.element(document.body),
  13133. * controller: DemoMenuCtrl,
  13134. * controllerAs: 'ctrl',
  13135. * template: '' +
  13136. * '<div class="menu-panel" md-whiteframe="4">' +
  13137. * ' <div class="menu-content">' +
  13138. * ' <div class="menu-item" ng-repeat="item in ctrl.items">' +
  13139. * ' <button class="md-button">' +
  13140. * ' <span>{{item}}</span>' +
  13141. * ' </button>' +
  13142. * ' </div>' +
  13143. * ' <md-divider></md-divider>' +
  13144. * ' <div class="menu-item">' +
  13145. * ' <button class="md-button" ng-click="ctrl.closeMenu()">' +
  13146. * ' <span>Close Menu</span>' +
  13147. * ' </button>' +
  13148. * ' </div>' +
  13149. * ' </div>' +
  13150. * '</div>',
  13151. * panelClass: 'menu-panel-container',
  13152. * focusOnOpen: false,
  13153. * zIndex: 100,
  13154. * propagateContainerEvents: true,
  13155. * groupName: 'menus'
  13156. * });
  13157. * }
  13158. *
  13159. * function PanelProviderCtrl($mdPanel) {
  13160. * this.navigation = {
  13161. * name: 'navigation',
  13162. * items: [
  13163. * 'Home',
  13164. * 'About',
  13165. * 'Contact'
  13166. * ]
  13167. * };
  13168. * this.favorites = {
  13169. * name: 'favorites',
  13170. * items: [
  13171. * 'Add to Favorites'
  13172. * ]
  13173. * };
  13174. * this.more = {
  13175. * name: 'more',
  13176. * items: [
  13177. * 'Account',
  13178. * 'Sign Out'
  13179. * ]
  13180. * };
  13181. *
  13182. * $mdPanel.newPanelGroup('menus', {
  13183. * maxOpen: 2
  13184. * });
  13185. *
  13186. * this.showMenu = function($event, menu) {
  13187. * $mdPanel.open('demoPreset', {
  13188. * id: 'menu_' + menu.name,
  13189. * position: $mdPanel.newPanelPosition()
  13190. * .relativeTo($event.srcElement)
  13191. * .addPanelPosition(
  13192. * $mdPanel.xPosition.ALIGN_START,
  13193. * $mdPanel.yPosition.BELOW
  13194. * ),
  13195. * locals: {
  13196. * items: menu.items
  13197. * },
  13198. * openFrom: $event
  13199. * });
  13200. * };
  13201. * }
  13202. *
  13203. * function PanelMenuCtrl(mdPanelRef) {
  13204. * // The controller is provided with an import named 'mdPanelRef'
  13205. * this.closeMenu = function() {
  13206. * mdPanelRef && mdPanelRef.close();
  13207. * };
  13208. * }
  13209. * })(angular);
  13210. * </hljs>
  13211. */
  13212. /**
  13213. * @ngdoc method
  13214. * @name $mdPanelProvider#definePreset
  13215. * @description
  13216. * Takes the passed in preset name and preset configuration object and adds it
  13217. * to the `_presets` object of the provider. This `_presets` object is then
  13218. * passed along to the `$mdPanel` service.
  13219. *
  13220. * @param {string} name Preset name.
  13221. * @param {!Object} preset Specific configuration object that can contain any
  13222. * and all of the parameters avaialble within the `$mdPanel.create` method.
  13223. * However, parameters that pertain to id, position, animation, and user
  13224. * interaction are not allowed and will be removed from the preset
  13225. * configuration.
  13226. */
  13227. /*****************************************************************************
  13228. * MdPanel Service *
  13229. *****************************************************************************/
  13230. /**
  13231. * @ngdoc service
  13232. * @name $mdPanel
  13233. * @module material.components.panel
  13234. *
  13235. * @description
  13236. * `$mdPanel` is a robust, low-level service for creating floating panels on
  13237. * the screen. It can be used to implement tooltips, dialogs, pop-ups, etc.
  13238. *
  13239. * The following types, referenced below, have separate documentation:
  13240. * - <a href="api/type/MdPanelAnimation">MdPanelAnimation</a> from `$mdPanel.newPanelAnimation()`
  13241. * - <a href="api/type/MdPanelPosition">MdPanelPosition</a> from `$mdPanel.newPanelPosition()`
  13242. * - <a href="api/type/MdPanelRef">MdPanelRef</a> from the `$mdPanel.open()` Promise or
  13243. * injected in the panel's controller
  13244. *
  13245. * @usage
  13246. * <hljs lang="js">
  13247. * (function(angular, undefined) {
  13248. * 'use strict';
  13249. *
  13250. * angular
  13251. * .module('demoApp', ['ngMaterial'])
  13252. * .controller('DemoDialogController', DialogController)
  13253. * .controller('DemoCtrl', function($mdPanel) {
  13254. *
  13255. * var panelRef;
  13256. *
  13257. * function showPanel($event) {
  13258. * var panelPosition = $mdPanel.newPanelPosition()
  13259. * .absolute()
  13260. * .top('50%')
  13261. * .left('50%');
  13262. *
  13263. * var panelAnimation = $mdPanel.newPanelAnimation()
  13264. * .openFrom($event)
  13265. * .duration(200)
  13266. * .closeTo('.show-button')
  13267. * .withAnimation($mdPanel.animation.SCALE);
  13268. *
  13269. * var config = {
  13270. * attachTo: angular.element(document.body),
  13271. * controller: DialogController,
  13272. * controllerAs: 'ctrl',
  13273. * position: panelPosition,
  13274. * animation: panelAnimation,
  13275. * targetEvent: $event,
  13276. * templateUrl: 'dialog-template.html',
  13277. * clickOutsideToClose: true,
  13278. * escapeToClose: true,
  13279. * focusOnOpen: true
  13280. * };
  13281. *
  13282. * $mdPanel.open(config)
  13283. * .then(function(result) {
  13284. * panelRef = result;
  13285. * });
  13286. * }
  13287. * }
  13288. *
  13289. * function DialogController(MdPanelRef) {
  13290. * function closeDialog() {
  13291. * if (MdPanelRef) MdPanelRef.close();
  13292. * }
  13293. * }
  13294. * })(angular);
  13295. * </hljs>
  13296. */
  13297. /**
  13298. * @ngdoc method
  13299. * @name $mdPanel#create
  13300. * @description
  13301. * Creates a panel with the specified options.
  13302. *
  13303. * @param config {!Object=} Specific configuration object that may contain the
  13304. * following properties:
  13305. *
  13306. * - `id` - `{string=}`: An ID to track the panel by. When an ID is provided,
  13307. * the created panel is added to a tracked panels object. Any subsequent
  13308. * requests made to create a panel with that ID are ignored. This is useful
  13309. * in having the panel service not open multiple panels from the same user
  13310. * interaction when there is no backdrop and events are propagated. Defaults
  13311. * to an arbitrary string that is not tracked.
  13312. * - `template` - `{string=}`: HTML template to show in the panel. This
  13313. * **must** be trusted HTML with respect to AngularJS’s
  13314. * [$sce service](https://docs.angularjs.org/api/ng/service/$sce).
  13315. * - `templateUrl` - `{string=}`: The URL that will be used as the content of
  13316. * the panel.
  13317. * - `contentElement` - `{(string|!angular.JQLite|!Element)=}`: Pre-compiled
  13318. * element to be used as the panel's content.
  13319. * - `controller` - `{(function|string)=}`: The controller to associate with
  13320. * the panel. The controller can inject a reference to the returned
  13321. * panelRef, which allows the panel to be closed, hidden, and shown. Any
  13322. * fields passed in through locals or resolve will be bound to the
  13323. * controller.
  13324. * - `controllerAs` - `{string=}`: An alias to assign the controller to on
  13325. * the scope.
  13326. * - `bindToController` - `{boolean=}`: Binds locals to the controller
  13327. * instead of passing them in. Defaults to true, as this is a best
  13328. * practice.
  13329. * - `locals` - `{Object=}`: An object containing key/value pairs. The keys
  13330. * will be used as names of values to inject into the controller. For
  13331. * example, `locals: {three: 3}` would inject `three` into the controller,
  13332. * with the value 3. 'mdPanelRef' is a reserved key, and will always
  13333. * be set to the created MdPanelRef instance.
  13334. * - `resolve` - `{Object=}`: Similar to locals, except it takes promises as
  13335. * values. The panel will not open until all of the promises resolve.
  13336. * - `attachTo` - `{(string|!angular.JQLite|!Element)=}`: The element to
  13337. * attach the panel to. Defaults to appending to the root element of the
  13338. * application.
  13339. * - `propagateContainerEvents` - `{boolean=}`: Whether pointer or touch
  13340. * events should be allowed to propagate 'go through' the container, aka the
  13341. * wrapper, of the panel. Defaults to false.
  13342. * - `panelClass` - `{string=}`: A css class to apply to the panel element.
  13343. * This class should define any borders, box-shadow, etc. for the panel.
  13344. * - `zIndex` - `{number=}`: The z-index to place the panel at.
  13345. * Defaults to 80.
  13346. * - `position` - `{MdPanelPosition=}`: An MdPanelPosition object that
  13347. * specifies the alignment of the panel. For more information, see
  13348. * `MdPanelPosition`.
  13349. * - `clickOutsideToClose` - `{boolean=}`: Whether the user can click
  13350. * outside the panel to close it. Defaults to false.
  13351. * - `escapeToClose` - `{boolean=}`: Whether the user can press escape to
  13352. * close the panel. Defaults to false.
  13353. * - `onCloseSuccess` - `{function(!panelRef, string)=}`: Function that is
  13354. * called after the close successfully finishes. The first parameter passed
  13355. * into this function is the current panelRef and the 2nd is an optional
  13356. * string explaining the close reason. The currently supported closeReasons
  13357. * can be found in the MdPanelRef.closeReasons enum. These are by default
  13358. * passed along by the panel.
  13359. * - `trapFocus` - `{boolean=}`: Whether focus should be trapped within the
  13360. * panel. If `trapFocus` is true, the user will not be able to interact
  13361. * with the rest of the page until the panel is dismissed. Defaults to
  13362. * false.
  13363. * - `focusOnOpen` - `{boolean=}`: An option to override focus behavior on
  13364. * open. Only disable if focusing some other way, as focus management is
  13365. * required for panels to be accessible. Defaults to true.
  13366. * - `fullscreen` - `{boolean=}`: Whether the panel should be full screen.
  13367. * Applies the class `._md-panel-fullscreen` to the panel on open. Defaults
  13368. * to false.
  13369. * - `animation` - `{MdPanelAnimation=}`: An MdPanelAnimation object that
  13370. * specifies the animation of the panel. For more information, see
  13371. * `MdPanelAnimation`.
  13372. * - `hasBackdrop` - `{boolean=}`: Whether there should be an opaque backdrop
  13373. * behind the panel. Defaults to false.
  13374. * - `disableParentScroll` - `{boolean=}`: Whether the user can scroll the
  13375. * page behind the panel. Defaults to false.
  13376. * - `onDomAdded` - `{function=}`: Callback function used to announce when
  13377. * the panel is added to the DOM.
  13378. * - `onOpenComplete` - `{function=}`: Callback function used to announce
  13379. * when the open() action is finished.
  13380. * - `onRemoving` - `{function=}`: Callback function used to announce the
  13381. * close/hide() action is starting.
  13382. * - `onDomRemoved` - `{function=}`: Callback function used to announce when
  13383. * the panel is removed from the DOM.
  13384. * - `origin` - `{(string|!angular.JQLite|!Element)=}`: The element to focus
  13385. * on when the panel closes. This is commonly the element which triggered
  13386. * the opening of the panel. If you do not use `origin`, you need to control
  13387. * the focus manually.
  13388. * - `groupName` - `{(string|!Array<string>)=}`: A group name or an array of
  13389. * group names. The group name is used for creating a group of panels. The
  13390. * group is used for configuring the number of open panels and identifying
  13391. * specific behaviors for groups. For instance, all tooltips could be
  13392. * identified using the same groupName.
  13393. *
  13394. * @returns {!MdPanelRef} panelRef
  13395. */
  13396. /**
  13397. * @ngdoc method
  13398. * @name $mdPanel#open
  13399. * @description
  13400. * Calls the create method above, then opens the panel. This is a shortcut for
  13401. * creating and then calling open manually. If custom methods need to be
  13402. * called when the panel is added to the DOM or opened, do not use this method.
  13403. * Instead create the panel, chain promises on the domAdded and openComplete
  13404. * methods, and call open from the returned panelRef.
  13405. *
  13406. * @param {!Object=} config Specific configuration object that may contain
  13407. * the properties defined in `$mdPanel.create`.
  13408. * @returns {!angular.$q.Promise<!MdPanelRef>} panelRef A promise that resolves
  13409. * to an instance of the panel.
  13410. */
  13411. /**
  13412. * @ngdoc method
  13413. * @name $mdPanel#newPanelPosition
  13414. * @description
  13415. * Returns a new instance of the MdPanelPosition object. Use this to create
  13416. * the position config object.
  13417. *
  13418. * @returns {!MdPanelPosition} panelPosition
  13419. */
  13420. /**
  13421. * @ngdoc method
  13422. * @name $mdPanel#newPanelAnimation
  13423. * @description
  13424. * Returns a new instance of the MdPanelAnimation object. Use this to create
  13425. * the animation config object.
  13426. *
  13427. * @returns {!MdPanelAnimation} panelAnimation
  13428. */
  13429. /**
  13430. * @ngdoc method
  13431. * @name $mdPanel#newPanelGroup
  13432. * @description
  13433. * Creates a panel group and adds it to a tracked list of panel groups.
  13434. *
  13435. * @param {string} groupName Name of the group to create.
  13436. * @param {!Object=} config Specific configuration object that may contain the
  13437. * following properties:
  13438. *
  13439. * - `maxOpen` - `{number=}`: The maximum number of panels that are allowed to
  13440. * be open within a defined panel group.
  13441. *
  13442. * @returns {!Object<string,
  13443. * {panels: !Array<!MdPanelRef>,
  13444. * openPanels: !Array<!MdPanelRef>,
  13445. * maxOpen: number}>} panelGroup
  13446. */
  13447. /**
  13448. * @ngdoc method
  13449. * @name $mdPanel#setGroupMaxOpen
  13450. * @description
  13451. * Sets the maximum number of panels in a group that can be opened at a given
  13452. * time.
  13453. *
  13454. * @param {string} groupName The name of the group to configure.
  13455. * @param {number} maxOpen The maximum number of panels that can be
  13456. * opened. Infinity can be passed in to remove the maxOpen limit.
  13457. */
  13458. /*****************************************************************************
  13459. * MdPanelRef *
  13460. *****************************************************************************/
  13461. /**
  13462. * @ngdoc type
  13463. * @name MdPanelRef
  13464. * @module material.components.panel
  13465. * @description
  13466. * A reference to a created panel. This reference contains a unique id for the
  13467. * panel, along with the following properties:
  13468. *
  13469. * - `id` - `{string}`: The unique id for the panel. This id is used to track
  13470. * when a panel was interacted with.
  13471. * - `config` - `{!Object=}`: The entire config object that was used in
  13472. * create.
  13473. * - `isAttached` - `{boolean}`: Whether the panel is attached to the DOM.
  13474. * Visibility to the user does not factor into isAttached.
  13475. * - `panelContainer` - `{angular.JQLite}`: The wrapper element containing the
  13476. * panel. This property is added in order to have access to the `addClass`,
  13477. * `removeClass`, `toggleClass`, etc methods.
  13478. * - `panelEl` - `{angular.JQLite}`: The panel element. This property is added
  13479. * in order to have access to the `addClass`, `removeClass`, `toggleClass`,
  13480. * etc methods.
  13481. */
  13482. /**
  13483. * @ngdoc method
  13484. * @name MdPanelRef#open
  13485. * @description
  13486. * Attaches and shows the panel.
  13487. *
  13488. * @returns {!angular.$q.Promise} A promise that is resolved when the panel is
  13489. * opened.
  13490. */
  13491. /**
  13492. * @ngdoc method
  13493. * @name MdPanelRef#close
  13494. * @description
  13495. * Hides and detaches the panel. Note that this will **not** destroy the panel.
  13496. * If you don't intend on using the panel again, call the {@link #destroy
  13497. * destroy} method afterwards.
  13498. *
  13499. * @returns {!angular.$q.Promise} A promise that is resolved when the panel is
  13500. * closed.
  13501. */
  13502. /**
  13503. * @ngdoc method
  13504. * @name MdPanelRef#attach
  13505. * @description
  13506. * Create the panel elements and attach them to the DOM. The panel will be
  13507. * hidden by default.
  13508. *
  13509. * @returns {!angular.$q.Promise} A promise that is resolved when the panel is
  13510. * attached.
  13511. */
  13512. /**
  13513. * @ngdoc method
  13514. * @name MdPanelRef#detach
  13515. * @description
  13516. * Removes the panel from the DOM. This will NOT hide the panel before removing
  13517. * it.
  13518. *
  13519. * @returns {!angular.$q.Promise} A promise that is resolved when the panel is
  13520. * detached.
  13521. */
  13522. /**
  13523. * @ngdoc method
  13524. * @name MdPanelRef#show
  13525. * @description
  13526. * Shows the panel.
  13527. *
  13528. * @returns {!angular.$q.Promise} A promise that is resolved when the panel has
  13529. * shown and animations are completed.
  13530. */
  13531. /**
  13532. * @ngdoc method
  13533. * @name MdPanelRef#hide
  13534. * @description
  13535. * Hides the panel.
  13536. *
  13537. * @returns {!angular.$q.Promise} A promise that is resolved when the panel has
  13538. * hidden and animations are completed.
  13539. */
  13540. /**
  13541. * @ngdoc method
  13542. * @name MdPanelRef#destroy
  13543. * @description
  13544. * Destroys the panel. The panel cannot be opened again after this is called.
  13545. */
  13546. /**
  13547. * @ngdoc method
  13548. * @name MdPanelRef#addClass
  13549. * @deprecated
  13550. * This method is in the process of being deprecated in favor of using the panel
  13551. * and container JQLite elements that are referenced in the MdPanelRef object.
  13552. * Full deprecation is scheduled for material 1.2.
  13553. * @description
  13554. * Adds a class to the panel. DO NOT use this hide/show the panel.
  13555. *
  13556. * @param {string} newClass class to be added.
  13557. * @param {boolean} toElement Whether or not to add the class to the panel
  13558. * element instead of the container.
  13559. */
  13560. /**
  13561. * @ngdoc method
  13562. * @name MdPanelRef#removeClass
  13563. * @deprecated
  13564. * This method is in the process of being deprecated in favor of using the panel
  13565. * and container JQLite elements that are referenced in the MdPanelRef object.
  13566. * Full deprecation is scheduled for material 1.2.
  13567. * @description
  13568. * Removes a class from the panel. DO NOT use this to hide/show the panel.
  13569. *
  13570. * @param {string} oldClass Class to be removed.
  13571. * @param {boolean} fromElement Whether or not to remove the class from the
  13572. * panel element instead of the container.
  13573. */
  13574. /**
  13575. * @ngdoc method
  13576. * @name MdPanelRef#toggleClass
  13577. * @deprecated
  13578. * This method is in the process of being deprecated in favor of using the panel
  13579. * and container JQLite elements that are referenced in the MdPanelRef object.
  13580. * Full deprecation is scheduled for material 1.2.
  13581. * @description
  13582. * Toggles a class on the panel. DO NOT use this to hide/show the panel.
  13583. *
  13584. * @param {string} toggleClass Class to be toggled.
  13585. * @param {boolean} onElement Whether or not to remove the class from the panel
  13586. * element instead of the container.
  13587. */
  13588. /**
  13589. * @ngdoc method
  13590. * @name MdPanelRef#updatePosition
  13591. * @description
  13592. * Updates the position configuration of a panel. Use this to update the
  13593. * position of a panel that is open, without having to close and re-open the
  13594. * panel.
  13595. *
  13596. * @param {!MdPanelPosition} position
  13597. */
  13598. /**
  13599. * @ngdoc method
  13600. * @name MdPanelRef#addToGroup
  13601. * @description
  13602. * Adds a panel to a group if the panel does not exist within the group already.
  13603. * A panel can only exist within a single group.
  13604. *
  13605. * @param {string} groupName The name of the group to add the panel to.
  13606. */
  13607. /**
  13608. * @ngdoc method
  13609. * @name MdPanelRef#removeFromGroup
  13610. * @description
  13611. * Removes a panel from a group if the panel exists within that group. The group
  13612. * must be created ahead of time.
  13613. *
  13614. * @param {string} groupName The name of the group.
  13615. */
  13616. /**
  13617. * @ngdoc method
  13618. * @name MdPanelRef#registerInterceptor
  13619. * @description
  13620. * Registers an interceptor with the panel. The callback should return a promise,
  13621. * which will allow the action to continue when it gets resolved, or will
  13622. * prevent an action if it is rejected. The interceptors are called sequentially
  13623. * and it reverse order. `type` must be one of the following
  13624. * values available on `$mdPanel.interceptorTypes`:
  13625. * * `CLOSE` - Gets called before the panel begins closing.
  13626. *
  13627. * @param {string} type Type of interceptor.
  13628. * @param {!angular.$q.Promise<any>} callback Callback to be registered.
  13629. * @returns {!MdPanelRef}
  13630. */
  13631. /**
  13632. * @ngdoc method
  13633. * @name MdPanelRef#removeInterceptor
  13634. * @description
  13635. * Removes a registered interceptor.
  13636. *
  13637. * @param {string} type Type of interceptor to be removed.
  13638. * @param {function(): !angular.$q.Promise<any>} callback Interceptor to be removed.
  13639. * @returns {!MdPanelRef}
  13640. */
  13641. /**
  13642. * @ngdoc method
  13643. * @name MdPanelRef#removeAllInterceptors
  13644. * @description
  13645. * Removes all interceptors. If a type is supplied, only the
  13646. * interceptors of that type will be cleared.
  13647. *
  13648. * @param {string=} type Type of interceptors to be removed.
  13649. * @returns {!MdPanelRef}
  13650. */
  13651. /**
  13652. * @ngdoc method
  13653. * @name MdPanelRef#updateAnimation
  13654. * @description
  13655. * Updates the animation configuration for a panel. You can use this to change
  13656. * the panel's animation without having to re-create it.
  13657. *
  13658. * @param {!MdPanelAnimation} animation
  13659. */
  13660. /*****************************************************************************
  13661. * MdPanelPosition *
  13662. *****************************************************************************/
  13663. /**
  13664. * @ngdoc type
  13665. * @name MdPanelPosition
  13666. * @module material.components.panel
  13667. * @description
  13668. *
  13669. * Object for configuring the position of the panel.
  13670. *
  13671. * @usage
  13672. *
  13673. * #### Centering the panel
  13674. *
  13675. * <hljs lang="js">
  13676. * new MdPanelPosition().absolute().center();
  13677. * </hljs>
  13678. *
  13679. * #### Overlapping the panel with an element
  13680. *
  13681. * <hljs lang="js">
  13682. * new MdPanelPosition()
  13683. * .relativeTo(someElement)
  13684. * .addPanelPosition(
  13685. * $mdPanel.xPosition.ALIGN_START,
  13686. * $mdPanel.yPosition.ALIGN_TOPS
  13687. * );
  13688. * </hljs>
  13689. *
  13690. * #### Aligning the panel with the bottom of an element
  13691. *
  13692. * <hljs lang="js">
  13693. * new MdPanelPosition()
  13694. * .relativeTo(someElement)
  13695. * .addPanelPosition($mdPanel.xPosition.CENTER, $mdPanel.yPosition.BELOW);
  13696. * </hljs>
  13697. */
  13698. /**
  13699. * @ngdoc method
  13700. * @name MdPanelPosition#absolute
  13701. * @description
  13702. * Positions the panel absolutely relative to the parent element. If the parent
  13703. * is document.body, this is equivalent to positioning the panel absolutely
  13704. * within the viewport.
  13705. *
  13706. * @returns {!MdPanelPosition}
  13707. */
  13708. /**
  13709. * @ngdoc method
  13710. * @name MdPanelPosition#relativeTo
  13711. * @description
  13712. * Positions the panel relative to a specific element.
  13713. *
  13714. * @param {string|!Element|!angular.JQLite} element Query selector, DOM element,
  13715. * or angular element to position the panel with respect to.
  13716. * @returns {!MdPanelPosition}
  13717. */
  13718. /**
  13719. * @ngdoc method
  13720. * @name MdPanelPosition#top
  13721. * @description
  13722. * Sets the value of `top` for the panel. Clears any previously set vertical
  13723. * position.
  13724. *
  13725. * @param {string=} top Value of `top`. Defaults to '0'.
  13726. * @returns {!MdPanelPosition}
  13727. */
  13728. /**
  13729. * @ngdoc method
  13730. * @name MdPanelPosition#bottom
  13731. * @description
  13732. * Sets the value of `bottom` for the panel. Clears any previously set vertical
  13733. * position.
  13734. *
  13735. * @param {string=} bottom Value of `bottom`. Defaults to '0'.
  13736. * @returns {!MdPanelPosition}
  13737. */
  13738. /**
  13739. * @ngdoc method
  13740. * @name MdPanelPosition#start
  13741. * @description
  13742. * Sets the panel to the start of the page - `left` if `ltr` or `right` for
  13743. * `rtl`. Clears any previously set horizontal position.
  13744. *
  13745. * @param {string=} start Value of position. Defaults to '0'.
  13746. * @returns {!MdPanelPosition}
  13747. */
  13748. /**
  13749. * @ngdoc method
  13750. * @name MdPanelPosition#end
  13751. * @description
  13752. * Sets the panel to the end of the page - `right` if `ltr` or `left` for `rtl`.
  13753. * Clears any previously set horizontal position.
  13754. *
  13755. * @param {string=} end Value of position. Defaults to '0'.
  13756. * @returns {!MdPanelPosition}
  13757. */
  13758. /**
  13759. * @ngdoc method
  13760. * @name MdPanelPosition#left
  13761. * @description
  13762. * Sets the value of `left` for the panel. Clears any previously set
  13763. * horizontal position.
  13764. *
  13765. * @param {string=} left Value of `left`. Defaults to '0'.
  13766. * @returns {!MdPanelPosition}
  13767. */
  13768. /**
  13769. * @ngdoc method
  13770. * @name MdPanelPosition#right
  13771. * @description
  13772. * Sets the value of `right` for the panel. Clears any previously set
  13773. * horizontal position.
  13774. *
  13775. * @param {string=} right Value of `right`. Defaults to '0'.
  13776. * @returns {!MdPanelPosition}
  13777. */
  13778. /**
  13779. * @ngdoc method
  13780. * @name MdPanelPosition#centerHorizontally
  13781. * @description
  13782. * Centers the panel horizontally in the viewport. Clears any previously set
  13783. * horizontal position.
  13784. *
  13785. * @returns {!MdPanelPosition}
  13786. */
  13787. /**
  13788. * @ngdoc method
  13789. * @name MdPanelPosition#centerVertically
  13790. * @description
  13791. * Centers the panel vertically in the viewport. Clears any previously set
  13792. * vertical position.
  13793. *
  13794. * @returns {!MdPanelPosition}
  13795. */
  13796. /**
  13797. * @ngdoc method
  13798. * @name MdPanelPosition#center
  13799. * @description
  13800. * Centers the panel horizontally and vertically in the viewport. This is
  13801. * equivalent to calling both `centerHorizontally` and `centerVertically`.
  13802. * Clears any previously set horizontal and vertical positions.
  13803. *
  13804. * @returns {!MdPanelPosition}
  13805. */
  13806. /**
  13807. * @ngdoc method
  13808. * @name MdPanelPosition#addPanelPosition
  13809. * @description
  13810. * Sets the x and y position for the panel relative to another element. Can be
  13811. * called multiple times to specify an ordered list of panel positions. The
  13812. * first position which allows the panel to be completely on-screen will be
  13813. * chosen; the last position will be chose whether it is on-screen or not.
  13814. *
  13815. * xPosition must be one of the following values available on
  13816. * $mdPanel.xPosition:
  13817. *
  13818. *
  13819. * CENTER | ALIGN_START | ALIGN_END | OFFSET_START | OFFSET_END
  13820. *
  13821. * <pre>
  13822. * *************
  13823. * * *
  13824. * * PANEL *
  13825. * * *
  13826. * *************
  13827. * A B C D E
  13828. *
  13829. * A: OFFSET_START (for LTR displays)
  13830. * B: ALIGN_START (for LTR displays)
  13831. * C: CENTER
  13832. * D: ALIGN_END (for LTR displays)
  13833. * E: OFFSET_END (for LTR displays)
  13834. * </pre>
  13835. *
  13836. * yPosition must be one of the following values available on
  13837. * $mdPanel.yPosition:
  13838. *
  13839. * CENTER | ALIGN_TOPS | ALIGN_BOTTOMS | ABOVE | BELOW
  13840. *
  13841. * <pre>
  13842. * F
  13843. * G *************
  13844. * * *
  13845. * H * PANEL *
  13846. * * *
  13847. * I *************
  13848. * J
  13849. *
  13850. * F: BELOW
  13851. * G: ALIGN_TOPS
  13852. * H: CENTER
  13853. * I: ALIGN_BOTTOMS
  13854. * J: ABOVE
  13855. * </pre>
  13856. *
  13857. * @param {string} xPosition
  13858. * @param {string} yPosition
  13859. * @returns {!MdPanelPosition}
  13860. */
  13861. /**
  13862. * @ngdoc method
  13863. * @name MdPanelPosition#withOffsetX
  13864. * @description
  13865. * Sets the value of the offset in the x-direction.
  13866. *
  13867. * @param {string|number} offsetX
  13868. * @returns {!MdPanelPosition}
  13869. */
  13870. /**
  13871. * @ngdoc method
  13872. * @name MdPanelPosition#withOffsetY
  13873. * @description
  13874. * Sets the value of the offset in the y-direction.
  13875. *
  13876. * @param {string|number} offsetY
  13877. * @returns {!MdPanelPosition}
  13878. */
  13879. /*****************************************************************************
  13880. * MdPanelAnimation *
  13881. *****************************************************************************/
  13882. /**
  13883. * @ngdoc type
  13884. * @name MdPanelAnimation
  13885. * @module material.components.panel
  13886. * @description
  13887. * Animation configuration object. To use, create an MdPanelAnimation with the
  13888. * desired properties, then pass the object as part of $mdPanel creation.
  13889. *
  13890. * @usage
  13891. *
  13892. * <hljs lang="js">
  13893. * var panelAnimation = new MdPanelAnimation()
  13894. * .openFrom(myButtonEl)
  13895. * .duration(1337)
  13896. * .closeTo('.my-button')
  13897. * .withAnimation($mdPanel.animation.SCALE);
  13898. *
  13899. * $mdPanel.create({
  13900. * animation: panelAnimation
  13901. * });
  13902. * </hljs>
  13903. */
  13904. /**
  13905. * @ngdoc method
  13906. * @name MdPanelAnimation#openFrom
  13907. * @description
  13908. * Specifies where to start the open animation. `openFrom` accepts a
  13909. * click event object, query selector, DOM element, or a Rect object that
  13910. * is used to determine the bounds. When passed a click event, the location
  13911. * of the click will be used as the position to start the animation.
  13912. *
  13913. * @param {string|!Element|!Event|{top: number, left: number}}
  13914. * @returns {!MdPanelAnimation}
  13915. */
  13916. /**
  13917. * @ngdoc method
  13918. * @name MdPanelAnimation#closeTo
  13919. * @description
  13920. * Specifies where to animate the panel close. `closeTo` accepts a
  13921. * query selector, DOM element, or a Rect object that is used to determine
  13922. * the bounds.
  13923. *
  13924. * @param {string|!Element|{top: number, left: number}}
  13925. * @returns {!MdPanelAnimation}
  13926. */
  13927. /**
  13928. * @ngdoc method
  13929. * @name MdPanelAnimation#withAnimation
  13930. * @description
  13931. * Specifies the animation class.
  13932. *
  13933. * There are several default animations that can be used: `$mdPanel.animation.`
  13934. * - `SLIDE`: The panel slides in and out from the specified
  13935. * elements. It will not fade in or out.
  13936. * - `SCALE`: The panel scales in and out. Slide and fade are
  13937. * included in this animation.
  13938. * - `FADE`: The panel fades in and out.
  13939. *
  13940. * Custom classes will by default fade in and out unless
  13941. * `transition: opacity 1ms` is added to the to custom class.
  13942. *
  13943. * @param {string|{open: string, close: string}} cssClass
  13944. * @returns {!MdPanelAnimation}
  13945. */
  13946. /**
  13947. * @ngdoc method
  13948. * @name MdPanelAnimation#duration
  13949. * @description
  13950. * Specifies the duration of the animation in milliseconds. The `duration`
  13951. * method accepts either a number or an object with separate open and close
  13952. * durations.
  13953. *
  13954. * @param {number|{open: number, close: number}} duration
  13955. * @returns {!MdPanelAnimation}
  13956. */
  13957. /*****************************************************************************
  13958. * PUBLIC DOCUMENTATION *
  13959. *****************************************************************************/
  13960. var MD_PANEL_Z_INDEX = 80;
  13961. var MD_PANEL_HIDDEN = '_md-panel-hidden';
  13962. var FOCUS_TRAP_TEMPLATE = angular.element(
  13963. '<div class="_md-panel-focus-trap" tabindex="0"></div>');
  13964. var _presets = {};
  13965. /**
  13966. * A provider that is used for creating presets for the panel API.
  13967. * @final @constructor @ngInject
  13968. */
  13969. function MdPanelProvider() {
  13970. return {
  13971. 'definePreset': definePreset,
  13972. 'getAllPresets': getAllPresets,
  13973. 'clearPresets': clearPresets,
  13974. '$get': $getProvider()
  13975. };
  13976. }
  13977. /**
  13978. * Takes the passed in panel configuration object and adds it to the `_presets`
  13979. * object at the specified name.
  13980. * @param {string} name Name of the preset to set.
  13981. * @param {!Object} preset Specific configuration object that can contain any
  13982. * and all of the parameters available within the `$mdPanel.create` method.
  13983. * However, parameters that pertain to id, position, animation, and user
  13984. * interaction are not allowed and will be removed from the preset
  13985. * configuration.
  13986. */
  13987. function definePreset(name, preset) {
  13988. if (!name || !preset) {
  13989. throw new Error('mdPanelProvider: The panel preset definition is ' +
  13990. 'malformed. The name and preset object are required.');
  13991. } else if (_presets.hasOwnProperty(name)) {
  13992. throw new Error('mdPanelProvider: The panel preset you have requested ' +
  13993. 'has already been defined.');
  13994. }
  13995. // Delete any property on the preset that is not allowed.
  13996. delete preset.id;
  13997. delete preset.position;
  13998. delete preset.animation;
  13999. _presets[name] = preset;
  14000. }
  14001. /**
  14002. * Gets a clone of the `_presets`.
  14003. * @return {!Object}
  14004. */
  14005. function getAllPresets() {
  14006. return angular.copy(_presets);
  14007. }
  14008. /**
  14009. * Clears all of the stored presets.
  14010. */
  14011. function clearPresets() {
  14012. _presets = {};
  14013. }
  14014. /**
  14015. * Represents the `$get` method of the AngularJS provider. From here, a new
  14016. * reference to the MdPanelService is returned where the needed arguments are
  14017. * passed in including the MdPanelProvider `_presets`.
  14018. * @param {!Object} _presets
  14019. * @param {!angular.JQLite} $rootElement
  14020. * @param {!angular.Scope} $rootScope
  14021. * @param {!angular.$injector} $injector
  14022. * @param {!angular.$window} $window
  14023. */
  14024. function $getProvider() {
  14025. return [
  14026. '$rootElement', '$rootScope', '$injector', '$window',
  14027. function($rootElement, $rootScope, $injector, $window) {
  14028. return new MdPanelService(_presets, $rootElement, $rootScope,
  14029. $injector, $window);
  14030. }
  14031. ];
  14032. }
  14033. /*****************************************************************************
  14034. * MdPanel Service *
  14035. *****************************************************************************/
  14036. /**
  14037. * A service that is used for controlling/displaying panels on the screen.
  14038. * @param {!Object} presets
  14039. * @param {!angular.JQLite} $rootElement
  14040. * @param {!angular.Scope} $rootScope
  14041. * @param {!angular.$injector} $injector
  14042. * @param {!angular.$window} $window
  14043. * @final @constructor @ngInject
  14044. */
  14045. function MdPanelService(presets, $rootElement, $rootScope, $injector, $window) {
  14046. /**
  14047. * Default config options for the panel.
  14048. * Anything angular related needs to be done later. Therefore
  14049. * scope: $rootScope.$new(true),
  14050. * attachTo: $rootElement,
  14051. * are added later.
  14052. * @private {!Object}
  14053. */
  14054. this._defaultConfigOptions = {
  14055. bindToController: true,
  14056. clickOutsideToClose: false,
  14057. disableParentScroll: false,
  14058. escapeToClose: false,
  14059. focusOnOpen: true,
  14060. fullscreen: false,
  14061. hasBackdrop: false,
  14062. propagateContainerEvents: false,
  14063. transformTemplate: angular.bind(this, this._wrapTemplate),
  14064. trapFocus: false,
  14065. zIndex: MD_PANEL_Z_INDEX
  14066. };
  14067. /** @private {!Object} */
  14068. this._config = {};
  14069. /** @private {!Object} */
  14070. this._presets = presets;
  14071. /** @private @const */
  14072. this._$rootElement = $rootElement;
  14073. /** @private @const */
  14074. this._$rootScope = $rootScope;
  14075. /** @private @const */
  14076. this._$injector = $injector;
  14077. /** @private @const */
  14078. this._$window = $window;
  14079. /** @private @const */
  14080. this._$mdUtil = this._$injector.get('$mdUtil');
  14081. /** @private {!Object<string, !MdPanelRef>} */
  14082. this._trackedPanels = {};
  14083. /**
  14084. * @private {!Object<string,
  14085. * {panels: !Array<!MdPanelRef>,
  14086. * openPanels: !Array<!MdPanelRef>,
  14087. * maxOpen: number}>}
  14088. */
  14089. this._groups = Object.create(null);
  14090. /**
  14091. * Default animations that can be used within the panel.
  14092. * @type {enum}
  14093. */
  14094. this.animation = MdPanelAnimation.animation;
  14095. /**
  14096. * Possible values of xPosition for positioning the panel relative to
  14097. * another element.
  14098. * @type {enum}
  14099. */
  14100. this.xPosition = MdPanelPosition.xPosition;
  14101. /**
  14102. * Possible values of yPosition for positioning the panel relative to
  14103. * another element.
  14104. * @type {enum}
  14105. */
  14106. this.yPosition = MdPanelPosition.yPosition;
  14107. /**
  14108. * Possible values for the interceptors that can be registered on a panel.
  14109. * @type {enum}
  14110. */
  14111. this.interceptorTypes = MdPanelRef.interceptorTypes;
  14112. /**
  14113. * Possible values for closing of a panel.
  14114. * @type {enum}
  14115. */
  14116. this.closeReasons = MdPanelRef.closeReasons;
  14117. /**
  14118. * Possible values of absolute position.
  14119. * @type {enum}
  14120. */
  14121. this.absPosition = MdPanelPosition.absPosition;
  14122. }
  14123. /**
  14124. * Creates a panel with the specified options.
  14125. * @param {string=} preset Name of a preset configuration that can be used to
  14126. * extend the panel configuration.
  14127. * @param {!Object=} config Configuration object for the panel.
  14128. * @returns {!MdPanelRef}
  14129. */
  14130. MdPanelService.prototype.create = function(preset, config) {
  14131. if (typeof preset === 'string') {
  14132. preset = this._getPresetByName(preset);
  14133. } else if (typeof preset === 'object' &&
  14134. (angular.isUndefined(config) || !config)) {
  14135. config = preset;
  14136. preset = {};
  14137. }
  14138. preset = preset || {};
  14139. config = config || {};
  14140. // If the passed-in config contains an ID and the ID is within _trackedPanels,
  14141. // return the tracked panel after updating its config with the passed-in
  14142. // config.
  14143. if (angular.isDefined(config.id) && this._trackedPanels[config.id]) {
  14144. var trackedPanel = this._trackedPanels[config.id];
  14145. angular.extend(trackedPanel.config, config);
  14146. return trackedPanel;
  14147. }
  14148. // Combine the passed-in config, the _defaultConfigOptions, and the preset
  14149. // configuration into the `_config`.
  14150. this._config = angular.extend({
  14151. // If no ID is set within the passed-in config, then create an arbitrary ID.
  14152. id: config.id || 'panel_' + this._$mdUtil.nextUid(),
  14153. scope: this._$rootScope.$new(true),
  14154. attachTo: this._$rootElement
  14155. }, this._defaultConfigOptions, config, preset);
  14156. // Create the panelRef and add it to the `_trackedPanels` object.
  14157. var panelRef = new MdPanelRef(this._config, this._$injector);
  14158. this._trackedPanels[config.id] = panelRef;
  14159. // Add the panel to each of its requested groups.
  14160. if (this._config.groupName) {
  14161. if (angular.isString(this._config.groupName)) {
  14162. this._config.groupName = [this._config.groupName];
  14163. }
  14164. angular.forEach(this._config.groupName, function(group) {
  14165. panelRef.addToGroup(group);
  14166. });
  14167. }
  14168. this._config.scope.$on('$destroy', angular.bind(panelRef, panelRef.detach));
  14169. return panelRef;
  14170. };
  14171. /**
  14172. * Creates and opens a panel with the specified options.
  14173. * @param {string=} preset Name of a preset configuration that can be used to
  14174. * extend the panel configuration.
  14175. * @param {!Object=} config Configuration object for the panel.
  14176. * @returns {!angular.$q.Promise<!MdPanelRef>} The panel created from create.
  14177. */
  14178. MdPanelService.prototype.open = function(preset, config) {
  14179. var panelRef = this.create(preset, config);
  14180. return panelRef.open().then(function() {
  14181. return panelRef;
  14182. });
  14183. };
  14184. /**
  14185. * Gets a specific preset configuration object saved within `_presets`.
  14186. * @param {string} preset Name of the preset to search for.
  14187. * @returns {!Object} The preset configuration object.
  14188. */
  14189. MdPanelService.prototype._getPresetByName = function(preset) {
  14190. if (!this._presets[preset]) {
  14191. throw new Error('mdPanel: The panel preset configuration that you ' +
  14192. 'requested does not exist. Use the $mdPanelProvider to create a ' +
  14193. 'preset before requesting one.');
  14194. }
  14195. return this._presets[preset];
  14196. };
  14197. /**
  14198. * Returns a new instance of the MdPanelPosition. Use this to create the
  14199. * positioning object.
  14200. * @returns {!MdPanelPosition}
  14201. */
  14202. MdPanelService.prototype.newPanelPosition = function() {
  14203. return new MdPanelPosition(this._$injector);
  14204. };
  14205. /**
  14206. * Returns a new instance of the MdPanelAnimation. Use this to create the
  14207. * animation object.
  14208. * @returns {!MdPanelAnimation}
  14209. */
  14210. MdPanelService.prototype.newPanelAnimation = function() {
  14211. return new MdPanelAnimation(this._$injector);
  14212. };
  14213. /**
  14214. * Creates a panel group and adds it to a tracked list of panel groups.
  14215. * @param groupName {string} Name of the group to create.
  14216. * @param config {!Object=} Specific configuration object that may contain the
  14217. * following properties:
  14218. *
  14219. * - `maxOpen` - `{number=}`: The maximum number of panels that are allowed
  14220. * open within a defined panel group.
  14221. *
  14222. * @returns {!Object<string,
  14223. * {panels: !Array<!MdPanelRef>,
  14224. * openPanels: !Array<!MdPanelRef>,
  14225. * maxOpen: number}>} panelGroup
  14226. */
  14227. MdPanelService.prototype.newPanelGroup = function(groupName, config) {
  14228. if (!this._groups[groupName]) {
  14229. config = config || {};
  14230. var group = {
  14231. panels: [],
  14232. openPanels: [],
  14233. maxOpen: config.maxOpen > 0 ? config.maxOpen : Infinity
  14234. };
  14235. this._groups[groupName] = group;
  14236. }
  14237. return this._groups[groupName];
  14238. };
  14239. /**
  14240. * Sets the maximum number of panels in a group that can be opened at a given
  14241. * time.
  14242. * @param {string} groupName The name of the group to configure.
  14243. * @param {number} maxOpen The maximum number of panels that can be
  14244. * opened. Infinity can be passed in to remove the maxOpen limit.
  14245. */
  14246. MdPanelService.prototype.setGroupMaxOpen = function(groupName, maxOpen) {
  14247. if (this._groups[groupName]) {
  14248. this._groups[groupName].maxOpen = maxOpen;
  14249. } else {
  14250. throw new Error('mdPanel: Group does not exist yet. Call newPanelGroup().');
  14251. }
  14252. };
  14253. /**
  14254. * Determines if the current number of open panels within a group exceeds the
  14255. * limit of allowed open panels.
  14256. * @param {string} groupName The name of the group to check.
  14257. * @returns {boolean} true if open count does exceed maxOpen and false if not.
  14258. * @private
  14259. */
  14260. MdPanelService.prototype._openCountExceedsMaxOpen = function(groupName) {
  14261. if (this._groups[groupName]) {
  14262. var group = this._groups[groupName];
  14263. return group.maxOpen > 0 && group.openPanels.length > group.maxOpen;
  14264. }
  14265. return false;
  14266. };
  14267. /**
  14268. * Closes the first open panel within a specific group.
  14269. * @param {string} groupName The name of the group.
  14270. * @private
  14271. */
  14272. MdPanelService.prototype._closeFirstOpenedPanel = function(groupName) {
  14273. this._groups[groupName].openPanels[0].close();
  14274. };
  14275. /**
  14276. * Wraps the users template in two elements, md-panel-outer-wrapper, which
  14277. * covers the entire attachTo element, and md-panel, which contains only the
  14278. * template. This allows the panel control over positioning, animations,
  14279. * and similar properties.
  14280. * @param {string} origTemplate The original template.
  14281. * @returns {string} The wrapped template.
  14282. * @private
  14283. */
  14284. MdPanelService.prototype._wrapTemplate = function(origTemplate) {
  14285. var template = origTemplate || '';
  14286. // The panel should be initially rendered offscreen so we can calculate
  14287. // height and width for positioning.
  14288. return '' +
  14289. '<div class="md-panel-outer-wrapper">' +
  14290. ' <div class="md-panel _md-panel-offscreen">' + template + '</div>' +
  14291. '</div>';
  14292. };
  14293. /**
  14294. * Wraps a content element in a md-panel-outer wrapper and
  14295. * positions it off-screen. Allows for proper control over positoning
  14296. * and animations.
  14297. * @param {!angular.JQLite} contentElement Element to be wrapped.
  14298. * @return {!angular.JQLite} Wrapper element.
  14299. * @private
  14300. */
  14301. MdPanelService.prototype._wrapContentElement = function(contentElement) {
  14302. var wrapper = angular.element('<div class="md-panel-outer-wrapper">');
  14303. contentElement.addClass('md-panel _md-panel-offscreen');
  14304. wrapper.append(contentElement);
  14305. return wrapper;
  14306. };
  14307. /*****************************************************************************
  14308. * MdPanelRef *
  14309. *****************************************************************************/
  14310. /**
  14311. * A reference to a created panel. This reference contains a unique id for the
  14312. * panel, along with properties/functions used to control the panel.
  14313. * @param {!Object} config
  14314. * @param {!angular.$injector} $injector
  14315. * @final @constructor
  14316. */
  14317. function MdPanelRef(config, $injector) {
  14318. // Injected variables.
  14319. /** @private @const {!angular.$q} */
  14320. this._$q = $injector.get('$q');
  14321. /** @private @const {!angular.$mdCompiler} */
  14322. this._$mdCompiler = $injector.get('$mdCompiler');
  14323. /** @private @const {!angular.$mdConstant} */
  14324. this._$mdConstant = $injector.get('$mdConstant');
  14325. /** @private @const {!angular.$mdUtil} */
  14326. this._$mdUtil = $injector.get('$mdUtil');
  14327. /** @private @const {!angular.$mdTheming} */
  14328. this._$mdTheming = $injector.get('$mdTheming');
  14329. /** @private @const {!angular.Scope} */
  14330. this._$rootScope = $injector.get('$rootScope');
  14331. /** @private @const {!angular.$animate} */
  14332. this._$animate = $injector.get('$animate');
  14333. /** @private @const {!MdPanelRef} */
  14334. this._$mdPanel = $injector.get('$mdPanel');
  14335. /** @private @const {!angular.$log} */
  14336. this._$log = $injector.get('$log');
  14337. /** @private @const {!angular.$window} */
  14338. this._$window = $injector.get('$window');
  14339. /** @private @const {!Function} */
  14340. this._$$rAF = $injector.get('$$rAF');
  14341. // Public variables.
  14342. /**
  14343. * Unique id for the panelRef.
  14344. * @type {string}
  14345. */
  14346. this.id = config.id;
  14347. /** @type {!Object} */
  14348. this.config = config;
  14349. /** @type {!angular.JQLite|undefined} */
  14350. this.panelContainer;
  14351. /** @type {!angular.JQLite|undefined} */
  14352. this.panelEl;
  14353. /**
  14354. * Whether the panel is attached. This is synchronous. When attach is called,
  14355. * isAttached is set to true. When detach is called, isAttached is set to
  14356. * false.
  14357. * @type {boolean}
  14358. */
  14359. this.isAttached = false;
  14360. // Private variables.
  14361. /** @private {Array<function()>} */
  14362. this._removeListeners = [];
  14363. /** @private {!angular.JQLite|undefined} */
  14364. this._topFocusTrap;
  14365. /** @private {!angular.JQLite|undefined} */
  14366. this._bottomFocusTrap;
  14367. /** @private {!$mdPanel|undefined} */
  14368. this._backdropRef;
  14369. /** @private {Function?} */
  14370. this._restoreScroll = null;
  14371. /**
  14372. * Keeps track of all the panel interceptors.
  14373. * @private {!Object}
  14374. */
  14375. this._interceptors = Object.create(null);
  14376. /**
  14377. * Cleanup function, provided by `$mdCompiler` and assigned after the element
  14378. * has been compiled. When `contentElement` is used, the function is used to
  14379. * restore the element to it's proper place in the DOM.
  14380. * @private {!Function}
  14381. */
  14382. this._compilerCleanup = null;
  14383. /**
  14384. * Cache for saving and restoring element inline styles, CSS classes etc.
  14385. * @type {{styles: string, classes: string}}
  14386. */
  14387. this._restoreCache = {
  14388. styles: '',
  14389. classes: ''
  14390. };
  14391. }
  14392. MdPanelRef.interceptorTypes = {
  14393. CLOSE: 'onClose'
  14394. };
  14395. /**
  14396. * Opens an already created and configured panel. If the panel is already
  14397. * visible, does nothing.
  14398. * @returns {!angular.$q.Promise<!MdPanelRef>} A promise that is resolved when
  14399. * the panel is opened and animations finish.
  14400. */
  14401. MdPanelRef.prototype.open = function() {
  14402. var self = this;
  14403. return this._$q(function(resolve, reject) {
  14404. var done = self._done(resolve, self);
  14405. var show = self._simpleBind(self.show, self);
  14406. var checkGroupMaxOpen = function() {
  14407. if (self.config.groupName) {
  14408. angular.forEach(self.config.groupName, function(group) {
  14409. if (self._$mdPanel._openCountExceedsMaxOpen(group)) {
  14410. self._$mdPanel._closeFirstOpenedPanel(group);
  14411. }
  14412. });
  14413. }
  14414. };
  14415. self.attach()
  14416. .then(show)
  14417. .then(checkGroupMaxOpen)
  14418. .then(done)
  14419. .catch(reject);
  14420. });
  14421. };
  14422. /**
  14423. * Closes the panel.
  14424. * @param {string} closeReason The event type that triggered the close.
  14425. * @returns {!angular.$q.Promise<!MdPanelRef>} A promise that is resolved when
  14426. * the panel is closed and animations finish.
  14427. */
  14428. MdPanelRef.prototype.close = function(closeReason) {
  14429. var self = this;
  14430. return this._$q(function(resolve, reject) {
  14431. self._callInterceptors(MdPanelRef.interceptorTypes.CLOSE).then(function() {
  14432. var done = self._done(resolve, self);
  14433. var detach = self._simpleBind(self.detach, self);
  14434. var onCloseSuccess = self.config['onCloseSuccess'] || angular.noop;
  14435. onCloseSuccess = angular.bind(self, onCloseSuccess, self, closeReason);
  14436. self.hide()
  14437. .then(detach)
  14438. .then(done)
  14439. .then(onCloseSuccess)
  14440. .catch(reject);
  14441. }, reject);
  14442. });
  14443. };
  14444. /**
  14445. * Attaches the panel. The panel will be hidden afterwards.
  14446. * @returns {!angular.$q.Promise<!MdPanelRef>} A promise that is resolved when
  14447. * the panel is attached.
  14448. */
  14449. MdPanelRef.prototype.attach = function() {
  14450. if (this.isAttached && this.panelEl) {
  14451. return this._$q.when(this);
  14452. }
  14453. var self = this;
  14454. return this._$q(function(resolve, reject) {
  14455. var done = self._done(resolve, self);
  14456. var onDomAdded = self.config['onDomAdded'] || angular.noop;
  14457. var addListeners = function(response) {
  14458. self.isAttached = true;
  14459. self._addEventListeners();
  14460. return response;
  14461. };
  14462. self._$q.all([
  14463. self._createBackdrop(),
  14464. self._createPanel()
  14465. .then(addListeners)
  14466. .catch(reject)
  14467. ]).then(onDomAdded)
  14468. .then(done)
  14469. .catch(reject);
  14470. });
  14471. };
  14472. /**
  14473. * Only detaches the panel. Will NOT hide the panel first.
  14474. * @returns {!angular.$q.Promise<!MdPanelRef>} A promise that is resolved when
  14475. * the panel is detached.
  14476. */
  14477. MdPanelRef.prototype.detach = function() {
  14478. if (!this.isAttached) {
  14479. return this._$q.when(this);
  14480. }
  14481. var self = this;
  14482. var onDomRemoved = self.config['onDomRemoved'] || angular.noop;
  14483. var detachFn = function() {
  14484. self._removeEventListeners();
  14485. // Remove the focus traps that we added earlier for keeping focus within
  14486. // the panel.
  14487. if (self._topFocusTrap && self._topFocusTrap.parentNode) {
  14488. self._topFocusTrap.parentNode.removeChild(self._topFocusTrap);
  14489. }
  14490. if (self._bottomFocusTrap && self._bottomFocusTrap.parentNode) {
  14491. self._bottomFocusTrap.parentNode.removeChild(self._bottomFocusTrap);
  14492. }
  14493. if (self._restoreCache.classes) {
  14494. self.panelEl[0].className = self._restoreCache.classes;
  14495. }
  14496. // Either restore the saved styles or clear the ones set by mdPanel.
  14497. self.panelEl[0].style.cssText = self._restoreCache.styles || '';
  14498. self._compilerCleanup();
  14499. self.panelContainer.remove();
  14500. self.isAttached = false;
  14501. return self._$q.when(self);
  14502. };
  14503. if (this._restoreScroll) {
  14504. this._restoreScroll();
  14505. this._restoreScroll = null;
  14506. }
  14507. return this._$q(function(resolve, reject) {
  14508. var done = self._done(resolve, self);
  14509. self._$q.all([
  14510. detachFn(),
  14511. self._backdropRef ? self._backdropRef.detach() : true
  14512. ]).then(onDomRemoved)
  14513. .then(done)
  14514. .catch(reject);
  14515. });
  14516. };
  14517. /**
  14518. * Destroys the panel. The Panel cannot be opened again after this.
  14519. */
  14520. MdPanelRef.prototype.destroy = function() {
  14521. var self = this;
  14522. if (this.config.groupName) {
  14523. angular.forEach(this.config.groupName, function(group) {
  14524. self.removeFromGroup(group);
  14525. });
  14526. }
  14527. this.config.scope.$destroy();
  14528. this.config.locals = null;
  14529. this.config.onDomAdded = null;
  14530. this.config.onDomRemoved = null;
  14531. this.config.onRemoving = null;
  14532. this.config.onOpenComplete = null;
  14533. this._interceptors = null;
  14534. };
  14535. /**
  14536. * Shows the panel.
  14537. * @returns {!angular.$q.Promise<!MdPanelRef>} A promise that is resolved when
  14538. * the panel has shown and animations finish.
  14539. */
  14540. MdPanelRef.prototype.show = function() {
  14541. if (!this.panelContainer) {
  14542. return this._$q(function(resolve, reject) {
  14543. reject('mdPanel: Panel does not exist yet. Call open() or attach().');
  14544. });
  14545. }
  14546. if (!this.panelContainer.hasClass(MD_PANEL_HIDDEN)) {
  14547. return this._$q.when(this);
  14548. }
  14549. var self = this;
  14550. var animatePromise = function() {
  14551. self.panelContainer.removeClass(MD_PANEL_HIDDEN);
  14552. return self._animateOpen();
  14553. };
  14554. return this._$q(function(resolve, reject) {
  14555. var done = self._done(resolve, self);
  14556. var onOpenComplete = self.config['onOpenComplete'] || angular.noop;
  14557. var addToGroupOpen = function() {
  14558. if (self.config.groupName) {
  14559. angular.forEach(self.config.groupName, function(group) {
  14560. self._$mdPanel._groups[group].openPanels.push(self);
  14561. });
  14562. }
  14563. };
  14564. self._$q.all([
  14565. self._backdropRef ? self._backdropRef.show() : self,
  14566. animatePromise().then(function() { self._focusOnOpen(); }, reject)
  14567. ]).then(onOpenComplete)
  14568. .then(addToGroupOpen)
  14569. .then(done)
  14570. .catch(reject);
  14571. });
  14572. };
  14573. /**
  14574. * Hides the panel.
  14575. * @returns {!angular.$q.Promise<!MdPanelRef>} A promise that is resolved when
  14576. * the panel has hidden and animations finish.
  14577. */
  14578. MdPanelRef.prototype.hide = function() {
  14579. if (!this.panelContainer) {
  14580. return this._$q(function(resolve, reject) {
  14581. reject('mdPanel: Panel does not exist yet. Call open() or attach().');
  14582. });
  14583. }
  14584. if (this.panelContainer.hasClass(MD_PANEL_HIDDEN)) {
  14585. return this._$q.when(this);
  14586. }
  14587. var self = this;
  14588. return this._$q(function(resolve, reject) {
  14589. var done = self._done(resolve, self);
  14590. var onRemoving = self.config['onRemoving'] || angular.noop;
  14591. var hidePanel = function() {
  14592. self.panelContainer.addClass(MD_PANEL_HIDDEN);
  14593. };
  14594. var removeFromGroupOpen = function() {
  14595. if (self.config.groupName) {
  14596. var group, index;
  14597. angular.forEach(self.config.groupName, function(group) {
  14598. group = self._$mdPanel._groups[group];
  14599. index = group.openPanels.indexOf(self);
  14600. if (index > -1) {
  14601. group.openPanels.splice(index, 1);
  14602. }
  14603. });
  14604. }
  14605. };
  14606. var focusOnOrigin = function() {
  14607. var origin = self.config['origin'];
  14608. if (origin) {
  14609. getElement(origin).focus();
  14610. }
  14611. };
  14612. self._$q.all([
  14613. self._backdropRef ? self._backdropRef.hide() : self,
  14614. self._animateClose()
  14615. .then(onRemoving)
  14616. .then(hidePanel)
  14617. .then(removeFromGroupOpen)
  14618. .then(focusOnOrigin)
  14619. .catch(reject)
  14620. ]).then(done, reject);
  14621. });
  14622. };
  14623. /**
  14624. * Add a class to the panel. DO NOT use this to hide/show the panel.
  14625. * @deprecated
  14626. * This method is in the process of being deprecated in favor of using the panel
  14627. * and container JQLite elements that are referenced in the MdPanelRef object.
  14628. * Full deprecation is scheduled for material 1.2.
  14629. *
  14630. * @param {string} newClass Class to be added.
  14631. * @param {boolean} toElement Whether or not to add the class to the panel
  14632. * element instead of the container.
  14633. */
  14634. MdPanelRef.prototype.addClass = function(newClass, toElement) {
  14635. this._$log.warn(
  14636. 'mdPanel: The addClass method is in the process of being deprecated. ' +
  14637. 'Full deprecation is scheduled for the AngularJS Material 1.2 release. ' +
  14638. 'To achieve the same results, use the panelContainer or panelEl ' +
  14639. 'JQLite elements that are referenced in MdPanelRef.');
  14640. if (!this.panelContainer) {
  14641. throw new Error(
  14642. 'mdPanel: Panel does not exist yet. Call open() or attach().');
  14643. }
  14644. if (!toElement && !this.panelContainer.hasClass(newClass)) {
  14645. this.panelContainer.addClass(newClass);
  14646. } else if (toElement && !this.panelEl.hasClass(newClass)) {
  14647. this.panelEl.addClass(newClass);
  14648. }
  14649. };
  14650. /**
  14651. * Remove a class from the panel. DO NOT use this to hide/show the panel.
  14652. * @deprecated
  14653. * This method is in the process of being deprecated in favor of using the panel
  14654. * and container JQLite elements that are referenced in the MdPanelRef object.
  14655. * Full deprecation is scheduled for material 1.2.
  14656. *
  14657. * @param {string} oldClass Class to be removed.
  14658. * @param {boolean} fromElement Whether or not to remove the class from the
  14659. * panel element instead of the container.
  14660. */
  14661. MdPanelRef.prototype.removeClass = function(oldClass, fromElement) {
  14662. this._$log.warn(
  14663. 'mdPanel: The removeClass method is in the process of being deprecated. ' +
  14664. 'Full deprecation is scheduled for the AngularJS Material 1.2 release. ' +
  14665. 'To achieve the same results, use the panelContainer or panelEl ' +
  14666. 'JQLite elements that are referenced in MdPanelRef.');
  14667. if (!this.panelContainer) {
  14668. throw new Error(
  14669. 'mdPanel: Panel does not exist yet. Call open() or attach().');
  14670. }
  14671. if (!fromElement && this.panelContainer.hasClass(oldClass)) {
  14672. this.panelContainer.removeClass(oldClass);
  14673. } else if (fromElement && this.panelEl.hasClass(oldClass)) {
  14674. this.panelEl.removeClass(oldClass);
  14675. }
  14676. };
  14677. /**
  14678. * Toggle a class on the panel. DO NOT use this to hide/show the panel.
  14679. * @deprecated
  14680. * This method is in the process of being deprecated in favor of using the panel
  14681. * and container JQLite elements that are referenced in the MdPanelRef object.
  14682. * Full deprecation is scheduled for material 1.2.
  14683. *
  14684. * @param {string} toggleClass The class to toggle.
  14685. * @param {boolean} onElement Whether or not to toggle the class on the panel
  14686. * element instead of the container.
  14687. */
  14688. MdPanelRef.prototype.toggleClass = function(toggleClass, onElement) {
  14689. this._$log.warn(
  14690. 'mdPanel: The toggleClass method is in the process of being deprecated. ' +
  14691. 'Full deprecation is scheduled for the AngularJS Material 1.2 release. ' +
  14692. 'To achieve the same results, use the panelContainer or panelEl ' +
  14693. 'JQLite elements that are referenced in MdPanelRef.');
  14694. if (!this.panelContainer) {
  14695. throw new Error(
  14696. 'mdPanel: Panel does not exist yet. Call open() or attach().');
  14697. }
  14698. if (!onElement) {
  14699. this.panelContainer.toggleClass(toggleClass);
  14700. } else {
  14701. this.panelEl.toggleClass(toggleClass);
  14702. }
  14703. };
  14704. /**
  14705. * Compiles the panel, according to the passed in config and appends it to
  14706. * the DOM. Helps normalize differences in the compilation process between
  14707. * using a string template and a content element.
  14708. * @returns {!angular.$q.Promise<!MdPanelRef>} Promise that is resolved when
  14709. * the element has been compiled and added to the DOM.
  14710. * @private
  14711. */
  14712. MdPanelRef.prototype._compile = function() {
  14713. var self = this;
  14714. // Compile the element via $mdCompiler. Note that when using a
  14715. // contentElement, the element isn't actually being compiled, rather the
  14716. // compiler saves it's place in the DOM and provides a way of restoring it.
  14717. return self._$mdCompiler.compile(self.config).then(function(compileData) {
  14718. var config = self.config;
  14719. if (config.contentElement) {
  14720. var panelEl = compileData.element;
  14721. // Since mdPanel modifies the inline styles and CSS classes, we need
  14722. // to save them in order to be able to restore on close.
  14723. self._restoreCache.styles = panelEl[0].style.cssText;
  14724. self._restoreCache.classes = panelEl[0].className;
  14725. self.panelContainer = self._$mdPanel._wrapContentElement(panelEl);
  14726. self.panelEl = panelEl;
  14727. } else {
  14728. self.panelContainer = compileData.link(config['scope']);
  14729. self.panelEl = angular.element(
  14730. self.panelContainer[0].querySelector('.md-panel')
  14731. );
  14732. }
  14733. // Save a reference to the cleanup function from the compiler.
  14734. self._compilerCleanup = compileData.cleanup;
  14735. // Attach the panel to the proper place in the DOM.
  14736. getElement(self.config['attachTo']).append(self.panelContainer);
  14737. return self;
  14738. });
  14739. };
  14740. /**
  14741. * Creates a panel and adds it to the dom.
  14742. * @returns {!angular.$q.Promise} A promise that is resolved when the panel is
  14743. * created.
  14744. * @private
  14745. */
  14746. MdPanelRef.prototype._createPanel = function() {
  14747. var self = this;
  14748. return this._$q(function(resolve, reject) {
  14749. if (!self.config.locals) {
  14750. self.config.locals = {};
  14751. }
  14752. self.config.locals.mdPanelRef = self;
  14753. self._compile().then(function() {
  14754. if (self.config['disableParentScroll']) {
  14755. self._restoreScroll = self._$mdUtil.disableScrollAround(
  14756. null,
  14757. self.panelContainer,
  14758. { disableScrollMask: true }
  14759. );
  14760. }
  14761. // Add a custom CSS class to the panel element.
  14762. if (self.config['panelClass']) {
  14763. self.panelEl.addClass(self.config['panelClass']);
  14764. }
  14765. // Handle click and touch events for the panel container.
  14766. if (self.config['propagateContainerEvents']) {
  14767. self.panelContainer.css('pointer-events', 'none');
  14768. self.panelEl.css('pointer-events', 'all');
  14769. }
  14770. // Panel may be outside the $rootElement, tell ngAnimate to animate
  14771. // regardless.
  14772. if (self._$animate.pin) {
  14773. self._$animate.pin(
  14774. self.panelContainer,
  14775. getElement(self.config['attachTo'])
  14776. );
  14777. }
  14778. self._configureTrapFocus();
  14779. self._addStyles().then(function() {
  14780. resolve(self);
  14781. }, reject);
  14782. }, reject);
  14783. });
  14784. };
  14785. /**
  14786. * Adds the styles for the panel, such as positioning and z-index. Also,
  14787. * themes the panel element and panel container using `$mdTheming`.
  14788. * @returns {!angular.$q.Promise<!MdPanelRef>}
  14789. * @private
  14790. */
  14791. MdPanelRef.prototype._addStyles = function() {
  14792. var self = this;
  14793. return this._$q(function(resolve) {
  14794. self.panelContainer.css('z-index', self.config['zIndex']);
  14795. self.panelEl.css('z-index', self.config['zIndex'] + 1);
  14796. var hideAndResolve = function() {
  14797. // Theme the element and container.
  14798. self._setTheming();
  14799. // Remove offscreen class and add hidden class.
  14800. self.panelEl.removeClass('_md-panel-offscreen');
  14801. self.panelContainer.addClass(MD_PANEL_HIDDEN);
  14802. resolve(self);
  14803. };
  14804. if (self.config['fullscreen']) {
  14805. self.panelEl.addClass('_md-panel-fullscreen');
  14806. hideAndResolve();
  14807. return; // Don't setup positioning.
  14808. }
  14809. var positionConfig = self.config['position'];
  14810. if (!positionConfig) {
  14811. hideAndResolve();
  14812. return; // Don't setup positioning.
  14813. }
  14814. // Wait for angular to finish processing the template
  14815. self._$rootScope['$$postDigest'](function() {
  14816. // Position it correctly. This is necessary so that the panel will have a
  14817. // defined height and width.
  14818. self._updatePosition(true);
  14819. // Theme the element and container.
  14820. self._setTheming();
  14821. resolve(self);
  14822. });
  14823. });
  14824. };
  14825. /**
  14826. * Sets the `$mdTheming` classes on the `panelContainer` and `panelEl`.
  14827. * @private
  14828. */
  14829. MdPanelRef.prototype._setTheming = function() {
  14830. this._$mdTheming(this.panelEl);
  14831. this._$mdTheming(this.panelContainer);
  14832. };
  14833. /**
  14834. * Updates the position configuration of a panel
  14835. * @param {!MdPanelPosition} position
  14836. */
  14837. MdPanelRef.prototype.updatePosition = function(position) {
  14838. if (!this.panelContainer) {
  14839. throw new Error(
  14840. 'mdPanel: Panel does not exist yet. Call open() or attach().');
  14841. }
  14842. this.config['position'] = position;
  14843. this._updatePosition();
  14844. };
  14845. /**
  14846. * Calculates and updates the position of the panel.
  14847. * @param {boolean=} init
  14848. * @private
  14849. */
  14850. MdPanelRef.prototype._updatePosition = function(init) {
  14851. var positionConfig = this.config['position'];
  14852. if (positionConfig) {
  14853. positionConfig._setPanelPosition(this.panelEl);
  14854. // Hide the panel now that position is known.
  14855. if (init) {
  14856. this.panelEl.removeClass('_md-panel-offscreen');
  14857. this.panelContainer.addClass(MD_PANEL_HIDDEN);
  14858. }
  14859. this.panelEl.css(
  14860. MdPanelPosition.absPosition.TOP,
  14861. positionConfig.getTop()
  14862. );
  14863. this.panelEl.css(
  14864. MdPanelPosition.absPosition.BOTTOM,
  14865. positionConfig.getBottom()
  14866. );
  14867. this.panelEl.css(
  14868. MdPanelPosition.absPosition.LEFT,
  14869. positionConfig.getLeft()
  14870. );
  14871. this.panelEl.css(
  14872. MdPanelPosition.absPosition.RIGHT,
  14873. positionConfig.getRight()
  14874. );
  14875. }
  14876. };
  14877. /**
  14878. * Focuses on the panel or the first focus target.
  14879. * @private
  14880. */
  14881. MdPanelRef.prototype._focusOnOpen = function() {
  14882. if (this.config['focusOnOpen']) {
  14883. // Wait for the template to finish rendering to guarantee md-autofocus has
  14884. // finished adding the class md-autofocus, otherwise the focusable element
  14885. // isn't available to focus.
  14886. var self = this;
  14887. this._$rootScope['$$postDigest'](function() {
  14888. var target = self._$mdUtil.findFocusTarget(self.panelEl) ||
  14889. self.panelEl;
  14890. target.focus();
  14891. });
  14892. }
  14893. };
  14894. /**
  14895. * Shows the backdrop.
  14896. * @returns {!angular.$q.Promise} A promise that is resolved when the backdrop
  14897. * is created and attached.
  14898. * @private
  14899. */
  14900. MdPanelRef.prototype._createBackdrop = function() {
  14901. if (this.config.hasBackdrop) {
  14902. if (!this._backdropRef) {
  14903. var backdropAnimation = this._$mdPanel.newPanelAnimation()
  14904. .openFrom(this.config.attachTo)
  14905. .withAnimation({
  14906. open: '_md-opaque-enter',
  14907. close: '_md-opaque-leave'
  14908. });
  14909. if (this.config.animation) {
  14910. backdropAnimation.duration(this.config.animation._rawDuration);
  14911. }
  14912. var backdropConfig = {
  14913. animation: backdropAnimation,
  14914. attachTo: this.config.attachTo,
  14915. focusOnOpen: false,
  14916. panelClass: '_md-panel-backdrop',
  14917. zIndex: this.config.zIndex - 1
  14918. };
  14919. this._backdropRef = this._$mdPanel.create(backdropConfig);
  14920. }
  14921. if (!this._backdropRef.isAttached) {
  14922. return this._backdropRef.attach();
  14923. }
  14924. }
  14925. };
  14926. /**
  14927. * Listen for escape keys and outside clicks to auto close.
  14928. * @private
  14929. */
  14930. MdPanelRef.prototype._addEventListeners = function() {
  14931. this._configureEscapeToClose();
  14932. this._configureClickOutsideToClose();
  14933. this._configureScrollListener();
  14934. };
  14935. /**
  14936. * Remove event listeners added in _addEventListeners.
  14937. * @private
  14938. */
  14939. MdPanelRef.prototype._removeEventListeners = function() {
  14940. this._removeListeners && this._removeListeners.forEach(function(removeFn) {
  14941. removeFn();
  14942. });
  14943. this._removeListeners = [];
  14944. };
  14945. /**
  14946. * Setup the escapeToClose event listeners.
  14947. * @private
  14948. */
  14949. MdPanelRef.prototype._configureEscapeToClose = function() {
  14950. if (this.config['escapeToClose']) {
  14951. var parentTarget = getElement(this.config['attachTo']);
  14952. var self = this;
  14953. var keyHandlerFn = function(ev) {
  14954. if (ev.keyCode === self._$mdConstant.KEY_CODE.ESCAPE) {
  14955. ev.stopPropagation();
  14956. ev.preventDefault();
  14957. self.close(MdPanelRef.closeReasons.ESCAPE);
  14958. }
  14959. };
  14960. // Add keydown listeners
  14961. this.panelContainer.on('keydown', keyHandlerFn);
  14962. parentTarget.on('keydown', keyHandlerFn);
  14963. // Queue remove listeners function
  14964. this._removeListeners.push(function() {
  14965. self.panelContainer.off('keydown', keyHandlerFn);
  14966. parentTarget.off('keydown', keyHandlerFn);
  14967. });
  14968. }
  14969. };
  14970. /**
  14971. * Setup the clickOutsideToClose event listeners.
  14972. * @private
  14973. */
  14974. MdPanelRef.prototype._configureClickOutsideToClose = function() {
  14975. if (this.config['clickOutsideToClose']) {
  14976. var target = this.config['propagateContainerEvents'] ?
  14977. angular.element(document.body) :
  14978. this.panelContainer;
  14979. var sourceEl;
  14980. // Keep track of the element on which the mouse originally went down
  14981. // so that we can only close the backdrop when the 'click' started on it.
  14982. // A simple 'click' handler does not work, it sets the target object as the
  14983. // element the mouse went down on.
  14984. var mousedownHandler = function(ev) {
  14985. sourceEl = ev.target;
  14986. };
  14987. // We check if our original element and the target is the backdrop
  14988. // because if the original was the backdrop and the target was inside the
  14989. // panel we don't want to panel to close.
  14990. var self = this;
  14991. var mouseupHandler = function(ev) {
  14992. if (self.config['propagateContainerEvents']) {
  14993. // We check if the sourceEl of the event is the panel element or one
  14994. // of it's children. If it is not, then close the panel.
  14995. if (sourceEl !== self.panelEl[0] && !self.panelEl[0].contains(sourceEl)) {
  14996. self.close();
  14997. }
  14998. } else if (sourceEl === target[0] && ev.target === target[0]) {
  14999. ev.stopPropagation();
  15000. ev.preventDefault();
  15001. self.close(MdPanelRef.closeReasons.CLICK_OUTSIDE);
  15002. }
  15003. };
  15004. // Add listeners
  15005. target.on('mousedown', mousedownHandler);
  15006. target.on('mouseup', mouseupHandler);
  15007. // Queue remove listeners function
  15008. this._removeListeners.push(function() {
  15009. target.off('mousedown', mousedownHandler);
  15010. target.off('mouseup', mouseupHandler);
  15011. });
  15012. }
  15013. };
  15014. /**
  15015. * Configures the listeners for updating the panel position on scroll.
  15016. * @private
  15017. */
  15018. MdPanelRef.prototype._configureScrollListener = function() {
  15019. // No need to bind the event if scrolling is disabled.
  15020. if (!this.config['disableParentScroll']) {
  15021. var updatePosition = angular.bind(this, this._updatePosition);
  15022. var debouncedUpdatePosition = this._$$rAF.throttle(updatePosition);
  15023. var self = this;
  15024. var onScroll = function() {
  15025. debouncedUpdatePosition();
  15026. };
  15027. // Add listeners.
  15028. this._$window.addEventListener('scroll', onScroll, true);
  15029. // Queue remove listeners function.
  15030. this._removeListeners.push(function() {
  15031. self._$window.removeEventListener('scroll', onScroll, true);
  15032. });
  15033. }
  15034. };
  15035. /**
  15036. * Setup the focus traps. These traps will wrap focus when tabbing past the
  15037. * panel. When shift-tabbing, the focus will stick in place.
  15038. * @private
  15039. */
  15040. MdPanelRef.prototype._configureTrapFocus = function() {
  15041. // Focus doesn't remain inside of the panel without this.
  15042. this.panelEl.attr('tabIndex', '-1');
  15043. if (this.config['trapFocus']) {
  15044. var element = this.panelEl;
  15045. // Set up elements before and after the panel to capture focus and
  15046. // redirect back into the panel.
  15047. this._topFocusTrap = FOCUS_TRAP_TEMPLATE.clone()[0];
  15048. this._bottomFocusTrap = FOCUS_TRAP_TEMPLATE.clone()[0];
  15049. // When focus is about to move out of the panel, we want to intercept it
  15050. // and redirect it back to the panel element.
  15051. var focusHandler = function() {
  15052. element.focus();
  15053. };
  15054. this._topFocusTrap.addEventListener('focus', focusHandler);
  15055. this._bottomFocusTrap.addEventListener('focus', focusHandler);
  15056. // Queue remove listeners function
  15057. this._removeListeners.push(this._simpleBind(function() {
  15058. this._topFocusTrap.removeEventListener('focus', focusHandler);
  15059. this._bottomFocusTrap.removeEventListener('focus', focusHandler);
  15060. }, this));
  15061. // The top focus trap inserted immediately before the md-panel element (as
  15062. // a sibling). The bottom focus trap inserted immediately after the
  15063. // md-panel element (as a sibling).
  15064. element[0].parentNode.insertBefore(this._topFocusTrap, element[0]);
  15065. element.after(this._bottomFocusTrap);
  15066. }
  15067. };
  15068. /**
  15069. * Updates the animation of a panel.
  15070. * @param {!MdPanelAnimation} animation
  15071. */
  15072. MdPanelRef.prototype.updateAnimation = function(animation) {
  15073. this.config['animation'] = animation;
  15074. if (this._backdropRef) {
  15075. this._backdropRef.config.animation.duration(animation._rawDuration);
  15076. }
  15077. };
  15078. /**
  15079. * Animate the panel opening.
  15080. * @returns {!angular.$q.Promise} A promise that is resolved when the panel has
  15081. * animated open.
  15082. * @private
  15083. */
  15084. MdPanelRef.prototype._animateOpen = function() {
  15085. this.panelContainer.addClass('md-panel-is-showing');
  15086. var animationConfig = this.config['animation'];
  15087. if (!animationConfig) {
  15088. // Promise is in progress, return it.
  15089. this.panelContainer.addClass('_md-panel-shown');
  15090. return this._$q.when(this);
  15091. }
  15092. var self = this;
  15093. return this._$q(function(resolve) {
  15094. var done = self._done(resolve, self);
  15095. var warnAndOpen = function() {
  15096. self._$log.warn(
  15097. 'mdPanel: MdPanel Animations failed. ' +
  15098. 'Showing panel without animating.');
  15099. done();
  15100. };
  15101. animationConfig.animateOpen(self.panelEl)
  15102. .then(done, warnAndOpen);
  15103. });
  15104. };
  15105. /**
  15106. * Animate the panel closing.
  15107. * @returns {!angular.$q.Promise} A promise that is resolved when the panel has
  15108. * animated closed.
  15109. * @private
  15110. */
  15111. MdPanelRef.prototype._animateClose = function() {
  15112. var animationConfig = this.config['animation'];
  15113. if (!animationConfig) {
  15114. this.panelContainer.removeClass('md-panel-is-showing');
  15115. this.panelContainer.removeClass('_md-panel-shown');
  15116. return this._$q.when(this);
  15117. }
  15118. var self = this;
  15119. return this._$q(function(resolve) {
  15120. var done = function() {
  15121. self.panelContainer.removeClass('md-panel-is-showing');
  15122. resolve(self);
  15123. };
  15124. var warnAndClose = function() {
  15125. self._$log.warn(
  15126. 'mdPanel: MdPanel Animations failed. ' +
  15127. 'Hiding panel without animating.');
  15128. done();
  15129. };
  15130. animationConfig.animateClose(self.panelEl)
  15131. .then(done, warnAndClose);
  15132. });
  15133. };
  15134. /**
  15135. * Registers a interceptor with the panel. The callback should return a promise,
  15136. * which will allow the action to continue when it gets resolved, or will
  15137. * prevent an action if it is rejected.
  15138. * @param {string} type Type of interceptor.
  15139. * @param {!angular.$q.Promise<!any>} callback Callback to be registered.
  15140. * @returns {!MdPanelRef}
  15141. */
  15142. MdPanelRef.prototype.registerInterceptor = function(type, callback) {
  15143. var error = null;
  15144. if (!angular.isString(type)) {
  15145. error = 'Interceptor type must be a string, instead got ' + typeof type;
  15146. } else if (!angular.isFunction(callback)) {
  15147. error = 'Interceptor callback must be a function, instead got ' + typeof callback;
  15148. }
  15149. if (error) {
  15150. throw new Error('MdPanel: ' + error);
  15151. }
  15152. var interceptors = this._interceptors[type] = this._interceptors[type] || [];
  15153. if (interceptors.indexOf(callback) === -1) {
  15154. interceptors.push(callback);
  15155. }
  15156. return this;
  15157. };
  15158. /**
  15159. * Removes a registered interceptor.
  15160. * @param {string} type Type of interceptor to be removed.
  15161. * @param {Function} callback Interceptor to be removed.
  15162. * @returns {!MdPanelRef}
  15163. */
  15164. MdPanelRef.prototype.removeInterceptor = function(type, callback) {
  15165. var index = this._interceptors[type] ?
  15166. this._interceptors[type].indexOf(callback) : -1;
  15167. if (index > -1) {
  15168. this._interceptors[type].splice(index, 1);
  15169. }
  15170. return this;
  15171. };
  15172. /**
  15173. * Removes all interceptors.
  15174. * @param {string=} type Type of interceptors to be removed.
  15175. * If ommited, all interceptors types will be removed.
  15176. * @returns {!MdPanelRef}
  15177. */
  15178. MdPanelRef.prototype.removeAllInterceptors = function(type) {
  15179. if (type) {
  15180. this._interceptors[type] = [];
  15181. } else {
  15182. this._interceptors = Object.create(null);
  15183. }
  15184. return this;
  15185. };
  15186. /**
  15187. * Invokes all the interceptors of a certain type sequantially in
  15188. * reverse order. Works in a similar way to `$q.all`, except it
  15189. * respects the order of the functions.
  15190. * @param {string} type Type of interceptors to be invoked.
  15191. * @returns {!angular.$q.Promise<!MdPanelRef>}
  15192. * @private
  15193. */
  15194. MdPanelRef.prototype._callInterceptors = function(type) {
  15195. var self = this;
  15196. var $q = self._$q;
  15197. var interceptors = self._interceptors && self._interceptors[type] || [];
  15198. return interceptors.reduceRight(function(promise, interceptor) {
  15199. var isPromiseLike = interceptor && angular.isFunction(interceptor.then);
  15200. var response = isPromiseLike ? interceptor : null;
  15201. /**
  15202. * For interceptors to reject/cancel subsequent portions of the chain, simply
  15203. * return a `$q.reject(<value>)`
  15204. */
  15205. return promise.then(function() {
  15206. if (!response) {
  15207. try {
  15208. response = interceptor(self);
  15209. } catch(e) {
  15210. response = $q.reject(e);
  15211. }
  15212. }
  15213. return response;
  15214. });
  15215. }, $q.resolve(self));
  15216. };
  15217. /**
  15218. * Faster, more basic than angular.bind
  15219. * http://jsperf.com/angular-bind-vs-custom-vs-native
  15220. * @param {function} callback
  15221. * @param {!Object} self
  15222. * @return {function} Callback function with a bound self.
  15223. */
  15224. MdPanelRef.prototype._simpleBind = function(callback, self) {
  15225. return function(value) {
  15226. return callback.apply(self, value);
  15227. };
  15228. };
  15229. /**
  15230. * @param {function} callback
  15231. * @param {!Object} self
  15232. * @return {function} Callback function with a self param.
  15233. */
  15234. MdPanelRef.prototype._done = function(callback, self) {
  15235. return function() {
  15236. callback(self);
  15237. };
  15238. };
  15239. /**
  15240. * Adds a panel to a group if the panel does not exist within the group already.
  15241. * A panel can only exist within a single group.
  15242. * @param {string} groupName The name of the group.
  15243. */
  15244. MdPanelRef.prototype.addToGroup = function(groupName) {
  15245. if (!this._$mdPanel._groups[groupName]) {
  15246. this._$mdPanel.newPanelGroup(groupName);
  15247. }
  15248. var group = this._$mdPanel._groups[groupName];
  15249. var index = group.panels.indexOf(this);
  15250. if (index < 0) {
  15251. group.panels.push(this);
  15252. }
  15253. };
  15254. /**
  15255. * Removes a panel from a group if the panel exists within that group. The group
  15256. * must be created ahead of time.
  15257. * @param {string} groupName The name of the group.
  15258. */
  15259. MdPanelRef.prototype.removeFromGroup = function(groupName) {
  15260. if (!this._$mdPanel._groups[groupName]) {
  15261. throw new Error('mdPanel: The group ' + groupName + ' does not exist.');
  15262. }
  15263. var group = this._$mdPanel._groups[groupName];
  15264. var index = group.panels.indexOf(this);
  15265. if (index > -1) {
  15266. group.panels.splice(index, 1);
  15267. }
  15268. };
  15269. /**
  15270. * Possible default closeReasons for the close function.
  15271. * @enum {string}
  15272. */
  15273. MdPanelRef.closeReasons = {
  15274. CLICK_OUTSIDE: 'clickOutsideToClose',
  15275. ESCAPE: 'escapeToClose',
  15276. };
  15277. /*****************************************************************************
  15278. * MdPanelPosition *
  15279. *****************************************************************************/
  15280. /**
  15281. * Position configuration object. To use, create an MdPanelPosition with the
  15282. * desired properties, then pass the object as part of $mdPanel creation.
  15283. *
  15284. * Example:
  15285. *
  15286. * var panelPosition = new MdPanelPosition()
  15287. * .relativeTo(myButtonEl)
  15288. * .addPanelPosition(
  15289. * $mdPanel.xPosition.CENTER,
  15290. * $mdPanel.yPosition.ALIGN_TOPS
  15291. * );
  15292. *
  15293. * $mdPanel.create({
  15294. * position: panelPosition
  15295. * });
  15296. *
  15297. * @param {!angular.$injector} $injector
  15298. * @final @constructor
  15299. */
  15300. function MdPanelPosition($injector) {
  15301. /** @private @const {!angular.$window} */
  15302. this._$window = $injector.get('$window');
  15303. /** @private {boolean} */
  15304. this._isRTL = $injector.get('$mdUtil').bidi() === 'rtl';
  15305. /** @private @const {!angular.$mdConstant} */
  15306. this._$mdConstant = $injector.get('$mdConstant');
  15307. /** @private {boolean} */
  15308. this._absolute = false;
  15309. /** @private {!angular.JQLite} */
  15310. this._relativeToEl;
  15311. /** @private {string} */
  15312. this._top = '';
  15313. /** @private {string} */
  15314. this._bottom = '';
  15315. /** @private {string} */
  15316. this._left = '';
  15317. /** @private {string} */
  15318. this._right = '';
  15319. /** @private {!Array<string>} */
  15320. this._translateX = [];
  15321. /** @private {!Array<string>} */
  15322. this._translateY = [];
  15323. /** @private {!Array<{x:string, y:string}>} */
  15324. this._positions = [];
  15325. /** @private {?{x:string, y:string}} */
  15326. this._actualPosition;
  15327. }
  15328. /**
  15329. * Possible values of xPosition.
  15330. * @enum {string}
  15331. */
  15332. MdPanelPosition.xPosition = {
  15333. CENTER: 'center',
  15334. ALIGN_START: 'align-start',
  15335. ALIGN_END: 'align-end',
  15336. OFFSET_START: 'offset-start',
  15337. OFFSET_END: 'offset-end'
  15338. };
  15339. /**
  15340. * Possible values of yPosition.
  15341. * @enum {string}
  15342. */
  15343. MdPanelPosition.yPosition = {
  15344. CENTER: 'center',
  15345. ALIGN_TOPS: 'align-tops',
  15346. ALIGN_BOTTOMS: 'align-bottoms',
  15347. ABOVE: 'above',
  15348. BELOW: 'below'
  15349. };
  15350. /**
  15351. * Possible values of absolute position.
  15352. * @enum {string}
  15353. */
  15354. MdPanelPosition.absPosition = {
  15355. TOP: 'top',
  15356. RIGHT: 'right',
  15357. BOTTOM: 'bottom',
  15358. LEFT: 'left'
  15359. };
  15360. /**
  15361. * Margin between the edges of a panel and the viewport.
  15362. * @const {number}
  15363. */
  15364. MdPanelPosition.viewportMargin = 8;
  15365. /**
  15366. * Sets absolute positioning for the panel.
  15367. * @return {!MdPanelPosition}
  15368. */
  15369. MdPanelPosition.prototype.absolute = function() {
  15370. this._absolute = true;
  15371. return this;
  15372. };
  15373. /**
  15374. * Sets the value of a position for the panel. Clears any previously set
  15375. * position.
  15376. * @param {string} position Position to set
  15377. * @param {string=} value Value of the position. Defaults to '0'.
  15378. * @returns {!MdPanelPosition}
  15379. * @private
  15380. */
  15381. MdPanelPosition.prototype._setPosition = function(position, value) {
  15382. if (position === MdPanelPosition.absPosition.RIGHT ||
  15383. position === MdPanelPosition.absPosition.LEFT) {
  15384. this._left = this._right = '';
  15385. } else if (
  15386. position === MdPanelPosition.absPosition.BOTTOM ||
  15387. position === MdPanelPosition.absPosition.TOP) {
  15388. this._top = this._bottom = '';
  15389. } else {
  15390. var positions = Object.keys(MdPanelPosition.absPosition).join()
  15391. .toLowerCase();
  15392. throw new Error('mdPanel: Position must be one of ' + positions + '.');
  15393. }
  15394. this['_' + position] = angular.isString(value) ? value : '0';
  15395. return this;
  15396. };
  15397. /**
  15398. * Sets the value of `top` for the panel. Clears any previously set vertical
  15399. * position.
  15400. * @param {string=} top Value of `top`. Defaults to '0'.
  15401. * @returns {!MdPanelPosition}
  15402. */
  15403. MdPanelPosition.prototype.top = function(top) {
  15404. return this._setPosition(MdPanelPosition.absPosition.TOP, top);
  15405. };
  15406. /**
  15407. * Sets the value of `bottom` for the panel. Clears any previously set vertical
  15408. * position.
  15409. * @param {string=} bottom Value of `bottom`. Defaults to '0'.
  15410. * @returns {!MdPanelPosition}
  15411. */
  15412. MdPanelPosition.prototype.bottom = function(bottom) {
  15413. return this._setPosition(MdPanelPosition.absPosition.BOTTOM, bottom);
  15414. };
  15415. /**
  15416. * Sets the panel to the start of the page - `left` if `ltr` or `right` for
  15417. * `rtl`. Clears any previously set horizontal position.
  15418. * @param {string=} start Value of position. Defaults to '0'.
  15419. * @returns {!MdPanelPosition}
  15420. */
  15421. MdPanelPosition.prototype.start = function(start) {
  15422. var position = this._isRTL ? MdPanelPosition.absPosition.RIGHT : MdPanelPosition.absPosition.LEFT;
  15423. return this._setPosition(position, start);
  15424. };
  15425. /**
  15426. * Sets the panel to the end of the page - `right` if `ltr` or `left` for `rtl`.
  15427. * Clears any previously set horizontal position.
  15428. * @param {string=} end Value of position. Defaults to '0'.
  15429. * @returns {!MdPanelPosition}
  15430. */
  15431. MdPanelPosition.prototype.end = function(end) {
  15432. var position = this._isRTL ? MdPanelPosition.absPosition.LEFT : MdPanelPosition.absPosition.RIGHT;
  15433. return this._setPosition(position, end);
  15434. };
  15435. /**
  15436. * Sets the value of `left` for the panel. Clears any previously set
  15437. * horizontal position.
  15438. * @param {string=} left Value of `left`. Defaults to '0'.
  15439. * @returns {!MdPanelPosition}
  15440. */
  15441. MdPanelPosition.prototype.left = function(left) {
  15442. return this._setPosition(MdPanelPosition.absPosition.LEFT, left);
  15443. };
  15444. /**
  15445. * Sets the value of `right` for the panel. Clears any previously set
  15446. * horizontal position.
  15447. * @param {string=} right Value of `right`. Defaults to '0'.
  15448. * @returns {!MdPanelPosition}
  15449. */
  15450. MdPanelPosition.prototype.right = function(right) {
  15451. return this._setPosition(MdPanelPosition.absPosition.RIGHT, right);
  15452. };
  15453. /**
  15454. * Centers the panel horizontally in the viewport. Clears any previously set
  15455. * horizontal position.
  15456. * @returns {!MdPanelPosition}
  15457. */
  15458. MdPanelPosition.prototype.centerHorizontally = function() {
  15459. this._left = '50%';
  15460. this._right = '';
  15461. this._translateX = ['-50%'];
  15462. return this;
  15463. };
  15464. /**
  15465. * Centers the panel vertically in the viewport. Clears any previously set
  15466. * vertical position.
  15467. * @returns {!MdPanelPosition}
  15468. */
  15469. MdPanelPosition.prototype.centerVertically = function() {
  15470. this._top = '50%';
  15471. this._bottom = '';
  15472. this._translateY = ['-50%'];
  15473. return this;
  15474. };
  15475. /**
  15476. * Centers the panel horizontally and vertically in the viewport. This is
  15477. * equivalent to calling both `centerHorizontally` and `centerVertically`.
  15478. * Clears any previously set horizontal and vertical positions.
  15479. * @returns {!MdPanelPosition}
  15480. */
  15481. MdPanelPosition.prototype.center = function() {
  15482. return this.centerHorizontally().centerVertically();
  15483. };
  15484. /**
  15485. * Sets element for relative positioning.
  15486. * @param {string|!Element|!angular.JQLite} element Query selector, DOM element,
  15487. * or angular element to set the panel relative to.
  15488. * @returns {!MdPanelPosition}
  15489. */
  15490. MdPanelPosition.prototype.relativeTo = function(element) {
  15491. this._absolute = false;
  15492. this._relativeToEl = getElement(element);
  15493. return this;
  15494. };
  15495. /**
  15496. * Sets the x and y positions for the panel relative to another element.
  15497. * @param {string} xPosition must be one of the MdPanelPosition.xPosition
  15498. * values.
  15499. * @param {string} yPosition must be one of the MdPanelPosition.yPosition
  15500. * values.
  15501. * @returns {!MdPanelPosition}
  15502. */
  15503. MdPanelPosition.prototype.addPanelPosition = function(xPosition, yPosition) {
  15504. if (!this._relativeToEl) {
  15505. throw new Error('mdPanel: addPanelPosition can only be used with ' +
  15506. 'relative positioning. Set relativeTo first.');
  15507. }
  15508. this._validateXPosition(xPosition);
  15509. this._validateYPosition(yPosition);
  15510. this._positions.push({
  15511. x: xPosition,
  15512. y: yPosition,
  15513. });
  15514. return this;
  15515. };
  15516. /**
  15517. * Ensures that yPosition is a valid position name. Throw an exception if not.
  15518. * @param {string} yPosition
  15519. */
  15520. MdPanelPosition.prototype._validateYPosition = function(yPosition) {
  15521. // empty is ok
  15522. if (yPosition == null) {
  15523. return;
  15524. }
  15525. var positionKeys = Object.keys(MdPanelPosition.yPosition);
  15526. var positionValues = [];
  15527. for (var key, i = 0; key = positionKeys[i]; i++) {
  15528. var position = MdPanelPosition.yPosition[key];
  15529. positionValues.push(position);
  15530. if (position === yPosition) {
  15531. return;
  15532. }
  15533. }
  15534. throw new Error('mdPanel: Panel y position only accepts the following ' +
  15535. 'values:\n' + positionValues.join(' | '));
  15536. };
  15537. /**
  15538. * Ensures that xPosition is a valid position name. Throw an exception if not.
  15539. * @param {string} xPosition
  15540. */
  15541. MdPanelPosition.prototype._validateXPosition = function(xPosition) {
  15542. // empty is ok
  15543. if (xPosition == null) {
  15544. return;
  15545. }
  15546. var positionKeys = Object.keys(MdPanelPosition.xPosition);
  15547. var positionValues = [];
  15548. for (var key, i = 0; key = positionKeys[i]; i++) {
  15549. var position = MdPanelPosition.xPosition[key];
  15550. positionValues.push(position);
  15551. if (position === xPosition) {
  15552. return;
  15553. }
  15554. }
  15555. throw new Error('mdPanel: Panel x Position only accepts the following ' +
  15556. 'values:\n' + positionValues.join(' | '));
  15557. };
  15558. /**
  15559. * Sets the value of the offset in the x-direction. This will add to any
  15560. * previously set offsets.
  15561. * @param {string|number|function(MdPanelPosition): string} offsetX
  15562. * @returns {!MdPanelPosition}
  15563. */
  15564. MdPanelPosition.prototype.withOffsetX = function(offsetX) {
  15565. this._translateX.push(addUnits(offsetX));
  15566. return this;
  15567. };
  15568. /**
  15569. * Sets the value of the offset in the y-direction. This will add to any
  15570. * previously set offsets.
  15571. * @param {string|number|function(MdPanelPosition): string} offsetY
  15572. * @returns {!MdPanelPosition}
  15573. */
  15574. MdPanelPosition.prototype.withOffsetY = function(offsetY) {
  15575. this._translateY.push(addUnits(offsetY));
  15576. return this;
  15577. };
  15578. /**
  15579. * Gets the value of `top` for the panel.
  15580. * @returns {string}
  15581. */
  15582. MdPanelPosition.prototype.getTop = function() {
  15583. return this._top;
  15584. };
  15585. /**
  15586. * Gets the value of `bottom` for the panel.
  15587. * @returns {string}
  15588. */
  15589. MdPanelPosition.prototype.getBottom = function() {
  15590. return this._bottom;
  15591. };
  15592. /**
  15593. * Gets the value of `left` for the panel.
  15594. * @returns {string}
  15595. */
  15596. MdPanelPosition.prototype.getLeft = function() {
  15597. return this._left;
  15598. };
  15599. /**
  15600. * Gets the value of `right` for the panel.
  15601. * @returns {string}
  15602. */
  15603. MdPanelPosition.prototype.getRight = function() {
  15604. return this._right;
  15605. };
  15606. /**
  15607. * Gets the value of `transform` for the panel.
  15608. * @returns {string}
  15609. */
  15610. MdPanelPosition.prototype.getTransform = function() {
  15611. var translateX = this._reduceTranslateValues('translateX', this._translateX);
  15612. var translateY = this._reduceTranslateValues('translateY', this._translateY);
  15613. // It's important to trim the result, because the browser will ignore the set
  15614. // operation if the string contains only whitespace.
  15615. return (translateX + ' ' + translateY).trim();
  15616. };
  15617. /**
  15618. * Sets the `transform` value for a panel element.
  15619. * @param {!angular.JQLite} panelEl
  15620. * @returns {!angular.JQLite}
  15621. * @private
  15622. */
  15623. MdPanelPosition.prototype._setTransform = function(panelEl) {
  15624. return panelEl.css(this._$mdConstant.CSS.TRANSFORM, this.getTransform());
  15625. };
  15626. /**
  15627. * True if the panel is completely on-screen with this positioning; false
  15628. * otherwise.
  15629. * @param {!angular.JQLite} panelEl
  15630. * @return {boolean}
  15631. * @private
  15632. */
  15633. MdPanelPosition.prototype._isOnscreen = function(panelEl) {
  15634. // this works because we always use fixed positioning for the panel,
  15635. // which is relative to the viewport.
  15636. var left = parseInt(this.getLeft());
  15637. var top = parseInt(this.getTop());
  15638. if (this._translateX.length || this._translateY.length) {
  15639. var prefixedTransform = this._$mdConstant.CSS.TRANSFORM;
  15640. var offsets = getComputedTranslations(panelEl, prefixedTransform);
  15641. left += offsets.x;
  15642. top += offsets.y;
  15643. }
  15644. var right = left + panelEl[0].offsetWidth;
  15645. var bottom = top + panelEl[0].offsetHeight;
  15646. return (left >= 0) &&
  15647. (top >= 0) &&
  15648. (bottom <= this._$window.innerHeight) &&
  15649. (right <= this._$window.innerWidth);
  15650. };
  15651. /**
  15652. * Gets the first x/y position that can fit on-screen.
  15653. * @returns {{x: string, y: string}}
  15654. */
  15655. MdPanelPosition.prototype.getActualPosition = function() {
  15656. return this._actualPosition;
  15657. };
  15658. /**
  15659. * Reduces a list of translate values to a string that can be used within
  15660. * transform.
  15661. * @param {string} translateFn
  15662. * @param {!Array<string>} values
  15663. * @returns {string}
  15664. * @private
  15665. */
  15666. MdPanelPosition.prototype._reduceTranslateValues =
  15667. function(translateFn, values) {
  15668. return values.map(function(translation) {
  15669. var translationValue = angular.isFunction(translation) ?
  15670. addUnits(translation(this)) : translation;
  15671. return translateFn + '(' + translationValue + ')';
  15672. }, this).join(' ');
  15673. };
  15674. /**
  15675. * Sets the panel position based on the created panel element and best x/y
  15676. * positioning.
  15677. * @param {!angular.JQLite} panelEl
  15678. * @private
  15679. */
  15680. MdPanelPosition.prototype._setPanelPosition = function(panelEl) {
  15681. // Remove the "position adjusted" class in case it has been added before.
  15682. panelEl.removeClass('_md-panel-position-adjusted');
  15683. // Only calculate the position if necessary.
  15684. if (this._absolute) {
  15685. this._setTransform(panelEl);
  15686. return;
  15687. }
  15688. if (this._actualPosition) {
  15689. this._calculatePanelPosition(panelEl, this._actualPosition);
  15690. this._setTransform(panelEl);
  15691. this._constrainToViewport(panelEl);
  15692. return;
  15693. }
  15694. for (var i = 0; i < this._positions.length; i++) {
  15695. this._actualPosition = this._positions[i];
  15696. this._calculatePanelPosition(panelEl, this._actualPosition);
  15697. this._setTransform(panelEl);
  15698. if (this._isOnscreen(panelEl)) {
  15699. return;
  15700. }
  15701. }
  15702. this._constrainToViewport(panelEl);
  15703. };
  15704. /**
  15705. * Constrains a panel's position to the viewport.
  15706. * @param {!angular.JQLite} panelEl
  15707. * @private
  15708. */
  15709. MdPanelPosition.prototype._constrainToViewport = function(panelEl) {
  15710. var margin = MdPanelPosition.viewportMargin;
  15711. var initialTop = this._top;
  15712. var initialLeft = this._left;
  15713. if (this.getTop()) {
  15714. var top = parseInt(this.getTop());
  15715. var bottom = panelEl[0].offsetHeight + top;
  15716. var viewportHeight = this._$window.innerHeight;
  15717. if (top < margin) {
  15718. this._top = margin + 'px';
  15719. } else if (bottom > viewportHeight) {
  15720. this._top = top - (bottom - viewportHeight + margin) + 'px';
  15721. }
  15722. }
  15723. if (this.getLeft()) {
  15724. var left = parseInt(this.getLeft());
  15725. var right = panelEl[0].offsetWidth + left;
  15726. var viewportWidth = this._$window.innerWidth;
  15727. if (left < margin) {
  15728. this._left = margin + 'px';
  15729. } else if (right > viewportWidth) {
  15730. this._left = left - (right - viewportWidth + margin) + 'px';
  15731. }
  15732. }
  15733. // Class that can be used to re-style the panel if it was repositioned.
  15734. panelEl.toggleClass(
  15735. '_md-panel-position-adjusted',
  15736. this._top !== initialTop || this._left !== initialLeft
  15737. );
  15738. };
  15739. /**
  15740. * Switches between 'start' and 'end'.
  15741. * @param {string} position Horizontal position of the panel
  15742. * @returns {string} Reversed position
  15743. * @private
  15744. */
  15745. MdPanelPosition.prototype._reverseXPosition = function(position) {
  15746. if (position === MdPanelPosition.xPosition.CENTER) {
  15747. return position;
  15748. }
  15749. var start = 'start';
  15750. var end = 'end';
  15751. return position.indexOf(start) > -1 ? position.replace(start, end) : position.replace(end, start);
  15752. };
  15753. /**
  15754. * Handles horizontal positioning in rtl or ltr environments.
  15755. * @param {string} position Horizontal position of the panel
  15756. * @returns {string} The correct position according the page direction
  15757. * @private
  15758. */
  15759. MdPanelPosition.prototype._bidi = function(position) {
  15760. return this._isRTL ? this._reverseXPosition(position) : position;
  15761. };
  15762. /**
  15763. * Calculates the panel position based on the created panel element and the
  15764. * provided positioning.
  15765. * @param {!angular.JQLite} panelEl
  15766. * @param {!{x:string, y:string}} position
  15767. * @private
  15768. */
  15769. MdPanelPosition.prototype._calculatePanelPosition = function(panelEl, position) {
  15770. var panelBounds = panelEl[0].getBoundingClientRect();
  15771. var panelWidth = Math.max(panelBounds.width, panelEl[0].clientWidth);
  15772. var panelHeight = Math.max(panelBounds.height, panelEl[0].clientHeight);
  15773. var targetBounds = this._relativeToEl[0].getBoundingClientRect();
  15774. var targetLeft = targetBounds.left;
  15775. var targetRight = targetBounds.right;
  15776. var targetWidth = targetBounds.width;
  15777. switch (this._bidi(position.x)) {
  15778. case MdPanelPosition.xPosition.OFFSET_START:
  15779. this._left = targetLeft - panelWidth + 'px';
  15780. break;
  15781. case MdPanelPosition.xPosition.ALIGN_END:
  15782. this._left = targetRight - panelWidth + 'px';
  15783. break;
  15784. case MdPanelPosition.xPosition.CENTER:
  15785. var left = targetLeft + (0.5 * targetWidth) - (0.5 * panelWidth);
  15786. this._left = left + 'px';
  15787. break;
  15788. case MdPanelPosition.xPosition.ALIGN_START:
  15789. this._left = targetLeft + 'px';
  15790. break;
  15791. case MdPanelPosition.xPosition.OFFSET_END:
  15792. this._left = targetRight + 'px';
  15793. break;
  15794. }
  15795. var targetTop = targetBounds.top;
  15796. var targetBottom = targetBounds.bottom;
  15797. var targetHeight = targetBounds.height;
  15798. switch (position.y) {
  15799. case MdPanelPosition.yPosition.ABOVE:
  15800. this._top = targetTop - panelHeight + 'px';
  15801. break;
  15802. case MdPanelPosition.yPosition.ALIGN_BOTTOMS:
  15803. this._top = targetBottom - panelHeight + 'px';
  15804. break;
  15805. case MdPanelPosition.yPosition.CENTER:
  15806. var top = targetTop + (0.5 * targetHeight) - (0.5 * panelHeight);
  15807. this._top = top + 'px';
  15808. break;
  15809. case MdPanelPosition.yPosition.ALIGN_TOPS:
  15810. this._top = targetTop + 'px';
  15811. break;
  15812. case MdPanelPosition.yPosition.BELOW:
  15813. this._top = targetBottom + 'px';
  15814. break;
  15815. }
  15816. };
  15817. /*****************************************************************************
  15818. * MdPanelAnimation *
  15819. *****************************************************************************/
  15820. /**
  15821. * Animation configuration object. To use, create an MdPanelAnimation with the
  15822. * desired properties, then pass the object as part of $mdPanel creation.
  15823. *
  15824. * Example:
  15825. *
  15826. * var panelAnimation = new MdPanelAnimation()
  15827. * .openFrom(myButtonEl)
  15828. * .closeTo('.my-button')
  15829. * .withAnimation($mdPanel.animation.SCALE);
  15830. *
  15831. * $mdPanel.create({
  15832. * animation: panelAnimation
  15833. * });
  15834. *
  15835. * @param {!angular.$injector} $injector
  15836. * @final @constructor
  15837. */
  15838. function MdPanelAnimation($injector) {
  15839. /** @private @const {!angular.$mdUtil} */
  15840. this._$mdUtil = $injector.get('$mdUtil');
  15841. /**
  15842. * @private {{element: !angular.JQLite|undefined, bounds: !DOMRect}|
  15843. * undefined}
  15844. */
  15845. this._openFrom;
  15846. /**
  15847. * @private {{element: !angular.JQLite|undefined, bounds: !DOMRect}|
  15848. * undefined}
  15849. */
  15850. this._closeTo;
  15851. /** @private {string|{open: string, close: string}} */
  15852. this._animationClass = '';
  15853. /** @private {number} */
  15854. this._openDuration;
  15855. /** @private {number} */
  15856. this._closeDuration;
  15857. /** @private {number|{open: number, close: number}} */
  15858. this._rawDuration;
  15859. }
  15860. /**
  15861. * Possible default animations.
  15862. * @enum {string}
  15863. */
  15864. MdPanelAnimation.animation = {
  15865. SLIDE: 'md-panel-animate-slide',
  15866. SCALE: 'md-panel-animate-scale',
  15867. FADE: 'md-panel-animate-fade'
  15868. };
  15869. /**
  15870. * Specifies where to start the open animation. `openFrom` accepts a
  15871. * click event object, query selector, DOM element, or a Rect object that
  15872. * is used to determine the bounds. When passed a click event, the location
  15873. * of the click will be used as the position to start the animation.
  15874. * @param {string|!Element|!Event|{top: number, left: number}} openFrom
  15875. * @returns {!MdPanelAnimation}
  15876. */
  15877. MdPanelAnimation.prototype.openFrom = function(openFrom) {
  15878. // Check if 'openFrom' is an Event.
  15879. openFrom = openFrom.target ? openFrom.target : openFrom;
  15880. this._openFrom = this._getPanelAnimationTarget(openFrom);
  15881. if (!this._closeTo) {
  15882. this._closeTo = this._openFrom;
  15883. }
  15884. return this;
  15885. };
  15886. /**
  15887. * Specifies where to animate the panel close. `closeTo` accepts a
  15888. * query selector, DOM element, or a Rect object that is used to determine
  15889. * the bounds.
  15890. * @param {string|!Element|{top: number, left: number}} closeTo
  15891. * @returns {!MdPanelAnimation}
  15892. */
  15893. MdPanelAnimation.prototype.closeTo = function(closeTo) {
  15894. this._closeTo = this._getPanelAnimationTarget(closeTo);
  15895. return this;
  15896. };
  15897. /**
  15898. * Specifies the duration of the animation in milliseconds.
  15899. * @param {number|{open: number, close: number}} duration
  15900. * @returns {!MdPanelAnimation}
  15901. */
  15902. MdPanelAnimation.prototype.duration = function(duration) {
  15903. if (duration) {
  15904. if (angular.isNumber(duration)) {
  15905. this._openDuration = this._closeDuration = toSeconds(duration);
  15906. } else if (angular.isObject(duration)) {
  15907. this._openDuration = toSeconds(duration.open);
  15908. this._closeDuration = toSeconds(duration.close);
  15909. }
  15910. }
  15911. // Save the original value so it can be passed to the backdrop.
  15912. this._rawDuration = duration;
  15913. return this;
  15914. function toSeconds(value) {
  15915. if (angular.isNumber(value)) return value / 1000;
  15916. }
  15917. };
  15918. /**
  15919. * Returns the element and bounds for the animation target.
  15920. * @param {string|!Element|{top: number, left: number}} location
  15921. * @returns {{element: !angular.JQLite|undefined, bounds: !DOMRect}}
  15922. * @private
  15923. */
  15924. MdPanelAnimation.prototype._getPanelAnimationTarget = function(location) {
  15925. if (angular.isDefined(location.top) || angular.isDefined(location.left)) {
  15926. return {
  15927. element: undefined,
  15928. bounds: {
  15929. top: location.top || 0,
  15930. left: location.left || 0
  15931. }
  15932. };
  15933. } else {
  15934. return this._getBoundingClientRect(getElement(location));
  15935. }
  15936. };
  15937. /**
  15938. * Specifies the animation class.
  15939. *
  15940. * There are several default animations that can be used:
  15941. * (MdPanelAnimation.animation)
  15942. * SLIDE: The panel slides in and out from the specified
  15943. * elements.
  15944. * SCALE: The panel scales in and out.
  15945. * FADE: The panel fades in and out.
  15946. *
  15947. * @param {string|{open: string, close: string}} cssClass
  15948. * @returns {!MdPanelAnimation}
  15949. */
  15950. MdPanelAnimation.prototype.withAnimation = function(cssClass) {
  15951. this._animationClass = cssClass;
  15952. return this;
  15953. };
  15954. /**
  15955. * Animate the panel open.
  15956. * @param {!angular.JQLite} panelEl
  15957. * @returns {!angular.$q.Promise} A promise that is resolved when the open
  15958. * animation is complete.
  15959. */
  15960. MdPanelAnimation.prototype.animateOpen = function(panelEl) {
  15961. var animator = this._$mdUtil.dom.animator;
  15962. this._fixBounds(panelEl);
  15963. var animationOptions = {};
  15964. // Include the panel transformations when calculating the animations.
  15965. var panelTransform = panelEl[0].style.transform || '';
  15966. var openFrom = animator.toTransformCss(panelTransform);
  15967. var openTo = animator.toTransformCss(panelTransform);
  15968. switch (this._animationClass) {
  15969. case MdPanelAnimation.animation.SLIDE:
  15970. // Slide should start with opacity: 1.
  15971. panelEl.css('opacity', '1');
  15972. animationOptions = {
  15973. transitionInClass: '_md-panel-animate-enter'
  15974. };
  15975. var openSlide = animator.calculateSlideToOrigin(
  15976. panelEl, this._openFrom) || '';
  15977. openFrom = animator.toTransformCss(openSlide + ' ' + panelTransform);
  15978. break;
  15979. case MdPanelAnimation.animation.SCALE:
  15980. animationOptions = {
  15981. transitionInClass: '_md-panel-animate-enter'
  15982. };
  15983. var openScale = animator.calculateZoomToOrigin(
  15984. panelEl, this._openFrom) || '';
  15985. openFrom = animator.toTransformCss(openScale + ' ' + panelTransform);
  15986. break;
  15987. case MdPanelAnimation.animation.FADE:
  15988. animationOptions = {
  15989. transitionInClass: '_md-panel-animate-enter'
  15990. };
  15991. break;
  15992. default:
  15993. if (angular.isString(this._animationClass)) {
  15994. animationOptions = {
  15995. transitionInClass: this._animationClass
  15996. };
  15997. } else {
  15998. animationOptions = {
  15999. transitionInClass: this._animationClass['open'],
  16000. transitionOutClass: this._animationClass['close'],
  16001. };
  16002. }
  16003. }
  16004. animationOptions.duration = this._openDuration;
  16005. return animator
  16006. .translate3d(panelEl, openFrom, openTo, animationOptions);
  16007. };
  16008. /**
  16009. * Animate the panel close.
  16010. * @param {!angular.JQLite} panelEl
  16011. * @returns {!angular.$q.Promise} A promise that resolves when the close
  16012. * animation is complete.
  16013. */
  16014. MdPanelAnimation.prototype.animateClose = function(panelEl) {
  16015. var animator = this._$mdUtil.dom.animator;
  16016. var reverseAnimationOptions = {};
  16017. // Include the panel transformations when calculating the animations.
  16018. var panelTransform = panelEl[0].style.transform || '';
  16019. var closeFrom = animator.toTransformCss(panelTransform);
  16020. var closeTo = animator.toTransformCss(panelTransform);
  16021. switch (this._animationClass) {
  16022. case MdPanelAnimation.animation.SLIDE:
  16023. // Slide should start with opacity: 1.
  16024. panelEl.css('opacity', '1');
  16025. reverseAnimationOptions = {
  16026. transitionInClass: '_md-panel-animate-leave'
  16027. };
  16028. var closeSlide = animator.calculateSlideToOrigin(
  16029. panelEl, this._closeTo) || '';
  16030. closeTo = animator.toTransformCss(closeSlide + ' ' + panelTransform);
  16031. break;
  16032. case MdPanelAnimation.animation.SCALE:
  16033. reverseAnimationOptions = {
  16034. transitionInClass: '_md-panel-animate-scale-out _md-panel-animate-leave'
  16035. };
  16036. var closeScale = animator.calculateZoomToOrigin(
  16037. panelEl, this._closeTo) || '';
  16038. closeTo = animator.toTransformCss(closeScale + ' ' + panelTransform);
  16039. break;
  16040. case MdPanelAnimation.animation.FADE:
  16041. reverseAnimationOptions = {
  16042. transitionInClass: '_md-panel-animate-fade-out _md-panel-animate-leave'
  16043. };
  16044. break;
  16045. default:
  16046. if (angular.isString(this._animationClass)) {
  16047. reverseAnimationOptions = {
  16048. transitionOutClass: this._animationClass
  16049. };
  16050. } else {
  16051. reverseAnimationOptions = {
  16052. transitionInClass: this._animationClass['close'],
  16053. transitionOutClass: this._animationClass['open']
  16054. };
  16055. }
  16056. }
  16057. reverseAnimationOptions.duration = this._closeDuration;
  16058. return animator
  16059. .translate3d(panelEl, closeFrom, closeTo, reverseAnimationOptions);
  16060. };
  16061. /**
  16062. * Set the height and width to match the panel if not provided.
  16063. * @param {!angular.JQLite} panelEl
  16064. * @private
  16065. */
  16066. MdPanelAnimation.prototype._fixBounds = function(panelEl) {
  16067. var panelWidth = panelEl[0].offsetWidth;
  16068. var panelHeight = panelEl[0].offsetHeight;
  16069. if (this._openFrom && this._openFrom.bounds.height == null) {
  16070. this._openFrom.bounds.height = panelHeight;
  16071. }
  16072. if (this._openFrom && this._openFrom.bounds.width == null) {
  16073. this._openFrom.bounds.width = panelWidth;
  16074. }
  16075. if (this._closeTo && this._closeTo.bounds.height == null) {
  16076. this._closeTo.bounds.height = panelHeight;
  16077. }
  16078. if (this._closeTo && this._closeTo.bounds.width == null) {
  16079. this._closeTo.bounds.width = panelWidth;
  16080. }
  16081. };
  16082. /**
  16083. * Identify the bounding RECT for the target element.
  16084. * @param {!angular.JQLite} element
  16085. * @returns {{element: !angular.JQLite|undefined, bounds: !DOMRect}}
  16086. * @private
  16087. */
  16088. MdPanelAnimation.prototype._getBoundingClientRect = function(element) {
  16089. if (element instanceof angular.element) {
  16090. return {
  16091. element: element,
  16092. bounds: element[0].getBoundingClientRect()
  16093. };
  16094. }
  16095. };
  16096. /*****************************************************************************
  16097. * Util Methods *
  16098. *****************************************************************************/
  16099. /**
  16100. * Returns the angular element associated with a css selector or element.
  16101. * @param el {string|!angular.JQLite|!Element}
  16102. * @returns {!angular.JQLite}
  16103. */
  16104. function getElement(el) {
  16105. var queryResult = angular.isString(el) ?
  16106. document.querySelector(el) : el;
  16107. return angular.element(queryResult);
  16108. }
  16109. /**
  16110. * Gets the computed values for an element's translateX and translateY in px.
  16111. * @param {!angular.JQLite|!Element} el
  16112. * @param {string} property
  16113. * @return {{x: number, y: number}}
  16114. */
  16115. function getComputedTranslations(el, property) {
  16116. // The transform being returned by `getComputedStyle` is in the format:
  16117. // `matrix(a, b, c, d, translateX, translateY)` if defined and `none`
  16118. // if the element doesn't have a transform.
  16119. var transform = getComputedStyle(el[0] || el)[property];
  16120. var openIndex = transform.indexOf('(');
  16121. var closeIndex = transform.lastIndexOf(')');
  16122. var output = { x: 0, y: 0 };
  16123. if (openIndex > -1 && closeIndex > -1) {
  16124. var parsedValues = transform
  16125. .substring(openIndex + 1, closeIndex)
  16126. .split(', ')
  16127. .slice(-2);
  16128. output.x = parseInt(parsedValues[0]);
  16129. output.y = parseInt(parsedValues[1]);
  16130. }
  16131. return output;
  16132. }
  16133. /**
  16134. * Adds units to a number value.
  16135. * @param {string|number} value
  16136. * @return {string}
  16137. */
  16138. function addUnits(value) {
  16139. return angular.isNumber(value) ? value + 'px' : value;
  16140. }
  16141. })();
  16142. (function(){
  16143. "use strict";
  16144. /**
  16145. * @ngdoc module
  16146. * @name material.components.progressCircular
  16147. * @description Module for a circular progressbar
  16148. */
  16149. angular.module('material.components.progressCircular', ['material.core']);
  16150. })();
  16151. (function(){
  16152. "use strict";
  16153. /**
  16154. * @ngdoc module
  16155. * @name material.components.progressLinear
  16156. * @description Linear Progress module!
  16157. */
  16158. MdProgressLinearDirective.$inject = ["$mdTheming", "$mdUtil", "$log"];
  16159. angular.module('material.components.progressLinear', [
  16160. 'material.core'
  16161. ])
  16162. .directive('mdProgressLinear', MdProgressLinearDirective);
  16163. /**
  16164. * @ngdoc directive
  16165. * @name mdProgressLinear
  16166. * @module material.components.progressLinear
  16167. * @restrict E
  16168. *
  16169. * @description
  16170. * The linear progress directive is used to make loading content
  16171. * in your app as delightful and painless as possible by minimizing
  16172. * the amount of visual change a user sees before they can view
  16173. * and interact with content.
  16174. *
  16175. * Each operation should only be represented by one activity indicator
  16176. * For example: one refresh operation should not display both a
  16177. * refresh bar and an activity circle.
  16178. *
  16179. * For operations where the percentage of the operation completed
  16180. * can be determined, use a determinate indicator. They give users
  16181. * a quick sense of how long an operation will take.
  16182. *
  16183. * For operations where the user is asked to wait a moment while
  16184. * something finishes up, and it’s not necessary to expose what's
  16185. * happening behind the scenes and how long it will take, use an
  16186. * indeterminate indicator.
  16187. *
  16188. * @param {string} md-mode Select from one of four modes: determinate, indeterminate, buffer or query.
  16189. *
  16190. * Note: if the `md-mode` value is set as undefined or specified as 1 of the four (4) valid modes, then `indeterminate`
  16191. * will be auto-applied as the mode.
  16192. *
  16193. * Note: if not configured, the `md-mode="indeterminate"` will be auto injected as an attribute. If `value=""` is also specified, however,
  16194. * then `md-mode="determinate"` would be auto-injected instead.
  16195. * @param {number=} value In determinate and buffer modes, this number represents the percentage of the primary progress bar. Default: 0
  16196. * @param {number=} md-buffer-value In the buffer mode, this number represents the percentage of the secondary progress bar. Default: 0
  16197. * @param {boolean=} ng-disabled Determines whether to disable the progress element.
  16198. *
  16199. * @usage
  16200. * <hljs lang="html">
  16201. * <md-progress-linear md-mode="determinate" value="..."></md-progress-linear>
  16202. *
  16203. * <md-progress-linear md-mode="determinate" ng-value="..."></md-progress-linear>
  16204. *
  16205. * <md-progress-linear md-mode="indeterminate"></md-progress-linear>
  16206. *
  16207. * <md-progress-linear md-mode="buffer" value="..." md-buffer-value="..."></md-progress-linear>
  16208. *
  16209. * <md-progress-linear md-mode="query"></md-progress-linear>
  16210. * </hljs>
  16211. */
  16212. function MdProgressLinearDirective($mdTheming, $mdUtil, $log) {
  16213. var MODE_DETERMINATE = "determinate";
  16214. var MODE_INDETERMINATE = "indeterminate";
  16215. var MODE_BUFFER = "buffer";
  16216. var MODE_QUERY = "query";
  16217. var DISABLED_CLASS = "_md-progress-linear-disabled";
  16218. return {
  16219. restrict: 'E',
  16220. template: '<div class="md-container">' +
  16221. '<div class="md-dashed"></div>' +
  16222. '<div class="md-bar md-bar1"></div>' +
  16223. '<div class="md-bar md-bar2"></div>' +
  16224. '</div>',
  16225. compile: compile
  16226. };
  16227. function compile(tElement, tAttrs, transclude) {
  16228. tElement.attr('aria-valuemin', 0);
  16229. tElement.attr('aria-valuemax', 100);
  16230. tElement.attr('role', 'progressbar');
  16231. return postLink;
  16232. }
  16233. function postLink(scope, element, attr) {
  16234. $mdTheming(element);
  16235. var lastMode;
  16236. var isDisabled = attr.hasOwnProperty('disabled');
  16237. var toVendorCSS = $mdUtil.dom.animator.toCss;
  16238. var bar1 = angular.element(element[0].querySelector('.md-bar1'));
  16239. var bar2 = angular.element(element[0].querySelector('.md-bar2'));
  16240. var container = angular.element(element[0].querySelector('.md-container'));
  16241. element
  16242. .attr('md-mode', mode())
  16243. .toggleClass(DISABLED_CLASS, isDisabled);
  16244. validateMode();
  16245. watchAttributes();
  16246. /**
  16247. * Watch the value, md-buffer-value, and md-mode attributes
  16248. */
  16249. function watchAttributes() {
  16250. attr.$observe('value', function(value) {
  16251. var percentValue = clamp(value);
  16252. element.attr('aria-valuenow', percentValue);
  16253. if (mode() != MODE_QUERY) animateIndicator(bar2, percentValue);
  16254. });
  16255. attr.$observe('mdBufferValue', function(value) {
  16256. animateIndicator(bar1, clamp(value));
  16257. });
  16258. attr.$observe('disabled', function(value) {
  16259. if (value === true || value === false) {
  16260. isDisabled = !!value;
  16261. } else {
  16262. isDisabled = angular.isDefined(value);
  16263. }
  16264. element.toggleClass(DISABLED_CLASS, isDisabled);
  16265. container.toggleClass(lastMode, !isDisabled);
  16266. });
  16267. attr.$observe('mdMode', function(mode) {
  16268. if (lastMode) container.removeClass( lastMode );
  16269. switch( mode ) {
  16270. case MODE_QUERY:
  16271. case MODE_BUFFER:
  16272. case MODE_DETERMINATE:
  16273. case MODE_INDETERMINATE:
  16274. container.addClass( lastMode = "md-mode-" + mode );
  16275. break;
  16276. default:
  16277. container.addClass( lastMode = "md-mode-" + MODE_INDETERMINATE );
  16278. break;
  16279. }
  16280. });
  16281. }
  16282. /**
  16283. * Auto-defaults the mode to either `determinate` or `indeterminate` mode; if not specified
  16284. */
  16285. function validateMode() {
  16286. if ( angular.isUndefined(attr.mdMode) ) {
  16287. var hasValue = angular.isDefined(attr.value);
  16288. var mode = hasValue ? MODE_DETERMINATE : MODE_INDETERMINATE;
  16289. var info = "Auto-adding the missing md-mode='{0}' to the ProgressLinear element";
  16290. //$log.debug( $mdUtil.supplant(info, [mode]) );
  16291. element.attr("md-mode", mode);
  16292. attr.mdMode = mode;
  16293. }
  16294. }
  16295. /**
  16296. * Is the md-mode a valid option?
  16297. */
  16298. function mode() {
  16299. var value = (attr.mdMode || "").trim();
  16300. if ( value ) {
  16301. switch(value) {
  16302. case MODE_DETERMINATE:
  16303. case MODE_INDETERMINATE:
  16304. case MODE_BUFFER:
  16305. case MODE_QUERY:
  16306. break;
  16307. default:
  16308. value = MODE_INDETERMINATE;
  16309. break;
  16310. }
  16311. }
  16312. return value;
  16313. }
  16314. /**
  16315. * Manually set CSS to animate the Determinate indicator based on the specified
  16316. * percentage value (0-100).
  16317. */
  16318. function animateIndicator(target, value) {
  16319. if ( isDisabled || !mode() ) return;
  16320. var to = $mdUtil.supplant("translateX({0}%) scale({1},1)", [ (value-100)/2, value/100 ]);
  16321. var styles = toVendorCSS({ transform : to });
  16322. angular.element(target).css( styles );
  16323. }
  16324. }
  16325. /**
  16326. * Clamps the value to be between 0 and 100.
  16327. * @param {number} value The value to clamp.
  16328. * @returns {number}
  16329. */
  16330. function clamp(value) {
  16331. return Math.max(0, Math.min(value || 0, 100));
  16332. }
  16333. }
  16334. })();
  16335. (function(){
  16336. "use strict";
  16337. /**
  16338. * @ngdoc module
  16339. * @name material.components.radioButton
  16340. * @description radioButton module!
  16341. */
  16342. mdRadioGroupDirective.$inject = ["$mdUtil", "$mdConstant", "$mdTheming", "$timeout"];
  16343. mdRadioButtonDirective.$inject = ["$mdAria", "$mdUtil", "$mdTheming"];
  16344. angular.module('material.components.radioButton', [
  16345. 'material.core'
  16346. ])
  16347. .directive('mdRadioGroup', mdRadioGroupDirective)
  16348. .directive('mdRadioButton', mdRadioButtonDirective);
  16349. /**
  16350. * @ngdoc directive
  16351. * @module material.components.radioButton
  16352. * @name mdRadioGroup
  16353. *
  16354. * @restrict E
  16355. *
  16356. * @description
  16357. * The `<md-radio-group>` directive identifies a grouping
  16358. * container for the 1..n grouped radio buttons; specified using nested
  16359. * `<md-radio-button>` elements.
  16360. *
  16361. * The radio button uses the accent color by default. The primary color palette may be used with
  16362. * the `md-primary` class.
  16363. *
  16364. * Note: `<md-radio-group>` and `<md-radio-button>` handle `tabindex` differently
  16365. * than the native `<input type="radio">` controls. Whereas the native controls
  16366. * force the user to tab through all the radio buttons, `<md-radio-group>`
  16367. * is focusable and by default the `<md-radio-button>`s are not.
  16368. *
  16369. * @param {string} ng-model Assignable angular expression to data-bind to.
  16370. * @param {string=} ng-change AngularJS expression to be executed when input changes due to user
  16371. * interaction.
  16372. * @param {boolean=} md-no-ink If present, disables ink ripple effects.
  16373. *
  16374. * @usage
  16375. * <hljs lang="html">
  16376. * <md-radio-group ng-model="selected">
  16377. * <md-radio-button ng-repeat="item in items"
  16378. * ng-value="item.value" aria-label="{{item.label}}">
  16379. * {{ item.label }}
  16380. * </md-radio-button>
  16381. * </md-radio-group>
  16382. * </hljs>
  16383. */
  16384. function mdRadioGroupDirective($mdUtil, $mdConstant, $mdTheming, $timeout) {
  16385. RadioGroupController.prototype = createRadioGroupControllerProto();
  16386. return {
  16387. restrict: 'E',
  16388. controller: ['$element', RadioGroupController],
  16389. require: ['mdRadioGroup', '?ngModel'],
  16390. link: { pre: linkRadioGroup }
  16391. };
  16392. function linkRadioGroup(scope, element, attr, ctrls) {
  16393. element.addClass('_md'); // private md component indicator for styling
  16394. $mdTheming(element);
  16395. var rgCtrl = ctrls[0];
  16396. var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel();
  16397. rgCtrl.init(ngModelCtrl);
  16398. scope.mouseActive = false;
  16399. element
  16400. .attr({
  16401. 'role': 'radiogroup',
  16402. 'tabIndex': element.attr('tabindex') || '0'
  16403. })
  16404. .on('keydown', keydownListener)
  16405. .on('mousedown', function(event) {
  16406. scope.mouseActive = true;
  16407. $timeout(function() {
  16408. scope.mouseActive = false;
  16409. }, 100);
  16410. })
  16411. .on('focus', function() {
  16412. if(scope.mouseActive === false) {
  16413. rgCtrl.$element.addClass('md-focused');
  16414. }
  16415. })
  16416. .on('blur', function() {
  16417. rgCtrl.$element.removeClass('md-focused');
  16418. });
  16419. /**
  16420. *
  16421. */
  16422. function setFocus() {
  16423. if (!element.hasClass('md-focused')) { element.addClass('md-focused'); }
  16424. }
  16425. /**
  16426. *
  16427. */
  16428. function keydownListener(ev) {
  16429. var keyCode = ev.which || ev.keyCode;
  16430. // Only listen to events that we originated ourselves
  16431. // so that we don't trigger on things like arrow keys in
  16432. // inputs.
  16433. if (keyCode != $mdConstant.KEY_CODE.ENTER &&
  16434. ev.currentTarget != ev.target) {
  16435. return;
  16436. }
  16437. switch (keyCode) {
  16438. case $mdConstant.KEY_CODE.LEFT_ARROW:
  16439. case $mdConstant.KEY_CODE.UP_ARROW:
  16440. ev.preventDefault();
  16441. rgCtrl.selectPrevious();
  16442. setFocus();
  16443. break;
  16444. case $mdConstant.KEY_CODE.RIGHT_ARROW:
  16445. case $mdConstant.KEY_CODE.DOWN_ARROW:
  16446. ev.preventDefault();
  16447. rgCtrl.selectNext();
  16448. setFocus();
  16449. break;
  16450. case $mdConstant.KEY_CODE.ENTER:
  16451. var form = angular.element($mdUtil.getClosest(element[0], 'form'));
  16452. if (form.length > 0) {
  16453. form.triggerHandler('submit');
  16454. }
  16455. break;
  16456. }
  16457. }
  16458. }
  16459. function RadioGroupController($element) {
  16460. this._radioButtonRenderFns = [];
  16461. this.$element = $element;
  16462. }
  16463. function createRadioGroupControllerProto() {
  16464. return {
  16465. init: function(ngModelCtrl) {
  16466. this._ngModelCtrl = ngModelCtrl;
  16467. this._ngModelCtrl.$render = angular.bind(this, this.render);
  16468. },
  16469. add: function(rbRender) {
  16470. this._radioButtonRenderFns.push(rbRender);
  16471. },
  16472. remove: function(rbRender) {
  16473. var index = this._radioButtonRenderFns.indexOf(rbRender);
  16474. if (index !== -1) {
  16475. this._radioButtonRenderFns.splice(index, 1);
  16476. }
  16477. },
  16478. render: function() {
  16479. this._radioButtonRenderFns.forEach(function(rbRender) {
  16480. rbRender();
  16481. });
  16482. },
  16483. setViewValue: function(value, eventType) {
  16484. this._ngModelCtrl.$setViewValue(value, eventType);
  16485. // update the other radio buttons as well
  16486. this.render();
  16487. },
  16488. getViewValue: function() {
  16489. return this._ngModelCtrl.$viewValue;
  16490. },
  16491. selectNext: function() {
  16492. return changeSelectedButton(this.$element, 1);
  16493. },
  16494. selectPrevious: function() {
  16495. return changeSelectedButton(this.$element, -1);
  16496. },
  16497. setActiveDescendant: function (radioId) {
  16498. this.$element.attr('aria-activedescendant', radioId);
  16499. },
  16500. isDisabled: function() {
  16501. return this.$element[0].hasAttribute('disabled');
  16502. }
  16503. };
  16504. }
  16505. /**
  16506. * Change the radio group's selected button by a given increment.
  16507. * If no button is selected, select the first button.
  16508. */
  16509. function changeSelectedButton(parent, increment) {
  16510. // Coerce all child radio buttons into an array, then wrap then in an iterator
  16511. var buttons = $mdUtil.iterator(parent[0].querySelectorAll('md-radio-button'), true);
  16512. if (buttons.count()) {
  16513. var validate = function (button) {
  16514. // If disabled, then NOT valid
  16515. return !angular.element(button).attr("disabled");
  16516. };
  16517. var selected = parent[0].querySelector('md-radio-button.md-checked');
  16518. var target = buttons[increment < 0 ? 'previous' : 'next'](selected, validate) || buttons.first();
  16519. // Activate radioButton's click listener (triggerHandler won't create a real click event)
  16520. angular.element(target).triggerHandler('click');
  16521. }
  16522. }
  16523. }
  16524. /**
  16525. * @ngdoc directive
  16526. * @module material.components.radioButton
  16527. * @name mdRadioButton
  16528. *
  16529. * @restrict E
  16530. *
  16531. * @description
  16532. * The `<md-radio-button>`directive is the child directive required to be used within `<md-radio-group>` elements.
  16533. *
  16534. * While similar to the `<input type="radio" ng-model="" value="">` directive,
  16535. * the `<md-radio-button>` directive provides ink effects, ARIA support, and
  16536. * supports use within named radio groups.
  16537. *
  16538. * One of `value` or `ng-value` must be set so that the `md-radio-group`'s model is set properly when the
  16539. * `md-radio-button` is selected.
  16540. *
  16541. * @param {string} value The value to which the model should be set when selected.
  16542. * @param {string} ng-value AngularJS expression which sets the value to which the model should
  16543. * be set when selected.
  16544. * @param {string=} name Property name of the form under which the control is published.
  16545. * @param {string=} aria-label Adds label to radio button for accessibility.
  16546. * Defaults to radio button's text. If no text content is available, a warning will be logged.
  16547. *
  16548. * @usage
  16549. * <hljs lang="html">
  16550. *
  16551. * <md-radio-button value="1" aria-label="Label 1">
  16552. * Label 1
  16553. * </md-radio-button>
  16554. *
  16555. * <md-radio-button ng-value="specialValue" aria-label="Green">
  16556. * Green
  16557. * </md-radio-button>
  16558. *
  16559. * </hljs>
  16560. *
  16561. */
  16562. function mdRadioButtonDirective($mdAria, $mdUtil, $mdTheming) {
  16563. var CHECKED_CSS = 'md-checked';
  16564. return {
  16565. restrict: 'E',
  16566. require: '^mdRadioGroup',
  16567. transclude: true,
  16568. template: '<div class="md-container" md-ink-ripple md-ink-ripple-checkbox>' +
  16569. '<div class="md-off"></div>' +
  16570. '<div class="md-on"></div>' +
  16571. '</div>' +
  16572. '<div ng-transclude class="md-label"></div>',
  16573. link: link
  16574. };
  16575. function link(scope, element, attr, rgCtrl) {
  16576. var lastChecked;
  16577. $mdTheming(element);
  16578. configureAria(element, scope);
  16579. // ngAria overwrites the aria-checked inside a $watch for ngValue.
  16580. // We should defer the initialization until all the watches have fired.
  16581. // This can also be fixed by removing the `lastChecked` check, but that'll
  16582. // cause more DOM manipulation on each digest.
  16583. if (attr.ngValue) {
  16584. $mdUtil.nextTick(initialize, false);
  16585. } else {
  16586. initialize();
  16587. }
  16588. /**
  16589. * Initializes the component.
  16590. */
  16591. function initialize() {
  16592. if (!rgCtrl) {
  16593. throw 'RadioButton: No RadioGroupController could be found.';
  16594. }
  16595. rgCtrl.add(render);
  16596. attr.$observe('value', render);
  16597. element
  16598. .on('click', listener)
  16599. .on('$destroy', function() {
  16600. rgCtrl.remove(render);
  16601. });
  16602. }
  16603. /**
  16604. * On click functionality.
  16605. */
  16606. function listener(ev) {
  16607. if (element[0].hasAttribute('disabled') || rgCtrl.isDisabled()) return;
  16608. scope.$apply(function() {
  16609. rgCtrl.setViewValue(attr.value, ev && ev.type);
  16610. });
  16611. }
  16612. /**
  16613. * Add or remove the `.md-checked` class from the RadioButton (and conditionally its parent).
  16614. * Update the `aria-activedescendant` attribute.
  16615. */
  16616. function render() {
  16617. var checked = rgCtrl.getViewValue() == attr.value;
  16618. if (checked === lastChecked) return;
  16619. if (element[0].parentNode.nodeName.toLowerCase() !== 'md-radio-group') {
  16620. // If the radioButton is inside a div, then add class so highlighting will work
  16621. element.parent().toggleClass(CHECKED_CSS, checked);
  16622. }
  16623. if (checked) {
  16624. rgCtrl.setActiveDescendant(element.attr('id'));
  16625. }
  16626. lastChecked = checked;
  16627. element
  16628. .attr('aria-checked', checked)
  16629. .toggleClass(CHECKED_CSS, checked);
  16630. }
  16631. /**
  16632. * Inject ARIA-specific attributes appropriate for each radio button
  16633. */
  16634. function configureAria(element, scope){
  16635. element.attr({
  16636. id: attr.id || 'radio_' + $mdUtil.nextUid(),
  16637. role: 'radio',
  16638. 'aria-checked': 'false'
  16639. });
  16640. $mdAria.expectWithText(element, 'aria-label');
  16641. }
  16642. }
  16643. }
  16644. })();
  16645. (function(){
  16646. "use strict";
  16647. /**
  16648. * @ngdoc module
  16649. * @name material.components.select
  16650. */
  16651. /***************************************************
  16652. ### TODO - POST RC1 ###
  16653. - [ ] Abstract placement logic in $mdSelect service to $mdMenu service
  16654. ***************************************************/
  16655. SelectDirective.$inject = ["$mdSelect", "$mdUtil", "$mdConstant", "$mdTheming", "$mdAria", "$parse", "$sce", "$injector"];
  16656. SelectMenuDirective.$inject = ["$parse", "$mdUtil", "$mdConstant", "$mdTheming"];
  16657. OptionDirective.$inject = ["$mdButtonInkRipple", "$mdUtil", "$mdTheming"];
  16658. SelectProvider.$inject = ["$$interimElementProvider"];
  16659. var SELECT_EDGE_MARGIN = 8;
  16660. var selectNextId = 0;
  16661. var CHECKBOX_SELECTION_INDICATOR =
  16662. angular.element('<div class="md-container"><div class="md-icon"></div></div>');
  16663. angular.module('material.components.select', [
  16664. 'material.core',
  16665. 'material.components.backdrop'
  16666. ])
  16667. .directive('mdSelect', SelectDirective)
  16668. .directive('mdSelectMenu', SelectMenuDirective)
  16669. .directive('mdOption', OptionDirective)
  16670. .directive('mdOptgroup', OptgroupDirective)
  16671. .directive('mdSelectHeader', SelectHeaderDirective)
  16672. .provider('$mdSelect', SelectProvider);
  16673. /**
  16674. * @ngdoc directive
  16675. * @name mdSelect
  16676. * @restrict E
  16677. * @module material.components.select
  16678. *
  16679. * @description Displays a select box, bound to an ng-model.
  16680. *
  16681. * When the select is required and uses a floating label, then the label will automatically contain
  16682. * an asterisk (`*`). This behavior can be disabled by using the `md-no-asterisk` attribute.
  16683. *
  16684. * By default, the select will display with an underline to match other form elements. This can be
  16685. * disabled by applying the `md-no-underline` CSS class.
  16686. *
  16687. * ### Option Params
  16688. *
  16689. * When applied, `md-option-empty` will mark the option as "empty" allowing the option to clear the
  16690. * select and put it back in it's default state. You may supply this attribute on any option you
  16691. * wish, however, it is automatically applied to an option whose `value` or `ng-value` are not
  16692. * defined.
  16693. *
  16694. * **Automatically Applied**
  16695. *
  16696. * - `<md-option>`
  16697. * - `<md-option value>`
  16698. * - `<md-option value="">`
  16699. * - `<md-option ng-value>`
  16700. * - `<md-option ng-value="">`
  16701. *
  16702. * **NOT Automatically Applied**
  16703. *
  16704. * - `<md-option ng-value="1">`
  16705. * - `<md-option ng-value="''">`
  16706. * - `<md-option ng-value="undefined">`
  16707. * - `<md-option value="undefined">` (this evaluates to the string `"undefined"`)
  16708. * - <code ng-non-bindable>&lt;md-option ng-value="{{someValueThatMightBeUndefined}}"&gt;</code>
  16709. *
  16710. * **Note:** A value of `undefined` ***is considered a valid value*** (and does not auto-apply this
  16711. * attribute) since you may wish this to be your "Not Available" or "None" option.
  16712. *
  16713. * **Note:** Using the `value` attribute (as opposed to `ng-value`) always evaluates to a string, so
  16714. * `value="null"` will require the test `ng-if="myValue != 'null'"` rather than `ng-if="!myValue"`.
  16715. *
  16716. * @param {expression} ng-model Assignable angular expression to data-bind to.
  16717. * @param {expression=} ng-change Expression to be executed when the model value changes.
  16718. * @param {boolean=} multiple When set to true, allows for more than one option to be selected. The model is an array with the selected choices.
  16719. * @param {expression=} md-on-close Expression to be evaluated when the select is closed.
  16720. * @param {expression=} md-on-open Expression to be evaluated when opening the select.
  16721. * Will hide the select options and show a spinner until the evaluated promise resolves.
  16722. * @param {expression=} md-selected-text Expression to be evaluated that will return a string
  16723. * to be displayed as a placeholder in the select input box when it is closed. The value
  16724. * will be treated as *text* (not html).
  16725. * @param {expression=} md-selected-html Expression to be evaluated that will return a string
  16726. * to be displayed as a placeholder in the select input box when it is closed. The value
  16727. * will be treated as *html*. The value must either be explicitly marked as trustedHtml or
  16728. * the ngSanitize module must be loaded.
  16729. * @param {string=} placeholder Placeholder hint text.
  16730. * @param md-no-asterisk {boolean=} When set to true, an asterisk will not be appended to the
  16731. * floating label. **Note:** This attribute is only evaluated once; it is not watched.
  16732. * @param {string=} aria-label Optional label for accessibility. Only necessary if no placeholder or
  16733. * explicit label is present.
  16734. * @param {string=} md-container-class Class list to get applied to the `.md-select-menu-container`
  16735. * element (for custom styling).
  16736. *
  16737. * @usage
  16738. * With a placeholder (label and aria-label are added dynamically)
  16739. * <hljs lang="html">
  16740. * <md-input-container>
  16741. * <md-select
  16742. * ng-model="someModel"
  16743. * placeholder="Select a state">
  16744. * <md-option ng-value="opt" ng-repeat="opt in neighborhoods2">{{ opt }}</md-option>
  16745. * </md-select>
  16746. * </md-input-container>
  16747. * </hljs>
  16748. *
  16749. * With an explicit label
  16750. * <hljs lang="html">
  16751. * <md-input-container>
  16752. * <label>State</label>
  16753. * <md-select
  16754. * ng-model="someModel">
  16755. * <md-option ng-value="opt" ng-repeat="opt in neighborhoods2">{{ opt }}</md-option>
  16756. * </md-select>
  16757. * </md-input-container>
  16758. * </hljs>
  16759. *
  16760. * With a select-header
  16761. *
  16762. * When a developer needs to put more than just a text label in the
  16763. * md-select-menu, they should use the md-select-header.
  16764. * The user can put custom HTML inside of the header and style it to their liking.
  16765. * One common use case of this would be a sticky search bar.
  16766. *
  16767. * When using the md-select-header the labels that would previously be added to the
  16768. * OptGroupDirective are ignored.
  16769. *
  16770. * <hljs lang="html">
  16771. * <md-input-container>
  16772. * <md-select ng-model="someModel">
  16773. * <md-select-header>
  16774. * <span> Neighborhoods - </span>
  16775. * </md-select-header>
  16776. * <md-option ng-value="opt" ng-repeat="opt in neighborhoods2">{{ opt }}</md-option>
  16777. * </md-select>
  16778. * </md-input-container>
  16779. * </hljs>
  16780. *
  16781. * ## Selects and object equality
  16782. * When using a `md-select` to pick from a list of objects, it is important to realize how javascript handles
  16783. * equality. Consider the following example:
  16784. * <hljs lang="js">
  16785. * angular.controller('MyCtrl', function($scope) {
  16786. * $scope.users = [
  16787. * { id: 1, name: 'Bob' },
  16788. * { id: 2, name: 'Alice' },
  16789. * { id: 3, name: 'Steve' }
  16790. * ];
  16791. * $scope.selectedUser = { id: 1, name: 'Bob' };
  16792. * });
  16793. * </hljs>
  16794. * <hljs lang="html">
  16795. * <div ng-controller="MyCtrl">
  16796. * <md-select ng-model="selectedUser">
  16797. * <md-option ng-value="user" ng-repeat="user in users">{{ user.name }}</md-option>
  16798. * </md-select>
  16799. * </div>
  16800. * </hljs>
  16801. *
  16802. * At first one might expect that the select should be populated with "Bob" as the selected user. However,
  16803. * this is not true. To determine whether something is selected,
  16804. * `ngModelController` is looking at whether `$scope.selectedUser == (any user in $scope.users);`;
  16805. *
  16806. * Javascript's `==` operator does not check for deep equality (ie. that all properties
  16807. * on the object are the same), but instead whether the objects are *the same object in memory*.
  16808. * In this case, we have two instances of identical objects, but they exist in memory as unique
  16809. * entities. Because of this, the select will have no value populated for a selected user.
  16810. *
  16811. * To get around this, `ngModelController` provides a `track by` option that allows us to specify a different
  16812. * expression which will be used for the equality operator. As such, we can update our `html` to
  16813. * make use of this by specifying the `ng-model-options="{trackBy: '$value.id'}"` on the `md-select`
  16814. * element. This converts our equality expression to be
  16815. * `$scope.selectedUser.id == (any id in $scope.users.map(function(u) { return u.id; }));`
  16816. * which results in Bob being selected as desired.
  16817. *
  16818. * Working HTML:
  16819. * <hljs lang="html">
  16820. * <div ng-controller="MyCtrl">
  16821. * <md-select ng-model="selectedUser" ng-model-options="{trackBy: '$value.id'}">
  16822. * <md-option ng-value="user" ng-repeat="user in users">{{ user.name }}</md-option>
  16823. * </md-select>
  16824. * </div>
  16825. * </hljs>
  16826. */
  16827. function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $parse, $sce,
  16828. $injector) {
  16829. var keyCodes = $mdConstant.KEY_CODE;
  16830. var NAVIGATION_KEYS = [keyCodes.SPACE, keyCodes.ENTER, keyCodes.UP_ARROW, keyCodes.DOWN_ARROW];
  16831. return {
  16832. restrict: 'E',
  16833. require: ['^?mdInputContainer', 'mdSelect', 'ngModel', '?^form'],
  16834. compile: compile,
  16835. controller: function() {
  16836. } // empty placeholder controller to be initialized in link
  16837. };
  16838. function compile(element, attr) {
  16839. // add the select value that will hold our placeholder or selected option value
  16840. var valueEl = angular.element('<md-select-value><span></span></md-select-value>');
  16841. valueEl.append('<span class="md-select-icon" aria-hidden="true"></span>');
  16842. valueEl.addClass('md-select-value');
  16843. if (!valueEl[0].hasAttribute('id')) {
  16844. valueEl.attr('id', 'select_value_label_' + $mdUtil.nextUid());
  16845. }
  16846. // There's got to be an md-content inside. If there's not one, let's add it.
  16847. var mdContentEl = element.find('md-content');
  16848. if (!mdContentEl.length) {
  16849. element.append(angular.element('<md-content>').append(element.contents()));
  16850. }
  16851. mdContentEl.attr('role', 'presentation');
  16852. // Add progress spinner for md-options-loading
  16853. if (attr.mdOnOpen) {
  16854. // Show progress indicator while loading async
  16855. // Use ng-hide for `display:none` so the indicator does not interfere with the options list
  16856. element
  16857. .find('md-content')
  16858. .prepend(angular.element(
  16859. '<div>' +
  16860. ' <md-progress-circular md-mode="indeterminate" ng-if="$$loadingAsyncDone === false" md-diameter="25px"></md-progress-circular>' +
  16861. '</div>'
  16862. ));
  16863. // Hide list [of item options] while loading async
  16864. element
  16865. .find('md-option')
  16866. .attr('ng-show', '$$loadingAsyncDone');
  16867. }
  16868. if (attr.name) {
  16869. var autofillClone = angular.element('<select class="md-visually-hidden"></select>');
  16870. autofillClone.attr({
  16871. 'name': attr.name,
  16872. 'aria-hidden': 'true',
  16873. 'tabindex': '-1'
  16874. });
  16875. var opts = element.find('md-option');
  16876. angular.forEach(opts, function(el) {
  16877. var newEl = angular.element('<option>' + el.innerHTML + '</option>');
  16878. if (el.hasAttribute('ng-value')) newEl.attr('ng-value', el.getAttribute('ng-value'));
  16879. else if (el.hasAttribute('value')) newEl.attr('value', el.getAttribute('value'));
  16880. autofillClone.append(newEl);
  16881. });
  16882. // Adds an extra option that will hold the selected value for the
  16883. // cases where the select is a part of a non-angular form. This can be done with a ng-model,
  16884. // however if the `md-option` is being `ng-repeat`-ed, AngularJS seems to insert a similar
  16885. // `option` node, but with a value of `? string: <value> ?` which would then get submitted.
  16886. // This also goes around having to prepend a dot to the name attribute.
  16887. autofillClone.append(
  16888. '<option ng-value="' + attr.ngModel + '" selected></option>'
  16889. );
  16890. element.parent().append(autofillClone);
  16891. }
  16892. var isMultiple = $mdUtil.parseAttributeBoolean(attr.multiple);
  16893. // Use everything that's left inside element.contents() as the contents of the menu
  16894. var multipleContent = isMultiple ? 'multiple' : '';
  16895. var selectTemplate = '' +
  16896. '<div class="md-select-menu-container" aria-hidden="true" role="presentation">' +
  16897. '<md-select-menu role="presentation" {0}>{1}</md-select-menu>' +
  16898. '</div>';
  16899. selectTemplate = $mdUtil.supplant(selectTemplate, [multipleContent, element.html()]);
  16900. element.empty().append(valueEl);
  16901. element.append(selectTemplate);
  16902. if(!attr.tabindex){
  16903. attr.$set('tabindex', 0);
  16904. }
  16905. return function postLink(scope, element, attr, ctrls) {
  16906. var untouched = true;
  16907. var isDisabled, ariaLabelBase;
  16908. var containerCtrl = ctrls[0];
  16909. var mdSelectCtrl = ctrls[1];
  16910. var ngModelCtrl = ctrls[2];
  16911. var formCtrl = ctrls[3];
  16912. // grab a reference to the select menu value label
  16913. var valueEl = element.find('md-select-value');
  16914. var isReadonly = angular.isDefined(attr.readonly);
  16915. var disableAsterisk = $mdUtil.parseAttributeBoolean(attr.mdNoAsterisk);
  16916. if (disableAsterisk) {
  16917. element.addClass('md-no-asterisk');
  16918. }
  16919. if (containerCtrl) {
  16920. var isErrorGetter = containerCtrl.isErrorGetter || function() {
  16921. return ngModelCtrl.$invalid && (ngModelCtrl.$touched || (formCtrl && formCtrl.$submitted));
  16922. };
  16923. if (containerCtrl.input) {
  16924. // We ignore inputs that are in the md-select-header (one
  16925. // case where this might be useful would be adding as searchbox)
  16926. if (element.find('md-select-header').find('input')[0] !== containerCtrl.input[0]) {
  16927. throw new Error("<md-input-container> can only have *one* child <input>, <textarea> or <select> element!");
  16928. }
  16929. }
  16930. containerCtrl.input = element;
  16931. if (!containerCtrl.label) {
  16932. $mdAria.expect(element, 'aria-label', element.attr('placeholder'));
  16933. }
  16934. scope.$watch(isErrorGetter, containerCtrl.setInvalid);
  16935. }
  16936. var selectContainer, selectScope, selectMenuCtrl;
  16937. findSelectContainer();
  16938. $mdTheming(element);
  16939. if (formCtrl && angular.isDefined(attr.multiple)) {
  16940. $mdUtil.nextTick(function() {
  16941. var hasModelValue = ngModelCtrl.$modelValue || ngModelCtrl.$viewValue;
  16942. if (hasModelValue) {
  16943. formCtrl.$setPristine();
  16944. }
  16945. });
  16946. }
  16947. var originalRender = ngModelCtrl.$render;
  16948. ngModelCtrl.$render = function() {
  16949. originalRender();
  16950. syncLabelText();
  16951. syncAriaLabel();
  16952. inputCheckValue();
  16953. };
  16954. attr.$observe('placeholder', ngModelCtrl.$render);
  16955. if (containerCtrl && containerCtrl.label) {
  16956. attr.$observe('required', function (value) {
  16957. // Toggle the md-required class on the input containers label, because the input container is automatically
  16958. // applying the asterisk indicator on the label.
  16959. containerCtrl.label.toggleClass('md-required', value && !disableAsterisk);
  16960. });
  16961. }
  16962. mdSelectCtrl.setLabelText = function(text) {
  16963. mdSelectCtrl.setIsPlaceholder(!text);
  16964. // Whether the select label has been given via user content rather than the internal
  16965. // template of <md-option>
  16966. var isSelectLabelFromUser = false;
  16967. if (attr.mdSelectedText && attr.mdSelectedHtml) {
  16968. throw Error('md-select cannot have both `md-selected-text` and `md-selected-html`');
  16969. }
  16970. if (attr.mdSelectedText || attr.mdSelectedHtml) {
  16971. text = $parse(attr.mdSelectedText || attr.mdSelectedHtml)(scope);
  16972. isSelectLabelFromUser = true;
  16973. } else if (!text) {
  16974. // Use placeholder attribute, otherwise fallback to the md-input-container label
  16975. var tmpPlaceholder = attr.placeholder ||
  16976. (containerCtrl && containerCtrl.label ? containerCtrl.label.text() : '');
  16977. text = tmpPlaceholder || '';
  16978. isSelectLabelFromUser = true;
  16979. }
  16980. var target = valueEl.children().eq(0);
  16981. if (attr.mdSelectedHtml) {
  16982. // Using getTrustedHtml will run the content through $sanitize if it is not already
  16983. // explicitly trusted. If the ngSanitize module is not loaded, this will
  16984. // *correctly* throw an sce error.
  16985. target.html($sce.getTrustedHtml(text));
  16986. } else if (isSelectLabelFromUser) {
  16987. target.text(text);
  16988. } else {
  16989. // If we've reached this point, the text is not user-provided.
  16990. target.html(text);
  16991. }
  16992. };
  16993. mdSelectCtrl.setIsPlaceholder = function(isPlaceholder) {
  16994. if (isPlaceholder) {
  16995. valueEl.addClass('md-select-placeholder');
  16996. if (containerCtrl && containerCtrl.label) {
  16997. containerCtrl.label.addClass('md-placeholder');
  16998. }
  16999. } else {
  17000. valueEl.removeClass('md-select-placeholder');
  17001. if (containerCtrl && containerCtrl.label) {
  17002. containerCtrl.label.removeClass('md-placeholder');
  17003. }
  17004. }
  17005. };
  17006. if (!isReadonly) {
  17007. element
  17008. .on('focus', function(ev) {
  17009. // Always focus the container (if we have one) so floating labels and other styles are
  17010. // applied properly
  17011. containerCtrl && containerCtrl.setFocused(true);
  17012. });
  17013. // Attach before ngModel's blur listener to stop propagation of blur event
  17014. // to prevent from setting $touched.
  17015. element.on('blur', function(event) {
  17016. if (untouched) {
  17017. untouched = false;
  17018. if (selectScope._mdSelectIsOpen) {
  17019. event.stopImmediatePropagation();
  17020. }
  17021. }
  17022. if (selectScope._mdSelectIsOpen) return;
  17023. containerCtrl && containerCtrl.setFocused(false);
  17024. inputCheckValue();
  17025. });
  17026. }
  17027. mdSelectCtrl.triggerClose = function() {
  17028. $parse(attr.mdOnClose)(scope);
  17029. };
  17030. scope.$$postDigest(function() {
  17031. initAriaLabel();
  17032. syncLabelText();
  17033. syncAriaLabel();
  17034. });
  17035. function initAriaLabel() {
  17036. var labelText = element.attr('aria-label') || element.attr('placeholder');
  17037. if (!labelText && containerCtrl && containerCtrl.label) {
  17038. labelText = containerCtrl.label.text();
  17039. }
  17040. ariaLabelBase = labelText;
  17041. $mdAria.expect(element, 'aria-label', labelText);
  17042. }
  17043. scope.$watch(function() {
  17044. return selectMenuCtrl.selectedLabels();
  17045. }, syncLabelText);
  17046. function syncLabelText() {
  17047. if (selectContainer) {
  17048. selectMenuCtrl = selectMenuCtrl || selectContainer.find('md-select-menu').controller('mdSelectMenu');
  17049. mdSelectCtrl.setLabelText(selectMenuCtrl.selectedLabels());
  17050. }
  17051. }
  17052. function syncAriaLabel() {
  17053. if (!ariaLabelBase) return;
  17054. var ariaLabels = selectMenuCtrl.selectedLabels({mode: 'aria'});
  17055. element.attr('aria-label', ariaLabels.length ? ariaLabelBase + ': ' + ariaLabels : ariaLabelBase);
  17056. }
  17057. var deregisterWatcher;
  17058. attr.$observe('ngMultiple', function(val) {
  17059. if (deregisterWatcher) deregisterWatcher();
  17060. var parser = $parse(val);
  17061. deregisterWatcher = scope.$watch(function() {
  17062. return parser(scope);
  17063. }, function(multiple, prevVal) {
  17064. if (multiple === undefined && prevVal === undefined) return; // assume compiler did a good job
  17065. if (multiple) {
  17066. element.attr('multiple', 'multiple');
  17067. } else {
  17068. element.removeAttr('multiple');
  17069. }
  17070. element.attr('aria-multiselectable', multiple ? 'true' : 'false');
  17071. if (selectContainer) {
  17072. selectMenuCtrl.setMultiple(multiple);
  17073. originalRender = ngModelCtrl.$render;
  17074. ngModelCtrl.$render = function() {
  17075. originalRender();
  17076. syncLabelText();
  17077. syncAriaLabel();
  17078. inputCheckValue();
  17079. };
  17080. ngModelCtrl.$render();
  17081. }
  17082. });
  17083. });
  17084. attr.$observe('disabled', function(disabled) {
  17085. if (angular.isString(disabled)) {
  17086. disabled = true;
  17087. }
  17088. // Prevent click event being registered twice
  17089. if (isDisabled !== undefined && isDisabled === disabled) {
  17090. return;
  17091. }
  17092. isDisabled = disabled;
  17093. if (disabled) {
  17094. element
  17095. .attr({'aria-disabled': 'true'})
  17096. .removeAttr('tabindex')
  17097. .off('click', openSelect)
  17098. .off('keydown', handleKeypress);
  17099. } else {
  17100. element
  17101. .attr({'tabindex': attr.tabindex, 'aria-disabled': 'false'})
  17102. .on('click', openSelect)
  17103. .on('keydown', handleKeypress);
  17104. }
  17105. });
  17106. if (!attr.hasOwnProperty('disabled') && !attr.hasOwnProperty('ngDisabled')) {
  17107. element.attr({'aria-disabled': 'false'});
  17108. element.on('click', openSelect);
  17109. element.on('keydown', handleKeypress);
  17110. }
  17111. var ariaAttrs = {
  17112. role: 'listbox',
  17113. 'aria-expanded': 'false',
  17114. 'aria-multiselectable': isMultiple && !attr.ngMultiple ? 'true' : 'false'
  17115. };
  17116. if (!element[0].hasAttribute('id')) {
  17117. ariaAttrs.id = 'select_' + $mdUtil.nextUid();
  17118. }
  17119. var containerId = 'select_container_' + $mdUtil.nextUid();
  17120. selectContainer.attr('id', containerId);
  17121. // Only add aria-owns if element ownership is NOT represented in the DOM.
  17122. if (!element.find('md-select-menu').length) {
  17123. ariaAttrs['aria-owns'] = containerId;
  17124. }
  17125. element.attr(ariaAttrs);
  17126. scope.$on('$destroy', function() {
  17127. $mdSelect
  17128. .destroy()
  17129. .finally(function() {
  17130. if (containerCtrl) {
  17131. containerCtrl.setFocused(false);
  17132. containerCtrl.setHasValue(false);
  17133. containerCtrl.input = null;
  17134. }
  17135. ngModelCtrl.$setTouched();
  17136. });
  17137. });
  17138. function inputCheckValue() {
  17139. // The select counts as having a value if one or more options are selected,
  17140. // or if the input's validity state says it has bad input (eg string in a number input)
  17141. containerCtrl && containerCtrl.setHasValue(selectMenuCtrl.selectedLabels().length > 0 || (element[0].validity || {}).badInput);
  17142. }
  17143. function findSelectContainer() {
  17144. selectContainer = angular.element(
  17145. element[0].querySelector('.md-select-menu-container')
  17146. );
  17147. selectScope = scope;
  17148. if (attr.mdContainerClass) {
  17149. var value = selectContainer[0].getAttribute('class') + ' ' + attr.mdContainerClass;
  17150. selectContainer[0].setAttribute('class', value);
  17151. }
  17152. selectMenuCtrl = selectContainer.find('md-select-menu').controller('mdSelectMenu');
  17153. selectMenuCtrl.init(ngModelCtrl, attr.ngModel);
  17154. element.on('$destroy', function() {
  17155. selectContainer.remove();
  17156. });
  17157. }
  17158. function handleKeypress(e) {
  17159. if ($mdConstant.isNavigationKey(e)) {
  17160. // prevent page scrolling on interaction
  17161. e.preventDefault();
  17162. openSelect(e);
  17163. } else {
  17164. if (shouldHandleKey(e, $mdConstant)) {
  17165. e.preventDefault();
  17166. var node = selectMenuCtrl.optNodeForKeyboardSearch(e);
  17167. if (!node || node.hasAttribute('disabled')) return;
  17168. var optionCtrl = angular.element(node).controller('mdOption');
  17169. if (!selectMenuCtrl.isMultiple) {
  17170. selectMenuCtrl.deselect(Object.keys(selectMenuCtrl.selected)[0]);
  17171. }
  17172. selectMenuCtrl.select(optionCtrl.hashKey, optionCtrl.value);
  17173. selectMenuCtrl.refreshViewValue();
  17174. }
  17175. }
  17176. }
  17177. function openSelect() {
  17178. selectScope._mdSelectIsOpen = true;
  17179. element.attr('aria-expanded', 'true');
  17180. $mdSelect.show({
  17181. scope: selectScope,
  17182. preserveScope: true,
  17183. skipCompile: true,
  17184. element: selectContainer,
  17185. target: element[0],
  17186. selectCtrl: mdSelectCtrl,
  17187. preserveElement: true,
  17188. hasBackdrop: true,
  17189. loadingAsync: attr.mdOnOpen ? scope.$eval(attr.mdOnOpen) || true : false
  17190. }).finally(function() {
  17191. selectScope._mdSelectIsOpen = false;
  17192. element.focus();
  17193. element.attr('aria-expanded', 'false');
  17194. ngModelCtrl.$setTouched();
  17195. });
  17196. }
  17197. };
  17198. }
  17199. }
  17200. function SelectMenuDirective($parse, $mdUtil, $mdConstant, $mdTheming) {
  17201. // We want the scope to be set to 'false' so an isolated scope is not created
  17202. // which would interfere with the md-select-header's access to the
  17203. // parent scope.
  17204. SelectMenuController.$inject = ["$scope", "$attrs", "$element"];
  17205. return {
  17206. restrict: 'E',
  17207. require: ['mdSelectMenu'],
  17208. scope: false,
  17209. controller: SelectMenuController,
  17210. link: {pre: preLink}
  17211. };
  17212. // We use preLink instead of postLink to ensure that the select is initialized before
  17213. // its child options run postLink.
  17214. function preLink(scope, element, attr, ctrls) {
  17215. var selectCtrl = ctrls[0];
  17216. element.addClass('_md'); // private md component indicator for styling
  17217. $mdTheming(element);
  17218. element.on('click', clickListener);
  17219. element.on('keypress', keyListener);
  17220. function keyListener(e) {
  17221. if (e.keyCode == 13 || e.keyCode == 32) {
  17222. clickListener(e);
  17223. }
  17224. }
  17225. function clickListener(ev) {
  17226. var option = $mdUtil.getClosest(ev.target, 'md-option');
  17227. var optionCtrl = option && angular.element(option).data('$mdOptionController');
  17228. if (!option || !optionCtrl) return;
  17229. if (option.hasAttribute('disabled')) {
  17230. ev.stopImmediatePropagation();
  17231. return false;
  17232. }
  17233. var optionHashKey = selectCtrl.hashGetter(optionCtrl.value);
  17234. var isSelected = angular.isDefined(selectCtrl.selected[optionHashKey]);
  17235. scope.$apply(function() {
  17236. if (selectCtrl.isMultiple) {
  17237. if (isSelected) {
  17238. selectCtrl.deselect(optionHashKey);
  17239. } else {
  17240. selectCtrl.select(optionHashKey, optionCtrl.value);
  17241. }
  17242. } else {
  17243. if (!isSelected) {
  17244. selectCtrl.deselect(Object.keys(selectCtrl.selected)[0]);
  17245. selectCtrl.select(optionHashKey, optionCtrl.value);
  17246. }
  17247. }
  17248. selectCtrl.refreshViewValue();
  17249. });
  17250. }
  17251. }
  17252. function SelectMenuController($scope, $attrs, $element) {
  17253. var self = this;
  17254. self.isMultiple = angular.isDefined($attrs.multiple);
  17255. // selected is an object with keys matching all of the selected options' hashed values
  17256. self.selected = {};
  17257. // options is an object with keys matching every option's hash value,
  17258. // and values matching every option's controller.
  17259. self.options = {};
  17260. $scope.$watchCollection(function() {
  17261. return self.options;
  17262. }, function() {
  17263. self.ngModel.$render();
  17264. });
  17265. var deregisterCollectionWatch;
  17266. var defaultIsEmpty;
  17267. self.setMultiple = function(isMultiple) {
  17268. var ngModel = self.ngModel;
  17269. defaultIsEmpty = defaultIsEmpty || ngModel.$isEmpty;
  17270. self.isMultiple = isMultiple;
  17271. if (deregisterCollectionWatch) deregisterCollectionWatch();
  17272. if (self.isMultiple) {
  17273. ngModel.$validators['md-multiple'] = validateArray;
  17274. ngModel.$render = renderMultiple;
  17275. // watchCollection on the model because by default ngModel only watches the model's
  17276. // reference. This allowed the developer to also push and pop from their array.
  17277. $scope.$watchCollection(self.modelBinding, function(value) {
  17278. if (validateArray(value)) renderMultiple(value);
  17279. });
  17280. ngModel.$isEmpty = function(value) {
  17281. return !value || value.length === 0;
  17282. };
  17283. } else {
  17284. delete ngModel.$validators['md-multiple'];
  17285. ngModel.$render = renderSingular;
  17286. }
  17287. function validateArray(modelValue, viewValue) {
  17288. // If a value is truthy but not an array, reject it.
  17289. // If value is undefined/falsy, accept that it's an empty array.
  17290. return angular.isArray(modelValue || viewValue || []);
  17291. }
  17292. };
  17293. var searchStr = '';
  17294. var clearSearchTimeout, optNodes, optText;
  17295. var CLEAR_SEARCH_AFTER = 300;
  17296. self.optNodeForKeyboardSearch = function(e) {
  17297. clearSearchTimeout && clearTimeout(clearSearchTimeout);
  17298. clearSearchTimeout = setTimeout(function() {
  17299. clearSearchTimeout = undefined;
  17300. searchStr = '';
  17301. optText = undefined;
  17302. optNodes = undefined;
  17303. }, CLEAR_SEARCH_AFTER);
  17304. // Support 1-9 on numpad
  17305. var keyCode = e.keyCode - ($mdConstant.isNumPadKey(e) ? 48 : 0);
  17306. searchStr += String.fromCharCode(keyCode);
  17307. var search = new RegExp('^' + searchStr, 'i');
  17308. if (!optNodes) {
  17309. optNodes = $element.find('md-option');
  17310. optText = new Array(optNodes.length);
  17311. angular.forEach(optNodes, function(el, i) {
  17312. optText[i] = el.textContent.trim();
  17313. });
  17314. }
  17315. for (var i = 0; i < optText.length; ++i) {
  17316. if (search.test(optText[i])) {
  17317. return optNodes[i];
  17318. }
  17319. }
  17320. };
  17321. self.init = function(ngModel, binding) {
  17322. self.ngModel = ngModel;
  17323. self.modelBinding = binding;
  17324. // Setup a more robust version of isEmpty to ensure value is a valid option
  17325. self.ngModel.$isEmpty = function($viewValue) {
  17326. // We have to transform the viewValue into the hashKey, because otherwise the
  17327. // OptionCtrl may not exist. Developers may have specified a trackBy function.
  17328. return !self.options[self.hashGetter($viewValue)];
  17329. };
  17330. // Allow users to provide `ng-model="foo" ng-model-options="{trackBy: 'foo.id'}"` so
  17331. // that we can properly compare objects set on the model to the available options
  17332. var trackByOption = $mdUtil.getModelOption(ngModel, 'trackBy');
  17333. if (trackByOption) {
  17334. var trackByLocals = {};
  17335. var trackByParsed = $parse(trackByOption);
  17336. self.hashGetter = function(value, valueScope) {
  17337. trackByLocals.$value = value;
  17338. return trackByParsed(valueScope || $scope, trackByLocals);
  17339. };
  17340. // If the user doesn't provide a trackBy, we automatically generate an id for every
  17341. // value passed in
  17342. } else {
  17343. self.hashGetter = function getHashValue(value) {
  17344. if (angular.isObject(value)) {
  17345. return 'object_' + (value.$$mdSelectId || (value.$$mdSelectId = ++selectNextId));
  17346. }
  17347. return value;
  17348. };
  17349. }
  17350. self.setMultiple(self.isMultiple);
  17351. };
  17352. self.selectedLabels = function(opts) {
  17353. opts = opts || {};
  17354. var mode = opts.mode || 'html';
  17355. var selectedOptionEls = $mdUtil.nodesToArray($element[0].querySelectorAll('md-option[selected]'));
  17356. if (selectedOptionEls.length) {
  17357. var mapFn;
  17358. if (mode == 'html') {
  17359. // Map the given element to its innerHTML string. If the element has a child ripple
  17360. // container remove it from the HTML string, before returning the string.
  17361. mapFn = function(el) {
  17362. // If we do not have a `value` or `ng-value`, assume it is an empty option which clears the select
  17363. if (el.hasAttribute('md-option-empty')) {
  17364. return '';
  17365. }
  17366. var html = el.innerHTML;
  17367. // Remove the ripple container from the selected option, copying it would cause a CSP violation.
  17368. var rippleContainer = el.querySelector('.md-ripple-container');
  17369. if (rippleContainer) {
  17370. html = html.replace(rippleContainer.outerHTML, '');
  17371. }
  17372. // Remove the checkbox container, because it will cause the label to wrap inside of the placeholder.
  17373. // It should be not displayed inside of the label element.
  17374. var checkboxContainer = el.querySelector('.md-container');
  17375. if (checkboxContainer) {
  17376. html = html.replace(checkboxContainer.outerHTML, '');
  17377. }
  17378. return html;
  17379. };
  17380. } else if (mode == 'aria') {
  17381. mapFn = function(el) { return el.hasAttribute('aria-label') ? el.getAttribute('aria-label') : el.textContent; };
  17382. }
  17383. // Ensure there are no duplicates; see https://github.com/angular/material/issues/9442
  17384. return $mdUtil.uniq(selectedOptionEls.map(mapFn)).join(', ');
  17385. } else {
  17386. return '';
  17387. }
  17388. };
  17389. self.select = function(hashKey, hashedValue) {
  17390. var option = self.options[hashKey];
  17391. option && option.setSelected(true);
  17392. self.selected[hashKey] = hashedValue;
  17393. };
  17394. self.deselect = function(hashKey) {
  17395. var option = self.options[hashKey];
  17396. option && option.setSelected(false);
  17397. delete self.selected[hashKey];
  17398. };
  17399. self.addOption = function(hashKey, optionCtrl) {
  17400. if (angular.isDefined(self.options[hashKey])) {
  17401. throw new Error('Duplicate md-option values are not allowed in a select. ' +
  17402. 'Duplicate value "' + optionCtrl.value + '" found.');
  17403. }
  17404. self.options[hashKey] = optionCtrl;
  17405. // If this option's value was already in our ngModel, go ahead and select it.
  17406. if (angular.isDefined(self.selected[hashKey])) {
  17407. self.select(hashKey, optionCtrl.value);
  17408. // When the current $modelValue of the ngModel Controller is using the same hash as
  17409. // the current option, which will be added, then we can be sure, that the validation
  17410. // of the option has occurred before the option was added properly.
  17411. // This means, that we have to manually trigger a new validation of the current option.
  17412. if (angular.isDefined(self.ngModel.$modelValue) && self.hashGetter(self.ngModel.$modelValue) === hashKey) {
  17413. self.ngModel.$validate();
  17414. }
  17415. self.refreshViewValue();
  17416. }
  17417. };
  17418. self.removeOption = function(hashKey) {
  17419. delete self.options[hashKey];
  17420. // Don't deselect an option when it's removed - the user's ngModel should be allowed
  17421. // to have values that do not match a currently available option.
  17422. };
  17423. self.refreshViewValue = function() {
  17424. var values = [];
  17425. var option;
  17426. for (var hashKey in self.selected) {
  17427. // If this hashKey has an associated option, push that option's value to the model.
  17428. if ((option = self.options[hashKey])) {
  17429. values.push(option.value);
  17430. } else {
  17431. // Otherwise, the given hashKey has no associated option, and we got it
  17432. // from an ngModel value at an earlier time. Push the unhashed value of
  17433. // this hashKey to the model.
  17434. // This allows the developer to put a value in the model that doesn't yet have
  17435. // an associated option.
  17436. values.push(self.selected[hashKey]);
  17437. }
  17438. }
  17439. var usingTrackBy = $mdUtil.getModelOption(self.ngModel, 'trackBy');
  17440. var newVal = self.isMultiple ? values : values[0];
  17441. var prevVal = self.ngModel.$modelValue;
  17442. if (usingTrackBy ? !angular.equals(prevVal, newVal) : (prevVal + '') !== newVal) {
  17443. self.ngModel.$setViewValue(newVal);
  17444. self.ngModel.$render();
  17445. }
  17446. };
  17447. function renderMultiple() {
  17448. var newSelectedValues = self.ngModel.$modelValue || self.ngModel.$viewValue || [];
  17449. if (!angular.isArray(newSelectedValues)) return;
  17450. var oldSelected = Object.keys(self.selected);
  17451. var newSelectedHashes = newSelectedValues.map(self.hashGetter);
  17452. var deselected = oldSelected.filter(function(hash) {
  17453. return newSelectedHashes.indexOf(hash) === -1;
  17454. });
  17455. deselected.forEach(self.deselect);
  17456. newSelectedHashes.forEach(function(hashKey, i) {
  17457. self.select(hashKey, newSelectedValues[i]);
  17458. });
  17459. }
  17460. function renderSingular() {
  17461. var value = self.ngModel.$viewValue || self.ngModel.$modelValue;
  17462. Object.keys(self.selected).forEach(self.deselect);
  17463. self.select(self.hashGetter(value), value);
  17464. }
  17465. }
  17466. }
  17467. function OptionDirective($mdButtonInkRipple, $mdUtil, $mdTheming) {
  17468. OptionController.$inject = ["$element"];
  17469. return {
  17470. restrict: 'E',
  17471. require: ['mdOption', '^^mdSelectMenu'],
  17472. controller: OptionController,
  17473. compile: compile
  17474. };
  17475. function compile(element, attr) {
  17476. // Manual transclusion to avoid the extra inner <span> that ng-transclude generates
  17477. element.append(angular.element('<div class="md-text">').append(element.contents()));
  17478. element.attr('tabindex', attr.tabindex || '0');
  17479. if (!hasDefinedValue(attr)) {
  17480. element.attr('md-option-empty', '');
  17481. }
  17482. return postLink;
  17483. }
  17484. function hasDefinedValue(attr) {
  17485. var value = attr.value;
  17486. var ngValue = attr.ngValue;
  17487. return value || ngValue;
  17488. }
  17489. function postLink(scope, element, attr, ctrls) {
  17490. var optionCtrl = ctrls[0];
  17491. var selectCtrl = ctrls[1];
  17492. $mdTheming(element);
  17493. if (selectCtrl.isMultiple) {
  17494. element.addClass('md-checkbox-enabled');
  17495. element.prepend(CHECKBOX_SELECTION_INDICATOR.clone());
  17496. }
  17497. if (angular.isDefined(attr.ngValue)) {
  17498. scope.$watch(attr.ngValue, setOptionValue);
  17499. } else if (angular.isDefined(attr.value)) {
  17500. setOptionValue(attr.value);
  17501. } else {
  17502. scope.$watch(function() {
  17503. return element.text().trim();
  17504. }, setOptionValue);
  17505. }
  17506. attr.$observe('disabled', function(disabled) {
  17507. if (disabled) {
  17508. element.attr('tabindex', '-1');
  17509. } else {
  17510. element.attr('tabindex', '0');
  17511. }
  17512. });
  17513. scope.$$postDigest(function() {
  17514. attr.$observe('selected', function(selected) {
  17515. if (!angular.isDefined(selected)) return;
  17516. if (typeof selected == 'string') selected = true;
  17517. if (selected) {
  17518. if (!selectCtrl.isMultiple) {
  17519. selectCtrl.deselect(Object.keys(selectCtrl.selected)[0]);
  17520. }
  17521. selectCtrl.select(optionCtrl.hashKey, optionCtrl.value);
  17522. } else {
  17523. selectCtrl.deselect(optionCtrl.hashKey);
  17524. }
  17525. selectCtrl.refreshViewValue();
  17526. });
  17527. });
  17528. $mdButtonInkRipple.attach(scope, element);
  17529. configureAria();
  17530. function setOptionValue(newValue, oldValue, prevAttempt) {
  17531. if (!selectCtrl.hashGetter) {
  17532. if (!prevAttempt) {
  17533. scope.$$postDigest(function() {
  17534. setOptionValue(newValue, oldValue, true);
  17535. });
  17536. }
  17537. return;
  17538. }
  17539. var oldHashKey = selectCtrl.hashGetter(oldValue, scope);
  17540. var newHashKey = selectCtrl.hashGetter(newValue, scope);
  17541. optionCtrl.hashKey = newHashKey;
  17542. optionCtrl.value = newValue;
  17543. selectCtrl.removeOption(oldHashKey, optionCtrl);
  17544. selectCtrl.addOption(newHashKey, optionCtrl);
  17545. }
  17546. scope.$on('$destroy', function() {
  17547. selectCtrl.removeOption(optionCtrl.hashKey, optionCtrl);
  17548. });
  17549. function configureAria() {
  17550. var ariaAttrs = {
  17551. 'role': 'option',
  17552. 'aria-selected': 'false'
  17553. };
  17554. if (!element[0].hasAttribute('id')) {
  17555. ariaAttrs.id = 'select_option_' + $mdUtil.nextUid();
  17556. }
  17557. element.attr(ariaAttrs);
  17558. }
  17559. }
  17560. function OptionController($element) {
  17561. this.selected = false;
  17562. this.setSelected = function(isSelected) {
  17563. if (isSelected && !this.selected) {
  17564. $element.attr({
  17565. 'selected': 'selected',
  17566. 'aria-selected': 'true'
  17567. });
  17568. } else if (!isSelected && this.selected) {
  17569. $element.removeAttr('selected');
  17570. $element.attr('aria-selected', 'false');
  17571. }
  17572. this.selected = isSelected;
  17573. };
  17574. }
  17575. }
  17576. function OptgroupDirective() {
  17577. return {
  17578. restrict: 'E',
  17579. compile: compile
  17580. };
  17581. function compile(el, attrs) {
  17582. // If we have a select header element, we don't want to add the normal label
  17583. // header.
  17584. if (!hasSelectHeader()) {
  17585. setupLabelElement();
  17586. }
  17587. function hasSelectHeader() {
  17588. return el.parent().find('md-select-header').length;
  17589. }
  17590. function setupLabelElement() {
  17591. var labelElement = el.find('label');
  17592. if (!labelElement.length) {
  17593. labelElement = angular.element('<label>');
  17594. el.prepend(labelElement);
  17595. }
  17596. labelElement.addClass('md-container-ignore');
  17597. labelElement.attr('aria-hidden', 'true');
  17598. if (attrs.label) labelElement.text(attrs.label);
  17599. }
  17600. }
  17601. }
  17602. function SelectHeaderDirective() {
  17603. return {
  17604. restrict: 'E',
  17605. };
  17606. }
  17607. function SelectProvider($$interimElementProvider) {
  17608. selectDefaultOptions.$inject = ["$mdSelect", "$mdConstant", "$mdUtil", "$window", "$q", "$$rAF", "$animateCss", "$animate", "$document"];
  17609. return $$interimElementProvider('$mdSelect')
  17610. .setDefaults({
  17611. methods: ['target'],
  17612. options: selectDefaultOptions
  17613. });
  17614. /* @ngInject */
  17615. function selectDefaultOptions($mdSelect, $mdConstant, $mdUtil, $window, $q, $$rAF, $animateCss, $animate, $document) {
  17616. var ERROR_TARGET_EXPECTED = "$mdSelect.show() expected a target element in options.target but got '{0}'!";
  17617. var animator = $mdUtil.dom.animator;
  17618. var keyCodes = $mdConstant.KEY_CODE;
  17619. return {
  17620. parent: 'body',
  17621. themable: true,
  17622. onShow: onShow,
  17623. onRemove: onRemove,
  17624. hasBackdrop: true,
  17625. disableParentScroll: true
  17626. };
  17627. /**
  17628. * Interim-element onRemove logic....
  17629. */
  17630. function onRemove(scope, element, opts) {
  17631. var animationRunner = null;
  17632. var destroyListener = scope.$on('$destroy', function() {
  17633. // Listen for the case where the element was destroyed while there was an
  17634. // ongoing close animation. If this happens, we need to end the animation
  17635. // manually.
  17636. animationRunner.end();
  17637. });
  17638. opts = opts || { };
  17639. opts.cleanupInteraction();
  17640. opts.cleanupResizing();
  17641. opts.hideBackdrop();
  17642. // For navigation $destroy events, do a quick, non-animated removal,
  17643. // but for normal closes (from clicks, etc) animate the removal
  17644. return (opts.$destroy === true) ? cleanElement() : animateRemoval().then(cleanElement);
  17645. /**
  17646. * For normal closes (eg clicks), animate the removal.
  17647. * For forced closes (like $destroy events from navigation),
  17648. * skip the animations
  17649. */
  17650. function animateRemoval() {
  17651. animationRunner = $animateCss(element, {addClass: 'md-leave'});
  17652. return animationRunner.start();
  17653. }
  17654. /**
  17655. * Restore the element to a closed state
  17656. */
  17657. function cleanElement() {
  17658. destroyListener();
  17659. element
  17660. .removeClass('md-active')
  17661. .attr('aria-hidden', 'true')
  17662. .css('display', 'none');
  17663. element.parent().find('md-select-value').removeAttr('aria-hidden');
  17664. announceClosed(opts);
  17665. if (!opts.$destroy && opts.restoreFocus) {
  17666. opts.target.focus();
  17667. }
  17668. }
  17669. }
  17670. /**
  17671. * Interim-element onShow logic....
  17672. */
  17673. function onShow(scope, element, opts) {
  17674. watchAsyncLoad();
  17675. sanitizeAndConfigure(scope, opts);
  17676. opts.hideBackdrop = showBackdrop(scope, element, opts);
  17677. return showDropDown(scope, element, opts)
  17678. .then(function(response) {
  17679. element.attr('aria-hidden', 'false');
  17680. opts.alreadyOpen = true;
  17681. opts.cleanupInteraction = activateInteraction();
  17682. opts.cleanupResizing = activateResizing();
  17683. autoFocus(opts.focusedNode);
  17684. return response;
  17685. }, opts.hideBackdrop);
  17686. // ************************************
  17687. // Closure Functions
  17688. // ************************************
  17689. /**
  17690. * Attach the select DOM element(s) and animate to the correct positions
  17691. * and scalings...
  17692. */
  17693. function showDropDown(scope, element, opts) {
  17694. if (opts.parent !== element.parent()) {
  17695. element.parent().attr('aria-owns', element.attr('id'));
  17696. }
  17697. element.parent().find('md-select-value').attr('aria-hidden', 'true');
  17698. opts.parent.append(element);
  17699. return $q(function(resolve, reject) {
  17700. try {
  17701. $animateCss(element, {removeClass: 'md-leave', duration: 0})
  17702. .start()
  17703. .then(positionAndFocusMenu)
  17704. .then(resolve);
  17705. } catch (e) {
  17706. reject(e);
  17707. }
  17708. });
  17709. }
  17710. /**
  17711. * Initialize container and dropDown menu positions/scale, then animate
  17712. * to show.
  17713. */
  17714. function positionAndFocusMenu() {
  17715. return $q(function(resolve) {
  17716. if (opts.isRemoved) return $q.reject(false);
  17717. var info = calculateMenuPositions(scope, element, opts);
  17718. info.container.element.css(animator.toCss(info.container.styles));
  17719. info.dropDown.element.css(animator.toCss(info.dropDown.styles));
  17720. $$rAF(function() {
  17721. element.addClass('md-active');
  17722. info.dropDown.element.css(animator.toCss({transform: ''}));
  17723. resolve();
  17724. });
  17725. });
  17726. }
  17727. /**
  17728. * Show modal backdrop element...
  17729. */
  17730. function showBackdrop(scope, element, options) {
  17731. // If we are not within a dialog...
  17732. if (options.disableParentScroll && !$mdUtil.getClosest(options.target, 'MD-DIALOG')) {
  17733. // !! DO this before creating the backdrop; since disableScrollAround()
  17734. // configures the scroll offset; which is used by mdBackDrop postLink()
  17735. options.restoreScroll = $mdUtil.disableScrollAround(options.element, options.parent);
  17736. } else {
  17737. options.disableParentScroll = false;
  17738. }
  17739. if (options.hasBackdrop) {
  17740. // Override duration to immediately show invisible backdrop
  17741. options.backdrop = $mdUtil.createBackdrop(scope, "md-select-backdrop md-click-catcher");
  17742. $animate.enter(options.backdrop, $document[0].body, null, {duration: 0});
  17743. }
  17744. /**
  17745. * Hide modal backdrop element...
  17746. */
  17747. return function hideBackdrop() {
  17748. if (options.backdrop) options.backdrop.remove();
  17749. if (options.disableParentScroll) options.restoreScroll();
  17750. delete options.restoreScroll;
  17751. };
  17752. }
  17753. /**
  17754. *
  17755. */
  17756. function autoFocus(focusedNode) {
  17757. if (focusedNode && !focusedNode.hasAttribute('disabled')) {
  17758. focusedNode.focus();
  17759. }
  17760. }
  17761. /**
  17762. * Check for valid opts and set some sane defaults
  17763. */
  17764. function sanitizeAndConfigure(scope, options) {
  17765. var selectEl = element.find('md-select-menu');
  17766. if (!options.target) {
  17767. throw new Error($mdUtil.supplant(ERROR_TARGET_EXPECTED, [options.target]));
  17768. }
  17769. angular.extend(options, {
  17770. isRemoved: false,
  17771. target: angular.element(options.target), //make sure it's not a naked dom node
  17772. parent: angular.element(options.parent),
  17773. selectEl: selectEl,
  17774. contentEl: element.find('md-content'),
  17775. optionNodes: selectEl[0].getElementsByTagName('md-option')
  17776. });
  17777. }
  17778. /**
  17779. * Configure various resize listeners for screen changes
  17780. */
  17781. function activateResizing() {
  17782. var debouncedOnResize = (function(scope, target, options) {
  17783. return function() {
  17784. if (options.isRemoved) return;
  17785. var updates = calculateMenuPositions(scope, target, options);
  17786. var container = updates.container;
  17787. var dropDown = updates.dropDown;
  17788. container.element.css(animator.toCss(container.styles));
  17789. dropDown.element.css(animator.toCss(dropDown.styles));
  17790. };
  17791. })(scope, element, opts);
  17792. var window = angular.element($window);
  17793. window.on('resize', debouncedOnResize);
  17794. window.on('orientationchange', debouncedOnResize);
  17795. // Publish deactivation closure...
  17796. return function deactivateResizing() {
  17797. // Disable resizing handlers
  17798. window.off('resize', debouncedOnResize);
  17799. window.off('orientationchange', debouncedOnResize);
  17800. };
  17801. }
  17802. /**
  17803. * If asynchronously loading, watch and update internal
  17804. * '$$loadingAsyncDone' flag
  17805. */
  17806. function watchAsyncLoad() {
  17807. if (opts.loadingAsync && !opts.isRemoved) {
  17808. scope.$$loadingAsyncDone = false;
  17809. $q.when(opts.loadingAsync)
  17810. .then(function() {
  17811. scope.$$loadingAsyncDone = true;
  17812. delete opts.loadingAsync;
  17813. }).then(function() {
  17814. $$rAF(positionAndFocusMenu);
  17815. });
  17816. }
  17817. }
  17818. /**
  17819. *
  17820. */
  17821. function activateInteraction() {
  17822. if (opts.isRemoved) return;
  17823. var dropDown = opts.selectEl;
  17824. var selectCtrl = dropDown.controller('mdSelectMenu') || {};
  17825. element.addClass('md-clickable');
  17826. // Close on backdrop click
  17827. opts.backdrop && opts.backdrop.on('click', onBackdropClick);
  17828. // Escape to close
  17829. // Cycling of options, and closing on enter
  17830. dropDown.on('keydown', onMenuKeyDown);
  17831. dropDown.on('click', checkCloseMenu);
  17832. return function cleanupInteraction() {
  17833. opts.backdrop && opts.backdrop.off('click', onBackdropClick);
  17834. dropDown.off('keydown', onMenuKeyDown);
  17835. dropDown.off('click', checkCloseMenu);
  17836. element.removeClass('md-clickable');
  17837. opts.isRemoved = true;
  17838. };
  17839. // ************************************
  17840. // Closure Functions
  17841. // ************************************
  17842. function onBackdropClick(e) {
  17843. e.preventDefault();
  17844. e.stopPropagation();
  17845. opts.restoreFocus = false;
  17846. $mdUtil.nextTick($mdSelect.hide, true);
  17847. }
  17848. function onMenuKeyDown(ev) {
  17849. ev.preventDefault();
  17850. ev.stopPropagation();
  17851. switch (ev.keyCode) {
  17852. case keyCodes.UP_ARROW:
  17853. return focusPrevOption();
  17854. case keyCodes.DOWN_ARROW:
  17855. return focusNextOption();
  17856. case keyCodes.SPACE:
  17857. case keyCodes.ENTER:
  17858. var option = $mdUtil.getClosest(ev.target, 'md-option');
  17859. if (option) {
  17860. dropDown.triggerHandler({
  17861. type: 'click',
  17862. target: option
  17863. });
  17864. ev.preventDefault();
  17865. }
  17866. checkCloseMenu(ev);
  17867. break;
  17868. case keyCodes.TAB:
  17869. case keyCodes.ESCAPE:
  17870. ev.stopPropagation();
  17871. ev.preventDefault();
  17872. opts.restoreFocus = true;
  17873. $mdUtil.nextTick($mdSelect.hide, true);
  17874. break;
  17875. default:
  17876. if (shouldHandleKey(ev, $mdConstant)) {
  17877. var optNode = dropDown.controller('mdSelectMenu').optNodeForKeyboardSearch(ev);
  17878. opts.focusedNode = optNode || opts.focusedNode;
  17879. optNode && optNode.focus();
  17880. }
  17881. }
  17882. }
  17883. function focusOption(direction) {
  17884. var optionsArray = $mdUtil.nodesToArray(opts.optionNodes);
  17885. var index = optionsArray.indexOf(opts.focusedNode);
  17886. var newOption;
  17887. do {
  17888. if (index === -1) {
  17889. // We lost the previously focused element, reset to first option
  17890. index = 0;
  17891. } else if (direction === 'next' && index < optionsArray.length - 1) {
  17892. index++;
  17893. } else if (direction === 'prev' && index > 0) {
  17894. index--;
  17895. }
  17896. newOption = optionsArray[index];
  17897. if (newOption.hasAttribute('disabled')) newOption = undefined;
  17898. } while (!newOption && index < optionsArray.length - 1 && index > 0);
  17899. newOption && newOption.focus();
  17900. opts.focusedNode = newOption;
  17901. }
  17902. function focusNextOption() {
  17903. focusOption('next');
  17904. }
  17905. function focusPrevOption() {
  17906. focusOption('prev');
  17907. }
  17908. function checkCloseMenu(ev) {
  17909. if (ev && ( ev.type == 'click') && (ev.currentTarget != dropDown[0])) return;
  17910. if ( mouseOnScrollbar() ) return;
  17911. var option = $mdUtil.getClosest(ev.target, 'md-option');
  17912. if (option && option.hasAttribute && !option.hasAttribute('disabled')) {
  17913. ev.preventDefault();
  17914. ev.stopPropagation();
  17915. if (!selectCtrl.isMultiple) {
  17916. opts.restoreFocus = true;
  17917. $mdUtil.nextTick(function () {
  17918. $mdSelect.hide(selectCtrl.ngModel.$viewValue);
  17919. }, true);
  17920. }
  17921. }
  17922. /**
  17923. * check if the mouseup event was on a scrollbar
  17924. */
  17925. function mouseOnScrollbar() {
  17926. var clickOnScrollbar = false;
  17927. if (ev && (ev.currentTarget.children.length > 0)) {
  17928. var child = ev.currentTarget.children[0];
  17929. var hasScrollbar = child.scrollHeight > child.clientHeight;
  17930. if (hasScrollbar && child.children.length > 0) {
  17931. var relPosX = ev.pageX - ev.currentTarget.getBoundingClientRect().left;
  17932. if (relPosX > child.querySelector('md-option').offsetWidth)
  17933. clickOnScrollbar = true;
  17934. }
  17935. }
  17936. return clickOnScrollbar;
  17937. }
  17938. }
  17939. }
  17940. }
  17941. /**
  17942. * To notify listeners that the Select menu has closed,
  17943. * trigger the [optional] user-defined expression
  17944. */
  17945. function announceClosed(opts) {
  17946. var mdSelect = opts.selectCtrl;
  17947. if (mdSelect) {
  17948. var menuController = opts.selectEl.controller('mdSelectMenu');
  17949. mdSelect.setLabelText(menuController ? menuController.selectedLabels() : '');
  17950. mdSelect.triggerClose();
  17951. }
  17952. }
  17953. /**
  17954. * Calculate the
  17955. */
  17956. function calculateMenuPositions(scope, element, opts) {
  17957. var
  17958. containerNode = element[0],
  17959. targetNode = opts.target[0].children[0], // target the label
  17960. parentNode = $document[0].body,
  17961. selectNode = opts.selectEl[0],
  17962. contentNode = opts.contentEl[0],
  17963. parentRect = parentNode.getBoundingClientRect(),
  17964. targetRect = targetNode.getBoundingClientRect(),
  17965. shouldOpenAroundTarget = false,
  17966. bounds = {
  17967. left: parentRect.left + SELECT_EDGE_MARGIN,
  17968. top: SELECT_EDGE_MARGIN,
  17969. bottom: parentRect.height - SELECT_EDGE_MARGIN,
  17970. right: parentRect.width - SELECT_EDGE_MARGIN - ($mdUtil.floatingScrollbars() ? 16 : 0)
  17971. },
  17972. spaceAvailable = {
  17973. top: targetRect.top - bounds.top,
  17974. left: targetRect.left - bounds.left,
  17975. right: bounds.right - (targetRect.left + targetRect.width),
  17976. bottom: bounds.bottom - (targetRect.top + targetRect.height)
  17977. },
  17978. maxWidth = parentRect.width - SELECT_EDGE_MARGIN * 2,
  17979. selectedNode = selectNode.querySelector('md-option[selected]'),
  17980. optionNodes = selectNode.getElementsByTagName('md-option'),
  17981. optgroupNodes = selectNode.getElementsByTagName('md-optgroup'),
  17982. isScrollable = calculateScrollable(element, contentNode),
  17983. centeredNode;
  17984. var loading = isPromiseLike(opts.loadingAsync);
  17985. if (!loading) {
  17986. // If a selected node, center around that
  17987. if (selectedNode) {
  17988. centeredNode = selectedNode;
  17989. // If there are option groups, center around the first option group
  17990. } else if (optgroupNodes.length) {
  17991. centeredNode = optgroupNodes[0];
  17992. // Otherwise - if we are not loading async - center around the first optionNode
  17993. } else if (optionNodes.length) {
  17994. centeredNode = optionNodes[0];
  17995. // In case there are no options, center on whatever's in there... (eg progress indicator)
  17996. } else {
  17997. centeredNode = contentNode.firstElementChild || contentNode;
  17998. }
  17999. } else {
  18000. // If loading, center on progress indicator
  18001. centeredNode = contentNode.firstElementChild || contentNode;
  18002. }
  18003. if (contentNode.offsetWidth > maxWidth) {
  18004. contentNode.style['max-width'] = maxWidth + 'px';
  18005. } else {
  18006. contentNode.style.maxWidth = null;
  18007. }
  18008. if (shouldOpenAroundTarget) {
  18009. contentNode.style['min-width'] = targetRect.width + 'px';
  18010. }
  18011. // Remove padding before we compute the position of the menu
  18012. if (isScrollable) {
  18013. selectNode.classList.add('md-overflow');
  18014. }
  18015. var focusedNode = centeredNode;
  18016. if ((focusedNode.tagName || '').toUpperCase() === 'MD-OPTGROUP') {
  18017. focusedNode = optionNodes[0] || contentNode.firstElementChild || contentNode;
  18018. centeredNode = focusedNode;
  18019. }
  18020. // Cache for autoFocus()
  18021. opts.focusedNode = focusedNode;
  18022. // Get the selectMenuRect *after* max-width is possibly set above
  18023. containerNode.style.display = 'block';
  18024. var selectMenuRect = selectNode.getBoundingClientRect();
  18025. var centeredRect = getOffsetRect(centeredNode);
  18026. if (centeredNode) {
  18027. var centeredStyle = $window.getComputedStyle(centeredNode);
  18028. centeredRect.paddingLeft = parseInt(centeredStyle.paddingLeft, 10) || 0;
  18029. centeredRect.paddingRight = parseInt(centeredStyle.paddingRight, 10) || 0;
  18030. }
  18031. if (isScrollable) {
  18032. var scrollBuffer = contentNode.offsetHeight / 2;
  18033. contentNode.scrollTop = centeredRect.top + centeredRect.height / 2 - scrollBuffer;
  18034. if (spaceAvailable.top < scrollBuffer) {
  18035. contentNode.scrollTop = Math.min(
  18036. centeredRect.top,
  18037. contentNode.scrollTop + scrollBuffer - spaceAvailable.top
  18038. );
  18039. } else if (spaceAvailable.bottom < scrollBuffer) {
  18040. contentNode.scrollTop = Math.max(
  18041. centeredRect.top + centeredRect.height - selectMenuRect.height,
  18042. contentNode.scrollTop - scrollBuffer + spaceAvailable.bottom
  18043. );
  18044. }
  18045. }
  18046. var left, top, transformOrigin, minWidth, fontSize;
  18047. if (shouldOpenAroundTarget) {
  18048. left = targetRect.left;
  18049. top = targetRect.top + targetRect.height;
  18050. transformOrigin = '50% 0';
  18051. if (top + selectMenuRect.height > bounds.bottom) {
  18052. top = targetRect.top - selectMenuRect.height;
  18053. transformOrigin = '50% 100%';
  18054. }
  18055. } else {
  18056. left = (targetRect.left + centeredRect.left - centeredRect.paddingLeft) + 2;
  18057. top = Math.floor(targetRect.top + targetRect.height / 2 - centeredRect.height / 2 -
  18058. centeredRect.top + contentNode.scrollTop) + 2;
  18059. transformOrigin = (centeredRect.left + targetRect.width / 2) + 'px ' +
  18060. (centeredRect.top + centeredRect.height / 2 - contentNode.scrollTop) + 'px 0px';
  18061. minWidth = Math.min(targetRect.width + centeredRect.paddingLeft + centeredRect.paddingRight, maxWidth);
  18062. fontSize = window.getComputedStyle(targetNode)['font-size'];
  18063. }
  18064. // Keep left and top within the window
  18065. var containerRect = containerNode.getBoundingClientRect();
  18066. var scaleX = Math.round(100 * Math.min(targetRect.width / selectMenuRect.width, 1.0)) / 100;
  18067. var scaleY = Math.round(100 * Math.min(targetRect.height / selectMenuRect.height, 1.0)) / 100;
  18068. return {
  18069. container: {
  18070. element: angular.element(containerNode),
  18071. styles: {
  18072. left: Math.floor(clamp(bounds.left, left, bounds.right - containerRect.width)),
  18073. top: Math.floor(clamp(bounds.top, top, bounds.bottom - containerRect.height)),
  18074. 'min-width': minWidth,
  18075. 'font-size': fontSize
  18076. }
  18077. },
  18078. dropDown: {
  18079. element: angular.element(selectNode),
  18080. styles: {
  18081. transformOrigin: transformOrigin,
  18082. transform: !opts.alreadyOpen ? $mdUtil.supplant('scale({0},{1})', [scaleX, scaleY]) : ""
  18083. }
  18084. }
  18085. };
  18086. }
  18087. }
  18088. function isPromiseLike(obj) {
  18089. return obj && angular.isFunction(obj.then);
  18090. }
  18091. function clamp(min, n, max) {
  18092. return Math.max(min, Math.min(n, max));
  18093. }
  18094. function getOffsetRect(node) {
  18095. return node ? {
  18096. left: node.offsetLeft,
  18097. top: node.offsetTop,
  18098. width: node.offsetWidth,
  18099. height: node.offsetHeight
  18100. } : {left: 0, top: 0, width: 0, height: 0};
  18101. }
  18102. function calculateScrollable(element, contentNode) {
  18103. var isScrollable = false;
  18104. try {
  18105. var oldDisplay = element[0].style.display;
  18106. // Set the element's display to block so that this calculation is correct
  18107. element[0].style.display = 'block';
  18108. isScrollable = contentNode.scrollHeight > contentNode.offsetHeight;
  18109. // Reset it back afterwards
  18110. element[0].style.display = oldDisplay;
  18111. } finally {
  18112. // Nothing to do
  18113. }
  18114. return isScrollable;
  18115. }
  18116. }
  18117. function shouldHandleKey(ev, $mdConstant) {
  18118. var char = String.fromCharCode(ev.keyCode);
  18119. var isNonUsefulKey = (ev.keyCode <= 31);
  18120. return (char && char.length && !isNonUsefulKey &&
  18121. !$mdConstant.isMetaKey(ev) && !$mdConstant.isFnLockKey(ev) && !$mdConstant.hasModifierKey(ev));
  18122. }
  18123. })();
  18124. (function(){
  18125. "use strict";
  18126. /**
  18127. * @ngdoc module
  18128. * @name material.components.showHide
  18129. */
  18130. // Add additional handlers to ng-show and ng-hide that notify directives
  18131. // contained within that they should recompute their size.
  18132. // These run in addition to AngularJS's built-in ng-hide and ng-show directives.
  18133. angular.module('material.components.showHide', [
  18134. 'material.core'
  18135. ])
  18136. .directive('ngShow', createDirective('ngShow', true))
  18137. .directive('ngHide', createDirective('ngHide', false));
  18138. function createDirective(name, targetValue) {
  18139. return ['$mdUtil', '$window', function($mdUtil, $window) {
  18140. return {
  18141. restrict: 'A',
  18142. multiElement: true,
  18143. link: function($scope, $element, $attr) {
  18144. var unregister = $scope.$on('$md-resize-enable', function() {
  18145. unregister();
  18146. var node = $element[0];
  18147. var cachedTransitionStyles = node.nodeType === $window.Node.ELEMENT_NODE ?
  18148. $window.getComputedStyle(node) : {};
  18149. $scope.$watch($attr[name], function(value) {
  18150. if (!!value === targetValue) {
  18151. $mdUtil.nextTick(function() {
  18152. $scope.$broadcast('$md-resize');
  18153. });
  18154. var opts = {
  18155. cachedTransitionStyles: cachedTransitionStyles
  18156. };
  18157. $mdUtil.dom.animator.waitTransitionEnd($element, opts).then(function() {
  18158. $scope.$broadcast('$md-resize');
  18159. });
  18160. }
  18161. });
  18162. });
  18163. }
  18164. };
  18165. }];
  18166. }
  18167. })();
  18168. (function(){
  18169. "use strict";
  18170. /**
  18171. * @ngdoc module
  18172. * @name material.components.sidenav
  18173. *
  18174. * @description
  18175. * A Sidenav QP component.
  18176. */
  18177. SidenavService.$inject = ["$mdComponentRegistry", "$mdUtil", "$q", "$log"];
  18178. SidenavDirective.$inject = ["$mdMedia", "$mdUtil", "$mdConstant", "$mdTheming", "$mdInteraction", "$animate", "$compile", "$parse", "$log", "$q", "$document", "$window", "$$rAF"];
  18179. SidenavController.$inject = ["$scope", "$attrs", "$mdComponentRegistry", "$q", "$interpolate"];
  18180. angular
  18181. .module('material.components.sidenav', [
  18182. 'material.core',
  18183. 'material.components.backdrop'
  18184. ])
  18185. .factory('$mdSidenav', SidenavService )
  18186. .directive('mdSidenav', SidenavDirective)
  18187. .directive('mdSidenavFocus', SidenavFocusDirective)
  18188. .controller('$mdSidenavController', SidenavController);
  18189. /**
  18190. * @ngdoc service
  18191. * @name $mdSidenav
  18192. * @module material.components.sidenav
  18193. *
  18194. * @description
  18195. * `$mdSidenav` makes it easy to interact with multiple sidenavs
  18196. * in an app. When looking up a sidenav instance, you can either look
  18197. * it up synchronously or wait for it to be initializied asynchronously.
  18198. * This is done by passing the second argument to `$mdSidenav`.
  18199. *
  18200. * @usage
  18201. * <hljs lang="js">
  18202. * // Async lookup for sidenav instance; will resolve when the instance is available
  18203. * $mdSidenav(componentId, true).then(function(instance) {
  18204. * $log.debug( componentId + "is now ready" );
  18205. * });
  18206. * // Sync lookup for sidenav instance; this will resolve immediately.
  18207. * $mdSidenav(componentId).then(function(instance) {
  18208. * $log.debug( componentId + "is now ready" );
  18209. * });
  18210. * // Async toggle the given sidenav;
  18211. * // when instance is known ready and lazy lookup is not needed.
  18212. * $mdSidenav(componentId)
  18213. * .toggle()
  18214. * .then(function(){
  18215. * $log.debug('toggled');
  18216. * });
  18217. * // Async open the given sidenav
  18218. * $mdSidenav(componentId)
  18219. * .open()
  18220. * .then(function(){
  18221. * $log.debug('opened');
  18222. * });
  18223. * // Async close the given sidenav
  18224. * $mdSidenav(componentId)
  18225. * .close()
  18226. * .then(function(){
  18227. * $log.debug('closed');
  18228. * });
  18229. * // Async lookup for sidenav instance
  18230. * $mdSidenav(componentId, true).then(function(instance) {
  18231. * // On close callback to handle close, backdrop click, or escape key pressed.
  18232. * // Callback happens BEFORE the close action occurs.
  18233. * instance.onClose(function() {
  18234. * $log.debug('closing');
  18235. * });
  18236. * });
  18237. * // Sync check to see if the specified sidenav is set to be open
  18238. * $mdSidenav(componentId).isOpen();
  18239. * // Sync check to whether given sidenav is locked open
  18240. * // If this is true, the sidenav will be open regardless of close()
  18241. * $mdSidenav(componentId).isLockedOpen();
  18242. * </hljs>
  18243. */
  18244. function SidenavService($mdComponentRegistry, $mdUtil, $q, $log) {
  18245. var errorMsg = "SideNav '{0}' is not available! Did you use md-component-id='{0}'?";
  18246. var service = {
  18247. find : findInstance, // sync - returns proxy API
  18248. waitFor : waitForInstance // async - returns promise
  18249. };
  18250. /**
  18251. * Service API that supports three (3) usages:
  18252. * $mdSidenav().find("left") // sync (must already exist) or returns undefined
  18253. * $mdSidenav("left").toggle(); // sync (must already exist) or returns reject promise;
  18254. * $mdSidenav("left",true).then( function(left){ // async returns instance when available
  18255. * left.toggle();
  18256. * });
  18257. */
  18258. return function(handle, enableWait) {
  18259. if ( angular.isUndefined(handle) ) return service;
  18260. var shouldWait = enableWait === true;
  18261. var instance = service.find(handle, shouldWait);
  18262. return !instance && shouldWait ? service.waitFor(handle) :
  18263. !instance && angular.isUndefined(enableWait) ? addLegacyAPI(service, handle) : instance;
  18264. };
  18265. /**
  18266. * For failed instance/handle lookups, older-clients expect an response object with noops
  18267. * that include `rejected promise APIs`
  18268. */
  18269. function addLegacyAPI(service, handle) {
  18270. var falseFn = function() { return false; };
  18271. var rejectFn = function() {
  18272. return $q.when($mdUtil.supplant(errorMsg, [handle || ""]));
  18273. };
  18274. return angular.extend({
  18275. isLockedOpen : falseFn,
  18276. isOpen : falseFn,
  18277. toggle : rejectFn,
  18278. open : rejectFn,
  18279. close : rejectFn,
  18280. onClose : angular.noop,
  18281. then : function(callback) {
  18282. return waitForInstance(handle)
  18283. .then(callback || angular.noop);
  18284. }
  18285. }, service);
  18286. }
  18287. /**
  18288. * Synchronously lookup the controller instance for the specified sidNav instance which has been
  18289. * registered with the markup `md-component-id`
  18290. */
  18291. function findInstance(handle, shouldWait) {
  18292. var instance = $mdComponentRegistry.get(handle);
  18293. if (!instance && !shouldWait) {
  18294. // Report missing instance
  18295. $log.error( $mdUtil.supplant(errorMsg, [handle || ""]) );
  18296. // The component has not registered itself... most like NOT yet created
  18297. // return null to indicate that the Sidenav is not in the DOM
  18298. return undefined;
  18299. }
  18300. return instance;
  18301. }
  18302. /**
  18303. * Asynchronously wait for the component instantiation,
  18304. * Deferred lookup of component instance using $component registry
  18305. */
  18306. function waitForInstance(handle) {
  18307. return $mdComponentRegistry.when(handle).catch($log.error);
  18308. }
  18309. }
  18310. /**
  18311. * @ngdoc directive
  18312. * @name mdSidenavFocus
  18313. * @module material.components.sidenav
  18314. *
  18315. * @restrict A
  18316. *
  18317. * @description
  18318. * `mdSidenavFocus` provides a way to specify the focused element when a sidenav opens.
  18319. * This is completely optional, as the sidenav itself is focused by default.
  18320. *
  18321. * @usage
  18322. * <hljs lang="html">
  18323. * <md-sidenav>
  18324. * <form>
  18325. * <md-input-container>
  18326. * <label for="testInput">Label</label>
  18327. * <input id="testInput" type="text" md-sidenav-focus>
  18328. * </md-input-container>
  18329. * </form>
  18330. * </md-sidenav>
  18331. * </hljs>
  18332. **/
  18333. function SidenavFocusDirective() {
  18334. return {
  18335. restrict: 'A',
  18336. require: '^mdSidenav',
  18337. link: function(scope, element, attr, sidenavCtrl) {
  18338. // @see $mdUtil.findFocusTarget(...)
  18339. }
  18340. };
  18341. }
  18342. /**
  18343. * @ngdoc directive
  18344. * @name mdSidenav
  18345. * @module material.components.sidenav
  18346. * @restrict E
  18347. *
  18348. * @description
  18349. *
  18350. * A Sidenav component that can be opened and closed programatically.
  18351. *
  18352. * By default, upon opening it will slide out on top of the main content area.
  18353. *
  18354. * For keyboard and screen reader accessibility, focus is sent to the sidenav wrapper by default.
  18355. * It can be overridden with the `md-autofocus` directive on the child element you want focused.
  18356. *
  18357. * @usage
  18358. * <hljs lang="html">
  18359. * <div layout="row" ng-controller="MyController">
  18360. * <md-sidenav md-component-id="left" class="md-sidenav-left">
  18361. * Left Nav!
  18362. * </md-sidenav>
  18363. *
  18364. * <md-content>
  18365. * Center Content
  18366. * <md-button ng-click="openLeftMenu()">
  18367. * Open Left Menu
  18368. * </md-button>
  18369. * </md-content>
  18370. *
  18371. * <md-sidenav md-component-id="right"
  18372. * md-is-locked-open="$mdMedia('min-width: 333px')"
  18373. * class="md-sidenav-right">
  18374. * <form>
  18375. * <md-input-container>
  18376. * <label for="testInput">Test input</label>
  18377. * <input id="testInput" type="text"
  18378. * ng-model="data" md-autofocus>
  18379. * </md-input-container>
  18380. * </form>
  18381. * </md-sidenav>
  18382. * </div>
  18383. * </hljs>
  18384. *
  18385. * <hljs lang="js">
  18386. * var app = angular.module('myApp', ['ngMaterial']);
  18387. * app.controller('MyController', function($scope, $mdSidenav) {
  18388. * $scope.openLeftMenu = function() {
  18389. * $mdSidenav('left').toggle();
  18390. * };
  18391. * });
  18392. * </hljs>
  18393. *
  18394. * @param {expression=} md-is-open A model bound to whether the sidenav is opened.
  18395. * @param {boolean=} md-disable-backdrop When present in the markup, the sidenav will not show a backdrop.
  18396. * @param {boolean=} md-disable-close-events When present in the markup, clicking the backdrop or pressing the 'Escape' key will not close the sidenav.
  18397. * @param {string=} md-component-id componentId to use with $mdSidenav service.
  18398. * @param {expression=} md-is-locked-open When this expression evaluates to true,
  18399. * the sidenav 'locks open': it falls into the content's flow instead
  18400. * of appearing over it. This overrides the `md-is-open` attribute.
  18401. * @param {string=} md-disable-scroll-target Selector, pointing to an element, whose scrolling will
  18402. * be disabled when the sidenav is opened. By default this is the sidenav's direct parent.
  18403. *
  18404. * The $mdMedia() service is exposed to the is-locked-open attribute, which
  18405. * can be given a media query or one of the `sm`, `gt-sm`, `md`, `gt-md`, `lg` or `gt-lg` presets.
  18406. * Examples:
  18407. *
  18408. * - `<md-sidenav md-is-locked-open="shouldLockOpen"></md-sidenav>`
  18409. * - `<md-sidenav md-is-locked-open="$mdMedia('min-width: 1000px')"></md-sidenav>`
  18410. * - `<md-sidenav md-is-locked-open="$mdMedia('sm')"></md-sidenav>` (locks open on small screens)
  18411. */
  18412. function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $mdInteraction, $animate,
  18413. $compile, $parse, $log, $q, $document, $window, $$rAF) {
  18414. return {
  18415. restrict: 'E',
  18416. scope: {
  18417. isOpen: '=?mdIsOpen'
  18418. },
  18419. controller: '$mdSidenavController',
  18420. compile: function(element) {
  18421. element.addClass('md-closed').attr('tabIndex', '-1');
  18422. return postLink;
  18423. }
  18424. };
  18425. /**
  18426. * Directive Post Link function...
  18427. */
  18428. function postLink(scope, element, attr, sidenavCtrl) {
  18429. var lastParentOverFlow;
  18430. var backdrop;
  18431. var disableScrollTarget = null;
  18432. var triggeringInteractionType;
  18433. var triggeringElement = null;
  18434. var previousContainerStyles;
  18435. var promise = $q.when(true);
  18436. var isLockedOpenParsed = $parse(attr.mdIsLockedOpen);
  18437. var ngWindow = angular.element($window);
  18438. var isLocked = function() {
  18439. return isLockedOpenParsed(scope.$parent, {
  18440. $media: function(arg) {
  18441. $log.warn("$media is deprecated for is-locked-open. Use $mdMedia instead.");
  18442. return $mdMedia(arg);
  18443. },
  18444. $mdMedia: $mdMedia
  18445. });
  18446. };
  18447. if (attr.mdDisableScrollTarget) {
  18448. disableScrollTarget = $document[0].querySelector(attr.mdDisableScrollTarget);
  18449. if (disableScrollTarget) {
  18450. disableScrollTarget = angular.element(disableScrollTarget);
  18451. } else {
  18452. $log.warn($mdUtil.supplant('mdSidenav: couldn\'t find element matching ' +
  18453. 'selector "{selector}". Falling back to parent.', { selector: attr.mdDisableScrollTarget }));
  18454. }
  18455. }
  18456. if (!disableScrollTarget) {
  18457. disableScrollTarget = element.parent();
  18458. }
  18459. // Only create the backdrop if the backdrop isn't disabled.
  18460. if (!attr.hasOwnProperty('mdDisableBackdrop')) {
  18461. backdrop = $mdUtil.createBackdrop(scope, "md-sidenav-backdrop md-opaque ng-enter");
  18462. }
  18463. // If md-disable-close-events is set on the sidenav we will disable
  18464. // backdrop click and Escape key events
  18465. if (attr.hasOwnProperty('mdDisableCloseEvents')) {
  18466. var disableCloseEvents = true;
  18467. }
  18468. element.addClass('_md'); // private md component indicator for styling
  18469. $mdTheming(element);
  18470. // The backdrop should inherit the sidenavs theme,
  18471. // because the backdrop will take its parent theme by default.
  18472. if ( backdrop ) $mdTheming.inherit(backdrop, element);
  18473. element.on('$destroy', function() {
  18474. backdrop && backdrop.remove();
  18475. sidenavCtrl.destroy();
  18476. });
  18477. scope.$on('$destroy', function(){
  18478. backdrop && backdrop.remove();
  18479. });
  18480. scope.$watch(isLocked, updateIsLocked);
  18481. scope.$watch('isOpen', updateIsOpen);
  18482. // Publish special accessor for the Controller instance
  18483. sidenavCtrl.$toggleOpen = toggleOpen;
  18484. /**
  18485. * Toggle the DOM classes to indicate `locked`
  18486. * @param isLocked
  18487. */
  18488. function updateIsLocked(isLocked, oldValue) {
  18489. scope.isLockedOpen = isLocked;
  18490. if (isLocked === oldValue) {
  18491. element.toggleClass('md-locked-open', !!isLocked);
  18492. } else {
  18493. $animate[isLocked ? 'addClass' : 'removeClass'](element, 'md-locked-open');
  18494. }
  18495. if (backdrop) {
  18496. backdrop.toggleClass('md-locked-open', !!isLocked);
  18497. }
  18498. }
  18499. /**
  18500. * Toggle the SideNav view and attach/detach listeners
  18501. * @param isOpen
  18502. */
  18503. function updateIsOpen(isOpen) {
  18504. // Support deprecated md-sidenav-focus attribute as fallback
  18505. var focusEl = $mdUtil.findFocusTarget(element) || $mdUtil.findFocusTarget(element,'[md-sidenav-focus]') || element;
  18506. var parent = element.parent();
  18507. // If the user hasn't set the disable close events property we are adding
  18508. // click and escape events to close the sidenav
  18509. if ( !disableCloseEvents ) {
  18510. parent[isOpen ? 'on' : 'off']('keydown', onKeyDown);
  18511. if (backdrop) backdrop[isOpen ? 'on' : 'off']('click', close);
  18512. }
  18513. var restorePositioning = updateContainerPositions(parent, isOpen);
  18514. if ( isOpen ) {
  18515. // Capture upon opening..
  18516. triggeringElement = $document[0].activeElement;
  18517. triggeringInteractionType = $mdInteraction.getLastInteractionType();
  18518. }
  18519. disableParentScroll(isOpen);
  18520. return promise = $q.all([
  18521. isOpen && backdrop ? $animate.enter(backdrop, parent) : backdrop ?
  18522. $animate.leave(backdrop) : $q.when(true),
  18523. $animate[isOpen ? 'removeClass' : 'addClass'](element, 'md-closed')
  18524. ]).then(function() {
  18525. // Perform focus when animations are ALL done...
  18526. if (scope.isOpen) {
  18527. $$rAF(function() {
  18528. // Notifies child components that the sidenav was opened. Should wait
  18529. // a frame in order to allow for the element height to be computed.
  18530. ngWindow.triggerHandler('resize');
  18531. });
  18532. focusEl && focusEl.focus();
  18533. }
  18534. // Restores the positioning on the sidenav and backdrop.
  18535. restorePositioning && restorePositioning();
  18536. });
  18537. }
  18538. function updateContainerPositions(parent, willOpen) {
  18539. var drawerEl = element[0];
  18540. var scrollTop = parent[0].scrollTop;
  18541. if (willOpen && scrollTop) {
  18542. previousContainerStyles = {
  18543. top: drawerEl.style.top,
  18544. bottom: drawerEl.style.bottom,
  18545. height: drawerEl.style.height
  18546. };
  18547. // When the parent is scrolled down, then we want to be able to show the sidenav at the current scroll
  18548. // position. We're moving the sidenav down to the correct scroll position and apply the height of the
  18549. // parent, to increase the performance. Using 100% as height, will impact the performance heavily.
  18550. var positionStyle = {
  18551. top: scrollTop + 'px',
  18552. bottom: 'auto',
  18553. height: parent[0].clientHeight + 'px'
  18554. };
  18555. // Apply the new position styles to the sidenav and backdrop.
  18556. element.css(positionStyle);
  18557. backdrop.css(positionStyle);
  18558. }
  18559. // When the sidenav is closing and we have previous defined container styles,
  18560. // then we return a restore function, which resets the sidenav and backdrop.
  18561. if (!willOpen && previousContainerStyles) {
  18562. return function() {
  18563. drawerEl.style.top = previousContainerStyles.top;
  18564. drawerEl.style.bottom = previousContainerStyles.bottom;
  18565. drawerEl.style.height = previousContainerStyles.height;
  18566. backdrop[0].style.top = null;
  18567. backdrop[0].style.bottom = null;
  18568. backdrop[0].style.height = null;
  18569. previousContainerStyles = null;
  18570. };
  18571. }
  18572. }
  18573. /**
  18574. * Prevent parent scrolling (when the SideNav is open)
  18575. */
  18576. function disableParentScroll(disabled) {
  18577. if ( disabled && !lastParentOverFlow ) {
  18578. lastParentOverFlow = disableScrollTarget.css('overflow');
  18579. disableScrollTarget.css('overflow', 'hidden');
  18580. } else if (angular.isDefined(lastParentOverFlow)) {
  18581. disableScrollTarget.css('overflow', lastParentOverFlow);
  18582. lastParentOverFlow = undefined;
  18583. }
  18584. }
  18585. /**
  18586. * Toggle the sideNav view and publish a promise to be resolved when
  18587. * the view animation finishes.
  18588. *
  18589. * @param isOpen
  18590. * @returns {*}
  18591. */
  18592. function toggleOpen( isOpen ) {
  18593. if (scope.isOpen == isOpen ) {
  18594. return $q.when(true);
  18595. } else {
  18596. if (scope.isOpen && sidenavCtrl.onCloseCb) sidenavCtrl.onCloseCb();
  18597. return $q(function(resolve){
  18598. // Toggle value to force an async `updateIsOpen()` to run
  18599. scope.isOpen = isOpen;
  18600. $mdUtil.nextTick(function() {
  18601. // When the current `updateIsOpen()` animation finishes
  18602. promise.then(function(result) {
  18603. if ( !scope.isOpen && triggeringElement && triggeringInteractionType === 'keyboard') {
  18604. // reset focus to originating element (if available) upon close
  18605. triggeringElement.focus();
  18606. triggeringElement = null;
  18607. }
  18608. resolve(result);
  18609. });
  18610. });
  18611. });
  18612. }
  18613. }
  18614. /**
  18615. * Auto-close sideNav when the `escape` key is pressed.
  18616. * @param evt
  18617. */
  18618. function onKeyDown(ev) {
  18619. var isEscape = (ev.keyCode === $mdConstant.KEY_CODE.ESCAPE);
  18620. return isEscape ? close(ev) : $q.when(true);
  18621. }
  18622. /**
  18623. * With backdrop `clicks` or `escape` key-press, immediately
  18624. * apply the CSS close transition... Then notify the controller
  18625. * to close() and perform its own actions.
  18626. */
  18627. function close(ev) {
  18628. ev.preventDefault();
  18629. return sidenavCtrl.close();
  18630. }
  18631. }
  18632. }
  18633. /*
  18634. * @private
  18635. * @ngdoc controller
  18636. * @name SidenavController
  18637. * @module material.components.sidenav
  18638. */
  18639. function SidenavController($scope, $attrs, $mdComponentRegistry, $q, $interpolate) {
  18640. var self = this;
  18641. // Use Default internal method until overridden by directive postLink
  18642. // Synchronous getters
  18643. self.isOpen = function() { return !!$scope.isOpen; };
  18644. self.isLockedOpen = function() { return !!$scope.isLockedOpen; };
  18645. // Synchronous setters
  18646. self.onClose = function (callback) {
  18647. self.onCloseCb = callback;
  18648. return self;
  18649. };
  18650. // Async actions
  18651. self.open = function() { return self.$toggleOpen( true ); };
  18652. self.close = function() { return self.$toggleOpen( false ); };
  18653. self.toggle = function() { return self.$toggleOpen( !$scope.isOpen ); };
  18654. self.$toggleOpen = function(value) { return $q.when($scope.isOpen = value); };
  18655. // Evaluate the component id.
  18656. var rawId = $attrs.mdComponentId;
  18657. var hasDataBinding = rawId && rawId.indexOf($interpolate.startSymbol()) > -1;
  18658. var componentId = hasDataBinding ? $interpolate(rawId)($scope.$parent) : rawId;
  18659. // Register the component.
  18660. self.destroy = $mdComponentRegistry.register(self, componentId);
  18661. // Watch and update the component, if the id has changed.
  18662. if (hasDataBinding) {
  18663. $attrs.$observe('mdComponentId', function(id) {
  18664. if (id && id !== self.$$mdHandle) {
  18665. self.destroy(); // `destroy` only deregisters the old component id so we can add the new one.
  18666. self.destroy = $mdComponentRegistry.register(self, id);
  18667. }
  18668. });
  18669. }
  18670. }
  18671. })();
  18672. (function(){
  18673. "use strict";
  18674. /**
  18675. * @ngdoc module
  18676. * @name material.components.slider
  18677. */
  18678. SliderDirective.$inject = ["$$rAF", "$window", "$mdAria", "$mdUtil", "$mdConstant", "$mdTheming", "$mdGesture", "$parse", "$log", "$timeout"];
  18679. angular.module('material.components.slider', [
  18680. 'material.core'
  18681. ])
  18682. .directive('mdSlider', SliderDirective)
  18683. .directive('mdSliderContainer', SliderContainerDirective);
  18684. /**
  18685. * @ngdoc directive
  18686. * @name mdSliderContainer
  18687. * @module material.components.slider
  18688. * @restrict E
  18689. * @description
  18690. * The `<md-slider-container>` can hold the slider with two other elements.
  18691. * In this case, the other elements are a `span` for the label and an `input` for displaying
  18692. * the model value.
  18693. *
  18694. * @usage
  18695. * <hljs lang="html">
  18696. * <md-slider-container>
  18697. * <span>Red</span>
  18698. * <md-slider min="0" max="255" ng-model="color.red" aria-label="red" id="red-slider">
  18699. * </md-slider>
  18700. * <md-input-container>
  18701. * <input type="number" ng-model="color.red" aria-label="Red" aria-controls="red-slider">
  18702. * </md-input-container>
  18703. * </md-slider-container>
  18704. * </hljs>
  18705. */
  18706. function SliderContainerDirective() {
  18707. return {
  18708. controller: function () {},
  18709. compile: function (elem) {
  18710. var slider = elem.find('md-slider');
  18711. if (!slider) {
  18712. return;
  18713. }
  18714. var vertical = slider.attr('md-vertical');
  18715. if (vertical !== undefined) {
  18716. elem.attr('md-vertical', '');
  18717. }
  18718. if(!slider.attr('flex')) {
  18719. slider.attr('flex', '');
  18720. }
  18721. return function postLink(scope, element, attr, ctrl) {
  18722. element.addClass('_md'); // private md component indicator for styling
  18723. // We have to manually stop the $watch on ngDisabled because it exists
  18724. // on the parent scope, and won't be automatically destroyed when
  18725. // the component is destroyed.
  18726. function setDisable(value) {
  18727. element.children().attr('disabled', value);
  18728. element.find('input').attr('disabled', value);
  18729. }
  18730. var stopDisabledWatch = angular.noop;
  18731. if (attr.disabled) {
  18732. setDisable(true);
  18733. }
  18734. else if (attr.ngDisabled) {
  18735. stopDisabledWatch = scope.$watch(attr.ngDisabled, function (value) {
  18736. setDisable(value);
  18737. });
  18738. }
  18739. scope.$on('$destroy', function () {
  18740. stopDisabledWatch();
  18741. });
  18742. var initialMaxWidth;
  18743. ctrl.fitInputWidthToTextLength = function (length) {
  18744. var input = element[0].querySelector('md-input-container');
  18745. if (input) {
  18746. var computedStyle = getComputedStyle(input);
  18747. var minWidth = parseInt(computedStyle.minWidth);
  18748. var padding = parseInt(computedStyle.paddingLeft) + parseInt(computedStyle.paddingRight);
  18749. initialMaxWidth = initialMaxWidth || parseInt(computedStyle.maxWidth);
  18750. var newMaxWidth = Math.max(initialMaxWidth, minWidth + padding + (minWidth / 2 * length));
  18751. input.style.maxWidth = newMaxWidth + 'px';
  18752. }
  18753. };
  18754. };
  18755. }
  18756. };
  18757. }
  18758. /**
  18759. * @ngdoc directive
  18760. * @name mdSlider
  18761. * @module material.components.slider
  18762. * @restrict E
  18763. * @description
  18764. * The `<md-slider>` component allows the user to choose from a range of values.
  18765. *
  18766. * As per the [material design spec](https://material.io/guidelines/style/color.html#color-color-system)
  18767. * the slider is in the accent color by default. The primary color palette may be used with
  18768. * the `md-primary` class.
  18769. *
  18770. * It has two modes:
  18771. * - "normal" mode where the user slides between a wide range of values
  18772. * - "discrete" mode where the user slides between only a few select values
  18773. *
  18774. * To enable discrete mode, add the `md-discrete` attribute to a slider
  18775. * and use the `step` attribute to change the distance between
  18776. * values the user is allowed to pick.
  18777. *
  18778. * When using the keyboard, holding the Meta, Control, or Alt key while pressing the left
  18779. * and right arrow buttons will cause the slider to move 4 steps.
  18780. *
  18781. * @usage
  18782. * <h4>Normal Mode</h4>
  18783. * <hljs lang="html">
  18784. * <md-slider ng-model="myValue" min="5" max="500">
  18785. * </md-slider>
  18786. * </hljs>
  18787. * <h4>Discrete Mode</h4>
  18788. * <hljs lang="html">
  18789. * <md-slider md-discrete ng-model="myDiscreteValue" step="10" min="10" max="130">
  18790. * </md-slider>
  18791. * </hljs>
  18792. * <h4>Invert Mode</h4>
  18793. * <hljs lang="html">
  18794. * <md-slider md-invert ng-model="myValue" step="10" min="10" max="130">
  18795. * </md-slider>
  18796. * </hljs>
  18797. *
  18798. * @param {expression} ng-model Assignable angular expression to be data-bound.
  18799. * The expression should evaluate to a `number`.
  18800. * @param {boolean=} md-discrete Whether to enable discrete mode.
  18801. * @param {boolean=} md-invert Whether to enable invert mode.
  18802. * @param {number=} step The distance between values the user is allowed to pick. Default `1`.
  18803. * @param {number=} min The minimum value the user is allowed to pick. Default `0`.
  18804. * @param {number=} max The maximum value the user is allowed to pick. Default `100`.
  18805. * @param {number=} round The amount of numbers after the decimal point. The maximum is 6 to
  18806. * prevent scientific notation. Default `3`.
  18807. */
  18808. function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdTheming, $mdGesture,
  18809. $parse, $log, $timeout) {
  18810. return {
  18811. scope: {},
  18812. require: ['?ngModel', '?^mdSliderContainer'],
  18813. template:
  18814. '<div class="md-slider-wrapper">' +
  18815. '<div class="md-slider-content">' +
  18816. '<div class="md-track-container">' +
  18817. '<div class="md-track"></div>' +
  18818. '<div class="md-track md-track-fill"></div>' +
  18819. '<div class="md-track-ticks"></div>' +
  18820. '</div>' +
  18821. '<div class="md-thumb-container">' +
  18822. '<div class="md-thumb"></div>' +
  18823. '<div class="md-focus-thumb"></div>' +
  18824. '<div class="md-focus-ring"></div>' +
  18825. '<div class="md-sign">' +
  18826. '<span class="md-thumb-text"></span>' +
  18827. '</div>' +
  18828. '<div class="md-disabled-thumb"></div>' +
  18829. '</div>' +
  18830. '</div>' +
  18831. '</div>',
  18832. compile: compile
  18833. };
  18834. // **********************************************************
  18835. // Private Methods
  18836. // **********************************************************
  18837. function compile (tElement, tAttrs) {
  18838. var wrapper = angular.element(tElement[0].getElementsByClassName('md-slider-wrapper'));
  18839. var tabIndex = tAttrs.tabindex || 0;
  18840. wrapper.attr('tabindex', tabIndex);
  18841. if (tAttrs.disabled || tAttrs.ngDisabled) wrapper.attr('tabindex', -1);
  18842. tElement.attr('role', 'slider');
  18843. $mdAria.expect(tElement, 'aria-label');
  18844. return postLink;
  18845. }
  18846. function postLink(scope, element, attr, ctrls) {
  18847. $mdTheming(element);
  18848. var ngModelCtrl = ctrls[0] || {
  18849. // Mock ngModelController if it doesn't exist to give us
  18850. // the minimum functionality needed
  18851. $setViewValue: function(val) {
  18852. this.$viewValue = val;
  18853. this.$viewChangeListeners.forEach(function(cb) { cb(); });
  18854. },
  18855. $parsers: [],
  18856. $formatters: [],
  18857. $viewChangeListeners: []
  18858. };
  18859. var containerCtrl = ctrls[1];
  18860. var container = angular.element($mdUtil.getClosest(element, '_md-slider-container', true));
  18861. var isDisabled = attr.ngDisabled ? angular.bind(null, $parse(attr.ngDisabled), scope.$parent) : function () {
  18862. return element[0].hasAttribute('disabled');
  18863. };
  18864. var thumb = angular.element(element[0].querySelector('.md-thumb'));
  18865. var thumbText = angular.element(element[0].querySelector('.md-thumb-text'));
  18866. var thumbContainer = thumb.parent();
  18867. var trackContainer = angular.element(element[0].querySelector('.md-track-container'));
  18868. var activeTrack = angular.element(element[0].querySelector('.md-track-fill'));
  18869. var tickContainer = angular.element(element[0].querySelector('.md-track-ticks'));
  18870. var wrapper = angular.element(element[0].getElementsByClassName('md-slider-wrapper'));
  18871. var content = angular.element(element[0].getElementsByClassName('md-slider-content'));
  18872. var throttledRefreshDimensions = $mdUtil.throttle(refreshSliderDimensions, 5000);
  18873. // Default values, overridable by attrs
  18874. var DEFAULT_ROUND = 3;
  18875. var vertical = angular.isDefined(attr.mdVertical);
  18876. var discrete = angular.isDefined(attr.mdDiscrete);
  18877. var invert = angular.isDefined(attr.mdInvert);
  18878. angular.isDefined(attr.min) ? attr.$observe('min', updateMin) : updateMin(0);
  18879. angular.isDefined(attr.max) ? attr.$observe('max', updateMax) : updateMax(100);
  18880. angular.isDefined(attr.step)? attr.$observe('step', updateStep) : updateStep(1);
  18881. angular.isDefined(attr.round)? attr.$observe('round', updateRound) : updateRound(DEFAULT_ROUND);
  18882. // We have to manually stop the $watch on ngDisabled because it exists
  18883. // on the parent scope, and won't be automatically destroyed when
  18884. // the component is destroyed.
  18885. var stopDisabledWatch = angular.noop;
  18886. if (attr.ngDisabled) {
  18887. stopDisabledWatch = scope.$parent.$watch(attr.ngDisabled, updateAriaDisabled);
  18888. }
  18889. $mdGesture.register(wrapper, 'drag', { horizontal: !vertical });
  18890. scope.mouseActive = false;
  18891. wrapper
  18892. .on('keydown', keydownListener)
  18893. .on('mousedown', mouseDownListener)
  18894. .on('focus', focusListener)
  18895. .on('blur', blurListener)
  18896. .on('$md.pressdown', onPressDown)
  18897. .on('$md.pressup', onPressUp)
  18898. .on('$md.dragstart', onDragStart)
  18899. .on('$md.drag', onDrag)
  18900. .on('$md.dragend', onDragEnd);
  18901. // On resize, recalculate the slider's dimensions and re-render
  18902. function updateAll() {
  18903. refreshSliderDimensions();
  18904. ngModelRender();
  18905. }
  18906. setTimeout(updateAll, 0);
  18907. var debouncedUpdateAll = $$rAF.throttle(updateAll);
  18908. angular.element($window).on('resize', debouncedUpdateAll);
  18909. scope.$on('$destroy', function() {
  18910. angular.element($window).off('resize', debouncedUpdateAll);
  18911. });
  18912. ngModelCtrl.$render = ngModelRender;
  18913. ngModelCtrl.$viewChangeListeners.push(ngModelRender);
  18914. ngModelCtrl.$formatters.push(minMaxValidator);
  18915. ngModelCtrl.$formatters.push(stepValidator);
  18916. /**
  18917. * Attributes
  18918. */
  18919. var min;
  18920. var max;
  18921. var step;
  18922. var round;
  18923. function updateMin(value) {
  18924. min = parseFloat(value);
  18925. ngModelCtrl.$viewValue = minMaxValidator(ngModelCtrl.$modelValue, min, max);
  18926. element.attr('aria-valuemin', value);
  18927. updateAll();
  18928. }
  18929. function updateMax(value) {
  18930. max = parseFloat(value);
  18931. ngModelCtrl.$viewValue = minMaxValidator(ngModelCtrl.$modelValue, min, max);
  18932. element.attr('aria-valuemax', value);
  18933. updateAll();
  18934. }
  18935. function updateStep(value) {
  18936. step = parseFloat(value);
  18937. }
  18938. function updateRound(value) {
  18939. // Set max round digits to 6, after 6 the input uses scientific notation
  18940. round = minMaxValidator(parseInt(value), 0, 6);
  18941. }
  18942. function updateAriaDisabled() {
  18943. element.attr('aria-disabled', !!isDisabled());
  18944. }
  18945. // Draw the ticks with canvas.
  18946. // The alternative to drawing ticks with canvas is to draw one element for each tick,
  18947. // which could quickly become a performance bottleneck.
  18948. var tickCanvas, tickCtx;
  18949. function redrawTicks() {
  18950. if (!discrete || isDisabled()) return;
  18951. if ( angular.isUndefined(step) ) return;
  18952. if ( step <= 0 ) {
  18953. var msg = 'Slider step value must be greater than zero when in discrete mode';
  18954. $log.error(msg);
  18955. throw new Error(msg);
  18956. }
  18957. var numSteps = Math.floor( (max - min) / step );
  18958. if (!tickCanvas) {
  18959. tickCanvas = angular.element('<canvas>').css('position', 'absolute');
  18960. tickContainer.append(tickCanvas);
  18961. tickCtx = tickCanvas[0].getContext('2d');
  18962. }
  18963. var dimensions = getSliderDimensions();
  18964. // If `dimensions` doesn't have height and width it might be the first attempt so we will refresh dimensions
  18965. if (dimensions && !dimensions.height && !dimensions.width) {
  18966. refreshSliderDimensions();
  18967. dimensions = sliderDimensions;
  18968. }
  18969. tickCanvas[0].width = dimensions.width;
  18970. tickCanvas[0].height = dimensions.height;
  18971. var distance;
  18972. for (var i = 0; i <= numSteps; i++) {
  18973. var trackTicksStyle = $window.getComputedStyle(tickContainer[0]);
  18974. tickCtx.fillStyle = trackTicksStyle.color || 'black';
  18975. distance = Math.floor((vertical ? dimensions.height : dimensions.width) * (i / numSteps));
  18976. tickCtx.fillRect(vertical ? 0 : distance - 1,
  18977. vertical ? distance - 1 : 0,
  18978. vertical ? dimensions.width : 2,
  18979. vertical ? 2 : dimensions.height);
  18980. }
  18981. }
  18982. function clearTicks() {
  18983. if(tickCanvas && tickCtx) {
  18984. var dimensions = getSliderDimensions();
  18985. tickCtx.clearRect(0, 0, dimensions.width, dimensions.height);
  18986. }
  18987. }
  18988. /**
  18989. * Refreshing Dimensions
  18990. */
  18991. var sliderDimensions = {};
  18992. refreshSliderDimensions();
  18993. function refreshSliderDimensions() {
  18994. sliderDimensions = trackContainer[0].getBoundingClientRect();
  18995. }
  18996. function getSliderDimensions() {
  18997. throttledRefreshDimensions();
  18998. return sliderDimensions;
  18999. }
  19000. /**
  19001. * left/right/up/down arrow listener
  19002. */
  19003. function keydownListener(ev) {
  19004. if (isDisabled()) return;
  19005. var changeAmount;
  19006. if (vertical ? ev.keyCode === $mdConstant.KEY_CODE.DOWN_ARROW : ev.keyCode === $mdConstant.KEY_CODE.LEFT_ARROW) {
  19007. changeAmount = -step;
  19008. } else if (vertical ? ev.keyCode === $mdConstant.KEY_CODE.UP_ARROW : ev.keyCode === $mdConstant.KEY_CODE.RIGHT_ARROW) {
  19009. changeAmount = step;
  19010. }
  19011. changeAmount = invert ? -changeAmount : changeAmount;
  19012. if (changeAmount) {
  19013. if (ev.metaKey || ev.ctrlKey || ev.altKey) {
  19014. changeAmount *= 4;
  19015. }
  19016. ev.preventDefault();
  19017. ev.stopPropagation();
  19018. scope.$evalAsync(function() {
  19019. setModelValue(ngModelCtrl.$viewValue + changeAmount);
  19020. });
  19021. }
  19022. }
  19023. function mouseDownListener() {
  19024. redrawTicks();
  19025. scope.mouseActive = true;
  19026. wrapper.removeClass('md-focused');
  19027. $timeout(function() {
  19028. scope.mouseActive = false;
  19029. }, 100);
  19030. }
  19031. function focusListener() {
  19032. if (scope.mouseActive === false) {
  19033. wrapper.addClass('md-focused');
  19034. }
  19035. }
  19036. function blurListener() {
  19037. wrapper.removeClass('md-focused');
  19038. element.removeClass('md-active');
  19039. clearTicks();
  19040. }
  19041. /**
  19042. * ngModel setters and validators
  19043. */
  19044. function setModelValue(value) {
  19045. ngModelCtrl.$setViewValue( minMaxValidator(stepValidator(value)) );
  19046. }
  19047. function ngModelRender() {
  19048. if (isNaN(ngModelCtrl.$viewValue)) {
  19049. ngModelCtrl.$viewValue = ngModelCtrl.$modelValue;
  19050. }
  19051. ngModelCtrl.$viewValue = minMaxValidator(ngModelCtrl.$viewValue);
  19052. var percent = valueToPercent(ngModelCtrl.$viewValue);
  19053. scope.modelValue = ngModelCtrl.$viewValue;
  19054. element.attr('aria-valuenow', ngModelCtrl.$viewValue);
  19055. setSliderPercent(percent);
  19056. thumbText.text( ngModelCtrl.$viewValue );
  19057. }
  19058. function minMaxValidator(value, minValue, maxValue) {
  19059. if (angular.isNumber(value)) {
  19060. minValue = angular.isNumber(minValue) ? minValue : min;
  19061. maxValue = angular.isNumber(maxValue) ? maxValue : max;
  19062. return Math.max(minValue, Math.min(maxValue, value));
  19063. }
  19064. }
  19065. function stepValidator(value) {
  19066. if (angular.isNumber(value)) {
  19067. var formattedValue = (Math.round((value - min) / step) * step + min);
  19068. formattedValue = (Math.round(formattedValue * Math.pow(10, round)) / Math.pow(10, round));
  19069. if (containerCtrl && containerCtrl.fitInputWidthToTextLength){
  19070. $mdUtil.debounce(function () {
  19071. containerCtrl.fitInputWidthToTextLength(formattedValue.toString().length);
  19072. }, 100)();
  19073. }
  19074. return formattedValue;
  19075. }
  19076. }
  19077. /**
  19078. * @param percent 0-1
  19079. */
  19080. function setSliderPercent(percent) {
  19081. percent = clamp(percent);
  19082. var thumbPosition = (percent * 100) + '%';
  19083. var activeTrackPercent = invert ? (1 - percent) * 100 + '%' : thumbPosition;
  19084. if (vertical) {
  19085. thumbContainer.css('bottom', thumbPosition);
  19086. }
  19087. else {
  19088. $mdUtil.bidiProperty(thumbContainer, 'left', 'right', thumbPosition);
  19089. }
  19090. activeTrack.css(vertical ? 'height' : 'width', activeTrackPercent);
  19091. element.toggleClass((invert ? 'md-max' : 'md-min'), percent === 0);
  19092. element.toggleClass((invert ? 'md-min' : 'md-max'), percent === 1);
  19093. }
  19094. /**
  19095. * Slide listeners
  19096. */
  19097. var isDragging = false;
  19098. function onPressDown(ev) {
  19099. if (isDisabled()) return;
  19100. element.addClass('md-active');
  19101. element[0].focus();
  19102. refreshSliderDimensions();
  19103. var exactVal = percentToValue( positionToPercent( vertical ? ev.pointer.y : ev.pointer.x ));
  19104. var closestVal = minMaxValidator( stepValidator(exactVal) );
  19105. scope.$apply(function() {
  19106. setModelValue( closestVal );
  19107. setSliderPercent( valueToPercent(closestVal));
  19108. });
  19109. }
  19110. function onPressUp(ev) {
  19111. if (isDisabled()) return;
  19112. element.removeClass('md-dragging');
  19113. var exactVal = percentToValue( positionToPercent( vertical ? ev.pointer.y : ev.pointer.x ));
  19114. var closestVal = minMaxValidator( stepValidator(exactVal) );
  19115. scope.$apply(function() {
  19116. setModelValue(closestVal);
  19117. ngModelRender();
  19118. });
  19119. }
  19120. function onDragStart(ev) {
  19121. if (isDisabled()) return;
  19122. isDragging = true;
  19123. ev.stopPropagation();
  19124. element.addClass('md-dragging');
  19125. setSliderFromEvent(ev);
  19126. }
  19127. function onDrag(ev) {
  19128. if (!isDragging) return;
  19129. ev.stopPropagation();
  19130. setSliderFromEvent(ev);
  19131. }
  19132. function onDragEnd(ev) {
  19133. if (!isDragging) return;
  19134. ev.stopPropagation();
  19135. isDragging = false;
  19136. }
  19137. function setSliderFromEvent(ev) {
  19138. // While panning discrete, update only the
  19139. // visual positioning but not the model value.
  19140. if ( discrete ) adjustThumbPosition( vertical ? ev.pointer.y : ev.pointer.x );
  19141. else doSlide( vertical ? ev.pointer.y : ev.pointer.x );
  19142. }
  19143. /**
  19144. * Slide the UI by changing the model value
  19145. * @param x
  19146. */
  19147. function doSlide( x ) {
  19148. scope.$evalAsync( function() {
  19149. setModelValue( percentToValue( positionToPercent(x) ));
  19150. });
  19151. }
  19152. /**
  19153. * Slide the UI without changing the model (while dragging/panning)
  19154. * @param x
  19155. */
  19156. function adjustThumbPosition( x ) {
  19157. var exactVal = percentToValue( positionToPercent( x ));
  19158. var closestVal = minMaxValidator( stepValidator(exactVal) );
  19159. setSliderPercent( positionToPercent(x) );
  19160. thumbText.text( closestVal );
  19161. }
  19162. /**
  19163. * Clamps the value to be between 0 and 1.
  19164. * @param {number} value The value to clamp.
  19165. * @returns {number}
  19166. */
  19167. function clamp(value) {
  19168. return Math.max(0, Math.min(value || 0, 1));
  19169. }
  19170. /**
  19171. * Convert position on slider to percentage value of offset from beginning...
  19172. * @param position
  19173. * @returns {number}
  19174. */
  19175. function positionToPercent( position ) {
  19176. var offset = vertical ? sliderDimensions.top : sliderDimensions.left;
  19177. var size = vertical ? sliderDimensions.height : sliderDimensions.width;
  19178. var calc = (position - offset) / size;
  19179. if (!vertical && $mdUtil.bidi() === 'rtl') {
  19180. calc = 1 - calc;
  19181. }
  19182. return Math.max(0, Math.min(1, vertical ? 1 - calc : calc));
  19183. }
  19184. /**
  19185. * Convert percentage offset on slide to equivalent model value
  19186. * @param percent
  19187. * @returns {*}
  19188. */
  19189. function percentToValue( percent ) {
  19190. var adjustedPercent = invert ? (1 - percent) : percent;
  19191. return (min + adjustedPercent * (max - min));
  19192. }
  19193. function valueToPercent( val ) {
  19194. var percent = (val - min) / (max - min);
  19195. return invert ? (1 - percent) : percent;
  19196. }
  19197. }
  19198. }
  19199. })();
  19200. (function(){
  19201. "use strict";
  19202. /**
  19203. * @ngdoc module
  19204. * @name material.components.sticky
  19205. * @description
  19206. * Sticky effects for md
  19207. *
  19208. */
  19209. MdSticky.$inject = ["$mdConstant", "$$rAF", "$mdUtil", "$compile"];
  19210. angular
  19211. .module('material.components.sticky', [
  19212. 'material.core',
  19213. 'material.components.content'
  19214. ])
  19215. .factory('$mdSticky', MdSticky);
  19216. /**
  19217. * @ngdoc service
  19218. * @name $mdSticky
  19219. * @module material.components.sticky
  19220. *
  19221. * @description
  19222. * The `$mdSticky`service provides a mixin to make elements sticky.
  19223. *
  19224. * Whenever the current browser supports stickiness natively, the `$mdSticky` service will just
  19225. * use the native browser stickiness.
  19226. *
  19227. * By default the `$mdSticky` service compiles the cloned element, when not specified through the `elementClone`
  19228. * parameter, in the same scope as the actual element lives.
  19229. *
  19230. *
  19231. * <h3>Notes</h3>
  19232. * When using an element which is containing a compiled directive, which changed its DOM structure during compilation,
  19233. * you should compile the clone yourself using the plain template.<br/><br/>
  19234. * See the right usage below:
  19235. * <hljs lang="js">
  19236. * angular.module('myModule')
  19237. * .directive('stickySelect', function($mdSticky, $compile) {
  19238. * var SELECT_TEMPLATE =
  19239. * '<md-select ng-model="selected">' +
  19240. * '<md-option>Option 1</md-option>' +
  19241. * '</md-select>';
  19242. *
  19243. * return {
  19244. * restrict: 'E',
  19245. * replace: true,
  19246. * template: SELECT_TEMPLATE,
  19247. * link: function(scope,element) {
  19248. * $mdSticky(scope, element, $compile(SELECT_TEMPLATE)(scope));
  19249. * }
  19250. * };
  19251. * });
  19252. * </hljs>
  19253. *
  19254. * @usage
  19255. * <hljs lang="js">
  19256. * angular.module('myModule')
  19257. * .directive('stickyText', function($mdSticky, $compile) {
  19258. * return {
  19259. * restrict: 'E',
  19260. * template: '<span>Sticky Text</span>',
  19261. * link: function(scope,element) {
  19262. * $mdSticky(scope, element);
  19263. * }
  19264. * };
  19265. * });
  19266. * </hljs>
  19267. *
  19268. * @returns A `$mdSticky` function that takes three arguments:
  19269. * - `scope`
  19270. * - `element`: The element that will be 'sticky'
  19271. * - `elementClone`: A clone of the element, that will be shown
  19272. * when the user starts scrolling past the original element.
  19273. * If not provided, it will use the result of `element.clone()` and compiles it in the given scope.
  19274. */
  19275. function MdSticky($mdConstant, $$rAF, $mdUtil, $compile) {
  19276. var browserStickySupport = $mdUtil.checkStickySupport();
  19277. /**
  19278. * Registers an element as sticky, used internally by directives to register themselves
  19279. */
  19280. return function registerStickyElement(scope, element, stickyClone) {
  19281. var contentCtrl = element.controller('mdContent');
  19282. if (!contentCtrl) return;
  19283. if (browserStickySupport) {
  19284. element.css({
  19285. position: browserStickySupport,
  19286. top: 0,
  19287. 'z-index': 2
  19288. });
  19289. } else {
  19290. var $$sticky = contentCtrl.$element.data('$$sticky');
  19291. if (!$$sticky) {
  19292. $$sticky = setupSticky(contentCtrl);
  19293. contentCtrl.$element.data('$$sticky', $$sticky);
  19294. }
  19295. // Compile our cloned element, when cloned in this service, into the given scope.
  19296. var cloneElement = stickyClone || $compile(element.clone())(scope);
  19297. var deregister = $$sticky.add(element, cloneElement);
  19298. scope.$on('$destroy', deregister);
  19299. }
  19300. };
  19301. function setupSticky(contentCtrl) {
  19302. var contentEl = contentCtrl.$element;
  19303. // Refresh elements is very expensive, so we use the debounced
  19304. // version when possible.
  19305. var debouncedRefreshElements = $$rAF.throttle(refreshElements);
  19306. // setupAugmentedScrollEvents gives us `$scrollstart` and `$scroll`,
  19307. // more reliable than `scroll` on android.
  19308. setupAugmentedScrollEvents(contentEl);
  19309. contentEl.on('$scrollstart', debouncedRefreshElements);
  19310. contentEl.on('$scroll', onScroll);
  19311. var self;
  19312. return self = {
  19313. prev: null,
  19314. current: null, //the currently stickied item
  19315. next: null,
  19316. items: [],
  19317. add: add,
  19318. refreshElements: refreshElements
  19319. };
  19320. /***************
  19321. * Public
  19322. ***************/
  19323. // Add an element and its sticky clone to this content's sticky collection
  19324. function add(element, stickyClone) {
  19325. stickyClone.addClass('md-sticky-clone');
  19326. var item = {
  19327. element: element,
  19328. clone: stickyClone
  19329. };
  19330. self.items.push(item);
  19331. $mdUtil.nextTick(function() {
  19332. contentEl.prepend(item.clone);
  19333. });
  19334. debouncedRefreshElements();
  19335. return function remove() {
  19336. self.items.forEach(function(item, index) {
  19337. if (item.element[0] === element[0]) {
  19338. self.items.splice(index, 1);
  19339. item.clone.remove();
  19340. }
  19341. });
  19342. debouncedRefreshElements();
  19343. };
  19344. }
  19345. function refreshElements() {
  19346. // Sort our collection of elements by their current position in the DOM.
  19347. // We need to do this because our elements' order of being added may not
  19348. // be the same as their order of display.
  19349. self.items.forEach(refreshPosition);
  19350. self.items = self.items.sort(function(a, b) {
  19351. return a.top < b.top ? -1 : 1;
  19352. });
  19353. // Find which item in the list should be active,
  19354. // based upon the content's current scroll position
  19355. var item;
  19356. var currentScrollTop = contentEl.prop('scrollTop');
  19357. for (var i = self.items.length - 1; i >= 0; i--) {
  19358. if (currentScrollTop > self.items[i].top) {
  19359. item = self.items[i];
  19360. break;
  19361. }
  19362. }
  19363. setCurrentItem(item);
  19364. }
  19365. /***************
  19366. * Private
  19367. ***************/
  19368. // Find the `top` of an item relative to the content element,
  19369. // and also the height.
  19370. function refreshPosition(item) {
  19371. // Find the top of an item by adding to the offsetHeight until we reach the
  19372. // content element.
  19373. var current = item.element[0];
  19374. item.top = 0;
  19375. item.left = 0;
  19376. item.right = 0;
  19377. while (current && current !== contentEl[0]) {
  19378. item.top += current.offsetTop;
  19379. item.left += current.offsetLeft;
  19380. if ( current.offsetParent ){
  19381. item.right += current.offsetParent.offsetWidth - current.offsetWidth - current.offsetLeft; //Compute offsetRight
  19382. }
  19383. current = current.offsetParent;
  19384. }
  19385. item.height = item.element.prop('offsetHeight');
  19386. var defaultVal = $mdUtil.floatingScrollbars() ? '0' : undefined;
  19387. $mdUtil.bidi(item.clone, 'margin-left', item.left, defaultVal);
  19388. $mdUtil.bidi(item.clone, 'margin-right', defaultVal, item.right);
  19389. }
  19390. // As we scroll, push in and select the correct sticky element.
  19391. function onScroll() {
  19392. var scrollTop = contentEl.prop('scrollTop');
  19393. var isScrollingDown = scrollTop > (onScroll.prevScrollTop || 0);
  19394. // Store the previous scroll so we know which direction we are scrolling
  19395. onScroll.prevScrollTop = scrollTop;
  19396. //
  19397. // AT TOP (not scrolling)
  19398. //
  19399. if (scrollTop === 0) {
  19400. // If we're at the top, just clear the current item and return
  19401. setCurrentItem(null);
  19402. return;
  19403. }
  19404. //
  19405. // SCROLLING DOWN (going towards the next item)
  19406. //
  19407. if (isScrollingDown) {
  19408. // If we've scrolled down past the next item's position, sticky it and return
  19409. if (self.next && self.next.top <= scrollTop) {
  19410. setCurrentItem(self.next);
  19411. return;
  19412. }
  19413. // If the next item is close to the current one, push the current one up out of the way
  19414. if (self.current && self.next && self.next.top - scrollTop <= self.next.height) {
  19415. translate(self.current, scrollTop + (self.next.top - self.next.height - scrollTop));
  19416. return;
  19417. }
  19418. }
  19419. //
  19420. // SCROLLING UP (not at the top & not scrolling down; must be scrolling up)
  19421. //
  19422. if (!isScrollingDown) {
  19423. // If we've scrolled up past the previous item's position, sticky it and return
  19424. if (self.current && self.prev && scrollTop < self.current.top) {
  19425. setCurrentItem(self.prev);
  19426. return;
  19427. }
  19428. // If the next item is close to the current one, pull the current one down into view
  19429. if (self.next && self.current && (scrollTop >= (self.next.top - self.current.height))) {
  19430. translate(self.current, scrollTop + (self.next.top - scrollTop - self.current.height));
  19431. return;
  19432. }
  19433. }
  19434. //
  19435. // Otherwise, just move the current item to the proper place (scrolling up or down)
  19436. //
  19437. if (self.current) {
  19438. translate(self.current, scrollTop);
  19439. }
  19440. }
  19441. function setCurrentItem(item) {
  19442. if (self.current === item) return;
  19443. // Deactivate currently active item
  19444. if (self.current) {
  19445. translate(self.current, null);
  19446. setStickyState(self.current, null);
  19447. }
  19448. // Activate new item if given
  19449. if (item) {
  19450. setStickyState(item, 'active');
  19451. }
  19452. self.current = item;
  19453. var index = self.items.indexOf(item);
  19454. // If index === -1, index + 1 = 0. It works out.
  19455. self.next = self.items[index + 1];
  19456. self.prev = self.items[index - 1];
  19457. setStickyState(self.next, 'next');
  19458. setStickyState(self.prev, 'prev');
  19459. }
  19460. function setStickyState(item, state) {
  19461. if (!item || item.state === state) return;
  19462. if (item.state) {
  19463. item.clone.attr('sticky-prev-state', item.state);
  19464. item.element.attr('sticky-prev-state', item.state);
  19465. }
  19466. item.clone.attr('sticky-state', state);
  19467. item.element.attr('sticky-state', state);
  19468. item.state = state;
  19469. }
  19470. function translate(item, amount) {
  19471. if (!item) return;
  19472. if (amount === null || amount === undefined) {
  19473. if (item.translateY) {
  19474. item.translateY = null;
  19475. item.clone.css($mdConstant.CSS.TRANSFORM, '');
  19476. }
  19477. } else {
  19478. item.translateY = amount;
  19479. $mdUtil.bidi( item.clone, $mdConstant.CSS.TRANSFORM,
  19480. 'translate3d(' + item.left + 'px,' + amount + 'px,0)',
  19481. 'translateY(' + amount + 'px)'
  19482. );
  19483. }
  19484. }
  19485. }
  19486. // Android 4.4 don't accurately give scroll events.
  19487. // To fix this problem, we setup a fake scroll event. We say:
  19488. // > If a scroll or touchmove event has happened in the last DELAY milliseconds,
  19489. // then send a `$scroll` event every animationFrame.
  19490. // Additionally, we add $scrollstart and $scrollend events.
  19491. function setupAugmentedScrollEvents(element) {
  19492. var SCROLL_END_DELAY = 200;
  19493. var isScrolling;
  19494. var lastScrollTime;
  19495. element.on('scroll touchmove', function() {
  19496. if (!isScrolling) {
  19497. isScrolling = true;
  19498. $$rAF.throttle(loopScrollEvent);
  19499. element.triggerHandler('$scrollstart');
  19500. }
  19501. element.triggerHandler('$scroll');
  19502. lastScrollTime = +$mdUtil.now();
  19503. });
  19504. function loopScrollEvent() {
  19505. if (+$mdUtil.now() - lastScrollTime > SCROLL_END_DELAY) {
  19506. isScrolling = false;
  19507. element.triggerHandler('$scrollend');
  19508. } else {
  19509. element.triggerHandler('$scroll');
  19510. $$rAF.throttle(loopScrollEvent);
  19511. }
  19512. }
  19513. }
  19514. }
  19515. })();
  19516. (function(){
  19517. "use strict";
  19518. /**
  19519. * @ngdoc module
  19520. * @name material.components.subheader
  19521. * @description
  19522. * SubHeader module
  19523. *
  19524. * Subheaders are special list tiles that delineate distinct sections of a
  19525. * list or grid list and are typically related to the current filtering or
  19526. * sorting criteria. Subheader tiles are either displayed inline with tiles or
  19527. * can be associated with content, for example, in an adjacent column.
  19528. *
  19529. * Upon scrolling, subheaders remain pinned to the top of the screen and remain
  19530. * pinned until pushed on or off screen by the next subheader. @see [Material
  19531. * Design Specifications](https://www.google.com/design/spec/components/subheaders.html)
  19532. *
  19533. * > To improve the visual grouping of content, use the system color for your subheaders.
  19534. *
  19535. */
  19536. MdSubheaderDirective.$inject = ["$mdSticky", "$compile", "$mdTheming", "$mdUtil", "$mdAria"];
  19537. angular
  19538. .module('material.components.subheader', [
  19539. 'material.core',
  19540. 'material.components.sticky'
  19541. ])
  19542. .directive('mdSubheader', MdSubheaderDirective);
  19543. /**
  19544. * @ngdoc directive
  19545. * @name mdSubheader
  19546. * @module material.components.subheader
  19547. *
  19548. * @restrict E
  19549. *
  19550. * @description
  19551. * The `md-subheader` directive creates a sticky subheader for a section.
  19552. *
  19553. * Developers are able to disable the stickiness of the subheader by using the following markup
  19554. *
  19555. * <hljs lang="html">
  19556. * <md-subheader class="md-no-sticky">Not Sticky</md-subheader>
  19557. * </hljs>
  19558. *
  19559. * ### Notes
  19560. * - The `md-subheader` directive uses the <a ng-href="api/service/$mdSticky">$mdSticky</a> service
  19561. * to make the subheader sticky.
  19562. *
  19563. * > Whenever the current browser doesn't support stickiness natively, the subheader
  19564. * will be compiled twice to create a sticky clone of the subheader.
  19565. *
  19566. * @usage
  19567. * <hljs lang="html">
  19568. * <md-subheader>Online Friends</md-subheader>
  19569. * </hljs>
  19570. */
  19571. function MdSubheaderDirective($mdSticky, $compile, $mdTheming, $mdUtil, $mdAria) {
  19572. return {
  19573. restrict: 'E',
  19574. replace: true,
  19575. transclude: true,
  19576. template: (
  19577. '<div class="md-subheader _md">' +
  19578. ' <div class="md-subheader-inner">' +
  19579. ' <div class="md-subheader-content"></div>' +
  19580. ' </div>' +
  19581. '</div>'
  19582. ),
  19583. link: function postLink(scope, element, attr, controllers, transclude) {
  19584. $mdTheming(element);
  19585. element.addClass('_md');
  19586. // Remove the ngRepeat attribute from the root element, because we don't want to compile
  19587. // the ngRepeat for the sticky clone again.
  19588. $mdUtil.prefixer().removeAttribute(element, 'ng-repeat');
  19589. var outerHTML = element[0].outerHTML;
  19590. function getContent(el) {
  19591. return angular.element(el[0].querySelector('.md-subheader-content'));
  19592. }
  19593. // Set the ARIA attributes on the original element since it keeps it's original place in
  19594. // the DOM, whereas the clones are in reverse order. Should be done after the outerHTML,
  19595. // in order to avoid having multiple element be marked as headers.
  19596. attr.$set('role', 'heading');
  19597. $mdAria.expect(element, 'aria-level', '2');
  19598. // Transclude the user-given contents of the subheader
  19599. // the conventional way.
  19600. transclude(scope, function(clone) {
  19601. getContent(element).append(clone);
  19602. });
  19603. // Create another clone, that uses the outer and inner contents
  19604. // of the element, that will be 'stickied' as the user scrolls.
  19605. if (!element.hasClass('md-no-sticky')) {
  19606. transclude(scope, function(clone) {
  19607. // If the user adds an ng-if or ng-repeat directly to the md-subheader element, the
  19608. // compiled clone below will only be a comment tag (since they replace their elements with
  19609. // a comment) which cannot be properly passed to the $mdSticky; so we wrap it in our own
  19610. // DIV to ensure we have something $mdSticky can use
  19611. var wrapper = $compile('<div class="md-subheader-wrapper" aria-hidden="true">' + outerHTML + '</div>')(scope);
  19612. // Delay initialization until after any `ng-if`/`ng-repeat`/etc has finished before
  19613. // attempting to create the clone
  19614. $mdUtil.nextTick(function() {
  19615. // Append our transcluded clone into the wrapper.
  19616. // We don't have to recompile the element again, because the clone is already
  19617. // compiled in it's transclusion scope. If we recompile the outerHTML of the new clone, we would lose
  19618. // our ngIf's and other previous registered bindings / properties.
  19619. getContent(wrapper).append(clone);
  19620. });
  19621. // Make the element sticky and provide the stickyClone our self, to avoid recompilation of the subheader
  19622. // element.
  19623. $mdSticky(scope, element, wrapper);
  19624. });
  19625. }
  19626. }
  19627. };
  19628. }
  19629. })();
  19630. (function(){
  19631. "use strict";
  19632. /**
  19633. * @ngdoc module
  19634. * @name material.components.swipe
  19635. * @description Swipe module!
  19636. */
  19637. /**
  19638. * @ngdoc directive
  19639. * @module material.components.swipe
  19640. * @name mdSwipeLeft
  19641. *
  19642. * @restrict A
  19643. *
  19644. * @description
  19645. * The md-swipe-left directive allows you to specify custom behavior when an element is swiped
  19646. * left.
  19647. *
  19648. * ### Notes
  19649. * - The `$event.currentTarget` of the swiped element will be `null`, but you can get a
  19650. * reference to the element that actually holds the `md-swipe-left` directive by using `$target.current`
  19651. *
  19652. * > You can see this in action on the <a ng-href="demo/swipe">demo page</a> (Look at the Developer Tools console while swiping).
  19653. *
  19654. * @usage
  19655. * <hljs lang="html">
  19656. * <div md-swipe-left="onSwipeLeft($event, $target)">Swipe me left!</div>
  19657. * </hljs>
  19658. */
  19659. /**
  19660. * @ngdoc directive
  19661. * @module material.components.swipe
  19662. * @name mdSwipeRight
  19663. *
  19664. * @restrict A
  19665. *
  19666. * @description
  19667. * The md-swipe-right directive allows you to specify custom behavior when an element is swiped
  19668. * right.
  19669. *
  19670. * ### Notes
  19671. * - The `$event.currentTarget` of the swiped element will be `null`, but you can get a
  19672. * reference to the element that actually holds the `md-swipe-right` directive by using `$target.current`
  19673. *
  19674. * > You can see this in action on the <a ng-href="demo/swipe">demo page</a> (Look at the Developer Tools console while swiping).
  19675. *
  19676. * @usage
  19677. * <hljs lang="html">
  19678. * <div md-swipe-right="onSwipeRight($event, $target)">Swipe me right!</div>
  19679. * </hljs>
  19680. */
  19681. /**
  19682. * @ngdoc directive
  19683. * @module material.components.swipe
  19684. * @name mdSwipeUp
  19685. *
  19686. * @restrict A
  19687. *
  19688. * @description
  19689. * The md-swipe-up directive allows you to specify custom behavior when an element is swiped
  19690. * up.
  19691. *
  19692. * ### Notes
  19693. * - The `$event.currentTarget` of the swiped element will be `null`, but you can get a
  19694. * reference to the element that actually holds the `md-swipe-up` directive by using `$target.current`
  19695. *
  19696. * > You can see this in action on the <a ng-href="demo/swipe">demo page</a> (Look at the Developer Tools console while swiping).
  19697. *
  19698. * @usage
  19699. * <hljs lang="html">
  19700. * <div md-swipe-up="onSwipeUp($event, $target)">Swipe me up!</div>
  19701. * </hljs>
  19702. */
  19703. /**
  19704. * @ngdoc directive
  19705. * @module material.components.swipe
  19706. * @name mdSwipeDown
  19707. *
  19708. * @restrict A
  19709. *
  19710. * @description
  19711. * The md-swipe-down directive allows you to specify custom behavior when an element is swiped
  19712. * down.
  19713. *
  19714. * ### Notes
  19715. * - The `$event.currentTarget` of the swiped element will be `null`, but you can get a
  19716. * reference to the element that actually holds the `md-swipe-down` directive by using `$target.current`
  19717. *
  19718. * > You can see this in action on the <a ng-href="demo/swipe">demo page</a> (Look at the Developer Tools console while swiping).
  19719. *
  19720. * @usage
  19721. * <hljs lang="html">
  19722. * <div md-swipe-down="onSwipDown($event, $target)">Swipe me down!</div>
  19723. * </hljs>
  19724. */
  19725. angular.module('material.components.swipe', ['material.core'])
  19726. .directive('mdSwipeLeft', getDirective('SwipeLeft'))
  19727. .directive('mdSwipeRight', getDirective('SwipeRight'))
  19728. .directive('mdSwipeUp', getDirective('SwipeUp'))
  19729. .directive('mdSwipeDown', getDirective('SwipeDown'));
  19730. function getDirective(name) {
  19731. DirectiveFactory.$inject = ["$parse"];
  19732. var directiveName = 'md' + name;
  19733. var eventName = '$md.' + name.toLowerCase();
  19734. return DirectiveFactory;
  19735. /* @ngInject */
  19736. function DirectiveFactory($parse) {
  19737. return { restrict: 'A', link: postLink };
  19738. function postLink(scope, element, attr) {
  19739. var fn = $parse(attr[directiveName]);
  19740. element.on(eventName, function(ev) {
  19741. var currentTarget = ev.currentTarget;
  19742. scope.$applyAsync(function() { fn(scope, { $event: ev, $target: { current: currentTarget } }); });
  19743. });
  19744. }
  19745. }
  19746. }
  19747. })();
  19748. (function(){
  19749. "use strict";
  19750. /**
  19751. * @ngdoc module
  19752. * @name material.components.switch
  19753. */
  19754. MdSwitch.$inject = ["mdCheckboxDirective", "$mdUtil", "$mdConstant", "$parse", "$$rAF", "$mdGesture", "$timeout"];
  19755. angular.module('material.components.switch', [
  19756. 'material.core',
  19757. 'material.components.checkbox'
  19758. ])
  19759. .directive('mdSwitch', MdSwitch);
  19760. /**
  19761. * @ngdoc directive
  19762. * @module material.components.switch
  19763. * @name mdSwitch
  19764. * @restrict E
  19765. *
  19766. * The switch directive is used very much like the normal [angular checkbox](https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D).
  19767. *
  19768. * As per the [material design spec](http://www.google.com/design/spec/style/color.html#color-ui-color-application)
  19769. * the switch is in the accent color by default. The primary color palette may be used with
  19770. * the `md-primary` class.
  19771. *
  19772. * @param {expression} ng-model Assignable angular expression to data-bind to.
  19773. * @param {string=} name Property name of the form under which the control is published.
  19774. * @param {expression=} ng-true-value The value to which the expression should be set when selected.
  19775. * @param {expression=} ng-false-value The value to which the expression should be set when not selected.
  19776. * @param {expression=} ng-change Expression to be executed when the model value changes.
  19777. * @param {expression=} ng-disabled En/Disable based on the expression.
  19778. * @param {boolean=} md-no-ink Use of attribute indicates use of ripple ink effects.
  19779. * @param {string=} aria-label Publish the button label used by screen-readers for accessibility. Defaults to the switch's text.
  19780. * @param {boolean=} md-invert When set to true, the switch will be inverted.
  19781. *
  19782. * @usage
  19783. * <hljs lang="html">
  19784. * <md-switch ng-model="isActive" aria-label="Finished?">
  19785. * Finished ?
  19786. * </md-switch>
  19787. *
  19788. * <md-switch md-no-ink ng-model="hasInk" aria-label="No Ink Effects">
  19789. * No Ink Effects
  19790. * </md-switch>
  19791. *
  19792. * <md-switch ng-disabled="true" ng-model="isDisabled" aria-label="Disabled">
  19793. * Disabled
  19794. * </md-switch>
  19795. *
  19796. * </hljs>
  19797. */
  19798. function MdSwitch(mdCheckboxDirective, $mdUtil, $mdConstant, $parse, $$rAF, $mdGesture, $timeout) {
  19799. var checkboxDirective = mdCheckboxDirective[0];
  19800. return {
  19801. restrict: 'E',
  19802. priority: $mdConstant.BEFORE_NG_ARIA,
  19803. transclude: true,
  19804. template:
  19805. '<div class="md-container">' +
  19806. '<div class="md-bar"></div>' +
  19807. '<div class="md-thumb-container">' +
  19808. '<div class="md-thumb" md-ink-ripple md-ink-ripple-checkbox></div>' +
  19809. '</div>'+
  19810. '</div>' +
  19811. '<div ng-transclude class="md-label"></div>',
  19812. require: ['^?mdInputContainer', '?ngModel', '?^form'],
  19813. compile: mdSwitchCompile
  19814. };
  19815. function mdSwitchCompile(element, attr) {
  19816. var checkboxLink = checkboxDirective.compile(element, attr).post;
  19817. // No transition on initial load.
  19818. element.addClass('md-dragging');
  19819. return function (scope, element, attr, ctrls) {
  19820. var containerCtrl = ctrls[0];
  19821. var ngModel = ctrls[1] || $mdUtil.fakeNgModel();
  19822. var formCtrl = ctrls[2];
  19823. var disabledGetter = null;
  19824. if (attr.disabled != null) {
  19825. disabledGetter = function() { return true; };
  19826. } else if (attr.ngDisabled) {
  19827. disabledGetter = $parse(attr.ngDisabled);
  19828. }
  19829. var thumbContainer = angular.element(element[0].querySelector('.md-thumb-container'));
  19830. var switchContainer = angular.element(element[0].querySelector('.md-container'));
  19831. var labelContainer = angular.element(element[0].querySelector('.md-label'));
  19832. // no transition on initial load
  19833. $$rAF(function() {
  19834. element.removeClass('md-dragging');
  19835. });
  19836. checkboxLink(scope, element, attr, ctrls);
  19837. if (disabledGetter) {
  19838. scope.$watch(disabledGetter, function(isDisabled) {
  19839. element.attr('tabindex', isDisabled ? -1 : 0);
  19840. });
  19841. }
  19842. attr.$observe('mdInvert', function(newValue) {
  19843. var isInverted = $mdUtil.parseAttributeBoolean(newValue);
  19844. isInverted ? element.prepend(labelContainer) : element.prepend(switchContainer);
  19845. // Toggle a CSS class to update the margin.
  19846. element.toggleClass('md-inverted', isInverted);
  19847. });
  19848. // These events are triggered by setup drag
  19849. $mdGesture.register(switchContainer, 'drag');
  19850. switchContainer
  19851. .on('$md.dragstart', onDragStart)
  19852. .on('$md.drag', onDrag)
  19853. .on('$md.dragend', onDragEnd);
  19854. var drag;
  19855. function onDragStart(ev) {
  19856. // Don't go if the switch is disabled.
  19857. if (disabledGetter && disabledGetter(scope)) return;
  19858. ev.stopPropagation();
  19859. element.addClass('md-dragging');
  19860. drag = {width: thumbContainer.prop('offsetWidth')};
  19861. }
  19862. function onDrag(ev) {
  19863. if (!drag) return;
  19864. ev.stopPropagation();
  19865. ev.srcEvent && ev.srcEvent.preventDefault();
  19866. var percent = ev.pointer.distanceX / drag.width;
  19867. //if checked, start from right. else, start from left
  19868. var translate = ngModel.$viewValue ? 1 + percent : percent;
  19869. // Make sure the switch stays inside its bounds, 0-1%
  19870. translate = Math.max(0, Math.min(1, translate));
  19871. thumbContainer.css($mdConstant.CSS.TRANSFORM, 'translate3d(' + (100*translate) + '%,0,0)');
  19872. drag.translate = translate;
  19873. }
  19874. function onDragEnd(ev) {
  19875. if (!drag) return;
  19876. ev.stopPropagation();
  19877. element.removeClass('md-dragging');
  19878. thumbContainer.css($mdConstant.CSS.TRANSFORM, '');
  19879. // We changed if there is no distance (this is a click a click),
  19880. // or if the drag distance is >50% of the total.
  19881. var isChanged = ngModel.$viewValue ? drag.translate < 0.5 : drag.translate > 0.5;
  19882. if (isChanged) {
  19883. applyModelValue(!ngModel.$viewValue);
  19884. }
  19885. drag = null;
  19886. // Wait for incoming mouse click
  19887. scope.skipToggle = true;
  19888. $timeout(function() {
  19889. scope.skipToggle = false;
  19890. }, 1);
  19891. }
  19892. function applyModelValue(newValue) {
  19893. scope.$apply(function() {
  19894. ngModel.$setViewValue(newValue);
  19895. ngModel.$render();
  19896. });
  19897. }
  19898. };
  19899. }
  19900. }
  19901. })();
  19902. (function(){
  19903. "use strict";
  19904. /**
  19905. * @ngdoc module
  19906. * @name material.components.tabs
  19907. * @description
  19908. *
  19909. * Tabs, created with the `<md-tabs>` directive provide *tabbed* navigation with different styles.
  19910. * The Tabs component consists of clickable tabs that are aligned horizontally side-by-side.
  19911. *
  19912. * Features include support for:
  19913. *
  19914. * - static or dynamic tabs,
  19915. * - responsive designs,
  19916. * - accessibility support (ARIA),
  19917. * - tab pagination,
  19918. * - external or internal tab content,
  19919. * - focus indicators and arrow-key navigations,
  19920. * - programmatic lookup and access to tab controllers, and
  19921. * - dynamic transitions through different tab contents.
  19922. *
  19923. */
  19924. /*
  19925. * @see js folder for tabs implementation
  19926. */
  19927. angular.module('material.components.tabs', [
  19928. 'material.core',
  19929. 'material.components.icon'
  19930. ]);
  19931. })();
  19932. (function(){
  19933. "use strict";
  19934. angular
  19935. .module('material.components.tabs')
  19936. .service('MdTabsPaginationService', MdTabsPaginationService);
  19937. /**
  19938. * @private
  19939. * @module material.components.tabs
  19940. * @name MdTabsPaginationService
  19941. * @description Provides many standalone functions to ease in pagination calculations.
  19942. *
  19943. * Most functions accept the elements and the current offset.
  19944. *
  19945. * The `elements` parameter is typically the value returned from the `getElements()` function of the
  19946. * tabsController.
  19947. *
  19948. * The `offset` parameter is always positive regardless of LTR or RTL (we simply make the LTR one
  19949. * negative when we apply our transform). This is typically the `ctrl.leftOffset` variable in the
  19950. * tabsController.
  19951. *
  19952. * @returns MdTabsPaginationService
  19953. * @constructor
  19954. */
  19955. function MdTabsPaginationService() {
  19956. return {
  19957. decreasePageOffset: decreasePageOffset,
  19958. increasePageOffset: increasePageOffset,
  19959. getTabOffsets: getTabOffsets,
  19960. getTotalTabsWidth: getTotalTabsWidth
  19961. };
  19962. /**
  19963. * Returns the offset for the next decreasing page.
  19964. *
  19965. * @param elements
  19966. * @param currentOffset
  19967. * @returns {number}
  19968. */
  19969. function decreasePageOffset(elements, currentOffset) {
  19970. var canvas = elements.canvas,
  19971. tabOffsets = getTabOffsets(elements),
  19972. i, firstVisibleTabOffset;
  19973. // Find the first fully visible tab in offset range
  19974. for (i = 0; i < tabOffsets.length; i++) {
  19975. if (tabOffsets[i] >= currentOffset) {
  19976. firstVisibleTabOffset = tabOffsets[i];
  19977. break;
  19978. }
  19979. }
  19980. // Return (the first visible tab offset - the tabs container width) without going negative
  19981. return Math.max(0, firstVisibleTabOffset - canvas.clientWidth);
  19982. }
  19983. /**
  19984. * Returns the offset for the next increasing page.
  19985. *
  19986. * @param elements
  19987. * @param currentOffset
  19988. * @returns {number}
  19989. */
  19990. function increasePageOffset(elements, currentOffset) {
  19991. var canvas = elements.canvas,
  19992. maxOffset = getTotalTabsWidth(elements) - canvas.clientWidth,
  19993. tabOffsets = getTabOffsets(elements),
  19994. i, firstHiddenTabOffset;
  19995. // Find the first partially (or fully) invisible tab
  19996. for (i = 0; i < tabOffsets.length, tabOffsets[i] <= currentOffset + canvas.clientWidth; i++) {
  19997. firstHiddenTabOffset = tabOffsets[i];
  19998. }
  19999. // Return the offset of the first hidden tab, or the maximum offset (whichever is smaller)
  20000. return Math.min(maxOffset, firstHiddenTabOffset);
  20001. }
  20002. /**
  20003. * Returns the offsets of all of the tabs based on their widths.
  20004. *
  20005. * @param elements
  20006. * @returns {number[]}
  20007. */
  20008. function getTabOffsets(elements) {
  20009. var i, tab, currentOffset = 0, offsets = [];
  20010. for (i = 0; i < elements.tabs.length; i++) {
  20011. tab = elements.tabs[i];
  20012. offsets.push(currentOffset);
  20013. currentOffset += tab.offsetWidth;
  20014. }
  20015. return offsets;
  20016. }
  20017. /**
  20018. * Sum the width of all tabs.
  20019. *
  20020. * @param elements
  20021. * @returns {number}
  20022. */
  20023. function getTotalTabsWidth(elements) {
  20024. var sum = 0, i, tab;
  20025. for (i = 0; i < elements.tabs.length; i++) {
  20026. tab = elements.tabs[i];
  20027. sum += tab.offsetWidth;
  20028. }
  20029. return sum;
  20030. }
  20031. }
  20032. })();
  20033. (function(){
  20034. "use strict";
  20035. /**
  20036. * @ngdoc module
  20037. * @name material.components.toast
  20038. * @description
  20039. * Toast
  20040. */
  20041. MdToastDirective.$inject = ["$mdToast"];
  20042. MdToastProvider.$inject = ["$$interimElementProvider"];
  20043. angular.module('material.components.toast', [
  20044. 'material.core',
  20045. 'material.components.button'
  20046. ])
  20047. .directive('mdToast', MdToastDirective)
  20048. .provider('$mdToast', MdToastProvider);
  20049. /* @ngInject */
  20050. function MdToastDirective($mdToast) {
  20051. return {
  20052. restrict: 'E',
  20053. link: function postLink(scope, element) {
  20054. element.addClass('_md'); // private md component indicator for styling
  20055. // When navigation force destroys an interimElement, then
  20056. // listen and $destroy() that interim instance...
  20057. scope.$on('$destroy', function() {
  20058. $mdToast.destroy();
  20059. });
  20060. }
  20061. };
  20062. }
  20063. /**
  20064. * @ngdoc service
  20065. * @name $mdToast
  20066. * @module material.components.toast
  20067. *
  20068. * @description
  20069. * `$mdToast` is a service to build a toast notification on any position
  20070. * on the screen with an optional duration, and provides a simple promise API.
  20071. *
  20072. * The toast will be always positioned at the `bottom`, when the screen size is
  20073. * between `600px` and `959px` (`sm` breakpoint)
  20074. *
  20075. * ## Restrictions on custom toasts
  20076. * - The toast's template must have an outer `<md-toast>` element.
  20077. * - For a toast action, use element with class `md-action`.
  20078. * - Add the class `md-capsule` for curved corners.
  20079. *
  20080. * ### Custom Presets
  20081. * Developers are also able to create their own preset, which can be easily used without repeating
  20082. * their options each time.
  20083. *
  20084. * <hljs lang="js">
  20085. * $mdToastProvider.addPreset('testPreset', {
  20086. * options: function() {
  20087. * return {
  20088. * template:
  20089. * '<md-toast>' +
  20090. * '<div class="md-toast-content">' +
  20091. * 'This is a custom preset' +
  20092. * '</div>' +
  20093. * '</md-toast>',
  20094. * controllerAs: 'toast',
  20095. * bindToController: true
  20096. * };
  20097. * }
  20098. * });
  20099. * </hljs>
  20100. *
  20101. * After you created your preset at config phase, you can easily access it.
  20102. *
  20103. * <hljs lang="js">
  20104. * $mdToast.show(
  20105. * $mdToast.testPreset()
  20106. * );
  20107. * </hljs>
  20108. *
  20109. * ## Parent container notes
  20110. *
  20111. * The toast is positioned using absolute positioning relative to its first non-static parent
  20112. * container. Thus, if the requested parent container uses static positioning, we will temporarily
  20113. * set its positioning to `relative` while the toast is visible and reset it when the toast is
  20114. * hidden.
  20115. *
  20116. * Because of this, it is usually best to ensure that the parent container has a fixed height and
  20117. * prevents scrolling by setting the `overflow: hidden;` style. Since the position is based off of
  20118. * the parent's height, the toast may be mispositioned if you allow the parent to scroll.
  20119. *
  20120. * You can, however, have a scrollable element inside of the container; just make sure the
  20121. * container itself does not scroll.
  20122. *
  20123. * <hljs lang="html">
  20124. * <div layout-fill id="toast-container">
  20125. * <md-content>
  20126. * I can have lots of content and scroll!
  20127. * </md-content>
  20128. * </div>
  20129. * </hljs>
  20130. *
  20131. * @usage
  20132. * <hljs lang="html">
  20133. * <div ng-controller="MyController">
  20134. * <md-button ng-click="openToast()">
  20135. * Open a Toast!
  20136. * </md-button>
  20137. * </div>
  20138. * </hljs>
  20139. *
  20140. * <hljs lang="js">
  20141. * var app = angular.module('app', ['ngMaterial']);
  20142. * app.controller('MyController', function($scope, $mdToast) {
  20143. * $scope.openToast = function($event) {
  20144. * $mdToast.show($mdToast.simple().textContent('Hello!'));
  20145. * // Could also do $mdToast.showSimple('Hello');
  20146. * };
  20147. * });
  20148. * </hljs>
  20149. */
  20150. /**
  20151. * @ngdoc method
  20152. * @name $mdToast#showSimple
  20153. *
  20154. * @param {string} message The message to display inside the toast
  20155. * @description
  20156. * Convenience method which builds and shows a simple toast.
  20157. *
  20158. * @returns {promise} A promise that can be resolved with `$mdToast.hide()` or
  20159. * rejected with `$mdToast.cancel()`.
  20160. *
  20161. */
  20162. /**
  20163. * @ngdoc method
  20164. * @name $mdToast#simple
  20165. *
  20166. * @description
  20167. * Builds a preconfigured toast.
  20168. *
  20169. * @returns {obj} a `$mdToastPreset` with the following chainable configuration methods.
  20170. *
  20171. * _**Note:** These configuration methods are provided in addition to the methods provided by
  20172. * the `build()` and `show()` methods below._
  20173. *
  20174. * <table class="md-api-table methods">
  20175. * <thead>
  20176. * <tr>
  20177. * <th>Method</th>
  20178. * <th>Description</th>
  20179. * </tr>
  20180. * </thead>
  20181. * <tbody>
  20182. * <tr>
  20183. * <td>`.textContent(string)`</td>
  20184. * <td>Sets the toast content to the specified string</td>
  20185. * </tr>
  20186. * <tr>
  20187. * <td>`.action(string)`</td>
  20188. * <td>
  20189. * Adds an action button. <br/>
  20190. * If clicked, the promise (returned from `show()`)
  20191. * will resolve with the value `'ok'`; otherwise, it is resolved with `true` after a `hideDelay`
  20192. * timeout
  20193. * </td>
  20194. * </tr>
  20195. * <tr>
  20196. * <td>`.highlightAction(boolean)`</td>
  20197. * <td>
  20198. * Whether or not the action button will have an additional highlight class.<br/>
  20199. * By default the `accent` color will be applied to the action button.
  20200. * </td>
  20201. * </tr>
  20202. * <tr>
  20203. * <td>`.highlightClass(string)`</td>
  20204. * <td>
  20205. * If set, the given class will be applied to the highlighted action button.<br/>
  20206. * This allows you to specify the highlight color easily. Highlight classes are `md-primary`, `md-warn`
  20207. * and `md-accent`
  20208. * </td>
  20209. * </tr>
  20210. * <tr>
  20211. * <td>`.capsule(boolean)`</td>
  20212. * <td>Whether or not to add the `md-capsule` class to the toast to provide rounded corners</td>
  20213. * </tr>
  20214. * <tr>
  20215. * <td>`.theme(string)`</td>
  20216. * <td>Sets the theme on the toast to the requested theme. Default is `$mdThemingProvider`'s default.</td>
  20217. * </tr>
  20218. * <tr>
  20219. * <td>`.toastClass(string)`</td>
  20220. * <td>Sets a class on the toast element</td>
  20221. * </tr>
  20222. * </tbody>
  20223. * </table>
  20224. *
  20225. */
  20226. /**
  20227. * @ngdoc method
  20228. * @name $mdToast#updateTextContent
  20229. *
  20230. * @description
  20231. * Updates the content of an existing toast. Useful for updating things like counts, etc.
  20232. *
  20233. */
  20234. /**
  20235. * @ngdoc method
  20236. * @name $mdToast#build
  20237. *
  20238. * @description
  20239. * Creates a custom `$mdToastPreset` that you can configure.
  20240. *
  20241. * @returns {obj} a `$mdToastPreset` with the chainable configuration methods for shows' options (see below).
  20242. */
  20243. /**
  20244. * @ngdoc method
  20245. * @name $mdToast#show
  20246. *
  20247. * @description Shows the toast.
  20248. *
  20249. * @param {object} optionsOrPreset Either provide an `$mdToastPreset` returned from `simple()`
  20250. * and `build()`, or an options object with the following properties:
  20251. *
  20252. * - `templateUrl` - `{string=}`: The url of an html template file that will
  20253. * be used as the content of the toast. Restrictions: the template must
  20254. * have an outer `md-toast` element.
  20255. * - `template` - `{string=}`: Same as templateUrl, except this is an actual
  20256. * template string.
  20257. * - `autoWrap` - `{boolean=}`: Whether or not to automatically wrap the template content with a
  20258. * `<div class="md-toast-content">` if one is not provided. Defaults to true. Can be disabled if you provide a
  20259. * custom toast directive.
  20260. * - `scope` - `{object=}`: the scope to link the template / controller to. If none is specified, it will create a new child scope.
  20261. * This scope will be destroyed when the toast is removed unless `preserveScope` is set to true.
  20262. * - `preserveScope` - `{boolean=}`: whether to preserve the scope when the element is removed. Default is false
  20263. * - `hideDelay` - `{number=}`: How many milliseconds the toast should stay
  20264. * active before automatically closing. Set to 0 or false to have the toast stay open until
  20265. * closed manually. Default: 3000.
  20266. * - `position` - `{string=}`: Sets the position of the toast. <br/>
  20267. * Available: any combination of `'bottom'`, `'left'`, `'top'`, `'right'`, `'end'` and `'start'`.
  20268. * The properties `'end'` and `'start'` are dynamic and can be used for RTL support.<br/>
  20269. * Default combination: `'bottom left'`.
  20270. * - `toastClass` - `{string=}`: A class to set on the toast element.
  20271. * - `controller` - `{string=}`: The controller to associate with this toast.
  20272. * The controller will be injected the local `$mdToast.hide( )`, which is a function
  20273. * used to hide the toast.
  20274. * - `locals` - `{string=}`: An object containing key/value pairs. The keys will
  20275. * be used as names of values to inject into the controller. For example,
  20276. * `locals: {three: 3}` would inject `three` into the controller with the value
  20277. * of 3.
  20278. * - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in.
  20279. * - `resolve` - `{object=}`: Similar to locals, except it takes promises as values
  20280. * and the toast will not open until the promises resolve.
  20281. * - `controllerAs` - `{string=}`: An alias to assign the controller to on the scope.
  20282. * - `parent` - `{element=}`: The element to append the toast to. Defaults to appending
  20283. * to the root element of the application.
  20284. *
  20285. * @returns {promise} A promise that can be resolved with `$mdToast.hide()` or
  20286. * rejected with `$mdToast.cancel()`. `$mdToast.hide()` will resolve either with a Boolean
  20287. * value == 'true' or the value passed as an argument to `$mdToast.hide()`.
  20288. * And `$mdToast.cancel()` will resolve the promise with a Boolean value == 'false'
  20289. */
  20290. /**
  20291. * @ngdoc method
  20292. * @name $mdToast#hide
  20293. *
  20294. * @description
  20295. * Hide an existing toast and resolve the promise returned from `$mdToast.show()`.
  20296. *
  20297. * @param {*=} response An argument for the resolved promise.
  20298. *
  20299. * @returns {promise} a promise that is called when the existing element is removed from the DOM.
  20300. * The promise is resolved with either a Boolean value == 'true' or the value passed as the
  20301. * argument to `.hide()`.
  20302. *
  20303. */
  20304. /**
  20305. * @ngdoc method
  20306. * @name $mdToast#cancel
  20307. *
  20308. * @description
  20309. * `DEPRECATED` - The promise returned from opening a toast is used only to notify about the closing of the toast.
  20310. * As such, there isn't any reason to also allow that promise to be rejected,
  20311. * since it's not clear what the difference between resolve and reject would be.
  20312. *
  20313. * Hide the existing toast and reject the promise returned from
  20314. * `$mdToast.show()`.
  20315. *
  20316. * @param {*=} response An argument for the rejected promise.
  20317. *
  20318. * @returns {promise} a promise that is called when the existing element is removed from the DOM
  20319. * The promise is resolved with a Boolean value == 'false'.
  20320. *
  20321. */
  20322. function MdToastProvider($$interimElementProvider) {
  20323. // Differentiate promise resolves: hide timeout (value == true) and hide action clicks (value == ok).
  20324. MdToastController.$inject = ["$mdToast", "$scope"];
  20325. toastDefaultOptions.$inject = ["$animate", "$mdToast", "$mdUtil", "$mdMedia"];
  20326. var ACTION_RESOLVE = 'ok';
  20327. var activeToastContent;
  20328. var $mdToast = $$interimElementProvider('$mdToast')
  20329. .setDefaults({
  20330. methods: ['position', 'hideDelay', 'capsule', 'parent', 'position', 'toastClass'],
  20331. options: toastDefaultOptions
  20332. })
  20333. .addPreset('simple', {
  20334. argOption: 'textContent',
  20335. methods: ['textContent', 'content', 'action', 'highlightAction', 'highlightClass', 'theme', 'parent' ],
  20336. options: /* @ngInject */ ["$mdToast", "$mdTheming", function($mdToast, $mdTheming) {
  20337. return {
  20338. template:
  20339. '<md-toast md-theme="{{ toast.theme }}" ng-class="{\'md-capsule\': toast.capsule}">' +
  20340. ' <div class="md-toast-content">' +
  20341. ' <span class="md-toast-text" role="alert" aria-relevant="all" aria-atomic="true">' +
  20342. ' {{ toast.content }}' +
  20343. ' </span>' +
  20344. ' <md-button class="md-action" ng-if="toast.action" ng-click="toast.resolve()" ' +
  20345. ' ng-class="highlightClasses">' +
  20346. ' {{ toast.action }}' +
  20347. ' </md-button>' +
  20348. ' </div>' +
  20349. '</md-toast>',
  20350. controller: MdToastController,
  20351. theme: $mdTheming.defaultTheme(),
  20352. controllerAs: 'toast',
  20353. bindToController: true
  20354. };
  20355. }]
  20356. })
  20357. .addMethod('updateTextContent', updateTextContent)
  20358. .addMethod('updateContent', updateTextContent);
  20359. function updateTextContent(newContent) {
  20360. activeToastContent = newContent;
  20361. }
  20362. return $mdToast;
  20363. /**
  20364. * Controller for the Toast interim elements.
  20365. * @ngInject
  20366. */
  20367. function MdToastController($mdToast, $scope) {
  20368. // For compatibility with AngularJS 1.6+, we should always use the $onInit hook in
  20369. // interimElements. The $mdCompiler simulates the $onInit hook for all versions.
  20370. this.$onInit = function() {
  20371. var self = this;
  20372. if (self.highlightAction) {
  20373. $scope.highlightClasses = [
  20374. 'md-highlight',
  20375. self.highlightClass
  20376. ];
  20377. }
  20378. $scope.$watch(function() { return activeToastContent; }, function() {
  20379. self.content = activeToastContent;
  20380. });
  20381. this.resolve = function() {
  20382. $mdToast.hide( ACTION_RESOLVE );
  20383. };
  20384. };
  20385. }
  20386. /* @ngInject */
  20387. function toastDefaultOptions($animate, $mdToast, $mdUtil, $mdMedia) {
  20388. var SWIPE_EVENTS = '$md.swipeleft $md.swiperight $md.swipeup $md.swipedown';
  20389. return {
  20390. onShow: onShow,
  20391. onRemove: onRemove,
  20392. toastClass: '',
  20393. position: 'bottom left',
  20394. themable: true,
  20395. hideDelay: 3000,
  20396. autoWrap: true,
  20397. transformTemplate: function(template, options) {
  20398. var shouldAddWrapper = options.autoWrap && template && !/md-toast-content/g.test(template);
  20399. if (shouldAddWrapper) {
  20400. // Root element of template will be <md-toast>. We need to wrap all of its content inside of
  20401. // of <div class="md-toast-content">. All templates provided here should be static, developer-controlled
  20402. // content (meaning we're not attempting to guard against XSS).
  20403. var templateRoot = document.createElement('md-template');
  20404. templateRoot.innerHTML = template;
  20405. // Iterate through all root children, to detect possible md-toast directives.
  20406. for (var i = 0; i < templateRoot.children.length; i++) {
  20407. if (templateRoot.children[i].nodeName === 'MD-TOAST') {
  20408. var wrapper = angular.element('<div class="md-toast-content">');
  20409. // Wrap the children of the `md-toast` directive in jqLite, to be able to append multiple
  20410. // nodes with the same execution.
  20411. wrapper.append(angular.element(templateRoot.children[i].childNodes));
  20412. // Append the new wrapped element to the `md-toast` directive.
  20413. templateRoot.children[i].appendChild(wrapper[0]);
  20414. }
  20415. }
  20416. // We have to return the innerHTMl, because we do not want to have the `md-template` element to be
  20417. // the root element of our interimElement.
  20418. return templateRoot.innerHTML;
  20419. }
  20420. return template || '';
  20421. }
  20422. };
  20423. function onShow(scope, element, options) {
  20424. activeToastContent = options.textContent || options.content; // support deprecated #content method
  20425. var isSmScreen = !$mdMedia('gt-sm');
  20426. element = $mdUtil.extractElementByName(element, 'md-toast', true);
  20427. options.element = element;
  20428. options.onSwipe = function(ev, gesture) {
  20429. //Add the relevant swipe class to the element so it can animate correctly
  20430. var swipe = ev.type.replace('$md.','');
  20431. var direction = swipe.replace('swipe', '');
  20432. // If the swipe direction is down/up but the toast came from top/bottom don't fade away
  20433. // Unless the screen is small, then the toast always on bottom
  20434. if ((direction === 'down' && options.position.indexOf('top') != -1 && !isSmScreen) ||
  20435. (direction === 'up' && (options.position.indexOf('bottom') != -1 || isSmScreen))) {
  20436. return;
  20437. }
  20438. if ((direction === 'left' || direction === 'right') && isSmScreen) {
  20439. return;
  20440. }
  20441. element.addClass('md-' + swipe);
  20442. $mdUtil.nextTick($mdToast.cancel);
  20443. };
  20444. options.openClass = toastOpenClass(options.position);
  20445. element.addClass(options.toastClass);
  20446. // 'top left' -> 'md-top md-left'
  20447. options.parent.addClass(options.openClass);
  20448. // static is the default position
  20449. if ($mdUtil.hasComputedStyle(options.parent, 'position', 'static')) {
  20450. options.parent.css('position', 'relative');
  20451. }
  20452. element.on(SWIPE_EVENTS, options.onSwipe);
  20453. element.addClass(isSmScreen ? 'md-bottom' : options.position.split(' ').map(function(pos) {
  20454. return 'md-' + pos;
  20455. }).join(' '));
  20456. if (options.parent) options.parent.addClass('md-toast-animating');
  20457. return $animate.enter(element, options.parent).then(function() {
  20458. if (options.parent) options.parent.removeClass('md-toast-animating');
  20459. });
  20460. }
  20461. function onRemove(scope, element, options) {
  20462. element.off(SWIPE_EVENTS, options.onSwipe);
  20463. if (options.parent) options.parent.addClass('md-toast-animating');
  20464. if (options.openClass) options.parent.removeClass(options.openClass);
  20465. return ((options.$destroy == true) ? element.remove() : $animate.leave(element))
  20466. .then(function () {
  20467. if (options.parent) options.parent.removeClass('md-toast-animating');
  20468. if ($mdUtil.hasComputedStyle(options.parent, 'position', 'static')) {
  20469. options.parent.css('position', '');
  20470. }
  20471. });
  20472. }
  20473. function toastOpenClass(position) {
  20474. // For mobile, always open full-width on bottom
  20475. if (!$mdMedia('gt-xs')) {
  20476. return 'md-toast-open-bottom';
  20477. }
  20478. return 'md-toast-open-' +
  20479. (position.indexOf('top') > -1 ? 'top' : 'bottom');
  20480. }
  20481. }
  20482. }
  20483. })();
  20484. (function(){
  20485. "use strict";
  20486. /**
  20487. * @ngdoc module
  20488. * @name material.components.toolbar
  20489. */
  20490. mdToolbarDirective.$inject = ["$$rAF", "$mdConstant", "$mdUtil", "$mdTheming", "$animate"];
  20491. angular.module('material.components.toolbar', [
  20492. 'material.core',
  20493. 'material.components.content'
  20494. ])
  20495. .directive('mdToolbar', mdToolbarDirective);
  20496. /**
  20497. * @ngdoc directive
  20498. * @name mdToolbar
  20499. * @module material.components.toolbar
  20500. * @restrict E
  20501. * @description
  20502. * `md-toolbar` is used to place a toolbar in your app.
  20503. *
  20504. * Toolbars are usually used above a content area to display the title of the
  20505. * current page, and show relevant action buttons for that page.
  20506. *
  20507. * You can change the height of the toolbar by adding either the
  20508. * `md-medium-tall` or `md-tall` class to the toolbar.
  20509. *
  20510. * @usage
  20511. * <hljs lang="html">
  20512. * <div layout="column" layout-fill>
  20513. * <md-toolbar>
  20514. *
  20515. * <div class="md-toolbar-tools">
  20516. * <h2 md-truncate flex>My App's Title</h2>
  20517. *
  20518. * <md-button>
  20519. * Right Bar Button
  20520. * </md-button>
  20521. * </div>
  20522. *
  20523. * </md-toolbar>
  20524. * <md-content>
  20525. * Hello!
  20526. * </md-content>
  20527. * </div>
  20528. * </hljs>
  20529. *
  20530. * <i><b>Note:</b> The code above shows usage with the `md-truncate` component which provides an
  20531. * ellipsis if the title is longer than the width of the Toolbar.</i>
  20532. *
  20533. * ## CSS & Styles
  20534. *
  20535. * The `<md-toolbar>` provides a few custom CSS classes that you may use to enhance the
  20536. * functionality of your toolbar.
  20537. *
  20538. * <div>
  20539. * <docs-css-api-table>
  20540. *
  20541. * <docs-css-selector code="md-toolbar .md-toolbar-tools">
  20542. * The `md-toolbar-tools` class provides quite a bit of automatic styling for your toolbar
  20543. * buttons and text. When applied, it will center the buttons and text vertically for you.
  20544. * </docs-css-selector>
  20545. *
  20546. * </docs-css-api-table>
  20547. * </div>
  20548. *
  20549. * ### Private Classes
  20550. *
  20551. * Currently, the only private class is the `md-toolbar-transitions` class. All other classes are
  20552. * considered public.
  20553. *
  20554. * @param {boolean=} md-scroll-shrink Whether the header should shrink away as
  20555. * the user scrolls down, and reveal itself as the user scrolls up.
  20556. *
  20557. * _**Note (1):** for scrollShrink to work, the toolbar must be a sibling of a
  20558. * `md-content` element, placed before it. See the scroll shrink demo._
  20559. *
  20560. * _**Note (2):** The `md-scroll-shrink` attribute is only parsed on component
  20561. * initialization, it does not watch for scope changes._
  20562. *
  20563. *
  20564. * @param {number=} md-shrink-speed-factor How much to change the speed of the toolbar's
  20565. * shrinking by. For example, if 0.25 is given then the toolbar will shrink
  20566. * at one fourth the rate at which the user scrolls down. Default 0.5.
  20567. *
  20568. */
  20569. function mdToolbarDirective($$rAF, $mdConstant, $mdUtil, $mdTheming, $animate) {
  20570. var translateY = angular.bind(null, $mdUtil.supplant, 'translate3d(0,{0}px,0)');
  20571. return {
  20572. template: '',
  20573. restrict: 'E',
  20574. link: function(scope, element, attr) {
  20575. element.addClass('_md'); // private md component indicator for styling
  20576. $mdTheming(element);
  20577. $mdUtil.nextTick(function () {
  20578. element.addClass('_md-toolbar-transitions'); // adding toolbar transitions after digest
  20579. }, false);
  20580. if (angular.isDefined(attr.mdScrollShrink)) {
  20581. setupScrollShrink();
  20582. }
  20583. function setupScrollShrink() {
  20584. var toolbarHeight;
  20585. var contentElement;
  20586. var disableScrollShrink = angular.noop;
  20587. // Current "y" position of scroll
  20588. // Store the last scroll top position
  20589. var y = 0;
  20590. var prevScrollTop = 0;
  20591. var shrinkSpeedFactor = attr.mdShrinkSpeedFactor || 0.5;
  20592. var debouncedContentScroll = $$rAF.throttle(onContentScroll);
  20593. var debouncedUpdateHeight = $mdUtil.debounce(updateToolbarHeight, 5 * 1000);
  20594. // Wait for $mdContentLoaded event from mdContent directive.
  20595. // If the mdContent element is a sibling of our toolbar, hook it up
  20596. // to scroll events.
  20597. scope.$on('$mdContentLoaded', onMdContentLoad);
  20598. // If the toolbar is used inside an ng-if statement, we may miss the
  20599. // $mdContentLoaded event, so we attempt to fake it if we have a
  20600. // md-content close enough.
  20601. attr.$observe('mdScrollShrink', onChangeScrollShrink);
  20602. // If the toolbar has ngShow or ngHide we need to update height immediately as it changed
  20603. // and not wait for $mdUtil.debounce to happen
  20604. if (attr.ngShow) { scope.$watch(attr.ngShow, updateToolbarHeight); }
  20605. if (attr.ngHide) { scope.$watch(attr.ngHide, updateToolbarHeight); }
  20606. // If the scope is destroyed (which could happen with ng-if), make sure
  20607. // to disable scroll shrinking again
  20608. scope.$on('$destroy', disableScrollShrink);
  20609. /**
  20610. *
  20611. */
  20612. function onChangeScrollShrink(shrinkWithScroll) {
  20613. var closestContent = element.parent().find('md-content');
  20614. // If we have a content element, fake the call; this might still fail
  20615. // if the content element isn't a sibling of the toolbar
  20616. if (!contentElement && closestContent.length) {
  20617. onMdContentLoad(null, closestContent);
  20618. }
  20619. // Evaluate the expression
  20620. shrinkWithScroll = scope.$eval(shrinkWithScroll);
  20621. // Disable only if the attribute's expression evaluates to false
  20622. if (shrinkWithScroll === false) {
  20623. disableScrollShrink();
  20624. } else {
  20625. disableScrollShrink = enableScrollShrink();
  20626. }
  20627. }
  20628. /**
  20629. *
  20630. */
  20631. function onMdContentLoad($event, newContentEl) {
  20632. // Toolbar and content must be siblings
  20633. if (newContentEl && element.parent()[0] === newContentEl.parent()[0]) {
  20634. // unhook old content event listener if exists
  20635. if (contentElement) {
  20636. contentElement.off('scroll', debouncedContentScroll);
  20637. }
  20638. contentElement = newContentEl;
  20639. disableScrollShrink = enableScrollShrink();
  20640. }
  20641. }
  20642. /**
  20643. *
  20644. */
  20645. function onContentScroll(e) {
  20646. var scrollTop = e ? e.target.scrollTop : prevScrollTop;
  20647. debouncedUpdateHeight();
  20648. y = Math.min(
  20649. toolbarHeight / shrinkSpeedFactor,
  20650. Math.max(0, y + scrollTop - prevScrollTop)
  20651. );
  20652. element.css($mdConstant.CSS.TRANSFORM, translateY([-y * shrinkSpeedFactor]));
  20653. contentElement.css($mdConstant.CSS.TRANSFORM, translateY([(toolbarHeight - y) * shrinkSpeedFactor]));
  20654. prevScrollTop = scrollTop;
  20655. $mdUtil.nextTick(function() {
  20656. var hasWhiteFrame = element.hasClass('md-whiteframe-z1');
  20657. if (hasWhiteFrame && !y) {
  20658. $animate.removeClass(element, 'md-whiteframe-z1');
  20659. } else if (!hasWhiteFrame && y) {
  20660. $animate.addClass(element, 'md-whiteframe-z1');
  20661. }
  20662. });
  20663. }
  20664. /**
  20665. *
  20666. */
  20667. function enableScrollShrink() {
  20668. if (!contentElement) return angular.noop; // no md-content
  20669. contentElement.on('scroll', debouncedContentScroll);
  20670. contentElement.attr('scroll-shrink', 'true');
  20671. $mdUtil.nextTick(updateToolbarHeight, false);
  20672. return function disableScrollShrink() {
  20673. contentElement.off('scroll', debouncedContentScroll);
  20674. contentElement.attr('scroll-shrink', 'false');
  20675. updateToolbarHeight();
  20676. };
  20677. }
  20678. /**
  20679. *
  20680. */
  20681. function updateToolbarHeight() {
  20682. toolbarHeight = element.prop('offsetHeight');
  20683. // Add a negative margin-top the size of the toolbar to the content el.
  20684. // The content will start transformed down the toolbarHeight amount,
  20685. // so everything looks normal.
  20686. //
  20687. // As the user scrolls down, the content will be transformed up slowly
  20688. // to put the content underneath where the toolbar was.
  20689. var margin = (-toolbarHeight * shrinkSpeedFactor) + 'px';
  20690. contentElement.css({
  20691. "margin-top": margin,
  20692. "margin-bottom": margin
  20693. });
  20694. onContentScroll();
  20695. }
  20696. }
  20697. }
  20698. };
  20699. }
  20700. })();
  20701. (function(){
  20702. "use strict";
  20703. /**
  20704. * @ngdoc module
  20705. * @name material.components.tooltip
  20706. */
  20707. MdTooltipDirective.$inject = ["$timeout", "$window", "$$rAF", "$document", "$interpolate", "$mdUtil", "$mdPanel", "$$mdTooltipRegistry"];
  20708. angular
  20709. .module('material.components.tooltip', [
  20710. 'material.core',
  20711. 'material.components.panel'
  20712. ])
  20713. .directive('mdTooltip', MdTooltipDirective)
  20714. .service('$$mdTooltipRegistry', MdTooltipRegistry);
  20715. /**
  20716. * @ngdoc directive
  20717. * @name mdTooltip
  20718. * @module material.components.tooltip
  20719. * @description
  20720. * Tooltips are used to describe elements that are interactive and primarily
  20721. * graphical (not textual).
  20722. *
  20723. * Place a `<md-tooltip>` as a child of the element it describes.
  20724. *
  20725. * A tooltip will activate when the user hovers over, focuses, or touches the
  20726. * parent element.
  20727. *
  20728. * @usage
  20729. * <hljs lang="html">
  20730. * <md-button class="md-fab md-accent" aria-label="Play">
  20731. * <md-tooltip>Play Music</md-tooltip>
  20732. * <md-icon md-svg-src="img/icons/ic_play_arrow_24px.svg"></md-icon>
  20733. * </md-button>
  20734. * </hljs>
  20735. *
  20736. * @param {number=} md-z-index The visual level that the tooltip will appear
  20737. * in comparison with the rest of the elements of the application.
  20738. * @param {expression=} md-visible Boolean bound to whether the tooltip is
  20739. * currently visible.
  20740. * @param {number=} md-delay How many milliseconds to wait to show the tooltip
  20741. * after the user hovers over, focuses, or touches the parent element.
  20742. * Defaults to 0ms on non-touch devices and 75ms on touch.
  20743. * @param {boolean=} md-autohide If present or provided with a boolean value,
  20744. * the tooltip will hide on mouse leave, regardless of focus.
  20745. * @param {string=} md-direction The direction that the tooltip is shown,
  20746. * relative to the parent element. Supports top, right, bottom, and left.
  20747. * Defaults to bottom.
  20748. */
  20749. function MdTooltipDirective($timeout, $window, $$rAF, $document, $interpolate,
  20750. $mdUtil, $mdPanel, $$mdTooltipRegistry) {
  20751. var ENTER_EVENTS = 'focus touchstart mouseenter';
  20752. var LEAVE_EVENTS = 'blur touchcancel mouseleave';
  20753. var TOOLTIP_DEFAULT_Z_INDEX = 100;
  20754. var TOOLTIP_DEFAULT_SHOW_DELAY = 0;
  20755. var TOOLTIP_DEFAULT_DIRECTION = 'bottom';
  20756. var TOOLTIP_DIRECTIONS = {
  20757. top: { x: $mdPanel.xPosition.CENTER, y: $mdPanel.yPosition.ABOVE },
  20758. right: { x: $mdPanel.xPosition.OFFSET_END, y: $mdPanel.yPosition.CENTER },
  20759. bottom: { x: $mdPanel.xPosition.CENTER, y: $mdPanel.yPosition.BELOW },
  20760. left: { x: $mdPanel.xPosition.OFFSET_START, y: $mdPanel.yPosition.CENTER }
  20761. };
  20762. return {
  20763. restrict: 'E',
  20764. priority: 210, // Before ngAria
  20765. scope: {
  20766. mdZIndex: '=?mdZIndex',
  20767. mdDelay: '=?mdDelay',
  20768. mdVisible: '=?mdVisible',
  20769. mdAutohide: '=?mdAutohide',
  20770. mdDirection: '@?mdDirection' // Do not expect expressions.
  20771. },
  20772. link: linkFunc
  20773. };
  20774. function linkFunc(scope, element, attr) {
  20775. // Set constants.
  20776. var tooltipId = 'md-tooltip-' + $mdUtil.nextUid();
  20777. var parent = $mdUtil.getParentWithPointerEvents(element);
  20778. var debouncedOnResize = $$rAF.throttle(updatePosition);
  20779. var mouseActive = false;
  20780. var origin, position, panelPosition, panelRef, autohide, showTimeout,
  20781. elementFocusedOnWindowBlur = null;
  20782. // Set defaults
  20783. setDefaults();
  20784. // Set parent aria-label.
  20785. addAriaLabel();
  20786. // Remove the element from its current DOM position.
  20787. element.detach();
  20788. updatePosition();
  20789. bindEvents();
  20790. configureWatchers();
  20791. function setDefaults() {
  20792. scope.mdZIndex = scope.mdZIndex || TOOLTIP_DEFAULT_Z_INDEX;
  20793. scope.mdDelay = scope.mdDelay || TOOLTIP_DEFAULT_SHOW_DELAY;
  20794. if (!TOOLTIP_DIRECTIONS[scope.mdDirection]) {
  20795. scope.mdDirection = TOOLTIP_DEFAULT_DIRECTION;
  20796. }
  20797. }
  20798. function addAriaLabel(labelText) {
  20799. // Only interpolate the text from the HTML element because otherwise the custom text could
  20800. // be interpolated twice and cause XSS violations.
  20801. var interpolatedText = labelText || $interpolate(element.text().trim())(scope.$parent);
  20802. // Only add the `aria-label` to the parent if there isn't already one, if there isn't an
  20803. // already present `aria-labelledby`, or if the previous `aria-label` was added by the
  20804. // tooltip directive.
  20805. if (
  20806. (!parent.attr('aria-label') && !parent.attr('aria-labelledby')) ||
  20807. parent.attr('md-labeled-by-tooltip')
  20808. ) {
  20809. parent.attr('aria-label', interpolatedText);
  20810. // Set the `md-labeled-by-tooltip` attribute if it has not already been set.
  20811. if (!parent.attr('md-labeled-by-tooltip')) {
  20812. parent.attr('md-labeled-by-tooltip', tooltipId);
  20813. }
  20814. }
  20815. }
  20816. function updatePosition() {
  20817. setDefaults();
  20818. // If the panel has already been created, remove the current origin
  20819. // class from the panel element.
  20820. if (panelRef && panelRef.panelEl) {
  20821. panelRef.panelEl.removeClass(origin);
  20822. }
  20823. // Set the panel element origin class based off of the current
  20824. // mdDirection.
  20825. origin = 'md-origin-' + scope.mdDirection;
  20826. // Create the position of the panel based off of the mdDirection.
  20827. position = TOOLTIP_DIRECTIONS[scope.mdDirection];
  20828. // Using the newly created position object, use the MdPanel
  20829. // panelPosition API to build the panel's position.
  20830. panelPosition = $mdPanel.newPanelPosition()
  20831. .relativeTo(parent)
  20832. .addPanelPosition(position.x, position.y);
  20833. // If the panel has already been created, add the new origin class to
  20834. // the panel element and update it's position with the panelPosition.
  20835. if (panelRef && panelRef.panelEl) {
  20836. panelRef.panelEl.addClass(origin);
  20837. panelRef.updatePosition(panelPosition);
  20838. }
  20839. }
  20840. function bindEvents() {
  20841. // Add a mutationObserver where there is support for it and the need
  20842. // for it in the form of viable host(parent[0]).
  20843. if (parent[0] && 'MutationObserver' in $window) {
  20844. // Use a mutationObserver to tackle #2602.
  20845. var attributeObserver = new MutationObserver(function(mutations) {
  20846. if (isDisabledMutation(mutations)) {
  20847. $mdUtil.nextTick(function() {
  20848. setVisible(false);
  20849. });
  20850. }
  20851. });
  20852. attributeObserver.observe(parent[0], {
  20853. attributes: true
  20854. });
  20855. }
  20856. elementFocusedOnWindowBlur = false;
  20857. $$mdTooltipRegistry.register('scroll', windowScrollEventHandler, true);
  20858. $$mdTooltipRegistry.register('blur', windowBlurEventHandler);
  20859. $$mdTooltipRegistry.register('resize', debouncedOnResize);
  20860. scope.$on('$destroy', onDestroy);
  20861. // To avoid 'synthetic clicks', we listen to mousedown instead of
  20862. // 'click'.
  20863. parent.on('mousedown', mousedownEventHandler);
  20864. parent.on(ENTER_EVENTS, enterEventHandler);
  20865. function isDisabledMutation(mutations) {
  20866. mutations.some(function(mutation) {
  20867. return mutation.attributeName === 'disabled' && parent[0].disabled;
  20868. });
  20869. return false;
  20870. }
  20871. function windowScrollEventHandler() {
  20872. setVisible(false);
  20873. }
  20874. function windowBlurEventHandler() {
  20875. elementFocusedOnWindowBlur = document.activeElement === parent[0];
  20876. }
  20877. function enterEventHandler($event) {
  20878. // Prevent the tooltip from showing when the window is receiving
  20879. // focus.
  20880. if ($event.type === 'focus' && elementFocusedOnWindowBlur) {
  20881. elementFocusedOnWindowBlur = false;
  20882. } else if (!scope.mdVisible) {
  20883. parent.on(LEAVE_EVENTS, leaveEventHandler);
  20884. setVisible(true);
  20885. // If the user is on a touch device, we should bind the tap away
  20886. // after the 'touched' in order to prevent the tooltip being
  20887. // removed immediately.
  20888. if ($event.type === 'touchstart') {
  20889. parent.one('touchend', function() {
  20890. $mdUtil.nextTick(function() {
  20891. $document.one('touchend', leaveEventHandler);
  20892. }, false);
  20893. });
  20894. }
  20895. }
  20896. }
  20897. function leaveEventHandler() {
  20898. autohide = scope.hasOwnProperty('mdAutohide') ?
  20899. scope.mdAutohide :
  20900. attr.hasOwnProperty('mdAutohide');
  20901. if (autohide || mouseActive ||
  20902. $document[0].activeElement !== parent[0]) {
  20903. // When a show timeout is currently in progress, then we have
  20904. // to cancel it, otherwise the tooltip will remain showing
  20905. // without focus or hover.
  20906. if (showTimeout) {
  20907. $timeout.cancel(showTimeout);
  20908. setVisible.queued = false;
  20909. showTimeout = null;
  20910. }
  20911. parent.off(LEAVE_EVENTS, leaveEventHandler);
  20912. parent.triggerHandler('blur');
  20913. setVisible(false);
  20914. }
  20915. mouseActive = false;
  20916. }
  20917. function mousedownEventHandler() {
  20918. mouseActive = true;
  20919. }
  20920. function onDestroy() {
  20921. $$mdTooltipRegistry.deregister('scroll', windowScrollEventHandler, true);
  20922. $$mdTooltipRegistry.deregister('blur', windowBlurEventHandler);
  20923. $$mdTooltipRegistry.deregister('resize', debouncedOnResize);
  20924. parent
  20925. .off(ENTER_EVENTS, enterEventHandler)
  20926. .off(LEAVE_EVENTS, leaveEventHandler)
  20927. .off('mousedown', mousedownEventHandler);
  20928. // Trigger the handler in case any of the tooltips are
  20929. // still visible.
  20930. leaveEventHandler();
  20931. attributeObserver && attributeObserver.disconnect();
  20932. }
  20933. }
  20934. function configureWatchers() {
  20935. if (element[0] && 'MutationObserver' in $window) {
  20936. var attributeObserver = new MutationObserver(function(mutations) {
  20937. mutations.forEach(function(mutation) {
  20938. if (mutation.attributeName === 'md-visible' &&
  20939. !scope.visibleWatcher ) {
  20940. scope.visibleWatcher = scope.$watch('mdVisible',
  20941. onVisibleChanged);
  20942. }
  20943. });
  20944. });
  20945. attributeObserver.observe(element[0], {
  20946. attributes: true
  20947. });
  20948. // Build watcher only if mdVisible is being used.
  20949. if (attr.hasOwnProperty('mdVisible')) {
  20950. scope.visibleWatcher = scope.$watch('mdVisible',
  20951. onVisibleChanged);
  20952. }
  20953. } else {
  20954. // MutationObserver not supported
  20955. scope.visibleWatcher = scope.$watch('mdVisible', onVisibleChanged);
  20956. }
  20957. // Direction watcher
  20958. scope.$watch('mdDirection', updatePosition);
  20959. // Clean up if the element or parent was removed via jqLite's .remove.
  20960. // A couple of notes:
  20961. // - In these cases the scope might not have been destroyed, which
  20962. // is why we destroy it manually. An example of this can be having
  20963. // `md-visible="false"` and adding tooltips while they're
  20964. // invisible. If `md-visible` becomes true, at some point, you'd
  20965. // usually get a lot of tooltips.
  20966. // - We use `.one`, not `.on`, because this only needs to fire once.
  20967. // If we were using `.on`, it would get thrown into an infinite
  20968. // loop.
  20969. // - This kicks off the scope's `$destroy` event which finishes the
  20970. // cleanup.
  20971. element.one('$destroy', onElementDestroy);
  20972. parent.one('$destroy', onElementDestroy);
  20973. scope.$on('$destroy', function() {
  20974. setVisible(false);
  20975. panelRef && panelRef.destroy();
  20976. attributeObserver && attributeObserver.disconnect();
  20977. element.remove();
  20978. });
  20979. // Updates the aria-label when the element text changes. This watch
  20980. // doesn't need to be set up if the element doesn't have any data
  20981. // bindings.
  20982. if (element.text().indexOf($interpolate.startSymbol()) > -1) {
  20983. scope.$watch(function() {
  20984. return element.text().trim();
  20985. }, addAriaLabel);
  20986. }
  20987. function onElementDestroy() {
  20988. scope.$destroy();
  20989. }
  20990. }
  20991. function setVisible(value) {
  20992. // Break if passed value is already in queue or there is no queue and
  20993. // passed value is current in the controller.
  20994. if (setVisible.queued && setVisible.value === !!value ||
  20995. !setVisible.queued && scope.mdVisible === !!value) {
  20996. return;
  20997. }
  20998. setVisible.value = !!value;
  20999. if (!setVisible.queued) {
  21000. if (value) {
  21001. setVisible.queued = true;
  21002. showTimeout = $timeout(function() {
  21003. scope.mdVisible = setVisible.value;
  21004. setVisible.queued = false;
  21005. showTimeout = null;
  21006. if (!scope.visibleWatcher) {
  21007. onVisibleChanged(scope.mdVisible);
  21008. }
  21009. }, scope.mdDelay);
  21010. } else {
  21011. $mdUtil.nextTick(function() {
  21012. scope.mdVisible = false;
  21013. if (!scope.visibleWatcher) {
  21014. onVisibleChanged(false);
  21015. }
  21016. });
  21017. }
  21018. }
  21019. }
  21020. function onVisibleChanged(isVisible) {
  21021. isVisible ? showTooltip() : hideTooltip();
  21022. }
  21023. function showTooltip() {
  21024. // Do not show the tooltip if the text is empty.
  21025. if (!element[0].textContent.trim()) {
  21026. throw new Error('Text for the tooltip has not been provided. ' +
  21027. 'Please include text within the mdTooltip element.');
  21028. }
  21029. if (!panelRef) {
  21030. var attachTo = angular.element(document.body);
  21031. var panelAnimation = $mdPanel.newPanelAnimation()
  21032. .openFrom(parent)
  21033. .closeTo(parent)
  21034. .withAnimation({
  21035. open: 'md-show',
  21036. close: 'md-hide'
  21037. });
  21038. var panelConfig = {
  21039. id: tooltipId,
  21040. attachTo: attachTo,
  21041. contentElement: element,
  21042. propagateContainerEvents: true,
  21043. panelClass: 'md-tooltip',
  21044. animation: panelAnimation,
  21045. position: panelPosition,
  21046. zIndex: scope.mdZIndex,
  21047. focusOnOpen: false,
  21048. onDomAdded: function() {
  21049. panelRef.panelEl.addClass(origin);
  21050. }
  21051. };
  21052. panelRef = $mdPanel.create(panelConfig);
  21053. }
  21054. panelRef.open().then(function() {
  21055. panelRef.panelEl.attr('role', 'tooltip');
  21056. });
  21057. }
  21058. function hideTooltip() {
  21059. panelRef && panelRef.close();
  21060. }
  21061. }
  21062. }
  21063. /**
  21064. * Service that is used to reduce the amount of listeners that are being
  21065. * registered on the `window` by the tooltip component. Works by collecting
  21066. * the individual event handlers and dispatching them from a global handler.
  21067. *
  21068. * @ngInject
  21069. */
  21070. function MdTooltipRegistry() {
  21071. var listeners = {};
  21072. var ngWindow = angular.element(window);
  21073. return {
  21074. register: register,
  21075. deregister: deregister
  21076. };
  21077. /**
  21078. * Global event handler that dispatches the registered handlers in the
  21079. * service.
  21080. * @param {!Event} event Event object passed in by the browser
  21081. */
  21082. function globalEventHandler(event) {
  21083. if (listeners[event.type]) {
  21084. listeners[event.type].forEach(function(currentHandler) {
  21085. currentHandler.call(this, event);
  21086. }, this);
  21087. }
  21088. }
  21089. /**
  21090. * Registers a new handler with the service.
  21091. * @param {string} type Type of event to be registered.
  21092. * @param {!Function} handler Event handler.
  21093. * @param {boolean} useCapture Whether to use event capturing.
  21094. */
  21095. function register(type, handler, useCapture) {
  21096. var handlers = listeners[type] = listeners[type] || [];
  21097. if (!handlers.length) {
  21098. useCapture ? window.addEventListener(type, globalEventHandler, true) :
  21099. ngWindow.on(type, globalEventHandler);
  21100. }
  21101. if (handlers.indexOf(handler) === -1) {
  21102. handlers.push(handler);
  21103. }
  21104. }
  21105. /**
  21106. * Removes an event handler from the service.
  21107. * @param {string} type Type of event handler.
  21108. * @param {!Function} handler The event handler itself.
  21109. * @param {boolean} useCapture Whether the event handler used event capturing.
  21110. */
  21111. function deregister(type, handler, useCapture) {
  21112. var handlers = listeners[type];
  21113. var index = handlers ? handlers.indexOf(handler) : -1;
  21114. if (index > -1) {
  21115. handlers.splice(index, 1);
  21116. if (handlers.length === 0) {
  21117. useCapture ? window.removeEventListener(type, globalEventHandler, true) :
  21118. ngWindow.off(type, globalEventHandler);
  21119. }
  21120. }
  21121. }
  21122. }
  21123. })();
  21124. (function(){
  21125. "use strict";
  21126. /**
  21127. * @ngdoc module
  21128. * @name material.components.truncate
  21129. */
  21130. MdTruncateController.$inject = ["$element"];
  21131. angular.module('material.components.truncate', ['material.core'])
  21132. .directive('mdTruncate', MdTruncateDirective);
  21133. /**
  21134. * @ngdoc directive
  21135. * @name mdTruncate
  21136. * @module material.components.truncate
  21137. * @restrict AE
  21138. * @description
  21139. *
  21140. * The `md-truncate` component displays a label that will automatically clip text which is wider
  21141. * than the component. By default, it displays an ellipsis, but you may apply the `md-clip` CSS
  21142. * class to override this default and use a standard "clipping" approach.
  21143. *
  21144. * <i><b>Note:</b> The `md-truncate` component does not automatically adjust it's width. You must
  21145. * provide the `flex` attribute, or some other CSS-based width management. See the
  21146. * <a ng-href="./demo/truncate">demos</a> for examples.</i>
  21147. *
  21148. * @usage
  21149. *
  21150. * ### As an Element
  21151. *
  21152. * <hljs lang="html">
  21153. * <div layout="row">
  21154. * <md-button>Back</md-button>
  21155. *
  21156. * <md-truncate flex>Chapter 1 - The Way of the Old West</md-truncate>
  21157. *
  21158. * <md-button>Forward</md-button>
  21159. * </div>
  21160. * </hljs>
  21161. *
  21162. * ### As an Attribute
  21163. *
  21164. * <hljs lang="html">
  21165. * <h2 md-truncate style="max-width: 100px;">Some Title With a Lot of Text</h2>
  21166. * </hljs>
  21167. *
  21168. * ## CSS & Styles
  21169. *
  21170. * `<md-truncate>` provides two CSS classes that you may use to control the type of clipping.
  21171. *
  21172. * <i><b>Note:</b> The `md-truncate` also applies a setting of `width: 0;` when used with the `flex`
  21173. * attribute to fix an issue with the flex element not shrinking properly.</i>
  21174. *
  21175. * <div>
  21176. * <docs-css-api-table>
  21177. *
  21178. * <docs-css-selector code=".md-ellipsis">
  21179. * Assigns the "ellipsis" behavior (default) which will cut off mid-word and append an ellipsis
  21180. * (&hellip;) to the end of the text.
  21181. * </docs-css-selector>
  21182. *
  21183. * <docs-css-selector code=".md-clip">
  21184. * Assigns the "clipping" behavior which will simply chop off the text. This may happen
  21185. * mid-word or even mid-character.
  21186. * </docs-css-selector>
  21187. *
  21188. * </docs-css-api-table>
  21189. * </div>
  21190. */
  21191. function MdTruncateDirective() {
  21192. return {
  21193. restrict: 'AE',
  21194. controller: MdTruncateController
  21195. };
  21196. }
  21197. /**
  21198. * Controller for the <md-truncate> component.
  21199. *
  21200. * @param $element The md-truncate element.
  21201. *
  21202. * @constructor
  21203. * @ngInject
  21204. */
  21205. function MdTruncateController($element) {
  21206. $element.addClass('md-truncate');
  21207. }
  21208. })();
  21209. (function(){
  21210. "use strict";
  21211. /**
  21212. * @ngdoc module
  21213. * @name material.components.virtualRepeat
  21214. */
  21215. VirtualRepeatContainerController.$inject = ["$$rAF", "$mdUtil", "$mdConstant", "$parse", "$rootScope", "$window", "$scope", "$element", "$attrs"];
  21216. VirtualRepeatController.$inject = ["$scope", "$element", "$attrs", "$browser", "$document", "$rootScope", "$$rAF", "$mdUtil"];
  21217. VirtualRepeatDirective.$inject = ["$parse"];
  21218. angular.module('material.components.virtualRepeat', [
  21219. 'material.core',
  21220. 'material.components.showHide'
  21221. ])
  21222. .directive('mdVirtualRepeatContainer', VirtualRepeatContainerDirective)
  21223. .directive('mdVirtualRepeat', VirtualRepeatDirective)
  21224. .directive('mdForceHeight', ForceHeightDirective);
  21225. /**
  21226. * @ngdoc directive
  21227. * @name mdVirtualRepeatContainer
  21228. * @module material.components.virtualRepeat
  21229. * @restrict E
  21230. * @description
  21231. * `md-virtual-repeat-container` provides the scroll container for md-virtual-repeat.
  21232. *
  21233. * VirtualRepeat is a limited substitute for ng-repeat that renders only
  21234. * enough DOM nodes to fill the container and recycling them as the user scrolls.
  21235. *
  21236. * Once an element is not visible anymore, the VirtualRepeat recycles it and will reuse it for
  21237. * another visible item by replacing the previous dataset with the new one.
  21238. *
  21239. * ### Common Issues
  21240. *
  21241. * - When having one-time bindings inside of the view template, the VirtualRepeat will not properly
  21242. * update the bindings for new items, since the view will be recycled.
  21243. * - Directives inside of a VirtualRepeat will be only compiled (linked) once, because those
  21244. * items will be recycled and used for other items.
  21245. * The VirtualRepeat just updates the scope bindings.
  21246. *
  21247. *
  21248. * ### Notes
  21249. *
  21250. * > The VirtualRepeat is a similar implementation to the Android
  21251. * [RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html)
  21252. *
  21253. * <!-- This comment forces a break between blockquotes //-->
  21254. *
  21255. * > Please also review the <a ng-href="api/directive/mdVirtualRepeat">VirtualRepeat</a>
  21256. * documentation for more information.
  21257. *
  21258. *
  21259. * @usage
  21260. * <hljs lang="html">
  21261. *
  21262. * <md-virtual-repeat-container md-top-index="topIndex">
  21263. * <div md-virtual-repeat="i in items" md-item-size="20">Hello {{i}}!</div>
  21264. * </md-virtual-repeat-container>
  21265. * </hljs>
  21266. *
  21267. * @param {number=} md-top-index Binds the index of the item that is at the top of the scroll
  21268. * container to `$scope`. It can both read and set the scroll position.
  21269. * @param {boolean=} md-orient-horizontal Whether the container should scroll horizontally
  21270. * (defaults to orientation and scrolling vertically).
  21271. * @param {boolean=} md-auto-shrink When present, the container will shrink to fit
  21272. * the number of items when that number is less than its original size.
  21273. * @param {number=} md-auto-shrink-min Minimum number of items that md-auto-shrink
  21274. * will shrink to (default: 0).
  21275. */
  21276. function VirtualRepeatContainerDirective() {
  21277. return {
  21278. controller: VirtualRepeatContainerController,
  21279. template: virtualRepeatContainerTemplate,
  21280. compile: function virtualRepeatContainerCompile($element, $attrs) {
  21281. $element
  21282. .addClass('md-virtual-repeat-container')
  21283. .addClass($attrs.hasOwnProperty('mdOrientHorizontal')
  21284. ? 'md-orient-horizontal'
  21285. : 'md-orient-vertical');
  21286. }
  21287. };
  21288. }
  21289. function virtualRepeatContainerTemplate($element) {
  21290. return '<div class="md-virtual-repeat-scroller" role="presentation">' +
  21291. '<div class="md-virtual-repeat-sizer" role="presentation"></div>' +
  21292. '<div class="md-virtual-repeat-offsetter" role="presentation">' +
  21293. $element[0].innerHTML +
  21294. '</div></div>';
  21295. }
  21296. /**
  21297. * Number of additional elements to render above and below the visible area inside
  21298. * of the virtual repeat container. A higher number results in less flicker when scrolling
  21299. * very quickly in Safari, but comes with a higher rendering and dirty-checking cost.
  21300. * @const {number}
  21301. */
  21302. var NUM_EXTRA = 3;
  21303. /** @ngInject */
  21304. function VirtualRepeatContainerController($$rAF, $mdUtil, $mdConstant, $parse, $rootScope, $window, $scope,
  21305. $element, $attrs) {
  21306. this.$rootScope = $rootScope;
  21307. this.$scope = $scope;
  21308. this.$element = $element;
  21309. this.$attrs = $attrs;
  21310. /** @type {number} The width or height of the container */
  21311. this.size = 0;
  21312. /** @type {number} The scroll width or height of the scroller */
  21313. this.scrollSize = 0;
  21314. /** @type {number} The scrollLeft or scrollTop of the scroller */
  21315. this.scrollOffset = 0;
  21316. /** @type {boolean} Whether the scroller is oriented horizontally */
  21317. this.horizontal = this.$attrs.hasOwnProperty('mdOrientHorizontal');
  21318. /** @type {!VirtualRepeatController} The repeater inside of this container */
  21319. this.repeater = null;
  21320. /** @type {boolean} Whether auto-shrink is enabled */
  21321. this.autoShrink = this.$attrs.hasOwnProperty('mdAutoShrink');
  21322. /** @type {number} Minimum number of items to auto-shrink to */
  21323. this.autoShrinkMin = parseInt(this.$attrs.mdAutoShrinkMin, 10) || 0;
  21324. /** @type {?number} Original container size when shrank */
  21325. this.originalSize = null;
  21326. /** @type {number} Amount to offset the total scroll size by. */
  21327. this.offsetSize = parseInt(this.$attrs.mdOffsetSize, 10) || 0;
  21328. /** @type {?string} height or width element style on the container prior to auto-shrinking. */
  21329. this.oldElementSize = null;
  21330. /** @type {!number} Maximum amount of pixels allowed for a single DOM element */
  21331. this.maxElementPixels = $mdConstant.ELEMENT_MAX_PIXELS;
  21332. if (this.$attrs.mdTopIndex) {
  21333. /** @type {function(angular.Scope): number} Binds to topIndex on AngularJS scope */
  21334. this.bindTopIndex = $parse(this.$attrs.mdTopIndex);
  21335. /** @type {number} The index of the item that is at the top of the scroll container */
  21336. this.topIndex = this.bindTopIndex(this.$scope);
  21337. if (!angular.isDefined(this.topIndex)) {
  21338. this.topIndex = 0;
  21339. this.bindTopIndex.assign(this.$scope, 0);
  21340. }
  21341. this.$scope.$watch(this.bindTopIndex, angular.bind(this, function(newIndex) {
  21342. if (newIndex !== this.topIndex) {
  21343. this.scrollToIndex(newIndex);
  21344. }
  21345. }));
  21346. } else {
  21347. this.topIndex = 0;
  21348. }
  21349. this.scroller = $element[0].querySelector('.md-virtual-repeat-scroller');
  21350. this.sizer = this.scroller.querySelector('.md-virtual-repeat-sizer');
  21351. this.offsetter = this.scroller.querySelector('.md-virtual-repeat-offsetter');
  21352. // After the dom stablizes, measure the initial size of the container and
  21353. // make a best effort at re-measuring as it changes.
  21354. var boundUpdateSize = angular.bind(this, this.updateSize);
  21355. $$rAF(angular.bind(this, function() {
  21356. boundUpdateSize();
  21357. var debouncedUpdateSize = $mdUtil.debounce(boundUpdateSize, 10, null, false);
  21358. var jWindow = angular.element($window);
  21359. // Make one more attempt to get the size if it is 0.
  21360. // This is not by any means a perfect approach, but there's really no
  21361. // silver bullet here.
  21362. if (!this.size) {
  21363. debouncedUpdateSize();
  21364. }
  21365. jWindow.on('resize', debouncedUpdateSize);
  21366. $scope.$on('$destroy', function() {
  21367. jWindow.off('resize', debouncedUpdateSize);
  21368. });
  21369. $scope.$emit('$md-resize-enable');
  21370. $scope.$on('$md-resize', boundUpdateSize);
  21371. }));
  21372. }
  21373. /** Called by the md-virtual-repeat inside of the container at startup. */
  21374. VirtualRepeatContainerController.prototype.register = function(repeaterCtrl) {
  21375. this.repeater = repeaterCtrl;
  21376. angular.element(this.scroller)
  21377. .on('scroll wheel touchmove touchend', angular.bind(this, this.handleScroll_));
  21378. };
  21379. /** @return {boolean} Whether the container is configured for horizontal scrolling. */
  21380. VirtualRepeatContainerController.prototype.isHorizontal = function() {
  21381. return this.horizontal;
  21382. };
  21383. /** @return {number} The size (width or height) of the container. */
  21384. VirtualRepeatContainerController.prototype.getSize = function() {
  21385. return this.size;
  21386. };
  21387. /**
  21388. * Resizes the container.
  21389. * @private
  21390. * @param {number} size The new size to set.
  21391. */
  21392. VirtualRepeatContainerController.prototype.setSize_ = function(size) {
  21393. var dimension = this.getDimensionName_();
  21394. this.size = size;
  21395. this.$element[0].style[dimension] = size + 'px';
  21396. };
  21397. VirtualRepeatContainerController.prototype.unsetSize_ = function() {
  21398. this.$element[0].style[this.getDimensionName_()] = this.oldElementSize;
  21399. this.oldElementSize = null;
  21400. };
  21401. /** Instructs the container to re-measure its size. */
  21402. VirtualRepeatContainerController.prototype.updateSize = function() {
  21403. // If the original size is already determined, we can skip the update.
  21404. if (this.originalSize) return;
  21405. this.size = this.isHorizontal()
  21406. ? this.$element[0].clientWidth
  21407. : this.$element[0].clientHeight;
  21408. // Recheck the scroll position after updating the size. This resolves
  21409. // problems that can result if the scroll position was measured while the
  21410. // element was display: none or detached from the document.
  21411. this.handleScroll_();
  21412. this.repeater && this.repeater.containerUpdated();
  21413. };
  21414. /** @return {number} The container's scrollHeight or scrollWidth. */
  21415. VirtualRepeatContainerController.prototype.getScrollSize = function() {
  21416. return this.scrollSize;
  21417. };
  21418. VirtualRepeatContainerController.prototype.getDimensionName_ = function() {
  21419. return this.isHorizontal() ? 'width' : 'height';
  21420. };
  21421. /**
  21422. * Sets the scroller element to the specified size.
  21423. * @private
  21424. * @param {number} size The new size.
  21425. */
  21426. VirtualRepeatContainerController.prototype.sizeScroller_ = function(size) {
  21427. var dimension = this.getDimensionName_();
  21428. var crossDimension = this.isHorizontal() ? 'height' : 'width';
  21429. // Clear any existing dimensions.
  21430. this.sizer.innerHTML = '';
  21431. // If the size falls within the browser's maximum explicit size for a single element, we can
  21432. // set the size and be done. Otherwise, we have to create children that add up the the desired
  21433. // size.
  21434. if (size < this.maxElementPixels) {
  21435. this.sizer.style[dimension] = size + 'px';
  21436. } else {
  21437. this.sizer.style[dimension] = 'auto';
  21438. this.sizer.style[crossDimension] = 'auto';
  21439. // Divide the total size we have to render into N max-size pieces.
  21440. var numChildren = Math.floor(size / this.maxElementPixels);
  21441. // Element template to clone for each max-size piece.
  21442. var sizerChild = document.createElement('div');
  21443. sizerChild.style[dimension] = this.maxElementPixels + 'px';
  21444. sizerChild.style[crossDimension] = '1px';
  21445. for (var i = 0; i < numChildren; i++) {
  21446. this.sizer.appendChild(sizerChild.cloneNode(false));
  21447. }
  21448. // Re-use the element template for the remainder.
  21449. sizerChild.style[dimension] = (size - (numChildren * this.maxElementPixels)) + 'px';
  21450. this.sizer.appendChild(sizerChild);
  21451. }
  21452. };
  21453. /**
  21454. * If auto-shrinking is enabled, shrinks or unshrinks as appropriate.
  21455. * @private
  21456. * @param {number} size The new size.
  21457. */
  21458. VirtualRepeatContainerController.prototype.autoShrink_ = function(size) {
  21459. var shrinkSize = Math.max(size, this.autoShrinkMin * this.repeater.getItemSize());
  21460. if (this.autoShrink && shrinkSize !== this.size) {
  21461. if (this.oldElementSize === null) {
  21462. this.oldElementSize = this.$element[0].style[this.getDimensionName_()];
  21463. }
  21464. var currentSize = this.originalSize || this.size;
  21465. if (!currentSize || shrinkSize < currentSize) {
  21466. if (!this.originalSize) {
  21467. this.originalSize = this.size;
  21468. }
  21469. // Now we update the containers size, because shrinking is enabled.
  21470. this.setSize_(shrinkSize);
  21471. } else if (this.originalSize !== null) {
  21472. // Set the size back to our initial size.
  21473. this.unsetSize_();
  21474. var _originalSize = this.originalSize;
  21475. this.originalSize = null;
  21476. // We determine the repeaters size again, if the original size was zero.
  21477. // The originalSize needs to be null, to be able to determine the size.
  21478. if (!_originalSize) this.updateSize();
  21479. // Apply the original size or the determined size back to the container, because
  21480. // it has been overwritten before, in the shrink block.
  21481. this.setSize_(_originalSize || this.size);
  21482. }
  21483. this.repeater.containerUpdated();
  21484. }
  21485. };
  21486. /**
  21487. * Sets the scrollHeight or scrollWidth. Called by the repeater based on
  21488. * its item count and item size.
  21489. * @param {number} itemsSize The total size of the items.
  21490. */
  21491. VirtualRepeatContainerController.prototype.setScrollSize = function(itemsSize) {
  21492. var size = itemsSize + this.offsetSize;
  21493. if (this.scrollSize === size) return;
  21494. this.sizeScroller_(size);
  21495. this.autoShrink_(size);
  21496. this.scrollSize = size;
  21497. };
  21498. /** @return {number} The container's current scroll offset. */
  21499. VirtualRepeatContainerController.prototype.getScrollOffset = function() {
  21500. return this.scrollOffset;
  21501. };
  21502. /**
  21503. * Scrolls to a given scrollTop position.
  21504. * @param {number} position
  21505. */
  21506. VirtualRepeatContainerController.prototype.scrollTo = function(position) {
  21507. this.scroller[this.isHorizontal() ? 'scrollLeft' : 'scrollTop'] = position;
  21508. this.handleScroll_();
  21509. };
  21510. /**
  21511. * Scrolls the item with the given index to the top of the scroll container.
  21512. * @param {number} index
  21513. */
  21514. VirtualRepeatContainerController.prototype.scrollToIndex = function(index) {
  21515. var itemSize = this.repeater.getItemSize();
  21516. var itemsLength = this.repeater.itemsLength;
  21517. if(index > itemsLength) {
  21518. index = itemsLength - 1;
  21519. }
  21520. this.scrollTo(itemSize * index);
  21521. };
  21522. VirtualRepeatContainerController.prototype.resetScroll = function() {
  21523. this.scrollTo(0);
  21524. };
  21525. VirtualRepeatContainerController.prototype.handleScroll_ = function() {
  21526. var ltr = document.dir != 'rtl' && document.body.dir != 'rtl';
  21527. if(!ltr && !this.maxSize) {
  21528. this.scroller.scrollLeft = this.scrollSize;
  21529. this.maxSize = this.scroller.scrollLeft;
  21530. }
  21531. var offset = this.isHorizontal() ?
  21532. (ltr?this.scroller.scrollLeft : this.maxSize - this.scroller.scrollLeft)
  21533. : this.scroller.scrollTop;
  21534. if (offset === this.scrollOffset || offset > this.scrollSize - this.size) return;
  21535. var itemSize = this.repeater.getItemSize();
  21536. if (!itemSize) return;
  21537. var numItems = Math.max(0, Math.floor(offset / itemSize) - NUM_EXTRA);
  21538. var transform = (this.isHorizontal() ? 'translateX(' : 'translateY(') +
  21539. (!this.isHorizontal() || ltr ? (numItems * itemSize) : - (numItems * itemSize)) + 'px)';
  21540. this.scrollOffset = offset;
  21541. this.offsetter.style.webkitTransform = transform;
  21542. this.offsetter.style.transform = transform;
  21543. if (this.bindTopIndex) {
  21544. var topIndex = Math.floor(offset / itemSize);
  21545. if (topIndex !== this.topIndex && topIndex < this.repeater.getItemCount()) {
  21546. this.topIndex = topIndex;
  21547. this.bindTopIndex.assign(this.$scope, topIndex);
  21548. if (!this.$rootScope.$$phase) this.$scope.$digest();
  21549. }
  21550. }
  21551. this.repeater.containerUpdated();
  21552. };
  21553. /**
  21554. * @ngdoc directive
  21555. * @name mdVirtualRepeat
  21556. * @module material.components.virtualRepeat
  21557. * @restrict A
  21558. * @priority 1000
  21559. * @description
  21560. * `md-virtual-repeat` specifies an element to repeat using virtual scrolling.
  21561. *
  21562. * Virtual repeat is a limited substitute for ng-repeat that renders only
  21563. * enough DOM nodes to fill the container and recycling them as the user scrolls.
  21564. *
  21565. * Arrays, but not objects are supported for iteration.
  21566. * Track by, as alias, and (key, value) syntax are not supported.
  21567. *
  21568. * ### On-Demand Async Item Loading
  21569. *
  21570. * When using the `md-on-demand` attribute and loading some asynchronous data, the `getItemAtIndex` function will
  21571. * mostly return nothing.
  21572. *
  21573. * <hljs lang="js">
  21574. * DynamicItems.prototype.getItemAtIndex = function(index) {
  21575. * if (this.pages[index]) {
  21576. * return this.pages[index];
  21577. * } else {
  21578. * // This is an asynchronous action and does not return any value.
  21579. * this.loadPage(index);
  21580. * }
  21581. * };
  21582. * </hljs>
  21583. *
  21584. * This means that the VirtualRepeat will not have any value for the given index.<br/>
  21585. * After the data loading completed, the user expects the VirtualRepeat to recognize the change.
  21586. *
  21587. * To make sure that the VirtualRepeat properly detects any change, you need to run the operation
  21588. * in another digest.
  21589. *
  21590. * <hljs lang="js">
  21591. * DynamicItems.prototype.loadPage = function(index) {
  21592. * var self = this;
  21593. *
  21594. * // Trigger a new digest by using $timeout
  21595. * $timeout(function() {
  21596. * self.pages[index] = Data;
  21597. * });
  21598. * };
  21599. * </hljs>
  21600. *
  21601. * > <b>Note:</b> Please also review the
  21602. * <a ng-href="api/directive/mdVirtualRepeatContainer">VirtualRepeatContainer</a> documentation
  21603. * for more information.
  21604. *
  21605. * @usage
  21606. * <hljs lang="html">
  21607. * <md-virtual-repeat-container>
  21608. * <div md-virtual-repeat="i in items">Hello {{i}}!</div>
  21609. * </md-virtual-repeat-container>
  21610. *
  21611. * <md-virtual-repeat-container md-orient-horizontal>
  21612. * <div md-virtual-repeat="i in items" md-item-size="20">Hello {{i}}!</div>
  21613. * </md-virtual-repeat-container>
  21614. * </hljs>
  21615. *
  21616. * @param {number=} md-item-size The height or width of the repeated elements (which must be
  21617. * identical for each element). Optional. Will attempt to read the size from the dom if missing,
  21618. * but still assumes that all repeated nodes have same height or width.
  21619. * @param {string=} md-extra-name Evaluates to an additional name to which the current iterated item
  21620. * can be assigned on the repeated scope (needed for use in `md-autocomplete`).
  21621. * @param {boolean=} md-on-demand When present, treats the md-virtual-repeat argument as an object
  21622. * that can fetch rows rather than an array.
  21623. *
  21624. * **NOTE:** This object must implement the following interface with two (2) methods:
  21625. *
  21626. * - `getItemAtIndex: function(index) [object]` The item at that index or null if it is not yet
  21627. * loaded (it should start downloading the item in that case).
  21628. * - `getLength: function() [number]` The data length to which the repeater container
  21629. * should be sized. Ideally, when the count is known, this method should return it.
  21630. * Otherwise, return a higher number than the currently loaded items to produce an
  21631. * infinite-scroll behavior.
  21632. */
  21633. function VirtualRepeatDirective($parse) {
  21634. return {
  21635. controller: VirtualRepeatController,
  21636. priority: 1000,
  21637. require: ['mdVirtualRepeat', '^^mdVirtualRepeatContainer'],
  21638. restrict: 'A',
  21639. terminal: true,
  21640. transclude: 'element',
  21641. compile: function VirtualRepeatCompile($element, $attrs) {
  21642. var expression = $attrs.mdVirtualRepeat;
  21643. var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)\s*$/);
  21644. var repeatName = match[1];
  21645. var repeatListExpression = $parse(match[2]);
  21646. var extraName = $attrs.mdExtraName && $parse($attrs.mdExtraName);
  21647. return function VirtualRepeatLink($scope, $element, $attrs, ctrl, $transclude) {
  21648. ctrl[0].link_(ctrl[1], $transclude, repeatName, repeatListExpression, extraName);
  21649. };
  21650. }
  21651. };
  21652. }
  21653. /** @ngInject */
  21654. function VirtualRepeatController($scope, $element, $attrs, $browser, $document, $rootScope,
  21655. $$rAF, $mdUtil) {
  21656. this.$scope = $scope;
  21657. this.$element = $element;
  21658. this.$attrs = $attrs;
  21659. this.$browser = $browser;
  21660. this.$document = $document;
  21661. this.$mdUtil = $mdUtil;
  21662. this.$rootScope = $rootScope;
  21663. this.$$rAF = $$rAF;
  21664. /** @type {boolean} Whether we are in on-demand mode. */
  21665. this.onDemand = $mdUtil.parseAttributeBoolean($attrs.mdOnDemand);
  21666. /** @type {!Function} Backup reference to $browser.$$checkUrlChange */
  21667. this.browserCheckUrlChange = $browser.$$checkUrlChange;
  21668. /** @type {number} Most recent starting repeat index (based on scroll offset) */
  21669. this.newStartIndex = 0;
  21670. /** @type {number} Most recent ending repeat index (based on scroll offset) */
  21671. this.newEndIndex = 0;
  21672. /** @type {number} Most recent end visible index (based on scroll offset) */
  21673. this.newVisibleEnd = 0;
  21674. /** @type {number} Previous starting repeat index (based on scroll offset) */
  21675. this.startIndex = 0;
  21676. /** @type {number} Previous ending repeat index (based on scroll offset) */
  21677. this.endIndex = 0;
  21678. // TODO: measure width/height of first element from dom if not provided.
  21679. // getComputedStyle?
  21680. /** @type {?number} Height/width of repeated elements. */
  21681. this.itemSize = $scope.$eval($attrs.mdItemSize) || null;
  21682. /** @type {boolean} Whether this is the first time that items are rendered. */
  21683. this.isFirstRender = true;
  21684. /**
  21685. * @private {boolean} Whether the items in the list are already being updated. Used to prevent
  21686. * nested calls to virtualRepeatUpdate_.
  21687. */
  21688. this.isVirtualRepeatUpdating_ = false;
  21689. /** @type {number} Most recently seen length of items. */
  21690. this.itemsLength = 0;
  21691. /**
  21692. * @type {!Function} Unwatch callback for item size (when md-items-size is
  21693. * not specified), or angular.noop otherwise.
  21694. */
  21695. this.unwatchItemSize_ = angular.noop;
  21696. /**
  21697. * Presently rendered blocks by repeat index.
  21698. * @type {Object<number, !VirtualRepeatController.Block}
  21699. */
  21700. this.blocks = {};
  21701. /** @type {Array<!VirtualRepeatController.Block>} A pool of presently unused blocks. */
  21702. this.pooledBlocks = [];
  21703. $scope.$on('$destroy', angular.bind(this, this.cleanupBlocks_));
  21704. }
  21705. /**
  21706. * An object representing a repeated item.
  21707. * @typedef {{element: !jqLite, new: boolean, scope: !angular.Scope}}
  21708. */
  21709. VirtualRepeatController.Block;
  21710. /**
  21711. * Called at startup by the md-virtual-repeat postLink function.
  21712. * @param {!VirtualRepeatContainerController} container The container's controller.
  21713. * @param {!Function} transclude The repeated element's bound transclude function.
  21714. * @param {string} repeatName The left hand side of the repeat expression, indicating
  21715. * the name for each item in the array.
  21716. * @param {!Function} repeatListExpression A compiled expression based on the right hand side
  21717. * of the repeat expression. Points to the array to repeat over.
  21718. * @param {string|undefined} extraName The optional extra repeatName.
  21719. */
  21720. VirtualRepeatController.prototype.link_ =
  21721. function(container, transclude, repeatName, repeatListExpression, extraName) {
  21722. this.container = container;
  21723. this.transclude = transclude;
  21724. this.repeatName = repeatName;
  21725. this.rawRepeatListExpression = repeatListExpression;
  21726. this.extraName = extraName;
  21727. this.sized = false;
  21728. this.repeatListExpression = angular.bind(this, this.repeatListExpression_);
  21729. this.container.register(this);
  21730. };
  21731. /** @private Cleans up unused blocks. */
  21732. VirtualRepeatController.prototype.cleanupBlocks_ = function() {
  21733. angular.forEach(this.pooledBlocks, function cleanupBlock(block) {
  21734. block.element.remove();
  21735. });
  21736. };
  21737. /** @private Attempts to set itemSize by measuring a repeated element in the dom */
  21738. VirtualRepeatController.prototype.readItemSize_ = function() {
  21739. if (this.itemSize) {
  21740. // itemSize was successfully read in a different asynchronous call.
  21741. return;
  21742. }
  21743. this.items = this.repeatListExpression(this.$scope);
  21744. this.parentNode = this.$element[0].parentNode;
  21745. var block = this.getBlock_(0);
  21746. if (!block.element[0].parentNode) {
  21747. this.parentNode.appendChild(block.element[0]);
  21748. }
  21749. this.itemSize = block.element[0][
  21750. this.container.isHorizontal() ? 'offsetWidth' : 'offsetHeight'] || null;
  21751. this.blocks[0] = block;
  21752. this.poolBlock_(0);
  21753. if (this.itemSize) {
  21754. this.containerUpdated();
  21755. }
  21756. };
  21757. /**
  21758. * Returns the user-specified repeat list, transforming it into an array-like
  21759. * object in the case of infinite scroll/dynamic load mode.
  21760. * @param {!angular.Scope} The scope.
  21761. * @return {!Array|!Object} An array or array-like object for iteration.
  21762. */
  21763. VirtualRepeatController.prototype.repeatListExpression_ = function(scope) {
  21764. var repeatList = this.rawRepeatListExpression(scope);
  21765. if (this.onDemand && repeatList) {
  21766. var virtualList = new VirtualRepeatModelArrayLike(repeatList);
  21767. virtualList.$$includeIndexes(this.newStartIndex, this.newVisibleEnd);
  21768. return virtualList;
  21769. } else {
  21770. return repeatList;
  21771. }
  21772. };
  21773. /**
  21774. * Called by the container. Informs us that the containers scroll or size has
  21775. * changed.
  21776. */
  21777. VirtualRepeatController.prototype.containerUpdated = function() {
  21778. // If itemSize is unknown, attempt to measure it.
  21779. if (!this.itemSize) {
  21780. // Make sure to clean up watchers if we can (see #8178)
  21781. if(this.unwatchItemSize_ && this.unwatchItemSize_ !== angular.noop){
  21782. this.unwatchItemSize_();
  21783. }
  21784. this.unwatchItemSize_ = this.$scope.$watchCollection(
  21785. this.repeatListExpression,
  21786. angular.bind(this, function(items) {
  21787. if (items && items.length) {
  21788. this.readItemSize_();
  21789. }
  21790. }));
  21791. if (!this.$rootScope.$$phase) this.$scope.$digest();
  21792. return;
  21793. } else if (!this.sized) {
  21794. this.items = this.repeatListExpression(this.$scope);
  21795. }
  21796. if (!this.sized) {
  21797. this.unwatchItemSize_();
  21798. this.sized = true;
  21799. this.$scope.$watchCollection(this.repeatListExpression,
  21800. angular.bind(this, function(items, oldItems) {
  21801. if (!this.isVirtualRepeatUpdating_) {
  21802. this.virtualRepeatUpdate_(items, oldItems);
  21803. }
  21804. }));
  21805. }
  21806. this.updateIndexes_();
  21807. if (this.newStartIndex !== this.startIndex ||
  21808. this.newEndIndex !== this.endIndex ||
  21809. this.container.getScrollOffset() > this.container.getScrollSize()) {
  21810. if (this.items instanceof VirtualRepeatModelArrayLike) {
  21811. this.items.$$includeIndexes(this.newStartIndex, this.newEndIndex);
  21812. }
  21813. this.virtualRepeatUpdate_(this.items, this.items);
  21814. }
  21815. };
  21816. /**
  21817. * Called by the container. Returns the size of a single repeated item.
  21818. * @return {?number} Size of a repeated item.
  21819. */
  21820. VirtualRepeatController.prototype.getItemSize = function() {
  21821. return this.itemSize;
  21822. };
  21823. /**
  21824. * Called by the container. Returns the size of a single repeated item.
  21825. * @return {?number} Size of a repeated item.
  21826. */
  21827. VirtualRepeatController.prototype.getItemCount = function() {
  21828. return this.itemsLength;
  21829. };
  21830. /**
  21831. * Updates the order and visible offset of repeated blocks in response to scrolling
  21832. * or items updates.
  21833. * @private
  21834. */
  21835. VirtualRepeatController.prototype.virtualRepeatUpdate_ = function(items, oldItems) {
  21836. this.isVirtualRepeatUpdating_ = true;
  21837. var itemsLength = items && items.length || 0;
  21838. var lengthChanged = false;
  21839. // If the number of items shrank, keep the scroll position.
  21840. if (this.items && itemsLength < this.items.length && this.container.getScrollOffset() !== 0) {
  21841. this.items = items;
  21842. var previousScrollOffset = this.container.getScrollOffset();
  21843. this.container.resetScroll();
  21844. this.container.scrollTo(previousScrollOffset);
  21845. }
  21846. if (itemsLength !== this.itemsLength) {
  21847. lengthChanged = true;
  21848. this.itemsLength = itemsLength;
  21849. }
  21850. this.items = items;
  21851. if (items !== oldItems || lengthChanged) {
  21852. this.updateIndexes_();
  21853. }
  21854. this.parentNode = this.$element[0].parentNode;
  21855. if (lengthChanged) {
  21856. this.container.setScrollSize(itemsLength * this.itemSize);
  21857. }
  21858. // Detach and pool any blocks that are no longer in the viewport.
  21859. Object.keys(this.blocks).forEach(function(blockIndex) {
  21860. var index = parseInt(blockIndex, 10);
  21861. if (index < this.newStartIndex || index >= this.newEndIndex) {
  21862. this.poolBlock_(index);
  21863. }
  21864. }, this);
  21865. // Add needed blocks.
  21866. // For performance reasons, temporarily block browser url checks as we digest
  21867. // the restored block scopes ($$checkUrlChange reads window.location to
  21868. // check for changes and trigger route change, etc, which we don't need when
  21869. // trying to scroll at 60fps).
  21870. this.$browser.$$checkUrlChange = angular.noop;
  21871. var i, block,
  21872. newStartBlocks = [],
  21873. newEndBlocks = [];
  21874. // Collect blocks at the top.
  21875. for (i = this.newStartIndex; i < this.newEndIndex && this.blocks[i] == null; i++) {
  21876. block = this.getBlock_(i);
  21877. this.updateBlock_(block, i);
  21878. newStartBlocks.push(block);
  21879. }
  21880. // Update blocks that are already rendered.
  21881. for (; this.blocks[i] != null; i++) {
  21882. this.updateBlock_(this.blocks[i], i);
  21883. }
  21884. var maxIndex = i - 1;
  21885. // Collect blocks at the end.
  21886. for (; i < this.newEndIndex; i++) {
  21887. block = this.getBlock_(i);
  21888. this.updateBlock_(block, i);
  21889. newEndBlocks.push(block);
  21890. }
  21891. // Attach collected blocks to the document.
  21892. if (newStartBlocks.length) {
  21893. this.parentNode.insertBefore(
  21894. this.domFragmentFromBlocks_(newStartBlocks),
  21895. this.$element[0].nextSibling);
  21896. }
  21897. if (newEndBlocks.length) {
  21898. this.parentNode.insertBefore(
  21899. this.domFragmentFromBlocks_(newEndBlocks),
  21900. this.blocks[maxIndex] && this.blocks[maxIndex].element[0].nextSibling);
  21901. }
  21902. // Restore $$checkUrlChange.
  21903. this.$browser.$$checkUrlChange = this.browserCheckUrlChange;
  21904. this.startIndex = this.newStartIndex;
  21905. this.endIndex = this.newEndIndex;
  21906. if (this.isFirstRender) {
  21907. this.isFirstRender = false;
  21908. var firstRenderStartIndex = this.$attrs.mdStartIndex ?
  21909. this.$scope.$eval(this.$attrs.mdStartIndex) :
  21910. this.container.topIndex;
  21911. // The first call to virtualRepeatUpdate_ may not be when the virtual repeater is ready.
  21912. // Introduce a slight delay so that the update happens when it is actually ready.
  21913. this.$mdUtil.nextTick(function() {
  21914. this.container.scrollToIndex(firstRenderStartIndex);
  21915. }.bind(this));
  21916. }
  21917. this.isVirtualRepeatUpdating_ = false;
  21918. };
  21919. /**
  21920. * @param {number} index Where the block is to be in the repeated list.
  21921. * @return {!VirtualRepeatController.Block} A new or pooled block to place at the specified index.
  21922. * @private
  21923. */
  21924. VirtualRepeatController.prototype.getBlock_ = function(index) {
  21925. if (this.pooledBlocks.length) {
  21926. return this.pooledBlocks.pop();
  21927. }
  21928. var block;
  21929. this.transclude(angular.bind(this, function(clone, scope) {
  21930. block = {
  21931. element: clone,
  21932. new: true,
  21933. scope: scope
  21934. };
  21935. this.updateScope_(scope, index);
  21936. this.parentNode.appendChild(clone[0]);
  21937. }));
  21938. return block;
  21939. };
  21940. /**
  21941. * Updates and if not in a digest cycle, digests the specified block's scope to the data
  21942. * at the specified index.
  21943. * @param {!VirtualRepeatController.Block} block The block whose scope should be updated.
  21944. * @param {number} index The index to set.
  21945. * @private
  21946. */
  21947. VirtualRepeatController.prototype.updateBlock_ = function(block, index) {
  21948. this.blocks[index] = block;
  21949. if (!block.new &&
  21950. (block.scope.$index === index && block.scope[this.repeatName] === this.items[index])) {
  21951. return;
  21952. }
  21953. block.new = false;
  21954. // Update and digest the block's scope.
  21955. this.updateScope_(block.scope, index);
  21956. // Perform digest before reattaching the block.
  21957. // Any resulting synchronous dom mutations should be much faster as a result.
  21958. // This might break some directives, but I'm going to try it for now.
  21959. if (!this.$rootScope.$$phase) {
  21960. block.scope.$digest();
  21961. }
  21962. };
  21963. /**
  21964. * Updates scope to the data at the specified index.
  21965. * @param {!angular.Scope} scope The scope which should be updated.
  21966. * @param {number} index The index to set.
  21967. * @private
  21968. */
  21969. VirtualRepeatController.prototype.updateScope_ = function(scope, index) {
  21970. scope.$index = index;
  21971. scope[this.repeatName] = this.items && this.items[index];
  21972. if (this.extraName) scope[this.extraName(this.$scope)] = this.items[index];
  21973. };
  21974. /**
  21975. * Pools the block at the specified index (Pulls its element out of the dom and stores it).
  21976. * @param {number} index The index at which the block to pool is stored.
  21977. * @private
  21978. */
  21979. VirtualRepeatController.prototype.poolBlock_ = function(index) {
  21980. this.pooledBlocks.push(this.blocks[index]);
  21981. this.parentNode.removeChild(this.blocks[index].element[0]);
  21982. delete this.blocks[index];
  21983. };
  21984. /**
  21985. * Produces a dom fragment containing the elements from the list of blocks.
  21986. * @param {!Array<!VirtualRepeatController.Block>} blocks The blocks whose elements
  21987. * should be added to the document fragment.
  21988. * @return {DocumentFragment}
  21989. * @private
  21990. */
  21991. VirtualRepeatController.prototype.domFragmentFromBlocks_ = function(blocks) {
  21992. var fragment = this.$document[0].createDocumentFragment();
  21993. blocks.forEach(function(block) {
  21994. fragment.appendChild(block.element[0]);
  21995. });
  21996. return fragment;
  21997. };
  21998. /**
  21999. * Updates start and end indexes based on length of repeated items and container size.
  22000. * @private
  22001. */
  22002. VirtualRepeatController.prototype.updateIndexes_ = function() {
  22003. var itemsLength = this.items ? this.items.length : 0;
  22004. var containerLength = Math.ceil(this.container.getSize() / this.itemSize);
  22005. this.newStartIndex = Math.max(0, Math.min(
  22006. itemsLength - containerLength,
  22007. Math.floor(this.container.getScrollOffset() / this.itemSize)));
  22008. this.newVisibleEnd = this.newStartIndex + containerLength + NUM_EXTRA;
  22009. this.newEndIndex = Math.min(itemsLength, this.newVisibleEnd);
  22010. this.newStartIndex = Math.max(0, this.newStartIndex - NUM_EXTRA);
  22011. };
  22012. /**
  22013. * This VirtualRepeatModelArrayLike class enforces the interface requirements
  22014. * for infinite scrolling within a mdVirtualRepeatContainer. An object with this
  22015. * interface must implement the following interface with two (2) methods:
  22016. *
  22017. * getItemAtIndex: function(index) -> item at that index or null if it is not yet
  22018. * loaded (It should start downloading the item in that case).
  22019. *
  22020. * getLength: function() -> number The data legnth to which the repeater container
  22021. * should be sized. Ideally, when the count is known, this method should return it.
  22022. * Otherwise, return a higher number than the currently loaded items to produce an
  22023. * infinite-scroll behavior.
  22024. *
  22025. * @usage
  22026. * <hljs lang="html">
  22027. * <md-virtual-repeat-container md-orient-horizontal>
  22028. * <div md-virtual-repeat="i in items" md-on-demand>
  22029. * Hello {{i}}!
  22030. * </div>
  22031. * </md-virtual-repeat-container>
  22032. * </hljs>
  22033. *
  22034. */
  22035. function VirtualRepeatModelArrayLike(model) {
  22036. if (!angular.isFunction(model.getItemAtIndex) ||
  22037. !angular.isFunction(model.getLength)) {
  22038. throw Error('When md-on-demand is enabled, the Object passed to md-virtual-repeat must implement ' +
  22039. 'functions getItemAtIndex() and getLength() ');
  22040. }
  22041. this.model = model;
  22042. }
  22043. VirtualRepeatModelArrayLike.prototype.$$includeIndexes = function(start, end) {
  22044. for (var i = start; i < end; i++) {
  22045. if (!this.hasOwnProperty(i)) {
  22046. this[i] = this.model.getItemAtIndex(i);
  22047. }
  22048. }
  22049. this.length = this.model.getLength();
  22050. };
  22051. /**
  22052. * @ngdoc directive
  22053. * @name mdForceHeight
  22054. * @module material.components.virtualRepeat
  22055. * @restrict A
  22056. * @description
  22057. *
  22058. * Force an element to have a certain px height. This is used in place of a style tag in order to
  22059. * conform to the Content Security Policy regarding unsafe-inline style tags.
  22060. *
  22061. * @usage
  22062. * <hljs lang="html">
  22063. * <div md-force-height="'100px'"></div>
  22064. * </hljs>
  22065. */
  22066. function ForceHeightDirective($mdUtil) {
  22067. return {
  22068. restrict: 'A',
  22069. link: function(scope, element, attrs) {
  22070. var height = scope.$eval(attrs.mdForceHeight) || null;
  22071. if (height && element) {
  22072. element[0].style.height = height;
  22073. }
  22074. }
  22075. };
  22076. }
  22077. ForceHeightDirective.$inject = ['$mdUtil'];
  22078. })();
  22079. (function(){
  22080. "use strict";
  22081. /**
  22082. * @ngdoc module
  22083. * @name material.components.whiteframe
  22084. */
  22085. MdWhiteframeDirective.$inject = ["$log"];
  22086. angular
  22087. .module('material.components.whiteframe', ['material.core'])
  22088. .directive('mdWhiteframe', MdWhiteframeDirective);
  22089. /**
  22090. * @ngdoc directive
  22091. * @module material.components.whiteframe
  22092. * @name mdWhiteframe
  22093. *
  22094. * @description
  22095. * The md-whiteframe directive allows you to apply an elevation shadow to an element.
  22096. *
  22097. * The attribute values needs to be a number between 1 and 24 or -1.
  22098. * When set to -1 no style is applied.
  22099. *
  22100. * ### Notes
  22101. * - If there is no value specified it defaults to 4dp.
  22102. * - If the value is not valid it defaults to 4dp.
  22103. * @usage
  22104. * <hljs lang="html">
  22105. * <div md-whiteframe="3">
  22106. * <span>Elevation of 3dp</span>
  22107. * </div>
  22108. * </hljs>
  22109. *
  22110. * <hljs lang="html">
  22111. * <div md-whiteframe="-1">
  22112. * <span>No elevation shadow applied</span>
  22113. * </div>
  22114. * </hljs>
  22115. *
  22116. * <hljs lang="html">
  22117. * <div ng-init="elevation = 5" md-whiteframe="{{elevation}}">
  22118. * <span>Elevation of 5dp with an interpolated value</span>
  22119. * </div>
  22120. * </hljs>
  22121. */
  22122. function MdWhiteframeDirective($log) {
  22123. var DISABLE_DP = -1;
  22124. var MIN_DP = 1;
  22125. var MAX_DP = 24;
  22126. var DEFAULT_DP = 4;
  22127. return {
  22128. link: postLink
  22129. };
  22130. function postLink(scope, element, attr) {
  22131. var oldClass = '';
  22132. attr.$observe('mdWhiteframe', function(elevation) {
  22133. elevation = parseInt(elevation, 10) || DEFAULT_DP;
  22134. if (elevation != DISABLE_DP && (elevation > MAX_DP || elevation < MIN_DP)) {
  22135. $log.warn('md-whiteframe attribute value is invalid. It should be a number between ' + MIN_DP + ' and ' + MAX_DP, element[0]);
  22136. elevation = DEFAULT_DP;
  22137. }
  22138. var newClass = elevation == DISABLE_DP ? '' : 'md-whiteframe-' + elevation + 'dp';
  22139. attr.$updateClass(newClass, oldClass);
  22140. oldClass = newClass;
  22141. });
  22142. }
  22143. }
  22144. })();
  22145. (function(){
  22146. "use strict";
  22147. MdAutocompleteCtrl.$inject = ["$scope", "$element", "$mdUtil", "$mdConstant", "$mdTheming", "$window", "$animate", "$rootElement", "$attrs", "$q", "$log", "$mdLiveAnnouncer"];angular
  22148. .module('material.components.autocomplete')
  22149. .controller('MdAutocompleteCtrl', MdAutocompleteCtrl);
  22150. var ITEM_HEIGHT = 48,
  22151. MAX_ITEMS = 5,
  22152. MENU_PADDING = 8,
  22153. INPUT_PADDING = 2; // Padding provided by `md-input-container`
  22154. function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming, $window,
  22155. $animate, $rootElement, $attrs, $q, $log, $mdLiveAnnouncer) {
  22156. // Internal Variables.
  22157. var ctrl = this,
  22158. itemParts = $scope.itemsExpr.split(/ in /i),
  22159. itemExpr = itemParts[ 1 ],
  22160. elements = null,
  22161. cache = {},
  22162. noBlur = false,
  22163. selectedItemWatchers = [],
  22164. hasFocus = false,
  22165. fetchesInProgress = 0,
  22166. enableWrapScroll = null,
  22167. inputModelCtrl = null,
  22168. debouncedOnResize = $mdUtil.debounce(onWindowResize);
  22169. // Public Exported Variables with handlers
  22170. defineProperty('hidden', handleHiddenChange, true);
  22171. // Public Exported Variables
  22172. ctrl.scope = $scope;
  22173. ctrl.parent = $scope.$parent;
  22174. ctrl.itemName = itemParts[ 0 ];
  22175. ctrl.matches = [];
  22176. ctrl.loading = false;
  22177. ctrl.hidden = true;
  22178. ctrl.index = null;
  22179. ctrl.id = $mdUtil.nextUid();
  22180. ctrl.isDisabled = null;
  22181. ctrl.isRequired = null;
  22182. ctrl.isReadonly = null;
  22183. ctrl.hasNotFound = false;
  22184. // Public Exported Methods
  22185. ctrl.keydown = keydown;
  22186. ctrl.blur = blur;
  22187. ctrl.focus = focus;
  22188. ctrl.clear = clearValue;
  22189. ctrl.select = select;
  22190. ctrl.listEnter = onListEnter;
  22191. ctrl.listLeave = onListLeave;
  22192. ctrl.mouseUp = onMouseup;
  22193. ctrl.getCurrentDisplayValue = getCurrentDisplayValue;
  22194. ctrl.registerSelectedItemWatcher = registerSelectedItemWatcher;
  22195. ctrl.unregisterSelectedItemWatcher = unregisterSelectedItemWatcher;
  22196. ctrl.notFoundVisible = notFoundVisible;
  22197. ctrl.loadingIsVisible = loadingIsVisible;
  22198. ctrl.positionDropdown = positionDropdown;
  22199. /**
  22200. * Report types to be used for the $mdLiveAnnouncer
  22201. * @enum {number} Unique flag id.
  22202. */
  22203. var ReportType = {
  22204. Count: 1,
  22205. Selected: 2
  22206. };
  22207. return init();
  22208. //-- initialization methods
  22209. /**
  22210. * Initialize the controller, setup watchers, gather elements
  22211. */
  22212. function init () {
  22213. $mdUtil.initOptionalProperties($scope, $attrs, {
  22214. searchText: '',
  22215. selectedItem: null,
  22216. clearButton: false
  22217. });
  22218. $mdTheming($element);
  22219. configureWatchers();
  22220. $mdUtil.nextTick(function () {
  22221. gatherElements();
  22222. moveDropdown();
  22223. // Forward all focus events to the input element when autofocus is enabled
  22224. if ($scope.autofocus) {
  22225. $element.on('focus', focusInputElement);
  22226. }
  22227. });
  22228. }
  22229. function updateModelValidators() {
  22230. if (!$scope.requireMatch || !inputModelCtrl) return;
  22231. inputModelCtrl.$setValidity('md-require-match', !!$scope.selectedItem || !$scope.searchText);
  22232. }
  22233. /**
  22234. * Calculates the dropdown's position and applies the new styles to the menu element
  22235. * @returns {*}
  22236. */
  22237. function positionDropdown () {
  22238. if (!elements) {
  22239. return $mdUtil.nextTick(positionDropdown, false, $scope);
  22240. }
  22241. var dropdownHeight = ($scope.dropdownItems || MAX_ITEMS) * ITEM_HEIGHT;
  22242. var hrect = elements.wrap.getBoundingClientRect(),
  22243. vrect = elements.snap.getBoundingClientRect(),
  22244. root = elements.root.getBoundingClientRect(),
  22245. top = vrect.bottom - root.top,
  22246. bot = root.bottom - vrect.top,
  22247. left = hrect.left - root.left,
  22248. width = hrect.width,
  22249. offset = getVerticalOffset(),
  22250. position = $scope.dropdownPosition,
  22251. styles;
  22252. // Automatically determine dropdown placement based on available space in viewport.
  22253. if (!position) {
  22254. position = (top > bot && root.height - top - MENU_PADDING < dropdownHeight) ? 'top' : 'bottom';
  22255. }
  22256. // Adjust the width to account for the padding provided by `md-input-container`
  22257. if ($attrs.mdFloatingLabel) {
  22258. left += INPUT_PADDING;
  22259. width -= INPUT_PADDING * 2;
  22260. }
  22261. styles = {
  22262. left: left + 'px',
  22263. minWidth: width + 'px',
  22264. maxWidth: Math.max(hrect.right - root.left, root.right - hrect.left) - MENU_PADDING + 'px'
  22265. };
  22266. if (position === 'top') {
  22267. styles.top = 'auto';
  22268. styles.bottom = bot + 'px';
  22269. styles.maxHeight = Math.min(dropdownHeight, hrect.top - root.top - MENU_PADDING) + 'px';
  22270. } else {
  22271. var bottomSpace = root.bottom - hrect.bottom - MENU_PADDING + $mdUtil.getViewportTop();
  22272. styles.top = (top - offset) + 'px';
  22273. styles.bottom = 'auto';
  22274. styles.maxHeight = Math.min(dropdownHeight, bottomSpace) + 'px';
  22275. }
  22276. elements.$.scrollContainer.css(styles);
  22277. $mdUtil.nextTick(correctHorizontalAlignment, false);
  22278. /**
  22279. * Calculates the vertical offset for floating label examples to account for ngMessages
  22280. * @returns {number}
  22281. */
  22282. function getVerticalOffset () {
  22283. var offset = 0;
  22284. var inputContainer = $element.find('md-input-container');
  22285. if (inputContainer.length) {
  22286. var input = inputContainer.find('input');
  22287. offset = inputContainer.prop('offsetHeight');
  22288. offset -= input.prop('offsetTop');
  22289. offset -= input.prop('offsetHeight');
  22290. // add in the height left up top for the floating label text
  22291. offset += inputContainer.prop('offsetTop');
  22292. }
  22293. return offset;
  22294. }
  22295. /**
  22296. * Makes sure that the menu doesn't go off of the screen on either side.
  22297. */
  22298. function correctHorizontalAlignment () {
  22299. var dropdown = elements.scrollContainer.getBoundingClientRect(),
  22300. styles = {};
  22301. if (dropdown.right > root.right - MENU_PADDING) {
  22302. styles.left = (hrect.right - dropdown.width) + 'px';
  22303. }
  22304. elements.$.scrollContainer.css(styles);
  22305. }
  22306. }
  22307. /**
  22308. * Moves the dropdown menu to the body tag in order to avoid z-index and overflow issues.
  22309. */
  22310. function moveDropdown () {
  22311. if (!elements.$.root.length) return;
  22312. $mdTheming(elements.$.scrollContainer);
  22313. elements.$.scrollContainer.detach();
  22314. elements.$.root.append(elements.$.scrollContainer);
  22315. if ($animate.pin) $animate.pin(elements.$.scrollContainer, $rootElement);
  22316. }
  22317. /**
  22318. * Sends focus to the input element.
  22319. */
  22320. function focusInputElement () {
  22321. elements.input.focus();
  22322. }
  22323. /**
  22324. * Sets up any watchers used by autocomplete
  22325. */
  22326. function configureWatchers () {
  22327. var wait = parseInt($scope.delay, 10) || 0;
  22328. $attrs.$observe('disabled', function (value) { ctrl.isDisabled = $mdUtil.parseAttributeBoolean(value, false); });
  22329. $attrs.$observe('required', function (value) { ctrl.isRequired = $mdUtil.parseAttributeBoolean(value, false); });
  22330. $attrs.$observe('readonly', function (value) { ctrl.isReadonly = $mdUtil.parseAttributeBoolean(value, false); });
  22331. $scope.$watch('searchText', wait ? $mdUtil.debounce(handleSearchText, wait) : handleSearchText);
  22332. $scope.$watch('selectedItem', selectedItemChange);
  22333. angular.element($window).on('resize', debouncedOnResize);
  22334. $scope.$on('$destroy', cleanup);
  22335. }
  22336. /**
  22337. * Removes any events or leftover elements created by this controller
  22338. */
  22339. function cleanup () {
  22340. if (!ctrl.hidden) {
  22341. $mdUtil.enableScrolling();
  22342. }
  22343. angular.element($window).off('resize', debouncedOnResize);
  22344. if ( elements ){
  22345. var items = ['ul', 'scroller', 'scrollContainer', 'input'];
  22346. angular.forEach(items, function(key){
  22347. elements.$[key].remove();
  22348. });
  22349. }
  22350. }
  22351. /**
  22352. * Event handler to be called whenever the window resizes.
  22353. */
  22354. function onWindowResize() {
  22355. if (!ctrl.hidden) {
  22356. positionDropdown();
  22357. }
  22358. }
  22359. /**
  22360. * Gathers all of the elements needed for this controller
  22361. */
  22362. function gatherElements () {
  22363. var snapWrap = gatherSnapWrap();
  22364. elements = {
  22365. main: $element[0],
  22366. scrollContainer: $element[0].querySelector('.md-virtual-repeat-container'),
  22367. scroller: $element[0].querySelector('.md-virtual-repeat-scroller'),
  22368. ul: $element.find('ul')[0],
  22369. input: $element.find('input')[0],
  22370. wrap: snapWrap.wrap,
  22371. snap: snapWrap.snap,
  22372. root: document.body
  22373. };
  22374. elements.li = elements.ul.getElementsByTagName('li');
  22375. elements.$ = getAngularElements(elements);
  22376. inputModelCtrl = elements.$.input.controller('ngModel');
  22377. }
  22378. /**
  22379. * Gathers the snap and wrap elements
  22380. *
  22381. */
  22382. function gatherSnapWrap() {
  22383. var element;
  22384. var value;
  22385. for (element = $element; element.length; element = element.parent()) {
  22386. value = element.attr('md-autocomplete-snap');
  22387. if (angular.isDefined(value)) break;
  22388. }
  22389. if (element.length) {
  22390. return {
  22391. snap: element[0],
  22392. wrap: (value.toLowerCase() === 'width') ? element[0] : $element.find('md-autocomplete-wrap')[0]
  22393. };
  22394. }
  22395. var wrap = $element.find('md-autocomplete-wrap')[0];
  22396. return {
  22397. snap: wrap,
  22398. wrap: wrap
  22399. };
  22400. }
  22401. /**
  22402. * Gathers angular-wrapped versions of each element
  22403. * @param elements
  22404. * @returns {{}}
  22405. */
  22406. function getAngularElements (elements) {
  22407. var obj = {};
  22408. for (var key in elements) {
  22409. if (elements.hasOwnProperty(key)) obj[ key ] = angular.element(elements[ key ]);
  22410. }
  22411. return obj;
  22412. }
  22413. //-- event/change handlers
  22414. /**
  22415. * Handles changes to the `hidden` property.
  22416. * @param hidden
  22417. * @param oldHidden
  22418. */
  22419. function handleHiddenChange (hidden, oldHidden) {
  22420. if (!hidden && oldHidden) {
  22421. positionDropdown();
  22422. // Report in polite mode, because the screenreader should finish the default description of
  22423. // the input. element.
  22424. reportMessages(true, ReportType.Count | ReportType.Selected);
  22425. if (elements) {
  22426. $mdUtil.disableScrollAround(elements.ul);
  22427. enableWrapScroll = disableElementScrollEvents(angular.element(elements.wrap));
  22428. }
  22429. } else if (hidden && !oldHidden) {
  22430. $mdUtil.enableScrolling();
  22431. if (enableWrapScroll) {
  22432. enableWrapScroll();
  22433. enableWrapScroll = null;
  22434. }
  22435. }
  22436. }
  22437. /**
  22438. * Disables scrolling for a specific element
  22439. */
  22440. function disableElementScrollEvents(element) {
  22441. function preventDefault(e) {
  22442. e.preventDefault();
  22443. }
  22444. element.on('wheel', preventDefault);
  22445. element.on('touchmove', preventDefault);
  22446. return function() {
  22447. element.off('wheel', preventDefault);
  22448. element.off('touchmove', preventDefault);
  22449. };
  22450. }
  22451. /**
  22452. * When the user mouses over the dropdown menu, ignore blur events.
  22453. */
  22454. function onListEnter () {
  22455. noBlur = true;
  22456. }
  22457. /**
  22458. * When the user's mouse leaves the menu, blur events may hide the menu again.
  22459. */
  22460. function onListLeave () {
  22461. if (!hasFocus && !ctrl.hidden) elements.input.focus();
  22462. noBlur = false;
  22463. ctrl.hidden = shouldHide();
  22464. }
  22465. /**
  22466. * When the mouse button is released, send focus back to the input field.
  22467. */
  22468. function onMouseup () {
  22469. elements.input.focus();
  22470. }
  22471. /**
  22472. * Handles changes to the selected item.
  22473. * @param selectedItem
  22474. * @param previousSelectedItem
  22475. */
  22476. function selectedItemChange (selectedItem, previousSelectedItem) {
  22477. updateModelValidators();
  22478. if (selectedItem) {
  22479. getDisplayValue(selectedItem).then(function (val) {
  22480. $scope.searchText = val;
  22481. handleSelectedItemChange(selectedItem, previousSelectedItem);
  22482. });
  22483. } else if (previousSelectedItem && $scope.searchText) {
  22484. getDisplayValue(previousSelectedItem).then(function(displayValue) {
  22485. // Clear the searchText, when the selectedItem is set to null.
  22486. // Do not clear the searchText, when the searchText isn't matching with the previous
  22487. // selected item.
  22488. if (angular.isString($scope.searchText)
  22489. && displayValue.toString().toLowerCase() === $scope.searchText.toLowerCase()) {
  22490. $scope.searchText = '';
  22491. }
  22492. });
  22493. }
  22494. if (selectedItem !== previousSelectedItem) announceItemChange();
  22495. }
  22496. /**
  22497. * Use the user-defined expression to announce changes each time a new item is selected
  22498. */
  22499. function announceItemChange () {
  22500. angular.isFunction($scope.itemChange) && $scope.itemChange(getItemAsNameVal($scope.selectedItem));
  22501. }
  22502. /**
  22503. * Use the user-defined expression to announce changes each time the search text is changed
  22504. */
  22505. function announceTextChange () {
  22506. angular.isFunction($scope.textChange) && $scope.textChange();
  22507. }
  22508. /**
  22509. * Calls any external watchers listening for the selected item. Used in conjunction with
  22510. * `registerSelectedItemWatcher`.
  22511. * @param selectedItem
  22512. * @param previousSelectedItem
  22513. */
  22514. function handleSelectedItemChange (selectedItem, previousSelectedItem) {
  22515. selectedItemWatchers.forEach(function (watcher) { watcher(selectedItem, previousSelectedItem); });
  22516. }
  22517. /**
  22518. * Register a function to be called when the selected item changes.
  22519. * @param cb
  22520. */
  22521. function registerSelectedItemWatcher (cb) {
  22522. if (selectedItemWatchers.indexOf(cb) == -1) {
  22523. selectedItemWatchers.push(cb);
  22524. }
  22525. }
  22526. /**
  22527. * Unregister a function previously registered for selected item changes.
  22528. * @param cb
  22529. */
  22530. function unregisterSelectedItemWatcher (cb) {
  22531. var i = selectedItemWatchers.indexOf(cb);
  22532. if (i != -1) {
  22533. selectedItemWatchers.splice(i, 1);
  22534. }
  22535. }
  22536. /**
  22537. * Handles changes to the searchText property.
  22538. * @param searchText
  22539. * @param previousSearchText
  22540. */
  22541. function handleSearchText (searchText, previousSearchText) {
  22542. ctrl.index = getDefaultIndex();
  22543. // do nothing on init
  22544. if (searchText === previousSearchText) return;
  22545. updateModelValidators();
  22546. getDisplayValue($scope.selectedItem).then(function (val) {
  22547. // clear selected item if search text no longer matches it
  22548. if (searchText !== val) {
  22549. $scope.selectedItem = null;
  22550. // trigger change event if available
  22551. if (searchText !== previousSearchText) announceTextChange();
  22552. // cancel results if search text is not long enough
  22553. if (!isMinLengthMet()) {
  22554. ctrl.matches = [];
  22555. setLoading(false);
  22556. reportMessages(false, ReportType.Count);
  22557. } else {
  22558. handleQuery();
  22559. }
  22560. }
  22561. });
  22562. }
  22563. /**
  22564. * Handles input blur event, determines if the dropdown should hide.
  22565. */
  22566. function blur($event) {
  22567. hasFocus = false;
  22568. if (!noBlur) {
  22569. ctrl.hidden = shouldHide();
  22570. evalAttr('ngBlur', { $event: $event });
  22571. }
  22572. }
  22573. /**
  22574. * Force blur on input element
  22575. * @param forceBlur
  22576. */
  22577. function doBlur(forceBlur) {
  22578. if (forceBlur) {
  22579. noBlur = false;
  22580. hasFocus = false;
  22581. }
  22582. elements.input.blur();
  22583. }
  22584. /**
  22585. * Handles input focus event, determines if the dropdown should show.
  22586. */
  22587. function focus($event) {
  22588. hasFocus = true;
  22589. if (isSearchable() && isMinLengthMet()) {
  22590. handleQuery();
  22591. }
  22592. ctrl.hidden = shouldHide();
  22593. evalAttr('ngFocus', { $event: $event });
  22594. }
  22595. /**
  22596. * Handles keyboard input.
  22597. * @param event
  22598. */
  22599. function keydown (event) {
  22600. switch (event.keyCode) {
  22601. case $mdConstant.KEY_CODE.DOWN_ARROW:
  22602. if (ctrl.loading) return;
  22603. event.stopPropagation();
  22604. event.preventDefault();
  22605. ctrl.index = Math.min(ctrl.index + 1, ctrl.matches.length - 1);
  22606. updateScroll();
  22607. reportMessages(false, ReportType.Selected);
  22608. break;
  22609. case $mdConstant.KEY_CODE.UP_ARROW:
  22610. if (ctrl.loading) return;
  22611. event.stopPropagation();
  22612. event.preventDefault();
  22613. ctrl.index = ctrl.index < 0 ? ctrl.matches.length - 1 : Math.max(0, ctrl.index - 1);
  22614. updateScroll();
  22615. reportMessages(false, ReportType.Selected);
  22616. break;
  22617. case $mdConstant.KEY_CODE.TAB:
  22618. // If we hit tab, assume that we've left the list so it will close
  22619. onListLeave();
  22620. if (ctrl.hidden || ctrl.loading || ctrl.index < 0 || ctrl.matches.length < 1) return;
  22621. select(ctrl.index);
  22622. break;
  22623. case $mdConstant.KEY_CODE.ENTER:
  22624. if (ctrl.hidden || ctrl.loading || ctrl.index < 0 || ctrl.matches.length < 1) return;
  22625. if (hasSelection()) return;
  22626. event.stopPropagation();
  22627. event.preventDefault();
  22628. select(ctrl.index);
  22629. break;
  22630. case $mdConstant.KEY_CODE.ESCAPE:
  22631. event.preventDefault(); // Prevent browser from always clearing input
  22632. if (!shouldProcessEscape()) return;
  22633. event.stopPropagation();
  22634. clearSelectedItem();
  22635. if ($scope.searchText && hasEscapeOption('clear')) {
  22636. clearSearchText();
  22637. }
  22638. // Manually hide (needed for mdNotFound support)
  22639. ctrl.hidden = true;
  22640. if (hasEscapeOption('blur')) {
  22641. // Force the component to blur if they hit escape
  22642. doBlur(true);
  22643. }
  22644. break;
  22645. default:
  22646. }
  22647. }
  22648. //-- getters
  22649. /**
  22650. * Returns the minimum length needed to display the dropdown.
  22651. * @returns {*}
  22652. */
  22653. function getMinLength () {
  22654. return angular.isNumber($scope.minLength) ? $scope.minLength : 1;
  22655. }
  22656. /**
  22657. * Returns the display value for an item.
  22658. * @param item
  22659. * @returns {*}
  22660. */
  22661. function getDisplayValue (item) {
  22662. return $q.when(getItemText(item) || item).then(function(itemText) {
  22663. if (itemText && !angular.isString(itemText)) {
  22664. $log.warn('md-autocomplete: Could not resolve display value to a string. ' +
  22665. 'Please check the `md-item-text` attribute.');
  22666. }
  22667. return itemText;
  22668. });
  22669. /**
  22670. * Getter function to invoke user-defined expression (in the directive)
  22671. * to convert your object to a single string.
  22672. */
  22673. function getItemText (item) {
  22674. return (item && $scope.itemText) ? $scope.itemText(getItemAsNameVal(item)) : null;
  22675. }
  22676. }
  22677. /**
  22678. * Returns the locals object for compiling item templates.
  22679. * @param item
  22680. * @returns {{}}
  22681. */
  22682. function getItemAsNameVal (item) {
  22683. if (!item) return undefined;
  22684. var locals = {};
  22685. if (ctrl.itemName) locals[ ctrl.itemName ] = item;
  22686. return locals;
  22687. }
  22688. /**
  22689. * Returns the default index based on whether or not autoselect is enabled.
  22690. * @returns {number}
  22691. */
  22692. function getDefaultIndex () {
  22693. return $scope.autoselect ? 0 : -1;
  22694. }
  22695. /**
  22696. * Sets the loading parameter and updates the hidden state.
  22697. * @param value {boolean} Whether or not the component is currently loading.
  22698. */
  22699. function setLoading(value) {
  22700. if (ctrl.loading != value) {
  22701. ctrl.loading = value;
  22702. }
  22703. // Always refresh the hidden variable as something else might have changed
  22704. ctrl.hidden = shouldHide();
  22705. }
  22706. /**
  22707. * Determines if the menu should be hidden.
  22708. * @returns {boolean}
  22709. */
  22710. function shouldHide () {
  22711. if (!isSearchable()) return true; // Hide when not able to query
  22712. else return !shouldShow(); // Hide when the dropdown is not able to show.
  22713. }
  22714. /**
  22715. * Determines whether the autocomplete is able to query within the current state.
  22716. * @returns {boolean}
  22717. */
  22718. function isSearchable() {
  22719. if (ctrl.loading && !hasMatches()) return false; // No query when query is in progress.
  22720. else if (hasSelection()) return false; // No query if there is already a selection
  22721. else if (!hasFocus) return false; // No query if the input does not have focus
  22722. return true;
  22723. }
  22724. /**
  22725. * Determines if the escape keydown should be processed
  22726. * @returns {boolean}
  22727. */
  22728. function shouldProcessEscape() {
  22729. return hasEscapeOption('blur') || !ctrl.hidden || ctrl.loading || hasEscapeOption('clear') && $scope.searchText;
  22730. }
  22731. /**
  22732. * Determines if an escape option is set
  22733. * @returns {boolean}
  22734. */
  22735. function hasEscapeOption(option) {
  22736. return !$scope.escapeOptions || $scope.escapeOptions.toLowerCase().indexOf(option) !== -1;
  22737. }
  22738. /**
  22739. * Determines if the menu should be shown.
  22740. * @returns {boolean}
  22741. */
  22742. function shouldShow() {
  22743. return (isMinLengthMet() && hasMatches()) || notFoundVisible();
  22744. }
  22745. /**
  22746. * Returns true if the search text has matches.
  22747. * @returns {boolean}
  22748. */
  22749. function hasMatches() {
  22750. return ctrl.matches.length ? true : false;
  22751. }
  22752. /**
  22753. * Returns true if the autocomplete has a valid selection.
  22754. * @returns {boolean}
  22755. */
  22756. function hasSelection() {
  22757. return ctrl.scope.selectedItem ? true : false;
  22758. }
  22759. /**
  22760. * Returns true if the loading indicator is, or should be, visible.
  22761. * @returns {boolean}
  22762. */
  22763. function loadingIsVisible() {
  22764. return ctrl.loading && !hasSelection();
  22765. }
  22766. /**
  22767. * Returns the display value of the current item.
  22768. * @returns {*}
  22769. */
  22770. function getCurrentDisplayValue () {
  22771. return getDisplayValue(ctrl.matches[ ctrl.index ]);
  22772. }
  22773. /**
  22774. * Determines if the minimum length is met by the search text.
  22775. * @returns {*}
  22776. */
  22777. function isMinLengthMet () {
  22778. return ($scope.searchText || '').length >= getMinLength();
  22779. }
  22780. //-- actions
  22781. /**
  22782. * Defines a public property with a handler and a default value.
  22783. * @param key
  22784. * @param handler
  22785. * @param value
  22786. */
  22787. function defineProperty (key, handler, value) {
  22788. Object.defineProperty(ctrl, key, {
  22789. get: function () { return value; },
  22790. set: function (newValue) {
  22791. var oldValue = value;
  22792. value = newValue;
  22793. handler(newValue, oldValue);
  22794. }
  22795. });
  22796. }
  22797. /**
  22798. * Selects the item at the given index.
  22799. * @param index
  22800. */
  22801. function select (index) {
  22802. //-- force form to update state for validation
  22803. $mdUtil.nextTick(function () {
  22804. getDisplayValue(ctrl.matches[ index ]).then(function (val) {
  22805. var ngModel = elements.$.input.controller('ngModel');
  22806. ngModel.$setViewValue(val);
  22807. ngModel.$render();
  22808. }).finally(function () {
  22809. $scope.selectedItem = ctrl.matches[ index ];
  22810. setLoading(false);
  22811. });
  22812. }, false);
  22813. }
  22814. /**
  22815. * Clears the searchText value and selected item.
  22816. */
  22817. function clearValue () {
  22818. clearSelectedItem();
  22819. clearSearchText();
  22820. }
  22821. /**
  22822. * Clears the selected item
  22823. */
  22824. function clearSelectedItem () {
  22825. // Reset our variables
  22826. ctrl.index = 0;
  22827. ctrl.matches = [];
  22828. }
  22829. /**
  22830. * Clears the searchText value
  22831. */
  22832. function clearSearchText () {
  22833. // Set the loading to true so we don't see flashes of content.
  22834. // The flashing will only occur when an async request is running.
  22835. // So the loading process will stop when the results had been retrieved.
  22836. setLoading(true);
  22837. $scope.searchText = '';
  22838. // Normally, triggering the change / input event is unnecessary, because the browser detects it properly.
  22839. // But some browsers are not detecting it properly, which means that we have to trigger the event.
  22840. // Using the `input` is not working properly, because for example IE11 is not supporting the `input` event.
  22841. // The `change` event is a good alternative and is supported by all supported browsers.
  22842. var eventObj = document.createEvent('CustomEvent');
  22843. eventObj.initCustomEvent('change', true, true, { value: '' });
  22844. elements.input.dispatchEvent(eventObj);
  22845. // For some reason, firing the above event resets the value of $scope.searchText if
  22846. // $scope.searchText has a space character at the end, so we blank it one more time and then
  22847. // focus.
  22848. elements.input.blur();
  22849. $scope.searchText = '';
  22850. elements.input.focus();
  22851. }
  22852. /**
  22853. * Fetches the results for the provided search text.
  22854. * @param searchText
  22855. */
  22856. function fetchResults (searchText) {
  22857. var items = $scope.$parent.$eval(itemExpr),
  22858. term = searchText.toLowerCase(),
  22859. isList = angular.isArray(items),
  22860. isPromise = !!items.then; // Every promise should contain a `then` property
  22861. if (isList) onResultsRetrieved(items);
  22862. else if (isPromise) handleAsyncResults(items);
  22863. function handleAsyncResults(items) {
  22864. if ( !items ) return;
  22865. items = $q.when(items);
  22866. fetchesInProgress++;
  22867. setLoading(true);
  22868. $mdUtil.nextTick(function () {
  22869. items
  22870. .then(onResultsRetrieved)
  22871. .finally(function(){
  22872. if (--fetchesInProgress === 0) {
  22873. setLoading(false);
  22874. }
  22875. });
  22876. },true, $scope);
  22877. }
  22878. function onResultsRetrieved(matches) {
  22879. cache[term] = matches;
  22880. // Just cache the results if the request is now outdated.
  22881. // The request becomes outdated, when the new searchText has changed during the result fetching.
  22882. if ((searchText || '') !== ($scope.searchText || '')) {
  22883. return;
  22884. }
  22885. handleResults(matches);
  22886. }
  22887. }
  22888. /**
  22889. * Reports given message types to supported screenreaders.
  22890. * @param {boolean} isPolite Whether the announcement should be polite.
  22891. * @param {!number} types Message flags to be reported to the screenreader.
  22892. */
  22893. function reportMessages(isPolite, types) {
  22894. var politeness = isPolite ? 'polite' : 'assertive';
  22895. var messages = [];
  22896. if (types & ReportType.Selected && ctrl.index !== -1) {
  22897. messages.push(getCurrentDisplayValue());
  22898. }
  22899. if (types & ReportType.Count) {
  22900. messages.push($q.resolve(getCountMessage()));
  22901. }
  22902. $q.all(messages).then(function(data) {
  22903. $mdLiveAnnouncer.announce(data.join(' '), politeness);
  22904. });
  22905. }
  22906. /**
  22907. * Returns the ARIA message for how many results match the current query.
  22908. * @returns {*}
  22909. */
  22910. function getCountMessage () {
  22911. switch (ctrl.matches.length) {
  22912. case 0:
  22913. return 'There are no matches available.';
  22914. case 1:
  22915. return 'There is 1 match available.';
  22916. default:
  22917. return 'There are ' + ctrl.matches.length + ' matches available.';
  22918. }
  22919. }
  22920. /**
  22921. * Makes sure that the focused element is within view.
  22922. */
  22923. function updateScroll () {
  22924. if (!elements.li[0]) return;
  22925. var height = elements.li[0].offsetHeight,
  22926. top = height * ctrl.index,
  22927. bot = top + height,
  22928. hgt = elements.scroller.clientHeight,
  22929. scrollTop = elements.scroller.scrollTop;
  22930. if (top < scrollTop) {
  22931. scrollTo(top);
  22932. } else if (bot > scrollTop + hgt) {
  22933. scrollTo(bot - hgt);
  22934. }
  22935. }
  22936. function isPromiseFetching() {
  22937. return fetchesInProgress !== 0;
  22938. }
  22939. function scrollTo (offset) {
  22940. elements.$.scrollContainer.controller('mdVirtualRepeatContainer').scrollTo(offset);
  22941. }
  22942. function notFoundVisible () {
  22943. var textLength = (ctrl.scope.searchText || '').length;
  22944. return ctrl.hasNotFound && !hasMatches() && (!ctrl.loading || isPromiseFetching()) && textLength >= getMinLength() && (hasFocus || noBlur) && !hasSelection();
  22945. }
  22946. /**
  22947. * Starts the query to gather the results for the current searchText. Attempts to return cached
  22948. * results first, then forwards the process to `fetchResults` if necessary.
  22949. */
  22950. function handleQuery () {
  22951. var searchText = $scope.searchText || '';
  22952. var term = searchText.toLowerCase();
  22953. // If caching is enabled and the current searchText is stored in the cache
  22954. if (!$scope.noCache && cache[term]) {
  22955. // The results should be handled as same as a normal un-cached request does.
  22956. handleResults(cache[term]);
  22957. } else {
  22958. fetchResults(searchText);
  22959. }
  22960. ctrl.hidden = shouldHide();
  22961. }
  22962. /**
  22963. * Handles the retrieved results by showing them in the autocompletes dropdown.
  22964. * @param results Retrieved results
  22965. */
  22966. function handleResults(results) {
  22967. ctrl.matches = results;
  22968. ctrl.hidden = shouldHide();
  22969. // If loading is in progress, then we'll end the progress. This is needed for example,
  22970. // when the `clear` button was clicked, because there we always show the loading process, to prevent flashing.
  22971. if (ctrl.loading) setLoading(false);
  22972. if ($scope.selectOnMatch) selectItemOnMatch();
  22973. positionDropdown();
  22974. reportMessages(true, ReportType.Count);
  22975. }
  22976. /**
  22977. * If there is only one matching item and the search text matches its display value exactly,
  22978. * automatically select that item. Note: This function is only called if the user uses the
  22979. * `md-select-on-match` flag.
  22980. */
  22981. function selectItemOnMatch () {
  22982. var searchText = $scope.searchText,
  22983. matches = ctrl.matches,
  22984. item = matches[ 0 ];
  22985. if (matches.length === 1) getDisplayValue(item).then(function (displayValue) {
  22986. var isMatching = searchText == displayValue;
  22987. if ($scope.matchInsensitive && !isMatching) {
  22988. isMatching = searchText.toLowerCase() == displayValue.toLowerCase();
  22989. }
  22990. if (isMatching) select(0);
  22991. });
  22992. }
  22993. /**
  22994. * Evaluates an attribute expression against the parent scope.
  22995. * @param {String} attr Name of the attribute to be evaluated.
  22996. * @param {Object?} locals Properties to be injected into the evaluation context.
  22997. */
  22998. function evalAttr(attr, locals) {
  22999. if ($attrs[attr]) {
  23000. $scope.$parent.$eval($attrs[attr], locals || {});
  23001. }
  23002. }
  23003. }
  23004. })();
  23005. (function(){
  23006. "use strict";
  23007. MdAutocomplete.$inject = ["$$mdSvgRegistry"];angular
  23008. .module('material.components.autocomplete')
  23009. .directive('mdAutocomplete', MdAutocomplete);
  23010. /**
  23011. * @ngdoc directive
  23012. * @name mdAutocomplete
  23013. * @module material.components.autocomplete
  23014. *
  23015. * @description
  23016. * `<md-autocomplete>` is a special input component with a drop-down of all possible matches to a
  23017. * custom query. This component allows you to provide real-time suggestions as the user types
  23018. * in the input area.
  23019. *
  23020. * To start, you will need to specify the required parameters and provide a template for your
  23021. * results. The content inside `md-autocomplete` will be treated as a template.
  23022. *
  23023. * In more complex cases, you may want to include other content such as a message to display when
  23024. * no matches were found. You can do this by wrapping your template in `md-item-template` and
  23025. * adding a tag for `md-not-found`. An example of this is shown below.
  23026. *
  23027. * To reset the displayed value you must clear both values for `md-search-text` and `md-selected-item`.
  23028. *
  23029. * ### Validation
  23030. *
  23031. * You can use `ng-messages` to include validation the same way that you would normally validate;
  23032. * however, if you want to replicate a standard input with a floating label, you will have to
  23033. * do the following:
  23034. *
  23035. * - Make sure that your template is wrapped in `md-item-template`
  23036. * - Add your `ng-messages` code inside of `md-autocomplete`
  23037. * - Add your validation properties to `md-autocomplete` (ie. `required`)
  23038. * - Add a `name` to `md-autocomplete` (to be used on the generated `input`)
  23039. *
  23040. * There is an example below of how this should look.
  23041. *
  23042. * ### Snapping Drop-Down
  23043. *
  23044. * You can cause the autocomplete drop-down to snap to an ancestor element by applying the
  23045. * `md-autocomplete-snap` attribute to that element. You can also snap to the width of
  23046. * the `md-autocomplete-snap` element by setting the attribute's value to `width`
  23047. * (ie. `md-autocomplete-snap="width"`).
  23048. *
  23049. * ### Notes
  23050. *
  23051. * **Autocomplete Dropdown Items Rendering**
  23052. *
  23053. * The `md-autocomplete` uses the the <a ng-href="api/directive/mdVirtualRepeatContainer">VirtualRepeat</a>
  23054. * directive for displaying the results inside of the dropdown.<br/>
  23055. *
  23056. * > When encountering issues regarding the item template please take a look at the
  23057. * <a ng-href="api/directive/mdVirtualRepeatContainer">VirtualRepeatContainer</a> documentation.
  23058. *
  23059. * **Autocomplete inside of a Virtual Repeat**
  23060. *
  23061. * When using the `md-autocomplete` directive inside of a
  23062. * <a ng-href="api/directive/mdVirtualRepeatContainer">VirtualRepeatContainer</a> the dropdown items might
  23063. * not update properly, because caching of the results is enabled by default.
  23064. *
  23065. * The autocomplete will then show invalid dropdown items, because the VirtualRepeat only updates the
  23066. * scope bindings, rather than re-creating the `md-autocomplete` and the previous cached results will be used.
  23067. *
  23068. * > To avoid such problems ensure that the autocomplete does not cache any results.
  23069. *
  23070. * <hljs lang="html">
  23071. * <md-autocomplete
  23072. * md-no-cache="true"
  23073. * md-selected-item="selectedItem"
  23074. * md-items="item in items"
  23075. * md-search-text="searchText"
  23076. * md-item-text="item.display">
  23077. * <span>{{ item.display }}</span>
  23078. * </md-autocomplete>
  23079. * </hljs>
  23080. *
  23081. *
  23082. * @param {expression} md-items An expression in the format of `item in results` to iterate over
  23083. * matches for your search.<br/><br/>
  23084. * The `results` expression can be also a function, which returns the results synchronously
  23085. * or asynchronously (per Promise).
  23086. * @param {expression=} md-selected-item-change An expression to be run each time a new item is
  23087. * selected.
  23088. * @param {expression=} md-search-text-change An expression to be run each time the search text
  23089. * updates.
  23090. * @param {expression=} md-search-text A model to bind the search query text to.
  23091. * @param {object=} md-selected-item A model to bind the selected item to.
  23092. * @param {expression=} md-item-text An expression that will convert your object to a single string.
  23093. * @param {string=} placeholder Placeholder text that will be forwarded to the input.
  23094. * @param {boolean=} md-no-cache Disables the internal caching that happens in autocomplete.
  23095. * @param {boolean=} ng-disabled Determines whether or not to disable the input field.
  23096. * @param {boolean=} md-require-match When set to true, the autocomplete will add a validator,
  23097. * which will evaluate to false, when no item is currently selected.
  23098. * @param {number=} md-min-length Specifies the minimum length of text before autocomplete will
  23099. * make suggestions.
  23100. * @param {number=} md-delay Specifies the amount of time (in milliseconds) to wait before looking
  23101. * for results.
  23102. * @param {boolean=} md-clear-button Whether the clear button for the autocomplete input should show up or not.
  23103. * @param {boolean=} md-autofocus If true, the autocomplete will be automatically focused when a `$mdDialog`,
  23104. * `$mdBottomsheet` or `$mdSidenav`, which contains the autocomplete, is opening. <br/><br/>
  23105. * Also the autocomplete will immediately focus the input element.
  23106. * @param {boolean=} md-no-asterisk When present, asterisk will not be appended to the floating label.
  23107. * @param {boolean=} md-autoselect If set to true, the first item will be automatically selected
  23108. * in the dropdown upon open.
  23109. * @param {string=} md-input-name The name attribute given to the input element to be used with
  23110. * FormController.
  23111. * @param {string=} md-menu-class This class will be applied to the dropdown menu for styling.
  23112. * @param {string=} md-menu-container-class This class will be applied to the parent container
  23113. * of the dropdown panel.
  23114. * @param {string=} md-input-class This will be applied to the input for styling. This attribute is only valid when a `md-floating-label` is defined
  23115. * @param {string=} md-floating-label This will add a floating label to autocomplete and wrap it in
  23116. * `md-input-container`
  23117. * @param {string=} md-input-name The name attribute given to the input element to be used with
  23118. * FormController
  23119. * @param {string=} md-select-on-focus When present the inputs text will be automatically selected
  23120. * on focus.
  23121. * @param {string=} md-input-id An ID to be added to the input element.
  23122. * @param {number=} md-input-minlength The minimum length for the input's value for validation.
  23123. * @param {number=} md-input-maxlength The maximum length for the input's value for validation.
  23124. * @param {boolean=} md-select-on-match When set, autocomplete will automatically select
  23125. * the item if the search text is an exact match. <br/><br/>
  23126. * An exact match is when only one match is displayed.
  23127. * @param {boolean=} md-match-case-insensitive When set and using `md-select-on-match`, autocomplete
  23128. * will select on case-insensitive match.
  23129. * @param {string=} md-escape-options Override escape key logic. Default is `blur clear`.<br/>
  23130. * Options: `blur`, `clear`, `none`.
  23131. * @param {string=} md-dropdown-items Specifies the maximum amount of items to be shown in
  23132. * the dropdown.<br/><br/>
  23133. * When the dropdown doesn't fit into the viewport, the dropdown will shrink
  23134. * as much as possible.
  23135. * @param {string=} md-dropdown-position Overrides the default dropdown position. Options: `top`, `bottom`.
  23136. * @param {string=} ng-trim If set to false, the search text will be not trimmed automatically.
  23137. * Defaults to true.
  23138. * @param {string=} ng-pattern Adds the pattern validator to the ngModel of the search text.
  23139. * See the [ngPattern Directive](https://docs.angularjs.org/api/ng/directive/ngPattern)
  23140. * for more details.
  23141. *
  23142. * @usage
  23143. * ### Basic Example
  23144. * <hljs lang="html">
  23145. * <md-autocomplete
  23146. * md-selected-item="selectedItem"
  23147. * md-search-text="searchText"
  23148. * md-items="item in getMatches(searchText)"
  23149. * md-item-text="item.display">
  23150. * <span md-highlight-text="searchText">{{item.display}}</span>
  23151. * </md-autocomplete>
  23152. * </hljs>
  23153. *
  23154. * ### Example with "not found" message
  23155. * <hljs lang="html">
  23156. * <md-autocomplete
  23157. * md-selected-item="selectedItem"
  23158. * md-search-text="searchText"
  23159. * md-items="item in getMatches(searchText)"
  23160. * md-item-text="item.display">
  23161. * <md-item-template>
  23162. * <span md-highlight-text="searchText">{{item.display}}</span>
  23163. * </md-item-template>
  23164. * <md-not-found>
  23165. * No matches found.
  23166. * </md-not-found>
  23167. * </md-autocomplete>
  23168. * </hljs>
  23169. *
  23170. * In this example, our code utilizes `md-item-template` and `md-not-found` to specify the
  23171. * different parts that make up our component.
  23172. *
  23173. * ### Clear button for the input
  23174. * By default, for floating label autocomplete's the clear button is not showing up
  23175. * ([See specs](https://material.google.com/components/text-fields.html#text-fields-auto-complete-text-field))
  23176. *
  23177. * Nevertheless, developers are able to explicitly toggle the clear button for all types of autocomplete's.
  23178. *
  23179. * <hljs lang="html">
  23180. * <md-autocomplete ... md-clear-button="true"></md-autocomplete>
  23181. * <md-autocomplete ... md-clear-button="false"></md-autocomplete>
  23182. * </hljs>
  23183. *
  23184. * ### Example with validation
  23185. * <hljs lang="html">
  23186. * <form name="autocompleteForm">
  23187. * <md-autocomplete
  23188. * required
  23189. * md-input-name="autocomplete"
  23190. * md-selected-item="selectedItem"
  23191. * md-search-text="searchText"
  23192. * md-items="item in getMatches(searchText)"
  23193. * md-item-text="item.display">
  23194. * <md-item-template>
  23195. * <span md-highlight-text="searchText">{{item.display}}</span>
  23196. * </md-item-template>
  23197. * <div ng-messages="autocompleteForm.autocomplete.$error">
  23198. * <div ng-message="required">This field is required</div>
  23199. * </div>
  23200. * </md-autocomplete>
  23201. * </form>
  23202. * </hljs>
  23203. *
  23204. * In this example, our code utilizes `md-item-template` and `ng-messages` to specify
  23205. * input validation for the field.
  23206. *
  23207. * ### Asynchronous Results
  23208. * The autocomplete items expression also supports promises, which will resolve with the query results.
  23209. *
  23210. * <hljs lang="js">
  23211. * function AppController($scope, $http) {
  23212. * $scope.query = function(searchText) {
  23213. * return $http
  23214. * .get(BACKEND_URL + '/items/' + searchText)
  23215. * .then(function(data) {
  23216. * // Map the response object to the data object.
  23217. * return data;
  23218. * });
  23219. * };
  23220. * }
  23221. * </hljs>
  23222. *
  23223. * <hljs lang="html">
  23224. * <md-autocomplete
  23225. * md-selected-item="selectedItem"
  23226. * md-search-text="searchText"
  23227. * md-items="item in query(searchText)">
  23228. * <md-item-template>
  23229. * <span md-highlight-text="searchText">{{item}}</span>
  23230. * </md-item-template>
  23231. * </md-autocomplete>
  23232. * </hljs>
  23233. *
  23234. */
  23235. function MdAutocomplete ($$mdSvgRegistry) {
  23236. return {
  23237. controller: 'MdAutocompleteCtrl',
  23238. controllerAs: '$mdAutocompleteCtrl',
  23239. scope: {
  23240. inputName: '@mdInputName',
  23241. inputMinlength: '@mdInputMinlength',
  23242. inputMaxlength: '@mdInputMaxlength',
  23243. searchText: '=?mdSearchText',
  23244. selectedItem: '=?mdSelectedItem',
  23245. itemsExpr: '@mdItems',
  23246. itemText: '&mdItemText',
  23247. placeholder: '@placeholder',
  23248. noCache: '=?mdNoCache',
  23249. requireMatch: '=?mdRequireMatch',
  23250. selectOnMatch: '=?mdSelectOnMatch',
  23251. matchInsensitive: '=?mdMatchCaseInsensitive',
  23252. itemChange: '&?mdSelectedItemChange',
  23253. textChange: '&?mdSearchTextChange',
  23254. minLength: '=?mdMinLength',
  23255. delay: '=?mdDelay',
  23256. autofocus: '=?mdAutofocus',
  23257. floatingLabel: '@?mdFloatingLabel',
  23258. autoselect: '=?mdAutoselect',
  23259. menuClass: '@?mdMenuClass',
  23260. menuContainerClass: '@?mdMenuContainerClass',
  23261. inputClass: '@?mdInputClass',
  23262. inputId: '@?mdInputId',
  23263. escapeOptions: '@?mdEscapeOptions',
  23264. dropdownItems: '=?mdDropdownItems',
  23265. dropdownPosition: '@?mdDropdownPosition',
  23266. clearButton: '=?mdClearButton'
  23267. },
  23268. compile: function(tElement, tAttrs) {
  23269. var attributes = ['md-select-on-focus', 'md-no-asterisk', 'ng-trim', 'ng-pattern'];
  23270. var input = tElement.find('input');
  23271. attributes.forEach(function(attribute) {
  23272. var attrValue = tAttrs[tAttrs.$normalize(attribute)];
  23273. if (attrValue !== null) {
  23274. input.attr(attribute, attrValue);
  23275. }
  23276. });
  23277. return function(scope, element, attrs, ctrl) {
  23278. // Retrieve the state of using a md-not-found template by using our attribute, which will
  23279. // be added to the element in the template function.
  23280. ctrl.hasNotFound = !!element.attr('md-has-not-found');
  23281. // By default the inset autocomplete should show the clear button when not explicitly overwritten.
  23282. if (!angular.isDefined(attrs.mdClearButton) && !scope.floatingLabel) {
  23283. scope.clearButton = true;
  23284. }
  23285. };
  23286. },
  23287. template: function (element, attr) {
  23288. var noItemsTemplate = getNoItemsTemplate(),
  23289. itemTemplate = getItemTemplate(),
  23290. leftover = element.html(),
  23291. tabindex = attr.tabindex;
  23292. var menuContainerClass = attr.mdMenuContainerClass ? ' ' + attr.mdMenuContainerClass : '';
  23293. // Set our attribute for the link function above which runs later.
  23294. // We will set an attribute, because otherwise the stored variables will be trashed when
  23295. // removing the element is hidden while retrieving the template. For example when using ngIf.
  23296. if (noItemsTemplate) element.attr('md-has-not-found', true);
  23297. // Always set our tabindex of the autocomplete directive to -1, because our input
  23298. // will hold the actual tabindex.
  23299. element.attr('tabindex', '-1');
  23300. return '\
  23301. <md-autocomplete-wrap\
  23302. ng-class="{ \'md-whiteframe-z1\': !floatingLabel, \
  23303. \'md-menu-showing\': !$mdAutocompleteCtrl.hidden, \
  23304. \'md-show-clear-button\': !!clearButton }">\
  23305. ' + getInputElement() + '\
  23306. ' + getClearButton() + '\
  23307. <md-progress-linear\
  23308. class="' + (attr.mdFloatingLabel ? 'md-inline' : '') + '"\
  23309. ng-if="$mdAutocompleteCtrl.loadingIsVisible()"\
  23310. md-mode="indeterminate"></md-progress-linear>\
  23311. <md-virtual-repeat-container\
  23312. md-auto-shrink\
  23313. md-auto-shrink-min="1"\
  23314. ng-mouseenter="$mdAutocompleteCtrl.listEnter()"\
  23315. ng-mouseleave="$mdAutocompleteCtrl.listLeave()"\
  23316. ng-mouseup="$mdAutocompleteCtrl.mouseUp()"\
  23317. ng-hide="$mdAutocompleteCtrl.hidden"\
  23318. class="md-autocomplete-suggestions-container md-whiteframe-z1' + menuContainerClass + '"\
  23319. ng-class="{ \'md-not-found\': $mdAutocompleteCtrl.notFoundVisible() }"\
  23320. role="presentation">\
  23321. <ul class="md-autocomplete-suggestions"\
  23322. ng-class="::menuClass"\
  23323. id="ul-{{$mdAutocompleteCtrl.id}}">\
  23324. <li md-virtual-repeat="item in $mdAutocompleteCtrl.matches"\
  23325. ng-class="{ selected: $index === $mdAutocompleteCtrl.index }"\
  23326. ng-click="$mdAutocompleteCtrl.select($index)"\
  23327. md-extra-name="$mdAutocompleteCtrl.itemName">\
  23328. ' + itemTemplate + '\
  23329. </li>' + noItemsTemplate + '\
  23330. </ul>\
  23331. </md-virtual-repeat-container>\
  23332. </md-autocomplete-wrap>';
  23333. function getItemTemplate() {
  23334. var templateTag = element.find('md-item-template').detach(),
  23335. html = templateTag.length ? templateTag.html() : element.html();
  23336. if (!templateTag.length) element.empty();
  23337. return '<md-autocomplete-parent-scope md-autocomplete-replace>' + html + '</md-autocomplete-parent-scope>';
  23338. }
  23339. function getNoItemsTemplate() {
  23340. var templateTag = element.find('md-not-found').detach(),
  23341. template = templateTag.length ? templateTag.html() : '';
  23342. return template
  23343. ? '<li ng-if="$mdAutocompleteCtrl.notFoundVisible()"\
  23344. md-autocomplete-parent-scope>' + template + '</li>'
  23345. : '';
  23346. }
  23347. function getInputElement () {
  23348. if (attr.mdFloatingLabel) {
  23349. return '\
  23350. <md-input-container ng-if="floatingLabel">\
  23351. <label>{{floatingLabel}}</label>\
  23352. <input type="search"\
  23353. ' + (tabindex != null ? 'tabindex="' + tabindex + '"' : '') + '\
  23354. id="{{ inputId || \'fl-input-\' + $mdAutocompleteCtrl.id }}"\
  23355. name="{{inputName}}"\
  23356. ng-class="::inputClass"\
  23357. autocomplete="off"\
  23358. ng-required="$mdAutocompleteCtrl.isRequired"\
  23359. ng-readonly="$mdAutocompleteCtrl.isReadonly"\
  23360. ng-minlength="inputMinlength"\
  23361. ng-maxlength="inputMaxlength"\
  23362. ng-disabled="$mdAutocompleteCtrl.isDisabled"\
  23363. ng-model="$mdAutocompleteCtrl.scope.searchText"\
  23364. ng-model-options="{ allowInvalid: true }"\
  23365. ng-keydown="$mdAutocompleteCtrl.keydown($event)"\
  23366. ng-blur="$mdAutocompleteCtrl.blur($event)"\
  23367. ng-focus="$mdAutocompleteCtrl.focus($event)"\
  23368. aria-owns="ul-{{$mdAutocompleteCtrl.id}}"\
  23369. aria-label="{{floatingLabel}}"\
  23370. aria-autocomplete="list"\
  23371. role="combobox"\
  23372. aria-haspopup="true"\
  23373. aria-activedescendant=""\
  23374. aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\
  23375. <div md-autocomplete-parent-scope md-autocomplete-replace>' + leftover + '</div>\
  23376. </md-input-container>';
  23377. } else {
  23378. return '\
  23379. <input type="search"\
  23380. ' + (tabindex != null ? 'tabindex="' + tabindex + '"' : '') + '\
  23381. id="{{ inputId || \'input-\' + $mdAutocompleteCtrl.id }}"\
  23382. name="{{inputName}}"\
  23383. ng-class="::inputClass"\
  23384. ng-if="!floatingLabel"\
  23385. autocomplete="off"\
  23386. ng-required="$mdAutocompleteCtrl.isRequired"\
  23387. ng-disabled="$mdAutocompleteCtrl.isDisabled"\
  23388. ng-readonly="$mdAutocompleteCtrl.isReadonly"\
  23389. ng-minlength="inputMinlength"\
  23390. ng-maxlength="inputMaxlength"\
  23391. ng-model="$mdAutocompleteCtrl.scope.searchText"\
  23392. ng-keydown="$mdAutocompleteCtrl.keydown($event)"\
  23393. ng-blur="$mdAutocompleteCtrl.blur($event)"\
  23394. ng-focus="$mdAutocompleteCtrl.focus($event)"\
  23395. placeholder="{{placeholder}}"\
  23396. aria-owns="ul-{{$mdAutocompleteCtrl.id}}"\
  23397. aria-label="{{placeholder}}"\
  23398. aria-autocomplete="list"\
  23399. role="combobox"\
  23400. aria-haspopup="true"\
  23401. aria-activedescendant=""\
  23402. aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>';
  23403. }
  23404. }
  23405. function getClearButton() {
  23406. return '' +
  23407. '<button ' +
  23408. 'type="button" ' +
  23409. 'aria-label="Clear Input" ' +
  23410. 'tabindex="-1" ' +
  23411. 'ng-if="clearButton && $mdAutocompleteCtrl.scope.searchText" ' +
  23412. 'ng-click="$mdAutocompleteCtrl.clear($event)">' +
  23413. '<md-icon md-svg-src="' + $$mdSvgRegistry.mdClose + '"></md-icon>' +
  23414. '</button>';
  23415. }
  23416. }
  23417. };
  23418. }
  23419. })();
  23420. (function(){
  23421. "use strict";
  23422. MdAutocompleteItemScopeDirective.$inject = ["$compile", "$mdUtil"];angular
  23423. .module('material.components.autocomplete')
  23424. .directive('mdAutocompleteParentScope', MdAutocompleteItemScopeDirective);
  23425. function MdAutocompleteItemScopeDirective($compile, $mdUtil) {
  23426. return {
  23427. restrict: 'AE',
  23428. compile: compile,
  23429. terminal: true,
  23430. transclude: 'element'
  23431. };
  23432. function compile(tElement, tAttr, transclude) {
  23433. return function postLink(scope, element, attr) {
  23434. var ctrl = scope.$mdAutocompleteCtrl;
  23435. var newScope = ctrl.parent.$new();
  23436. var itemName = ctrl.itemName;
  23437. // Watch for changes to our scope's variables and copy them to the new scope
  23438. watchVariable('$index', '$index');
  23439. watchVariable('item', itemName);
  23440. // Ensure that $digest calls on our scope trigger $digest on newScope.
  23441. connectScopes();
  23442. // Link the element against newScope.
  23443. transclude(newScope, function(clone) {
  23444. element.after(clone);
  23445. });
  23446. /**
  23447. * Creates a watcher for variables that are copied from the parent scope
  23448. * @param variable
  23449. * @param alias
  23450. */
  23451. function watchVariable(variable, alias) {
  23452. newScope[alias] = scope[variable];
  23453. scope.$watch(variable, function(value) {
  23454. $mdUtil.nextTick(function() {
  23455. newScope[alias] = value;
  23456. });
  23457. });
  23458. }
  23459. /**
  23460. * Creates watchers on scope and newScope that ensure that for any
  23461. * $digest of scope, newScope is also $digested.
  23462. */
  23463. function connectScopes() {
  23464. var scopeDigesting = false;
  23465. var newScopeDigesting = false;
  23466. scope.$watch(function() {
  23467. if (newScopeDigesting || scopeDigesting) {
  23468. return;
  23469. }
  23470. scopeDigesting = true;
  23471. scope.$$postDigest(function() {
  23472. if (!newScopeDigesting) {
  23473. newScope.$digest();
  23474. }
  23475. scopeDigesting = newScopeDigesting = false;
  23476. });
  23477. });
  23478. newScope.$watch(function() {
  23479. newScopeDigesting = true;
  23480. });
  23481. }
  23482. };
  23483. }
  23484. }
  23485. })();
  23486. (function(){
  23487. "use strict";
  23488. MdHighlightCtrl.$inject = ["$scope", "$element", "$attrs"];angular
  23489. .module('material.components.autocomplete')
  23490. .controller('MdHighlightCtrl', MdHighlightCtrl);
  23491. function MdHighlightCtrl ($scope, $element, $attrs) {
  23492. this.$scope = $scope;
  23493. this.$element = $element;
  23494. this.$attrs = $attrs;
  23495. // Cache the Regex to avoid rebuilding each time.
  23496. this.regex = null;
  23497. }
  23498. MdHighlightCtrl.prototype.init = function(unsafeTermFn, unsafeContentFn) {
  23499. this.flags = this.$attrs.mdHighlightFlags || '';
  23500. this.unregisterFn = this.$scope.$watch(function($scope) {
  23501. return {
  23502. term: unsafeTermFn($scope),
  23503. contentText: unsafeContentFn($scope)
  23504. };
  23505. }.bind(this), this.onRender.bind(this), true);
  23506. this.$element.on('$destroy', this.unregisterFn);
  23507. };
  23508. /**
  23509. * Triggered once a new change has been recognized and the highlighted
  23510. * text needs to be updated.
  23511. */
  23512. MdHighlightCtrl.prototype.onRender = function(state, prevState) {
  23513. var contentText = state.contentText;
  23514. /* Update the regex if it's outdated, because we don't want to rebuilt it constantly. */
  23515. if (this.regex === null || state.term !== prevState.term) {
  23516. this.regex = this.createRegex(state.term, this.flags);
  23517. }
  23518. /* If a term is available apply the regex to the content */
  23519. if (state.term) {
  23520. this.applyRegex(contentText);
  23521. } else {
  23522. this.$element.text(contentText);
  23523. }
  23524. };
  23525. /**
  23526. * Decomposes the specified text into different tokens (whether match or not).
  23527. * Breaking down the string guarantees proper XSS protection due to the native browser
  23528. * escaping of unsafe text.
  23529. */
  23530. MdHighlightCtrl.prototype.applyRegex = function(text) {
  23531. var tokens = this.resolveTokens(text);
  23532. this.$element.empty();
  23533. tokens.forEach(function (token) {
  23534. if (token.isMatch) {
  23535. var tokenEl = angular.element('<span class="highlight">').text(token.text);
  23536. this.$element.append(tokenEl);
  23537. } else {
  23538. this.$element.append(document.createTextNode(token));
  23539. }
  23540. }.bind(this));
  23541. };
  23542. /**
  23543. * Decomposes the specified text into different tokens by running the regex against the text.
  23544. */
  23545. MdHighlightCtrl.prototype.resolveTokens = function(string) {
  23546. var tokens = [];
  23547. var lastIndex = 0;
  23548. // Use replace here, because it supports global and single regular expressions at same time.
  23549. string.replace(this.regex, function(match, index) {
  23550. appendToken(lastIndex, index);
  23551. tokens.push({
  23552. text: match,
  23553. isMatch: true
  23554. });
  23555. lastIndex = index + match.length;
  23556. });
  23557. // Append the missing text as a token.
  23558. appendToken(lastIndex);
  23559. return tokens;
  23560. function appendToken(from, to) {
  23561. var targetText = string.slice(from, to);
  23562. targetText && tokens.push(targetText);
  23563. }
  23564. };
  23565. /** Creates a regex for the specified text with the given flags. */
  23566. MdHighlightCtrl.prototype.createRegex = function(term, flags) {
  23567. var startFlag = '', endFlag = '';
  23568. var regexTerm = this.sanitizeRegex(term);
  23569. if (flags.indexOf('^') >= 0) startFlag = '^';
  23570. if (flags.indexOf('$') >= 0) endFlag = '$';
  23571. return new RegExp(startFlag + regexTerm + endFlag, flags.replace(/[$^]/g, ''));
  23572. };
  23573. /** Sanitizes a regex by removing all common RegExp identifiers */
  23574. MdHighlightCtrl.prototype.sanitizeRegex = function(term) {
  23575. return term && term.toString().replace(/[\\^$*+?.()|{}[\]]/g, '\\$&');
  23576. };
  23577. })();
  23578. (function(){
  23579. "use strict";
  23580. MdHighlight.$inject = ["$interpolate", "$parse"];angular
  23581. .module('material.components.autocomplete')
  23582. .directive('mdHighlightText', MdHighlight);
  23583. /**
  23584. * @ngdoc directive
  23585. * @name mdHighlightText
  23586. * @module material.components.autocomplete
  23587. *
  23588. * @description
  23589. * The `md-highlight-text` directive allows you to specify text that should be highlighted within
  23590. * an element. Highlighted text will be wrapped in `<span class="highlight"></span>` which can
  23591. * be styled through CSS. Please note that child elements may not be used with this directive.
  23592. *
  23593. * @param {string} md-highlight-text A model to be searched for
  23594. * @param {string=} md-highlight-flags A list of flags (loosely based on JavaScript RexExp flags).
  23595. * #### **Supported flags**:
  23596. * - `g`: Find all matches within the provided text
  23597. * - `i`: Ignore case when searching for matches
  23598. * - `$`: Only match if the text ends with the search term
  23599. * - `^`: Only match if the text begins with the search term
  23600. *
  23601. * @usage
  23602. * <hljs lang="html">
  23603. * <input placeholder="Enter a search term..." ng-model="searchTerm" type="text" />
  23604. * <ul>
  23605. * <li ng-repeat="result in results" md-highlight-text="searchTerm">
  23606. * {{result.text}}
  23607. * </li>
  23608. * </ul>
  23609. * </hljs>
  23610. */
  23611. function MdHighlight ($interpolate, $parse) {
  23612. return {
  23613. terminal: true,
  23614. controller: 'MdHighlightCtrl',
  23615. compile: function mdHighlightCompile(tElement, tAttr) {
  23616. var termExpr = $parse(tAttr.mdHighlightText);
  23617. var unsafeContentExpr = $interpolate(tElement.html());
  23618. return function mdHighlightLink(scope, element, attr, ctrl) {
  23619. ctrl.init(termExpr, unsafeContentExpr);
  23620. };
  23621. }
  23622. };
  23623. }
  23624. })();
  23625. (function(){
  23626. "use strict";
  23627. MdChipCtrl.$inject = ["$scope", "$element", "$mdConstant", "$timeout", "$mdUtil"];angular
  23628. .module('material.components.chips')
  23629. .controller('MdChipCtrl', MdChipCtrl);
  23630. /**
  23631. * Controller for the MdChip component. Responsible for handling keyboard
  23632. * events and editting the chip if needed.
  23633. *
  23634. * @param $scope
  23635. * @param $element
  23636. * @param $mdConstant
  23637. * @param $timeout
  23638. * @param $mdUtil
  23639. * @constructor
  23640. */
  23641. function MdChipCtrl ($scope, $element, $mdConstant, $timeout, $mdUtil) {
  23642. /**
  23643. * @type {$scope}
  23644. */
  23645. this.$scope = $scope;
  23646. /**
  23647. * @type {$element}
  23648. */
  23649. this.$element = $element;
  23650. /**
  23651. * @type {$mdConstant}
  23652. */
  23653. this.$mdConstant = $mdConstant;
  23654. /**
  23655. * @type {$timeout}
  23656. */
  23657. this.$timeout = $timeout;
  23658. /**
  23659. * @type {$mdUtil}
  23660. */
  23661. this.$mdUtil = $mdUtil;
  23662. /**
  23663. * @type {boolean}
  23664. */
  23665. this.isEditting = false;
  23666. /**
  23667. * @type {MdChipsCtrl}
  23668. */
  23669. this.parentController = undefined;
  23670. /**
  23671. * @type {boolean}
  23672. */
  23673. this.enableChipEdit = false;
  23674. }
  23675. /**
  23676. * @param {MdChipsCtrl} controller
  23677. */
  23678. MdChipCtrl.prototype.init = function(controller) {
  23679. this.parentController = controller;
  23680. this.enableChipEdit = this.parentController.enableChipEdit;
  23681. if (this.enableChipEdit) {
  23682. this.$element.on('keydown', this.chipKeyDown.bind(this));
  23683. this.$element.on('mousedown', this.chipMouseDown.bind(this));
  23684. this.getChipContent().addClass('_md-chip-content-edit-is-enabled');
  23685. }
  23686. };
  23687. /**
  23688. * @return {Object}
  23689. */
  23690. MdChipCtrl.prototype.getChipContent = function() {
  23691. var chipContents = this.$element[0].getElementsByClassName('md-chip-content');
  23692. return angular.element(chipContents[0]);
  23693. };
  23694. /**
  23695. * @return {Object}
  23696. */
  23697. MdChipCtrl.prototype.getContentElement = function() {
  23698. return angular.element(this.getChipContent().children()[0]);
  23699. };
  23700. /**
  23701. * @return {number}
  23702. */
  23703. MdChipCtrl.prototype.getChipIndex = function() {
  23704. return parseInt(this.$element.attr('index'));
  23705. };
  23706. /**
  23707. * Presents an input element to edit the contents of the chip.
  23708. */
  23709. MdChipCtrl.prototype.goOutOfEditMode = function() {
  23710. if (!this.isEditting) return;
  23711. this.isEditting = false;
  23712. this.$element.removeClass('_md-chip-editing');
  23713. this.getChipContent()[0].contentEditable = 'false';
  23714. var chipIndex = this.getChipIndex();
  23715. var content = this.getContentElement().text();
  23716. if (content) {
  23717. this.parentController.updateChipContents(
  23718. chipIndex,
  23719. this.getContentElement().text()
  23720. );
  23721. this.$mdUtil.nextTick(function() {
  23722. if (this.parentController.selectedChip === chipIndex) {
  23723. this.parentController.focusChip(chipIndex);
  23724. }
  23725. }.bind(this));
  23726. } else {
  23727. this.parentController.removeChipAndFocusInput(chipIndex);
  23728. }
  23729. };
  23730. /**
  23731. * Given an HTML element. Selects contents of it.
  23732. * @param node
  23733. */
  23734. MdChipCtrl.prototype.selectNodeContents = function(node) {
  23735. var range, selection;
  23736. if (document.body.createTextRange) {
  23737. range = document.body.createTextRange();
  23738. range.moveToElementText(node);
  23739. range.select();
  23740. } else if (window.getSelection) {
  23741. selection = window.getSelection();
  23742. range = document.createRange();
  23743. range.selectNodeContents(node);
  23744. selection.removeAllRanges();
  23745. selection.addRange(range);
  23746. }
  23747. };
  23748. /**
  23749. * Presents an input element to edit the contents of the chip.
  23750. */
  23751. MdChipCtrl.prototype.goInEditMode = function() {
  23752. this.isEditting = true;
  23753. this.$element.addClass('_md-chip-editing');
  23754. this.getChipContent()[0].contentEditable = 'true';
  23755. this.getChipContent().on('blur', function() {
  23756. this.goOutOfEditMode();
  23757. }.bind(this));
  23758. this.selectNodeContents(this.getChipContent()[0]);
  23759. };
  23760. /**
  23761. * Handles the keydown event on the chip element. If enable-chip-edit attribute is
  23762. * set to true, space or enter keys can trigger going into edit mode. Enter can also
  23763. * trigger submitting if the chip is already being edited.
  23764. * @param event
  23765. */
  23766. MdChipCtrl.prototype.chipKeyDown = function(event) {
  23767. if (!this.isEditting &&
  23768. (event.keyCode === this.$mdConstant.KEY_CODE.ENTER ||
  23769. event.keyCode === this.$mdConstant.KEY_CODE.SPACE)) {
  23770. event.preventDefault();
  23771. this.goInEditMode();
  23772. } else if (this.isEditting &&
  23773. event.keyCode === this.$mdConstant.KEY_CODE.ENTER) {
  23774. event.preventDefault();
  23775. this.goOutOfEditMode();
  23776. }
  23777. };
  23778. /**
  23779. * Handles the double click event
  23780. */
  23781. MdChipCtrl.prototype.chipMouseDown = function() {
  23782. if(this.getChipIndex() == this.parentController.selectedChip &&
  23783. this.enableChipEdit &&
  23784. !this.isEditting) {
  23785. this.goInEditMode();
  23786. }
  23787. };
  23788. })();
  23789. (function(){
  23790. "use strict";
  23791. MdChip.$inject = ["$mdTheming", "$mdUtil", "$compile", "$timeout"];angular
  23792. .module('material.components.chips')
  23793. .directive('mdChip', MdChip);
  23794. /**
  23795. * @ngdoc directive
  23796. * @name mdChip
  23797. * @module material.components.chips
  23798. *
  23799. * @description
  23800. * `<md-chip>` is a component used within `<md-chips>` and is responsible for rendering individual
  23801. * chips.
  23802. *
  23803. *
  23804. * @usage
  23805. * <hljs lang="html">
  23806. * <md-chip>{{$chip}}</md-chip>
  23807. * </hljs>
  23808. *
  23809. */
  23810. // This hint text is hidden within a chip but used by screen readers to
  23811. // inform the user how they can interact with a chip.
  23812. var DELETE_HINT_TEMPLATE = '\
  23813. <span ng-if="!$mdChipsCtrl.readonly" class="md-visually-hidden">\
  23814. {{$mdChipsCtrl.deleteHint}}\
  23815. </span>';
  23816. /**
  23817. * MDChip Directive Definition
  23818. *
  23819. * @param $mdTheming
  23820. * @param $mdUtil
  23821. * @ngInject
  23822. */
  23823. function MdChip($mdTheming, $mdUtil, $compile, $timeout) {
  23824. var deleteHintTemplate = $mdUtil.processTemplate(DELETE_HINT_TEMPLATE);
  23825. return {
  23826. restrict: 'E',
  23827. require: ['^?mdChips', 'mdChip'],
  23828. link: postLink,
  23829. controller: 'MdChipCtrl'
  23830. };
  23831. function postLink(scope, element, attr, ctrls) {
  23832. var chipsController = ctrls.shift();
  23833. var chipController = ctrls.shift();
  23834. var chipContentElement = angular.element(element[0].querySelector('.md-chip-content'));
  23835. $mdTheming(element);
  23836. if (chipsController) {
  23837. chipController.init(chipsController);
  23838. // Append our delete hint to the div.md-chip-content (which does not exist at compile time)
  23839. chipContentElement.append($compile(deleteHintTemplate)(scope));
  23840. // When a chip is blurred, make sure to unset (or reset) the selected chip so that tabbing
  23841. // through elements works properly
  23842. chipContentElement.on('blur', function() {
  23843. chipsController.resetSelectedChip();
  23844. chipsController.$scope.$applyAsync();
  23845. });
  23846. }
  23847. // Use $timeout to ensure we run AFTER the element has been added to the DOM so we can focus it.
  23848. $timeout(function() {
  23849. if (!chipsController) {
  23850. return;
  23851. }
  23852. if (chipsController.shouldFocusLastChip) {
  23853. chipsController.focusLastChipThenInput();
  23854. }
  23855. });
  23856. }
  23857. }
  23858. })();
  23859. (function(){
  23860. "use strict";
  23861. MdChipRemove.$inject = ["$timeout"];angular
  23862. .module('material.components.chips')
  23863. .directive('mdChipRemove', MdChipRemove);
  23864. /**
  23865. * @ngdoc directive
  23866. * @name mdChipRemove
  23867. * @restrict A
  23868. * @module material.components.chips
  23869. *
  23870. * @description
  23871. * Designates an element to be used as the delete button for a chip. <br/>
  23872. * This element is passed as a child of the `md-chips` element.
  23873. *
  23874. * The designated button will be just appended to the chip and removes the given chip on click.<br/>
  23875. * By default the button is not being styled by the `md-chips` component.
  23876. *
  23877. * @usage
  23878. * <hljs lang="html">
  23879. * <md-chips>
  23880. * <button md-chip-remove="">
  23881. * <md-icon md-svg-icon="md-close"></md-icon>
  23882. * </button>
  23883. * </md-chips>
  23884. * </hljs>
  23885. */
  23886. /**
  23887. * MdChipRemove Directive Definition.
  23888. *
  23889. * @param $timeout
  23890. * @returns {{restrict: string, require: string[], link: Function, scope: boolean}}
  23891. * @constructor
  23892. */
  23893. function MdChipRemove ($timeout) {
  23894. return {
  23895. restrict: 'A',
  23896. require: '^mdChips',
  23897. scope: false,
  23898. link: postLink
  23899. };
  23900. function postLink(scope, element, attr, ctrl) {
  23901. element.on('click', function(event) {
  23902. scope.$apply(function() {
  23903. ctrl.removeChip(scope.$$replacedScope.$index);
  23904. });
  23905. });
  23906. // Child elements aren't available until after a $timeout tick as they are hidden by an
  23907. // `ng-if`. see http://goo.gl/zIWfuw
  23908. $timeout(function() {
  23909. element.attr({ tabindex: -1, 'aria-hidden': true });
  23910. element.find('button').attr('tabindex', '-1');
  23911. });
  23912. }
  23913. }
  23914. })();
  23915. (function(){
  23916. "use strict";
  23917. MdChipTransclude.$inject = ["$compile"];angular
  23918. .module('material.components.chips')
  23919. .directive('mdChipTransclude', MdChipTransclude);
  23920. function MdChipTransclude ($compile) {
  23921. return {
  23922. restrict: 'EA',
  23923. terminal: true,
  23924. link: link,
  23925. scope: false
  23926. };
  23927. function link (scope, element, attr) {
  23928. var ctrl = scope.$parent.$mdChipsCtrl,
  23929. newScope = ctrl.parent.$new(false, ctrl.parent);
  23930. newScope.$$replacedScope = scope;
  23931. newScope.$chip = scope.$chip;
  23932. newScope.$index = scope.$index;
  23933. newScope.$mdChipsCtrl = ctrl;
  23934. var newHtml = ctrl.$scope.$eval(attr.mdChipTransclude);
  23935. element.html(newHtml);
  23936. $compile(element.contents())(newScope);
  23937. }
  23938. }
  23939. })();
  23940. (function(){
  23941. "use strict";
  23942. /**
  23943. * The default chip append delay.
  23944. *
  23945. * @type {number}
  23946. */
  23947. MdChipsCtrl.$inject = ["$scope", "$attrs", "$mdConstant", "$log", "$element", "$timeout", "$mdUtil"];
  23948. var DEFAULT_CHIP_APPEND_DELAY = 300;
  23949. angular
  23950. .module('material.components.chips')
  23951. .controller('MdChipsCtrl', MdChipsCtrl);
  23952. /**
  23953. * Controller for the MdChips component. Responsible for adding to and
  23954. * removing from the list of chips, marking chips as selected, and binding to
  23955. * the models of various input components.
  23956. *
  23957. * @param $scope
  23958. * @param $attrs
  23959. * @param $mdConstant
  23960. * @param $log
  23961. * @param $element
  23962. * @param $timeout
  23963. * @param $mdUtil
  23964. * @constructor
  23965. */
  23966. function MdChipsCtrl ($scope, $attrs, $mdConstant, $log, $element, $timeout, $mdUtil) {
  23967. /** @type {$timeout} **/
  23968. this.$timeout = $timeout;
  23969. /** @type {Object} */
  23970. this.$mdConstant = $mdConstant;
  23971. /** @type {angular.$scope} */
  23972. this.$scope = $scope;
  23973. /** @type {angular.$scope} */
  23974. this.parent = $scope.$parent;
  23975. /** @type {$mdUtil} */
  23976. this.$mdUtil = $mdUtil;
  23977. /** @type {$log} */
  23978. this.$log = $log;
  23979. /** @type {$element} */
  23980. this.$element = $element;
  23981. /** @type {$attrs} */
  23982. this.$attrs = $attrs;
  23983. /** @type {angular.NgModelController} */
  23984. this.ngModelCtrl = null;
  23985. /** @type {angular.NgModelController} */
  23986. this.userInputNgModelCtrl = null;
  23987. /** @type {MdAutocompleteCtrl} */
  23988. this.autocompleteCtrl = null;
  23989. /** @type {Element} */
  23990. this.userInputElement = null;
  23991. /** @type {Array.<Object>} */
  23992. this.items = [];
  23993. /** @type {number} */
  23994. this.selectedChip = -1;
  23995. /** @type {string} */
  23996. this.enableChipEdit = $mdUtil.parseAttributeBoolean($attrs.mdEnableChipEdit);
  23997. /** @type {string} */
  23998. this.addOnBlur = $mdUtil.parseAttributeBoolean($attrs.mdAddOnBlur);
  23999. /**
  24000. * The text to be used as the aria-label for the input.
  24001. * @type {string}
  24002. */
  24003. this.inputAriaLabel = 'Chips input.';
  24004. /**
  24005. * Hidden hint text to describe the chips container. Used to give context to screen readers when
  24006. * the chips are readonly and the input cannot be selected.
  24007. *
  24008. * @type {string}
  24009. */
  24010. this.containerHint = 'Chips container. Use arrow keys to select chips.';
  24011. /**
  24012. * Hidden hint text for how to delete a chip. Used to give context to screen readers.
  24013. * @type {string}
  24014. */
  24015. this.deleteHint = 'Press delete to remove this chip.';
  24016. /**
  24017. * Hidden label for the delete button. Used to give context to screen readers.
  24018. * @type {string}
  24019. */
  24020. this.deleteButtonLabel = 'Remove';
  24021. /**
  24022. * Model used by the input element.
  24023. * @type {string}
  24024. */
  24025. this.chipBuffer = '';
  24026. /**
  24027. * Whether to use the transformChip expression to transform the chip buffer
  24028. * before appending it to the list.
  24029. * @type {boolean}
  24030. */
  24031. this.useTransformChip = false;
  24032. /**
  24033. * Whether to use the onAdd expression to notify of chip additions.
  24034. * @type {boolean}
  24035. */
  24036. this.useOnAdd = false;
  24037. /**
  24038. * Whether to use the onRemove expression to notify of chip removals.
  24039. * @type {boolean}
  24040. */
  24041. this.useOnRemove = false;
  24042. /**
  24043. * The ID of the chips wrapper which is used to build unique IDs for the chips and the aria-owns
  24044. * attribute.
  24045. *
  24046. * Defaults to '_md-chips-wrapper-' plus a unique number.
  24047. *
  24048. * @type {string}
  24049. */
  24050. this.wrapperId = '';
  24051. /**
  24052. * Array of unique numbers which will be auto-generated any time the items change, and is used to
  24053. * create unique IDs for the aria-owns attribute.
  24054. *
  24055. * @type {Array}
  24056. */
  24057. this.contentIds = [];
  24058. /**
  24059. * The index of the chip that should have it's tabindex property set to 0 so it is selectable
  24060. * via the keyboard.
  24061. *
  24062. * @type {int}
  24063. */
  24064. this.ariaTabIndex = null;
  24065. /**
  24066. * After appending a chip, the chip will be focused for this number of milliseconds before the
  24067. * input is refocused.
  24068. *
  24069. * **Note:** This is **required** for compatibility with certain screen readers in order for
  24070. * them to properly allow keyboard access.
  24071. *
  24072. * @type {number}
  24073. */
  24074. this.chipAppendDelay = DEFAULT_CHIP_APPEND_DELAY;
  24075. this.init();
  24076. }
  24077. /**
  24078. * Initializes variables and sets up watchers
  24079. */
  24080. MdChipsCtrl.prototype.init = function() {
  24081. var ctrl = this;
  24082. // Set the wrapper ID
  24083. ctrl.wrapperId = '_md-chips-wrapper-' + ctrl.$mdUtil.nextUid();
  24084. // Setup a watcher which manages the role and aria-owns attributes
  24085. ctrl.$scope.$watchCollection('$mdChipsCtrl.items', function() {
  24086. // Make sure our input and wrapper have the correct ARIA attributes
  24087. ctrl.setupInputAria();
  24088. ctrl.setupWrapperAria();
  24089. });
  24090. ctrl.$attrs.$observe('mdChipAppendDelay', function(newValue) {
  24091. ctrl.chipAppendDelay = parseInt(newValue) || DEFAULT_CHIP_APPEND_DELAY;
  24092. });
  24093. };
  24094. /**
  24095. * If we have an input, ensure it has the appropriate ARIA attributes.
  24096. */
  24097. MdChipsCtrl.prototype.setupInputAria = function() {
  24098. var input = this.$element.find('input');
  24099. // If we have no input, just return
  24100. if (!input) {
  24101. return;
  24102. }
  24103. input.attr('role', 'textbox');
  24104. input.attr('aria-multiline', true);
  24105. };
  24106. /**
  24107. * Ensure our wrapper has the appropriate ARIA attributes.
  24108. */
  24109. MdChipsCtrl.prototype.setupWrapperAria = function() {
  24110. var ctrl = this,
  24111. wrapper = this.$element.find('md-chips-wrap');
  24112. if (this.items && this.items.length) {
  24113. // Dynamically add the listbox role on every change because it must be removed when there are
  24114. // no items.
  24115. wrapper.attr('role', 'listbox');
  24116. // Generate some random (but unique) IDs for each chip
  24117. this.contentIds = this.items.map(function() {
  24118. return ctrl.wrapperId + '-chip-' + ctrl.$mdUtil.nextUid();
  24119. });
  24120. // Use the contentIDs above to generate the aria-owns attribute
  24121. wrapper.attr('aria-owns', this.contentIds.join(' '));
  24122. } else {
  24123. // If we have no items, then the role and aria-owns attributes MUST be removed
  24124. wrapper.removeAttr('role');
  24125. wrapper.removeAttr('aria-owns');
  24126. }
  24127. };
  24128. /**
  24129. * Handles the keydown event on the input element: by default <enter> appends
  24130. * the buffer to the chip list, while backspace removes the last chip in the
  24131. * list if the current buffer is empty.
  24132. * @param event
  24133. */
  24134. MdChipsCtrl.prototype.inputKeydown = function(event) {
  24135. var chipBuffer = this.getChipBuffer();
  24136. // If we have an autocomplete, and it handled the event, we have nothing to do
  24137. if (this.autocompleteCtrl && event.isDefaultPrevented && event.isDefaultPrevented()) {
  24138. return;
  24139. }
  24140. if (event.keyCode === this.$mdConstant.KEY_CODE.BACKSPACE) {
  24141. // Only select and focus the previous chip, if the current caret position of the
  24142. // input element is at the beginning.
  24143. if (this.getCursorPosition(event.target) !== 0) {
  24144. return;
  24145. }
  24146. event.preventDefault();
  24147. event.stopPropagation();
  24148. if (this.items.length) {
  24149. this.selectAndFocusChipSafe(this.items.length - 1);
  24150. }
  24151. return;
  24152. }
  24153. // By default <enter> appends the buffer to the chip list.
  24154. if (!this.separatorKeys || this.separatorKeys.length < 1) {
  24155. this.separatorKeys = [this.$mdConstant.KEY_CODE.ENTER];
  24156. }
  24157. // Support additional separator key codes in an array of `md-separator-keys`.
  24158. if (this.separatorKeys.indexOf(event.keyCode) !== -1) {
  24159. if ((this.autocompleteCtrl && this.requireMatch) || !chipBuffer) return;
  24160. event.preventDefault();
  24161. // Only append the chip and reset the chip buffer if the max chips limit isn't reached.
  24162. if (this.hasMaxChipsReached()) return;
  24163. this.appendChip(chipBuffer.trim());
  24164. this.resetChipBuffer();
  24165. return false;
  24166. }
  24167. };
  24168. /**
  24169. * Returns the cursor position of the specified input element.
  24170. * @param element HTMLInputElement
  24171. * @returns {Number} Cursor Position of the input.
  24172. */
  24173. MdChipsCtrl.prototype.getCursorPosition = function(element) {
  24174. /*
  24175. * Figure out whether the current input for the chips buffer is valid for using
  24176. * the selectionStart / end property to retrieve the cursor position.
  24177. * Some browsers do not allow the use of those attributes, on different input types.
  24178. */
  24179. try {
  24180. if (element.selectionStart === element.selectionEnd) {
  24181. return element.selectionStart;
  24182. }
  24183. } catch (e) {
  24184. if (!element.value) {
  24185. return 0;
  24186. }
  24187. }
  24188. };
  24189. /**
  24190. * Updates the content of the chip at given index
  24191. * @param chipIndex
  24192. * @param chipContents
  24193. */
  24194. MdChipsCtrl.prototype.updateChipContents = function(chipIndex, chipContents){
  24195. if(chipIndex >= 0 && chipIndex < this.items.length) {
  24196. this.items[chipIndex] = chipContents;
  24197. this.ngModelCtrl.$setDirty();
  24198. }
  24199. };
  24200. /**
  24201. * Returns true if a chip is currently being edited. False otherwise.
  24202. * @return {boolean}
  24203. */
  24204. MdChipsCtrl.prototype.isEditingChip = function() {
  24205. return !!this.$element[0].querySelector('._md-chip-editing');
  24206. };
  24207. MdChipsCtrl.prototype.isRemovable = function() {
  24208. // Return false if we have static chips
  24209. if (!this.ngModelCtrl) {
  24210. return false;
  24211. }
  24212. return this.readonly ? this.removable :
  24213. angular.isDefined(this.removable) ? this.removable : true;
  24214. };
  24215. /**
  24216. * Handles the keydown event on the chip elements: backspace removes the selected chip, arrow
  24217. * keys switch which chips is active
  24218. * @param event
  24219. */
  24220. MdChipsCtrl.prototype.chipKeydown = function (event) {
  24221. if (this.getChipBuffer()) return;
  24222. if (this.isEditingChip()) return;
  24223. switch (event.keyCode) {
  24224. case this.$mdConstant.KEY_CODE.BACKSPACE:
  24225. case this.$mdConstant.KEY_CODE.DELETE:
  24226. if (this.selectedChip < 0) return;
  24227. event.preventDefault();
  24228. // Cancel the delete action only after the event cancel. Otherwise the page will go back.
  24229. if (!this.isRemovable()) return;
  24230. this.removeAndSelectAdjacentChip(this.selectedChip, event);
  24231. break;
  24232. case this.$mdConstant.KEY_CODE.LEFT_ARROW:
  24233. event.preventDefault();
  24234. // By default, allow selection of -1 which will focus the input; if we're readonly, don't go
  24235. // below 0
  24236. if (this.selectedChip < 0 || (this.readonly && this.selectedChip == 0)) {
  24237. this.selectedChip = this.items.length;
  24238. }
  24239. if (this.items.length) this.selectAndFocusChipSafe(this.selectedChip - 1);
  24240. break;
  24241. case this.$mdConstant.KEY_CODE.RIGHT_ARROW:
  24242. event.preventDefault();
  24243. this.selectAndFocusChipSafe(this.selectedChip + 1);
  24244. break;
  24245. case this.$mdConstant.KEY_CODE.ESCAPE:
  24246. case this.$mdConstant.KEY_CODE.TAB:
  24247. if (this.selectedChip < 0) return;
  24248. event.preventDefault();
  24249. this.onFocus();
  24250. break;
  24251. }
  24252. };
  24253. /**
  24254. * Get the input's placeholder - uses `placeholder` when list is empty and `secondary-placeholder`
  24255. * when the list is non-empty. If `secondary-placeholder` is not provided, `placeholder` is used
  24256. * always.
  24257. */
  24258. MdChipsCtrl.prototype.getPlaceholder = function() {
  24259. // Allow `secondary-placeholder` to be blank.
  24260. var useSecondary = (this.items && this.items.length &&
  24261. (this.secondaryPlaceholder == '' || this.secondaryPlaceholder));
  24262. return useSecondary ? this.secondaryPlaceholder : this.placeholder;
  24263. };
  24264. /**
  24265. * Removes chip at {@code index} and selects the adjacent chip.
  24266. * @param {number} index
  24267. * @param {Event=} event
  24268. */
  24269. MdChipsCtrl.prototype.removeAndSelectAdjacentChip = function(index, event) {
  24270. var self = this;
  24271. var selIndex = self.getAdjacentChipIndex(index);
  24272. var wrap = this.$element[0].querySelector('md-chips-wrap');
  24273. var chip = this.$element[0].querySelector('md-chip[index="' + index + '"]');
  24274. self.removeChip(index, event);
  24275. // The double-timeout is currently necessary to ensure that the DOM has finalized and the select()
  24276. // will find the proper chip since the selection is index-based.
  24277. //
  24278. // TODO: Investigate calling from within chip $scope.$on('$destroy') to reduce/remove timeouts
  24279. self.$timeout(function() {
  24280. self.$timeout(function() {
  24281. self.selectAndFocusChipSafe(selIndex);
  24282. });
  24283. });
  24284. };
  24285. /**
  24286. * Sets the selected chip index to -1.
  24287. */
  24288. MdChipsCtrl.prototype.resetSelectedChip = function() {
  24289. this.selectedChip = -1;
  24290. this.ariaTabIndex = null;
  24291. };
  24292. /**
  24293. * Gets the index of an adjacent chip to select after deletion. Adjacency is
  24294. * determined as the next chip in the list, unless the target chip is the
  24295. * last in the list, then it is the chip immediately preceding the target. If
  24296. * there is only one item in the list, -1 is returned (select none).
  24297. * The number returned is the index to select AFTER the target has been
  24298. * removed.
  24299. * If the current chip is not selected, then -1 is returned to select none.
  24300. */
  24301. MdChipsCtrl.prototype.getAdjacentChipIndex = function(index) {
  24302. var len = this.items.length - 1;
  24303. return (len == 0) ? -1 :
  24304. (index == len) ? index -1 : index;
  24305. };
  24306. /**
  24307. * Append the contents of the buffer to the chip list. This method will first
  24308. * call out to the md-transform-chip method, if provided.
  24309. *
  24310. * @param newChip
  24311. */
  24312. MdChipsCtrl.prototype.appendChip = function(newChip) {
  24313. this.shouldFocusLastChip = true;
  24314. if (this.useTransformChip && this.transformChip) {
  24315. var transformedChip = this.transformChip({'$chip': newChip});
  24316. // Check to make sure the chip is defined before assigning it, otherwise, we'll just assume
  24317. // they want the string version.
  24318. if (angular.isDefined(transformedChip)) {
  24319. newChip = transformedChip;
  24320. }
  24321. }
  24322. // If items contains an identical object to newChip, do not append
  24323. if (angular.isObject(newChip)){
  24324. var identical = this.items.some(function(item){
  24325. return angular.equals(newChip, item);
  24326. });
  24327. if (identical) return;
  24328. }
  24329. // Check for a null (but not undefined), or existing chip and cancel appending
  24330. if (newChip == null || this.items.indexOf(newChip) + 1) return;
  24331. // Append the new chip onto our list
  24332. var length = this.items.push(newChip);
  24333. var index = length - 1;
  24334. // Update model validation
  24335. this.ngModelCtrl.$setDirty();
  24336. this.validateModel();
  24337. // If they provide the md-on-add attribute, notify them of the chip addition
  24338. if (this.useOnAdd && this.onAdd) {
  24339. this.onAdd({ '$chip': newChip, '$index': index });
  24340. }
  24341. };
  24342. /**
  24343. * Sets whether to use the md-transform-chip expression. This expression is
  24344. * bound to scope and controller in {@code MdChipsDirective} as
  24345. * {@code transformChip}. Due to the nature of directive scope bindings, the
  24346. * controller cannot know on its own/from the scope whether an expression was
  24347. * actually provided.
  24348. */
  24349. MdChipsCtrl.prototype.useTransformChipExpression = function() {
  24350. this.useTransformChip = true;
  24351. };
  24352. /**
  24353. * Sets whether to use the md-on-add expression. This expression is
  24354. * bound to scope and controller in {@code MdChipsDirective} as
  24355. * {@code onAdd}. Due to the nature of directive scope bindings, the
  24356. * controller cannot know on its own/from the scope whether an expression was
  24357. * actually provided.
  24358. */
  24359. MdChipsCtrl.prototype.useOnAddExpression = function() {
  24360. this.useOnAdd = true;
  24361. };
  24362. /**
  24363. * Sets whether to use the md-on-remove expression. This expression is
  24364. * bound to scope and controller in {@code MdChipsDirective} as
  24365. * {@code onRemove}. Due to the nature of directive scope bindings, the
  24366. * controller cannot know on its own/from the scope whether an expression was
  24367. * actually provided.
  24368. */
  24369. MdChipsCtrl.prototype.useOnRemoveExpression = function() {
  24370. this.useOnRemove = true;
  24371. };
  24372. /*
  24373. * Sets whether to use the md-on-select expression. This expression is
  24374. * bound to scope and controller in {@code MdChipsDirective} as
  24375. * {@code onSelect}. Due to the nature of directive scope bindings, the
  24376. * controller cannot know on its own/from the scope whether an expression was
  24377. * actually provided.
  24378. */
  24379. MdChipsCtrl.prototype.useOnSelectExpression = function() {
  24380. this.useOnSelect = true;
  24381. };
  24382. /**
  24383. * Gets the input buffer. The input buffer can be the model bound to the
  24384. * default input item {@code this.chipBuffer}, the {@code selectedItem}
  24385. * model of an {@code md-autocomplete}, or, through some magic, the model
  24386. * bound to any inpput or text area element found within a
  24387. * {@code md-input-container} element.
  24388. * @return {string}
  24389. */
  24390. MdChipsCtrl.prototype.getChipBuffer = function() {
  24391. var chipBuffer = !this.userInputElement ? this.chipBuffer :
  24392. this.userInputNgModelCtrl ? this.userInputNgModelCtrl.$viewValue :
  24393. this.userInputElement[0].value;
  24394. // Ensure that the chip buffer is always a string. For example, the input element buffer might be falsy.
  24395. return angular.isString(chipBuffer) ? chipBuffer : '';
  24396. };
  24397. /**
  24398. * Resets the input buffer for either the internal input or user provided input element.
  24399. */
  24400. MdChipsCtrl.prototype.resetChipBuffer = function() {
  24401. if (this.userInputElement) {
  24402. if (this.userInputNgModelCtrl) {
  24403. this.userInputNgModelCtrl.$setViewValue('');
  24404. this.userInputNgModelCtrl.$render();
  24405. } else {
  24406. this.userInputElement[0].value = '';
  24407. }
  24408. } else {
  24409. this.chipBuffer = '';
  24410. }
  24411. };
  24412. MdChipsCtrl.prototype.hasMaxChipsReached = function() {
  24413. if (angular.isString(this.maxChips)) this.maxChips = parseInt(this.maxChips, 10) || 0;
  24414. return this.maxChips > 0 && this.items.length >= this.maxChips;
  24415. };
  24416. /**
  24417. * Updates the validity properties for the ngModel.
  24418. */
  24419. MdChipsCtrl.prototype.validateModel = function() {
  24420. this.ngModelCtrl.$setValidity('md-max-chips', !this.hasMaxChipsReached());
  24421. };
  24422. /**
  24423. * Removes the chip at the given index.
  24424. * @param {number} index
  24425. * @param {Event=} event
  24426. */
  24427. MdChipsCtrl.prototype.removeChip = function(index, event) {
  24428. var removed = this.items.splice(index, 1);
  24429. // Update model validation
  24430. this.ngModelCtrl.$setDirty();
  24431. this.validateModel();
  24432. if (removed && removed.length && this.useOnRemove && this.onRemove) {
  24433. this.onRemove({ '$chip': removed[0], '$index': index, '$event': event });
  24434. }
  24435. };
  24436. MdChipsCtrl.prototype.removeChipAndFocusInput = function (index, $event) {
  24437. this.removeChip(index, $event);
  24438. if (this.autocompleteCtrl) {
  24439. // Always hide the autocomplete dropdown before focusing the autocomplete input.
  24440. // Wait for the input to move horizontally, because the chip was removed.
  24441. // This can lead to an incorrect dropdown position.
  24442. this.autocompleteCtrl.hidden = true;
  24443. this.$mdUtil.nextTick(this.onFocus.bind(this));
  24444. } else {
  24445. this.onFocus();
  24446. }
  24447. };
  24448. /**
  24449. * Selects the chip at `index`,
  24450. * @param index
  24451. */
  24452. MdChipsCtrl.prototype.selectAndFocusChipSafe = function(index) {
  24453. // If we have no chips, or are asked to select a chip before the first, just focus the input
  24454. if (!this.items.length || index === -1) {
  24455. return this.focusInput();
  24456. }
  24457. // If we are asked to select a chip greater than the number of chips...
  24458. if (index >= this.items.length) {
  24459. if (this.readonly) {
  24460. // If we are readonly, jump back to the start (because we have no input)
  24461. index = 0;
  24462. } else {
  24463. // If we are not readonly, we should attempt to focus the input
  24464. return this.onFocus();
  24465. }
  24466. }
  24467. index = Math.max(index, 0);
  24468. index = Math.min(index, this.items.length - 1);
  24469. this.selectChip(index);
  24470. this.focusChip(index);
  24471. };
  24472. MdChipsCtrl.prototype.focusLastChipThenInput = function() {
  24473. var ctrl = this;
  24474. ctrl.shouldFocusLastChip = false;
  24475. ctrl.focusChip(this.items.length - 1);
  24476. ctrl.$timeout(function() {
  24477. ctrl.focusInput();
  24478. }, ctrl.chipAppendDelay);
  24479. };
  24480. MdChipsCtrl.prototype.focusInput = function() {
  24481. this.selectChip(-1);
  24482. this.onFocus();
  24483. };
  24484. /**
  24485. * Marks the chip at the given index as selected.
  24486. * @param index
  24487. */
  24488. MdChipsCtrl.prototype.selectChip = function(index) {
  24489. if (index >= -1 && index <= this.items.length) {
  24490. this.selectedChip = index;
  24491. // Fire the onSelect if provided
  24492. if (this.useOnSelect && this.onSelect) {
  24493. this.onSelect({'$chip': this.items[index] });
  24494. }
  24495. } else {
  24496. this.$log.warn('Selected Chip index out of bounds; ignoring.');
  24497. }
  24498. };
  24499. /**
  24500. * Selects the chip at `index` and gives it focus.
  24501. * @param index
  24502. */
  24503. MdChipsCtrl.prototype.selectAndFocusChip = function(index) {
  24504. this.selectChip(index);
  24505. if (index != -1) {
  24506. this.focusChip(index);
  24507. }
  24508. };
  24509. /**
  24510. * Call `focus()` on the chip at `index`
  24511. */
  24512. MdChipsCtrl.prototype.focusChip = function(index) {
  24513. var chipContent = this.$element[0].querySelector('md-chip[index="' + index + '"] .md-chip-content');
  24514. this.ariaTabIndex = index;
  24515. chipContent.focus();
  24516. };
  24517. /**
  24518. * Configures the required interactions with the ngModel Controller.
  24519. * Specifically, set {@code this.items} to the {@code NgModelCtrl#$viewVale}.
  24520. * @param ngModelCtrl
  24521. */
  24522. MdChipsCtrl.prototype.configureNgModel = function(ngModelCtrl) {
  24523. this.ngModelCtrl = ngModelCtrl;
  24524. var self = this;
  24525. ngModelCtrl.$render = function() {
  24526. // model is updated. do something.
  24527. self.items = self.ngModelCtrl.$viewValue;
  24528. };
  24529. };
  24530. MdChipsCtrl.prototype.onFocus = function () {
  24531. var input = this.$element[0].querySelector('input');
  24532. input && input.focus();
  24533. this.resetSelectedChip();
  24534. };
  24535. MdChipsCtrl.prototype.onInputFocus = function () {
  24536. this.inputHasFocus = true;
  24537. // Make sure we have the appropriate ARIA attributes
  24538. this.setupInputAria();
  24539. // Make sure we don't have any chips selected
  24540. this.resetSelectedChip();
  24541. };
  24542. MdChipsCtrl.prototype.onInputBlur = function () {
  24543. this.inputHasFocus = false;
  24544. if (this.shouldAddOnBlur()) {
  24545. this.appendChip(this.getChipBuffer().trim());
  24546. this.resetChipBuffer();
  24547. }
  24548. };
  24549. /**
  24550. * Configure event bindings on a user-provided input element.
  24551. * @param inputElement
  24552. */
  24553. MdChipsCtrl.prototype.configureUserInput = function(inputElement) {
  24554. this.userInputElement = inputElement;
  24555. // Find the NgModelCtrl for the input element
  24556. var ngModelCtrl = inputElement.controller('ngModel');
  24557. // `.controller` will look in the parent as well.
  24558. if (ngModelCtrl != this.ngModelCtrl) {
  24559. this.userInputNgModelCtrl = ngModelCtrl;
  24560. }
  24561. var scope = this.$scope;
  24562. var ctrl = this;
  24563. // Run all of the events using evalAsync because a focus may fire a blur in the same digest loop
  24564. var scopeApplyFn = function(event, fn) {
  24565. scope.$evalAsync(angular.bind(ctrl, fn, event));
  24566. };
  24567. // Bind to keydown and focus events of input
  24568. inputElement
  24569. .attr({ tabindex: 0 })
  24570. .on('keydown', function(event) { scopeApplyFn(event, ctrl.inputKeydown) })
  24571. .on('focus', function(event) { scopeApplyFn(event, ctrl.onInputFocus) })
  24572. .on('blur', function(event) { scopeApplyFn(event, ctrl.onInputBlur) })
  24573. };
  24574. MdChipsCtrl.prototype.configureAutocomplete = function(ctrl) {
  24575. if (ctrl) {
  24576. this.autocompleteCtrl = ctrl;
  24577. ctrl.registerSelectedItemWatcher(angular.bind(this, function (item) {
  24578. if (item) {
  24579. // Only append the chip and reset the chip buffer if the max chips limit isn't reached.
  24580. if (this.hasMaxChipsReached()) return;
  24581. this.appendChip(item);
  24582. this.resetChipBuffer();
  24583. }
  24584. }));
  24585. this.$element.find('input')
  24586. .on('focus',angular.bind(this, this.onInputFocus) )
  24587. .on('blur', angular.bind(this, this.onInputBlur) );
  24588. }
  24589. };
  24590. /**
  24591. * Whether the current chip buffer should be added on input blur or not.
  24592. * @returns {boolean}
  24593. */
  24594. MdChipsCtrl.prototype.shouldAddOnBlur = function() {
  24595. // Update the custom ngModel validators from the chips component.
  24596. this.validateModel();
  24597. var chipBuffer = this.getChipBuffer().trim();
  24598. var isModelValid = this.ngModelCtrl.$valid;
  24599. var isAutocompleteShowing = this.autocompleteCtrl && !this.autocompleteCtrl.hidden;
  24600. if (this.userInputNgModelCtrl) {
  24601. isModelValid = isModelValid && this.userInputNgModelCtrl.$valid;
  24602. }
  24603. return this.addOnBlur && !this.requireMatch && chipBuffer && isModelValid && !isAutocompleteShowing;
  24604. };
  24605. MdChipsCtrl.prototype.hasFocus = function () {
  24606. return this.inputHasFocus || this.selectedChip >= 0;
  24607. };
  24608. MdChipsCtrl.prototype.contentIdFor = function(index) {
  24609. return this.contentIds[index];
  24610. };
  24611. })();
  24612. (function(){
  24613. "use strict";
  24614. MdChips.$inject = ["$mdTheming", "$mdUtil", "$compile", "$log", "$timeout", "$$mdSvgRegistry"];angular
  24615. .module('material.components.chips')
  24616. .directive('mdChips', MdChips);
  24617. /**
  24618. * @ngdoc directive
  24619. * @name mdChips
  24620. * @module material.components.chips
  24621. *
  24622. * @description
  24623. * `<md-chips>` is an input component for building lists of strings or objects. The list items are
  24624. * displayed as 'chips'. This component can make use of an `<input>` element or an
  24625. * `<md-autocomplete>` element.
  24626. *
  24627. * ### Custom templates
  24628. * A custom template may be provided to render the content of each chip. This is achieved by
  24629. * specifying an `<md-chip-template>` element containing the custom content as a child of
  24630. * `<md-chips>`.
  24631. *
  24632. * Note: Any attributes on
  24633. * `<md-chip-template>` will be dropped as only the innerHTML is used for the chip template. The
  24634. * variables `$chip` and `$index` are available in the scope of `<md-chip-template>`, representing
  24635. * the chip object and its index in the list of chips, respectively.
  24636. * To override the chip delete control, include an element (ideally a button) with the attribute
  24637. * `md-chip-remove`. A click listener to remove the chip will be added automatically. The element
  24638. * is also placed as a sibling to the chip content (on which there are also click listeners) to
  24639. * avoid a nested ng-click situation.
  24640. *
  24641. * <!-- Note: We no longer want to include this in the site docs; but it should remain here for
  24642. * future developers and those looking at the documentation.
  24643. *
  24644. * <h3> Pending Features </h3>
  24645. * <ul style="padding-left:20px;">
  24646. *
  24647. * <ul>Style
  24648. * <li>Colours for hover, press states (ripple?).</li>
  24649. * </ul>
  24650. *
  24651. * <ul>Validation
  24652. * <li>allow a validation callback</li>
  24653. * <li>highlighting style for invalid chips</li>
  24654. * </ul>
  24655. *
  24656. * <ul>Item mutation
  24657. * <li>Support `
  24658. * <md-chip-edit>` template, show/hide the edit element on tap/click? double tap/double
  24659. * click?
  24660. * </li>
  24661. * </ul>
  24662. *
  24663. * <ul>Truncation and Disambiguation (?)
  24664. * <li>Truncate chip text where possible, but do not truncate entries such that two are
  24665. * indistinguishable.</li>
  24666. * </ul>
  24667. *
  24668. * <ul>Drag and Drop
  24669. * <li>Drag and drop chips between related `<md-chips>` elements.
  24670. * </li>
  24671. * </ul>
  24672. * </ul>
  24673. *
  24674. * //-->
  24675. *
  24676. * Sometimes developers want to limit the amount of possible chips.<br/>
  24677. * You can specify the maximum amount of chips by using the following markup.
  24678. *
  24679. * <hljs lang="html">
  24680. * <md-chips
  24681. * ng-model="myItems"
  24682. * placeholder="Add an item"
  24683. * md-max-chips="5">
  24684. * </md-chips>
  24685. * </hljs>
  24686. *
  24687. * In some cases, you have an autocomplete inside of the `md-chips`.<br/>
  24688. * When the maximum amount of chips has been reached, you can also disable the autocomplete selection.<br/>
  24689. * Here is an example markup.
  24690. *
  24691. * <hljs lang="html">
  24692. * <md-chips ng-model="myItems" md-max-chips="5">
  24693. * <md-autocomplete ng-hide="myItems.length > 5" ...></md-autocomplete>
  24694. * </md-chips>
  24695. * </hljs>
  24696. *
  24697. * ### Accessibility
  24698. *
  24699. * The `md-chips` component supports keyboard and screen reader users since Version 1.1.2. In
  24700. * order to achieve this, we modified the chips behavior to select newly appended chips for
  24701. * `300ms` before re-focusing the input and allowing the user to type.
  24702. *
  24703. * For most users, this delay is small enough that it will not be noticeable but allows certain
  24704. * screen readers to function properly (JAWS and NVDA in particular).
  24705. *
  24706. * We introduced a new `md-chip-append-delay` option to allow developers to better control this
  24707. * behavior.
  24708. *
  24709. * Please refer to the documentation of this option (below) for more information.
  24710. *
  24711. * @param {string|object=} ng-model A model to which the list of items will be bound.
  24712. * @param {string=} placeholder Placeholder text that will be forwarded to the input.
  24713. * @param {string=} secondary-placeholder Placeholder text that will be forwarded to the input,
  24714. * displayed when there is at least one item in the list
  24715. * @param {boolean=} md-removable Enables or disables the deletion of chips through the
  24716. * removal icon or the Delete/Backspace key. Defaults to true.
  24717. * @param {boolean=} readonly Disables list manipulation (deleting or adding list items), hiding
  24718. * the input and delete buttons. If no `ng-model` is provided, the chips will automatically be
  24719. * marked as readonly.<br/><br/>
  24720. * When `md-removable` is not defined, the `md-remove` behavior will be overwritten and disabled.
  24721. * @param {string=} md-enable-chip-edit Set this to "true" to enable editing of chip contents. The user can
  24722. * go into edit mode with pressing "space", "enter", or double clicking on the chip. Chip edit is only
  24723. * supported for chips with basic template.
  24724. * @param {number=} md-max-chips The maximum number of chips allowed to add through user input.
  24725. * <br/><br/>The validation property `md-max-chips` can be used when the max chips
  24726. * amount is reached.
  24727. * @param {boolean=} md-add-on-blur When set to true, remaining text inside of the input will
  24728. * be converted into a new chip on blur.
  24729. * @param {expression} md-transform-chip An expression of form `myFunction($chip)` that when called
  24730. * expects one of the following return values:
  24731. * - an object representing the `$chip` input string
  24732. * - `undefined` to simply add the `$chip` input string, or
  24733. * - `null` to prevent the chip from being appended
  24734. * @param {expression=} md-on-add An expression which will be called when a chip has been
  24735. * added with `$chip` and `$index` available as parameters.
  24736. * @param {expression=} md-on-remove An expression which will be called when a chip has been
  24737. * removed with `$chip`, `$index`, and `$event` available as parameters.
  24738. * @param {expression=} md-on-select An expression which will be called when a chip is selected.
  24739. * @param {boolean} md-require-match If true, and the chips template contains an autocomplete,
  24740. * only allow selection of pre-defined chips (i.e. you cannot add new ones).
  24741. * @param {string=} input-aria-label A string read by screen readers to identify the input.
  24742. * @param {string=} container-hint A string read by screen readers informing users of how to
  24743. * navigate the chips. Used in readonly mode.
  24744. * @param {string=} delete-hint A string read by screen readers instructing users that pressing
  24745. * the delete key will remove the chip.
  24746. * @param {string=} delete-button-label A label for the delete button. Also hidden and read by
  24747. * screen readers.
  24748. * @param {expression=} md-separator-keys An array of key codes used to separate chips.
  24749. * @param {string=} md-chip-append-delay The number of milliseconds that the component will select
  24750. * a newly appended chip before allowing a user to type into the input. This is **necessary**
  24751. * for keyboard accessibility for screen readers. It defaults to 300ms and any number less than
  24752. * 300 can cause issues with screen readers (particularly JAWS and sometimes NVDA).
  24753. *
  24754. * _Available since Version 1.1.2._
  24755. *
  24756. * **Note:** You can safely set this to `0` in one of the following two instances:
  24757. *
  24758. * 1. You are targeting an iOS or Safari-only application (where users would use VoiceOver) or
  24759. * only ChromeVox users.
  24760. *
  24761. * 2. If you have utilized the `md-separator-keys` to disable the `enter` keystroke in
  24762. * favor of another one (such as `,` or `;`).
  24763. *
  24764. * @usage
  24765. * <hljs lang="html">
  24766. * <md-chips
  24767. * ng-model="myItems"
  24768. * placeholder="Add an item"
  24769. * readonly="isReadOnly">
  24770. * </md-chips>
  24771. * </hljs>
  24772. *
  24773. * <h3>Validation</h3>
  24774. * When using [ngMessages](https://docs.angularjs.org/api/ngMessages), you can show errors based
  24775. * on our custom validators.
  24776. * <hljs lang="html">
  24777. * <form name="userForm">
  24778. * <md-chips
  24779. * name="fruits"
  24780. * ng-model="myItems"
  24781. * placeholder="Add an item"
  24782. * md-max-chips="5">
  24783. * </md-chips>
  24784. * <div ng-messages="userForm.fruits.$error" ng-if="userForm.$dirty">
  24785. * <div ng-message="md-max-chips">You reached the maximum amount of chips</div>
  24786. * </div>
  24787. * </form>
  24788. * </hljs>
  24789. *
  24790. */
  24791. var MD_CHIPS_TEMPLATE = '\
  24792. <md-chips-wrap\
  24793. id="{{$mdChipsCtrl.wrapperId}}"\
  24794. tabindex="{{$mdChipsCtrl.readonly ? 0 : -1}}"\
  24795. ng-keydown="$mdChipsCtrl.chipKeydown($event)"\
  24796. ng-class="{ \'md-focused\': $mdChipsCtrl.hasFocus(), \
  24797. \'md-readonly\': !$mdChipsCtrl.ngModelCtrl || $mdChipsCtrl.readonly,\
  24798. \'md-removable\': $mdChipsCtrl.isRemovable() }"\
  24799. aria-setsize="{{$mdChipsCtrl.items.length}}"\
  24800. class="md-chips">\
  24801. <span ng-if="$mdChipsCtrl.readonly" class="md-visually-hidden">\
  24802. {{$mdChipsCtrl.containerHint}}\
  24803. </span>\
  24804. <md-chip ng-repeat="$chip in $mdChipsCtrl.items"\
  24805. index="{{$index}}"\
  24806. ng-class="{\'md-focused\': $mdChipsCtrl.selectedChip == $index, \'md-readonly\': !$mdChipsCtrl.ngModelCtrl || $mdChipsCtrl.readonly}">\
  24807. <div class="md-chip-content"\
  24808. tabindex="{{$mdChipsCtrl.ariaTabIndex == $index ? 0 : -1}}"\
  24809. id="{{$mdChipsCtrl.contentIdFor($index)}}"\
  24810. role="option"\
  24811. aria-selected="{{$mdChipsCtrl.selectedChip == $index}}" \
  24812. aria-posinset="{{$index}}"\
  24813. ng-click="!$mdChipsCtrl.readonly && $mdChipsCtrl.focusChip($index)"\
  24814. ng-focus="!$mdChipsCtrl.readonly && $mdChipsCtrl.selectChip($index)"\
  24815. md-chip-transclude="$mdChipsCtrl.chipContentsTemplate"></div>\
  24816. <div ng-if="$mdChipsCtrl.isRemovable()"\
  24817. class="md-chip-remove-container"\
  24818. tabindex="-1"\
  24819. md-chip-transclude="$mdChipsCtrl.chipRemoveTemplate"></div>\
  24820. </md-chip>\
  24821. <div class="md-chip-input-container" ng-if="!$mdChipsCtrl.readonly && $mdChipsCtrl.ngModelCtrl">\
  24822. <div md-chip-transclude="$mdChipsCtrl.chipInputTemplate"></div>\
  24823. </div>\
  24824. </md-chips-wrap>';
  24825. var CHIP_INPUT_TEMPLATE = '\
  24826. <input\
  24827. class="md-input"\
  24828. tabindex="0"\
  24829. aria-label="{{$mdChipsCtrl.inputAriaLabel}}" \
  24830. placeholder="{{$mdChipsCtrl.getPlaceholder()}}"\
  24831. ng-model="$mdChipsCtrl.chipBuffer"\
  24832. ng-focus="$mdChipsCtrl.onInputFocus()"\
  24833. ng-blur="$mdChipsCtrl.onInputBlur()"\
  24834. ng-keydown="$mdChipsCtrl.inputKeydown($event)">';
  24835. var CHIP_DEFAULT_TEMPLATE = '\
  24836. <span>{{$chip}}</span>';
  24837. var CHIP_REMOVE_TEMPLATE = '\
  24838. <button\
  24839. class="md-chip-remove"\
  24840. ng-if="$mdChipsCtrl.isRemovable()"\
  24841. ng-click="$mdChipsCtrl.removeChipAndFocusInput($$replacedScope.$index, $event)"\
  24842. type="button"\
  24843. tabindex="-1">\
  24844. <md-icon md-svg-src="{{ $mdChipsCtrl.mdCloseIcon }}"></md-icon>\
  24845. <span class="md-visually-hidden">\
  24846. {{$mdChipsCtrl.deleteButtonLabel}}\
  24847. </span>\
  24848. </button>';
  24849. /**
  24850. * MDChips Directive Definition
  24851. */
  24852. function MdChips ($mdTheming, $mdUtil, $compile, $log, $timeout, $$mdSvgRegistry) {
  24853. // Run our templates through $mdUtil.processTemplate() to allow custom start/end symbols
  24854. var templates = getTemplates();
  24855. return {
  24856. template: function(element, attrs) {
  24857. // Clone the element into an attribute. By prepending the attribute
  24858. // name with '$', AngularJS won't write it into the DOM. The cloned
  24859. // element propagates to the link function via the attrs argument,
  24860. // where various contained-elements can be consumed.
  24861. attrs['$mdUserTemplate'] = element.clone();
  24862. return templates.chips;
  24863. },
  24864. require: ['mdChips'],
  24865. restrict: 'E',
  24866. controller: 'MdChipsCtrl',
  24867. controllerAs: '$mdChipsCtrl',
  24868. bindToController: true,
  24869. compile: compile,
  24870. scope: {
  24871. readonly: '=readonly',
  24872. removable: '=mdRemovable',
  24873. placeholder: '@',
  24874. secondaryPlaceholder: '@',
  24875. maxChips: '@mdMaxChips',
  24876. transformChip: '&mdTransformChip',
  24877. onAppend: '&mdOnAppend',
  24878. onAdd: '&mdOnAdd',
  24879. onRemove: '&mdOnRemove',
  24880. onSelect: '&mdOnSelect',
  24881. inputAriaLabel: '@',
  24882. containerHint: '@',
  24883. deleteHint: '@',
  24884. deleteButtonLabel: '@',
  24885. separatorKeys: '=?mdSeparatorKeys',
  24886. requireMatch: '=?mdRequireMatch',
  24887. chipAppendDelayString: '@?mdChipAppendDelay'
  24888. }
  24889. };
  24890. /**
  24891. * Builds the final template for `md-chips` and returns the postLink function.
  24892. *
  24893. * Building the template involves 3 key components:
  24894. * static chips
  24895. * chip template
  24896. * input control
  24897. *
  24898. * If no `ng-model` is provided, only the static chip work needs to be done.
  24899. *
  24900. * If no user-passed `md-chip-template` exists, the default template is used. This resulting
  24901. * template is appended to the chip content element.
  24902. *
  24903. * The remove button may be overridden by passing an element with an md-chip-remove attribute.
  24904. *
  24905. * If an `input` or `md-autocomplete` element is provided by the caller, it is set aside for
  24906. * transclusion later. The transclusion happens in `postLink` as the parent scope is required.
  24907. * If no user input is provided, a default one is appended to the input container node in the
  24908. * template.
  24909. *
  24910. * Static Chips (i.e. `md-chip` elements passed from the caller) are gathered and set aside for
  24911. * transclusion in the `postLink` function.
  24912. *
  24913. *
  24914. * @param element
  24915. * @param attr
  24916. * @returns {Function}
  24917. */
  24918. function compile(element, attr) {
  24919. // Grab the user template from attr and reset the attribute to null.
  24920. var userTemplate = attr['$mdUserTemplate'];
  24921. attr['$mdUserTemplate'] = null;
  24922. var chipTemplate = getTemplateByQuery('md-chips>md-chip-template');
  24923. var chipRemoveSelector = $mdUtil
  24924. .prefixer()
  24925. .buildList('md-chip-remove')
  24926. .map(function(attr) {
  24927. return 'md-chips>*[' + attr + ']';
  24928. })
  24929. .join(',');
  24930. // Set the chip remove, chip contents and chip input templates. The link function will put
  24931. // them on the scope for transclusion later.
  24932. var chipRemoveTemplate = getTemplateByQuery(chipRemoveSelector) || templates.remove,
  24933. chipContentsTemplate = chipTemplate || templates.default,
  24934. chipInputTemplate = getTemplateByQuery('md-chips>md-autocomplete')
  24935. || getTemplateByQuery('md-chips>input')
  24936. || templates.input,
  24937. staticChips = userTemplate.find('md-chip');
  24938. // Warn of malformed template. See #2545
  24939. if (userTemplate[0].querySelector('md-chip-template>*[md-chip-remove]')) {
  24940. $log.warn('invalid placement of md-chip-remove within md-chip-template.');
  24941. }
  24942. function getTemplateByQuery (query) {
  24943. if (!attr.ngModel) return;
  24944. var element = userTemplate[0].querySelector(query);
  24945. return element && element.outerHTML;
  24946. }
  24947. /**
  24948. * Configures controller and transcludes.
  24949. */
  24950. return function postLink(scope, element, attrs, controllers) {
  24951. $mdUtil.initOptionalProperties(scope, attr);
  24952. $mdTheming(element);
  24953. var mdChipsCtrl = controllers[0];
  24954. if(chipTemplate) {
  24955. // Chip editing functionality assumes we are using the default chip template.
  24956. mdChipsCtrl.enableChipEdit = false;
  24957. }
  24958. mdChipsCtrl.chipContentsTemplate = chipContentsTemplate;
  24959. mdChipsCtrl.chipRemoveTemplate = chipRemoveTemplate;
  24960. mdChipsCtrl.chipInputTemplate = chipInputTemplate;
  24961. mdChipsCtrl.mdCloseIcon = $$mdSvgRegistry.mdClose;
  24962. element
  24963. .attr({ tabindex: -1 })
  24964. .on('focus', function () { mdChipsCtrl.onFocus(); });
  24965. if (attr.ngModel) {
  24966. mdChipsCtrl.configureNgModel(element.controller('ngModel'));
  24967. // If an `md-transform-chip` attribute was set, tell the controller to use the expression
  24968. // before appending chips.
  24969. if (attrs.mdTransformChip) mdChipsCtrl.useTransformChipExpression();
  24970. // If an `md-on-append` attribute was set, tell the controller to use the expression
  24971. // when appending chips.
  24972. //
  24973. // DEPRECATED: Will remove in official 1.0 release
  24974. if (attrs.mdOnAppend) mdChipsCtrl.useOnAppendExpression();
  24975. // If an `md-on-add` attribute was set, tell the controller to use the expression
  24976. // when adding chips.
  24977. if (attrs.mdOnAdd) mdChipsCtrl.useOnAddExpression();
  24978. // If an `md-on-remove` attribute was set, tell the controller to use the expression
  24979. // when removing chips.
  24980. if (attrs.mdOnRemove) mdChipsCtrl.useOnRemoveExpression();
  24981. // If an `md-on-select` attribute was set, tell the controller to use the expression
  24982. // when selecting chips.
  24983. if (attrs.mdOnSelect) mdChipsCtrl.useOnSelectExpression();
  24984. // The md-autocomplete and input elements won't be compiled until after this directive
  24985. // is complete (due to their nested nature). Wait a tick before looking for them to
  24986. // configure the controller.
  24987. if (chipInputTemplate != templates.input) {
  24988. // The autocomplete will not appear until the readonly attribute is not true (i.e.
  24989. // false or undefined), so we have to watch the readonly and then on the next tick
  24990. // after the chip transclusion has run, we can configure the autocomplete and user
  24991. // input.
  24992. scope.$watch('$mdChipsCtrl.readonly', function(readonly) {
  24993. if (!readonly) {
  24994. $mdUtil.nextTick(function(){
  24995. if (chipInputTemplate.indexOf('<md-autocomplete') === 0) {
  24996. var autocompleteEl = element.find('md-autocomplete');
  24997. mdChipsCtrl.configureAutocomplete(autocompleteEl.controller('mdAutocomplete'));
  24998. }
  24999. mdChipsCtrl.configureUserInput(element.find('input'));
  25000. });
  25001. }
  25002. });
  25003. }
  25004. // At the next tick, if we find an input, make sure it has the md-input class
  25005. $mdUtil.nextTick(function() {
  25006. var input = element.find('input');
  25007. input && input.toggleClass('md-input', true);
  25008. });
  25009. }
  25010. // Compile with the parent's scope and prepend any static chips to the wrapper.
  25011. if (staticChips.length > 0) {
  25012. var compiledStaticChips = $compile(staticChips.clone())(scope.$parent);
  25013. $timeout(function() { element.find('md-chips-wrap').prepend(compiledStaticChips); });
  25014. }
  25015. };
  25016. }
  25017. function getTemplates() {
  25018. return {
  25019. chips: $mdUtil.processTemplate(MD_CHIPS_TEMPLATE),
  25020. input: $mdUtil.processTemplate(CHIP_INPUT_TEMPLATE),
  25021. default: $mdUtil.processTemplate(CHIP_DEFAULT_TEMPLATE),
  25022. remove: $mdUtil.processTemplate(CHIP_REMOVE_TEMPLATE)
  25023. };
  25024. }
  25025. }
  25026. })();
  25027. (function(){
  25028. "use strict";
  25029. angular
  25030. .module('material.components.chips')
  25031. .controller('MdContactChipsCtrl', MdContactChipsCtrl);
  25032. /**
  25033. * Controller for the MdContactChips component
  25034. * @constructor
  25035. */
  25036. function MdContactChipsCtrl () {
  25037. /** @type {Object} */
  25038. this.selectedItem = null;
  25039. /** @type {string} */
  25040. this.searchText = '';
  25041. }
  25042. MdContactChipsCtrl.prototype.queryContact = function(searchText) {
  25043. return this.contactQuery({'$query': searchText});
  25044. };
  25045. MdContactChipsCtrl.prototype.itemName = function(item) {
  25046. return item[this.contactName];
  25047. };
  25048. })();
  25049. (function(){
  25050. "use strict";
  25051. MdContactChips.$inject = ["$mdTheming", "$mdUtil"];angular
  25052. .module('material.components.chips')
  25053. .directive('mdContactChips', MdContactChips);
  25054. /**
  25055. * @ngdoc directive
  25056. * @name mdContactChips
  25057. * @module material.components.chips
  25058. *
  25059. * @description
  25060. * `<md-contact-chips>` is an input component based on `md-chips` and makes use of an
  25061. * `md-autocomplete` element. The component allows the caller to supply a query expression which
  25062. * returns a list of possible contacts. The user can select one of these and add it to the list of
  25063. * chips.
  25064. *
  25065. * You may also use the `md-highlight-text` directive along with its parameters to control the
  25066. * appearance of the matched text inside of the contacts' autocomplete popup.
  25067. *
  25068. * @param {string=|object=} ng-model A model to bind the list of items to
  25069. * @param {string=} placeholder Placeholder text that will be forwarded to the input.
  25070. * @param {string=} secondary-placeholder Placeholder text that will be forwarded to the input,
  25071. * displayed when there is at least on item in the list
  25072. * @param {expression} md-contacts An expression expected to return contacts matching the search
  25073. * test, `$query`. If this expression involves a promise, a loading bar is displayed while
  25074. * waiting for it to resolve.
  25075. * @param {string} md-contact-name The field name of the contact object representing the
  25076. * contact's name.
  25077. * @param {string} md-contact-email The field name of the contact object representing the
  25078. * contact's email address.
  25079. * @param {string} md-contact-image The field name of the contact object representing the
  25080. * contact's image.
  25081. * @param {number=} md-min-length Specifies the minimum length of text before autocomplete will
  25082. * make suggestions
  25083. *
  25084. * @param {expression=} filter-selected Whether to filter selected contacts from the list of
  25085. * suggestions shown in the autocomplete.
  25086. *
  25087. * ***Note:** This attribute has been removed but may come back.*
  25088. *
  25089. *
  25090. *
  25091. * @usage
  25092. * <hljs lang="html">
  25093. * <md-contact-chips
  25094. * ng-model="ctrl.contacts"
  25095. * md-contacts="ctrl.querySearch($query)"
  25096. * md-contact-name="name"
  25097. * md-contact-image="image"
  25098. * md-contact-email="email"
  25099. * placeholder="To">
  25100. * </md-contact-chips>
  25101. * </hljs>
  25102. *
  25103. */
  25104. var MD_CONTACT_CHIPS_TEMPLATE = '\
  25105. <md-chips class="md-contact-chips"\
  25106. ng-model="$mdContactChipsCtrl.contacts"\
  25107. md-require-match="$mdContactChipsCtrl.requireMatch"\
  25108. md-chip-append-delay="{{$mdContactChipsCtrl.chipAppendDelay}}" \
  25109. md-autocomplete-snap>\
  25110. <md-autocomplete\
  25111. md-menu-class="md-contact-chips-suggestions"\
  25112. md-selected-item="$mdContactChipsCtrl.selectedItem"\
  25113. md-search-text="$mdContactChipsCtrl.searchText"\
  25114. md-items="item in $mdContactChipsCtrl.queryContact($mdContactChipsCtrl.searchText)"\
  25115. md-item-text="$mdContactChipsCtrl.itemName(item)"\
  25116. md-no-cache="true"\
  25117. md-min-length="$mdContactChipsCtrl.minLength"\
  25118. md-autoselect\
  25119. placeholder="{{$mdContactChipsCtrl.contacts.length == 0 ?\
  25120. $mdContactChipsCtrl.placeholder : $mdContactChipsCtrl.secondaryPlaceholder}}">\
  25121. <div class="md-contact-suggestion">\
  25122. <img \
  25123. ng-src="{{item[$mdContactChipsCtrl.contactImage]}}"\
  25124. alt="{{item[$mdContactChipsCtrl.contactName]}}"\
  25125. ng-if="item[$mdContactChipsCtrl.contactImage]" />\
  25126. <span class="md-contact-name" md-highlight-text="$mdContactChipsCtrl.searchText"\
  25127. md-highlight-flags="{{$mdContactChipsCtrl.highlightFlags}}">\
  25128. {{item[$mdContactChipsCtrl.contactName]}}\
  25129. </span>\
  25130. <span class="md-contact-email" >{{item[$mdContactChipsCtrl.contactEmail]}}</span>\
  25131. </div>\
  25132. </md-autocomplete>\
  25133. <md-chip-template>\
  25134. <div class="md-contact-avatar">\
  25135. <img \
  25136. ng-src="{{$chip[$mdContactChipsCtrl.contactImage]}}"\
  25137. alt="{{$chip[$mdContactChipsCtrl.contactName]}}"\
  25138. ng-if="$chip[$mdContactChipsCtrl.contactImage]" />\
  25139. </div>\
  25140. <div class="md-contact-name">\
  25141. {{$chip[$mdContactChipsCtrl.contactName]}}\
  25142. </div>\
  25143. </md-chip-template>\
  25144. </md-chips>';
  25145. /**
  25146. * MDContactChips Directive Definition
  25147. *
  25148. * @param $mdTheming
  25149. * @returns {*}
  25150. * @ngInject
  25151. */
  25152. function MdContactChips($mdTheming, $mdUtil) {
  25153. return {
  25154. template: function(element, attrs) {
  25155. return MD_CONTACT_CHIPS_TEMPLATE;
  25156. },
  25157. restrict: 'E',
  25158. controller: 'MdContactChipsCtrl',
  25159. controllerAs: '$mdContactChipsCtrl',
  25160. bindToController: true,
  25161. compile: compile,
  25162. scope: {
  25163. contactQuery: '&mdContacts',
  25164. placeholder: '@',
  25165. secondaryPlaceholder: '@',
  25166. contactName: '@mdContactName',
  25167. contactImage: '@mdContactImage',
  25168. contactEmail: '@mdContactEmail',
  25169. contacts: '=ngModel',
  25170. requireMatch: '=?mdRequireMatch',
  25171. minLength: '=?mdMinLength',
  25172. highlightFlags: '@?mdHighlightFlags',
  25173. chipAppendDelay: '@?mdChipAppendDelay'
  25174. }
  25175. };
  25176. function compile(element, attr) {
  25177. return function postLink(scope, element, attrs, controllers) {
  25178. var contactChipsController = controllers;
  25179. $mdUtil.initOptionalProperties(scope, attr);
  25180. $mdTheming(element);
  25181. element.attr('tabindex', '-1');
  25182. attrs.$observe('mdChipAppendDelay', function(newValue) {
  25183. contactChipsController.chipAppendDelay = newValue;
  25184. });
  25185. };
  25186. }
  25187. }
  25188. })();
  25189. (function(){
  25190. "use strict";
  25191. (function() {
  25192. 'use strict';
  25193. /**
  25194. * @ngdoc directive
  25195. * @name mdCalendar
  25196. * @module material.components.datepicker
  25197. *
  25198. * @param {Date} ng-model The component's model. Should be a Date object.
  25199. * @param {Date=} md-min-date Expression representing the minimum date.
  25200. * @param {Date=} md-max-date Expression representing the maximum date.
  25201. * @param {(function(Date): boolean)=} md-date-filter Function expecting a date and returning a boolean whether it can be selected or not.
  25202. * @param {String=} md-current-view Current view of the calendar. Can be either "month" or "year".
  25203. * @param {String=} md-mode Restricts the user to only selecting a value from a particular view. This option can
  25204. * be used if the user is only supposed to choose from a certain date type (e.g. only selecting the month).
  25205. * Can be either "month" or "day". **Note** that this will ovewrite the `md-current-view` value.
  25206. *
  25207. * @description
  25208. * `<md-calendar>` is a component that renders a calendar that can be used to select a date.
  25209. * It is a part of the `<md-datepicker>` pane, however it can also be used on it's own.
  25210. *
  25211. * @usage
  25212. *
  25213. * <hljs lang="html">
  25214. * <md-calendar ng-model="birthday"></md-calendar>
  25215. * </hljs>
  25216. */
  25217. CalendarCtrl.$inject = ["$element", "$scope", "$$mdDateUtil", "$mdUtil", "$mdConstant", "$mdTheming", "$$rAF", "$attrs", "$mdDateLocale"];
  25218. angular.module('material.components.datepicker')
  25219. .directive('mdCalendar', calendarDirective);
  25220. // POST RELEASE
  25221. // TODO(jelbourn): Mac Cmd + left / right == Home / End
  25222. // TODO(jelbourn): Refactor month element creation to use cloneNode (performance).
  25223. // TODO(jelbourn): Define virtual scrolling constants (compactness) users can override.
  25224. // TODO(jelbourn): Animated month transition on ng-model change (virtual-repeat)
  25225. // TODO(jelbourn): Scroll snapping (virtual repeat)
  25226. // TODO(jelbourn): Remove superfluous row from short months (virtual-repeat)
  25227. // TODO(jelbourn): Month headers stick to top when scrolling.
  25228. // TODO(jelbourn): Previous month opacity is lowered when partially scrolled out of view.
  25229. // TODO(jelbourn): Support md-calendar standalone on a page (as a tabstop w/ aria-live
  25230. // announcement and key handling).
  25231. // Read-only calendar (not just date-picker).
  25232. function calendarDirective() {
  25233. return {
  25234. template: function(tElement, tAttr) {
  25235. // TODO(crisbeto): This is a workaround that allows the calendar to work, without
  25236. // a datepicker, until issue #8585 gets resolved. It can safely be removed
  25237. // afterwards. This ensures that the virtual repeater scrolls to the proper place on load by
  25238. // deferring the execution until the next digest. It's necessary only if the calendar is used
  25239. // without a datepicker, otherwise it's already wrapped in an ngIf.
  25240. var extraAttrs = tAttr.hasOwnProperty('ngIf') ? '' : 'ng-if="calendarCtrl.isInitialized"';
  25241. var template = '' +
  25242. '<div ng-switch="calendarCtrl.currentView" ' + extraAttrs + '>' +
  25243. '<md-calendar-year ng-switch-when="year"></md-calendar-year>' +
  25244. '<md-calendar-month ng-switch-default></md-calendar-month>' +
  25245. '</div>';
  25246. return template;
  25247. },
  25248. scope: {
  25249. minDate: '=mdMinDate',
  25250. maxDate: '=mdMaxDate',
  25251. dateFilter: '=mdDateFilter',
  25252. // These need to be prefixed, because Angular resets
  25253. // any changes to the value due to bindToController.
  25254. _mode: '@mdMode',
  25255. _currentView: '@mdCurrentView'
  25256. },
  25257. require: ['ngModel', 'mdCalendar'],
  25258. controller: CalendarCtrl,
  25259. controllerAs: 'calendarCtrl',
  25260. bindToController: true,
  25261. link: function(scope, element, attrs, controllers) {
  25262. var ngModelCtrl = controllers[0];
  25263. var mdCalendarCtrl = controllers[1];
  25264. mdCalendarCtrl.configureNgModel(ngModelCtrl);
  25265. }
  25266. };
  25267. }
  25268. /**
  25269. * Occasionally the hideVerticalScrollbar method might read an element's
  25270. * width as 0, because it hasn't been laid out yet. This value will be used
  25271. * as a fallback, in order to prevent scenarios where the element's width
  25272. * would otherwise have been set to 0. This value is the "usual" width of a
  25273. * calendar within a floating calendar pane.
  25274. */
  25275. var FALLBACK_WIDTH = 340;
  25276. /** Next identifier for calendar instance. */
  25277. var nextUniqueId = 0;
  25278. /** Maps the `md-mode` values to their corresponding calendar views. */
  25279. var MODE_MAP = {
  25280. day: 'month',
  25281. month: 'year'
  25282. };
  25283. /**
  25284. * Controller for the mdCalendar component.
  25285. * @ngInject @constructor
  25286. */
  25287. function CalendarCtrl($element, $scope, $$mdDateUtil, $mdUtil,
  25288. $mdConstant, $mdTheming, $$rAF, $attrs, $mdDateLocale) {
  25289. $mdTheming($element);
  25290. /** @final {!angular.JQLite} */
  25291. this.$element = $element;
  25292. /** @final {!angular.Scope} */
  25293. this.$scope = $scope;
  25294. /** @final */
  25295. this.dateUtil = $$mdDateUtil;
  25296. /** @final */
  25297. this.$mdUtil = $mdUtil;
  25298. /** @final */
  25299. this.keyCode = $mdConstant.KEY_CODE;
  25300. /** @final */
  25301. this.$$rAF = $$rAF;
  25302. /** @final */
  25303. this.$mdDateLocale = $mdDateLocale;
  25304. /** @final {Date} */
  25305. this.today = this.dateUtil.createDateAtMidnight();
  25306. /** @type {!angular.NgModelController} */
  25307. this.ngModelCtrl = null;
  25308. /** @type {String} Class applied to the selected date cell. */
  25309. this.SELECTED_DATE_CLASS = 'md-calendar-selected-date';
  25310. /** @type {String} Class applied to the cell for today. */
  25311. this.TODAY_CLASS = 'md-calendar-date-today';
  25312. /** @type {String} Class applied to the focused cell. */
  25313. this.FOCUSED_DATE_CLASS = 'md-focus';
  25314. /** @final {number} Unique ID for this calendar instance. */
  25315. this.id = nextUniqueId++;
  25316. /**
  25317. * The date that is currently focused or showing in the calendar. This will initially be set
  25318. * to the ng-model value if set, otherwise to today. It will be updated as the user navigates
  25319. * to other months. The cell corresponding to the displayDate does not necesarily always have
  25320. * focus in the document (such as for cases when the user is scrolling the calendar).
  25321. * @type {Date}
  25322. */
  25323. this.displayDate = null;
  25324. /**
  25325. * The selected date. Keep track of this separately from the ng-model value so that we
  25326. * can know, when the ng-model value changes, what the previous value was before it's updated
  25327. * in the component's UI.
  25328. *
  25329. * @type {Date}
  25330. */
  25331. this.selectedDate = null;
  25332. /**
  25333. * The first date that can be rendered by the calendar. The default is taken
  25334. * from the mdDateLocale provider and is limited by the mdMinDate.
  25335. * @type {Date}
  25336. */
  25337. this.firstRenderableDate = null;
  25338. /**
  25339. * The last date that can be rendered by the calendar. The default comes
  25340. * from the mdDateLocale provider and is limited by the maxDate.
  25341. * @type {Date}
  25342. */
  25343. this.lastRenderableDate = null;
  25344. /**
  25345. * Used to toggle initialize the root element in the next digest.
  25346. * @type {Boolean}
  25347. */
  25348. this.isInitialized = false;
  25349. /**
  25350. * Cache for the width of the element without a scrollbar. Used to hide the scrollbar later on
  25351. * and to avoid extra reflows when switching between views.
  25352. * @type {Number}
  25353. */
  25354. this.width = 0;
  25355. /**
  25356. * Caches the width of the scrollbar in order to be used when hiding it and to avoid extra reflows.
  25357. * @type {Number}
  25358. */
  25359. this.scrollbarWidth = 0;
  25360. // Unless the user specifies so, the calendar should not be a tab stop.
  25361. // This is necessary because ngAria might add a tabindex to anything with an ng-model
  25362. // (based on whether or not the user has turned that particular feature on/off).
  25363. if (!$attrs.tabindex) {
  25364. $element.attr('tabindex', '-1');
  25365. }
  25366. var boundKeyHandler = angular.bind(this, this.handleKeyEvent);
  25367. // If use the md-calendar directly in the body without datepicker,
  25368. // handleKeyEvent will disable other inputs on the page.
  25369. // So only apply the handleKeyEvent on the body when the md-calendar inside datepicker,
  25370. // otherwise apply on the calendar element only.
  25371. var handleKeyElement;
  25372. if ($element.parent().hasClass('md-datepicker-calendar')) {
  25373. handleKeyElement = angular.element(document.body);
  25374. } else {
  25375. handleKeyElement = $element;
  25376. }
  25377. // Bind the keydown handler to the body, in order to handle cases where the focused
  25378. // element gets removed from the DOM and stops propagating click events.
  25379. handleKeyElement.on('keydown', boundKeyHandler);
  25380. $scope.$on('$destroy', function() {
  25381. handleKeyElement.off('keydown', boundKeyHandler);
  25382. });
  25383. // For AngularJS 1.4 and older, where there are no lifecycle hooks but bindings are pre-assigned,
  25384. // manually call the $onInit hook.
  25385. if (angular.version.major === 1 && angular.version.minor <= 4) {
  25386. this.$onInit();
  25387. }
  25388. }
  25389. /**
  25390. * AngularJS Lifecycle hook for newer AngularJS versions.
  25391. * Bindings are not guaranteed to have been assigned in the controller, but they are in the $onInit hook.
  25392. */
  25393. CalendarCtrl.prototype.$onInit = function() {
  25394. /**
  25395. * The currently visible calendar view. Note the prefix on the scope value,
  25396. * which is necessary, because the datepicker seems to reset the real one value if the
  25397. * calendar is open, but the `currentView` on the datepicker's scope is empty.
  25398. * @type {String}
  25399. */
  25400. if (this._mode && MODE_MAP.hasOwnProperty(this._mode)) {
  25401. this.currentView = MODE_MAP[this._mode];
  25402. this.mode = this._mode;
  25403. } else {
  25404. this.currentView = this._currentView || 'month';
  25405. this.mode = null;
  25406. }
  25407. var dateLocale = this.$mdDateLocale;
  25408. if (this.minDate && this.minDate > dateLocale.firstRenderableDate) {
  25409. this.firstRenderableDate = this.minDate;
  25410. } else {
  25411. this.firstRenderableDate = dateLocale.firstRenderableDate;
  25412. }
  25413. if (this.maxDate && this.maxDate < dateLocale.lastRenderableDate) {
  25414. this.lastRenderableDate = this.maxDate;
  25415. } else {
  25416. this.lastRenderableDate = dateLocale.lastRenderableDate;
  25417. }
  25418. };
  25419. /**
  25420. * Sets up the controller's reference to ngModelController.
  25421. * @param {!angular.NgModelController} ngModelCtrl
  25422. */
  25423. CalendarCtrl.prototype.configureNgModel = function(ngModelCtrl) {
  25424. var self = this;
  25425. self.ngModelCtrl = ngModelCtrl;
  25426. self.$mdUtil.nextTick(function() {
  25427. self.isInitialized = true;
  25428. });
  25429. ngModelCtrl.$render = function() {
  25430. var value = this.$viewValue;
  25431. // Notify the child scopes of any changes.
  25432. self.$scope.$broadcast('md-calendar-parent-changed', value);
  25433. // Set up the selectedDate if it hasn't been already.
  25434. if (!self.selectedDate) {
  25435. self.selectedDate = value;
  25436. }
  25437. // Also set up the displayDate.
  25438. if (!self.displayDate) {
  25439. self.displayDate = self.selectedDate || self.today;
  25440. }
  25441. };
  25442. };
  25443. /**
  25444. * Sets the ng-model value for the calendar and emits a change event.
  25445. * @param {Date} date
  25446. */
  25447. CalendarCtrl.prototype.setNgModelValue = function(date) {
  25448. var value = this.dateUtil.createDateAtMidnight(date);
  25449. this.focus(value);
  25450. this.$scope.$emit('md-calendar-change', value);
  25451. this.ngModelCtrl.$setViewValue(value);
  25452. this.ngModelCtrl.$render();
  25453. return value;
  25454. };
  25455. /**
  25456. * Sets the current view that should be visible in the calendar
  25457. * @param {string} newView View name to be set.
  25458. * @param {number|Date} time Date object or a timestamp for the new display date.
  25459. */
  25460. CalendarCtrl.prototype.setCurrentView = function(newView, time) {
  25461. var self = this;
  25462. self.$mdUtil.nextTick(function() {
  25463. self.currentView = newView;
  25464. if (time) {
  25465. self.displayDate = angular.isDate(time) ? time : new Date(time);
  25466. }
  25467. });
  25468. };
  25469. /**
  25470. * Focus the cell corresponding to the given date.
  25471. * @param {Date} date The date to be focused.
  25472. */
  25473. CalendarCtrl.prototype.focus = function(date) {
  25474. if (this.dateUtil.isValidDate(date)) {
  25475. var previousFocus = this.$element[0].querySelector('.' + this.FOCUSED_DATE_CLASS);
  25476. if (previousFocus) {
  25477. previousFocus.classList.remove(this.FOCUSED_DATE_CLASS);
  25478. }
  25479. var cellId = this.getDateId(date, this.currentView);
  25480. var cell = document.getElementById(cellId);
  25481. if (cell) {
  25482. cell.classList.add(this.FOCUSED_DATE_CLASS);
  25483. cell.focus();
  25484. this.displayDate = date;
  25485. }
  25486. } else {
  25487. var rootElement = this.$element[0].querySelector('[ng-switch]');
  25488. if (rootElement) {
  25489. rootElement.focus();
  25490. }
  25491. }
  25492. };
  25493. /**
  25494. * Highlights a date cell on the calendar and changes the selected date.
  25495. * @param {Date=} date Date to be marked as selected.
  25496. */
  25497. CalendarCtrl.prototype.changeSelectedDate = function(date) {
  25498. var selectedDateClass = this.SELECTED_DATE_CLASS;
  25499. var prevDateCell = this.$element[0].querySelector('.' + selectedDateClass);
  25500. // Remove the selected class from the previously selected date, if any.
  25501. if (prevDateCell) {
  25502. prevDateCell.classList.remove(selectedDateClass);
  25503. prevDateCell.setAttribute('aria-selected', 'false');
  25504. }
  25505. // Apply the select class to the new selected date if it is set.
  25506. if (date) {
  25507. var dateCell = document.getElementById(this.getDateId(date, this.currentView));
  25508. if (dateCell) {
  25509. dateCell.classList.add(selectedDateClass);
  25510. dateCell.setAttribute('aria-selected', 'true');
  25511. }
  25512. }
  25513. this.selectedDate = date;
  25514. };
  25515. /**
  25516. * Normalizes the key event into an action name. The action will be broadcast
  25517. * to the child controllers.
  25518. * @param {KeyboardEvent} event
  25519. * @returns {String} The action that should be taken, or null if the key
  25520. * does not match a calendar shortcut.
  25521. */
  25522. CalendarCtrl.prototype.getActionFromKeyEvent = function(event) {
  25523. var keyCode = this.keyCode;
  25524. switch (event.which) {
  25525. case keyCode.ENTER: return 'select';
  25526. case keyCode.RIGHT_ARROW: return 'move-right';
  25527. case keyCode.LEFT_ARROW: return 'move-left';
  25528. case keyCode.DOWN_ARROW: return event.metaKey ? 'move-page-down' : 'move-row-down';
  25529. case keyCode.UP_ARROW: return event.metaKey ? 'move-page-up' : 'move-row-up';
  25530. case keyCode.PAGE_DOWN: return 'move-page-down';
  25531. case keyCode.PAGE_UP: return 'move-page-up';
  25532. case keyCode.HOME: return 'start';
  25533. case keyCode.END: return 'end';
  25534. default: return null;
  25535. }
  25536. };
  25537. /**
  25538. * Handles a key event in the calendar with the appropriate action. The action will either
  25539. * be to select the focused date or to navigate to focus a new date.
  25540. * @param {KeyboardEvent} event
  25541. */
  25542. CalendarCtrl.prototype.handleKeyEvent = function(event) {
  25543. var self = this;
  25544. this.$scope.$apply(function() {
  25545. // Capture escape and emit back up so that a wrapping component
  25546. // (such as a date-picker) can decide to close.
  25547. if (event.which == self.keyCode.ESCAPE || event.which == self.keyCode.TAB) {
  25548. self.$scope.$emit('md-calendar-close');
  25549. if (event.which == self.keyCode.TAB) {
  25550. event.preventDefault();
  25551. }
  25552. return;
  25553. }
  25554. // Broadcast the action that any child controllers should take.
  25555. var action = self.getActionFromKeyEvent(event);
  25556. if (action) {
  25557. event.preventDefault();
  25558. event.stopPropagation();
  25559. self.$scope.$broadcast('md-calendar-parent-action', action);
  25560. }
  25561. });
  25562. };
  25563. /**
  25564. * Hides the vertical scrollbar on the calendar scroller of a child controller by
  25565. * setting the width on the calendar scroller and the `overflow: hidden` wrapper
  25566. * around the scroller, and then setting a padding-right on the scroller equal
  25567. * to the width of the browser's scrollbar.
  25568. *
  25569. * This will cause a reflow.
  25570. *
  25571. * @param {object} childCtrl The child controller whose scrollbar should be hidden.
  25572. */
  25573. CalendarCtrl.prototype.hideVerticalScrollbar = function(childCtrl) {
  25574. var self = this;
  25575. var element = childCtrl.$element[0];
  25576. var scrollMask = element.querySelector('.md-calendar-scroll-mask');
  25577. if (self.width > 0) {
  25578. setWidth();
  25579. } else {
  25580. self.$$rAF(function() {
  25581. var scroller = childCtrl.calendarScroller;
  25582. self.scrollbarWidth = scroller.offsetWidth - scroller.clientWidth;
  25583. self.width = element.querySelector('table').offsetWidth;
  25584. setWidth();
  25585. });
  25586. }
  25587. function setWidth() {
  25588. var width = self.width || FALLBACK_WIDTH;
  25589. var scrollbarWidth = self.scrollbarWidth;
  25590. var scroller = childCtrl.calendarScroller;
  25591. scrollMask.style.width = width + 'px';
  25592. scroller.style.width = (width + scrollbarWidth) + 'px';
  25593. scroller.style.paddingRight = scrollbarWidth + 'px';
  25594. }
  25595. };
  25596. /**
  25597. * Gets an identifier for a date unique to the calendar instance for internal
  25598. * purposes. Not to be displayed.
  25599. * @param {Date} date The date for which the id is being generated
  25600. * @param {string} namespace Namespace for the id. (month, year etc.)
  25601. * @returns {string}
  25602. */
  25603. CalendarCtrl.prototype.getDateId = function(date, namespace) {
  25604. if (!namespace) {
  25605. throw new Error('A namespace for the date id has to be specified.');
  25606. }
  25607. return [
  25608. 'md',
  25609. this.id,
  25610. namespace,
  25611. date.getFullYear(),
  25612. date.getMonth(),
  25613. date.getDate()
  25614. ].join('-');
  25615. };
  25616. /**
  25617. * Util to trigger an extra digest on a parent scope, in order to to ensure that
  25618. * any child virtual repeaters have updated. This is necessary, because the virtual
  25619. * repeater doesn't update the $index the first time around since the content isn't
  25620. * in place yet. The case, in which this is an issue, is when the repeater has less
  25621. * than a page of content (e.g. a month or year view has a min or max date).
  25622. */
  25623. CalendarCtrl.prototype.updateVirtualRepeat = function() {
  25624. var scope = this.$scope;
  25625. var virtualRepeatResizeListener = scope.$on('$md-resize-enable', function() {
  25626. if (!scope.$$phase) {
  25627. scope.$apply();
  25628. }
  25629. virtualRepeatResizeListener();
  25630. });
  25631. };
  25632. })();
  25633. })();
  25634. (function(){
  25635. "use strict";
  25636. (function() {
  25637. 'use strict';
  25638. CalendarMonthCtrl.$inject = ["$element", "$scope", "$animate", "$q", "$$mdDateUtil", "$mdDateLocale"];
  25639. angular.module('material.components.datepicker')
  25640. .directive('mdCalendarMonth', calendarDirective);
  25641. /**
  25642. * Height of one calendar month tbody. This must be made known to the virtual-repeat and is
  25643. * subsequently used for scrolling to specific months.
  25644. */
  25645. var TBODY_HEIGHT = 265;
  25646. /**
  25647. * Height of a calendar month with a single row. This is needed to calculate the offset for
  25648. * rendering an extra month in virtual-repeat that only contains one row.
  25649. */
  25650. var TBODY_SINGLE_ROW_HEIGHT = 45;
  25651. /** Private directive that represents a list of months inside the calendar. */
  25652. function calendarDirective() {
  25653. return {
  25654. template:
  25655. '<table aria-hidden="true" class="md-calendar-day-header"><thead></thead></table>' +
  25656. '<div class="md-calendar-scroll-mask">' +
  25657. '<md-virtual-repeat-container class="md-calendar-scroll-container" ' +
  25658. 'md-offset-size="' + (TBODY_SINGLE_ROW_HEIGHT - TBODY_HEIGHT) + '">' +
  25659. '<table role="grid" tabindex="0" class="md-calendar" aria-readonly="true">' +
  25660. '<tbody ' +
  25661. 'md-calendar-month-body ' +
  25662. 'role="rowgroup" ' +
  25663. 'md-virtual-repeat="i in monthCtrl.items" ' +
  25664. 'md-month-offset="$index" ' +
  25665. 'class="md-calendar-month" ' +
  25666. 'md-start-index="monthCtrl.getSelectedMonthIndex()" ' +
  25667. 'md-item-size="' + TBODY_HEIGHT + '">' +
  25668. // The <tr> ensures that the <tbody> will always have the
  25669. // proper height, even if it's empty. If it's content is
  25670. // compiled, the <tr> will be overwritten.
  25671. '<tr aria-hidden="true" md-force-height="\'' + TBODY_HEIGHT + 'px\'"></tr>' +
  25672. '</tbody>' +
  25673. '</table>' +
  25674. '</md-virtual-repeat-container>' +
  25675. '</div>',
  25676. require: ['^^mdCalendar', 'mdCalendarMonth'],
  25677. controller: CalendarMonthCtrl,
  25678. controllerAs: 'monthCtrl',
  25679. bindToController: true,
  25680. link: function(scope, element, attrs, controllers) {
  25681. var calendarCtrl = controllers[0];
  25682. var monthCtrl = controllers[1];
  25683. monthCtrl.initialize(calendarCtrl);
  25684. }
  25685. };
  25686. }
  25687. /**
  25688. * Controller for the calendar month component.
  25689. * @ngInject @constructor
  25690. */
  25691. function CalendarMonthCtrl($element, $scope, $animate, $q,
  25692. $$mdDateUtil, $mdDateLocale) {
  25693. /** @final {!angular.JQLite} */
  25694. this.$element = $element;
  25695. /** @final {!angular.Scope} */
  25696. this.$scope = $scope;
  25697. /** @final {!angular.$animate} */
  25698. this.$animate = $animate;
  25699. /** @final {!angular.$q} */
  25700. this.$q = $q;
  25701. /** @final */
  25702. this.dateUtil = $$mdDateUtil;
  25703. /** @final */
  25704. this.dateLocale = $mdDateLocale;
  25705. /** @final {HTMLElement} */
  25706. this.calendarScroller = $element[0].querySelector('.md-virtual-repeat-scroller');
  25707. /** @type {boolean} */
  25708. this.isInitialized = false;
  25709. /** @type {boolean} */
  25710. this.isMonthTransitionInProgress = false;
  25711. var self = this;
  25712. /**
  25713. * Handles a click event on a date cell.
  25714. * Created here so that every cell can use the same function instance.
  25715. * @this {HTMLTableCellElement} The cell that was clicked.
  25716. */
  25717. this.cellClickHandler = function() {
  25718. var timestamp = $$mdDateUtil.getTimestampFromNode(this);
  25719. self.$scope.$apply(function() {
  25720. self.calendarCtrl.setNgModelValue(timestamp);
  25721. });
  25722. };
  25723. /**
  25724. * Handles click events on the month headers. Switches
  25725. * the calendar to the year view.
  25726. * @this {HTMLTableCellElement} The cell that was clicked.
  25727. */
  25728. this.headerClickHandler = function() {
  25729. self.calendarCtrl.setCurrentView('year', $$mdDateUtil.getTimestampFromNode(this));
  25730. };
  25731. }
  25732. /*** Initialization ***/
  25733. /**
  25734. * Initialize the controller by saving a reference to the calendar and
  25735. * setting up the object that will be iterated by the virtual repeater.
  25736. */
  25737. CalendarMonthCtrl.prototype.initialize = function(calendarCtrl) {
  25738. /**
  25739. * Dummy array-like object for virtual-repeat to iterate over. The length is the total
  25740. * number of months that can be viewed. We add 2 months: one to include the current month
  25741. * and one for the last dummy month.
  25742. *
  25743. * This is shorter than ideal because of a (potential) Firefox bug
  25744. * https://bugzilla.mozilla.org/show_bug.cgi?id=1181658.
  25745. */
  25746. this.items = {
  25747. length: this.dateUtil.getMonthDistance(
  25748. calendarCtrl.firstRenderableDate,
  25749. calendarCtrl.lastRenderableDate
  25750. ) + 2
  25751. };
  25752. this.calendarCtrl = calendarCtrl;
  25753. this.attachScopeListeners();
  25754. calendarCtrl.updateVirtualRepeat();
  25755. // Fire the initial render, since we might have missed it the first time it fired.
  25756. calendarCtrl.ngModelCtrl && calendarCtrl.ngModelCtrl.$render();
  25757. };
  25758. /**
  25759. * Gets the "index" of the currently selected date as it would be in the virtual-repeat.
  25760. * @returns {number}
  25761. */
  25762. CalendarMonthCtrl.prototype.getSelectedMonthIndex = function() {
  25763. var calendarCtrl = this.calendarCtrl;
  25764. return this.dateUtil.getMonthDistance(
  25765. calendarCtrl.firstRenderableDate,
  25766. calendarCtrl.displayDate || calendarCtrl.selectedDate || calendarCtrl.today
  25767. );
  25768. };
  25769. /**
  25770. * Change the date that is being shown in the calendar. If the given date is in a different
  25771. * month, the displayed month will be transitioned.
  25772. * @param {Date} date
  25773. */
  25774. CalendarMonthCtrl.prototype.changeDisplayDate = function(date) {
  25775. // Initialization is deferred until this function is called because we want to reflect
  25776. // the starting value of ngModel.
  25777. if (!this.isInitialized) {
  25778. this.buildWeekHeader();
  25779. this.calendarCtrl.hideVerticalScrollbar(this);
  25780. this.isInitialized = true;
  25781. return this.$q.when();
  25782. }
  25783. // If trying to show an invalid date or a transition is in progress, do nothing.
  25784. if (!this.dateUtil.isValidDate(date) || this.isMonthTransitionInProgress) {
  25785. return this.$q.when();
  25786. }
  25787. this.isMonthTransitionInProgress = true;
  25788. var animationPromise = this.animateDateChange(date);
  25789. this.calendarCtrl.displayDate = date;
  25790. var self = this;
  25791. animationPromise.then(function() {
  25792. self.isMonthTransitionInProgress = false;
  25793. });
  25794. return animationPromise;
  25795. };
  25796. /**
  25797. * Animates the transition from the calendar's current month to the given month.
  25798. * @param {Date} date
  25799. * @returns {angular.$q.Promise} The animation promise.
  25800. */
  25801. CalendarMonthCtrl.prototype.animateDateChange = function(date) {
  25802. if (this.dateUtil.isValidDate(date)) {
  25803. var monthDistance = this.dateUtil.getMonthDistance(this.calendarCtrl.firstRenderableDate, date);
  25804. this.calendarScroller.scrollTop = monthDistance * TBODY_HEIGHT;
  25805. }
  25806. return this.$q.when();
  25807. };
  25808. /**
  25809. * Builds and appends a day-of-the-week header to the calendar.
  25810. * This should only need to be called once during initialization.
  25811. */
  25812. CalendarMonthCtrl.prototype.buildWeekHeader = function() {
  25813. var firstDayOfWeek = this.dateLocale.firstDayOfWeek;
  25814. var shortDays = this.dateLocale.shortDays;
  25815. var row = document.createElement('tr');
  25816. for (var i = 0; i < 7; i++) {
  25817. var th = document.createElement('th');
  25818. th.textContent = shortDays[(i + firstDayOfWeek) % 7];
  25819. row.appendChild(th);
  25820. }
  25821. this.$element.find('thead').append(row);
  25822. };
  25823. /**
  25824. * Attaches listeners for the scope events that are broadcast by the calendar.
  25825. */
  25826. CalendarMonthCtrl.prototype.attachScopeListeners = function() {
  25827. var self = this;
  25828. self.$scope.$on('md-calendar-parent-changed', function(event, value) {
  25829. self.calendarCtrl.changeSelectedDate(value);
  25830. self.changeDisplayDate(value);
  25831. });
  25832. self.$scope.$on('md-calendar-parent-action', angular.bind(this, this.handleKeyEvent));
  25833. };
  25834. /**
  25835. * Handles the month-specific keyboard interactions.
  25836. * @param {Object} event Scope event object passed by the calendar.
  25837. * @param {String} action Action, corresponding to the key that was pressed.
  25838. */
  25839. CalendarMonthCtrl.prototype.handleKeyEvent = function(event, action) {
  25840. var calendarCtrl = this.calendarCtrl;
  25841. var displayDate = calendarCtrl.displayDate;
  25842. if (action === 'select') {
  25843. calendarCtrl.setNgModelValue(displayDate);
  25844. } else {
  25845. var date = null;
  25846. var dateUtil = this.dateUtil;
  25847. switch (action) {
  25848. case 'move-right': date = dateUtil.incrementDays(displayDate, 1); break;
  25849. case 'move-left': date = dateUtil.incrementDays(displayDate, -1); break;
  25850. case 'move-page-down': date = dateUtil.incrementMonths(displayDate, 1); break;
  25851. case 'move-page-up': date = dateUtil.incrementMonths(displayDate, -1); break;
  25852. case 'move-row-down': date = dateUtil.incrementDays(displayDate, 7); break;
  25853. case 'move-row-up': date = dateUtil.incrementDays(displayDate, -7); break;
  25854. case 'start': date = dateUtil.getFirstDateOfMonth(displayDate); break;
  25855. case 'end': date = dateUtil.getLastDateOfMonth(displayDate); break;
  25856. }
  25857. if (date) {
  25858. date = this.dateUtil.clampDate(date, calendarCtrl.minDate, calendarCtrl.maxDate);
  25859. this.changeDisplayDate(date).then(function() {
  25860. calendarCtrl.focus(date);
  25861. });
  25862. }
  25863. }
  25864. };
  25865. })();
  25866. })();
  25867. (function(){
  25868. "use strict";
  25869. (function() {
  25870. 'use strict';
  25871. mdCalendarMonthBodyDirective.$inject = ["$compile", "$$mdSvgRegistry"];
  25872. CalendarMonthBodyCtrl.$inject = ["$element", "$$mdDateUtil", "$mdDateLocale"];
  25873. angular.module('material.components.datepicker')
  25874. .directive('mdCalendarMonthBody', mdCalendarMonthBodyDirective);
  25875. /**
  25876. * Private directive consumed by md-calendar-month. Having this directive lets the calender use
  25877. * md-virtual-repeat and also cleanly separates the month DOM construction functions from
  25878. * the rest of the calendar controller logic.
  25879. * @ngInject
  25880. */
  25881. function mdCalendarMonthBodyDirective($compile, $$mdSvgRegistry) {
  25882. var ARROW_ICON = $compile('<md-icon md-svg-src="' +
  25883. $$mdSvgRegistry.mdTabsArrow + '"></md-icon>')({})[0];
  25884. return {
  25885. require: ['^^mdCalendar', '^^mdCalendarMonth', 'mdCalendarMonthBody'],
  25886. scope: { offset: '=mdMonthOffset' },
  25887. controller: CalendarMonthBodyCtrl,
  25888. controllerAs: 'mdMonthBodyCtrl',
  25889. bindToController: true,
  25890. link: function(scope, element, attrs, controllers) {
  25891. var calendarCtrl = controllers[0];
  25892. var monthCtrl = controllers[1];
  25893. var monthBodyCtrl = controllers[2];
  25894. monthBodyCtrl.calendarCtrl = calendarCtrl;
  25895. monthBodyCtrl.monthCtrl = monthCtrl;
  25896. monthBodyCtrl.arrowIcon = ARROW_ICON.cloneNode(true);
  25897. // The virtual-repeat re-uses the same DOM elements, so there are only a limited number
  25898. // of repeated items that are linked, and then those elements have their bindings updated.
  25899. // Since the months are not generated by bindings, we simply regenerate the entire thing
  25900. // when the binding (offset) changes.
  25901. scope.$watch(function() { return monthBodyCtrl.offset; }, function(offset) {
  25902. if (angular.isNumber(offset)) {
  25903. monthBodyCtrl.generateContent();
  25904. }
  25905. });
  25906. }
  25907. };
  25908. }
  25909. /**
  25910. * Controller for a single calendar month.
  25911. * @ngInject @constructor
  25912. */
  25913. function CalendarMonthBodyCtrl($element, $$mdDateUtil, $mdDateLocale) {
  25914. /** @final {!angular.JQLite} */
  25915. this.$element = $element;
  25916. /** @final */
  25917. this.dateUtil = $$mdDateUtil;
  25918. /** @final */
  25919. this.dateLocale = $mdDateLocale;
  25920. /** @type {Object} Reference to the month view. */
  25921. this.monthCtrl = null;
  25922. /** @type {Object} Reference to the calendar. */
  25923. this.calendarCtrl = null;
  25924. /**
  25925. * Number of months from the start of the month "items" that the currently rendered month
  25926. * occurs. Set via angular data binding.
  25927. * @type {number}
  25928. */
  25929. this.offset = null;
  25930. /**
  25931. * Date cell to focus after appending the month to the document.
  25932. * @type {HTMLElement}
  25933. */
  25934. this.focusAfterAppend = null;
  25935. }
  25936. /** Generate and append the content for this month to the directive element. */
  25937. CalendarMonthBodyCtrl.prototype.generateContent = function() {
  25938. var date = this.dateUtil.incrementMonths(this.calendarCtrl.firstRenderableDate, this.offset);
  25939. this.$element
  25940. .empty()
  25941. .append(this.buildCalendarForMonth(date));
  25942. if (this.focusAfterAppend) {
  25943. this.focusAfterAppend.classList.add(this.calendarCtrl.FOCUSED_DATE_CLASS);
  25944. this.focusAfterAppend.focus();
  25945. this.focusAfterAppend = null;
  25946. }
  25947. };
  25948. /**
  25949. * Creates a single cell to contain a date in the calendar with all appropriate
  25950. * attributes and classes added. If a date is given, the cell content will be set
  25951. * based on the date.
  25952. * @param {Date=} opt_date
  25953. * @returns {HTMLElement}
  25954. */
  25955. CalendarMonthBodyCtrl.prototype.buildDateCell = function(opt_date) {
  25956. var monthCtrl = this.monthCtrl;
  25957. var calendarCtrl = this.calendarCtrl;
  25958. // TODO(jelbourn): cloneNode is likely a faster way of doing this.
  25959. var cell = document.createElement('td');
  25960. cell.tabIndex = -1;
  25961. cell.classList.add('md-calendar-date');
  25962. cell.setAttribute('role', 'gridcell');
  25963. if (opt_date) {
  25964. cell.setAttribute('tabindex', '-1');
  25965. cell.setAttribute('aria-label', this.dateLocale.longDateFormatter(opt_date));
  25966. cell.id = calendarCtrl.getDateId(opt_date, 'month');
  25967. // Use `data-timestamp` attribute because IE10 does not support the `dataset` property.
  25968. cell.setAttribute('data-timestamp', opt_date.getTime());
  25969. // TODO(jelourn): Doing these comparisons for class addition during generation might be slow.
  25970. // It may be better to finish the construction and then query the node and add the class.
  25971. if (this.dateUtil.isSameDay(opt_date, calendarCtrl.today)) {
  25972. cell.classList.add(calendarCtrl.TODAY_CLASS);
  25973. }
  25974. if (this.dateUtil.isValidDate(calendarCtrl.selectedDate) &&
  25975. this.dateUtil.isSameDay(opt_date, calendarCtrl.selectedDate)) {
  25976. cell.classList.add(calendarCtrl.SELECTED_DATE_CLASS);
  25977. cell.setAttribute('aria-selected', 'true');
  25978. }
  25979. var cellText = this.dateLocale.dates[opt_date.getDate()];
  25980. if (this.isDateEnabled(opt_date)) {
  25981. // Add a indicator for select, hover, and focus states.
  25982. var selectionIndicator = document.createElement('span');
  25983. selectionIndicator.classList.add('md-calendar-date-selection-indicator');
  25984. selectionIndicator.textContent = cellText;
  25985. cell.appendChild(selectionIndicator);
  25986. cell.addEventListener('click', monthCtrl.cellClickHandler);
  25987. if (calendarCtrl.displayDate && this.dateUtil.isSameDay(opt_date, calendarCtrl.displayDate)) {
  25988. this.focusAfterAppend = cell;
  25989. }
  25990. } else {
  25991. cell.classList.add('md-calendar-date-disabled');
  25992. cell.textContent = cellText;
  25993. }
  25994. }
  25995. return cell;
  25996. };
  25997. /**
  25998. * Check whether date is in range and enabled
  25999. * @param {Date=} opt_date
  26000. * @return {boolean} Whether the date is enabled.
  26001. */
  26002. CalendarMonthBodyCtrl.prototype.isDateEnabled = function(opt_date) {
  26003. return this.dateUtil.isDateWithinRange(opt_date,
  26004. this.calendarCtrl.minDate, this.calendarCtrl.maxDate) &&
  26005. (!angular.isFunction(this.calendarCtrl.dateFilter)
  26006. || this.calendarCtrl.dateFilter(opt_date));
  26007. };
  26008. /**
  26009. * Builds a `tr` element for the calendar grid.
  26010. * @param rowNumber The week number within the month.
  26011. * @returns {HTMLElement}
  26012. */
  26013. CalendarMonthBodyCtrl.prototype.buildDateRow = function(rowNumber) {
  26014. var row = document.createElement('tr');
  26015. row.setAttribute('role', 'row');
  26016. // Because of an NVDA bug (with Firefox), the row needs an aria-label in order
  26017. // to prevent the entire row being read aloud when the user moves between rows.
  26018. // See http://community.nvda-project.org/ticket/4643.
  26019. row.setAttribute('aria-label', this.dateLocale.weekNumberFormatter(rowNumber));
  26020. return row;
  26021. };
  26022. /**
  26023. * Builds the <tbody> content for the given date's month.
  26024. * @param {Date=} opt_dateInMonth
  26025. * @returns {DocumentFragment} A document fragment containing the <tr> elements.
  26026. */
  26027. CalendarMonthBodyCtrl.prototype.buildCalendarForMonth = function(opt_dateInMonth) {
  26028. var date = this.dateUtil.isValidDate(opt_dateInMonth) ? opt_dateInMonth : new Date();
  26029. var firstDayOfMonth = this.dateUtil.getFirstDateOfMonth(date);
  26030. var firstDayOfTheWeek = this.getLocaleDay_(firstDayOfMonth);
  26031. var numberOfDaysInMonth = this.dateUtil.getNumberOfDaysInMonth(date);
  26032. // Store rows for the month in a document fragment so that we can append them all at once.
  26033. var monthBody = document.createDocumentFragment();
  26034. var rowNumber = 1;
  26035. var row = this.buildDateRow(rowNumber);
  26036. monthBody.appendChild(row);
  26037. // If this is the final month in the list of items, only the first week should render,
  26038. // so we should return immediately after the first row is complete and has been
  26039. // attached to the body.
  26040. var isFinalMonth = this.offset === this.monthCtrl.items.length - 1;
  26041. // Add a label for the month. If the month starts on a Sun/Mon/Tues, the month label
  26042. // goes on a row above the first of the month. Otherwise, the month label takes up the first
  26043. // two cells of the first row.
  26044. var blankCellOffset = 0;
  26045. var monthLabelCell = document.createElement('td');
  26046. var monthLabelCellContent = document.createElement('span');
  26047. var calendarCtrl = this.calendarCtrl;
  26048. monthLabelCellContent.textContent = this.dateLocale.monthHeaderFormatter(date);
  26049. monthLabelCell.appendChild(monthLabelCellContent);
  26050. monthLabelCell.classList.add('md-calendar-month-label');
  26051. // If the entire month is after the max date, render the label as a disabled state.
  26052. if (calendarCtrl.maxDate && firstDayOfMonth > calendarCtrl.maxDate) {
  26053. monthLabelCell.classList.add('md-calendar-month-label-disabled');
  26054. // If the user isn't supposed to be able to change views, render the
  26055. // label as usual, but disable the clicking functionality.
  26056. } else if (!calendarCtrl.mode) {
  26057. monthLabelCell.addEventListener('click', this.monthCtrl.headerClickHandler);
  26058. monthLabelCell.setAttribute('data-timestamp', firstDayOfMonth.getTime());
  26059. monthLabelCell.setAttribute('aria-label', this.dateLocale.monthFormatter(date));
  26060. monthLabelCell.classList.add('md-calendar-label-clickable');
  26061. monthLabelCell.appendChild(this.arrowIcon.cloneNode(true));
  26062. }
  26063. if (firstDayOfTheWeek <= 2) {
  26064. monthLabelCell.setAttribute('colspan', '7');
  26065. var monthLabelRow = this.buildDateRow();
  26066. monthLabelRow.appendChild(monthLabelCell);
  26067. monthBody.insertBefore(monthLabelRow, row);
  26068. if (isFinalMonth) {
  26069. return monthBody;
  26070. }
  26071. } else {
  26072. blankCellOffset = 3;
  26073. monthLabelCell.setAttribute('colspan', '3');
  26074. row.appendChild(monthLabelCell);
  26075. }
  26076. // Add a blank cell for each day of the week that occurs before the first of the month.
  26077. // For example, if the first day of the month is a Tuesday, add blank cells for Sun and Mon.
  26078. // The blankCellOffset is needed in cases where the first N cells are used by the month label.
  26079. for (var i = blankCellOffset; i < firstDayOfTheWeek; i++) {
  26080. row.appendChild(this.buildDateCell());
  26081. }
  26082. // Add a cell for each day of the month, keeping track of the day of the week so that
  26083. // we know when to start a new row.
  26084. var dayOfWeek = firstDayOfTheWeek;
  26085. var iterationDate = firstDayOfMonth;
  26086. for (var d = 1; d <= numberOfDaysInMonth; d++) {
  26087. // If we've reached the end of the week, start a new row.
  26088. if (dayOfWeek === 7) {
  26089. // We've finished the first row, so we're done if this is the final month.
  26090. if (isFinalMonth) {
  26091. return monthBody;
  26092. }
  26093. dayOfWeek = 0;
  26094. rowNumber++;
  26095. row = this.buildDateRow(rowNumber);
  26096. monthBody.appendChild(row);
  26097. }
  26098. iterationDate.setDate(d);
  26099. var cell = this.buildDateCell(iterationDate);
  26100. row.appendChild(cell);
  26101. dayOfWeek++;
  26102. }
  26103. // Ensure that the last row of the month has 7 cells.
  26104. while (row.childNodes.length < 7) {
  26105. row.appendChild(this.buildDateCell());
  26106. }
  26107. // Ensure that all months have 6 rows. This is necessary for now because the virtual-repeat
  26108. // requires that all items have exactly the same height.
  26109. while (monthBody.childNodes.length < 6) {
  26110. var whitespaceRow = this.buildDateRow();
  26111. for (var j = 0; j < 7; j++) {
  26112. whitespaceRow.appendChild(this.buildDateCell());
  26113. }
  26114. monthBody.appendChild(whitespaceRow);
  26115. }
  26116. return monthBody;
  26117. };
  26118. /**
  26119. * Gets the day-of-the-week index for a date for the current locale.
  26120. * @private
  26121. * @param {Date} date
  26122. * @returns {number} The column index of the date in the calendar.
  26123. */
  26124. CalendarMonthBodyCtrl.prototype.getLocaleDay_ = function(date) {
  26125. return (date.getDay() + (7 - this.dateLocale.firstDayOfWeek)) % 7;
  26126. };
  26127. })();
  26128. })();
  26129. (function(){
  26130. "use strict";
  26131. (function() {
  26132. 'use strict';
  26133. CalendarYearCtrl.$inject = ["$element", "$scope", "$animate", "$q", "$$mdDateUtil", "$mdUtil"];
  26134. angular.module('material.components.datepicker')
  26135. .directive('mdCalendarYear', calendarDirective);
  26136. /**
  26137. * Height of one calendar year tbody. This must be made known to the virtual-repeat and is
  26138. * subsequently used for scrolling to specific years.
  26139. */
  26140. var TBODY_HEIGHT = 88;
  26141. /** Private component, representing a list of years in the calendar. */
  26142. function calendarDirective() {
  26143. return {
  26144. template:
  26145. '<div class="md-calendar-scroll-mask">' +
  26146. '<md-virtual-repeat-container class="md-calendar-scroll-container">' +
  26147. '<table role="grid" tabindex="0" class="md-calendar" aria-readonly="true">' +
  26148. '<tbody ' +
  26149. 'md-calendar-year-body ' +
  26150. 'role="rowgroup" ' +
  26151. 'md-virtual-repeat="i in yearCtrl.items" ' +
  26152. 'md-year-offset="$index" class="md-calendar-year" ' +
  26153. 'md-start-index="yearCtrl.getFocusedYearIndex()" ' +
  26154. 'md-item-size="' + TBODY_HEIGHT + '">' +
  26155. // The <tr> ensures that the <tbody> will have the proper
  26156. // height, even though it may be empty.
  26157. '<tr aria-hidden="true" md-force-height="\'' + TBODY_HEIGHT + 'px\'"></tr>' +
  26158. '</tbody>' +
  26159. '</table>' +
  26160. '</md-virtual-repeat-container>' +
  26161. '</div>',
  26162. require: ['^^mdCalendar', 'mdCalendarYear'],
  26163. controller: CalendarYearCtrl,
  26164. controllerAs: 'yearCtrl',
  26165. bindToController: true,
  26166. link: function(scope, element, attrs, controllers) {
  26167. var calendarCtrl = controllers[0];
  26168. var yearCtrl = controllers[1];
  26169. yearCtrl.initialize(calendarCtrl);
  26170. }
  26171. };
  26172. }
  26173. /**
  26174. * Controller for the mdCalendar component.
  26175. * @ngInject @constructor
  26176. */
  26177. function CalendarYearCtrl($element, $scope, $animate, $q,
  26178. $$mdDateUtil, $mdUtil) {
  26179. /** @final {!angular.JQLite} */
  26180. this.$element = $element;
  26181. /** @final {!angular.Scope} */
  26182. this.$scope = $scope;
  26183. /** @final {!angular.$animate} */
  26184. this.$animate = $animate;
  26185. /** @final {!angular.$q} */
  26186. this.$q = $q;
  26187. /** @final */
  26188. this.dateUtil = $$mdDateUtil;
  26189. /** @final {HTMLElement} */
  26190. this.calendarScroller = $element[0].querySelector('.md-virtual-repeat-scroller');
  26191. /** @type {boolean} */
  26192. this.isInitialized = false;
  26193. /** @type {boolean} */
  26194. this.isMonthTransitionInProgress = false;
  26195. /** @final */
  26196. this.$mdUtil = $mdUtil;
  26197. var self = this;
  26198. /**
  26199. * Handles a click event on a date cell.
  26200. * Created here so that every cell can use the same function instance.
  26201. * @this {HTMLTableCellElement} The cell that was clicked.
  26202. */
  26203. this.cellClickHandler = function() {
  26204. self.onTimestampSelected($$mdDateUtil.getTimestampFromNode(this));
  26205. };
  26206. }
  26207. /**
  26208. * Initialize the controller by saving a reference to the calendar and
  26209. * setting up the object that will be iterated by the virtual repeater.
  26210. */
  26211. CalendarYearCtrl.prototype.initialize = function(calendarCtrl) {
  26212. /**
  26213. * Dummy array-like object for virtual-repeat to iterate over. The length is the total
  26214. * number of years that can be viewed. We add 1 extra in order to include the current year.
  26215. */
  26216. this.items = {
  26217. length: this.dateUtil.getYearDistance(
  26218. calendarCtrl.firstRenderableDate,
  26219. calendarCtrl.lastRenderableDate
  26220. ) + 1
  26221. };
  26222. this.calendarCtrl = calendarCtrl;
  26223. this.attachScopeListeners();
  26224. calendarCtrl.updateVirtualRepeat();
  26225. // Fire the initial render, since we might have missed it the first time it fired.
  26226. calendarCtrl.ngModelCtrl && calendarCtrl.ngModelCtrl.$render();
  26227. };
  26228. /**
  26229. * Gets the "index" of the currently selected date as it would be in the virtual-repeat.
  26230. * @returns {number}
  26231. */
  26232. CalendarYearCtrl.prototype.getFocusedYearIndex = function() {
  26233. var calendarCtrl = this.calendarCtrl;
  26234. return this.dateUtil.getYearDistance(
  26235. calendarCtrl.firstRenderableDate,
  26236. calendarCtrl.displayDate || calendarCtrl.selectedDate || calendarCtrl.today
  26237. );
  26238. };
  26239. /**
  26240. * Change the date that is highlighted in the calendar.
  26241. * @param {Date} date
  26242. */
  26243. CalendarYearCtrl.prototype.changeDate = function(date) {
  26244. // Initialization is deferred until this function is called because we want to reflect
  26245. // the starting value of ngModel.
  26246. if (!this.isInitialized) {
  26247. this.calendarCtrl.hideVerticalScrollbar(this);
  26248. this.isInitialized = true;
  26249. return this.$q.when();
  26250. } else if (this.dateUtil.isValidDate(date) && !this.isMonthTransitionInProgress) {
  26251. var self = this;
  26252. var animationPromise = this.animateDateChange(date);
  26253. self.isMonthTransitionInProgress = true;
  26254. self.calendarCtrl.displayDate = date;
  26255. return animationPromise.then(function() {
  26256. self.isMonthTransitionInProgress = false;
  26257. });
  26258. }
  26259. };
  26260. /**
  26261. * Animates the transition from the calendar's current month to the given month.
  26262. * @param {Date} date
  26263. * @returns {angular.$q.Promise} The animation promise.
  26264. */
  26265. CalendarYearCtrl.prototype.animateDateChange = function(date) {
  26266. if (this.dateUtil.isValidDate(date)) {
  26267. var monthDistance = this.dateUtil.getYearDistance(this.calendarCtrl.firstRenderableDate, date);
  26268. this.calendarScroller.scrollTop = monthDistance * TBODY_HEIGHT;
  26269. }
  26270. return this.$q.when();
  26271. };
  26272. /**
  26273. * Handles the year-view-specific keyboard interactions.
  26274. * @param {Object} event Scope event object passed by the calendar.
  26275. * @param {String} action Action, corresponding to the key that was pressed.
  26276. */
  26277. CalendarYearCtrl.prototype.handleKeyEvent = function(event, action) {
  26278. var self = this;
  26279. var calendarCtrl = self.calendarCtrl;
  26280. var displayDate = calendarCtrl.displayDate;
  26281. if (action === 'select') {
  26282. self.changeDate(displayDate).then(function() {
  26283. self.onTimestampSelected(displayDate);
  26284. });
  26285. } else {
  26286. var date = null;
  26287. var dateUtil = self.dateUtil;
  26288. switch (action) {
  26289. case 'move-right': date = dateUtil.incrementMonths(displayDate, 1); break;
  26290. case 'move-left': date = dateUtil.incrementMonths(displayDate, -1); break;
  26291. case 'move-row-down': date = dateUtil.incrementMonths(displayDate, 6); break;
  26292. case 'move-row-up': date = dateUtil.incrementMonths(displayDate, -6); break;
  26293. }
  26294. if (date) {
  26295. var min = calendarCtrl.minDate ? dateUtil.getFirstDateOfMonth(calendarCtrl.minDate) : null;
  26296. var max = calendarCtrl.maxDate ? dateUtil.getFirstDateOfMonth(calendarCtrl.maxDate) : null;
  26297. date = dateUtil.getFirstDateOfMonth(self.dateUtil.clampDate(date, min, max));
  26298. self.changeDate(date).then(function() {
  26299. calendarCtrl.focus(date);
  26300. });
  26301. }
  26302. }
  26303. };
  26304. /**
  26305. * Attaches listeners for the scope events that are broadcast by the calendar.
  26306. */
  26307. CalendarYearCtrl.prototype.attachScopeListeners = function() {
  26308. var self = this;
  26309. self.$scope.$on('md-calendar-parent-changed', function(event, value) {
  26310. self.calendarCtrl.changeSelectedDate(value ? self.dateUtil.getFirstDateOfMonth(value) : value);
  26311. self.changeDate(value);
  26312. });
  26313. self.$scope.$on('md-calendar-parent-action', angular.bind(self, self.handleKeyEvent));
  26314. };
  26315. /**
  26316. * Handles the behavior when a date is selected. Depending on the `mode`
  26317. * of the calendar, this can either switch back to the calendar view or
  26318. * set the model value.
  26319. * @param {number} timestamp The selected timestamp.
  26320. */
  26321. CalendarYearCtrl.prototype.onTimestampSelected = function(timestamp) {
  26322. var calendarCtrl = this.calendarCtrl;
  26323. if (calendarCtrl.mode) {
  26324. this.$mdUtil.nextTick(function() {
  26325. calendarCtrl.setNgModelValue(timestamp);
  26326. });
  26327. } else {
  26328. calendarCtrl.setCurrentView('month', timestamp);
  26329. }
  26330. };
  26331. })();
  26332. })();
  26333. (function(){
  26334. "use strict";
  26335. (function() {
  26336. 'use strict';
  26337. CalendarYearBodyCtrl.$inject = ["$element", "$$mdDateUtil", "$mdDateLocale"];
  26338. angular.module('material.components.datepicker')
  26339. .directive('mdCalendarYearBody', mdCalendarYearDirective);
  26340. /**
  26341. * Private component, consumed by the md-calendar-year, which separates the DOM construction logic
  26342. * and allows for the year view to use md-virtual-repeat.
  26343. */
  26344. function mdCalendarYearDirective() {
  26345. return {
  26346. require: ['^^mdCalendar', '^^mdCalendarYear', 'mdCalendarYearBody'],
  26347. scope: { offset: '=mdYearOffset' },
  26348. controller: CalendarYearBodyCtrl,
  26349. controllerAs: 'mdYearBodyCtrl',
  26350. bindToController: true,
  26351. link: function(scope, element, attrs, controllers) {
  26352. var calendarCtrl = controllers[0];
  26353. var yearCtrl = controllers[1];
  26354. var yearBodyCtrl = controllers[2];
  26355. yearBodyCtrl.calendarCtrl = calendarCtrl;
  26356. yearBodyCtrl.yearCtrl = yearCtrl;
  26357. scope.$watch(function() { return yearBodyCtrl.offset; }, function(offset) {
  26358. if (angular.isNumber(offset)) {
  26359. yearBodyCtrl.generateContent();
  26360. }
  26361. });
  26362. }
  26363. };
  26364. }
  26365. /**
  26366. * Controller for a single year.
  26367. * @ngInject @constructor
  26368. */
  26369. function CalendarYearBodyCtrl($element, $$mdDateUtil, $mdDateLocale) {
  26370. /** @final {!angular.JQLite} */
  26371. this.$element = $element;
  26372. /** @final */
  26373. this.dateUtil = $$mdDateUtil;
  26374. /** @final */
  26375. this.dateLocale = $mdDateLocale;
  26376. /** @type {Object} Reference to the calendar. */
  26377. this.calendarCtrl = null;
  26378. /** @type {Object} Reference to the year view. */
  26379. this.yearCtrl = null;
  26380. /**
  26381. * Number of months from the start of the month "items" that the currently rendered month
  26382. * occurs. Set via angular data binding.
  26383. * @type {number}
  26384. */
  26385. this.offset = null;
  26386. /**
  26387. * Date cell to focus after appending the month to the document.
  26388. * @type {HTMLElement}
  26389. */
  26390. this.focusAfterAppend = null;
  26391. }
  26392. /** Generate and append the content for this year to the directive element. */
  26393. CalendarYearBodyCtrl.prototype.generateContent = function() {
  26394. var date = this.dateUtil.incrementYears(this.calendarCtrl.firstRenderableDate, this.offset);
  26395. this.$element
  26396. .empty()
  26397. .append(this.buildCalendarForYear(date));
  26398. if (this.focusAfterAppend) {
  26399. this.focusAfterAppend.classList.add(this.calendarCtrl.FOCUSED_DATE_CLASS);
  26400. this.focusAfterAppend.focus();
  26401. this.focusAfterAppend = null;
  26402. }
  26403. };
  26404. /**
  26405. * Creates a single cell to contain a year in the calendar.
  26406. * @param {number} opt_year Four-digit year.
  26407. * @param {number} opt_month Zero-indexed month.
  26408. * @returns {HTMLElement}
  26409. */
  26410. CalendarYearBodyCtrl.prototype.buildMonthCell = function(year, month) {
  26411. var calendarCtrl = this.calendarCtrl;
  26412. var yearCtrl = this.yearCtrl;
  26413. var cell = this.buildBlankCell();
  26414. // Represent this month/year as a date.
  26415. var firstOfMonth = new Date(year, month, 1);
  26416. cell.setAttribute('aria-label', this.dateLocale.monthFormatter(firstOfMonth));
  26417. cell.id = calendarCtrl.getDateId(firstOfMonth, 'year');
  26418. // Use `data-timestamp` attribute because IE10 does not support the `dataset` property.
  26419. cell.setAttribute('data-timestamp', firstOfMonth.getTime());
  26420. if (this.dateUtil.isSameMonthAndYear(firstOfMonth, calendarCtrl.today)) {
  26421. cell.classList.add(calendarCtrl.TODAY_CLASS);
  26422. }
  26423. if (this.dateUtil.isValidDate(calendarCtrl.selectedDate) &&
  26424. this.dateUtil.isSameMonthAndYear(firstOfMonth, calendarCtrl.selectedDate)) {
  26425. cell.classList.add(calendarCtrl.SELECTED_DATE_CLASS);
  26426. cell.setAttribute('aria-selected', 'true');
  26427. }
  26428. var cellText = this.dateLocale.shortMonths[month];
  26429. if (this.dateUtil.isMonthWithinRange(firstOfMonth,
  26430. calendarCtrl.minDate, calendarCtrl.maxDate)) {
  26431. var selectionIndicator = document.createElement('span');
  26432. selectionIndicator.classList.add('md-calendar-date-selection-indicator');
  26433. selectionIndicator.textContent = cellText;
  26434. cell.appendChild(selectionIndicator);
  26435. cell.addEventListener('click', yearCtrl.cellClickHandler);
  26436. if (calendarCtrl.displayDate && this.dateUtil.isSameMonthAndYear(firstOfMonth, calendarCtrl.displayDate)) {
  26437. this.focusAfterAppend = cell;
  26438. }
  26439. } else {
  26440. cell.classList.add('md-calendar-date-disabled');
  26441. cell.textContent = cellText;
  26442. }
  26443. return cell;
  26444. };
  26445. /**
  26446. * Builds a blank cell.
  26447. * @return {HTMLTableCellElement}
  26448. */
  26449. CalendarYearBodyCtrl.prototype.buildBlankCell = function() {
  26450. var cell = document.createElement('td');
  26451. cell.tabIndex = -1;
  26452. cell.classList.add('md-calendar-date');
  26453. cell.setAttribute('role', 'gridcell');
  26454. cell.setAttribute('tabindex', '-1');
  26455. return cell;
  26456. };
  26457. /**
  26458. * Builds the <tbody> content for the given year.
  26459. * @param {Date} date Date for which the content should be built.
  26460. * @returns {DocumentFragment} A document fragment containing the months within the year.
  26461. */
  26462. CalendarYearBodyCtrl.prototype.buildCalendarForYear = function(date) {
  26463. // Store rows for the month in a document fragment so that we can append them all at once.
  26464. var year = date.getFullYear();
  26465. var yearBody = document.createDocumentFragment();
  26466. var monthCell, i;
  26467. // First row contains label and Jan-Jun.
  26468. var firstRow = document.createElement('tr');
  26469. var labelCell = document.createElement('td');
  26470. labelCell.className = 'md-calendar-month-label';
  26471. labelCell.textContent = year;
  26472. firstRow.appendChild(labelCell);
  26473. for (i = 0; i < 6; i++) {
  26474. firstRow.appendChild(this.buildMonthCell(year, i));
  26475. }
  26476. yearBody.appendChild(firstRow);
  26477. // Second row contains a blank cell and Jul-Dec.
  26478. var secondRow = document.createElement('tr');
  26479. secondRow.appendChild(this.buildBlankCell());
  26480. for (i = 6; i < 12; i++) {
  26481. secondRow.appendChild(this.buildMonthCell(year, i));
  26482. }
  26483. yearBody.appendChild(secondRow);
  26484. return yearBody;
  26485. };
  26486. })();
  26487. })();
  26488. (function(){
  26489. "use strict";
  26490. (function() {
  26491. 'use strict';
  26492. /**
  26493. * @ngdoc service
  26494. * @name $mdDateLocaleProvider
  26495. * @module material.components.datepicker
  26496. *
  26497. * @description
  26498. * The `$mdDateLocaleProvider` is the provider that creates the `$mdDateLocale` service.
  26499. * This provider that allows the user to specify messages, formatters, and parsers for date
  26500. * internationalization. The `$mdDateLocale` service itself is consumed by AngularJS Material
  26501. * components that deal with dates.
  26502. *
  26503. * @property {(Array<string>)=} months Array of month names (in order).
  26504. * @property {(Array<string>)=} shortMonths Array of abbreviated month names.
  26505. * @property {(Array<string>)=} days Array of the days of the week (in order).
  26506. * @property {(Array<string>)=} shortDays Array of abbreviated days of the week.
  26507. * @property {(Array<string>)=} dates Array of dates of the month. Only necessary for locales
  26508. * using a numeral system other than [1, 2, 3...].
  26509. * @property {(Array<string>)=} firstDayOfWeek The first day of the week. Sunday = 0, Monday = 1,
  26510. * etc.
  26511. * @property {(function(string): Date)=} parseDate Function to parse a date object from a string.
  26512. * @property {(function(Date, string): string)=} formatDate Function to format a date object to a
  26513. * string. The datepicker directive also provides the time zone, if it was specified.
  26514. * @property {(function(Date): string)=} monthHeaderFormatter Function that returns the label for
  26515. * a month given a date.
  26516. * @property {(function(Date): string)=} monthFormatter Function that returns the full name of a month
  26517. * for a given date.
  26518. * @property {(function(number): string)=} weekNumberFormatter Function that returns a label for
  26519. * a week given the week number.
  26520. * @property {(string)=} msgCalendar Translation of the label "Calendar" for the current locale.
  26521. * @property {(string)=} msgOpenCalendar Translation of the button label "Open calendar" for the
  26522. * current locale.
  26523. * @property {Date=} firstRenderableDate The date from which the datepicker calendar will begin
  26524. * rendering. Note that this will be ignored if a minimum date is set. Defaults to January 1st 1880.
  26525. * @property {Date=} lastRenderableDate The last date that will be rendered by the datepicker
  26526. * calendar. Note that this will be ignored if a maximum date is set. Defaults to January 1st 2130.
  26527. *
  26528. * @usage
  26529. * <hljs lang="js">
  26530. * myAppModule.config(function($mdDateLocaleProvider) {
  26531. *
  26532. * // Example of a French localization.
  26533. * $mdDateLocaleProvider.months = ['janvier', 'février', 'mars', ...];
  26534. * $mdDateLocaleProvider.shortMonths = ['janv', 'févr', 'mars', ...];
  26535. * $mdDateLocaleProvider.days = ['dimanche', 'lundi', 'mardi', ...];
  26536. * $mdDateLocaleProvider.shortDays = ['Di', 'Lu', 'Ma', ...];
  26537. *
  26538. * // Can change week display to start on Monday.
  26539. * $mdDateLocaleProvider.firstDayOfWeek = 1;
  26540. *
  26541. * // Optional.
  26542. * $mdDateLocaleProvider.dates = [1, 2, 3, 4, 5, 6, ...];
  26543. *
  26544. * // Example uses moment.js to parse and format dates.
  26545. * $mdDateLocaleProvider.parseDate = function(dateString) {
  26546. * var m = moment(dateString, 'L', true);
  26547. * return m.isValid() ? m.toDate() : new Date(NaN);
  26548. * };
  26549. *
  26550. * $mdDateLocaleProvider.formatDate = function(date) {
  26551. * var m = moment(date);
  26552. * return m.isValid() ? m.format('L') : '';
  26553. * };
  26554. *
  26555. * $mdDateLocaleProvider.monthHeaderFormatter = function(date) {
  26556. * return myShortMonths[date.getMonth()] + ' ' + date.getFullYear();
  26557. * };
  26558. *
  26559. * // In addition to date display, date components also need localized messages
  26560. * // for aria-labels for screen-reader users.
  26561. *
  26562. * $mdDateLocaleProvider.weekNumberFormatter = function(weekNumber) {
  26563. * return 'Semaine ' + weekNumber;
  26564. * };
  26565. *
  26566. * $mdDateLocaleProvider.msgCalendar = 'Calendrier';
  26567. * $mdDateLocaleProvider.msgOpenCalendar = 'Ouvrir le calendrier';
  26568. *
  26569. * // You can also set when your calendar begins and ends.
  26570. * $mdDateLocaleProvider.firstRenderableDate = new Date(1776, 6, 4);
  26571. * $mdDateLocaleProvider.lastRenderableDate = new Date(2012, 11, 21);
  26572. * });
  26573. * </hljs>
  26574. *
  26575. */
  26576. angular.module('material.components.datepicker').config(["$provide", function($provide) {
  26577. // TODO(jelbourn): Assert provided values are correctly formatted. Need assertions.
  26578. /** @constructor */
  26579. function DateLocaleProvider() {
  26580. /** Array of full month names. E.g., ['January', 'Febuary', ...] */
  26581. this.months = null;
  26582. /** Array of abbreviated month names. E.g., ['Jan', 'Feb', ...] */
  26583. this.shortMonths = null;
  26584. /** Array of full day of the week names. E.g., ['Monday', 'Tuesday', ...] */
  26585. this.days = null;
  26586. /** Array of abbreviated dat of the week names. E.g., ['M', 'T', ...] */
  26587. this.shortDays = null;
  26588. /** Array of dates of a month (1 - 31). Characters might be different in some locales. */
  26589. this.dates = null;
  26590. /** Index of the first day of the week. 0 = Sunday, 1 = Monday, etc. */
  26591. this.firstDayOfWeek = 0;
  26592. /**
  26593. * Function that converts the date portion of a Date to a string.
  26594. * @type {(function(Date): string)}
  26595. */
  26596. this.formatDate = null;
  26597. /**
  26598. * Function that converts a date string to a Date object (the date portion)
  26599. * @type {function(string): Date}
  26600. */
  26601. this.parseDate = null;
  26602. /**
  26603. * Function that formats a Date into a month header string.
  26604. * @type {function(Date): string}
  26605. */
  26606. this.monthHeaderFormatter = null;
  26607. /**
  26608. * Function that formats a week number into a label for the week.
  26609. * @type {function(number): string}
  26610. */
  26611. this.weekNumberFormatter = null;
  26612. /**
  26613. * Function that formats a date into a long aria-label that is read
  26614. * when the focused date changes.
  26615. * @type {function(Date): string}
  26616. */
  26617. this.longDateFormatter = null;
  26618. /**
  26619. * ARIA label for the calendar "dialog" used in the datepicker.
  26620. * @type {string}
  26621. */
  26622. this.msgCalendar = '';
  26623. /**
  26624. * ARIA label for the datepicker's "Open calendar" buttons.
  26625. * @type {string}
  26626. */
  26627. this.msgOpenCalendar = '';
  26628. }
  26629. /**
  26630. * Factory function that returns an instance of the dateLocale service.
  26631. * @ngInject
  26632. * @param $locale
  26633. * @returns {DateLocale}
  26634. */
  26635. DateLocaleProvider.prototype.$get = function($locale, $filter) {
  26636. /**
  26637. * Default date-to-string formatting function.
  26638. * @param {!Date} date
  26639. * @param {string=} timezone
  26640. * @returns {string}
  26641. */
  26642. function defaultFormatDate(date, timezone) {
  26643. if (!date) {
  26644. return '';
  26645. }
  26646. // All of the dates created through ng-material *should* be set to midnight.
  26647. // If we encounter a date where the localeTime shows at 11pm instead of midnight,
  26648. // we have run into an issue with DST where we need to increment the hour by one:
  26649. // var d = new Date(1992, 9, 8, 0, 0, 0);
  26650. // d.toLocaleString(); // == "10/7/1992, 11:00:00 PM"
  26651. var localeTime = date.toLocaleTimeString();
  26652. var formatDate = date;
  26653. if (date.getHours() === 0 &&
  26654. (localeTime.indexOf('11:') !== -1 || localeTime.indexOf('23:') !== -1)) {
  26655. formatDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 1, 0, 0);
  26656. }
  26657. return $filter('date')(formatDate, 'M/d/yyyy', timezone);
  26658. }
  26659. /**
  26660. * Default string-to-date parsing function.
  26661. * @param {string} dateString
  26662. * @returns {!Date}
  26663. */
  26664. function defaultParseDate(dateString) {
  26665. return new Date(dateString);
  26666. }
  26667. /**
  26668. * Default function to determine whether a string makes sense to be
  26669. * parsed to a Date object.
  26670. *
  26671. * This is very permissive and is just a basic sanity check to ensure that
  26672. * things like single integers aren't able to be parsed into dates.
  26673. * @param {string} dateString
  26674. * @returns {boolean}
  26675. */
  26676. function defaultIsDateComplete(dateString) {
  26677. dateString = dateString.trim();
  26678. // Looks for three chunks of content (either numbers or text) separated
  26679. // by delimiters.
  26680. var re = /^(([a-zA-Z]{3,}|[0-9]{1,4})([ .,]+|[/-])){2}([a-zA-Z]{3,}|[0-9]{1,4})$/;
  26681. return re.test(dateString);
  26682. }
  26683. /**
  26684. * Default date-to-string formatter to get a month header.
  26685. * @param {!Date} date
  26686. * @returns {string}
  26687. */
  26688. function defaultMonthHeaderFormatter(date) {
  26689. return service.shortMonths[date.getMonth()] + ' ' + date.getFullYear();
  26690. }
  26691. /**
  26692. * Default formatter for a month.
  26693. * @param {!Date} date
  26694. * @returns {string}
  26695. */
  26696. function defaultMonthFormatter(date) {
  26697. return service.months[date.getMonth()] + ' ' + date.getFullYear();
  26698. }
  26699. /**
  26700. * Default week number formatter.
  26701. * @param number
  26702. * @returns {string}
  26703. */
  26704. function defaultWeekNumberFormatter(number) {
  26705. return 'Week ' + number;
  26706. }
  26707. /**
  26708. * Default formatter for date cell aria-labels.
  26709. * @param {!Date} date
  26710. * @returns {string}
  26711. */
  26712. function defaultLongDateFormatter(date) {
  26713. // Example: 'Thursday June 18 2015'
  26714. return [
  26715. service.days[date.getDay()],
  26716. service.months[date.getMonth()],
  26717. service.dates[date.getDate()],
  26718. date.getFullYear()
  26719. ].join(' ');
  26720. }
  26721. // The default "short" day strings are the first character of each day,
  26722. // e.g., "Monday" => "M".
  26723. var defaultShortDays = $locale.DATETIME_FORMATS.SHORTDAY.map(function(day) {
  26724. return day.substring(0, 1);
  26725. });
  26726. // The default dates are simply the numbers 1 through 31.
  26727. var defaultDates = Array(32);
  26728. for (var i = 1; i <= 31; i++) {
  26729. defaultDates[i] = i;
  26730. }
  26731. // Default ARIA messages are in English (US).
  26732. var defaultMsgCalendar = 'Calendar';
  26733. var defaultMsgOpenCalendar = 'Open calendar';
  26734. // Default start/end dates that are rendered in the calendar.
  26735. var defaultFirstRenderableDate = new Date(1880, 0, 1);
  26736. var defaultLastRendereableDate = new Date(defaultFirstRenderableDate.getFullYear() + 250, 0, 1);
  26737. var service = {
  26738. months: this.months || $locale.DATETIME_FORMATS.MONTH,
  26739. shortMonths: this.shortMonths || $locale.DATETIME_FORMATS.SHORTMONTH,
  26740. days: this.days || $locale.DATETIME_FORMATS.DAY,
  26741. shortDays: this.shortDays || defaultShortDays,
  26742. dates: this.dates || defaultDates,
  26743. firstDayOfWeek: this.firstDayOfWeek || 0,
  26744. formatDate: this.formatDate || defaultFormatDate,
  26745. parseDate: this.parseDate || defaultParseDate,
  26746. isDateComplete: this.isDateComplete || defaultIsDateComplete,
  26747. monthHeaderFormatter: this.monthHeaderFormatter || defaultMonthHeaderFormatter,
  26748. monthFormatter: this.monthFormatter || defaultMonthFormatter,
  26749. weekNumberFormatter: this.weekNumberFormatter || defaultWeekNumberFormatter,
  26750. longDateFormatter: this.longDateFormatter || defaultLongDateFormatter,
  26751. msgCalendar: this.msgCalendar || defaultMsgCalendar,
  26752. msgOpenCalendar: this.msgOpenCalendar || defaultMsgOpenCalendar,
  26753. firstRenderableDate: this.firstRenderableDate || defaultFirstRenderableDate,
  26754. lastRenderableDate: this.lastRenderableDate || defaultLastRendereableDate
  26755. };
  26756. return service;
  26757. };
  26758. DateLocaleProvider.prototype.$get.$inject = ["$locale", "$filter"];
  26759. $provide.provider('$mdDateLocale', new DateLocaleProvider());
  26760. }]);
  26761. })();
  26762. })();
  26763. (function(){
  26764. "use strict";
  26765. (function() {
  26766. 'use strict';
  26767. /**
  26768. * Utility for performing date calculations to facilitate operation of the calendar and
  26769. * datepicker.
  26770. */
  26771. angular.module('material.components.datepicker').factory('$$mdDateUtil', function() {
  26772. return {
  26773. getFirstDateOfMonth: getFirstDateOfMonth,
  26774. getNumberOfDaysInMonth: getNumberOfDaysInMonth,
  26775. getDateInNextMonth: getDateInNextMonth,
  26776. getDateInPreviousMonth: getDateInPreviousMonth,
  26777. isInNextMonth: isInNextMonth,
  26778. isInPreviousMonth: isInPreviousMonth,
  26779. getDateMidpoint: getDateMidpoint,
  26780. isSameMonthAndYear: isSameMonthAndYear,
  26781. getWeekOfMonth: getWeekOfMonth,
  26782. incrementDays: incrementDays,
  26783. incrementMonths: incrementMonths,
  26784. getLastDateOfMonth: getLastDateOfMonth,
  26785. isSameDay: isSameDay,
  26786. getMonthDistance: getMonthDistance,
  26787. isValidDate: isValidDate,
  26788. setDateTimeToMidnight: setDateTimeToMidnight,
  26789. createDateAtMidnight: createDateAtMidnight,
  26790. isDateWithinRange: isDateWithinRange,
  26791. incrementYears: incrementYears,
  26792. getYearDistance: getYearDistance,
  26793. clampDate: clampDate,
  26794. getTimestampFromNode: getTimestampFromNode,
  26795. isMonthWithinRange: isMonthWithinRange
  26796. };
  26797. /**
  26798. * Gets the first day of the month for the given date's month.
  26799. * @param {Date} date
  26800. * @returns {Date}
  26801. */
  26802. function getFirstDateOfMonth(date) {
  26803. return new Date(date.getFullYear(), date.getMonth(), 1);
  26804. }
  26805. /**
  26806. * Gets the number of days in the month for the given date's month.
  26807. * @param date
  26808. * @returns {number}
  26809. */
  26810. function getNumberOfDaysInMonth(date) {
  26811. return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
  26812. }
  26813. /**
  26814. * Get an arbitrary date in the month after the given date's month.
  26815. * @param date
  26816. * @returns {Date}
  26817. */
  26818. function getDateInNextMonth(date) {
  26819. return new Date(date.getFullYear(), date.getMonth() + 1, 1);
  26820. }
  26821. /**
  26822. * Get an arbitrary date in the month before the given date's month.
  26823. * @param date
  26824. * @returns {Date}
  26825. */
  26826. function getDateInPreviousMonth(date) {
  26827. return new Date(date.getFullYear(), date.getMonth() - 1, 1);
  26828. }
  26829. /**
  26830. * Gets whether two dates have the same month and year.
  26831. * @param {Date} d1
  26832. * @param {Date} d2
  26833. * @returns {boolean}
  26834. */
  26835. function isSameMonthAndYear(d1, d2) {
  26836. return d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth();
  26837. }
  26838. /**
  26839. * Gets whether two dates are the same day (not not necesarily the same time).
  26840. * @param {Date} d1
  26841. * @param {Date} d2
  26842. * @returns {boolean}
  26843. */
  26844. function isSameDay(d1, d2) {
  26845. return d1.getDate() == d2.getDate() && isSameMonthAndYear(d1, d2);
  26846. }
  26847. /**
  26848. * Gets whether a date is in the month immediately after some date.
  26849. * @param {Date} startDate The date from which to compare.
  26850. * @param {Date} endDate The date to check.
  26851. * @returns {boolean}
  26852. */
  26853. function isInNextMonth(startDate, endDate) {
  26854. var nextMonth = getDateInNextMonth(startDate);
  26855. return isSameMonthAndYear(nextMonth, endDate);
  26856. }
  26857. /**
  26858. * Gets whether a date is in the month immediately before some date.
  26859. * @param {Date} startDate The date from which to compare.
  26860. * @param {Date} endDate The date to check.
  26861. * @returns {boolean}
  26862. */
  26863. function isInPreviousMonth(startDate, endDate) {
  26864. var previousMonth = getDateInPreviousMonth(startDate);
  26865. return isSameMonthAndYear(endDate, previousMonth);
  26866. }
  26867. /**
  26868. * Gets the midpoint between two dates.
  26869. * @param {Date} d1
  26870. * @param {Date} d2
  26871. * @returns {Date}
  26872. */
  26873. function getDateMidpoint(d1, d2) {
  26874. return createDateAtMidnight((d1.getTime() + d2.getTime()) / 2);
  26875. }
  26876. /**
  26877. * Gets the week of the month that a given date occurs in.
  26878. * @param {Date} date
  26879. * @returns {number} Index of the week of the month (zero-based).
  26880. */
  26881. function getWeekOfMonth(date) {
  26882. var firstDayOfMonth = getFirstDateOfMonth(date);
  26883. return Math.floor((firstDayOfMonth.getDay() + date.getDate() - 1) / 7);
  26884. }
  26885. /**
  26886. * Gets a new date incremented by the given number of days. Number of days can be negative.
  26887. * @param {Date} date
  26888. * @param {number} numberOfDays
  26889. * @returns {Date}
  26890. */
  26891. function incrementDays(date, numberOfDays) {
  26892. return new Date(date.getFullYear(), date.getMonth(), date.getDate() + numberOfDays);
  26893. }
  26894. /**
  26895. * Gets a new date incremented by the given number of months. Number of months can be negative.
  26896. * If the date of the given month does not match the target month, the date will be set to the
  26897. * last day of the month.
  26898. * @param {Date} date
  26899. * @param {number} numberOfMonths
  26900. * @returns {Date}
  26901. */
  26902. function incrementMonths(date, numberOfMonths) {
  26903. // If the same date in the target month does not actually exist, the Date object will
  26904. // automatically advance *another* month by the number of missing days.
  26905. // For example, if you try to go from Jan. 30 to Feb. 30, you'll end up on March 2.
  26906. // So, we check if the month overflowed and go to the last day of the target month instead.
  26907. var dateInTargetMonth = new Date(date.getFullYear(), date.getMonth() + numberOfMonths, 1);
  26908. var numberOfDaysInMonth = getNumberOfDaysInMonth(dateInTargetMonth);
  26909. if (numberOfDaysInMonth < date.getDate()) {
  26910. dateInTargetMonth.setDate(numberOfDaysInMonth);
  26911. } else {
  26912. dateInTargetMonth.setDate(date.getDate());
  26913. }
  26914. return dateInTargetMonth;
  26915. }
  26916. /**
  26917. * Get the integer distance between two months. This *only* considers the month and year
  26918. * portion of the Date instances.
  26919. *
  26920. * @param {Date} start
  26921. * @param {Date} end
  26922. * @returns {number} Number of months between `start` and `end`. If `end` is before `start`
  26923. * chronologically, this number will be negative.
  26924. */
  26925. function getMonthDistance(start, end) {
  26926. return (12 * (end.getFullYear() - start.getFullYear())) + (end.getMonth() - start.getMonth());
  26927. }
  26928. /**
  26929. * Gets the last day of the month for the given date.
  26930. * @param {Date} date
  26931. * @returns {Date}
  26932. */
  26933. function getLastDateOfMonth(date) {
  26934. return new Date(date.getFullYear(), date.getMonth(), getNumberOfDaysInMonth(date));
  26935. }
  26936. /**
  26937. * Checks whether a date is valid.
  26938. * @param {Date} date
  26939. * @return {boolean} Whether the date is a valid Date.
  26940. */
  26941. function isValidDate(date) {
  26942. return date && date.getTime && !isNaN(date.getTime());
  26943. }
  26944. /**
  26945. * Sets a date's time to midnight.
  26946. * @param {Date} date
  26947. */
  26948. function setDateTimeToMidnight(date) {
  26949. if (isValidDate(date)) {
  26950. date.setHours(0, 0, 0, 0);
  26951. }
  26952. }
  26953. /**
  26954. * Creates a date with the time set to midnight.
  26955. * Drop-in replacement for two forms of the Date constructor:
  26956. * 1. No argument for Date representing now.
  26957. * 2. Single-argument value representing number of seconds since Unix Epoch
  26958. * or a Date object.
  26959. * @param {number|Date=} opt_value
  26960. * @return {Date} New date with time set to midnight.
  26961. */
  26962. function createDateAtMidnight(opt_value) {
  26963. var date;
  26964. if (angular.isUndefined(opt_value)) {
  26965. date = new Date();
  26966. } else {
  26967. date = new Date(opt_value);
  26968. }
  26969. setDateTimeToMidnight(date);
  26970. return date;
  26971. }
  26972. /**
  26973. * Checks if a date is within a min and max range, ignoring the time component.
  26974. * If minDate or maxDate are not dates, they are ignored.
  26975. * @param {Date} date
  26976. * @param {Date} minDate
  26977. * @param {Date} maxDate
  26978. */
  26979. function isDateWithinRange(date, minDate, maxDate) {
  26980. var dateAtMidnight = createDateAtMidnight(date);
  26981. var minDateAtMidnight = isValidDate(minDate) ? createDateAtMidnight(minDate) : null;
  26982. var maxDateAtMidnight = isValidDate(maxDate) ? createDateAtMidnight(maxDate) : null;
  26983. return (!minDateAtMidnight || minDateAtMidnight <= dateAtMidnight) &&
  26984. (!maxDateAtMidnight || maxDateAtMidnight >= dateAtMidnight);
  26985. }
  26986. /**
  26987. * Gets a new date incremented by the given number of years. Number of years can be negative.
  26988. * See `incrementMonths` for notes on overflow for specific dates.
  26989. * @param {Date} date
  26990. * @param {number} numberOfYears
  26991. * @returns {Date}
  26992. */
  26993. function incrementYears(date, numberOfYears) {
  26994. return incrementMonths(date, numberOfYears * 12);
  26995. }
  26996. /**
  26997. * Get the integer distance between two years. This *only* considers the year portion of the
  26998. * Date instances.
  26999. *
  27000. * @param {Date} start
  27001. * @param {Date} end
  27002. * @returns {number} Number of months between `start` and `end`. If `end` is before `start`
  27003. * chronologically, this number will be negative.
  27004. */
  27005. function getYearDistance(start, end) {
  27006. return end.getFullYear() - start.getFullYear();
  27007. }
  27008. /**
  27009. * Clamps a date between a minimum and a maximum date.
  27010. * @param {Date} date Date to be clamped
  27011. * @param {Date=} minDate Minimum date
  27012. * @param {Date=} maxDate Maximum date
  27013. * @return {Date}
  27014. */
  27015. function clampDate(date, minDate, maxDate) {
  27016. var boundDate = date;
  27017. if (minDate && date < minDate) {
  27018. boundDate = new Date(minDate.getTime());
  27019. }
  27020. if (maxDate && date > maxDate) {
  27021. boundDate = new Date(maxDate.getTime());
  27022. }
  27023. return boundDate;
  27024. }
  27025. /**
  27026. * Extracts and parses the timestamp from a DOM node.
  27027. * @param {HTMLElement} node Node from which the timestamp will be extracted.
  27028. * @return {number} Time since epoch.
  27029. */
  27030. function getTimestampFromNode(node) {
  27031. if (node && node.hasAttribute('data-timestamp')) {
  27032. return Number(node.getAttribute('data-timestamp'));
  27033. }
  27034. }
  27035. /**
  27036. * Checks if a month is within a min and max range, ignoring the date and time components.
  27037. * If minDate or maxDate are not dates, they are ignored.
  27038. * @param {Date} date
  27039. * @param {Date} minDate
  27040. * @param {Date} maxDate
  27041. */
  27042. function isMonthWithinRange(date, minDate, maxDate) {
  27043. var month = date.getMonth();
  27044. var year = date.getFullYear();
  27045. return (!minDate || minDate.getFullYear() < year || minDate.getMonth() <= month) &&
  27046. (!maxDate || maxDate.getFullYear() > year || maxDate.getMonth() >= month);
  27047. }
  27048. });
  27049. })();
  27050. })();
  27051. (function(){
  27052. "use strict";
  27053. (function() {
  27054. 'use strict';
  27055. // POST RELEASE
  27056. // TODO(jelbourn): Demo that uses moment.js
  27057. // TODO(jelbourn): make sure this plays well with validation and ngMessages.
  27058. // TODO(jelbourn): calendar pane doesn't open up outside of visible viewport.
  27059. // TODO(jelbourn): forward more attributes to the internal input (required, autofocus, etc.)
  27060. // TODO(jelbourn): something better for mobile (calendar panel takes up entire screen?)
  27061. // TODO(jelbourn): input behavior (masking? auto-complete?)
  27062. DatePickerCtrl.$inject = ["$scope", "$element", "$attrs", "$window", "$mdConstant", "$mdTheming", "$mdUtil", "$mdDateLocale", "$$mdDateUtil", "$$rAF", "$filter"];
  27063. datePickerDirective.$inject = ["$$mdSvgRegistry", "$mdUtil", "$mdAria", "inputDirective"];
  27064. angular.module('material.components.datepicker')
  27065. .directive('mdDatepicker', datePickerDirective);
  27066. /**
  27067. * @ngdoc directive
  27068. * @name mdDatepicker
  27069. * @module material.components.datepicker
  27070. *
  27071. * @param {Date} ng-model The component's model. Expects either a JavaScript Date object or a value that can be parsed into one (e.g. a ISO 8601 string).
  27072. * @param {Object=} ng-model-options Allows tuning of the way in which `ng-model` is being updated. Also allows
  27073. * for a timezone to be specified. <a href="https://docs.angularjs.org/api/ng/directive/ngModelOptions#usage">Read more at the ngModelOptions docs.</a>
  27074. * @param {expression=} ng-change Expression evaluated when the model value changes.
  27075. * @param {expression=} ng-focus Expression evaluated when the input is focused or the calendar is opened.
  27076. * @param {expression=} ng-blur Expression evaluated when focus is removed from the input or the calendar is closed.
  27077. * @param {boolean=} ng-disabled Whether the datepicker is disabled.
  27078. * @param {boolean=} ng-required Whether a value is required for the datepicker.
  27079. * @param {Date=} md-min-date Expression representing a min date (inclusive).
  27080. * @param {Date=} md-max-date Expression representing a max date (inclusive).
  27081. * @param {(function(Date): boolean)=} md-date-filter Function expecting a date and returning a boolean whether it can be selected or not.
  27082. * @param {String=} md-placeholder The date input placeholder value.
  27083. * @param {String=} md-open-on-focus When present, the calendar will be opened when the input is focused.
  27084. * @param {Boolean=} md-is-open Expression that can be used to open the datepicker's calendar on-demand.
  27085. * @param {String=} md-current-view Default open view of the calendar pane. Can be either "month" or "year".
  27086. * @param {String=} md-mode Restricts the user to only selecting a value from a particular view. This option can
  27087. * be used if the user is only supposed to choose from a certain date type (e.g. only selecting the month).
  27088. * Can be either "month" or "day". **Note** that this will ovewrite the `md-current-view` value.
  27089. *
  27090. * @param {String=} md-hide-icons Determines which datepicker icons should be hidden. Note that this may cause the
  27091. * datepicker to not align properly with other components. **Use at your own risk.** Possible values are:
  27092. * * `"all"` - Hides all icons.
  27093. * * `"calendar"` - Only hides the calendar icon.
  27094. * * `"triangle"` - Only hides the triangle icon.
  27095. * @param {Object=} md-date-locale Allows for the values from the `$mdDateLocaleProvider` to be
  27096. * ovewritten on a per-element basis (e.g. `msgOpenCalendar` can be overwritten with
  27097. * `md-date-locale="{ msgOpenCalendar: 'Open a special calendar' }"`).
  27098. *
  27099. * @description
  27100. * `<md-datepicker>` is a component used to select a single date.
  27101. * For information on how to configure internationalization for the date picker,
  27102. * see `$mdDateLocaleProvider`.
  27103. *
  27104. * This component supports [ngMessages](https://docs.angularjs.org/api/ngMessages/directive/ngMessages).
  27105. * Supported attributes are:
  27106. * * `required`: whether a required date is not set.
  27107. * * `mindate`: whether the selected date is before the minimum allowed date.
  27108. * * `maxdate`: whether the selected date is after the maximum allowed date.
  27109. * * `debounceInterval`: ms to delay input processing (since last debounce reset); default value 500ms
  27110. *
  27111. * @usage
  27112. * <hljs lang="html">
  27113. * <md-datepicker ng-model="birthday"></md-datepicker>
  27114. * </hljs>
  27115. *
  27116. */
  27117. function datePickerDirective($$mdSvgRegistry, $mdUtil, $mdAria, inputDirective) {
  27118. return {
  27119. template: function(tElement, tAttrs) {
  27120. // Buttons are not in the tab order because users can open the calendar via keyboard
  27121. // interaction on the text input, and multiple tab stops for one component (picker)
  27122. // may be confusing.
  27123. var hiddenIcons = tAttrs.mdHideIcons;
  27124. var ariaLabelValue = tAttrs.ariaLabel || tAttrs.mdPlaceholder;
  27125. var calendarButton = (hiddenIcons === 'all' || hiddenIcons === 'calendar') ? '' :
  27126. '<md-button class="md-datepicker-button md-icon-button" type="button" ' +
  27127. 'tabindex="-1" aria-hidden="true" ' +
  27128. 'ng-click="ctrl.openCalendarPane($event)">' +
  27129. '<md-icon class="md-datepicker-calendar-icon" aria-label="md-calendar" ' +
  27130. 'md-svg-src="' + $$mdSvgRegistry.mdCalendar + '"></md-icon>' +
  27131. '</md-button>';
  27132. var triangleButton = '';
  27133. if (hiddenIcons !== 'all' && hiddenIcons !== 'triangle') {
  27134. triangleButton = '' +
  27135. '<md-button type="button" md-no-ink ' +
  27136. 'class="md-datepicker-triangle-button md-icon-button" ' +
  27137. 'ng-click="ctrl.openCalendarPane($event)" ' +
  27138. 'aria-label="{{::ctrl.locale.msgOpenCalendar}}">' +
  27139. '<div class="md-datepicker-expand-triangle"></div>' +
  27140. '</md-button>';
  27141. tElement.addClass(HAS_TRIANGLE_ICON_CLASS);
  27142. }
  27143. return calendarButton +
  27144. '<div class="md-datepicker-input-container" ng-class="{\'md-datepicker-focused\': ctrl.isFocused}">' +
  27145. '<input ' +
  27146. (ariaLabelValue ? 'aria-label="' + ariaLabelValue + '" ' : '') +
  27147. 'class="md-datepicker-input" ' +
  27148. 'aria-haspopup="true" ' +
  27149. 'aria-expanded="{{ctrl.isCalendarOpen}}" ' +
  27150. 'ng-focus="ctrl.setFocused(true)" ' +
  27151. 'ng-blur="ctrl.setFocused(false)"> ' +
  27152. triangleButton +
  27153. '</div>' +
  27154. // This pane will be detached from here and re-attached to the document body.
  27155. '<div class="md-datepicker-calendar-pane md-whiteframe-z1" id="{{::ctrl.calendarPaneId}}">' +
  27156. '<div class="md-datepicker-input-mask">' +
  27157. '<div class="md-datepicker-input-mask-opaque"></div>' +
  27158. '</div>' +
  27159. '<div class="md-datepicker-calendar">' +
  27160. '<md-calendar role="dialog" aria-label="{{::ctrl.locale.msgCalendar}}" ' +
  27161. 'md-current-view="{{::ctrl.currentView}}"' +
  27162. 'md-mode="{{::ctrl.mode}}"' +
  27163. 'md-min-date="ctrl.minDate"' +
  27164. 'md-max-date="ctrl.maxDate"' +
  27165. 'md-date-filter="ctrl.dateFilter"' +
  27166. 'ng-model="ctrl.date" ng-if="ctrl.isCalendarOpen">' +
  27167. '</md-calendar>' +
  27168. '</div>' +
  27169. '</div>';
  27170. },
  27171. require: ['ngModel', 'mdDatepicker', '?^mdInputContainer', '?^form'],
  27172. scope: {
  27173. minDate: '=mdMinDate',
  27174. maxDate: '=mdMaxDate',
  27175. placeholder: '@mdPlaceholder',
  27176. currentView: '@mdCurrentView',
  27177. mode: '@mdMode',
  27178. dateFilter: '=mdDateFilter',
  27179. isOpen: '=?mdIsOpen',
  27180. debounceInterval: '=mdDebounceInterval',
  27181. dateLocale: '=mdDateLocale'
  27182. },
  27183. controller: DatePickerCtrl,
  27184. controllerAs: 'ctrl',
  27185. bindToController: true,
  27186. link: function(scope, element, attr, controllers) {
  27187. var ngModelCtrl = controllers[0];
  27188. var mdDatePickerCtrl = controllers[1];
  27189. var mdInputContainer = controllers[2];
  27190. var parentForm = controllers[3];
  27191. var mdNoAsterisk = $mdUtil.parseAttributeBoolean(attr.mdNoAsterisk);
  27192. mdDatePickerCtrl.configureNgModel(ngModelCtrl, mdInputContainer, inputDirective);
  27193. if (mdInputContainer) {
  27194. // We need to move the spacer after the datepicker itself,
  27195. // because md-input-container adds it after the
  27196. // md-datepicker-input by default. The spacer gets wrapped in a
  27197. // div, because it floats and gets aligned next to the datepicker.
  27198. // There are easier ways of working around this with CSS (making the
  27199. // datepicker 100% wide, change the `display` etc.), however they
  27200. // break the alignment with any other form controls.
  27201. var spacer = element[0].querySelector('.md-errors-spacer');
  27202. if (spacer) {
  27203. element.after(angular.element('<div>').append(spacer));
  27204. }
  27205. mdInputContainer.setHasPlaceholder(attr.mdPlaceholder);
  27206. mdInputContainer.input = element;
  27207. mdInputContainer.element
  27208. .addClass(INPUT_CONTAINER_CLASS)
  27209. .toggleClass(HAS_CALENDAR_ICON_CLASS, attr.mdHideIcons !== 'calendar' && attr.mdHideIcons !== 'all');
  27210. if (!mdInputContainer.label) {
  27211. $mdAria.expect(element, 'aria-label', attr.mdPlaceholder);
  27212. } else if(!mdNoAsterisk) {
  27213. attr.$observe('required', function(value) {
  27214. mdInputContainer.label.toggleClass('md-required', !!value);
  27215. });
  27216. }
  27217. scope.$watch(mdInputContainer.isErrorGetter || function() {
  27218. return ngModelCtrl.$invalid && (ngModelCtrl.$touched || (parentForm && parentForm.$submitted));
  27219. }, mdInputContainer.setInvalid);
  27220. } else if (parentForm) {
  27221. // If invalid, highlights the input when the parent form is submitted.
  27222. var parentSubmittedWatcher = scope.$watch(function() {
  27223. return parentForm.$submitted;
  27224. }, function(isSubmitted) {
  27225. if (isSubmitted) {
  27226. mdDatePickerCtrl.updateErrorState();
  27227. parentSubmittedWatcher();
  27228. }
  27229. });
  27230. }
  27231. }
  27232. };
  27233. }
  27234. /** Additional offset for the input's `size` attribute, which is updated based on its content. */
  27235. var EXTRA_INPUT_SIZE = 3;
  27236. /** Class applied to the container if the date is invalid. */
  27237. var INVALID_CLASS = 'md-datepicker-invalid';
  27238. /** Class applied to the datepicker when it's open. */
  27239. var OPEN_CLASS = 'md-datepicker-open';
  27240. /** Class applied to the md-input-container, if a datepicker is placed inside it */
  27241. var INPUT_CONTAINER_CLASS = '_md-datepicker-floating-label';
  27242. /** Class to be applied when the calendar icon is enabled. */
  27243. var HAS_CALENDAR_ICON_CLASS = '_md-datepicker-has-calendar-icon';
  27244. /** Class to be applied when the triangle icon is enabled. */
  27245. var HAS_TRIANGLE_ICON_CLASS = '_md-datepicker-has-triangle-icon';
  27246. /** Default time in ms to debounce input event by. */
  27247. var DEFAULT_DEBOUNCE_INTERVAL = 500;
  27248. /**
  27249. * Height of the calendar pane used to check if the pane is going outside the boundary of
  27250. * the viewport. See calendar.scss for how $md-calendar-height is computed; an extra 20px is
  27251. * also added to space the pane away from the exact edge of the screen.
  27252. *
  27253. * This is computed statically now, but can be changed to be measured if the circumstances
  27254. * of calendar sizing are changed.
  27255. */
  27256. var CALENDAR_PANE_HEIGHT = 368;
  27257. /**
  27258. * Width of the calendar pane used to check if the pane is going outside the boundary of
  27259. * the viewport. See calendar.scss for how $md-calendar-width is computed; an extra 20px is
  27260. * also added to space the pane away from the exact edge of the screen.
  27261. *
  27262. * This is computed statically now, but can be changed to be measured if the circumstances
  27263. * of calendar sizing are changed.
  27264. */
  27265. var CALENDAR_PANE_WIDTH = 360;
  27266. /** Used for checking whether the current user agent is on iOS or Android. */
  27267. var IS_MOBILE_REGEX = /ipad|iphone|ipod|android/i;
  27268. /**
  27269. * Controller for md-datepicker.
  27270. *
  27271. * @ngInject @constructor
  27272. */
  27273. function DatePickerCtrl($scope, $element, $attrs, $window, $mdConstant,
  27274. $mdTheming, $mdUtil, $mdDateLocale, $$mdDateUtil, $$rAF, $filter) {
  27275. /** @final */
  27276. this.$window = $window;
  27277. /** @final */
  27278. this.dateUtil = $$mdDateUtil;
  27279. /** @final */
  27280. this.$mdConstant = $mdConstant;
  27281. /* @final */
  27282. this.$mdUtil = $mdUtil;
  27283. /** @final */
  27284. this.$$rAF = $$rAF;
  27285. /** @final */
  27286. this.$mdDateLocale = $mdDateLocale;
  27287. /**
  27288. * The root document element. This is used for attaching a top-level click handler to
  27289. * close the calendar panel when a click outside said panel occurs. We use `documentElement`
  27290. * instead of body because, when scrolling is disabled, some browsers consider the body element
  27291. * to be completely off the screen and propagate events directly to the html element.
  27292. * @type {!angular.JQLite}
  27293. */
  27294. this.documentElement = angular.element(document.documentElement);
  27295. /** @type {!angular.NgModelController} */
  27296. this.ngModelCtrl = null;
  27297. /** @type {HTMLInputElement} */
  27298. this.inputElement = $element[0].querySelector('input');
  27299. /** @final {!angular.JQLite} */
  27300. this.ngInputElement = angular.element(this.inputElement);
  27301. /** @type {HTMLElement} */
  27302. this.inputContainer = $element[0].querySelector('.md-datepicker-input-container');
  27303. /** @type {HTMLElement} Floating calendar pane. */
  27304. this.calendarPane = $element[0].querySelector('.md-datepicker-calendar-pane');
  27305. /** @type {HTMLElement} Calendar icon button. */
  27306. this.calendarButton = $element[0].querySelector('.md-datepicker-button');
  27307. /**
  27308. * Element covering everything but the input in the top of the floating calendar pane.
  27309. * @type {!angular.JQLite}
  27310. */
  27311. this.inputMask = angular.element($element[0].querySelector('.md-datepicker-input-mask-opaque'));
  27312. /** @final {!angular.JQLite} */
  27313. this.$element = $element;
  27314. /** @final {!angular.Attributes} */
  27315. this.$attrs = $attrs;
  27316. /** @final {!angular.Scope} */
  27317. this.$scope = $scope;
  27318. /** @type {Date} */
  27319. this.date = null;
  27320. /** @type {boolean} */
  27321. this.isFocused = false;
  27322. /** @type {boolean} */
  27323. this.isDisabled;
  27324. this.setDisabled($element[0].disabled || angular.isString($attrs.disabled));
  27325. /** @type {boolean} Whether the date-picker's calendar pane is open. */
  27326. this.isCalendarOpen = false;
  27327. /** @type {boolean} Whether the calendar should open when the input is focused. */
  27328. this.openOnFocus = $attrs.hasOwnProperty('mdOpenOnFocus');
  27329. /** @final */
  27330. this.mdInputContainer = null;
  27331. /**
  27332. * Element from which the calendar pane was opened. Keep track of this so that we can return
  27333. * focus to it when the pane is closed.
  27334. * @type {HTMLElement}
  27335. */
  27336. this.calendarPaneOpenedFrom = null;
  27337. /** @type {String} Unique id for the calendar pane. */
  27338. this.calendarPaneId = 'md-date-pane-' + $mdUtil.nextUid();
  27339. /** Pre-bound click handler is saved so that the event listener can be removed. */
  27340. this.bodyClickHandler = angular.bind(this, this.handleBodyClick);
  27341. /**
  27342. * Name of the event that will trigger a close. Necessary to sniff the browser, because
  27343. * the resize event doesn't make sense on mobile and can have a negative impact since it
  27344. * triggers whenever the browser zooms in on a focused input.
  27345. */
  27346. this.windowEventName = IS_MOBILE_REGEX.test(
  27347. navigator.userAgent || navigator.vendor || window.opera
  27348. ) ? 'orientationchange' : 'resize';
  27349. /** Pre-bound close handler so that the event listener can be removed. */
  27350. this.windowEventHandler = $mdUtil.debounce(angular.bind(this, this.closeCalendarPane), 100);
  27351. /** Pre-bound handler for the window blur event. Allows for it to be removed later. */
  27352. this.windowBlurHandler = angular.bind(this, this.handleWindowBlur);
  27353. /** The built-in AngularJS date filter. */
  27354. this.ngDateFilter = $filter('date');
  27355. /** @type {Number} Extra margin for the left side of the floating calendar pane. */
  27356. this.leftMargin = 20;
  27357. /** @type {Number} Extra margin for the top of the floating calendar. Gets determined on the first open. */
  27358. this.topMargin = null;
  27359. // Unless the user specifies so, the datepicker should not be a tab stop.
  27360. // This is necessary because ngAria might add a tabindex to anything with an ng-model
  27361. // (based on whether or not the user has turned that particular feature on/off).
  27362. if ($attrs.tabindex) {
  27363. this.ngInputElement.attr('tabindex', $attrs.tabindex);
  27364. $attrs.$set('tabindex', null);
  27365. } else {
  27366. $attrs.$set('tabindex', '-1');
  27367. }
  27368. $attrs.$set('aria-owns', this.calendarPaneId);
  27369. $mdTheming($element);
  27370. $mdTheming(angular.element(this.calendarPane));
  27371. var self = this;
  27372. $scope.$on('$destroy', function() {
  27373. self.detachCalendarPane();
  27374. });
  27375. if ($attrs.mdIsOpen) {
  27376. $scope.$watch('ctrl.isOpen', function(shouldBeOpen) {
  27377. if (shouldBeOpen) {
  27378. self.openCalendarPane({
  27379. target: self.inputElement
  27380. });
  27381. } else {
  27382. self.closeCalendarPane();
  27383. }
  27384. });
  27385. }
  27386. // For AngularJS 1.4 and older, where there are no lifecycle hooks but bindings are pre-assigned,
  27387. // manually call the $onInit hook.
  27388. if (angular.version.major === 1 && angular.version.minor <= 4) {
  27389. this.$onInit();
  27390. }
  27391. }
  27392. /**
  27393. * AngularJS Lifecycle hook for newer AngularJS versions.
  27394. * Bindings are not guaranteed to have been assigned in the controller, but they are in the $onInit hook.
  27395. */
  27396. DatePickerCtrl.prototype.$onInit = function() {
  27397. /**
  27398. * Holds locale-specific formatters, parsers, labels etc. Allows
  27399. * the user to override specific ones from the $mdDateLocale provider.
  27400. * @type {!Object}
  27401. */
  27402. this.locale = this.dateLocale ? angular.extend({}, this.$mdDateLocale, this.dateLocale) : this.$mdDateLocale;
  27403. this.installPropertyInterceptors();
  27404. this.attachChangeListeners();
  27405. this.attachInteractionListeners();
  27406. };
  27407. /**
  27408. * Sets up the controller's reference to ngModelController and
  27409. * applies AngularJS's `input[type="date"]` directive.
  27410. * @param {!angular.NgModelController} ngModelCtrl Instance of the ngModel controller.
  27411. * @param {Object} mdInputContainer Instance of the mdInputContainer controller.
  27412. * @param {Object} inputDirective Config for AngularJS's `input` directive.
  27413. */
  27414. DatePickerCtrl.prototype.configureNgModel = function(ngModelCtrl, mdInputContainer, inputDirective) {
  27415. this.ngModelCtrl = ngModelCtrl;
  27416. this.mdInputContainer = mdInputContainer;
  27417. // The input needs to be [type="date"] in order to be picked up by AngularJS.
  27418. this.$attrs.$set('type', 'date');
  27419. // Invoke the `input` directive link function, adding a stub for the element.
  27420. // This allows us to re-use AngularJS's logic for setting the timezone via ng-model-options.
  27421. // It works by calling the link function directly which then adds the proper `$parsers` and
  27422. // `$formatters` to the ngModel controller.
  27423. inputDirective[0].link.pre(this.$scope, {
  27424. on: angular.noop,
  27425. val: angular.noop,
  27426. 0: {}
  27427. }, this.$attrs, [ngModelCtrl]);
  27428. var self = this;
  27429. // Responds to external changes to the model value.
  27430. self.ngModelCtrl.$formatters.push(function(value) {
  27431. var parsedValue = angular.isDefined(value) ? value : null;
  27432. if (!(value instanceof Date)) {
  27433. parsedValue = Date.parse(value);
  27434. // `parsedValue` is the time since epoch if valid or `NaN` if invalid.
  27435. if (!isNaN(parsedValue) && angular.isNumber(parsedValue)) {
  27436. value = new Date(parsedValue);
  27437. }
  27438. if (value && !(value instanceof Date)) {
  27439. throw Error(
  27440. 'The ng-model for md-datepicker must be a Date instance or a value ' +
  27441. 'that can be parsed into a date. Currently the model is of type: ' + typeof value
  27442. );
  27443. }
  27444. }
  27445. self.onExternalChange(value);
  27446. return value;
  27447. });
  27448. // Responds to external error state changes (e.g. ng-required based on another input).
  27449. ngModelCtrl.$viewChangeListeners.unshift(angular.bind(this, this.updateErrorState));
  27450. // Forwards any events from the input to the root element. This is necessary to get `updateOn`
  27451. // working for events that don't bubble (e.g. 'blur') since AngularJS binds the handlers to
  27452. // the `<md-datepicker>`.
  27453. var updateOn = self.$mdUtil.getModelOption(ngModelCtrl, 'updateOn');
  27454. if (updateOn) {
  27455. this.ngInputElement.on(
  27456. updateOn,
  27457. angular.bind(this.$element, this.$element.triggerHandler, updateOn)
  27458. );
  27459. }
  27460. };
  27461. /**
  27462. * Attach event listeners for both the text input and the md-calendar.
  27463. * Events are used instead of ng-model so that updates don't infinitely update the other
  27464. * on a change. This should also be more performant than using a $watch.
  27465. */
  27466. DatePickerCtrl.prototype.attachChangeListeners = function() {
  27467. var self = this;
  27468. self.$scope.$on('md-calendar-change', function(event, date) {
  27469. self.setModelValue(date);
  27470. self.onExternalChange(date);
  27471. self.closeCalendarPane();
  27472. });
  27473. self.ngInputElement.on('input', angular.bind(self, self.resizeInputElement));
  27474. var debounceInterval = angular.isDefined(this.debounceInterval) ?
  27475. this.debounceInterval : DEFAULT_DEBOUNCE_INTERVAL;
  27476. self.ngInputElement.on('input', self.$mdUtil.debounce(self.handleInputEvent,
  27477. debounceInterval, self));
  27478. };
  27479. /** Attach event listeners for user interaction. */
  27480. DatePickerCtrl.prototype.attachInteractionListeners = function() {
  27481. var self = this;
  27482. var $scope = this.$scope;
  27483. var keyCodes = this.$mdConstant.KEY_CODE;
  27484. // Add event listener through angular so that we can triggerHandler in unit tests.
  27485. self.ngInputElement.on('keydown', function(event) {
  27486. if (event.altKey && event.keyCode == keyCodes.DOWN_ARROW) {
  27487. self.openCalendarPane(event);
  27488. $scope.$digest();
  27489. }
  27490. });
  27491. if (self.openOnFocus) {
  27492. self.ngInputElement.on('focus', angular.bind(self, self.openCalendarPane));
  27493. angular.element(self.$window).on('blur', self.windowBlurHandler);
  27494. $scope.$on('$destroy', function() {
  27495. angular.element(self.$window).off('blur', self.windowBlurHandler);
  27496. });
  27497. }
  27498. $scope.$on('md-calendar-close', function() {
  27499. self.closeCalendarPane();
  27500. });
  27501. };
  27502. /**
  27503. * Capture properties set to the date-picker and imperitively handle internal changes.
  27504. * This is done to avoid setting up additional $watches.
  27505. */
  27506. DatePickerCtrl.prototype.installPropertyInterceptors = function() {
  27507. var self = this;
  27508. if (this.$attrs.ngDisabled) {
  27509. // The expression is to be evaluated against the directive element's scope and not
  27510. // the directive's isolate scope.
  27511. var scope = this.$scope.$parent;
  27512. if (scope) {
  27513. scope.$watch(this.$attrs.ngDisabled, function(isDisabled) {
  27514. self.setDisabled(isDisabled);
  27515. });
  27516. }
  27517. }
  27518. Object.defineProperty(this, 'placeholder', {
  27519. get: function() { return self.inputElement.placeholder; },
  27520. set: function(value) { self.inputElement.placeholder = value || ''; }
  27521. });
  27522. };
  27523. /**
  27524. * Sets whether the date-picker is disabled.
  27525. * @param {boolean} isDisabled
  27526. */
  27527. DatePickerCtrl.prototype.setDisabled = function(isDisabled) {
  27528. this.isDisabled = isDisabled;
  27529. this.inputElement.disabled = isDisabled;
  27530. if (this.calendarButton) {
  27531. this.calendarButton.disabled = isDisabled;
  27532. }
  27533. };
  27534. /**
  27535. * Sets the custom ngModel.$error flags to be consumed by ngMessages. Flags are:
  27536. * - mindate: whether the selected date is before the minimum date.
  27537. * - maxdate: whether the selected flag is after the maximum date.
  27538. * - filtered: whether the selected date is allowed by the custom filtering function.
  27539. * - valid: whether the entered text input is a valid date
  27540. *
  27541. * The 'required' flag is handled automatically by ngModel.
  27542. *
  27543. * @param {Date=} opt_date Date to check. If not given, defaults to the datepicker's model value.
  27544. */
  27545. DatePickerCtrl.prototype.updateErrorState = function(opt_date) {
  27546. var date = opt_date || this.date;
  27547. // Clear any existing errors to get rid of anything that's no longer relevant.
  27548. this.clearErrorState();
  27549. if (this.dateUtil.isValidDate(date)) {
  27550. // Force all dates to midnight in order to ignore the time portion.
  27551. date = this.dateUtil.createDateAtMidnight(date);
  27552. if (this.dateUtil.isValidDate(this.minDate)) {
  27553. var minDate = this.dateUtil.createDateAtMidnight(this.minDate);
  27554. this.ngModelCtrl.$setValidity('mindate', date >= minDate);
  27555. }
  27556. if (this.dateUtil.isValidDate(this.maxDate)) {
  27557. var maxDate = this.dateUtil.createDateAtMidnight(this.maxDate);
  27558. this.ngModelCtrl.$setValidity('maxdate', date <= maxDate);
  27559. }
  27560. if (angular.isFunction(this.dateFilter)) {
  27561. this.ngModelCtrl.$setValidity('filtered', this.dateFilter(date));
  27562. }
  27563. } else {
  27564. // The date is seen as "not a valid date" if there is *something* set
  27565. // (i.e.., not null or undefined), but that something isn't a valid date.
  27566. this.ngModelCtrl.$setValidity('valid', date == null);
  27567. }
  27568. angular.element(this.inputContainer).toggleClass(INVALID_CLASS, !this.ngModelCtrl.$valid);
  27569. };
  27570. /** Clears any error flags set by `updateErrorState`. */
  27571. DatePickerCtrl.prototype.clearErrorState = function() {
  27572. this.inputContainer.classList.remove(INVALID_CLASS);
  27573. ['mindate', 'maxdate', 'filtered', 'valid'].forEach(function(field) {
  27574. this.ngModelCtrl.$setValidity(field, true);
  27575. }, this);
  27576. };
  27577. /** Resizes the input element based on the size of its content. */
  27578. DatePickerCtrl.prototype.resizeInputElement = function() {
  27579. this.inputElement.size = this.inputElement.value.length + EXTRA_INPUT_SIZE;
  27580. };
  27581. /**
  27582. * Sets the model value if the user input is a valid date.
  27583. * Adds an invalid class to the input element if not.
  27584. */
  27585. DatePickerCtrl.prototype.handleInputEvent = function() {
  27586. var inputString = this.inputElement.value;
  27587. var parsedDate = inputString ? this.locale.parseDate(inputString) : null;
  27588. this.dateUtil.setDateTimeToMidnight(parsedDate);
  27589. // An input string is valid if it is either empty (representing no date)
  27590. // or if it parses to a valid date that the user is allowed to select.
  27591. var isValidInput = inputString == '' || (
  27592. this.dateUtil.isValidDate(parsedDate) &&
  27593. this.locale.isDateComplete(inputString) &&
  27594. this.isDateEnabled(parsedDate)
  27595. );
  27596. // The datepicker's model is only updated when there is a valid input.
  27597. if (isValidInput) {
  27598. this.setModelValue(parsedDate);
  27599. this.date = parsedDate;
  27600. }
  27601. this.updateErrorState(parsedDate);
  27602. };
  27603. /**
  27604. * Check whether date is in range and enabled
  27605. * @param {Date=} opt_date
  27606. * @return {boolean} Whether the date is enabled.
  27607. */
  27608. DatePickerCtrl.prototype.isDateEnabled = function(opt_date) {
  27609. return this.dateUtil.isDateWithinRange(opt_date, this.minDate, this.maxDate) &&
  27610. (!angular.isFunction(this.dateFilter) || this.dateFilter(opt_date));
  27611. };
  27612. /** Position and attach the floating calendar to the document. */
  27613. DatePickerCtrl.prototype.attachCalendarPane = function() {
  27614. var calendarPane = this.calendarPane;
  27615. var body = document.body;
  27616. calendarPane.style.transform = '';
  27617. this.$element.addClass(OPEN_CLASS);
  27618. this.mdInputContainer && this.mdInputContainer.element.addClass(OPEN_CLASS);
  27619. angular.element(body).addClass('md-datepicker-is-showing');
  27620. var elementRect = this.inputContainer.getBoundingClientRect();
  27621. var bodyRect = body.getBoundingClientRect();
  27622. if (!this.topMargin || this.topMargin < 0) {
  27623. this.topMargin = (this.inputMask.parent().prop('clientHeight') - this.ngInputElement.prop('clientHeight')) / 2;
  27624. }
  27625. // Check to see if the calendar pane would go off the screen. If so, adjust position
  27626. // accordingly to keep it within the viewport.
  27627. var paneTop = elementRect.top - bodyRect.top - this.topMargin;
  27628. var paneLeft = elementRect.left - bodyRect.left - this.leftMargin;
  27629. // If ng-material has disabled body scrolling (for example, if a dialog is open),
  27630. // then it's possible that the already-scrolled body has a negative top/left. In this case,
  27631. // we want to treat the "real" top as (0 - bodyRect.top). In a normal scrolling situation,
  27632. // though, the top of the viewport should just be the body's scroll position.
  27633. var viewportTop = (bodyRect.top < 0 && document.body.scrollTop == 0) ?
  27634. -bodyRect.top :
  27635. document.body.scrollTop;
  27636. var viewportLeft = (bodyRect.left < 0 && document.body.scrollLeft == 0) ?
  27637. -bodyRect.left :
  27638. document.body.scrollLeft;
  27639. var viewportBottom = viewportTop + this.$window.innerHeight;
  27640. var viewportRight = viewportLeft + this.$window.innerWidth;
  27641. // Creates an overlay with a hole the same size as element. We remove a pixel or two
  27642. // on each end to make it overlap slightly. The overlay's background is added in
  27643. // the theme in the form of a box-shadow with a huge spread.
  27644. this.inputMask.css({
  27645. position: 'absolute',
  27646. left: this.leftMargin + 'px',
  27647. top: this.topMargin + 'px',
  27648. width: (elementRect.width - 1) + 'px',
  27649. height: (elementRect.height - 2) + 'px'
  27650. });
  27651. // If the right edge of the pane would be off the screen and shifting it left by the
  27652. // difference would not go past the left edge of the screen. If the calendar pane is too
  27653. // big to fit on the screen at all, move it to the left of the screen and scale the entire
  27654. // element down to fit.
  27655. if (paneLeft + CALENDAR_PANE_WIDTH > viewportRight) {
  27656. if (viewportRight - CALENDAR_PANE_WIDTH > 0) {
  27657. paneLeft = viewportRight - CALENDAR_PANE_WIDTH;
  27658. } else {
  27659. paneLeft = viewportLeft;
  27660. var scale = this.$window.innerWidth / CALENDAR_PANE_WIDTH;
  27661. calendarPane.style.transform = 'scale(' + scale + ')';
  27662. }
  27663. calendarPane.classList.add('md-datepicker-pos-adjusted');
  27664. }
  27665. // If the bottom edge of the pane would be off the screen and shifting it up by the
  27666. // difference would not go past the top edge of the screen.
  27667. if (paneTop + CALENDAR_PANE_HEIGHT > viewportBottom &&
  27668. viewportBottom - CALENDAR_PANE_HEIGHT > viewportTop) {
  27669. paneTop = viewportBottom - CALENDAR_PANE_HEIGHT;
  27670. calendarPane.classList.add('md-datepicker-pos-adjusted');
  27671. }
  27672. calendarPane.style.left = paneLeft + 'px';
  27673. calendarPane.style.top = paneTop + 'px';
  27674. document.body.appendChild(calendarPane);
  27675. // Add CSS class after one frame to trigger open animation.
  27676. this.$$rAF(function() {
  27677. calendarPane.classList.add('md-pane-open');
  27678. });
  27679. };
  27680. /** Detach the floating calendar pane from the document. */
  27681. DatePickerCtrl.prototype.detachCalendarPane = function() {
  27682. this.$element.removeClass(OPEN_CLASS);
  27683. this.mdInputContainer && this.mdInputContainer.element.removeClass(OPEN_CLASS);
  27684. angular.element(document.body).removeClass('md-datepicker-is-showing');
  27685. this.calendarPane.classList.remove('md-pane-open');
  27686. this.calendarPane.classList.remove('md-datepicker-pos-adjusted');
  27687. if (this.isCalendarOpen) {
  27688. this.$mdUtil.enableScrolling();
  27689. }
  27690. if (this.calendarPane.parentNode) {
  27691. // Use native DOM removal because we do not want any of the
  27692. // angular state of this element to be disposed.
  27693. this.calendarPane.parentNode.removeChild(this.calendarPane);
  27694. }
  27695. };
  27696. /**
  27697. * Open the floating calendar pane.
  27698. * @param {Event} event
  27699. */
  27700. DatePickerCtrl.prototype.openCalendarPane = function(event) {
  27701. if (!this.isCalendarOpen && !this.isDisabled && !this.inputFocusedOnWindowBlur) {
  27702. this.isCalendarOpen = this.isOpen = true;
  27703. this.calendarPaneOpenedFrom = event.target;
  27704. // Because the calendar pane is attached directly to the body, it is possible that the
  27705. // rest of the component (input, etc) is in a different scrolling container, such as
  27706. // an md-content. This means that, if the container is scrolled, the pane would remain
  27707. // stationary. To remedy this, we disable scrolling while the calendar pane is open, which
  27708. // also matches the native behavior for things like `<select>` on Mac and Windows.
  27709. this.$mdUtil.disableScrollAround(this.calendarPane);
  27710. this.attachCalendarPane();
  27711. this.focusCalendar();
  27712. this.evalAttr('ngFocus');
  27713. // Attach click listener inside of a timeout because, if this open call was triggered by a
  27714. // click, we don't want it to be immediately propogated up to the body and handled.
  27715. var self = this;
  27716. this.$mdUtil.nextTick(function() {
  27717. // Use 'touchstart` in addition to click in order to work on iOS Safari, where click
  27718. // events aren't propogated under most circumstances.
  27719. // See http://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
  27720. self.documentElement.on('click touchstart', self.bodyClickHandler);
  27721. }, false);
  27722. window.addEventListener(this.windowEventName, this.windowEventHandler);
  27723. }
  27724. };
  27725. /** Close the floating calendar pane. */
  27726. DatePickerCtrl.prototype.closeCalendarPane = function() {
  27727. if (this.isCalendarOpen) {
  27728. var self = this;
  27729. self.detachCalendarPane();
  27730. self.ngModelCtrl.$setTouched();
  27731. self.evalAttr('ngBlur');
  27732. self.documentElement.off('click touchstart', self.bodyClickHandler);
  27733. window.removeEventListener(self.windowEventName, self.windowEventHandler);
  27734. self.calendarPaneOpenedFrom.focus();
  27735. self.calendarPaneOpenedFrom = null;
  27736. if (self.openOnFocus) {
  27737. // Ensures that all focus events have fired before resetting
  27738. // the calendar. Prevents the calendar from reopening immediately
  27739. // in IE when md-open-on-focus is set. Also it needs to trigger
  27740. // a digest, in order to prevent issues where the calendar wasn't
  27741. // showing up on the next open.
  27742. self.$mdUtil.nextTick(reset);
  27743. } else {
  27744. reset();
  27745. }
  27746. }
  27747. function reset(){
  27748. self.isCalendarOpen = self.isOpen = false;
  27749. }
  27750. };
  27751. /** Gets the controller instance for the calendar in the floating pane. */
  27752. DatePickerCtrl.prototype.getCalendarCtrl = function() {
  27753. return angular.element(this.calendarPane.querySelector('md-calendar')).controller('mdCalendar');
  27754. };
  27755. /** Focus the calendar in the floating pane. */
  27756. DatePickerCtrl.prototype.focusCalendar = function() {
  27757. // Use a timeout in order to allow the calendar to be rendered, as it is gated behind an ng-if.
  27758. var self = this;
  27759. this.$mdUtil.nextTick(function() {
  27760. self.getCalendarCtrl().focus();
  27761. }, false);
  27762. };
  27763. /**
  27764. * Sets whether the input is currently focused.
  27765. * @param {boolean} isFocused
  27766. */
  27767. DatePickerCtrl.prototype.setFocused = function(isFocused) {
  27768. if (!isFocused) {
  27769. this.ngModelCtrl.$setTouched();
  27770. }
  27771. // The ng* expressions shouldn't be evaluated when mdOpenOnFocus is on,
  27772. // because they also get called when the calendar is opened/closed.
  27773. if (!this.openOnFocus) {
  27774. this.evalAttr(isFocused ? 'ngFocus' : 'ngBlur');
  27775. }
  27776. this.isFocused = isFocused;
  27777. };
  27778. /**
  27779. * Handles a click on the document body when the floating calendar pane is open.
  27780. * Closes the floating calendar pane if the click is not inside of it.
  27781. * @param {MouseEvent} event
  27782. */
  27783. DatePickerCtrl.prototype.handleBodyClick = function(event) {
  27784. if (this.isCalendarOpen) {
  27785. var isInCalendar = this.$mdUtil.getClosest(event.target, 'md-calendar');
  27786. if (!isInCalendar) {
  27787. this.closeCalendarPane();
  27788. }
  27789. this.$scope.$digest();
  27790. }
  27791. };
  27792. /**
  27793. * Handles the event when the user navigates away from the current tab. Keeps track of
  27794. * whether the input was focused when the event happened, in order to prevent the calendar
  27795. * from re-opening.
  27796. */
  27797. DatePickerCtrl.prototype.handleWindowBlur = function() {
  27798. this.inputFocusedOnWindowBlur = document.activeElement === this.inputElement;
  27799. };
  27800. /**
  27801. * Evaluates an attribute expression against the parent scope.
  27802. * @param {String} attr Name of the attribute to be evaluated.
  27803. */
  27804. DatePickerCtrl.prototype.evalAttr = function(attr) {
  27805. if (this.$attrs[attr]) {
  27806. this.$scope.$parent.$eval(this.$attrs[attr]);
  27807. }
  27808. };
  27809. /**
  27810. * Sets the ng-model value by first converting the date object into a strng. Converting it
  27811. * is necessary, in order to pass AngularJS's `input[type="date"]` validations. AngularJS turns
  27812. * the value into a Date object afterwards, before setting it on the model.
  27813. * @param {Date=} value Date to be set as the model value.
  27814. */
  27815. DatePickerCtrl.prototype.setModelValue = function(value) {
  27816. var timezone = this.$mdUtil.getModelOption(this.ngModelCtrl, 'timezone');
  27817. this.ngModelCtrl.$setViewValue(this.ngDateFilter(value, 'yyyy-MM-dd', timezone));
  27818. };
  27819. /**
  27820. * Updates the datepicker when a model change occurred externally.
  27821. * @param {Date=} value Value that was set to the model.
  27822. */
  27823. DatePickerCtrl.prototype.onExternalChange = function(value) {
  27824. var timezone = this.$mdUtil.getModelOption(this.ngModelCtrl, 'timezone');
  27825. this.date = value;
  27826. this.inputElement.value = this.locale.formatDate(value, timezone);
  27827. this.mdInputContainer && this.mdInputContainer.setHasValue(!!value);
  27828. this.resizeInputElement();
  27829. this.updateErrorState();
  27830. };
  27831. })();
  27832. })();
  27833. (function(){
  27834. "use strict";
  27835. angular
  27836. .module('material.components.icon')
  27837. .directive('mdIcon', ['$mdIcon', '$mdTheming', '$mdAria', '$sce', mdIconDirective]);
  27838. /**
  27839. * @ngdoc directive
  27840. * @name mdIcon
  27841. * @module material.components.icon
  27842. *
  27843. * @restrict E
  27844. *
  27845. * @description
  27846. * The `md-icon` directive makes it easier to use vector-based icons in your app (as opposed to
  27847. * raster-based icons types like PNG). The directive supports both icon fonts and SVG icons.
  27848. *
  27849. * Icons should be considered view-only elements that should not be used directly as buttons; instead nest a `<md-icon>`
  27850. * inside a `md-button` to add hover and click features.
  27851. *
  27852. * ### Icon fonts
  27853. * Icon fonts are a technique in which you use a font where the glyphs in the font are
  27854. * your icons instead of text. Benefits include a straightforward way to bundle everything into a
  27855. * single HTTP request, simple scaling, easy color changing, and more.
  27856. *
  27857. * `md-icon` lets you consume an icon font by letting you reference specific icons in that font
  27858. * by name rather than character code.
  27859. *
  27860. * ### SVG
  27861. * For SVGs, the problem with using `<img>` or a CSS `background-image` is that you can't take
  27862. * advantage of some SVG features, such as styling specific parts of the icon with CSS or SVG
  27863. * animation.
  27864. *
  27865. * `md-icon` makes it easier to use SVG icons by *inlining* the SVG into an `<svg>` element in the
  27866. * document. The most straightforward way of referencing an SVG icon is via URL, just like a
  27867. * traditional `<img>`. `$mdIconProvider`, as a convenience, lets you _name_ an icon so you can
  27868. * reference it by name instead of URL throughout your templates.
  27869. *
  27870. * Additionally, you may not want to make separate HTTP requests for every icon, so you can bundle
  27871. * your SVG icons together and pre-load them with $mdIconProvider as an icon set. An icon set can
  27872. * also be given a name, which acts as a namespace for individual icons, so you can reference them
  27873. * like `"social:cake"`.
  27874. *
  27875. * When using SVGs, both external SVGs (via URLs) or sets of SVGs [from icon sets] can be
  27876. * easily loaded and used. When using font-icons, developers must follow three (3) simple steps:
  27877. *
  27878. * <ol>
  27879. * <li>Load the font library. e.g.<br/>
  27880. * `<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
  27881. * rel="stylesheet">`
  27882. * </li>
  27883. * <li>
  27884. * Use either (a) font-icon class names or (b) a fontset and a font ligature to render the font glyph by
  27885. * using its textual name _or_ numerical character reference. Note that `material-icons` is the default fontset when
  27886. * none is specified.
  27887. * </li>
  27888. * <li> Use any of the following templates: <br/>
  27889. * <ul>
  27890. * <li>`<md-icon md-font-icon="classname"></md-icon>`</li>
  27891. * <li>`<md-icon md-font-set="font library classname or alias">textual_name</md-icon>`</li>
  27892. * <li>`<md-icon> numerical_character_reference </md-icon>`</li>
  27893. * <li>`<md-icon ng_bind="'textual_name'"></md-icon>`</li>
  27894. * <li>`<md-icon ng-bind="scopeVariable"></md-icon>`</li>
  27895. * </ul>
  27896. * </li>
  27897. * </ol>
  27898. *
  27899. * Full details for these steps can be found:
  27900. *
  27901. * <ul>
  27902. * <li>http://google.github.io/material-design-icons/</li>
  27903. * <li>http://google.github.io/material-design-icons/#icon-font-for-the-web</li>
  27904. * </ul>
  27905. *
  27906. * The Material Design icon style <code>.material-icons</code> and the icon font references are published in
  27907. * Material Design Icons:
  27908. *
  27909. * <ul>
  27910. * <li>https://design.google.com/icons/</li>
  27911. * <li>https://design.google.com/icons/#ic_accessibility</li>
  27912. * </ul>
  27913. *
  27914. * ### Localization
  27915. *
  27916. * Because an `md-icon` element's text content is not intended to be translated, it is recommended to declare the text
  27917. * content for an `md-icon` element in its start tag. Instead of using the HTML text content, consider using `ng-bind`
  27918. * with a scope variable or literal string.
  27919. *
  27920. * Examples:
  27921. *
  27922. * <ul>
  27923. * <li>`<md-icon ng-bind="myIconVariable"></md-icon>`</li>
  27924. * <li>`<md-icon ng-bind="'menu'"></md-icon>`
  27925. * </ul>
  27926. *
  27927. * <h2 id="material_design_icons">Material Design Icons</h2>
  27928. * Using the Material Design Icon-Selector, developers can easily and quickly search for a Material Design font-icon and
  27929. * determine its textual name and character reference code. Click on any icon to see the slide-up information
  27930. * panel with details regarding a SVG download or information on the font-icon usage.
  27931. *
  27932. * <a href="https://www.google.com/design/icons/#ic_accessibility" target="_blank" style="border-bottom:none;">
  27933. * <img src="https://cloud.githubusercontent.com/assets/210413/7902490/fe8dd14c-0780-11e5-98fb-c821cc6475e6.png"
  27934. * aria-label="Material Design Icon-Selector" style="max-width:75%;padding-left:10%">
  27935. * </a>
  27936. *
  27937. * <span class="image_caption">
  27938. * Click on the image above to link to the
  27939. * <a href="https://design.google.com/icons/#ic_accessibility" target="_blank">Material Design Icon-Selector</a>.
  27940. * </span>
  27941. *
  27942. * @param {string} md-font-icon String name of CSS icon associated with the font-face will be used
  27943. * to render the icon. Requires the fonts and the named CSS styles to be preloaded.
  27944. * @param {string} md-font-set CSS style name associated with the font library; which will be assigned as
  27945. * the class for the font-icon ligature. This value may also be an alias that is used to lookup the classname;
  27946. * internally use `$mdIconProvider.fontSet(<alias>)` to determine the style name.
  27947. * @param {string} md-svg-src String URL (or expression) used to load, cache, and display an
  27948. * external SVG.
  27949. * @param {string} md-svg-icon md-svg-icon String name used for lookup of the icon from the internal cache;
  27950. * interpolated strings or expressions may also be used. Specific set names can be used with
  27951. * the syntax `<set name>:<icon name>`.<br/><br/>
  27952. * To use icon sets, developers are required to pre-register the sets using the `$mdIconProvider` service.
  27953. * @param {string=} aria-label Labels icon for accessibility. If an empty string is provided, icon
  27954. * will be hidden from accessibility layer with `aria-hidden="true"`. If there's no aria-label on the icon
  27955. * nor a label on the parent element, a warning will be logged to the console.
  27956. * @param {string=} alt Labels icon for accessibility. If an empty string is provided, icon
  27957. * will be hidden from accessibility layer with `aria-hidden="true"`. If there's no alt on the icon
  27958. * nor a label on the parent element, a warning will be logged to the console.
  27959. *
  27960. * @usage
  27961. * When using SVGs:
  27962. * <hljs lang="html">
  27963. *
  27964. * <!-- Icon ID; may contain optional icon set prefix; icons must registered using $mdIconProvider -->
  27965. * <md-icon md-svg-icon="social:android" aria-label="android " ></md-icon>
  27966. *
  27967. * <!-- Icon urls; may be preloaded in templateCache -->
  27968. * <md-icon md-svg-src="/android.svg" aria-label="android " ></md-icon>
  27969. * <md-icon md-svg-src="{{ getAndroid() }}" aria-label="android " ></md-icon>
  27970. *
  27971. * </hljs>
  27972. *
  27973. * Use the <code>$mdIconProvider</code> to configure your application with
  27974. * svg iconsets.
  27975. *
  27976. * <hljs lang="js">
  27977. * angular.module('appSvgIconSets', ['ngMaterial'])
  27978. * .controller('DemoCtrl', function($scope) {})
  27979. * .config(function($mdIconProvider) {
  27980. * $mdIconProvider
  27981. * .iconSet('social', 'img/icons/sets/social-icons.svg', 24)
  27982. * .defaultIconSet('img/icons/sets/core-icons.svg', 24);
  27983. * });
  27984. * </hljs>
  27985. *
  27986. *
  27987. * When using Font Icons with classnames:
  27988. * <hljs lang="html">
  27989. *
  27990. * <md-icon md-font-icon="android" aria-label="android" ></md-icon>
  27991. * <md-icon class="icon_home" aria-label="Home" ></md-icon>
  27992. *
  27993. * </hljs>
  27994. *
  27995. * When using Material Font Icons with ligatures:
  27996. * <hljs lang="html">
  27997. * <!--
  27998. * For Material Design Icons
  27999. * The class '.material-icons' is auto-added if a style has NOT been specified
  28000. * since `material-icons` is the default fontset. So your markup:
  28001. * -->
  28002. * <md-icon> face </md-icon>
  28003. * <!-- becomes this at runtime: -->
  28004. * <md-icon md-font-set="material-icons"> face </md-icon>
  28005. * <!-- If the fontset does not support ligature names, then we need to use the ligature unicode.-->
  28006. * <md-icon> &#xE87C; </md-icon>
  28007. * <!-- The class '.material-icons' must be manually added if other styles are also specified-->
  28008. * <md-icon class="material-icons md-light md-48"> face </md-icon>
  28009. * </hljs>
  28010. *
  28011. * When using other Font-Icon libraries:
  28012. *
  28013. * <hljs lang="js">
  28014. * // Specify a font-icon style alias
  28015. * angular.config(function($mdIconProvider) {
  28016. * $mdIconProvider.fontSet('md', 'material-icons');
  28017. * });
  28018. * </hljs>
  28019. *
  28020. * <hljs lang="html">
  28021. * <md-icon md-font-set="md">favorite</md-icon>
  28022. * </hljs>
  28023. *
  28024. */
  28025. function mdIconDirective($mdIcon, $mdTheming, $mdAria, $sce) {
  28026. return {
  28027. restrict: 'E',
  28028. link : postLink
  28029. };
  28030. /**
  28031. * Directive postLink
  28032. * Supports embedded SVGs, font-icons, & external SVGs
  28033. */
  28034. function postLink(scope, element, attr) {
  28035. $mdTheming(element);
  28036. var lastFontIcon = attr.mdFontIcon;
  28037. var lastFontSet = $mdIcon.fontSet(attr.mdFontSet);
  28038. prepareForFontIcon();
  28039. attr.$observe('mdFontIcon', fontIconChanged);
  28040. attr.$observe('mdFontSet', fontIconChanged);
  28041. // Keep track of the content of the svg src so we can compare against it later to see if the
  28042. // attribute is static (and thus safe).
  28043. var originalSvgSrc = element[0].getAttribute(attr.$attr.mdSvgSrc);
  28044. // If using a font-icon, then the textual name of the icon itself
  28045. // provides the aria-label.
  28046. var attrName = attr.$normalize(attr.$attr.mdSvgIcon || attr.$attr.mdSvgSrc || '');
  28047. /* Provide a default accessibility role of img */
  28048. if (!attr.role) {
  28049. $mdAria.expect(element, 'role', 'img');
  28050. /* manually update attr variable */
  28051. attr.role = 'img';
  28052. }
  28053. /* Don't process ARIA if already valid */
  28054. if ( attr.role === "img" && !attr.ariaHidden && !$mdAria.hasAriaLabel(element) ) {
  28055. var iconName;
  28056. if (attr.alt) {
  28057. /* Use alt text by default if available */
  28058. $mdAria.expect(element, 'aria-label', attr.alt);
  28059. } else if ($mdAria.parentHasAriaLabel(element, 2)) {
  28060. /* Parent has ARIA so we will assume it will describe the image */
  28061. $mdAria.expect(element, 'aria-hidden', 'true');
  28062. } else if (iconName = (attr.mdFontIcon || attr.mdSvgIcon || element.text())) {
  28063. /* Use icon name as aria-label */
  28064. $mdAria.expect(element, 'aria-label', iconName);
  28065. } else {
  28066. /* No label found */
  28067. $mdAria.expect(element, 'aria-hidden', 'true');
  28068. }
  28069. }
  28070. if (attrName) {
  28071. // Use either pre-configured SVG or URL source, respectively.
  28072. attr.$observe(attrName, function(attrVal) {
  28073. element.empty();
  28074. if (attrVal) {
  28075. $mdIcon(attrVal)
  28076. .then(function(svg) {
  28077. element.empty();
  28078. element.append(svg);
  28079. });
  28080. }
  28081. });
  28082. }
  28083. function prepareForFontIcon() {
  28084. if (!attr.mdSvgIcon && !attr.mdSvgSrc) {
  28085. if (attr.mdFontIcon) {
  28086. element.addClass('md-font ' + attr.mdFontIcon);
  28087. }
  28088. element.addClass(lastFontSet);
  28089. }
  28090. }
  28091. function fontIconChanged() {
  28092. if (!attr.mdSvgIcon && !attr.mdSvgSrc) {
  28093. if (attr.mdFontIcon) {
  28094. element.removeClass(lastFontIcon);
  28095. element.addClass(attr.mdFontIcon);
  28096. lastFontIcon = attr.mdFontIcon;
  28097. }
  28098. var fontSet = $mdIcon.fontSet(attr.mdFontSet);
  28099. if (lastFontSet !== fontSet) {
  28100. element.removeClass(lastFontSet);
  28101. element.addClass(fontSet);
  28102. lastFontSet = fontSet;
  28103. }
  28104. }
  28105. }
  28106. }
  28107. }
  28108. })();
  28109. (function(){
  28110. "use strict";
  28111. MdIconService.$inject = ["config", "$templateRequest", "$q", "$log", "$mdUtil", "$sce"];angular
  28112. .module('material.components.icon')
  28113. .constant('$$mdSvgRegistry', {
  28114. 'mdTabsArrow': 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxnPjxwb2x5Z29uIHBvaW50cz0iMTUuNCw3LjQgMTQsNiA4LDEyIDE0LDE4IDE1LjQsMTYuNiAxMC44LDEyICIvPjwvZz48L3N2Zz4=',
  28115. 'mdClose': 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxnPjxwYXRoIGQ9Ik0xOSA2LjQxbC0xLjQxLTEuNDEtNS41OSA1LjU5LTUuNTktNS41OS0xLjQxIDEuNDEgNS41OSA1LjU5LTUuNTkgNS41OSAxLjQxIDEuNDEgNS41OS01LjU5IDUuNTkgNS41OSAxLjQxLTEuNDEtNS41OS01LjU5eiIvPjwvZz48L3N2Zz4=',
  28116. 'mdCancel': 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxnPjxwYXRoIGQ9Ik0xMiAyYy01LjUzIDAtMTAgNC40Ny0xMCAxMHM0LjQ3IDEwIDEwIDEwIDEwLTQuNDcgMTAtMTAtNC40Ny0xMC0xMC0xMHptNSAxMy41OWwtMS40MSAxLjQxLTMuNTktMy41OS0zLjU5IDMuNTktMS40MS0xLjQxIDMuNTktMy41OS0zLjU5LTMuNTkgMS40MS0xLjQxIDMuNTkgMy41OSAzLjU5LTMuNTkgMS40MSAxLjQxLTMuNTkgMy41OSAzLjU5IDMuNTl6Ii8+PC9nPjwvc3ZnPg==',
  28117. 'mdMenu': 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxwYXRoIGQ9Ik0zLDZIMjFWOEgzVjZNMywxMUgyMVYxM0gzVjExTTMsMTZIMjFWMThIM1YxNloiIC8+PC9zdmc+',
  28118. 'mdToggleArrow': 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgNDggNDgiPjxwYXRoIGQ9Ik0yNCAxNmwtMTIgMTIgMi44MyAyLjgzIDkuMTctOS4xNyA5LjE3IDkuMTcgMi44My0yLjgzeiIvPjxwYXRoIGQ9Ik0wIDBoNDh2NDhoLTQ4eiIgZmlsbD0ibm9uZSIvPjwvc3ZnPg==',
  28119. 'mdCalendar': 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTkgM2gtMVYxaC0ydjJIOFYxSDZ2Mkg1Yy0xLjExIDAtMS45OS45LTEuOTkgMkwzIDE5YzAgMS4xLjg5IDIgMiAyaDE0YzEuMSAwIDItLjkgMi0yVjVjMC0xLjEtLjktMi0yLTJ6bTAgMTZINVY4aDE0djExek03IDEwaDV2NUg3eiIvPjwvc3ZnPg==',
  28120. 'mdChecked': 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxnPjxwYXRoIGQ9Ik05IDE2LjE3TDQuODMgMTJsLTEuNDIgMS40MUw5IDE5IDIxIDdsLTEuNDEtMS40MXoiLz48L2c+PC9zdmc+'
  28121. })
  28122. .provider('$mdIcon', MdIconProvider);
  28123. /**
  28124. * @ngdoc service
  28125. * @name $mdIconProvider
  28126. * @module material.components.icon
  28127. *
  28128. * @description
  28129. * `$mdIconProvider` is used only to register icon IDs with URLs. These configuration features allow
  28130. * icons and icon sets to be pre-registered and associated with source URLs **before** the `<md-icon />`
  28131. * directives are compiled.
  28132. *
  28133. * If using font-icons, the developer is responsible for loading the fonts.
  28134. *
  28135. * If using SVGs, loading of the actual svg files are deferred to on-demand requests and are loaded
  28136. * internally by the `$mdIcon` service using the `$templateRequest` service. When an SVG is
  28137. * requested by name/ID, the `$mdIcon` service searches its registry for the associated source URL;
  28138. * that URL is used to on-demand load and parse the SVG dynamically.
  28139. *
  28140. * The `$templateRequest` service expects the icons source to be loaded over trusted URLs.<br/>
  28141. * This means, when loading icons from an external URL, you have to trust the URL in the `$sceDelegateProvider`.
  28142. *
  28143. * <hljs lang="js">
  28144. * app.config(function($sceDelegateProvider) {
  28145. * $sceDelegateProvider.resourceUrlWhitelist([
  28146. * // Adding 'self' to the whitelist, will allow requests from the current origin.
  28147. * 'self',
  28148. * // Using double asterisks here, will allow all URLs to load.
  28149. * // We recommend to only specify the given domain you want to allow.
  28150. * '**'
  28151. * ]);
  28152. * });
  28153. * </hljs>
  28154. *
  28155. * Read more about the [$sceDelegateProvider](https://docs.angularjs.org/api/ng/provider/$sceDelegateProvider).
  28156. *
  28157. * **Notice:** Most font-icons libraries do not support ligatures (for example `fontawesome`).<br/>
  28158. * In such cases you are not able to use the icon's ligature name - Like so:
  28159. *
  28160. * <hljs lang="html">
  28161. * <md-icon md-font-set="fa">fa-bell</md-icon>
  28162. * </hljs>
  28163. *
  28164. * You should instead use the given unicode, instead of the ligature name.
  28165. *
  28166. * <p ng-hide="true"> ##// Notice we can't use a hljs element here, because the characters will be escaped.</p>
  28167. * ```html
  28168. * <md-icon md-font-set="fa">&#xf0f3</md-icon>
  28169. * ```
  28170. *
  28171. * All unicode ligatures are prefixed with the `&#x` string.
  28172. *
  28173. * @usage
  28174. * <hljs lang="js">
  28175. * app.config(function($mdIconProvider) {
  28176. *
  28177. * // Configure URLs for icons specified by [set:]id.
  28178. *
  28179. * $mdIconProvider
  28180. * .defaultFontSet( 'fa' ) // This sets our default fontset className.
  28181. * .defaultIconSet('my/app/icons.svg') // Register a default set of SVG icons
  28182. * .iconSet('social', 'my/app/social.svg') // Register a named icon set of SVGs
  28183. * .icon('android', 'my/app/android.svg') // Register a specific icon (by name)
  28184. * .icon('work:chair', 'my/app/chair.svg'); // Register icon in a specific set
  28185. * });
  28186. * </hljs>
  28187. *
  28188. * SVG icons and icon sets can be easily pre-loaded and cached using either (a) a build process or (b) a runtime
  28189. * **startup** process (shown below):
  28190. *
  28191. * <hljs lang="js">
  28192. * app.config(function($mdIconProvider) {
  28193. *
  28194. * // Register a default set of SVG icon definitions
  28195. * $mdIconProvider.defaultIconSet('my/app/icons.svg')
  28196. *
  28197. * })
  28198. * .run(function($templateRequest){
  28199. *
  28200. * // Pre-fetch icons sources by URL and cache in the $templateCache...
  28201. * // subsequent $templateRequest calls will look there first.
  28202. *
  28203. * var urls = [ 'imy/app/icons.svg', 'img/icons/android.svg'];
  28204. *
  28205. * angular.forEach(urls, function(url) {
  28206. * $templateRequest(url);
  28207. * });
  28208. *
  28209. * });
  28210. *
  28211. * </hljs>
  28212. *
  28213. * > <b>Note:</b> The loaded SVG data is subsequently cached internally for future requests.
  28214. *
  28215. */
  28216. /**
  28217. * @ngdoc method
  28218. * @name $mdIconProvider#icon
  28219. *
  28220. * @description
  28221. * Register a source URL for a specific icon name; the name may include optional 'icon set' name prefix.
  28222. * These icons will later be retrieved from the cache using `$mdIcon( <icon name> )`
  28223. *
  28224. * @param {string} id Icon name/id used to register the icon
  28225. * @param {string} url specifies the external location for the data file. Used internally by
  28226. * `$templateRequest` to load the data or as part of the lookup in `$templateCache` if pre-loading
  28227. * was configured.
  28228. * @param {number=} viewBoxSize Sets the width and height the icon's viewBox.
  28229. * It is ignored for icons with an existing viewBox. Default size is 24.
  28230. *
  28231. * @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
  28232. *
  28233. * @usage
  28234. * <hljs lang="js">
  28235. * app.config(function($mdIconProvider) {
  28236. *
  28237. * // Configure URLs for icons specified by [set:]id.
  28238. *
  28239. * $mdIconProvider
  28240. * .icon('android', 'my/app/android.svg') // Register a specific icon (by name)
  28241. * .icon('work:chair', 'my/app/chair.svg'); // Register icon in a specific set
  28242. * });
  28243. * </hljs>
  28244. *
  28245. */
  28246. /**
  28247. * @ngdoc method
  28248. * @name $mdIconProvider#iconSet
  28249. *
  28250. * @description
  28251. * Register a source URL for a 'named' set of icons; group of SVG definitions where each definition
  28252. * has an icon id. Individual icons can be subsequently retrieved from this cached set using
  28253. * `$mdIcon(<icon set name>:<icon name>)`
  28254. *
  28255. * @param {string} id Icon name/id used to register the iconset
  28256. * @param {string} url specifies the external location for the data file. Used internally by
  28257. * `$templateRequest` to load the data or as part of the lookup in `$templateCache` if pre-loading
  28258. * was configured.
  28259. * @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
  28260. * It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
  28261. * Default value is 24.
  28262. *
  28263. * @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
  28264. *
  28265. *
  28266. * @usage
  28267. * <hljs lang="js">
  28268. * app.config(function($mdIconProvider) {
  28269. *
  28270. * // Configure URLs for icons specified by [set:]id.
  28271. *
  28272. * $mdIconProvider
  28273. * .iconSet('social', 'my/app/social.svg') // Register a named icon set
  28274. * });
  28275. * </hljs>
  28276. *
  28277. */
  28278. /**
  28279. * @ngdoc method
  28280. * @name $mdIconProvider#defaultIconSet
  28281. *
  28282. * @description
  28283. * Register a source URL for the default 'named' set of icons. Unless explicitly registered,
  28284. * subsequent lookups of icons will failover to search this 'default' icon set.
  28285. * Icon can be retrieved from this cached, default set using `$mdIcon(<name>)`
  28286. *
  28287. * @param {string} url specifies the external location for the data file. Used internally by
  28288. * `$templateRequest` to load the data or as part of the lookup in `$templateCache` if pre-loading
  28289. * was configured.
  28290. * @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
  28291. * It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
  28292. * Default value is 24.
  28293. *
  28294. * @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
  28295. *
  28296. * @usage
  28297. * <hljs lang="js">
  28298. * app.config(function($mdIconProvider) {
  28299. *
  28300. * // Configure URLs for icons specified by [set:]id.
  28301. *
  28302. * $mdIconProvider
  28303. * .defaultIconSet( 'my/app/social.svg' ) // Register a default icon set
  28304. * });
  28305. * </hljs>
  28306. *
  28307. */
  28308. /**
  28309. * @ngdoc method
  28310. * @name $mdIconProvider#defaultFontSet
  28311. *
  28312. * @description
  28313. * When using Font-Icons, AngularJS Material assumes the the Material Design icons will be used and automatically
  28314. * configures the default font-set == 'material-icons'. Note that the font-set references the font-icon library
  28315. * class style that should be applied to the `<md-icon>`.
  28316. *
  28317. * Configuring the default means that the attributes
  28318. * `md-font-set="material-icons"` or `class="material-icons"` do not need to be explicitly declared on the
  28319. * `<md-icon>` markup. For example:
  28320. *
  28321. * `<md-icon> face </md-icon>`
  28322. * will render as
  28323. * `<span class="material-icons"> face </span>`, and
  28324. *
  28325. * `<md-icon md-font-set="fa"> face </md-icon>`
  28326. * will render as
  28327. * `<span class="fa"> face </span>`
  28328. *
  28329. * @param {string} name of the font-library style that should be applied to the md-icon DOM element
  28330. *
  28331. * @usage
  28332. * <hljs lang="js">
  28333. * app.config(function($mdIconProvider) {
  28334. * $mdIconProvider.defaultFontSet( 'fa' );
  28335. * });
  28336. * </hljs>
  28337. *
  28338. */
  28339. /**
  28340. * @ngdoc method
  28341. * @name $mdIconProvider#fontSet
  28342. *
  28343. * @description
  28344. * When using a font set for `<md-icon>` you must specify the correct font classname in the `md-font-set`
  28345. * attribute. If the fonset className is really long, your markup may become cluttered... an easy
  28346. * solution is to define an `alias` for your fontset:
  28347. *
  28348. * @param {string} alias of the specified fontset.
  28349. * @param {string} className of the fontset.
  28350. *
  28351. * @usage
  28352. * <hljs lang="js">
  28353. * app.config(function($mdIconProvider) {
  28354. * // In this case, we set an alias for the `material-icons` fontset.
  28355. * $mdIconProvider.fontSet('md', 'material-icons');
  28356. * });
  28357. * </hljs>
  28358. *
  28359. */
  28360. /**
  28361. * @ngdoc method
  28362. * @name $mdIconProvider#defaultViewBoxSize
  28363. *
  28364. * @description
  28365. * While `<md-icon />` markup can also be style with sizing CSS, this method configures
  28366. * the default width **and** height used for all icons; unless overridden by specific CSS.
  28367. * The default sizing is (24px, 24px).
  28368. * @param {number=} viewBoxSize Sets the width and height of the viewBox for an icon or an icon set.
  28369. * All icons in a set should be the same size. The default value is 24.
  28370. *
  28371. * @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
  28372. *
  28373. * @usage
  28374. * <hljs lang="js">
  28375. * app.config(function($mdIconProvider) {
  28376. *
  28377. * // Configure URLs for icons specified by [set:]id.
  28378. *
  28379. * $mdIconProvider
  28380. * .defaultViewBoxSize(36) // Register a default icon size (width == height)
  28381. * });
  28382. * </hljs>
  28383. *
  28384. */
  28385. var config = {
  28386. defaultViewBoxSize: 24,
  28387. defaultFontSet: 'material-icons',
  28388. fontSets: []
  28389. };
  28390. function MdIconProvider() {
  28391. }
  28392. MdIconProvider.prototype = {
  28393. icon: function(id, url, viewBoxSize) {
  28394. if (id.indexOf(':') == -1) id = '$default:' + id;
  28395. config[id] = new ConfigurationItem(url, viewBoxSize);
  28396. return this;
  28397. },
  28398. iconSet: function(id, url, viewBoxSize) {
  28399. config[id] = new ConfigurationItem(url, viewBoxSize);
  28400. return this;
  28401. },
  28402. defaultIconSet: function(url, viewBoxSize) {
  28403. var setName = '$default';
  28404. if (!config[setName]) {
  28405. config[setName] = new ConfigurationItem(url, viewBoxSize);
  28406. }
  28407. config[setName].viewBoxSize = viewBoxSize || config.defaultViewBoxSize;
  28408. return this;
  28409. },
  28410. defaultViewBoxSize: function(viewBoxSize) {
  28411. config.defaultViewBoxSize = viewBoxSize;
  28412. return this;
  28413. },
  28414. /**
  28415. * Register an alias name associated with a font-icon library style ;
  28416. */
  28417. fontSet: function fontSet(alias, className) {
  28418. config.fontSets.push({
  28419. alias: alias,
  28420. fontSet: className || alias
  28421. });
  28422. return this;
  28423. },
  28424. /**
  28425. * Specify a default style name associated with a font-icon library
  28426. * fallback to Material Icons.
  28427. *
  28428. */
  28429. defaultFontSet: function defaultFontSet(className) {
  28430. config.defaultFontSet = !className ? '' : className;
  28431. return this;
  28432. },
  28433. defaultIconSize: function defaultIconSize(iconSize) {
  28434. config.defaultIconSize = iconSize;
  28435. return this;
  28436. },
  28437. $get: ['$templateRequest', '$q', '$log', '$mdUtil', '$sce', function($templateRequest, $q, $log, $mdUtil, $sce) {
  28438. return MdIconService(config, $templateRequest, $q, $log, $mdUtil, $sce);
  28439. }]
  28440. };
  28441. /**
  28442. * Configuration item stored in the Icon registry; used for lookups
  28443. * to load if not already cached in the `loaded` cache
  28444. */
  28445. function ConfigurationItem(url, viewBoxSize) {
  28446. this.url = url;
  28447. this.viewBoxSize = viewBoxSize || config.defaultViewBoxSize;
  28448. }
  28449. /**
  28450. * @ngdoc service
  28451. * @name $mdIcon
  28452. * @module material.components.icon
  28453. *
  28454. * @description
  28455. * The `$mdIcon` service is a function used to lookup SVG icons.
  28456. *
  28457. * @param {string} id Query value for a unique Id or URL. If the argument is a URL, then the service will retrieve the icon element
  28458. * from its internal cache or load the icon and cache it first. If the value is not a URL-type string, then an ID lookup is
  28459. * performed. The Id may be a unique icon ID or may include an iconSet ID prefix.
  28460. *
  28461. * For the **id** query to work properly, this means that all id-to-URL mappings must have been previously configured
  28462. * using the `$mdIconProvider`.
  28463. *
  28464. * @returns {angular.$q.Promise} A promise that gets resolved to a clone of the initial SVG DOM element; which was
  28465. * created from the SVG markup in the SVG data file. If an error occurs (e.g. the icon cannot be found) the promise
  28466. * will get rejected.
  28467. *
  28468. * @usage
  28469. * <hljs lang="js">
  28470. * function SomeDirective($mdIcon) {
  28471. *
  28472. * // See if the icon has already been loaded, if not
  28473. * // then lookup the icon from the registry cache, load and cache
  28474. * // it for future requests.
  28475. * // NOTE: ID queries require configuration with $mdIconProvider
  28476. *
  28477. * $mdIcon('android').then(function(iconEl) { element.append(iconEl); });
  28478. * $mdIcon('work:chair').then(function(iconEl) { element.append(iconEl); });
  28479. *
  28480. * // Load and cache the external SVG using a URL
  28481. *
  28482. * $mdIcon('img/icons/android.svg').then(function(iconEl) {
  28483. * element.append(iconEl);
  28484. * });
  28485. * };
  28486. * </hljs>
  28487. *
  28488. * > <b>Note:</b> The `<md-icon>` directive internally uses the `$mdIcon` service to query, loaded,
  28489. * and instantiate SVG DOM elements.
  28490. */
  28491. /* @ngInject */
  28492. function MdIconService(config, $templateRequest, $q, $log, $mdUtil, $sce) {
  28493. var iconCache = {};
  28494. var svgCache = {};
  28495. var urlRegex = /[-\w@:%+.~#?&//=]{2,}\.[a-z]{2,4}\b(\/[-\w@:%+.~#?&//=]*)?/i;
  28496. var dataUrlRegex = /^data:image\/svg\+xml[\s*;\w\-=]*?(base64)?,(.*)$/i;
  28497. Icon.prototype = {clone: cloneSVG, prepare: prepareAndStyle};
  28498. getIcon.fontSet = findRegisteredFontSet;
  28499. // Publish service...
  28500. return getIcon;
  28501. /**
  28502. * Actual $mdIcon service is essentially a lookup function
  28503. */
  28504. function getIcon(id) {
  28505. id = id || '';
  28506. // If the "id" provided is not a string, the only other valid value is a $sce trust wrapper
  28507. // over a URL string. If the value is not trusted, this will intentionally throw an error
  28508. // because the user is attempted to use an unsafe URL, potentially opening themselves up
  28509. // to an XSS attack.
  28510. if (!angular.isString(id)) {
  28511. id = $sce.getTrustedUrl(id);
  28512. }
  28513. // If already loaded and cached, use a clone of the cached icon.
  28514. // Otherwise either load by URL, or lookup in the registry and then load by URL, and cache.
  28515. if (iconCache[id]) {
  28516. return $q.when(transformClone(iconCache[id]));
  28517. }
  28518. if (urlRegex.test(id) || dataUrlRegex.test(id)) {
  28519. return loadByURL(id).then(cacheIcon(id));
  28520. }
  28521. if (id.indexOf(':') == -1) {
  28522. id = '$default:' + id;
  28523. }
  28524. var load = config[id] ? loadByID : loadFromIconSet;
  28525. return load(id)
  28526. .then(cacheIcon(id));
  28527. }
  28528. /**
  28529. * Lookup registered fontSet style using its alias...
  28530. * If not found,
  28531. */
  28532. function findRegisteredFontSet(alias) {
  28533. var useDefault = angular.isUndefined(alias) || !(alias && alias.length);
  28534. if (useDefault) return config.defaultFontSet;
  28535. var result = alias;
  28536. angular.forEach(config.fontSets, function(it) {
  28537. if (it.alias == alias) result = it.fontSet || result;
  28538. });
  28539. return result;
  28540. }
  28541. function transformClone(cacheElement) {
  28542. var clone = cacheElement.clone();
  28543. var cacheSuffix = '_cache' + $mdUtil.nextUid();
  28544. // We need to modify for each cached icon the id attributes.
  28545. // This is needed because SVG id's are treated as normal DOM ids
  28546. // and should not have a duplicated id.
  28547. if (clone.id) clone.id += cacheSuffix;
  28548. angular.forEach(clone.querySelectorAll('[id]'), function(item) {
  28549. item.id += cacheSuffix;
  28550. });
  28551. return clone;
  28552. }
  28553. /**
  28554. * Prepare and cache the loaded icon for the specified `id`
  28555. */
  28556. function cacheIcon(id) {
  28557. return function updateCache(icon) {
  28558. iconCache[id] = isIcon(icon) ? icon : new Icon(icon, config[id]);
  28559. return iconCache[id].clone();
  28560. };
  28561. }
  28562. /**
  28563. * Lookup the configuration in the registry, if !registered throw an error
  28564. * otherwise load the icon [on-demand] using the registered URL.
  28565. *
  28566. */
  28567. function loadByID(id) {
  28568. var iconConfig = config[id];
  28569. return loadByURL(iconConfig.url).then(function(icon) {
  28570. return new Icon(icon, iconConfig);
  28571. });
  28572. }
  28573. /**
  28574. * Loads the file as XML and uses querySelector( <id> ) to find
  28575. * the desired node...
  28576. */
  28577. function loadFromIconSet(id) {
  28578. var setName = id.substring(0, id.lastIndexOf(':')) || '$default';
  28579. var iconSetConfig = config[setName];
  28580. return !iconSetConfig ? announceIdNotFound(id) : loadByURL(iconSetConfig.url).then(extractFromSet);
  28581. function extractFromSet(set) {
  28582. var iconName = id.slice(id.lastIndexOf(':') + 1);
  28583. var icon = set.querySelector('#' + iconName);
  28584. return icon ? new Icon(icon, iconSetConfig) : announceIdNotFound(id);
  28585. }
  28586. function announceIdNotFound(id) {
  28587. var msg = 'icon ' + id + ' not found';
  28588. $log.warn(msg);
  28589. return $q.reject(msg || id);
  28590. }
  28591. }
  28592. /**
  28593. * Load the icon by URL (may use the $templateCache).
  28594. * Extract the data for later conversion to Icon
  28595. */
  28596. function loadByURL(url) {
  28597. /* Load the icon from embedded data URL. */
  28598. function loadByDataUrl(url) {
  28599. var results = dataUrlRegex.exec(url);
  28600. var isBase64 = /base64/i.test(url);
  28601. var data = isBase64 ? window.atob(results[2]) : results[2];
  28602. return $q.when(angular.element(data)[0]);
  28603. }
  28604. /* Load the icon by URL using HTTP. */
  28605. function loadByHttpUrl(url) {
  28606. return $q(function(resolve, reject) {
  28607. // Catch HTTP or generic errors not related to incorrect icon IDs.
  28608. var announceAndReject = function(err) {
  28609. var msg = angular.isString(err) ? err : (err.message || err.data || err.statusText);
  28610. $log.warn(msg);
  28611. reject(err);
  28612. },
  28613. extractSvg = function(response) {
  28614. if (!svgCache[url]) {
  28615. svgCache[url] = angular.element('<div>').append(response)[0].querySelector('svg');
  28616. }
  28617. resolve(svgCache[url]);
  28618. };
  28619. $templateRequest(url, true).then(extractSvg, announceAndReject);
  28620. });
  28621. }
  28622. return dataUrlRegex.test(url)
  28623. ? loadByDataUrl(url)
  28624. : loadByHttpUrl(url);
  28625. }
  28626. /**
  28627. * Check target signature to see if it is an Icon instance.
  28628. */
  28629. function isIcon(target) {
  28630. return angular.isDefined(target.element) && angular.isDefined(target.config);
  28631. }
  28632. /**
  28633. * Define the Icon class
  28634. */
  28635. function Icon(el, config) {
  28636. if (el && el.tagName != 'svg') {
  28637. el = angular.element('<svg xmlns="http://www.w3.org/2000/svg">').append(el.cloneNode(true))[0];
  28638. }
  28639. // Inject the namespace if not available...
  28640. if (!el.getAttribute('xmlns')) {
  28641. el.setAttribute('xmlns', "http://www.w3.org/2000/svg");
  28642. }
  28643. this.element = el;
  28644. this.config = config;
  28645. this.prepare();
  28646. }
  28647. /**
  28648. * Prepare the DOM element that will be cached in the
  28649. * loaded iconCache store.
  28650. */
  28651. function prepareAndStyle() {
  28652. var viewBoxSize = this.config ? this.config.viewBoxSize : config.defaultViewBoxSize;
  28653. angular.forEach({
  28654. 'fit': '',
  28655. 'height': '100%',
  28656. 'width': '100%',
  28657. 'preserveAspectRatio': 'xMidYMid meet',
  28658. 'viewBox': this.element.getAttribute('viewBox') || ('0 0 ' + viewBoxSize + ' ' + viewBoxSize),
  28659. 'focusable': false // Disable IE11s default behavior to make SVGs focusable
  28660. }, function(val, attr) {
  28661. this.element.setAttribute(attr, val);
  28662. }, this);
  28663. }
  28664. /**
  28665. * Clone the Icon DOM element.
  28666. */
  28667. function cloneSVG() {
  28668. // If the element or any of its children have a style attribute, then a CSP policy without
  28669. // 'unsafe-inline' in the style-src directive, will result in a violation.
  28670. return this.element.cloneNode(true);
  28671. }
  28672. }
  28673. })();
  28674. (function(){
  28675. "use strict";
  28676. MenuController.$inject = ["$mdMenu", "$attrs", "$element", "$scope", "$mdUtil", "$timeout", "$rootScope", "$q", "$log"];
  28677. angular
  28678. .module('material.components.menu')
  28679. .controller('mdMenuCtrl', MenuController);
  28680. /**
  28681. * @ngInject
  28682. */
  28683. function MenuController($mdMenu, $attrs, $element, $scope, $mdUtil, $timeout, $rootScope, $q, $log) {
  28684. var prefixer = $mdUtil.prefixer();
  28685. var menuContainer;
  28686. var self = this;
  28687. var triggerElement;
  28688. this.nestLevel = parseInt($attrs.mdNestLevel, 10) || 0;
  28689. /**
  28690. * Called by our linking fn to provide access to the menu-content
  28691. * element removed during link
  28692. */
  28693. this.init = function init(setMenuContainer, opts) {
  28694. opts = opts || {};
  28695. menuContainer = setMenuContainer;
  28696. // Default element for ARIA attributes has the ngClick or ngMouseenter expression
  28697. triggerElement = $element[0].querySelector(prefixer.buildSelector(['ng-click', 'ng-mouseenter']));
  28698. triggerElement.setAttribute('aria-expanded', 'false');
  28699. this.isInMenuBar = opts.isInMenuBar;
  28700. this.nestedMenus = $mdUtil.nodesToArray(menuContainer[0].querySelectorAll('.md-nested-menu'));
  28701. menuContainer.on('$mdInterimElementRemove', function() {
  28702. self.isOpen = false;
  28703. $mdUtil.nextTick(function(){ self.onIsOpenChanged(self.isOpen);});
  28704. });
  28705. $mdUtil.nextTick(function(){ self.onIsOpenChanged(self.isOpen);});
  28706. var menuContainerId = 'menu_container_' + $mdUtil.nextUid();
  28707. menuContainer.attr('id', menuContainerId);
  28708. angular.element(triggerElement).attr({
  28709. 'aria-owns': menuContainerId,
  28710. 'aria-haspopup': 'true'
  28711. });
  28712. $scope.$on('$destroy', angular.bind(this, function() {
  28713. this.disableHoverListener();
  28714. $mdMenu.destroy();
  28715. }));
  28716. menuContainer.on('$destroy', function() {
  28717. $mdMenu.destroy();
  28718. });
  28719. };
  28720. var openMenuTimeout, menuItems, deregisterScopeListeners = [];
  28721. this.enableHoverListener = function() {
  28722. deregisterScopeListeners.push($rootScope.$on('$mdMenuOpen', function(event, el) {
  28723. if (menuContainer[0].contains(el[0])) {
  28724. self.currentlyOpenMenu = el.controller('mdMenu');
  28725. self.isAlreadyOpening = false;
  28726. self.currentlyOpenMenu.registerContainerProxy(self.triggerContainerProxy.bind(self));
  28727. }
  28728. }));
  28729. deregisterScopeListeners.push($rootScope.$on('$mdMenuClose', function(event, el) {
  28730. if (menuContainer[0].contains(el[0])) {
  28731. self.currentlyOpenMenu = undefined;
  28732. }
  28733. }));
  28734. menuItems = angular.element($mdUtil.nodesToArray(menuContainer[0].children[0].children));
  28735. menuItems.on('mouseenter', self.handleMenuItemHover);
  28736. menuItems.on('mouseleave', self.handleMenuItemMouseLeave);
  28737. };
  28738. this.disableHoverListener = function() {
  28739. while (deregisterScopeListeners.length) {
  28740. deregisterScopeListeners.shift()();
  28741. }
  28742. menuItems && menuItems.off('mouseenter', self.handleMenuItemHover);
  28743. menuItems && menuItems.off('mouseleave', self.handleMenuItemMouseLeave);
  28744. };
  28745. this.handleMenuItemHover = function(event) {
  28746. if (self.isAlreadyOpening) return;
  28747. var nestedMenu = (
  28748. event.target.querySelector('md-menu')
  28749. || $mdUtil.getClosest(event.target, 'MD-MENU')
  28750. );
  28751. openMenuTimeout = $timeout(function() {
  28752. if (nestedMenu) {
  28753. nestedMenu = angular.element(nestedMenu).controller('mdMenu');
  28754. }
  28755. if (self.currentlyOpenMenu && self.currentlyOpenMenu != nestedMenu) {
  28756. var closeTo = self.nestLevel + 1;
  28757. self.currentlyOpenMenu.close(true, { closeTo: closeTo });
  28758. self.isAlreadyOpening = !!nestedMenu;
  28759. nestedMenu && nestedMenu.open();
  28760. } else if (nestedMenu && !nestedMenu.isOpen && nestedMenu.open) {
  28761. self.isAlreadyOpening = !!nestedMenu;
  28762. nestedMenu && nestedMenu.open();
  28763. }
  28764. }, nestedMenu ? 100 : 250);
  28765. var focusableTarget = event.currentTarget.querySelector('.md-button:not([disabled])');
  28766. focusableTarget && focusableTarget.focus();
  28767. };
  28768. this.handleMenuItemMouseLeave = function() {
  28769. if (openMenuTimeout) {
  28770. $timeout.cancel(openMenuTimeout);
  28771. openMenuTimeout = undefined;
  28772. }
  28773. };
  28774. /**
  28775. * Uses the $mdMenu interim element service to open the menu contents
  28776. */
  28777. this.open = function openMenu(ev) {
  28778. ev && ev.stopPropagation();
  28779. ev && ev.preventDefault();
  28780. if (self.isOpen) return;
  28781. self.enableHoverListener();
  28782. self.isOpen = true;
  28783. $mdUtil.nextTick(function(){ self.onIsOpenChanged(self.isOpen);});
  28784. triggerElement = triggerElement || (ev ? ev.target : $element[0]);
  28785. triggerElement.setAttribute('aria-expanded', 'true');
  28786. $scope.$emit('$mdMenuOpen', $element);
  28787. $mdMenu.show({
  28788. scope: $scope,
  28789. mdMenuCtrl: self,
  28790. nestLevel: self.nestLevel,
  28791. element: menuContainer,
  28792. target: triggerElement,
  28793. preserveElement: true,
  28794. parent: 'body'
  28795. }).finally(function() {
  28796. triggerElement.setAttribute('aria-expanded', 'false');
  28797. self.disableHoverListener();
  28798. });
  28799. };
  28800. this.onIsOpenChanged = function(isOpen) {
  28801. if (isOpen) {
  28802. menuContainer.attr('aria-hidden', 'false');
  28803. $element[0].classList.add('md-open');
  28804. angular.forEach(self.nestedMenus, function(el) {
  28805. el.classList.remove('md-open');
  28806. });
  28807. } else {
  28808. menuContainer.attr('aria-hidden', 'true');
  28809. $element[0].classList.remove('md-open');
  28810. }
  28811. $scope.$mdMenuIsOpen = self.isOpen;
  28812. };
  28813. this.focusMenuContainer = function focusMenuContainer() {
  28814. var focusTarget = menuContainer[0]
  28815. .querySelector(prefixer.buildSelector(['md-menu-focus-target', 'md-autofocus']));
  28816. if (!focusTarget) focusTarget = menuContainer[0].querySelector('.md-button:not([disabled])');
  28817. focusTarget.focus();
  28818. };
  28819. this.registerContainerProxy = function registerContainerProxy(handler) {
  28820. this.containerProxy = handler;
  28821. };
  28822. this.triggerContainerProxy = function triggerContainerProxy(ev) {
  28823. this.containerProxy && this.containerProxy(ev);
  28824. };
  28825. this.destroy = function() {
  28826. return self.isOpen ? $mdMenu.destroy() : $q.when(false);
  28827. };
  28828. // Use the $mdMenu interim element service to close the menu contents
  28829. this.close = function closeMenu(skipFocus, closeOpts) {
  28830. if ( !self.isOpen ) return;
  28831. self.isOpen = false;
  28832. $mdUtil.nextTick(function(){ self.onIsOpenChanged(self.isOpen);});
  28833. var eventDetails = angular.extend({}, closeOpts, { skipFocus: skipFocus });
  28834. $scope.$emit('$mdMenuClose', $element, eventDetails);
  28835. $mdMenu.hide(null, closeOpts);
  28836. if (!skipFocus) {
  28837. var el = self.restoreFocusTo || $element.find('button')[0];
  28838. if (el instanceof angular.element) el = el[0];
  28839. if (el) el.focus();
  28840. }
  28841. };
  28842. /**
  28843. * Build a nice object out of our string attribute which specifies the
  28844. * target mode for left and top positioning
  28845. */
  28846. this.positionMode = function positionMode() {
  28847. var attachment = ($attrs.mdPositionMode || 'target').split(' ');
  28848. // If attachment is a single item, duplicate it for our second value.
  28849. // ie. 'target' -> 'target target'
  28850. if (attachment.length === 1) {
  28851. attachment.push(attachment[0]);
  28852. }
  28853. return {
  28854. left: attachment[0],
  28855. top: attachment[1]
  28856. };
  28857. };
  28858. /**
  28859. * Build a nice object out of our string attribute which specifies
  28860. * the offset of top and left in pixels.
  28861. */
  28862. this.offsets = function offsets() {
  28863. var position = ($attrs.mdOffset || '0 0').split(' ').map(parseFloat);
  28864. if (position.length === 2) {
  28865. return {
  28866. left: position[0],
  28867. top: position[1]
  28868. };
  28869. } else if (position.length === 1) {
  28870. return {
  28871. top: position[0],
  28872. left: position[0]
  28873. };
  28874. } else {
  28875. throw Error('Invalid offsets specified. Please follow format <x, y> or <n>');
  28876. }
  28877. };
  28878. // Functionality that is exposed in the view.
  28879. $scope.$mdMenu = {
  28880. open: this.open,
  28881. close: this.close
  28882. };
  28883. // Deprecated APIs
  28884. $scope.$mdOpenMenu = angular.bind(this, function() {
  28885. $log.warn('mdMenu: The $mdOpenMenu method is deprecated. Please use `$mdMenu.open`.');
  28886. return this.open.apply(this, arguments);
  28887. });
  28888. }
  28889. })();
  28890. (function(){
  28891. "use strict";
  28892. /**
  28893. * @ngdoc directive
  28894. * @name mdMenu
  28895. * @module material.components.menu
  28896. * @restrict E
  28897. * @description
  28898. *
  28899. * Menus are elements that open when clicked. They are useful for displaying
  28900. * additional options within the context of an action.
  28901. *
  28902. * Every `md-menu` must specify exactly two child elements. The first element is what is
  28903. * left in the DOM and is used to open the menu. This element is called the trigger element.
  28904. * The trigger element's scope has access to `$mdMenu.open($event)`
  28905. * which it may call to open the menu. By passing $event as argument, the
  28906. * corresponding event is stopped from propagating up the DOM-tree. Similarly, `$mdMenu.close()`
  28907. * can be used to close the menu.
  28908. *
  28909. * The second element is the `md-menu-content` element which represents the
  28910. * contents of the menu when it is open. Typically this will contain `md-menu-item`s,
  28911. * but you can do custom content as well.
  28912. *
  28913. * <hljs lang="html">
  28914. * <md-menu>
  28915. * <!-- Trigger element is a md-button with an icon -->
  28916. * <md-button ng-click="$mdMenu.open($event)" class="md-icon-button" aria-label="Open sample menu">
  28917. * <md-icon md-svg-icon="call:phone"></md-icon>
  28918. * </md-button>
  28919. * <md-menu-content>
  28920. * <md-menu-item><md-button ng-click="doSomething()">Do Something</md-button></md-menu-item>
  28921. * </md-menu-content>
  28922. * </md-menu>
  28923. * </hljs>
  28924. * ## Sizing Menus
  28925. *
  28926. * The width of the menu when it is open may be specified by specifying a `width`
  28927. * attribute on the `md-menu-content` element.
  28928. * See the [Material Design Spec](https://material.io/guidelines/components/menus.html#menus-simple-menus)
  28929. * for more information.
  28930. *
  28931. *
  28932. * ## Aligning Menus
  28933. *
  28934. * When a menu opens, it is important that the content aligns with the trigger element.
  28935. * Failure to align menus can result in jarring experiences for users as content
  28936. * suddenly shifts. To help with this, `md-menu` provides several APIs to help
  28937. * with alignment.
  28938. *
  28939. * ### Target Mode
  28940. *
  28941. * By default, `md-menu` will attempt to align the `md-menu-content` by aligning
  28942. * designated child elements in both the trigger and the menu content.
  28943. *
  28944. * To specify the alignment element in the `trigger` you can use the `md-menu-origin`
  28945. * attribute on a child element. If no `md-menu-origin` is specified, the `md-menu`
  28946. * will be used as the origin element.
  28947. *
  28948. * Similarly, the `md-menu-content` may specify a `md-menu-align-target` for a
  28949. * `md-menu-item` to specify the node that it should try and align with.
  28950. *
  28951. * In this example code, we specify an icon to be our origin element, and an
  28952. * icon in our menu content to be our alignment target. This ensures that both
  28953. * icons are aligned when the menu opens.
  28954. *
  28955. * <hljs lang="html">
  28956. * <md-menu>
  28957. * <md-button ng-click="$mdMenu.open($event)" class="md-icon-button" aria-label="Open some menu">
  28958. * <md-icon md-menu-origin md-svg-icon="call:phone"></md-icon>
  28959. * </md-button>
  28960. * <md-menu-content>
  28961. * <md-menu-item>
  28962. * <md-button ng-click="doSomething()" aria-label="Do something">
  28963. * <md-icon md-menu-align-target md-svg-icon="call:phone"></md-icon>
  28964. * Do Something
  28965. * </md-button>
  28966. * </md-menu-item>
  28967. * </md-menu-content>
  28968. * </md-menu>
  28969. * </hljs>
  28970. *
  28971. * ### Position Mode
  28972. *
  28973. * We can specify the origin of the menu by using the `md-position-mode` attribute.
  28974. * This attribute allows specifying the positioning by the `x` and `y` axes.
  28975. *
  28976. * The default mode is `target target`. This mode uses the left and top edges of the origin element
  28977. * to position the menu in LTR layouts. The `x` axis modes will adjust when in RTL layouts.
  28978. *
  28979. * Sometimes you want to specify alignment from the right side of a origin element. For example,
  28980. * if we have a menu on the right side a toolbar, we may want to right align our menu content.
  28981. * We can use `target-right target` to specify a right-oriented alignment target.
  28982. * There is a working example of this in the Menu Position Modes demo.
  28983. *
  28984. * #### Horizontal Positioning Options
  28985. * - `target`
  28986. * - `target-left`
  28987. * - `target-right`
  28988. * - `cascade`
  28989. * - `right`
  28990. * - `left`
  28991. *
  28992. * #### Vertical Positioning Options
  28993. * - `target`
  28994. * - `cascade`
  28995. * - `bottom`
  28996. *
  28997. * ### Menu Offsets
  28998. *
  28999. * It is sometimes unavoidable to need to have a deeper level of control for
  29000. * the positioning of a menu to ensure perfect alignment. `md-menu` provides
  29001. * the `md-offset` attribute to allow pixel-level specificity when adjusting
  29002. * menu positioning.
  29003. *
  29004. * This offset is provided in the format of `x y` or `n` where `n` will be used
  29005. * in both the `x` and `y` axis.
  29006. * For example, to move a menu by `2px` down from the top, we can use:
  29007. *
  29008. * <hljs lang="html">
  29009. * <md-menu md-offset="0 2">
  29010. * <!-- menu-content -->
  29011. * </md-menu>
  29012. * </hljs>
  29013. *
  29014. * Specifying `md-offset="2 2"` would shift the menu two pixels down and two pixels to the right.
  29015. *
  29016. * ### Auto Focus
  29017. * By default, when a menu opens, `md-menu` focuses the first button in the menu content.
  29018. *
  29019. * Sometimes you would like to focus another menu item instead of the first.<br/>
  29020. * This can be done by applying the `md-autofocus` directive on the given element.
  29021. *
  29022. * <hljs lang="html">
  29023. * <md-menu-item>
  29024. * <md-button md-autofocus ng-click="doSomething()">
  29025. * Auto Focus
  29026. * </md-button>
  29027. * </md-menu-item>
  29028. * </hljs>
  29029. *
  29030. *
  29031. * ### Preventing close
  29032. *
  29033. * Sometimes you would like to be able to click on a menu item without having the menu
  29034. * close. To do this, AngularJS Material exposes the `md-prevent-menu-close` attribute which
  29035. * can be added to a button inside a menu to stop the menu from automatically closing.
  29036. * You can then close the menu either by using `$mdMenu.close()` in the template,
  29037. * or programmatically by injecting `$mdMenu` and calling `$mdMenu.hide()`.
  29038. *
  29039. * <hljs lang="html">
  29040. * <md-menu-content ng-mouseleave="$mdMenu.close()">
  29041. * <md-menu-item>
  29042. * <md-button ng-click="doSomething()" aria-label="Do something" md-prevent-menu-close="md-prevent-menu-close">
  29043. * <md-icon md-menu-align-target md-svg-icon="call:phone"></md-icon>
  29044. * Do Something
  29045. * </md-button>
  29046. * </md-menu-item>
  29047. * </md-menu-content>
  29048. * </hljs>
  29049. *
  29050. * @usage
  29051. * <hljs lang="html">
  29052. * <md-menu>
  29053. * <md-button ng-click="$mdMenu.open($event)" class="md-icon-button">
  29054. * <md-icon md-svg-icon="call:phone"></md-icon>
  29055. * </md-button>
  29056. * <md-menu-content>
  29057. * <md-menu-item><md-button ng-click="doSomething()">Do Something</md-button></md-menu-item>
  29058. * </md-menu-content>
  29059. * </md-menu>
  29060. * </hljs>
  29061. *
  29062. * @param {string=} md-position-mode Specify pre-defined position modes for the `x` and `y` axes.
  29063. * The default modes are `target target`. This positions the origin of the menu using the left and top edges
  29064. * of the origin element in LTR layouts.<br>
  29065. * #### Valid modes for horizontal positioning
  29066. * - `target`
  29067. * - `target-left`
  29068. * - `target-right`
  29069. * - `cascade`
  29070. * - `right`
  29071. * - `left`<br>
  29072. * #### Valid modes for vertical positioning
  29073. * - `target`
  29074. * - `cascade`
  29075. * - `bottom`
  29076. * @param {string=} md-offset An offset to apply to the dropdown on opening, after positioning.
  29077. * Defined as `x` and `y` pixel offset values in the form of `x y`.<br>
  29078. * The default value is `0 0`.
  29079. */
  29080. MenuDirective.$inject = ["$mdUtil"];
  29081. angular
  29082. .module('material.components.menu')
  29083. .directive('mdMenu', MenuDirective);
  29084. /**
  29085. * @ngInject
  29086. */
  29087. function MenuDirective($mdUtil) {
  29088. var INVALID_PREFIX = 'Invalid HTML for md-menu: ';
  29089. return {
  29090. restrict: 'E',
  29091. require: ['mdMenu', '?^mdMenuBar'],
  29092. controller: 'mdMenuCtrl', // empty function to be built by link
  29093. scope: true,
  29094. compile: compile
  29095. };
  29096. function compile(templateElement) {
  29097. templateElement.addClass('md-menu');
  29098. var triggerEl = templateElement.children()[0];
  29099. var prefixer = $mdUtil.prefixer();
  29100. if (!prefixer.hasAttribute(triggerEl, 'ng-click')) {
  29101. triggerEl = triggerEl
  29102. .querySelector(prefixer.buildSelector(['ng-click', 'ng-mouseenter'])) || triggerEl;
  29103. }
  29104. var isButtonTrigger = triggerEl.nodeName === 'MD-BUTTON' || triggerEl.nodeName === 'BUTTON';
  29105. if (triggerEl && isButtonTrigger && !triggerEl.hasAttribute('type')) {
  29106. triggerEl.setAttribute('type', 'button');
  29107. }
  29108. if (!triggerEl) {
  29109. throw Error(INVALID_PREFIX + 'Expected the menu to have a trigger element.');
  29110. }
  29111. if (templateElement.children().length !== 2) {
  29112. throw Error(INVALID_PREFIX + 'Expected two children elements. The second element must have a `md-menu-content` element.');
  29113. }
  29114. // Default element for ARIA attributes has the ngClick or ngMouseenter expression
  29115. triggerEl && triggerEl.setAttribute('aria-haspopup', 'true');
  29116. var nestedMenus = templateElement[0].querySelectorAll('md-menu');
  29117. var nestingDepth = parseInt(templateElement[0].getAttribute('md-nest-level'), 10) || 0;
  29118. if (nestedMenus) {
  29119. angular.forEach($mdUtil.nodesToArray(nestedMenus), function(menuEl) {
  29120. if (!menuEl.hasAttribute('md-position-mode')) {
  29121. menuEl.setAttribute('md-position-mode', 'cascade');
  29122. }
  29123. menuEl.classList.add('_md-nested-menu');
  29124. menuEl.setAttribute('md-nest-level', nestingDepth + 1);
  29125. });
  29126. }
  29127. return link;
  29128. }
  29129. function link(scope, element, attr, ctrls) {
  29130. var mdMenuCtrl = ctrls[0];
  29131. var isInMenuBar = !!ctrls[1];
  29132. // Move everything into a md-menu-container and pass it to the controller
  29133. var menuContainer = angular.element( '<div class="_md md-open-menu-container md-whiteframe-z2"></div>');
  29134. var menuContents = element.children()[1];
  29135. element.addClass('_md'); // private md component indicator for styling
  29136. if (!menuContents.hasAttribute('role')) {
  29137. menuContents.setAttribute('role', 'menu');
  29138. }
  29139. menuContainer.append(menuContents);
  29140. element.on('$destroy', function() {
  29141. menuContainer.remove();
  29142. });
  29143. element.append(menuContainer);
  29144. menuContainer[0].style.display = 'none';
  29145. mdMenuCtrl.init(menuContainer, { isInMenuBar: isInMenuBar });
  29146. }
  29147. }
  29148. })();
  29149. (function(){
  29150. "use strict";
  29151. MenuProvider.$inject = ["$$interimElementProvider"];angular
  29152. .module('material.components.menu')
  29153. .provider('$mdMenu', MenuProvider);
  29154. /*
  29155. * Interim element provider for the menu.
  29156. * Handles behavior for a menu while it is open, including:
  29157. * - handling animating the menu opening/closing
  29158. * - handling key/mouse events on the menu element
  29159. * - handling enabling/disabling scroll while the menu is open
  29160. * - handling redrawing during resizes and orientation changes
  29161. *
  29162. */
  29163. function MenuProvider($$interimElementProvider) {
  29164. menuDefaultOptions.$inject = ["$mdUtil", "$mdTheming", "$mdConstant", "$document", "$window", "$q", "$$rAF", "$animateCss", "$animate", "$log"];
  29165. var MENU_EDGE_MARGIN = 8;
  29166. return $$interimElementProvider('$mdMenu')
  29167. .setDefaults({
  29168. methods: ['target'],
  29169. options: menuDefaultOptions
  29170. });
  29171. /* @ngInject */
  29172. function menuDefaultOptions($mdUtil, $mdTheming, $mdConstant, $document, $window, $q, $$rAF,
  29173. $animateCss, $animate, $log) {
  29174. var prefixer = $mdUtil.prefixer();
  29175. var animator = $mdUtil.dom.animator;
  29176. return {
  29177. parent: 'body',
  29178. onShow: onShow,
  29179. onRemove: onRemove,
  29180. hasBackdrop: true,
  29181. disableParentScroll: true,
  29182. skipCompile: true,
  29183. preserveScope: true,
  29184. multiple: true,
  29185. themable: true
  29186. };
  29187. /**
  29188. * Show modal backdrop element...
  29189. * @returns {function(): void} A function that removes this backdrop
  29190. */
  29191. function showBackdrop(scope, element, options) {
  29192. if (options.nestLevel) return angular.noop;
  29193. // If we are not within a dialog...
  29194. if (options.disableParentScroll && !$mdUtil.getClosest(options.target, 'MD-DIALOG')) {
  29195. // !! DO this before creating the backdrop; since disableScrollAround()
  29196. // configures the scroll offset; which is used by mdBackDrop postLink()
  29197. options.restoreScroll = $mdUtil.disableScrollAround(options.element, options.parent);
  29198. } else {
  29199. options.disableParentScroll = false;
  29200. }
  29201. if (options.hasBackdrop) {
  29202. options.backdrop = $mdUtil.createBackdrop(scope, "md-menu-backdrop md-click-catcher");
  29203. $animate.enter(options.backdrop, $document[0].body);
  29204. }
  29205. /**
  29206. * Hide and destroys the backdrop created by showBackdrop()
  29207. */
  29208. return function hideBackdrop() {
  29209. if (options.backdrop) options.backdrop.remove();
  29210. if (options.disableParentScroll) options.restoreScroll();
  29211. };
  29212. }
  29213. /**
  29214. * Removing the menu element from the DOM and remove all associated event listeners
  29215. * and backdrop
  29216. */
  29217. function onRemove(scope, element, opts) {
  29218. opts.cleanupInteraction();
  29219. opts.cleanupBackdrop();
  29220. opts.cleanupResizing();
  29221. opts.hideBackdrop();
  29222. // Before the menu is closing remove the clickable class.
  29223. element.removeClass('md-clickable');
  29224. // For navigation $destroy events, do a quick, non-animated removal,
  29225. // but for normal closes (from clicks, etc) animate the removal
  29226. return (opts.$destroy === true) ? detachAndClean() : animateRemoval().then( detachAndClean );
  29227. /**
  29228. * For normal closes, animate the removal.
  29229. * For forced closes (like $destroy events), skip the animations
  29230. */
  29231. function animateRemoval() {
  29232. return $animateCss(element, {addClass: 'md-leave'}).start();
  29233. }
  29234. /**
  29235. * Detach the element
  29236. */
  29237. function detachAndClean() {
  29238. element.removeClass('md-active');
  29239. detachElement(element, opts);
  29240. opts.alreadyOpen = false;
  29241. }
  29242. }
  29243. /**
  29244. * Inserts and configures the staged Menu element into the DOM, positioning it,
  29245. * and wiring up various interaction events
  29246. */
  29247. function onShow(scope, element, opts) {
  29248. sanitizeAndConfigure(opts);
  29249. if (opts.menuContentEl[0]) {
  29250. // Inherit the theme from the target element.
  29251. $mdTheming.inherit(opts.menuContentEl, opts.target);
  29252. } else {
  29253. $log.warn(
  29254. '$mdMenu: Menu elements should always contain a `md-menu-content` element,' +
  29255. 'otherwise interactivity features will not work properly.',
  29256. element
  29257. );
  29258. }
  29259. // Register various listeners to move menu on resize/orientation change
  29260. opts.cleanupResizing = startRepositioningOnResize();
  29261. opts.hideBackdrop = showBackdrop(scope, element, opts);
  29262. // Return the promise for when our menu is done animating in
  29263. return showMenu()
  29264. .then(function(response) {
  29265. opts.alreadyOpen = true;
  29266. opts.cleanupInteraction = activateInteraction();
  29267. opts.cleanupBackdrop = setupBackdrop();
  29268. // Since the menu finished its animation, mark the menu as clickable.
  29269. element.addClass('md-clickable');
  29270. return response;
  29271. });
  29272. /**
  29273. * Place the menu into the DOM and call positioning related functions
  29274. */
  29275. function showMenu() {
  29276. opts.parent.append(element);
  29277. element[0].style.display = '';
  29278. return $q(function(resolve) {
  29279. var position = calculateMenuPosition(element, opts);
  29280. element.removeClass('md-leave');
  29281. // Animate the menu scaling, and opacity [from its position origin (default == top-left)]
  29282. // to normal scale.
  29283. $animateCss(element, {
  29284. addClass: 'md-active',
  29285. from: animator.toCss(position),
  29286. to: animator.toCss({transform: ''})
  29287. })
  29288. .start()
  29289. .then(resolve);
  29290. });
  29291. }
  29292. /**
  29293. * Check for valid opts and set some sane defaults
  29294. */
  29295. function sanitizeAndConfigure() {
  29296. if (!opts.target) {
  29297. throw Error(
  29298. '$mdMenu.show() expected a target to animate from in options.target'
  29299. );
  29300. }
  29301. angular.extend(opts, {
  29302. alreadyOpen: false,
  29303. isRemoved: false,
  29304. target: angular.element(opts.target), //make sure it's not a naked dom node
  29305. parent: angular.element(opts.parent),
  29306. menuContentEl: angular.element(element[0].querySelector('md-menu-content'))
  29307. });
  29308. }
  29309. /**
  29310. * Configure various resize listeners for screen changes
  29311. */
  29312. function startRepositioningOnResize() {
  29313. var repositionMenu = (function(target, options) {
  29314. return $$rAF.throttle(function() {
  29315. if (opts.isRemoved) return;
  29316. var position = calculateMenuPosition(target, options);
  29317. target.css(animator.toCss(position));
  29318. });
  29319. })(element, opts);
  29320. $window.addEventListener('resize', repositionMenu);
  29321. $window.addEventListener('orientationchange', repositionMenu);
  29322. return function stopRepositioningOnResize() {
  29323. // Disable resizing handlers
  29324. $window.removeEventListener('resize', repositionMenu);
  29325. $window.removeEventListener('orientationchange', repositionMenu);
  29326. };
  29327. }
  29328. /**
  29329. * Sets up the backdrop and listens for click elements.
  29330. * Once the backdrop will be clicked, the menu will automatically close.
  29331. * @returns {!Function} Function to remove the backdrop.
  29332. */
  29333. function setupBackdrop() {
  29334. if (!opts.backdrop) return angular.noop;
  29335. opts.backdrop.on('click', onBackdropClick);
  29336. return function() {
  29337. opts.backdrop.off('click', onBackdropClick);
  29338. };
  29339. }
  29340. /**
  29341. * Function to be called whenever the backdrop is clicked.
  29342. * @param {!MouseEvent} event
  29343. */
  29344. function onBackdropClick(event) {
  29345. event.preventDefault();
  29346. event.stopPropagation();
  29347. scope.$apply(function() {
  29348. opts.mdMenuCtrl.close(true, { closeAll: true });
  29349. });
  29350. }
  29351. /**
  29352. * Activate interaction on the menu. Resolves the focus target and closes the menu on
  29353. * escape or option click.
  29354. * @returns {!Function} Function to deactivate the interaction listeners.
  29355. */
  29356. function activateInteraction() {
  29357. if (!opts.menuContentEl[0]) return angular.noop;
  29358. // Wire up keyboard listeners.
  29359. // - Close on escape,
  29360. // - focus next item on down arrow,
  29361. // - focus prev item on up
  29362. opts.menuContentEl.on('keydown', onMenuKeyDown);
  29363. opts.menuContentEl[0].addEventListener('click', captureClickListener, true);
  29364. // kick off initial focus in the menu on the first enabled element
  29365. var focusTarget = opts.menuContentEl[0]
  29366. .querySelector(prefixer.buildSelector(['md-menu-focus-target', 'md-autofocus']));
  29367. if ( !focusTarget ) {
  29368. var childrenLen = opts.menuContentEl[0].children.length;
  29369. for(var childIndex = 0; childIndex < childrenLen; childIndex++) {
  29370. var child = opts.menuContentEl[0].children[childIndex];
  29371. focusTarget = child.querySelector('.md-button:not([disabled])');
  29372. if (focusTarget) {
  29373. break;
  29374. }
  29375. if (child.firstElementChild && !child.firstElementChild.disabled) {
  29376. focusTarget = child.firstElementChild;
  29377. break;
  29378. }
  29379. }
  29380. }
  29381. focusTarget && focusTarget.focus();
  29382. return function cleanupInteraction() {
  29383. opts.menuContentEl.off('keydown', onMenuKeyDown);
  29384. opts.menuContentEl[0].removeEventListener('click', captureClickListener, true);
  29385. };
  29386. // ************************************
  29387. // internal functions
  29388. // ************************************
  29389. function onMenuKeyDown(ev) {
  29390. var handled;
  29391. switch (ev.keyCode) {
  29392. case $mdConstant.KEY_CODE.ESCAPE:
  29393. opts.mdMenuCtrl.close(false, { closeAll: true });
  29394. handled = true;
  29395. break;
  29396. case $mdConstant.KEY_CODE.TAB:
  29397. opts.mdMenuCtrl.close(false, { closeAll: true });
  29398. // Don't prevent default or stop propagation on this event as we want tab
  29399. // to move the focus to the next focusable element on the page.
  29400. handled = false;
  29401. break;
  29402. case $mdConstant.KEY_CODE.UP_ARROW:
  29403. if (!focusMenuItem(ev, opts.menuContentEl, opts, -1) && !opts.nestLevel) {
  29404. opts.mdMenuCtrl.triggerContainerProxy(ev);
  29405. }
  29406. handled = true;
  29407. break;
  29408. case $mdConstant.KEY_CODE.DOWN_ARROW:
  29409. if (!focusMenuItem(ev, opts.menuContentEl, opts, 1) && !opts.nestLevel) {
  29410. opts.mdMenuCtrl.triggerContainerProxy(ev);
  29411. }
  29412. handled = true;
  29413. break;
  29414. case $mdConstant.KEY_CODE.LEFT_ARROW:
  29415. if (opts.nestLevel) {
  29416. opts.mdMenuCtrl.close();
  29417. } else {
  29418. opts.mdMenuCtrl.triggerContainerProxy(ev);
  29419. }
  29420. handled = true;
  29421. break;
  29422. case $mdConstant.KEY_CODE.RIGHT_ARROW:
  29423. var parentMenu = $mdUtil.getClosest(ev.target, 'MD-MENU');
  29424. if (parentMenu && parentMenu != opts.parent[0]) {
  29425. ev.target.click();
  29426. } else {
  29427. opts.mdMenuCtrl.triggerContainerProxy(ev);
  29428. }
  29429. handled = true;
  29430. break;
  29431. }
  29432. if (handled) {
  29433. ev.preventDefault();
  29434. ev.stopImmediatePropagation();
  29435. }
  29436. }
  29437. function onBackdropClick(e) {
  29438. e.preventDefault();
  29439. e.stopPropagation();
  29440. scope.$apply(function() {
  29441. opts.mdMenuCtrl.close(true, { closeAll: true });
  29442. });
  29443. }
  29444. // Close menu on menu item click, if said menu-item is not disabled
  29445. function captureClickListener(e) {
  29446. var target = e.target;
  29447. // Traverse up the event until we get to the menuContentEl to see if
  29448. // there is an ng-click and that the ng-click is not disabled
  29449. do {
  29450. if (target == opts.menuContentEl[0]) return;
  29451. if ((hasAnyAttribute(target, ['ng-click', 'ng-href', 'ui-sref']) ||
  29452. target.nodeName == 'BUTTON' || target.nodeName == 'MD-BUTTON') && !hasAnyAttribute(target, ['md-prevent-menu-close'])) {
  29453. var closestMenu = $mdUtil.getClosest(target, 'MD-MENU');
  29454. if (!target.hasAttribute('disabled') && (!closestMenu || closestMenu == opts.parent[0])) {
  29455. close();
  29456. }
  29457. break;
  29458. }
  29459. } while (target = target.parentNode);
  29460. function close() {
  29461. scope.$apply(function() {
  29462. opts.mdMenuCtrl.close(true, { closeAll: true });
  29463. });
  29464. }
  29465. function hasAnyAttribute(target, attrs) {
  29466. if (!target) return false;
  29467. for (var i = 0, attr; attr = attrs[i]; ++i) {
  29468. if (prefixer.hasAttribute(target, attr)) {
  29469. return true;
  29470. }
  29471. }
  29472. return false;
  29473. }
  29474. }
  29475. }
  29476. }
  29477. /**
  29478. * Takes a keypress event and focuses the next/previous menu
  29479. * item from the emitting element
  29480. * @param {event} e - The origin keypress event
  29481. * @param {angular.element} menuEl - The menu element
  29482. * @param {object} opts - The interim element options for the mdMenu
  29483. * @param {number} direction - The direction to move in (+1 = next, -1 = prev)
  29484. */
  29485. function focusMenuItem(e, menuEl, opts, direction) {
  29486. var currentItem = $mdUtil.getClosest(e.target, 'MD-MENU-ITEM');
  29487. var items = $mdUtil.nodesToArray(menuEl[0].children);
  29488. var currentIndex = items.indexOf(currentItem);
  29489. // Traverse through our elements in the specified direction (+/-1) and try to
  29490. // focus them until we find one that accepts focus
  29491. var didFocus;
  29492. for (var i = currentIndex + direction; i >= 0 && i < items.length; i = i + direction) {
  29493. var focusTarget = items[i].querySelector('.md-button');
  29494. didFocus = attemptFocus(focusTarget);
  29495. if (didFocus) {
  29496. break;
  29497. }
  29498. }
  29499. return didFocus;
  29500. }
  29501. /**
  29502. * Attempts to focus an element. Checks whether that element is the currently
  29503. * focused element after attempting.
  29504. * @param {HTMLElement} el - the element to attempt focus on
  29505. * @returns {boolean} - whether the element was successfully focused
  29506. */
  29507. function attemptFocus(el) {
  29508. if (el && el.getAttribute('tabindex') != -1) {
  29509. el.focus();
  29510. return ($document[0].activeElement == el);
  29511. }
  29512. }
  29513. /**
  29514. * Use browser to remove this element without triggering a $destroy event
  29515. */
  29516. function detachElement(element, opts) {
  29517. if (!opts.preserveElement) {
  29518. if (toNode(element).parentNode === toNode(opts.parent)) {
  29519. toNode(opts.parent).removeChild(toNode(element));
  29520. }
  29521. } else {
  29522. toNode(element).style.display = 'none';
  29523. }
  29524. }
  29525. /**
  29526. * Computes menu position and sets the style on the menu container
  29527. * @param {HTMLElement} el - the menu container element
  29528. * @param {object} opts - the interim element options object
  29529. */
  29530. function calculateMenuPosition(el, opts) {
  29531. var containerNode = el[0],
  29532. openMenuNode = el[0].firstElementChild,
  29533. openMenuNodeRect = openMenuNode.getBoundingClientRect(),
  29534. boundryNode = $document[0].body,
  29535. boundryNodeRect = boundryNode.getBoundingClientRect();
  29536. var menuStyle = $window.getComputedStyle(openMenuNode);
  29537. var originNode = opts.target[0].querySelector(prefixer.buildSelector('md-menu-origin')) || opts.target[0],
  29538. originNodeRect = originNode.getBoundingClientRect();
  29539. var bounds = {
  29540. left: boundryNodeRect.left + MENU_EDGE_MARGIN,
  29541. top: Math.max(boundryNodeRect.top, 0) + MENU_EDGE_MARGIN,
  29542. bottom: Math.max(boundryNodeRect.bottom, Math.max(boundryNodeRect.top, 0) + boundryNodeRect.height) - MENU_EDGE_MARGIN,
  29543. right: boundryNodeRect.right - MENU_EDGE_MARGIN
  29544. };
  29545. var alignTarget, alignTargetRect = { top:0, left : 0, right:0, bottom:0 }, existingOffsets = { top:0, left : 0, right:0, bottom:0 };
  29546. var positionMode = opts.mdMenuCtrl.positionMode();
  29547. if (positionMode.top === 'target' || positionMode.left === 'target' || positionMode.left === 'target-right') {
  29548. alignTarget = firstVisibleChild();
  29549. if ( alignTarget ) {
  29550. // TODO: Allow centering on an arbitrary node, for now center on first menu-item's child
  29551. alignTarget = alignTarget.firstElementChild || alignTarget;
  29552. alignTarget = alignTarget.querySelector(prefixer.buildSelector('md-menu-align-target')) || alignTarget;
  29553. alignTargetRect = alignTarget.getBoundingClientRect();
  29554. existingOffsets = {
  29555. top: parseFloat(containerNode.style.top || 0),
  29556. left: parseFloat(containerNode.style.left || 0)
  29557. };
  29558. }
  29559. }
  29560. var position = {};
  29561. var transformOrigin = 'top ';
  29562. switch (positionMode.top) {
  29563. case 'target':
  29564. position.top = existingOffsets.top + originNodeRect.top - alignTargetRect.top;
  29565. break;
  29566. case 'cascade':
  29567. position.top = originNodeRect.top - parseFloat(menuStyle.paddingTop) - originNode.style.top;
  29568. break;
  29569. case 'bottom':
  29570. position.top = originNodeRect.top + originNodeRect.height;
  29571. break;
  29572. default:
  29573. throw new Error('Invalid target mode "' + positionMode.top + '" specified for md-menu on Y axis.');
  29574. }
  29575. var rtl = ($mdUtil.bidi() === 'rtl');
  29576. switch (positionMode.left) {
  29577. case 'target':
  29578. position.left = existingOffsets.left + originNodeRect.left - alignTargetRect.left;
  29579. transformOrigin += rtl ? 'right' : 'left';
  29580. break;
  29581. case 'target-left':
  29582. position.left = originNodeRect.left;
  29583. transformOrigin += 'left';
  29584. break;
  29585. case 'target-right':
  29586. position.left = originNodeRect.right - openMenuNodeRect.width + (openMenuNodeRect.right - alignTargetRect.right);
  29587. transformOrigin += 'right';
  29588. break;
  29589. case 'cascade':
  29590. var willFitRight = rtl ? (originNodeRect.left - openMenuNodeRect.width) < bounds.left : (originNodeRect.right + openMenuNodeRect.width) < bounds.right;
  29591. position.left = willFitRight ? originNodeRect.right - originNode.style.left : originNodeRect.left - originNode.style.left - openMenuNodeRect.width;
  29592. transformOrigin += willFitRight ? 'left' : 'right';
  29593. break;
  29594. case 'right':
  29595. if (rtl) {
  29596. position.left = originNodeRect.right - originNodeRect.width;
  29597. transformOrigin += 'left';
  29598. } else {
  29599. position.left = originNodeRect.right - openMenuNodeRect.width;
  29600. transformOrigin += 'right';
  29601. }
  29602. break;
  29603. case 'left':
  29604. if (rtl) {
  29605. position.left = originNodeRect.right - openMenuNodeRect.width;
  29606. transformOrigin += 'right';
  29607. } else {
  29608. position.left = originNodeRect.left;
  29609. transformOrigin += 'left';
  29610. }
  29611. break;
  29612. default:
  29613. throw new Error('Invalid target mode "' + positionMode.left + '" specified for md-menu on X axis.');
  29614. }
  29615. var offsets = opts.mdMenuCtrl.offsets();
  29616. position.top += offsets.top;
  29617. position.left += offsets.left;
  29618. clamp(position);
  29619. var scaleX = Math.round(100 * Math.min(originNodeRect.width / containerNode.offsetWidth, 1.0)) / 100;
  29620. var scaleY = Math.round(100 * Math.min(originNodeRect.height / containerNode.offsetHeight, 1.0)) / 100;
  29621. return {
  29622. top: Math.round(position.top),
  29623. left: Math.round(position.left),
  29624. // Animate a scale out if we aren't just repositioning
  29625. transform: !opts.alreadyOpen ? $mdUtil.supplant('scale({0},{1})', [scaleX, scaleY]) : undefined,
  29626. transformOrigin: transformOrigin
  29627. };
  29628. /**
  29629. * Clamps the repositioning of the menu within the confines of
  29630. * bounding element (often the screen/body)
  29631. */
  29632. function clamp(pos) {
  29633. pos.top = Math.max(Math.min(pos.top, bounds.bottom - containerNode.offsetHeight), bounds.top);
  29634. pos.left = Math.max(Math.min(pos.left, bounds.right - containerNode.offsetWidth), bounds.left);
  29635. }
  29636. /**
  29637. * Gets the first visible child in the openMenuNode
  29638. * Necessary incase menu nodes are being dynamically hidden
  29639. */
  29640. function firstVisibleChild() {
  29641. for (var i = 0; i < openMenuNode.children.length; ++i) {
  29642. if ($window.getComputedStyle(openMenuNode.children[i]).display != 'none') {
  29643. return openMenuNode.children[i];
  29644. }
  29645. }
  29646. }
  29647. }
  29648. }
  29649. function toNode(el) {
  29650. if (el instanceof angular.element) {
  29651. el = el[0];
  29652. }
  29653. return el;
  29654. }
  29655. }
  29656. })();
  29657. (function(){
  29658. "use strict";
  29659. MenuBarController.$inject = ["$scope", "$rootScope", "$element", "$attrs", "$mdConstant", "$document", "$mdUtil", "$timeout"];
  29660. angular
  29661. .module('material.components.menuBar')
  29662. .controller('MenuBarController', MenuBarController);
  29663. var BOUND_MENU_METHODS = ['handleKeyDown', 'handleMenuHover', 'scheduleOpenHoveredMenu', 'cancelScheduledOpen'];
  29664. /**
  29665. * @ngInject
  29666. */
  29667. function MenuBarController($scope, $rootScope, $element, $attrs, $mdConstant, $document, $mdUtil, $timeout) {
  29668. this.$element = $element;
  29669. this.$attrs = $attrs;
  29670. this.$mdConstant = $mdConstant;
  29671. this.$mdUtil = $mdUtil;
  29672. this.$document = $document;
  29673. this.$scope = $scope;
  29674. this.$rootScope = $rootScope;
  29675. this.$timeout = $timeout;
  29676. var self = this;
  29677. angular.forEach(BOUND_MENU_METHODS, function(methodName) {
  29678. self[methodName] = angular.bind(self, self[methodName]);
  29679. });
  29680. }
  29681. MenuBarController.prototype.init = function() {
  29682. var $element = this.$element;
  29683. var $mdUtil = this.$mdUtil;
  29684. var $scope = this.$scope;
  29685. var self = this;
  29686. var deregisterFns = [];
  29687. $element.on('keydown', this.handleKeyDown);
  29688. this.parentToolbar = $mdUtil.getClosest($element, 'MD-TOOLBAR');
  29689. deregisterFns.push(this.$rootScope.$on('$mdMenuOpen', function(event, el) {
  29690. if (self.getMenus().indexOf(el[0]) != -1) {
  29691. $element[0].classList.add('md-open');
  29692. el[0].classList.add('md-open');
  29693. self.currentlyOpenMenu = el.controller('mdMenu');
  29694. self.currentlyOpenMenu.registerContainerProxy(self.handleKeyDown);
  29695. self.enableOpenOnHover();
  29696. }
  29697. }));
  29698. deregisterFns.push(this.$rootScope.$on('$mdMenuClose', function(event, el, opts) {
  29699. var rootMenus = self.getMenus();
  29700. if (rootMenus.indexOf(el[0]) != -1) {
  29701. $element[0].classList.remove('md-open');
  29702. el[0].classList.remove('md-open');
  29703. }
  29704. if ($element[0].contains(el[0])) {
  29705. var parentMenu = el[0];
  29706. while (parentMenu && rootMenus.indexOf(parentMenu) == -1) {
  29707. parentMenu = $mdUtil.getClosest(parentMenu, 'MD-MENU', true);
  29708. }
  29709. if (parentMenu) {
  29710. if (!opts.skipFocus) parentMenu.querySelector('button:not([disabled])').focus();
  29711. self.currentlyOpenMenu = undefined;
  29712. self.disableOpenOnHover();
  29713. self.setKeyboardMode(true);
  29714. }
  29715. }
  29716. }));
  29717. $scope.$on('$destroy', function() {
  29718. self.disableOpenOnHover();
  29719. while (deregisterFns.length) {
  29720. deregisterFns.shift()();
  29721. }
  29722. });
  29723. this.setKeyboardMode(true);
  29724. };
  29725. MenuBarController.prototype.setKeyboardMode = function(enabled) {
  29726. if (enabled) this.$element[0].classList.add('md-keyboard-mode');
  29727. else this.$element[0].classList.remove('md-keyboard-mode');
  29728. };
  29729. MenuBarController.prototype.enableOpenOnHover = function() {
  29730. if (this.openOnHoverEnabled) return;
  29731. var self = this;
  29732. self.openOnHoverEnabled = true;
  29733. if (self.parentToolbar) {
  29734. self.parentToolbar.classList.add('md-has-open-menu');
  29735. // Needs to be on the next tick so it doesn't close immediately.
  29736. self.$mdUtil.nextTick(function() {
  29737. angular.element(self.parentToolbar).on('click', self.handleParentClick);
  29738. }, false);
  29739. }
  29740. angular
  29741. .element(self.getMenus())
  29742. .on('mouseenter', self.handleMenuHover);
  29743. };
  29744. MenuBarController.prototype.handleMenuHover = function(e) {
  29745. this.setKeyboardMode(false);
  29746. if (this.openOnHoverEnabled) {
  29747. this.scheduleOpenHoveredMenu(e);
  29748. }
  29749. };
  29750. MenuBarController.prototype.disableOpenOnHover = function() {
  29751. if (!this.openOnHoverEnabled) return;
  29752. this.openOnHoverEnabled = false;
  29753. if (this.parentToolbar) {
  29754. this.parentToolbar.classList.remove('md-has-open-menu');
  29755. angular.element(this.parentToolbar).off('click', this.handleParentClick);
  29756. }
  29757. angular
  29758. .element(this.getMenus())
  29759. .off('mouseenter', this.handleMenuHover);
  29760. };
  29761. MenuBarController.prototype.scheduleOpenHoveredMenu = function(e) {
  29762. var menuEl = angular.element(e.currentTarget);
  29763. var menuCtrl = menuEl.controller('mdMenu');
  29764. this.setKeyboardMode(false);
  29765. this.scheduleOpenMenu(menuCtrl);
  29766. };
  29767. MenuBarController.prototype.scheduleOpenMenu = function(menuCtrl) {
  29768. var self = this;
  29769. var $timeout = this.$timeout;
  29770. if (menuCtrl != self.currentlyOpenMenu) {
  29771. $timeout.cancel(self.pendingMenuOpen);
  29772. self.pendingMenuOpen = $timeout(function() {
  29773. self.pendingMenuOpen = undefined;
  29774. if (self.currentlyOpenMenu) {
  29775. self.currentlyOpenMenu.close(true, { closeAll: true });
  29776. }
  29777. menuCtrl.open();
  29778. }, 200, false);
  29779. }
  29780. };
  29781. MenuBarController.prototype.handleKeyDown = function(e) {
  29782. var keyCodes = this.$mdConstant.KEY_CODE;
  29783. var currentMenu = this.currentlyOpenMenu;
  29784. var wasOpen = currentMenu && currentMenu.isOpen;
  29785. this.setKeyboardMode(true);
  29786. var handled, newMenu, newMenuCtrl;
  29787. switch (e.keyCode) {
  29788. case keyCodes.DOWN_ARROW:
  29789. if (currentMenu) {
  29790. currentMenu.focusMenuContainer();
  29791. } else {
  29792. this.openFocusedMenu();
  29793. }
  29794. handled = true;
  29795. break;
  29796. case keyCodes.UP_ARROW:
  29797. currentMenu && currentMenu.close();
  29798. handled = true;
  29799. break;
  29800. case keyCodes.LEFT_ARROW:
  29801. newMenu = this.focusMenu(-1);
  29802. if (wasOpen) {
  29803. newMenuCtrl = angular.element(newMenu).controller('mdMenu');
  29804. this.scheduleOpenMenu(newMenuCtrl);
  29805. }
  29806. handled = true;
  29807. break;
  29808. case keyCodes.RIGHT_ARROW:
  29809. newMenu = this.focusMenu(+1);
  29810. if (wasOpen) {
  29811. newMenuCtrl = angular.element(newMenu).controller('mdMenu');
  29812. this.scheduleOpenMenu(newMenuCtrl);
  29813. }
  29814. handled = true;
  29815. break;
  29816. }
  29817. if (handled) {
  29818. e && e.preventDefault && e.preventDefault();
  29819. e && e.stopImmediatePropagation && e.stopImmediatePropagation();
  29820. }
  29821. };
  29822. MenuBarController.prototype.focusMenu = function(direction) {
  29823. var menus = this.getMenus();
  29824. var focusedIndex = this.getFocusedMenuIndex();
  29825. if (focusedIndex == -1) { focusedIndex = this.getOpenMenuIndex(); }
  29826. var changed = false;
  29827. if (focusedIndex == -1) { focusedIndex = 0; changed = true; }
  29828. else if (
  29829. direction < 0 && focusedIndex > 0 ||
  29830. direction > 0 && focusedIndex < menus.length - direction
  29831. ) {
  29832. focusedIndex += direction;
  29833. changed = true;
  29834. }
  29835. if (changed) {
  29836. menus[focusedIndex].querySelector('button').focus();
  29837. return menus[focusedIndex];
  29838. }
  29839. };
  29840. MenuBarController.prototype.openFocusedMenu = function() {
  29841. var menu = this.getFocusedMenu();
  29842. menu && angular.element(menu).controller('mdMenu').open();
  29843. };
  29844. MenuBarController.prototype.getMenus = function() {
  29845. var $element = this.$element;
  29846. return this.$mdUtil.nodesToArray($element[0].children)
  29847. .filter(function(el) { return el.nodeName == 'MD-MENU'; });
  29848. };
  29849. MenuBarController.prototype.getFocusedMenu = function() {
  29850. return this.getMenus()[this.getFocusedMenuIndex()];
  29851. };
  29852. MenuBarController.prototype.getFocusedMenuIndex = function() {
  29853. var $mdUtil = this.$mdUtil;
  29854. var focusedEl = $mdUtil.getClosest(
  29855. this.$document[0].activeElement,
  29856. 'MD-MENU'
  29857. );
  29858. if (!focusedEl) return -1;
  29859. var focusedIndex = this.getMenus().indexOf(focusedEl);
  29860. return focusedIndex;
  29861. };
  29862. MenuBarController.prototype.getOpenMenuIndex = function() {
  29863. var menus = this.getMenus();
  29864. for (var i = 0; i < menus.length; ++i) {
  29865. if (menus[i].classList.contains('md-open')) return i;
  29866. }
  29867. return -1;
  29868. };
  29869. MenuBarController.prototype.handleParentClick = function(event) {
  29870. var openMenu = this.querySelector('md-menu.md-open');
  29871. if (openMenu && !openMenu.contains(event.target)) {
  29872. angular.element(openMenu).controller('mdMenu').close(true, {
  29873. closeAll: true
  29874. });
  29875. }
  29876. };
  29877. })();
  29878. (function(){
  29879. "use strict";
  29880. /**
  29881. * @ngdoc directive
  29882. * @name mdMenuBar
  29883. * @module material.components.menuBar
  29884. * @restrict E
  29885. * @description
  29886. *
  29887. * Menu bars are containers that hold multiple menus. They change the behavior and appearence
  29888. * of the `md-menu` directive to behave similar to an operating system provided menu.
  29889. *
  29890. * @usage
  29891. * <hljs lang="html">
  29892. * <md-menu-bar>
  29893. * <md-menu>
  29894. * <button ng-click="$mdMenu.open()">
  29895. * File
  29896. * </button>
  29897. * <md-menu-content>
  29898. * <md-menu-item>
  29899. * <md-button ng-click="ctrl.sampleAction('share', $event)">
  29900. * Share...
  29901. * </md-button>
  29902. * </md-menu-item>
  29903. * <md-menu-divider></md-menu-divider>
  29904. * <md-menu-item>
  29905. * <md-menu-item>
  29906. * <md-menu>
  29907. * <md-button ng-click="$mdMenu.open()">New</md-button>
  29908. * <md-menu-content>
  29909. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Document', $event)">Document</md-button></md-menu-item>
  29910. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Spreadsheet', $event)">Spreadsheet</md-button></md-menu-item>
  29911. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Presentation', $event)">Presentation</md-button></md-menu-item>
  29912. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Form', $event)">Form</md-button></md-menu-item>
  29913. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Drawing', $event)">Drawing</md-button></md-menu-item>
  29914. * </md-menu-content>
  29915. * </md-menu>
  29916. * </md-menu-item>
  29917. * </md-menu-content>
  29918. * </md-menu>
  29919. * </md-menu-bar>
  29920. * </hljs>
  29921. *
  29922. * ## Menu Bar Controls
  29923. *
  29924. * You may place `md-menu-items` that function as controls within menu bars.
  29925. * There are two modes that are exposed via the `type` attribute of the `md-menu-item`.
  29926. * `type="checkbox"` will function as a boolean control for the `ng-model` attribute of the
  29927. * `md-menu-item`. `type="radio"` will function like a radio button, setting the `ngModel`
  29928. * to the `string` value of the `value` attribute. If you need non-string values, you can use
  29929. * `ng-value` to provide an expression (this is similar to how angular's native `input[type=radio]` works.
  29930. *
  29931. * <hljs lang="html">
  29932. * <md-menu-bar>
  29933. * <md-menu>
  29934. * <button ng-click="$mdMenu.open()">
  29935. * Sample Menu
  29936. * </button>
  29937. * <md-menu-content>
  29938. * <md-menu-item type="checkbox" ng-model="settings.allowChanges">Allow changes</md-menu-item>
  29939. * <md-menu-divider></md-menu-divider>
  29940. * <md-menu-item type="radio" ng-model="settings.mode" ng-value="1">Mode 1</md-menu-item>
  29941. * <md-menu-item type="radio" ng-model="settings.mode" ng-value="1">Mode 2</md-menu-item>
  29942. * <md-menu-item type="radio" ng-model="settings.mode" ng-value="1">Mode 3</md-menu-item>
  29943. * </md-menu-content>
  29944. * </md-menu>
  29945. * </md-menu-bar>
  29946. * </hljs>
  29947. *
  29948. *
  29949. * ### Nesting Menus
  29950. *
  29951. * Menus may be nested within menu bars. This is commonly called cascading menus.
  29952. * To nest a menu place the nested menu inside the content of the `md-menu-item`.
  29953. * <hljs lang="html">
  29954. * <md-menu-item>
  29955. * <md-menu>
  29956. * <button ng-click="$mdMenu.open()">New</md-button>
  29957. * <md-menu-content>
  29958. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Document', $event)">Document</md-button></md-menu-item>
  29959. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Spreadsheet', $event)">Spreadsheet</md-button></md-menu-item>
  29960. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Presentation', $event)">Presentation</md-button></md-menu-item>
  29961. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Form', $event)">Form</md-button></md-menu-item>
  29962. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Drawing', $event)">Drawing</md-button></md-menu-item>
  29963. * </md-menu-content>
  29964. * </md-menu>
  29965. * </md-menu-item>
  29966. * </hljs>
  29967. *
  29968. */
  29969. MenuBarDirective.$inject = ["$mdUtil", "$mdTheming"];
  29970. angular
  29971. .module('material.components.menuBar')
  29972. .directive('mdMenuBar', MenuBarDirective);
  29973. /* @ngInject */
  29974. function MenuBarDirective($mdUtil, $mdTheming) {
  29975. return {
  29976. restrict: 'E',
  29977. require: 'mdMenuBar',
  29978. controller: 'MenuBarController',
  29979. compile: function compile(templateEl, templateAttrs) {
  29980. if (!templateAttrs.ariaRole) {
  29981. templateEl[0].setAttribute('role', 'menubar');
  29982. }
  29983. angular.forEach(templateEl[0].children, function(menuEl) {
  29984. if (menuEl.nodeName == 'MD-MENU') {
  29985. if (!menuEl.hasAttribute('md-position-mode')) {
  29986. menuEl.setAttribute('md-position-mode', 'left bottom');
  29987. // Since we're in the compile function and actual `md-buttons` are not compiled yet,
  29988. // we need to query for possible `md-buttons` as well.
  29989. menuEl.querySelector('button, a, md-button').setAttribute('role', 'menuitem');
  29990. }
  29991. var contentEls = $mdUtil.nodesToArray(menuEl.querySelectorAll('md-menu-content'));
  29992. angular.forEach(contentEls, function(contentEl) {
  29993. contentEl.classList.add('md-menu-bar-menu');
  29994. contentEl.classList.add('md-dense');
  29995. if (!contentEl.hasAttribute('width')) {
  29996. contentEl.setAttribute('width', 5);
  29997. }
  29998. });
  29999. }
  30000. });
  30001. // Mark the child menu items that they're inside a menu bar. This is necessary,
  30002. // because mnMenuItem has special behaviour during compilation, depending on
  30003. // whether it is inside a mdMenuBar. We can usually figure this out via the DOM,
  30004. // however if a directive that uses documentFragment is applied to the child (e.g. ngRepeat),
  30005. // the element won't have a parent and won't compile properly.
  30006. templateEl.find('md-menu-item').addClass('md-in-menu-bar');
  30007. return function postLink(scope, el, attr, ctrl) {
  30008. el.addClass('_md'); // private md component indicator for styling
  30009. $mdTheming(scope, el);
  30010. ctrl.init();
  30011. };
  30012. }
  30013. };
  30014. }
  30015. })();
  30016. (function(){
  30017. "use strict";
  30018. angular
  30019. .module('material.components.menuBar')
  30020. .directive('mdMenuDivider', MenuDividerDirective);
  30021. function MenuDividerDirective() {
  30022. return {
  30023. restrict: 'E',
  30024. compile: function(templateEl, templateAttrs) {
  30025. if (!templateAttrs.role) {
  30026. templateEl[0].setAttribute('role', 'separator');
  30027. }
  30028. }
  30029. };
  30030. }
  30031. })();
  30032. (function(){
  30033. "use strict";
  30034. MenuItemController.$inject = ["$scope", "$element", "$attrs"];
  30035. angular
  30036. .module('material.components.menuBar')
  30037. .controller('MenuItemController', MenuItemController);
  30038. /**
  30039. * @ngInject
  30040. */
  30041. function MenuItemController($scope, $element, $attrs) {
  30042. this.$element = $element;
  30043. this.$attrs = $attrs;
  30044. this.$scope = $scope;
  30045. }
  30046. MenuItemController.prototype.init = function(ngModel) {
  30047. var $element = this.$element;
  30048. var $attrs = this.$attrs;
  30049. this.ngModel = ngModel;
  30050. if ($attrs.type == 'checkbox' || $attrs.type == 'radio') {
  30051. this.mode = $attrs.type;
  30052. this.iconEl = $element[0].children[0];
  30053. this.buttonEl = $element[0].children[1];
  30054. if (ngModel) {
  30055. // Clear ngAria set attributes
  30056. this.initClickListeners();
  30057. }
  30058. }
  30059. };
  30060. // ngAria auto sets attributes on a menu-item with a ngModel.
  30061. // We don't want this because our content (buttons) get the focus
  30062. // and set their own aria attributes appropritately. Having both
  30063. // breaks NVDA / JAWS. This undeoes ngAria's attrs.
  30064. MenuItemController.prototype.clearNgAria = function() {
  30065. var el = this.$element[0];
  30066. var clearAttrs = ['role', 'tabindex', 'aria-invalid', 'aria-checked'];
  30067. angular.forEach(clearAttrs, function(attr) {
  30068. el.removeAttribute(attr);
  30069. });
  30070. };
  30071. MenuItemController.prototype.initClickListeners = function() {
  30072. var self = this;
  30073. var ngModel = this.ngModel;
  30074. var $scope = this.$scope;
  30075. var $attrs = this.$attrs;
  30076. var $element = this.$element;
  30077. var mode = this.mode;
  30078. this.handleClick = angular.bind(this, this.handleClick);
  30079. var icon = this.iconEl;
  30080. var button = angular.element(this.buttonEl);
  30081. var handleClick = this.handleClick;
  30082. $attrs.$observe('disabled', setDisabled);
  30083. setDisabled($attrs.disabled);
  30084. ngModel.$render = function render() {
  30085. self.clearNgAria();
  30086. if (isSelected()) {
  30087. icon.style.display = '';
  30088. button.attr('aria-checked', 'true');
  30089. } else {
  30090. icon.style.display = 'none';
  30091. button.attr('aria-checked', 'false');
  30092. }
  30093. };
  30094. $scope.$$postDigest(ngModel.$render);
  30095. function isSelected() {
  30096. if (mode == 'radio') {
  30097. var val = $attrs.ngValue ? $scope.$eval($attrs.ngValue) : $attrs.value;
  30098. return ngModel.$modelValue == val;
  30099. } else {
  30100. return ngModel.$modelValue;
  30101. }
  30102. }
  30103. function setDisabled(disabled) {
  30104. if (disabled) {
  30105. button.off('click', handleClick);
  30106. } else {
  30107. button.on('click', handleClick);
  30108. }
  30109. }
  30110. };
  30111. MenuItemController.prototype.handleClick = function(e) {
  30112. var mode = this.mode;
  30113. var ngModel = this.ngModel;
  30114. var $attrs = this.$attrs;
  30115. var newVal;
  30116. if (mode == 'checkbox') {
  30117. newVal = !ngModel.$modelValue;
  30118. } else if (mode == 'radio') {
  30119. newVal = $attrs.ngValue ? this.$scope.$eval($attrs.ngValue) : $attrs.value;
  30120. }
  30121. ngModel.$setViewValue(newVal);
  30122. ngModel.$render();
  30123. };
  30124. })();
  30125. (function(){
  30126. "use strict";
  30127. MenuItemDirective.$inject = ["$mdUtil", "$mdConstant", "$$mdSvgRegistry"];
  30128. angular
  30129. .module('material.components.menuBar')
  30130. .directive('mdMenuItem', MenuItemDirective);
  30131. /* @ngInject */
  30132. function MenuItemDirective($mdUtil, $mdConstant, $$mdSvgRegistry) {
  30133. return {
  30134. controller: 'MenuItemController',
  30135. require: ['mdMenuItem', '?ngModel'],
  30136. priority: $mdConstant.BEFORE_NG_ARIA,
  30137. compile: function(templateEl, templateAttrs) {
  30138. var type = templateAttrs.type;
  30139. var inMenuBarClass = 'md-in-menu-bar';
  30140. // Note: This allows us to show the `check` icon for the md-menu-bar items.
  30141. // The `md-in-menu-bar` class is set by the mdMenuBar directive.
  30142. if ((type == 'checkbox' || type == 'radio') && templateEl.hasClass(inMenuBarClass)) {
  30143. var text = templateEl[0].textContent;
  30144. var buttonEl = angular.element('<md-button type="button"></md-button>');
  30145. var iconTemplate = '<md-icon md-svg-src="' + $$mdSvgRegistry.mdChecked + '"></md-icon>';
  30146. buttonEl.html(text);
  30147. buttonEl.attr('tabindex', '0');
  30148. templateEl.html('');
  30149. templateEl.append(angular.element(iconTemplate));
  30150. templateEl.append(buttonEl);
  30151. templateEl.addClass('md-indent').removeClass(inMenuBarClass);
  30152. setDefault('role', type == 'checkbox' ? 'menuitemcheckbox' : 'menuitemradio', buttonEl);
  30153. moveAttrToButton('ng-disabled');
  30154. } else {
  30155. setDefault('role', 'menuitem', templateEl[0].querySelector('md-button, button, a'));
  30156. }
  30157. return function(scope, el, attrs, ctrls) {
  30158. var ctrl = ctrls[0];
  30159. var ngModel = ctrls[1];
  30160. ctrl.init(ngModel);
  30161. };
  30162. function setDefault(attr, val, el) {
  30163. el = el || templateEl;
  30164. if (el instanceof angular.element) {
  30165. el = el[0];
  30166. }
  30167. if (!el.hasAttribute(attr)) {
  30168. el.setAttribute(attr, val);
  30169. }
  30170. }
  30171. function moveAttrToButton(attribute) {
  30172. var attributes = $mdUtil.prefixer(attribute);
  30173. angular.forEach(attributes, function(attr) {
  30174. if (templateEl[0].hasAttribute(attr)) {
  30175. var val = templateEl[0].getAttribute(attr);
  30176. buttonEl[0].setAttribute(attr, val);
  30177. templateEl[0].removeAttribute(attr);
  30178. }
  30179. });
  30180. }
  30181. }
  30182. };
  30183. }
  30184. })();
  30185. (function(){
  30186. "use strict";
  30187. /**
  30188. * @ngdoc directive
  30189. * @name mdProgressCircular
  30190. * @module material.components.progressCircular
  30191. * @restrict E
  30192. *
  30193. * @description
  30194. * The circular progress directive is used to make loading content in your app as delightful and
  30195. * painless as possible by minimizing the amount of visual change a user sees before they can view
  30196. * and interact with content.
  30197. *
  30198. * For operations where the percentage of the operation completed can be determined, use a
  30199. * determinate indicator. They give users a quick sense of how long an operation will take.
  30200. *
  30201. * For operations where the user is asked to wait a moment while something finishes up, and it’s
  30202. * not necessary to expose what's happening behind the scenes and how long it will take, use an
  30203. * indeterminate indicator.
  30204. *
  30205. * @param {string} md-mode Select from one of two modes: **'determinate'** and **'indeterminate'**.
  30206. *
  30207. * Note: if the `md-mode` value is set as undefined or specified as not 1 of the two (2) valid modes, then **'indeterminate'**
  30208. * will be auto-applied as the mode.
  30209. *
  30210. * Note: if not configured, the `md-mode="indeterminate"` will be auto injected as an attribute.
  30211. * If `value=""` is also specified, however, then `md-mode="determinate"` would be auto-injected instead.
  30212. * @param {number=} value In determinate mode, this number represents the percentage of the
  30213. * circular progress. Default: 0
  30214. * @param {number=} md-diameter This specifies the diameter of the circular progress. The value
  30215. * should be a pixel-size value (eg '100'). If this attribute is
  30216. * not present then a default value of '50px' is assumed.
  30217. *
  30218. * @param {boolean=} ng-disabled Determines whether to disable the progress element.
  30219. *
  30220. * @usage
  30221. * <hljs lang="html">
  30222. * <md-progress-circular md-mode="determinate" value="..."></md-progress-circular>
  30223. *
  30224. * <md-progress-circular md-mode="determinate" ng-value="..."></md-progress-circular>
  30225. *
  30226. * <md-progress-circular md-mode="determinate" value="..." md-diameter="100"></md-progress-circular>
  30227. *
  30228. * <md-progress-circular md-mode="indeterminate"></md-progress-circular>
  30229. * </hljs>
  30230. */
  30231. MdProgressCircularDirective.$inject = ["$window", "$mdProgressCircular", "$mdTheming", "$mdUtil", "$interval", "$log"];
  30232. angular
  30233. .module('material.components.progressCircular')
  30234. .directive('mdProgressCircular', MdProgressCircularDirective);
  30235. /* @ngInject */
  30236. function MdProgressCircularDirective($window, $mdProgressCircular, $mdTheming,
  30237. $mdUtil, $interval, $log) {
  30238. // Note that this shouldn't use use $$rAF, because it can cause an infinite loop
  30239. // in any tests that call $animate.flush.
  30240. var rAF = $window.requestAnimationFrame ||
  30241. $window.webkitRequestAnimationFrame ||
  30242. angular.noop;
  30243. var cAF = $window.cancelAnimationFrame ||
  30244. $window.webkitCancelAnimationFrame ||
  30245. $window.webkitCancelRequestAnimationFrame ||
  30246. angular.noop;
  30247. var MODE_DETERMINATE = 'determinate';
  30248. var MODE_INDETERMINATE = 'indeterminate';
  30249. var DISABLED_CLASS = '_md-progress-circular-disabled';
  30250. var INDETERMINATE_CLASS = 'md-mode-indeterminate';
  30251. return {
  30252. restrict: 'E',
  30253. scope: {
  30254. value: '@',
  30255. mdDiameter: '@',
  30256. mdMode: '@'
  30257. },
  30258. template:
  30259. '<svg xmlns="http://www.w3.org/2000/svg">' +
  30260. '<path fill="none"/>' +
  30261. '</svg>',
  30262. compile: function(element, attrs) {
  30263. element.attr({
  30264. 'aria-valuemin': 0,
  30265. 'aria-valuemax': 100,
  30266. 'role': 'progressbar'
  30267. });
  30268. if (angular.isUndefined(attrs.mdMode)) {
  30269. var mode = attrs.hasOwnProperty('value') ? MODE_DETERMINATE : MODE_INDETERMINATE;
  30270. attrs.$set('mdMode', mode);
  30271. } else {
  30272. attrs.$set('mdMode', attrs.mdMode.trim());
  30273. }
  30274. return MdProgressCircularLink;
  30275. }
  30276. };
  30277. function MdProgressCircularLink(scope, element, attrs) {
  30278. var node = element[0];
  30279. var svg = angular.element(node.querySelector('svg'));
  30280. var path = angular.element(node.querySelector('path'));
  30281. var startIndeterminate = $mdProgressCircular.startIndeterminate;
  30282. var endIndeterminate = $mdProgressCircular.endIndeterminate;
  30283. var iterationCount = 0;
  30284. var lastAnimationId = 0;
  30285. var lastDrawFrame;
  30286. var interval;
  30287. $mdTheming(element);
  30288. element.toggleClass(DISABLED_CLASS, attrs.hasOwnProperty('disabled'));
  30289. // If the mode is indeterminate, it doesn't need to
  30290. // wait for the next digest. It can start right away.
  30291. if(scope.mdMode === MODE_INDETERMINATE){
  30292. startIndeterminateAnimation();
  30293. }
  30294. scope.$on('$destroy', function(){
  30295. cleanupIndeterminateAnimation();
  30296. if (lastDrawFrame) {
  30297. cAF(lastDrawFrame);
  30298. }
  30299. });
  30300. scope.$watchGroup(['value', 'mdMode', function() {
  30301. var isDisabled = node.disabled;
  30302. // Sometimes the browser doesn't return a boolean, in
  30303. // which case we should check whether the attribute is
  30304. // present.
  30305. if (isDisabled === true || isDisabled === false){
  30306. return isDisabled;
  30307. }
  30308. return angular.isDefined(element.attr('disabled'));
  30309. }], function(newValues, oldValues) {
  30310. var mode = newValues[1];
  30311. var isDisabled = newValues[2];
  30312. var wasDisabled = oldValues[2];
  30313. if (isDisabled !== wasDisabled) {
  30314. element.toggleClass(DISABLED_CLASS, !!isDisabled);
  30315. }
  30316. if (isDisabled) {
  30317. cleanupIndeterminateAnimation();
  30318. } else {
  30319. if (mode !== MODE_DETERMINATE && mode !== MODE_INDETERMINATE) {
  30320. mode = MODE_INDETERMINATE;
  30321. attrs.$set('mdMode', mode);
  30322. }
  30323. if (mode === MODE_INDETERMINATE) {
  30324. startIndeterminateAnimation();
  30325. } else {
  30326. var newValue = clamp(newValues[0]);
  30327. cleanupIndeterminateAnimation();
  30328. element.attr('aria-valuenow', newValue);
  30329. renderCircle(clamp(oldValues[0]), newValue);
  30330. }
  30331. }
  30332. });
  30333. // This is in a separate watch in order to avoid layout, unless
  30334. // the value has actually changed.
  30335. scope.$watch('mdDiameter', function(newValue) {
  30336. var diameter = getSize(newValue);
  30337. var strokeWidth = getStroke(diameter);
  30338. var value = clamp(scope.value);
  30339. var transformOrigin = (diameter / 2) + 'px';
  30340. var dimensions = {
  30341. width: diameter + 'px',
  30342. height: diameter + 'px'
  30343. };
  30344. // The viewBox has to be applied via setAttribute, because it is
  30345. // case-sensitive. If jQuery is included in the page, `.attr` lowercases
  30346. // all attribute names.
  30347. svg[0].setAttribute('viewBox', '0 0 ' + diameter + ' ' + diameter);
  30348. // Usually viewBox sets the dimensions for the SVG, however that doesn't
  30349. // seem to be the case on IE10.
  30350. // Important! The transform origin has to be set from here and it has to
  30351. // be in the format of "Ypx Ypx Ypx", otherwise the rotation wobbles in
  30352. // IE and Edge, because they don't account for the stroke width when
  30353. // rotating. Also "center" doesn't help in this case, it has to be a
  30354. // precise value.
  30355. svg
  30356. .css(dimensions)
  30357. .css('transform-origin', transformOrigin + ' ' + transformOrigin + ' ' + transformOrigin);
  30358. element.css(dimensions);
  30359. path.attr('stroke-width', strokeWidth);
  30360. path.attr('stroke-linecap', 'square');
  30361. if (scope.mdMode == MODE_INDETERMINATE) {
  30362. path.attr('d', getSvgArc(diameter, strokeWidth, true));
  30363. path.attr('stroke-dasharray', (diameter - strokeWidth) * $window.Math.PI * 0.75);
  30364. path.attr('stroke-dashoffset', getDashLength(diameter, strokeWidth, 1, 75));
  30365. } else {
  30366. path.attr('d', getSvgArc(diameter, strokeWidth, false));
  30367. path.attr('stroke-dasharray', (diameter - strokeWidth) * $window.Math.PI);
  30368. path.attr('stroke-dashoffset', getDashLength(diameter, strokeWidth, 0, 100));
  30369. renderCircle(value, value);
  30370. }
  30371. });
  30372. function renderCircle(animateFrom, animateTo, easing, duration, iterationCount, maxValue) {
  30373. var id = ++lastAnimationId;
  30374. var startTime = $mdUtil.now();
  30375. var changeInValue = animateTo - animateFrom;
  30376. var diameter = getSize(scope.mdDiameter);
  30377. var strokeWidth = getStroke(diameter);
  30378. var ease = easing || $mdProgressCircular.easeFn;
  30379. var animationDuration = duration || $mdProgressCircular.duration;
  30380. var rotation = -90 * (iterationCount || 0);
  30381. var dashLimit = maxValue || 100;
  30382. // No need to animate it if the values are the same
  30383. if (animateTo === animateFrom) {
  30384. renderFrame(animateTo);
  30385. } else {
  30386. lastDrawFrame = rAF(function animation() {
  30387. var currentTime = $window.Math.max(0, $window.Math.min($mdUtil.now() - startTime, animationDuration));
  30388. renderFrame(ease(currentTime, animateFrom, changeInValue, animationDuration));
  30389. // Do not allow overlapping animations
  30390. if (id === lastAnimationId && currentTime < animationDuration) {
  30391. lastDrawFrame = rAF(animation);
  30392. }
  30393. });
  30394. }
  30395. function renderFrame(value) {
  30396. path.attr('stroke-dashoffset', getDashLength(diameter, strokeWidth, value, dashLimit));
  30397. path.attr('transform','rotate(' + (rotation) + ' ' + diameter/2 + ' ' + diameter/2 + ')');
  30398. }
  30399. }
  30400. function animateIndeterminate() {
  30401. renderCircle(
  30402. startIndeterminate,
  30403. endIndeterminate,
  30404. $mdProgressCircular.easeFnIndeterminate,
  30405. $mdProgressCircular.durationIndeterminate,
  30406. iterationCount,
  30407. 75
  30408. );
  30409. // The %4 technically isn't necessary, but it keeps the rotation
  30410. // under 360, instead of becoming a crazy large number.
  30411. iterationCount = ++iterationCount % 4;
  30412. }
  30413. function startIndeterminateAnimation() {
  30414. if (!interval) {
  30415. // Note that this interval isn't supposed to trigger a digest.
  30416. interval = $interval(
  30417. animateIndeterminate,
  30418. $mdProgressCircular.durationIndeterminate,
  30419. 0,
  30420. false
  30421. );
  30422. animateIndeterminate();
  30423. element
  30424. .addClass(INDETERMINATE_CLASS)
  30425. .removeAttr('aria-valuenow');
  30426. }
  30427. }
  30428. function cleanupIndeterminateAnimation() {
  30429. if (interval) {
  30430. $interval.cancel(interval);
  30431. interval = null;
  30432. element.removeClass(INDETERMINATE_CLASS);
  30433. }
  30434. }
  30435. }
  30436. /**
  30437. * Returns SVG path data for progress circle
  30438. * Syntax spec: https://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
  30439. *
  30440. * @param {number} diameter Diameter of the container.
  30441. * @param {number} strokeWidth Stroke width to be used when drawing circle
  30442. * @param {boolean} indeterminate Use if progress circle will be used for indeterminate
  30443. *
  30444. * @returns {string} String representation of an SVG arc.
  30445. */
  30446. function getSvgArc(diameter, strokeWidth, indeterminate) {
  30447. var radius = diameter / 2;
  30448. var offset = strokeWidth / 2;
  30449. var start = radius + ',' + offset; // ie: (25, 2.5) or 12 o'clock
  30450. var end = offset + ',' + radius; // ie: (2.5, 25) or 9 o'clock
  30451. var arcRadius = radius - offset;
  30452. return 'M' + start
  30453. + 'A' + arcRadius + ',' + arcRadius + ' 0 1 1 ' + end // 75% circle
  30454. + (indeterminate ? '' : 'A' + arcRadius + ',' + arcRadius + ' 0 0 1 ' + start); // loop to start
  30455. }
  30456. /**
  30457. * Return stroke length for progress circle
  30458. *
  30459. * @param {number} diameter Diameter of the container.
  30460. * @param {number} strokeWidth Stroke width to be used when drawing circle
  30461. * @param {number} value Percentage of circle (between 0 and 100)
  30462. * @param {number} limit Max percentage for circle
  30463. *
  30464. * @returns {number} Stroke length for progres circle
  30465. */
  30466. function getDashLength(diameter, strokeWidth, value, limit) {
  30467. return (diameter - strokeWidth) * $window.Math.PI * ( (3 * (limit || 100) / 100) - (value/100) );
  30468. }
  30469. /**
  30470. * Limits a value between 0 and 100.
  30471. */
  30472. function clamp(value) {
  30473. return $window.Math.max(0, $window.Math.min(value || 0, 100));
  30474. }
  30475. /**
  30476. * Determines the size of a progress circle, based on the provided
  30477. * value in the following formats: `X`, `Ypx`, `Z%`.
  30478. */
  30479. function getSize(value) {
  30480. var defaultValue = $mdProgressCircular.progressSize;
  30481. if (value) {
  30482. var parsed = parseFloat(value);
  30483. if (value.lastIndexOf('%') === value.length - 1) {
  30484. parsed = (parsed / 100) * defaultValue;
  30485. }
  30486. return parsed;
  30487. }
  30488. return defaultValue;
  30489. }
  30490. /**
  30491. * Determines the circle's stroke width, based on
  30492. * the provided diameter.
  30493. */
  30494. function getStroke(diameter) {
  30495. return $mdProgressCircular.strokeWidth / 100 * diameter;
  30496. }
  30497. }
  30498. })();
  30499. (function(){
  30500. "use strict";
  30501. /**
  30502. * @ngdoc service
  30503. * @name $mdProgressCircular
  30504. * @module material.components.progressCircular
  30505. *
  30506. * @description
  30507. * Allows the user to specify the default options for the `progressCircular` directive.
  30508. *
  30509. * @property {number} progressSize Diameter of the progress circle in pixels.
  30510. * @property {number} strokeWidth Width of the circle's stroke as a percentage of the circle's size.
  30511. * @property {number} duration Length of the circle animation in milliseconds.
  30512. * @property {function} easeFn Default easing animation function.
  30513. * @property {object} easingPresets Collection of pre-defined easing functions.
  30514. *
  30515. * @property {number} durationIndeterminate Duration of the indeterminate animation.
  30516. * @property {number} startIndeterminate Indeterminate animation start point.
  30517. * @property {number} endIndeterminate Indeterminate animation end point.
  30518. * @property {function} easeFnIndeterminate Easing function to be used when animating
  30519. * between the indeterminate values.
  30520. *
  30521. * @property {(function(object): object)} configure Used to modify the default options.
  30522. *
  30523. * @usage
  30524. * <hljs lang="js">
  30525. * myAppModule.config(function($mdProgressCircularProvider) {
  30526. *
  30527. * // Example of changing the default progress options.
  30528. * $mdProgressCircularProvider.configure({
  30529. * progressSize: 100,
  30530. * strokeWidth: 20,
  30531. * duration: 800
  30532. * });
  30533. * });
  30534. * </hljs>
  30535. *
  30536. */
  30537. angular
  30538. .module('material.components.progressCircular')
  30539. .provider("$mdProgressCircular", MdProgressCircularProvider);
  30540. function MdProgressCircularProvider() {
  30541. var progressConfig = {
  30542. progressSize: 50,
  30543. strokeWidth: 10,
  30544. duration: 100,
  30545. easeFn: linearEase,
  30546. durationIndeterminate: 1333,
  30547. startIndeterminate: 1,
  30548. endIndeterminate: 149,
  30549. easeFnIndeterminate: materialEase,
  30550. easingPresets: {
  30551. linearEase: linearEase,
  30552. materialEase: materialEase
  30553. }
  30554. };
  30555. return {
  30556. configure: function(options) {
  30557. progressConfig = angular.extend(progressConfig, options || {});
  30558. return progressConfig;
  30559. },
  30560. $get: function() { return progressConfig; }
  30561. };
  30562. function linearEase(t, b, c, d) {
  30563. return c * t / d + b;
  30564. }
  30565. function materialEase(t, b, c, d) {
  30566. // via http://www.timotheegroleau.com/Flash/experiments/easing_function_generator.htm
  30567. // with settings of [0, 0, 1, 1]
  30568. var ts = (t /= d) * t;
  30569. var tc = ts * t;
  30570. return b + c * (6 * tc * ts + -15 * ts * ts + 10 * tc);
  30571. }
  30572. }
  30573. })();
  30574. (function(){
  30575. "use strict";
  30576. /**
  30577. * @ngdoc directive
  30578. * @name mdTab
  30579. * @module material.components.tabs
  30580. *
  30581. * @restrict E
  30582. *
  30583. * @description
  30584. * The `<md-tab>` is a nested directive used within `<md-tabs>` to specify a tab with a **label** and optional *view content*.
  30585. *
  30586. * If the `label` attribute is not specified, then an optional `<md-tab-label>` tag can be used to specify more
  30587. * complex tab header markup. If neither the **label** nor the **md-tab-label** are specified, then the nested
  30588. * markup of the `<md-tab>` is used as the tab header markup.
  30589. *
  30590. * Please note that if you use `<md-tab-label>`, your content **MUST** be wrapped in the `<md-tab-body>` tag. This
  30591. * is to define a clear separation between the tab content and the tab label.
  30592. *
  30593. * This container is used by the TabsController to show/hide the active tab's content view. This synchronization is
  30594. * automatically managed by the internal TabsController whenever the tab selection changes. Selection changes can
  30595. * be initiated via data binding changes, programmatic invocation, or user gestures.
  30596. *
  30597. * @param {string=} label Optional attribute to specify a simple string as the tab label
  30598. * @param {boolean=} ng-disabled If present and expression evaluates to truthy, disabled tab selection.
  30599. * @param {expression=} md-on-deselect Expression to be evaluated after the tab has been de-selected.
  30600. * @param {expression=} md-on-select Expression to be evaluated after the tab has been selected.
  30601. * @param {boolean=} md-active When true, sets the active tab. Note: There can only be one active tab at a time.
  30602. *
  30603. *
  30604. * @usage
  30605. *
  30606. * <hljs lang="html">
  30607. * <md-tab label="" ng-disabled md-on-select="" md-on-deselect="" >
  30608. * <h3>My Tab content</h3>
  30609. * </md-tab>
  30610. *
  30611. * <md-tab >
  30612. * <md-tab-label>
  30613. * <h3>My Tab content</h3>
  30614. * </md-tab-label>
  30615. * <md-tab-body>
  30616. * <p>
  30617. * Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,
  30618. * totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
  30619. * dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit,
  30620. * sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
  30621. * </p>
  30622. * </md-tab-body>
  30623. * </md-tab>
  30624. * </hljs>
  30625. *
  30626. */
  30627. angular
  30628. .module('material.components.tabs')
  30629. .directive('mdTab', MdTab);
  30630. function MdTab () {
  30631. return {
  30632. require: '^?mdTabs',
  30633. terminal: true,
  30634. compile: function (element, attr) {
  30635. var label = firstChild(element, 'md-tab-label'),
  30636. body = firstChild(element, 'md-tab-body');
  30637. if (label.length === 0) {
  30638. label = angular.element('<md-tab-label></md-tab-label>');
  30639. if (attr.label) label.text(attr.label);
  30640. else label.append(element.contents());
  30641. if (body.length === 0) {
  30642. var contents = element.contents().detach();
  30643. body = angular.element('<md-tab-body></md-tab-body>');
  30644. body.append(contents);
  30645. }
  30646. }
  30647. element.append(label);
  30648. if (body.html()) element.append(body);
  30649. return postLink;
  30650. },
  30651. scope: {
  30652. active: '=?mdActive',
  30653. disabled: '=?ngDisabled',
  30654. select: '&?mdOnSelect',
  30655. deselect: '&?mdOnDeselect'
  30656. }
  30657. };
  30658. function postLink (scope, element, attr, ctrl) {
  30659. if (!ctrl) return;
  30660. var index = ctrl.getTabElementIndex(element),
  30661. body = firstChild(element, 'md-tab-body').remove(),
  30662. label = firstChild(element, 'md-tab-label').remove(),
  30663. data = ctrl.insertTab({
  30664. scope: scope,
  30665. parent: scope.$parent,
  30666. index: index,
  30667. element: element,
  30668. template: body.html(),
  30669. label: label.html()
  30670. }, index);
  30671. scope.select = scope.select || angular.noop;
  30672. scope.deselect = scope.deselect || angular.noop;
  30673. scope.$watch('active', function (active) { if (active) ctrl.select(data.getIndex(), true); });
  30674. scope.$watch('disabled', function () { ctrl.refreshIndex(); });
  30675. scope.$watch(
  30676. function () {
  30677. return ctrl.getTabElementIndex(element);
  30678. },
  30679. function (newIndex) {
  30680. data.index = newIndex;
  30681. ctrl.updateTabOrder();
  30682. }
  30683. );
  30684. scope.$on('$destroy', function () { ctrl.removeTab(data); });
  30685. }
  30686. function firstChild (element, tagName) {
  30687. var children = element[0].children;
  30688. for (var i = 0, len = children.length; i < len; i++) {
  30689. var child = children[i];
  30690. if (child.tagName === tagName.toUpperCase()) return angular.element(child);
  30691. }
  30692. return angular.element();
  30693. }
  30694. }
  30695. })();
  30696. (function(){
  30697. "use strict";
  30698. angular
  30699. .module('material.components.tabs')
  30700. .directive('mdTabItem', MdTabItem);
  30701. function MdTabItem () {
  30702. return {
  30703. require: '^?mdTabs',
  30704. link: function link (scope, element, attr, ctrl) {
  30705. if (!ctrl) return;
  30706. ctrl.attachRipple(scope, element);
  30707. }
  30708. };
  30709. }
  30710. })();
  30711. (function(){
  30712. "use strict";
  30713. angular
  30714. .module('material.components.tabs')
  30715. .directive('mdTabLabel', MdTabLabel);
  30716. function MdTabLabel () {
  30717. return { terminal: true };
  30718. }
  30719. })();
  30720. (function(){
  30721. "use strict";
  30722. MdTabScroll.$inject = ["$parse"];angular.module('material.components.tabs')
  30723. .directive('mdTabScroll', MdTabScroll);
  30724. function MdTabScroll ($parse) {
  30725. return {
  30726. restrict: 'A',
  30727. compile: function ($element, attr) {
  30728. var fn = $parse(attr.mdTabScroll, null, true);
  30729. return function ngEventHandler (scope, element) {
  30730. element.on('mousewheel', function (event) {
  30731. scope.$apply(function () { fn(scope, { $event: event }); });
  30732. });
  30733. };
  30734. }
  30735. };
  30736. }
  30737. })();
  30738. (function(){
  30739. "use strict";
  30740. MdTabsController.$inject = ["$scope", "$element", "$window", "$mdConstant", "$mdTabInkRipple", "$mdUtil", "$animateCss", "$attrs", "$compile", "$mdTheming", "$mdInteraction", "MdTabsPaginationService"];angular
  30741. .module('material.components.tabs')
  30742. .controller('MdTabsController', MdTabsController);
  30743. /**
  30744. * @ngInject
  30745. */
  30746. function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipple, $mdUtil,
  30747. $animateCss, $attrs, $compile, $mdTheming, $mdInteraction,
  30748. MdTabsPaginationService) {
  30749. // define private properties
  30750. var ctrl = this,
  30751. locked = false,
  30752. elements = getElements(),
  30753. queue = [],
  30754. destroyed = false,
  30755. loaded = false;
  30756. // Define public methods
  30757. ctrl.$onInit = $onInit;
  30758. ctrl.updatePagination = $mdUtil.debounce(updatePagination, 100);
  30759. ctrl.redirectFocus = redirectFocus;
  30760. ctrl.attachRipple = attachRipple;
  30761. ctrl.insertTab = insertTab;
  30762. ctrl.removeTab = removeTab;
  30763. ctrl.select = select;
  30764. ctrl.scroll = scroll;
  30765. ctrl.nextPage = nextPage;
  30766. ctrl.previousPage = previousPage;
  30767. ctrl.keydown = keydown;
  30768. ctrl.canPageForward = canPageForward;
  30769. ctrl.canPageBack = canPageBack;
  30770. ctrl.refreshIndex = refreshIndex;
  30771. ctrl.incrementIndex = incrementIndex;
  30772. ctrl.getTabElementIndex = getTabElementIndex;
  30773. ctrl.updateInkBarStyles = $mdUtil.debounce(updateInkBarStyles, 100);
  30774. ctrl.updateTabOrder = $mdUtil.debounce(updateTabOrder, 100);
  30775. ctrl.getFocusedTabId = getFocusedTabId;
  30776. // For AngularJS 1.4 and older, where there are no lifecycle hooks but bindings are pre-assigned,
  30777. // manually call the $onInit hook.
  30778. if (angular.version.major === 1 && angular.version.minor <= 4) {
  30779. this.$onInit();
  30780. }
  30781. /**
  30782. * AngularJS Lifecycle hook for newer AngularJS versions.
  30783. * Bindings are not guaranteed to have been assigned in the controller, but they are in the $onInit hook.
  30784. */
  30785. function $onInit() {
  30786. // Define one-way bindings
  30787. defineOneWayBinding('stretchTabs', handleStretchTabs);
  30788. // Define public properties with change handlers
  30789. defineProperty('focusIndex', handleFocusIndexChange, ctrl.selectedIndex || 0);
  30790. defineProperty('offsetLeft', handleOffsetChange, 0);
  30791. defineProperty('hasContent', handleHasContent, false);
  30792. defineProperty('maxTabWidth', handleMaxTabWidth, getMaxTabWidth());
  30793. defineProperty('shouldPaginate', handleShouldPaginate, false);
  30794. // Define boolean attributes
  30795. defineBooleanAttribute('noInkBar', handleInkBar);
  30796. defineBooleanAttribute('dynamicHeight', handleDynamicHeight);
  30797. defineBooleanAttribute('noPagination');
  30798. defineBooleanAttribute('swipeContent');
  30799. defineBooleanAttribute('noDisconnect');
  30800. defineBooleanAttribute('autoselect');
  30801. defineBooleanAttribute('noSelectClick');
  30802. defineBooleanAttribute('centerTabs', handleCenterTabs, false);
  30803. defineBooleanAttribute('enableDisconnect');
  30804. // Define public properties
  30805. ctrl.scope = $scope;
  30806. ctrl.parent = $scope.$parent;
  30807. ctrl.tabs = [];
  30808. ctrl.lastSelectedIndex = null;
  30809. ctrl.hasFocus = false;
  30810. ctrl.styleTabItemFocus = false;
  30811. ctrl.shouldCenterTabs = shouldCenterTabs();
  30812. ctrl.tabContentPrefix = 'tab-content-';
  30813. // Setup the tabs controller after all bindings are available.
  30814. setupTabsController();
  30815. }
  30816. /**
  30817. * Perform setup for the controller, setup events and watcher(s)
  30818. */
  30819. function setupTabsController () {
  30820. ctrl.selectedIndex = ctrl.selectedIndex || 0;
  30821. compileTemplate();
  30822. configureWatchers();
  30823. bindEvents();
  30824. $mdTheming($element);
  30825. $mdUtil.nextTick(function () {
  30826. // Note that the element references need to be updated, because certain "browsers"
  30827. // (IE/Edge) lose them and start throwing "Invalid calling object" errors, when we
  30828. // compile the element contents down in `compileElement`.
  30829. elements = getElements();
  30830. updateHeightFromContent();
  30831. adjustOffset();
  30832. updateInkBarStyles();
  30833. ctrl.tabs[ ctrl.selectedIndex ] && ctrl.tabs[ ctrl.selectedIndex ].scope.select();
  30834. loaded = true;
  30835. updatePagination();
  30836. });
  30837. }
  30838. /**
  30839. * Compiles the template provided by the user. This is passed as an attribute from the tabs
  30840. * directive's template function.
  30841. */
  30842. function compileTemplate () {
  30843. var template = $attrs.$mdTabsTemplate,
  30844. element = angular.element($element[0].querySelector('md-tab-data'));
  30845. element.html(template);
  30846. $compile(element.contents())(ctrl.parent);
  30847. delete $attrs.$mdTabsTemplate;
  30848. }
  30849. /**
  30850. * Binds events used by the tabs component.
  30851. */
  30852. function bindEvents () {
  30853. angular.element($window).on('resize', handleWindowResize);
  30854. $scope.$on('$destroy', cleanup);
  30855. }
  30856. /**
  30857. * Configure watcher(s) used by Tabs
  30858. */
  30859. function configureWatchers () {
  30860. $scope.$watch('$mdTabsCtrl.selectedIndex', handleSelectedIndexChange);
  30861. }
  30862. /**
  30863. * Creates a one-way binding manually rather than relying on AngularJS's isolated scope
  30864. * @param key
  30865. * @param handler
  30866. */
  30867. function defineOneWayBinding (key, handler) {
  30868. var attr = $attrs.$normalize('md-' + key);
  30869. if (handler) defineProperty(key, handler);
  30870. $attrs.$observe(attr, function (newValue) { ctrl[ key ] = newValue; });
  30871. }
  30872. /**
  30873. * Defines boolean attributes with default value set to true. (ie. md-stretch-tabs with no value
  30874. * will be treated as being truthy)
  30875. * @param key
  30876. * @param handler
  30877. */
  30878. function defineBooleanAttribute (key, handler) {
  30879. var attr = $attrs.$normalize('md-' + key);
  30880. if (handler) defineProperty(key, handler);
  30881. if ($attrs.hasOwnProperty(attr)) updateValue($attrs[attr]);
  30882. $attrs.$observe(attr, updateValue);
  30883. function updateValue (newValue) {
  30884. ctrl[ key ] = newValue !== 'false';
  30885. }
  30886. }
  30887. /**
  30888. * Remove any events defined by this controller
  30889. */
  30890. function cleanup () {
  30891. destroyed = true;
  30892. angular.element($window).off('resize', handleWindowResize);
  30893. }
  30894. // Change handlers
  30895. /**
  30896. * Toggles stretch tabs class and updates inkbar when tab stretching changes
  30897. * @param stretchTabs
  30898. */
  30899. function handleStretchTabs (stretchTabs) {
  30900. var elements = getElements();
  30901. angular.element(elements.wrapper).toggleClass('md-stretch-tabs', shouldStretchTabs());
  30902. updateInkBarStyles();
  30903. }
  30904. function handleCenterTabs (newValue) {
  30905. ctrl.shouldCenterTabs = shouldCenterTabs();
  30906. }
  30907. function handleMaxTabWidth (newWidth, oldWidth) {
  30908. if (newWidth !== oldWidth) {
  30909. var elements = getElements();
  30910. // Set the max width for the real tabs
  30911. angular.forEach(elements.tabs, function(tab) {
  30912. tab.style.maxWidth = newWidth + 'px';
  30913. });
  30914. // Set the max width for the dummy tabs too
  30915. angular.forEach(elements.dummies, function(tab) {
  30916. tab.style.maxWidth = newWidth + 'px';
  30917. });
  30918. $mdUtil.nextTick(ctrl.updateInkBarStyles);
  30919. }
  30920. }
  30921. function handleShouldPaginate (newValue, oldValue) {
  30922. if (newValue !== oldValue) {
  30923. ctrl.maxTabWidth = getMaxTabWidth();
  30924. ctrl.shouldCenterTabs = shouldCenterTabs();
  30925. $mdUtil.nextTick(function () {
  30926. ctrl.maxTabWidth = getMaxTabWidth();
  30927. adjustOffset(ctrl.selectedIndex);
  30928. });
  30929. }
  30930. }
  30931. /**
  30932. * Add/remove the `md-no-tab-content` class depending on `ctrl.hasContent`
  30933. * @param hasContent
  30934. */
  30935. function handleHasContent (hasContent) {
  30936. $element[ hasContent ? 'removeClass' : 'addClass' ]('md-no-tab-content');
  30937. }
  30938. /**
  30939. * Apply ctrl.offsetLeft to the paging element when it changes
  30940. * @param left
  30941. */
  30942. function handleOffsetChange (left) {
  30943. var elements = getElements();
  30944. var newValue = ((ctrl.shouldCenterTabs || isRtl() ? '' : '-') + left + 'px');
  30945. // Fix double-negative which can happen with RTL support
  30946. newValue = newValue.replace('--', '');
  30947. angular.element(elements.paging).css($mdConstant.CSS.TRANSFORM, 'translate3d(' + newValue + ', 0, 0)');
  30948. $scope.$broadcast('$mdTabsPaginationChanged');
  30949. }
  30950. /**
  30951. * Update the UI whenever `ctrl.focusIndex` is updated
  30952. * @param newIndex
  30953. * @param oldIndex
  30954. */
  30955. function handleFocusIndexChange (newIndex, oldIndex) {
  30956. if (newIndex === oldIndex) return;
  30957. if (!getElements().tabs[ newIndex ]) return;
  30958. adjustOffset();
  30959. redirectFocus();
  30960. }
  30961. /**
  30962. * Update the UI whenever the selected index changes. Calls user-defined select/deselect methods.
  30963. * @param newValue
  30964. * @param oldValue
  30965. */
  30966. function handleSelectedIndexChange (newValue, oldValue) {
  30967. if (newValue === oldValue) return;
  30968. ctrl.selectedIndex = getNearestSafeIndex(newValue);
  30969. ctrl.lastSelectedIndex = oldValue;
  30970. ctrl.updateInkBarStyles();
  30971. updateHeightFromContent();
  30972. adjustOffset(newValue);
  30973. $scope.$broadcast('$mdTabsChanged');
  30974. ctrl.tabs[ oldValue ] && ctrl.tabs[ oldValue ].scope.deselect();
  30975. ctrl.tabs[ newValue ] && ctrl.tabs[ newValue ].scope.select();
  30976. }
  30977. function getTabElementIndex(tabEl){
  30978. var tabs = $element[0].getElementsByTagName('md-tab');
  30979. return Array.prototype.indexOf.call(tabs, tabEl[0]);
  30980. }
  30981. /**
  30982. * Queues up a call to `handleWindowResize` when a resize occurs while the tabs component is
  30983. * hidden.
  30984. */
  30985. function handleResizeWhenVisible () {
  30986. // if there is already a watcher waiting for resize, do nothing
  30987. if (handleResizeWhenVisible.watcher) return;
  30988. // otherwise, we will abuse the $watch function to check for visible
  30989. handleResizeWhenVisible.watcher = $scope.$watch(function () {
  30990. // since we are checking for DOM size, we use $mdUtil.nextTick() to wait for after the DOM updates
  30991. $mdUtil.nextTick(function () {
  30992. // if the watcher has already run (ie. multiple digests in one cycle), do nothing
  30993. if (!handleResizeWhenVisible.watcher) return;
  30994. if ($element.prop('offsetParent')) {
  30995. handleResizeWhenVisible.watcher();
  30996. handleResizeWhenVisible.watcher = null;
  30997. handleWindowResize();
  30998. }
  30999. }, false);
  31000. });
  31001. }
  31002. // Event handlers / actions
  31003. /**
  31004. * Handle user keyboard interactions
  31005. * @param event
  31006. */
  31007. function keydown (event) {
  31008. switch (event.keyCode) {
  31009. case $mdConstant.KEY_CODE.LEFT_ARROW:
  31010. event.preventDefault();
  31011. incrementIndex(-1, true);
  31012. break;
  31013. case $mdConstant.KEY_CODE.RIGHT_ARROW:
  31014. event.preventDefault();
  31015. incrementIndex(1, true);
  31016. break;
  31017. case $mdConstant.KEY_CODE.SPACE:
  31018. case $mdConstant.KEY_CODE.ENTER:
  31019. event.preventDefault();
  31020. if (!locked) select(ctrl.focusIndex);
  31021. break;
  31022. case $mdConstant.KEY_CODE.TAB:
  31023. // On tabbing out of the tablist, reset hasFocus to reset ng-focused and
  31024. // its md-focused class if the focused tab is not the active tab.
  31025. if (ctrl.focusIndex !== ctrl.selectedIndex) {
  31026. ctrl.focusIndex = ctrl.selectedIndex;
  31027. }
  31028. break;
  31029. }
  31030. }
  31031. /**
  31032. * Update the selected index. Triggers a click event on the original `md-tab` element in order
  31033. * to fire user-added click events if canSkipClick or `md-no-select-click` are false.
  31034. * @param index
  31035. * @param canSkipClick Optionally allow not firing the click event if `md-no-select-click` is also true.
  31036. */
  31037. function select (index, canSkipClick) {
  31038. if (!locked) ctrl.focusIndex = ctrl.selectedIndex = index;
  31039. // skip the click event if noSelectClick is enabled
  31040. if (canSkipClick && ctrl.noSelectClick) return;
  31041. // nextTick is required to prevent errors in user-defined click events
  31042. $mdUtil.nextTick(function () {
  31043. ctrl.tabs[ index ].element.triggerHandler('click');
  31044. }, false);
  31045. }
  31046. /**
  31047. * When pagination is on, this makes sure the selected index is in view.
  31048. * @param event
  31049. */
  31050. function scroll (event) {
  31051. if (!ctrl.shouldPaginate) return;
  31052. event.preventDefault();
  31053. ctrl.offsetLeft = fixOffset(ctrl.offsetLeft - event.wheelDelta);
  31054. }
  31055. /**
  31056. * Slides the tabs over approximately one page forward.
  31057. */
  31058. function nextPage () {
  31059. if (!ctrl.canPageForward()) { return; }
  31060. var newOffset = MdTabsPaginationService.increasePageOffset(getElements(), ctrl.offsetLeft);
  31061. ctrl.offsetLeft = fixOffset(newOffset);
  31062. }
  31063. /**
  31064. * Slides the tabs over approximately one page backward.
  31065. */
  31066. function previousPage () {
  31067. if (!ctrl.canPageBack()) { return; }
  31068. var newOffset = MdTabsPaginationService.decreasePageOffset(getElements(), ctrl.offsetLeft);
  31069. // Set the new offset
  31070. ctrl.offsetLeft = fixOffset(newOffset);
  31071. }
  31072. /**
  31073. * Update size calculations when the window is resized.
  31074. */
  31075. function handleWindowResize () {
  31076. ctrl.lastSelectedIndex = ctrl.selectedIndex;
  31077. ctrl.offsetLeft = fixOffset(ctrl.offsetLeft);
  31078. $mdUtil.nextTick(function () {
  31079. ctrl.updateInkBarStyles();
  31080. updatePagination();
  31081. });
  31082. }
  31083. function handleInkBar (hide) {
  31084. angular.element(getElements().inkBar).toggleClass('ng-hide', hide);
  31085. }
  31086. /**
  31087. * Toggle dynamic height class when value changes
  31088. * @param value
  31089. */
  31090. function handleDynamicHeight (value) {
  31091. $element.toggleClass('md-dynamic-height', value);
  31092. }
  31093. /**
  31094. * Remove a tab from the data and select the nearest valid tab.
  31095. * @param tabData
  31096. */
  31097. function removeTab (tabData) {
  31098. if (destroyed) return;
  31099. var selectedIndex = ctrl.selectedIndex,
  31100. tab = ctrl.tabs.splice(tabData.getIndex(), 1)[ 0 ];
  31101. refreshIndex();
  31102. // when removing a tab, if the selected index did not change, we have to manually trigger the
  31103. // tab select/deselect events
  31104. if (ctrl.selectedIndex === selectedIndex) {
  31105. tab.scope.deselect();
  31106. ctrl.tabs[ ctrl.selectedIndex ] && ctrl.tabs[ ctrl.selectedIndex ].scope.select();
  31107. }
  31108. $mdUtil.nextTick(function () {
  31109. updatePagination();
  31110. ctrl.offsetLeft = fixOffset(ctrl.offsetLeft);
  31111. });
  31112. }
  31113. /**
  31114. * Create an entry in the tabs array for a new tab at the specified index.
  31115. * @param tabData
  31116. * @param index
  31117. * @returns {*}
  31118. */
  31119. function insertTab (tabData, index) {
  31120. var hasLoaded = loaded;
  31121. var proto = {
  31122. getIndex: function () { return ctrl.tabs.indexOf(tab); },
  31123. isActive: function () { return this.getIndex() === ctrl.selectedIndex; },
  31124. isLeft: function () { return this.getIndex() < ctrl.selectedIndex; },
  31125. isRight: function () { return this.getIndex() > ctrl.selectedIndex; },
  31126. shouldRender: function () { return !ctrl.noDisconnect || this.isActive(); },
  31127. hasFocus: function () {
  31128. return ctrl.styleTabItemFocus
  31129. && ctrl.hasFocus && this.getIndex() === ctrl.focusIndex;
  31130. },
  31131. id: $mdUtil.nextUid(),
  31132. hasContent: !!(tabData.template && tabData.template.trim())
  31133. },
  31134. tab = angular.extend(proto, tabData);
  31135. if (angular.isDefined(index)) {
  31136. ctrl.tabs.splice(index, 0, tab);
  31137. } else {
  31138. ctrl.tabs.push(tab);
  31139. }
  31140. processQueue();
  31141. updateHasContent();
  31142. $mdUtil.nextTick(function () {
  31143. updatePagination();
  31144. setAriaControls(tab);
  31145. // if autoselect is enabled, select the newly added tab
  31146. if (hasLoaded && ctrl.autoselect) $mdUtil.nextTick(function () {
  31147. $mdUtil.nextTick(function () { select(ctrl.tabs.indexOf(tab)); });
  31148. });
  31149. });
  31150. return tab;
  31151. }
  31152. // Getter methods
  31153. /**
  31154. * Gathers references to all of the DOM elements used by this controller.
  31155. * @returns {{}}
  31156. */
  31157. function getElements () {
  31158. var elements = {};
  31159. var node = $element[0];
  31160. // gather tab bar elements
  31161. elements.wrapper = node.querySelector('md-tabs-wrapper');
  31162. elements.canvas = elements.wrapper.querySelector('md-tabs-canvas');
  31163. elements.paging = elements.canvas.querySelector('md-pagination-wrapper');
  31164. elements.inkBar = elements.paging.querySelector('md-ink-bar');
  31165. elements.nextButton = node.querySelector('md-next-button');
  31166. elements.prevButton = node.querySelector('md-prev-button');
  31167. elements.contents = node.querySelectorAll('md-tabs-content-wrapper > md-tab-content');
  31168. elements.tabs = elements.paging.querySelectorAll('md-tab-item');
  31169. elements.dummies = elements.canvas.querySelectorAll('md-dummy-tab');
  31170. return elements;
  31171. }
  31172. /**
  31173. * Determines whether or not the left pagination arrow should be enabled.
  31174. * @returns {boolean}
  31175. */
  31176. function canPageBack () {
  31177. // This works for both LTR and RTL
  31178. return ctrl.offsetLeft > 0;
  31179. }
  31180. /**
  31181. * Determines whether or not the right pagination arrow should be enabled.
  31182. * @returns {*|boolean}
  31183. */
  31184. function canPageForward () {
  31185. var elements = getElements();
  31186. var lastTab = elements.tabs[ elements.tabs.length - 1 ];
  31187. if (isRtl()) {
  31188. return ctrl.offsetLeft < elements.paging.offsetWidth - elements.canvas.offsetWidth;
  31189. }
  31190. return lastTab && lastTab.offsetLeft + lastTab.offsetWidth > elements.canvas.clientWidth +
  31191. ctrl.offsetLeft;
  31192. }
  31193. /**
  31194. * Returns currently focused tab item's element ID
  31195. */
  31196. function getFocusedTabId() {
  31197. var focusedTab = ctrl.tabs[ctrl.focusIndex];
  31198. if (!focusedTab || !focusedTab.id) {
  31199. return null;
  31200. }
  31201. return 'tab-item-' + focusedTab.id;
  31202. }
  31203. /**
  31204. * Determines if the UI should stretch the tabs to fill the available space.
  31205. * @returns {*}
  31206. */
  31207. function shouldStretchTabs () {
  31208. switch (ctrl.stretchTabs) {
  31209. case 'always':
  31210. return true;
  31211. case 'never':
  31212. return false;
  31213. default:
  31214. return !ctrl.shouldPaginate
  31215. && $window.matchMedia('(max-width: 600px)').matches;
  31216. }
  31217. }
  31218. /**
  31219. * Determines if the tabs should appear centered.
  31220. * @returns {string|boolean}
  31221. */
  31222. function shouldCenterTabs () {
  31223. return ctrl.centerTabs && !ctrl.shouldPaginate;
  31224. }
  31225. /**
  31226. * Determines if pagination is necessary to display the tabs within the available space.
  31227. * @returns {boolean}
  31228. */
  31229. function shouldPaginate () {
  31230. if (ctrl.noPagination || !loaded) return false;
  31231. var canvasWidth = $element.prop('clientWidth');
  31232. angular.forEach(getElements().tabs, function (tab) {
  31233. canvasWidth -= tab.offsetWidth;
  31234. });
  31235. return canvasWidth < 0;
  31236. }
  31237. /**
  31238. * Finds the nearest tab index that is available. This is primarily used for when the active
  31239. * tab is removed.
  31240. * @param newIndex
  31241. * @returns {*}
  31242. */
  31243. function getNearestSafeIndex (newIndex) {
  31244. if (newIndex === -1) return -1;
  31245. var maxOffset = Math.max(ctrl.tabs.length - newIndex, newIndex),
  31246. i, tab;
  31247. for (i = 0; i <= maxOffset; i++) {
  31248. tab = ctrl.tabs[ newIndex + i ];
  31249. if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
  31250. tab = ctrl.tabs[ newIndex - i ];
  31251. if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
  31252. }
  31253. return newIndex;
  31254. }
  31255. // Utility methods
  31256. /**
  31257. * Defines a property using a getter and setter in order to trigger a change handler without
  31258. * using `$watch` to observe changes.
  31259. * @param key
  31260. * @param handler
  31261. * @param value
  31262. */
  31263. function defineProperty (key, handler, value) {
  31264. Object.defineProperty(ctrl, key, {
  31265. get: function () { return value; },
  31266. set: function (newValue) {
  31267. var oldValue = value;
  31268. value = newValue;
  31269. handler && handler(newValue, oldValue);
  31270. }
  31271. });
  31272. }
  31273. /**
  31274. * Updates whether or not pagination should be displayed.
  31275. */
  31276. function updatePagination () {
  31277. ctrl.maxTabWidth = getMaxTabWidth();
  31278. ctrl.shouldPaginate = shouldPaginate();
  31279. }
  31280. /**
  31281. * Calculates the width of the pagination wrapper by summing the widths of the dummy tabs.
  31282. * @returns {number}
  31283. */
  31284. function calcPagingWidth () {
  31285. return calcTabsWidth(getElements().tabs);
  31286. }
  31287. function calcTabsWidth(tabs) {
  31288. var width = 0;
  31289. angular.forEach(tabs, function (tab) {
  31290. //-- Uses the larger value between `getBoundingClientRect().width` and `offsetWidth`. This
  31291. // prevents `offsetWidth` value from being rounded down and causing wrapping issues, but
  31292. // also handles scenarios where `getBoundingClientRect()` is inaccurate (ie. tabs inside
  31293. // of a dialog)
  31294. width += Math.max(tab.offsetWidth, tab.getBoundingClientRect().width);
  31295. });
  31296. return Math.ceil(width);
  31297. }
  31298. function getMaxTabWidth () {
  31299. var elements = getElements(),
  31300. containerWidth = elements.canvas.clientWidth,
  31301. // See https://material.google.com/components/tabs.html#tabs-specs
  31302. specMax = 264;
  31303. // Do the spec maximum, or the canvas width; whichever is *smaller* (tabs larger than the canvas
  31304. // width can break the pagination) but not less than 0
  31305. return Math.max(0, Math.min(containerWidth - 1, specMax));
  31306. }
  31307. function getMinTabWidth() {
  31308. var elements = getElements(),
  31309. containerWidth = elements.canvas.clientWidth,
  31310. xsBreakpoint = 600,
  31311. // See https://material.google.com/components/tabs.html#tabs-specs
  31312. specMin = containerWidth > xsBreakpoint ? 160 : 72;
  31313. // Do the spec minimum, or the canvas width; whichever is *smaller* (tabs larger than the canvas
  31314. // width can break the pagination) but not less than 0
  31315. return Math.max(0, Math.min(containerWidth - 1, specMin));
  31316. }
  31317. /**
  31318. * Re-orders the tabs and updates the selected and focus indexes to their new positions.
  31319. * This is triggered by `tabDirective.js` when the user's tabs have been re-ordered.
  31320. */
  31321. function updateTabOrder () {
  31322. var selectedItem = ctrl.tabs[ ctrl.selectedIndex ],
  31323. focusItem = ctrl.tabs[ ctrl.focusIndex ];
  31324. ctrl.tabs = ctrl.tabs.sort(function (a, b) {
  31325. return a.index - b.index;
  31326. });
  31327. ctrl.selectedIndex = ctrl.tabs.indexOf(selectedItem);
  31328. ctrl.focusIndex = ctrl.tabs.indexOf(focusItem);
  31329. }
  31330. /**
  31331. * This moves the selected or focus index left or right. This is used by the keydown handler.
  31332. * @param inc
  31333. */
  31334. function incrementIndex (inc, focus) {
  31335. var newIndex,
  31336. key = focus ? 'focusIndex' : 'selectedIndex',
  31337. index = ctrl[ key ];
  31338. for (newIndex = index + inc;
  31339. ctrl.tabs[ newIndex ] && ctrl.tabs[ newIndex ].scope.disabled;
  31340. newIndex += inc) { /* do nothing */ }
  31341. newIndex = (index + inc + ctrl.tabs.length) % ctrl.tabs.length;
  31342. if (ctrl.tabs[ newIndex ]) {
  31343. ctrl[ key ] = newIndex;
  31344. }
  31345. }
  31346. /**
  31347. * This is used to forward focus to tab container elements. This method is necessary to avoid
  31348. * animation issues when attempting to focus an item that is out of view.
  31349. */
  31350. function redirectFocus () {
  31351. ctrl.styleTabItemFocus = ($mdInteraction.getLastInteractionType() === 'keyboard');
  31352. getElements().tabs[ ctrl.focusIndex ].focus();
  31353. }
  31354. /**
  31355. * Forces the pagination to move the focused tab into view.
  31356. */
  31357. function adjustOffset (index) {
  31358. var elements = getElements();
  31359. if (!angular.isNumber(index)) index = ctrl.focusIndex;
  31360. if (!elements.tabs[ index ]) return;
  31361. if (ctrl.shouldCenterTabs) return;
  31362. var tab = elements.tabs[ index ],
  31363. left = tab.offsetLeft,
  31364. right = tab.offsetWidth + left,
  31365. extraOffset = 32;
  31366. // If we are selecting the first tab (in LTR and RTL), always set the offset to 0
  31367. if (index == 0) {
  31368. ctrl.offsetLeft = 0;
  31369. return;
  31370. }
  31371. if (isRtl()) {
  31372. var tabWidthsBefore = calcTabsWidth(Array.prototype.slice.call(elements.tabs, 0, index));
  31373. var tabWidthsIncluding = calcTabsWidth(Array.prototype.slice.call(elements.tabs, 0, index + 1));
  31374. ctrl.offsetLeft = Math.min(ctrl.offsetLeft, fixOffset(tabWidthsBefore));
  31375. ctrl.offsetLeft = Math.max(ctrl.offsetLeft, fixOffset(tabWidthsIncluding - elements.canvas.clientWidth));
  31376. } else {
  31377. ctrl.offsetLeft = Math.max(ctrl.offsetLeft, fixOffset(right - elements.canvas.clientWidth + extraOffset));
  31378. ctrl.offsetLeft = Math.min(ctrl.offsetLeft, fixOffset(left));
  31379. }
  31380. }
  31381. /**
  31382. * Iterates through all queued functions and clears the queue. This is used for functions that
  31383. * are called before the UI is ready, such as size calculations.
  31384. */
  31385. function processQueue () {
  31386. queue.forEach(function (func) { $mdUtil.nextTick(func); });
  31387. queue = [];
  31388. }
  31389. /**
  31390. * Determines if the tab content area is needed.
  31391. */
  31392. function updateHasContent () {
  31393. var hasContent = false;
  31394. for (var i = 0; i < ctrl.tabs.length; i++) {
  31395. if (ctrl.tabs[i].hasContent) {
  31396. hasContent = true;
  31397. break;
  31398. }
  31399. }
  31400. ctrl.hasContent = hasContent;
  31401. }
  31402. /**
  31403. * Moves the indexes to their nearest valid values.
  31404. */
  31405. function refreshIndex () {
  31406. ctrl.selectedIndex = getNearestSafeIndex(ctrl.selectedIndex);
  31407. ctrl.focusIndex = getNearestSafeIndex(ctrl.focusIndex);
  31408. }
  31409. /**
  31410. * Calculates the content height of the current tab.
  31411. * @returns {*}
  31412. */
  31413. function updateHeightFromContent () {
  31414. if (!ctrl.dynamicHeight) return $element.css('height', '');
  31415. if (!ctrl.tabs.length) return queue.push(updateHeightFromContent);
  31416. var elements = getElements();
  31417. var tabContent = elements.contents[ ctrl.selectedIndex ],
  31418. contentHeight = tabContent ? tabContent.offsetHeight : 0,
  31419. tabsHeight = elements.wrapper.offsetHeight,
  31420. newHeight = contentHeight + tabsHeight,
  31421. currentHeight = $element.prop('clientHeight');
  31422. if (currentHeight === newHeight) return;
  31423. // Adjusts calculations for when the buttons are bottom-aligned since this relies on absolute
  31424. // positioning. This should probably be cleaned up if a cleaner solution is possible.
  31425. if ($element.attr('md-align-tabs') === 'bottom') {
  31426. currentHeight -= tabsHeight;
  31427. newHeight -= tabsHeight;
  31428. // Need to include bottom border in these calculations
  31429. if ($element.attr('md-border-bottom') !== undefined) ++currentHeight;
  31430. }
  31431. // Lock during animation so the user can't change tabs
  31432. locked = true;
  31433. var fromHeight = { height: currentHeight + 'px' },
  31434. toHeight = { height: newHeight + 'px' };
  31435. // Set the height to the current, specific pixel height to fix a bug on iOS where the height
  31436. // first animates to 0, then back to the proper height causing a visual glitch
  31437. $element.css(fromHeight);
  31438. // Animate the height from the old to the new
  31439. $animateCss($element, {
  31440. from: fromHeight,
  31441. to: toHeight,
  31442. easing: 'cubic-bezier(0.35, 0, 0.25, 1)',
  31443. duration: 0.5
  31444. }).start().done(function () {
  31445. // Then (to fix the same iOS issue as above), disable transitions and remove the specific
  31446. // pixel height so the height can size with browser width/content changes, etc.
  31447. $element.css({
  31448. transition: 'none',
  31449. height: ''
  31450. });
  31451. // In the next tick, re-allow transitions (if we do it all at once, $element.css is "smart"
  31452. // enough to batch it for us instead of doing it immediately, which undoes the original
  31453. // transition: none)
  31454. $mdUtil.nextTick(function() {
  31455. $element.css('transition', '');
  31456. });
  31457. // And unlock so tab changes can occur
  31458. locked = false;
  31459. });
  31460. }
  31461. /**
  31462. * Repositions the ink bar to the selected tab.
  31463. * @returns {*}
  31464. */
  31465. function updateInkBarStyles () {
  31466. var elements = getElements();
  31467. if (!elements.tabs[ ctrl.selectedIndex ]) {
  31468. angular.element(elements.inkBar).css({ left: 'auto', right: 'auto' });
  31469. return;
  31470. }
  31471. if (!ctrl.tabs.length) return queue.push(ctrl.updateInkBarStyles);
  31472. // if the element is not visible, we will not be able to calculate sizes until it is
  31473. // we should treat that as a resize event rather than just updating the ink bar
  31474. if (!$element.prop('offsetParent')) return handleResizeWhenVisible();
  31475. var index = ctrl.selectedIndex,
  31476. totalWidth = elements.paging.offsetWidth,
  31477. tab = elements.tabs[ index ],
  31478. left = tab.offsetLeft,
  31479. right = totalWidth - left - tab.offsetWidth;
  31480. if (ctrl.shouldCenterTabs) {
  31481. // We need to use the same calculate process as in the pagination wrapper, to avoid rounding deviations.
  31482. var tabWidth = calcTabsWidth(elements.tabs);
  31483. if (totalWidth > tabWidth) {
  31484. $mdUtil.nextTick(updateInkBarStyles, false);
  31485. }
  31486. }
  31487. updateInkBarClassName();
  31488. angular.element(elements.inkBar).css({ left: left + 'px', right: right + 'px' });
  31489. }
  31490. /**
  31491. * Adds left/right classes so that the ink bar will animate properly.
  31492. */
  31493. function updateInkBarClassName () {
  31494. var elements = getElements();
  31495. var newIndex = ctrl.selectedIndex,
  31496. oldIndex = ctrl.lastSelectedIndex,
  31497. ink = angular.element(elements.inkBar);
  31498. if (!angular.isNumber(oldIndex)) return;
  31499. ink
  31500. .toggleClass('md-left', newIndex < oldIndex)
  31501. .toggleClass('md-right', newIndex > oldIndex);
  31502. }
  31503. /**
  31504. * Takes an offset value and makes sure that it is within the min/max allowed values.
  31505. * @param value
  31506. * @returns {*}
  31507. */
  31508. function fixOffset (value) {
  31509. var elements = getElements();
  31510. if (!elements.tabs.length || !ctrl.shouldPaginate) return 0;
  31511. var lastTab = elements.tabs[ elements.tabs.length - 1 ],
  31512. totalWidth = lastTab.offsetLeft + lastTab.offsetWidth;
  31513. if (isRtl()) {
  31514. value = Math.min(elements.paging.offsetWidth - elements.canvas.clientWidth, value);
  31515. value = Math.max(0, value);
  31516. } else {
  31517. value = Math.max(0, value);
  31518. value = Math.min(totalWidth - elements.canvas.clientWidth, value);
  31519. }
  31520. return value;
  31521. }
  31522. /**
  31523. * Attaches a ripple to the tab item element.
  31524. * @param scope
  31525. * @param element
  31526. */
  31527. function attachRipple (scope, element) {
  31528. var elements = getElements();
  31529. var options = { colorElement: angular.element(elements.inkBar) };
  31530. $mdTabInkRipple.attach(scope, element, options);
  31531. }
  31532. /**
  31533. * Sets the `aria-controls` attribute to the elements that
  31534. * correspond to the passed-in tab.
  31535. * @param tab
  31536. */
  31537. function setAriaControls (tab) {
  31538. if (tab.hasContent) {
  31539. var nodes = $element[0].querySelectorAll('[md-tab-id="' + tab.id + '"]');
  31540. angular.element(nodes).attr('aria-controls', ctrl.tabContentPrefix + tab.id);
  31541. }
  31542. }
  31543. function isRtl() {
  31544. return ($mdUtil.bidi() == 'rtl');
  31545. }
  31546. }
  31547. })();
  31548. (function(){
  31549. "use strict";
  31550. /**
  31551. * @ngdoc directive
  31552. * @name mdTabs
  31553. * @module material.components.tabs
  31554. *
  31555. * @restrict E
  31556. *
  31557. * @description
  31558. * The `<md-tabs>` directive serves as the container for 1..n `<md-tab>` child directives to
  31559. * produces a Tabs components. In turn, the nested `<md-tab>` directive is used to specify a tab
  31560. * label for the **header button** and a [optional] tab view content that will be associated with
  31561. * each tab button.
  31562. *
  31563. * Below is the markup for its simplest usage:
  31564. *
  31565. * <hljs lang="html">
  31566. * <md-tabs>
  31567. * <md-tab label="Tab #1"></md-tab>
  31568. * <md-tab label="Tab #2"></md-tab>
  31569. * <md-tab label="Tab #3"></md-tab>
  31570. * </md-tabs>
  31571. * </hljs>
  31572. *
  31573. * Tabs supports three (3) usage scenarios:
  31574. *
  31575. * 1. Tabs (buttons only)
  31576. * 2. Tabs with internal view content
  31577. * 3. Tabs with external view content
  31578. *
  31579. * **Tab-only** support is useful when tab buttons are used for custom navigation regardless of any
  31580. * other components, content, or views.
  31581. *
  31582. * <i><b>Note:</b> If you are using the Tabs component for page-level navigation, please take a look
  31583. * at the <a ng-href="./api/directive/mdNavBar">NavBar component</a> instead as it can handle this
  31584. * case a bit more natively.</i>
  31585. *
  31586. * **Tabs with internal views** are the traditional usages where each tab has associated view
  31587. * content and the view switching is managed internally by the Tabs component.
  31588. *
  31589. * **Tabs with external view content** is often useful when content associated with each tab is
  31590. * independently managed and data-binding notifications announce tab selection changes.
  31591. *
  31592. * Additional features also include:
  31593. *
  31594. * * Content can include any markup.
  31595. * * If a tab is disabled while active/selected, then the next tab will be auto-selected.
  31596. *
  31597. * ### Explanation of tab stretching
  31598. *
  31599. * Initially, tabs will have an inherent size. This size will either be defined by how much space is needed to accommodate their text or set by the user through CSS. Calculations will be based on this size.
  31600. *
  31601. * On mobile devices, tabs will be expanded to fill the available horizontal space. When this happens, all tabs will become the same size.
  31602. *
  31603. * On desktops, by default, stretching will never occur.
  31604. *
  31605. * This default behavior can be overridden through the `md-stretch-tabs` attribute. Here is a table showing when stretching will occur:
  31606. *
  31607. * `md-stretch-tabs` | mobile | desktop
  31608. * ------------------|-----------|--------
  31609. * `auto` | stretched | ---
  31610. * `always` | stretched | stretched
  31611. * `never` | --- | ---
  31612. *
  31613. * @param {integer=} md-selected Index of the active/selected tab
  31614. * @param {boolean=} md-no-ink If present, disables ink ripple effects.
  31615. * @param {boolean=} md-no-ink-bar If present, disables the selection ink bar.
  31616. * @param {string=} md-align-tabs Attribute to indicate position of tab buttons: `bottom` or `top`; default is `top`
  31617. * @param {string=} md-stretch-tabs Attribute to indicate whether or not to stretch tabs: `auto`, `always`, or `never`; default is `auto`
  31618. * @param {boolean=} md-dynamic-height When enabled, the tab wrapper will resize based on the contents of the selected tab
  31619. * @param {boolean=} md-border-bottom If present, shows a solid `1px` border between the tabs and their content
  31620. * @param {boolean=} md-center-tabs When enabled, tabs will be centered provided there is no need for pagination
  31621. * @param {boolean=} md-no-pagination When enabled, pagination will remain off
  31622. * @param {boolean=} md-swipe-content When enabled, swipe gestures will be enabled for the content area to jump between tabs
  31623. * @param {boolean=} md-enable-disconnect When enabled, scopes will be disconnected for tabs that are not being displayed. This provides a performance boost, but may also cause unexpected issues and is not recommended for most users.
  31624. * @param {boolean=} md-autoselect When present, any tabs added after the initial load will be automatically selected
  31625. * @param {boolean=} md-no-select-click When enabled, click events will not be fired when selecting tabs
  31626. *
  31627. * @usage
  31628. * <hljs lang="html">
  31629. * <md-tabs md-selected="selectedIndex" >
  31630. * <img ng-src="img/angular.png" class="centered">
  31631. * <md-tab
  31632. * ng-repeat="tab in tabs | orderBy:predicate:reversed"
  31633. * md-on-select="onTabSelected(tab)"
  31634. * md-on-deselect="announceDeselected(tab)"
  31635. * ng-disabled="tab.disabled">
  31636. * <md-tab-label>
  31637. * {{tab.title}}
  31638. * <img src="img/removeTab.png" ng-click="removeTab(tab)" class="delete">
  31639. * </md-tab-label>
  31640. * <md-tab-body>
  31641. * {{tab.content}}
  31642. * </md-tab-body>
  31643. * </md-tab>
  31644. * </md-tabs>
  31645. * </hljs>
  31646. *
  31647. */
  31648. MdTabs.$inject = ["$$mdSvgRegistry"];
  31649. angular
  31650. .module('material.components.tabs')
  31651. .directive('mdTabs', MdTabs);
  31652. function MdTabs ($$mdSvgRegistry) {
  31653. return {
  31654. scope: {
  31655. selectedIndex: '=?mdSelected'
  31656. },
  31657. template: function (element, attr) {
  31658. attr.$mdTabsTemplate = element.html();
  31659. return '' +
  31660. '<md-tabs-wrapper> ' +
  31661. '<md-tab-data></md-tab-data> ' +
  31662. '<md-prev-button ' +
  31663. 'tabindex="-1" ' +
  31664. 'role="button" ' +
  31665. 'aria-label="Previous Page" ' +
  31666. 'aria-disabled="{{!$mdTabsCtrl.canPageBack()}}" ' +
  31667. 'ng-class="{ \'md-disabled\': !$mdTabsCtrl.canPageBack() }" ' +
  31668. 'ng-if="$mdTabsCtrl.shouldPaginate" ' +
  31669. 'ng-click="$mdTabsCtrl.previousPage()"> ' +
  31670. '<md-icon md-svg-src="'+ $$mdSvgRegistry.mdTabsArrow +'"></md-icon> ' +
  31671. '</md-prev-button> ' +
  31672. '<md-next-button ' +
  31673. 'tabindex="-1" ' +
  31674. 'role="button" ' +
  31675. 'aria-label="Next Page" ' +
  31676. 'aria-disabled="{{!$mdTabsCtrl.canPageForward()}}" ' +
  31677. 'ng-class="{ \'md-disabled\': !$mdTabsCtrl.canPageForward() }" ' +
  31678. 'ng-if="$mdTabsCtrl.shouldPaginate" ' +
  31679. 'ng-click="$mdTabsCtrl.nextPage()"> ' +
  31680. '<md-icon md-svg-src="'+ $$mdSvgRegistry.mdTabsArrow +'"></md-icon> ' +
  31681. '</md-next-button> ' +
  31682. '<md-tabs-canvas ' +
  31683. 'ng-focus="$mdTabsCtrl.redirectFocus()" ' +
  31684. 'ng-class="{ ' +
  31685. '\'md-paginated\': $mdTabsCtrl.shouldPaginate, ' +
  31686. '\'md-center-tabs\': $mdTabsCtrl.shouldCenterTabs ' +
  31687. '}" ' +
  31688. 'ng-keydown="$mdTabsCtrl.keydown($event)"> ' +
  31689. '<md-pagination-wrapper ' +
  31690. 'ng-class="{ \'md-center-tabs\': $mdTabsCtrl.shouldCenterTabs }" ' +
  31691. 'md-tab-scroll="$mdTabsCtrl.scroll($event)" ' +
  31692. 'role="tablist"> ' +
  31693. '<md-tab-item ' +
  31694. 'tabindex="{{ tab.isActive() ? 0 : -1 }}" ' +
  31695. 'class="md-tab" ' +
  31696. 'ng-repeat="tab in $mdTabsCtrl.tabs" ' +
  31697. 'role="tab" ' +
  31698. 'id="tab-item-{{::tab.id}}" ' +
  31699. 'md-tab-id="{{::tab.id}}"' +
  31700. 'aria-selected="{{tab.isActive()}}" ' +
  31701. 'aria-disabled="{{tab.scope.disabled || \'false\'}}" ' +
  31702. 'ng-click="$mdTabsCtrl.select(tab.getIndex())" ' +
  31703. 'ng-focus="$mdTabsCtrl.hasFocus = true" ' +
  31704. 'ng-blur="$mdTabsCtrl.hasFocus = false" ' +
  31705. 'ng-class="{ ' +
  31706. '\'md-active\': tab.isActive(), ' +
  31707. '\'md-focused\': tab.hasFocus(), ' +
  31708. '\'md-disabled\': tab.scope.disabled ' +
  31709. '}" ' +
  31710. 'ng-disabled="tab.scope.disabled" ' +
  31711. 'md-swipe-left="$mdTabsCtrl.nextPage()" ' +
  31712. 'md-swipe-right="$mdTabsCtrl.previousPage()" ' +
  31713. 'md-tabs-template="::tab.label" ' +
  31714. 'md-scope="::tab.parent"></md-tab-item> ' +
  31715. '<md-ink-bar></md-ink-bar> ' +
  31716. '</md-pagination-wrapper> ' +
  31717. '<md-tabs-dummy-wrapper aria-hidden="true" class="md-visually-hidden md-dummy-wrapper"> ' +
  31718. '<md-dummy-tab ' +
  31719. 'class="md-tab" ' +
  31720. 'tabindex="-1" ' +
  31721. 'ng-repeat="tab in $mdTabsCtrl.tabs" ' +
  31722. 'md-tabs-template="::tab.label" ' +
  31723. 'md-scope="::tab.parent"></md-dummy-tab> ' +
  31724. '</md-tabs-dummy-wrapper> ' +
  31725. '</md-tabs-canvas> ' +
  31726. '</md-tabs-wrapper> ' +
  31727. '<md-tabs-content-wrapper ng-show="$mdTabsCtrl.hasContent && $mdTabsCtrl.selectedIndex >= 0" class="_md"> ' +
  31728. '<md-tab-content ' +
  31729. 'id="{{:: $mdTabsCtrl.tabContentPrefix + tab.id}}" ' +
  31730. 'class="_md" ' +
  31731. 'role="tabpanel" ' +
  31732. 'aria-labelledby="tab-item-{{::tab.id}}" ' +
  31733. 'md-swipe-left="$mdTabsCtrl.swipeContent && $mdTabsCtrl.incrementIndex(1)" ' +
  31734. 'md-swipe-right="$mdTabsCtrl.swipeContent && $mdTabsCtrl.incrementIndex(-1)" ' +
  31735. 'ng-if="tab.hasContent" ' +
  31736. 'ng-repeat="(index, tab) in $mdTabsCtrl.tabs" ' +
  31737. 'ng-class="{ ' +
  31738. '\'md-no-transition\': $mdTabsCtrl.lastSelectedIndex == null, ' +
  31739. '\'md-active\': tab.isActive(), ' +
  31740. '\'md-left\': tab.isLeft(), ' +
  31741. '\'md-right\': tab.isRight(), ' +
  31742. '\'md-no-scroll\': $mdTabsCtrl.dynamicHeight ' +
  31743. '}"> ' +
  31744. '<div ' +
  31745. 'md-tabs-template="::tab.template" ' +
  31746. 'md-connected-if="tab.isActive()" ' +
  31747. 'md-scope="::tab.parent" ' +
  31748. 'ng-if="$mdTabsCtrl.enableDisconnect || tab.shouldRender()"></div> ' +
  31749. '</md-tab-content> ' +
  31750. '</md-tabs-content-wrapper>';
  31751. },
  31752. controller: 'MdTabsController',
  31753. controllerAs: '$mdTabsCtrl',
  31754. bindToController: true
  31755. };
  31756. }
  31757. })();
  31758. (function(){
  31759. "use strict";
  31760. MdTabsDummyWrapper.$inject = ["$mdUtil", "$window"];angular
  31761. .module('material.components.tabs')
  31762. .directive('mdTabsDummyWrapper', MdTabsDummyWrapper);
  31763. /**
  31764. * @private
  31765. *
  31766. * @param $mdUtil
  31767. * @param $window
  31768. * @returns {{require: string, link: link}}
  31769. * @constructor
  31770. *
  31771. * @ngInject
  31772. */
  31773. function MdTabsDummyWrapper ($mdUtil, $window) {
  31774. return {
  31775. require: '^?mdTabs',
  31776. link: function link (scope, element, attr, ctrl) {
  31777. if (!ctrl) return;
  31778. var observer;
  31779. var disconnect;
  31780. var mutationCallback = function() {
  31781. ctrl.updatePagination();
  31782. ctrl.updateInkBarStyles();
  31783. };
  31784. if('MutationObserver' in $window) {
  31785. var config = {
  31786. childList: true,
  31787. subtree: true,
  31788. // Per https://bugzilla.mozilla.org/show_bug.cgi?id=1138368, browsers will not fire
  31789. // the childList mutation, once a <span> element's innerText changes.
  31790. // The characterData of the <span> element will change.
  31791. characterData: true
  31792. };
  31793. observer = new MutationObserver(mutationCallback);
  31794. observer.observe(element[0], config);
  31795. disconnect = observer.disconnect.bind(observer);
  31796. } else {
  31797. var debounced = $mdUtil.debounce(mutationCallback, 15, null, false);
  31798. element.on('DOMSubtreeModified', debounced);
  31799. disconnect = element.off.bind(element, 'DOMSubtreeModified', debounced);
  31800. }
  31801. // Disconnect the observer
  31802. scope.$on('$destroy', function() {
  31803. disconnect();
  31804. });
  31805. }
  31806. };
  31807. }
  31808. })();
  31809. (function(){
  31810. "use strict";
  31811. MdTabsTemplate.$inject = ["$compile", "$mdUtil"];angular
  31812. .module('material.components.tabs')
  31813. .directive('mdTabsTemplate', MdTabsTemplate);
  31814. function MdTabsTemplate ($compile, $mdUtil) {
  31815. return {
  31816. restrict: 'A',
  31817. link: link,
  31818. scope: {
  31819. template: '=mdTabsTemplate',
  31820. connected: '=?mdConnectedIf',
  31821. compileScope: '=mdScope'
  31822. },
  31823. require: '^?mdTabs'
  31824. };
  31825. function link (scope, element, attr, ctrl) {
  31826. if (!ctrl) return;
  31827. var compileScope = ctrl.enableDisconnect ? scope.compileScope.$new() : scope.compileScope;
  31828. element.html(scope.template);
  31829. $compile(element.contents())(compileScope);
  31830. return $mdUtil.nextTick(handleScope);
  31831. function handleScope () {
  31832. scope.$watch('connected', function (value) { value === false ? disconnect() : reconnect(); });
  31833. scope.$on('$destroy', reconnect);
  31834. }
  31835. function disconnect () {
  31836. if (ctrl.enableDisconnect) $mdUtil.disconnectScope(compileScope);
  31837. }
  31838. function reconnect () {
  31839. if (ctrl.enableDisconnect) $mdUtil.reconnectScope(compileScope);
  31840. }
  31841. }
  31842. }
  31843. })();
  31844. (function(){
  31845. angular.module("material.core").constant("$MD_THEME_CSS", "md-autocomplete.md-THEME_NAME-theme{background:\"{{background-hue-1}}\"}md-autocomplete.md-THEME_NAME-theme[disabled]:not([md-floating-label]){background:\"{{background-hue-2}}\"}md-autocomplete.md-THEME_NAME-theme button md-icon path{fill:\"{{background-600}}\"}md-autocomplete.md-THEME_NAME-theme button:after{background:\"{{background-600-0.3}}\"}md-autocomplete.md-THEME_NAME-theme input{color:\"{{foreground-1}}\"}.md-autocomplete-suggestions-container.md-THEME_NAME-theme{background:\"{{background-hue-1}}\"}.md-autocomplete-suggestions-container.md-THEME_NAME-theme li{color:\"{{foreground-1}}\"}.md-autocomplete-suggestions-container.md-THEME_NAME-theme li .highlight{color:\"{{background-600}}\"}.md-autocomplete-suggestions-container.md-THEME_NAME-theme li.selected,.md-autocomplete-suggestions-container.md-THEME_NAME-theme li:hover{background:\"{{background-500-0.18}}\"}md-backdrop{background-color:\"{{background-900-0.0}}\"}md-backdrop.md-opaque.md-THEME_NAME-theme{background-color:\"{{background-900-1.0}}\"}md-bottom-sheet.md-THEME_NAME-theme{background-color:\"{{background-50}}\";border-top-color:\"{{background-300}}\"}md-bottom-sheet.md-THEME_NAME-theme.md-list md-list-item{color:\"{{foreground-1}}\"}md-bottom-sheet.md-THEME_NAME-theme .md-subheader{background-color:\"{{background-50}}\";color:\"{{foreground-1}}\"}.md-button.md-THEME_NAME-theme:not([disabled]).md-focused,.md-button.md-THEME_NAME-theme:not([disabled]):hover{background-color:\"{{background-500-0.2}}\"}.md-button.md-THEME_NAME-theme:not([disabled]).md-icon-button:hover{background-color:transparent}.md-button.md-THEME_NAME-theme.md-fab md-icon{color:\"{{accent-contrast}}\"}.md-button.md-THEME_NAME-theme.md-primary{color:\"{{primary-color}}\"}.md-button.md-THEME_NAME-theme.md-primary.md-fab,.md-button.md-THEME_NAME-theme.md-primary.md-raised{color:\"{{primary-contrast}}\";background-color:\"{{primary-color}}\"}.md-button.md-THEME_NAME-theme.md-primary.md-fab:not([disabled]) md-icon,.md-button.md-THEME_NAME-theme.md-primary.md-raised:not([disabled]) md-icon{color:\"{{primary-contrast}}\"}.md-button.md-THEME_NAME-theme.md-primary.md-fab:not([disabled]).md-focused,.md-button.md-THEME_NAME-theme.md-primary.md-fab:not([disabled]):hover,.md-button.md-THEME_NAME-theme.md-primary.md-raised:not([disabled]).md-focused,.md-button.md-THEME_NAME-theme.md-primary.md-raised:not([disabled]):hover{background-color:\"{{primary-600}}\"}.md-button.md-THEME_NAME-theme.md-primary:not([disabled]) md-icon{color:\"{{primary-color}}\"}.md-button.md-THEME_NAME-theme.md-fab{background-color:\"{{accent-color}}\";color:\"{{accent-contrast}}\"}.md-button.md-THEME_NAME-theme.md-fab:not([disabled]) .md-icon{color:\"{{accent-contrast}}\"}.md-button.md-THEME_NAME-theme.md-fab:not([disabled]).md-focused,.md-button.md-THEME_NAME-theme.md-fab:not([disabled]):hover{background-color:\"{{accent-A700}}\"}.md-button.md-THEME_NAME-theme.md-raised{color:\"{{background-900}}\";background-color:\"{{background-50}}\"}.md-button.md-THEME_NAME-theme.md-raised:not([disabled]) md-icon{color:\"{{background-900}}\"}.md-button.md-THEME_NAME-theme.md-raised:not([disabled]):hover{background-color:\"{{background-50}}\"}.md-button.md-THEME_NAME-theme.md-raised:not([disabled]).md-focused{background-color:\"{{background-200}}\"}.md-button.md-THEME_NAME-theme.md-warn{color:\"{{warn-color}}\"}.md-button.md-THEME_NAME-theme.md-warn.md-fab,.md-button.md-THEME_NAME-theme.md-warn.md-raised{color:\"{{warn-contrast}}\";background-color:\"{{warn-color}}\"}.md-button.md-THEME_NAME-theme.md-warn.md-fab:not([disabled]) md-icon,.md-button.md-THEME_NAME-theme.md-warn.md-raised:not([disabled]) md-icon{color:\"{{warn-contrast}}\"}.md-button.md-THEME_NAME-theme.md-warn.md-fab:not([disabled]).md-focused,.md-button.md-THEME_NAME-theme.md-warn.md-fab:not([disabled]):hover,.md-button.md-THEME_NAME-theme.md-warn.md-raised:not([disabled]).md-focused,.md-button.md-THEME_NAME-theme.md-warn.md-raised:not([disabled]):hover{background-color:\"{{warn-600}}\"}.md-button.md-THEME_NAME-theme.md-warn:not([disabled]) md-icon{color:\"{{warn-color}}\"}.md-button.md-THEME_NAME-theme.md-accent{color:\"{{accent-color}}\"}.md-button.md-THEME_NAME-theme.md-accent.md-fab,.md-button.md-THEME_NAME-theme.md-accent.md-raised{color:\"{{accent-contrast}}\";background-color:\"{{accent-color}}\"}.md-button.md-THEME_NAME-theme.md-accent.md-fab:not([disabled]) md-icon,.md-button.md-THEME_NAME-theme.md-accent.md-raised:not([disabled]) md-icon{color:\"{{accent-contrast}}\"}.md-button.md-THEME_NAME-theme.md-accent.md-fab:not([disabled]).md-focused,.md-button.md-THEME_NAME-theme.md-accent.md-fab:not([disabled]):hover,.md-button.md-THEME_NAME-theme.md-accent.md-raised:not([disabled]).md-focused,.md-button.md-THEME_NAME-theme.md-accent.md-raised:not([disabled]):hover{background-color:\"{{accent-A700}}\"}.md-button.md-THEME_NAME-theme.md-accent:not([disabled]) md-icon{color:\"{{accent-color}}\"}.md-button.md-THEME_NAME-theme.md-accent[disabled],.md-button.md-THEME_NAME-theme.md-fab[disabled],.md-button.md-THEME_NAME-theme.md-raised[disabled],.md-button.md-THEME_NAME-theme.md-warn[disabled],.md-button.md-THEME_NAME-theme[disabled]{color:\"{{foreground-3}}\";cursor:default}.md-button.md-THEME_NAME-theme.md-accent[disabled] md-icon,.md-button.md-THEME_NAME-theme.md-fab[disabled] md-icon,.md-button.md-THEME_NAME-theme.md-raised[disabled] md-icon,.md-button.md-THEME_NAME-theme.md-warn[disabled] md-icon,.md-button.md-THEME_NAME-theme[disabled] md-icon{color:\"{{foreground-3}}\"}.md-button.md-THEME_NAME-theme.md-fab[disabled],.md-button.md-THEME_NAME-theme.md-raised[disabled]{background-color:\"{{foreground-4}}\"}.md-button.md-THEME_NAME-theme[disabled]{background-color:transparent}._md a.md-THEME_NAME-theme:not(.md-button).md-primary{color:\"{{primary-color}}\"}._md a.md-THEME_NAME-theme:not(.md-button).md-primary:hover{color:\"{{primary-700}}\"}._md a.md-THEME_NAME-theme:not(.md-button).md-accent{color:\"{{accent-color}}\"}._md a.md-THEME_NAME-theme:not(.md-button).md-accent:hover{color:\"{{accent-A700}}\"}._md a.md-THEME_NAME-theme:not(.md-button).md-warn{color:\"{{warn-color}}\"}._md a.md-THEME_NAME-theme:not(.md-button).md-warn:hover{color:\"{{warn-700}}\"}md-card.md-THEME_NAME-theme{color:\"{{foreground-1}}\";background-color:\"{{background-hue-1}}\";border-radius:2px}md-card.md-THEME_NAME-theme .md-card-image{border-radius:2px 2px 0 0}md-card.md-THEME_NAME-theme md-card-header md-card-avatar md-icon{color:\"{{background-color}}\";background-color:\"{{foreground-3}}\"}md-card.md-THEME_NAME-theme md-card-header md-card-header-text .md-subhead,md-card.md-THEME_NAME-theme md-card-title md-card-title-text:not(:only-child) .md-subhead{color:\"{{foreground-2}}\"}md-checkbox.md-THEME_NAME-theme .md-ripple{color:\"{{accent-A700}}\"}md-checkbox.md-THEME_NAME-theme.md-checked .md-ripple{color:\"{{background-600}}\"}md-checkbox.md-THEME_NAME-theme.md-checked.md-focused .md-container:before{background-color:\"{{accent-color-0.26}}\"}md-checkbox.md-THEME_NAME-theme .md-ink-ripple{color:\"{{foreground-2}}\"}md-checkbox.md-THEME_NAME-theme.md-checked .md-ink-ripple{color:\"{{accent-color-0.87}}\"}md-checkbox.md-THEME_NAME-theme:not(.md-checked) .md-icon{border-color:\"{{foreground-2}}\"}md-checkbox.md-THEME_NAME-theme.md-checked .md-icon{background-color:\"{{accent-color-0.87}}\"}md-checkbox.md-THEME_NAME-theme.md-checked .md-icon:after{border-color:\"{{accent-contrast-0.87}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-primary .md-ripple{color:\"{{primary-600}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-primary.md-checked .md-ripple{color:\"{{background-600}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-primary .md-ink-ripple{color:\"{{foreground-2}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-primary.md-checked .md-ink-ripple{color:\"{{primary-color-0.87}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-primary:not(.md-checked) .md-icon{border-color:\"{{foreground-2}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-primary.md-checked .md-icon{background-color:\"{{primary-color-0.87}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-primary.md-checked.md-focused .md-container:before{background-color:\"{{primary-color-0.26}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-primary.md-checked .md-icon:after{border-color:\"{{primary-contrast-0.87}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-primary .md-indeterminate[disabled] .md-container{color:\"{{foreground-3}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-warn .md-ripple{color:\"{{warn-600}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-warn .md-ink-ripple{color:\"{{foreground-2}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-warn.md-checked .md-ink-ripple{color:\"{{warn-color-0.87}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-warn:not(.md-checked) .md-icon{border-color:\"{{foreground-2}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-warn.md-checked .md-icon{background-color:\"{{warn-color-0.87}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-warn.md-checked.md-focused:not([disabled]) .md-container:before{background-color:\"{{warn-color-0.26}}\"}md-checkbox.md-THEME_NAME-theme:not([disabled]).md-warn.md-checked .md-icon:after{border-color:\"{{background-200}}\"}md-checkbox.md-THEME_NAME-theme[disabled]:not(.md-checked) .md-icon{border-color:\"{{foreground-3}}\"}md-checkbox.md-THEME_NAME-theme[disabled].md-checked .md-icon{background-color:\"{{foreground-3}}\"}md-checkbox.md-THEME_NAME-theme[disabled].md-checked .md-icon:after{border-color:\"{{background-200}}\"}md-checkbox.md-THEME_NAME-theme[disabled] .md-icon:after{border-color:\"{{foreground-3}}\"}md-checkbox.md-THEME_NAME-theme[disabled] .md-label{color:\"{{foreground-3}}\"}md-chips.md-THEME_NAME-theme .md-chips{box-shadow:0 1px \"{{foreground-4}}\"}md-chips.md-THEME_NAME-theme .md-chips.md-focused{box-shadow:0 2px \"{{primary-color}}\"}md-chips.md-THEME_NAME-theme .md-chips .md-chip-input-container input{color:\"{{foreground-1}}\"}md-chips.md-THEME_NAME-theme .md-chips .md-chip-input-container input:-moz-placeholder,md-chips.md-THEME_NAME-theme .md-chips .md-chip-input-container input::-moz-placeholder{color:\"{{foreground-3}}\"}md-chips.md-THEME_NAME-theme .md-chips .md-chip-input-container input:-ms-input-placeholder{color:\"{{foreground-3}}\"}md-chips.md-THEME_NAME-theme .md-chips .md-chip-input-container input::-webkit-input-placeholder{color:\"{{foreground-3}}\"}md-chips.md-THEME_NAME-theme md-chip{background:\"{{background-300}}\";color:\"{{background-800}}\"}md-chips.md-THEME_NAME-theme md-chip md-icon{color:\"{{background-700}}\"}md-chips.md-THEME_NAME-theme md-chip.md-focused{background:\"{{primary-color}}\";color:\"{{primary-contrast}}\"}md-chips.md-THEME_NAME-theme md-chip.md-focused md-icon{color:\"{{primary-contrast}}\"}md-chips.md-THEME_NAME-theme md-chip._md-chip-editing{background:transparent;color:\"{{background-800}}\"}md-chips.md-THEME_NAME-theme md-chip-remove .md-button md-icon path{fill:\"{{background-500}}\"}.md-contact-suggestion span.md-contact-email{color:\"{{background-400}}\"}md-content.md-THEME_NAME-theme{color:\"{{foreground-1}}\";background-color:\"{{background-default}}\"}.md-calendar.md-THEME_NAME-theme{background:\"{{background-hue-1}}\";color:\"{{foreground-1-0.87}}\"}.md-calendar.md-THEME_NAME-theme tr:last-child td{border-bottom-color:\"{{background-hue-2}}\"}.md-THEME_NAME-theme .md-calendar-day-header{background:\"{{background-500-0.32}}\";color:\"{{foreground-1-0.87}}\"}.md-THEME_NAME-theme .md-calendar-date.md-calendar-date-today .md-calendar-date-selection-indicator{border:1px solid \"{{primary-500}}\"}.md-THEME_NAME-theme .md-calendar-date.md-calendar-date-today.md-calendar-date-disabled{color:\"{{primary-500-0.6}}\"}.md-calendar-date.md-focus .md-THEME_NAME-theme .md-calendar-date-selection-indicator,.md-THEME_NAME-theme .md-calendar-date-selection-indicator:hover{background:\"{{background-500-0.32}}\"}.md-THEME_NAME-theme .md-calendar-date.md-calendar-selected-date .md-calendar-date-selection-indicator,.md-THEME_NAME-theme .md-calendar-date.md-focus.md-calendar-selected-date .md-calendar-date-selection-indicator{background:\"{{primary-500}}\";color:\"{{primary-500-contrast}}\";border-color:transparent}.md-THEME_NAME-theme .md-calendar-date-disabled,.md-THEME_NAME-theme .md-calendar-month-label-disabled{color:\"{{foreground-3}}\"}.md-THEME_NAME-theme .md-datepicker-input{color:\"{{foreground-1}}\"}.md-THEME_NAME-theme .md-datepicker-input:-moz-placeholder,.md-THEME_NAME-theme .md-datepicker-input::-moz-placeholder{color:\"{{foreground-3}}\"}.md-THEME_NAME-theme .md-datepicker-input:-ms-input-placeholder{color:\"{{foreground-3}}\"}.md-THEME_NAME-theme .md-datepicker-input::-webkit-input-placeholder{color:\"{{foreground-3}}\"}.md-THEME_NAME-theme .md-datepicker-input-container{border-bottom-color:\"{{foreground-4}}\"}.md-THEME_NAME-theme .md-datepicker-input-container.md-datepicker-focused{border-bottom-color:\"{{primary-color}}\"}.md-accent .md-THEME_NAME-theme .md-datepicker-input-container.md-datepicker-focused{border-bottom-color:\"{{accent-color}}\"}.md-THEME_NAME-theme .md-datepicker-input-container.md-datepicker-invalid,.md-warn .md-THEME_NAME-theme .md-datepicker-input-container.md-datepicker-focused{border-bottom-color:\"{{warn-A700}}\"}.md-THEME_NAME-theme .md-datepicker-calendar-pane{border-color:\"{{background-hue-1}}\"}.md-THEME_NAME-theme .md-datepicker-triangle-button .md-datepicker-expand-triangle{border-top-color:\"{{foreground-2}}\"}.md-THEME_NAME-theme .md-datepicker-open .md-datepicker-calendar-icon{color:\"{{primary-color}}\"}.md-accent .md-THEME_NAME-theme .md-datepicker-open .md-datepicker-calendar-icon,.md-THEME_NAME-theme .md-datepicker-open.md-accent .md-datepicker-calendar-icon{color:\"{{accent-color}}\"}.md-THEME_NAME-theme .md-datepicker-open.md-warn .md-datepicker-calendar-icon,.md-warn .md-THEME_NAME-theme .md-datepicker-open .md-datepicker-calendar-icon{color:\"{{warn-A700}}\"}.md-THEME_NAME-theme .md-datepicker-calendar{background:\"{{background-hue-1}}\"}.md-THEME_NAME-theme .md-datepicker-input-mask-opaque{box-shadow:0 0 0 9999px \"{{background-hue-1}}\"}.md-THEME_NAME-theme .md-datepicker-open .md-datepicker-input-container{background:\"{{background-hue-1}}\"}md-dialog.md-THEME_NAME-theme{border-radius:4px;background-color:\"{{background-hue-1}}\";color:\"{{foreground-1}}\"}md-dialog.md-THEME_NAME-theme.md-content-overflow .md-actions,md-dialog.md-THEME_NAME-theme.md-content-overflow md-dialog-actions,md-divider.md-THEME_NAME-theme{border-top-color:\"{{foreground-4}}\"}.layout-gt-lg-row>md-divider.md-THEME_NAME-theme,.layout-gt-md-row>md-divider.md-THEME_NAME-theme,.layout-gt-sm-row>md-divider.md-THEME_NAME-theme,.layout-gt-xs-row>md-divider.md-THEME_NAME-theme,.layout-lg-row>md-divider.md-THEME_NAME-theme,.layout-md-row>md-divider.md-THEME_NAME-theme,.layout-row>md-divider.md-THEME_NAME-theme,.layout-sm-row>md-divider.md-THEME_NAME-theme,.layout-xl-row>md-divider.md-THEME_NAME-theme,.layout-xs-row>md-divider.md-THEME_NAME-theme{border-right-color:\"{{foreground-4}}\"}md-icon.md-THEME_NAME-theme{color:\"{{foreground-2}}\"}md-icon.md-THEME_NAME-theme.md-primary{color:\"{{primary-color}}\"}md-icon.md-THEME_NAME-theme.md-accent{color:\"{{accent-color}}\"}md-icon.md-THEME_NAME-theme.md-warn{color:\"{{warn-color}}\"}md-input-container.md-THEME_NAME-theme .md-input{color:\"{{foreground-1}}\";border-color:\"{{foreground-4}}\"}md-input-container.md-THEME_NAME-theme .md-input:-moz-placeholder,md-input-container.md-THEME_NAME-theme .md-input::-moz-placeholder{color:\"{{foreground-3}}\"}md-input-container.md-THEME_NAME-theme .md-input:-ms-input-placeholder{color:\"{{foreground-3}}\"}md-input-container.md-THEME_NAME-theme .md-input::-webkit-input-placeholder{color:\"{{foreground-3}}\"}md-input-container.md-THEME_NAME-theme>md-icon{color:\"{{foreground-1}}\"}md-input-container.md-THEME_NAME-theme .md-placeholder,md-input-container.md-THEME_NAME-theme label{color:\"{{foreground-3}}\"}md-input-container.md-THEME_NAME-theme label.md-required:after{color:\"{{warn-A700}}\"}md-input-container.md-THEME_NAME-theme:not(.md-input-focused):not(.md-input-invalid) label.md-required:after{color:\"{{foreground-2}}\"}md-input-container.md-THEME_NAME-theme .md-input-message-animation,md-input-container.md-THEME_NAME-theme .md-input-messages-animation{color:\"{{warn-A700}}\"}md-input-container.md-THEME_NAME-theme .md-input-message-animation .md-char-counter,md-input-container.md-THEME_NAME-theme .md-input-messages-animation .md-char-counter{color:\"{{foreground-1}}\"}md-input-container.md-THEME_NAME-theme.md-input-focused .md-input:-moz-placeholder,md-input-container.md-THEME_NAME-theme.md-input-focused .md-input::-moz-placeholder{color:\"{{foreground-2}}\"}md-input-container.md-THEME_NAME-theme.md-input-focused .md-input:-ms-input-placeholder{color:\"{{foreground-2}}\"}md-input-container.md-THEME_NAME-theme.md-input-focused .md-input::-webkit-input-placeholder{color:\"{{foreground-2}}\"}md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-has-value label{color:\"{{foreground-2}}\"}md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused .md-input,md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-resized .md-input{border-color:\"{{primary-color}}\"}md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused label,md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused md-icon{color:\"{{primary-color}}\"}md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused.md-accent .md-input{border-color:\"{{accent-color}}\"}md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused.md-accent label,md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused.md-accent md-icon{color:\"{{accent-color}}\"}md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused.md-warn .md-input{border-color:\"{{warn-A700}}\"}md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused.md-warn label,md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused.md-warn md-icon{color:\"{{warn-A700}}\"}md-input-container.md-THEME_NAME-theme.md-input-invalid .md-input{border-color:\"{{warn-A700}}\"}md-input-container.md-THEME_NAME-theme.md-input-invalid .md-char-counter,md-input-container.md-THEME_NAME-theme.md-input-invalid .md-input-message-animation,md-input-container.md-THEME_NAME-theme.md-input-invalid label{color:\"{{warn-A700}}\"}[disabled] md-input-container.md-THEME_NAME-theme .md-input,md-input-container.md-THEME_NAME-theme .md-input[disabled]{border-bottom-color:transparent;color:\"{{foreground-3}}\";background-image:linear-gradient(90deg,\"{{foreground-3}}\" 0,\"{{foreground-3}}\" 33%,transparent 0);background-image:-ms-linear-gradient(left,transparent 0,\"{{foreground-3}}\" 100%)}md-list.md-THEME_NAME-theme md-list-item.md-2-line .md-list-item-text h3,md-list.md-THEME_NAME-theme md-list-item.md-2-line .md-list-item-text h4,md-list.md-THEME_NAME-theme md-list-item.md-3-line .md-list-item-text h3,md-list.md-THEME_NAME-theme md-list-item.md-3-line .md-list-item-text h4{color:\"{{foreground-1}}\"}md-list.md-THEME_NAME-theme md-list-item.md-2-line .md-list-item-text p,md-list.md-THEME_NAME-theme md-list-item.md-3-line .md-list-item-text p{color:\"{{foreground-2}}\"}md-list.md-THEME_NAME-theme .md-proxy-focus.md-focused div.md-no-style{background-color:\"{{background-100}}\"}md-list.md-THEME_NAME-theme md-list-item .md-avatar-icon{background-color:\"{{foreground-3}}\";color:\"{{background-color}}\"}md-list.md-THEME_NAME-theme md-list-item>md-icon{color:\"{{foreground-2}}\"}md-list.md-THEME_NAME-theme md-list-item>md-icon.md-highlight{color:\"{{primary-color}}\"}md-list.md-THEME_NAME-theme md-list-item>md-icon.md-highlight.md-accent{color:\"{{accent-color}}\"}md-menu-content.md-THEME_NAME-theme{background-color:\"{{background-A100}}\"}md-menu-content.md-THEME_NAME-theme md-menu-item{color:\"{{background-A200-0.87}}\"}md-menu-content.md-THEME_NAME-theme md-menu-item md-icon{color:\"{{background-A200-0.54}}\"}md-menu-content.md-THEME_NAME-theme md-menu-item .md-button[disabled],md-menu-content.md-THEME_NAME-theme md-menu-item .md-button[disabled] md-icon{color:\"{{background-A200-0.25}}\"}md-menu-content.md-THEME_NAME-theme md-menu-divider{background-color:\"{{background-A200-0.11}}\"}md-menu-bar.md-THEME_NAME-theme>button.md-button{color:\"{{foreground-2}}\";border-radius:2px}md-menu-bar.md-THEME_NAME-theme md-menu.md-open>button,md-menu-bar.md-THEME_NAME-theme md-menu>button:focus{outline:none;background:\"{{background-200}}\"}md-menu-bar.md-THEME_NAME-theme.md-open:not(.md-keyboard-mode) md-menu:hover>button{background-color:\"{{ background-500-0.2}}\"}md-menu-bar.md-THEME_NAME-theme:not(.md-keyboard-mode):not(.md-open) md-menu button:focus,md-menu-bar.md-THEME_NAME-theme:not(.md-keyboard-mode):not(.md-open) md-menu button:hover{background:transparent}md-menu-content.md-THEME_NAME-theme .md-menu>.md-button:after{color:\"{{background-A200-0.54}}\"}md-menu-content.md-THEME_NAME-theme .md-menu.md-open>.md-button{background-color:\"{{ background-500-0.2}}\"}md-toolbar.md-THEME_NAME-theme.md-menu-toolbar{background-color:\"{{background-A100}}\";color:\"{{background-A200}}\"}md-toolbar.md-THEME_NAME-theme.md-menu-toolbar md-toolbar-filler{background-color:\"{{primary-color}}\";color:\"{{background-A100-0.87}}\"}md-toolbar.md-THEME_NAME-theme.md-menu-toolbar md-toolbar-filler md-icon{color:\"{{background-A100-0.87}}\"}md-nav-bar.md-THEME_NAME-theme .md-nav-bar{background-color:transparent;border-color:\"{{foreground-4}}\"}md-nav-bar.md-THEME_NAME-theme .md-button._md-nav-button.md-unselected{color:\"{{foreground-2}}\"}md-nav-bar.md-THEME_NAME-theme md-nav-ink-bar{color:\"{{accent-color}}\";background:\"{{accent-color}}\"}md-nav-bar.md-THEME_NAME-theme.md-accent>.md-nav-bar{background-color:\"{{accent-color}}\"}md-nav-bar.md-THEME_NAME-theme.md-accent>.md-nav-bar .md-button._md-nav-button{color:\"{{accent-A100}}\"}md-nav-bar.md-THEME_NAME-theme.md-accent>.md-nav-bar .md-button._md-nav-button.md-active,md-nav-bar.md-THEME_NAME-theme.md-accent>.md-nav-bar .md-button._md-nav-button.md-focused{color:\"{{accent-contrast}}\"}md-nav-bar.md-THEME_NAME-theme.md-accent>.md-nav-bar .md-button._md-nav-button.md-focused{background:\"{{accent-contrast-0.1}}\"}md-nav-bar.md-THEME_NAME-theme.md-accent>.md-nav-bar md-nav-ink-bar{color:\"{{primary-600-1}}\";background:\"{{primary-600-1}}\"}md-nav-bar.md-THEME_NAME-theme.md-warn>.md-nav-bar{background-color:\"{{warn-color}}\"}md-nav-bar.md-THEME_NAME-theme.md-warn>.md-nav-bar .md-button._md-nav-button{color:\"{{warn-100}}\"}md-nav-bar.md-THEME_NAME-theme.md-warn>.md-nav-bar .md-button._md-nav-button.md-active,md-nav-bar.md-THEME_NAME-theme.md-warn>.md-nav-bar .md-button._md-nav-button.md-focused{color:\"{{warn-contrast}}\"}md-nav-bar.md-THEME_NAME-theme.md-warn>.md-nav-bar .md-button._md-nav-button.md-focused{background:\"{{warn-contrast-0.1}}\"}md-nav-bar.md-THEME_NAME-theme.md-primary>.md-nav-bar{background-color:\"{{primary-color}}\"}md-nav-bar.md-THEME_NAME-theme.md-primary>.md-nav-bar .md-button._md-nav-button{color:\"{{primary-100}}\"}md-nav-bar.md-THEME_NAME-theme.md-primary>.md-nav-bar .md-button._md-nav-button.md-active,md-nav-bar.md-THEME_NAME-theme.md-primary>.md-nav-bar .md-button._md-nav-button.md-focused{color:\"{{primary-contrast}}\"}md-nav-bar.md-THEME_NAME-theme.md-primary>.md-nav-bar .md-button._md-nav-button.md-focused{background:\"{{primary-contrast-0.1}}\"}md-toolbar>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar{background-color:\"{{primary-color}}\"}md-toolbar>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar .md-button._md-nav-button{color:\"{{primary-100}}\"}md-toolbar>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar .md-button._md-nav-button.md-active,md-toolbar>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar .md-button._md-nav-button.md-focused{color:\"{{primary-contrast}}\"}md-toolbar>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar .md-button._md-nav-button.md-focused{background:\"{{primary-contrast-0.1}}\"}md-toolbar.md-accent>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar{background-color:\"{{accent-color}}\"}md-toolbar.md-accent>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar .md-button._md-nav-button{color:\"{{accent-A100}}\"}md-toolbar.md-accent>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar .md-button._md-nav-button.md-active,md-toolbar.md-accent>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar .md-button._md-nav-button.md-focused{color:\"{{accent-contrast}}\"}md-toolbar.md-accent>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar .md-button._md-nav-button.md-focused{background:\"{{accent-contrast-0.1}}\"}md-toolbar.md-accent>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar md-nav-ink-bar{color:\"{{primary-600-1}}\";background:\"{{primary-600-1}}\"}md-toolbar.md-warn>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar{background-color:\"{{warn-color}}\"}md-toolbar.md-warn>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar .md-button._md-nav-button{color:\"{{warn-100}}\"}md-toolbar.md-warn>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar .md-button._md-nav-button.md-active,md-toolbar.md-warn>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar .md-button._md-nav-button.md-focused{color:\"{{warn-contrast}}\"}md-toolbar.md-warn>md-nav-bar.md-THEME_NAME-theme>.md-nav-bar .md-button._md-nav-button.md-focused{background:\"{{warn-contrast-0.1}}\"}._md-panel-backdrop.md-THEME_NAME-theme{background-color:\"{{background-900-1.0}}\"}md-progress-circular.md-THEME_NAME-theme path{stroke:\"{{primary-color}}\"}md-progress-circular.md-THEME_NAME-theme.md-warn path{stroke:\"{{warn-color}}\"}md-progress-circular.md-THEME_NAME-theme.md-accent path{stroke:\"{{accent-color}}\"}md-progress-linear.md-THEME_NAME-theme .md-container{background-color:\"{{primary-100}}\"}md-progress-linear.md-THEME_NAME-theme .md-bar{background-color:\"{{primary-color}}\"}md-progress-linear.md-THEME_NAME-theme.md-warn .md-container{background-color:\"{{warn-100}}\"}md-progress-linear.md-THEME_NAME-theme.md-warn .md-bar{background-color:\"{{warn-color}}\"}md-progress-linear.md-THEME_NAME-theme.md-accent .md-container{background-color:\"{{accent-100}}\"}md-progress-linear.md-THEME_NAME-theme.md-accent .md-bar{background-color:\"{{accent-color}}\"}md-progress-linear.md-THEME_NAME-theme[md-mode=buffer].md-primary .md-bar1{background-color:\"{{primary-100}}\"}md-progress-linear.md-THEME_NAME-theme[md-mode=buffer].md-primary .md-dashed:before{background:radial-gradient(\"{{primary-100}}\" 0,\"{{primary-100}}\" 16%,transparent 42%)}md-progress-linear.md-THEME_NAME-theme[md-mode=buffer].md-warn .md-bar1{background-color:\"{{warn-100}}\"}md-progress-linear.md-THEME_NAME-theme[md-mode=buffer].md-warn .md-dashed:before{background:radial-gradient(\"{{warn-100}}\" 0,\"{{warn-100}}\" 16%,transparent 42%)}md-progress-linear.md-THEME_NAME-theme[md-mode=buffer].md-accent .md-bar1{background-color:\"{{accent-100}}\"}md-progress-linear.md-THEME_NAME-theme[md-mode=buffer].md-accent .md-dashed:before{background:radial-gradient(\"{{accent-100}}\" 0,\"{{accent-100}}\" 16%,transparent 42%)}md-radio-button.md-THEME_NAME-theme .md-off{border-color:\"{{foreground-2}}\"}md-radio-button.md-THEME_NAME-theme .md-on{background-color:\"{{accent-color-0.87}}\"}md-radio-button.md-THEME_NAME-theme.md-checked .md-off{border-color:\"{{accent-color-0.87}}\"}md-radio-button.md-THEME_NAME-theme.md-checked .md-ink-ripple{color:\"{{accent-color-0.87}}\"}md-radio-button.md-THEME_NAME-theme .md-container .md-ripple{color:\"{{accent-A700}}\"}md-radio-button.md-THEME_NAME-theme:not([disabled]).md-primary .md-on,md-radio-button.md-THEME_NAME-theme:not([disabled]) .md-primary .md-on,md-radio-group.md-THEME_NAME-theme:not([disabled]).md-primary .md-on,md-radio-group.md-THEME_NAME-theme:not([disabled]) .md-primary .md-on{background-color:\"{{primary-color-0.87}}\"}md-radio-button.md-THEME_NAME-theme:not([disabled]).md-primary.md-checked .md-off,md-radio-button.md-THEME_NAME-theme:not([disabled]) .md-primary.md-checked .md-off,md-radio-button.md-THEME_NAME-theme:not([disabled]).md-primary .md-checked .md-off,md-radio-button.md-THEME_NAME-theme:not([disabled]) .md-primary .md-checked .md-off,md-radio-group.md-THEME_NAME-theme:not([disabled]).md-primary.md-checked .md-off,md-radio-group.md-THEME_NAME-theme:not([disabled]) .md-primary.md-checked .md-off,md-radio-group.md-THEME_NAME-theme:not([disabled]).md-primary .md-checked .md-off,md-radio-group.md-THEME_NAME-theme:not([disabled]) .md-primary .md-checked .md-off{border-color:\"{{primary-color-0.87}}\"}md-radio-button.md-THEME_NAME-theme:not([disabled]).md-primary.md-checked .md-ink-ripple,md-radio-button.md-THEME_NAME-theme:not([disabled]) .md-primary.md-checked .md-ink-ripple,md-radio-button.md-THEME_NAME-theme:not([disabled]).md-primary .md-checked .md-ink-ripple,md-radio-button.md-THEME_NAME-theme:not([disabled]) .md-primary .md-checked .md-ink-ripple,md-radio-group.md-THEME_NAME-theme:not([disabled]).md-primary.md-checked .md-ink-ripple,md-radio-group.md-THEME_NAME-theme:not([disabled]) .md-primary.md-checked .md-ink-ripple,md-radio-group.md-THEME_NAME-theme:not([disabled]).md-primary .md-checked .md-ink-ripple,md-radio-group.md-THEME_NAME-theme:not([disabled]) .md-primary .md-checked .md-ink-ripple{color:\"{{primary-color-0.87}}\"}md-radio-button.md-THEME_NAME-theme:not([disabled]).md-primary .md-container .md-ripple,md-radio-button.md-THEME_NAME-theme:not([disabled]) .md-primary .md-container .md-ripple,md-radio-group.md-THEME_NAME-theme:not([disabled]).md-primary .md-container .md-ripple,md-radio-group.md-THEME_NAME-theme:not([disabled]) .md-primary .md-container .md-ripple{color:\"{{primary-600}}\"}md-radio-button.md-THEME_NAME-theme:not([disabled]).md-warn .md-on,md-radio-button.md-THEME_NAME-theme:not([disabled]) .md-warn .md-on,md-radio-group.md-THEME_NAME-theme:not([disabled]).md-warn .md-on,md-radio-group.md-THEME_NAME-theme:not([disabled]) .md-warn .md-on{background-color:\"{{warn-color-0.87}}\"}md-radio-button.md-THEME_NAME-theme:not([disabled]).md-warn.md-checked .md-off,md-radio-button.md-THEME_NAME-theme:not([disabled]) .md-warn.md-checked .md-off,md-radio-button.md-THEME_NAME-theme:not([disabled]).md-warn .md-checked .md-off,md-radio-button.md-THEME_NAME-theme:not([disabled]) .md-warn .md-checked .md-off,md-radio-group.md-THEME_NAME-theme:not([disabled]).md-warn.md-checked .md-off,md-radio-group.md-THEME_NAME-theme:not([disabled]) .md-warn.md-checked .md-off,md-radio-group.md-THEME_NAME-theme:not([disabled]).md-warn .md-checked .md-off,md-radio-group.md-THEME_NAME-theme:not([disabled]) .md-warn .md-checked .md-off{border-color:\"{{warn-color-0.87}}\"}md-radio-button.md-THEME_NAME-theme:not([disabled]).md-warn.md-checked .md-ink-ripple,md-radio-button.md-THEME_NAME-theme:not([disabled]) .md-warn.md-checked .md-ink-ripple,md-radio-button.md-THEME_NAME-theme:not([disabled]).md-warn .md-checked .md-ink-ripple,md-radio-button.md-THEME_NAME-theme:not([disabled]) .md-warn .md-checked .md-ink-ripple,md-radio-group.md-THEME_NAME-theme:not([disabled]).md-warn.md-checked .md-ink-ripple,md-radio-group.md-THEME_NAME-theme:not([disabled]) .md-warn.md-checked .md-ink-ripple,md-radio-group.md-THEME_NAME-theme:not([disabled]).md-warn .md-checked .md-ink-ripple,md-radio-group.md-THEME_NAME-theme:not([disabled]) .md-warn .md-checked .md-ink-ripple{color:\"{{warn-color-0.87}}\"}md-radio-button.md-THEME_NAME-theme:not([disabled]).md-warn .md-container .md-ripple,md-radio-button.md-THEME_NAME-theme:not([disabled]) .md-warn .md-container .md-ripple,md-radio-group.md-THEME_NAME-theme:not([disabled]).md-warn .md-container .md-ripple,md-radio-group.md-THEME_NAME-theme:not([disabled]) .md-warn .md-container .md-ripple{color:\"{{warn-600}}\"}md-radio-button.md-THEME_NAME-theme[disabled],md-radio-group.md-THEME_NAME-theme[disabled]{color:\"{{foreground-3}}\"}md-radio-button.md-THEME_NAME-theme[disabled] .md-container .md-off,md-radio-button.md-THEME_NAME-theme[disabled] .md-container .md-on,md-radio-group.md-THEME_NAME-theme[disabled] .md-container .md-off,md-radio-group.md-THEME_NAME-theme[disabled] .md-container .md-on{border-color:\"{{foreground-3}}\"}md-radio-group.md-THEME_NAME-theme .md-checked .md-ink-ripple{color:\"{{accent-color-0.26}}\"}md-radio-group.md-THEME_NAME-theme .md-checked:not([disabled]).md-primary .md-ink-ripple,md-radio-group.md-THEME_NAME-theme.md-primary .md-checked:not([disabled]) .md-ink-ripple{color:\"{{primary-color-0.26}}\"}md-radio-group.md-THEME_NAME-theme.md-focused:not(:empty) .md-checked .md-container:before{background-color:\"{{accent-color-0.26}}\"}md-radio-group.md-THEME_NAME-theme.md-focused:not(:empty) .md-checked.md-primary .md-container:before,md-radio-group.md-THEME_NAME-theme.md-focused:not(:empty).md-primary .md-checked .md-container:before{background-color:\"{{primary-color-0.26}}\"}md-radio-group.md-THEME_NAME-theme.md-focused:not(:empty) .md-checked.md-warn .md-container:before,md-radio-group.md-THEME_NAME-theme.md-focused:not(:empty).md-warn .md-checked .md-container:before{background-color:\"{{warn-color-0.26}}\"}md-input-container md-select.md-THEME_NAME-theme .md-select-value span:first-child:after{color:\"{{warn-A700}}\"}md-input-container:not(.md-input-focused):not(.md-input-invalid) md-select.md-THEME_NAME-theme .md-select-value span:first-child:after{color:\"{{foreground-3}}\"}md-input-container.md-input-focused:not(.md-input-has-value) md-select.md-THEME_NAME-theme .md-select-value,md-input-container.md-input-focused:not(.md-input-has-value) md-select.md-THEME_NAME-theme .md-select-value.md-select-placeholder{color:\"{{primary-color}}\"}md-input-container.md-input-invalid md-select.md-THEME_NAME-theme .md-select-value{color:\"{{warn-A700}}\"!important;border-bottom-color:\"{{warn-A700}}\"!important}md-input-container.md-input-invalid md-select.md-THEME_NAME-theme.md-no-underline .md-select-value{border-bottom-color:transparent!important}md-select.md-THEME_NAME-theme[disabled] .md-select-value{border-bottom-color:transparent;background-image:linear-gradient(90deg,\"{{foreground-3}}\" 0,\"{{foreground-3}}\" 33%,transparent 0);background-image:-ms-linear-gradient(left,transparent 0,\"{{foreground-3}}\" 100%)}md-select.md-THEME_NAME-theme .md-select-value{border-bottom-color:\"{{foreground-4}}\"}md-select.md-THEME_NAME-theme .md-select-value.md-select-placeholder{color:\"{{foreground-3}}\"}md-select.md-THEME_NAME-theme .md-select-value span:first-child:after{color:\"{{warn-A700}}\"}md-select.md-THEME_NAME-theme.md-no-underline .md-select-value{border-bottom-color:transparent!important}md-select.md-THEME_NAME-theme.ng-invalid.ng-touched .md-select-value{color:\"{{warn-A700}}\"!important;border-bottom-color:\"{{warn-A700}}\"!important}md-select.md-THEME_NAME-theme.ng-invalid.ng-touched.md-no-underline .md-select-value{border-bottom-color:transparent!important}md-select.md-THEME_NAME-theme:not([disabled]):focus .md-select-value{border-bottom-color:\"{{primary-color}}\";color:\"{{ foreground-1 }}\"}md-select.md-THEME_NAME-theme:not([disabled]):focus .md-select-value.md-select-placeholder{color:\"{{ foreground-1 }}\"}md-select.md-THEME_NAME-theme:not([disabled]):focus.md-no-underline .md-select-value{border-bottom-color:transparent!important}md-select.md-THEME_NAME-theme:not([disabled]):focus.md-accent .md-select-value{border-bottom-color:\"{{accent-color}}\"}md-select.md-THEME_NAME-theme:not([disabled]):focus.md-warn .md-select-value{border-bottom-color:\"{{warn-color}}\"}md-select.md-THEME_NAME-theme[disabled] .md-select-icon,md-select.md-THEME_NAME-theme[disabled] .md-select-value,md-select.md-THEME_NAME-theme[disabled] .md-select-value.md-select-placeholder{color:\"{{foreground-3}}\"}md-select.md-THEME_NAME-theme .md-select-icon{color:\"{{foreground-2}}\"}md-select-menu.md-THEME_NAME-theme md-content{background:\"{{background-A100}}\"}md-select-menu.md-THEME_NAME-theme md-content md-optgroup{color:\"{{background-600-0.87}}\"}md-select-menu.md-THEME_NAME-theme md-content md-option{color:\"{{background-900-0.87}}\"}md-select-menu.md-THEME_NAME-theme md-content md-option[disabled] .md-text{color:\"{{background-400-0.87}}\"}md-select-menu.md-THEME_NAME-theme md-content md-option:not([disabled]):focus,md-select-menu.md-THEME_NAME-theme md-content md-option:not([disabled]):hover{background:\"{{background-200}}\"}md-select-menu.md-THEME_NAME-theme md-content md-option[selected]{color:\"{{primary-500}}\"}md-select-menu.md-THEME_NAME-theme md-content md-option[selected]:focus{color:\"{{primary-600}}\"}md-select-menu.md-THEME_NAME-theme md-content md-option[selected].md-accent{color:\"{{accent-color}}\"}md-select-menu.md-THEME_NAME-theme md-content md-option[selected].md-accent:focus{color:\"{{accent-A700}}\"}.md-checkbox-enabled.md-THEME_NAME-theme .md-ripple{color:\"{{primary-600}}\"}.md-checkbox-enabled.md-THEME_NAME-theme[selected] .md-ripple{color:\"{{background-600}}\"}.md-checkbox-enabled.md-THEME_NAME-theme .md-ink-ripple{color:\"{{foreground-2}}\"}.md-checkbox-enabled.md-THEME_NAME-theme[selected] .md-ink-ripple{color:\"{{primary-color-0.87}}\"}.md-checkbox-enabled.md-THEME_NAME-theme:not(.md-checked) .md-icon{border-color:\"{{foreground-2}}\"}.md-checkbox-enabled.md-THEME_NAME-theme[selected] .md-icon{background-color:\"{{primary-color-0.87}}\"}.md-checkbox-enabled.md-THEME_NAME-theme[selected].md-focused .md-container:before{background-color:\"{{primary-color-0.26}}\"}.md-checkbox-enabled.md-THEME_NAME-theme[selected] .md-icon:after{border-color:\"{{primary-contrast-0.87}}\"}.md-checkbox-enabled.md-THEME_NAME-theme .md-indeterminate[disabled] .md-container{color:\"{{foreground-3}}\"}.md-checkbox-enabled.md-THEME_NAME-theme md-option .md-text{color:\"{{background-900-0.87}}\"}md-sidenav.md-THEME_NAME-theme,md-sidenav.md-THEME_NAME-theme md-content{background-color:\"{{background-hue-1}}\"}md-slider.md-THEME_NAME-theme .md-track{background-color:\"{{foreground-3}}\"}md-slider.md-THEME_NAME-theme .md-track-ticks{color:\"{{background-contrast}}\"}md-slider.md-THEME_NAME-theme .md-focus-ring{background-color:\"{{accent-A200-0.2}}\"}md-slider.md-THEME_NAME-theme .md-disabled-thumb{border-color:\"{{background-color}}\";background-color:\"{{background-color}}\"}md-slider.md-THEME_NAME-theme.md-min .md-thumb:after{background-color:\"{{background-color}}\";border-color:\"{{foreground-3}}\"}md-slider.md-THEME_NAME-theme.md-min .md-focus-ring{background-color:\"{{foreground-3-0.38}}\"}md-slider.md-THEME_NAME-theme.md-min[md-discrete] .md-thumb:after{background-color:\"{{background-contrast}}\";border-color:transparent}md-slider.md-THEME_NAME-theme.md-min[md-discrete] .md-sign{background-color:\"{{background-400}}\"}md-slider.md-THEME_NAME-theme.md-min[md-discrete] .md-sign:after{border-top-color:\"{{background-400}}\"}md-slider.md-THEME_NAME-theme.md-min[md-discrete][md-vertical] .md-sign:after{border-top-color:transparent;border-left-color:\"{{background-400}}\"}md-slider.md-THEME_NAME-theme .md-track.md-track-fill{background-color:\"{{accent-color}}\"}md-slider.md-THEME_NAME-theme .md-thumb:after{border-color:\"{{accent-color}}\";background-color:\"{{accent-color}}\"}md-slider.md-THEME_NAME-theme .md-sign{background-color:\"{{accent-color}}\"}md-slider.md-THEME_NAME-theme .md-sign:after{border-top-color:\"{{accent-color}}\"}md-slider.md-THEME_NAME-theme[md-vertical] .md-sign:after{border-top-color:transparent;border-left-color:\"{{accent-color}}\"}md-slider.md-THEME_NAME-theme .md-thumb-text{color:\"{{accent-contrast}}\"}md-slider.md-THEME_NAME-theme.md-warn .md-focus-ring{background-color:\"{{warn-200-0.38}}\"}md-slider.md-THEME_NAME-theme.md-warn .md-track.md-track-fill{background-color:\"{{warn-color}}\"}md-slider.md-THEME_NAME-theme.md-warn .md-thumb:after{border-color:\"{{warn-color}}\";background-color:\"{{warn-color}}\"}md-slider.md-THEME_NAME-theme.md-warn .md-sign{background-color:\"{{warn-color}}\"}md-slider.md-THEME_NAME-theme.md-warn .md-sign:after{border-top-color:\"{{warn-color}}\"}md-slider.md-THEME_NAME-theme.md-warn[md-vertical] .md-sign:after{border-top-color:transparent;border-left-color:\"{{warn-color}}\"}md-slider.md-THEME_NAME-theme.md-warn .md-thumb-text{color:\"{{warn-contrast}}\"}md-slider.md-THEME_NAME-theme.md-primary .md-focus-ring{background-color:\"{{primary-200-0.38}}\"}md-slider.md-THEME_NAME-theme.md-primary .md-track.md-track-fill{background-color:\"{{primary-color}}\"}md-slider.md-THEME_NAME-theme.md-primary .md-thumb:after{border-color:\"{{primary-color}}\";background-color:\"{{primary-color}}\"}md-slider.md-THEME_NAME-theme.md-primary .md-sign{background-color:\"{{primary-color}}\"}md-slider.md-THEME_NAME-theme.md-primary .md-sign:after{border-top-color:\"{{primary-color}}\"}md-slider.md-THEME_NAME-theme.md-primary[md-vertical] .md-sign:after{border-top-color:transparent;border-left-color:\"{{primary-color}}\"}md-slider.md-THEME_NAME-theme.md-primary .md-thumb-text{color:\"{{primary-contrast}}\"}md-slider.md-THEME_NAME-theme[disabled] .md-thumb:after{border-color:transparent}md-slider.md-THEME_NAME-theme[disabled]:not(.md-min) .md-thumb:after,md-slider.md-THEME_NAME-theme[disabled][md-discrete] .md-thumb:after{background-color:\"{{foreground-3}}\";border-color:transparent}md-slider.md-THEME_NAME-theme[disabled][readonly] .md-sign{background-color:\"{{background-400}}\"}md-slider.md-THEME_NAME-theme[disabled][readonly] .md-sign:after{border-top-color:\"{{background-400}}\"}md-slider.md-THEME_NAME-theme[disabled][readonly][md-vertical] .md-sign:after{border-top-color:transparent;border-left-color:\"{{background-400}}\"}md-slider.md-THEME_NAME-theme[disabled][readonly] .md-disabled-thumb{border-color:transparent;background-color:transparent}md-slider-container[disabled]>:first-child:not(md-slider),md-slider-container[disabled]>:last-child:not(md-slider){color:\"{{foreground-3}}\"}.md-subheader.md-THEME_NAME-theme{color:\"{{ foreground-2-0.23 }}\";background-color:\"{{background-default}}\"}.md-subheader.md-THEME_NAME-theme.md-primary{color:\"{{primary-color}}\"}.md-subheader.md-THEME_NAME-theme.md-accent{color:\"{{accent-color}}\"}.md-subheader.md-THEME_NAME-theme.md-warn{color:\"{{warn-color}}\"}md-switch.md-THEME_NAME-theme .md-ink-ripple{color:\"{{background-500}}\"}md-switch.md-THEME_NAME-theme .md-thumb{background-color:\"{{background-50}}\"}md-switch.md-THEME_NAME-theme .md-bar{background-color:\"{{background-500}}\"}md-switch.md-THEME_NAME-theme.md-checked .md-ink-ripple{color:\"{{accent-color}}\"}md-switch.md-THEME_NAME-theme.md-checked .md-thumb{background-color:\"{{accent-color}}\"}md-switch.md-THEME_NAME-theme.md-checked .md-bar{background-color:\"{{accent-color-0.5}}\"}md-switch.md-THEME_NAME-theme.md-checked.md-focused .md-thumb:before{background-color:\"{{accent-color-0.26}}\"}md-switch.md-THEME_NAME-theme.md-checked.md-primary .md-ink-ripple{color:\"{{primary-color}}\"}md-switch.md-THEME_NAME-theme.md-checked.md-primary .md-thumb{background-color:\"{{primary-color}}\"}md-switch.md-THEME_NAME-theme.md-checked.md-primary .md-bar{background-color:\"{{primary-color-0.5}}\"}md-switch.md-THEME_NAME-theme.md-checked.md-primary.md-focused .md-thumb:before{background-color:\"{{primary-color-0.26}}\"}md-switch.md-THEME_NAME-theme.md-checked.md-warn .md-ink-ripple{color:\"{{warn-color}}\"}md-switch.md-THEME_NAME-theme.md-checked.md-warn .md-thumb{background-color:\"{{warn-color}}\"}md-switch.md-THEME_NAME-theme.md-checked.md-warn .md-bar{background-color:\"{{warn-color-0.5}}\"}md-switch.md-THEME_NAME-theme.md-checked.md-warn.md-focused .md-thumb:before{background-color:\"{{warn-color-0.26}}\"}md-switch.md-THEME_NAME-theme[disabled] .md-thumb{background-color:\"{{background-400}}\"}md-switch.md-THEME_NAME-theme[disabled] .md-bar{background-color:\"{{foreground-4}}\"}md-tabs.md-THEME_NAME-theme md-tabs-wrapper{background-color:transparent;border-color:\"{{foreground-4}}\"}md-tabs.md-THEME_NAME-theme .md-paginator md-icon{color:\"{{primary-color}}\"}md-tabs.md-THEME_NAME-theme md-ink-bar{color:\"{{accent-color}}\";background:\"{{accent-color}}\"}md-tabs.md-THEME_NAME-theme .md-tab{color:\"{{foreground-2}}\"}md-tabs.md-THEME_NAME-theme .md-tab[disabled],md-tabs.md-THEME_NAME-theme .md-tab[disabled] md-icon{color:\"{{foreground-3}}\"}md-tabs.md-THEME_NAME-theme .md-tab.md-active,md-tabs.md-THEME_NAME-theme .md-tab.md-active md-icon,md-tabs.md-THEME_NAME-theme .md-tab.md-focused,md-tabs.md-THEME_NAME-theme .md-tab.md-focused md-icon{color:\"{{primary-color}}\"}md-tabs.md-THEME_NAME-theme .md-tab.md-focused{background:\"{{primary-color-0.1}}\"}md-tabs.md-THEME_NAME-theme .md-tab .md-ripple-container{color:\"{{accent-A100}}\"}md-tabs.md-THEME_NAME-theme.md-accent>md-tabs-wrapper{background-color:\"{{accent-color}}\"}md-tabs.md-THEME_NAME-theme.md-accent>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]),md-tabs.md-THEME_NAME-theme.md-accent>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]) md-icon{color:\"{{accent-A100}}\"}md-tabs.md-THEME_NAME-theme.md-accent>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-active,md-tabs.md-THEME_NAME-theme.md-accent>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-active md-icon,md-tabs.md-THEME_NAME-theme.md-accent>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused,md-tabs.md-THEME_NAME-theme.md-accent>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused md-icon{color:\"{{accent-contrast}}\"}md-tabs.md-THEME_NAME-theme.md-accent>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused{background:\"{{accent-contrast-0.1}}\"}md-tabs.md-THEME_NAME-theme.md-accent>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-ink-bar{color:\"{{primary-600-1}}\";background:\"{{primary-600-1}}\"}md-tabs.md-THEME_NAME-theme.md-primary>md-tabs-wrapper{background-color:\"{{primary-color}}\"}md-tabs.md-THEME_NAME-theme.md-primary>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]),md-tabs.md-THEME_NAME-theme.md-primary>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]) md-icon{color:\"{{primary-100}}\"}md-tabs.md-THEME_NAME-theme.md-primary>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-active,md-tabs.md-THEME_NAME-theme.md-primary>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-active md-icon,md-tabs.md-THEME_NAME-theme.md-primary>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused,md-tabs.md-THEME_NAME-theme.md-primary>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused md-icon{color:\"{{primary-contrast}}\"}md-tabs.md-THEME_NAME-theme.md-primary>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused{background:\"{{primary-contrast-0.1}}\"}md-tabs.md-THEME_NAME-theme.md-warn>md-tabs-wrapper{background-color:\"{{warn-color}}\"}md-tabs.md-THEME_NAME-theme.md-warn>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]),md-tabs.md-THEME_NAME-theme.md-warn>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]) md-icon{color:\"{{warn-100}}\"}md-tabs.md-THEME_NAME-theme.md-warn>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-active,md-tabs.md-THEME_NAME-theme.md-warn>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-active md-icon,md-tabs.md-THEME_NAME-theme.md-warn>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused,md-tabs.md-THEME_NAME-theme.md-warn>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused md-icon{color:\"{{warn-contrast}}\"}md-tabs.md-THEME_NAME-theme.md-warn>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused{background:\"{{warn-contrast-0.1}}\"}md-toolbar>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper{background-color:\"{{primary-color}}\"}md-toolbar>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]),md-toolbar>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]) md-icon{color:\"{{primary-100}}\"}md-toolbar>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-active,md-toolbar>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-active md-icon,md-toolbar>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused,md-toolbar>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused md-icon{color:\"{{primary-contrast}}\"}md-toolbar>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused{background:\"{{primary-contrast-0.1}}\"}md-toolbar.md-accent>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper{background-color:\"{{accent-color}}\"}md-toolbar.md-accent>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]),md-toolbar.md-accent>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]) md-icon{color:\"{{accent-A100}}\"}md-toolbar.md-accent>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-active,md-toolbar.md-accent>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-active md-icon,md-toolbar.md-accent>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused,md-toolbar.md-accent>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused md-icon{color:\"{{accent-contrast}}\"}md-toolbar.md-accent>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused{background:\"{{accent-contrast-0.1}}\"}md-toolbar.md-accent>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-ink-bar{color:\"{{primary-600-1}}\";background:\"{{primary-600-1}}\"}md-toolbar.md-warn>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper{background-color:\"{{warn-color}}\"}md-toolbar.md-warn>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]),md-toolbar.md-warn>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]) md-icon{color:\"{{warn-100}}\"}md-toolbar.md-warn>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-active,md-toolbar.md-warn>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-active md-icon,md-toolbar.md-warn>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused,md-toolbar.md-warn>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused md-icon{color:\"{{warn-contrast}}\"}md-toolbar.md-warn>md-tabs.md-THEME_NAME-theme>md-tabs-wrapper>md-tabs-canvas>md-pagination-wrapper>md-tab-item:not([disabled]).md-focused{background:\"{{warn-contrast-0.1}}\"}md-toast.md-THEME_NAME-theme .md-toast-content{background-color:#323232;color:\"{{background-50}}\"}md-toast.md-THEME_NAME-theme .md-toast-content .md-button{color:\"{{background-50}}\"}md-toast.md-THEME_NAME-theme .md-toast-content .md-button.md-highlight{color:\"{{accent-color}}\"}md-toast.md-THEME_NAME-theme .md-toast-content .md-button.md-highlight.md-primary{color:\"{{primary-color}}\"}md-toast.md-THEME_NAME-theme .md-toast-content .md-button.md-highlight.md-warn{color:\"{{warn-color}}\"}md-toolbar.md-THEME_NAME-theme:not(.md-menu-toolbar){background-color:\"{{primary-color}}\";color:\"{{primary-contrast}}\"}md-toolbar.md-THEME_NAME-theme:not(.md-menu-toolbar) md-icon{color:\"{{primary-contrast}}\";fill:\"{{primary-contrast}}\"}md-toolbar.md-THEME_NAME-theme:not(.md-menu-toolbar) .md-button[disabled] md-icon{color:\"{{primary-contrast-0.26}}\";fill:\"{{primary-contrast-0.26}}\"}md-toolbar.md-THEME_NAME-theme:not(.md-menu-toolbar).md-accent{background-color:\"{{accent-color}}\";color:\"{{accent-contrast}}\"}md-toolbar.md-THEME_NAME-theme:not(.md-menu-toolbar).md-accent .md-ink-ripple{color:\"{{accent-contrast}}\"}md-toolbar.md-THEME_NAME-theme:not(.md-menu-toolbar).md-accent md-icon{color:\"{{accent-contrast}}\";fill:\"{{accent-contrast}}\"}md-toolbar.md-THEME_NAME-theme:not(.md-menu-toolbar).md-accent .md-button[disabled] md-icon{color:\"{{accent-contrast-0.26}}\";fill:\"{{accent-contrast-0.26}}\"}md-toolbar.md-THEME_NAME-theme:not(.md-menu-toolbar).md-warn{background-color:\"{{warn-color}}\";color:\"{{warn-contrast}}\"}.md-panel.md-tooltip.md-THEME_NAME-theme{color:\"{{background-700-contrast}}\";background-color:\"{{background-700}}\"}body.md-THEME_NAME-theme,html.md-THEME_NAME-theme{color:\"{{foreground-1}}\";background-color:\"{{background-color}}\"}");
  31846. })();
  31847. })(window, window.angular);;window.ngMaterial={version:{full: "1.1.8-master-aba7b2b"}};