angular-material.js 721 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321
  1. /*!
  2. * Angular Material Design
  3. * https://github.com/angular/material
  4. * @license MIT
  5. * v0.10.1-master-8157dec
  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.layout","material.core.theming.palette","material.core.theming","material.animate","material.components.autocomplete","material.components.backdrop","material.components.bottomSheet","material.components.button","material.components.card","material.components.checkbox","material.components.chips","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.fabTrigger","material.components.gridList","material.components.icon","material.components.input","material.components.list","material.components.menu","material.components.menuBar","material.components.progressCircular","material.components.progressLinear","material.components.radioButton","material.components.select","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.virtualRepeat","material.components.whiteframe"]);
  12. })();
  13. (function(){
  14. "use strict";
  15. /**
  16. * Initialization function that validates environment
  17. * requirements.
  18. */
  19. angular
  20. .module('material.core', [
  21. 'ngAnimate',
  22. 'material.animate',
  23. 'material.layout',
  24. 'material.core.gestures',
  25. 'material.core.theming'
  26. ])
  27. .directive('mdTemplate', MdTemplateDirective)
  28. .config(MdCoreConfigure);
  29. function MdCoreConfigure($provide, $mdThemingProvider) {
  30. $provide.decorator('$$rAF', ["$delegate", rAFDecorator]);
  31. $mdThemingProvider.theme('default')
  32. .primaryPalette('indigo')
  33. .accentPalette('pink')
  34. .warnPalette('red')
  35. .backgroundPalette('grey');
  36. }
  37. MdCoreConfigure.$inject = ["$provide", "$mdThemingProvider"];
  38. function MdTemplateDirective($compile) {
  39. return {
  40. restrict: 'A',
  41. scope: {
  42. template: '=mdTemplate'
  43. },
  44. link: function postLink(scope, element) {
  45. scope.$watch('template', assignSafeHTML);
  46. /**
  47. * To add safe HTML: assign and compile in
  48. * isolated scope.
  49. */
  50. function assignSafeHTML(value) {
  51. // when the 'compile' expression changes
  52. // assign it into the current DOM
  53. element.html(value);
  54. // Compile the new DOM and link it to the current scope.
  55. // NOTE: we only compile .childNodes so that we don't get
  56. // into infinite loop compiling ourselves
  57. $compile(element.contents())(scope);
  58. }
  59. }
  60. };
  61. }
  62. MdTemplateDirective.$inject = ["$compile"];
  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. (function(){
  95. "use strict";
  96. angular.module('material.core')
  97. .factory('$mdConstant', MdConstantFactory);
  98. /**
  99. * Factory function that creates the grab-bag $mdConstant service.
  100. * @ngInject
  101. */
  102. function MdConstantFactory($sniffer) {
  103. var webkit = /webkit/i.test($sniffer.vendorPrefix);
  104. function vendorProperty(name) {
  105. return webkit ? ('webkit' + name.charAt(0).toUpperCase() + name.substring(1)) : name;
  106. }
  107. return {
  108. KEY_CODE: {
  109. ENTER: 13,
  110. ESCAPE: 27,
  111. SPACE: 32,
  112. PAGE_UP: 33,
  113. PAGE_DOWN: 34,
  114. END: 35,
  115. HOME: 36,
  116. LEFT_ARROW : 37,
  117. UP_ARROW : 38,
  118. RIGHT_ARROW : 39,
  119. DOWN_ARROW : 40,
  120. TAB : 9,
  121. BACKSPACE: 8,
  122. DELETE: 46
  123. },
  124. CSS: {
  125. /* Constants */
  126. TRANSITIONEND: 'transitionend' + (webkit ? ' webkitTransitionEnd' : ''),
  127. ANIMATIONEND: 'animationend' + (webkit ? ' webkitAnimationEnd' : ''),
  128. TRANSFORM: vendorProperty('transform'),
  129. TRANSFORM_ORIGIN: vendorProperty('transformOrigin'),
  130. TRANSITION: vendorProperty('transition'),
  131. TRANSITION_DURATION: vendorProperty('transitionDuration'),
  132. ANIMATION_PLAY_STATE: vendorProperty('animationPlayState'),
  133. ANIMATION_DURATION: vendorProperty('animationDuration'),
  134. ANIMATION_NAME: vendorProperty('animationName'),
  135. ANIMATION_TIMING: vendorProperty('animationTimingFunction'),
  136. ANIMATION_DIRECTION: vendorProperty('animationDirection')
  137. },
  138. MEDIA: {
  139. 'sm': '(max-width: 599px)',
  140. 'gt-sm': '(min-width: 600px)',
  141. 'md': '(min-width: 600px) and (max-width: 959px)',
  142. 'gt-md': '(min-width: 960px)',
  143. 'lg': '(min-width: 960px) and (max-width: 1199px)',
  144. 'gt-lg': '(min-width: 1200px)'
  145. },
  146. MEDIA_PRIORITY: [
  147. 'gt-lg',
  148. 'lg',
  149. 'gt-md',
  150. 'md',
  151. 'gt-sm',
  152. 'sm'
  153. ]
  154. };
  155. }
  156. MdConstantFactory.$inject = ["$sniffer"];
  157. })();
  158. (function(){
  159. "use strict";
  160. angular
  161. .module('material.core')
  162. .config( ["$provide", function($provide){
  163. $provide.decorator('$mdUtil', ['$delegate', function ($delegate){
  164. /**
  165. * Inject the iterator facade to easily support iteration and accessors
  166. * @see iterator below
  167. */
  168. $delegate.iterator = MdIterator;
  169. return $delegate;
  170. }
  171. ]);
  172. }]);
  173. /**
  174. * iterator is a list facade to easily support iteration and accessors
  175. *
  176. * @param items Array list which this iterator will enumerate
  177. * @param reloop Boolean enables iterator to consider the list as an endless reloop
  178. */
  179. function MdIterator(items, reloop) {
  180. var trueFn = function() { return true; };
  181. if (items && !angular.isArray(items)) {
  182. items = Array.prototype.slice.call(items);
  183. }
  184. reloop = !!reloop;
  185. var _items = items || [ ];
  186. // Published API
  187. return {
  188. items: getItems,
  189. count: count,
  190. inRange: inRange,
  191. contains: contains,
  192. indexOf: indexOf,
  193. itemAt: itemAt,
  194. findBy: findBy,
  195. add: add,
  196. remove: remove,
  197. first: first,
  198. last: last,
  199. next: angular.bind(null, findSubsequentItem, false),
  200. previous: angular.bind(null, findSubsequentItem, true),
  201. hasPrevious: hasPrevious,
  202. hasNext: hasNext
  203. };
  204. /**
  205. * Publish copy of the enumerable set
  206. * @returns {Array|*}
  207. */
  208. function getItems() {
  209. return [].concat(_items);
  210. }
  211. /**
  212. * Determine length of the list
  213. * @returns {Array.length|*|number}
  214. */
  215. function count() {
  216. return _items.length;
  217. }
  218. /**
  219. * Is the index specified valid
  220. * @param index
  221. * @returns {Array.length|*|number|boolean}
  222. */
  223. function inRange(index) {
  224. return _items.length && ( index > -1 ) && (index < _items.length );
  225. }
  226. /**
  227. * Can the iterator proceed to the next item in the list; relative to
  228. * the specified item.
  229. *
  230. * @param item
  231. * @returns {Array.length|*|number|boolean}
  232. */
  233. function hasNext(item) {
  234. return item ? inRange(indexOf(item) + 1) : false;
  235. }
  236. /**
  237. * Can the iterator proceed to the previous item in the list; relative to
  238. * the specified item.
  239. *
  240. * @param item
  241. * @returns {Array.length|*|number|boolean}
  242. */
  243. function hasPrevious(item) {
  244. return item ? inRange(indexOf(item) - 1) : false;
  245. }
  246. /**
  247. * Get item at specified index/position
  248. * @param index
  249. * @returns {*}
  250. */
  251. function itemAt(index) {
  252. return inRange(index) ? _items[index] : null;
  253. }
  254. /**
  255. * Find all elements matching the key/value pair
  256. * otherwise return null
  257. *
  258. * @param val
  259. * @param key
  260. *
  261. * @return array
  262. */
  263. function findBy(key, val) {
  264. return _items.filter(function(item) {
  265. return item[key] === val;
  266. });
  267. }
  268. /**
  269. * Add item to list
  270. * @param item
  271. * @param index
  272. * @returns {*}
  273. */
  274. function add(item, index) {
  275. if ( !item ) return -1;
  276. if (!angular.isNumber(index)) {
  277. index = _items.length;
  278. }
  279. _items.splice(index, 0, item);
  280. return indexOf(item);
  281. }
  282. /**
  283. * Remove item from list...
  284. * @param item
  285. */
  286. function remove(item) {
  287. if ( contains(item) ){
  288. _items.splice(indexOf(item), 1);
  289. }
  290. }
  291. /**
  292. * Get the zero-based index of the target item
  293. * @param item
  294. * @returns {*}
  295. */
  296. function indexOf(item) {
  297. return _items.indexOf(item);
  298. }
  299. /**
  300. * Boolean existence check
  301. * @param item
  302. * @returns {boolean}
  303. */
  304. function contains(item) {
  305. return item && (indexOf(item) > -1);
  306. }
  307. /**
  308. * Return first item in the list
  309. * @returns {*}
  310. */
  311. function first() {
  312. return _items.length ? _items[0] : null;
  313. }
  314. /**
  315. * Return last item in the list...
  316. * @returns {*}
  317. */
  318. function last() {
  319. return _items.length ? _items[_items.length - 1] : null;
  320. }
  321. /**
  322. * Find the next item. If reloop is true and at the end of the list, it will go back to the
  323. * first item. If given, the `validate` callback will be used to determine whether the next item
  324. * is valid. If not valid, it will try to find the next item again.
  325. *
  326. * @param {boolean} backwards Specifies the direction of searching (forwards/backwards)
  327. * @param {*} item The item whose subsequent item we are looking for
  328. * @param {Function=} validate The `validate` function
  329. * @param {integer=} limit The recursion limit
  330. *
  331. * @returns {*} The subsequent item or null
  332. */
  333. function findSubsequentItem(backwards, item, validate, limit) {
  334. validate = validate || trueFn;
  335. var curIndex = indexOf(item);
  336. while (true) {
  337. if (!inRange(curIndex)) return null;
  338. var nextIndex = curIndex + (backwards ? -1 : 1);
  339. var foundItem = null;
  340. if (inRange(nextIndex)) {
  341. foundItem = _items[nextIndex];
  342. } else if (reloop) {
  343. foundItem = backwards ? last() : first();
  344. nextIndex = indexOf(foundItem);
  345. }
  346. if ((foundItem === null) || (nextIndex === limit)) return null;
  347. if (validate(foundItem)) return foundItem;
  348. if (angular.isUndefined(limit)) limit = nextIndex;
  349. curIndex = nextIndex;
  350. }
  351. }
  352. }
  353. })();
  354. (function(){
  355. "use strict";
  356. angular.module('material.core')
  357. .factory('$mdMedia', mdMediaFactory);
  358. /**
  359. * @ngdoc service
  360. * @name $mdMedia
  361. * @module material.core
  362. *
  363. * @description
  364. * `$mdMedia` is used to evaluate whether a given media query is true or false given the
  365. * current device's screen / window size. The media query will be re-evaluated on resize, allowing
  366. * you to register a watch.
  367. *
  368. * `$mdMedia` also has pre-programmed support for media queries that match the layout breakpoints.
  369. * (`sm`, `gt-sm`, `md`, `gt-md`, `lg`, `gt-lg`).
  370. *
  371. * @returns {boolean} a boolean representing whether or not the given media query is true or false.
  372. *
  373. * @usage
  374. * <hljs lang="js">
  375. * app.controller('MyController', function($mdMedia, $scope) {
  376. * $scope.$watch(function() { return $mdMedia('lg'); }, function(big) {
  377. * $scope.bigScreen = big;
  378. * });
  379. *
  380. * $scope.screenIsSmall = $mdMedia('sm');
  381. * $scope.customQuery = $mdMedia('(min-width: 1234px)');
  382. * $scope.anotherCustom = $mdMedia('max-width: 300px');
  383. * });
  384. * </hljs>
  385. */
  386. function mdMediaFactory($mdConstant, $rootScope, $window) {
  387. var queries = {};
  388. var mqls = {};
  389. var results = {};
  390. var normalizeCache = {};
  391. $mdMedia.getResponsiveAttribute = getResponsiveAttribute;
  392. $mdMedia.getQuery = getQuery;
  393. $mdMedia.watchResponsiveAttributes = watchResponsiveAttributes;
  394. return $mdMedia;
  395. function $mdMedia(query) {
  396. var validated = queries[query];
  397. if (angular.isUndefined(validated)) {
  398. validated = queries[query] = validate(query);
  399. }
  400. var result = results[validated];
  401. if (angular.isUndefined(result)) {
  402. result = add(validated);
  403. }
  404. return result;
  405. }
  406. function validate(query) {
  407. return $mdConstant.MEDIA[query] ||
  408. ((query.charAt(0) !== '(') ? ('(' + query + ')') : query);
  409. }
  410. function add(query) {
  411. var result = mqls[query] = $window.matchMedia(query);
  412. result.addListener(onQueryChange);
  413. return (results[result.media] = !!result.matches);
  414. }
  415. function onQueryChange(query) {
  416. $rootScope.$evalAsync(function() {
  417. results[query.media] = !!query.matches;
  418. });
  419. }
  420. function getQuery(name) {
  421. return mqls[name];
  422. }
  423. function getResponsiveAttribute(attrs, attrName) {
  424. for (var i = 0; i < $mdConstant.MEDIA_PRIORITY.length; i++) {
  425. var mediaName = $mdConstant.MEDIA_PRIORITY[i];
  426. if (!mqls[queries[mediaName]].matches) {
  427. continue;
  428. }
  429. var normalizedName = getNormalizedName(attrs, attrName + '-' + mediaName);
  430. if (attrs[normalizedName]) {
  431. return attrs[normalizedName];
  432. }
  433. }
  434. // fallback on unprefixed
  435. return attrs[getNormalizedName(attrs, attrName)];
  436. }
  437. function watchResponsiveAttributes(attrNames, attrs, watchFn) {
  438. var unwatchFns = [];
  439. attrNames.forEach(function(attrName) {
  440. var normalizedName = getNormalizedName(attrs, attrName);
  441. if (attrs[normalizedName]) {
  442. unwatchFns.push(
  443. attrs.$observe(normalizedName, angular.bind(void 0, watchFn, null)));
  444. }
  445. for (var mediaName in $mdConstant.MEDIA) {
  446. normalizedName = getNormalizedName(attrs, attrName + '-' + mediaName);
  447. if (!attrs[normalizedName]) {
  448. return;
  449. }
  450. unwatchFns.push(attrs.$observe(normalizedName, angular.bind(void 0, watchFn, mediaName)));
  451. }
  452. });
  453. return function unwatch() {
  454. unwatchFns.forEach(function(fn) { fn(); })
  455. };
  456. }
  457. // Improves performance dramatically
  458. function getNormalizedName(attrs, attrName) {
  459. return normalizeCache[attrName] ||
  460. (normalizeCache[attrName] = attrs.$normalize(attrName));
  461. }
  462. }
  463. mdMediaFactory.$inject = ["$mdConstant", "$rootScope", "$window"];
  464. })();
  465. (function(){
  466. "use strict";
  467. /*
  468. * This var has to be outside the angular factory, otherwise when
  469. * there are multiple material apps on the same page, each app
  470. * will create its own instance of this array and the app's IDs
  471. * will not be unique.
  472. */
  473. var nextUniqueId = 0;
  474. angular
  475. .module('material.core')
  476. .factory('$mdUtil', UtilFactory);
  477. function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $interpolate, $log) {
  478. // Setup some core variables for the processTemplate method
  479. var startSymbol = $interpolate.startSymbol(),
  480. endSymbol = $interpolate.endSymbol(),
  481. usesStandardSymbols = ((startSymbol === '{{') && (endSymbol === '}}'));
  482. var $mdUtil = {
  483. dom: {},
  484. now: window.performance ?
  485. angular.bind(window.performance, window.performance.now) : Date.now || function() {
  486. return new Date().getTime();
  487. },
  488. clientRect: function(element, offsetParent, isOffsetRect) {
  489. var node = getNode(element);
  490. offsetParent = getNode(offsetParent || node.offsetParent || document.body);
  491. var nodeRect = node.getBoundingClientRect();
  492. // The user can ask for an offsetRect: a rect relative to the offsetParent,
  493. // or a clientRect: a rect relative to the page
  494. var offsetRect = isOffsetRect ?
  495. offsetParent.getBoundingClientRect() :
  496. {left: 0, top: 0, width: 0, height: 0};
  497. return {
  498. left: nodeRect.left - offsetRect.left,
  499. top: nodeRect.top - offsetRect.top,
  500. width: nodeRect.width,
  501. height: nodeRect.height
  502. };
  503. },
  504. offsetRect: function(element, offsetParent) {
  505. return $mdUtil.clientRect(element, offsetParent, true);
  506. },
  507. // Annoying method to copy nodes to an array, thanks to IE
  508. nodesToArray: function(nodes) {
  509. nodes = nodes || [];
  510. var results = [];
  511. for (var i = 0; i < nodes.length; ++i) {
  512. results.push(nodes.item(i));
  513. }
  514. return results;
  515. },
  516. /**
  517. * Calculate the positive scroll offset
  518. * TODO: Check with pinch-zoom in IE/Chrome;
  519. * https://code.google.com/p/chromium/issues/detail?id=496285
  520. */
  521. scrollTop: function(element) {
  522. element = angular.element(element || $document[0].body);
  523. var body = (element[0] == $document[0].body) ? $document[0].body : undefined;
  524. var scrollTop = body ? body.scrollTop + body.parentElement.scrollTop : 0;
  525. // Calculate the positive scroll offset
  526. return scrollTop || Math.abs(element[0].getBoundingClientRect().top);
  527. },
  528. /**
  529. * `findFocusTarget()` provides an optional way to identify the focused element when a dialog, bottomsheet, sideNav
  530. * or other element opens. This is optional attribute finds a nested element with the mdAutoFocus attribute and optional
  531. * expression. An expression may be specified as the directive value; to enable conditional activation of the autoFocus.
  532. *
  533. * NOTE: It is up to the component logic to use the '$mdUtil.findFocusTarget()'
  534. *
  535. * @usage
  536. * <hljs lang="html">
  537. * <md-dialog>
  538. * <form>
  539. * <md-input-container>
  540. * <label for="testInput">Label</label>
  541. * <input id="testInput" type="text" md-autofocus>
  542. * </md-input-container>
  543. * </form>
  544. * </md-dialog>
  545. * </hljs>
  546. *
  547. *<hljs lang="html">
  548. * <md-bottom-sheet class="md-list md-has-header">
  549. * <md-subheader>Comment Actions</md-subheader>
  550. * <md-list>
  551. * <md-list-item ng-repeat="item in items">
  552. *
  553. * <md-button md-autofocus="$index == 2">
  554. * <md-icon md-svg-src="{{item.icon}}"></md-icon>
  555. * <span class="md-inline-list-icon-label">{{ item.name }}</span>
  556. * </md-button>
  557. *
  558. * </md-list-item>
  559. * </md-list>
  560. * </md-bottom-sheet>
  561. *</hljs>
  562. *
  563. **/
  564. findFocusTarget: function(containerEl, attributeVal) {
  565. var elToFocus, items = containerEl[0].querySelectorAll(attributeVal || '[md-autofocus]');
  566. // Find the last child element with the focus attribute
  567. items.length && angular.forEach(items, function(it) {
  568. it = angular.element(it);
  569. // If the expression evaluates to FALSE, then it is not focusable target
  570. var focusExpression = it[0].getAttribute('md-autofocus');
  571. var isFocusable = focusExpression ? (it.scope().$eval(focusExpression) !== false ) : true;
  572. if (isFocusable) elToFocus = it;
  573. });
  574. return elToFocus;
  575. },
  576. // Disables scroll around the passed element.
  577. disableScrollAround: function(element, parent) {
  578. $mdUtil.disableScrollAround._count = $mdUtil.disableScrollAround._count || 0;
  579. ++$mdUtil.disableScrollAround._count;
  580. if ($mdUtil.disableScrollAround._enableScrolling) return $mdUtil.disableScrollAround._enableScrolling;
  581. element = angular.element(element);
  582. var body = $document[0].body,
  583. restoreBody = disableBodyScroll(),
  584. restoreElement = disableElementScroll(parent);
  585. return $mdUtil.disableScrollAround._enableScrolling = function() {
  586. if (!--$mdUtil.disableScrollAround._count) {
  587. restoreBody();
  588. restoreElement();
  589. delete $mdUtil.disableScrollAround._enableScrolling;
  590. }
  591. };
  592. // Creates a virtual scrolling mask to absorb touchmove, keyboard, scrollbar clicking, and wheel events
  593. function disableElementScroll(element) {
  594. element = angular.element(element || body)[0];
  595. var zIndex = 50;
  596. var scrollMask = angular.element(
  597. '<div class="md-scroll-mask" style="z-index: ' + zIndex + '">' +
  598. ' <div class="md-scroll-mask-bar"></div>' +
  599. '</div>');
  600. element.appendChild(scrollMask[0]);
  601. scrollMask.on('wheel', preventDefault);
  602. scrollMask.on('touchmove', preventDefault);
  603. $document.on('keydown', disableKeyNav);
  604. return function restoreScroll() {
  605. scrollMask.off('wheel');
  606. scrollMask.off('touchmove');
  607. scrollMask[0].parentNode.removeChild(scrollMask[0]);
  608. $document.off('keydown', disableKeyNav);
  609. delete $mdUtil.disableScrollAround._enableScrolling;
  610. };
  611. // Prevent keypresses from elements inside the body
  612. // used to stop the keypresses that could cause the page to scroll
  613. // (arrow keys, spacebar, tab, etc).
  614. function disableKeyNav(e) {
  615. //-- temporarily removed this logic, will possibly re-add at a later date
  616. return;
  617. if (!element[0].contains(e.target)) {
  618. e.preventDefault();
  619. e.stopImmediatePropagation();
  620. }
  621. }
  622. function preventDefault(e) {
  623. e.preventDefault();
  624. }
  625. }
  626. // Converts the body to a position fixed block and translate it to the proper scroll
  627. // position
  628. function disableBodyScroll() {
  629. var htmlNode = body.parentNode;
  630. var restoreHtmlStyle = htmlNode.getAttribute('style') || '';
  631. var restoreBodyStyle = body.getAttribute('style') || '';
  632. var scrollOffset = $mdUtil.scrollTop(body);
  633. var clientWidth = body.clientWidth;
  634. if (body.scrollHeight > body.clientHeight) {
  635. applyStyles(body, {
  636. position: 'fixed',
  637. width: '100%',
  638. top: -scrollOffset + 'px'
  639. });
  640. applyStyles(htmlNode, {
  641. overflowY: 'scroll'
  642. });
  643. }
  644. if (body.clientWidth < clientWidth) applyStyles(body, {overflow: 'hidden'});
  645. return function restoreScroll() {
  646. body.setAttribute('style', restoreBodyStyle);
  647. htmlNode.setAttribute('style', restoreHtmlStyle);
  648. body.scrollTop = scrollOffset;
  649. };
  650. }
  651. function applyStyles(el, styles) {
  652. for (var key in styles) {
  653. el.style[key] = styles[key];
  654. }
  655. }
  656. },
  657. enableScrolling: function() {
  658. var method = this.disableScrollAround._enableScrolling;
  659. method && method();
  660. },
  661. floatingScrollbars: function() {
  662. if (this.floatingScrollbars.cached === undefined) {
  663. var tempNode = angular.element('<div style="width: 100%; z-index: -1; position: absolute; height: 35px; overflow-y: scroll"><div style="height: 60;"></div></div>');
  664. $document[0].body.appendChild(tempNode[0]);
  665. this.floatingScrollbars.cached = (tempNode[0].offsetWidth == tempNode[0].childNodes[0].offsetWidth);
  666. tempNode.remove();
  667. }
  668. return this.floatingScrollbars.cached;
  669. },
  670. // Mobile safari only allows you to set focus in click event listeners...
  671. forceFocus: function(element) {
  672. var node = element[0] || element;
  673. document.addEventListener('click', function focusOnClick(ev) {
  674. if (ev.target === node && ev.$focus) {
  675. node.focus();
  676. ev.stopImmediatePropagation();
  677. ev.preventDefault();
  678. node.removeEventListener('click', focusOnClick);
  679. }
  680. }, true);
  681. var newEvent = document.createEvent('MouseEvents');
  682. newEvent.initMouseEvent('click', false, true, window, {}, 0, 0, 0, 0,
  683. false, false, false, false, 0, null);
  684. newEvent.$material = true;
  685. newEvent.$focus = true;
  686. node.dispatchEvent(newEvent);
  687. },
  688. /**
  689. * facade to build md-backdrop element with desired styles
  690. * NOTE: Use $compile to trigger backdrop postLink function
  691. */
  692. createBackdrop: function(scope, addClass) {
  693. return $compile($mdUtil.supplant('<md-backdrop class="{0}">', [addClass]))(scope);
  694. },
  695. /**
  696. * supplant() method from Crockford's `Remedial Javascript`
  697. * Equivalent to use of $interpolate; without dependency on
  698. * interpolation symbols and scope. Note: the '{<token>}' can
  699. * be property names, property chains, or array indices.
  700. */
  701. supplant: function(template, values, pattern) {
  702. pattern = pattern || /\{([^\{\}]*)\}/g;
  703. return template.replace(pattern, function(a, b) {
  704. var p = b.split('.'),
  705. r = values;
  706. try {
  707. for (var s in p) {
  708. r = r[p[s]];
  709. }
  710. } catch (e) {
  711. r = a;
  712. }
  713. return (typeof r === 'string' || typeof r === 'number') ? r : a;
  714. });
  715. },
  716. fakeNgModel: function() {
  717. return {
  718. $fake: true,
  719. $setTouched: angular.noop,
  720. $setViewValue: function(value) {
  721. this.$viewValue = value;
  722. this.$render(value);
  723. this.$viewChangeListeners.forEach(function(cb) {
  724. cb();
  725. });
  726. },
  727. $isEmpty: function(value) {
  728. return ('' + value).length === 0;
  729. },
  730. $parsers: [],
  731. $formatters: [],
  732. $viewChangeListeners: [],
  733. $render: angular.noop
  734. };
  735. },
  736. // Returns a function, that, as long as it continues to be invoked, will not
  737. // be triggered. The function will be called after it stops being called for
  738. // N milliseconds.
  739. // @param wait Integer value of msecs to delay (since last debounce reset); default value 10 msecs
  740. // @param invokeApply should the $timeout trigger $digest() dirty checking
  741. debounce: function(func, wait, scope, invokeApply) {
  742. var timer;
  743. return function debounced() {
  744. var context = scope,
  745. args = Array.prototype.slice.call(arguments);
  746. $timeout.cancel(timer);
  747. timer = $timeout(function() {
  748. timer = undefined;
  749. func.apply(context, args);
  750. }, wait || 10, invokeApply);
  751. };
  752. },
  753. // Returns a function that can only be triggered every `delay` milliseconds.
  754. // In other words, the function will not be called unless it has been more
  755. // than `delay` milliseconds since the last call.
  756. throttle: function throttle(func, delay) {
  757. var recent;
  758. return function throttled() {
  759. var context = this;
  760. var args = arguments;
  761. var now = $mdUtil.now();
  762. if (!recent || (now - recent > delay)) {
  763. func.apply(context, args);
  764. recent = now;
  765. }
  766. };
  767. },
  768. /**
  769. * Measures the number of milliseconds taken to run the provided callback
  770. * function. Uses a high-precision timer if available.
  771. */
  772. time: function time(cb) {
  773. var start = $mdUtil.now();
  774. cb();
  775. return $mdUtil.now() - start;
  776. },
  777. /**
  778. * Create an implicit getter that caches its `getter()`
  779. * lookup value
  780. */
  781. valueOnUse : function (scope, key, getter) {
  782. var value = null, args = Array.prototype.slice.call(arguments);
  783. var params = (args.length > 3) ? args.slice(3) : [ ];
  784. Object.defineProperty(scope, key, {
  785. get: function () {
  786. if (value === null) value = getter.apply(scope, params);
  787. return value;
  788. }
  789. });
  790. },
  791. /**
  792. * Get a unique ID.
  793. *
  794. * @returns {string} an unique numeric string
  795. */
  796. nextUid: function() {
  797. return '' + nextUniqueId++;
  798. },
  799. // Stop watchers and events from firing on a scope without destroying it,
  800. // by disconnecting it from its parent and its siblings' linked lists.
  801. disconnectScope: function disconnectScope(scope) {
  802. if (!scope) return;
  803. // we can't destroy the root scope or a scope that has been already destroyed
  804. if (scope.$root === scope) return;
  805. if (scope.$$destroyed) return;
  806. var parent = scope.$parent;
  807. scope.$$disconnected = true;
  808. // See Scope.$destroy
  809. if (parent.$$childHead === scope) parent.$$childHead = scope.$$nextSibling;
  810. if (parent.$$childTail === scope) parent.$$childTail = scope.$$prevSibling;
  811. if (scope.$$prevSibling) scope.$$prevSibling.$$nextSibling = scope.$$nextSibling;
  812. if (scope.$$nextSibling) scope.$$nextSibling.$$prevSibling = scope.$$prevSibling;
  813. scope.$$nextSibling = scope.$$prevSibling = null;
  814. },
  815. // Undo the effects of disconnectScope above.
  816. reconnectScope: function reconnectScope(scope) {
  817. if (!scope) return;
  818. // we can't disconnect the root node or scope already disconnected
  819. if (scope.$root === scope) return;
  820. if (!scope.$$disconnected) return;
  821. var child = scope;
  822. var parent = child.$parent;
  823. child.$$disconnected = false;
  824. // See Scope.$new for this logic...
  825. child.$$prevSibling = parent.$$childTail;
  826. if (parent.$$childHead) {
  827. parent.$$childTail.$$nextSibling = child;
  828. parent.$$childTail = child;
  829. } else {
  830. parent.$$childHead = parent.$$childTail = child;
  831. }
  832. },
  833. /*
  834. * getClosest replicates jQuery.closest() to walk up the DOM tree until it finds a matching nodeName
  835. *
  836. * @param el Element to start walking the DOM from
  837. * @param tagName Tag name to find closest to el, such as 'form'
  838. */
  839. getClosest: function getClosest(el, tagName, onlyParent) {
  840. if (el instanceof angular.element) el = el[0];
  841. tagName = tagName.toUpperCase();
  842. if (onlyParent) el = el.parentNode;
  843. if (!el) return null;
  844. do {
  845. if (el.nodeName === tagName) {
  846. return el;
  847. }
  848. } while (el = el.parentNode);
  849. return null;
  850. },
  851. /**
  852. * Build polyfill for the Node.contains feature (if needed)
  853. */
  854. elementContains: function(node, child) {
  855. var hasContains = (window.Node && window.Node.prototype && Node.prototype.contains);
  856. var findFn = hasContains ? angular.bind(node, node.contains) : angular.bind(node, function(arg) {
  857. // compares the positions of two nodes and returns a bitmask
  858. return (node === child) || !!(this.compareDocumentPosition(arg) & 16)
  859. });
  860. return findFn(child);
  861. },
  862. /**
  863. * Functional equivalent for $element.filter(‘md-bottom-sheet’)
  864. * useful with interimElements where the element and its container are important...
  865. */
  866. extractElementByName: function(element, nodeName) {
  867. for (var i = 0, len = element.length; i < len; i++) {
  868. if (element[i].nodeName.toLowerCase() === nodeName) {
  869. return angular.element(element[i]);
  870. }
  871. }
  872. $log.warn( $mdUtil.supplant("Unable to find node '{0}' in element.",[nodeName]) );
  873. return element;
  874. },
  875. /**
  876. * Give optional properties with no value a boolean true if attr provided or false otherwise
  877. */
  878. initOptionalProperties: function(scope, attr, defaults) {
  879. defaults = defaults || {};
  880. angular.forEach(scope.$$isolateBindings, function(binding, key) {
  881. if (binding.optional && angular.isUndefined(scope[key])) {
  882. var attrIsDefined = angular.isDefined(attr[binding.attrName]);
  883. scope[key] = angular.isDefined(defaults[key]) ? defaults[key] : attrIsDefined;
  884. }
  885. });
  886. },
  887. /**
  888. * Alternative to $timeout calls with 0 delay.
  889. * nextTick() coalesces all calls within a single frame
  890. * to minimize $digest thrashing
  891. *
  892. * @param callback
  893. * @param digest
  894. * @returns {*}
  895. */
  896. nextTick: function(callback, digest) {
  897. //-- grab function reference for storing state details
  898. var nextTick = $mdUtil.nextTick;
  899. var timeout = nextTick.timeout;
  900. var queue = nextTick.queue || [];
  901. //-- add callback to the queue
  902. queue.push(callback);
  903. //-- set default value for digest
  904. if (digest == null) digest = true;
  905. //-- store updated digest/queue values
  906. nextTick.digest = nextTick.digest || digest;
  907. nextTick.queue = queue;
  908. //-- either return existing timeout or create a new one
  909. return timeout || (nextTick.timeout = $timeout(processQueue, 0, false));
  910. /**
  911. * Grab a copy of the current queue
  912. * Clear the queue for future use
  913. * Process the existing queue
  914. * Trigger digest if necessary
  915. */
  916. function processQueue() {
  917. var queue = nextTick.queue;
  918. var digest = nextTick.digest;
  919. nextTick.queue = [];
  920. nextTick.timeout = null;
  921. nextTick.digest = false;
  922. queue.forEach(function(callback) {
  923. callback();
  924. });
  925. if (digest) $rootScope.$digest();
  926. }
  927. },
  928. /**
  929. * Processes a template and replaces the start/end symbols if the application has
  930. * overriden them.
  931. *
  932. * @param template The template to process whose start/end tags may be replaced.
  933. * @returns {*}
  934. */
  935. processTemplate: function(template) {
  936. if (usesStandardSymbols) {
  937. return template;
  938. } else {
  939. if (!template || !angular.isString(template)) return template;
  940. return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);
  941. }
  942. }
  943. };
  944. // Instantiate other namespace utility methods
  945. $mdUtil.dom.animator = $$mdAnimate($mdUtil);
  946. return $mdUtil;
  947. function getNode(el) {
  948. return el[0] || el;
  949. }
  950. }
  951. UtilFactory.$inject = ["$document", "$timeout", "$compile", "$rootScope", "$$mdAnimate", "$interpolate", "$log"];
  952. /*
  953. * Since removing jQuery from the demos, some code that uses `element.focus()` is broken.
  954. * We need to add `element.focus()`, because it's testable unlike `element[0].focus`.
  955. */
  956. angular.element.prototype.focus = angular.element.prototype.focus || function() {
  957. if (this.length) {
  958. this[0].focus();
  959. }
  960. return this;
  961. };
  962. angular.element.prototype.blur = angular.element.prototype.blur || function() {
  963. if (this.length) {
  964. this[0].blur();
  965. }
  966. return this;
  967. };
  968. })();
  969. (function(){
  970. "use strict";
  971. angular.module('material.core')
  972. .service('$mdAria', AriaService);
  973. /*
  974. * @ngInject
  975. */
  976. function AriaService($$rAF, $log, $window) {
  977. return {
  978. expect: expect,
  979. expectAsync: expectAsync,
  980. expectWithText: expectWithText
  981. };
  982. /**
  983. * Check if expected attribute has been specified on the target element or child
  984. * @param element
  985. * @param attrName
  986. * @param {optional} defaultValue What to set the attr to if no value is found
  987. */
  988. function expect(element, attrName, defaultValue) {
  989. var node = angular.element(element)[0] || element;
  990. // if node exists and neither it nor its children have the attribute
  991. if (node &&
  992. ((!node.hasAttribute(attrName) ||
  993. node.getAttribute(attrName).length === 0) &&
  994. !childHasAttribute(node, attrName))) {
  995. defaultValue = angular.isString(defaultValue) ? defaultValue.trim() : '';
  996. if (defaultValue.length) {
  997. element.attr(attrName, defaultValue);
  998. } else {
  999. $log.warn('ARIA: Attribute "', attrName, '", required for accessibility, is missing on node:', node);
  1000. }
  1001. }
  1002. }
  1003. function expectAsync(element, attrName, defaultValueGetter) {
  1004. // Problem: when retrieving the element's contents synchronously to find the label,
  1005. // the text may not be defined yet in the case of a binding.
  1006. // There is a higher chance that a binding will be defined if we wait one frame.
  1007. $$rAF(function() {
  1008. expect(element, attrName, defaultValueGetter());
  1009. });
  1010. }
  1011. function expectWithText(element, attrName) {
  1012. expectAsync(element, attrName, function() {
  1013. return getText(element);
  1014. });
  1015. }
  1016. function getText(element) {
  1017. return element.text().trim();
  1018. }
  1019. function childHasAttribute(node, attrName) {
  1020. var hasChildren = node.hasChildNodes(),
  1021. hasAttr = false;
  1022. function isHidden(el) {
  1023. var style = el.currentStyle ? el.currentStyle : $window.getComputedStyle(el);
  1024. return (style.display === 'none');
  1025. }
  1026. if(hasChildren) {
  1027. var children = node.childNodes;
  1028. for(var i=0; i<children.length; i++){
  1029. var child = children[i];
  1030. if(child.nodeType === 1 && child.hasAttribute(attrName)) {
  1031. if(!isHidden(child)){
  1032. hasAttr = true;
  1033. }
  1034. }
  1035. }
  1036. }
  1037. return hasAttr;
  1038. }
  1039. }
  1040. AriaService.$inject = ["$$rAF", "$log", "$window"];
  1041. })();
  1042. (function(){
  1043. "use strict";
  1044. angular
  1045. .module('material.core')
  1046. .service('$mdCompiler', mdCompilerService);
  1047. function mdCompilerService($q, $http, $injector, $compile, $controller, $templateCache) {
  1048. /* jshint validthis: true */
  1049. /*
  1050. * @ngdoc service
  1051. * @name $mdCompiler
  1052. * @module material.core
  1053. * @description
  1054. * The $mdCompiler service is an abstraction of angular's compiler, that allows the developer
  1055. * to easily compile an element with a templateUrl, controller, and locals.
  1056. *
  1057. * @usage
  1058. * <hljs lang="js">
  1059. * $mdCompiler.compile({
  1060. * templateUrl: 'modal.html',
  1061. * controller: 'ModalCtrl',
  1062. * locals: {
  1063. * modal: myModalInstance;
  1064. * }
  1065. * }).then(function(compileData) {
  1066. * compileData.element; // modal.html's template in an element
  1067. * compileData.link(myScope); //attach controller & scope to element
  1068. * });
  1069. * </hljs>
  1070. */
  1071. /*
  1072. * @ngdoc method
  1073. * @name $mdCompiler#compile
  1074. * @description A helper to compile an HTML template/templateUrl with a given controller,
  1075. * locals, and scope.
  1076. * @param {object} options An options object, with the following properties:
  1077. *
  1078. * - `controller` - `{(string=|function()=}` Controller fn that should be associated with
  1079. * newly created scope or the name of a registered controller if passed as a string.
  1080. * - `controllerAs` - `{string=}` A controller alias name. If present the controller will be
  1081. * published to scope under the `controllerAs` name.
  1082. * - `template` - `{string=}` An html template as a string.
  1083. * - `templateUrl` - `{string=}` A path to an html template.
  1084. * - `transformTemplate` - `{function(template)=}` A function which transforms the template after
  1085. * it is loaded. It will be given the template string as a parameter, and should
  1086. * return a a new string representing the transformed template.
  1087. * - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should
  1088. * be injected into the controller. If any of these dependencies are promises, the compiler
  1089. * will wait for them all to be resolved, or if one is rejected before the controller is
  1090. * instantiated `compile()` will fail..
  1091. * * `key` - `{string}`: a name of a dependency to be injected into the controller.
  1092. * * `factory` - `{string|function}`: If `string` then it is an alias for a service.
  1093. * Otherwise if function, then it is injected and the return value is treated as the
  1094. * dependency. If the result is a promise, it is resolved before its value is
  1095. * injected into the controller.
  1096. *
  1097. * @returns {object=} promise A promise, which will be resolved with a `compileData` object.
  1098. * `compileData` has the following properties:
  1099. *
  1100. * - `element` - `{element}`: an uncompiled element matching the provided template.
  1101. * - `link` - `{function(scope)}`: A link function, which, when called, will compile
  1102. * the element and instantiate the provided controller (if given).
  1103. * - `locals` - `{object}`: The locals which will be passed into the controller once `link` is
  1104. * called. If `bindToController` is true, they will be coppied to the ctrl instead
  1105. * - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in.
  1106. */
  1107. this.compile = function(options) {
  1108. var templateUrl = options.templateUrl;
  1109. var template = options.template || '';
  1110. var controller = options.controller;
  1111. var controllerAs = options.controllerAs;
  1112. var resolve = angular.extend({}, options.resolve || {});
  1113. var locals = angular.extend({}, options.locals || {});
  1114. var transformTemplate = options.transformTemplate || angular.identity;
  1115. var bindToController = options.bindToController;
  1116. // Take resolve values and invoke them.
  1117. // Resolves can either be a string (value: 'MyRegisteredAngularConst'),
  1118. // or an invokable 'factory' of sorts: (value: function ValueGetter($dependency) {})
  1119. angular.forEach(resolve, function(value, key) {
  1120. if (angular.isString(value)) {
  1121. resolve[key] = $injector.get(value);
  1122. } else {
  1123. resolve[key] = $injector.invoke(value);
  1124. }
  1125. });
  1126. //Add the locals, which are just straight values to inject
  1127. //eg locals: { three: 3 }, will inject three into the controller
  1128. angular.extend(resolve, locals);
  1129. if (templateUrl) {
  1130. resolve.$template = $http.get(templateUrl, {cache: $templateCache})
  1131. .then(function(response) {
  1132. return response.data;
  1133. });
  1134. } else {
  1135. resolve.$template = $q.when(template);
  1136. }
  1137. // Wait for all the resolves to finish if they are promises
  1138. return $q.all(resolve).then(function(locals) {
  1139. var compiledData;
  1140. var template = transformTemplate(locals.$template);
  1141. var element = options.element || angular.element('<div>').html(template.trim()).contents();
  1142. var linkFn = $compile(element);
  1143. // Return a linking function that can be used later when the element is ready
  1144. return compiledData = {
  1145. locals: locals,
  1146. element: element,
  1147. link: function link(scope) {
  1148. locals.$scope = scope;
  1149. //Instantiate controller if it exists, because we have scope
  1150. if (controller) {
  1151. var invokeCtrl = $controller(controller, locals, true);
  1152. if (bindToController) {
  1153. angular.extend(invokeCtrl.instance, locals);
  1154. }
  1155. var ctrl = invokeCtrl();
  1156. //See angular-route source for this logic
  1157. element.data('$ngControllerController', ctrl);
  1158. element.children().data('$ngControllerController', ctrl);
  1159. if (controllerAs) {
  1160. scope[controllerAs] = ctrl;
  1161. }
  1162. // Publish reference to this controller
  1163. compiledData.controller = ctrl;
  1164. }
  1165. return linkFn(scope);
  1166. }
  1167. };
  1168. });
  1169. };
  1170. }
  1171. mdCompilerService.$inject = ["$q", "$http", "$injector", "$compile", "$controller", "$templateCache"];
  1172. })();
  1173. (function(){
  1174. "use strict";
  1175. var HANDLERS = {};
  1176. /* The state of the current 'pointer'
  1177. * The pointer represents the state of the current touch.
  1178. * It contains normalized x and y coordinates from DOM events,
  1179. * as well as other information abstracted from the DOM.
  1180. */
  1181. var pointer, lastPointer, forceSkipClickHijack = false;
  1182. /**
  1183. * The position of the most recent click if that click was on a label element.
  1184. * @type {{x: number, y: number}?}
  1185. */
  1186. var lastLabelClickPos = null;
  1187. // Used to attach event listeners once when multiple ng-apps are running.
  1188. var isInitialized = false;
  1189. angular
  1190. .module('material.core.gestures', [ ])
  1191. .provider('$mdGesture', MdGestureProvider)
  1192. .factory('$$MdGestureHandler', MdGestureHandler)
  1193. .run( attachToDocument );
  1194. /**
  1195. * @ngdoc service
  1196. * @name $mdGestureProvider
  1197. * @module material.core.gestures
  1198. *
  1199. * @description
  1200. * In some scenarios on Mobile devices (without jQuery), the click events should NOT be hijacked.
  1201. * `$mdGestureProvider` is used to configure the Gesture module to ignore or skip click hijacking on mobile
  1202. * devices.
  1203. *
  1204. * <hljs lang="js">
  1205. * app.config(function($mdGestureProvider) {
  1206. *
  1207. * // For mobile devices without jQuery loaded, do not
  1208. * // intercept click events during the capture phase.
  1209. * $mdGestureProvider.skipClickHijack();
  1210. *
  1211. * });
  1212. * </hljs>
  1213. *
  1214. */
  1215. function MdGestureProvider() { }
  1216. MdGestureProvider.prototype = {
  1217. // Publish access to setter to configure a variable BEFORE the
  1218. // $mdGesture service is instantiated...
  1219. skipClickHijack: function() {
  1220. return forceSkipClickHijack = true;
  1221. },
  1222. /**
  1223. * $get is used to build an instance of $mdGesture
  1224. * @ngInject
  1225. */
  1226. $get : ["$$MdGestureHandler", "$$rAF", "$timeout", function($$MdGestureHandler, $$rAF, $timeout) {
  1227. return new MdGesture($$MdGestureHandler, $$rAF, $timeout);
  1228. }]
  1229. };
  1230. /**
  1231. * MdGesture factory construction function
  1232. * @ngInject
  1233. */
  1234. function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
  1235. var userAgent = navigator.userAgent || navigator.vendor || window.opera;
  1236. var isIos = userAgent.match(/ipad|iphone|ipod/i);
  1237. var isAndroid = userAgent.match(/android/i);
  1238. var hasJQuery = (typeof window.jQuery !== 'undefined') && (angular.element === window.jQuery);
  1239. var self = {
  1240. handler: addHandler,
  1241. register: register,
  1242. // On mobile w/out jQuery, we normally intercept clicks. Should we skip that?
  1243. isHijackingClicks: (isIos || isAndroid) && !hasJQuery && !forceSkipClickHijack
  1244. };
  1245. if (self.isHijackingClicks) {
  1246. self.handler('click', {
  1247. options: {
  1248. maxDistance: 6
  1249. },
  1250. onEnd: function (ev, pointer) {
  1251. if (pointer.distance < this.state.options.maxDistance) {
  1252. this.dispatchEvent(ev, 'click');
  1253. }
  1254. }
  1255. });
  1256. }
  1257. /*
  1258. * Register an element to listen for a handler.
  1259. * This allows an element to override the default options for a handler.
  1260. * Additionally, some handlers like drag and hold only dispatch events if
  1261. * the domEvent happens inside an element that's registered to listen for these events.
  1262. *
  1263. * @see GestureHandler for how overriding of default options works.
  1264. * @example $mdGesture.register(myElement, 'drag', { minDistance: 20, horziontal: false })
  1265. */
  1266. function register(element, handlerName, options) {
  1267. var handler = HANDLERS[handlerName.replace(/^\$md./, '')];
  1268. if (!handler) {
  1269. throw new Error('Failed to register element with handler ' + handlerName + '. ' +
  1270. 'Available handlers: ' + Object.keys(HANDLERS).join(', '));
  1271. }
  1272. return handler.registerElement(element, options);
  1273. }
  1274. /*
  1275. * add a handler to $mdGesture. see below.
  1276. */
  1277. function addHandler(name, definition) {
  1278. var handler = new $$MdGestureHandler(name);
  1279. angular.extend(handler, definition);
  1280. HANDLERS[name] = handler;
  1281. return self;
  1282. }
  1283. /*
  1284. * Register handlers. These listen to touch/start/move events, interpret them,
  1285. * and dispatch gesture events depending on options & conditions. These are all
  1286. * instances of GestureHandler.
  1287. * @see GestureHandler
  1288. */
  1289. return self
  1290. /*
  1291. * The press handler dispatches an event on touchdown/touchend.
  1292. * It's a simple abstraction of touch/mouse/pointer start and end.
  1293. */
  1294. .handler('press', {
  1295. onStart: function (ev, pointer) {
  1296. this.dispatchEvent(ev, '$md.pressdown');
  1297. },
  1298. onEnd: function (ev, pointer) {
  1299. this.dispatchEvent(ev, '$md.pressup');
  1300. }
  1301. })
  1302. /*
  1303. * The hold handler dispatches an event if the user keeps their finger within
  1304. * the same <maxDistance> area for <delay> ms.
  1305. * The hold handler will only run if a parent of the touch target is registered
  1306. * to listen for hold events through $mdGesture.register()
  1307. */
  1308. .handler('hold', {
  1309. options: {
  1310. maxDistance: 6,
  1311. delay: 500
  1312. },
  1313. onCancel: function () {
  1314. $timeout.cancel(this.state.timeout);
  1315. },
  1316. onStart: function (ev, pointer) {
  1317. // For hold, require a parent to be registered with $mdGesture.register()
  1318. // Because we prevent scroll events, this is necessary.
  1319. if (!this.state.registeredParent) return this.cancel();
  1320. this.state.pos = {x: pointer.x, y: pointer.y};
  1321. this.state.timeout = $timeout(angular.bind(this, function holdDelayFn() {
  1322. this.dispatchEvent(ev, '$md.hold');
  1323. this.cancel(); //we're done!
  1324. }), this.state.options.delay, false);
  1325. },
  1326. onMove: function (ev, pointer) {
  1327. // Don't scroll while waiting for hold.
  1328. // If we don't preventDefault touchmove events here, Android will assume we don't
  1329. // want to listen to anymore touch events. It will start scrolling and stop sending
  1330. // touchmove events.
  1331. ev.preventDefault();
  1332. // If the user moves greater than <maxDistance> pixels, stop the hold timer
  1333. // set in onStart
  1334. var dx = this.state.pos.x - pointer.x;
  1335. var dy = this.state.pos.y - pointer.y;
  1336. if (Math.sqrt(dx * dx + dy * dy) > this.options.maxDistance) {
  1337. this.cancel();
  1338. }
  1339. },
  1340. onEnd: function () {
  1341. this.onCancel();
  1342. }
  1343. })
  1344. /*
  1345. * The drag handler dispatches a drag event if the user holds and moves his finger greater than
  1346. * <minDistance> px in the x or y direction, depending on options.horizontal.
  1347. * The drag will be cancelled if the user moves his finger greater than <minDistance>*<cancelMultiplier> in
  1348. * the perpindicular direction. Eg if the drag is horizontal and the user moves his finger <minDistance>*<cancelMultiplier>
  1349. * pixels vertically, this handler won't consider the move part of a drag.
  1350. */
  1351. .handler('drag', {
  1352. options: {
  1353. minDistance: 6,
  1354. horizontal: true,
  1355. cancelMultiplier: 1.5
  1356. },
  1357. onStart: function (ev) {
  1358. // For drag, require a parent to be registered with $mdGesture.register()
  1359. if (!this.state.registeredParent) this.cancel();
  1360. },
  1361. onMove: function (ev, pointer) {
  1362. var shouldStartDrag, shouldCancel;
  1363. // Don't scroll while deciding if this touchmove qualifies as a drag event.
  1364. // If we don't preventDefault touchmove events here, Android will assume we don't
  1365. // want to listen to anymore touch events. It will start scrolling and stop sending
  1366. // touchmove events.
  1367. ev.preventDefault();
  1368. if (!this.state.dragPointer) {
  1369. if (this.state.options.horizontal) {
  1370. shouldStartDrag = Math.abs(pointer.distanceX) > this.state.options.minDistance;
  1371. shouldCancel = Math.abs(pointer.distanceY) > this.state.options.minDistance * this.state.options.cancelMultiplier;
  1372. } else {
  1373. shouldStartDrag = Math.abs(pointer.distanceY) > this.state.options.minDistance;
  1374. shouldCancel = Math.abs(pointer.distanceX) > this.state.options.minDistance * this.state.options.cancelMultiplier;
  1375. }
  1376. if (shouldStartDrag) {
  1377. // Create a new pointer representing this drag, starting at this point where the drag started.
  1378. this.state.dragPointer = makeStartPointer(ev);
  1379. updatePointerState(ev, this.state.dragPointer);
  1380. this.dispatchEvent(ev, '$md.dragstart', this.state.dragPointer);
  1381. } else if (shouldCancel) {
  1382. this.cancel();
  1383. }
  1384. } else {
  1385. this.dispatchDragMove(ev);
  1386. }
  1387. },
  1388. // Only dispatch dragmove events every frame; any more is unnecessray
  1389. dispatchDragMove: $$rAF.throttle(function (ev) {
  1390. // Make sure the drag didn't stop while waiting for the next frame
  1391. if (this.state.isRunning) {
  1392. updatePointerState(ev, this.state.dragPointer);
  1393. this.dispatchEvent(ev, '$md.drag', this.state.dragPointer);
  1394. }
  1395. }),
  1396. onEnd: function (ev, pointer) {
  1397. if (this.state.dragPointer) {
  1398. updatePointerState(ev, this.state.dragPointer);
  1399. this.dispatchEvent(ev, '$md.dragend', this.state.dragPointer);
  1400. }
  1401. }
  1402. })
  1403. /*
  1404. * The swipe handler will dispatch a swipe event if, on the end of a touch,
  1405. * the velocity and distance were high enough.
  1406. * TODO: add vertical swiping with a `horizontal` option similar to the drag handler.
  1407. */
  1408. .handler('swipe', {
  1409. options: {
  1410. minVelocity: 0.65,
  1411. minDistance: 10
  1412. },
  1413. onEnd: function (ev, pointer) {
  1414. if (Math.abs(pointer.velocityX) > this.state.options.minVelocity &&
  1415. Math.abs(pointer.distanceX) > this.state.options.minDistance) {
  1416. var eventType = pointer.directionX == 'left' ? '$md.swipeleft' : '$md.swiperight';
  1417. this.dispatchEvent(ev, eventType);
  1418. }
  1419. }
  1420. });
  1421. }
  1422. MdGesture.$inject = ["$$MdGestureHandler", "$$rAF", "$timeout"];
  1423. /**
  1424. * MdGestureHandler
  1425. * A GestureHandler is an object which is able to dispatch custom dom events
  1426. * based on native dom {touch,pointer,mouse}{start,move,end} events.
  1427. *
  1428. * A gesture will manage its lifecycle through the start,move,end, and cancel
  1429. * functions, which are called by native dom events.
  1430. *
  1431. * A gesture has the concept of 'options' (eg a swipe's required velocity), which can be
  1432. * overridden by elements registering through $mdGesture.register()
  1433. */
  1434. function GestureHandler (name) {
  1435. this.name = name;
  1436. this.state = {};
  1437. }
  1438. function MdGestureHandler() {
  1439. var hasJQuery = (typeof window.jQuery !== 'undefined') && (angular.element === window.jQuery);
  1440. GestureHandler.prototype = {
  1441. options: {},
  1442. // jQuery listeners don't work with custom DOMEvents, so we have to dispatch events
  1443. // differently when jQuery is loaded
  1444. dispatchEvent: hasJQuery ? jQueryDispatchEvent : nativeDispatchEvent,
  1445. // These are overridden by the registered handler
  1446. onStart: angular.noop,
  1447. onMove: angular.noop,
  1448. onEnd: angular.noop,
  1449. onCancel: angular.noop,
  1450. // onStart sets up a new state for the handler, which includes options from the
  1451. // nearest registered parent element of ev.target.
  1452. start: function (ev, pointer) {
  1453. if (this.state.isRunning) return;
  1454. var parentTarget = this.getNearestParent(ev.target);
  1455. // Get the options from the nearest registered parent
  1456. var parentTargetOptions = parentTarget && parentTarget.$mdGesture[this.name] || {};
  1457. this.state = {
  1458. isRunning: true,
  1459. // Override the default options with the nearest registered parent's options
  1460. options: angular.extend({}, this.options, parentTargetOptions),
  1461. // Pass in the registered parent node to the state so the onStart listener can use
  1462. registeredParent: parentTarget
  1463. };
  1464. this.onStart(ev, pointer);
  1465. },
  1466. move: function (ev, pointer) {
  1467. if (!this.state.isRunning) return;
  1468. this.onMove(ev, pointer);
  1469. },
  1470. end: function (ev, pointer) {
  1471. if (!this.state.isRunning) return;
  1472. this.onEnd(ev, pointer);
  1473. this.state.isRunning = false;
  1474. },
  1475. cancel: function (ev, pointer) {
  1476. this.onCancel(ev, pointer);
  1477. this.state = {};
  1478. },
  1479. // Find and return the nearest parent element that has been registered to
  1480. // listen for this handler via $mdGesture.register(element, 'handlerName').
  1481. getNearestParent: function (node) {
  1482. var current = node;
  1483. while (current) {
  1484. if ((current.$mdGesture || {})[this.name]) {
  1485. return current;
  1486. }
  1487. current = current.parentNode;
  1488. }
  1489. return null;
  1490. },
  1491. // Called from $mdGesture.register when an element reigsters itself with a handler.
  1492. // Store the options the user gave on the DOMElement itself. These options will
  1493. // be retrieved with getNearestParent when the handler starts.
  1494. registerElement: function (element, options) {
  1495. var self = this;
  1496. element[0].$mdGesture = element[0].$mdGesture || {};
  1497. element[0].$mdGesture[this.name] = options || {};
  1498. element.on('$destroy', onDestroy);
  1499. return onDestroy;
  1500. function onDestroy() {
  1501. delete element[0].$mdGesture[self.name];
  1502. element.off('$destroy', onDestroy);
  1503. }
  1504. }
  1505. };
  1506. return GestureHandler;
  1507. /*
  1508. * Dispatch an event with jQuery
  1509. * TODO: Make sure this sends bubbling events
  1510. *
  1511. * @param srcEvent the original DOM touch event that started this.
  1512. * @param eventType the name of the custom event to send (eg 'click' or '$md.drag')
  1513. * @param eventPointer the pointer object that matches this event.
  1514. */
  1515. function jQueryDispatchEvent(srcEvent, eventType, eventPointer) {
  1516. eventPointer = eventPointer || pointer;
  1517. var eventObj = new angular.element.Event(eventType);
  1518. eventObj.$material = true;
  1519. eventObj.pointer = eventPointer;
  1520. eventObj.srcEvent = srcEvent;
  1521. angular.extend(eventObj, {
  1522. clientX: eventPointer.x,
  1523. clientY: eventPointer.y,
  1524. screenX: eventPointer.x,
  1525. screenY: eventPointer.y,
  1526. pageX: eventPointer.x,
  1527. pageY: eventPointer.y,
  1528. ctrlKey: srcEvent.ctrlKey,
  1529. altKey: srcEvent.altKey,
  1530. shiftKey: srcEvent.shiftKey,
  1531. metaKey: srcEvent.metaKey
  1532. });
  1533. angular.element(eventPointer.target).trigger(eventObj);
  1534. }
  1535. /*
  1536. * NOTE: nativeDispatchEvent is very performance sensitive.
  1537. * @param srcEvent the original DOM touch event that started this.
  1538. * @param eventType the name of the custom event to send (eg 'click' or '$md.drag')
  1539. * @param eventPointer the pointer object that matches this event.
  1540. */
  1541. function nativeDispatchEvent(srcEvent, eventType, eventPointer) {
  1542. eventPointer = eventPointer || pointer;
  1543. var eventObj;
  1544. if (eventType === 'click') {
  1545. eventObj = document.createEvent('MouseEvents');
  1546. eventObj.initMouseEvent(
  1547. 'click', true, true, window, srcEvent.detail,
  1548. eventPointer.x, eventPointer.y, eventPointer.x, eventPointer.y,
  1549. srcEvent.ctrlKey, srcEvent.altKey, srcEvent.shiftKey, srcEvent.metaKey,
  1550. srcEvent.button, srcEvent.relatedTarget || null
  1551. );
  1552. } else {
  1553. eventObj = document.createEvent('CustomEvent');
  1554. eventObj.initCustomEvent(eventType, true, true, {});
  1555. }
  1556. eventObj.$material = true;
  1557. eventObj.pointer = eventPointer;
  1558. eventObj.srcEvent = srcEvent;
  1559. eventPointer.target.dispatchEvent(eventObj);
  1560. }
  1561. }
  1562. /**
  1563. * Attach Gestures: hook document and check shouldHijack clicks
  1564. * @ngInject
  1565. */
  1566. function attachToDocument( $mdGesture, $$MdGestureHandler ) {
  1567. // Polyfill document.contains for IE11.
  1568. // TODO: move to util
  1569. document.contains || (document.contains = function (node) {
  1570. return document.body.contains(node);
  1571. });
  1572. if (!isInitialized && $mdGesture.isHijackingClicks ) {
  1573. /*
  1574. * If hijack clicks is true, we preventDefault any click that wasn't
  1575. * sent by ngMaterial. This is because on older Android & iOS, a false, or 'ghost',
  1576. * click event will be sent ~400ms after a touchend event happens.
  1577. * The only way to know if this click is real is to prevent any normal
  1578. * click events, and add a flag to events sent by material so we know not to prevent those.
  1579. *
  1580. * Two exceptions to click events that should be prevented are:
  1581. * - click events sent by the keyboard (eg form submit)
  1582. * - events that originate from an Ionic app
  1583. */
  1584. document.addEventListener('click', function clickHijacker(ev) {
  1585. var isKeyClick = ev.clientX === 0 && ev.clientY === 0;
  1586. if (!isKeyClick && !ev.$material && !ev.isIonicTap
  1587. && !isInputEventFromLabelClick(ev)) {
  1588. ev.preventDefault();
  1589. ev.stopPropagation();
  1590. lastLabelClickPos = null;
  1591. } else {
  1592. lastLabelClickPos = null;
  1593. if (ev.target.tagName.toLowerCase() == 'label') {
  1594. lastLabelClickPos = {x: ev.x, y: ev.y};
  1595. }
  1596. }
  1597. }, true);
  1598. isInitialized = true;
  1599. }
  1600. // Listen to all events to cover all platforms.
  1601. var START_EVENTS = 'mousedown touchstart pointerdown';
  1602. var MOVE_EVENTS = 'mousemove touchmove pointermove';
  1603. var END_EVENTS = 'mouseup mouseleave touchend touchcancel pointerup pointercancel';
  1604. angular.element(document)
  1605. .on(START_EVENTS, gestureStart)
  1606. .on(MOVE_EVENTS, gestureMove)
  1607. .on(END_EVENTS, gestureEnd)
  1608. // For testing
  1609. .on('$$mdGestureReset', function gestureClearCache () {
  1610. lastPointer = pointer = null;
  1611. });
  1612. /*
  1613. * When a DOM event happens, run all registered gesture handlers' lifecycle
  1614. * methods which match the DOM event.
  1615. * Eg when a 'touchstart' event happens, runHandlers('start') will call and
  1616. * run `handler.cancel()` and `handler.start()` on all registered handlers.
  1617. */
  1618. function runHandlers(handlerEvent, event) {
  1619. var handler;
  1620. for (var name in HANDLERS) {
  1621. handler = HANDLERS[name];
  1622. if( handler instanceof $$MdGestureHandler ) {
  1623. if (handlerEvent === 'start') {
  1624. // Run cancel to reset any handlers' state
  1625. handler.cancel();
  1626. }
  1627. handler[handlerEvent](event, pointer);
  1628. }
  1629. }
  1630. }
  1631. /*
  1632. * gestureStart vets if a start event is legitimate (and not part of a 'ghost click' from iOS/Android)
  1633. * If it is legitimate, we initiate the pointer state and mark the current pointer's type
  1634. * For example, for a touchstart event, mark the current pointer as a 'touch' pointer, so mouse events
  1635. * won't effect it.
  1636. */
  1637. function gestureStart(ev) {
  1638. // If we're already touched down, abort
  1639. if (pointer) return;
  1640. var now = +Date.now();
  1641. // iOS & old android bug: after a touch event, a click event is sent 350 ms later.
  1642. // If <400ms have passed, don't allow an event of a different type than the previous event
  1643. if (lastPointer && !typesMatch(ev, lastPointer) && (now - lastPointer.endTime < 1500)) {
  1644. return;
  1645. }
  1646. pointer = makeStartPointer(ev);
  1647. runHandlers('start', ev);
  1648. }
  1649. /*
  1650. * If a move event happens of the right type, update the pointer and run all the move handlers.
  1651. * "of the right type": if a mousemove happens but our pointer started with a touch event, do nothing.
  1652. */
  1653. function gestureMove(ev) {
  1654. if (!pointer || !typesMatch(ev, pointer)) return;
  1655. updatePointerState(ev, pointer);
  1656. runHandlers('move', ev);
  1657. }
  1658. /*
  1659. * If an end event happens of the right type, update the pointer, run endHandlers, and save the pointer as 'lastPointer'
  1660. */
  1661. function gestureEnd(ev) {
  1662. if (!pointer || !typesMatch(ev, pointer)) return;
  1663. updatePointerState(ev, pointer);
  1664. pointer.endTime = +Date.now();
  1665. runHandlers('end', ev);
  1666. lastPointer = pointer;
  1667. pointer = null;
  1668. }
  1669. }
  1670. attachToDocument.$inject = ["$mdGesture", "$$MdGestureHandler"];
  1671. // ********************
  1672. // Module Functions
  1673. // ********************
  1674. /*
  1675. * Initiate the pointer. x, y, and the pointer's type.
  1676. */
  1677. function makeStartPointer(ev) {
  1678. var point = getEventPoint(ev);
  1679. var startPointer = {
  1680. startTime: +Date.now(),
  1681. target: ev.target,
  1682. // 'p' for pointer events, 'm' for mouse, 't' for touch
  1683. type: ev.type.charAt(0)
  1684. };
  1685. startPointer.startX = startPointer.x = point.pageX;
  1686. startPointer.startY = startPointer.y = point.pageY;
  1687. return startPointer;
  1688. }
  1689. /*
  1690. * return whether the pointer's type matches the event's type.
  1691. * Eg if a touch event happens but the pointer has a mouse type, return false.
  1692. */
  1693. function typesMatch(ev, pointer) {
  1694. return ev && pointer && ev.type.charAt(0) === pointer.type;
  1695. }
  1696. /**
  1697. * Gets whether the given event is an input event that was caused by clicking on an
  1698. * associated label element.
  1699. *
  1700. * This is necessary because the browser will, upon clicking on a label element, fire an
  1701. * *extra* click event on its associated input (if any). mdGesture is able to flag the label
  1702. * click as with `$material` correctly, but not the second input click.
  1703. *
  1704. * In order to determine whether an input event is from a label click, we compare the (x, y) for
  1705. * the event to the (x, y) for the most recent label click (which is cleared whenever a non-label
  1706. * click occurs). Unfortunately, there are no event properties that tie the input and the label
  1707. * together (such as relatedTarget).
  1708. *
  1709. * @param {MouseEvent} event
  1710. * @returns {boolean}
  1711. */
  1712. function isInputEventFromLabelClick(event) {
  1713. return lastLabelClickPos
  1714. && lastLabelClickPos.x == event.x
  1715. && lastLabelClickPos.y == event.y;
  1716. }
  1717. /*
  1718. * Update the given pointer based upon the given DOMEvent.
  1719. * Distance, velocity, direction, duration, etc
  1720. */
  1721. function updatePointerState(ev, pointer) {
  1722. var point = getEventPoint(ev);
  1723. var x = pointer.x = point.pageX;
  1724. var y = pointer.y = point.pageY;
  1725. pointer.distanceX = x - pointer.startX;
  1726. pointer.distanceY = y - pointer.startY;
  1727. pointer.distance = Math.sqrt(
  1728. pointer.distanceX * pointer.distanceX + pointer.distanceY * pointer.distanceY
  1729. );
  1730. pointer.directionX = pointer.distanceX > 0 ? 'right' : pointer.distanceX < 0 ? 'left' : '';
  1731. pointer.directionY = pointer.distanceY > 0 ? 'up' : pointer.distanceY < 0 ? 'down' : '';
  1732. pointer.duration = +Date.now() - pointer.startTime;
  1733. pointer.velocityX = pointer.distanceX / pointer.duration;
  1734. pointer.velocityY = pointer.distanceY / pointer.duration;
  1735. }
  1736. /*
  1737. * Normalize the point where the DOM event happened whether it's touch or mouse.
  1738. * @returns point event obj with pageX and pageY on it.
  1739. */
  1740. function getEventPoint(ev) {
  1741. ev = ev.originalEvent || ev; // support jQuery events
  1742. return (ev.touches && ev.touches[0]) ||
  1743. (ev.changedTouches && ev.changedTouches[0]) ||
  1744. ev;
  1745. }
  1746. })();
  1747. (function(){
  1748. "use strict";
  1749. angular.module('material.core')
  1750. .provider('$$interimElement', InterimElementProvider);
  1751. /*
  1752. * @ngdoc service
  1753. * @name $$interimElement
  1754. * @module material.core
  1755. *
  1756. * @description
  1757. *
  1758. * Factory that contructs `$$interimElement.$service` services.
  1759. * Used internally in material design for elements that appear on screen temporarily.
  1760. * The service provides a promise-like API for interacting with the temporary
  1761. * elements.
  1762. *
  1763. * ```js
  1764. * app.service('$mdToast', function($$interimElement) {
  1765. * var $mdToast = $$interimElement(toastDefaultOptions);
  1766. * return $mdToast;
  1767. * });
  1768. * ```
  1769. * @param {object=} defaultOptions Options used by default for the `show` method on the service.
  1770. *
  1771. * @returns {$$interimElement.$service}
  1772. *
  1773. */
  1774. function InterimElementProvider() {
  1775. createInterimElementProvider.$get = InterimElementFactory;
  1776. InterimElementFactory.$inject = ["$document", "$q", "$rootScope", "$timeout", "$rootElement", "$animate", "$mdUtil", "$mdCompiler", "$mdTheming", "$log"];
  1777. return createInterimElementProvider;
  1778. /**
  1779. * Returns a new provider which allows configuration of a new interimElement
  1780. * service. Allows configuration of default options & methods for options,
  1781. * as well as configuration of 'preset' methods (eg dialog.basic(): basic is a preset method)
  1782. */
  1783. function createInterimElementProvider(interimFactoryName) {
  1784. var EXPOSED_METHODS = ['onHide', 'onShow', 'onRemove'];
  1785. var customMethods = {};
  1786. var providerConfig = {
  1787. presets: {}
  1788. };
  1789. var provider = {
  1790. setDefaults: setDefaults,
  1791. addPreset: addPreset,
  1792. addMethod: addMethod,
  1793. $get: factory
  1794. };
  1795. /**
  1796. * all interim elements will come with the 'build' preset
  1797. */
  1798. provider.addPreset('build', {
  1799. methods: ['controller', 'controllerAs', 'resolve',
  1800. 'template', 'templateUrl', 'themable', 'transformTemplate', 'parent']
  1801. });
  1802. factory.$inject = ["$$interimElement", "$injector"];
  1803. return provider;
  1804. /**
  1805. * Save the configured defaults to be used when the factory is instantiated
  1806. */
  1807. function setDefaults(definition) {
  1808. providerConfig.optionsFactory = definition.options;
  1809. providerConfig.methods = (definition.methods || []).concat(EXPOSED_METHODS);
  1810. return provider;
  1811. }
  1812. /**
  1813. * Add a method to the factory that isn't specific to any interim element operations
  1814. */
  1815. function addMethod(name, fn) {
  1816. customMethods[name] = fn;
  1817. return provider;
  1818. }
  1819. /**
  1820. * Save the configured preset to be used when the factory is instantiated
  1821. */
  1822. function addPreset(name, definition) {
  1823. definition = definition || {};
  1824. definition.methods = definition.methods || [];
  1825. definition.options = definition.options || function() { return {}; };
  1826. if (/^cancel|hide|show$/.test(name)) {
  1827. throw new Error("Preset '" + name + "' in " + interimFactoryName + " is reserved!");
  1828. }
  1829. if (definition.methods.indexOf('_options') > -1) {
  1830. throw new Error("Method '_options' in " + interimFactoryName + " is reserved!");
  1831. }
  1832. providerConfig.presets[name] = {
  1833. methods: definition.methods.concat(EXPOSED_METHODS),
  1834. optionsFactory: definition.options,
  1835. argOption: definition.argOption
  1836. };
  1837. return provider;
  1838. }
  1839. /**
  1840. * Create a factory that has the given methods & defaults implementing interimElement
  1841. */
  1842. /* @ngInject */
  1843. function factory($$interimElement, $injector) {
  1844. var defaultMethods;
  1845. var defaultOptions;
  1846. var interimElementService = $$interimElement();
  1847. /*
  1848. * publicService is what the developer will be using.
  1849. * It has methods hide(), cancel(), show(), build(), and any other
  1850. * presets which were set during the config phase.
  1851. */
  1852. var publicService = {
  1853. hide: interimElementService.hide,
  1854. cancel: interimElementService.cancel,
  1855. show: showInterimElement
  1856. };
  1857. defaultMethods = providerConfig.methods || [];
  1858. // This must be invoked after the publicService is initialized
  1859. defaultOptions = invokeFactory(providerConfig.optionsFactory, {});
  1860. // Copy over the simple custom methods
  1861. angular.forEach(customMethods, function(fn, name) {
  1862. publicService[name] = fn;
  1863. });
  1864. angular.forEach(providerConfig.presets, function(definition, name) {
  1865. var presetDefaults = invokeFactory(definition.optionsFactory, {});
  1866. var presetMethods = (definition.methods || []).concat(defaultMethods);
  1867. // Every interimElement built with a preset has a field called `$type`,
  1868. // which matches the name of the preset.
  1869. // Eg in preset 'confirm', options.$type === 'confirm'
  1870. angular.extend(presetDefaults, { $type: name });
  1871. // This creates a preset class which has setter methods for every
  1872. // method given in the `.addPreset()` function, as well as every
  1873. // method given in the `.setDefaults()` function.
  1874. //
  1875. // @example
  1876. // .setDefaults({
  1877. // methods: ['hasBackdrop', 'clickOutsideToClose', 'escapeToClose', 'targetEvent'],
  1878. // options: dialogDefaultOptions
  1879. // })
  1880. // .addPreset('alert', {
  1881. // methods: ['title', 'ok'],
  1882. // options: alertDialogOptions
  1883. // })
  1884. //
  1885. // Set values will be passed to the options when interimElement.show() is called.
  1886. function Preset(opts) {
  1887. this._options = angular.extend({}, presetDefaults, opts);
  1888. }
  1889. angular.forEach(presetMethods, function(name) {
  1890. Preset.prototype[name] = function(value) {
  1891. this._options[name] = value;
  1892. return this;
  1893. };
  1894. });
  1895. // Create shortcut method for one-linear methods
  1896. if (definition.argOption) {
  1897. var methodName = 'show' + name.charAt(0).toUpperCase() + name.slice(1);
  1898. publicService[methodName] = function(arg) {
  1899. var config = publicService[name](arg);
  1900. return publicService.show(config);
  1901. };
  1902. }
  1903. // eg $mdDialog.alert() will return a new alert preset
  1904. publicService[name] = function(arg) {
  1905. // If argOption is supplied, eg `argOption: 'content'`, then we assume
  1906. // if the argument is not an options object then it is the `argOption` option.
  1907. //
  1908. // @example `$mdToast.simple('hello')` // sets options.content to hello
  1909. // // because argOption === 'content'
  1910. if (arguments.length && definition.argOption && !angular.isObject(arg) &&
  1911. !angular.isArray(arg)) {
  1912. return (new Preset())[definition.argOption](arg);
  1913. } else {
  1914. return new Preset(arg);
  1915. }
  1916. };
  1917. });
  1918. return publicService;
  1919. function showInterimElement(opts) {
  1920. // opts is either a preset which stores its options on an _options field,
  1921. // or just an object made up of options
  1922. opts = opts || { };
  1923. if (opts._options) opts = opts._options;
  1924. return interimElementService.show(
  1925. angular.extend({}, defaultOptions, opts)
  1926. );
  1927. }
  1928. /**
  1929. * Helper to call $injector.invoke with a local of the factory name for
  1930. * this provider.
  1931. * If an $mdDialog is providing options for a dialog and tries to inject
  1932. * $mdDialog, a circular dependency error will happen.
  1933. * We get around that by manually injecting $mdDialog as a local.
  1934. */
  1935. function invokeFactory(factory, defaultVal) {
  1936. var locals = {};
  1937. locals[interimFactoryName] = publicService;
  1938. return $injector.invoke(factory || function() { return defaultVal; }, {}, locals);
  1939. }
  1940. }
  1941. }
  1942. /* @ngInject */
  1943. function InterimElementFactory($document, $q, $rootScope, $timeout, $rootElement, $animate,
  1944. $mdUtil, $mdCompiler, $mdTheming, $log ) {
  1945. return function createInterimElementService() {
  1946. var SHOW_CANCELLED = false;
  1947. var SHOW_CLOSED = true;
  1948. /*
  1949. * @ngdoc service
  1950. * @name $$interimElement.$service
  1951. *
  1952. * @description
  1953. * A service used to control inserting and removing an element into the DOM.
  1954. *
  1955. */
  1956. var service, stack = [];
  1957. // Publish instance $$interimElement service;
  1958. // ... used as $mdDialog, $mdToast, $mdMenu, and $mdSelect
  1959. return service = {
  1960. show: show,
  1961. hide: hide,
  1962. cancel: cancel
  1963. };
  1964. /*
  1965. * @ngdoc method
  1966. * @name $$interimElement.$service#show
  1967. * @kind function
  1968. *
  1969. * @description
  1970. * Adds the `$interimElement` to the DOM and returns a special promise that will be resolved or rejected
  1971. * with hide or cancel, respectively. To external cancel/hide, developers should use the
  1972. *
  1973. * @param {*} options is hashMap of settings
  1974. * @returns a Promise
  1975. *
  1976. */
  1977. function show(options) {
  1978. options = options || {};
  1979. var interimElement = new InterimElement(options);
  1980. var hideExisting = !options.skipHide && stack.length ? service.hide() : $q.when(true);
  1981. // This hide()s only the current interim element before showing the next, new one
  1982. // NOTE: this is not reversible (e.g. interim elements are not stackable)
  1983. hideExisting.finally(function() {
  1984. stack.push(interimElement);
  1985. interimElement
  1986. .show()
  1987. .catch(function( reason ) {
  1988. // $log.error("InterimElement.show() error: " + reason );
  1989. });
  1990. });
  1991. // Return a promise that will be resolved when the interim
  1992. // element is hidden or cancelled...
  1993. return interimElement.deferred.promise;
  1994. }
  1995. /*
  1996. * @ngdoc method
  1997. * @name $$interimElement.$service#hide
  1998. * @kind function
  1999. *
  2000. * @description
  2001. * Removes the `$interimElement` from the DOM and resolves the promise returned from `show`
  2002. *
  2003. * @param {*} resolveParam Data to resolve the promise with
  2004. * @returns a Promise that will be resolved after the element has been removed.
  2005. *
  2006. */
  2007. function hide(reason, options) {
  2008. if ( !stack.length ) return $q.when(reason);
  2009. options = options || {};
  2010. if (options.closeAll) {
  2011. var promise = $q.all(stack.reverse().map(closeElement));
  2012. stack = [];
  2013. return promise;
  2014. } else if (options.closeTo !== undefined) {
  2015. return $q.all(stack.splice(options.closeTo).map(closeElement));
  2016. } else {
  2017. var interim = stack.pop();
  2018. return closeElement(interim);
  2019. }
  2020. function closeElement(interim) {
  2021. interim
  2022. .remove(reason || SHOW_CLOSED, false)
  2023. .catch(function( reason ) {
  2024. // $log.error("InterimElement.hide() error: " + reason );
  2025. });
  2026. return interim.deferred.promise;
  2027. }
  2028. }
  2029. /*
  2030. * @ngdoc method
  2031. * @name $$interimElement.$service#cancel
  2032. * @kind function
  2033. *
  2034. * @description
  2035. * Removes the `$interimElement` from the DOM and rejects the promise returned from `show`
  2036. *
  2037. * @param {*} reason Data to reject the promise with
  2038. * @returns Promise that will be resolved after the element has been removed.
  2039. *
  2040. */
  2041. function cancel(reason) {
  2042. var interim = stack.shift();
  2043. if ( !interim ) return $q.when(reason);
  2044. interim
  2045. .remove(reason || SHOW_CANCELLED, true)
  2046. .catch(function( reason ) {
  2047. // $log.error("InterimElement.cancel() error: " + reason );
  2048. });
  2049. return interim.deferred.promise;
  2050. }
  2051. /*
  2052. * Internal Interim Element Object
  2053. * Used internally to manage the DOM element and related data
  2054. */
  2055. function InterimElement(options) {
  2056. var self, element, showAction = $q.when(true);
  2057. options = configureScopeAndTransitions(options);
  2058. return self = {
  2059. options : options,
  2060. deferred: $q.defer(),
  2061. show : createAndTransitionIn,
  2062. remove : transitionOutAndRemove
  2063. };
  2064. /**
  2065. * Compile, link, and show this interim element
  2066. * Use optional autoHided and transition-in effects
  2067. */
  2068. function createAndTransitionIn() {
  2069. return $q(function(resolve, reject){
  2070. compileElement(options)
  2071. .then(function( compiledData ) {
  2072. element = linkElement( compiledData, options );
  2073. showAction = showElement(element, options, compiledData.controller)
  2074. .then(resolve, rejectAll );
  2075. });
  2076. function rejectAll(fault) {
  2077. // Force the '$md<xxx>.show()' promise to reject
  2078. self.deferred.reject(fault);
  2079. // Continue rejection propagation
  2080. reject(fault);
  2081. }
  2082. });
  2083. }
  2084. /**
  2085. * After the show process has finished/rejected:
  2086. * - announce 'removing',
  2087. * - perform the transition-out, and
  2088. * - perform optional clean up scope.
  2089. */
  2090. function transitionOutAndRemove(response, isCancelled) {
  2091. options.cancelAutoHide && options.cancelAutoHide();
  2092. return $q(function(resolve, reject){
  2093. $q.when(showAction).finally(function(){
  2094. options.element.triggerHandler('$mdInterimElementRemove');
  2095. hideElement(options.element, options).then( function() {
  2096. (isCancelled && rejectAll(response)) || resolveAll();
  2097. }, rejectAll );
  2098. });
  2099. function resolveAll() {
  2100. // The `show()` returns a promise that will be resolved when the interim
  2101. // element is hidden or cancelled...
  2102. self.deferred.resolve(response);
  2103. // Now resolve the `.hide()` promise itself (optional)
  2104. resolve(response);
  2105. }
  2106. function rejectAll(fault) {
  2107. // Force the '$md<xxx>.show()' promise to reject
  2108. self.deferred.reject(fault);
  2109. // Continue rejection propagation
  2110. reject(fault);
  2111. }
  2112. });
  2113. }
  2114. /**
  2115. * Prepare optional isolated scope and prepare $animate with default enter and leave
  2116. * transitions for the new element instance.
  2117. */
  2118. function configureScopeAndTransitions(options) {
  2119. options = options || { };
  2120. if ( options.template ) {
  2121. options.template = $mdUtil.processTemplate(options.template);
  2122. }
  2123. return angular.extend({
  2124. preserveScope: false,
  2125. cancelAutoHide : angular.noop,
  2126. scope: options.scope || $rootScope.$new(options.isolateScope),
  2127. /**
  2128. * Default usage to enable $animate to transition-in; can be easily overridden via 'options'
  2129. */
  2130. onShow: function transitionIn(scope, element, options) {
  2131. return $animate.enter(element, options.parent);
  2132. },
  2133. /**
  2134. * Default usage to enable $animate to transition-out; can be easily overridden via 'options'
  2135. */
  2136. onRemove: function transitionOut(scope, element) {
  2137. // Element could be undefined if a new element is shown before
  2138. // the old one finishes compiling.
  2139. return element && $animate.leave(element) || $q.when();
  2140. }
  2141. }, options );
  2142. }
  2143. /**
  2144. * Compile an element with a templateUrl, controller, and locals
  2145. */
  2146. function compileElement(options) {
  2147. var compiled = !options.skipCompile ? $mdCompiler.compile(options) : null;
  2148. return compiled || $q(function (resolve) {
  2149. resolve({
  2150. locals: {},
  2151. link: function () {
  2152. return options.element;
  2153. }
  2154. });
  2155. });
  2156. }
  2157. /**
  2158. * Link an element with compiled configuration
  2159. */
  2160. function linkElement(compileData, options){
  2161. angular.extend(compileData.locals, options);
  2162. var element = compileData.link(options.scope);
  2163. // Search for parent at insertion time, if not specified
  2164. options.element = element;
  2165. options.parent = findParent(element, options);
  2166. if (options.themable) $mdTheming(element);
  2167. return element;
  2168. }
  2169. /**
  2170. * Search for parent at insertion time, if not specified
  2171. */
  2172. function findParent(element, options) {
  2173. var parent = options.parent;
  2174. // Search for parent at insertion time, if not specified
  2175. if (angular.isFunction(parent)) {
  2176. parent = parent(options.scope, element, options);
  2177. } else if (angular.isString(parent)) {
  2178. parent = angular.element($document[0].querySelector(parent));
  2179. } else {
  2180. parent = angular.element(parent);
  2181. }
  2182. // If parent querySelector/getter function fails, or it's just null,
  2183. // find a default.
  2184. if (!(parent || {}).length) {
  2185. var el;
  2186. if ($rootElement[0] && $rootElement[0].querySelector) {
  2187. el = $rootElement[0].querySelector(':not(svg) > body');
  2188. }
  2189. if (!el) el = $rootElement[0];
  2190. if (el.nodeName == '#comment') {
  2191. el = $document[0].body;
  2192. }
  2193. return angular.element(el);
  2194. }
  2195. return parent;
  2196. }
  2197. /**
  2198. * If auto-hide is enabled, start timer and prepare cancel function
  2199. */
  2200. function startAutoHide() {
  2201. var autoHideTimer, cancelAutoHide = angular.noop;
  2202. if (options.hideDelay) {
  2203. autoHideTimer = $timeout(service.hide, options.hideDelay) ;
  2204. cancelAutoHide = function() {
  2205. $timeout.cancel(autoHideTimer);
  2206. }
  2207. }
  2208. // Cache for subsequent use
  2209. options.cancelAutoHide = function() {
  2210. cancelAutoHide();
  2211. options.cancelAutoHide = undefined;
  2212. }
  2213. }
  2214. /**
  2215. * Show the element ( with transitions), notify complete and start
  2216. * optional auto-Hide
  2217. */
  2218. function showElement(element, options, controller) {
  2219. // Trigger onComplete callback when the `show()` finishes
  2220. var notifyComplete = options.onComplete || angular.noop;
  2221. return $q(function (resolve, reject) {
  2222. try {
  2223. // Start transitionIn
  2224. $q.when(options.onShow(options.scope, element, options, controller))
  2225. .then(function () {
  2226. notifyComplete(options.scope, element, options);
  2227. startAutoHide();
  2228. resolve(element);
  2229. }, reject );
  2230. } catch(e) {
  2231. reject(e.message);
  2232. }
  2233. });
  2234. }
  2235. function hideElement(element, options) {
  2236. var announceRemoving = options.onRemoving || angular.noop;
  2237. return $q(function (resolve, reject) {
  2238. try {
  2239. // Start transitionIn
  2240. var action = $q.when(element ? options.onRemove(options.scope, element, options) : true);
  2241. // Trigger callback *before* the remove operation starts
  2242. announceRemoving(element, action);
  2243. // Wait until transition-out is done
  2244. action.then(function () {
  2245. !options.preserveScope && options.scope.$destroy();
  2246. resolve(element);
  2247. }, reject );
  2248. } catch(e) {
  2249. reject(e.message);
  2250. }
  2251. });
  2252. }
  2253. }
  2254. };
  2255. /**
  2256. * Replace `{{` and `}}` in a string (usually a template) with the actual start-/endSymbols used
  2257. * for interpolation. This allows pre-defined templates (for components such as dialog, toast etc)
  2258. * to continue to work in apps that use custom interpolation start-/endSymbols.
  2259. *
  2260. * @param {string} text The text in which to replace `{{` / `}}`
  2261. * @returns {string} The modified string using the actual interpolation start-/endSymbols
  2262. */
  2263. function replaceInterpolationSymbols(text) {
  2264. if (!text || !angular.isString(text)) return text;
  2265. return text.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);
  2266. }
  2267. }
  2268. }
  2269. })();
  2270. (function(){
  2271. "use strict";
  2272. (function () {
  2273. 'use strict';
  2274. /**
  2275. *
  2276. * The original ngMaterial Layout solution used attribute selectors and CSS.
  2277. *
  2278. * ```html
  2279. * <div layout="column"> My Content </div>
  2280. * ```
  2281. *
  2282. * ```css
  2283. * [layout] {
  2284. * box-sizing: border-box;
  2285. * display:flex;
  2286. * }
  2287. * [layout=column] {
  2288. * flex-direction : column
  2289. * }
  2290. * ```
  2291. *
  2292. * Use of attribute selectors creates significant performance impacts in some
  2293. * browsers... mainly IE.
  2294. *
  2295. * This module registers directives that allow the same layout attributes to be
  2296. * interpreted and converted to class selectors. The directive will add equivalent classes to each element that
  2297. * contains a Layout directive.
  2298. *
  2299. * ```html
  2300. * <div layout="column" class="layout layout-column"> My Content </div>
  2301. *```
  2302. *
  2303. * ```css
  2304. * .layout {
  2305. * box-sizing: border-box;
  2306. * display:flex;
  2307. * }
  2308. * .layout-column {
  2309. * flex-direction : column
  2310. * }
  2311. * ```
  2312. */
  2313. angular.module('material.layout', [ 'ng' ])
  2314. // Attribute directives with optional value(s)
  2315. .directive('layout' , attributeWithObserve('layout' , true) )
  2316. .directive('layoutSm' , attributeWithObserve('layout-sm' , true) )
  2317. .directive('layoutGtSm' , attributeWithObserve('layout-gt-sm', true) )
  2318. .directive('layoutLtMd' , warnAttrNotSupported('layout-lt-md',true) )
  2319. .directive('layoutMd' , attributeWithObserve('layout-md' , true) )
  2320. .directive('layoutGtMd' , attributeWithObserve('layout-gt-md', true) )
  2321. .directive('layoutLtLg' , warnAttrNotSupported('layout-lt-lg',true) )
  2322. .directive('layoutLg' , attributeWithObserve('layout-lg' , true) )
  2323. .directive('layoutGtLg' , attributeWithObserve('layout-gt-lg', true) )
  2324. .directive('flex' , attributeWithObserve('flex' , true) )
  2325. .directive('flexSm' , attributeWithObserve('flex-sm' , true) )
  2326. .directive('flexGtSm' , attributeWithObserve('flex-gt-sm' , true) )
  2327. .directive('flexLtMd' , warnAttrNotSupported('flex-lt-md' ,true) )
  2328. .directive('flexMd' , attributeWithObserve('flex-md' , true) )
  2329. .directive('flexGtMd' , attributeWithObserve('flex-gt-md' , true) )
  2330. .directive('flexLtLg' , warnAttrNotSupported('flex-lt-lg' ,true) )
  2331. .directive('flexLg' , attributeWithObserve('flex-lg' , true) )
  2332. .directive('flexGtLg' , attributeWithObserve('flex-gt-lg' , true) )
  2333. // Attribute directives with optional value(s) but directiveName is NOT added as a class
  2334. .directive('layoutAlign' , attributeWithObserve('layout-align') )
  2335. .directive('layoutAlignSm' , attributeWithObserve('layout-align-sm') )
  2336. .directive('layoutAlignGtSm' , attributeWithObserve('layout-align-gt-sm') )
  2337. .directive('layoutAlignLtMd' , warnAttrNotSupported('layout-align-lt-md') )
  2338. .directive('layoutAlignMd' , attributeWithObserve('layout-align-md') )
  2339. .directive('layoutAlignGtMd' , attributeWithObserve('layout-align-gt-md') )
  2340. .directive('layoutAlignLtLg' , warnAttrNotSupported('layout-align-lt-lg') )
  2341. .directive('layoutAlignLg' , attributeWithObserve('layout-align-lg') )
  2342. .directive('layoutAlignGtLg' , attributeWithObserve('layout-align-gt-lg') )
  2343. .directive('flexOrder' , attributeWithObserve('flex-order') )
  2344. .directive('flexOrderSm' , attributeWithObserve('flex-order-sm') )
  2345. .directive('flexOrderGtSm' , attributeWithObserve('flex-order-gt-sm') )
  2346. .directive('flexOrderLtMd' , warnAttrNotSupported('flex-order-lt-md') )
  2347. .directive('flexOrderMd' , attributeWithObserve('flex-order-md') )
  2348. .directive('flexOrderGtMd' , attributeWithObserve('flex-order-gt-md') )
  2349. .directive('flexOrderLtLg' , warnAttrNotSupported('flex-order-lt-lg') )
  2350. .directive('flexOrderLg' , attributeWithObserve('flex-order-lg') )
  2351. .directive('flexOrderGtLg' , attributeWithObserve('flex-order-gt-lg') )
  2352. .directive('offset' , attributeWithObserve('offset') )
  2353. .directive('offsetSm' , attributeWithObserve('offset-sm') )
  2354. .directive('offsetGtSm' , attributeWithObserve('offset-gt-sm') )
  2355. .directive('offsetLtMd' , warnAttrNotSupported('offset-lt-md') )
  2356. .directive('offsetMd' , attributeWithObserve('offset-md') )
  2357. .directive('offsetGtMd' , attributeWithObserve('offset-gt-md') )
  2358. .directive('offsetLtLg' , warnAttrNotSupported('offset-lt-lg') )
  2359. .directive('offsetLg' , attributeWithObserve('offset-lg') )
  2360. .directive('offsetGtLg' , attributeWithObserve('offset-gt-lg') )
  2361. // Attribute directives with no value(s)
  2362. .directive('layoutMargin' , attributeWithoutValue('layout-margin') )
  2363. .directive('layoutPadding' , attributeWithoutValue('layout-padding') )
  2364. .directive('layoutWrap' , attributeWithoutValue('layout-wrap') )
  2365. .directive('layoutFill' , attributeWithoutValue('layout-fill') )
  2366. .directive('hide' , attributeWithoutValue('hide') )
  2367. .directive('hideSm' , attributeWithoutValue('hide-sm') )
  2368. .directive('hideGtSm' , attributeWithoutValue('hide-gt-sm') )
  2369. .directive('hideLtMd' , warnAttrNotSupported ('hide-lt-md') )
  2370. .directive('hideMd' , attributeWithoutValue('hide-md') )
  2371. .directive('hideGtMd' , attributeWithoutValue('hide-gt-md') )
  2372. .directive('hideLtLg' , warnAttrNotSupported ('hide-lt-lg') )
  2373. .directive('hideLg' , attributeWithoutValue('hide-lg') )
  2374. .directive('hideGtLg' , attributeWithoutValue('hide-gt-lg') )
  2375. .directive('show' , attributeWithoutValue('show') )
  2376. .directive('showSm' , attributeWithoutValue('show-sm') )
  2377. .directive('showGtSm' , attributeWithoutValue('show-gt-sm') )
  2378. .directive('showLtMd' , warnAttrNotSupported ('show-lt-md') )
  2379. .directive('showMd' , attributeWithoutValue('show-md') )
  2380. .directive('showGtMd' , attributeWithoutValue('show-gt-md') )
  2381. .directive('showLtLg' , warnAttrNotSupported ('show-lt-lg') )
  2382. .directive('showLg' , attributeWithoutValue('show-lg') )
  2383. .directive('showGtLg' , attributeWithoutValue('show-gt-lg') );
  2384. /**
  2385. * These functions create registration functions for ngMaterial Layout attribute directives
  2386. * This provides easy translation to switch ngMaterial attribute selectors to
  2387. * CLASS selectors and directives; which has huge performance implications
  2388. * for IE Browsers
  2389. */
  2390. /**
  2391. * Creates a directive registration function where a possbile dynamic attribute value will
  2392. * be observed/watched.
  2393. * @param {string} className attribute name; eg `md-layout-gt-md` with value ="row"
  2394. * @param {boolean=} addDirectiveAsClass
  2395. */
  2396. function attributeWithObserve(className, addDirectiveAsClass) {
  2397. return function() {
  2398. return {
  2399. compile: function(element, attr) {
  2400. attributeValueToClass(null, element, attr);
  2401. // Use for postLink to account for transforms after ng-transclude.
  2402. return attributeValueToClass;
  2403. }
  2404. };
  2405. };
  2406. /**
  2407. * Add as transformed class selector(s), then
  2408. * remove the deprecated attribute selector
  2409. */
  2410. function attributeValueToClass(scope, element, attr) {
  2411. var directive = attr.$normalize(className);
  2412. // Add transformed class selector(s)
  2413. if (addDirectiveAsClass) {
  2414. element.addClass(className);
  2415. }
  2416. if (attr[directive]) {
  2417. element.addClass(className + "-" + attr[directive].replace(/\s+/g, "-"));
  2418. }
  2419. if ( scope ) {
  2420. /**
  2421. * After link-phase, do NOT remove deprecated layout attribute selector.
  2422. * Instead watch the attribute so interpolated data-bindings to layout
  2423. * selectors will continue to be supported.
  2424. *
  2425. * $observe the className and update with new class (after removing the last one)
  2426. *
  2427. * e.g. `layout="{{layoutDemo.direction}}"` will update...
  2428. */
  2429. var lastClass;
  2430. attr.$observe(function() {
  2431. return attr[className];
  2432. }, function(newVal) {
  2433. element.removeClass(lastClass);
  2434. lastClass = className + "-" + String(newVal).replace(/\s+/g, "-");
  2435. element.addClass(lastClass);
  2436. });
  2437. }
  2438. }
  2439. }
  2440. /**
  2441. * Creates a registration function with for ngMaterial Layout attribute directive.
  2442. * This is a `simple` transpose of attribute usage to class usage
  2443. */
  2444. function attributeWithoutValue(className) {
  2445. return function() {
  2446. return {
  2447. compile: function(element, attr) {
  2448. attributeToClass(null, element);
  2449. // Use for postLink to account for transforms after ng-transclude.
  2450. return attributeToClass;
  2451. }
  2452. };
  2453. };
  2454. /**
  2455. * Add as transformed class selector, then
  2456. * remove the deprecated attribute selector
  2457. */
  2458. function attributeToClass(scope, element) {
  2459. element.addClass(className);
  2460. if ( scope ) {
  2461. // After link-phase, remove deprecated layout attribute selector
  2462. element.removeAttr(className);
  2463. }
  2464. }
  2465. }
  2466. /**
  2467. * Provide console warning that this layout attribute has been deprecated
  2468. */
  2469. function warnAttrNotSupported(className) {
  2470. var parts = className.split("-");
  2471. return ["$log", function($log) {
  2472. $log.warn( className + "has been deprecated. Please use a `" + parts[0] + "-gt-<xxx>` variant.");
  2473. return angular.noop;
  2474. }];
  2475. }
  2476. })();
  2477. })();
  2478. (function(){
  2479. "use strict";
  2480. /**
  2481. * @ngdoc module
  2482. * @name material.core.componentRegistry
  2483. *
  2484. * @description
  2485. * A component instance registration service.
  2486. * Note: currently this as a private service in the SideNav component.
  2487. */
  2488. angular.module('material.core')
  2489. .factory('$mdComponentRegistry', ComponentRegistry);
  2490. /*
  2491. * @private
  2492. * @ngdoc factory
  2493. * @name ComponentRegistry
  2494. * @module material.core.componentRegistry
  2495. *
  2496. */
  2497. function ComponentRegistry($log, $q) {
  2498. var self;
  2499. var instances = [ ];
  2500. var pendings = { };
  2501. return self = {
  2502. /**
  2503. * Used to print an error when an instance for a handle isn't found.
  2504. */
  2505. notFoundError: function(handle) {
  2506. $log.error('No instance found for handle', handle);
  2507. },
  2508. /**
  2509. * Return all registered instances as an array.
  2510. */
  2511. getInstances: function() {
  2512. return instances;
  2513. },
  2514. /**
  2515. * Get a registered instance.
  2516. * @param handle the String handle to look up for a registered instance.
  2517. */
  2518. get: function(handle) {
  2519. if ( !isValidID(handle) ) return null;
  2520. var i, j, instance;
  2521. for(i = 0, j = instances.length; i < j; i++) {
  2522. instance = instances[i];
  2523. if(instance.$$mdHandle === handle) {
  2524. return instance;
  2525. }
  2526. }
  2527. return null;
  2528. },
  2529. /**
  2530. * Register an instance.
  2531. * @param instance the instance to register
  2532. * @param handle the handle to identify the instance under.
  2533. */
  2534. register: function(instance, handle) {
  2535. if ( !handle ) return angular.noop;
  2536. instance.$$mdHandle = handle;
  2537. instances.push(instance);
  2538. resolveWhen();
  2539. return deregister;
  2540. /**
  2541. * Remove registration for an instance
  2542. */
  2543. function deregister() {
  2544. var index = instances.indexOf(instance);
  2545. if (index !== -1) {
  2546. instances.splice(index, 1);
  2547. }
  2548. }
  2549. /**
  2550. * Resolve any pending promises for this instance
  2551. */
  2552. function resolveWhen() {
  2553. var dfd = pendings[handle];
  2554. if ( dfd ) {
  2555. dfd.resolve( instance );
  2556. delete pendings[handle];
  2557. }
  2558. }
  2559. },
  2560. /**
  2561. * Async accessor to registered component instance
  2562. * If not available then a promise is created to notify
  2563. * all listeners when the instance is registered.
  2564. */
  2565. when : function(handle) {
  2566. if ( isValidID(handle) ) {
  2567. var deferred = $q.defer();
  2568. var instance = self.get(handle);
  2569. if ( instance ) {
  2570. deferred.resolve( instance );
  2571. } else {
  2572. pendings[handle] = deferred;
  2573. }
  2574. return deferred.promise;
  2575. }
  2576. return $q.reject("Invalid `md-component-id` value.");
  2577. }
  2578. };
  2579. function isValidID(handle){
  2580. return handle && (handle !== "");
  2581. }
  2582. }
  2583. ComponentRegistry.$inject = ["$log", "$q"];
  2584. })();
  2585. (function(){
  2586. "use strict";
  2587. (function() {
  2588. 'use strict';
  2589. /**
  2590. * @ngdoc service
  2591. * @name $mdButtonInkRipple
  2592. * @module material.core
  2593. *
  2594. * @description
  2595. * Provides ripple effects for md-button. See $mdInkRipple service for all possible configuration options.
  2596. *
  2597. * @param {object=} scope Scope within the current context
  2598. * @param {object=} element The element the ripple effect should be applied to
  2599. * @param {object=} options (Optional) Configuration options to override the defaultripple configuration
  2600. */
  2601. angular.module('material.core')
  2602. .factory('$mdButtonInkRipple', MdButtonInkRipple);
  2603. function MdButtonInkRipple($mdInkRipple) {
  2604. return {
  2605. attach: attach
  2606. };
  2607. function attach(scope, element, options) {
  2608. var elementOptions = optionsForElement(element);
  2609. return $mdInkRipple.attach(scope, element, angular.extend(elementOptions, options));
  2610. };
  2611. function optionsForElement(element) {
  2612. if (element.hasClass('md-icon-button')) {
  2613. return {
  2614. isMenuItem: element.hasClass('md-menu-item'),
  2615. fitRipple: true,
  2616. center: true
  2617. };
  2618. } else {
  2619. return {
  2620. isMenuItem: element.hasClass('md-menu-item'),
  2621. dimBackground: true
  2622. }
  2623. }
  2624. };
  2625. }
  2626. MdButtonInkRipple.$inject = ["$mdInkRipple"];;
  2627. })();
  2628. })();
  2629. (function(){
  2630. "use strict";
  2631. (function() {
  2632. 'use strict';
  2633. /**
  2634. * @ngdoc service
  2635. * @name $mdCheckboxInkRipple
  2636. * @module material.core
  2637. *
  2638. * @description
  2639. * Provides ripple effects for md-checkbox. See $mdInkRipple service for all possible configuration options.
  2640. *
  2641. * @param {object=} scope Scope within the current context
  2642. * @param {object=} element The element the ripple effect should be applied to
  2643. * @param {object=} options (Optional) Configuration options to override the defaultripple configuration
  2644. */
  2645. angular.module('material.core')
  2646. .factory('$mdCheckboxInkRipple', MdCheckboxInkRipple);
  2647. function MdCheckboxInkRipple($mdInkRipple) {
  2648. return {
  2649. attach: attach
  2650. };
  2651. function attach(scope, element, options) {
  2652. return $mdInkRipple.attach(scope, element, angular.extend({
  2653. center: true,
  2654. dimBackground: false,
  2655. fitRipple: true
  2656. }, options));
  2657. };
  2658. }
  2659. MdCheckboxInkRipple.$inject = ["$mdInkRipple"];;
  2660. })();
  2661. })();
  2662. (function(){
  2663. "use strict";
  2664. (function() {
  2665. 'use strict';
  2666. /**
  2667. * @ngdoc service
  2668. * @name $mdListInkRipple
  2669. * @module material.core
  2670. *
  2671. * @description
  2672. * Provides ripple effects for md-list. See $mdInkRipple service for all possible configuration options.
  2673. *
  2674. * @param {object=} scope Scope within the current context
  2675. * @param {object=} element The element the ripple effect should be applied to
  2676. * @param {object=} options (Optional) Configuration options to override the defaultripple configuration
  2677. */
  2678. angular.module('material.core')
  2679. .factory('$mdListInkRipple', MdListInkRipple);
  2680. function MdListInkRipple($mdInkRipple) {
  2681. return {
  2682. attach: attach
  2683. };
  2684. function attach(scope, element, options) {
  2685. return $mdInkRipple.attach(scope, element, angular.extend({
  2686. center: false,
  2687. dimBackground: true,
  2688. outline: false,
  2689. rippleSize: 'full'
  2690. }, options));
  2691. };
  2692. }
  2693. MdListInkRipple.$inject = ["$mdInkRipple"];;
  2694. })();
  2695. })();
  2696. (function(){
  2697. "use strict";
  2698. angular.module('material.core')
  2699. .factory('$mdInkRipple', InkRippleService)
  2700. .directive('mdInkRipple', InkRippleDirective)
  2701. .directive('mdNoInk', attrNoDirective)
  2702. .directive('mdNoBar', attrNoDirective)
  2703. .directive('mdNoStretch', attrNoDirective);
  2704. var DURATION = 450;
  2705. /**
  2706. * Directive used to add ripples to any element
  2707. * @ngInject
  2708. */
  2709. function InkRippleDirective ($mdButtonInkRipple, $mdCheckboxInkRipple) {
  2710. return {
  2711. controller: angular.noop,
  2712. link: function (scope, element, attr) {
  2713. attr.hasOwnProperty('mdInkRippleCheckbox')
  2714. ? $mdCheckboxInkRipple.attach(scope, element)
  2715. : $mdButtonInkRipple.attach(scope, element);
  2716. }
  2717. };
  2718. }
  2719. InkRippleDirective.$inject = ["$mdButtonInkRipple", "$mdCheckboxInkRipple"];
  2720. /**
  2721. * Service for adding ripples to any element
  2722. * @ngInject
  2723. */
  2724. function InkRippleService ($injector) {
  2725. return { attach: attach };
  2726. function attach (scope, element, options) {
  2727. if (element.controller('mdNoInk')) return angular.noop;
  2728. return $injector.instantiate(InkRippleCtrl, {
  2729. $scope: scope,
  2730. $element: element,
  2731. rippleOptions: options
  2732. });
  2733. }
  2734. }
  2735. InkRippleService.$inject = ["$injector"];
  2736. /**
  2737. * Controller used by the ripple service in order to apply ripples
  2738. * @ngInject
  2739. */
  2740. function InkRippleCtrl ($scope, $element, rippleOptions, $window, $timeout, $mdUtil) {
  2741. this.$window = $window;
  2742. this.$timeout = $timeout;
  2743. this.$mdUtil = $mdUtil;
  2744. this.$scope = $scope;
  2745. this.$element = $element;
  2746. this.options = rippleOptions;
  2747. this.mousedown = false;
  2748. this.ripples = [];
  2749. this.timeout = null; // Stores a reference to the most-recent ripple timeout
  2750. this.lastRipple = null;
  2751. $mdUtil.valueOnUse(this, 'container', this.createContainer);
  2752. $mdUtil.valueOnUse(this, 'color', this.getColor, 1);
  2753. $mdUtil.valueOnUse(this, 'background', this.getColor, 0.5);
  2754. // attach method for unit tests
  2755. ($element.controller('mdInkRipple') || {}).createRipple = angular.bind(this, this.createRipple);
  2756. this.bindEvents();
  2757. }
  2758. InkRippleCtrl.$inject = ["$scope", "$element", "rippleOptions", "$window", "$timeout", "$mdUtil"];
  2759. /**
  2760. * Returns the color that the ripple should be (either based on CSS or hard-coded)
  2761. * @returns {string}
  2762. */
  2763. InkRippleCtrl.prototype.getColor = function (multiplier) {
  2764. multiplier = multiplier || 1;
  2765. return parseColor(this.$element.attr('md-ink-ripple'))
  2766. || parseColor(getElementColor.call(this));
  2767. /**
  2768. * Finds the color element and returns its text color for use as default ripple color
  2769. * @returns {string}
  2770. */
  2771. function getElementColor () {
  2772. var colorElement = this.options.colorElement && this.options.colorElement[ 0 ];
  2773. colorElement = colorElement || this.$element[ 0 ];
  2774. return colorElement ? this.$window.getComputedStyle(colorElement).color : 'rgb(0,0,0)';
  2775. }
  2776. /**
  2777. * Takes a string color and converts it to RGBA format
  2778. * @param color {string}
  2779. * @returns {string}
  2780. */
  2781. function parseColor (color) {
  2782. if (!color) return;
  2783. if (color.indexOf('rgba') === 0) return color.replace(/\d?\.?\d*\s*\)\s*$/, (0.1 * multiplier).toString() + ')');
  2784. if (color.indexOf('rgb') === 0) return rgbToRGBA(color);
  2785. if (color.indexOf('#') === 0) return hexToRGBA(color);
  2786. /**
  2787. * Converts hex value to RGBA string
  2788. * @param color {string}
  2789. * @returns {string}
  2790. */
  2791. function hexToRGBA (color) {
  2792. var hex = color[ 0 ] === '#' ? color.substr(1) : color,
  2793. dig = hex.length / 3,
  2794. red = hex.substr(0, dig),
  2795. green = hex.substr(dig, dig),
  2796. blue = hex.substr(dig * 2);
  2797. if (dig === 1) {
  2798. red += red;
  2799. green += green;
  2800. blue += blue;
  2801. }
  2802. return 'rgba(' + parseInt(red, 16) + ',' + parseInt(green, 16) + ',' + parseInt(blue, 16) + ',0.1)';
  2803. }
  2804. /**
  2805. * Converts an RGB color to RGBA
  2806. * @param color {string}
  2807. * @returns {string}
  2808. */
  2809. function rgbToRGBA (color) {
  2810. return color.replace(')', ', 0.1)').replace('(', 'a(');
  2811. }
  2812. }
  2813. };
  2814. /**
  2815. * Binds events to the root element for
  2816. */
  2817. InkRippleCtrl.prototype.bindEvents = function () {
  2818. this.$element.on('mousedown', angular.bind(this, this.handleMousedown));
  2819. this.$element.on('mouseup', angular.bind(this, this.handleMouseup));
  2820. this.$element.on('mouseleave', angular.bind(this, this.handleMouseup));
  2821. };
  2822. /**
  2823. * Create a new ripple on every mousedown event from the root element
  2824. * @param event {MouseEvent}
  2825. */
  2826. InkRippleCtrl.prototype.handleMousedown = function (event) {
  2827. this.mousedown = true;
  2828. if (this.options.center) {
  2829. this.createRipple(this.container.prop('clientWidth') / 2, this.container.prop('clientWidth') / 2);
  2830. } else {
  2831. this.createRipple(event.layerX, event.layerY);
  2832. }
  2833. };
  2834. /**
  2835. * Either remove or unlock any remaining ripples when the user mouses off of the element (either by
  2836. * mouseup or mouseleave event)
  2837. */
  2838. InkRippleCtrl.prototype.handleMouseup = function () {
  2839. var ctrl = this;
  2840. this.mousedown = false;
  2841. this.$mdUtil.nextTick(function () { ctrl.clearRipples(); }, false);
  2842. };
  2843. /**
  2844. * Cycles through all ripples and attempts to remove them.
  2845. * Depending on logic within `fadeInComplete`, some removals will be postponed.
  2846. */
  2847. InkRippleCtrl.prototype.clearRipples = function () {
  2848. for (var i = 0; i < this.ripples.length; i++) this.fadeInComplete(this.ripples[ i ]);
  2849. };
  2850. /**
  2851. * Creates the ripple container element
  2852. * @returns {*}
  2853. */
  2854. InkRippleCtrl.prototype.createContainer = function () {
  2855. var container = angular.element('<div class="md-ripple-container"></div>');
  2856. this.$element.append(container);
  2857. return container;
  2858. };
  2859. InkRippleCtrl.prototype.clearTimeout = function () {
  2860. if (this.timeout) {
  2861. this.$timeout.cancel(this.timeout);
  2862. this.timeout = null;
  2863. }
  2864. };
  2865. /**
  2866. * Creates a new ripple and adds it to the container. Also tracks ripple in `this.ripples`.
  2867. * @param left
  2868. * @param top
  2869. */
  2870. InkRippleCtrl.prototype.createRipple = function (left, top) {
  2871. var ctrl = this;
  2872. var ripple = angular.element('<div class="md-ripple"></div>');
  2873. var width = this.$element.prop('clientWidth');
  2874. var height = this.$element.prop('clientHeight');
  2875. var x = Math.max(Math.abs(width - left), left) * 2;
  2876. var y = Math.max(Math.abs(height - top), top) * 2;
  2877. var size = getSize(this.options.fitRipple, x, y);
  2878. ripple.css({
  2879. left: left + 'px',
  2880. top: top + 'px',
  2881. background: 'black',
  2882. width: size + 'px',
  2883. height: size + 'px',
  2884. backgroundColor: rgbaToRGB(this.color),
  2885. borderColor: rgbaToRGB(this.color)
  2886. });
  2887. this.lastRipple = ripple;
  2888. // we only want one timeout to be running at a time
  2889. this.clearTimeout();
  2890. this.timeout = this.$timeout(function () {
  2891. ctrl.clearTimeout();
  2892. if (!ctrl.mousedown) ctrl.fadeInComplete(ripple);
  2893. }, DURATION * 0.35, false);
  2894. if (this.options.dimBackground) this.container.css({ backgroundColor: this.background });
  2895. this.container.append(ripple);
  2896. this.ripples.push(ripple);
  2897. ripple.addClass('md-ripple-placed');
  2898. this.$mdUtil.nextTick(function () {
  2899. ripple.addClass('md-ripple-scaled md-ripple-active');
  2900. ctrl.$timeout(function () { ctrl.clearRipples(); }, DURATION, false);
  2901. }, false);
  2902. function rgbaToRGB (color) {
  2903. return color
  2904. ? color.replace('rgba', 'rgb').replace(/,[^\),]+\)/, ')')
  2905. : 'rgb(0,0,0)';
  2906. }
  2907. function getSize (fit, x, y) {
  2908. return fit
  2909. ? Math.max(x, y)
  2910. : Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
  2911. }
  2912. };
  2913. /**
  2914. * Either kicks off the fade-out animation or queues the element for removal on mouseup
  2915. * @param ripple
  2916. */
  2917. InkRippleCtrl.prototype.fadeInComplete = function (ripple) {
  2918. if (this.lastRipple === ripple) {
  2919. if (!this.timeout && !this.mousedown) this.removeRipple(ripple);
  2920. } else {
  2921. this.removeRipple(ripple);
  2922. }
  2923. };
  2924. /**
  2925. * Kicks off the animation for removing a ripple
  2926. * @param ripple {Element}
  2927. */
  2928. InkRippleCtrl.prototype.removeRipple = function (ripple) {
  2929. var ctrl = this;
  2930. var index = this.ripples.indexOf(ripple);
  2931. if (index < 0) return;
  2932. this.ripples.splice(this.ripples.indexOf(ripple), 1);
  2933. ripple.removeClass('md-ripple-active');
  2934. if (this.ripples.length === 0) this.container.css({ backgroundColor: '' });
  2935. // use a 2-second timeout in order to allow for the animation to finish
  2936. // we don't actually care how long the animation takes
  2937. this.$timeout(function () { ctrl.fadeOutComplete(ripple); }, DURATION, false);
  2938. };
  2939. /**
  2940. * Removes the provided ripple from the DOM
  2941. * @param ripple
  2942. */
  2943. InkRippleCtrl.prototype.fadeOutComplete = function (ripple) { ripple.remove(); };
  2944. /**
  2945. * Used to create an empty directive. This is used to track flag-directives whose children may have
  2946. * functionality based on them.
  2947. *
  2948. * Example: `md-no-ink` will potentially be used by all child directives.
  2949. */
  2950. function attrNoDirective () {
  2951. return { controller: angular.noop };
  2952. }
  2953. })();
  2954. (function(){
  2955. "use strict";
  2956. (function() {
  2957. 'use strict';
  2958. /**
  2959. * @ngdoc service
  2960. * @name $mdTabInkRipple
  2961. * @module material.core
  2962. *
  2963. * @description
  2964. * Provides ripple effects for md-tabs. See $mdInkRipple service for all possible configuration options.
  2965. *
  2966. * @param {object=} scope Scope within the current context
  2967. * @param {object=} element The element the ripple effect should be applied to
  2968. * @param {object=} options (Optional) Configuration options to override the defaultripple configuration
  2969. */
  2970. angular.module('material.core')
  2971. .factory('$mdTabInkRipple', MdTabInkRipple);
  2972. function MdTabInkRipple($mdInkRipple) {
  2973. return {
  2974. attach: attach
  2975. };
  2976. function attach(scope, element, options) {
  2977. return $mdInkRipple.attach(scope, element, angular.extend({
  2978. center: false,
  2979. dimBackground: true,
  2980. outline: false,
  2981. rippleSize: 'full'
  2982. }, options));
  2983. };
  2984. }
  2985. MdTabInkRipple.$inject = ["$mdInkRipple"];;
  2986. })();
  2987. })();
  2988. (function(){
  2989. "use strict";
  2990. angular.module('material.core.theming.palette', [])
  2991. .constant('$mdColorPalette', {
  2992. 'red': {
  2993. '50': '#ffebee',
  2994. '100': '#ffcdd2',
  2995. '200': '#ef9a9a',
  2996. '300': '#e57373',
  2997. '400': '#ef5350',
  2998. '500': '#f44336',
  2999. '600': '#e53935',
  3000. '700': '#d32f2f',
  3001. '800': '#c62828',
  3002. '900': '#b71c1c',
  3003. 'A100': '#ff8a80',
  3004. 'A200': '#ff5252',
  3005. 'A400': '#ff1744',
  3006. 'A700': '#d50000',
  3007. 'contrastDefaultColor': 'light',
  3008. 'contrastDarkColors': '50 100 200 300 A100',
  3009. 'contrastStrongLightColors': '400 500 600 700 A200 A400 A700'
  3010. },
  3011. 'pink': {
  3012. '50': '#fce4ec',
  3013. '100': '#f8bbd0',
  3014. '200': '#f48fb1',
  3015. '300': '#f06292',
  3016. '400': '#ec407a',
  3017. '500': '#e91e63',
  3018. '600': '#d81b60',
  3019. '700': '#c2185b',
  3020. '800': '#ad1457',
  3021. '900': '#880e4f',
  3022. 'A100': '#ff80ab',
  3023. 'A200': '#ff4081',
  3024. 'A400': '#f50057',
  3025. 'A700': '#c51162',
  3026. 'contrastDefaultColor': 'light',
  3027. 'contrastDarkColors': '50 100 200 A100',
  3028. 'contrastStrongLightColors': '500 600 A200 A400 A700'
  3029. },
  3030. 'purple': {
  3031. '50': '#f3e5f5',
  3032. '100': '#e1bee7',
  3033. '200': '#ce93d8',
  3034. '300': '#ba68c8',
  3035. '400': '#ab47bc',
  3036. '500': '#9c27b0',
  3037. '600': '#8e24aa',
  3038. '700': '#7b1fa2',
  3039. '800': '#6a1b9a',
  3040. '900': '#4a148c',
  3041. 'A100': '#ea80fc',
  3042. 'A200': '#e040fb',
  3043. 'A400': '#d500f9',
  3044. 'A700': '#aa00ff',
  3045. 'contrastDefaultColor': 'light',
  3046. 'contrastDarkColors': '50 100 200 A100',
  3047. 'contrastStrongLightColors': '300 400 A200 A400 A700'
  3048. },
  3049. 'deep-purple': {
  3050. '50': '#ede7f6',
  3051. '100': '#d1c4e9',
  3052. '200': '#b39ddb',
  3053. '300': '#9575cd',
  3054. '400': '#7e57c2',
  3055. '500': '#673ab7',
  3056. '600': '#5e35b1',
  3057. '700': '#512da8',
  3058. '800': '#4527a0',
  3059. '900': '#311b92',
  3060. 'A100': '#b388ff',
  3061. 'A200': '#7c4dff',
  3062. 'A400': '#651fff',
  3063. 'A700': '#6200ea',
  3064. 'contrastDefaultColor': 'light',
  3065. 'contrastDarkColors': '50 100 200 A100',
  3066. 'contrastStrongLightColors': '300 400 A200'
  3067. },
  3068. 'indigo': {
  3069. '50': '#e8eaf6',
  3070. '100': '#c5cae9',
  3071. '200': '#9fa8da',
  3072. '300': '#7986cb',
  3073. '400': '#5c6bc0',
  3074. '500': '#3f51b5',
  3075. '600': '#3949ab',
  3076. '700': '#303f9f',
  3077. '800': '#283593',
  3078. '900': '#1a237e',
  3079. 'A100': '#8c9eff',
  3080. 'A200': '#536dfe',
  3081. 'A400': '#3d5afe',
  3082. 'A700': '#304ffe',
  3083. 'contrastDefaultColor': 'light',
  3084. 'contrastDarkColors': '50 100 200 A100',
  3085. 'contrastStrongLightColors': '300 400 A200 A400'
  3086. },
  3087. 'blue': {
  3088. '50': '#e3f2fd',
  3089. '100': '#bbdefb',
  3090. '200': '#90caf9',
  3091. '300': '#64b5f6',
  3092. '400': '#42a5f5',
  3093. '500': '#2196f3',
  3094. '600': '#1e88e5',
  3095. '700': '#1976d2',
  3096. '800': '#1565c0',
  3097. '900': '#0d47a1',
  3098. 'A100': '#82b1ff',
  3099. 'A200': '#448aff',
  3100. 'A400': '#2979ff',
  3101. 'A700': '#2962ff',
  3102. 'contrastDefaultColor': 'light',
  3103. 'contrastDarkColors': '50 100 200 300 400 A100',
  3104. 'contrastStrongLightColors': '500 600 700 A200 A400 A700'
  3105. },
  3106. 'light-blue': {
  3107. '50': '#e1f5fe',
  3108. '100': '#b3e5fc',
  3109. '200': '#81d4fa',
  3110. '300': '#4fc3f7',
  3111. '400': '#29b6f6',
  3112. '500': '#03a9f4',
  3113. '600': '#039be5',
  3114. '700': '#0288d1',
  3115. '800': '#0277bd',
  3116. '900': '#01579b',
  3117. 'A100': '#80d8ff',
  3118. 'A200': '#40c4ff',
  3119. 'A400': '#00b0ff',
  3120. 'A700': '#0091ea',
  3121. 'contrastDefaultColor': 'dark',
  3122. 'contrastLightColors': '600 700 800 900 A700',
  3123. 'contrastStrongLightColors': '600 700 800 A700'
  3124. },
  3125. 'cyan': {
  3126. '50': '#e0f7fa',
  3127. '100': '#b2ebf2',
  3128. '200': '#80deea',
  3129. '300': '#4dd0e1',
  3130. '400': '#26c6da',
  3131. '500': '#00bcd4',
  3132. '600': '#00acc1',
  3133. '700': '#0097a7',
  3134. '800': '#00838f',
  3135. '900': '#006064',
  3136. 'A100': '#84ffff',
  3137. 'A200': '#18ffff',
  3138. 'A400': '#00e5ff',
  3139. 'A700': '#00b8d4',
  3140. 'contrastDefaultColor': 'dark',
  3141. 'contrastLightColors': '700 800 900',
  3142. 'contrastStrongLightColors': '700 800 900'
  3143. },
  3144. 'teal': {
  3145. '50': '#e0f2f1',
  3146. '100': '#b2dfdb',
  3147. '200': '#80cbc4',
  3148. '300': '#4db6ac',
  3149. '400': '#26a69a',
  3150. '500': '#009688',
  3151. '600': '#00897b',
  3152. '700': '#00796b',
  3153. '800': '#00695c',
  3154. '900': '#004d40',
  3155. 'A100': '#a7ffeb',
  3156. 'A200': '#64ffda',
  3157. 'A400': '#1de9b6',
  3158. 'A700': '#00bfa5',
  3159. 'contrastDefaultColor': 'dark',
  3160. 'contrastLightColors': '500 600 700 800 900',
  3161. 'contrastStrongLightColors': '500 600 700'
  3162. },
  3163. 'green': {
  3164. '50': '#e8f5e9',
  3165. '100': '#c8e6c9',
  3166. '200': '#a5d6a7',
  3167. '300': '#81c784',
  3168. '400': '#66bb6a',
  3169. '500': '#4caf50',
  3170. '600': '#43a047',
  3171. '700': '#388e3c',
  3172. '800': '#2e7d32',
  3173. '900': '#1b5e20',
  3174. 'A100': '#b9f6ca',
  3175. 'A200': '#69f0ae',
  3176. 'A400': '#00e676',
  3177. 'A700': '#00c853',
  3178. 'contrastDefaultColor': 'dark',
  3179. 'contrastLightColors': '600 700 800 900',
  3180. 'contrastStrongLightColors': '600 700'
  3181. },
  3182. 'light-green': {
  3183. '50': '#f1f8e9',
  3184. '100': '#dcedc8',
  3185. '200': '#c5e1a5',
  3186. '300': '#aed581',
  3187. '400': '#9ccc65',
  3188. '500': '#8bc34a',
  3189. '600': '#7cb342',
  3190. '700': '#689f38',
  3191. '800': '#558b2f',
  3192. '900': '#33691e',
  3193. 'A100': '#ccff90',
  3194. 'A200': '#b2ff59',
  3195. 'A400': '#76ff03',
  3196. 'A700': '#64dd17',
  3197. 'contrastDefaultColor': 'dark',
  3198. 'contrastLightColors': '700 800 900',
  3199. 'contrastStrongLightColors': '700 800 900'
  3200. },
  3201. 'lime': {
  3202. '50': '#f9fbe7',
  3203. '100': '#f0f4c3',
  3204. '200': '#e6ee9c',
  3205. '300': '#dce775',
  3206. '400': '#d4e157',
  3207. '500': '#cddc39',
  3208. '600': '#c0ca33',
  3209. '700': '#afb42b',
  3210. '800': '#9e9d24',
  3211. '900': '#827717',
  3212. 'A100': '#f4ff81',
  3213. 'A200': '#eeff41',
  3214. 'A400': '#c6ff00',
  3215. 'A700': '#aeea00',
  3216. 'contrastDefaultColor': 'dark',
  3217. 'contrastLightColors': '900',
  3218. 'contrastStrongLightColors': '900'
  3219. },
  3220. 'yellow': {
  3221. '50': '#fffde7',
  3222. '100': '#fff9c4',
  3223. '200': '#fff59d',
  3224. '300': '#fff176',
  3225. '400': '#ffee58',
  3226. '500': '#ffeb3b',
  3227. '600': '#fdd835',
  3228. '700': '#fbc02d',
  3229. '800': '#f9a825',
  3230. '900': '#f57f17',
  3231. 'A100': '#ffff8d',
  3232. 'A200': '#ffff00',
  3233. 'A400': '#ffea00',
  3234. 'A700': '#ffd600',
  3235. 'contrastDefaultColor': 'dark'
  3236. },
  3237. 'amber': {
  3238. '50': '#fff8e1',
  3239. '100': '#ffecb3',
  3240. '200': '#ffe082',
  3241. '300': '#ffd54f',
  3242. '400': '#ffca28',
  3243. '500': '#ffc107',
  3244. '600': '#ffb300',
  3245. '700': '#ffa000',
  3246. '800': '#ff8f00',
  3247. '900': '#ff6f00',
  3248. 'A100': '#ffe57f',
  3249. 'A200': '#ffd740',
  3250. 'A400': '#ffc400',
  3251. 'A700': '#ffab00',
  3252. 'contrastDefaultColor': 'dark'
  3253. },
  3254. 'orange': {
  3255. '50': '#fff3e0',
  3256. '100': '#ffe0b2',
  3257. '200': '#ffcc80',
  3258. '300': '#ffb74d',
  3259. '400': '#ffa726',
  3260. '500': '#ff9800',
  3261. '600': '#fb8c00',
  3262. '700': '#f57c00',
  3263. '800': '#ef6c00',
  3264. '900': '#e65100',
  3265. 'A100': '#ffd180',
  3266. 'A200': '#ffab40',
  3267. 'A400': '#ff9100',
  3268. 'A700': '#ff6d00',
  3269. 'contrastDefaultColor': 'dark',
  3270. 'contrastLightColors': '800 900',
  3271. 'contrastStrongLightColors': '800 900'
  3272. },
  3273. 'deep-orange': {
  3274. '50': '#fbe9e7',
  3275. '100': '#ffccbc',
  3276. '200': '#ffab91',
  3277. '300': '#ff8a65',
  3278. '400': '#ff7043',
  3279. '500': '#ff5722',
  3280. '600': '#f4511e',
  3281. '700': '#e64a19',
  3282. '800': '#d84315',
  3283. '900': '#bf360c',
  3284. 'A100': '#ff9e80',
  3285. 'A200': '#ff6e40',
  3286. 'A400': '#ff3d00',
  3287. 'A700': '#dd2c00',
  3288. 'contrastDefaultColor': 'light',
  3289. 'contrastDarkColors': '50 100 200 300 400 A100 A200',
  3290. 'contrastStrongLightColors': '500 600 700 800 900 A400 A700'
  3291. },
  3292. 'brown': {
  3293. '50': '#efebe9',
  3294. '100': '#d7ccc8',
  3295. '200': '#bcaaa4',
  3296. '300': '#a1887f',
  3297. '400': '#8d6e63',
  3298. '500': '#795548',
  3299. '600': '#6d4c41',
  3300. '700': '#5d4037',
  3301. '800': '#4e342e',
  3302. '900': '#3e2723',
  3303. 'A100': '#d7ccc8',
  3304. 'A200': '#bcaaa4',
  3305. 'A400': '#8d6e63',
  3306. 'A700': '#5d4037',
  3307. 'contrastDefaultColor': 'light',
  3308. 'contrastDarkColors': '50 100 200',
  3309. 'contrastStrongLightColors': '300 400'
  3310. },
  3311. 'grey': {
  3312. '50': '#fafafa',
  3313. '100': '#f5f5f5',
  3314. '200': '#eeeeee',
  3315. '300': '#e0e0e0',
  3316. '400': '#bdbdbd',
  3317. '500': '#9e9e9e',
  3318. '600': '#757575',
  3319. '700': '#616161',
  3320. '800': '#424242',
  3321. '900': '#212121',
  3322. '1000': '#000000',
  3323. 'A100': '#ffffff',
  3324. 'A200': '#eeeeee',
  3325. 'A400': '#bdbdbd',
  3326. 'A700': '#616161',
  3327. 'contrastDefaultColor': 'dark',
  3328. 'contrastLightColors': '600 700 800 900'
  3329. },
  3330. 'blue-grey': {
  3331. '50': '#eceff1',
  3332. '100': '#cfd8dc',
  3333. '200': '#b0bec5',
  3334. '300': '#90a4ae',
  3335. '400': '#78909c',
  3336. '500': '#607d8b',
  3337. '600': '#546e7a',
  3338. '700': '#455a64',
  3339. '800': '#37474f',
  3340. '900': '#263238',
  3341. 'A100': '#cfd8dc',
  3342. 'A200': '#b0bec5',
  3343. 'A400': '#78909c',
  3344. 'A700': '#455a64',
  3345. 'contrastDefaultColor': 'light',
  3346. 'contrastDarkColors': '50 100 200 300',
  3347. 'contrastStrongLightColors': '400 500'
  3348. }
  3349. });
  3350. })();
  3351. (function(){
  3352. "use strict";
  3353. angular.module('material.core.theming', ['material.core.theming.palette'])
  3354. .directive('mdTheme', ThemingDirective)
  3355. .directive('mdThemable', ThemableDirective)
  3356. .provider('$mdTheming', ThemingProvider)
  3357. .run(generateThemes);
  3358. /**
  3359. * @ngdoc service
  3360. * @name $mdThemingProvider
  3361. * @module material.core.theming
  3362. *
  3363. * @description Provider to configure the `$mdTheming` service.
  3364. */
  3365. /**
  3366. * @ngdoc method
  3367. * @name $mdThemingProvider#setDefaultTheme
  3368. * @param {string} themeName Default theme name to be applied to elements. Default value is `default`.
  3369. */
  3370. /**
  3371. * @ngdoc method
  3372. * @name $mdThemingProvider#alwaysWatchTheme
  3373. * @param {boolean} watch Whether or not to always watch themes for changes and re-apply
  3374. * classes when they change. Default is `false`. Enabling can reduce performance.
  3375. */
  3376. /* Some Example Valid Theming Expressions
  3377. * =======================================
  3378. *
  3379. * Intention group expansion: (valid for primary, accent, warn, background)
  3380. *
  3381. * {{primary-100}} - grab shade 100 from the primary palette
  3382. * {{primary-100-0.7}} - grab shade 100, apply opacity of 0.7
  3383. * {{primary-100-contrast}} - grab shade 100's contrast color
  3384. * {{primary-hue-1}} - grab the shade assigned to hue-1 from the primary palette
  3385. * {{primary-hue-1-0.7}} - apply 0.7 opacity to primary-hue-1
  3386. * {{primary-color}} - Generates .md-hue-1, .md-hue-2, .md-hue-3 with configured shades set for each hue
  3387. * {{primary-color-0.7}} - Apply 0.7 opacity to each of the above rules
  3388. * {{primary-contrast}} - Generates .md-hue-1, .md-hue-2, .md-hue-3 with configured contrast (ie. text) color shades set for each hue
  3389. * {{primary-contrast-0.7}} - Apply 0.7 opacity to each of the above rules
  3390. *
  3391. * Foreground expansion: Applies rgba to black/white foreground text
  3392. *
  3393. * {{foreground-1}} - used for primary text
  3394. * {{foreground-2}} - used for secondary text/divider
  3395. * {{foreground-3}} - used for disabled text
  3396. * {{foreground-4}} - used for dividers
  3397. *
  3398. */
  3399. // In memory generated CSS rules; registered by theme.name
  3400. var GENERATED = { };
  3401. // In memory storage of defined themes and color palettes (both loaded by CSS, and user specified)
  3402. var PALETTES;
  3403. var THEMES;
  3404. var DARK_FOREGROUND = {
  3405. name: 'dark',
  3406. '1': 'rgba(0,0,0,0.87)',
  3407. '2': 'rgba(0,0,0,0.54)',
  3408. '3': 'rgba(0,0,0,0.26)',
  3409. '4': 'rgba(0,0,0,0.12)'
  3410. };
  3411. var LIGHT_FOREGROUND = {
  3412. name: 'light',
  3413. '1': 'rgba(255,255,255,1.0)',
  3414. '2': 'rgba(255,255,255,0.7)',
  3415. '3': 'rgba(255,255,255,0.3)',
  3416. '4': 'rgba(255,255,255,0.12)'
  3417. };
  3418. var DARK_SHADOW = '1px 1px 0px rgba(0,0,0,0.4), -1px -1px 0px rgba(0,0,0,0.4)';
  3419. var LIGHT_SHADOW = '';
  3420. var DARK_CONTRAST_COLOR = colorToRgbaArray('rgba(0,0,0,0.87)');
  3421. var LIGHT_CONTRAST_COLOR = colorToRgbaArray('rgba(255,255,255,0.87');
  3422. var STRONG_LIGHT_CONTRAST_COLOR = colorToRgbaArray('rgb(255,255,255)');
  3423. var THEME_COLOR_TYPES = ['primary', 'accent', 'warn', 'background'];
  3424. var DEFAULT_COLOR_TYPE = 'primary';
  3425. // A color in a theme will use these hues by default, if not specified by user.
  3426. var LIGHT_DEFAULT_HUES = {
  3427. 'accent': {
  3428. 'default': 'A200',
  3429. 'hue-1': 'A100',
  3430. 'hue-2': 'A400',
  3431. 'hue-3': 'A700'
  3432. },
  3433. 'background': {
  3434. 'default': 'A100',
  3435. 'hue-1': '300',
  3436. 'hue-2': '800',
  3437. 'hue-3': '900'
  3438. }
  3439. };
  3440. var DARK_DEFAULT_HUES = {
  3441. 'background': {
  3442. 'default': '800',
  3443. 'hue-1': '300',
  3444. 'hue-2': '600',
  3445. 'hue-3': '900'
  3446. }
  3447. };
  3448. THEME_COLOR_TYPES.forEach(function(colorType) {
  3449. // Color types with unspecified default hues will use these default hue values
  3450. var defaultDefaultHues = {
  3451. 'default': '500',
  3452. 'hue-1': '300',
  3453. 'hue-2': '800',
  3454. 'hue-3': 'A100'
  3455. };
  3456. if (!LIGHT_DEFAULT_HUES[colorType]) LIGHT_DEFAULT_HUES[colorType] = defaultDefaultHues;
  3457. if (!DARK_DEFAULT_HUES[colorType]) DARK_DEFAULT_HUES[colorType] = defaultDefaultHues;
  3458. });
  3459. var VALID_HUE_VALUES = [
  3460. '50', '100', '200', '300', '400', '500', '600',
  3461. '700', '800', '900', 'A100', 'A200', 'A400', 'A700'
  3462. ];
  3463. function ThemingProvider($mdColorPalette) {
  3464. PALETTES = { };
  3465. THEMES = { };
  3466. var themingProvider;
  3467. var defaultTheme = 'default';
  3468. var alwaysWatchTheme = false;
  3469. // Load JS Defined Palettes
  3470. angular.extend(PALETTES, $mdColorPalette);
  3471. // Default theme defined in core.js
  3472. ThemingService.$inject = ["$rootScope", "$log"];
  3473. return themingProvider = {
  3474. definePalette: definePalette,
  3475. extendPalette: extendPalette,
  3476. theme: registerTheme,
  3477. setDefaultTheme: function(theme) {
  3478. defaultTheme = theme;
  3479. },
  3480. alwaysWatchTheme: function(alwaysWatch) {
  3481. alwaysWatchTheme = alwaysWatch;
  3482. },
  3483. $get: ThemingService,
  3484. _LIGHT_DEFAULT_HUES: LIGHT_DEFAULT_HUES,
  3485. _DARK_DEFAULT_HUES: DARK_DEFAULT_HUES,
  3486. _PALETTES: PALETTES,
  3487. _THEMES: THEMES,
  3488. _parseRules: parseRules,
  3489. _rgba: rgba
  3490. };
  3491. // Example: $mdThemingProvider.definePalette('neonRed', { 50: '#f5fafa', ... });
  3492. function definePalette(name, map) {
  3493. map = map || {};
  3494. PALETTES[name] = checkPaletteValid(name, map);
  3495. return themingProvider;
  3496. }
  3497. // Returns an new object which is a copy of a given palette `name` with variables from
  3498. // `map` overwritten
  3499. // Example: var neonRedMap = $mdThemingProvider.extendPalette('red', { 50: '#f5fafafa' });
  3500. function extendPalette(name, map) {
  3501. return checkPaletteValid(name, angular.extend({}, PALETTES[name] || {}, map) );
  3502. }
  3503. // Make sure that palette has all required hues
  3504. function checkPaletteValid(name, map) {
  3505. var missingColors = VALID_HUE_VALUES.filter(function(field) {
  3506. return !map[field];
  3507. });
  3508. if (missingColors.length) {
  3509. throw new Error("Missing colors %1 in palette %2!"
  3510. .replace('%1', missingColors.join(', '))
  3511. .replace('%2', name));
  3512. }
  3513. return map;
  3514. }
  3515. // Register a theme (which is a collection of color palettes to use with various states
  3516. // ie. warn, accent, primary )
  3517. // Optionally inherit from an existing theme
  3518. // $mdThemingProvider.theme('custom-theme').primaryPalette('red');
  3519. function registerTheme(name, inheritFrom) {
  3520. if (THEMES[name]) return THEMES[name];
  3521. inheritFrom = inheritFrom || 'default';
  3522. var parentTheme = typeof inheritFrom === 'string' ? THEMES[inheritFrom] : inheritFrom;
  3523. var theme = new Theme(name);
  3524. if (parentTheme) {
  3525. angular.forEach(parentTheme.colors, function(color, colorType) {
  3526. theme.colors[colorType] = {
  3527. name: color.name,
  3528. // Make sure a COPY of the hues is given to the child color,
  3529. // not the same reference.
  3530. hues: angular.extend({}, color.hues)
  3531. };
  3532. });
  3533. }
  3534. THEMES[name] = theme;
  3535. return theme;
  3536. }
  3537. function Theme(name) {
  3538. var self = this;
  3539. self.name = name;
  3540. self.colors = {};
  3541. self.dark = setDark;
  3542. setDark(false);
  3543. function setDark(isDark) {
  3544. isDark = arguments.length === 0 ? true : !!isDark;
  3545. // If no change, abort
  3546. if (isDark === self.isDark) return;
  3547. self.isDark = isDark;
  3548. self.foregroundPalette = self.isDark ? LIGHT_FOREGROUND : DARK_FOREGROUND;
  3549. self.foregroundShadow = self.isDark ? DARK_SHADOW : LIGHT_SHADOW;
  3550. // Light and dark themes have different default hues.
  3551. // Go through each existing color type for this theme, and for every
  3552. // hue value that is still the default hue value from the previous light/dark setting,
  3553. // set it to the default hue value from the new light/dark setting.
  3554. var newDefaultHues = self.isDark ? DARK_DEFAULT_HUES : LIGHT_DEFAULT_HUES;
  3555. var oldDefaultHues = self.isDark ? LIGHT_DEFAULT_HUES : DARK_DEFAULT_HUES;
  3556. angular.forEach(newDefaultHues, function(newDefaults, colorType) {
  3557. var color = self.colors[colorType];
  3558. var oldDefaults = oldDefaultHues[colorType];
  3559. if (color) {
  3560. for (var hueName in color.hues) {
  3561. if (color.hues[hueName] === oldDefaults[hueName]) {
  3562. color.hues[hueName] = newDefaults[hueName];
  3563. }
  3564. }
  3565. }
  3566. });
  3567. return self;
  3568. }
  3569. THEME_COLOR_TYPES.forEach(function(colorType) {
  3570. var defaultHues = (self.isDark ? DARK_DEFAULT_HUES : LIGHT_DEFAULT_HUES)[colorType];
  3571. self[colorType + 'Palette'] = function setPaletteType(paletteName, hues) {
  3572. var color = self.colors[colorType] = {
  3573. name: paletteName,
  3574. hues: angular.extend({}, defaultHues, hues)
  3575. };
  3576. Object.keys(color.hues).forEach(function(name) {
  3577. if (!defaultHues[name]) {
  3578. throw new Error("Invalid hue name '%1' in theme %2's %3 color %4. Available hue names: %4"
  3579. .replace('%1', name)
  3580. .replace('%2', self.name)
  3581. .replace('%3', paletteName)
  3582. .replace('%4', Object.keys(defaultHues).join(', '))
  3583. );
  3584. }
  3585. });
  3586. Object.keys(color.hues).map(function(key) {
  3587. return color.hues[key];
  3588. }).forEach(function(hueValue) {
  3589. if (VALID_HUE_VALUES.indexOf(hueValue) == -1) {
  3590. throw new Error("Invalid hue value '%1' in theme %2's %3 color %4. Available hue values: %5"
  3591. .replace('%1', hueValue)
  3592. .replace('%2', self.name)
  3593. .replace('%3', colorType)
  3594. .replace('%4', paletteName)
  3595. .replace('%5', VALID_HUE_VALUES.join(', '))
  3596. );
  3597. }
  3598. });
  3599. return self;
  3600. };
  3601. self[colorType + 'Color'] = function() {
  3602. var args = Array.prototype.slice.call(arguments);
  3603. console.warn('$mdThemingProviderTheme.' + colorType + 'Color() has been deprecated. ' +
  3604. 'Use $mdThemingProviderTheme.' + colorType + 'Palette() instead.');
  3605. return self[colorType + 'Palette'].apply(self, args);
  3606. };
  3607. });
  3608. }
  3609. /**
  3610. * @ngdoc service
  3611. * @name $mdTheming
  3612. *
  3613. * @description
  3614. *
  3615. * Service that makes an element apply theming related classes to itself.
  3616. *
  3617. * ```js
  3618. * app.directive('myFancyDirective', function($mdTheming) {
  3619. * return {
  3620. * restrict: 'e',
  3621. * link: function(scope, el, attrs) {
  3622. * $mdTheming(el);
  3623. * }
  3624. * };
  3625. * });
  3626. * ```
  3627. * @param {el=} element to apply theming to
  3628. */
  3629. /* @ngInject */
  3630. function ThemingService($rootScope, $log) {
  3631. applyTheme.inherit = function(el, parent) {
  3632. var ctrl = parent.controller('mdTheme');
  3633. var attrThemeValue = el.attr('md-theme-watch');
  3634. if ( (alwaysWatchTheme || angular.isDefined(attrThemeValue)) && attrThemeValue != 'false') {
  3635. var deregisterWatch = $rootScope.$watch(function() {
  3636. return ctrl && ctrl.$mdTheme || defaultTheme;
  3637. }, changeTheme);
  3638. el.on('$destroy', deregisterWatch);
  3639. } else {
  3640. var theme = ctrl && ctrl.$mdTheme || defaultTheme;
  3641. changeTheme(theme);
  3642. }
  3643. function changeTheme(theme) {
  3644. if (!registered(theme)) {
  3645. $log.warn('Attempted to use unregistered theme \'' + theme + '\'. ' +
  3646. 'Register it with $mdThemingProvider.theme().');
  3647. }
  3648. var oldTheme = el.data('$mdThemeName');
  3649. if (oldTheme) el.removeClass('md-' + oldTheme +'-theme');
  3650. el.addClass('md-' + theme + '-theme');
  3651. el.data('$mdThemeName', theme);
  3652. if (ctrl) {
  3653. el.data('$mdThemeController', ctrl);
  3654. }
  3655. }
  3656. };
  3657. applyTheme.THEMES = angular.extend({}, THEMES);
  3658. applyTheme.defaultTheme = function() { return defaultTheme; };
  3659. applyTheme.registered = registered;
  3660. return applyTheme;
  3661. function registered(themeName) {
  3662. if (themeName === undefined || themeName === '') return true;
  3663. return applyTheme.THEMES[themeName] !== undefined;
  3664. }
  3665. function applyTheme(scope, el) {
  3666. // Allow us to be invoked via a linking function signature.
  3667. if (el === undefined) {
  3668. el = scope;
  3669. scope = undefined;
  3670. }
  3671. if (scope === undefined) {
  3672. scope = $rootScope;
  3673. }
  3674. applyTheme.inherit(el, el);
  3675. }
  3676. }
  3677. }
  3678. ThemingProvider.$inject = ["$mdColorPalette"];
  3679. function ThemingDirective($mdTheming, $interpolate, $log) {
  3680. return {
  3681. priority: 100,
  3682. link: {
  3683. pre: function(scope, el, attrs) {
  3684. var ctrl = {
  3685. $setTheme: function(theme) {
  3686. if (!$mdTheming.registered(theme)) {
  3687. $log.warn('attempted to use unregistered theme \'' + theme + '\'');
  3688. }
  3689. ctrl.$mdTheme = theme;
  3690. }
  3691. };
  3692. el.data('$mdThemeController', ctrl);
  3693. ctrl.$setTheme($interpolate(attrs.mdTheme)(scope));
  3694. attrs.$observe('mdTheme', ctrl.$setTheme);
  3695. }
  3696. }
  3697. };
  3698. }
  3699. ThemingDirective.$inject = ["$mdTheming", "$interpolate", "$log"];
  3700. function ThemableDirective($mdTheming) {
  3701. return $mdTheming;
  3702. }
  3703. ThemableDirective.$inject = ["$mdTheming"];
  3704. function parseRules(theme, colorType, rules) {
  3705. checkValidPalette(theme, colorType);
  3706. rules = rules.replace(/THEME_NAME/g, theme.name);
  3707. var generatedRules = [];
  3708. var color = theme.colors[colorType];
  3709. var themeNameRegex = new RegExp('.md-' + theme.name + '-theme', 'g');
  3710. // Matches '{{ primary-color }}', etc
  3711. var hueRegex = new RegExp('(\'|")?{{\\s*(' + colorType + ')-(color|contrast)-?(\\d\\.?\\d*)?\\s*}}(\"|\')?','g');
  3712. var simpleVariableRegex = /'?"?\{\{\s*([a-zA-Z]+)-(A?\d+|hue\-[0-3]|shadow)-?(\d\.?\d*)?(contrast)?\s*\}\}'?"?/g;
  3713. var palette = PALETTES[color.name];
  3714. // find and replace simple variables where we use a specific hue, not an entire palette
  3715. // eg. "{{primary-100}}"
  3716. //\(' + THEME_COLOR_TYPES.join('\|') + '\)'
  3717. rules = rules.replace(simpleVariableRegex, function(match, colorType, hue, opacity, contrast) {
  3718. if (colorType === 'foreground') {
  3719. if (hue == 'shadow') {
  3720. return theme.foregroundShadow;
  3721. } else {
  3722. return theme.foregroundPalette[hue] || theme.foregroundPalette['1'];
  3723. }
  3724. }
  3725. if (hue.indexOf('hue') === 0) {
  3726. hue = theme.colors[colorType].hues[hue];
  3727. }
  3728. return rgba( (PALETTES[ theme.colors[colorType].name ][hue] || '')[contrast ? 'contrast' : 'value'], opacity );
  3729. });
  3730. // For each type, generate rules for each hue (ie. default, md-hue-1, md-hue-2, md-hue-3)
  3731. angular.forEach(color.hues, function(hueValue, hueName) {
  3732. var newRule = rules
  3733. .replace(hueRegex, function(match, _, colorType, hueType, opacity) {
  3734. return rgba(palette[hueValue][hueType === 'color' ? 'value' : 'contrast'], opacity);
  3735. });
  3736. if (hueName !== 'default') {
  3737. newRule = newRule.replace(themeNameRegex, '.md-' + theme.name + '-theme.md-' + hueName);
  3738. }
  3739. // Don't apply a selector rule to the default theme, making it easier to override
  3740. // styles of the base-component
  3741. if (theme.name == 'default') {
  3742. newRule = newRule.replace(/\.md-default-theme/g, '');
  3743. }
  3744. generatedRules.push(newRule);
  3745. });
  3746. return generatedRules;
  3747. }
  3748. // Generate our themes at run time given the state of THEMES and PALETTES
  3749. function generateThemes($injector) {
  3750. var head = document.getElementsByTagName('head')[0];
  3751. var firstChild = head ? head.firstElementChild : null;
  3752. var themeCss = $injector.has('$MD_THEME_CSS') ? $injector.get('$MD_THEME_CSS') : '';
  3753. if ( !firstChild ) return;
  3754. if (themeCss.length === 0) return; // no rules, so no point in running this expensive task
  3755. // Expose contrast colors for palettes to ensure that text is always readable
  3756. angular.forEach(PALETTES, sanitizePalette);
  3757. // MD_THEME_CSS is a string generated by the build process that includes all the themable
  3758. // components as templates
  3759. // Break the CSS into individual rules
  3760. var rulesByType = {};
  3761. var rules = themeCss
  3762. .split(/\}(?!(\}|'|"|;))/)
  3763. .filter(function(rule) { return rule && rule.length; })
  3764. .map(function(rule) { return rule.trim() + '}'; });
  3765. var ruleMatchRegex = new RegExp('md-(' + THEME_COLOR_TYPES.join('|') + ')', 'g');
  3766. THEME_COLOR_TYPES.forEach(function(type) {
  3767. rulesByType[type] = '';
  3768. });
  3769. // Sort the rules based on type, allowing us to do color substitution on a per-type basis
  3770. rules.forEach(function(rule) {
  3771. var match = rule.match(ruleMatchRegex);
  3772. // First: test that if the rule has '.md-accent', it goes into the accent set of rules
  3773. for (var i = 0, type; type = THEME_COLOR_TYPES[i]; i++) {
  3774. if (rule.indexOf('.md-' + type) > -1) {
  3775. return rulesByType[type] += rule;
  3776. }
  3777. }
  3778. // If no eg 'md-accent' class is found, try to just find 'accent' in the rule and guess from
  3779. // there
  3780. for (i = 0; type = THEME_COLOR_TYPES[i]; i++) {
  3781. if (rule.indexOf(type) > -1) {
  3782. return rulesByType[type] += rule;
  3783. }
  3784. }
  3785. // Default to the primary array
  3786. return rulesByType[DEFAULT_COLOR_TYPE] += rule;
  3787. });
  3788. // For each theme, use the color palettes specified for
  3789. // `primary`, `warn` and `accent` to generate CSS rules.
  3790. angular.forEach(THEMES, function(theme) {
  3791. if ( !GENERATED[theme.name] ) {
  3792. THEME_COLOR_TYPES.forEach(function(colorType) {
  3793. var styleStrings = parseRules(theme, colorType, rulesByType[colorType]);
  3794. while (styleStrings.length) {
  3795. var style = document.createElement('style');
  3796. style.setAttribute('type', 'text/css');
  3797. style.appendChild(document.createTextNode(styleStrings.shift()));
  3798. head.insertBefore(style, firstChild);
  3799. }
  3800. });
  3801. if (theme.colors.primary.name == theme.colors.accent.name) {
  3802. console.warn("$mdThemingProvider: Using the same palette for primary and" +
  3803. " accent. This violates the material design spec.");
  3804. }
  3805. GENERATED[theme.name] = true;
  3806. }
  3807. });
  3808. // *************************
  3809. // Internal functions
  3810. // *************************
  3811. // The user specifies a 'default' contrast color as either light or dark,
  3812. // then explicitly lists which hues are the opposite contrast (eg. A100 has dark, A200 has light)
  3813. function sanitizePalette(palette) {
  3814. var defaultContrast = palette.contrastDefaultColor;
  3815. var lightColors = palette.contrastLightColors || [];
  3816. var strongLightColors = palette.contrastStrongLightColors || [];
  3817. var darkColors = palette.contrastDarkColors || [];
  3818. // These colors are provided as space-separated lists
  3819. if (typeof lightColors === 'string') lightColors = lightColors.split(' ');
  3820. if (typeof strongLightColors === 'string') strongLightColors = strongLightColors.split(' ');
  3821. if (typeof darkColors === 'string') darkColors = darkColors.split(' ');
  3822. // Cleanup after ourselves
  3823. delete palette.contrastDefaultColor;
  3824. delete palette.contrastLightColors;
  3825. delete palette.contrastStrongLightColors;
  3826. delete palette.contrastDarkColors;
  3827. // Change { 'A100': '#fffeee' } to { 'A100': { value: '#fffeee', contrast:DARK_CONTRAST_COLOR }
  3828. angular.forEach(palette, function(hueValue, hueName) {
  3829. if (angular.isObject(hueValue)) return; // Already converted
  3830. // Map everything to rgb colors
  3831. var rgbValue = colorToRgbaArray(hueValue);
  3832. if (!rgbValue) {
  3833. throw new Error("Color %1, in palette %2's hue %3, is invalid. Hex or rgb(a) color expected."
  3834. .replace('%1', hueValue)
  3835. .replace('%2', palette.name)
  3836. .replace('%3', hueName));
  3837. }
  3838. palette[hueName] = {
  3839. value: rgbValue,
  3840. contrast: getContrastColor()
  3841. };
  3842. function getContrastColor() {
  3843. if (defaultContrast === 'light') {
  3844. if (darkColors.indexOf(hueName) > -1) {
  3845. return DARK_CONTRAST_COLOR;
  3846. } else {
  3847. return strongLightColors.indexOf(hueName) > -1 ? STRONG_LIGHT_CONTRAST_COLOR
  3848. : LIGHT_CONTRAST_COLOR;
  3849. }
  3850. } else {
  3851. if (lightColors.indexOf(hueName) > -1) {
  3852. return strongLightColors.indexOf(hueName) > -1 ? STRONG_LIGHT_CONTRAST_COLOR
  3853. : LIGHT_CONTRAST_COLOR;
  3854. } else {
  3855. return DARK_CONTRAST_COLOR;
  3856. }
  3857. }
  3858. }
  3859. });
  3860. }
  3861. }
  3862. generateThemes.$inject = ["$injector"];
  3863. function checkValidPalette(theme, colorType) {
  3864. // If theme attempts to use a palette that doesnt exist, throw error
  3865. if (!PALETTES[ (theme.colors[colorType] || {}).name ]) {
  3866. throw new Error(
  3867. "You supplied an invalid color palette for theme %1's %2 palette. Available palettes: %3"
  3868. .replace('%1', theme.name)
  3869. .replace('%2', colorType)
  3870. .replace('%3', Object.keys(PALETTES).join(', '))
  3871. );
  3872. }
  3873. }
  3874. function colorToRgbaArray(clr) {
  3875. if (angular.isArray(clr) && clr.length == 3) return clr;
  3876. if (/^rgb/.test(clr)) {
  3877. return clr.replace(/(^\s*rgba?\(|\)\s*$)/g, '').split(',').map(function(value, i) {
  3878. return i == 3 ? parseFloat(value, 10) : parseInt(value, 10);
  3879. });
  3880. }
  3881. if (clr.charAt(0) == '#') clr = clr.substring(1);
  3882. if (!/^([a-fA-F0-9]{3}){1,2}$/g.test(clr)) return;
  3883. var dig = clr.length / 3;
  3884. var red = clr.substr(0, dig);
  3885. var grn = clr.substr(dig, dig);
  3886. var blu = clr.substr(dig * 2);
  3887. if (dig === 1) {
  3888. red += red;
  3889. grn += grn;
  3890. blu += blu;
  3891. }
  3892. return [parseInt(red, 16), parseInt(grn, 16), parseInt(blu, 16)];
  3893. }
  3894. function rgba(rgbArray, opacity) {
  3895. if ( !rgbArray ) return "rgb('0,0,0')";
  3896. if (rgbArray.length == 4) {
  3897. rgbArray = angular.copy(rgbArray);
  3898. opacity ? rgbArray.pop() : opacity = rgbArray.pop();
  3899. }
  3900. return opacity && (typeof opacity == 'number' || (typeof opacity == 'string' && opacity.length)) ?
  3901. 'rgba(' + rgbArray.join(',') + ',' + opacity + ')' :
  3902. 'rgb(' + rgbArray.join(',') + ')';
  3903. }
  3904. })();
  3905. (function(){
  3906. "use strict";
  3907. // Polyfill angular < 1.4 (provide $animateCss)
  3908. angular
  3909. .module('material.core')
  3910. .factory('$$mdAnimate', ["$q", "$timeout", "$mdConstant", "$animateCss", function($q, $timeout, $mdConstant, $animateCss){
  3911. // Since $$mdAnimate is injected into $mdUtil... use a wrapper function
  3912. // to subsequently inject $mdUtil as an argument to the AnimateDomUtils
  3913. return function($mdUtil) {
  3914. return AnimateDomUtils( $mdUtil, $q, $timeout, $mdConstant, $animateCss);
  3915. };
  3916. }]);
  3917. /**
  3918. * Factory function that requires special injections
  3919. */
  3920. function AnimateDomUtils($mdUtil, $q, $timeout, $mdConstant, $animateCss) {
  3921. var self;
  3922. return self = {
  3923. /**
  3924. *
  3925. */
  3926. translate3d : function( target, from, to, options ) {
  3927. return $animateCss(target,{
  3928. from:from,
  3929. to:to,
  3930. addClass:options.transitionInClass
  3931. })
  3932. .start()
  3933. .then(function(){
  3934. // Resolve with reverser function...
  3935. return reverseTranslate;
  3936. });
  3937. /**
  3938. * Specific reversal of the request translate animation above...
  3939. */
  3940. function reverseTranslate (newFrom) {
  3941. return $animateCss(target, {
  3942. to: newFrom || from,
  3943. addClass: options.transitionOutClass,
  3944. removeClass: options.transitionInClass
  3945. }).start();
  3946. }
  3947. },
  3948. /**
  3949. * Listen for transitionEnd event (with optional timeout)
  3950. * Announce completion or failure via promise handlers
  3951. */
  3952. waitTransitionEnd: function (element, opts) {
  3953. var TIMEOUT = 3000; // fallback is 3 secs
  3954. return $q(function(resolve, reject){
  3955. opts = opts || { };
  3956. var timer = $timeout(finished, opts.timeout || TIMEOUT);
  3957. element.on($mdConstant.CSS.TRANSITIONEND, finished);
  3958. /**
  3959. * Upon timeout or transitionEnd, reject or resolve (respectively) this promise.
  3960. * NOTE: Make sure this transitionEnd didn't bubble up from a child
  3961. */
  3962. function finished(ev) {
  3963. if ( ev && ev.target !== element[0]) return;
  3964. if ( ev ) $timeout.cancel(timer);
  3965. element.off($mdConstant.CSS.TRANSITIONEND, finished);
  3966. // Never reject since ngAnimate may cause timeouts due missed transitionEnd events
  3967. resolve();
  3968. }
  3969. });
  3970. },
  3971. /**
  3972. * Calculate the zoom transform from dialog to origin.
  3973. *
  3974. * We use this to set the dialog position immediately;
  3975. * then the md-transition-in actually translates back to
  3976. * `translate3d(0,0,0) scale(1.0)`...
  3977. *
  3978. * NOTE: all values are rounded to the nearest integer
  3979. */
  3980. calculateZoomToOrigin: function (element, originator) {
  3981. var origin = originator.element;
  3982. var zoomTemplate = "translate3d( {centerX}px, {centerY}px, 0 ) scale( {scaleX}, {scaleY} )";
  3983. var buildZoom = angular.bind(null, $mdUtil.supplant, zoomTemplate);
  3984. var zoomStyle = buildZoom({centerX: 0, centerY: 0, scaleX: 0.5, scaleY: 0.5});
  3985. if (origin) {
  3986. var originBnds = self.clientRect(origin) || self.copyRect(originator.bounds);
  3987. var dialogRect = self.copyRect(element[0].getBoundingClientRect());
  3988. var dialogCenterPt = self.centerPointFor(dialogRect);
  3989. var originCenterPt = self.centerPointFor(originBnds);
  3990. // Build the transform to zoom from the dialog center to the origin center
  3991. zoomStyle = buildZoom({
  3992. centerX: originCenterPt.x - dialogCenterPt.x,
  3993. centerY: originCenterPt.y - dialogCenterPt.y,
  3994. scaleX: Math.round(100 * Math.min(0.5, originBnds.width / dialogRect.width))/100,
  3995. scaleY: Math.round(100 * Math.min(0.5, originBnds.height / dialogRect.height))/100
  3996. });
  3997. }
  3998. return zoomStyle;
  3999. },
  4000. /**
  4001. * Enhance raw values to represent valid css stylings...
  4002. */
  4003. toCss : function( raw ) {
  4004. var css = { };
  4005. var lookups = 'left top right bottom width height x y min-width min-height max-width max-height';
  4006. angular.forEach(raw, function(value,key) {
  4007. if ( angular.isUndefined(value) ) return;
  4008. if ( lookups.indexOf(key) >= 0 ) {
  4009. css[key] = value + 'px';
  4010. } else {
  4011. switch (key) {
  4012. case 'transform':
  4013. convertToVendor(key, $mdConstant.CSS.TRANSFORM, value);
  4014. break;
  4015. case 'transformOrigin':
  4016. convertToVendor(key, $mdConstant.CSS.TRANSFORM_ORIGIN, value);
  4017. break;
  4018. }
  4019. }
  4020. });
  4021. return css;
  4022. function convertToVendor(key, vendor, value) {
  4023. angular.forEach(vendor.split(' '), function (key) {
  4024. css[key] = value;
  4025. });
  4026. }
  4027. },
  4028. /**
  4029. * Convert the translate CSS value to key/value pair(s).
  4030. */
  4031. toTransformCss: function (transform, addTransition, transition) {
  4032. var css = {};
  4033. angular.forEach($mdConstant.CSS.TRANSFORM.split(' '), function (key) {
  4034. css[key] = transform;
  4035. });
  4036. if (addTransition) {
  4037. transition = transition || "all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) !important";
  4038. css['transition'] = transition;
  4039. }
  4040. return css;
  4041. },
  4042. /**
  4043. * Clone the Rect and calculate the height/width if needed
  4044. */
  4045. copyRect: function (source, destination) {
  4046. if (!source) return null;
  4047. destination = destination || {};
  4048. angular.forEach('left top right bottom width height'.split(' '), function (key) {
  4049. destination[key] = Math.round(source[key])
  4050. });
  4051. destination.width = destination.width || (destination.right - destination.left);
  4052. destination.height = destination.height || (destination.bottom - destination.top);
  4053. return destination;
  4054. },
  4055. /**
  4056. * Calculate ClientRect of element; return null if hidden or zero size
  4057. */
  4058. clientRect: function (element) {
  4059. var bounds = angular.element(element)[0].getBoundingClientRect();
  4060. var isPositiveSizeClientRect = function (rect) {
  4061. return rect && (rect.width > 0) && (rect.height > 0);
  4062. };
  4063. // If the event origin element has zero size, it has probably been hidden.
  4064. return isPositiveSizeClientRect(bounds) ? self.copyRect(bounds) : null;
  4065. },
  4066. /**
  4067. * Calculate 'rounded' center point of Rect
  4068. */
  4069. centerPointFor: function (targetRect) {
  4070. return {
  4071. x: Math.round(targetRect.left + (targetRect.width / 2)),
  4072. y: Math.round(targetRect.top + (targetRect.height / 2))
  4073. }
  4074. }
  4075. };
  4076. };
  4077. })();
  4078. (function(){
  4079. "use strict";
  4080. "use strict";
  4081. if (angular.version.minor >= 4) {
  4082. angular.module('material.animate', []);
  4083. } else {
  4084. (function() {
  4085. var forEach = angular.forEach;
  4086. var WEBKIT = window.ontransitionend === undefined && window.onwebkittransitionend !== undefined;
  4087. var TRANSITION_PROP = WEBKIT ? 'WebkitTransition' : 'transition';
  4088. var ANIMATION_PROP = WEBKIT ? 'WebkitAnimation' : 'animation';
  4089. var PREFIX = WEBKIT ? '-webkit-' : '';
  4090. var TRANSITION_EVENTS = (WEBKIT ? 'webkitTransitionEnd ' : '') + 'transitionend';
  4091. var ANIMATION_EVENTS = (WEBKIT ? 'webkitAnimationEnd ' : '') + 'animationend';
  4092. var $$ForceReflowFactory = ['$document', function($document) {
  4093. return function() {
  4094. return $document[0].body.clientWidth + 1;
  4095. }
  4096. }];
  4097. var $$rAFMutexFactory = ['$$rAF', function($$rAF) {
  4098. return function() {
  4099. var passed = false;
  4100. $$rAF(function() {
  4101. passed = true;
  4102. });
  4103. return function(fn) {
  4104. passed ? fn() : $$rAF(fn);
  4105. };
  4106. };
  4107. }];
  4108. var $$AnimateRunnerFactory = ['$q', '$$rAFMutex', function($q, $$rAFMutex) {
  4109. var INITIAL_STATE = 0;
  4110. var DONE_PENDING_STATE = 1;
  4111. var DONE_COMPLETE_STATE = 2;
  4112. function AnimateRunner(host) {
  4113. this.setHost(host);
  4114. this._doneCallbacks = [];
  4115. this._runInAnimationFrame = $$rAFMutex();
  4116. this._state = 0;
  4117. }
  4118. AnimateRunner.prototype = {
  4119. setHost: function(host) {
  4120. this.host = host || {};
  4121. },
  4122. done: function(fn) {
  4123. if (this._state === DONE_COMPLETE_STATE) {
  4124. fn();
  4125. } else {
  4126. this._doneCallbacks.push(fn);
  4127. }
  4128. },
  4129. progress: angular.noop,
  4130. getPromise: function() {
  4131. if (!this.promise) {
  4132. var self = this;
  4133. this.promise = $q(function(resolve, reject) {
  4134. self.done(function(status) {
  4135. status === false ? reject() : resolve();
  4136. });
  4137. });
  4138. }
  4139. return this.promise;
  4140. },
  4141. then: function(resolveHandler, rejectHandler) {
  4142. return this.getPromise().then(resolveHandler, rejectHandler);
  4143. },
  4144. 'catch': function(handler) {
  4145. return this.getPromise()['catch'](handler);
  4146. },
  4147. 'finally': function(handler) {
  4148. return this.getPromise()['finally'](handler);
  4149. },
  4150. pause: function() {
  4151. if (this.host.pause) {
  4152. this.host.pause();
  4153. }
  4154. },
  4155. resume: function() {
  4156. if (this.host.resume) {
  4157. this.host.resume();
  4158. }
  4159. },
  4160. end: function() {
  4161. if (this.host.end) {
  4162. this.host.end();
  4163. }
  4164. this._resolve(true);
  4165. },
  4166. cancel: function() {
  4167. if (this.host.cancel) {
  4168. this.host.cancel();
  4169. }
  4170. this._resolve(false);
  4171. },
  4172. complete: function(response) {
  4173. var self = this;
  4174. if (self._state === INITIAL_STATE) {
  4175. self._state = DONE_PENDING_STATE;
  4176. self._runInAnimationFrame(function() {
  4177. self._resolve(response);
  4178. });
  4179. }
  4180. },
  4181. _resolve: function(response) {
  4182. if (this._state !== DONE_COMPLETE_STATE) {
  4183. forEach(this._doneCallbacks, function(fn) {
  4184. fn(response);
  4185. });
  4186. this._doneCallbacks.length = 0;
  4187. this._state = DONE_COMPLETE_STATE;
  4188. }
  4189. }
  4190. };
  4191. return AnimateRunner;
  4192. }];
  4193. angular
  4194. .module('material.animate', [])
  4195. .factory('$$forceReflow', $$ForceReflowFactory)
  4196. .factory('$$AnimateRunner', $$AnimateRunnerFactory)
  4197. .factory('$$rAFMutex', $$rAFMutexFactory)
  4198. .factory('$animateCss', ['$window', '$$rAF', '$$AnimateRunner', '$$forceReflow', '$$jqLite', '$timeout',
  4199. function($window, $$rAF, $$AnimateRunner, $$forceReflow, $$jqLite, $timeout) {
  4200. function init(element, options) {
  4201. var temporaryStyles = [];
  4202. var node = getDomNode(element);
  4203. if (options.transitionStyle) {
  4204. temporaryStyles.push([PREFIX + 'transition', options.transitionStyle]);
  4205. }
  4206. if (options.keyframeStyle) {
  4207. temporaryStyles.push([PREFIX + 'animation', options.keyframeStyle]);
  4208. }
  4209. if (options.delay) {
  4210. temporaryStyles.push([PREFIX + 'transition-delay', options.delay + 's']);
  4211. }
  4212. if (options.duration) {
  4213. temporaryStyles.push([PREFIX + 'transition-duration', options.duration + 's']);
  4214. }
  4215. var hasCompleteStyles = options.keyframeStyle ||
  4216. (options.to && (options.duration > 0 || options.transitionStyle));
  4217. var hasCompleteClasses = !!options.addClass || !!options.removeClass;
  4218. var hasCompleteAnimation = hasCompleteStyles || hasCompleteClasses;
  4219. blockTransition(element, true);
  4220. applyAnimationFromStyles(element, options);
  4221. var animationClosed = false;
  4222. var events, eventFn;
  4223. return {
  4224. close: close,
  4225. start: function() {
  4226. var runner = new $$AnimateRunner();
  4227. waitUntilQuiet(function() {
  4228. blockTransition(element, false);
  4229. if (!hasCompleteAnimation) {
  4230. return close();
  4231. }
  4232. forEach(temporaryStyles, function(entry) {
  4233. var key = entry[0];
  4234. var value = entry[1];
  4235. node.style[camelCase(key)] = value;
  4236. });
  4237. applyClasses(element, options);
  4238. var timings = computeTimings(element);
  4239. if (timings.duration === 0) {
  4240. return close();
  4241. }
  4242. var moreStyles = [];
  4243. if (options.easing) {
  4244. if (timings.transitionDuration) {
  4245. moreStyles.push([PREFIX + 'transition-timing-function', options.easing]);
  4246. }
  4247. if (timings.animationDuration) {
  4248. moreStyles.push([PREFIX + 'animation-timing-function', options.easing]);
  4249. }
  4250. }
  4251. if (options.delay && timings.animationDelay) {
  4252. moreStyles.push([PREFIX + 'animation-delay', options.delay + 's']);
  4253. }
  4254. if (options.duration && timings.animationDuration) {
  4255. moreStyles.push([PREFIX + 'animation-duration', options.duration + 's']);
  4256. }
  4257. forEach(moreStyles, function(entry) {
  4258. var key = entry[0];
  4259. var value = entry[1];
  4260. node.style[camelCase(key)] = value;
  4261. temporaryStyles.push(entry);
  4262. });
  4263. var maxDelay = timings.delay;
  4264. var maxDelayTime = maxDelay * 1000;
  4265. var maxDuration = timings.duration;
  4266. var maxDurationTime = maxDuration * 1000;
  4267. var startTime = Date.now();
  4268. events = [];
  4269. if (timings.transitionDuration) {
  4270. events.push(TRANSITION_EVENTS);
  4271. }
  4272. if (timings.animationDuration) {
  4273. events.push(ANIMATION_EVENTS);
  4274. }
  4275. events = events.join(' ');
  4276. eventFn = function(event) {
  4277. event.stopPropagation();
  4278. var ev = event.originalEvent || event;
  4279. var timeStamp = ev.timeStamp || Date.now();
  4280. var elapsedTime = parseFloat(ev.elapsedTime.toFixed(3));
  4281. if (Math.max(timeStamp - startTime, 0) >= maxDelayTime && elapsedTime >= maxDuration) {
  4282. close();
  4283. }
  4284. };
  4285. element.on(events, eventFn);
  4286. applyAnimationToStyles(element, options);
  4287. $timeout(close, maxDelayTime + maxDurationTime * 1.5, false);
  4288. });
  4289. return runner;
  4290. function close() {
  4291. if (animationClosed) return;
  4292. animationClosed = true;
  4293. if (events && eventFn) {
  4294. element.off(events, eventFn);
  4295. }
  4296. applyClasses(element, options);
  4297. applyAnimationStyles(element, options);
  4298. forEach(temporaryStyles, function(entry) {
  4299. node.style[camelCase(entry[0])] = '';
  4300. });
  4301. runner.complete(true);
  4302. return runner;
  4303. }
  4304. }
  4305. }
  4306. }
  4307. function applyClasses(element, options) {
  4308. if (options.addClass) {
  4309. $$jqLite.addClass(element, options.addClass);
  4310. options.addClass = null;
  4311. }
  4312. if (options.removeClass) {
  4313. $$jqLite.removeClass(element, options.removeClass);
  4314. options.removeClass = null;
  4315. }
  4316. }
  4317. function computeTimings(element) {
  4318. var node = getDomNode(element);
  4319. var cs = $window.getComputedStyle(node)
  4320. var tdr = parseMaxTime(cs[prop('transitionDuration')]);
  4321. var adr = parseMaxTime(cs[prop('animationDuration')]);
  4322. var tdy = parseMaxTime(cs[prop('transitionDelay')]);
  4323. var ady = parseMaxTime(cs[prop('animationDelay')]);
  4324. adr *= (parseInt(cs[prop('animationIterationCount')], 10) || 1);
  4325. var duration = Math.max(adr, tdr);
  4326. var delay = Math.max(ady, tdy);
  4327. return {
  4328. duration: duration,
  4329. delay: delay,
  4330. animationDuration: adr,
  4331. transitionDuration: tdr,
  4332. animationDelay: ady,
  4333. transitionDelay: tdy
  4334. };
  4335. function prop(key) {
  4336. return WEBKIT ? 'Webkit' + key.charAt(0).toUpperCase() + key.substr(1)
  4337. : key;
  4338. }
  4339. }
  4340. function parseMaxTime(str) {
  4341. var maxValue = 0;
  4342. var values = str.split(/\s*,\s*/);
  4343. forEach(values, function(value) {
  4344. // it's always safe to consider only second values and omit `ms` values since
  4345. // getComputedStyle will always handle the conversion for us
  4346. if (value.charAt(value.length - 1) == 's') {
  4347. value = value.substring(0, value.length - 1);
  4348. }
  4349. value = parseFloat(value) || 0;
  4350. maxValue = maxValue ? Math.max(value, maxValue) : value;
  4351. });
  4352. return maxValue;
  4353. }
  4354. var cancelLastRAFRequest;
  4355. var rafWaitQueue = [];
  4356. function waitUntilQuiet(callback) {
  4357. if (cancelLastRAFRequest) {
  4358. cancelLastRAFRequest(); //cancels the request
  4359. }
  4360. rafWaitQueue.push(callback);
  4361. cancelLastRAFRequest = $$rAF(function() {
  4362. cancelLastRAFRequest = null;
  4363. // DO NOT REMOVE THIS LINE OR REFACTOR OUT THE `pageWidth` variable.
  4364. // PLEASE EXAMINE THE `$$forceReflow` service to understand why.
  4365. var pageWidth = $$forceReflow();
  4366. // we use a for loop to ensure that if the queue is changed
  4367. // during this looping then it will consider new requests
  4368. for (var i = 0; i < rafWaitQueue.length; i++) {
  4369. rafWaitQueue[i](pageWidth);
  4370. }
  4371. rafWaitQueue.length = 0;
  4372. });
  4373. }
  4374. function applyAnimationStyles(element, options) {
  4375. applyAnimationFromStyles(element, options);
  4376. applyAnimationToStyles(element, options);
  4377. }
  4378. function applyAnimationFromStyles(element, options) {
  4379. if (options.from) {
  4380. element.css(options.from);
  4381. options.from = null;
  4382. }
  4383. }
  4384. function applyAnimationToStyles(element, options) {
  4385. if (options.to) {
  4386. element.css(options.to);
  4387. options.to = null;
  4388. }
  4389. }
  4390. function getDomNode(element) {
  4391. for (var i = 0; i < element.length; i++) {
  4392. if (element[i].nodeType === 1) return element[i];
  4393. }
  4394. }
  4395. function blockTransition(element, bool) {
  4396. var node = getDomNode(element);
  4397. var key = camelCase(PREFIX + 'transition-delay');
  4398. node.style[key] = bool ? '-9999s' : '';
  4399. }
  4400. return init;
  4401. }]);
  4402. /**
  4403. * Older browsers [FF31] expect camelCase
  4404. * property keys.
  4405. * e.g.
  4406. * animation-duration --> animationDuration
  4407. */
  4408. function camelCase(str) {
  4409. return str.replace(/-[a-z]/g, function(str) {
  4410. return str.charAt(1).toUpperCase();
  4411. });
  4412. }
  4413. })();
  4414. }
  4415. })();
  4416. (function(){
  4417. "use strict";
  4418. /**
  4419. * @ngdoc module
  4420. * @name material.components.autocomplete
  4421. */
  4422. /*
  4423. * @see js folder for autocomplete implementation
  4424. */
  4425. angular.module('material.components.autocomplete', [
  4426. 'material.core',
  4427. 'material.components.icon',
  4428. 'material.components.virtualRepeat'
  4429. ]);
  4430. })();
  4431. (function(){
  4432. "use strict";
  4433. /*
  4434. * @ngdoc module
  4435. * @name material.components.backdrop
  4436. * @description Backdrop
  4437. */
  4438. /**
  4439. * @ngdoc directive
  4440. * @name mdBackdrop
  4441. * @module material.components.backdrop
  4442. *
  4443. * @restrict E
  4444. *
  4445. * @description
  4446. * `<md-backdrop>` is a backdrop element used by other components, such as dialog and bottom sheet.
  4447. * Apply class `opaque` to make the backdrop use the theme backdrop color.
  4448. *
  4449. */
  4450. angular
  4451. .module('material.components.backdrop', ['material.core'])
  4452. .directive('mdBackdrop', ["$mdTheming", "$animate", "$rootElement", "$window", "$log", "$$rAF", "$document", function BackdropDirective($mdTheming, $animate, $rootElement, $window, $log, $$rAF, $document) {
  4453. var ERROR_CSS_POSITION = "<md-backdrop> may not work properly in a scrolled, static-positioned parent container.";
  4454. return {
  4455. restrict: 'E',
  4456. link: postLink
  4457. };
  4458. function postLink(scope, element, attrs) {
  4459. // If body scrolling has been disabled using mdUtil.disableBodyScroll(),
  4460. // adjust the 'backdrop' height to account for the fixed 'body' top offset
  4461. var body = $window.getComputedStyle($document[0].body);
  4462. if (body.position == 'fixed') {
  4463. var hViewport = parseInt(body.height, 10) + Math.abs(parseInt(body.top, 10));
  4464. element.css({
  4465. height: hViewport + 'px'
  4466. });
  4467. }
  4468. // backdrop may be outside the $rootElement, tell ngAnimate to animate regardless
  4469. if ($animate.pin) $animate.pin(element, $rootElement);
  4470. $$rAF(function () {
  4471. // Often $animate.enter() is used to append the backDrop element
  4472. // so let's wait until $animate is done...
  4473. var parent = element.parent()[0];
  4474. if (parent) {
  4475. var styles = $window.getComputedStyle(parent);
  4476. if (styles.position == 'static') {
  4477. // backdrop uses position:absolute and will not work properly with parent position:static (default)
  4478. $log.warn(ERROR_CSS_POSITION);
  4479. }
  4480. }
  4481. $mdTheming.inherit(element, element.parent());
  4482. });
  4483. }
  4484. }]);
  4485. })();
  4486. (function(){
  4487. "use strict";
  4488. /**
  4489. * @ngdoc module
  4490. * @name material.components.bottomSheet
  4491. * @description
  4492. * BottomSheet
  4493. */
  4494. angular
  4495. .module('material.components.bottomSheet', [
  4496. 'material.core',
  4497. 'material.components.backdrop'
  4498. ])
  4499. .directive('mdBottomSheet', MdBottomSheetDirective)
  4500. .provider('$mdBottomSheet', MdBottomSheetProvider);
  4501. function MdBottomSheetDirective() {
  4502. return {
  4503. restrict: 'E'
  4504. };
  4505. }
  4506. /**
  4507. * @ngdoc service
  4508. * @name $mdBottomSheet
  4509. * @module material.components.bottomSheet
  4510. *
  4511. * @description
  4512. * `$mdBottomSheet` opens a bottom sheet over the app and provides a simple promise API.
  4513. *
  4514. * ## Restrictions
  4515. *
  4516. * - The bottom sheet's template must have an outer `<md-bottom-sheet>` element.
  4517. * - Add the `md-grid` class to the bottom sheet for a grid layout.
  4518. * - Add the `md-list` class to the bottom sheet for a list layout.
  4519. *
  4520. * @usage
  4521. * <hljs lang="html">
  4522. * <div ng-controller="MyController">
  4523. * <md-button ng-click="openBottomSheet()">
  4524. * Open a Bottom Sheet!
  4525. * </md-button>
  4526. * </div>
  4527. * </hljs>
  4528. * <hljs lang="js">
  4529. * var app = angular.module('app', ['ngMaterial']);
  4530. * app.controller('MyController', function($scope, $mdBottomSheet) {
  4531. * $scope.openBottomSheet = function() {
  4532. * $mdBottomSheet.show({
  4533. * template: '<md-bottom-sheet>Hello!</md-bottom-sheet>'
  4534. * });
  4535. * };
  4536. * });
  4537. * </hljs>
  4538. */
  4539. /**
  4540. * @ngdoc method
  4541. * @name $mdBottomSheet#show
  4542. *
  4543. * @description
  4544. * Show a bottom sheet with the specified options.
  4545. *
  4546. * @param {object} options An options object, with the following properties:
  4547. *
  4548. * - `templateUrl` - `{string=}`: The url of an html template file that will
  4549. * be used as the content of the bottom sheet. Restrictions: the template must
  4550. * have an outer `md-bottom-sheet` element.
  4551. * - `template` - `{string=}`: Same as templateUrl, except this is an actual
  4552. * template string.
  4553. * - `scope` - `{object=}`: the scope to link the template / controller to. If none is specified, it will create a new child scope.
  4554. * This scope will be destroyed when the bottom sheet is removed unless `preserveScope` is set to true.
  4555. * - `preserveScope` - `{boolean=}`: whether to preserve the scope when the element is removed. Default is false
  4556. * - `controller` - `{string=}`: The controller to associate with this bottom sheet.
  4557. * - `locals` - `{string=}`: An object containing key/value pairs. The keys will
  4558. * be used as names of values to inject into the controller. For example,
  4559. * `locals: {three: 3}` would inject `three` into the controller with the value
  4560. * of 3.
  4561. * - `targetEvent` - `{DOMClickEvent=}`: A click's event object. When passed in as an option,
  4562. * the location of the click will be used as the starting point for the opening animation
  4563. * of the the dialog.
  4564. * - `resolve` - `{object=}`: Similar to locals, except it takes promises as values
  4565. * and the bottom sheet will not open until the promises resolve.
  4566. * - `controllerAs` - `{string=}`: An alias to assign the controller to on the scope.
  4567. * - `parent` - `{element=}`: The element to append the bottom sheet to. The `parent` may be a `function`, `string`,
  4568. * `object`, or null. Defaults to appending to the body of the root element (or the root element) of the application.
  4569. * e.g. angular.element(document.getElementById('content')) or "#content"
  4570. * - `disableParentScroll` - `{boolean=}`: Whether to disable scrolling while the bottom sheet is open.
  4571. * Default true.
  4572. *
  4573. * @returns {promise} A promise that can be resolved with `$mdBottomSheet.hide()` or
  4574. * rejected with `$mdBottomSheet.cancel()`.
  4575. */
  4576. /**
  4577. * @ngdoc method
  4578. * @name $mdBottomSheet#hide
  4579. *
  4580. * @description
  4581. * Hide the existing bottom sheet and resolve the promise returned from
  4582. * `$mdBottomSheet.show()`. This call will close the most recently opened/current bottomsheet (if any).
  4583. *
  4584. * @param {*=} response An argument for the resolved promise.
  4585. *
  4586. */
  4587. /**
  4588. * @ngdoc method
  4589. * @name $mdBottomSheet#cancel
  4590. *
  4591. * @description
  4592. * Hide the existing bottom sheet and reject the promise returned from
  4593. * `$mdBottomSheet.show()`.
  4594. *
  4595. * @param {*=} response An argument for the rejected promise.
  4596. *
  4597. */
  4598. function MdBottomSheetProvider($$interimElementProvider) {
  4599. // how fast we need to flick down to close the sheet, pixels/ms
  4600. var CLOSING_VELOCITY = 0.5;
  4601. var PADDING = 80; // same as css
  4602. bottomSheetDefaults.$inject = ["$animate", "$mdConstant", "$mdUtil", "$mdTheming", "$mdBottomSheet", "$rootElement", "$mdGesture"];
  4603. return $$interimElementProvider('$mdBottomSheet')
  4604. .setDefaults({
  4605. methods: ['disableParentScroll', 'escapeToClose', 'targetEvent'],
  4606. options: bottomSheetDefaults
  4607. });
  4608. /* @ngInject */
  4609. function bottomSheetDefaults($animate, $mdConstant, $mdUtil, $mdTheming, $mdBottomSheet, $rootElement, $mdGesture) {
  4610. var backdrop;
  4611. return {
  4612. themable: true,
  4613. targetEvent: null,
  4614. onShow: onShow,
  4615. onRemove: onRemove,
  4616. escapeToClose: true,
  4617. disableParentScroll: true
  4618. };
  4619. function onShow(scope, element, options, controller) {
  4620. element = $mdUtil.extractElementByName(element, 'md-bottom-sheet');
  4621. // Add a backdrop that will close on click
  4622. backdrop = $mdUtil.createBackdrop(scope, "md-bottom-sheet-backdrop md-opaque");
  4623. backdrop.on('click', function() {
  4624. $mdUtil.nextTick($mdBottomSheet.cancel,true);
  4625. });
  4626. $mdTheming.inherit(backdrop, options.parent);
  4627. $animate.enter(backdrop, options.parent, null);
  4628. var bottomSheet = new BottomSheet(element, options.parent);
  4629. options.bottomSheet = bottomSheet;
  4630. // Give up focus on calling item
  4631. options.targetEvent && angular.element(options.targetEvent.target).blur();
  4632. $mdTheming.inherit(bottomSheet.element, options.parent);
  4633. if (options.disableParentScroll) {
  4634. options.restoreScroll = $mdUtil.disableScrollAround(bottomSheet.element, options.parent);
  4635. }
  4636. return $animate.enter(bottomSheet.element, options.parent)
  4637. .then(function() {
  4638. var focusable = $mdUtil.findFocusTarget(element) || angular.element(
  4639. element[0].querySelector('button') ||
  4640. element[0].querySelector('a') ||
  4641. element[0].querySelector('[ng-click]')
  4642. );
  4643. focusable.focus();
  4644. if (options.escapeToClose) {
  4645. options.rootElementKeyupCallback = function(e) {
  4646. if (e.keyCode === $mdConstant.KEY_CODE.ESCAPE) {
  4647. $mdUtil.nextTick($mdBottomSheet.cancel,true);
  4648. }
  4649. };
  4650. $rootElement.on('keyup', options.rootElementKeyupCallback);
  4651. }
  4652. });
  4653. }
  4654. function onRemove(scope, element, options) {
  4655. var bottomSheet = options.bottomSheet;
  4656. $animate.leave(backdrop);
  4657. return $animate.leave(bottomSheet.element).then(function() {
  4658. if (options.disableParentScroll) {
  4659. options.restoreScroll();
  4660. delete options.restoreScroll;
  4661. }
  4662. bottomSheet.cleanup();
  4663. // Restore focus
  4664. options.targetEvent && angular.element(options.targetEvent.target).focus();
  4665. });
  4666. }
  4667. /**
  4668. * BottomSheet class to apply bottom-sheet behavior to an element
  4669. */
  4670. function BottomSheet(element, parent) {
  4671. var deregister = $mdGesture.register(parent, 'drag', { horizontal: false });
  4672. parent.on('$md.dragstart', onDragStart)
  4673. .on('$md.drag', onDrag)
  4674. .on('$md.dragend', onDragEnd);
  4675. return {
  4676. element: element,
  4677. cleanup: function cleanup() {
  4678. deregister();
  4679. parent.off('$md.dragstart', onDragStart);
  4680. parent.off('$md.drag', onDrag);
  4681. parent.off('$md.dragend', onDragEnd);
  4682. }
  4683. };
  4684. function onDragStart(ev) {
  4685. // Disable transitions on transform so that it feels fast
  4686. element.css($mdConstant.CSS.TRANSITION_DURATION, '0ms');
  4687. }
  4688. function onDrag(ev) {
  4689. var transform = ev.pointer.distanceY;
  4690. if (transform < 5) {
  4691. // Slow down drag when trying to drag up, and stop after PADDING
  4692. transform = Math.max(-PADDING, transform / 2);
  4693. }
  4694. element.css($mdConstant.CSS.TRANSFORM, 'translate3d(0,' + (PADDING + transform) + 'px,0)');
  4695. }
  4696. function onDragEnd(ev) {
  4697. if (ev.pointer.distanceY > 0 &&
  4698. (ev.pointer.distanceY > 20 || Math.abs(ev.pointer.velocityY) > CLOSING_VELOCITY)) {
  4699. var distanceRemaining = element.prop('offsetHeight') - ev.pointer.distanceY;
  4700. var transitionDuration = Math.min(distanceRemaining / ev.pointer.velocityY * 0.75, 500);
  4701. element.css($mdConstant.CSS.TRANSITION_DURATION, transitionDuration + 'ms');
  4702. $mdUtil.nextTick($mdBottomSheet.cancel,true);
  4703. } else {
  4704. element.css($mdConstant.CSS.TRANSITION_DURATION, '');
  4705. element.css($mdConstant.CSS.TRANSFORM, '');
  4706. }
  4707. }
  4708. }
  4709. }
  4710. }
  4711. MdBottomSheetProvider.$inject = ["$$interimElementProvider"];
  4712. })();
  4713. (function(){
  4714. "use strict";
  4715. /**
  4716. * @ngdoc module
  4717. * @name material.components.button
  4718. * @description
  4719. *
  4720. * Button
  4721. */
  4722. angular
  4723. .module('material.components.button', [ 'material.core' ])
  4724. .directive('mdButton', MdButtonDirective);
  4725. /**
  4726. * @ngdoc directive
  4727. * @name mdButton
  4728. * @module material.components.button
  4729. *
  4730. * @restrict E
  4731. *
  4732. * @description
  4733. * `<md-button>` is a button directive with optional ink ripples (default enabled).
  4734. *
  4735. * If you supply a `href` or `ng-href` attribute, it will become an `<a>` element. Otherwise, it will
  4736. * become a `<button>` element. As per the [Material Design specifications](http://www.google.com/design/spec/style/color.html#color-ui-color-application)
  4737. * the FAB button background is filled with the accent color [by default]. The primary color palette may be used with
  4738. * the `md-primary` class.
  4739. *
  4740. * @param {boolean=} md-no-ink If present, disable ripple ink effects.
  4741. * @param {expression=} ng-disabled En/Disable based on the expression
  4742. * @param {string=} md-ripple-size Overrides the default ripple size logic. Options: `full`, `partial`, `auto`
  4743. * @param {string=} aria-label Adds alternative text to button for accessibility, useful for icon buttons.
  4744. * If no default text is found, a warning will be logged.
  4745. *
  4746. * @usage
  4747. *
  4748. * Regular buttons:
  4749. *
  4750. * <hljs lang="html">
  4751. * <md-button> Flat Button </md-button>
  4752. * <md-button href="http://google.com"> Flat link </md-button>
  4753. * <md-button class="md-raised"> Raised Button </md-button>
  4754. * <md-button ng-disabled="true"> Disabled Button </md-button>
  4755. * <md-button>
  4756. * <md-icon md-svg-src="your/icon.svg"></md-icon>
  4757. * Register Now
  4758. * </md-button>
  4759. * </hljs>
  4760. *
  4761. * FAB buttons:
  4762. *
  4763. * <hljs lang="html">
  4764. * <md-button class="md-fab" aria-label="FAB">
  4765. * <md-icon md-svg-src="your/icon.svg"></md-icon>
  4766. * </md-button>
  4767. * <!-- mini-FAB -->
  4768. * <md-button class="md-fab md-mini" aria-label="Mini FAB">
  4769. * <md-icon md-svg-src="your/icon.svg"></md-icon>
  4770. * </md-button>
  4771. * <!-- Button with SVG Icon -->
  4772. * <md-button class="md-icon-button" aria-label="Custom Icon Button">
  4773. * <md-icon md-svg-icon="path/to/your.svg"></md-icon>
  4774. * </md-button>
  4775. * </hljs>
  4776. */
  4777. function MdButtonDirective($mdButtonInkRipple, $mdTheming, $mdAria, $timeout) {
  4778. return {
  4779. restrict: 'EA',
  4780. replace: true,
  4781. transclude: true,
  4782. template: getTemplate,
  4783. link: postLink
  4784. };
  4785. function isAnchor(attr) {
  4786. return angular.isDefined(attr.href) || angular.isDefined(attr.ngHref) || angular.isDefined(attr.ngLink) || angular.isDefined(attr.uiSref);
  4787. }
  4788. function getTemplate(element, attr) {
  4789. return isAnchor(attr) ?
  4790. '<a class="md-button" ng-transclude></a>' :
  4791. '<button class="md-button" ng-transclude></button>';
  4792. }
  4793. function postLink(scope, element, attr) {
  4794. var node = element[0];
  4795. $mdTheming(element);
  4796. $mdButtonInkRipple.attach(scope, element);
  4797. var elementHasText = node.textContent.trim();
  4798. if (!elementHasText) {
  4799. $mdAria.expect(element, 'aria-label');
  4800. }
  4801. // For anchor elements, we have to set tabindex manually when the
  4802. // element is disabled
  4803. if (isAnchor(attr) && angular.isDefined(attr.ngDisabled) ) {
  4804. scope.$watch(attr.ngDisabled, function(isDisabled) {
  4805. element.attr('tabindex', isDisabled ? -1 : 0);
  4806. });
  4807. }
  4808. // disabling click event when disabled is true
  4809. element.on('click', function(e){
  4810. if (attr.disabled === true) {
  4811. e.preventDefault();
  4812. e.stopImmediatePropagation();
  4813. }
  4814. });
  4815. // restrict focus styles to the keyboard
  4816. scope.mouseActive = false;
  4817. element.on('mousedown', function() {
  4818. scope.mouseActive = true;
  4819. $timeout(function(){
  4820. scope.mouseActive = false;
  4821. }, 100);
  4822. })
  4823. .on('focus', function() {
  4824. if (scope.mouseActive === false) { element.addClass('md-focused'); }
  4825. })
  4826. .on('blur', function() { element.removeClass('md-focused'); });
  4827. }
  4828. }
  4829. MdButtonDirective.$inject = ["$mdButtonInkRipple", "$mdTheming", "$mdAria", "$timeout"];
  4830. })();
  4831. (function(){
  4832. "use strict";
  4833. /**
  4834. * @ngdoc module
  4835. * @name material.components.card
  4836. *
  4837. * @description
  4838. * Card components.
  4839. */
  4840. angular.module('material.components.card', [
  4841. 'material.core'
  4842. ])
  4843. .directive('mdCard', mdCardDirective);
  4844. /**
  4845. * @ngdoc directive
  4846. * @name mdCard
  4847. * @module material.components.card
  4848. *
  4849. * @restrict E
  4850. *
  4851. * @description
  4852. * The `<md-card>` directive is a container element used within `<md-content>` containers.
  4853. *
  4854. * An image included as a direct descendant will fill the card's width, while the `<md-card-content>`
  4855. * container will wrap text content and provide padding. An `<md-card-footer>` element can be
  4856. * optionally included to put content flush against the bottom edge of the card.
  4857. *
  4858. * Action buttons can be included in an element with the `.md-actions` class, also used in `md-dialog`.
  4859. * You can then position buttons using layout attributes.
  4860. *
  4861. * Cards have constant width and variable heights; where the maximum height is limited to what can
  4862. * fit within a single view on a platform, but it can temporarily expand as needed.
  4863. *
  4864. * @usage
  4865. * ###Card with optional footer
  4866. * <hljs lang="html">
  4867. * <md-card>
  4868. * <img src="card-image.png" class="md-card-image" alt="image caption">
  4869. * <md-card-content>
  4870. * <h2>Card headline</h2>
  4871. * <p>Card content</p>
  4872. * </md-card-content>
  4873. * <md-card-footer>
  4874. * Card footer
  4875. * </md-card-footer>
  4876. * </md-card>
  4877. * </hljs>
  4878. *
  4879. * ###Card with actions
  4880. * <hljs lang="html">
  4881. * <md-card>
  4882. * <img src="card-image.png" class="md-card-image" alt="image caption">
  4883. * <md-card-content>
  4884. * <h2>Card headline</h2>
  4885. * <p>Card content</p>
  4886. * </md-card-content>
  4887. * <div class="md-actions" layout="row" layout-align="end center">
  4888. * <md-button>Action 1</md-button>
  4889. * <md-button>Action 2</md-button>
  4890. * </div>
  4891. * </md-card>
  4892. * </hljs>
  4893. *
  4894. */
  4895. function mdCardDirective($mdTheming) {
  4896. return {
  4897. restrict: 'E',
  4898. link: function($scope, $element, $attr) {
  4899. $mdTheming($element);
  4900. }
  4901. };
  4902. }
  4903. mdCardDirective.$inject = ["$mdTheming"];
  4904. })();
  4905. (function(){
  4906. "use strict";
  4907. /**
  4908. * @ngdoc module
  4909. * @name material.components.checkbox
  4910. * @description Checkbox module!
  4911. */
  4912. angular
  4913. .module('material.components.checkbox', ['material.core'])
  4914. .directive('mdCheckbox', MdCheckboxDirective);
  4915. /**
  4916. * @ngdoc directive
  4917. * @name mdCheckbox
  4918. * @module material.components.checkbox
  4919. * @restrict E
  4920. *
  4921. * @description
  4922. * The checkbox directive is used like the normal [angular checkbox](https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D).
  4923. *
  4924. * As per the [material design spec](http://www.google.com/design/spec/style/color.html#color-ui-color-application)
  4925. * the checkbox is in the accent color by default. The primary color palette may be used with
  4926. * the `md-primary` class.
  4927. *
  4928. * @param {string} ng-model Assignable angular expression to data-bind to.
  4929. * @param {string=} name Property name of the form under which the control is published.
  4930. * @param {expression=} ng-true-value The value to which the expression should be set when selected.
  4931. * @param {expression=} ng-false-value The value to which the expression should be set when not selected.
  4932. * @param {string=} ng-change Angular expression to be executed when input changes due to user interaction with the input element.
  4933. * @param {boolean=} md-no-ink Use of attribute indicates use of ripple ink effects
  4934. * @param {string=} aria-label Adds label to checkbox for accessibility.
  4935. * Defaults to checkbox's text. If no default text is found, a warning will be logged.
  4936. *
  4937. * @usage
  4938. * <hljs lang="html">
  4939. * <md-checkbox ng-model="isChecked" aria-label="Finished?">
  4940. * Finished ?
  4941. * </md-checkbox>
  4942. *
  4943. * <md-checkbox md-no-ink ng-model="hasInk" aria-label="No Ink Effects">
  4944. * No Ink Effects
  4945. * </md-checkbox>
  4946. *
  4947. * <md-checkbox ng-disabled="true" ng-model="isDisabled" aria-label="Disabled">
  4948. * Disabled
  4949. * </md-checkbox>
  4950. *
  4951. * </hljs>
  4952. *
  4953. */
  4954. function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $mdUtil, $timeout) {
  4955. inputDirective = inputDirective[0];
  4956. var CHECKED_CSS = 'md-checked';
  4957. return {
  4958. restrict: 'E',
  4959. transclude: true,
  4960. require: '?ngModel',
  4961. priority:210, // Run before ngAria
  4962. template:
  4963. '<div class="md-container" md-ink-ripple md-ink-ripple-checkbox>' +
  4964. '<div class="md-icon"></div>' +
  4965. '</div>' +
  4966. '<div ng-transclude class="md-label"></div>',
  4967. compile: compile
  4968. };
  4969. // **********************************************************
  4970. // Private Methods
  4971. // **********************************************************
  4972. function compile (tElement, tAttrs) {
  4973. tAttrs.type = 'checkbox';
  4974. tAttrs.tabindex = tAttrs.tabindex || '0';
  4975. tElement.attr('role', tAttrs.type);
  4976. return function postLink(scope, element, attr, ngModelCtrl) {
  4977. ngModelCtrl = ngModelCtrl || $mdUtil.fakeNgModel();
  4978. $mdTheming(element);
  4979. if (attr.ngChecked) {
  4980. scope.$watch(
  4981. scope.$eval.bind(scope, attr.ngChecked),
  4982. ngModelCtrl.$setViewValue.bind(ngModelCtrl)
  4983. );
  4984. }
  4985. $$watchExpr('ngDisabled', 'tabindex', {
  4986. true: '-1',
  4987. false: attr.tabindex
  4988. });
  4989. $mdAria.expectWithText(element, 'aria-label');
  4990. // Reuse the original input[type=checkbox] directive from Angular core.
  4991. // This is a bit hacky as we need our own event listener and own render
  4992. // function.
  4993. inputDirective.link.pre(scope, {
  4994. on: angular.noop,
  4995. 0: {}
  4996. }, attr, [ngModelCtrl]);
  4997. scope.mouseActive = false;
  4998. element.on('click', listener)
  4999. .on('keypress', keypressHandler)
  5000. .on('mousedown', function() {
  5001. scope.mouseActive = true;
  5002. $timeout(function(){
  5003. scope.mouseActive = false;
  5004. }, 100);
  5005. })
  5006. .on('focus', function() {
  5007. if(scope.mouseActive === false) { element.addClass('md-focused'); }
  5008. })
  5009. .on('blur', function() { element.removeClass('md-focused'); });
  5010. ngModelCtrl.$render = render;
  5011. function $$watchExpr(expr, htmlAttr, valueOpts) {
  5012. if (attr[expr]) {
  5013. scope.$watch(attr[expr], function(val) {
  5014. if (valueOpts[val]) {
  5015. element.attr(htmlAttr, valueOpts[val]);
  5016. }
  5017. });
  5018. }
  5019. }
  5020. function keypressHandler(ev) {
  5021. var keyCode = ev.which || ev.keyCode;
  5022. if (keyCode === $mdConstant.KEY_CODE.SPACE || keyCode === $mdConstant.KEY_CODE.ENTER) {
  5023. ev.preventDefault();
  5024. if (!element.hasClass('md-focused')) { element.addClass('md-focused'); }
  5025. listener(ev);
  5026. }
  5027. }
  5028. function listener(ev) {
  5029. if (element[0].hasAttribute('disabled')) return;
  5030. scope.$apply(function() {
  5031. // Toggle the checkbox value...
  5032. var viewValue = attr.ngChecked ? attr.checked : !ngModelCtrl.$viewValue;
  5033. ngModelCtrl.$setViewValue( viewValue, ev && ev.type);
  5034. ngModelCtrl.$render();
  5035. });
  5036. }
  5037. function render() {
  5038. if(ngModelCtrl.$viewValue) {
  5039. element.addClass(CHECKED_CSS);
  5040. } else {
  5041. element.removeClass(CHECKED_CSS);
  5042. }
  5043. }
  5044. };
  5045. }
  5046. }
  5047. MdCheckboxDirective.$inject = ["inputDirective", "$mdAria", "$mdConstant", "$mdTheming", "$mdUtil", "$timeout"];
  5048. })();
  5049. (function(){
  5050. "use strict";
  5051. /**
  5052. * @ngdoc module
  5053. * @name material.components.chips
  5054. */
  5055. /*
  5056. * @see js folder for chips implementation
  5057. */
  5058. angular.module('material.components.chips', [
  5059. 'material.core',
  5060. 'material.components.autocomplete'
  5061. ]);
  5062. })();
  5063. (function(){
  5064. "use strict";
  5065. /**
  5066. * @ngdoc module
  5067. * @name material.components.content
  5068. *
  5069. * @description
  5070. * Scrollable content
  5071. */
  5072. angular.module('material.components.content', [
  5073. 'material.core'
  5074. ])
  5075. .directive('mdContent', mdContentDirective);
  5076. /**
  5077. * @ngdoc directive
  5078. * @name mdContent
  5079. * @module material.components.content
  5080. *
  5081. * @restrict E
  5082. *
  5083. * @description
  5084. * The `<md-content>` directive is a container element useful for scrollable content
  5085. *
  5086. * @usage
  5087. *
  5088. * - Add the `[layout-padding]` attribute to make the content padded.
  5089. *
  5090. * <hljs lang="html">
  5091. * <md-content layout-padding>
  5092. * Lorem ipsum dolor sit amet, ne quod novum mei.
  5093. * </md-content>
  5094. * </hljs>
  5095. *
  5096. */
  5097. function mdContentDirective($mdTheming) {
  5098. return {
  5099. restrict: 'E',
  5100. controller: ['$scope', '$element', ContentController],
  5101. link: function(scope, element, attr) {
  5102. var node = element[0];
  5103. $mdTheming(element);
  5104. scope.$broadcast('$mdContentLoaded', element);
  5105. iosScrollFix(element[0]);
  5106. }
  5107. };
  5108. function ContentController($scope, $element) {
  5109. this.$scope = $scope;
  5110. this.$element = $element;
  5111. }
  5112. }
  5113. mdContentDirective.$inject = ["$mdTheming"];
  5114. function iosScrollFix(node) {
  5115. // IOS FIX:
  5116. // If we scroll where there is no more room for the webview to scroll,
  5117. // by default the webview itself will scroll up and down, this looks really
  5118. // bad. So if we are scrolling to the very top or bottom, add/subtract one
  5119. angular.element(node).on('$md.pressdown', function(ev) {
  5120. // Only touch events
  5121. if (ev.pointer.type !== 't') return;
  5122. // Don't let a child content's touchstart ruin it for us.
  5123. if (ev.$materialScrollFixed) return;
  5124. ev.$materialScrollFixed = true;
  5125. if (node.scrollTop === 0) {
  5126. node.scrollTop = 1;
  5127. } else if (node.scrollHeight === node.scrollTop + node.offsetHeight) {
  5128. node.scrollTop -= 1;
  5129. }
  5130. });
  5131. }
  5132. })();
  5133. (function(){
  5134. "use strict";
  5135. (function() {
  5136. 'use strict';
  5137. /**
  5138. * @ngdoc module
  5139. * @name material.components.datepicker
  5140. * @description Datepicker
  5141. */
  5142. angular.module('material.components.datepicker', [
  5143. 'material.core',
  5144. 'material.components.icon',
  5145. 'material.components.virtualRepeat'
  5146. ]).directive('mdCalendar', calendarDirective);
  5147. // POST RELEASE
  5148. // TODO(jelbourn): Mac Cmd + left / right == Home / End
  5149. // TODO(jelbourn): Clicking on the month label opens the month-picker.
  5150. // TODO(jelbourn): Minimum and maximum date
  5151. // TODO(jelbourn): Refactor month element creation to use cloneNode (performance).
  5152. // TODO(jelbourn): Define virtual scrolling constants (compactness) users can override.
  5153. // TODO(jelbourn): Animated month transition on ng-model change (virtual-repeat)
  5154. // TODO(jelbourn): Scroll snapping (virtual repeat)
  5155. // TODO(jelbourn): Remove superfluous row from short months (virtual-repeat)
  5156. // TODO(jelbourn): Month headers stick to top when scrolling.
  5157. // TODO(jelbourn): Previous month opacity is lowered when partially scrolled out of view.
  5158. // TODO(jelbourn): Support md-calendar standalone on a page (as a tabstop w/ aria-live
  5159. // announcement and key handling).
  5160. // Read-only calendar (not just date-picker).
  5161. /**
  5162. * Height of one calendar month tbody. This must be made known to the virtual-repeat and is
  5163. * subsequently used for scrolling to specific months.
  5164. */
  5165. var TBODY_HEIGHT = 265;
  5166. /**
  5167. * Height of a calendar month with a single row. This is needed to calculate the offset for
  5168. * rendering an extra month in virtual-repeat that only contains one row.
  5169. */
  5170. var TBODY_SINGLE_ROW_HEIGHT = 45;
  5171. function calendarDirective() {
  5172. return {
  5173. template:
  5174. '<table aria-hidden="true" class="md-calendar-day-header"><thead></thead></table>' +
  5175. '<div class="md-calendar-scroll-mask">' +
  5176. '<md-virtual-repeat-container class="md-calendar-scroll-container" ' +
  5177. 'md-offset-size="' + (TBODY_SINGLE_ROW_HEIGHT - TBODY_HEIGHT) + '">' +
  5178. '<table role="grid" tabindex="0" class="md-calendar" aria-readonly="true">' +
  5179. '<tbody role="rowgroup" md-virtual-repeat="i in ctrl.items" md-calendar-month ' +
  5180. 'md-month-offset="$index" class="md-calendar-month" ' +
  5181. 'md-start-index="ctrl.getSelectedMonthIndex()" ' +
  5182. 'md-item-size="' + TBODY_HEIGHT + '"></tbody>' +
  5183. '</table>' +
  5184. '</md-virtual-repeat-container>' +
  5185. '</div>',
  5186. scope: {
  5187. minDate: '=mdMinDate',
  5188. maxDate: '=mdMaxDate',
  5189. },
  5190. require: ['ngModel', 'mdCalendar'],
  5191. controller: CalendarCtrl,
  5192. controllerAs: 'ctrl',
  5193. bindToController: true,
  5194. link: function(scope, element, attrs, controllers) {
  5195. var ngModelCtrl = controllers[0];
  5196. var mdCalendarCtrl = controllers[1];
  5197. mdCalendarCtrl.configureNgModel(ngModelCtrl);
  5198. }
  5199. };
  5200. }
  5201. /** Class applied to the selected date cell/. */
  5202. var SELECTED_DATE_CLASS = 'md-calendar-selected-date';
  5203. /** Class applied to the focused date cell/. */
  5204. var FOCUSED_DATE_CLASS = 'md-focus';
  5205. /** Next identifier for calendar instance. */
  5206. var nextUniqueId = 0;
  5207. /** The first renderable date in the virtual-scrolling calendar (for all instances). */
  5208. var firstRenderableDate = null;
  5209. /**
  5210. * Controller for the mdCalendar component.
  5211. * @ngInject @constructor
  5212. */
  5213. function CalendarCtrl($element, $attrs, $scope, $animate, $q, $mdConstant,
  5214. $mdTheming, $$mdDateUtil, $mdDateLocale, $mdInkRipple, $mdUtil) {
  5215. $mdTheming($element);
  5216. /**
  5217. * Dummy array-like object for virtual-repeat to iterate over. The length is the total
  5218. * number of months that can be viewed. This is shorter than ideal because of (potential)
  5219. * Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=1181658.
  5220. */
  5221. this.items = {length: 2000};
  5222. if (this.maxDate && this.minDate) {
  5223. // Limit the number of months if min and max dates are set.
  5224. var numMonths = $$mdDateUtil.getMonthDistance(this.minDate, this.maxDate) + 1;
  5225. numMonths = Math.max(numMonths, 1);
  5226. // Add an additional month as the final dummy month for rendering purposes.
  5227. numMonths += 1;
  5228. this.items.length = numMonths;
  5229. }
  5230. /** @final {!angular.$animate} */
  5231. this.$animate = $animate;
  5232. /** @final {!angular.$q} */
  5233. this.$q = $q;
  5234. /** @final */
  5235. this.$mdInkRipple = $mdInkRipple;
  5236. /** @final */
  5237. this.$mdUtil = $mdUtil;
  5238. /** @final */
  5239. this.keyCode = $mdConstant.KEY_CODE;
  5240. /** @final */
  5241. this.dateUtil = $$mdDateUtil;
  5242. /** @final */
  5243. this.dateLocale = $mdDateLocale;
  5244. /** @final {!angular.JQLite} */
  5245. this.$element = $element;
  5246. /** @final {!angular.Scope} */
  5247. this.$scope = $scope;
  5248. /** @final {HTMLElement} */
  5249. this.calendarElement = $element[0].querySelector('.md-calendar');
  5250. /** @final {HTMLElement} */
  5251. this.calendarScroller = $element[0].querySelector('.md-virtual-repeat-scroller');
  5252. /** @final {Date} */
  5253. this.today = this.dateUtil.createDateAtMidnight();
  5254. /** @type {Date} */
  5255. this.firstRenderableDate = this.dateUtil.incrementMonths(this.today, -this.items.length / 2);
  5256. if (this.minDate && this.minDate > this.firstRenderableDate) {
  5257. this.firstRenderableDate = this.minDate;
  5258. } else if (this.maxDate) {
  5259. // Calculate the difference between the start date and max date.
  5260. // Subtract 1 because it's an inclusive difference and 1 for the final dummy month.
  5261. //
  5262. var monthDifference = this.items.length - 2;
  5263. this.firstRenderableDate = this.dateUtil.incrementMonths(this.maxDate, -(this.items.length - 2));
  5264. }
  5265. /** @final {number} Unique ID for this calendar instance. */
  5266. this.id = nextUniqueId++;
  5267. /** @type {!angular.NgModelController} */
  5268. this.ngModelCtrl = null;
  5269. /**
  5270. * The selected date. Keep track of this separately from the ng-model value so that we
  5271. * can know, when the ng-model value changes, what the previous value was before its updated
  5272. * in the component's UI.
  5273. *
  5274. * @type {Date}
  5275. */
  5276. this.selectedDate = null;
  5277. /**
  5278. * The date that is currently focused or showing in the calendar. This will initially be set
  5279. * to the ng-model value if set, otherwise to today. It will be updated as the user navigates
  5280. * to other months. The cell corresponding to the displayDate does not necesarily always have
  5281. * focus in the document (such as for cases when the user is scrolling the calendar).
  5282. * @type {Date}
  5283. */
  5284. this.displayDate = null;
  5285. /**
  5286. * The date that has or should have focus.
  5287. * @type {Date}
  5288. */
  5289. this.focusDate = null;
  5290. /** @type {boolean} */
  5291. this.isInitialized = false;
  5292. /** @type {boolean} */
  5293. this.isMonthTransitionInProgress = false;
  5294. // Unless the user specifies so, the calendar should not be a tab stop.
  5295. // This is necessary because ngAria might add a tabindex to anything with an ng-model
  5296. // (based on whether or not the user has turned that particular feature on/off).
  5297. if (!$attrs['tabindex']) {
  5298. $element.attr('tabindex', '-1');
  5299. }
  5300. var self = this;
  5301. /**
  5302. * Handles a click event on a date cell.
  5303. * Created here so that every cell can use the same function instance.
  5304. * @this {HTMLTableCellElement} The cell that was clicked.
  5305. */
  5306. this.cellClickHandler = function() {
  5307. var cellElement = this;
  5308. if (this.hasAttribute('data-timestamp')) {
  5309. $scope.$apply(function() {
  5310. var timestamp = Number(cellElement.getAttribute('data-timestamp'));
  5311. self.setNgModelValue(self.dateUtil.createDateAtMidnight(timestamp));
  5312. });
  5313. }
  5314. };
  5315. this.attachCalendarEventListeners();
  5316. }
  5317. CalendarCtrl.$inject = ["$element", "$attrs", "$scope", "$animate", "$q", "$mdConstant", "$mdTheming", "$$mdDateUtil", "$mdDateLocale", "$mdInkRipple", "$mdUtil"];
  5318. /*** Initialization ***/
  5319. /**
  5320. * Sets up the controller's reference to ngModelController.
  5321. * @param {!angular.NgModelController} ngModelCtrl
  5322. */
  5323. CalendarCtrl.prototype.configureNgModel = function(ngModelCtrl) {
  5324. this.ngModelCtrl = ngModelCtrl;
  5325. var self = this;
  5326. ngModelCtrl.$render = function() {
  5327. self.changeSelectedDate(self.ngModelCtrl.$viewValue);
  5328. };
  5329. };
  5330. /**
  5331. * Initialize the calendar by building the months that are initially visible.
  5332. * Initialization should occur after the ngModel value is known.
  5333. */
  5334. CalendarCtrl.prototype.buildInitialCalendarDisplay = function() {
  5335. this.buildWeekHeader();
  5336. this.hideVerticalScrollbar();
  5337. this.displayDate = this.selectedDate || this.today;
  5338. this.isInitialized = true;
  5339. };
  5340. /**
  5341. * Hides the vertical scrollbar on the calendar scroller by setting the width on the
  5342. * calendar scroller and the `overflow: hidden` wrapper around the scroller, and then setting
  5343. * a padding-right on the scroller equal to the width of the browser's scrollbar.
  5344. *
  5345. * This will cause a reflow.
  5346. */
  5347. CalendarCtrl.prototype.hideVerticalScrollbar = function() {
  5348. var element = this.$element[0];
  5349. var scrollMask = element.querySelector('.md-calendar-scroll-mask');
  5350. var scroller = this.calendarScroller;
  5351. var headerWidth = element.querySelector('.md-calendar-day-header').clientWidth;
  5352. var scrollbarWidth = scroller.offsetWidth - scroller.clientWidth;
  5353. scrollMask.style.width = headerWidth + 'px';
  5354. scroller.style.width = (headerWidth + scrollbarWidth) + 'px';
  5355. scroller.style.paddingRight = scrollbarWidth + 'px';
  5356. };
  5357. /** Attach event listeners for the calendar. */
  5358. CalendarCtrl.prototype.attachCalendarEventListeners = function() {
  5359. // Keyboard interaction.
  5360. this.$element.on('keydown', angular.bind(this, this.handleKeyEvent));
  5361. };
  5362. /*** User input handling ***/
  5363. /**
  5364. * Handles a key event in the calendar with the appropriate action. The action will either
  5365. * be to select the focused date or to navigate to focus a new date.
  5366. * @param {KeyboardEvent} event
  5367. */
  5368. CalendarCtrl.prototype.handleKeyEvent = function(event) {
  5369. var self = this;
  5370. this.$scope.$apply(function() {
  5371. // Capture escape and emit back up so that a wrapping component
  5372. // (such as a date-picker) can decide to close.
  5373. if (event.which == self.keyCode.ESCAPE || event.which == self.keyCode.TAB) {
  5374. self.$scope.$emit('md-calendar-close');
  5375. if (event.which == self.keyCode.TAB) {
  5376. event.preventDefault();
  5377. }
  5378. return;
  5379. }
  5380. // Remaining key events fall into two categories: selection and navigation.
  5381. // Start by checking if this is a selection event.
  5382. if (event.which === self.keyCode.ENTER) {
  5383. self.setNgModelValue(self.displayDate);
  5384. event.preventDefault();
  5385. return;
  5386. }
  5387. // Selection isn't occuring, so the key event is either navigation or nothing.
  5388. var date = self.getFocusDateFromKeyEvent(event);
  5389. if (date) {
  5390. date = self.boundDateByMinAndMax(date);
  5391. event.preventDefault();
  5392. event.stopPropagation();
  5393. // Since this is a keyboard interaction, actually give the newly focused date keyboard
  5394. // focus after the been brought into view.
  5395. self.changeDisplayDate(date).then(function () {
  5396. self.focus(date);
  5397. });
  5398. }
  5399. });
  5400. };
  5401. /**
  5402. * Gets the date to focus as the result of a key event.
  5403. * @param {KeyboardEvent} event
  5404. * @returns {Date} Date to navigate to, or null if the key does not match a calendar shortcut.
  5405. */
  5406. CalendarCtrl.prototype.getFocusDateFromKeyEvent = function(event) {
  5407. var dateUtil = this.dateUtil;
  5408. var keyCode = this.keyCode;
  5409. switch (event.which) {
  5410. case keyCode.RIGHT_ARROW: return dateUtil.incrementDays(this.displayDate, 1);
  5411. case keyCode.LEFT_ARROW: return dateUtil.incrementDays(this.displayDate, -1);
  5412. case keyCode.DOWN_ARROW:
  5413. return event.metaKey ?
  5414. dateUtil.incrementMonths(this.displayDate, 1) :
  5415. dateUtil.incrementDays(this.displayDate, 7);
  5416. case keyCode.UP_ARROW:
  5417. return event.metaKey ?
  5418. dateUtil.incrementMonths(this.displayDate, -1) :
  5419. dateUtil.incrementDays(this.displayDate, -7);
  5420. case keyCode.PAGE_DOWN: return dateUtil.incrementMonths(this.displayDate, 1);
  5421. case keyCode.PAGE_UP: return dateUtil.incrementMonths(this.displayDate, -1);
  5422. case keyCode.HOME: return dateUtil.getFirstDateOfMonth(this.displayDate);
  5423. case keyCode.END: return dateUtil.getLastDateOfMonth(this.displayDate);
  5424. default: return null;
  5425. }
  5426. };
  5427. /**
  5428. * Gets the "index" of the currently selected date as it would be in the virtual-repeat.
  5429. * @returns {number}
  5430. */
  5431. CalendarCtrl.prototype.getSelectedMonthIndex = function() {
  5432. return this.dateUtil.getMonthDistance(this.firstRenderableDate,
  5433. this.selectedDate || this.today);
  5434. };
  5435. /**
  5436. * Scrolls to the month of the given date.
  5437. * @param {Date} date
  5438. */
  5439. CalendarCtrl.prototype.scrollToMonth = function(date) {
  5440. if (!this.dateUtil.isValidDate(date)) {
  5441. return;
  5442. }
  5443. var monthDistance = this.dateUtil.getMonthDistance(this.firstRenderableDate, date);
  5444. this.calendarScroller.scrollTop = monthDistance * TBODY_HEIGHT;
  5445. };
  5446. /**
  5447. * Sets the ng-model value for the calendar and emits a change event.
  5448. * @param {Date} date
  5449. */
  5450. CalendarCtrl.prototype.setNgModelValue = function(date) {
  5451. this.$scope.$emit('md-calendar-change', date);
  5452. this.ngModelCtrl.$setViewValue(date);
  5453. this.ngModelCtrl.$render();
  5454. };
  5455. /**
  5456. * Focus the cell corresponding to the given date.
  5457. * @param {Date=} opt_date
  5458. */
  5459. CalendarCtrl.prototype.focus = function(opt_date) {
  5460. var date = opt_date || this.selectedDate || this.today;
  5461. var previousFocus = this.calendarElement.querySelector('.md-focus');
  5462. if (previousFocus) {
  5463. previousFocus.classList.remove(FOCUSED_DATE_CLASS);
  5464. }
  5465. var cellId = this.getDateId(date);
  5466. var cell = document.getElementById(cellId);
  5467. if (cell) {
  5468. cell.classList.add(FOCUSED_DATE_CLASS);
  5469. cell.focus();
  5470. } else {
  5471. this.focusDate = date;
  5472. }
  5473. };
  5474. /**
  5475. * If a date exceeds minDate or maxDate, returns date matching minDate or maxDate, respectively.
  5476. * Otherwise, returns the date.
  5477. * @param {Date} date
  5478. * @return {Date}
  5479. */
  5480. CalendarCtrl.prototype.boundDateByMinAndMax = function(date) {
  5481. var boundDate = date;
  5482. if (this.minDate && date < this.minDate) {
  5483. boundDate = new Date(this.minDate.getTime());
  5484. }
  5485. if (this.maxDate && date > this.maxDate) {
  5486. boundDate = new Date(this.maxDate.getTime());
  5487. }
  5488. return boundDate;
  5489. };
  5490. /*** Updating the displayed / selected date ***/
  5491. /**
  5492. * Change the selected date in the calendar (ngModel value has already been changed).
  5493. * @param {Date} date
  5494. */
  5495. CalendarCtrl.prototype.changeSelectedDate = function(date) {
  5496. var self = this;
  5497. var previousSelectedDate = this.selectedDate;
  5498. this.selectedDate = date;
  5499. this.changeDisplayDate(date).then(function() {
  5500. // Remove the selected class from the previously selected date, if any.
  5501. if (previousSelectedDate) {
  5502. var prevDateCell =
  5503. document.getElementById(self.getDateId(previousSelectedDate));
  5504. if (prevDateCell) {
  5505. prevDateCell.classList.remove(SELECTED_DATE_CLASS);
  5506. prevDateCell.setAttribute('aria-selected', 'false');
  5507. }
  5508. }
  5509. // Apply the select class to the new selected date if it is set.
  5510. if (date) {
  5511. var dateCell = document.getElementById(self.getDateId(date));
  5512. if (dateCell) {
  5513. dateCell.classList.add(SELECTED_DATE_CLASS);
  5514. dateCell.setAttribute('aria-selected', 'true');
  5515. }
  5516. }
  5517. });
  5518. };
  5519. /**
  5520. * Change the date that is being shown in the calendar. If the given date is in a different
  5521. * month, the displayed month will be transitioned.
  5522. * @param {Date} date
  5523. */
  5524. CalendarCtrl.prototype.changeDisplayDate = function(date) {
  5525. // Initialization is deferred until this function is called because we want to reflect
  5526. // the starting value of ngModel.
  5527. if (!this.isInitialized) {
  5528. this.buildInitialCalendarDisplay();
  5529. return this.$q.when();
  5530. }
  5531. // If trying to show an invalid date or a transition is in progress, do nothing.
  5532. if (!this.dateUtil.isValidDate(date) || this.isMonthTransitionInProgress) {
  5533. return this.$q.when();
  5534. }
  5535. this.isMonthTransitionInProgress = true;
  5536. var animationPromise = this.animateDateChange(date);
  5537. this.displayDate = date;
  5538. var self = this;
  5539. animationPromise.then(function() {
  5540. self.isMonthTransitionInProgress = false;
  5541. });
  5542. return animationPromise;
  5543. };
  5544. /**
  5545. * Animates the transition from the calendar's current month to the given month.
  5546. * @param {Date} date
  5547. * @returns {angular.$q.Promise} The animation promise.
  5548. */
  5549. CalendarCtrl.prototype.animateDateChange = function(date) {
  5550. this.scrollToMonth(date);
  5551. return this.$q.when();
  5552. };
  5553. /*** Constructing the calendar table ***/
  5554. /**
  5555. * Builds and appends a day-of-the-week header to the calendar.
  5556. * This should only need to be called once during initialization.
  5557. */
  5558. CalendarCtrl.prototype.buildWeekHeader = function() {
  5559. var row = document.createElement('tr');
  5560. for (var i = 0; i < 7; i++) {
  5561. var th = document.createElement('th');
  5562. th.textContent = this.dateLocale.shortDays[i];
  5563. row.appendChild(th);
  5564. }
  5565. this.$element.find('thead').append(row);
  5566. };
  5567. /**
  5568. * Gets an identifier for a date unique to the calendar instance for internal
  5569. * purposes. Not to be displayed.
  5570. * @param {Date} date
  5571. * @returns {string}
  5572. */
  5573. CalendarCtrl.prototype.getDateId = function(date) {
  5574. return [
  5575. 'md',
  5576. this.id,
  5577. date.getFullYear(),
  5578. date.getMonth(),
  5579. date.getDate()
  5580. ].join('-');
  5581. };
  5582. })();
  5583. })();
  5584. (function(){
  5585. "use strict";
  5586. (function() {
  5587. 'use strict';
  5588. angular.module('material.components.datepicker')
  5589. .directive('mdCalendarMonth', mdCalendarMonthDirective);
  5590. /**
  5591. * Private directive consumed by md-calendar. Having this directive lets the calender use
  5592. * md-virtual-repeat and also cleanly separates the month DOM construction functions from
  5593. * the rest of the calendar controller logic.
  5594. */
  5595. function mdCalendarMonthDirective() {
  5596. return {
  5597. require: ['^^mdCalendar', 'mdCalendarMonth'],
  5598. scope: {offset: '=mdMonthOffset'},
  5599. controller: CalendarMonthCtrl,
  5600. controllerAs: 'mdMonthCtrl',
  5601. bindToController: true,
  5602. link: function(scope, element, attrs, controllers) {
  5603. var calendarCtrl = controllers[0];
  5604. var monthCtrl = controllers[1];
  5605. monthCtrl.calendarCtrl = calendarCtrl;
  5606. monthCtrl.generateContent();
  5607. // The virtual-repeat re-uses the same DOM elements, so there are only a limited number
  5608. // of repeated items that are linked, and then those elements have their bindings updataed.
  5609. // Since the months are not generated by bindings, we simply regenerate the entire thing
  5610. // when the binding (offset) changes.
  5611. scope.$watch(function() { return monthCtrl.offset; }, function(offset, oldOffset) {
  5612. if (offset != oldOffset) {
  5613. monthCtrl.generateContent();
  5614. }
  5615. });
  5616. }
  5617. };
  5618. }
  5619. /** Class applied to the cell for today. */
  5620. var TODAY_CLASS = 'md-calendar-date-today';
  5621. /** Class applied to the selected date cell/. */
  5622. var SELECTED_DATE_CLASS = 'md-calendar-selected-date';
  5623. /** Class applied to the focused date cell/. */
  5624. var FOCUSED_DATE_CLASS = 'md-focus';
  5625. /**
  5626. * Controller for a single calendar month.
  5627. * @ngInject @constructor
  5628. */
  5629. function CalendarMonthCtrl($element, $$mdDateUtil, $mdDateLocale) {
  5630. this.dateUtil = $$mdDateUtil;
  5631. this.dateLocale = $mdDateLocale;
  5632. this.$element = $element;
  5633. this.calendarCtrl = null;
  5634. /**
  5635. * Number of months from the start of the month "items" that the currently rendered month
  5636. * occurs. Set via angular data binding.
  5637. * @type {number}
  5638. */
  5639. this.offset;
  5640. /**
  5641. * Date cell to focus after appending the month to the document.
  5642. * @type {HTMLElement}
  5643. */
  5644. this.focusAfterAppend = null;
  5645. }
  5646. CalendarMonthCtrl.$inject = ["$element", "$$mdDateUtil", "$mdDateLocale"];
  5647. /** Generate and append the content for this month to the directive element. */
  5648. CalendarMonthCtrl.prototype.generateContent = function() {
  5649. var calendarCtrl = this.calendarCtrl;
  5650. var date = this.dateUtil.incrementMonths(calendarCtrl.firstRenderableDate, this.offset);
  5651. this.$element.empty();
  5652. this.$element.append(this.buildCalendarForMonth(date));
  5653. if (this.focusAfterAppend) {
  5654. this.focusAfterAppend.classList.add(FOCUSED_DATE_CLASS);
  5655. this.focusAfterAppend.focus();
  5656. this.focusAfterAppend = null;
  5657. }
  5658. };
  5659. /**
  5660. * Creates a single cell to contain a date in the calendar with all appropriate
  5661. * attributes and classes added. If a date is given, the cell content will be set
  5662. * based on the date.
  5663. * @param {Date=} opt_date
  5664. * @returns {HTMLElement}
  5665. */
  5666. CalendarMonthCtrl.prototype.buildDateCell = function(opt_date) {
  5667. var calendarCtrl = this.calendarCtrl;
  5668. // TODO(jelbourn): cloneNode is likely a faster way of doing this.
  5669. var cell = document.createElement('td');
  5670. cell.tabIndex = -1;
  5671. cell.classList.add('md-calendar-date');
  5672. cell.setAttribute('role', 'gridcell');
  5673. if (opt_date) {
  5674. cell.setAttribute('tabindex', '-1');
  5675. cell.setAttribute('aria-label', this.dateLocale.longDateFormatter(opt_date));
  5676. cell.id = calendarCtrl.getDateId(opt_date);
  5677. // Use `data-timestamp` attribute because IE10 does not support the `dataset` property.
  5678. cell.setAttribute('data-timestamp', opt_date.getTime());
  5679. // TODO(jelourn): Doing these comparisons for class addition during generation might be slow.
  5680. // It may be better to finish the construction and then query the node and add the class.
  5681. if (this.dateUtil.isSameDay(opt_date, calendarCtrl.today)) {
  5682. cell.classList.add(TODAY_CLASS);
  5683. }
  5684. if (this.dateUtil.isValidDate(calendarCtrl.selectedDate) &&
  5685. this.dateUtil.isSameDay(opt_date, calendarCtrl.selectedDate)) {
  5686. cell.classList.add(SELECTED_DATE_CLASS);
  5687. cell.setAttribute('aria-selected', 'true');
  5688. }
  5689. var cellText = this.dateLocale.dates[opt_date.getDate()];
  5690. if (this.dateUtil.isDateWithinRange(opt_date,
  5691. this.calendarCtrl.minDate, this.calendarCtrl.maxDate)) {
  5692. // Add a indicator for select, hover, and focus states.
  5693. var selectionIndicator = document.createElement('span');
  5694. cell.appendChild(selectionIndicator);
  5695. selectionIndicator.classList.add('md-calendar-date-selection-indicator');
  5696. selectionIndicator.textContent = cellText;
  5697. cell.addEventListener('click', calendarCtrl.cellClickHandler);
  5698. if (calendarCtrl.focusDate && this.dateUtil.isSameDay(opt_date, calendarCtrl.focusDate)) {
  5699. this.focusAfterAppend = cell;
  5700. }
  5701. } else {
  5702. cell.classList.add('md-calendar-date-disabled');
  5703. cell.textContent = cellText;
  5704. }
  5705. }
  5706. return cell;
  5707. };
  5708. /**
  5709. * Builds a `tr` element for the calendar grid.
  5710. * @param rowNumber The week number within the month.
  5711. * @returns {HTMLElement}
  5712. */
  5713. CalendarMonthCtrl.prototype.buildDateRow = function(rowNumber) {
  5714. var row = document.createElement('tr');
  5715. row.setAttribute('role', 'row');
  5716. // Because of an NVDA bug (with Firefox), the row needs an aria-label in order
  5717. // to prevent the entire row being read aloud when the user moves between rows.
  5718. // See http://community.nvda-project.org/ticket/4643.
  5719. row.setAttribute('aria-label', this.dateLocale.weekNumberFormatter(rowNumber));
  5720. return row;
  5721. };
  5722. /**
  5723. * Builds the <tbody> content for the given date's month.
  5724. * @param {Date=} opt_dateInMonth
  5725. * @returns {DocumentFragment} A document fragment containing the <tr> elements.
  5726. */
  5727. CalendarMonthCtrl.prototype.buildCalendarForMonth = function(opt_dateInMonth) {
  5728. var date = this.dateUtil.isValidDate(opt_dateInMonth) ? opt_dateInMonth : new Date();
  5729. var firstDayOfMonth = this.dateUtil.getFirstDateOfMonth(date);
  5730. var firstDayOfTheWeek = firstDayOfMonth.getDay();
  5731. var numberOfDaysInMonth = this.dateUtil.getNumberOfDaysInMonth(date);
  5732. // Store rows for the month in a document fragment so that we can append them all at once.
  5733. var monthBody = document.createDocumentFragment();
  5734. var rowNumber = 1;
  5735. var row = this.buildDateRow(rowNumber);
  5736. monthBody.appendChild(row);
  5737. // If this is the final month in the list of items, only the first week should render,
  5738. // so we should return immediately after the first row is complete and has been
  5739. // attached to the body.
  5740. var isFinalMonth = this.offset === this.calendarCtrl.items.length - 1;
  5741. // Add a label for the month. If the month starts on a Sun/Mon/Tues, the month label
  5742. // goes on a row above the first of the month. Otherwise, the month label takes up the first
  5743. // two cells of the first row.
  5744. var blankCellOffset = 0;
  5745. var monthLabelCell = document.createElement('td');
  5746. monthLabelCell.classList.add('md-calendar-month-label');
  5747. // If the entire month is after the max date, render the label as a disabled state.
  5748. if (this.calendarCtrl.maxDate && firstDayOfMonth > this.calendarCtrl.maxDate) {
  5749. monthLabelCell.classList.add('md-calendar-month-label-disabled');
  5750. }
  5751. monthLabelCell.textContent = this.dateLocale.monthHeaderFormatter(date);
  5752. if (firstDayOfTheWeek <= 2) {
  5753. monthLabelCell.setAttribute('colspan', '7');
  5754. var monthLabelRow = this.buildDateRow();
  5755. monthLabelRow.appendChild(monthLabelCell);
  5756. monthBody.insertBefore(monthLabelRow, row);
  5757. if (isFinalMonth) {
  5758. return monthBody;
  5759. }
  5760. } else {
  5761. blankCellOffset = 2;
  5762. monthLabelCell.setAttribute('colspan', '2');
  5763. row.appendChild(monthLabelCell);
  5764. }
  5765. // Add a blank cell for each day of the week that occurs before the first of the month.
  5766. // For example, if the first day of the month is a Tuesday, add blank cells for Sun and Mon.
  5767. // The blankCellOffset is needed in cases where the first N cells are used by the month label.
  5768. for (var i = blankCellOffset; i < firstDayOfTheWeek; i++) {
  5769. row.appendChild(this.buildDateCell());
  5770. }
  5771. // Add a cell for each day of the month, keeping track of the day of the week so that
  5772. // we know when to start a new row.
  5773. var dayOfWeek = firstDayOfTheWeek;
  5774. var iterationDate = firstDayOfMonth;
  5775. for (var d = 1; d <= numberOfDaysInMonth; d++) {
  5776. // If we've reached the end of the week, start a new row.
  5777. if (dayOfWeek === 7) {
  5778. // We've finished the first row, so we're done if this is the final month.
  5779. if (isFinalMonth) {
  5780. return monthBody;
  5781. }
  5782. dayOfWeek = 0;
  5783. rowNumber++;
  5784. row = this.buildDateRow(rowNumber);
  5785. monthBody.appendChild(row);
  5786. }
  5787. iterationDate.setDate(d);
  5788. var cell = this.buildDateCell(iterationDate);
  5789. row.appendChild(cell);
  5790. dayOfWeek++;
  5791. }
  5792. // Ensure that the last row of the month has 7 cells.
  5793. while (row.childNodes.length < 7) {
  5794. row.appendChild(this.buildDateCell());
  5795. }
  5796. // Ensure that all months have 6 rows. This is necessary for now because the virtual-repeat
  5797. // requires that all items have exactly the same height.
  5798. while (monthBody.childNodes.length < 6) {
  5799. var whitespaceRow = this.buildDateRow();
  5800. for (var i = 0; i < 7; i++) {
  5801. whitespaceRow.appendChild(this.buildDateCell());
  5802. }
  5803. monthBody.appendChild(whitespaceRow);
  5804. }
  5805. return monthBody;
  5806. };
  5807. })();
  5808. })();
  5809. (function(){
  5810. "use strict";
  5811. (function() {
  5812. 'use strict';
  5813. /**
  5814. * @ngdoc service
  5815. * @name $mdDateLocaleProvider
  5816. * @module material.components.datepicker
  5817. *
  5818. * @description
  5819. * The `$mdDateLocaleProvider` is the provider that creates the `$mdDateLocale` service.
  5820. * This provider that allows the user to specify messages, formatters, and parsers for date
  5821. * internationalization. The `$mdDateLocale` service itself is consumed by Angular Material
  5822. * components that that deal with dates.
  5823. *
  5824. * @property {(Array<string>)=} months Array of month names (in order).
  5825. * @property {(Array<string>)=} shortMonths Array of abbreviated month names.
  5826. * @property {(Array<string>)=} days Array of the days of the week (in order).
  5827. * @property {(Array<string>)=} shortDays Array of abbreviated dayes of the week.
  5828. * @property {(Array<string>)=} dates Array of dates of the month. Only necessary for locales
  5829. * using a numeral system other than [1, 2, 3...].
  5830. * @property {(function(string): Date)=} parseDate Function to parse a date object from a string.
  5831. * @property {(function(Date): string)=} formatDate Function to format a date object to a string.
  5832. * @property {(function(Date): string)=} monthHeaderFormatter Function that returns the label for
  5833. * a month given a date.
  5834. * @property {(function(number): string)=} weekNumberFormatter Function that returns a label for
  5835. * a week given the week number.
  5836. * @property {(string)=} msgCalendar Translation of the label "Calendar" for the current locale.
  5837. * @property {(string)=} msgOpenCalendar Translation of the button label "Open calendar" for the
  5838. * current locale.
  5839. *
  5840. * @usage
  5841. * <hljs lang="js">
  5842. * myAppModule.config(function($mdDateLocaleProvider) {
  5843. *
  5844. * // Example of a French localization.
  5845. * $mdDateLocaleProvider.months = ['janvier', 'février', 'mars', ...];
  5846. * $mdDateLocaleProvider.shortMonths = ['janv', 'févr', 'mars', ...];
  5847. * $mdDateLocaleProvider.days = ['dimanche', 'lundi', 'mardi', ...];
  5848. * $mdDateLocaleProvider.shortDays = ['Di', 'Lu', 'Ma', ...];
  5849. *
  5850. * // Optional.
  5851. * $mdDateLocaleProvider.dates = [1, 2, 3, 4, 5, 6, ...];
  5852. *
  5853. * // Example uses moment.js to parse and format dates.
  5854. * $mdDateLocaleProvider.parseDate = function(dateString) {
  5855. * return moment(dateString).toDate();
  5856. * };
  5857. *
  5858. * $mdDateLocaleProvider.formatDate = function(date) {
  5859. * return moment(date).format('L');
  5860. * };
  5861. *
  5862. * $mdDateLocaleProvider.monthHeaderFormatter = function(date) {
  5863. * myShortMonths[date.getMonth()] + ' ' + date.getFullYear();
  5864. * };
  5865. *
  5866. * // In addition to date display, date components also need localized messages
  5867. * // for aria-labels for screen-reader users.
  5868. *
  5869. * $mdDateLocaleProvider.weekNumberFormatter = function(weekNumber) {
  5870. * return 'Semaine ' + weekNumber;
  5871. * };
  5872. *
  5873. * $mdDateLocaleProvider.msgCalendar = 'Calendrier';
  5874. * $mdDateLocaleProvider.msgOpenCalendar = 'Ouvrir le calendrier';
  5875. *
  5876. * });
  5877. * </hljs>
  5878. *
  5879. */
  5880. angular.module('material.components.datepicker').config(["$provide", function($provide) {
  5881. // TODO(jelbourn): Assert provided values are correctly formatted. Need assertions.
  5882. /** @constructor */
  5883. function DateLocaleProvider() {
  5884. /** Array of full month names. E.g., ['January', 'Febuary', ...] */
  5885. this.months = null;
  5886. /** Array of abbreviated month names. E.g., ['Jan', 'Feb', ...] */
  5887. this.shortMonths = null;
  5888. /** Array of full day of the week names. E.g., ['Monday', 'Tuesday', ...] */
  5889. this.days = null;
  5890. /** Array of abbreviated dat of the week names. E.g., ['M', 'T', ...] */
  5891. this.shortDays = null;
  5892. /** Array of dates of a month (1 - 31). Characters might be different in some locales. */
  5893. this.dates = null;
  5894. /**
  5895. * Function that converts the date portion of a Date to a string.
  5896. * @type {(function(Date): string)}
  5897. */
  5898. this.formatDate = null;
  5899. /**
  5900. * Function that converts a date string to a Date object (the date portion)
  5901. * @type {function(string): Date}
  5902. */
  5903. this.parseDate = null;
  5904. /**
  5905. * Function that formats a Date into a month header string.
  5906. * @type {function(Date): string}
  5907. */
  5908. this.monthHeaderFormatter = null;
  5909. /**
  5910. * Function that formats a week number into a label for the week.
  5911. * @type {function(number): string}
  5912. */
  5913. this.weekNumberFormatter = null;
  5914. /**
  5915. * Function that formats a date into a long aria-label that is read
  5916. * when the focused date changes.
  5917. * @type {function(Date): string}
  5918. */
  5919. this.longDateFormatter = null;
  5920. /**
  5921. * ARIA label for the calendar "dialog" used in the datepicker.
  5922. * @type {string}
  5923. */
  5924. this.msgCalendar = '';
  5925. /**
  5926. * ARIA label for the datepicker's "Open calendar" buttons.
  5927. * @type {string}
  5928. */
  5929. this.msgOpenCalendar = '';
  5930. }
  5931. /**
  5932. * Factory function that returns an instance of the dateLocale service.
  5933. * @ngInject
  5934. * @param $locale
  5935. * @returns {DateLocale}
  5936. */
  5937. DateLocaleProvider.prototype.$get = function($locale) {
  5938. /**
  5939. * Default date-to-string formatting function.
  5940. * @param {!Date} date
  5941. * @returns {string}
  5942. */
  5943. function defaultFormatDate(date) {
  5944. return date ? date.toLocaleDateString() : '';
  5945. }
  5946. /**
  5947. * Default string-to-date parsing function.
  5948. * @param {string} dateString
  5949. * @returns {!Date}
  5950. */
  5951. function defaultParseDate(dateString) {
  5952. return new Date(dateString);
  5953. }
  5954. /**
  5955. * Default function to determine whether a string makes sense to be
  5956. * parsed to a Date object.
  5957. *
  5958. * This is very permissive and is just a basic sanity check to ensure that
  5959. * things like single integers aren't able to be parsed into dates.
  5960. * @param {string} dateString
  5961. * @returns {boolean}
  5962. */
  5963. function defaultIsDateComplete(dateString) {
  5964. dateString = dateString.trim();
  5965. // Looks for three chunks of content (either numbers or text) separated
  5966. // by delimiters.
  5967. var re = /^(([a-zA-Z]{3,}|[0-9]{1,4})([ \.,]+|[\/\-])){2}([a-zA-Z]{3,}|[0-9]{1,4})$/;
  5968. return re.test(dateString);
  5969. }
  5970. /**
  5971. * Default date-to-string formatter to get a month header.
  5972. * @param {!Date} date
  5973. * @returns {string}
  5974. */
  5975. function defaultMonthHeaderFormatter(date) {
  5976. return service.shortMonths[date.getMonth()] + ' ' + date.getFullYear();
  5977. }
  5978. /**
  5979. * Default week number formatter.
  5980. * @param number
  5981. * @returns {string}
  5982. */
  5983. function defaultWeekNumberFormatter(number) {
  5984. return 'Week ' + number;
  5985. }
  5986. /**
  5987. * Default formatter for date cell aria-labels.
  5988. * @param {!Date} date
  5989. * @returns {string}
  5990. */
  5991. function defaultLongDateFormatter(date) {
  5992. // Example: 'Thursday June 18 2015'
  5993. return [
  5994. service.days[date.getDay()],
  5995. service.months[date.getMonth()],
  5996. service.dates[date.getDate()],
  5997. date.getFullYear()
  5998. ].join(' ');
  5999. }
  6000. // The default "short" day strings are the first character of each day,
  6001. // e.g., "Monday" => "M".
  6002. var defaultShortDays = $locale.DATETIME_FORMATS.DAY.map(function(day) {
  6003. return day[0];
  6004. });
  6005. // The default dates are simply the numbers 1 through 31.
  6006. var defaultDates = Array(32);
  6007. for (var i = 1; i <= 31; i++) {
  6008. defaultDates[i] = i;
  6009. }
  6010. // Default ARIA messages are in English (US).
  6011. var defaultMsgCalendar = 'Calendar';
  6012. var defaultMsgOpenCalendar = 'Open calendar';
  6013. var service = {
  6014. months: this.months || $locale.DATETIME_FORMATS.MONTH,
  6015. shortMonths: this.shortMonths || $locale.DATETIME_FORMATS.SHORTMONTH,
  6016. days: this.days || $locale.DATETIME_FORMATS.DAY,
  6017. shortDays: this.shortDays || defaultShortDays,
  6018. dates: this.dates || defaultDates,
  6019. formatDate: this.formatDate || defaultFormatDate,
  6020. parseDate: this.parseDate || defaultParseDate,
  6021. isDateComplete: this.isDateComplete || defaultIsDateComplete,
  6022. monthHeaderFormatter: this.monthHeaderFormatter || defaultMonthHeaderFormatter,
  6023. weekNumberFormatter: this.weekNumberFormatter || defaultWeekNumberFormatter,
  6024. longDateFormatter: this.longDateFormatter || defaultLongDateFormatter,
  6025. msgCalendar: this.msgCalendar || defaultMsgCalendar,
  6026. msgOpenCalendar: this.msgOpenCalendar || defaultMsgOpenCalendar
  6027. };
  6028. return service;
  6029. };
  6030. DateLocaleProvider.prototype.$get.$inject = ["$locale"];
  6031. $provide.provider('$mdDateLocale', new DateLocaleProvider());
  6032. }]);
  6033. })();
  6034. })();
  6035. (function(){
  6036. "use strict";
  6037. (function() {
  6038. 'use strict';
  6039. // POST RELEASE
  6040. // TODO(jelbourn): Demo that uses moment.js
  6041. // TODO(jelbourn): make sure this plays well with validation and ngMessages.
  6042. // TODO(jelbourn): calendar pane doesn't open up outside of visible viewport.
  6043. // TODO(jelbourn): forward more attributes to the internal input (required, autofocus, etc.)
  6044. // TODO(jelbourn): something better for mobile (calendar panel takes up entire screen?)
  6045. // TODO(jelbourn): input behavior (masking? auto-complete?)
  6046. // TODO(jelbourn): UTC mode
  6047. // TODO(jelbourn): RTL
  6048. angular.module('material.components.datepicker')
  6049. .directive('mdDatepicker', datePickerDirective);
  6050. /**
  6051. * @ngdoc directive
  6052. * @name mdDatepicker
  6053. * @module material.components.datepicker
  6054. *
  6055. * @param {Date} ng-model The component's model. Expects a JavaScript Date object.
  6056. * @param {expression=} ng-change Expression evaluated when the model value changes.
  6057. * @param {expression=} md-min-date Expression representing a min date (inclusive).
  6058. * @param {expression=} md-max-date Expression representing a max date (inclusive).
  6059. * @param {boolean=} disabled Whether the datepicker is disabled.
  6060. *
  6061. * @description
  6062. * `<md-datepicker>` is a component used to select a single date.
  6063. * For information on how to configure internationalization for the date picker,
  6064. * see `$mdDateLocaleProvider`.
  6065. *
  6066. * @usage
  6067. * <hljs lang="html">
  6068. * <md-datepicker ng-model="birthday"></md-datepicker>
  6069. * </hljs>
  6070. *
  6071. */
  6072. function datePickerDirective() {
  6073. return {
  6074. template:
  6075. // Buttons are not in the tab order because users can open the calendar via keyboard
  6076. // interaction on the text input, and multiple tab stops for one component (picker)
  6077. // may be confusing.
  6078. '<md-button class="md-datepicker-button md-icon-button" type="button" ' +
  6079. 'tabindex="-1" aria-hidden="true" ' +
  6080. 'ng-click="ctrl.openCalendarPane($event)">' +
  6081. '<md-icon class="md-datepicker-calendar-icon" md-svg-icon="md-calendar"></md-icon>' +
  6082. '</md-button>' +
  6083. '<div class="md-datepicker-input-container" ' +
  6084. 'ng-class="{\'md-datepicker-focused\': ctrl.isFocused}">' +
  6085. '<input class="md-datepicker-input" aria-haspopup="true" ' +
  6086. 'ng-focus="ctrl.setFocused(true)" ng-blur="ctrl.setFocused(false)">' +
  6087. '<md-button type="button" md-no-ink ' +
  6088. 'class="md-datepicker-triangle-button md-icon-button" ' +
  6089. 'ng-click="ctrl.openCalendarPane($event)" ' +
  6090. 'aria-label="{{::ctrl.dateLocale.msgOpenCalendar}}">' +
  6091. '<div class="md-datepicker-expand-triangle"></div>' +
  6092. '</md-button>' +
  6093. '</div>' +
  6094. // This pane will be detached from here and re-attached to the document body.
  6095. '<div class="md-datepicker-calendar-pane md-whiteframe-z1">' +
  6096. '<div class="md-datepicker-input-mask">' +
  6097. '<div class="md-datepicker-input-mask-opaque"></div>' +
  6098. '</div>' +
  6099. '<div class="md-datepicker-calendar">' +
  6100. '<md-calendar role="dialog" aria-label="{{::ctrl.dateLocale.msgCalendar}}" ' +
  6101. 'md-min-date="ctrl.minDate" md-max-date="ctrl.maxDate"' +
  6102. 'ng-model="ctrl.date" ng-if="ctrl.isCalendarOpen">' +
  6103. '</md-calendar>' +
  6104. '</div>' +
  6105. '</div>',
  6106. require: ['ngModel', 'mdDatepicker'],
  6107. scope: {
  6108. minDate: '=mdMinDate',
  6109. maxDate: '=mdMaxDate',
  6110. placeholder: '@mdPlaceholder'
  6111. },
  6112. controller: DatePickerCtrl,
  6113. controllerAs: 'ctrl',
  6114. bindToController: true,
  6115. link: function(scope, element, attr, controllers) {
  6116. var ngModelCtrl = controllers[0];
  6117. var mdDatePickerCtrl = controllers[1];
  6118. mdDatePickerCtrl.configureNgModel(ngModelCtrl);
  6119. }
  6120. };
  6121. }
  6122. /** Additional offset for the input's `size` attribute, which is updated based on its content. */
  6123. var EXTRA_INPUT_SIZE = 3;
  6124. /** Class applied to the container if the date is invalid. */
  6125. var INVALID_CLASS = 'md-datepicker-invalid';
  6126. /** Default time in ms to debounce input event by. */
  6127. var DEFAULT_DEBOUNCE_INTERVAL = 500;
  6128. /**
  6129. * Controller for md-datepicker.
  6130. *
  6131. * @ngInject @constructor
  6132. */
  6133. function DatePickerCtrl($scope, $element, $attrs, $compile, $timeout, $mdConstant, $mdTheming,
  6134. $mdUtil, $mdDateLocale, $$mdDateUtil, $$rAF) {
  6135. /** @final */
  6136. this.$compile = $compile;
  6137. /** @final */
  6138. this.$timeout = $timeout;
  6139. /** @final */
  6140. this.dateLocale = $mdDateLocale;
  6141. /** @final */
  6142. this.dateUtil = $$mdDateUtil;
  6143. /** @final */
  6144. this.$mdConstant = $mdConstant;
  6145. /* @final */
  6146. this.$mdUtil = $mdUtil;
  6147. /** @final */
  6148. this.$$rAF = $$rAF;
  6149. /** @type {!angular.NgModelController} */
  6150. this.ngModelCtrl = null;
  6151. /** @type {HTMLInputElement} */
  6152. this.inputElement = $element[0].querySelector('input');
  6153. /** @final {!angular.JQLite} */
  6154. this.ngInputElement = angular.element(this.inputElement);
  6155. /** @type {HTMLElement} */
  6156. this.inputContainer = $element[0].querySelector('.md-datepicker-input-container');
  6157. /** @type {HTMLElement} Floating calendar pane. */
  6158. this.calendarPane = $element[0].querySelector('.md-datepicker-calendar-pane');
  6159. /** @type {HTMLElement} Calendar icon button. */
  6160. this.calendarButton = $element[0].querySelector('.md-datepicker-button');
  6161. /**
  6162. * Element covering everything but the input in the top of the floating calendar pane.
  6163. * @type {HTMLElement}
  6164. */
  6165. this.inputMask = $element[0].querySelector('.md-datepicker-input-mask-opaque');
  6166. /** @final {!angular.JQLite} */
  6167. this.$element = $element;
  6168. /** @final {!angular.Attributes} */
  6169. this.$attrs = $attrs;
  6170. /** @final {!angular.Scope} */
  6171. this.$scope = $scope;
  6172. /** @type {Date} */
  6173. this.date = null;
  6174. /** @type {boolean} */
  6175. this.isFocused = false;
  6176. /** @type {boolean} */
  6177. this.isDisabled;
  6178. this.setDisabled($element[0].disabled || angular.isString($attrs['disabled']));
  6179. /** @type {boolean} Whether the date-picker's calendar pane is open. */
  6180. this.isCalendarOpen = false;
  6181. /**
  6182. * Element from which the calendar pane was opened. Keep track of this so that we can return
  6183. * focus to it when the pane is closed.
  6184. * @type {HTMLElement}
  6185. */
  6186. this.calendarPaneOpenedFrom = null;
  6187. this.calendarPane.id = 'md-date-pane' + $mdUtil.nextUid();
  6188. $mdTheming($element);
  6189. /** Pre-bound click handler is saved so that the event listener can be removed. */
  6190. this.bodyClickHandler = angular.bind(this, this.handleBodyClick);
  6191. // Unless the user specifies so, the datepicker should not be a tab stop.
  6192. // This is necessary because ngAria might add a tabindex to anything with an ng-model
  6193. // (based on whether or not the user has turned that particular feature on/off).
  6194. if (!$attrs['tabindex']) {
  6195. $element.attr('tabindex', '-1');
  6196. }
  6197. this.installPropertyInterceptors();
  6198. this.attachChangeListeners();
  6199. this.attachInteractionListeners();
  6200. var self = this;
  6201. $scope.$on('$destroy', function() {
  6202. self.detachCalendarPane();
  6203. });
  6204. }
  6205. DatePickerCtrl.$inject = ["$scope", "$element", "$attrs", "$compile", "$timeout", "$mdConstant", "$mdTheming", "$mdUtil", "$mdDateLocale", "$$mdDateUtil", "$$rAF"];
  6206. /**
  6207. * Sets up the controller's reference to ngModelController.
  6208. * @param {!angular.NgModelController} ngModelCtrl
  6209. */
  6210. DatePickerCtrl.prototype.configureNgModel = function(ngModelCtrl) {
  6211. this.ngModelCtrl = ngModelCtrl;
  6212. var self = this;
  6213. ngModelCtrl.$render = function() {
  6214. self.date = self.ngModelCtrl.$viewValue;
  6215. self.inputElement.value = self.dateLocale.formatDate(self.date);
  6216. self.resizeInputElement();
  6217. };
  6218. };
  6219. /**
  6220. * Attach event listeners for both the text input and the md-calendar.
  6221. * Events are used instead of ng-model so that updates don't infinitely update the other
  6222. * on a change. This should also be more performant than using a $watch.
  6223. */
  6224. DatePickerCtrl.prototype.attachChangeListeners = function() {
  6225. var self = this;
  6226. self.$scope.$on('md-calendar-change', function(event, date) {
  6227. self.ngModelCtrl.$setViewValue(date);
  6228. self.date = date;
  6229. self.inputElement.value = self.dateLocale.formatDate(date);
  6230. self.closeCalendarPane();
  6231. self.resizeInputElement();
  6232. self.inputContainer.classList.remove(INVALID_CLASS);
  6233. });
  6234. self.ngInputElement.on('input', angular.bind(self, self.resizeInputElement));
  6235. // TODO(chenmike): Add ability for users to specify this interval.
  6236. self.ngInputElement.on('input', self.$mdUtil.debounce(self.handleInputEvent,
  6237. DEFAULT_DEBOUNCE_INTERVAL, self));
  6238. };
  6239. /** Attach event listeners for user interaction. */
  6240. DatePickerCtrl.prototype.attachInteractionListeners = function() {
  6241. var self = this;
  6242. var $scope = this.$scope;
  6243. var keyCodes = this.$mdConstant.KEY_CODE;
  6244. // Add event listener through angular so that we can triggerHandler in unit tests.
  6245. self.ngInputElement.on('keydown', function(event) {
  6246. if (event.altKey && event.keyCode == keyCodes.DOWN_ARROW) {
  6247. self.openCalendarPane(event);
  6248. $scope.$digest();
  6249. }
  6250. });
  6251. $scope.$on('md-calendar-close', function() {
  6252. self.closeCalendarPane();
  6253. });
  6254. };
  6255. /**
  6256. * Capture properties set to the date-picker and imperitively handle internal changes.
  6257. * This is done to avoid setting up additional $watches.
  6258. */
  6259. DatePickerCtrl.prototype.installPropertyInterceptors = function() {
  6260. var self = this;
  6261. if (this.$attrs['ngDisabled']) {
  6262. // The expression is to be evaluated against the directive element's scope and not
  6263. // the directive's isolate scope.
  6264. this.$element.scope().$watch(this.$attrs['ngDisabled'], function(isDisabled) {
  6265. self.setDisabled(isDisabled);
  6266. });
  6267. }
  6268. Object.defineProperty(this, 'placeholder', {
  6269. get: function() { return self.inputElement.placeholder; },
  6270. set: function(value) { self.inputElement.placeholder = value || ''; }
  6271. });
  6272. };
  6273. /**
  6274. * Sets whether the date-picker is disabled.
  6275. * @param {boolean} isDisabled
  6276. */
  6277. DatePickerCtrl.prototype.setDisabled = function(isDisabled) {
  6278. this.isDisabled = isDisabled;
  6279. this.inputElement.disabled = isDisabled;
  6280. this.calendarButton.disabled = isDisabled;
  6281. };
  6282. /**
  6283. * Resizes the input element based on the size of its content.
  6284. */
  6285. DatePickerCtrl.prototype.resizeInputElement = function() {
  6286. this.inputElement.size = this.inputElement.value.length + EXTRA_INPUT_SIZE;
  6287. };
  6288. /**
  6289. * Sets the model value if the user input is a valid date.
  6290. * Adds an invalid class to the input element if not.
  6291. */
  6292. DatePickerCtrl.prototype.handleInputEvent = function() {
  6293. var inputString = this.inputElement.value;
  6294. var parsedDate = this.dateLocale.parseDate(inputString);
  6295. this.dateUtil.setDateTimeToMidnight(parsedDate);
  6296. if (this.dateUtil.isValidDate(parsedDate) &&
  6297. this.dateLocale.isDateComplete(inputString) &&
  6298. this.dateUtil.isDateWithinRange(parsedDate, this.minDate, this.maxDate)) {
  6299. this.ngModelCtrl.$setViewValue(parsedDate);
  6300. this.date = parsedDate;
  6301. this.inputContainer.classList.remove(INVALID_CLASS);
  6302. } else {
  6303. // If there's an input string, it's an invalid date.
  6304. this.inputContainer.classList.toggle(INVALID_CLASS, inputString);
  6305. }
  6306. };
  6307. /** Position and attach the floating calendar to the document. */
  6308. DatePickerCtrl.prototype.attachCalendarPane = function() {
  6309. var calendarPane = this.calendarPane;
  6310. this.$element.addClass('md-datepicker-open');
  6311. var elementRect = this.inputContainer.getBoundingClientRect();
  6312. var bodyRect = document.body.getBoundingClientRect();
  6313. calendarPane.style.left = (elementRect.left - bodyRect.left) + 'px';
  6314. calendarPane.style.top = (elementRect.top - bodyRect.top) + 'px';
  6315. document.body.appendChild(this.calendarPane);
  6316. // The top of the calendar pane is a transparent box that shows the text input underneath.
  6317. // Since the pane is flowing, though, the page underneath the pane *adjacent* to the input is
  6318. // also shown unless we cover it up. The inputMask does this by filling up the remaining space
  6319. // based on the width of the input.
  6320. this.inputMask.style.left = elementRect.width + 'px';
  6321. // Add CSS class after one frame to trigger open animation.
  6322. this.$$rAF(function() {
  6323. calendarPane.classList.add('md-pane-open');
  6324. });
  6325. };
  6326. /** Detach the floating calendar pane from the document. */
  6327. DatePickerCtrl.prototype.detachCalendarPane = function() {
  6328. this.$element.removeClass('md-datepicker-open');
  6329. this.calendarPane.classList.remove('md-pane-open');
  6330. if (this.calendarPane.parentNode) {
  6331. // Use native DOM removal because we do not want any of the angular state of this element
  6332. // to be disposed.
  6333. this.calendarPane.parentNode.removeChild(this.calendarPane);
  6334. }
  6335. };
  6336. /**
  6337. * Open the floating calendar pane.
  6338. * @param {Event} event
  6339. */
  6340. DatePickerCtrl.prototype.openCalendarPane = function(event) {
  6341. if (!this.isCalendarOpen && !this.isDisabled) {
  6342. this.isCalendarOpen = true;
  6343. this.calendarPaneOpenedFrom = event.target;
  6344. this.attachCalendarPane();
  6345. this.focusCalendar();
  6346. // Because the calendar pane is attached directly to the body, it is possible that the
  6347. // rest of the component (input, etc) is in a different scrolling container, such as
  6348. // an md-content. This means that, if the container is scrolled, the pane would remain
  6349. // stationary. To remedy this, we disable scrolling while the calendar pane is open, which
  6350. // also matches the native behavior for things like `<select>` on Mac and Windows.
  6351. this.$mdUtil.disableScrollAround(this.calendarPane);
  6352. // Attach click listener inside of a timeout because, if this open call was triggered by a
  6353. // click, we don't want it to be immediately propogated up to the body and handled.
  6354. var self = this;
  6355. this.$mdUtil.nextTick(function() {
  6356. document.body.addEventListener('click', self.bodyClickHandler);
  6357. }, false);
  6358. }
  6359. };
  6360. /** Close the floating calendar pane. */
  6361. DatePickerCtrl.prototype.closeCalendarPane = function() {
  6362. this.isCalendarOpen = false;
  6363. this.detachCalendarPane();
  6364. this.calendarPaneOpenedFrom.focus();
  6365. this.calendarPaneOpenedFrom = null;
  6366. this.$mdUtil.enableScrolling();
  6367. document.body.removeEventListener('click', this.bodyClickHandler);
  6368. };
  6369. /** Gets the controller instance for the calendar in the floating pane. */
  6370. DatePickerCtrl.prototype.getCalendarCtrl = function() {
  6371. return angular.element(this.calendarPane.querySelector('md-calendar')).controller('mdCalendar');
  6372. };
  6373. /** Focus the calendar in the floating pane. */
  6374. DatePickerCtrl.prototype.focusCalendar = function() {
  6375. // Use a timeout in order to allow the calendar to be rendered, as it is gated behind an ng-if.
  6376. var self = this;
  6377. this.$mdUtil.nextTick(function() {
  6378. self.getCalendarCtrl().focus();
  6379. }, false);
  6380. };
  6381. /**
  6382. * Sets whether the input is currently focused.
  6383. * @param {boolean} isFocused
  6384. */
  6385. DatePickerCtrl.prototype.setFocused = function(isFocused) {
  6386. this.isFocused = isFocused;
  6387. };
  6388. /**
  6389. * Handles a click on the document body when the floating calendar pane is open.
  6390. * Closes the floating calendar pane if the click is not inside of it.
  6391. * @param {MouseEvent} event
  6392. */
  6393. DatePickerCtrl.prototype.handleBodyClick = function(event) {
  6394. if (this.isCalendarOpen) {
  6395. // TODO(jelbourn): way want to also include the md-datepicker itself in this check.
  6396. var isInCalendar = this.$mdUtil.getClosest(event.target, 'md-calendar');
  6397. if (!isInCalendar) {
  6398. this.closeCalendarPane();
  6399. }
  6400. this.$scope.$digest();
  6401. }
  6402. };
  6403. })();
  6404. })();
  6405. (function(){
  6406. "use strict";
  6407. (function() {
  6408. 'use strict';
  6409. /**
  6410. * Utility for performing date calculations to facilitate operation of the calendar and
  6411. * datepicker.
  6412. */
  6413. angular.module('material.components.datepicker').factory('$$mdDateUtil', function() {
  6414. return {
  6415. getFirstDateOfMonth: getFirstDateOfMonth,
  6416. getNumberOfDaysInMonth: getNumberOfDaysInMonth,
  6417. getDateInNextMonth: getDateInNextMonth,
  6418. getDateInPreviousMonth: getDateInPreviousMonth,
  6419. isInNextMonth: isInNextMonth,
  6420. isInPreviousMonth: isInPreviousMonth,
  6421. getDateMidpoint: getDateMidpoint,
  6422. isSameMonthAndYear: isSameMonthAndYear,
  6423. getWeekOfMonth: getWeekOfMonth,
  6424. incrementDays: incrementDays,
  6425. incrementMonths: incrementMonths,
  6426. getLastDateOfMonth: getLastDateOfMonth,
  6427. isSameDay: isSameDay,
  6428. getMonthDistance: getMonthDistance,
  6429. isValidDate: isValidDate,
  6430. setDateTimeToMidnight: setDateTimeToMidnight,
  6431. createDateAtMidnight: createDateAtMidnight,
  6432. isDateWithinRange: isDateWithinRange
  6433. };
  6434. /**
  6435. * Gets the first day of the month for the given date's month.
  6436. * @param {Date} date
  6437. * @returns {Date}
  6438. */
  6439. function getFirstDateOfMonth(date) {
  6440. return new Date(date.getFullYear(), date.getMonth(), 1);
  6441. }
  6442. /**
  6443. * Gets the number of days in the month for the given date's month.
  6444. * @param date
  6445. * @returns {number}
  6446. */
  6447. function getNumberOfDaysInMonth(date) {
  6448. return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
  6449. }
  6450. /**
  6451. * Get an arbitrary date in the month after the given date's month.
  6452. * @param date
  6453. * @returns {Date}
  6454. */
  6455. function getDateInNextMonth(date) {
  6456. return new Date(date.getFullYear(), date.getMonth() + 1, 1);
  6457. }
  6458. /**
  6459. * Get an arbitrary date in the month before the given date's month.
  6460. * @param date
  6461. * @returns {Date}
  6462. */
  6463. function getDateInPreviousMonth(date) {
  6464. return new Date(date.getFullYear(), date.getMonth() - 1, 1);
  6465. }
  6466. /**
  6467. * Gets whether two dates have the same month and year.
  6468. * @param {Date} d1
  6469. * @param {Date} d2
  6470. * @returns {boolean}
  6471. */
  6472. function isSameMonthAndYear(d1, d2) {
  6473. return d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth();
  6474. }
  6475. /**
  6476. * Gets whether two dates are the same day (not not necesarily the same time).
  6477. * @param {Date} d1
  6478. * @param {Date} d2
  6479. * @returns {boolean}
  6480. */
  6481. function isSameDay(d1, d2) {
  6482. return d1.getDate() == d2.getDate() && isSameMonthAndYear(d1, d2);
  6483. }
  6484. /**
  6485. * Gets whether a date is in the month immediately after some date.
  6486. * @param {Date} startDate The date from which to compare.
  6487. * @param {Date} endDate The date to check.
  6488. * @returns {boolean}
  6489. */
  6490. function isInNextMonth(startDate, endDate) {
  6491. var nextMonth = getDateInNextMonth(startDate);
  6492. return isSameMonthAndYear(nextMonth, endDate);
  6493. }
  6494. /**
  6495. * Gets whether a date is in the month immediately before some date.
  6496. * @param {Date} startDate The date from which to compare.
  6497. * @param {Date} endDate The date to check.
  6498. * @returns {boolean}
  6499. */
  6500. function isInPreviousMonth(startDate, endDate) {
  6501. var previousMonth = getDateInPreviousMonth(startDate);
  6502. return isSameMonthAndYear(endDate, previousMonth);
  6503. }
  6504. /**
  6505. * Gets the midpoint between two dates.
  6506. * @param {Date} d1
  6507. * @param {Date} d2
  6508. * @returns {Date}
  6509. */
  6510. function getDateMidpoint(d1, d2) {
  6511. return createDateAtMidnight((d1.getTime() + d2.getTime()) / 2);
  6512. }
  6513. /**
  6514. * Gets the week of the month that a given date occurs in.
  6515. * @param {Date} date
  6516. * @returns {number} Index of the week of the month (zero-based).
  6517. */
  6518. function getWeekOfMonth(date) {
  6519. var firstDayOfMonth = getFirstDateOfMonth(date);
  6520. return Math.floor((firstDayOfMonth.getDay() + date.getDate() - 1) / 7);
  6521. }
  6522. /**
  6523. * Gets a new date incremented by the given number of days. Number of days can be negative.
  6524. * @param {Date} date
  6525. * @param {number} numberOfDays
  6526. * @returns {Date}
  6527. */
  6528. function incrementDays(date, numberOfDays) {
  6529. return new Date(date.getFullYear(), date.getMonth(), date.getDate() + numberOfDays);
  6530. }
  6531. /**
  6532. * Gets a new date incremented by the given number of months. Number of months can be negative.
  6533. * If the date of the given month does not match the target month, the date will be set to the
  6534. * last day of the month.
  6535. * @param {Date} date
  6536. * @param {number} numberOfMonths
  6537. * @returns {Date}
  6538. */
  6539. function incrementMonths(date, numberOfMonths) {
  6540. // If the same date in the target month does not actually exist, the Date object will
  6541. // automatically advance *another* month by the number of missing days.
  6542. // For example, if you try to go from Jan. 30 to Feb. 30, you'll end up on March 2.
  6543. // So, we check if the month overflowed and go to the last day of the target month instead.
  6544. var dateInTargetMonth = new Date(date.getFullYear(), date.getMonth() + numberOfMonths, 1);
  6545. var numberOfDaysInMonth = getNumberOfDaysInMonth(dateInTargetMonth);
  6546. if (numberOfDaysInMonth < date.getDate()) {
  6547. dateInTargetMonth.setDate(numberOfDaysInMonth);
  6548. } else {
  6549. dateInTargetMonth.setDate(date.getDate());
  6550. }
  6551. return dateInTargetMonth;
  6552. }
  6553. /**
  6554. * Get the integer distance between two months. This *only* considers the month and year
  6555. * portion of the Date instances.
  6556. *
  6557. * @param {Date} start
  6558. * @param {Date} end
  6559. * @returns {number} Number of months between `start` and `end`. If `end` is before `start`
  6560. * chronologically, this number will be negative.
  6561. */
  6562. function getMonthDistance(start, end) {
  6563. return (12 * (end.getFullYear() - start.getFullYear())) + (end.getMonth() - start.getMonth());
  6564. }
  6565. /**
  6566. * Gets the last day of the month for the given date.
  6567. * @param {Date} date
  6568. * @returns {Date}
  6569. */
  6570. function getLastDateOfMonth(date) {
  6571. return new Date(date.getFullYear(), date.getMonth(), getNumberOfDaysInMonth(date));
  6572. }
  6573. /**
  6574. * Checks whether a date is valid.
  6575. * @param {Date} date
  6576. * @return {boolean} Whether the date is a valid Date.
  6577. */
  6578. function isValidDate(date) {
  6579. return date != null && date.getTime && !isNaN(date.getTime());
  6580. }
  6581. /**
  6582. * Sets a date's time to midnight.
  6583. * @param {Date} date
  6584. */
  6585. function setDateTimeToMidnight(date) {
  6586. date.setHours(0, 0, 0, 0);
  6587. }
  6588. /**
  6589. * Creates a date with the time set to midnight.
  6590. * Drop-in replacement for two forms of the Date constructor:
  6591. * 1. No argument for Date representing now.
  6592. * 2. Single-argument value representing number of seconds since Unix Epoch.
  6593. * @param {number=} opt_value
  6594. * @return {Date} New date with time set to midnight.
  6595. */
  6596. function createDateAtMidnight(opt_value) {
  6597. var date;
  6598. if (angular.isUndefined(opt_value)) {
  6599. date = new Date();
  6600. } else {
  6601. date = new Date(opt_value);
  6602. }
  6603. setDateTimeToMidnight(date);
  6604. return date;
  6605. }
  6606. /**
  6607. * Checks if a date is within a min and max range.
  6608. * If minDate or maxDate are not dates, they are ignored.
  6609. * @param {Date} date
  6610. * @param {Date} minDate
  6611. * @param {Date} maxDate
  6612. */
  6613. function isDateWithinRange(date, minDate, maxDate) {
  6614. return (!angular.isDate(minDate) || minDate <= date) &&
  6615. (!angular.isDate(maxDate) || maxDate >= date);
  6616. }
  6617. });
  6618. })();
  6619. })();
  6620. (function(){
  6621. "use strict";
  6622. /**
  6623. * @ngdoc module
  6624. * @name material.components.dialog
  6625. */
  6626. angular
  6627. .module('material.components.dialog', [
  6628. 'material.core',
  6629. 'material.components.backdrop'
  6630. ])
  6631. .directive('mdDialog', MdDialogDirective)
  6632. .provider('$mdDialog', MdDialogProvider);
  6633. function MdDialogDirective($$rAF, $mdTheming) {
  6634. return {
  6635. restrict: 'E',
  6636. link: function(scope, element, attr) {
  6637. $mdTheming(element);
  6638. $$rAF(function() {
  6639. var images;
  6640. var content = element[0].querySelector('md-dialog-content');
  6641. if (content) {
  6642. images = content.getElementsByTagName('img');
  6643. addOverflowClass();
  6644. //-- delayed image loading may impact scroll height, check after images are loaded
  6645. angular.element(images).on('load', addOverflowClass);
  6646. }
  6647. function addOverflowClass() {
  6648. element.toggleClass('md-content-overflow', content.scrollHeight > content.clientHeight);
  6649. }
  6650. });
  6651. }
  6652. };
  6653. }
  6654. MdDialogDirective.$inject = ["$$rAF", "$mdTheming"];
  6655. /**
  6656. * @ngdoc service
  6657. * @name $mdDialog
  6658. * @module material.components.dialog
  6659. *
  6660. * @description
  6661. * `$mdDialog` opens a dialog over the app to inform users about critical information or require
  6662. * them to make decisions. There are two approaches for setup: a simple promise API
  6663. * and regular object syntax.
  6664. *
  6665. * ## Restrictions
  6666. *
  6667. * - The dialog is always given an isolate scope.
  6668. * - The dialog's template must have an outer `<md-dialog>` element.
  6669. * Inside, use an `<md-dialog-content>` element for the dialog's content, and use
  6670. * an element with class `md-actions` for the dialog's actions.
  6671. * - Dialogs must cover the entire application to keep interactions inside of them.
  6672. * Use the `parent` option to change where dialogs are appended.
  6673. *
  6674. * ## Sizing
  6675. * - Complex dialogs can be sized with `flex="percentage"`, i.e. `flex="66"`.
  6676. * - Default max-width is 80% of the `rootElement` or `parent`.
  6677. *
  6678. * @usage
  6679. * <hljs lang="html">
  6680. * <div ng-app="demoApp" ng-controller="EmployeeController">
  6681. * <div>
  6682. * <md-button ng-click="showAlert()" class="md-raised md-warn">
  6683. * Employee Alert!
  6684. * </md-button>
  6685. * </div>
  6686. * <div>
  6687. * <md-button ng-click="showDialog($event)" class="md-raised">
  6688. * Custom Dialog
  6689. * </md-button>
  6690. * </div>
  6691. * <div>
  6692. * <md-button ng-click="closeAlert()" ng-disabled="!hasAlert()" class="md-raised">
  6693. * Close Alert
  6694. * </md-button>
  6695. * </div>
  6696. * <div>
  6697. * <md-button ng-click="showGreeting($event)" class="md-raised md-primary" >
  6698. * Greet Employee
  6699. * </md-button>
  6700. * </div>
  6701. * </div>
  6702. * </hljs>
  6703. *
  6704. * ### JavaScript: object syntax
  6705. * <hljs lang="js">
  6706. * (function(angular, undefined){
  6707. * "use strict";
  6708. *
  6709. * angular
  6710. * .module('demoApp', ['ngMaterial'])
  6711. * .controller('AppCtrl', AppController);
  6712. *
  6713. * function AppController($scope, $mdDialog) {
  6714. * var alert;
  6715. * $scope.showAlert = showAlert;
  6716. * $scope.showDialog = showDialog;
  6717. * $scope.items = [1, 2, 3];
  6718. *
  6719. * // Internal method
  6720. * function showAlert() {
  6721. * alert = $mdDialog.alert({
  6722. * title: 'Attention',
  6723. * content: 'This is an example of how easy dialogs can be!',
  6724. * ok: 'Close'
  6725. * });
  6726. *
  6727. * $mdDialog
  6728. * .show( alert )
  6729. * .finally(function() {
  6730. * alert = undefined;
  6731. * });
  6732. * }
  6733. *
  6734. * function showDialog($event) {
  6735. * var parentEl = angular.element(document.body);
  6736. * $mdDialog.show({
  6737. * parent: parentEl,
  6738. * targetEvent: $event,
  6739. * template:
  6740. * '<md-dialog aria-label="List dialog">' +
  6741. * ' <md-dialog-content>'+
  6742. * ' <md-list>'+
  6743. * ' <md-list-item ng-repeat="item in items">'+
  6744. * ' <p>Number {{item}}</p>' +
  6745. * ' </md-item>'+
  6746. * ' </md-list>'+
  6747. * ' </md-dialog-content>' +
  6748. * ' <div class="md-actions">' +
  6749. * ' <md-button ng-click="closeDialog()" class="md-primary">' +
  6750. * ' Close Dialog' +
  6751. * ' </md-button>' +
  6752. * ' </div>' +
  6753. * '</md-dialog>',
  6754. * locals: {
  6755. * items: $scope.items
  6756. * },
  6757. * controller: DialogController
  6758. * });
  6759. * function DialogController($scope, $mdDialog, items) {
  6760. * $scope.items = items;
  6761. * $scope.closeDialog = function() {
  6762. * $mdDialog.hide();
  6763. * }
  6764. * }
  6765. * }
  6766. * }
  6767. * })(angular);
  6768. * </hljs>
  6769. *
  6770. * ### JavaScript: promise API syntax, custom dialog template
  6771. * <hljs lang="js">
  6772. * (function(angular, undefined){
  6773. * "use strict";
  6774. *
  6775. * angular
  6776. * .module('demoApp', ['ngMaterial'])
  6777. * .controller('EmployeeController', EmployeeEditor)
  6778. * .controller('GreetingController', GreetingController);
  6779. *
  6780. * // Fictitious Employee Editor to show how to use simple and complex dialogs.
  6781. *
  6782. * function EmployeeEditor($scope, $mdDialog) {
  6783. * var alert;
  6784. *
  6785. * $scope.showAlert = showAlert;
  6786. * $scope.closeAlert = closeAlert;
  6787. * $scope.showGreeting = showCustomGreeting;
  6788. *
  6789. * $scope.hasAlert = function() { return !!alert };
  6790. * $scope.userName = $scope.userName || 'Bobby';
  6791. *
  6792. * // Dialog #1 - Show simple alert dialog and cache
  6793. * // reference to dialog instance
  6794. *
  6795. * function showAlert() {
  6796. * alert = $mdDialog.alert()
  6797. * .title('Attention, ' + $scope.userName)
  6798. * .content('This is an example of how easy dialogs can be!')
  6799. * .ok('Close');
  6800. *
  6801. * $mdDialog
  6802. * .show( alert )
  6803. * .finally(function() {
  6804. * alert = undefined;
  6805. * });
  6806. * }
  6807. *
  6808. * // Close the specified dialog instance and resolve with 'finished' flag
  6809. * // Normally this is not needed, just use '$mdDialog.hide()' to close
  6810. * // the most recent dialog popup.
  6811. *
  6812. * function closeAlert() {
  6813. * $mdDialog.hide( alert, "finished" );
  6814. * alert = undefined;
  6815. * }
  6816. *
  6817. * // Dialog #2 - Demonstrate more complex dialogs construction and popup.
  6818. *
  6819. * function showCustomGreeting($event) {
  6820. * $mdDialog.show({
  6821. * targetEvent: $event,
  6822. * template:
  6823. * '<md-dialog>' +
  6824. *
  6825. * ' <md-dialog-content>Hello {{ employee }}!</md-dialog-content>' +
  6826. *
  6827. * ' <div class="md-actions">' +
  6828. * ' <md-button ng-click="closeDialog()" class="md-primary">' +
  6829. * ' Close Greeting' +
  6830. * ' </md-button>' +
  6831. * ' </div>' +
  6832. * '</md-dialog>',
  6833. * controller: 'GreetingController',
  6834. * onComplete: afterShowAnimation,
  6835. * locals: { employee: $scope.userName }
  6836. * });
  6837. *
  6838. * // When the 'enter' animation finishes...
  6839. *
  6840. * function afterShowAnimation(scope, element, options) {
  6841. * // post-show code here: DOM element focus, etc.
  6842. * }
  6843. * }
  6844. *
  6845. * // Dialog #3 - Demonstrate use of ControllerAs and passing $scope to dialog
  6846. * // Here we used ng-controller="GreetingController as vm" and
  6847. * // $scope.vm === <controller instance>
  6848. *
  6849. * function showCustomGreeting() {
  6850. *
  6851. * $mdDialog.show({
  6852. * clickOutsideToClose: true,
  6853. *
  6854. * scope: $scope, // use parent scope in template
  6855. * preserveScope: true, // do not forget this if use parent scope
  6856. * // Since GreetingController is instantiated with ControllerAs syntax
  6857. * // AND we are passing the parent '$scope' to the dialog, we MUST
  6858. * // use 'vm.<xxx>' in the template markup
  6859. *
  6860. * template: '<md-dialog>' +
  6861. * ' <md-dialog-content>' +
  6862. * ' Hi There {{vm.employee}}' +
  6863. * ' </md-dialog-content>' +
  6864. * '</md-dialog>',
  6865. *
  6866. * controller: function DialogController($scope, $mdDialog) {
  6867. * $scope.closeDialog = function() {
  6868. * $mdDialog.hide();
  6869. * }
  6870. * }
  6871. * });
  6872. * }
  6873. *
  6874. * }
  6875. *
  6876. * // Greeting controller used with the more complex 'showCustomGreeting()' custom dialog
  6877. *
  6878. * function GreetingController($scope, $mdDialog, employee) {
  6879. * // Assigned from construction <code>locals</code> options...
  6880. * $scope.employee = employee;
  6881. *
  6882. * $scope.closeDialog = function() {
  6883. * // Easily hides most recent dialog shown...
  6884. * // no specific instance reference is needed.
  6885. * $mdDialog.hide();
  6886. * };
  6887. * }
  6888. *
  6889. * })(angular);
  6890. * </hljs>
  6891. */
  6892. /**
  6893. * @ngdoc method
  6894. * @name $mdDialog#alert
  6895. *
  6896. * @description
  6897. * Builds a preconfigured dialog with the specified message.
  6898. *
  6899. * @returns {obj} an `$mdDialogPreset` with the chainable configuration methods:
  6900. *
  6901. * - $mdDialogPreset#title(string) - sets title to string
  6902. * - $mdDialogPreset#content(string) - sets content / message to string
  6903. * - $mdDialogPreset#ok(string) - sets okay button text to string
  6904. * - $mdDialogPreset#theme(string) - sets the theme of the dialog
  6905. *
  6906. */
  6907. /**
  6908. * @ngdoc method
  6909. * @name $mdDialog#confirm
  6910. *
  6911. * @description
  6912. * Builds a preconfigured dialog with the specified message. You can call show and the promise returned
  6913. * will be resolved only if the user clicks the confirm action on the dialog.
  6914. *
  6915. * @returns {obj} an `$mdDialogPreset` with the chainable configuration methods:
  6916. *
  6917. * Additionally, it supports the following methods:
  6918. *
  6919. * - $mdDialogPreset#title(string) - sets title to string
  6920. * - $mdDialogPreset#content(string) - sets content / message to string
  6921. * - $mdDialogPreset#ok(string) - sets okay button text to string
  6922. * - $mdDialogPreset#cancel(string) - sets cancel button text to string
  6923. * - $mdDialogPreset#theme(string) - sets the theme of the dialog
  6924. *
  6925. */
  6926. /**
  6927. * @ngdoc method
  6928. * @name $mdDialog#show
  6929. *
  6930. * @description
  6931. * Show a dialog with the specified options.
  6932. *
  6933. * @param {object} optionsOrPreset Either provide an `$mdDialogPreset` returned from `alert()`, and
  6934. * `confirm()`, or an options object with the following properties:
  6935. * - `templateUrl` - `{string=}`: The url of a template that will be used as the content
  6936. * of the dialog.
  6937. * - `template` - `{string=}`: Same as templateUrl, except this is an actual template string.
  6938. * - `targetEvent` - `{DOMClickEvent=}`: A click's event object. When passed in as an option,
  6939. * the location of the click will be used as the starting point for the opening animation
  6940. * of the the dialog.
  6941. * - `scope` - `{object=}`: the scope to link the template / controller to. If none is specified,
  6942. * it will create a new isolate scope.
  6943. * This scope will be destroyed when the dialog is removed unless `preserveScope` is set to true.
  6944. * - `preserveScope` - `{boolean=}`: whether to preserve the scope when the element is removed. Default is false
  6945. * - `disableParentScroll` - `{boolean=}`: Whether to disable scrolling while the dialog is open.
  6946. * Default true.
  6947. * - `hasBackdrop` - `{boolean=}`: Whether there should be an opaque backdrop behind the dialog.
  6948. * Default true.
  6949. * - `clickOutsideToClose` - `{boolean=}`: Whether the user can click outside the dialog to
  6950. * close it. Default false.
  6951. * - `escapeToClose` - `{boolean=}`: Whether the user can press escape to close the dialog.
  6952. * Default true.
  6953. * - `focusOnOpen` - `{boolean=}`: An option to override focus behavior on open. Only disable if
  6954. * focusing some other way, as focus management is required for dialogs to be accessible.
  6955. * Defaults to true.
  6956. * - `controller` - `{string=}`: The controller to associate with the dialog. The controller
  6957. * will be injected with the local `$mdDialog`, which passes along a scope for the dialog.
  6958. * - `locals` - `{object=}`: An object containing key/value pairs. The keys will be used as names
  6959. * of values to inject into the controller. For example, `locals: {three: 3}` would inject
  6960. * `three` into the controller, with the value 3. If `bindToController` is true, they will be
  6961. * copied to the controller instead.
  6962. * - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in.
  6963. * These values will not be available until after initialization.
  6964. * - `resolve` - `{object=}`: Similar to locals, except it takes promises as values, and the
  6965. * dialog will not open until all of the promises resolve.
  6966. * - `controllerAs` - `{string=}`: An alias to assign the controller to on the scope.
  6967. * - `parent` - `{element=}`: The element to append the dialog to. Defaults to appending
  6968. * to the root element of the application.
  6969. * - `onComplete` `{function=}`: Callback function used to announce when the show() action is
  6970. * finished.
  6971. * - `onRemoving` `{function=} Callback function used to announce the close/hide() action is
  6972. * starting. This allows developers to run custom animations in parallel the close animations.
  6973. *
  6974. * @returns {promise} A promise that can be resolved with `$mdDialog.hide()` or
  6975. * rejected with `$mdDialog.cancel()`.
  6976. */
  6977. /**
  6978. * @ngdoc method
  6979. * @name $mdDialog#hide
  6980. *
  6981. * @description
  6982. * Hide an existing dialog and resolve the promise returned from `$mdDialog.show()`.
  6983. *
  6984. * @param {*=} response An argument for the resolved promise.
  6985. *
  6986. * @returns {promise} A promise that is resolved when the dialog has been closed.
  6987. */
  6988. /**
  6989. * @ngdoc method
  6990. * @name $mdDialog#cancel
  6991. *
  6992. * @description
  6993. * Hide an existing dialog and reject the promise returned from `$mdDialog.show()`.
  6994. *
  6995. * @param {*=} response An argument for the rejected promise.
  6996. *
  6997. * @returns {promise} A promise that is resolved when the dialog has been closed.
  6998. */
  6999. function MdDialogProvider($$interimElementProvider) {
  7000. advancedDialogOptions.$inject = ["$mdDialog", "$mdTheming"];
  7001. dialogDefaultOptions.$inject = ["$mdDialog", "$mdAria", "$mdUtil", "$mdConstant", "$animate", "$document", "$window", "$rootElement"];
  7002. return $$interimElementProvider('$mdDialog')
  7003. .setDefaults({
  7004. methods: ['disableParentScroll', 'hasBackdrop', 'clickOutsideToClose', 'escapeToClose', 'targetEvent', 'parent'],
  7005. options: dialogDefaultOptions
  7006. })
  7007. .addPreset('alert', {
  7008. methods: ['title', 'content', 'ariaLabel', 'ok', 'theme'],
  7009. options: advancedDialogOptions
  7010. })
  7011. .addPreset('confirm', {
  7012. methods: ['title', 'content', 'ariaLabel', 'ok', 'cancel', 'theme'],
  7013. options: advancedDialogOptions
  7014. });
  7015. /* @ngInject */
  7016. function advancedDialogOptions($mdDialog, $mdTheming) {
  7017. return {
  7018. template: [
  7019. '<md-dialog md-theme="{{ dialog.theme }}" aria-label="{{ dialog.ariaLabel }}">',
  7020. ' <md-dialog-content role="document" tabIndex="-1">',
  7021. ' <h2 class="md-title">{{ dialog.title }}</h2>',
  7022. ' <div class="md-dialog-content-body" md-template="::dialog.content"></div>',
  7023. ' </md-dialog-content>',
  7024. ' <div class="md-actions">',
  7025. ' <md-button ng-if="dialog.$type == \'confirm\'"' +
  7026. ' ng-click="dialog.abort()" class="md-primary">',
  7027. ' {{ dialog.cancel }}',
  7028. ' </md-button>',
  7029. ' <md-button ng-click="dialog.hide()" class="md-primary" md-autofocus="dialog.$type!=\'confirm\'">',
  7030. ' {{ dialog.ok }}',
  7031. ' </md-button>',
  7032. ' </div>',
  7033. '</md-dialog>'
  7034. ].join('').replace(/\s\s+/g, ''),
  7035. controller: function mdDialogCtrl() {
  7036. this.hide = function() {
  7037. $mdDialog.hide(true);
  7038. };
  7039. this.abort = function() {
  7040. $mdDialog.cancel();
  7041. };
  7042. },
  7043. controllerAs: 'dialog',
  7044. bindToController: true,
  7045. theme: $mdTheming.defaultTheme()
  7046. };
  7047. }
  7048. /* @ngInject */
  7049. function dialogDefaultOptions($mdDialog, $mdAria, $mdUtil, $mdConstant, $animate, $document, $window, $rootElement) {
  7050. return {
  7051. hasBackdrop: true,
  7052. isolateScope: true,
  7053. onShow: onShow,
  7054. onRemove: onRemove,
  7055. clickOutsideToClose: false,
  7056. escapeToClose: true,
  7057. targetEvent: null,
  7058. focusOnOpen: true,
  7059. disableParentScroll: true,
  7060. transformTemplate: function(template) {
  7061. return '<div class="md-dialog-container">' + validatedTemplate(template) + '</div>';
  7062. /**
  7063. * The specified template should contain a <md-dialog> wrapper element....
  7064. */
  7065. function validatedTemplate(template) {
  7066. template || ""
  7067. return /<\/md-dialog>/g.test(template) ? template : "<md-dialog>" + template + "</md-dialog>";
  7068. }
  7069. }
  7070. };
  7071. /**
  7072. * Show method for dialogs
  7073. */
  7074. function onShow(scope, element, options, controller) {
  7075. element = $mdUtil.extractElementByName(element, 'md-dialog');
  7076. angular.element($document[0].body).addClass('md-dialog-is-showing');
  7077. wrapSimpleContent();
  7078. captureSourceAndParent(element, options);
  7079. configureAria(element.find('md-dialog'), options);
  7080. showBackdrop(scope, element, options);
  7081. return dialogPopIn(element, options)
  7082. .then(function() {
  7083. activateListeners(element, options);
  7084. lockScreenReader(element, options);
  7085. focusOnOpen();
  7086. });
  7087. /**
  7088. * For alerts, focus on content... otherwise focus on
  7089. * the close button (or equivalent)
  7090. */
  7091. function focusOnOpen() {
  7092. if (options.focusOnOpen) {
  7093. var target = $mdUtil.findFocusTarget(element) || findCloseButton();
  7094. target.focus();
  7095. }
  7096. /**
  7097. * If no element with class dialog-close, try to find the last
  7098. * button child in md-actions and assume it is a close button
  7099. */
  7100. function findCloseButton() {
  7101. var closeButton = element[0].querySelector('.dialog-close');
  7102. if (!closeButton) {
  7103. var actionButtons = element[0].querySelectorAll('.md-actions button');
  7104. closeButton = actionButtons[actionButtons.length - 1];
  7105. }
  7106. return angular.element(closeButton);
  7107. }
  7108. }
  7109. /**
  7110. * Wrap any simple content [specified via .content("")] in <p></p> tags.
  7111. * otherwise accept HTML content within the dialog content area...
  7112. * NOTE: Dialog uses the md-template directive to safely inject HTML content.
  7113. */
  7114. function wrapSimpleContent() {
  7115. if ( controller ) {
  7116. var HTML_END_TAG = /<\/[\w-]*>/gm;
  7117. var content = controller.content;
  7118. var hasHTML = HTML_END_TAG.test(content);
  7119. if (!hasHTML) {
  7120. content = $mdUtil.supplant("<p>{0}</p>", [content]);
  7121. }
  7122. // Publish updated dialog content body... to be compiled by mdTemplate directive
  7123. controller.content = content;
  7124. }
  7125. }
  7126. }
  7127. /**
  7128. * Remove function for all dialogs
  7129. */
  7130. function onRemove(scope, element, options) {
  7131. options.deactivateListeners();
  7132. options.unlockScreenReader();
  7133. options.hideBackdrop();
  7134. return dialogPopOut(element, options)
  7135. .finally(function() {
  7136. angular.element($document[0].body).removeClass('md-dialog-is-showing');
  7137. element.remove();
  7138. options.origin.focus();
  7139. });
  7140. }
  7141. /**
  7142. * Capture originator/trigger element information (if available)
  7143. * and the parent container for the dialog; defaults to the $rootElement
  7144. * unless overridden in the options.parent
  7145. */
  7146. function captureSourceAndParent(element, options) {
  7147. var origin = {element: null, bounds: null, focus: angular.noop};
  7148. options.origin = angular.extend({}, origin, options.origin || {});
  7149. var source = angular.element((options.targetEvent || {}).target);
  7150. if (source && source.length) {
  7151. // Compute and save the target element's bounding rect, so that if the
  7152. // element is hidden when the dialog closes, we can shrink the dialog
  7153. // back to the same position it expanded from.
  7154. options.origin.element = source;
  7155. options.origin.bounds = source[0].getBoundingClientRect();
  7156. options.origin.focus = function() {
  7157. source.focus();
  7158. }
  7159. }
  7160. // In case the user provides a raw dom element, always wrap it in jqLite
  7161. options.parent = angular.element(options.parent || $rootElement);
  7162. }
  7163. /**
  7164. * Listen for escape keys and outside clicks to auto close
  7165. */
  7166. function activateListeners(element, options) {
  7167. var removeListeners = [];
  7168. var smartClose = function() {
  7169. // Only 'confirm' dialogs have a cancel button... escape/clickOutside will
  7170. // cancel or fallback to hide.
  7171. var closeFn = ( options.$type == 'alert' ) ? $mdDialog.hide : $mdDialog.cancel;
  7172. $mdUtil.nextTick(closeFn, true);
  7173. };
  7174. if (options.escapeToClose) {
  7175. var target = options.parent;
  7176. var keyHandlerFn = function(ev) {
  7177. if (ev.keyCode === $mdConstant.KEY_CODE.ESCAPE) {
  7178. ev.stopPropagation();
  7179. ev.preventDefault();
  7180. smartClose();
  7181. }
  7182. };
  7183. // Add keyup listeners
  7184. element.on('keyup', keyHandlerFn);
  7185. target.on('keyup', keyHandlerFn);
  7186. // Queue remove listeners function
  7187. removeListeners.push(function() {
  7188. element.off('keyup', keyHandlerFn);
  7189. target.off('keyup', keyHandlerFn);
  7190. });
  7191. }
  7192. if (options.clickOutsideToClose) {
  7193. var target = element;
  7194. var clickHandler = function(ev) {
  7195. // Only close if we click the flex container outside on the backdrop
  7196. if (ev.target === target[0]) {
  7197. ev.stopPropagation();
  7198. ev.preventDefault();
  7199. smartClose();
  7200. }
  7201. };
  7202. // Add click listeners
  7203. target.on('click', clickHandler);
  7204. // Queue remove listeners function
  7205. removeListeners.push(function() {
  7206. target.off('click', clickHandler);
  7207. });
  7208. }
  7209. // Attach specific `remove` listener handler
  7210. options.deactivateListeners = function() {
  7211. removeListeners.forEach(function(removeFn) {
  7212. removeFn();
  7213. });
  7214. options.deactivateListeners = null;
  7215. };
  7216. }
  7217. /**
  7218. * Show modal backdrop element...
  7219. */
  7220. function showBackdrop(scope, element, options) {
  7221. if (options.disableParentScroll) {
  7222. // !! DO this before creating the backdrop; since disableScrollAround()
  7223. // configures the scroll offset; which is used by mdBackDrop postLink()
  7224. options.restoreScroll = $mdUtil.disableScrollAround(element, options.parent);
  7225. }
  7226. if (options.hasBackdrop) {
  7227. options.backdrop = $mdUtil.createBackdrop(scope, "md-dialog-backdrop md-opaque");
  7228. $animate.enter(options.backdrop, options.parent);
  7229. }
  7230. /**
  7231. * Hide modal backdrop element...
  7232. */
  7233. options.hideBackdrop = function hideBackdrop() {
  7234. if (options.backdrop) {
  7235. $animate.leave(options.backdrop);
  7236. }
  7237. if (options.disableParentScroll) {
  7238. options.restoreScroll();
  7239. delete options.restoreScroll;
  7240. }
  7241. options.hideBackdrop = null;
  7242. }
  7243. }
  7244. /**
  7245. * Inject ARIA-specific attributes appropriate for Dialogs
  7246. */
  7247. function configureAria(element, options) {
  7248. var role = (options.$type === 'alert') ? 'alertdialog' : 'dialog';
  7249. var dialogContent = element.find('md-dialog-content');
  7250. var dialogId = element.attr('id') || ('dialog_' + $mdUtil.nextUid());
  7251. element.attr({
  7252. 'role': role,
  7253. 'tabIndex': '-1'
  7254. });
  7255. if (dialogContent.length === 0) {
  7256. dialogContent = element;
  7257. }
  7258. dialogContent.attr('id', dialogId);
  7259. element.attr('aria-describedby', dialogId);
  7260. if (options.ariaLabel) {
  7261. $mdAria.expect(element, 'aria-label', options.ariaLabel);
  7262. }
  7263. else {
  7264. $mdAria.expectAsync(element, 'aria-label', function() {
  7265. var words = dialogContent.text().split(/\s+/);
  7266. if (words.length > 3) words = words.slice(0, 3).concat('...');
  7267. return words.join(' ');
  7268. });
  7269. }
  7270. }
  7271. /**
  7272. * Prevents screen reader interaction behind modal window
  7273. * on swipe interfaces
  7274. */
  7275. function lockScreenReader(element, options) {
  7276. var isHidden = true;
  7277. // get raw DOM node
  7278. walkDOM(element[0]);
  7279. options.unlockScreenReader = function() {
  7280. isHidden = false;
  7281. walkDOM(element[0]);
  7282. options.unlockScreenReader = null;
  7283. };
  7284. /**
  7285. * Walk DOM to apply or remove aria-hidden on sibling nodes
  7286. * and parent sibling nodes
  7287. *
  7288. */
  7289. function walkDOM(element) {
  7290. while (element.parentNode) {
  7291. if (element === document.body) {
  7292. return;
  7293. }
  7294. var children = element.parentNode.children;
  7295. for (var i = 0; i < children.length; i++) {
  7296. // skip over child if it is an ascendant of the dialog
  7297. // or a script or style tag
  7298. if (element !== children[i] && !isNodeOneOf(children[i], ['SCRIPT', 'STYLE'])) {
  7299. children[i].setAttribute('aria-hidden', isHidden);
  7300. }
  7301. }
  7302. walkDOM(element = element.parentNode);
  7303. }
  7304. }
  7305. }
  7306. /**
  7307. * Ensure the dialog container fill-stretches to the viewport
  7308. */
  7309. function stretchDialogContainerToViewport(container, options) {
  7310. var isFixed = $window.getComputedStyle($document[0].body).position == 'fixed';
  7311. var backdrop = options.backdrop ? $window.getComputedStyle(options.backdrop[0]) : null;
  7312. var height = backdrop ? Math.ceil(Math.abs(parseInt(backdrop.height, 10))) : 0;
  7313. container.css({
  7314. top: (isFixed ? $mdUtil.scrollTop(options.parent) / 2 : 0) + 'px',
  7315. height: height ? height + 'px' : '100%'
  7316. });
  7317. return container;
  7318. }
  7319. /**
  7320. * Dialog open and pop-in animation
  7321. */
  7322. function dialogPopIn(container, options) {
  7323. // Add the `md-dialog-container` to the DOM
  7324. options.parent.append(container);
  7325. stretchDialogContainerToViewport(container, options);
  7326. var dialogEl = container.find('md-dialog');
  7327. var animator = $mdUtil.dom.animator;
  7328. var buildTranslateToOrigin = animator.calculateZoomToOrigin;
  7329. var translateOptions = {transitionInClass: 'md-transition-in', transitionOutClass: 'md-transition-out'};
  7330. var from = animator.toTransformCss(buildTranslateToOrigin(dialogEl, options.origin));
  7331. var to = animator.toTransformCss(""); // defaults to center display (or parent or $rootElement)
  7332. return animator
  7333. .translate3d(dialogEl, from, to, translateOptions)
  7334. .then(function(animateReversal) {
  7335. // Build a reversal translate function synched to this translation...
  7336. options.reverseAnimate = function() {
  7337. delete options.reverseAnimate;
  7338. return animateReversal(
  7339. animator.toTransformCss(
  7340. // in case the origin element has moved or is hidden,
  7341. // let's recalculate the translateCSS
  7342. buildTranslateToOrigin(dialogEl, options.origin)
  7343. )
  7344. );
  7345. };
  7346. return true;
  7347. });
  7348. }
  7349. /**
  7350. * Dialog close and pop-out animation
  7351. */
  7352. function dialogPopOut(container, options) {
  7353. return options.reverseAnimate();
  7354. }
  7355. /**
  7356. * Utility function to filter out raw DOM nodes
  7357. */
  7358. function isNodeOneOf(elem, nodeTypeArray) {
  7359. if (nodeTypeArray.indexOf(elem.nodeName) !== -1) {
  7360. return true;
  7361. }
  7362. }
  7363. }
  7364. }
  7365. MdDialogProvider.$inject = ["$$interimElementProvider"];
  7366. })();
  7367. (function(){
  7368. "use strict";
  7369. /**
  7370. * @ngdoc module
  7371. * @name material.components.divider
  7372. * @description Divider module!
  7373. */
  7374. angular.module('material.components.divider', [
  7375. 'material.core'
  7376. ])
  7377. .directive('mdDivider', MdDividerDirective);
  7378. /**
  7379. * @ngdoc directive
  7380. * @name mdDivider
  7381. * @module material.components.divider
  7382. * @restrict E
  7383. *
  7384. * @description
  7385. * 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.
  7386. *
  7387. * @param {boolean=} md-inset Add this attribute to activate the inset divider style.
  7388. * @usage
  7389. * <hljs lang="html">
  7390. * <md-divider></md-divider>
  7391. *
  7392. * <md-divider md-inset></md-divider>
  7393. * </hljs>
  7394. *
  7395. */
  7396. function MdDividerDirective($mdTheming) {
  7397. return {
  7398. restrict: 'E',
  7399. link: $mdTheming
  7400. };
  7401. }
  7402. MdDividerDirective.$inject = ["$mdTheming"];
  7403. })();
  7404. (function(){
  7405. "use strict";
  7406. (function() {
  7407. 'use strict';
  7408. /**
  7409. * @ngdoc module
  7410. * @name material.components.fabActions
  7411. */
  7412. angular
  7413. .module('material.components.fabActions', ['material.core'])
  7414. .directive('mdFabActions', MdFabActionsDirective);
  7415. /**
  7416. * @ngdoc directive
  7417. * @name mdFabActions
  7418. * @module material.components.fabActions
  7419. *
  7420. * @restrict E
  7421. *
  7422. * @description
  7423. * The `<md-fab-actions>` directive is used inside of a `<md-fab-speed-dial>` or
  7424. * `<md-fab-toolbar>` directive to mark the an element (or elements) as the actions and setup the
  7425. * proper event listeners.
  7426. *
  7427. * @usage
  7428. * See the `<md-fab-speed-dial>` or `<md-fab-toolbar>` directives for example usage.
  7429. */
  7430. function MdFabActionsDirective() {
  7431. return {
  7432. restrict: 'E',
  7433. require: ['^?mdFabSpeedDial', '^?mdFabToolbar'],
  7434. compile: function(element, attributes) {
  7435. var children = element.children();
  7436. var hasNgRepeat = false;
  7437. angular.forEach(['', 'data-', 'x-'], function(prefix) {
  7438. hasNgRepeat = hasNgRepeat || (children.attr(prefix + 'ng-repeat') ? true : false);
  7439. });
  7440. // Support both ng-repeat and static content
  7441. if (hasNgRepeat) {
  7442. children.addClass('md-fab-action-item');
  7443. } else {
  7444. // Wrap every child in a new div and add a class that we can scale/fling independently
  7445. children.wrap('<div class="md-fab-action-item">');
  7446. }
  7447. }
  7448. }
  7449. }
  7450. })();
  7451. })();
  7452. (function(){
  7453. "use strict";
  7454. (function() {
  7455. 'use strict';
  7456. angular.module('material.components.fabShared', ['material.core'])
  7457. .controller('FabController', FabController);
  7458. function FabController($scope, $element, $animate, $mdUtil, $mdConstant) {
  7459. var vm = this;
  7460. // NOTE: We use async evals below to avoid conflicts with any existing digest loops
  7461. vm.open = function() {
  7462. $scope.$evalAsync("vm.isOpen = true");
  7463. };
  7464. vm.close = function() {
  7465. // Async eval to avoid conflicts with existing digest loops
  7466. $scope.$evalAsync("vm.isOpen = false");
  7467. // Focus the trigger when the element closes so users can still tab to the next item
  7468. $element.find('md-fab-trigger')[0].focus();
  7469. };
  7470. // Toggle the open/close state when the trigger is clicked
  7471. vm.toggle = function() {
  7472. $scope.$evalAsync("vm.isOpen = !vm.isOpen");
  7473. };
  7474. setupDefaults();
  7475. setupListeners();
  7476. setupWatchers();
  7477. fireInitialAnimations();
  7478. function setupDefaults() {
  7479. // Set the default direction to 'down' if none is specified
  7480. vm.direction = vm.direction || 'down';
  7481. // Set the default to be closed
  7482. vm.isOpen = vm.isOpen || false;
  7483. // Start the keyboard interaction at the first action
  7484. resetActionIndex();
  7485. }
  7486. var events = [];
  7487. function setupListeners() {
  7488. var eventTypes = [
  7489. 'mousedown', 'mouseup', 'click', 'touchstart', 'touchend', 'focusin', 'focusout'
  7490. ];
  7491. // Add our listeners
  7492. angular.forEach(eventTypes, function(eventType) {
  7493. $element.on(eventType, parseEvents);
  7494. });
  7495. // Remove our listeners when destroyed
  7496. $scope.$on('$destroy', function() {
  7497. angular.forEach(eventTypes, function(eventType) {
  7498. $element.off(eventType, parseEvents);
  7499. });
  7500. });
  7501. }
  7502. function resetEvents() {
  7503. events = [];
  7504. }
  7505. function equalsEvents(toCheck) {
  7506. var isEqual, strippedCheck, moreToCheck;
  7507. // Quick check to make sure we don't get stuck in an infinite loop
  7508. var numTests = 0;
  7509. do {
  7510. // Strip out the question mark
  7511. strippedCheck = toCheck.map(function(event) {
  7512. return event.replace('?', '')
  7513. });
  7514. // Check if they are equal
  7515. isEqual = angular.equals(events, strippedCheck);
  7516. // If not, check to see if removing an optional event makes them equal
  7517. if (!isEqual) {
  7518. toCheck = removeOptionalEvent(toCheck);
  7519. moreToCheck = (toCheck.length >= events.length && toCheck.length !== strippedCheck.length);
  7520. }
  7521. }
  7522. while (numTests < 10 && !isEqual && moreToCheck);
  7523. return isEqual;
  7524. }
  7525. function removeOptionalEvent(events) {
  7526. var foundOptional = false;
  7527. return events.filter(function(event) {
  7528. // If we have not found an optional one, keep searching
  7529. if (!foundOptional && event.indexOf('?') !== -1) {
  7530. foundOptional = true;
  7531. // If we find an optional one, remove only that one and keep going
  7532. return false;
  7533. }
  7534. return true;
  7535. });
  7536. }
  7537. function parseEvents(latestEvent) {
  7538. events.push(latestEvent.type);
  7539. // Handle desktop click
  7540. if (equalsEvents(['mousedown', 'focusout?', 'focusin?', 'mouseup', 'click'])) {
  7541. handleItemClick(latestEvent);
  7542. resetEvents();
  7543. return;
  7544. }
  7545. // Handle mobile click/tap (and keyboard enter)
  7546. if (equalsEvents(['touchstart?', 'touchend?', 'click'])) {
  7547. handleItemClick(latestEvent);
  7548. resetEvents();
  7549. return;
  7550. }
  7551. // Handle tab keys (focusin)
  7552. if (equalsEvents(['focusin'])) {
  7553. vm.open();
  7554. resetEvents();
  7555. return;
  7556. }
  7557. // Handle tab keys (focusout)
  7558. if (equalsEvents(['focusout'])) {
  7559. vm.close();
  7560. resetEvents();
  7561. return;
  7562. }
  7563. eventUnhandled();
  7564. }
  7565. /*
  7566. * No event was handled, so setup a timeout to clear the events
  7567. *
  7568. * TODO: Use $mdUtil.debounce()?
  7569. */
  7570. var resetEventsTimeout;
  7571. function eventUnhandled() {
  7572. if (resetEventsTimeout) {
  7573. window.clearTimeout(resetEventsTimeout);
  7574. }
  7575. resetEventsTimeout = window.setTimeout(function() {
  7576. resetEvents();
  7577. }, 250);
  7578. }
  7579. function resetActionIndex() {
  7580. vm.currentActionIndex = -1;
  7581. }
  7582. function setupWatchers() {
  7583. // Watch for changes to the direction and update classes/attributes
  7584. $scope.$watch('vm.direction', function(newDir, oldDir) {
  7585. // Add the appropriate classes so we can target the direction in the CSS
  7586. $animate.removeClass($element, 'md-' + oldDir);
  7587. $animate.addClass($element, 'md-' + newDir);
  7588. // Reset the action index since it may have changed
  7589. resetActionIndex();
  7590. });
  7591. var trigger, actions;
  7592. // Watch for changes to md-open
  7593. $scope.$watch('vm.isOpen', function(isOpen) {
  7594. // Reset the action index since it may have changed
  7595. resetActionIndex();
  7596. // We can't get the trigger/actions outside of the watch because the component hasn't been
  7597. // linked yet, so we wait until the first watch fires to cache them.
  7598. if (!trigger || !actions) {
  7599. trigger = getTriggerElement();
  7600. actions = getActionsElement();
  7601. }
  7602. if (isOpen) {
  7603. enableKeyboard();
  7604. } else {
  7605. disableKeyboard();
  7606. }
  7607. var toAdd = isOpen ? 'md-is-open' : '';
  7608. var toRemove = isOpen ? '' : 'md-is-open';
  7609. // Set the proper ARIA attributes
  7610. trigger.attr('aria-haspopup', true);
  7611. trigger.attr('aria-expanded', isOpen);
  7612. actions.attr('aria-hidden', !isOpen);
  7613. // Animate the CSS classes
  7614. $animate.setClass($element, toAdd, toRemove);
  7615. });
  7616. }
  7617. // Fire the animations once in a separate digest loop to initialize them
  7618. function fireInitialAnimations() {
  7619. $mdUtil.nextTick(function() {
  7620. $animate.addClass($element, 'md-noop');
  7621. });
  7622. }
  7623. function enableKeyboard() {
  7624. angular.element(document).on('keydown', keyPressed);
  7625. }
  7626. function disableKeyboard() {
  7627. angular.element(document).off('keydown', keyPressed);
  7628. }
  7629. function keyPressed(event) {
  7630. switch (event.which) {
  7631. case $mdConstant.KEY_CODE.SPACE: event.preventDefault(); return false;
  7632. case $mdConstant.KEY_CODE.ESCAPE: vm.close(); event.preventDefault(); return false;
  7633. case $mdConstant.KEY_CODE.LEFT_ARROW: doKeyLeft(event); return false;
  7634. case $mdConstant.KEY_CODE.UP_ARROW: doKeyUp(event); return false;
  7635. case $mdConstant.KEY_CODE.RIGHT_ARROW: doKeyRight(event); return false;
  7636. case $mdConstant.KEY_CODE.DOWN_ARROW: doKeyDown(event); return false;
  7637. }
  7638. }
  7639. function doActionPrev(event) {
  7640. focusAction(event, -1);
  7641. }
  7642. function doActionNext(event) {
  7643. focusAction(event, 1);
  7644. }
  7645. function focusAction(event, direction) {
  7646. // Grab all of the actions
  7647. var actions = getActionsElement()[0].querySelectorAll('.md-fab-action-item');
  7648. // Disable all other actions for tabbing
  7649. angular.forEach(actions, function(action) {
  7650. angular.element(angular.element(action).children()[0]).attr('tabindex', -1);
  7651. });
  7652. // Increment/decrement the counter with restrictions
  7653. vm.currentActionIndex = vm.currentActionIndex + direction;
  7654. vm.currentActionIndex = Math.min(actions.length - 1, vm.currentActionIndex);
  7655. vm.currentActionIndex = Math.max(0, vm.currentActionIndex);
  7656. // Focus the element
  7657. var focusElement = angular.element(actions[vm.currentActionIndex]).children()[0];
  7658. angular.element(focusElement).attr('tabindex', 0);
  7659. focusElement.focus();
  7660. // Make sure the event doesn't bubble and cause something else
  7661. event.preventDefault();
  7662. event.stopImmediatePropagation();
  7663. }
  7664. function doKeyLeft(event) {
  7665. if (vm.direction === 'left') {
  7666. doActionNext(event);
  7667. } else {
  7668. doActionPrev(event);
  7669. }
  7670. }
  7671. function doKeyUp(event) {
  7672. if (vm.direction === 'down') {
  7673. doActionPrev(event);
  7674. } else {
  7675. doActionNext(event);
  7676. }
  7677. }
  7678. function doKeyRight(event) {
  7679. if (vm.direction === 'left') {
  7680. doActionPrev(event);
  7681. } else {
  7682. doActionNext(event);
  7683. }
  7684. }
  7685. function doKeyDown(event) {
  7686. if (vm.direction === 'up') {
  7687. doActionPrev(event);
  7688. } else {
  7689. doActionNext(event);
  7690. }
  7691. }
  7692. function isTrigger(element) {
  7693. return $mdUtil.getClosest(element, 'md-fab-trigger');
  7694. }
  7695. function isAction(element) {
  7696. return $mdUtil.getClosest(element, 'md-fab-actions');
  7697. }
  7698. function handleItemClick(event) {
  7699. if (isTrigger(event.target)) {
  7700. vm.toggle();
  7701. }
  7702. if (isAction(event.target)) {
  7703. vm.close();
  7704. }
  7705. }
  7706. function getTriggerElement() {
  7707. return $element.find('md-fab-trigger');
  7708. }
  7709. function getActionsElement() {
  7710. return $element.find('md-fab-actions');
  7711. }
  7712. }
  7713. FabController.$inject = ["$scope", "$element", "$animate", "$mdUtil", "$mdConstant"];
  7714. })();
  7715. })();
  7716. (function(){
  7717. "use strict";
  7718. (function() {
  7719. 'use strict';
  7720. /**
  7721. * @ngdoc module
  7722. * @name material.components.fabSpeedDial
  7723. */
  7724. angular
  7725. // Declare our module
  7726. .module('material.components.fabSpeedDial', [
  7727. 'material.core',
  7728. 'material.components.fabShared',
  7729. 'material.components.fabTrigger',
  7730. 'material.components.fabActions'
  7731. ])
  7732. // Register our directive
  7733. .directive('mdFabSpeedDial', MdFabSpeedDialDirective)
  7734. // Register our custom animations
  7735. .animation('.md-fling', MdFabSpeedDialFlingAnimation)
  7736. .animation('.md-scale', MdFabSpeedDialScaleAnimation)
  7737. // Register a service for each animation so that we can easily inject them into unit tests
  7738. .service('mdFabSpeedDialFlingAnimation', MdFabSpeedDialFlingAnimation)
  7739. .service('mdFabSpeedDialScaleAnimation', MdFabSpeedDialScaleAnimation);
  7740. /**
  7741. * @ngdoc directive
  7742. * @name mdFabSpeedDial
  7743. * @module material.components.fabSpeedDial
  7744. *
  7745. * @restrict E
  7746. *
  7747. * @description
  7748. * The `<md-fab-speed-dial>` directive is used to present a series of popup elements (usually
  7749. * `<md-button>`s) for quick access to common actions.
  7750. *
  7751. * There are currently two animations available by applying one of the following classes to
  7752. * the component:
  7753. *
  7754. * - `md-fling` - The speed dial items appear from underneath the trigger and move into their
  7755. * appropriate positions.
  7756. * - `md-scale` - The speed dial items appear in their proper places by scaling from 0% to 100%.
  7757. *
  7758. * You may also easily position the trigger by applying one one of the following classes to the
  7759. * `<md-fab-speed-dial>` element:
  7760. * - `md-fab-top-left`
  7761. * - `md-fab-top-right`
  7762. * - `md-fab-bottom-left`
  7763. * - `md-fab-bottom-right`
  7764. *
  7765. * These CSS classes use `position: absolute`, so you need to ensure that the container element
  7766. * also uses `position: absolute` or `position: relative` in order for them to work.
  7767. *
  7768. * @usage
  7769. * <hljs lang="html">
  7770. * <md-fab-speed-dial md-direction="up" class="md-fling">
  7771. * <md-fab-trigger>
  7772. * <md-button aria-label="Add..."><md-icon icon="/img/icons/plus.svg"></md-icon></md-button>
  7773. * </md-fab-trigger>
  7774. *
  7775. * <md-fab-actions>
  7776. * <md-button aria-label="Add User">
  7777. * <md-icon icon="/img/icons/user.svg"></md-icon>
  7778. * </md-button>
  7779. *
  7780. * <md-button aria-label="Add Group">
  7781. * <md-icon icon="/img/icons/group.svg"></md-icon>
  7782. * </md-button>
  7783. * </md-fab-actions>
  7784. * </md-fab-speed-dial>
  7785. * </hljs>
  7786. *
  7787. * @param {string=} md-direction From which direction you would like the speed dial to appear
  7788. * relative to the trigger element.
  7789. * @param {expression=} md-open Programmatically control whether or not the speed-dial is visible.
  7790. */
  7791. function MdFabSpeedDialDirective() {
  7792. return {
  7793. restrict: 'E',
  7794. scope: {
  7795. direction: '@?mdDirection',
  7796. isOpen: '=?mdOpen'
  7797. },
  7798. bindToController: true,
  7799. controller: 'FabController',
  7800. controllerAs: 'vm',
  7801. link: FabSpeedDialLink
  7802. };
  7803. function FabSpeedDialLink(scope, element) {
  7804. // Prepend an element to hold our CSS variables so we can use them in the animations below
  7805. element.prepend('<div class="md-css-variables"></div>');
  7806. }
  7807. }
  7808. function MdFabSpeedDialFlingAnimation() {
  7809. function runAnimation(element) {
  7810. var el = element[0];
  7811. var ctrl = element.controller('mdFabSpeedDial');
  7812. var items = el.querySelectorAll('.md-fab-action-item');
  7813. // Grab our trigger element
  7814. var triggerElement = el.querySelector('md-fab-trigger');
  7815. // Grab our element which stores CSS variables
  7816. var variablesElement = el.querySelector('.md-css-variables');
  7817. // Setup JS variables based on our CSS variables
  7818. var startZIndex = parseInt(window.getComputedStyle(variablesElement).zIndex);
  7819. // Always reset the items to their natural position/state
  7820. angular.forEach(items, function(item, index) {
  7821. var styles = item.style;
  7822. styles.transform = styles.webkitTransform = '';
  7823. styles.transitionDelay = '';
  7824. styles.opacity = 1;
  7825. // Make the items closest to the trigger have the highest z-index
  7826. styles.zIndex = (items.length - index) + startZIndex;
  7827. });
  7828. // Set the trigger to be above all of the actions so they disappear behind it.
  7829. triggerElement.style.zIndex = startZIndex + items.length + 1;
  7830. // If the control is closed, hide the items behind the trigger
  7831. if (!ctrl.isOpen) {
  7832. angular.forEach(items, function(item, index) {
  7833. var newPosition, axis;
  7834. var styles = item.style;
  7835. switch (ctrl.direction) {
  7836. case 'up':
  7837. newPosition = item.scrollHeight * (index + 1);
  7838. axis = 'Y';
  7839. break;
  7840. case 'down':
  7841. newPosition = -item.scrollHeight * (index + 1);
  7842. axis = 'Y';
  7843. break;
  7844. case 'left':
  7845. newPosition = item.scrollWidth * (index + 1);
  7846. axis = 'X';
  7847. break;
  7848. case 'right':
  7849. newPosition = -item.scrollWidth * (index + 1);
  7850. axis = 'X';
  7851. break;
  7852. }
  7853. var newTranslate = 'translate' + axis + '(' + newPosition + 'px)';
  7854. styles.transform = styles.webkitTransform = newTranslate;
  7855. });
  7856. }
  7857. }
  7858. return {
  7859. addClass: function(element, className, done) {
  7860. if (element.hasClass('md-fling')) {
  7861. runAnimation(element);
  7862. done();
  7863. }
  7864. },
  7865. removeClass: function(element, className, done) {
  7866. runAnimation(element);
  7867. done();
  7868. }
  7869. }
  7870. }
  7871. function MdFabSpeedDialScaleAnimation() {
  7872. var delay = 65;
  7873. function runAnimation(element) {
  7874. var el = element[0];
  7875. var ctrl = element.controller('mdFabSpeedDial');
  7876. var items = el.querySelectorAll('.md-fab-action-item');
  7877. // Always reset the items to their natural position/state
  7878. angular.forEach(items, function(item, index) {
  7879. var styles = item.style,
  7880. offsetDelay = index * delay;
  7881. styles.opacity = ctrl.isOpen ? 1 : 0;
  7882. styles.transform = styles.webkitTransform = ctrl.isOpen ? 'scale(1)' : 'scale(0)';
  7883. styles.transitionDelay = (ctrl.isOpen ? offsetDelay : (items.length - offsetDelay)) + 'ms';
  7884. });
  7885. }
  7886. return {
  7887. addClass: function(element, className, done) {
  7888. runAnimation(element);
  7889. done();
  7890. },
  7891. removeClass: function(element, className, done) {
  7892. runAnimation(element);
  7893. done();
  7894. }
  7895. }
  7896. }
  7897. })();
  7898. })();
  7899. (function(){
  7900. "use strict";
  7901. (function() {
  7902. 'use strict';
  7903. /**
  7904. * @ngdoc module
  7905. * @name material.components.fabToolbar
  7906. */
  7907. angular
  7908. // Declare our module
  7909. .module('material.components.fabToolbar', [
  7910. 'material.core',
  7911. 'material.components.fabShared',
  7912. 'material.components.fabTrigger',
  7913. 'material.components.fabActions'
  7914. ])
  7915. // Register our directive
  7916. .directive('mdFabToolbar', MdFabToolbarDirective)
  7917. // Register our custom animations
  7918. .animation('.md-fab-toolbar', MdFabToolbarAnimation)
  7919. // Register a service for the animation so that we can easily inject it into unit tests
  7920. .service('mdFabToolbarAnimation', MdFabToolbarAnimation);
  7921. /**
  7922. * @ngdoc directive
  7923. * @name mdFabToolbar
  7924. * @module material.components.fabToolbar
  7925. *
  7926. * @restrict E
  7927. *
  7928. * @description
  7929. *
  7930. * The `<md-fab-toolbar>` directive is used present a toolbar of elements (usually `<md-button>`s)
  7931. * for quick access to common actions when a floating action button is activated (via click or
  7932. * keyboard navigation).
  7933. *
  7934. * You may also easily position the trigger by applying one one of the following classes to the
  7935. * `<md-fab-toolbar>` element:
  7936. * - `md-fab-top-left`
  7937. * - `md-fab-top-right`
  7938. * - `md-fab-bottom-left`
  7939. * - `md-fab-bottom-right`
  7940. *
  7941. * These CSS classes use `position: absolute`, so you need to ensure that the container element
  7942. * also uses `position: absolute` or `position: relative` in order for them to work.
  7943. *
  7944. * @usage
  7945. *
  7946. * <hljs lang="html">
  7947. * <md-fab-toolbar md-direction='left'>
  7948. * <md-fab-trigger>
  7949. * <md-button aria-label="Add..."><md-icon icon="/img/icons/plus.svg"></md-icon></md-button>
  7950. * </md-fab-trigger>
  7951. *
  7952. * <md-fab-actions>
  7953. * <md-button aria-label="Add User">
  7954. * <md-icon icon="/img/icons/user.svg"></md-icon>
  7955. * </md-button>
  7956. *
  7957. * <md-button aria-label="Add Group">
  7958. * <md-icon icon="/img/icons/group.svg"></md-icon>
  7959. * </md-button>
  7960. * </md-fab-actions>
  7961. * </md-fab-toolbar>
  7962. * </hljs>
  7963. *
  7964. * @param {string=} md-direction From which direction you would like the toolbar items to appear
  7965. * relative to the trigger element. Supports `left` and `right` directions.
  7966. * @param {expression=} md-open Programmatically control whether or not the toolbar is visible.
  7967. */
  7968. function MdFabToolbarDirective() {
  7969. return {
  7970. restrict: 'E',
  7971. transclude: true,
  7972. template: '<div class="md-fab-toolbar-wrapper">' +
  7973. ' <div class="md-fab-toolbar-content" ng-transclude></div>' +
  7974. '</div>',
  7975. scope: {
  7976. direction: '@?mdDirection',
  7977. isOpen: '=?mdOpen'
  7978. },
  7979. bindToController: true,
  7980. controller: 'FabController',
  7981. controllerAs: 'vm',
  7982. link: link
  7983. };
  7984. function link(scope, element, attributes) {
  7985. // Add the base class for animations
  7986. element.addClass('md-fab-toolbar');
  7987. // Prepend the background element to the trigger's button
  7988. element.find('md-fab-trigger').find('button')
  7989. .prepend('<div class="md-fab-toolbar-background"></div>');
  7990. }
  7991. }
  7992. function MdFabToolbarAnimation() {
  7993. function runAnimation(element, className, done) {
  7994. // If no className was specified, don't do anything
  7995. if (!className) {
  7996. return;
  7997. }
  7998. var el = element[0];
  7999. var ctrl = element.controller('mdFabToolbar');
  8000. // Grab the relevant child elements
  8001. var backgroundElement = el.querySelector('.md-fab-toolbar-background');
  8002. var triggerElement = el.querySelector('md-fab-trigger button');
  8003. var toolbarElement = el.querySelector('md-toolbar');
  8004. var iconElement = el.querySelector('md-fab-trigger button md-icon');
  8005. var actions = element.find('md-fab-actions').children();
  8006. // If we have both elements, use them to position the new background
  8007. if (triggerElement && backgroundElement) {
  8008. // Get our variables
  8009. var color = window.getComputedStyle(triggerElement).getPropertyValue('background-color');
  8010. var width = el.offsetWidth;
  8011. var height = el.offsetHeight;
  8012. // Make a square
  8013. var scale = width * 2;
  8014. // Set some basic styles no matter what animation we're doing
  8015. backgroundElement.style.backgroundColor = color;
  8016. backgroundElement.style.borderRadius = width + 'px';
  8017. // If we're open
  8018. if (ctrl.isOpen) {
  8019. // Turn on toolbar pointer events when closed
  8020. toolbarElement.style.pointerEvents = 'initial';
  8021. // Set the width/height to take up the full toolbar width
  8022. backgroundElement.style.width = scale + 'px';
  8023. backgroundElement.style.height = scale + 'px';
  8024. // Set the top/left to move up/left (or right) by the scale width/height
  8025. backgroundElement.style.top = -(scale / 2) + 'px';
  8026. if (element.hasClass('md-right')) {
  8027. backgroundElement.style.left = -(scale / 2) + 'px';
  8028. backgroundElement.style.right = null;
  8029. }
  8030. if (element.hasClass('md-left')) {
  8031. backgroundElement.style.right = -(scale / 2) + 'px';
  8032. backgroundElement.style.left = null;
  8033. }
  8034. // Set the next close animation to have the proper delays
  8035. backgroundElement.style.transitionDelay = '0ms';
  8036. iconElement && (iconElement.style.transitionDelay = '.3s');
  8037. // Apply a transition delay to actions
  8038. angular.forEach(actions, function(action, index) {
  8039. action.style.transitionDelay = (actions.length - index) * 25 + 'ms';
  8040. });
  8041. } else {
  8042. // Turn off toolbar pointer events when closed
  8043. toolbarElement.style.pointerEvents = 'none';
  8044. // Otherwise, set the width/height to the trigger's width/height
  8045. backgroundElement.style.width = triggerElement.offsetWidth + 'px';
  8046. backgroundElement.style.height = triggerElement.offsetHeight + 'px';
  8047. // Reset the position
  8048. backgroundElement.style.top = '0px';
  8049. if (element.hasClass('md-right')) {
  8050. backgroundElement.style.left = '0px';
  8051. backgroundElement.style.right = null;
  8052. }
  8053. if (element.hasClass('md-left')) {
  8054. backgroundElement.style.right = '0px';
  8055. backgroundElement.style.left = null;
  8056. }
  8057. // Set the next open animation to have the proper delays
  8058. backgroundElement.style.transitionDelay = '200ms';
  8059. iconElement && (iconElement.style.transitionDelay = '0ms');
  8060. // Apply a transition delay to actions
  8061. angular.forEach(actions, function(action, index) {
  8062. action.style.transitionDelay = 200 + (index * 25) + 'ms';
  8063. });
  8064. }
  8065. }
  8066. }
  8067. return {
  8068. addClass: function(element, className, done) {
  8069. runAnimation(element, className, done);
  8070. done();
  8071. },
  8072. removeClass: function(element, className, done) {
  8073. runAnimation(element, className, done);
  8074. done();
  8075. }
  8076. }
  8077. }
  8078. })();
  8079. })();
  8080. (function(){
  8081. "use strict";
  8082. (function() {
  8083. 'use strict';
  8084. /**
  8085. * @ngdoc module
  8086. * @name material.components.fabTrigger
  8087. */
  8088. angular
  8089. .module('material.components.fabTrigger', ['material.core'])
  8090. .directive('mdFabTrigger', MdFabTriggerDirective);
  8091. /**
  8092. * @ngdoc directive
  8093. * @name mdFabTrigger
  8094. * @module material.components.fabSpeedDial
  8095. *
  8096. * @restrict E
  8097. *
  8098. * @description
  8099. * The `<md-fab-trigger>` directive is used inside of a `<md-fab-speed-dial>` or
  8100. * `<md-fab-toolbar>` directive to mark the an element (or elements) as the trigger and setup the
  8101. * proper event listeners.
  8102. *
  8103. * @usage
  8104. * See the `<md-fab-speed-dial>` or `<md-fab-toolbar>` directives for example usage.
  8105. */
  8106. function MdFabTriggerDirective() {
  8107. // TODO: Remove this completely?
  8108. return {
  8109. restrict: 'E',
  8110. require: ['^?mdFabSpeedDial', '^?mdFabToolbar']
  8111. };
  8112. }
  8113. })();
  8114. })();
  8115. (function(){
  8116. "use strict";
  8117. /**
  8118. * @ngdoc module
  8119. * @name material.components.gridList
  8120. */
  8121. angular.module('material.components.gridList', ['material.core'])
  8122. .directive('mdGridList', GridListDirective)
  8123. .directive('mdGridTile', GridTileDirective)
  8124. .directive('mdGridTileFooter', GridTileCaptionDirective)
  8125. .directive('mdGridTileHeader', GridTileCaptionDirective)
  8126. .factory('$mdGridLayout', GridLayoutFactory);
  8127. /**
  8128. * @ngdoc directive
  8129. * @name mdGridList
  8130. * @module material.components.gridList
  8131. * @restrict E
  8132. * @description
  8133. * Grid lists are an alternative to standard list views. Grid lists are distinct
  8134. * from grids used for layouts and other visual presentations.
  8135. *
  8136. * A grid list is best suited to presenting a homogenous data type, typically
  8137. * images, and is optimized for visual comprehension and differentiating between
  8138. * like data types.
  8139. *
  8140. * A grid list is a continuous element consisting of tessellated, regular
  8141. * subdivisions called cells that contain tiles (`md-grid-tile`).
  8142. *
  8143. * <img src="//material-design.storage.googleapis.com/publish/v_2/material_ext_publish/0Bx4BSt6jniD7OVlEaXZ5YmU1Xzg/components_grids_usage2.png"
  8144. * style="width: 300px; height: auto; margin-right: 16px;" alt="Concept of grid explained visually">
  8145. * <img src="//material-design.storage.googleapis.com/publish/v_2/material_ext_publish/0Bx4BSt6jniD7VGhsOE5idWlJWXM/components_grids_usage3.png"
  8146. * style="width: 300px; height: auto;" alt="Grid concepts legend">
  8147. *
  8148. * Cells are arrayed vertically and horizontally within the grid.
  8149. *
  8150. * Tiles hold content and can span one or more cells vertically or horizontally.
  8151. *
  8152. * ### Responsive Attributes
  8153. *
  8154. * The `md-grid-list` directive supports "responsive" attributes, which allow
  8155. * different `md-cols`, `md-gutter` and `md-row-height` values depending on the
  8156. * currently matching media query (as defined in `$mdConstant.MEDIA`).
  8157. *
  8158. * In order to set a responsive attribute, first define the fallback value with
  8159. * the standard attribute name, then add additional attributes with the
  8160. * following convention: `{base-attribute-name}-{media-query-name}="{value}"`
  8161. * (ie. `md-cols-lg="8"`)
  8162. *
  8163. * @param {number} md-cols Number of columns in the grid.
  8164. * @param {string} md-row-height One of
  8165. * <ul>
  8166. * <li>CSS length - Fixed height rows (eg. `8px` or `1rem`)</li>
  8167. * <li>`{width}:{height}` - Ratio of width to height (eg.
  8168. * `md-row-height="16:9"`)</li>
  8169. * <li>`"fit"` - Height will be determined by subdividing the available
  8170. * height by the number of rows</li>
  8171. * </ul>
  8172. * @param {string=} md-gutter The amount of space between tiles in CSS units
  8173. * (default 1px)
  8174. * @param {expression=} md-on-layout Expression to evaluate after layout. Event
  8175. * object is available as `$event`, and contains performance information.
  8176. *
  8177. * @usage
  8178. * Basic:
  8179. * <hljs lang="html">
  8180. * <md-grid-list md-cols="5" md-gutter="1em" md-row-height="4:3">
  8181. * <md-grid-tile></md-grid-tile>
  8182. * </md-grid-list>
  8183. * </hljs>
  8184. *
  8185. * Fixed-height rows:
  8186. * <hljs lang="html">
  8187. * <md-grid-list md-cols="4" md-row-height="200px" ...>
  8188. * <md-grid-tile></md-grid-tile>
  8189. * </md-grid-list>
  8190. * </hljs>
  8191. *
  8192. * Fit rows:
  8193. * <hljs lang="html">
  8194. * <md-grid-list md-cols="4" md-row-height="fit" style="height: 400px;" ...>
  8195. * <md-grid-tile></md-grid-tile>
  8196. * </md-grid-list>
  8197. * </hljs>
  8198. *
  8199. * Using responsive attributes:
  8200. * <hljs lang="html">
  8201. * <md-grid-list
  8202. * md-cols-sm="2"
  8203. * md-cols-md="4"
  8204. * md-cols-lg="8"
  8205. * md-cols-gt-lg="12"
  8206. * ...>
  8207. * <md-grid-tile></md-grid-tile>
  8208. * </md-grid-list>
  8209. * </hljs>
  8210. */
  8211. function GridListDirective($interpolate, $mdConstant, $mdGridLayout, $mdMedia) {
  8212. return {
  8213. restrict: 'E',
  8214. controller: GridListController,
  8215. scope: {
  8216. mdOnLayout: '&'
  8217. },
  8218. link: postLink
  8219. };
  8220. function postLink(scope, element, attrs, ctrl) {
  8221. // Apply semantics
  8222. element.attr('role', 'list');
  8223. // Provide the controller with a way to trigger layouts.
  8224. ctrl.layoutDelegate = layoutDelegate;
  8225. var invalidateLayout = angular.bind(ctrl, ctrl.invalidateLayout),
  8226. unwatchAttrs = watchMedia();
  8227. scope.$on('$destroy', unwatchMedia);
  8228. /**
  8229. * Watches for changes in media, invalidating layout as necessary.
  8230. */
  8231. function watchMedia() {
  8232. for (var mediaName in $mdConstant.MEDIA) {
  8233. $mdMedia(mediaName); // initialize
  8234. $mdMedia.getQuery($mdConstant.MEDIA[mediaName])
  8235. .addListener(invalidateLayout);
  8236. }
  8237. return $mdMedia.watchResponsiveAttributes(
  8238. ['md-cols', 'md-row-height'], attrs, layoutIfMediaMatch);
  8239. }
  8240. function unwatchMedia() {
  8241. ctrl.layoutDelegate = angular.noop;
  8242. unwatchAttrs();
  8243. for (var mediaName in $mdConstant.MEDIA) {
  8244. $mdMedia.getQuery($mdConstant.MEDIA[mediaName])
  8245. .removeListener(invalidateLayout);
  8246. }
  8247. }
  8248. /**
  8249. * Performs grid layout if the provided mediaName matches the currently
  8250. * active media type.
  8251. */
  8252. function layoutIfMediaMatch(mediaName) {
  8253. if (mediaName == null) {
  8254. // TODO(shyndman): It would be nice to only layout if we have
  8255. // instances of attributes using this media type
  8256. ctrl.invalidateLayout();
  8257. } else if ($mdMedia(mediaName)) {
  8258. ctrl.invalidateLayout();
  8259. }
  8260. }
  8261. var lastLayoutProps;
  8262. /**
  8263. * Invokes the layout engine, and uses its results to lay out our
  8264. * tile elements.
  8265. *
  8266. * @param {boolean} tilesInvalidated Whether tiles have been
  8267. * added/removed/moved since the last layout. This is to avoid situations
  8268. * where tiles are replaced with properties identical to their removed
  8269. * counterparts.
  8270. */
  8271. function layoutDelegate(tilesInvalidated) {
  8272. var tiles = getTileElements();
  8273. var props = {
  8274. tileSpans: getTileSpans(tiles),
  8275. colCount: getColumnCount(),
  8276. rowMode: getRowMode(),
  8277. rowHeight: getRowHeight(),
  8278. gutter: getGutter()
  8279. };
  8280. if (!tilesInvalidated && angular.equals(props, lastLayoutProps)) {
  8281. return;
  8282. }
  8283. var performance =
  8284. $mdGridLayout(props.colCount, props.tileSpans, tiles)
  8285. .map(function(tilePositions, rowCount) {
  8286. return {
  8287. grid: {
  8288. element: element,
  8289. style: getGridStyle(props.colCount, rowCount,
  8290. props.gutter, props.rowMode, props.rowHeight)
  8291. },
  8292. tiles: tilePositions.map(function(ps, i) {
  8293. return {
  8294. element: angular.element(tiles[i]),
  8295. style: getTileStyle(ps.position, ps.spans,
  8296. props.colCount, props.rowCount,
  8297. props.gutter, props.rowMode, props.rowHeight)
  8298. }
  8299. })
  8300. }
  8301. })
  8302. .reflow()
  8303. .performance();
  8304. // Report layout
  8305. scope.mdOnLayout({
  8306. $event: {
  8307. performance: performance
  8308. }
  8309. });
  8310. lastLayoutProps = props;
  8311. }
  8312. // Use $interpolate to do some simple string interpolation as a convenience.
  8313. var startSymbol = $interpolate.startSymbol();
  8314. var endSymbol = $interpolate.endSymbol();
  8315. // Returns an expression wrapped in the interpolator's start and end symbols.
  8316. function expr(exprStr) {
  8317. return startSymbol + exprStr + endSymbol;
  8318. }
  8319. // The amount of space a single 1x1 tile would take up (either width or height), used as
  8320. // a basis for other calculations. This consists of taking the base size percent (as would be
  8321. // if evenly dividing the size between cells), and then subtracting the size of one gutter.
  8322. // However, since there are no gutters on the edges, each tile only uses a fration
  8323. // (gutterShare = numGutters / numCells) of the gutter size. (Imagine having one gutter per
  8324. // tile, and then breaking up the extra gutter on the edge evenly among the cells).
  8325. var UNIT = $interpolate(expr('share') + '% - (' + expr('gutter') + ' * ' + expr('gutterShare') + ')');
  8326. // The horizontal or vertical position of a tile, e.g., the 'top' or 'left' property value.
  8327. // The position comes the size of a 1x1 tile plus gutter for each previous tile in the
  8328. // row/column (offset).
  8329. var POSITION = $interpolate('calc((' + expr('unit') + ' + ' + expr('gutter') + ') * ' + expr('offset') + ')');
  8330. // The actual size of a tile, e.g., width or height, taking rowSpan or colSpan into account.
  8331. // This is computed by multiplying the base unit by the rowSpan/colSpan, and then adding back
  8332. // in the space that the gutter would normally have used (which was already accounted for in
  8333. // the base unit calculation).
  8334. var DIMENSION = $interpolate('calc((' + expr('unit') + ') * ' + expr('span') + ' + (' + expr('span') + ' - 1) * ' + expr('gutter') + ')');
  8335. /**
  8336. * Gets the styles applied to a tile element described by the given parameters.
  8337. * @param {{row: number, col: number}} position The row and column indices of the tile.
  8338. * @param {{row: number, col: number}} spans The rowSpan and colSpan of the tile.
  8339. * @param {number} colCount The number of columns.
  8340. * @param {number} rowCount The number of rows.
  8341. * @param {string} gutter The amount of space between tiles. This will be something like
  8342. * '5px' or '2em'.
  8343. * @param {string} rowMode The row height mode. Can be one of:
  8344. * 'fixed': all rows have a fixed size, given by rowHeight,
  8345. * 'ratio': row height defined as a ratio to width, or
  8346. * 'fit': fit to the grid-list element height, divinding evenly among rows.
  8347. * @param {string|number} rowHeight The height of a row. This is only used for 'fixed' mode and
  8348. * for 'ratio' mode. For 'ratio' mode, this is the *ratio* of width-to-height (e.g., 0.75).
  8349. * @returns {Object} Map of CSS properties to be applied to the style element. Will define
  8350. * values for top, left, width, height, marginTop, and paddingTop.
  8351. */
  8352. function getTileStyle(position, spans, colCount, rowCount, gutter, rowMode, rowHeight) {
  8353. // TODO(shyndman): There are style caching opportunities here.
  8354. // Percent of the available horizontal space that one column takes up.
  8355. var hShare = (1 / colCount) * 100;
  8356. // Fraction of the gutter size that each column takes up.
  8357. var hGutterShare = (colCount - 1) / colCount;
  8358. // Base horizontal size of a column.
  8359. var hUnit = UNIT({share: hShare, gutterShare: hGutterShare, gutter: gutter});
  8360. // The width and horizontal position of each tile is always calculated the same way, but the
  8361. // height and vertical position depends on the rowMode.
  8362. var style = {
  8363. left: POSITION({ unit: hUnit, offset: position.col, gutter: gutter }),
  8364. width: DIMENSION({ unit: hUnit, span: spans.col, gutter: gutter }),
  8365. // resets
  8366. paddingTop: '',
  8367. marginTop: '',
  8368. top: '',
  8369. height: ''
  8370. };
  8371. switch (rowMode) {
  8372. case 'fixed':
  8373. // In fixed mode, simply use the given rowHeight.
  8374. style.top = POSITION({ unit: rowHeight, offset: position.row, gutter: gutter });
  8375. style.height = DIMENSION({ unit: rowHeight, span: spans.row, gutter: gutter });
  8376. break;
  8377. case 'ratio':
  8378. // Percent of the available vertical space that one row takes up. Here, rowHeight holds
  8379. // the ratio value. For example, if the width:height ratio is 4:3, rowHeight = 1.333.
  8380. var vShare = hShare / rowHeight;
  8381. // Base veritcal size of a row.
  8382. var vUnit = UNIT({ share: vShare, gutterShare: hGutterShare, gutter: gutter });
  8383. // padidngTop and marginTop are used to maintain the given aspect ratio, as
  8384. // a percentage-based value for these properties is applied to the *width* of the
  8385. // containing block. See http://www.w3.org/TR/CSS2/box.html#margin-properties
  8386. style.paddingTop = DIMENSION({ unit: vUnit, span: spans.row, gutter: gutter});
  8387. style.marginTop = POSITION({ unit: vUnit, offset: position.row, gutter: gutter });
  8388. break;
  8389. case 'fit':
  8390. // Fraction of the gutter size that each column takes up.
  8391. var vGutterShare = (rowCount - 1) / rowCount;
  8392. // Percent of the available vertical space that one row takes up.
  8393. var vShare = (1 / rowCount) * 100;
  8394. // Base vertical size of a row.
  8395. var vUnit = UNIT({share: vShare, gutterShare: vGutterShare, gutter: gutter});
  8396. style.top = POSITION({unit: vUnit, offset: position.row, gutter: gutter});
  8397. style.height = DIMENSION({unit: vUnit, span: spans.row, gutter: gutter});
  8398. break;
  8399. }
  8400. return style;
  8401. }
  8402. function getGridStyle(colCount, rowCount, gutter, rowMode, rowHeight) {
  8403. var style = {
  8404. height: '',
  8405. paddingBottom: ''
  8406. };
  8407. switch(rowMode) {
  8408. case 'fixed':
  8409. style.height = DIMENSION({ unit: rowHeight, span: rowCount, gutter: gutter });
  8410. break;
  8411. case 'ratio':
  8412. // rowHeight is width / height
  8413. var hGutterShare = colCount === 1 ? 0 : (colCount - 1) / colCount,
  8414. hShare = (1 / colCount) * 100,
  8415. vShare = hShare * (1 / rowHeight),
  8416. vUnit = UNIT({ share: vShare, gutterShare: hGutterShare, gutter: gutter });
  8417. style.paddingBottom = DIMENSION({ unit: vUnit, span: rowCount, gutter: gutter});
  8418. break;
  8419. case 'fit':
  8420. // noop, as the height is user set
  8421. break;
  8422. }
  8423. return style;
  8424. }
  8425. function getTileElements() {
  8426. return [].filter.call(element.children(), function(ele) {
  8427. return ele.tagName == 'MD-GRID-TILE';
  8428. });
  8429. }
  8430. /**
  8431. * Gets an array of objects containing the rowspan and colspan for each tile.
  8432. * @returns {Array<{row: number, col: number}>}
  8433. */
  8434. function getTileSpans(tileElements) {
  8435. return [].map.call(tileElements, function(ele) {
  8436. var ctrl = angular.element(ele).controller('mdGridTile');
  8437. return {
  8438. row: parseInt(
  8439. $mdMedia.getResponsiveAttribute(ctrl.$attrs, 'md-rowspan'), 10) || 1,
  8440. col: parseInt(
  8441. $mdMedia.getResponsiveAttribute(ctrl.$attrs, 'md-colspan'), 10) || 1
  8442. };
  8443. });
  8444. }
  8445. function getColumnCount() {
  8446. var colCount = parseInt($mdMedia.getResponsiveAttribute(attrs, 'md-cols'), 10);
  8447. if (isNaN(colCount)) {
  8448. throw 'md-grid-list: md-cols attribute was not found, or contained a non-numeric value';
  8449. }
  8450. return colCount;
  8451. }
  8452. function getGutter() {
  8453. return applyDefaultUnit($mdMedia.getResponsiveAttribute(attrs, 'md-gutter') || 1);
  8454. }
  8455. function getRowHeight() {
  8456. var rowHeight = $mdMedia.getResponsiveAttribute(attrs, 'md-row-height');
  8457. switch (getRowMode()) {
  8458. case 'fixed':
  8459. return applyDefaultUnit(rowHeight);
  8460. case 'ratio':
  8461. var whRatio = rowHeight.split(':');
  8462. return parseFloat(whRatio[0]) / parseFloat(whRatio[1]);
  8463. case 'fit':
  8464. return 0; // N/A
  8465. }
  8466. }
  8467. function getRowMode() {
  8468. var rowHeight = $mdMedia.getResponsiveAttribute(attrs, 'md-row-height');
  8469. if (rowHeight == 'fit') {
  8470. return 'fit';
  8471. } else if (rowHeight.indexOf(':') !== -1) {
  8472. return 'ratio';
  8473. } else {
  8474. return 'fixed';
  8475. }
  8476. }
  8477. function applyDefaultUnit(val) {
  8478. return /\D$/.test(val) ? val : val + 'px';
  8479. }
  8480. }
  8481. }
  8482. GridListDirective.$inject = ["$interpolate", "$mdConstant", "$mdGridLayout", "$mdMedia"];
  8483. /* @ngInject */
  8484. function GridListController($mdUtil) {
  8485. this.layoutInvalidated = false;
  8486. this.tilesInvalidated = false;
  8487. this.$timeout_ = $mdUtil.nextTick;
  8488. this.layoutDelegate = angular.noop;
  8489. }
  8490. GridListController.$inject = ["$mdUtil"];
  8491. GridListController.prototype = {
  8492. invalidateTiles: function() {
  8493. this.tilesInvalidated = true;
  8494. this.invalidateLayout();
  8495. },
  8496. invalidateLayout: function() {
  8497. if (this.layoutInvalidated) {
  8498. return;
  8499. }
  8500. this.layoutInvalidated = true;
  8501. this.$timeout_(angular.bind(this, this.layout));
  8502. },
  8503. layout: function() {
  8504. try {
  8505. this.layoutDelegate(this.tilesInvalidated);
  8506. } finally {
  8507. this.layoutInvalidated = false;
  8508. this.tilesInvalidated = false;
  8509. }
  8510. }
  8511. };
  8512. /* @ngInject */
  8513. function GridLayoutFactory($mdUtil) {
  8514. var defaultAnimator = GridTileAnimator;
  8515. /**
  8516. * Set the reflow animator callback
  8517. */
  8518. GridLayout.animateWith = function(customAnimator) {
  8519. defaultAnimator = !angular.isFunction(customAnimator) ? GridTileAnimator : customAnimator;
  8520. };
  8521. return GridLayout;
  8522. /**
  8523. * Publish layout function
  8524. */
  8525. function GridLayout(colCount, tileSpans) {
  8526. var self, layoutInfo, gridStyles, layoutTime, mapTime, reflowTime;
  8527. layoutTime = $mdUtil.time(function() {
  8528. layoutInfo = calculateGridFor(colCount, tileSpans);
  8529. });
  8530. return self = {
  8531. /**
  8532. * An array of objects describing each tile's position in the grid.
  8533. */
  8534. layoutInfo: function() {
  8535. return layoutInfo;
  8536. },
  8537. /**
  8538. * Maps grid positioning to an element and a set of styles using the
  8539. * provided updateFn.
  8540. */
  8541. map: function(updateFn) {
  8542. mapTime = $mdUtil.time(function() {
  8543. var info = self.layoutInfo();
  8544. gridStyles = updateFn(info.positioning, info.rowCount);
  8545. });
  8546. return self;
  8547. },
  8548. /**
  8549. * Default animator simply sets the element.css( <styles> ). An alternate
  8550. * animator can be provided as an argument. The function has the following
  8551. * signature:
  8552. *
  8553. * function({grid: {element: JQLite, style: Object}, tiles: Array<{element: JQLite, style: Object}>)
  8554. */
  8555. reflow: function(animatorFn) {
  8556. reflowTime = $mdUtil.time(function() {
  8557. var animator = animatorFn || defaultAnimator;
  8558. animator(gridStyles.grid, gridStyles.tiles);
  8559. });
  8560. return self;
  8561. },
  8562. /**
  8563. * Timing for the most recent layout run.
  8564. */
  8565. performance: function() {
  8566. return {
  8567. tileCount: tileSpans.length,
  8568. layoutTime: layoutTime,
  8569. mapTime: mapTime,
  8570. reflowTime: reflowTime,
  8571. totalTime: layoutTime + mapTime + reflowTime
  8572. };
  8573. }
  8574. };
  8575. }
  8576. /**
  8577. * Default Gridlist animator simple sets the css for each element;
  8578. * NOTE: any transitions effects must be manually set in the CSS.
  8579. * e.g.
  8580. *
  8581. * md-grid-tile {
  8582. * transition: all 700ms ease-out 50ms;
  8583. * }
  8584. *
  8585. */
  8586. function GridTileAnimator(grid, tiles) {
  8587. grid.element.css(grid.style);
  8588. tiles.forEach(function(t) {
  8589. t.element.css(t.style);
  8590. })
  8591. }
  8592. /**
  8593. * Calculates the positions of tiles.
  8594. *
  8595. * The algorithm works as follows:
  8596. * An Array<Number> with length colCount (spaceTracker) keeps track of
  8597. * available tiling positions, where elements of value 0 represents an
  8598. * empty position. Space for a tile is reserved by finding a sequence of
  8599. * 0s with length <= than the tile's colspan. When such a space has been
  8600. * found, the occupied tile positions are incremented by the tile's
  8601. * rowspan value, as these positions have become unavailable for that
  8602. * many rows.
  8603. *
  8604. * If the end of a row has been reached without finding space for the
  8605. * tile, spaceTracker's elements are each decremented by 1 to a minimum
  8606. * of 0. Rows are searched in this fashion until space is found.
  8607. */
  8608. function calculateGridFor(colCount, tileSpans) {
  8609. var curCol = 0,
  8610. curRow = 0,
  8611. spaceTracker = newSpaceTracker();
  8612. return {
  8613. positioning: tileSpans.map(function(spans, i) {
  8614. return {
  8615. spans: spans,
  8616. position: reserveSpace(spans, i)
  8617. };
  8618. }),
  8619. rowCount: curRow + Math.max.apply(Math, spaceTracker)
  8620. };
  8621. function reserveSpace(spans, i) {
  8622. if (spans.col > colCount) {
  8623. throw 'md-grid-list: Tile at position ' + i + ' has a colspan ' +
  8624. '(' + spans.col + ') that exceeds the column count ' +
  8625. '(' + colCount + ')';
  8626. }
  8627. var start = 0,
  8628. end = 0;
  8629. // TODO(shyndman): This loop isn't strictly necessary if you can
  8630. // determine the minimum number of rows before a space opens up. To do
  8631. // this, recognize that you've iterated across an entire row looking for
  8632. // space, and if so fast-forward by the minimum rowSpan count. Repeat
  8633. // until the required space opens up.
  8634. while (end - start < spans.col) {
  8635. if (curCol >= colCount) {
  8636. nextRow();
  8637. continue;
  8638. }
  8639. start = spaceTracker.indexOf(0, curCol);
  8640. if (start === -1 || (end = findEnd(start + 1)) === -1) {
  8641. start = end = 0;
  8642. nextRow();
  8643. continue;
  8644. }
  8645. curCol = end + 1;
  8646. }
  8647. adjustRow(start, spans.col, spans.row);
  8648. curCol = start + spans.col;
  8649. return {
  8650. col: start,
  8651. row: curRow
  8652. };
  8653. }
  8654. function nextRow() {
  8655. curCol = 0;
  8656. curRow++;
  8657. adjustRow(0, colCount, -1); // Decrement row spans by one
  8658. }
  8659. function adjustRow(from, cols, by) {
  8660. for (var i = from; i < from + cols; i++) {
  8661. spaceTracker[i] = Math.max(spaceTracker[i] + by, 0);
  8662. }
  8663. }
  8664. function findEnd(start) {
  8665. var i;
  8666. for (i = start; i < spaceTracker.length; i++) {
  8667. if (spaceTracker[i] !== 0) {
  8668. return i;
  8669. }
  8670. }
  8671. if (i === spaceTracker.length) {
  8672. return i;
  8673. }
  8674. }
  8675. function newSpaceTracker() {
  8676. var tracker = [];
  8677. for (var i = 0; i < colCount; i++) {
  8678. tracker.push(0);
  8679. }
  8680. return tracker;
  8681. }
  8682. }
  8683. }
  8684. GridLayoutFactory.$inject = ["$mdUtil"];
  8685. /**
  8686. * @ngdoc directive
  8687. * @name mdGridTile
  8688. * @module material.components.gridList
  8689. * @restrict E
  8690. * @description
  8691. * Tiles contain the content of an `md-grid-list`. They span one or more grid
  8692. * cells vertically or horizontally, and use `md-grid-tile-{footer,header}` to
  8693. * display secondary content.
  8694. *
  8695. * ### Responsive Attributes
  8696. *
  8697. * The `md-grid-tile` directive supports "responsive" attributes, which allow
  8698. * different `md-rowspan` and `md-colspan` values depending on the currently
  8699. * matching media query (as defined in `$mdConstant.MEDIA`).
  8700. *
  8701. * In order to set a responsive attribute, first define the fallback value with
  8702. * the standard attribute name, then add additional attributes with the
  8703. * following convention: `{base-attribute-name}-{media-query-name}="{value}"`
  8704. * (ie. `md-colspan-sm="4"`)
  8705. *
  8706. * @param {number=} md-colspan The number of columns to span (default 1). Cannot
  8707. * exceed the number of columns in the grid. Supports interpolation.
  8708. * @param {number=} md-rowspan The number of rows to span (default 1). Supports
  8709. * interpolation.
  8710. *
  8711. * @usage
  8712. * With header:
  8713. * <hljs lang="html">
  8714. * <md-grid-tile>
  8715. * <md-grid-tile-header>
  8716. * <h3>This is a header</h3>
  8717. * </md-grid-tile-header>
  8718. * </md-grid-tile>
  8719. * </hljs>
  8720. *
  8721. * With footer:
  8722. * <hljs lang="html">
  8723. * <md-grid-tile>
  8724. * <md-grid-tile-footer>
  8725. * <h3>This is a footer</h3>
  8726. * </md-grid-tile-footer>
  8727. * </md-grid-tile>
  8728. * </hljs>
  8729. *
  8730. * Spanning multiple rows/columns:
  8731. * <hljs lang="html">
  8732. * <md-grid-tile md-colspan="2" md-rowspan="3">
  8733. * </md-grid-tile>
  8734. * </hljs>
  8735. *
  8736. * Responsive attributes:
  8737. * <hljs lang="html">
  8738. * <md-grid-tile md-colspan="1" md-colspan-sm="3" md-colspan-md="5">
  8739. * </md-grid-tile>
  8740. * </hljs>
  8741. */
  8742. function GridTileDirective($mdMedia) {
  8743. return {
  8744. restrict: 'E',
  8745. require: '^mdGridList',
  8746. template: '<figure ng-transclude></figure>',
  8747. transclude: true,
  8748. scope: {},
  8749. // Simple controller that exposes attributes to the grid directive
  8750. controller: ["$attrs", function($attrs) {
  8751. this.$attrs = $attrs;
  8752. }],
  8753. link: postLink
  8754. };
  8755. function postLink(scope, element, attrs, gridCtrl) {
  8756. // Apply semantics
  8757. element.attr('role', 'listitem');
  8758. // If our colspan or rowspan changes, trigger a layout
  8759. var unwatchAttrs = $mdMedia.watchResponsiveAttributes(['md-colspan', 'md-rowspan'],
  8760. attrs, angular.bind(gridCtrl, gridCtrl.invalidateLayout));
  8761. // Tile registration/deregistration
  8762. gridCtrl.invalidateTiles();
  8763. scope.$on('$destroy', function() {
  8764. unwatchAttrs();
  8765. gridCtrl.invalidateLayout();
  8766. });
  8767. if (angular.isDefined(scope.$parent.$index)) {
  8768. scope.$watch(function() { return scope.$parent.$index; },
  8769. function indexChanged(newIdx, oldIdx) {
  8770. if (newIdx === oldIdx) {
  8771. return;
  8772. }
  8773. gridCtrl.invalidateTiles();
  8774. });
  8775. }
  8776. }
  8777. }
  8778. GridTileDirective.$inject = ["$mdMedia"];
  8779. function GridTileCaptionDirective() {
  8780. return {
  8781. template: '<figcaption ng-transclude></figcaption>',
  8782. transclude: true
  8783. };
  8784. }
  8785. })();
  8786. (function(){
  8787. "use strict";
  8788. /**
  8789. * @ngdoc module
  8790. * @name material.components.icon
  8791. * @description
  8792. * Icon
  8793. */
  8794. angular.module('material.components.icon', [
  8795. 'material.core'
  8796. ]);
  8797. })();
  8798. (function(){
  8799. "use strict";
  8800. /**
  8801. * @ngdoc module
  8802. * @name material.components.input
  8803. */
  8804. angular.module('material.components.input', [
  8805. 'material.core'
  8806. ])
  8807. .directive('mdInputContainer', mdInputContainerDirective)
  8808. .directive('label', labelDirective)
  8809. .directive('input', inputTextareaDirective)
  8810. .directive('textarea', inputTextareaDirective)
  8811. .directive('mdMaxlength', mdMaxlengthDirective)
  8812. .directive('placeholder', placeholderDirective);
  8813. /**
  8814. * @ngdoc directive
  8815. * @name mdInputContainer
  8816. * @module material.components.input
  8817. *
  8818. * @restrict E
  8819. *
  8820. * @description
  8821. * `<md-input-container>` is the parent of any input or textarea element.
  8822. *
  8823. * Input and textarea elements will not behave properly unless the md-input-container
  8824. * parent is provided.
  8825. *
  8826. * @param md-is-error {expression=} When the given expression evaluates to true, the input container will go into error state. Defaults to erroring if the input has been touched and is invalid.
  8827. * @param md-no-float {boolean=} When present, placeholders will not be converted to floating labels
  8828. *
  8829. * @usage
  8830. * <hljs lang="html">
  8831. *
  8832. * <md-input-container>
  8833. * <label>Username</label>
  8834. * <input type="text" ng-model="user.name">
  8835. * </md-input-container>
  8836. *
  8837. * <md-input-container>
  8838. * <label>Description</label>
  8839. * <textarea ng-model="user.description"></textarea>
  8840. * </md-input-container>
  8841. *
  8842. * </hljs>
  8843. */
  8844. function mdInputContainerDirective($mdTheming, $parse) {
  8845. ContainerCtrl.$inject = ["$scope", "$element", "$attrs"];
  8846. return {
  8847. restrict: 'E',
  8848. link: postLink,
  8849. controller: ContainerCtrl
  8850. };
  8851. function postLink(scope, element, attr) {
  8852. $mdTheming(element);
  8853. }
  8854. function ContainerCtrl($scope, $element, $attrs) {
  8855. var self = this;
  8856. self.isErrorGetter = $attrs.mdIsError && $parse($attrs.mdIsError);
  8857. self.delegateClick = function() {
  8858. self.input.focus();
  8859. };
  8860. self.element = $element;
  8861. self.setFocused = function(isFocused) {
  8862. $element.toggleClass('md-input-focused', !!isFocused);
  8863. };
  8864. self.setHasValue = function(hasValue) {
  8865. $element.toggleClass('md-input-has-value', !!hasValue);
  8866. };
  8867. self.setInvalid = function(isInvalid) {
  8868. $element.toggleClass('md-input-invalid', !!isInvalid);
  8869. };
  8870. $scope.$watch(function() {
  8871. return self.label && self.input;
  8872. }, function(hasLabelAndInput) {
  8873. if (hasLabelAndInput && !self.label.attr('for')) {
  8874. self.label.attr('for', self.input.attr('id'));
  8875. }
  8876. });
  8877. }
  8878. }
  8879. mdInputContainerDirective.$inject = ["$mdTheming", "$parse"];
  8880. function labelDirective() {
  8881. return {
  8882. restrict: 'E',
  8883. require: '^?mdInputContainer',
  8884. link: function(scope, element, attr, containerCtrl) {
  8885. if (!containerCtrl || attr.mdNoFloat) return;
  8886. containerCtrl.label = element;
  8887. scope.$on('$destroy', function() {
  8888. containerCtrl.label = null;
  8889. });
  8890. }
  8891. };
  8892. }
  8893. /**
  8894. * @ngdoc directive
  8895. * @name mdInput
  8896. * @restrict E
  8897. * @module material.components.input
  8898. *
  8899. * @description
  8900. * Use the `<input>` or the `<textarea>` as a child of an `<md-input-container>`.
  8901. *
  8902. * @param {number=} md-maxlength The maximum number of characters allowed in this input. If this is specified, a character counter will be shown underneath the input.<br/><br/>
  8903. * The purpose of **`md-maxlength`** is exactly to show the max length counter text. If you don't want the counter text and only need "plain" validation, you can use the "simple" `ng-maxlength` or maxlength attributes.
  8904. * @param {string=} aria-label Aria-label is required when no label is present. A warning message will be logged in the console if not present.
  8905. * @param {string=} placeholder An alternative approach to using aria-label when the label is not present. The placeholder text is copied to the aria-label attribute.
  8906. * @param md-no-autogrow {boolean=} When present, textareas will not grow automatically.
  8907. *
  8908. * @usage
  8909. * <hljs lang="html">
  8910. * <md-input-container>
  8911. * <label>Color</label>
  8912. * <input type="text" ng-model="color" required md-maxlength="10">
  8913. * </md-input-container>
  8914. * </hljs>
  8915. * <h3>With Errors</h3>
  8916. *
  8917. * <hljs lang="html">
  8918. * <form name="userForm">
  8919. * <md-input-container>
  8920. * <label>Last Name</label>
  8921. * <input name="lastName" ng-model="lastName" required md-maxlength="10" minlength="4">
  8922. * <div ng-messages="userForm.lastName.$error" ng-show="userForm.lastName.$dirty">
  8923. * <div ng-message="required">This is required!</div>
  8924. * <div ng-message="md-maxlength">That's too long!</div>
  8925. * <div ng-message="minlength">That's too short!</div>
  8926. * </div>
  8927. * </md-input-container>
  8928. * <md-input-container>
  8929. * <label>Biography</label>
  8930. * <textarea name="bio" ng-model="biography" required md-maxlength="150"></textarea>
  8931. * <div ng-messages="userForm.bio.$error" ng-show="userForm.bio.$dirty">
  8932. * <div ng-message="required">This is required!</div>
  8933. * <div ng-message="md-maxlength">That's too long!</div>
  8934. * </div>
  8935. * </md-input-container>
  8936. * <md-input-container>
  8937. * <input aria-label='title' ng-model='title'>
  8938. * </md-input-container>
  8939. * <md-input-container>
  8940. * <input placeholder='title' ng-model='title'>
  8941. * </md-input-container>
  8942. * </form>
  8943. * </hljs>
  8944. *
  8945. * Requires [ngMessages](https://docs.angularjs.org/api/ngMessages).
  8946. * Behaves like the [AngularJS input directive](https://docs.angularjs.org/api/ng/directive/input).
  8947. *
  8948. */
  8949. function inputTextareaDirective($mdUtil, $window, $mdAria) {
  8950. return {
  8951. restrict: 'E',
  8952. require: ['^?mdInputContainer', '?ngModel'],
  8953. link: postLink
  8954. };
  8955. function postLink(scope, element, attr, ctrls) {
  8956. var containerCtrl = ctrls[0];
  8957. var hasNgModel = !!ctrls[1];
  8958. var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel();
  8959. var isReadonly = angular.isDefined(attr.readonly);
  8960. if ( !containerCtrl ) return;
  8961. if (containerCtrl.input) {
  8962. throw new Error("<md-input-container> can only have *one* <input>, <textarea> or <md-select> child element!");
  8963. }
  8964. containerCtrl.input = element;
  8965. if(!containerCtrl.label) {
  8966. $mdAria.expect(element, 'aria-label', element.attr('placeholder'));
  8967. }
  8968. element.addClass('md-input');
  8969. if (!element.attr('id')) {
  8970. element.attr('id', 'input_' + $mdUtil.nextUid());
  8971. }
  8972. if (element[0].tagName.toLowerCase() === 'textarea') {
  8973. setupTextarea();
  8974. }
  8975. // If the input doesn't have an ngModel, it may have a static value. For that case,
  8976. // we have to do one initial check to determine if the container should be in the
  8977. // "has a value" state.
  8978. if (!hasNgModel) {
  8979. inputCheckValue();
  8980. }
  8981. var isErrorGetter = containerCtrl.isErrorGetter || function() {
  8982. return ngModelCtrl.$invalid && ngModelCtrl.$touched;
  8983. };
  8984. scope.$watch(isErrorGetter, containerCtrl.setInvalid);
  8985. ngModelCtrl.$parsers.push(ngModelPipelineCheckValue);
  8986. ngModelCtrl.$formatters.push(ngModelPipelineCheckValue);
  8987. element.on('input', inputCheckValue);
  8988. if (!isReadonly) {
  8989. element
  8990. .on('focus', function(ev) {
  8991. containerCtrl.setFocused(true);
  8992. })
  8993. .on('blur', function(ev) {
  8994. containerCtrl.setFocused(false);
  8995. inputCheckValue();
  8996. });
  8997. }
  8998. //ngModelCtrl.$setTouched();
  8999. //if( ngModelCtrl.$invalid ) containerCtrl.setInvalid();
  9000. scope.$on('$destroy', function() {
  9001. containerCtrl.setFocused(false);
  9002. containerCtrl.setHasValue(false);
  9003. containerCtrl.input = null;
  9004. });
  9005. /**
  9006. *
  9007. */
  9008. function ngModelPipelineCheckValue(arg) {
  9009. containerCtrl.setHasValue(!ngModelCtrl.$isEmpty(arg));
  9010. return arg;
  9011. }
  9012. function inputCheckValue() {
  9013. // An input's value counts if its length > 0,
  9014. // or if the input's validity state says it has bad input (eg string in a number input)
  9015. containerCtrl.setHasValue(element.val().length > 0 || (element[0].validity||{}).badInput);
  9016. }
  9017. function setupTextarea() {
  9018. if(angular.isDefined(element.attr('md-no-autogrow'))) {
  9019. return;
  9020. }
  9021. var node = element[0];
  9022. var container = containerCtrl.element[0];
  9023. var min_rows = NaN;
  9024. var lineHeight = null;
  9025. // can't check if height was or not explicity set,
  9026. // so rows attribute will take precedence if present
  9027. if(node.hasAttribute('rows')) {
  9028. min_rows = parseInt(node.getAttribute('rows'));
  9029. }
  9030. var onChangeTextarea = $mdUtil.debounce(growTextarea, 1);
  9031. function pipelineListener(value) {
  9032. onChangeTextarea();
  9033. return value;
  9034. }
  9035. if (ngModelCtrl) {
  9036. ngModelCtrl.$formatters.push(pipelineListener);
  9037. ngModelCtrl.$viewChangeListeners.push(pipelineListener);
  9038. } else {
  9039. onChangeTextarea();
  9040. }
  9041. element.on('keydown input', onChangeTextarea);
  9042. if(isNaN(min_rows)) {
  9043. element.attr('rows', '1');
  9044. element.on('scroll', onScroll);
  9045. }
  9046. angular.element($window).on('resize', onChangeTextarea);
  9047. scope.$on('$destroy', function() {
  9048. angular.element($window).off('resize', onChangeTextarea);
  9049. });
  9050. function growTextarea() {
  9051. // sets the md-input-container height to avoid jumping around
  9052. container.style.height = container.offsetHeight + 'px';
  9053. // temporarily disables element's flex so its height 'runs free'
  9054. element.addClass('md-no-flex');
  9055. if(isNaN(min_rows)) {
  9056. node.style.height = "auto";
  9057. node.scrollTop = 0;
  9058. var height = getHeight();
  9059. if (height) node.style.height = height + 'px';
  9060. } else {
  9061. node.setAttribute("rows", 1);
  9062. if(!lineHeight) {
  9063. node.style.minHeight = '0';
  9064. lineHeight = element.prop('clientHeight');
  9065. node.style.minHeight = null;
  9066. }
  9067. var rows = Math.max(min_rows, Math.round(node.scrollHeight / lineHeight));
  9068. node.setAttribute("rows", rows);
  9069. }
  9070. // reset everything back to normal
  9071. element.removeClass('md-no-flex');
  9072. container.style.height = 'auto';
  9073. }
  9074. function getHeight () {
  9075. var line = node.scrollHeight - node.offsetHeight;
  9076. return node.offsetHeight + (line > 0 ? line : 0);
  9077. }
  9078. function onScroll(e) {
  9079. node.scrollTop = 0;
  9080. // for smooth new line adding
  9081. var line = node.scrollHeight - node.offsetHeight;
  9082. var height = node.offsetHeight + line;
  9083. node.style.height = height + 'px';
  9084. }
  9085. }
  9086. }
  9087. }
  9088. inputTextareaDirective.$inject = ["$mdUtil", "$window", "$mdAria"];
  9089. function mdMaxlengthDirective($animate) {
  9090. return {
  9091. restrict: 'A',
  9092. require: ['ngModel', '^mdInputContainer'],
  9093. link: postLink
  9094. };
  9095. function postLink(scope, element, attr, ctrls) {
  9096. var maxlength;
  9097. var ngModelCtrl = ctrls[0];
  9098. var containerCtrl = ctrls[1];
  9099. var charCountEl = angular.element('<div class="md-char-counter">');
  9100. // Stop model from trimming. This makes it so whitespace
  9101. // over the maxlength still counts as invalid.
  9102. attr.$set('ngTrim', 'false');
  9103. containerCtrl.element.append(charCountEl);
  9104. ngModelCtrl.$formatters.push(renderCharCount);
  9105. ngModelCtrl.$viewChangeListeners.push(renderCharCount);
  9106. element.on('input keydown', function() {
  9107. renderCharCount(); //make sure it's called with no args
  9108. });
  9109. scope.$watch(attr.mdMaxlength, function(value) {
  9110. maxlength = value;
  9111. if (angular.isNumber(value) && value > 0) {
  9112. if (!charCountEl.parent().length) {
  9113. $animate.enter(charCountEl, containerCtrl.element,
  9114. angular.element(containerCtrl.element[0].lastElementChild));
  9115. }
  9116. renderCharCount();
  9117. } else {
  9118. $animate.leave(charCountEl);
  9119. }
  9120. });
  9121. ngModelCtrl.$validators['md-maxlength'] = function(modelValue, viewValue) {
  9122. if (!angular.isNumber(maxlength) || maxlength < 0) {
  9123. return true;
  9124. }
  9125. return ( modelValue || element.val() || viewValue || '' ).length <= maxlength;
  9126. };
  9127. function renderCharCount(value) {
  9128. charCountEl.text( ( element.val() || value || '' ).length + '/' + maxlength );
  9129. return value;
  9130. }
  9131. }
  9132. }
  9133. mdMaxlengthDirective.$inject = ["$animate"];
  9134. function placeholderDirective($log) {
  9135. return {
  9136. restrict: 'A',
  9137. require: '^^?mdInputContainer',
  9138. priority: 200,
  9139. link: postLink
  9140. };
  9141. function postLink(scope, element, attr, inputContainer) {
  9142. if (!inputContainer) return;
  9143. if (angular.isDefined(inputContainer.element.attr('md-no-float'))) return;
  9144. var placeholderText = attr.placeholder;
  9145. element.removeAttr('placeholder');
  9146. if ( inputContainer.element.find('label').length == 0 ) {
  9147. if (inputContainer.input && inputContainer.input[0].nodeName != 'MD-SELECT') {
  9148. var placeholder = '<label ng-click="delegateClick()">' + placeholderText + '</label>';
  9149. inputContainer.element.addClass('md-icon-float');
  9150. inputContainer.element.prepend(placeholder);
  9151. }
  9152. } else if (element[0].nodeName != 'MD-SELECT') {
  9153. $log.warn("The placeholder='" + placeholderText + "' will be ignored since this md-input-container has a child label element.");
  9154. }
  9155. }
  9156. }
  9157. placeholderDirective.$inject = ["$log"];
  9158. })();
  9159. (function(){
  9160. "use strict";
  9161. /**
  9162. * @ngdoc module
  9163. * @name material.components.list
  9164. * @description
  9165. * List module
  9166. */
  9167. angular.module('material.components.list', [
  9168. 'material.core'
  9169. ])
  9170. .controller('MdListController', MdListController)
  9171. .directive('mdList', mdListDirective)
  9172. .directive('mdListItem', mdListItemDirective);
  9173. /**
  9174. * @ngdoc directive
  9175. * @name mdList
  9176. * @module material.components.list
  9177. *
  9178. * @restrict E
  9179. *
  9180. * @description
  9181. * The `<md-list>` directive is a list container for 1..n `<md-list-item>` tags.
  9182. *
  9183. * @usage
  9184. * <hljs lang="html">
  9185. * <md-list>
  9186. * <md-list-item class="md-2-line" ng-repeat="item in todos">
  9187. * <md-checkbox ng-model="item.done"></md-checkbox>
  9188. * <div class="md-list-item-text">
  9189. * <h3>{{item.title}}</h3>
  9190. * <p>{{item.description}}</p>
  9191. * </div>
  9192. * </md-list-item>
  9193. * </md-list>
  9194. * </hljs>
  9195. */
  9196. function mdListDirective($mdTheming) {
  9197. return {
  9198. restrict: 'E',
  9199. compile: function(tEl) {
  9200. tEl[0].setAttribute('role', 'list');
  9201. return $mdTheming;
  9202. }
  9203. };
  9204. }
  9205. mdListDirective.$inject = ["$mdTheming"];
  9206. /**
  9207. * @ngdoc directive
  9208. * @name mdListItem
  9209. * @module material.components.list
  9210. *
  9211. * @restrict E
  9212. *
  9213. * @description
  9214. * The `<md-list-item>` directive is a container intended for row items in a `<md-list>` container.
  9215. *
  9216. * @usage
  9217. * <hljs lang="html">
  9218. * <md-list>
  9219. * <md-list-item>
  9220. * Item content in list
  9221. * </md-list-item>
  9222. * </md-list>
  9223. * </hljs>
  9224. *
  9225. */
  9226. function mdListItemDirective($mdAria, $mdConstant, $timeout) {
  9227. var proxiedTypes = ['md-checkbox', 'md-switch'];
  9228. return {
  9229. restrict: 'E',
  9230. controller: 'MdListController',
  9231. compile: function(tEl, tAttrs) {
  9232. // Check for proxy controls (no ng-click on parent, and a control inside)
  9233. var secondaryItem = tEl[0].querySelector('.md-secondary');
  9234. var hasProxiedElement;
  9235. var proxyElement;
  9236. tEl[0].setAttribute('role', 'listitem');
  9237. if (!tAttrs.ngClick) {
  9238. for (var i = 0, type; type = proxiedTypes[i]; ++i) {
  9239. if (proxyElement = tEl[0].querySelector(type)) {
  9240. hasProxiedElement = true;
  9241. break;
  9242. }
  9243. }
  9244. if (hasProxiedElement) {
  9245. wrapIn('div');
  9246. } else if (!tEl[0].querySelector('md-button')) {
  9247. tEl.addClass('md-no-proxy');
  9248. }
  9249. } else {
  9250. wrapIn('button');
  9251. }
  9252. setupToggleAria();
  9253. function setupToggleAria() {
  9254. var toggleTypes = ['md-switch', 'md-checkbox'];
  9255. var toggle;
  9256. for (var i = 0, toggleType; toggleType = toggleTypes[i]; ++i) {
  9257. if (toggle = tEl.find(toggleType)[0]) {
  9258. if (!toggle.hasAttribute('aria-label')) {
  9259. var p = tEl.find('p')[0];
  9260. if (!p) return;
  9261. toggle.setAttribute('aria-label', 'Toggle ' + p.textContent);
  9262. }
  9263. }
  9264. }
  9265. }
  9266. function wrapIn(type) {
  9267. var container;
  9268. if (type == 'div') {
  9269. container = angular.element('<div class="md-no-style md-list-item-inner">');
  9270. container.append(tEl.contents());
  9271. tEl.addClass('md-proxy-focus');
  9272. } else {
  9273. container = angular.element('<md-button class="md-no-style"><div class="md-list-item-inner"></div></md-button>');
  9274. var copiedAttrs = ['ng-click', 'aria-label', 'ng-disabled'];
  9275. angular.forEach(copiedAttrs, function(attr) {
  9276. if (tEl[0].hasAttribute(attr)) {
  9277. container[0].setAttribute(attr, tEl[0].getAttribute(attr));
  9278. tEl[0].removeAttribute(attr);
  9279. }
  9280. });
  9281. container.children().eq(0).append(tEl.contents());
  9282. }
  9283. tEl[0].setAttribute('tabindex', '-1');
  9284. tEl.append(container);
  9285. if (secondaryItem && secondaryItem.hasAttribute('ng-click')) {
  9286. $mdAria.expect(secondaryItem, 'aria-label');
  9287. var buttonWrapper = angular.element('<md-button class="md-secondary-container md-icon-button">');
  9288. buttonWrapper.attr('ng-click', secondaryItem.getAttribute('ng-click'));
  9289. secondaryItem.removeAttribute('ng-click');
  9290. secondaryItem.setAttribute('tabindex', '-1');
  9291. secondaryItem.classList.remove('md-secondary');
  9292. buttonWrapper.append(secondaryItem);
  9293. secondaryItem = buttonWrapper[0];
  9294. }
  9295. // Check for a secondary item and move it outside
  9296. if ( secondaryItem && (
  9297. secondaryItem.hasAttribute('ng-click') ||
  9298. ( tAttrs.ngClick &&
  9299. isProxiedElement(secondaryItem) )
  9300. )) {
  9301. tEl.addClass('md-with-secondary');
  9302. tEl.append(secondaryItem);
  9303. }
  9304. }
  9305. function isProxiedElement(el) {
  9306. return proxiedTypes.indexOf(el.nodeName.toLowerCase()) != -1;
  9307. }
  9308. return postLink;
  9309. function postLink($scope, $element, $attr, ctrl) {
  9310. var proxies = [],
  9311. firstChild = $element[0].firstElementChild,
  9312. hasClick = firstChild && firstChild.hasAttribute('ng-click');
  9313. computeProxies();
  9314. computeClickable();
  9315. if ($element.hasClass('md-proxy-focus') && proxies.length) {
  9316. angular.forEach(proxies, function(proxy) {
  9317. proxy = angular.element(proxy);
  9318. $scope.mouseActive = false;
  9319. proxy.on('mousedown', function() {
  9320. $scope.mouseActive = true;
  9321. $timeout(function(){
  9322. $scope.mouseActive = false;
  9323. }, 100);
  9324. })
  9325. .on('focus', function() {
  9326. if ($scope.mouseActive === false) { $element.addClass('md-focused'); }
  9327. proxy.on('blur', function proxyOnBlur() {
  9328. $element.removeClass('md-focused');
  9329. proxy.off('blur', proxyOnBlur);
  9330. });
  9331. });
  9332. });
  9333. }
  9334. function computeProxies() {
  9335. var children = $element.children();
  9336. if (children.length && !children[0].hasAttribute('ng-click')) {
  9337. angular.forEach(proxiedTypes, function(type) {
  9338. angular.forEach(firstChild.querySelectorAll(type), function(child) {
  9339. proxies.push(child);
  9340. });
  9341. });
  9342. }
  9343. }
  9344. function computeClickable() {
  9345. if (proxies.length || hasClick) {
  9346. $element.addClass('md-clickable');
  9347. ctrl.attachRipple($scope, angular.element($element[0].querySelector('.md-no-style')));
  9348. }
  9349. }
  9350. if (!hasClick && !proxies.length) {
  9351. firstChild && firstChild.addEventListener('keypress', function(e) {
  9352. if (e.target.nodeName != 'INPUT' && e.target.nodeName != 'TEXTAREA') {
  9353. var keyCode = e.which || e.keyCode;
  9354. if (keyCode == $mdConstant.KEY_CODE.SPACE) {
  9355. if (firstChild) {
  9356. firstChild.click();
  9357. e.preventDefault();
  9358. e.stopPropagation();
  9359. }
  9360. }
  9361. }
  9362. });
  9363. }
  9364. $element.off('click');
  9365. $element.off('keypress');
  9366. if (proxies.length && firstChild) {
  9367. $element.children().eq(0).on('click', function(e) {
  9368. if (firstChild.contains(e.target)) {
  9369. angular.forEach(proxies, function(proxy) {
  9370. if (e.target !== proxy && !proxy.contains(e.target)) {
  9371. angular.element(proxy).triggerHandler('click');
  9372. }
  9373. });
  9374. }
  9375. });
  9376. }
  9377. }
  9378. }
  9379. };
  9380. }
  9381. mdListItemDirective.$inject = ["$mdAria", "$mdConstant", "$timeout"];
  9382. /*
  9383. * @private
  9384. * @ngdoc controller
  9385. * @name MdListController
  9386. * @module material.components.list
  9387. *
  9388. */
  9389. function MdListController($scope, $element, $mdListInkRipple) {
  9390. var ctrl = this;
  9391. ctrl.attachRipple = attachRipple;
  9392. function attachRipple (scope, element) {
  9393. var options = {};
  9394. $mdListInkRipple.attach(scope, element, options);
  9395. }
  9396. }
  9397. MdListController.$inject = ["$scope", "$element", "$mdListInkRipple"];
  9398. })();
  9399. (function(){
  9400. "use strict";
  9401. /**
  9402. * @ngdoc module
  9403. * @name material.components.menu
  9404. */
  9405. angular.module('material.components.menu', [
  9406. 'material.core',
  9407. 'material.components.backdrop'
  9408. ]);
  9409. })();
  9410. (function(){
  9411. "use strict";
  9412. /**
  9413. * @ngdoc module
  9414. * @name material.components.menu-bar
  9415. */
  9416. angular.module('material.components.menuBar', [
  9417. 'material.core',
  9418. 'material.components.menu'
  9419. ]);
  9420. })();
  9421. (function(){
  9422. "use strict";
  9423. /**
  9424. * @ngdoc module
  9425. * @name material.components.progressCircular
  9426. * @description Circular Progress module!
  9427. */
  9428. angular.module('material.components.progressCircular', [
  9429. 'material.core'
  9430. ])
  9431. .directive('mdProgressCircular', MdProgressCircularDirective);
  9432. /**
  9433. * @ngdoc directive
  9434. * @name mdProgressCircular
  9435. * @module material.components.progressCircular
  9436. * @restrict E
  9437. *
  9438. * @description
  9439. * The circular progress directive is used to make loading content in your app as delightful and
  9440. * painless as possible by minimizing the amount of visual change a user sees before they can view
  9441. * and interact with content.
  9442. *
  9443. * For operations where the percentage of the operation completed can be determined, use a
  9444. * determinate indicator. They give users a quick sense of how long an operation will take.
  9445. *
  9446. * For operations where the user is asked to wait a moment while something finishes up, and it’s
  9447. * not necessary to expose what's happening behind the scenes and how long it will take, use an
  9448. * indeterminate indicator.
  9449. *
  9450. * @param {string} md-mode Select from one of two modes: determinate and indeterminate.
  9451. * @param {number=} value In determinate mode, this number represents the percentage of the
  9452. * circular progress. Default: 0
  9453. * @param {number=} md-diameter This specifies the diamter of the circular progress. The value
  9454. * may be a percentage (eg '25%') or a pixel-size value (eg '48'). If this attribute is
  9455. * not present then a default value of '48px' is assumed.
  9456. *
  9457. * @usage
  9458. * <hljs lang="html">
  9459. * <md-progress-circular md-mode="determinate" value="..."></md-progress-circular>
  9460. *
  9461. * <md-progress-circular md-mode="determinate" ng-value="..."></md-progress-circular>
  9462. *
  9463. * <md-progress-circular md-mode="determinate" value="..." md-diameter="100"></md-progress-circular>
  9464. *
  9465. * <md-progress-circular md-mode="indeterminate"></md-progress-circular>
  9466. * </hljs>
  9467. */
  9468. function MdProgressCircularDirective($mdConstant, $mdTheming) {
  9469. var DEFAULT_PROGRESS_SIZE = 100;
  9470. var DEFAULT_SCALING = 0.5;
  9471. return {
  9472. restrict: 'E',
  9473. template:
  9474. // The progress 'circle' is composed of two half-circles: the left side and the right
  9475. // side. Each side has CSS applied to 'fill-in' the half-circle to the appropriate progress.
  9476. '<div class="md-spinner-wrapper">' +
  9477. '<div class="md-inner">' +
  9478. '<div class="md-gap"></div>' +
  9479. '<div class="md-left">' +
  9480. '<div class="md-half-circle"></div>' +
  9481. '</div>' +
  9482. '<div class="md-right">' +
  9483. '<div class="md-half-circle"></div>' +
  9484. '</div>' +
  9485. '</div>' +
  9486. '</div>',
  9487. compile: compile
  9488. };
  9489. function compile(tElement) {
  9490. // The javascript in this file is mainly responsible for setting the correct aria attributes.
  9491. // The animation of the progress spinner is done entirely with just CSS.
  9492. tElement.attr('aria-valuemin', 0);
  9493. tElement.attr('aria-valuemax', 100);
  9494. tElement.attr('role', 'progressbar');
  9495. return postLink;
  9496. }
  9497. function postLink(scope, element, attr) {
  9498. $mdTheming(element);
  9499. var circle = element[0];
  9500. circle.style[$mdConstant.CSS.TRANSFORM] = 'scale(' + getDiameterRatio() + ')';
  9501. attr.$observe('value', function(value) {
  9502. var percentValue = clamp(value);
  9503. element.attr('aria-valuenow', percentValue);
  9504. });
  9505. /**
  9506. * We will scale the progress circle based on the default diameter.
  9507. *
  9508. * Determine the diameter percentage (defaults to 100%)
  9509. * May be express as float, percentage, or integer
  9510. */
  9511. function getDiameterRatio() {
  9512. if ( !attr.mdDiameter ) return DEFAULT_SCALING;
  9513. var match = /([0-9]*)%/.exec(attr.mdDiameter);
  9514. var value = match && match[1]/100;
  9515. value = Math.max(0, value || parseFloat(attr.mdDiameter));
  9516. // should return ratio; DEFAULT_PROGRESS_SIZE === 100px is default size
  9517. return (value > 1) ? value / DEFAULT_PROGRESS_SIZE : value;
  9518. }
  9519. }
  9520. /**
  9521. * Clamps the value to be between 0 and 100.
  9522. * @param {number} value The value to clamp.
  9523. * @returns {number}
  9524. */
  9525. function clamp(value) {
  9526. return Math.max(0, Math.min(value || 0, 100));
  9527. }
  9528. }
  9529. MdProgressCircularDirective.$inject = ["$mdConstant", "$mdTheming"];
  9530. })();
  9531. (function(){
  9532. "use strict";
  9533. /**
  9534. * @ngdoc module
  9535. * @name material.components.progressLinear
  9536. * @description Linear Progress module!
  9537. */
  9538. angular.module('material.components.progressLinear', [
  9539. 'material.core'
  9540. ])
  9541. .directive('mdProgressLinear', MdProgressLinearDirective);
  9542. /**
  9543. * @ngdoc directive
  9544. * @name mdProgressLinear
  9545. * @module material.components.progressLinear
  9546. * @restrict E
  9547. *
  9548. * @description
  9549. * The linear progress directive is used to make loading content in your app as delightful and painless as possible by minimizing the amount of visual change a user sees before they can view and interact with content. Each operation should only be represented by one activity indicator—for example, one refresh operation should not display both a refresh bar and an activity circle.
  9550. *
  9551. * For operations where the percentage of the operation completed can be determined, use a determinate indicator. They give users a quick sense of how long an operation will take.
  9552. *
  9553. * For operations where the user is asked to wait a moment while something finishes up, and it’s not necessary to expose what's happening behind the scenes and how long it will take, use an indeterminate indicator.
  9554. *
  9555. * @param {string} md-mode Select from one of four modes: determinate, indeterminate, buffer or query.
  9556. * @param {number=} value In determinate and buffer modes, this number represents the percentage of the primary progress bar. Default: 0
  9557. * @param {number=} md-buffer-value In the buffer mode, this number represents the precentage of the secondary progress bar. Default: 0
  9558. *
  9559. * @usage
  9560. * <hljs lang="html">
  9561. * <md-progress-linear md-mode="determinate" value="..."></md-progress-linear>
  9562. *
  9563. * <md-progress-linear md-mode="determinate" ng-value="..."></md-progress-linear>
  9564. *
  9565. * <md-progress-linear md-mode="indeterminate"></md-progress-linear>
  9566. *
  9567. * <md-progress-linear md-mode="buffer" value="..." md-buffer-value="..."></md-progress-linear>
  9568. *
  9569. * <md-progress-linear md-mode="query"></md-progress-linear>
  9570. * </hljs>
  9571. */
  9572. function MdProgressLinearDirective($$rAF, $mdConstant, $mdTheming) {
  9573. return {
  9574. restrict: 'E',
  9575. template: '<div class="md-container">' +
  9576. '<div class="md-dashed"></div>' +
  9577. '<div class="md-bar md-bar1"></div>' +
  9578. '<div class="md-bar md-bar2"></div>' +
  9579. '</div>',
  9580. compile: compile
  9581. };
  9582. function compile(tElement, tAttrs, transclude) {
  9583. tElement.attr('aria-valuemin', 0);
  9584. tElement.attr('aria-valuemax', 100);
  9585. tElement.attr('role', 'progressbar');
  9586. return postLink;
  9587. }
  9588. function postLink(scope, element, attr) {
  9589. $mdTheming(element);
  9590. var bar1Style = element[0].querySelector('.md-bar1').style,
  9591. bar2Style = element[0].querySelector('.md-bar2').style,
  9592. container = angular.element(element[0].querySelector('.md-container'));
  9593. attr.$observe('value', function(value) {
  9594. if (attr.mdMode == 'query') {
  9595. return;
  9596. }
  9597. var clamped = clamp(value);
  9598. element.attr('aria-valuenow', clamped);
  9599. bar2Style[$mdConstant.CSS.TRANSFORM] = transforms[clamped];
  9600. });
  9601. attr.$observe('mdBufferValue', function(value) {
  9602. bar1Style[$mdConstant.CSS.TRANSFORM] = transforms[clamp(value)];
  9603. });
  9604. $$rAF(function() {
  9605. container.addClass('md-ready');
  9606. });
  9607. }
  9608. function clamp(value) {
  9609. if (value > 100) {
  9610. return 100;
  9611. }
  9612. if (value < 0) {
  9613. return 0;
  9614. }
  9615. return Math.ceil(value || 0);
  9616. }
  9617. }
  9618. MdProgressLinearDirective.$inject = ["$$rAF", "$mdConstant", "$mdTheming"];
  9619. // **********************************************************
  9620. // Private Methods
  9621. // **********************************************************
  9622. var transforms = (function() {
  9623. var values = new Array(101);
  9624. for(var i = 0; i < 101; i++){
  9625. values[i] = makeTransform(i);
  9626. }
  9627. return values;
  9628. function makeTransform(value){
  9629. var scale = value/100;
  9630. var translateX = (value-100)/2;
  9631. return 'translateX(' + translateX.toString() + '%) scale(' + scale.toString() + ', 1)';
  9632. }
  9633. })();
  9634. })();
  9635. (function(){
  9636. "use strict";
  9637. /**
  9638. * @ngdoc module
  9639. * @name material.components.radioButton
  9640. * @description radioButton module!
  9641. */
  9642. angular.module('material.components.radioButton', [
  9643. 'material.core'
  9644. ])
  9645. .directive('mdRadioGroup', mdRadioGroupDirective)
  9646. .directive('mdRadioButton', mdRadioButtonDirective);
  9647. /**
  9648. * @ngdoc directive
  9649. * @module material.components.radioButton
  9650. * @name mdRadioGroup
  9651. *
  9652. * @restrict E
  9653. *
  9654. * @description
  9655. * The `<md-radio-group>` directive identifies a grouping
  9656. * container for the 1..n grouped radio buttons; specified using nested
  9657. * `<md-radio-button>` tags.
  9658. *
  9659. * As per the [material design spec](http://www.google.com/design/spec/style/color.html#color-ui-color-application)
  9660. * the radio button is in the accent color by default. The primary color palette may be used with
  9661. * the `md-primary` class.
  9662. *
  9663. * Note: `<md-radio-group>` and `<md-radio-button>` handle tabindex differently
  9664. * than the native `<input type='radio'>` controls. Whereas the native controls
  9665. * force the user to tab through all the radio buttons, `<md-radio-group>`
  9666. * is focusable, and by default the `<md-radio-button>`s are not.
  9667. *
  9668. * @param {string} ng-model Assignable angular expression to data-bind to.
  9669. * @param {boolean=} md-no-ink Use of attribute indicates flag to disable ink ripple effects.
  9670. *
  9671. * @usage
  9672. * <hljs lang="html">
  9673. * <md-radio-group ng-model="selected">
  9674. *
  9675. * <md-radio-button
  9676. * ng-repeat="d in colorOptions"
  9677. * ng-value="d.value" aria-label="{{ d.label }}">
  9678. *
  9679. * {{ d.label }}
  9680. *
  9681. * </md-radio-button>
  9682. *
  9683. * </md-radio-group>
  9684. * </hljs>
  9685. *
  9686. */
  9687. function mdRadioGroupDirective($mdUtil, $mdConstant, $mdTheming, $timeout) {
  9688. RadioGroupController.prototype = createRadioGroupControllerProto();
  9689. return {
  9690. restrict: 'E',
  9691. controller: ['$element', RadioGroupController],
  9692. require: ['mdRadioGroup', '?ngModel'],
  9693. link: { pre: linkRadioGroup }
  9694. };
  9695. function linkRadioGroup(scope, element, attr, ctrls) {
  9696. $mdTheming(element);
  9697. var rgCtrl = ctrls[0];
  9698. var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel();
  9699. function setFocus() {
  9700. if (!element.hasClass('md-focused')) { element.addClass('md-focused'); }
  9701. }
  9702. function keydownListener(ev) {
  9703. var keyCode = ev.which || ev.keyCode;
  9704. switch(keyCode) {
  9705. case $mdConstant.KEY_CODE.LEFT_ARROW:
  9706. case $mdConstant.KEY_CODE.UP_ARROW:
  9707. ev.preventDefault();
  9708. rgCtrl.selectPrevious();
  9709. setFocus();
  9710. break;
  9711. case $mdConstant.KEY_CODE.RIGHT_ARROW:
  9712. case $mdConstant.KEY_CODE.DOWN_ARROW:
  9713. ev.preventDefault();
  9714. rgCtrl.selectNext();
  9715. setFocus();
  9716. break;
  9717. case $mdConstant.KEY_CODE.ENTER:
  9718. var form = angular.element($mdUtil.getClosest(element[0], 'form'));
  9719. if (form.length > 0) {
  9720. form.triggerHandler('submit');
  9721. }
  9722. break;
  9723. }
  9724. }
  9725. rgCtrl.init(ngModelCtrl);
  9726. scope.mouseActive = false;
  9727. element.attr({
  9728. 'role': 'radiogroup',
  9729. 'tabIndex': element.attr('tabindex') || '0'
  9730. })
  9731. .on('keydown', keydownListener)
  9732. .on('mousedown', function(event) {
  9733. scope.mouseActive = true;
  9734. $timeout(function() {
  9735. scope.mouseActive = false;
  9736. }, 100);
  9737. })
  9738. .on('focus', function() {
  9739. if(scope.mouseActive === false) { rgCtrl.$element.addClass('md-focused'); }
  9740. })
  9741. .on('blur', function() { rgCtrl.$element.removeClass('md-focused'); });
  9742. }
  9743. function RadioGroupController($element) {
  9744. this._radioButtonRenderFns = [];
  9745. this.$element = $element;
  9746. }
  9747. function createRadioGroupControllerProto() {
  9748. return {
  9749. init: function(ngModelCtrl) {
  9750. this._ngModelCtrl = ngModelCtrl;
  9751. this._ngModelCtrl.$render = angular.bind(this, this.render);
  9752. },
  9753. add: function(rbRender) {
  9754. this._radioButtonRenderFns.push(rbRender);
  9755. },
  9756. remove: function(rbRender) {
  9757. var index = this._radioButtonRenderFns.indexOf(rbRender);
  9758. if (index !== -1) {
  9759. this._radioButtonRenderFns.splice(index, 1);
  9760. }
  9761. },
  9762. render: function() {
  9763. this._radioButtonRenderFns.forEach(function(rbRender) {
  9764. rbRender();
  9765. });
  9766. },
  9767. setViewValue: function(value, eventType) {
  9768. this._ngModelCtrl.$setViewValue(value, eventType);
  9769. // update the other radio buttons as well
  9770. this.render();
  9771. },
  9772. getViewValue: function() {
  9773. return this._ngModelCtrl.$viewValue;
  9774. },
  9775. selectNext: function() {
  9776. return changeSelectedButton(this.$element, 1);
  9777. },
  9778. selectPrevious: function() {
  9779. return changeSelectedButton(this.$element, -1);
  9780. },
  9781. setActiveDescendant: function (radioId) {
  9782. this.$element.attr('aria-activedescendant', radioId);
  9783. }
  9784. };
  9785. }
  9786. /**
  9787. * Change the radio group's selected button by a given increment.
  9788. * If no button is selected, select the first button.
  9789. */
  9790. function changeSelectedButton(parent, increment) {
  9791. // Coerce all child radio buttons into an array, then wrap then in an iterator
  9792. var buttons = $mdUtil.iterator(parent[0].querySelectorAll('md-radio-button'), true);
  9793. if (buttons.count()) {
  9794. var validate = function (button) {
  9795. // If disabled, then NOT valid
  9796. return !angular.element(button).attr("disabled");
  9797. };
  9798. var selected = parent[0].querySelector('md-radio-button.md-checked');
  9799. var target = buttons[increment < 0 ? 'previous' : 'next'](selected, validate) || buttons.first();
  9800. // Activate radioButton's click listener (triggerHandler won't create a real click event)
  9801. angular.element(target).triggerHandler('click');
  9802. }
  9803. }
  9804. }
  9805. mdRadioGroupDirective.$inject = ["$mdUtil", "$mdConstant", "$mdTheming", "$timeout"];
  9806. /**
  9807. * @ngdoc directive
  9808. * @module material.components.radioButton
  9809. * @name mdRadioButton
  9810. *
  9811. * @restrict E
  9812. *
  9813. * @description
  9814. * The `<md-radio-button>`directive is the child directive required to be used within `<md-radio-group>` elements.
  9815. *
  9816. * While similar to the `<input type="radio" ng-model="" value="">` directive,
  9817. * the `<md-radio-button>` directive provides ink effects, ARIA support, and
  9818. * supports use within named radio groups.
  9819. *
  9820. * @param {string} ngModel Assignable angular expression to data-bind to.
  9821. * @param {string=} ngChange Angular expression to be executed when input changes due to user
  9822. * interaction with the input element.
  9823. * @param {string} ngValue Angular expression which sets the value to which the expression should
  9824. * be set when selected.*
  9825. * @param {string} value The value to which the expression should be set when selected.
  9826. * @param {string=} name Property name of the form under which the control is published.
  9827. * @param {string=} aria-label Adds label to radio button for accessibility.
  9828. * Defaults to radio button's text. If no text content is available, a warning will be logged.
  9829. *
  9830. * @usage
  9831. * <hljs lang="html">
  9832. *
  9833. * <md-radio-button value="1" aria-label="Label 1">
  9834. * Label 1
  9835. * </md-radio-button>
  9836. *
  9837. * <md-radio-button ng-model="color" ng-value="specialValue" aria-label="Green">
  9838. * Green
  9839. * </md-radio-button>
  9840. *
  9841. * </hljs>
  9842. *
  9843. */
  9844. function mdRadioButtonDirective($mdAria, $mdUtil, $mdTheming) {
  9845. var CHECKED_CSS = 'md-checked';
  9846. return {
  9847. restrict: 'E',
  9848. require: '^mdRadioGroup',
  9849. transclude: true,
  9850. template: '<div class="md-container" md-ink-ripple md-ink-ripple-checkbox>' +
  9851. '<div class="md-off"></div>' +
  9852. '<div class="md-on"></div>' +
  9853. '</div>' +
  9854. '<div ng-transclude class="md-label"></div>',
  9855. link: link
  9856. };
  9857. function link(scope, element, attr, rgCtrl) {
  9858. var lastChecked;
  9859. $mdTheming(element);
  9860. configureAria(element, scope);
  9861. rgCtrl.add(render);
  9862. attr.$observe('value', render);
  9863. element
  9864. .on('click', listener)
  9865. .on('$destroy', function() {
  9866. rgCtrl.remove(render);
  9867. });
  9868. function listener(ev) {
  9869. if (element[0].hasAttribute('disabled')) return;
  9870. scope.$apply(function() {
  9871. rgCtrl.setViewValue(attr.value, ev && ev.type);
  9872. });
  9873. }
  9874. function render() {
  9875. var checked = (rgCtrl.getViewValue() == attr.value);
  9876. if (checked === lastChecked) {
  9877. return;
  9878. }
  9879. lastChecked = checked;
  9880. element.attr('aria-checked', checked);
  9881. if (checked) {
  9882. element.addClass(CHECKED_CSS);
  9883. rgCtrl.setActiveDescendant(element.attr('id'));
  9884. } else {
  9885. element.removeClass(CHECKED_CSS);
  9886. }
  9887. }
  9888. /**
  9889. * Inject ARIA-specific attributes appropriate for each radio button
  9890. */
  9891. function configureAria( element, scope ){
  9892. scope.ariaId = buildAriaID();
  9893. element.attr({
  9894. 'id' : scope.ariaId,
  9895. 'role' : 'radio',
  9896. 'aria-checked' : 'false'
  9897. });
  9898. $mdAria.expectWithText(element, 'aria-label');
  9899. /**
  9900. * Build a unique ID for each radio button that will be used with aria-activedescendant.
  9901. * Preserve existing ID if already specified.
  9902. * @returns {*|string}
  9903. */
  9904. function buildAriaID() {
  9905. return attr.id || ( 'radio' + "_" + $mdUtil.nextUid() );
  9906. }
  9907. }
  9908. }
  9909. }
  9910. mdRadioButtonDirective.$inject = ["$mdAria", "$mdUtil", "$mdTheming"];
  9911. })();
  9912. (function(){
  9913. "use strict";
  9914. /**
  9915. * @ngdoc module
  9916. * @name material.components.select
  9917. */
  9918. /***************************************************
  9919. ### TODO ###
  9920. **DOCUMENTATION AND DEMOS**
  9921. - [ ] ng-model with child mdOptions (basic)
  9922. - [ ] ng-model="foo" ng-model-options="{ trackBy: '$value.id' }" for objects
  9923. - [ ] mdOption with value
  9924. - [ ] Usage with input inside
  9925. ### TODO - POST RC1 ###
  9926. - [ ] Abstract placement logic in $mdSelect service to $mdMenu service
  9927. ***************************************************/
  9928. var SELECT_EDGE_MARGIN = 8;
  9929. var selectNextId = 0;
  9930. angular.module('material.components.select', [
  9931. 'material.core',
  9932. 'material.components.backdrop'
  9933. ])
  9934. .directive('mdSelect', SelectDirective)
  9935. .directive('mdSelectMenu', SelectMenuDirective)
  9936. .directive('mdOption', OptionDirective)
  9937. .directive('mdOptgroup', OptgroupDirective)
  9938. .provider('$mdSelect', SelectProvider);
  9939. /**
  9940. * @ngdoc directive
  9941. * @name mdSelect
  9942. * @restrict E
  9943. * @module material.components.select
  9944. *
  9945. * @description Displays a select box, bound to an ng-model.
  9946. *
  9947. * @param {expression} ng-model The model!
  9948. * @param {boolean=} multiple Whether it's multiple.
  9949. * @param {expression=} md-on-close expression to be evaluated when the select is closed
  9950. * @param {string=} placeholder Placeholder hint text.
  9951. * @param {string=} aria-label Optional label for accessibility. Only necessary if no placeholder or
  9952. * @param {string=} md-container-class class list to get applied to the .md-select-menu-container element (for custom styling)
  9953. * explicit label is present.
  9954. *
  9955. * @usage
  9956. * With a placeholder (label and aria-label are added dynamically)
  9957. * <hljs lang="html">
  9958. * <md-input-container>
  9959. * <md-select
  9960. * ng-model="someModel"
  9961. * placeholder="Select a state">
  9962. * <md-option ng-value="opt" ng-repeat="opt in neighborhoods2">{{ opt }}</md-option>
  9963. * </md-select>
  9964. * </md-input-container>
  9965. * </hljs>
  9966. *
  9967. * With an explicit label
  9968. * <hljs lang="html">
  9969. * <md-input-container>
  9970. * <label>State</label>
  9971. * <md-select
  9972. * ng-model="someModel">
  9973. * <md-option ng-value="opt" ng-repeat="opt in neighborhoods2">{{ opt }}</md-option>
  9974. * </md-select>
  9975. * </md-input-container>
  9976. * </hljs>
  9977. */
  9978. function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $rootElement, $compile, $parse) {
  9979. return {
  9980. restrict: 'E',
  9981. require: ['^?mdInputContainer', 'mdSelect', 'ngModel', '?^form'],
  9982. compile: compile,
  9983. controller: function() {
  9984. } // empty placeholder controller to be initialized in link
  9985. };
  9986. function compile(element, attr) {
  9987. // add the select value that will hold our placeholder or selected option value
  9988. var valueEl = angular.element('<md-select-value><span></span></md-select-value>');
  9989. valueEl.append('<span class="md-select-icon" aria-hidden="true"></span>');
  9990. valueEl.addClass('md-select-value');
  9991. if (!valueEl[0].hasAttribute('id')) {
  9992. valueEl.attr('id', 'select_value_label_' + $mdUtil.nextUid());
  9993. }
  9994. // There's got to be an md-content inside. If there's not one, let's add it.
  9995. if (!element.find('md-content').length) {
  9996. element.append(angular.element('<md-content>').append(element.contents()));
  9997. }
  9998. // Add progress spinner for md-options-loading
  9999. if (attr.mdOnOpen) {
  10000. // Show progress indicator while loading async
  10001. element
  10002. .find('md-content')
  10003. .prepend(angular.element(
  10004. '<div>' +
  10005. ' <md-progress-circular md-mode="indeterminate" ng-hide="$$loadingAsyncDone">' +
  10006. ' </md-progress-circular>' +
  10007. '</div>'
  10008. ));
  10009. // Hide list [of item options] while loading async
  10010. element
  10011. .find('md-option')
  10012. .attr('ng-show', '$$loadingAsyncDone');
  10013. }
  10014. if (attr.name) {
  10015. var autofillClone = angular.element('<select class="md-visually-hidden">');
  10016. autofillClone.attr({
  10017. 'name': '.' + attr.name,
  10018. 'ng-model': attr.ngModel,
  10019. 'aria-hidden': 'true',
  10020. 'tabindex': '-1'
  10021. });
  10022. var opts = element.find('md-option');
  10023. angular.forEach(opts, function(el) {
  10024. var newEl = angular.element('<option>' + el.innerHTML + '</option>');
  10025. if (el.hasAttribute('ng-value')) newEl.attr('ng-value', el.getAttribute('ng-value'));
  10026. else if (el.hasAttribute('value')) newEl.attr('value', el.getAttribute('value'));
  10027. autofillClone.append(newEl);
  10028. });
  10029. element.parent().append(autofillClone);
  10030. }
  10031. // Use everything that's left inside element.contents() as the contents of the menu
  10032. var multiple = angular.isDefined(attr.multiple) ? 'multiple' : '';
  10033. var selectTemplate = '' +
  10034. '<div class="md-select-menu-container">' +
  10035. '<md-select-menu {0}>{1}</md-select-menu>' +
  10036. '</div>';
  10037. selectTemplate = $mdUtil.supplant(selectTemplate, [multiple, element.html()]);
  10038. element.empty().append(valueEl);
  10039. attr.tabindex = attr.tabindex || '0';
  10040. return function postLink(scope, element, attr, ctrls) {
  10041. var isOpen;
  10042. var isDisabled;
  10043. var containerCtrl = ctrls[0];
  10044. var mdSelectCtrl = ctrls[1];
  10045. var ngModelCtrl = ctrls[2];
  10046. var formCtrl = ctrls[3];
  10047. // grab a reference to the select menu value label
  10048. var valueEl = element.find('md-select-value');
  10049. var isReadonly = angular.isDefined(attr.readonly);
  10050. if (containerCtrl) {
  10051. var isErrorGetter = containerCtrl.isErrorGetter || function() {
  10052. return ngModelCtrl.$invalid && ngModelCtrl.$touched;
  10053. };
  10054. if (containerCtrl.input) {
  10055. throw new Error("<md-input-container> can only have *one* child <input>, <textarea> or <select> element!");
  10056. }
  10057. containerCtrl.input = element;
  10058. if (!containerCtrl.label) {
  10059. $mdAria.expect(element, 'aria-label', element.attr('placeholder'));
  10060. }
  10061. scope.$watch(isErrorGetter, containerCtrl.setInvalid);
  10062. }
  10063. var selectContainer, selectScope, selectMenuCtrl;
  10064. createSelect();
  10065. $mdTheming(element);
  10066. if (attr.name && formCtrl) {
  10067. var selectEl = element.parent()[0].querySelector('select[name=".' + attr.name + '"]');
  10068. var controller = angular.element(selectEl).controller();
  10069. if (controller) {
  10070. formCtrl.$removeControl(controller);
  10071. }
  10072. }
  10073. var originalRender = ngModelCtrl.$render;
  10074. ngModelCtrl.$render = function() {
  10075. originalRender();
  10076. syncLabelText();
  10077. inputCheckValue();
  10078. };
  10079. mdSelectCtrl.setLabelText = function(text) {
  10080. mdSelectCtrl.setIsPlaceholder(!text);
  10081. // Use placeholder attribute, otherwise fallback to the md-input-container label
  10082. var tmpPlaceholder = attr.placeholder || (containerCtrl && containerCtrl.label ? containerCtrl.label.html() : '');
  10083. text = text || tmpPlaceholder || '';
  10084. var target = valueEl.children().eq(0);
  10085. target.html(text);
  10086. };
  10087. mdSelectCtrl.setIsPlaceholder = function(isPlaceholder) {
  10088. if (isPlaceholder) {
  10089. valueEl.addClass('md-select-placeholder');
  10090. if (containerCtrl && containerCtrl.label) {
  10091. containerCtrl.label.addClass('md-placeholder md-static');
  10092. }
  10093. } else {
  10094. valueEl.removeClass('md-select-placeholder');
  10095. if (containerCtrl && containerCtrl.label) {
  10096. containerCtrl.label.removeClass('md-placeholder');
  10097. }
  10098. }
  10099. };
  10100. if (!isReadonly) {
  10101. element
  10102. .on('focus', function(ev) {
  10103. // only set focus on if we don't currently have a selected value. This avoids the "bounce"
  10104. // on the label transition because the focus will immediately switch to the open menu.
  10105. if (containerCtrl && containerCtrl.element.hasClass('md-input-has-value')) {
  10106. containerCtrl.setFocused(true);
  10107. }
  10108. })
  10109. .on('blur', function(ev) {
  10110. containerCtrl && containerCtrl.setFocused(false);
  10111. inputCheckValue();
  10112. });
  10113. }
  10114. mdSelectCtrl.triggerClose = function() {
  10115. $parse(attr.mdOnClose)(scope);
  10116. };
  10117. scope.$$postDigest(function() {
  10118. setAriaLabel();
  10119. syncLabelText();
  10120. });
  10121. function setAriaLabel() {
  10122. var labelText = element.attr('placeholder');
  10123. if (!labelText && containerCtrl && containerCtrl.label) {
  10124. labelText = containerCtrl.label.html();
  10125. }
  10126. $mdAria.expect(element, 'aria-label', labelText);
  10127. }
  10128. function syncLabelText() {
  10129. if (selectContainer) {
  10130. selectMenuCtrl = selectMenuCtrl || selectContainer.find('md-select-menu').controller('mdSelectMenu');
  10131. mdSelectCtrl.setLabelText(selectMenuCtrl.selectedLabels());
  10132. }
  10133. }
  10134. var deregisterWatcher;
  10135. attr.$observe('ngMultiple', function(val) {
  10136. if (deregisterWatcher) deregisterWatcher();
  10137. var parser = $parse(val);
  10138. deregisterWatcher = scope.$watch(function() {
  10139. return parser(scope);
  10140. }, function(multiple, prevVal) {
  10141. if (multiple === undefined && prevVal === undefined) return; // assume compiler did a good job
  10142. if (multiple) {
  10143. element.attr('multiple', 'multiple');
  10144. } else {
  10145. element.removeAttr('multiple');
  10146. }
  10147. if (selectContainer) {
  10148. selectMenuCtrl.setMultiple(multiple);
  10149. originalRender = ngModelCtrl.$render;
  10150. ngModelCtrl.$render = function() {
  10151. originalRender();
  10152. syncLabelText();
  10153. };
  10154. selectMenuCtrl.refreshViewValue();
  10155. ngModelCtrl.$render();
  10156. }
  10157. });
  10158. });
  10159. attr.$observe('disabled', function(disabled) {
  10160. if (typeof disabled == "string") {
  10161. disabled = true;
  10162. }
  10163. // Prevent click event being registered twice
  10164. if (isDisabled !== undefined && isDisabled === disabled) {
  10165. return;
  10166. }
  10167. isDisabled = disabled;
  10168. if (disabled) {
  10169. element.attr({'tabindex': -1, 'aria-disabled': 'true'});
  10170. element.off('click', openSelect);
  10171. element.off('keydown', handleKeypress);
  10172. } else {
  10173. element.attr({'tabindex': attr.tabindex, 'aria-disabled': 'false'});
  10174. element.on('click', openSelect);
  10175. element.on('keydown', handleKeypress);
  10176. }
  10177. });
  10178. if (!attr.disabled && !attr.ngDisabled) {
  10179. element.attr({'tabindex': attr.tabindex, 'aria-disabled': 'false'});
  10180. element.on('click', openSelect);
  10181. element.on('keydown', handleKeypress);
  10182. }
  10183. var ariaAttrs = {
  10184. role: 'combobox',
  10185. 'aria-expanded': 'false'
  10186. };
  10187. if (!element[0].hasAttribute('id')) {
  10188. ariaAttrs.id = 'select_' + $mdUtil.nextUid();
  10189. }
  10190. element.attr(ariaAttrs);
  10191. scope.$on('$destroy', function() {
  10192. if (isOpen) {
  10193. $mdSelect.hide().finally(function() {
  10194. selectContainer.remove();
  10195. });
  10196. } else {
  10197. selectContainer.remove();
  10198. }
  10199. if (containerCtrl) {
  10200. containerCtrl.setFocused(false);
  10201. containerCtrl.setHasValue(false);
  10202. containerCtrl.input = null;
  10203. }
  10204. });
  10205. function inputCheckValue() {
  10206. // The select counts as having a value if one or more options are selected,
  10207. // or if the input's validity state says it has bad input (eg string in a number input)
  10208. containerCtrl && containerCtrl.setHasValue(selectMenuCtrl.selectedLabels().length > 0 || (element[0].validity || {}).badInput);
  10209. }
  10210. // Create a fake select to find out the label value
  10211. function createSelect() {
  10212. selectContainer = angular.element(selectTemplate);
  10213. var selectEl = selectContainer.find('md-select-menu');
  10214. selectEl.data('$ngModelController', ngModelCtrl);
  10215. selectEl.data('$mdSelectController', mdSelectCtrl);
  10216. selectScope = scope.$new();
  10217. $mdTheming.inherit(selectContainer, element);
  10218. selectContainer[0].setAttribute('class', selectContainer[0].getAttribute('class') + ' ' + element.attr('md-container-class'));
  10219. selectContainer = $compile(selectContainer)(selectScope);
  10220. selectMenuCtrl = selectContainer.find('md-select-menu').controller('mdSelectMenu');
  10221. }
  10222. function handleKeypress(e) {
  10223. var allowedCodes = [32, 13, 38, 40];
  10224. if (allowedCodes.indexOf(e.keyCode) != -1) {
  10225. // prevent page scrolling on interaction
  10226. e.preventDefault();
  10227. openSelect(e);
  10228. } else {
  10229. if (e.keyCode <= 90 && e.keyCode >= 31) {
  10230. e.preventDefault();
  10231. var node = selectMenuCtrl.optNodeForKeyboardSearch(e);
  10232. if (!node) return;
  10233. var optionCtrl = angular.element(node).controller('mdOption');
  10234. if (!selectMenuCtrl.isMultiple) {
  10235. selectMenuCtrl.deselect(Object.keys(selectMenuCtrl.selected)[0]);
  10236. }
  10237. selectMenuCtrl.select(optionCtrl.hashKey, optionCtrl.value);
  10238. selectMenuCtrl.refreshViewValue();
  10239. ngModelCtrl.$render();
  10240. }
  10241. }
  10242. }
  10243. function openSelect() {
  10244. scope.$apply('isOpen = true');
  10245. $mdSelect.show({
  10246. scope: selectScope,
  10247. preserveScope: true,
  10248. skipCompile: true,
  10249. element: selectContainer,
  10250. target: element[0],
  10251. hasBackdrop: true,
  10252. loadingAsync: attr.mdOnOpen ? scope.$eval(attr.mdOnOpen) || true : false
  10253. }).then(function() {
  10254. isOpen = false;
  10255. });
  10256. }
  10257. };
  10258. }
  10259. }
  10260. SelectDirective.$inject = ["$mdSelect", "$mdUtil", "$mdTheming", "$mdAria", "$rootElement", "$compile", "$parse"];
  10261. function SelectMenuDirective($parse, $mdUtil, $mdTheming) {
  10262. SelectMenuController.$inject = ["$scope", "$attrs", "$element"];
  10263. return {
  10264. restrict: 'E',
  10265. require: ['mdSelectMenu', '?ngModel'],
  10266. controller: SelectMenuController,
  10267. link: {pre: preLink}
  10268. };
  10269. // We use preLink instead of postLink to ensure that the select is initialized before
  10270. // its child options run postLink.
  10271. function preLink(scope, element, attr, ctrls) {
  10272. var selectCtrl = ctrls[0];
  10273. var ngModel = ctrls[1];
  10274. $mdTheming(element);
  10275. element.on('click', clickListener);
  10276. element.on('keypress', keyListener);
  10277. if (ngModel) selectCtrl.init(ngModel);
  10278. configureAria();
  10279. function configureAria() {
  10280. element.attr({
  10281. 'id': 'select_menu_' + $mdUtil.nextUid(),
  10282. 'role': 'listbox',
  10283. 'aria-multiselectable': (selectCtrl.isMultiple ? 'true' : 'false')
  10284. });
  10285. }
  10286. function keyListener(e) {
  10287. if (e.keyCode == 13 || e.keyCode == 32) {
  10288. clickListener(e);
  10289. }
  10290. }
  10291. function clickListener(ev) {
  10292. var option = $mdUtil.getClosest(ev.target, 'md-option');
  10293. var optionCtrl = option && angular.element(option).data('$mdOptionController');
  10294. if (!option || !optionCtrl) return;
  10295. if (option.hasAttribute('disabled')) {
  10296. ev.stopImmediatePropagation();
  10297. return false;
  10298. }
  10299. var optionHashKey = selectCtrl.hashGetter(optionCtrl.value);
  10300. var isSelected = angular.isDefined(selectCtrl.selected[optionHashKey]);
  10301. scope.$apply(function() {
  10302. if (selectCtrl.isMultiple) {
  10303. if (isSelected) {
  10304. selectCtrl.deselect(optionHashKey);
  10305. } else {
  10306. selectCtrl.select(optionHashKey, optionCtrl.value);
  10307. }
  10308. } else {
  10309. if (!isSelected) {
  10310. selectCtrl.deselect(Object.keys(selectCtrl.selected)[0]);
  10311. selectCtrl.select(optionHashKey, optionCtrl.value);
  10312. }
  10313. }
  10314. selectCtrl.refreshViewValue();
  10315. });
  10316. }
  10317. }
  10318. function SelectMenuController($scope, $attrs, $element) {
  10319. var self = this;
  10320. self.isMultiple = angular.isDefined($attrs.multiple);
  10321. // selected is an object with keys matching all of the selected options' hashed values
  10322. self.selected = {};
  10323. // options is an object with keys matching every option's hash value,
  10324. // and values matching every option's controller.
  10325. self.options = {};
  10326. $scope.$watch(function() {
  10327. return self.options;
  10328. }, function() {
  10329. self.ngModel.$render();
  10330. }, true);
  10331. var deregisterCollectionWatch;
  10332. self.setMultiple = function(isMultiple) {
  10333. var ngModel = self.ngModel;
  10334. self.isMultiple = isMultiple;
  10335. if (deregisterCollectionWatch) deregisterCollectionWatch();
  10336. if (self.isMultiple) {
  10337. ngModel.$validators['md-multiple'] = validateArray;
  10338. ngModel.$render = renderMultiple;
  10339. // watchCollection on the model because by default ngModel only watches the model's
  10340. // reference. This allowed the developer to also push and pop from their array.
  10341. $scope.$watchCollection($attrs.ngModel, function(value) {
  10342. if (validateArray(value)) renderMultiple(value);
  10343. });
  10344. } else {
  10345. delete ngModel.$validators['md-multiple'];
  10346. ngModel.$render = renderSingular;
  10347. }
  10348. function validateArray(modelValue, viewValue) {
  10349. // If a value is truthy but not an array, reject it.
  10350. // If value is undefined/falsy, accept that it's an empty array.
  10351. return angular.isArray(modelValue || viewValue || []);
  10352. }
  10353. };
  10354. var searchStr = '';
  10355. var clearSearchTimeout, optNodes, optText;
  10356. var CLEAR_SEARCH_AFTER = 300;
  10357. self.optNodeForKeyboardSearch = function(e) {
  10358. clearSearchTimeout && clearTimeout(clearSearchTimeout);
  10359. clearSearchTimeout = setTimeout(function() {
  10360. clearSearchTimeout = undefined;
  10361. searchStr = '';
  10362. optText = undefined;
  10363. optNodes = undefined;
  10364. }, CLEAR_SEARCH_AFTER);
  10365. searchStr += String.fromCharCode(e.keyCode);
  10366. var search = new RegExp('^' + searchStr, 'i');
  10367. if (!optNodes) {
  10368. optNodes = $element.find('md-option');
  10369. optText = new Array(optNodes.length);
  10370. angular.forEach(optNodes, function(el, i) {
  10371. optText[i] = el.textContent.trim();
  10372. });
  10373. }
  10374. for (var i = 0; i < optText.length; ++i) {
  10375. if (search.test(optText[i])) {
  10376. return optNodes[i];
  10377. }
  10378. }
  10379. };
  10380. self.init = function(ngModel) {
  10381. self.ngModel = ngModel;
  10382. // Allow users to provide `ng-model="foo" ng-model-options="{trackBy: 'foo.id'}"` so
  10383. // that we can properly compare objects set on the model to the available options
  10384. if (ngModel.$options && ngModel.$options.trackBy) {
  10385. var trackByLocals = {};
  10386. var trackByParsed = $parse(ngModel.$options.trackBy);
  10387. self.hashGetter = function(value, valueScope) {
  10388. trackByLocals.$value = value;
  10389. return trackByParsed(valueScope || $scope, trackByLocals);
  10390. };
  10391. // If the user doesn't provide a trackBy, we automatically generate an id for every
  10392. // value passed in
  10393. } else {
  10394. self.hashGetter = function getHashValue(value) {
  10395. if (angular.isObject(value)) {
  10396. return 'object_' + (value.$$mdSelectId || (value.$$mdSelectId = ++selectNextId));
  10397. }
  10398. return value;
  10399. };
  10400. }
  10401. self.setMultiple(self.isMultiple);
  10402. };
  10403. self.selectedLabels = function() {
  10404. var selectedOptionEls = $mdUtil.nodesToArray($element[0].querySelectorAll('md-option[selected]'));
  10405. if (selectedOptionEls.length) {
  10406. return selectedOptionEls.map(function(el) {
  10407. return el.textContent;
  10408. }).join(', ');
  10409. } else {
  10410. return '';
  10411. }
  10412. };
  10413. self.select = function(hashKey, hashedValue) {
  10414. var option = self.options[hashKey];
  10415. option && option.setSelected(true);
  10416. self.selected[hashKey] = hashedValue;
  10417. };
  10418. self.deselect = function(hashKey) {
  10419. var option = self.options[hashKey];
  10420. option && option.setSelected(false);
  10421. delete self.selected[hashKey];
  10422. };
  10423. self.addOption = function(hashKey, optionCtrl) {
  10424. if (angular.isDefined(self.options[hashKey])) {
  10425. throw new Error('Duplicate md-option values are not allowed in a select. ' +
  10426. 'Duplicate value "' + optionCtrl.value + '" found.');
  10427. }
  10428. self.options[hashKey] = optionCtrl;
  10429. // If this option's value was already in our ngModel, go ahead and select it.
  10430. if (angular.isDefined(self.selected[hashKey])) {
  10431. self.select(hashKey, optionCtrl.value);
  10432. self.refreshViewValue();
  10433. }
  10434. };
  10435. self.removeOption = function(hashKey) {
  10436. delete self.options[hashKey];
  10437. // Don't deselect an option when it's removed - the user's ngModel should be allowed
  10438. // to have values that do not match a currently available option.
  10439. };
  10440. self.refreshViewValue = function() {
  10441. var values = [];
  10442. var option;
  10443. for (var hashKey in self.selected) {
  10444. // If this hashKey has an associated option, push that option's value to the model.
  10445. if ((option = self.options[hashKey])) {
  10446. values.push(option.value);
  10447. } else {
  10448. // Otherwise, the given hashKey has no associated option, and we got it
  10449. // from an ngModel value at an earlier time. Push the unhashed value of
  10450. // this hashKey to the model.
  10451. // This allows the developer to put a value in the model that doesn't yet have
  10452. // an associated option.
  10453. values.push(self.selected[hashKey]);
  10454. }
  10455. }
  10456. self.ngModel.$setViewValue(self.isMultiple ? values : values[0]);
  10457. };
  10458. function renderMultiple() {
  10459. var newSelectedValues = self.ngModel.$modelValue || self.ngModel.$viewValue || [];
  10460. if (!angular.isArray(newSelectedValues)) return;
  10461. var oldSelected = Object.keys(self.selected);
  10462. var newSelectedHashes = newSelectedValues.map(self.hashGetter);
  10463. var deselected = oldSelected.filter(function(hash) {
  10464. return newSelectedHashes.indexOf(hash) === -1;
  10465. });
  10466. deselected.forEach(self.deselect);
  10467. newSelectedHashes.forEach(function(hashKey, i) {
  10468. self.select(hashKey, newSelectedValues[i]);
  10469. });
  10470. }
  10471. function renderSingular() {
  10472. var value = self.ngModel.$viewValue || self.ngModel.$modelValue;
  10473. Object.keys(self.selected).forEach(self.deselect);
  10474. self.select(self.hashGetter(value), value);
  10475. }
  10476. }
  10477. }
  10478. SelectMenuDirective.$inject = ["$parse", "$mdUtil", "$mdTheming"];
  10479. function OptionDirective($mdButtonInkRipple, $mdUtil) {
  10480. OptionController.$inject = ["$element"];
  10481. return {
  10482. restrict: 'E',
  10483. require: ['mdOption', '^^mdSelectMenu'],
  10484. controller: OptionController,
  10485. compile: compile
  10486. };
  10487. function compile(element, attr) {
  10488. // Manual transclusion to avoid the extra inner <span> that ng-transclude generates
  10489. element.append(angular.element('<div class="md-text">').append(element.contents()));
  10490. element.attr('tabindex', attr.tabindex || '0');
  10491. return postLink;
  10492. }
  10493. function postLink(scope, element, attr, ctrls) {
  10494. var optionCtrl = ctrls[0];
  10495. var selectCtrl = ctrls[1];
  10496. if (angular.isDefined(attr.ngValue)) {
  10497. scope.$watch(attr.ngValue, setOptionValue);
  10498. } else if (angular.isDefined(attr.value)) {
  10499. setOptionValue(isNaN(attr.value) ? attr.value : Number(attr.value));
  10500. } else {
  10501. scope.$watch(function() {
  10502. return element.text();
  10503. }, setOptionValue);
  10504. }
  10505. attr.$observe('disabled', function(disabled) {
  10506. if (disabled) {
  10507. element.attr('tabindex', '-1');
  10508. } else {
  10509. element.attr('tabindex', '0');
  10510. }
  10511. });
  10512. scope.$$postDigest(function() {
  10513. attr.$observe('selected', function(selected) {
  10514. if (!angular.isDefined(selected)) return;
  10515. if (typeof selected == 'string') selected = true;
  10516. if (selected) {
  10517. if (!selectCtrl.isMultiple) {
  10518. selectCtrl.deselect(Object.keys(selectCtrl.selected)[0]);
  10519. }
  10520. selectCtrl.select(optionCtrl.hashKey, optionCtrl.value);
  10521. } else {
  10522. selectCtrl.deselect(optionCtrl.hashKey);
  10523. }
  10524. selectCtrl.refreshViewValue();
  10525. selectCtrl.ngModel.$render();
  10526. });
  10527. });
  10528. $mdButtonInkRipple.attach(scope, element);
  10529. configureAria();
  10530. function setOptionValue(newValue, oldValue) {
  10531. var oldHashKey = selectCtrl.hashGetter(oldValue, scope);
  10532. var newHashKey = selectCtrl.hashGetter(newValue, scope);
  10533. optionCtrl.hashKey = newHashKey;
  10534. optionCtrl.value = newValue;
  10535. selectCtrl.removeOption(oldHashKey, optionCtrl);
  10536. selectCtrl.addOption(newHashKey, optionCtrl);
  10537. }
  10538. scope.$on('$destroy', function() {
  10539. selectCtrl.removeOption(optionCtrl.hashKey, optionCtrl);
  10540. });
  10541. function configureAria() {
  10542. var ariaAttrs = {
  10543. 'role': 'option',
  10544. 'aria-selected': 'false'
  10545. };
  10546. if (!element[0].hasAttribute('id')) {
  10547. ariaAttrs.id = 'select_option_' + $mdUtil.nextUid();
  10548. }
  10549. element.attr(ariaAttrs);
  10550. }
  10551. }
  10552. function OptionController($element) {
  10553. this.selected = false;
  10554. this.setSelected = function(isSelected) {
  10555. if (isSelected && !this.selected) {
  10556. $element.attr({
  10557. 'selected': 'selected',
  10558. 'aria-selected': 'true'
  10559. });
  10560. } else if (!isSelected && this.selected) {
  10561. $element.removeAttr('selected');
  10562. $element.attr('aria-selected', 'false');
  10563. }
  10564. this.selected = isSelected;
  10565. };
  10566. }
  10567. }
  10568. OptionDirective.$inject = ["$mdButtonInkRipple", "$mdUtil"];
  10569. function OptgroupDirective() {
  10570. return {
  10571. restrict: 'E',
  10572. compile: compile
  10573. };
  10574. function compile(el, attrs) {
  10575. var labelElement = el.find('label');
  10576. if (!labelElement.length) {
  10577. labelElement = angular.element('<label>');
  10578. el.prepend(labelElement);
  10579. }
  10580. if (attrs.label) labelElement.text(attrs.label);
  10581. }
  10582. }
  10583. function SelectProvider($$interimElementProvider) {
  10584. selectDefaultOptions.$inject = ["$mdSelect", "$mdConstant", "$mdUtil", "$window", "$q", "$$rAF", "$animateCss", "$animate"];
  10585. return $$interimElementProvider('$mdSelect')
  10586. .setDefaults({
  10587. methods: ['target'],
  10588. options: selectDefaultOptions
  10589. });
  10590. /* @ngInject */
  10591. function selectDefaultOptions($mdSelect, $mdConstant, $mdUtil, $window, $q, $$rAF, $animateCss, $animate) {
  10592. var ERRROR_TARGET_EXPECTED = "$mdSelect.show() expected a target element in options.target but got '{0}'!";
  10593. var animator = $mdUtil.dom.animator;
  10594. return {
  10595. parent: 'body',
  10596. themable: true,
  10597. onShow: onShow,
  10598. onRemove: onRemove,
  10599. hasBackdrop: true,
  10600. disableParentScroll: true
  10601. };
  10602. /**
  10603. * Interim-element onRemove logic....
  10604. */
  10605. function onRemove(scope, element, opts) {
  10606. opts.cleanupInteraction();
  10607. opts.cleanupResizing();
  10608. opts.hideBackdrop();
  10609. return $animateCss(element, {addClass: 'md-leave'})
  10610. .start()
  10611. .then(function(response) {
  10612. configureAria(opts.target, false);
  10613. element.removeClass('md-active');
  10614. announceClosed(opts);
  10615. detachElement(element, opts);
  10616. return response;
  10617. })
  10618. .finally(function() {
  10619. opts.restoreFocus && opts.target.focus();
  10620. });
  10621. // If we want to ignore leave animations (and remove immediately):
  10622. //
  10623. // configureAria(opts.target, false);
  10624. //
  10625. // element.addClass('md-leave');
  10626. // element.removeClass('md-active');
  10627. //
  10628. // announceClosed(opts);
  10629. // detachElement(element, opts);
  10630. // opts.restoreFocus && opts.target.focus();
  10631. //
  10632. // return $q.when(true);
  10633. }
  10634. /**
  10635. * Interim-element onShow logic....
  10636. */
  10637. function onShow(scope, element, opts) {
  10638. watchAsyncLoad();
  10639. sanitizeAndConfigure(scope, opts);
  10640. configureAria(opts.target);
  10641. opts.hideBackdrop = showBackdrop(scope, element, opts);
  10642. return showDropDown(scope, element, opts)
  10643. .then(function(response) {
  10644. opts.alreadyOpen = true;
  10645. opts.cleanupInteraction = activateInteraction();
  10646. opts.cleanupResizing = activateResizing();
  10647. return response;
  10648. }, opts.hideBackdrop);
  10649. // ************************************
  10650. // Closure Functions
  10651. // ************************************
  10652. /**
  10653. * Attach the select DOM element(s) and animate to the correct positions
  10654. * and scalings...
  10655. */
  10656. function showDropDown(scope, element, opts) {
  10657. opts.parent.append(element);
  10658. return $q(function(resolve, reject) {
  10659. try {
  10660. $animateCss(element, {removeClass: 'md-leave', duration: 0})
  10661. .start()
  10662. .then(positionAndFocusMenu)
  10663. .then(resolve);
  10664. } catch (e) {
  10665. reject(e);
  10666. }
  10667. });
  10668. }
  10669. /**
  10670. * Initialize container and dropDown menu positions/scale, then animate
  10671. * to show... and autoFocus.
  10672. */
  10673. function positionAndFocusMenu() {
  10674. return $q(function(resolve) {
  10675. if (opts.isRemoved) return $q.reject(false);
  10676. var info = calculateMenuPositions(scope, element, opts);
  10677. info.container.element.css(animator.toCss(info.container.styles));
  10678. info.dropDown.element.css(animator.toCss(info.dropDown.styles));
  10679. $$rAF(function() {
  10680. element.addClass('md-active');
  10681. info.dropDown.element.css(animator.toCss({transform: ''}));
  10682. autoFocus(opts.focusedNode);
  10683. resolve();
  10684. });
  10685. });
  10686. }
  10687. /**
  10688. * Show modal backdrop element...
  10689. */
  10690. function showBackdrop(scope, element, options) {
  10691. // If we are not within a dialog...
  10692. if (options.disableParentScroll && !$mdUtil.getClosest(options.target, 'MD-DIALOG')) {
  10693. // !! DO this before creating the backdrop; since disableScrollAround()
  10694. // configures the scroll offset; which is used by mdBackDrop postLink()
  10695. options.restoreScroll = $mdUtil.disableScrollAround(options.element, options.parent);
  10696. } else {
  10697. options.disableParentScroll = false;
  10698. }
  10699. if (options.hasBackdrop) {
  10700. // Override duration to immediately show invisible backdrop
  10701. options.backdrop = $mdUtil.createBackdrop(scope, "md-select-backdrop md-click-catcher");
  10702. $animate.enter(options.backdrop, options.parent, null, {duration: 0});
  10703. }
  10704. /**
  10705. * Hide modal backdrop element...
  10706. */
  10707. return function hideBackdrop() {
  10708. if (options.backdrop) {
  10709. // Override duration to immediately remove invisible backdrop
  10710. $animate.leave(options.backdrop, {duration: 0});
  10711. }
  10712. if (options.disableParentScroll) {
  10713. options.restoreScroll();
  10714. delete options.restoreScroll;
  10715. }
  10716. }
  10717. }
  10718. /**
  10719. *
  10720. */
  10721. function autoFocus(focusedNode) {
  10722. if (focusedNode && !focusedNode.hasAttribute('disabled')) {
  10723. focusedNode.focus();
  10724. }
  10725. }
  10726. /**
  10727. * Check for valid opts and set some sane defaults
  10728. */
  10729. function sanitizeAndConfigure(scope, options) {
  10730. var selectEl = element.find('md-select-menu');
  10731. if (!options.target) {
  10732. throw new Error($mdUtil.supplant(ERRROR_TARGET_EXPECTED, [options.target]));
  10733. }
  10734. angular.extend(options, {
  10735. isRemoved: false,
  10736. target: angular.element(options.target), //make sure it's not a naked dom node
  10737. parent: angular.element(options.parent),
  10738. selectEl: selectEl,
  10739. contentEl: element.find('md-content'),
  10740. optionNodes: selectEl[0].getElementsByTagName('md-option')
  10741. });
  10742. }
  10743. /**
  10744. * Configure various resize listeners for screen changes
  10745. */
  10746. function activateResizing() {
  10747. var debouncedOnResize = (function(scope, target, options) {
  10748. return function() {
  10749. if (options.isRemoved) return;
  10750. var updates = calculateMenuPositions(scope, target, options);
  10751. var container = updates.container;
  10752. var dropDown = updates.dropDown;
  10753. container.element.css(animator.toCss(container.styles));
  10754. dropDown.element.css(animator.toCss(dropDown.styles));
  10755. };
  10756. })(scope, element, opts);
  10757. var window = angular.element($window);
  10758. window.on('resize', debouncedOnResize);
  10759. window.on('orientationchange', debouncedOnResize);
  10760. // Publish deactivation closure...
  10761. return function deactivateResizing() {
  10762. // Disable resizing handlers
  10763. window.off('resize', debouncedOnResize);
  10764. window.off('orientationchange', debouncedOnResize);
  10765. }
  10766. }
  10767. /**
  10768. * If asynchronously loading, watch and update internal
  10769. * '$$loadingAsyncDone' flag
  10770. */
  10771. function watchAsyncLoad() {
  10772. if (opts.loadingAsync && !opts.isRemoved) {
  10773. scope.$$loadingAsyncDone = false;
  10774. $q.when(opts.loadingAsync)
  10775. .then(function() {
  10776. scope.$$loadingAsyncDone = true;
  10777. delete opts.loadingAsync;
  10778. }).then(function() {
  10779. $$rAF(positionAndFocusMenu);
  10780. })
  10781. }
  10782. }
  10783. /**
  10784. *
  10785. */
  10786. function activateInteraction() {
  10787. if (opts.isRemoved) return;
  10788. var dropDown = opts.selectEl;
  10789. var selectCtrl = dropDown.controller('mdSelectMenu') || {};
  10790. element.addClass('md-clickable');
  10791. // Close on backdrop click
  10792. opts.backdrop && opts.backdrop.on('click', onBackdropClick);
  10793. // Escape to close
  10794. // Cycling of options, and closing on enter
  10795. dropDown.on('keydown', onMenuKeyDown);
  10796. dropDown.on('mouseup', checkCloseMenu);
  10797. return function cleanupInteraction() {
  10798. opts.backdrop && opts.backdrop.off('click', onBackdropClick);
  10799. dropDown.off('keydown', onMenuKeyDown);
  10800. dropDown.off('mouseup', checkCloseMenu);
  10801. element.removeClass('md-clickable');
  10802. opts.isRemoved = true;
  10803. };
  10804. // ************************************
  10805. // Closure Functions
  10806. // ************************************
  10807. function onBackdropClick(e) {
  10808. e.preventDefault();
  10809. e.stopPropagation();
  10810. opts.restoreFocus = false;
  10811. $mdUtil.nextTick($mdSelect.hide, true);
  10812. }
  10813. function onMenuKeyDown(ev) {
  10814. var keyCodes = $mdConstant.KEY_CODE;
  10815. switch (ev.keyCode) {
  10816. case keyCodes.UP_ARROW:
  10817. return focusPrevOption();
  10818. break;
  10819. case keyCodes.DOWN_ARROW:
  10820. return focusNextOption();
  10821. break;
  10822. case keyCodes.SPACE:
  10823. case keyCodes.ENTER:
  10824. var option = $mdUtil.getClosest(ev.target, 'md-option');
  10825. if (option) {
  10826. dropDown.triggerHandler({
  10827. type: 'click',
  10828. target: option
  10829. });
  10830. ev.preventDefault();
  10831. }
  10832. checkCloseMenu();
  10833. break;
  10834. case keyCodes.TAB:
  10835. case keyCodes.ESCAPE:
  10836. ev.preventDefault();
  10837. opts.restoreFocus = true;
  10838. $mdUtil.nextTick($mdSelect.hide, true);
  10839. break;
  10840. default:
  10841. if (ev.keyCode >= 31 && ev.keyCode <= 90) {
  10842. var optNode = dropDown.controller('mdSelectMenu').optNodeForKeyboardSearch(ev);
  10843. opts.focusedNode = optNode || opts.focusedNode;
  10844. optNode && optNode.focus();
  10845. }
  10846. }
  10847. }
  10848. function focusOption(direction) {
  10849. var optionsArray = $mdUtil.nodesToArray(opts.optionNodes);
  10850. var index = optionsArray.indexOf(opts.focusedNode);
  10851. var newOption;
  10852. do {
  10853. if (index === -1) {
  10854. // We lost the previously focused element, reset to first option
  10855. index = 0;
  10856. } else if (direction === 'next' && index < optionsArray.length - 1) {
  10857. index++;
  10858. } else if (direction === 'prev' && index > 0) {
  10859. index--;
  10860. }
  10861. newOption = optionsArray[index];
  10862. if (newOption.hasAttribute('disabled')) newOption = undefined;
  10863. } while (!newOption && index < optionsArray.length - 1 && index > 0)
  10864. newOption && newOption.focus();
  10865. opts.focusedNode = newOption;
  10866. }
  10867. function focusNextOption() {
  10868. focusOption('next');
  10869. }
  10870. function focusPrevOption() {
  10871. focusOption('prev');
  10872. }
  10873. function checkCloseMenu(ev) {
  10874. if (ev && ( ev.type == 'mouseup') && (ev.currentTarget != dropDown[0])) return;
  10875. if ( mouseOnScrollbar() ) return;
  10876. if (!selectCtrl.isMultiple) {
  10877. opts.restoreFocus = true;
  10878. $mdUtil.nextTick(function() {
  10879. $mdSelect.hide(selectCtrl.ngModel.$viewValue);
  10880. }, true);
  10881. }
  10882. /**
  10883. * check if the mouseup event was on a scrollbar
  10884. */
  10885. function mouseOnScrollbar() {
  10886. var clickOnScrollbar = false;
  10887. if(ev.currentTarget.children.length > 0) {
  10888. var child = ev.currentTarget.children[0];
  10889. var hasScrollbar = child.scrollHeight > child.clientHeight;
  10890. if (hasScrollbar && child.children.length > 0) {
  10891. var relPosX = ev.pageX - ev.currentTarget.getBoundingClientRect().left;
  10892. if(relPosX > child.children[0].offsetWidth)
  10893. clickOnScrollbar = true;
  10894. }
  10895. }
  10896. return clickOnScrollbar;
  10897. }
  10898. }
  10899. }
  10900. }
  10901. /**
  10902. *
  10903. */
  10904. function configureAria(element, isExpanded) {
  10905. isExpanded = angular.isUndefined(isExpanded) ? 'true' : 'false';
  10906. element && element.attr('aria-expanded', isExpanded);
  10907. }
  10908. /**
  10909. * To notify listeners that the Select menu has closed,
  10910. * trigger the [optional] user-defined expression
  10911. */
  10912. function announceClosed(opts) {
  10913. var mdSelect = opts.selectEl.controller('mdSelect');
  10914. if (mdSelect) {
  10915. var menuController = opts.selectEl.controller('mdSelectMenu');
  10916. mdSelect.setLabelText(menuController.selectedLabels());
  10917. mdSelect.triggerClose();
  10918. }
  10919. }
  10920. /**
  10921. * Use browser to remove this element without triggering a $destory event
  10922. */
  10923. function detachElement(element, opts) {
  10924. if (element[0].parentNode === opts.parent[0]) {
  10925. opts.parent[0].removeChild(element[0]);
  10926. }
  10927. }
  10928. /**
  10929. * Calculate the
  10930. */
  10931. function calculateMenuPositions(scope, element, opts) {
  10932. var optionNodes,
  10933. containerNode = element[0],
  10934. targetNode = opts.target[0].firstElementChild, // target the label
  10935. parentNode = opts.parent[0],
  10936. selectNode = opts.selectEl[0],
  10937. contentNode = opts.contentEl[0],
  10938. parentRect = parentNode.getBoundingClientRect(),
  10939. targetRect = targetNode.getBoundingClientRect(),
  10940. shouldOpenAroundTarget = false,
  10941. bounds = {
  10942. left: parentRect.left + SELECT_EDGE_MARGIN,
  10943. top: SELECT_EDGE_MARGIN,
  10944. bottom: parentRect.height - SELECT_EDGE_MARGIN,
  10945. right: parentRect.width - SELECT_EDGE_MARGIN - ($mdUtil.floatingScrollbars() ? 16 : 0)
  10946. },
  10947. spaceAvailable = {
  10948. top: targetRect.top - bounds.top,
  10949. left: targetRect.left - bounds.left,
  10950. right: bounds.right - (targetRect.left + targetRect.width),
  10951. bottom: bounds.bottom - (targetRect.top + targetRect.height)
  10952. },
  10953. maxWidth = parentRect.width - SELECT_EDGE_MARGIN * 2,
  10954. isScrollable = contentNode.scrollHeight > contentNode.offsetHeight,
  10955. selectedNode = selectNode.querySelector('md-option[selected]'),
  10956. optionNodes = selectNode.getElementsByTagName('md-option'),
  10957. optgroupNodes = selectNode.getElementsByTagName('md-optgroup');
  10958. var loading = isPromiseLike(opts.loadingAsync);
  10959. var centeredNode;
  10960. if (!loading) {
  10961. // If a selected node, center around that
  10962. if (selectedNode) {
  10963. centeredNode = selectedNode;
  10964. // If there are option groups, center around the first option group
  10965. } else if (optgroupNodes.length) {
  10966. centeredNode = optgroupNodes[0];
  10967. // Otherwise - if we are not loading async - center around the first optionNode
  10968. } else if (optionNodes.length) {
  10969. centeredNode = optionNodes[0];
  10970. // In case there are no options, center on whatever's in there... (eg progress indicator)
  10971. } else {
  10972. centeredNode = contentNode.firstElementChild || contentNode;
  10973. }
  10974. } else {
  10975. // If loading, center on progress indicator
  10976. centeredNode = contentNode.firstElementChild || contentNode;
  10977. }
  10978. if (contentNode.offsetWidth > maxWidth) {
  10979. contentNode.style['max-width'] = maxWidth + 'px';
  10980. }
  10981. if (shouldOpenAroundTarget) {
  10982. contentNode.style['min-width'] = targetRect.width + 'px';
  10983. }
  10984. // Remove padding before we compute the position of the menu
  10985. if (isScrollable) {
  10986. selectNode.classList.add('md-overflow');
  10987. }
  10988. var focusedNode = centeredNode;
  10989. if ((focusedNode.tagName || '').toUpperCase() === 'MD-OPTGROUP') {
  10990. focusedNode = optionNodes[0] || contentNode.firstElementChild || contentNode;
  10991. centeredNode = focusedNode;
  10992. }
  10993. // Cache for autoFocus()
  10994. opts.focusedNode = focusedNode;
  10995. // Get the selectMenuRect *after* max-width is possibly set above
  10996. var selectMenuRect = selectNode.getBoundingClientRect();
  10997. var centeredRect = getOffsetRect(centeredNode);
  10998. if (centeredNode) {
  10999. var centeredStyle = $window.getComputedStyle(centeredNode);
  11000. centeredRect.paddingLeft = parseInt(centeredStyle.paddingLeft, 10) || 0;
  11001. centeredRect.paddingRight = parseInt(centeredStyle.paddingRight, 10) || 0;
  11002. }
  11003. if (isScrollable) {
  11004. var scrollBuffer = contentNode.offsetHeight / 2;
  11005. contentNode.scrollTop = centeredRect.top + centeredRect.height / 2 - scrollBuffer;
  11006. if (spaceAvailable.top < scrollBuffer) {
  11007. contentNode.scrollTop = Math.min(
  11008. centeredRect.top,
  11009. contentNode.scrollTop + scrollBuffer - spaceAvailable.top
  11010. );
  11011. } else if (spaceAvailable.bottom < scrollBuffer) {
  11012. contentNode.scrollTop = Math.max(
  11013. centeredRect.top + centeredRect.height - selectMenuRect.height,
  11014. contentNode.scrollTop - scrollBuffer + spaceAvailable.bottom
  11015. );
  11016. }
  11017. }
  11018. var left, top, transformOrigin, minWidth;
  11019. if (shouldOpenAroundTarget) {
  11020. left = targetRect.left;
  11021. top = targetRect.top + targetRect.height;
  11022. transformOrigin = '50% 0';
  11023. if (top + selectMenuRect.height > bounds.bottom) {
  11024. top = targetRect.top - selectMenuRect.height;
  11025. transformOrigin = '50% 100%';
  11026. }
  11027. } else {
  11028. left = (targetRect.left + centeredRect.left - centeredRect.paddingLeft) + 2;
  11029. top = Math.floor(targetRect.top + targetRect.height / 2 - centeredRect.height / 2 -
  11030. centeredRect.top + contentNode.scrollTop) + 2;
  11031. transformOrigin = (centeredRect.left + targetRect.width / 2) + 'px ' +
  11032. (centeredRect.top + centeredRect.height / 2 - contentNode.scrollTop) + 'px 0px';
  11033. minWidth = targetRect.width + centeredRect.paddingLeft + centeredRect.paddingRight;
  11034. }
  11035. // Keep left and top within the window
  11036. var containerRect = containerNode.getBoundingClientRect();
  11037. var scaleX = Math.round(100 * Math.min(targetRect.width / selectMenuRect.width, 1.0)) / 100;
  11038. var scaleY = Math.round(100 * Math.min(targetRect.height / selectMenuRect.height, 1.0)) / 100;
  11039. return {
  11040. container: {
  11041. element: angular.element(containerNode),
  11042. styles: {
  11043. left: Math.floor(clamp(bounds.left, left, bounds.right - containerRect.width)),
  11044. top: Math.floor(clamp(bounds.top, top, bounds.bottom - containerRect.height)),
  11045. 'min-width': minWidth
  11046. }
  11047. },
  11048. dropDown: {
  11049. element: angular.element(selectNode),
  11050. styles: {
  11051. transformOrigin: transformOrigin,
  11052. transform: !opts.alreadyOpen ? $mdUtil.supplant('scale({0},{1})', [scaleX, scaleY]) : ""
  11053. }
  11054. }
  11055. };
  11056. }
  11057. }
  11058. function isPromiseLike(obj) {
  11059. return obj && angular.isFunction(obj.then);
  11060. }
  11061. function clamp(min, n, max) {
  11062. return Math.max(min, Math.min(n, max));
  11063. }
  11064. function getOffsetRect(node) {
  11065. return node ? {
  11066. left: node.offsetLeft,
  11067. top: node.offsetTop,
  11068. width: node.offsetWidth,
  11069. height: node.offsetHeight
  11070. } : {left: 0, top: 0, width: 0, height: 0};
  11071. }
  11072. }
  11073. SelectProvider.$inject = ["$$interimElementProvider"];
  11074. })();
  11075. (function(){
  11076. "use strict";
  11077. /**
  11078. * @ngdoc module
  11079. * @name material.components.sidenav
  11080. *
  11081. * @description
  11082. * A Sidenav QP component.
  11083. */
  11084. angular
  11085. .module('material.components.sidenav', [
  11086. 'material.core',
  11087. 'material.components.backdrop'
  11088. ])
  11089. .factory('$mdSidenav', SidenavService )
  11090. .directive('mdSidenav', SidenavDirective)
  11091. .directive('mdSidenavFocus', SidenavFocusDirective)
  11092. .controller('$mdSidenavController', SidenavController);
  11093. /**
  11094. * @ngdoc service
  11095. * @name $mdSidenav
  11096. * @module material.components.sidenav
  11097. *
  11098. * @description
  11099. * `$mdSidenav` makes it easy to interact with multiple sidenavs
  11100. * in an app.
  11101. *
  11102. * @usage
  11103. * <hljs lang="js">
  11104. * // Async lookup for sidenav instance; will resolve when the instance is available
  11105. * $mdSidenav(componentId).then(function(instance) {
  11106. * $log.debug( componentId + "is now ready" );
  11107. * });
  11108. * // Async toggle the given sidenav;
  11109. * // when instance is known ready and lazy lookup is not needed.
  11110. * $mdSidenav(componentId)
  11111. * .toggle()
  11112. * .then(function(){
  11113. * $log.debug('toggled');
  11114. * });
  11115. * // Async open the given sidenav
  11116. * $mdSidenav(componentId)
  11117. * .open()
  11118. * .then(function(){
  11119. * $log.debug('opened');
  11120. * });
  11121. * // Async close the given sidenav
  11122. * $mdSidenav(componentId)
  11123. * .close()
  11124. * .then(function(){
  11125. * $log.debug('closed');
  11126. * });
  11127. * // Sync check to see if the specified sidenav is set to be open
  11128. * $mdSidenav(componentId).isOpen();
  11129. * // Sync check to whether given sidenav is locked open
  11130. * // If this is true, the sidenav will be open regardless of close()
  11131. * $mdSidenav(componentId).isLockedOpen();
  11132. * </hljs>
  11133. */
  11134. function SidenavService($mdComponentRegistry, $q) {
  11135. return function(handle) {
  11136. // Lookup the controller instance for the specified sidNav instance
  11137. var self;
  11138. var errorMsg = "SideNav '" + handle + "' is not available!";
  11139. var instance = $mdComponentRegistry.get(handle);
  11140. if(!instance) {
  11141. $mdComponentRegistry.notFoundError(handle);
  11142. }
  11143. return self = {
  11144. // -----------------
  11145. // Sync methods
  11146. // -----------------
  11147. isOpen: function() {
  11148. return instance && instance.isOpen();
  11149. },
  11150. isLockedOpen: function() {
  11151. return instance && instance.isLockedOpen();
  11152. },
  11153. // -----------------
  11154. // Async methods
  11155. // -----------------
  11156. toggle: function() {
  11157. return instance ? instance.toggle() : $q.reject(errorMsg);
  11158. },
  11159. open: function() {
  11160. return instance ? instance.open() : $q.reject(errorMsg);
  11161. },
  11162. close: function() {
  11163. return instance ? instance.close() : $q.reject(errorMsg);
  11164. },
  11165. then : function( callbackFn ) {
  11166. var promise = instance ? $q.when(instance) : waitForInstance();
  11167. return promise.then( callbackFn || angular.noop );
  11168. }
  11169. };
  11170. /**
  11171. * Deferred lookup of component instance using $component registry
  11172. */
  11173. function waitForInstance() {
  11174. return $mdComponentRegistry
  11175. .when(handle)
  11176. .then(function( it ){
  11177. instance = it;
  11178. return it;
  11179. });
  11180. }
  11181. };
  11182. }
  11183. SidenavService.$inject = ["$mdComponentRegistry", "$q"];
  11184. /**
  11185. * @ngdoc directive
  11186. * @name mdSidenavFocus
  11187. * @module material.components.sidenav
  11188. *
  11189. * @restrict A
  11190. *
  11191. * @description
  11192. * `mdSidenavFocus` provides a way to specify the focused element when a sidenav opens.
  11193. * This is completely optional, as the sidenav itself is focused by default.
  11194. *
  11195. * @usage
  11196. * <hljs lang="html">
  11197. * <md-sidenav>
  11198. * <form>
  11199. * <md-input-container>
  11200. * <label for="testInput">Label</label>
  11201. * <input id="testInput" type="text" md-sidenav-focus>
  11202. * </md-input-container>
  11203. * </form>
  11204. * </md-sidenav>
  11205. * </hljs>
  11206. **/
  11207. function SidenavFocusDirective() {
  11208. return {
  11209. restrict: 'A',
  11210. require: '^mdSidenav',
  11211. link: function(scope, element, attr, sidenavCtrl) {
  11212. // @see $mdUtil.findFocusTarget(...)
  11213. }
  11214. };
  11215. }
  11216. /**
  11217. * @ngdoc directive
  11218. * @name mdSidenav
  11219. * @module material.components.sidenav
  11220. * @restrict E
  11221. *
  11222. * @description
  11223. *
  11224. * A Sidenav component that can be opened and closed programatically.
  11225. *
  11226. * By default, upon opening it will slide out on top of the main content area.
  11227. *
  11228. * For keyboard and screen reader accessibility, focus is sent to the sidenav wrapper by default.
  11229. * It can be overridden with the `md-sidenav-focus` directive on the child element you want focused.
  11230. *
  11231. * @usage
  11232. * <hljs lang="html">
  11233. * <div layout="row" ng-controller="MyController">
  11234. * <md-sidenav md-component-id="left" class="md-sidenav-left">
  11235. * Left Nav!
  11236. * </md-sidenav>
  11237. *
  11238. * <md-content>
  11239. * Center Content
  11240. * <md-button ng-click="openLeftMenu()">
  11241. * Open Left Menu
  11242. * </md-button>
  11243. * </md-content>
  11244. *
  11245. * <md-sidenav md-component-id="right"
  11246. * md-is-locked-open="$mdMedia('min-width: 333px')"
  11247. * class="md-sidenav-right">
  11248. * <form>
  11249. * <md-input-container>
  11250. * <label for="testInput">Test input</label>
  11251. * <input id="testInput" type="text"
  11252. * ng-model="data" md-sidenav-focus>
  11253. * </md-input-container>
  11254. * </form>
  11255. * </md-sidenav>
  11256. * </div>
  11257. * </hljs>
  11258. *
  11259. * <hljs lang="js">
  11260. * var app = angular.module('myApp', ['ngMaterial']);
  11261. * app.controller('MyController', function($scope, $mdSidenav) {
  11262. * $scope.openLeftMenu = function() {
  11263. * $mdSidenav('left').toggle();
  11264. * };
  11265. * });
  11266. * </hljs>
  11267. *
  11268. * @param {expression=} md-is-open A model bound to whether the sidenav is opened.
  11269. * @param {string=} md-component-id componentId to use with $mdSidenav service.
  11270. * @param {expression=} md-is-locked-open When this expression evalutes to true,
  11271. * the sidenav 'locks open': it falls into the content's flow instead
  11272. * of appearing over it. This overrides the `is-open` attribute.
  11273. *
  11274. * The $mdMedia() service is exposed to the is-locked-open attribute, which
  11275. * can be given a media query or one of the `sm`, `gt-sm`, `md`, `gt-md`, `lg` or `gt-lg` presets.
  11276. * Examples:
  11277. *
  11278. * - `<md-sidenav md-is-locked-open="shouldLockOpen"></md-sidenav>`
  11279. * - `<md-sidenav md-is-locked-open="$mdMedia('min-width: 1000px')"></md-sidenav>`
  11280. * - `<md-sidenav md-is-locked-open="$mdMedia('sm')"></md-sidenav>` (locks open on small screens)
  11281. */
  11282. function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate, $compile, $parse, $log, $q, $document) {
  11283. return {
  11284. restrict: 'E',
  11285. scope: {
  11286. isOpen: '=?mdIsOpen'
  11287. },
  11288. controller: '$mdSidenavController',
  11289. compile: function(element) {
  11290. element.addClass('md-closed');
  11291. element.attr('tabIndex', '-1');
  11292. return postLink;
  11293. }
  11294. };
  11295. /**
  11296. * Directive Post Link function...
  11297. */
  11298. function postLink(scope, element, attr, sidenavCtrl) {
  11299. var lastParentOverFlow;
  11300. var triggeringElement = null;
  11301. var promise = $q.when(true);
  11302. var isLockedOpenParsed = $parse(attr.mdIsLockedOpen);
  11303. var isLocked = function() {
  11304. return isLockedOpenParsed(scope.$parent, {
  11305. $media: function(arg) {
  11306. $log.warn("$media is deprecated for is-locked-open. Use $mdMedia instead.");
  11307. return $mdMedia(arg);
  11308. },
  11309. $mdMedia: $mdMedia
  11310. });
  11311. };
  11312. var backdrop = $mdUtil.createBackdrop(scope, "md-sidenav-backdrop md-opaque ng-enter");
  11313. element.on('$destroy', sidenavCtrl.destroy);
  11314. $mdTheming.inherit(backdrop, element);
  11315. scope.$watch(isLocked, updateIsLocked);
  11316. scope.$watch('isOpen', updateIsOpen);
  11317. // Publish special accessor for the Controller instance
  11318. sidenavCtrl.$toggleOpen = toggleOpen;
  11319. /**
  11320. * Toggle the DOM classes to indicate `locked`
  11321. * @param isLocked
  11322. */
  11323. function updateIsLocked(isLocked, oldValue) {
  11324. scope.isLockedOpen = isLocked;
  11325. if (isLocked === oldValue) {
  11326. element.toggleClass('md-locked-open', !!isLocked);
  11327. } else {
  11328. $animate[isLocked ? 'addClass' : 'removeClass'](element, 'md-locked-open');
  11329. }
  11330. backdrop.toggleClass('md-locked-open', !!isLocked);
  11331. }
  11332. /**
  11333. * Toggle the SideNav view and attach/detach listeners
  11334. * @param isOpen
  11335. */
  11336. function updateIsOpen(isOpen) {
  11337. // Support deprecated md-sidenav-focus attribute as fallback
  11338. var focusEl = $mdUtil.findFocusTarget(element) || $mdUtil.findFocusTarget(element,'[md-sidenav-focus]') || element;
  11339. var parent = element.parent();
  11340. parent[isOpen ? 'on' : 'off']('keydown', onKeyDown);
  11341. backdrop[isOpen ? 'on' : 'off']('click', close);
  11342. if ( isOpen ) {
  11343. // Capture upon opening..
  11344. triggeringElement = $document[0].activeElement;
  11345. }
  11346. disableParentScroll(isOpen);
  11347. return promise = $q.all([
  11348. isOpen ? $animate.enter(backdrop, parent) : $animate.leave(backdrop),
  11349. $animate[isOpen ? 'removeClass' : 'addClass'](element, 'md-closed')
  11350. ])
  11351. .then(function() {
  11352. // Perform focus when animations are ALL done...
  11353. if (scope.isOpen) {
  11354. focusEl && focusEl.focus();
  11355. }
  11356. });
  11357. }
  11358. /**
  11359. * Prevent parent scrolling (when the SideNav is open)
  11360. */
  11361. function disableParentScroll(disabled) {
  11362. var parent = element.parent();
  11363. if ( disabled && !lastParentOverFlow ) {
  11364. lastParentOverFlow = parent.css('overflow');
  11365. parent.css('overflow', 'hidden');
  11366. } else if (angular.isDefined(lastParentOverFlow)) {
  11367. parent.css('overflow', lastParentOverFlow);
  11368. lastParentOverFlow = undefined;
  11369. }
  11370. }
  11371. /**
  11372. * Toggle the sideNav view and publish a promise to be resolved when
  11373. * the view animation finishes.
  11374. *
  11375. * @param isOpen
  11376. * @returns {*}
  11377. */
  11378. function toggleOpen( isOpen ) {
  11379. if (scope.isOpen == isOpen ) {
  11380. return $q.when(true);
  11381. } else {
  11382. return $q(function(resolve){
  11383. // Toggle value to force an async `updateIsOpen()` to run
  11384. scope.isOpen = isOpen;
  11385. $mdUtil.nextTick(function() {
  11386. // When the current `updateIsOpen()` animation finishes
  11387. promise.then(function(result) {
  11388. if ( !scope.isOpen ) {
  11389. // reset focus to originating element (if available) upon close
  11390. triggeringElement && triggeringElement.focus();
  11391. triggeringElement = null;
  11392. }
  11393. resolve(result);
  11394. });
  11395. });
  11396. });
  11397. }
  11398. }
  11399. /**
  11400. * Auto-close sideNav when the `escape` key is pressed.
  11401. * @param evt
  11402. */
  11403. function onKeyDown(ev) {
  11404. var isEscape = (ev.keyCode === $mdConstant.KEY_CODE.ESCAPE);
  11405. return isEscape ? close(ev) : $q.when(true);
  11406. }
  11407. /**
  11408. * With backdrop `clicks` or `escape` key-press, immediately
  11409. * apply the CSS close transition... Then notify the controller
  11410. * to close() and perform its own actions.
  11411. */
  11412. function close(ev) {
  11413. ev.preventDefault();
  11414. ev.stopPropagation();
  11415. return sidenavCtrl.close();
  11416. }
  11417. }
  11418. }
  11419. SidenavDirective.$inject = ["$mdMedia", "$mdUtil", "$mdConstant", "$mdTheming", "$animate", "$compile", "$parse", "$log", "$q", "$document"];
  11420. /*
  11421. * @private
  11422. * @ngdoc controller
  11423. * @name SidenavController
  11424. * @module material.components.sidenav
  11425. *
  11426. */
  11427. function SidenavController($scope, $element, $attrs, $mdComponentRegistry, $q) {
  11428. var self = this;
  11429. // Use Default internal method until overridden by directive postLink
  11430. // Synchronous getters
  11431. self.isOpen = function() { return !!$scope.isOpen; };
  11432. self.isLockedOpen = function() { return !!$scope.isLockedOpen; };
  11433. // Async actions
  11434. self.open = function() { return self.$toggleOpen( true ); };
  11435. self.close = function() { return self.$toggleOpen( false ); };
  11436. self.toggle = function() { return self.$toggleOpen( !$scope.isOpen ); };
  11437. self.$toggleOpen = function(value) { return $q.when($scope.isOpen = value); };
  11438. self.destroy = $mdComponentRegistry.register(self, $attrs.mdComponentId);
  11439. }
  11440. SidenavController.$inject = ["$scope", "$element", "$attrs", "$mdComponentRegistry", "$q"];
  11441. })();
  11442. (function(){
  11443. "use strict";
  11444. /**
  11445. * @ngdoc module
  11446. * @name material.components.slider
  11447. */
  11448. angular.module('material.components.slider', [
  11449. 'material.core'
  11450. ])
  11451. .directive('mdSlider', SliderDirective);
  11452. /**
  11453. * @ngdoc directive
  11454. * @name mdSlider
  11455. * @module material.components.slider
  11456. * @restrict E
  11457. * @description
  11458. * The `<md-slider>` component allows the user to choose from a range of
  11459. * values.
  11460. *
  11461. * As per the [material design spec](http://www.google.com/design/spec/style/color.html#color-ui-color-application)
  11462. * the slider is in the accent color by default. The primary color palette may be used with
  11463. * the `md-primary` class.
  11464. *
  11465. * It has two modes: 'normal' mode, where the user slides between a wide range
  11466. * of values, and 'discrete' mode, where the user slides between only a few
  11467. * select values.
  11468. *
  11469. * To enable discrete mode, add the `md-discrete` attribute to a slider,
  11470. * and use the `step` attribute to change the distance between
  11471. * values the user is allowed to pick.
  11472. *
  11473. * @usage
  11474. * <h4>Normal Mode</h4>
  11475. * <hljs lang="html">
  11476. * <md-slider ng-model="myValue" min="5" max="500">
  11477. * </md-slider>
  11478. * </hljs>
  11479. * <h4>Discrete Mode</h4>
  11480. * <hljs lang="html">
  11481. * <md-slider md-discrete ng-model="myDiscreteValue" step="10" min="10" max="130">
  11482. * </md-slider>
  11483. * </hljs>
  11484. *
  11485. * @param {boolean=} md-discrete Whether to enable discrete mode.
  11486. * @param {number=} step The distance between values the user is allowed to pick. Default 1.
  11487. * @param {number=} min The minimum value the user is allowed to pick. Default 0.
  11488. * @param {number=} max The maximum value the user is allowed to pick. Default 100.
  11489. */
  11490. function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdTheming, $mdGesture, $parse, $log) {
  11491. return {
  11492. scope: {},
  11493. require: '?ngModel',
  11494. template:
  11495. '<div class="md-slider-wrapper">\
  11496. <div class="md-track-container">\
  11497. <div class="md-track"></div>\
  11498. <div class="md-track md-track-fill"></div>\
  11499. <div class="md-track-ticks"></div>\
  11500. </div>\
  11501. <div class="md-thumb-container">\
  11502. <div class="md-thumb"></div>\
  11503. <div class="md-focus-thumb"></div>\
  11504. <div class="md-focus-ring"></div>\
  11505. <div class="md-sign">\
  11506. <span class="md-thumb-text"></span>\
  11507. </div>\
  11508. <div class="md-disabled-thumb"></div>\
  11509. </div>\
  11510. </div>',
  11511. compile: compile
  11512. };
  11513. // **********************************************************
  11514. // Private Methods
  11515. // **********************************************************
  11516. function compile (tElement, tAttrs) {
  11517. tElement.attr({
  11518. tabIndex: 0,
  11519. role: 'slider'
  11520. });
  11521. $mdAria.expect(tElement, 'aria-label');
  11522. return postLink;
  11523. }
  11524. function postLink(scope, element, attr, ngModelCtrl) {
  11525. $mdTheming(element);
  11526. ngModelCtrl = ngModelCtrl || {
  11527. // Mock ngModelController if it doesn't exist to give us
  11528. // the minimum functionality needed
  11529. $setViewValue: function(val) {
  11530. this.$viewValue = val;
  11531. this.$viewChangeListeners.forEach(function(cb) { cb(); });
  11532. },
  11533. $parsers: [],
  11534. $formatters: [],
  11535. $viewChangeListeners: []
  11536. };
  11537. var isDisabledParsed = attr.ngDisabled && $parse(attr.ngDisabled);
  11538. var isDisabledGetter = isDisabledParsed ?
  11539. function() { return isDisabledParsed(scope.$parent); } :
  11540. angular.noop;
  11541. var thumb = angular.element(element[0].querySelector('.md-thumb'));
  11542. var thumbText = angular.element(element[0].querySelector('.md-thumb-text'));
  11543. var thumbContainer = thumb.parent();
  11544. var trackContainer = angular.element(element[0].querySelector('.md-track-container'));
  11545. var activeTrack = angular.element(element[0].querySelector('.md-track-fill'));
  11546. var tickContainer = angular.element(element[0].querySelector('.md-track-ticks'));
  11547. var throttledRefreshDimensions = $mdUtil.throttle(refreshSliderDimensions, 5000);
  11548. // Default values, overridable by attrs
  11549. angular.isDefined(attr.min) ? attr.$observe('min', updateMin) : updateMin(0);
  11550. angular.isDefined(attr.max) ? attr.$observe('max', updateMax) : updateMax(100);
  11551. angular.isDefined(attr.step)? attr.$observe('step', updateStep) : updateStep(1);
  11552. // We have to manually stop the $watch on ngDisabled because it exists
  11553. // on the parent scope, and won't be automatically destroyed when
  11554. // the component is destroyed.
  11555. var stopDisabledWatch = angular.noop;
  11556. if (attr.ngDisabled) {
  11557. stopDisabledWatch = scope.$parent.$watch(attr.ngDisabled, updateAriaDisabled);
  11558. }
  11559. $mdGesture.register(element, 'drag');
  11560. element
  11561. .on('keydown', keydownListener)
  11562. .on('$md.pressdown', onPressDown)
  11563. .on('$md.pressup', onPressUp)
  11564. .on('$md.dragstart', onDragStart)
  11565. .on('$md.drag', onDrag)
  11566. .on('$md.dragend', onDragEnd);
  11567. // On resize, recalculate the slider's dimensions and re-render
  11568. function updateAll() {
  11569. refreshSliderDimensions();
  11570. ngModelRender();
  11571. redrawTicks();
  11572. }
  11573. setTimeout(updateAll);
  11574. var debouncedUpdateAll = $$rAF.throttle(updateAll);
  11575. angular.element($window).on('resize', debouncedUpdateAll);
  11576. scope.$on('$destroy', function() {
  11577. angular.element($window).off('resize', debouncedUpdateAll);
  11578. stopDisabledWatch();
  11579. });
  11580. ngModelCtrl.$render = ngModelRender;
  11581. ngModelCtrl.$viewChangeListeners.push(ngModelRender);
  11582. ngModelCtrl.$formatters.push(minMaxValidator);
  11583. ngModelCtrl.$formatters.push(stepValidator);
  11584. /**
  11585. * Attributes
  11586. */
  11587. var min;
  11588. var max;
  11589. var step;
  11590. function updateMin(value) {
  11591. min = parseFloat(value);
  11592. element.attr('aria-valuemin', value);
  11593. updateAll();
  11594. }
  11595. function updateMax(value) {
  11596. max = parseFloat(value);
  11597. element.attr('aria-valuemax', value);
  11598. updateAll();
  11599. }
  11600. function updateStep(value) {
  11601. step = parseFloat(value);
  11602. redrawTicks();
  11603. }
  11604. function updateAriaDisabled(isDisabled) {
  11605. element.attr('aria-disabled', !!isDisabled);
  11606. }
  11607. // Draw the ticks with canvas.
  11608. // The alternative to drawing ticks with canvas is to draw one element for each tick,
  11609. // which could quickly become a performance bottleneck.
  11610. var tickCanvas, tickCtx;
  11611. function redrawTicks() {
  11612. if (!angular.isDefined(attr.mdDiscrete)) return;
  11613. if ( angular.isUndefined(step) ) return;
  11614. if ( step <= 0 ) {
  11615. var msg = 'Slider step value must be greater than zero when in discrete mode';
  11616. $log.error(msg);
  11617. throw new Error(msg);
  11618. }
  11619. var numSteps = Math.floor( (max - min) / step );
  11620. if (!tickCanvas) {
  11621. tickCanvas = angular.element('<canvas style="position:absolute;">');
  11622. tickContainer.append(tickCanvas);
  11623. var trackTicksStyle = $window.getComputedStyle(tickContainer[0]);
  11624. tickCtx = tickCanvas[0].getContext('2d');
  11625. tickCtx.fillStyle = trackTicksStyle.backgroundColor || 'black';
  11626. }
  11627. var dimensions = getSliderDimensions();
  11628. tickCanvas[0].width = dimensions.width;
  11629. tickCanvas[0].height = dimensions.height;
  11630. var distance;
  11631. for (var i = 0; i <= numSteps; i++) {
  11632. distance = Math.floor(dimensions.width * (i / numSteps));
  11633. tickCtx.fillRect(distance - 1, 0, 2, dimensions.height);
  11634. }
  11635. }
  11636. /**
  11637. * Refreshing Dimensions
  11638. */
  11639. var sliderDimensions = {};
  11640. refreshSliderDimensions();
  11641. function refreshSliderDimensions() {
  11642. sliderDimensions = trackContainer[0].getBoundingClientRect();
  11643. }
  11644. function getSliderDimensions() {
  11645. throttledRefreshDimensions();
  11646. return sliderDimensions;
  11647. }
  11648. /**
  11649. * left/right arrow listener
  11650. */
  11651. function keydownListener(ev) {
  11652. if(element[0].hasAttribute('disabled')) {
  11653. return;
  11654. }
  11655. var changeAmount;
  11656. if (ev.keyCode === $mdConstant.KEY_CODE.LEFT_ARROW) {
  11657. changeAmount = -step;
  11658. } else if (ev.keyCode === $mdConstant.KEY_CODE.RIGHT_ARROW) {
  11659. changeAmount = step;
  11660. }
  11661. if (changeAmount) {
  11662. if (ev.metaKey || ev.ctrlKey || ev.altKey) {
  11663. changeAmount *= 4;
  11664. }
  11665. ev.preventDefault();
  11666. ev.stopPropagation();
  11667. scope.$evalAsync(function() {
  11668. setModelValue(ngModelCtrl.$viewValue + changeAmount);
  11669. });
  11670. }
  11671. }
  11672. /**
  11673. * ngModel setters and validators
  11674. */
  11675. function setModelValue(value) {
  11676. ngModelCtrl.$setViewValue( minMaxValidator(stepValidator(value)) );
  11677. }
  11678. function ngModelRender() {
  11679. if (isNaN(ngModelCtrl.$viewValue)) {
  11680. ngModelCtrl.$viewValue = ngModelCtrl.$modelValue;
  11681. }
  11682. var percent = (ngModelCtrl.$viewValue - min) / (max - min);
  11683. scope.modelValue = ngModelCtrl.$viewValue;
  11684. element.attr('aria-valuenow', ngModelCtrl.$viewValue);
  11685. setSliderPercent(percent);
  11686. thumbText.text( ngModelCtrl.$viewValue );
  11687. }
  11688. function minMaxValidator(value) {
  11689. if (angular.isNumber(value)) {
  11690. return Math.max(min, Math.min(max, value));
  11691. }
  11692. }
  11693. function stepValidator(value) {
  11694. if (angular.isNumber(value)) {
  11695. var formattedValue = (Math.round(value / step) * step);
  11696. // Format to 3 digits after the decimal point - fixes #2015.
  11697. return (Math.round(formattedValue * 1000) / 1000);
  11698. }
  11699. }
  11700. /**
  11701. * @param percent 0-1
  11702. */
  11703. function setSliderPercent(percent) {
  11704. activeTrack.css('width', (percent * 100) + '%');
  11705. thumbContainer.css(
  11706. 'left',
  11707. (percent * 100) + '%'
  11708. );
  11709. element.toggleClass('md-min', percent === 0);
  11710. }
  11711. /**
  11712. * Slide listeners
  11713. */
  11714. var isDragging = false;
  11715. var isDiscrete = angular.isDefined(attr.mdDiscrete);
  11716. function onPressDown(ev) {
  11717. if (isDisabledGetter()) return;
  11718. element.addClass('active');
  11719. element[0].focus();
  11720. refreshSliderDimensions();
  11721. var exactVal = percentToValue( positionToPercent( ev.pointer.x ));
  11722. var closestVal = minMaxValidator( stepValidator(exactVal) );
  11723. scope.$apply(function() {
  11724. setModelValue( closestVal );
  11725. setSliderPercent( valueToPercent(closestVal));
  11726. });
  11727. }
  11728. function onPressUp(ev) {
  11729. if (isDisabledGetter()) return;
  11730. element.removeClass('dragging active');
  11731. var exactVal = percentToValue( positionToPercent( ev.pointer.x ));
  11732. var closestVal = minMaxValidator( stepValidator(exactVal) );
  11733. scope.$apply(function() {
  11734. setModelValue(closestVal);
  11735. ngModelRender();
  11736. });
  11737. }
  11738. function onDragStart(ev) {
  11739. if (isDisabledGetter()) return;
  11740. isDragging = true;
  11741. ev.stopPropagation();
  11742. element.addClass('dragging');
  11743. setSliderFromEvent(ev);
  11744. }
  11745. function onDrag(ev) {
  11746. if (!isDragging) return;
  11747. ev.stopPropagation();
  11748. setSliderFromEvent(ev);
  11749. }
  11750. function onDragEnd(ev) {
  11751. if (!isDragging) return;
  11752. ev.stopPropagation();
  11753. isDragging = false;
  11754. }
  11755. function setSliderFromEvent(ev) {
  11756. // While panning discrete, update only the
  11757. // visual positioning but not the model value.
  11758. if ( isDiscrete ) adjustThumbPosition( ev.pointer.x );
  11759. else doSlide( ev.pointer.x );
  11760. }
  11761. /**
  11762. * Slide the UI by changing the model value
  11763. * @param x
  11764. */
  11765. function doSlide( x ) {
  11766. scope.$evalAsync( function() {
  11767. setModelValue( percentToValue( positionToPercent(x) ));
  11768. });
  11769. }
  11770. /**
  11771. * Slide the UI without changing the model (while dragging/panning)
  11772. * @param x
  11773. */
  11774. function adjustThumbPosition( x ) {
  11775. var exactVal = percentToValue( positionToPercent( x ));
  11776. var closestVal = minMaxValidator( stepValidator(exactVal) );
  11777. setSliderPercent( positionToPercent(x) );
  11778. thumbText.text( closestVal );
  11779. }
  11780. /**
  11781. * Convert horizontal position on slider to percentage value of offset from beginning...
  11782. * @param x
  11783. * @returns {number}
  11784. */
  11785. function positionToPercent( x ) {
  11786. return Math.max(0, Math.min(1, (x - sliderDimensions.left) / (sliderDimensions.width)));
  11787. }
  11788. /**
  11789. * Convert percentage offset on slide to equivalent model value
  11790. * @param percent
  11791. * @returns {*}
  11792. */
  11793. function percentToValue( percent ) {
  11794. return (min + percent * (max - min));
  11795. }
  11796. function valueToPercent( val ) {
  11797. return (val - min)/(max - min);
  11798. }
  11799. }
  11800. }
  11801. SliderDirective.$inject = ["$$rAF", "$window", "$mdAria", "$mdUtil", "$mdConstant", "$mdTheming", "$mdGesture", "$parse", "$log"];
  11802. })();
  11803. (function(){
  11804. "use strict";
  11805. /**
  11806. * @ngdoc module
  11807. * @name material.components.sticky
  11808. * @description
  11809. * Sticky effects for md
  11810. *
  11811. */
  11812. angular
  11813. .module('material.components.sticky', [
  11814. 'material.core',
  11815. 'material.components.content'
  11816. ])
  11817. .factory('$mdSticky', MdSticky);
  11818. /**
  11819. * @ngdoc service
  11820. * @name $mdSticky
  11821. * @module material.components.sticky
  11822. *
  11823. * @description
  11824. * The `$mdSticky`service provides a mixin to make elements sticky.
  11825. *
  11826. * @returns A `$mdSticky` function that takes three arguments:
  11827. * - `scope`
  11828. * - `element`: The element that will be 'sticky'
  11829. * - `elementClone`: A clone of the element, that will be shown
  11830. * when the user starts scrolling past the original element.
  11831. * If not provided, it will use the result of `element.clone()`.
  11832. */
  11833. function MdSticky($document, $mdConstant, $$rAF, $mdUtil) {
  11834. var browserStickySupport = checkStickySupport();
  11835. /**
  11836. * Registers an element as sticky, used internally by directives to register themselves
  11837. */
  11838. return function registerStickyElement(scope, element, stickyClone) {
  11839. var contentCtrl = element.controller('mdContent');
  11840. if (!contentCtrl) return;
  11841. if (browserStickySupport) {
  11842. element.css({
  11843. position: browserStickySupport,
  11844. top: 0,
  11845. 'z-index': 2
  11846. });
  11847. } else {
  11848. var $$sticky = contentCtrl.$element.data('$$sticky');
  11849. if (!$$sticky) {
  11850. $$sticky = setupSticky(contentCtrl);
  11851. contentCtrl.$element.data('$$sticky', $$sticky);
  11852. }
  11853. var deregister = $$sticky.add(element, stickyClone || element.clone());
  11854. scope.$on('$destroy', deregister);
  11855. }
  11856. };
  11857. function setupSticky(contentCtrl) {
  11858. var contentEl = contentCtrl.$element;
  11859. // Refresh elements is very expensive, so we use the debounced
  11860. // version when possible.
  11861. var debouncedRefreshElements = $$rAF.throttle(refreshElements);
  11862. // setupAugmentedScrollEvents gives us `$scrollstart` and `$scroll`,
  11863. // more reliable than `scroll` on android.
  11864. setupAugmentedScrollEvents(contentEl);
  11865. contentEl.on('$scrollstart', debouncedRefreshElements);
  11866. contentEl.on('$scroll', onScroll);
  11867. var self;
  11868. var stickyBaseoffset = contentEl.prop('offsetTop');
  11869. return self = {
  11870. prev: null,
  11871. current: null, //the currently stickied item
  11872. next: null,
  11873. items: [],
  11874. add: add,
  11875. refreshElements: refreshElements
  11876. };
  11877. /***************
  11878. * Public
  11879. ***************/
  11880. // Add an element and its sticky clone to this content's sticky collection
  11881. function add(element, stickyClone) {
  11882. stickyClone.addClass('md-sticky-clone');
  11883. stickyClone.css('top', stickyBaseoffset + 'px');
  11884. var item = {
  11885. element: element,
  11886. clone: stickyClone
  11887. };
  11888. self.items.push(item);
  11889. $mdUtil.nextTick(function() {
  11890. contentEl.prepend(item.clone);
  11891. });
  11892. debouncedRefreshElements();
  11893. return function remove() {
  11894. self.items.forEach(function(item, index) {
  11895. if (item.element[0] === element[0]) {
  11896. self.items.splice(index, 1);
  11897. item.clone.remove();
  11898. }
  11899. });
  11900. debouncedRefreshElements();
  11901. };
  11902. }
  11903. function refreshElements() {
  11904. // Sort our collection of elements by their current position in the DOM.
  11905. // We need to do this because our elements' order of being added may not
  11906. // be the same as their order of display.
  11907. self.items.forEach(refreshPosition);
  11908. self.items = self.items.sort(function(a, b) {
  11909. return a.top < b.top ? -1 : 1;
  11910. });
  11911. // Find which item in the list should be active,
  11912. // based upon the content's current scroll position
  11913. var item;
  11914. var currentScrollTop = contentEl.prop('scrollTop');
  11915. for (var i = self.items.length - 1; i >= 0; i--) {
  11916. if (currentScrollTop > self.items[i].top) {
  11917. item = self.items[i];
  11918. break;
  11919. }
  11920. }
  11921. setCurrentItem(item);
  11922. }
  11923. /***************
  11924. * Private
  11925. ***************/
  11926. // Find the `top` of an item relative to the content element,
  11927. // and also the height.
  11928. function refreshPosition(item) {
  11929. // Find the top of an item by adding to the offsetHeight until we reach the
  11930. // content element.
  11931. var current = item.element[0];
  11932. item.top = 0;
  11933. item.left = 0;
  11934. while (current && current !== contentEl[0]) {
  11935. item.top += current.offsetTop;
  11936. item.left += current.offsetLeft;
  11937. current = current.offsetParent;
  11938. }
  11939. item.height = item.element.prop('offsetHeight');
  11940. item.clone.css('margin-left', item.left + 'px');
  11941. if ($mdUtil.floatingScrollbars()) {
  11942. item.clone.css('margin-right', '0');
  11943. }
  11944. }
  11945. // As we scroll, push in and select the correct sticky element.
  11946. function onScroll() {
  11947. var scrollTop = contentEl.prop('scrollTop');
  11948. var isScrollingDown = scrollTop > (onScroll.prevScrollTop || 0);
  11949. // Store the previous scroll so we know which direction we are scrolling
  11950. onScroll.prevScrollTop = scrollTop;
  11951. //
  11952. // AT TOP (not scrolling)
  11953. //
  11954. if (scrollTop === 0) {
  11955. // If we're at the top, just clear the current item and return
  11956. setCurrentItem(null);
  11957. return;
  11958. }
  11959. //
  11960. // SCROLLING DOWN (going towards the next item)
  11961. //
  11962. if (isScrollingDown) {
  11963. // If we've scrolled down past the next item's position, sticky it and return
  11964. if (self.next && self.next.top <= scrollTop) {
  11965. setCurrentItem(self.next);
  11966. return;
  11967. }
  11968. // If the next item is close to the current one, push the current one up out of the way
  11969. if (self.current && self.next && self.next.top - scrollTop <= self.next.height) {
  11970. translate(self.current, scrollTop + (self.next.top - self.next.height - scrollTop));
  11971. return;
  11972. }
  11973. }
  11974. //
  11975. // SCROLLING UP (not at the top & not scrolling down; must be scrolling up)
  11976. //
  11977. if (!isScrollingDown) {
  11978. // If we've scrolled up past the previous item's position, sticky it and return
  11979. if (self.current && self.prev && scrollTop < self.current.top) {
  11980. setCurrentItem(self.prev);
  11981. return;
  11982. }
  11983. // If the next item is close to the current one, pull the current one down into view
  11984. if (self.next && self.current && (scrollTop >= (self.next.top - self.current.height))) {
  11985. translate(self.current, scrollTop + (self.next.top - scrollTop - self.current.height));
  11986. return;
  11987. }
  11988. }
  11989. //
  11990. // Otherwise, just move the current item to the proper place (scrolling up or down)
  11991. //
  11992. if (self.current) {
  11993. translate(self.current, scrollTop);
  11994. }
  11995. }
  11996. function setCurrentItem(item) {
  11997. if (self.current === item) return;
  11998. // Deactivate currently active item
  11999. if (self.current) {
  12000. translate(self.current, null);
  12001. setStickyState(self.current, null);
  12002. }
  12003. // Activate new item if given
  12004. if (item) {
  12005. setStickyState(item, 'active');
  12006. }
  12007. self.current = item;
  12008. var index = self.items.indexOf(item);
  12009. // If index === -1, index + 1 = 0. It works out.
  12010. self.next = self.items[index + 1];
  12011. self.prev = self.items[index - 1];
  12012. setStickyState(self.next, 'next');
  12013. setStickyState(self.prev, 'prev');
  12014. }
  12015. function setStickyState(item, state) {
  12016. if (!item || item.state === state) return;
  12017. if (item.state) {
  12018. item.clone.attr('sticky-prev-state', item.state);
  12019. item.element.attr('sticky-prev-state', item.state);
  12020. }
  12021. item.clone.attr('sticky-state', state);
  12022. item.element.attr('sticky-state', state);
  12023. item.state = state;
  12024. }
  12025. function translate(item, amount) {
  12026. if (!item) return;
  12027. if (amount === null || amount === undefined) {
  12028. if (item.translateY) {
  12029. item.translateY = null;
  12030. item.clone.css($mdConstant.CSS.TRANSFORM, '');
  12031. }
  12032. } else {
  12033. item.translateY = amount;
  12034. item.clone.css(
  12035. $mdConstant.CSS.TRANSFORM,
  12036. 'translate3d(' + item.left + 'px,' + amount + 'px,0)'
  12037. );
  12038. }
  12039. }
  12040. }
  12041. // Function to check for browser sticky support
  12042. function checkStickySupport($el) {
  12043. var stickyProp;
  12044. var testEl = angular.element('<div>');
  12045. $document[0].body.appendChild(testEl[0]);
  12046. var stickyProps = ['sticky', '-webkit-sticky'];
  12047. for (var i = 0; i < stickyProps.length; ++i) {
  12048. testEl.css({position: stickyProps[i], top: 0, 'z-index': 2});
  12049. if (testEl.css('position') == stickyProps[i]) {
  12050. stickyProp = stickyProps[i];
  12051. break;
  12052. }
  12053. }
  12054. testEl.remove();
  12055. return stickyProp;
  12056. }
  12057. // Android 4.4 don't accurately give scroll events.
  12058. // To fix this problem, we setup a fake scroll event. We say:
  12059. // > If a scroll or touchmove event has happened in the last DELAY milliseconds,
  12060. // then send a `$scroll` event every animationFrame.
  12061. // Additionally, we add $scrollstart and $scrollend events.
  12062. function setupAugmentedScrollEvents(element) {
  12063. var SCROLL_END_DELAY = 200;
  12064. var isScrolling;
  12065. var lastScrollTime;
  12066. element.on('scroll touchmove', function() {
  12067. if (!isScrolling) {
  12068. isScrolling = true;
  12069. $$rAF(loopScrollEvent);
  12070. element.triggerHandler('$scrollstart');
  12071. }
  12072. element.triggerHandler('$scroll');
  12073. lastScrollTime = +$mdUtil.now();
  12074. });
  12075. function loopScrollEvent() {
  12076. if (+$mdUtil.now() - lastScrollTime > SCROLL_END_DELAY) {
  12077. isScrolling = false;
  12078. element.triggerHandler('$scrollend');
  12079. } else {
  12080. element.triggerHandler('$scroll');
  12081. $$rAF(loopScrollEvent);
  12082. }
  12083. }
  12084. }
  12085. }
  12086. MdSticky.$inject = ["$document", "$mdConstant", "$$rAF", "$mdUtil"];
  12087. })();
  12088. (function(){
  12089. "use strict";
  12090. /**
  12091. * @ngdoc module
  12092. * @name material.components.subheader
  12093. * @description
  12094. * SubHeader module
  12095. *
  12096. * Subheaders are special list tiles that delineate distinct sections of a
  12097. * list or grid list and are typically related to the current filtering or
  12098. * sorting criteria. Subheader tiles are either displayed inline with tiles or
  12099. * can be associated with content, for example, in an adjacent column.
  12100. *
  12101. * Upon scrolling, subheaders remain pinned to the top of the screen and remain
  12102. * pinned until pushed on or off screen by the next subheader. @see [Material
  12103. * Design Specifications](https://www.google.com/design/spec/components/subheaders.html)
  12104. *
  12105. * > To improve the visual grouping of content, use the system color for your subheaders.
  12106. *
  12107. */
  12108. angular
  12109. .module('material.components.subheader', [
  12110. 'material.core',
  12111. 'material.components.sticky'
  12112. ])
  12113. .directive('mdSubheader', MdSubheaderDirective);
  12114. /**
  12115. * @ngdoc directive
  12116. * @name mdSubheader
  12117. * @module material.components.subheader
  12118. *
  12119. * @restrict E
  12120. *
  12121. * @description
  12122. * The `<md-subheader>` directive is a subheader for a section. By default it is sticky.
  12123. * You can make it not sticky by applying the `md-no-sticky` class to the subheader.
  12124. *
  12125. *
  12126. * @usage
  12127. * <hljs lang="html">
  12128. * <md-subheader>Online Friends</md-subheader>
  12129. * </hljs>
  12130. */
  12131. function MdSubheaderDirective($mdSticky, $compile, $mdTheming, $mdUtil) {
  12132. return {
  12133. restrict: 'E',
  12134. replace: true,
  12135. transclude: true,
  12136. template: (
  12137. '<div class="md-subheader">' +
  12138. ' <div class="md-subheader-inner">' +
  12139. ' <span class="md-subheader-content"></span>' +
  12140. ' </div>' +
  12141. '</div>'
  12142. ),
  12143. link: function postLink(scope, element, attr, controllers, transclude) {
  12144. $mdTheming(element);
  12145. var outerHTML = element[0].outerHTML;
  12146. function getContent(el) {
  12147. return angular.element(el[0].querySelector('.md-subheader-content'));
  12148. }
  12149. // Transclude the user-given contents of the subheader
  12150. // the conventional way.
  12151. transclude(scope, function(clone) {
  12152. getContent(element).append(clone);
  12153. });
  12154. // Create another clone, that uses the outer and inner contents
  12155. // of the element, that will be 'stickied' as the user scrolls.
  12156. if (!element.hasClass('md-no-sticky')) {
  12157. transclude(scope, function(clone) {
  12158. // If the user adds an ng-if or ng-repeat directly to the md-subheader element, the
  12159. // compiled clone below will only be a comment tag (since they replace their elements with
  12160. // a comment) which cannot be properly passed to the $mdSticky; so we wrap it in our own
  12161. // DIV to ensure we have something $mdSticky can use
  12162. var wrapperHtml = '<div class="md-subheader-wrapper">' + outerHTML + '</div>';
  12163. var stickyClone = $compile(wrapperHtml)(scope);
  12164. // Append the sticky
  12165. $mdSticky(scope, element, stickyClone);
  12166. // Delay initialization until after any `ng-if`/`ng-repeat`/etc has finished before
  12167. // attempting to create the clone
  12168. $mdUtil.nextTick(function() {
  12169. getContent(stickyClone).append(clone);
  12170. });
  12171. });
  12172. }
  12173. }
  12174. }
  12175. }
  12176. MdSubheaderDirective.$inject = ["$mdSticky", "$compile", "$mdTheming", "$mdUtil"];
  12177. })();
  12178. (function(){
  12179. "use strict";
  12180. /**
  12181. * @ngdoc module
  12182. * @name material.components.swipe
  12183. * @description Swipe module!
  12184. */
  12185. /**
  12186. * @ngdoc directive
  12187. * @module material.components.swipe
  12188. * @name mdSwipeLeft
  12189. *
  12190. * @restrict A
  12191. *
  12192. * @description
  12193. * The md-swipe-left directives allows you to specify custom behavior when an element is swiped
  12194. * left.
  12195. *
  12196. * @usage
  12197. * <hljs lang="html">
  12198. * <div md-swipe-left="onSwipeLeft()">Swipe me left!</div>
  12199. * </hljs>
  12200. */
  12201. /**
  12202. * @ngdoc directive
  12203. * @module material.components.swipe
  12204. * @name mdSwipeRight
  12205. *
  12206. * @restrict A
  12207. *
  12208. * @description
  12209. * The md-swipe-right directives allows you to specify custom behavior when an element is swiped
  12210. * right.
  12211. *
  12212. * @usage
  12213. * <hljs lang="html">
  12214. * <div md-swipe-right="onSwipeRight()">Swipe me right!</div>
  12215. * </hljs>
  12216. */
  12217. angular.module('material.components.swipe', ['material.core'])
  12218. .directive('mdSwipeLeft', getDirective('SwipeLeft'))
  12219. .directive('mdSwipeRight', getDirective('SwipeRight'));
  12220. function getDirective(name) {
  12221. var directiveName = 'md' + name;
  12222. var eventName = '$md.' + name.toLowerCase();
  12223. DirectiveFactory.$inject = ["$parse"];
  12224. return DirectiveFactory;
  12225. /* @ngInject */
  12226. function DirectiveFactory($parse) {
  12227. return { restrict: 'A', link: postLink };
  12228. function postLink(scope, element, attr) {
  12229. var fn = $parse(attr[directiveName]);
  12230. element.on(eventName, function(ev) {
  12231. scope.$apply(function() { fn(scope, { $event: ev }); });
  12232. });
  12233. }
  12234. }
  12235. }
  12236. })();
  12237. (function(){
  12238. "use strict";
  12239. /**
  12240. * @private
  12241. * @ngdoc module
  12242. * @name material.components.switch
  12243. */
  12244. angular.module('material.components.switch', [
  12245. 'material.core',
  12246. 'material.components.checkbox'
  12247. ])
  12248. .directive('mdSwitch', MdSwitch);
  12249. /**
  12250. * @private
  12251. * @ngdoc directive
  12252. * @module material.components.switch
  12253. * @name mdSwitch
  12254. * @restrict E
  12255. *
  12256. * The switch directive is used very much like the normal [angular checkbox](https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D).
  12257. *
  12258. * As per the [material design spec](http://www.google.com/design/spec/style/color.html#color-ui-color-application)
  12259. * the switch is in the accent color by default. The primary color palette may be used with
  12260. * the `md-primary` class.
  12261. *
  12262. * @param {string} ng-model Assignable angular expression to data-bind to.
  12263. * @param {string=} name Property name of the form under which the control is published.
  12264. * @param {expression=} ng-true-value The value to which the expression should be set when selected.
  12265. * @param {expression=} ng-false-value The value to which the expression should be set when not selected.
  12266. * @param {string=} ng-change Angular expression to be executed when input changes due to user interaction with the input element.
  12267. * @param {boolean=} md-no-ink Use of attribute indicates use of ripple ink effects.
  12268. * @param {string=} aria-label Publish the button label used by screen-readers for accessibility. Defaults to the switch's text.
  12269. *
  12270. * @usage
  12271. * <hljs lang="html">
  12272. * <md-switch ng-model="isActive" aria-label="Finished?">
  12273. * Finished ?
  12274. * </md-switch>
  12275. *
  12276. * <md-switch md-no-ink ng-model="hasInk" aria-label="No Ink Effects">
  12277. * No Ink Effects
  12278. * </md-switch>
  12279. *
  12280. * <md-switch ng-disabled="true" ng-model="isDisabled" aria-label="Disabled">
  12281. * Disabled
  12282. * </md-switch>
  12283. *
  12284. * </hljs>
  12285. */
  12286. function MdSwitch(mdCheckboxDirective, $mdTheming, $mdUtil, $document, $mdConstant, $parse, $$rAF, $mdGesture) {
  12287. var checkboxDirective = mdCheckboxDirective[0];
  12288. return {
  12289. restrict: 'E',
  12290. priority:210, // Run before ngAria
  12291. transclude: true,
  12292. template:
  12293. '<div class="md-container">' +
  12294. '<div class="md-bar"></div>' +
  12295. '<div class="md-thumb-container">' +
  12296. '<div class="md-thumb" md-ink-ripple md-ink-ripple-checkbox></div>' +
  12297. '</div>'+
  12298. '</div>' +
  12299. '<div ng-transclude class="md-label">' +
  12300. '</div>',
  12301. require: '?ngModel',
  12302. compile: compile
  12303. };
  12304. function compile(element, attr) {
  12305. var checkboxLink = checkboxDirective.compile(element, attr);
  12306. // no transition on initial load
  12307. element.addClass('md-dragging');
  12308. return function (scope, element, attr, ngModel) {
  12309. ngModel = ngModel || $mdUtil.fakeNgModel();
  12310. var disabledGetter = $parse(attr.ngDisabled);
  12311. var thumbContainer = angular.element(element[0].querySelector('.md-thumb-container'));
  12312. var switchContainer = angular.element(element[0].querySelector('.md-container'));
  12313. // no transition on initial load
  12314. $$rAF(function() {
  12315. element.removeClass('md-dragging');
  12316. });
  12317. checkboxLink(scope, element, attr, ngModel);
  12318. if (angular.isDefined(attr.ngDisabled)) {
  12319. scope.$watch(disabledGetter, function(isDisabled) {
  12320. element.attr('tabindex', isDisabled ? -1 : 0);
  12321. });
  12322. }
  12323. // These events are triggered by setup drag
  12324. $mdGesture.register(switchContainer, 'drag');
  12325. switchContainer
  12326. .on('$md.dragstart', onDragStart)
  12327. .on('$md.drag', onDrag)
  12328. .on('$md.dragend', onDragEnd);
  12329. var drag;
  12330. function onDragStart(ev) {
  12331. // Don't go if ng-disabled===true
  12332. if (disabledGetter(scope)) return;
  12333. ev.stopPropagation();
  12334. element.addClass('md-dragging');
  12335. drag = {
  12336. width: thumbContainer.prop('offsetWidth')
  12337. };
  12338. element.removeClass('transition');
  12339. }
  12340. function onDrag(ev) {
  12341. if (!drag) return;
  12342. ev.stopPropagation();
  12343. ev.srcEvent && ev.srcEvent.preventDefault();
  12344. var percent = ev.pointer.distanceX / drag.width;
  12345. //if checked, start from right. else, start from left
  12346. var translate = ngModel.$viewValue ? 1 + percent : percent;
  12347. // Make sure the switch stays inside its bounds, 0-1%
  12348. translate = Math.max(0, Math.min(1, translate));
  12349. thumbContainer.css($mdConstant.CSS.TRANSFORM, 'translate3d(' + (100*translate) + '%,0,0)');
  12350. drag.translate = translate;
  12351. }
  12352. function onDragEnd(ev) {
  12353. if (!drag) return;
  12354. ev.stopPropagation();
  12355. element.removeClass('md-dragging');
  12356. thumbContainer.css($mdConstant.CSS.TRANSFORM, '');
  12357. // We changed if there is no distance (this is a click a click),
  12358. // or if the drag distance is >50% of the total.
  12359. var isChanged = ngModel.$viewValue ? drag.translate < 0.5 : drag.translate > 0.5;
  12360. if (isChanged) {
  12361. applyModelValue(!ngModel.$viewValue);
  12362. }
  12363. drag = null;
  12364. }
  12365. function applyModelValue(newValue) {
  12366. scope.$apply(function() {
  12367. ngModel.$setViewValue(newValue);
  12368. ngModel.$render();
  12369. });
  12370. }
  12371. };
  12372. }
  12373. }
  12374. MdSwitch.$inject = ["mdCheckboxDirective", "$mdTheming", "$mdUtil", "$document", "$mdConstant", "$parse", "$$rAF", "$mdGesture"];
  12375. })();
  12376. (function(){
  12377. "use strict";
  12378. /**
  12379. * @ngdoc module
  12380. * @name material.components.tabs
  12381. * @description
  12382. *
  12383. * Tabs, created with the `<md-tabs>` directive provide *tabbed* navigation with different styles.
  12384. * The Tabs component consists of clickable tabs that are aligned horizontally side-by-side.
  12385. *
  12386. * Features include support for:
  12387. *
  12388. * - static or dynamic tabs,
  12389. * - responsive designs,
  12390. * - accessibility support (ARIA),
  12391. * - tab pagination,
  12392. * - external or internal tab content,
  12393. * - focus indicators and arrow-key navigations,
  12394. * - programmatic lookup and access to tab controllers, and
  12395. * - dynamic transitions through different tab contents.
  12396. *
  12397. */
  12398. /*
  12399. * @see js folder for tabs implementation
  12400. */
  12401. angular.module('material.components.tabs', [
  12402. 'material.core',
  12403. 'material.components.icon'
  12404. ]);
  12405. })();
  12406. (function(){
  12407. "use strict";
  12408. /**
  12409. * @ngdoc module
  12410. * @name material.components.toast
  12411. * @description
  12412. * Toast
  12413. */
  12414. angular.module('material.components.toast', [
  12415. 'material.core',
  12416. 'material.components.button'
  12417. ])
  12418. .directive('mdToast', MdToastDirective)
  12419. .provider('$mdToast', MdToastProvider);
  12420. function MdToastDirective() {
  12421. return {
  12422. restrict: 'E'
  12423. };
  12424. }
  12425. /**
  12426. * @ngdoc service
  12427. * @name $mdToast
  12428. * @module material.components.toast
  12429. *
  12430. * @description
  12431. * `$mdToast` is a service to build a toast notification on any position
  12432. * on the screen with an optional duration, and provides a simple promise API.
  12433. *
  12434. *
  12435. * ## Restrictions on custom toasts
  12436. * - The toast's template must have an outer `<md-toast>` element.
  12437. * - For a toast action, use element with class `md-action`.
  12438. * - Add the class `md-capsule` for curved corners.
  12439. *
  12440. * @usage
  12441. * <hljs lang="html">
  12442. * <div ng-controller="MyController">
  12443. * <md-button ng-click="openToast()">
  12444. * Open a Toast!
  12445. * </md-button>
  12446. * </div>
  12447. * </hljs>
  12448. *
  12449. * <hljs lang="js">
  12450. * var app = angular.module('app', ['ngMaterial']);
  12451. * app.controller('MyController', function($scope, $mdToast) {
  12452. * $scope.openToast = function($event) {
  12453. * $mdToast.show($mdToast.simple().content('Hello!'));
  12454. * // Could also do $mdToast.showSimple('Hello');
  12455. * };
  12456. * });
  12457. * </hljs>
  12458. */
  12459. /**
  12460. * @ngdoc method
  12461. * @name $mdToast#showSimple
  12462. *
  12463. * @description
  12464. * Convenience method which builds and shows a simple toast.
  12465. *
  12466. * @returns {promise} A promise that can be resolved with `$mdToast.hide()` or
  12467. * rejected with `$mdToast.cancel()`.
  12468. *
  12469. */
  12470. /**
  12471. * @ngdoc method
  12472. * @name $mdToast#simple
  12473. *
  12474. * @description
  12475. * Builds a preconfigured toast.
  12476. *
  12477. * @returns {obj} a `$mdToastPreset` with the chainable configuration methods:
  12478. *
  12479. * - $mdToastPreset#content(string) - sets toast content to string
  12480. * - $mdToastPreset#action(string) - adds an action button. If clicked the promise (returned from `show()`) will resolve
  12481. * with value 'ok'; otherwise it promise is resolved with 'true' after a hideDelay timeout.
  12482. * - $mdToastPreset#highlightAction(boolean) - sets action button to be highlighted
  12483. * - $mdToastPreset#capsule(boolean) - adds 'md-capsule' class to the toast (curved corners)
  12484. * - $mdToastPreset#theme(string) - sets the theme on the toast to theme (default is `$mdThemingProvider`'s default theme)
  12485. */
  12486. /**
  12487. * @ngdoc method
  12488. * @name $mdToast#updateContent
  12489. *
  12490. * @description
  12491. * Updates the content of an existing toast. Useful for updating things like counts, etc.
  12492. *
  12493. */
  12494. /**
  12495. * @ngdoc method
  12496. * @name $mdToast#build
  12497. *
  12498. * @description
  12499. * Creates a custom `$mdToastPreset` that you can configure.
  12500. *
  12501. * @returns {obj} a `$mdToastPreset` with the chainable configuration methods for shows' options (see below).
  12502. */
  12503. /**
  12504. * @ngdoc method
  12505. * @name $mdToast#show
  12506. *
  12507. * @description Shows the toast.
  12508. *
  12509. * @param {object} optionsOrPreset Either provide an `$mdToastPreset` returned from `simple()`
  12510. * and `build()`, or an options object with the following properties:
  12511. *
  12512. * - `templateUrl` - `{string=}`: The url of an html template file that will
  12513. * be used as the content of the toast. Restrictions: the template must
  12514. * have an outer `md-toast` element.
  12515. * - `template` - `{string=}`: Same as templateUrl, except this is an actual
  12516. * template string.
  12517. * - `scope` - `{object=}`: the scope to link the template / controller to. If none is specified, it will create a new child scope.
  12518. * This scope will be destroyed when the toast is removed unless `preserveScope` is set to true.
  12519. * - `preserveScope` - `{boolean=}`: whether to preserve the scope when the element is removed. Default is false
  12520. * - `hideDelay` - `{number=}`: How many milliseconds the toast should stay
  12521. * active before automatically closing. Set to 0 or false to have the toast stay open until
  12522. * closed manually. Default: 3000.
  12523. * - `position` - `{string=}`: Where to place the toast. Available: any combination
  12524. * of 'bottom', 'left', 'top', 'right', 'fit'. Default: 'bottom left'.
  12525. * - `controller` - `{string=}`: The controller to associate with this toast.
  12526. * The controller will be injected the local `$hideToast`, which is a function
  12527. * used to hide the toast.
  12528. * - `locals` - `{string=}`: An object containing key/value pairs. The keys will
  12529. * be used as names of values to inject into the controller. For example,
  12530. * `locals: {three: 3}` would inject `three` into the controller with the value
  12531. * of 3.
  12532. * - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in. These values will not be available until after initialization.
  12533. * - `resolve` - `{object=}`: Similar to locals, except it takes promises as values
  12534. * and the toast will not open until the promises resolve.
  12535. * - `controllerAs` - `{string=}`: An alias to assign the controller to on the scope.
  12536. * - `parent` - `{element=}`: The element to append the toast to. Defaults to appending
  12537. * to the root element of the application.
  12538. *
  12539. * @returns {promise} A promise that can be resolved with `$mdToast.hide()` or
  12540. * rejected with `$mdToast.cancel()`. `$mdToast.hide()` will resolve either with a Boolean
  12541. * value == 'true' or the value passed as an argument to `$mdToast.hide()`.
  12542. * And `$mdToast.cancel()` will resolve the promise with a Boolean value == 'false'
  12543. */
  12544. /**
  12545. * @ngdoc method
  12546. * @name $mdToast#hide
  12547. *
  12548. * @description
  12549. * Hide an existing toast and resolve the promise returned from `$mdToast.show()`.
  12550. *
  12551. * @param {*=} response An argument for the resolved promise.
  12552. *
  12553. * @returns {promise} a promise that is called when the existing element is removed from the DOM.
  12554. * The promise is resolved with either a Boolean value == 'true' or the value passed as the
  12555. * argument to `.hide()`.
  12556. *
  12557. */
  12558. /**
  12559. * @ngdoc method
  12560. * @name $mdToast#cancel
  12561. *
  12562. * @description
  12563. * Hide the existing toast and reject the promise returned from
  12564. * `$mdToast.show()`.
  12565. *
  12566. * @param {*=} response An argument for the rejected promise.
  12567. *
  12568. * @returns {promise} a promise that is called when the existing element is removed from the DOM
  12569. * The promise is resolved with a Boolean value == 'false'.
  12570. *
  12571. */
  12572. function MdToastProvider($$interimElementProvider) {
  12573. // Differentiate promise resolves: hide timeout (value == true) and hide action clicks (value == ok).
  12574. var ACTION_RESOLVE = 'ok';
  12575. var activeToastContent;
  12576. var $mdToast = $$interimElementProvider('$mdToast')
  12577. .setDefaults({
  12578. methods: ['position', 'hideDelay', 'capsule', 'parent' ],
  12579. options: toastDefaultOptions
  12580. })
  12581. .addPreset('simple', {
  12582. argOption: 'content',
  12583. methods: ['content', 'action', 'highlightAction', 'theme', 'parent'],
  12584. options: /* @ngInject */ ["$mdToast", "$mdTheming", function($mdToast, $mdTheming) {
  12585. var opts = {
  12586. template: [
  12587. '<md-toast md-theme="{{ toast.theme }}" ng-class="{\'md-capsule\': toast.capsule}">',
  12588. '<span flex>{{ toast.content }}</span>',
  12589. '<md-button class="md-action" ng-if="toast.action" ng-click="toast.resolve()" ng-class="{\'md-highlight\': toast.highlightAction}">',
  12590. '{{ toast.action }}',
  12591. '</md-button>',
  12592. '</md-toast>'
  12593. ].join(''),
  12594. controller: /* @ngInject */ ["$scope", function mdToastCtrl($scope) {
  12595. var self = this;
  12596. $scope.$watch(function() { return activeToastContent; }, function() {
  12597. self.content = activeToastContent;
  12598. });
  12599. this.resolve = function() {
  12600. $mdToast.hide( ACTION_RESOLVE );
  12601. };
  12602. }],
  12603. theme: $mdTheming.defaultTheme(),
  12604. controllerAs: 'toast',
  12605. bindToController: true
  12606. };
  12607. return opts;
  12608. }]
  12609. })
  12610. .addMethod('updateContent', function(newContent) {
  12611. activeToastContent = newContent;
  12612. });
  12613. toastDefaultOptions.$inject = ["$animate", "$mdToast", "$mdUtil"];
  12614. return $mdToast;
  12615. /* @ngInject */
  12616. function toastDefaultOptions($animate, $mdToast, $mdUtil) {
  12617. var SWIPE_EVENTS = '$md.swipeleft $md.swiperight';
  12618. return {
  12619. onShow: onShow,
  12620. onRemove: onRemove,
  12621. position: 'bottom left',
  12622. themable: true,
  12623. hideDelay: 3000
  12624. };
  12625. function onShow(scope, element, options) {
  12626. activeToastContent = options.content;
  12627. element = $mdUtil.extractElementByName(element, 'md-toast');
  12628. options.onSwipe = function(ev, gesture) {
  12629. //Add swipeleft/swiperight class to element so it can animate correctly
  12630. element.addClass('md-' + ev.type.replace('$md.',''));
  12631. $mdUtil.nextTick($mdToast.cancel);
  12632. };
  12633. options.openClass = toastOpenClass(options.position);
  12634. // 'top left' -> 'md-top md-left'
  12635. options.parent.addClass(options.openClass);
  12636. element.on(SWIPE_EVENTS, options.onSwipe);
  12637. element.addClass(options.position.split(' ').map(function(pos) {
  12638. return 'md-' + pos;
  12639. }).join(' '));
  12640. return $animate.enter(element, options.parent);
  12641. }
  12642. function onRemove(scope, element, options) {
  12643. element.off(SWIPE_EVENTS, options.onSwipe);
  12644. options.parent.removeClass(options.openClass);
  12645. return $animate.leave(element);
  12646. }
  12647. function toastOpenClass(position) {
  12648. return 'md-toast-open-' +
  12649. (position.indexOf('top') > -1 ? 'top' : 'bottom');
  12650. }
  12651. }
  12652. }
  12653. MdToastProvider.$inject = ["$$interimElementProvider"];
  12654. })();
  12655. (function(){
  12656. "use strict";
  12657. /**
  12658. * @ngdoc module
  12659. * @name material.components.toolbar
  12660. */
  12661. angular.module('material.components.toolbar', [
  12662. 'material.core',
  12663. 'material.components.content'
  12664. ])
  12665. .directive('mdToolbar', mdToolbarDirective);
  12666. /**
  12667. * @ngdoc directive
  12668. * @name mdToolbar
  12669. * @module material.components.toolbar
  12670. * @restrict E
  12671. * @description
  12672. * `md-toolbar` is used to place a toolbar in your app.
  12673. *
  12674. * Toolbars are usually used above a content area to display the title of the
  12675. * current page, and show relevant action buttons for that page.
  12676. *
  12677. * You can change the height of the toolbar by adding either the
  12678. * `md-medium-tall` or `md-tall` class to the toolbar.
  12679. *
  12680. * @usage
  12681. * <hljs lang="html">
  12682. * <div layout="column" layout-fill>
  12683. * <md-toolbar>
  12684. *
  12685. * <div class="md-toolbar-tools">
  12686. * <span>My App's Title</span>
  12687. *
  12688. * <!-- fill up the space between left and right area -->
  12689. * <span flex></span>
  12690. *
  12691. * <md-button>
  12692. * Right Bar Button
  12693. * </md-button>
  12694. * </div>
  12695. *
  12696. * </md-toolbar>
  12697. * <md-content>
  12698. * Hello!
  12699. * </md-content>
  12700. * </div>
  12701. * </hljs>
  12702. *
  12703. * @param {boolean=} md-scroll-shrink Whether the header should shrink away as
  12704. * the user scrolls down, and reveal itself as the user scrolls up.
  12705. * Note: for scrollShrink to work, the toolbar must be a sibling of a
  12706. * `md-content` element, placed before it. See the scroll shrink demo.
  12707. *
  12708. *
  12709. * @param {number=} md-shrink-speed-factor How much to change the speed of the toolbar's
  12710. * shrinking by. For example, if 0.25 is given then the toolbar will shrink
  12711. * at one fourth the rate at which the user scrolls down. Default 0.5.
  12712. */
  12713. function mdToolbarDirective($$rAF, $mdConstant, $mdUtil, $mdTheming, $animate ) {
  12714. var translateY = angular.bind(null, $mdUtil.supplant, 'translate3d(0,{0}px,0)' );
  12715. return {
  12716. restrict: 'E',
  12717. controller: angular.noop,
  12718. link: function(scope, element, attr) {
  12719. $mdTheming(element);
  12720. if (angular.isDefined(attr.mdScrollShrink)) {
  12721. setupScrollShrink();
  12722. }
  12723. function setupScrollShrink() {
  12724. // Current "y" position of scroll
  12725. var y = 0;
  12726. // Store the last scroll top position
  12727. var prevScrollTop = 0;
  12728. var shrinkSpeedFactor = attr.mdShrinkSpeedFactor || 0.5;
  12729. var toolbarHeight;
  12730. var contentElement;
  12731. var debouncedContentScroll = $$rAF.throttle(onContentScroll);
  12732. var debouncedUpdateHeight = $mdUtil.debounce(updateToolbarHeight, 5 * 1000);
  12733. // Wait for $mdContentLoaded event from mdContent directive.
  12734. // If the mdContent element is a sibling of our toolbar, hook it up
  12735. // to scroll events.
  12736. scope.$on('$mdContentLoaded', onMdContentLoad);
  12737. function onMdContentLoad($event, newContentEl) {
  12738. // Toolbar and content must be siblings
  12739. if (element.parent()[0] === newContentEl.parent()[0]) {
  12740. // unhook old content event listener if exists
  12741. if (contentElement) {
  12742. contentElement.off('scroll', debouncedContentScroll);
  12743. }
  12744. newContentEl.on('scroll', debouncedContentScroll);
  12745. newContentEl.attr('scroll-shrink', 'true');
  12746. contentElement = newContentEl;
  12747. $$rAF(updateToolbarHeight);
  12748. }
  12749. }
  12750. function updateToolbarHeight() {
  12751. toolbarHeight = element.prop('offsetHeight');
  12752. // Add a negative margin-top the size of the toolbar to the content el.
  12753. // The content will start transformed down the toolbarHeight amount,
  12754. // so everything looks normal.
  12755. //
  12756. // As the user scrolls down, the content will be transformed up slowly
  12757. // to put the content underneath where the toolbar was.
  12758. var margin = (-toolbarHeight * shrinkSpeedFactor) + 'px';
  12759. contentElement.css('margin-top', margin);
  12760. contentElement.css('margin-bottom', margin);
  12761. onContentScroll();
  12762. }
  12763. function onContentScroll(e) {
  12764. var scrollTop = e ? e.target.scrollTop : prevScrollTop;
  12765. debouncedUpdateHeight();
  12766. y = Math.min(
  12767. toolbarHeight / shrinkSpeedFactor,
  12768. Math.max(0, y + scrollTop - prevScrollTop)
  12769. );
  12770. element.css( $mdConstant.CSS.TRANSFORM, translateY([-y * shrinkSpeedFactor]) );
  12771. contentElement.css( $mdConstant.CSS.TRANSFORM, translateY([(toolbarHeight - y) * shrinkSpeedFactor]) );
  12772. prevScrollTop = scrollTop;
  12773. $mdUtil.nextTick(function () {
  12774. var hasWhiteFrame = element.hasClass('md-whiteframe-z1');
  12775. if ( hasWhiteFrame && !y) {
  12776. $animate.removeClass(element, 'md-whiteframe-z1');
  12777. } else if ( !hasWhiteFrame && y ) {
  12778. $animate.addClass(element, 'md-whiteframe-z1');
  12779. }
  12780. });
  12781. }
  12782. }
  12783. }
  12784. };
  12785. }
  12786. mdToolbarDirective.$inject = ["$$rAF", "$mdConstant", "$mdUtil", "$mdTheming", "$animate"];
  12787. })();
  12788. (function(){
  12789. "use strict";
  12790. /**
  12791. * @ngdoc module
  12792. * @name material.components.tooltip
  12793. */
  12794. angular
  12795. .module('material.components.tooltip', [ 'material.core' ])
  12796. .directive('mdTooltip', MdTooltipDirective);
  12797. /**
  12798. * @ngdoc directive
  12799. * @name mdTooltip
  12800. * @module material.components.tooltip
  12801. * @description
  12802. * Tooltips are used to describe elements that are interactive and primarily graphical (not textual).
  12803. *
  12804. * Place a `<md-tooltip>` as a child of the element it describes.
  12805. *
  12806. * A tooltip will activate when the user focuses, hovers over, or touches the parent.
  12807. *
  12808. * @usage
  12809. * <hljs lang="html">
  12810. * <md-button class="md-fab md-accent" aria-label="Play">
  12811. * <md-tooltip>
  12812. * Play Music
  12813. * </md-tooltip>
  12814. * <md-icon icon="img/icons/ic_play_arrow_24px.svg"></md-icon>
  12815. * </md-button>
  12816. * </hljs>
  12817. *
  12818. * @param {expression=} md-visible Boolean bound to whether the tooltip is
  12819. * currently visible.
  12820. * @param {number=} md-delay How many milliseconds to wait to show the tooltip after the user focuses, hovers, or touches the parent. Defaults to 300ms.
  12821. * @param {string=} md-direction Which direction would you like the tooltip to go? Supports left, right, top, and bottom. Defaults to bottom.
  12822. * @param {boolean=} md-autohide If present or provided with a boolean value, the tooltip will hide on mouse leave, regardless of focus
  12823. */
  12824. function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdTheming, $rootElement,
  12825. $animate, $q) {
  12826. var TOOLTIP_SHOW_DELAY = 300;
  12827. var TOOLTIP_WINDOW_EDGE_SPACE = 8;
  12828. return {
  12829. restrict: 'E',
  12830. transclude: true,
  12831. priority:210, // Before ngAria
  12832. template: '\
  12833. <div class="md-background"></div>\
  12834. <div class="md-content" ng-transclude></div>',
  12835. scope: {
  12836. visible: '=?mdVisible',
  12837. delay: '=?mdDelay',
  12838. autohide: '=?mdAutohide'
  12839. },
  12840. link: postLink
  12841. };
  12842. function postLink(scope, element, attr) {
  12843. $mdTheming(element);
  12844. var parent = getParentWithPointerEvents(),
  12845. background = angular.element(element[0].getElementsByClassName('md-background')[0]),
  12846. content = angular.element(element[0].getElementsByClassName('md-content')[0]),
  12847. direction = attr.mdDirection,
  12848. current = getNearestContentElement(),
  12849. tooltipParent = angular.element(current || document.body),
  12850. debouncedOnResize = $$rAF.throttle(function () { if (scope.visible) positionTooltip(); });
  12851. // Initialize element
  12852. setDefaults();
  12853. manipulateElement();
  12854. bindEvents();
  12855. configureWatchers();
  12856. addAriaLabel();
  12857. function setDefaults () {
  12858. if (!angular.isDefined(attr.mdDelay)) scope.delay = TOOLTIP_SHOW_DELAY;
  12859. }
  12860. function configureWatchers () {
  12861. scope.$on('$destroy', function() {
  12862. scope.visible = false;
  12863. element.remove();
  12864. angular.element($window).off('resize', debouncedOnResize);
  12865. });
  12866. scope.$watch('visible', function (isVisible) {
  12867. if (isVisible) showTooltip();
  12868. else hideTooltip();
  12869. });
  12870. }
  12871. function addAriaLabel () {
  12872. if (!parent.attr('aria-label') && !parent.text().trim()) {
  12873. parent.attr('aria-label', element.text().trim());
  12874. }
  12875. }
  12876. function manipulateElement () {
  12877. element.detach();
  12878. element.attr('role', 'tooltip');
  12879. }
  12880. /**
  12881. * Scan up dom hierarchy for enabled parent;
  12882. */
  12883. function getParentWithPointerEvents () {
  12884. var parent = element.parent();
  12885. while (parent && hasComputedStyleValue('pointer-events','none', parent[0])) {
  12886. parent = parent.parent();
  12887. }
  12888. return parent;
  12889. }
  12890. function getNearestContentElement () {
  12891. var current = element.parent()[0];
  12892. // Look for the nearest parent md-content, stopping at the rootElement.
  12893. while (current && current !== $rootElement[0] && current !== document.body) {
  12894. current = current.parentNode;
  12895. }
  12896. return current;
  12897. }
  12898. function hasComputedStyleValue(key, value, target) {
  12899. key = attr.$normalize(key);
  12900. target = target || element[0];
  12901. var computedStyles = $window.getComputedStyle(target);
  12902. return angular.isDefined(computedStyles[key]) && (computedStyles[key] == value);
  12903. }
  12904. function bindEvents () {
  12905. var mouseActive = false;
  12906. var ngWindow = angular.element($window);
  12907. // Store whether the element was focused when the window loses focus.
  12908. var windowBlurHandler = function() {
  12909. elementFocusedOnWindowBlur = document.activeElement === parent[0];
  12910. };
  12911. var elementFocusedOnWindowBlur = false;
  12912. ngWindow.on('blur', windowBlurHandler);
  12913. scope.$on('$destroy', function() {
  12914. ngWindow.off('blur', windowBlurHandler);
  12915. });
  12916. var enterHandler = function(e) {
  12917. // Prevent the tooltip from showing when the window is receiving focus.
  12918. if (e.type === 'focus' && elementFocusedOnWindowBlur) {
  12919. elementFocusedOnWindowBlur = false;
  12920. return;
  12921. }
  12922. parent.on('blur mouseleave touchend touchcancel', leaveHandler );
  12923. setVisible(true);
  12924. };
  12925. var leaveHandler = function () {
  12926. var autohide = scope.hasOwnProperty('autohide') ? scope.autohide : attr.hasOwnProperty('mdAutohide');
  12927. if (autohide || mouseActive || ($document[0].activeElement !== parent[0]) ) {
  12928. parent.off('blur mouseleave touchend touchcancel', leaveHandler );
  12929. setVisible(false);
  12930. }
  12931. mouseActive = false;
  12932. };
  12933. // to avoid `synthetic clicks` we listen to mousedown instead of `click`
  12934. parent.on('mousedown', function() { mouseActive = true; });
  12935. parent.on('focus mouseenter touchstart', enterHandler );
  12936. angular.element($window).on('resize', debouncedOnResize);
  12937. }
  12938. function setVisible (value) {
  12939. setVisible.value = !!value;
  12940. if (!setVisible.queued) {
  12941. if (value) {
  12942. setVisible.queued = true;
  12943. $timeout(function() {
  12944. scope.visible = setVisible.value;
  12945. setVisible.queued = false;
  12946. }, scope.delay);
  12947. } else {
  12948. $mdUtil.nextTick(function() { scope.visible = false; });
  12949. }
  12950. }
  12951. }
  12952. function showTooltip() {
  12953. // Insert the element before positioning it, so we can get the position
  12954. // and check if we should display it
  12955. tooltipParent.append(element);
  12956. // Check if we should display it or not.
  12957. // This handles hide-* and show-* along with any user defined css
  12958. if ( hasComputedStyleValue('display','none') ) {
  12959. scope.visible = false;
  12960. element.detach();
  12961. return;
  12962. }
  12963. positionTooltip();
  12964. angular.forEach([element, background, content], function (element) {
  12965. $animate.addClass(element, 'md-show');
  12966. });
  12967. }
  12968. function hideTooltip() {
  12969. var promises = [];
  12970. angular.forEach([element, background, content], function (it) {
  12971. if (it.parent() && it.hasClass('md-show')) {
  12972. promises.push($animate.removeClass(it, 'md-show'));
  12973. }
  12974. });
  12975. $q.all(promises)
  12976. .then(function () {
  12977. if (!scope.visible) element.detach();
  12978. });
  12979. }
  12980. function positionTooltip() {
  12981. var tipRect = $mdUtil.offsetRect(element, tooltipParent);
  12982. var parentRect = $mdUtil.offsetRect(parent, tooltipParent);
  12983. var newPosition = getPosition(direction);
  12984. // If the user provided a direction, just nudge the tooltip onto the screen
  12985. // Otherwise, recalculate based on 'top' since default is 'bottom'
  12986. if (direction) {
  12987. newPosition = fitInParent(newPosition);
  12988. } else if (newPosition.top > element.prop('offsetParent').scrollHeight - tipRect.height - TOOLTIP_WINDOW_EDGE_SPACE) {
  12989. newPosition = fitInParent(getPosition('top'));
  12990. }
  12991. element.css({top: newPosition.top + 'px', left: newPosition.left + 'px'});
  12992. positionBackground();
  12993. function positionBackground () {
  12994. var size = direction === 'left' || direction === 'right'
  12995. ? Math.sqrt(Math.pow(tipRect.width, 2) + Math.pow(tipRect.height / 2, 2)) * 2
  12996. : Math.sqrt(Math.pow(tipRect.width / 2, 2) + Math.pow(tipRect.height, 2)) * 2,
  12997. position = direction === 'left' ? { left: 100, top: 50 }
  12998. : direction === 'right' ? { left: 0, top: 50 }
  12999. : direction === 'top' ? { left: 50, top: 100 }
  13000. : { left: 50, top: 0 };
  13001. background.css({
  13002. width: size + 'px',
  13003. height: size + 'px',
  13004. left: position.left + '%',
  13005. top: position.top + '%'
  13006. });
  13007. }
  13008. function fitInParent (pos) {
  13009. var newPosition = { left: pos.left, top: pos.top };
  13010. newPosition.left = Math.min( newPosition.left, tooltipParent.prop('scrollWidth') - tipRect.width - TOOLTIP_WINDOW_EDGE_SPACE );
  13011. newPosition.left = Math.max( newPosition.left, TOOLTIP_WINDOW_EDGE_SPACE );
  13012. newPosition.top = Math.min( newPosition.top, tooltipParent.prop('scrollHeight') - tipRect.height - TOOLTIP_WINDOW_EDGE_SPACE );
  13013. newPosition.top = Math.max( newPosition.top, TOOLTIP_WINDOW_EDGE_SPACE );
  13014. return newPosition;
  13015. }
  13016. function getPosition (dir) {
  13017. return dir === 'left'
  13018. ? { left: parentRect.left - tipRect.width - TOOLTIP_WINDOW_EDGE_SPACE,
  13019. top: parentRect.top + parentRect.height / 2 - tipRect.height / 2 }
  13020. : dir === 'right'
  13021. ? { left: parentRect.left + parentRect.width + TOOLTIP_WINDOW_EDGE_SPACE,
  13022. top: parentRect.top + parentRect.height / 2 - tipRect.height / 2 }
  13023. : dir === 'top'
  13024. ? { left: parentRect.left + parentRect.width / 2 - tipRect.width / 2,
  13025. top: parentRect.top - tipRect.height - TOOLTIP_WINDOW_EDGE_SPACE }
  13026. : { left: parentRect.left + parentRect.width / 2 - tipRect.width / 2,
  13027. top: parentRect.top + parentRect.height + TOOLTIP_WINDOW_EDGE_SPACE };
  13028. }
  13029. }
  13030. }
  13031. }
  13032. MdTooltipDirective.$inject = ["$timeout", "$window", "$$rAF", "$document", "$mdUtil", "$mdTheming", "$rootElement", "$animate", "$q"];
  13033. })();
  13034. (function(){
  13035. "use strict";
  13036. /**
  13037. * @ngdoc module
  13038. * @name material.components.virtualRepeat
  13039. */
  13040. angular.module('material.components.virtualRepeat', [
  13041. 'material.core'
  13042. ])
  13043. .directive('mdVirtualRepeatContainer', VirtualRepeatContainerDirective)
  13044. .directive('mdVirtualRepeat', VirtualRepeatDirective);
  13045. /**
  13046. * @ngdoc directive
  13047. * @name mdVirtualRepeatContainer
  13048. * @module material.components.virtualRepeat
  13049. * @restrict E
  13050. * @description
  13051. * `md-virtual-repeat-container` provides the scroll container for md-virtual-repeat.
  13052. *
  13053. * Virtual repeat is a limited substitute for ng-repeat that renders only
  13054. * enough dom nodes to fill the container and recycling them as the user scrolls.
  13055. *
  13056. * @usage
  13057. * <hljs lang="html">
  13058. *
  13059. * <md-virtual-repeat-container>
  13060. * <div md-virtual-repeat="i in items" md-item-size="20">Hello {{i}}!</div>
  13061. * </md-virtual-repeat-container>
  13062. * </hljs>
  13063. *
  13064. * @param {boolean=} md-orient-horizontal Whether the container should scroll horizontally
  13065. * (defaults to orientation and scrolling vertically).
  13066. * @param {boolean=} md-auto-shrink When present, the container will shrink to fit
  13067. * the number of items when that number is less than its original size.
  13068. * @param {number=} md-auto-shrink-min Minimum number of items that md-auto-shrink
  13069. * will shrink to (default: 0).
  13070. */
  13071. function VirtualRepeatContainerDirective() {
  13072. return {
  13073. controller: VirtualRepeatContainerController,
  13074. template: virtualRepeatContainerTemplate,
  13075. compile: function virtualRepeatContainerCompile($element, $attrs) {
  13076. $element
  13077. .addClass('md-virtual-repeat-container')
  13078. .addClass($attrs.hasOwnProperty('mdOrientHorizontal')
  13079. ? 'md-orient-horizontal'
  13080. : 'md-orient-vertical');
  13081. }
  13082. };
  13083. }
  13084. function virtualRepeatContainerTemplate($element) {
  13085. return '<div class="md-virtual-repeat-scroller">' +
  13086. '<div class="md-virtual-repeat-sizer"></div>' +
  13087. '<div class="md-virtual-repeat-offsetter">' +
  13088. $element[0].innerHTML +
  13089. '</div></div>';
  13090. }
  13091. /**
  13092. * Maximum size, in pixels, that can be explicitly set to an element. The actual value varies
  13093. * between browsers, but IE11 has the very lowest size at a mere 1,533,917px. Ideally we could
  13094. * *compute* this value, but Firefox always reports an element to have a size of zero if it
  13095. * goes over the max, meaning that we'd have to binary search for the value.
  13096. * @const {number}
  13097. */
  13098. var MAX_ELEMENT_SIZE = 1533917;
  13099. /**
  13100. * Number of additional elements to render above and below the visible area inside
  13101. * of the virtual repeat container. A higher number results in less flicker when scrolling
  13102. * very quickly in Safari, but comes with a higher rendering and dirty-checking cost.
  13103. * @const {number}
  13104. */
  13105. var NUM_EXTRA = 3;
  13106. /** @ngInject */
  13107. function VirtualRepeatContainerController($$rAF, $scope, $element, $attrs) {
  13108. this.$scope = $scope;
  13109. this.$element = $element;
  13110. this.$attrs = $attrs;
  13111. /** @type {number} The width or height of the container */
  13112. this.size = 0;
  13113. /** @type {number} The scroll width or height of the scroller */
  13114. this.scrollSize = 0;
  13115. /** @type {number} The scrollLeft or scrollTop of the scroller */
  13116. this.scrollOffset = 0;
  13117. /** @type {boolean} Whether the scroller is oriented horizontally */
  13118. this.horizontal = this.$attrs.hasOwnProperty('mdOrientHorizontal');
  13119. /** @type {!VirtualRepeatController} The repeater inside of this container */
  13120. this.repeater = null;
  13121. /** @type {boolean} Whether auto-shrink is enabled */
  13122. this.autoShrink = this.$attrs.hasOwnProperty('mdAutoShrink');
  13123. /** @type {number} Minimum number of items to auto-shrink to */
  13124. this.autoShrinkMin = parseInt(this.$attrs.mdAutoShrinkMin, 10) || 0;
  13125. /** @type {?number} Original container size when shrank */
  13126. this.originalSize = null;
  13127. /** @type {number} Amount to offset the total scroll size by. */
  13128. this.offsetSize = parseInt(this.$attrs.mdOffsetSize, 10) || 0;
  13129. this.scroller = $element[0].getElementsByClassName('md-virtual-repeat-scroller')[0];
  13130. this.sizer = this.scroller.getElementsByClassName('md-virtual-repeat-sizer')[0];
  13131. this.offsetter = this.scroller.getElementsByClassName('md-virtual-repeat-offsetter')[0];
  13132. $$rAF(angular.bind(this, this.updateSize));
  13133. // TODO: Come up with a more robust (But hopefully also quick!) way of
  13134. // detecting that we're not visible.
  13135. if ($attrs.ngHide) {
  13136. $scope.$watch($attrs.ngHide, angular.bind(this, function(hidden) {
  13137. if (!hidden) {
  13138. $$rAF(angular.bind(this, this.updateSize));
  13139. }
  13140. }));
  13141. }
  13142. }
  13143. VirtualRepeatContainerController.$inject = ["$$rAF", "$scope", "$element", "$attrs"];
  13144. /** Called by the md-virtual-repeat inside of the container at startup. */
  13145. VirtualRepeatContainerController.prototype.register = function(repeaterCtrl) {
  13146. this.repeater = repeaterCtrl;
  13147. angular.element(this.scroller)
  13148. .on('scroll wheel touchmove touchend', angular.bind(this, this.handleScroll_));
  13149. };
  13150. /** @return {boolean} Whether the container is configured for horizontal scrolling. */
  13151. VirtualRepeatContainerController.prototype.isHorizontal = function() {
  13152. return this.horizontal;
  13153. };
  13154. /** @return {number} The size (width or height) of the container. */
  13155. VirtualRepeatContainerController.prototype.getSize = function() {
  13156. return this.size;
  13157. };
  13158. /**
  13159. * Resizes the container.
  13160. * @private
  13161. * @param {number} The new size to set.
  13162. */
  13163. VirtualRepeatContainerController.prototype.setSize_ = function(size) {
  13164. this.size = size;
  13165. this.$element[0].style[this.isHorizontal() ? 'width' : 'height'] = size + 'px';
  13166. };
  13167. /** Instructs the container to re-measure its size. */
  13168. VirtualRepeatContainerController.prototype.updateSize = function() {
  13169. if (this.originalSize) return;
  13170. this.size = this.isHorizontal()
  13171. ? this.$element[0].clientWidth
  13172. : this.$element[0].clientHeight;
  13173. this.repeater && this.repeater.containerUpdated();
  13174. };
  13175. /** @return {number} The container's scrollHeight or scrollWidth. */
  13176. VirtualRepeatContainerController.prototype.getScrollSize = function() {
  13177. return this.scrollSize;
  13178. };
  13179. /**
  13180. * Sets the scroller element to the specified size.
  13181. * @private
  13182. * @param {number} size The new size.
  13183. */
  13184. VirtualRepeatContainerController.prototype.sizeScroller_ = function(size) {
  13185. var dimension = this.isHorizontal() ? 'width' : 'height';
  13186. var crossDimension = this.isHorizontal() ? 'height' : 'width';
  13187. // If the size falls within the browser's maximum explicit size for a single element, we can
  13188. // set the size and be done. Otherwise, we have to create children that add up the the desired
  13189. // size.
  13190. if (size < MAX_ELEMENT_SIZE) {
  13191. this.sizer.style[dimension] = size + 'px';
  13192. } else {
  13193. // Clear any existing dimensions.
  13194. this.sizer.innerHTML = '';
  13195. this.sizer.style[dimension] = 'auto';
  13196. this.sizer.style[crossDimension] = 'auto';
  13197. // Divide the total size we have to render into N max-size pieces.
  13198. var numChildren = Math.floor(size / MAX_ELEMENT_SIZE);
  13199. // Element template to clone for each max-size piece.
  13200. var sizerChild = document.createElement('div');
  13201. sizerChild.style[dimension] = MAX_ELEMENT_SIZE + 'px';
  13202. sizerChild.style[crossDimension] = '1px';
  13203. for (var i = 0; i < numChildren; i++) {
  13204. this.sizer.appendChild(sizerChild.cloneNode(false));
  13205. }
  13206. // Re-use the element template for the remainder.
  13207. sizerChild.style[dimension] = (size - (numChildren * MAX_ELEMENT_SIZE)) + 'px';
  13208. this.sizer.appendChild(sizerChild);
  13209. }
  13210. };
  13211. /**
  13212. * If auto-shrinking is enabled, shrinks or unshrinks as appropriate.
  13213. * @private
  13214. * @param {number} size The new size.
  13215. */
  13216. VirtualRepeatContainerController.prototype.autoShrink_ = function(size) {
  13217. var shrinkSize = Math.max(size, this.autoShrinkMin * this.repeater.getItemSize());
  13218. if (this.autoShrink && shrinkSize !== this.size) {
  13219. if (shrinkSize < (this.originalSize || this.size)) {
  13220. if (!this.originalSize) {
  13221. this.originalSize = this.size;
  13222. }
  13223. this.setSize_(shrinkSize);
  13224. } else if (this.originalSize) {
  13225. this.setSize_(this.originalSize);
  13226. this.originalSize = null;
  13227. }
  13228. }
  13229. };
  13230. /**
  13231. * Sets the scrollHeight or scrollWidth. Called by the repeater based on
  13232. * its item count and item size.
  13233. * @param {number} itemsSize The total size of the items.
  13234. */
  13235. VirtualRepeatContainerController.prototype.setScrollSize = function(itemsSize) {
  13236. var size = itemsSize + this.offsetSize;
  13237. if (this.scrollSize === size) return;
  13238. this.sizeScroller_(size);
  13239. this.autoShrink_(size);
  13240. this.scrollSize = size;
  13241. };
  13242. /** @return {number} The container's current scroll offset. */
  13243. VirtualRepeatContainerController.prototype.getScrollOffset = function() {
  13244. return this.scrollOffset;
  13245. };
  13246. /**
  13247. * Scrolls to a given scrollTop position.
  13248. * @param {number} position
  13249. */
  13250. VirtualRepeatContainerController.prototype.scrollTo = function(position) {
  13251. this.scroller[this.isHorizontal() ? 'scrollLeft' : 'scrollTop'] = position;
  13252. this.handleScroll_();
  13253. };
  13254. VirtualRepeatContainerController.prototype.resetScroll = function() {
  13255. this.scrollTo(0);
  13256. };
  13257. VirtualRepeatContainerController.prototype.handleScroll_ = function() {
  13258. var offset = this.isHorizontal() ? this.scroller.scrollLeft : this.scroller.scrollTop;
  13259. if (offset === this.scrollOffset) return;
  13260. var itemSize = this.repeater.getItemSize();
  13261. if (!itemSize) return;
  13262. var numItems = Math.max(0, Math.floor(offset / itemSize) - NUM_EXTRA);
  13263. var transform = this.isHorizontal() ? 'translateX(' : 'translateY(';
  13264. transform += (numItems * itemSize) + 'px)';
  13265. this.scrollOffset = offset;
  13266. this.offsetter.style.webkitTransform = transform;
  13267. this.offsetter.style.transform = transform;
  13268. this.repeater.containerUpdated();
  13269. };
  13270. /**
  13271. * @ngdoc directive
  13272. * @name mdVirtualRepeat
  13273. * @module material.components.virtualRepeat
  13274. * @restrict A
  13275. * @priority 1000
  13276. * @description
  13277. * `md-virtual-repeat` specifies an element to repeat using virtual scrolling.
  13278. *
  13279. * Virtual repeat is a limited substitute for ng-repeat that renders only
  13280. * enough dom nodes to fill the container and recycling them as the user scrolls.
  13281. * Arrays, but not objects are supported for iteration.
  13282. * Track by, as alias, and (key, value) syntax are not supported.
  13283. *
  13284. * @usage
  13285. * <hljs lang="html">
  13286. * <md-virtual-repeat-container>
  13287. * <div md-virtual-repeat="i in items">Hello {{i}}!</div>
  13288. * </md-virtual-repeat-container>
  13289. *
  13290. * <md-virtual-repeat-container md-orient-horizontal>
  13291. * <div md-virtual-repeat="i in items" md-item-size="20">Hello {{i}}!</div>
  13292. * </md-virtual-repeat-container>
  13293. * </hljs>
  13294. *
  13295. * @param {number=} md-item-size The height or width of the repeated elements (which
  13296. * must be identical for each element). Optional. Will attempt to read the size
  13297. * from the dom if missing, but still assumes that all repeated nodes have same
  13298. * height or width.
  13299. * @param {string=} md-extra-name Evaluates to an additional name to which
  13300. * the current iterated item can be assigned on the repeated scope. (Needed
  13301. * for use in md-autocomplete).
  13302. * @param {boolean=} md-on-demand When present, treats the md-virtual-repeat argument
  13303. * as an object that can fetch rows rather than an array.
  13304. * NOTE: This object must implement the following interface with two (2) methods:
  13305. * getItemAtIndex: function(index) -> item at that index or null if it is not yet
  13306. * loaded (It should start downloading the item in that case).
  13307. * getLength: function() -> number The data legnth to which the repeater container
  13308. * should be sized. Ideally, when the count is known, this method should return it.
  13309. * Otherwise, return a higher number than the currently loaded items to produce an
  13310. * infinite-scroll behavior.
  13311. */
  13312. function VirtualRepeatDirective($parse) {
  13313. return {
  13314. controller: VirtualRepeatController,
  13315. priority: 1000,
  13316. require: ['mdVirtualRepeat', '^^mdVirtualRepeatContainer'],
  13317. restrict: 'A',
  13318. terminal: true,
  13319. transclude: 'element',
  13320. compile: function VirtualRepeatCompile($element, $attrs) {
  13321. var expression = $attrs.mdVirtualRepeat;
  13322. var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)\s*$/);
  13323. var repeatName = match[1];
  13324. var repeatListExpression = $parse(match[2]);
  13325. var extraName = $attrs.mdExtraName && $parse($attrs.mdExtraName);
  13326. return function VirtualRepeatLink($scope, $element, $attrs, ctrl, $transclude) {
  13327. ctrl[0].link_(ctrl[1], $transclude, repeatName, repeatListExpression, extraName);
  13328. };
  13329. }
  13330. };
  13331. }
  13332. VirtualRepeatDirective.$inject = ["$parse"];
  13333. /** @ngInject */
  13334. function VirtualRepeatController($scope, $element, $attrs, $browser, $document, $$rAF) {
  13335. this.$scope = $scope;
  13336. this.$element = $element;
  13337. this.$attrs = $attrs;
  13338. this.$browser = $browser;
  13339. this.$document = $document;
  13340. this.$$rAF = $$rAF;
  13341. /** @type {boolean} Whether we are in on-demand mode. */
  13342. this.onDemand = $attrs.hasOwnProperty('mdOnDemand');
  13343. /** @type {!Function} Backup reference to $browser.$$checkUrlChange */
  13344. this.browserCheckUrlChange = $browser.$$checkUrlChange;
  13345. /** @type {number} Most recent starting repeat index (based on scroll offset) */
  13346. this.newStartIndex = 0;
  13347. /** @type {number} Most recent ending repeat index (based on scroll offset) */
  13348. this.newEndIndex = 0;
  13349. /** @type {number} Most recent end visible index (based on scroll offset) */
  13350. this.newVisibleEnd = 0;
  13351. /** @type {number} Previous starting repeat index (based on scroll offset) */
  13352. this.startIndex = 0;
  13353. /** @type {number} Previous ending repeat index (based on scroll offset) */
  13354. this.endIndex = 0;
  13355. // TODO: measure width/height of first element from dom if not provided.
  13356. // getComputedStyle?
  13357. /** @type {?number} Height/width of repeated elements. */
  13358. this.itemSize = $scope.$eval($attrs.mdItemSize) || null;
  13359. /** @type {boolean} Whether this is the first time that items are rendered. */
  13360. this.isFirstRender = true;
  13361. /** @type {number} Most recently seen length of items. */
  13362. this.itemsLength = 0;
  13363. /**
  13364. * @type {!Function} Unwatch callback for item size (when md-items-size is
  13365. * not specified), or angular.noop otherwise.
  13366. */
  13367. this.unwatchItemSize_ = angular.noop;
  13368. /**
  13369. * Presently rendered blocks by repeat index.
  13370. * @type {Object<number, !VirtualRepeatController.Block}
  13371. */
  13372. this.blocks = {};
  13373. /** @type {Array<!VirtualRepeatController.Block>} A pool of presently unused blocks. */
  13374. this.pooledBlocks = [];
  13375. }
  13376. VirtualRepeatController.$inject = ["$scope", "$element", "$attrs", "$browser", "$document", "$$rAF"];
  13377. /**
  13378. * An object representing a repeated item.
  13379. * @typedef {{element: !jqLite, new: boolean, scope: !angular.Scope}}
  13380. */
  13381. VirtualRepeatController.Block;
  13382. /**
  13383. * Called at startup by the md-virtual-repeat postLink function.
  13384. * @param {!VirtualRepeatContainerController} container The container's controller.
  13385. * @param {!Function} transclude The repeated element's bound transclude function.
  13386. * @param {string} repeatName The left hand side of the repeat expression, indicating
  13387. * the name for each item in the array.
  13388. * @param {!Function} repeatListExpression A compiled expression based on the right hand side
  13389. * of the repeat expression. Points to the array to repeat over.
  13390. * @param {string|undefined} extraName The optional extra repeatName.
  13391. */
  13392. VirtualRepeatController.prototype.link_ =
  13393. function(container, transclude, repeatName, repeatListExpression, extraName) {
  13394. this.container = container;
  13395. this.transclude = transclude;
  13396. this.repeatName = repeatName;
  13397. this.rawRepeatListExpression = repeatListExpression;
  13398. this.extraName = extraName;
  13399. this.sized = false;
  13400. this.repeatListExpression = angular.bind(this, this.repeatListExpression_);
  13401. this.container.register(this);
  13402. };
  13403. /** @private Attempts to set itemSize by measuring a repeated element in the dom */
  13404. VirtualRepeatController.prototype.readItemSize_ = function() {
  13405. if (this.itemSize) {
  13406. // itemSize was successfully read in a different asynchronous call.
  13407. return;
  13408. }
  13409. this.items = this.repeatListExpression(this.$scope);
  13410. this.parentNode = this.$element[0].parentNode;
  13411. var block = this.getBlock_(0);
  13412. if (!block.element[0].parentNode) {
  13413. this.parentNode.appendChild(block.element[0]);
  13414. }
  13415. this.itemSize = block.element[0][
  13416. this.container.isHorizontal() ? 'offsetWidth' : 'offsetHeight'] || null;
  13417. this.blocks[0] = block;
  13418. this.poolBlock_(0);
  13419. if (this.itemSize) {
  13420. this.containerUpdated();
  13421. }
  13422. };
  13423. /**
  13424. * Returns the user-specified repeat list, transforming it into an array-like
  13425. * object in the case of infinite scroll/dynamic load mode.
  13426. * @param {!angular.Scope} The scope.
  13427. * @return {!Array|!Object} An array or array-like object for iteration.
  13428. */
  13429. VirtualRepeatController.prototype.repeatListExpression_ = function(scope) {
  13430. var repeatList = this.rawRepeatListExpression(scope);
  13431. if (this.onDemand && repeatList) {
  13432. var virtualList = new VirtualRepeatModelArrayLike(repeatList);
  13433. virtualList.$$includeIndexes(this.newStartIndex, this.newVisibleEnd);
  13434. return virtualList;
  13435. } else {
  13436. return repeatList;
  13437. }
  13438. };
  13439. /**
  13440. * Called by the container. Informs us that the containers scroll or size has
  13441. * changed.
  13442. */
  13443. VirtualRepeatController.prototype.containerUpdated = function() {
  13444. // If itemSize is unknown, attempt to measure it.
  13445. if (!this.itemSize) {
  13446. this.unwatchItemSize_ = this.$scope.$watchCollection(
  13447. this.repeatListExpression,
  13448. angular.bind(this, function(items) {
  13449. if (items && items.length) {
  13450. this.$$rAF(angular.bind(this, this.readItemSize_));
  13451. }
  13452. }));
  13453. this.$scope.$digest();
  13454. return;
  13455. } else if (!this.sized) {
  13456. this.items = this.repeatListExpression(this.$scope);
  13457. }
  13458. if (!this.sized) {
  13459. this.unwatchItemSize_();
  13460. this.sized = true;
  13461. this.$scope.$watchCollection(this.repeatListExpression,
  13462. angular.bind(this, this.virtualRepeatUpdate_));
  13463. }
  13464. this.updateIndexes_();
  13465. if (this.newStartIndex !== this.startIndex ||
  13466. this.newEndIndex !== this.endIndex ||
  13467. this.container.getScrollOffset() > this.container.getScrollSize()) {
  13468. if (this.items instanceof VirtualRepeatModelArrayLike) {
  13469. this.items.$$includeIndexes(this.newStartIndex, this.newEndIndex);
  13470. }
  13471. this.virtualRepeatUpdate_(this.items, this.items);
  13472. }
  13473. };
  13474. /**
  13475. * Called by the container. Returns the size of a single repeated item.
  13476. * @return {?number} Size of a repeated item.
  13477. */
  13478. VirtualRepeatController.prototype.getItemSize = function() {
  13479. return this.itemSize;
  13480. };
  13481. /**
  13482. * Updates the order and visible offset of repeated blocks in response to scrolling
  13483. * or items updates.
  13484. * @private
  13485. */
  13486. VirtualRepeatController.prototype.virtualRepeatUpdate_ = function(items, oldItems) {
  13487. var itemsLength = items ? items.length : 0;
  13488. var lengthChanged = false;
  13489. if (itemsLength !== this.itemsLength) {
  13490. lengthChanged = true;
  13491. this.itemsLength = itemsLength;
  13492. }
  13493. // If the number of items shrank, scroll up to the top.
  13494. if (this.items && itemsLength < this.items.length && this.container.getScrollOffset() !== 0) {
  13495. this.items = items;
  13496. this.container.resetScroll();
  13497. return;
  13498. }
  13499. this.items = items;
  13500. if (items !== oldItems || lengthChanged) {
  13501. this.updateIndexes_();
  13502. }
  13503. this.parentNode = this.$element[0].parentNode;
  13504. if (lengthChanged) {
  13505. this.container.setScrollSize(itemsLength * this.itemSize);
  13506. }
  13507. if (this.isFirstRender) {
  13508. this.isFirstRender = false;
  13509. var startIndex = this.$attrs.mdStartIndex ? this.$scope.$eval(this.$attrs.mdStartIndex) : 0;
  13510. this.container.scrollTo(startIndex * this.itemSize);
  13511. }
  13512. // Detach and pool any blocks that are no longer in the viewport.
  13513. Object.keys(this.blocks).forEach(function(blockIndex) {
  13514. var index = parseInt(blockIndex, 10);
  13515. if (index < this.newStartIndex || index >= this.newEndIndex) {
  13516. this.poolBlock_(index);
  13517. }
  13518. }, this);
  13519. // Add needed blocks.
  13520. // For performance reasons, temporarily block browser url checks as we digest
  13521. // the restored block scopes ($$checkUrlChange reads window.location to
  13522. // check for changes and trigger route change, etc, which we don't need when
  13523. // trying to scroll at 60fps).
  13524. this.$browser.$$checkUrlChange = angular.noop;
  13525. var i, block,
  13526. newStartBlocks = [],
  13527. newEndBlocks = [];
  13528. // Collect blocks at the top.
  13529. for (i = this.newStartIndex; i < this.newEndIndex && this.blocks[i] == null; i++) {
  13530. block = this.getBlock_(i);
  13531. this.updateBlock_(block, i);
  13532. newStartBlocks.push(block);
  13533. }
  13534. // Update blocks that are already rendered.
  13535. for (; this.blocks[i] != null; i++) {
  13536. this.updateBlock_(this.blocks[i], i);
  13537. }
  13538. var maxIndex = i - 1;
  13539. // Collect blocks at the end.
  13540. for (; i < this.newEndIndex; i++) {
  13541. block = this.getBlock_(i);
  13542. this.updateBlock_(block, i);
  13543. newEndBlocks.push(block);
  13544. }
  13545. // Attach collected blocks to the document.
  13546. if (newStartBlocks.length) {
  13547. this.parentNode.insertBefore(
  13548. this.domFragmentFromBlocks_(newStartBlocks),
  13549. this.$element[0].nextSibling);
  13550. }
  13551. if (newEndBlocks.length) {
  13552. this.parentNode.insertBefore(
  13553. this.domFragmentFromBlocks_(newEndBlocks),
  13554. this.blocks[maxIndex] && this.blocks[maxIndex].element[0].nextSibling);
  13555. }
  13556. // Restore $$checkUrlChange.
  13557. this.$browser.$$checkUrlChange = this.browserCheckUrlChange;
  13558. this.startIndex = this.newStartIndex;
  13559. this.endIndex = this.newEndIndex;
  13560. };
  13561. /**
  13562. * @param {number} index Where the block is to be in the repeated list.
  13563. * @return {!VirtualRepeatController.Block} A new or pooled block to place at the specified index.
  13564. * @private
  13565. */
  13566. VirtualRepeatController.prototype.getBlock_ = function(index) {
  13567. if (this.pooledBlocks.length) {
  13568. return this.pooledBlocks.pop();
  13569. }
  13570. var block;
  13571. this.transclude(angular.bind(this, function(clone, scope) {
  13572. block = {
  13573. element: clone,
  13574. new: true,
  13575. scope: scope
  13576. };
  13577. this.updateScope_(scope, index);
  13578. this.parentNode.appendChild(clone[0]);
  13579. }));
  13580. return block;
  13581. };
  13582. /**
  13583. * Updates and if not in a digest cycle, digests the specified block's scope to the data
  13584. * at the specified index.
  13585. * @param {!VirtualRepeatController.Block} block The block whose scope should be updated.
  13586. * @param {number} index The index to set.
  13587. * @private
  13588. */
  13589. VirtualRepeatController.prototype.updateBlock_ = function(block, index) {
  13590. this.blocks[index] = block;
  13591. if (!block.new &&
  13592. (block.scope.$index === index && block.scope[this.repeatName] === this.items[index])) {
  13593. return;
  13594. }
  13595. block.new = false;
  13596. // Update and digest the block's scope.
  13597. this.updateScope_(block.scope, index);
  13598. // Perform digest before reattaching the block.
  13599. // Any resulting synchronous dom mutations should be much faster as a result.
  13600. // This might break some directives, but I'm going to try it for now.
  13601. if (!this.$scope.$root.$$phase) {
  13602. block.scope.$digest();
  13603. }
  13604. };
  13605. /**
  13606. * Updates scope to the data at the specified index.
  13607. * @param {!angular.Scope} scope The scope which should be updated.
  13608. * @param {number} index The index to set.
  13609. * @private
  13610. */
  13611. VirtualRepeatController.prototype.updateScope_ = function(scope, index) {
  13612. scope.$index = index;
  13613. scope[this.repeatName] = this.items && this.items[index];
  13614. if (this.extraName) scope[this.extraName(this.$scope)] = this.items[index];
  13615. };
  13616. /**
  13617. * Pools the block at the specified index (Pulls its element out of the dom and stores it).
  13618. * @param {number} index The index at which the block to pool is stored.
  13619. * @private
  13620. */
  13621. VirtualRepeatController.prototype.poolBlock_ = function(index) {
  13622. this.pooledBlocks.push(this.blocks[index]);
  13623. this.parentNode.removeChild(this.blocks[index].element[0]);
  13624. delete this.blocks[index];
  13625. };
  13626. /**
  13627. * Produces a dom fragment containing the elements from the list of blocks.
  13628. * @param {!Array<!VirtualRepeatController.Block>} blocks The blocks whose elements
  13629. * should be added to the document fragment.
  13630. * @return {DocumentFragment}
  13631. * @private
  13632. */
  13633. VirtualRepeatController.prototype.domFragmentFromBlocks_ = function(blocks) {
  13634. var fragment = this.$document[0].createDocumentFragment();
  13635. blocks.forEach(function(block) {
  13636. fragment.appendChild(block.element[0]);
  13637. });
  13638. return fragment;
  13639. };
  13640. /**
  13641. * Updates start and end indexes based on length of repeated items and container size.
  13642. * @private
  13643. */
  13644. VirtualRepeatController.prototype.updateIndexes_ = function() {
  13645. var itemsLength = this.items ? this.items.length : 0;
  13646. var containerLength = Math.ceil(this.container.getSize() / this.itemSize);
  13647. this.newStartIndex = Math.max(0, Math.min(
  13648. itemsLength - containerLength,
  13649. Math.floor(this.container.getScrollOffset() / this.itemSize)));
  13650. this.newVisibleEnd = this.newStartIndex + containerLength + NUM_EXTRA;
  13651. this.newEndIndex = Math.min(itemsLength, this.newVisibleEnd);
  13652. this.newStartIndex = Math.max(0, this.newStartIndex - NUM_EXTRA);
  13653. };
  13654. /**
  13655. * This VirtualRepeatModelArrayLike class enforces the interface requirements
  13656. * for infinite scrolling within a mdVirtualRepeatContainer. An object with this
  13657. * interface must implement the following interface with two (2) methods:
  13658. *
  13659. * getItemAtIndex: function(index) -> item at that index or null if it is not yet
  13660. * loaded (It should start downloading the item in that case).
  13661. *
  13662. * getLength: function() -> number The data legnth to which the repeater container
  13663. * should be sized. Ideally, when the count is known, this method should return it.
  13664. * Otherwise, return a higher number than the currently loaded items to produce an
  13665. * infinite-scroll behavior.
  13666. *
  13667. * @usage
  13668. * <hljs lang="html">
  13669. * <md-virtual-repeat-container md-orient-horizontal>
  13670. * <div md-virtual-repeat="i in items" md-on-demand>
  13671. * Hello {{i}}!
  13672. * </div>
  13673. * </md-virtual-repeat-container>
  13674. * </hljs>
  13675. *
  13676. */
  13677. function VirtualRepeatModelArrayLike(model) {
  13678. if (!angular.isFunction(model.getItemAtIndex) ||
  13679. !angular.isFunction(model.getLength)) {
  13680. throw Error('When md-on-demand is enabled, the Object passed to md-virtual-repeat must implement ' +
  13681. 'functions getItemAtIndex() and getLength() ');
  13682. }
  13683. this.model = model;
  13684. }
  13685. VirtualRepeatModelArrayLike.prototype.$$includeIndexes = function(start, end) {
  13686. for (var i = start; i < end; i++) {
  13687. if (!this.hasOwnProperty(i)) {
  13688. this[i] = this.model.getItemAtIndex(i);
  13689. }
  13690. }
  13691. this.length = this.model.getLength();
  13692. };
  13693. function abstractMethod() {
  13694. throw Error('Non-overridden abstract method called.');
  13695. }
  13696. })();
  13697. (function(){
  13698. "use strict";
  13699. /**
  13700. * @ngdoc module
  13701. * @name material.components.whiteframe
  13702. */
  13703. angular.module('material.components.whiteframe', []);
  13704. })();
  13705. (function(){
  13706. "use strict";
  13707. angular
  13708. .module('material.components.autocomplete')
  13709. .controller('MdAutocompleteCtrl', MdAutocompleteCtrl);
  13710. var ITEM_HEIGHT = 41,
  13711. MAX_HEIGHT = 5.5 * ITEM_HEIGHT,
  13712. MENU_PADDING = 8;
  13713. function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming, $window,
  13714. $animate, $rootElement, $attrs, $q) {
  13715. //-- private variables
  13716. var ctrl = this,
  13717. itemParts = $scope.itemsExpr.split(/ in /i),
  13718. itemExpr = itemParts[ 1 ],
  13719. elements = null,
  13720. cache = {},
  13721. noBlur = false,
  13722. selectedItemWatchers = [],
  13723. hasFocus = false,
  13724. lastCount = 0;
  13725. //-- public variables with handlers
  13726. defineProperty('hidden', handleHiddenChange, true);
  13727. //-- public variables
  13728. ctrl.scope = $scope;
  13729. ctrl.parent = $scope.$parent;
  13730. ctrl.itemName = itemParts[ 0 ];
  13731. ctrl.matches = [];
  13732. ctrl.loading = false;
  13733. ctrl.hidden = true;
  13734. ctrl.index = null;
  13735. ctrl.messages = [];
  13736. ctrl.id = $mdUtil.nextUid();
  13737. ctrl.isDisabled = null;
  13738. ctrl.isRequired = null;
  13739. //-- public methods
  13740. ctrl.keydown = keydown;
  13741. ctrl.blur = blur;
  13742. ctrl.focus = focus;
  13743. ctrl.clear = clearValue;
  13744. ctrl.select = select;
  13745. ctrl.listEnter = onListEnter;
  13746. ctrl.listLeave = onListLeave;
  13747. ctrl.mouseUp = onMouseup;
  13748. ctrl.getCurrentDisplayValue = getCurrentDisplayValue;
  13749. ctrl.registerSelectedItemWatcher = registerSelectedItemWatcher;
  13750. ctrl.unregisterSelectedItemWatcher = unregisterSelectedItemWatcher;
  13751. ctrl.notFoundVisible = notFoundVisible;
  13752. return init();
  13753. //-- initialization methods
  13754. /**
  13755. * Initialize the controller, setup watchers, gather elements
  13756. */
  13757. function init () {
  13758. $mdUtil.initOptionalProperties($scope, $attrs, { searchText: null, selectedItem: null });
  13759. $mdTheming($element);
  13760. configureWatchers();
  13761. $mdUtil.nextTick(function () {
  13762. gatherElements();
  13763. moveDropdown();
  13764. focusElement();
  13765. $element.on('focus', focusElement);
  13766. });
  13767. }
  13768. /**
  13769. * Calculates the dropdown's position and applies the new styles to the menu element
  13770. * @returns {*}
  13771. */
  13772. function positionDropdown () {
  13773. if (!elements) return $mdUtil.nextTick(positionDropdown, false);
  13774. var hrect = elements.wrap.getBoundingClientRect(),
  13775. vrect = elements.snap.getBoundingClientRect(),
  13776. root = elements.root.getBoundingClientRect(),
  13777. top = vrect.bottom - root.top,
  13778. bot = root.bottom - vrect.top,
  13779. left = hrect.left - root.left,
  13780. width = hrect.width,
  13781. styles = {
  13782. left: left + 'px',
  13783. minWidth: width + 'px',
  13784. maxWidth: Math.max(hrect.right - root.left, root.right - hrect.left) - MENU_PADDING + 'px'
  13785. };
  13786. if (top > bot && root.height - hrect.bottom - MENU_PADDING < MAX_HEIGHT) {
  13787. styles.top = 'auto';
  13788. styles.bottom = bot + 'px';
  13789. styles.maxHeight = Math.min(MAX_HEIGHT, hrect.top - root.top - MENU_PADDING) + 'px';
  13790. } else {
  13791. styles.top = top + 'px';
  13792. styles.bottom = 'auto';
  13793. styles.maxHeight = Math.min(MAX_HEIGHT, root.bottom - hrect.bottom - MENU_PADDING) + 'px';
  13794. }
  13795. elements.$.scrollContainer.css(styles);
  13796. $mdUtil.nextTick(correctHorizontalAlignment, false);
  13797. /**
  13798. * Makes sure that the menu doesn't go off of the screen on either side.
  13799. */
  13800. function correctHorizontalAlignment () {
  13801. var dropdown = elements.scrollContainer.getBoundingClientRect(),
  13802. styles = {};
  13803. if (dropdown.right > root.right - MENU_PADDING) {
  13804. styles.left = (hrect.right - dropdown.width) + 'px';
  13805. }
  13806. elements.$.scrollContainer.css(styles);
  13807. }
  13808. }
  13809. /**
  13810. * Moves the dropdown menu to the body tag in order to avoid z-index and overflow issues.
  13811. */
  13812. function moveDropdown () {
  13813. if (!elements.$.root.length) return;
  13814. $mdTheming(elements.$.scrollContainer);
  13815. elements.$.scrollContainer.detach();
  13816. elements.$.root.append(elements.$.scrollContainer);
  13817. if ($animate.pin) $animate.pin(elements.$.scrollContainer, $rootElement);
  13818. }
  13819. /**
  13820. * Sends focus to the input element.
  13821. */
  13822. function focusElement () {
  13823. if ($scope.autofocus) elements.input.focus();
  13824. }
  13825. /**
  13826. * Sets up any watchers used by autocomplete
  13827. */
  13828. function configureWatchers () {
  13829. var wait = parseInt($scope.delay, 10) || 0;
  13830. $attrs.$observe('disabled', function (value) { ctrl.isDisabled = value; });
  13831. $attrs.$observe('required', function (value) { ctrl.isRequired = value !== null; });
  13832. $scope.$watch('searchText', wait ? $mdUtil.debounce(handleSearchText, wait) : handleSearchText);
  13833. $scope.$watch('selectedItem', selectedItemChange);
  13834. angular.element($window).on('resize', positionDropdown);
  13835. $scope.$on('$destroy', cleanup);
  13836. }
  13837. /**
  13838. * Removes any events or leftover elements created by this controller
  13839. */
  13840. function cleanup () {
  13841. angular.element($window).off('resize', positionDropdown);
  13842. elements.$.scrollContainer.remove();
  13843. }
  13844. /**
  13845. * Gathers all of the elements needed for this controller
  13846. */
  13847. function gatherElements () {
  13848. elements = {
  13849. main: $element[0],
  13850. scrollContainer: $element[0].getElementsByClassName('md-virtual-repeat-container')[0],
  13851. scroller: $element[0].getElementsByClassName('md-virtual-repeat-scroller')[0],
  13852. ul: $element.find('ul')[0],
  13853. input: $element.find('input')[0],
  13854. wrap: $element.find('md-autocomplete-wrap')[0],
  13855. root: document.body
  13856. };
  13857. elements.li = elements.ul.getElementsByTagName('li');
  13858. elements.snap = getSnapTarget();
  13859. elements.$ = getAngularElements(elements);
  13860. }
  13861. /**
  13862. * Finds the element that the menu will base its position on
  13863. * @returns {*}
  13864. */
  13865. function getSnapTarget () {
  13866. for (var element = $element; element.length; element = element.parent()) {
  13867. if (angular.isDefined(element.attr('md-autocomplete-snap'))) return element[ 0 ];
  13868. }
  13869. return elements.wrap;
  13870. }
  13871. /**
  13872. * Gathers angular-wrapped versions of each element
  13873. * @param elements
  13874. * @returns {{}}
  13875. */
  13876. function getAngularElements (elements) {
  13877. var obj = {};
  13878. for (var key in elements) {
  13879. if (elements.hasOwnProperty(key)) obj[ key ] = angular.element(elements[ key ]);
  13880. }
  13881. return obj;
  13882. }
  13883. //-- event/change handlers
  13884. /**
  13885. * Handles changes to the `hidden` property.
  13886. * @param hidden
  13887. * @param oldHidden
  13888. */
  13889. function handleHiddenChange (hidden, oldHidden) {
  13890. if (!hidden && oldHidden) {
  13891. positionDropdown();
  13892. if (elements) $mdUtil.nextTick(function () { $mdUtil.disableScrollAround(elements.ul); }, false);
  13893. } else if (hidden && !oldHidden) {
  13894. $mdUtil.nextTick(function () { $mdUtil.enableScrolling(); }, false);
  13895. }
  13896. }
  13897. /**
  13898. * When the user mouses over the dropdown menu, ignore blur events.
  13899. */
  13900. function onListEnter () {
  13901. noBlur = true;
  13902. }
  13903. /**
  13904. * When the user's mouse leaves the menu, blur events may hide the menu again.
  13905. */
  13906. function onListLeave () {
  13907. noBlur = false;
  13908. if (!hasFocus) ctrl.hidden = true;
  13909. }
  13910. /**
  13911. * When the mouse button is released, send focus back to the input field.
  13912. */
  13913. function onMouseup () {
  13914. elements.input.focus();
  13915. }
  13916. /**
  13917. * Handles changes to the selected item.
  13918. * @param selectedItem
  13919. * @param previousSelectedItem
  13920. */
  13921. function selectedItemChange (selectedItem, previousSelectedItem) {
  13922. if (selectedItem) {
  13923. getDisplayValue(selectedItem).then(function (val) {
  13924. $scope.searchText = val;
  13925. handleSelectedItemChange(selectedItem, previousSelectedItem);
  13926. });
  13927. }
  13928. if (selectedItem !== previousSelectedItem) announceItemChange();
  13929. }
  13930. /**
  13931. * Use the user-defined expression to announce changes each time a new item is selected
  13932. */
  13933. function announceItemChange () {
  13934. angular.isFunction($scope.itemChange) && $scope.itemChange(getItemAsNameVal($scope.selectedItem));
  13935. }
  13936. /**
  13937. * Use the user-defined expression to announce changes each time the search text is changed
  13938. */
  13939. function announceTextChange () {
  13940. angular.isFunction($scope.textChange) && $scope.textChange();
  13941. }
  13942. /**
  13943. * Calls any external watchers listening for the selected item. Used in conjunction with
  13944. * `registerSelectedItemWatcher`.
  13945. * @param selectedItem
  13946. * @param previousSelectedItem
  13947. */
  13948. function handleSelectedItemChange (selectedItem, previousSelectedItem) {
  13949. selectedItemWatchers.forEach(function (watcher) { watcher(selectedItem, previousSelectedItem); });
  13950. }
  13951. /**
  13952. * Register a function to be called when the selected item changes.
  13953. * @param cb
  13954. */
  13955. function registerSelectedItemWatcher (cb) {
  13956. if (selectedItemWatchers.indexOf(cb) == -1) {
  13957. selectedItemWatchers.push(cb);
  13958. }
  13959. }
  13960. /**
  13961. * Unregister a function previously registered for selected item changes.
  13962. * @param cb
  13963. */
  13964. function unregisterSelectedItemWatcher (cb) {
  13965. var i = selectedItemWatchers.indexOf(cb);
  13966. if (i != -1) {
  13967. selectedItemWatchers.splice(i, 1);
  13968. }
  13969. }
  13970. /**
  13971. * Handles changes to the searchText property.
  13972. * @param searchText
  13973. * @param previousSearchText
  13974. */
  13975. function handleSearchText (searchText, previousSearchText) {
  13976. ctrl.index = getDefaultIndex();
  13977. // do nothing on init
  13978. if (searchText === previousSearchText) return;
  13979. getDisplayValue($scope.selectedItem).then(function (val) {
  13980. // clear selected item if search text no longer matches it
  13981. if (searchText !== val) {
  13982. $scope.selectedItem = null;
  13983. // trigger change event if available
  13984. if (searchText !== previousSearchText) announceTextChange();
  13985. // cancel results if search text is not long enough
  13986. if (!isMinLengthMet()) {
  13987. ctrl.loading = false;
  13988. ctrl.matches = [];
  13989. ctrl.hidden = shouldHide();
  13990. updateMessages();
  13991. } else {
  13992. handleQuery();
  13993. }
  13994. }
  13995. });
  13996. }
  13997. /**
  13998. * Handles input blur event, determines if the dropdown should hide.
  13999. */
  14000. function blur () {
  14001. hasFocus = false;
  14002. if (!noBlur) ctrl.hidden = true;
  14003. }
  14004. /**
  14005. * Handles input focus event, determines if the dropdown should show.
  14006. */
  14007. function focus () {
  14008. hasFocus = true;
  14009. //-- if searchText is null, let's force it to be a string
  14010. if (!angular.isString($scope.searchText)) $scope.searchText = '';
  14011. if ($scope.minLength > 0) return;
  14012. ctrl.hidden = shouldHide();
  14013. if (!ctrl.hidden) handleQuery();
  14014. }
  14015. /**
  14016. * Handles keyboard input.
  14017. * @param event
  14018. */
  14019. function keydown (event) {
  14020. switch (event.keyCode) {
  14021. case $mdConstant.KEY_CODE.DOWN_ARROW:
  14022. if (ctrl.loading) return;
  14023. event.stopPropagation();
  14024. event.preventDefault();
  14025. ctrl.index = Math.min(ctrl.index + 1, ctrl.matches.length - 1);
  14026. updateScroll();
  14027. updateMessages();
  14028. break;
  14029. case $mdConstant.KEY_CODE.UP_ARROW:
  14030. if (ctrl.loading) return;
  14031. event.stopPropagation();
  14032. event.preventDefault();
  14033. ctrl.index = ctrl.index < 0 ? ctrl.matches.length - 1 : Math.max(0, ctrl.index - 1);
  14034. updateScroll();
  14035. updateMessages();
  14036. break;
  14037. case $mdConstant.KEY_CODE.TAB:
  14038. case $mdConstant.KEY_CODE.ENTER:
  14039. if (ctrl.hidden || ctrl.loading || ctrl.index < 0 || ctrl.matches.length < 1) return;
  14040. event.stopPropagation();
  14041. event.preventDefault();
  14042. select(ctrl.index);
  14043. break;
  14044. case $mdConstant.KEY_CODE.ESCAPE:
  14045. event.stopPropagation();
  14046. event.preventDefault();
  14047. clearValue();
  14048. ctrl.matches = [];
  14049. ctrl.hidden = true;
  14050. ctrl.index = getDefaultIndex();
  14051. break;
  14052. default:
  14053. }
  14054. }
  14055. //-- getters
  14056. /**
  14057. * Returns the minimum length needed to display the dropdown.
  14058. * @returns {*}
  14059. */
  14060. function getMinLength () {
  14061. return angular.isNumber($scope.minLength) ? $scope.minLength : 1;
  14062. }
  14063. /**
  14064. * Returns the display value for an item.
  14065. * @param item
  14066. * @returns {*}
  14067. */
  14068. function getDisplayValue (item) {
  14069. return $q.when(getItemText(item) || item);
  14070. /**
  14071. * Getter function to invoke user-defined expression (in the directive)
  14072. * to convert your object to a single string.
  14073. */
  14074. function getItemText (item) {
  14075. return (item && $scope.itemText) ? $scope.itemText(getItemAsNameVal(item)) : null;
  14076. }
  14077. }
  14078. /**
  14079. * Returns the locals object for compiling item templates.
  14080. * @param item
  14081. * @returns {{}}
  14082. */
  14083. function getItemAsNameVal (item) {
  14084. if (!item) return undefined;
  14085. var locals = {};
  14086. if (ctrl.itemName) locals[ ctrl.itemName ] = item;
  14087. return locals;
  14088. }
  14089. /**
  14090. * Returns the default index based on whether or not autoselect is enabled.
  14091. * @returns {number}
  14092. */
  14093. function getDefaultIndex () {
  14094. return $scope.autoselect ? 0 : -1;
  14095. }
  14096. /**
  14097. * Determines if the menu should be hidden.
  14098. * @returns {boolean}
  14099. */
  14100. function shouldHide () {
  14101. if (!isMinLengthMet() || !ctrl.matches.length) return true;
  14102. }
  14103. /**
  14104. * Returns the display value of the current item.
  14105. * @returns {*}
  14106. */
  14107. function getCurrentDisplayValue () {
  14108. return getDisplayValue(ctrl.matches[ ctrl.index ]);
  14109. }
  14110. /**
  14111. * Determines if the minimum length is met by the search text.
  14112. * @returns {*}
  14113. */
  14114. function isMinLengthMet () {
  14115. return angular.isDefined($scope.searchText) && $scope.searchText.length >= getMinLength();
  14116. }
  14117. //-- actions
  14118. /**
  14119. * Defines a public property with a handler and a default value.
  14120. * @param key
  14121. * @param handler
  14122. * @param value
  14123. */
  14124. function defineProperty (key, handler, value) {
  14125. Object.defineProperty(ctrl, key, {
  14126. get: function () { return value; },
  14127. set: function (newValue) {
  14128. var oldValue = value;
  14129. value = newValue;
  14130. handler(newValue, oldValue);
  14131. }
  14132. });
  14133. }
  14134. /**
  14135. * Selects the item at the given index.
  14136. * @param index
  14137. */
  14138. function select (index) {
  14139. //-- force form to update state for validation
  14140. $mdUtil.nextTick(function () {
  14141. getDisplayValue(ctrl.matches[ index ]).then(function (val) {
  14142. var ngModel = elements.$.input.controller('ngModel');
  14143. ngModel.$setViewValue(val);
  14144. ngModel.$render();
  14145. }).finally(function () {
  14146. $scope.selectedItem = ctrl.matches[ index ];
  14147. ctrl.loading = false;
  14148. ctrl.hidden = true;
  14149. ctrl.index = 0;
  14150. ctrl.matches = [];
  14151. });
  14152. }, false);
  14153. }
  14154. /**
  14155. * Clears the searchText value and selected item.
  14156. */
  14157. function clearValue () {
  14158. $scope.searchText = '';
  14159. select(-1);
  14160. // Per http://www.w3schools.com/jsref/event_oninput.asp
  14161. var eventObj = document.createEvent('CustomEvent');
  14162. eventObj.initCustomEvent('input', true, true, { value: $scope.searchText });
  14163. elements.input.dispatchEvent(eventObj);
  14164. elements.input.focus();
  14165. }
  14166. /**
  14167. * Fetches the results for the provided search text.
  14168. * @param searchText
  14169. */
  14170. function fetchResults (searchText) {
  14171. var items = $scope.$parent.$eval(itemExpr),
  14172. term = searchText.toLowerCase();
  14173. if (angular.isArray(items)) {
  14174. handleResults(items);
  14175. } else if (items) {
  14176. $mdUtil.nextTick(function () {
  14177. ctrl.loading = true;
  14178. if (items.success) items.success(handleResults);
  14179. if (items.then) items.then(handleResults);
  14180. if (items.finally) items.finally(function () { ctrl.loading = false; });
  14181. });
  14182. }
  14183. function handleResults (matches) {
  14184. cache[ term ] = matches;
  14185. if (searchText !== $scope.searchText) return; //-- just cache the results if old request
  14186. ctrl.matches = matches;
  14187. ctrl.hidden = shouldHide();
  14188. if ($scope.selectOnMatch) selectItemOnMatch();
  14189. updateMessages();
  14190. positionDropdown();
  14191. }
  14192. }
  14193. /**
  14194. * Updates the ARIA messages
  14195. */
  14196. function updateMessages () {
  14197. getCurrentDisplayValue().then(function (msg) {
  14198. ctrl.messages = [ getCountMessage(), msg ];
  14199. });
  14200. }
  14201. /**
  14202. * Returns the ARIA message for how many results match the current query.
  14203. * @returns {*}
  14204. */
  14205. function getCountMessage () {
  14206. if (lastCount === ctrl.matches.length) return '';
  14207. lastCount = ctrl.matches.length;
  14208. switch (ctrl.matches.length) {
  14209. case 0:
  14210. return 'There are no matches available.';
  14211. case 1:
  14212. return 'There is 1 match available.';
  14213. default:
  14214. return 'There are ' + ctrl.matches.length + ' matches available.';
  14215. }
  14216. }
  14217. /**
  14218. * Makes sure that the focused element is within view.
  14219. */
  14220. function updateScroll () {
  14221. if (!elements.li[0]) return;
  14222. var height = elements.li[0].offsetHeight,
  14223. top = height * ctrl.index,
  14224. bot = top + height,
  14225. hgt = elements.scroller.clientHeight,
  14226. scrollTop = elements.scroller.scrollTop;
  14227. if (top < scrollTop) {
  14228. scrollTo(top);
  14229. } else if (bot > scrollTop + hgt) {
  14230. scrollTo(bot - hgt);
  14231. }
  14232. }
  14233. function scrollTo (offset) {
  14234. elements.$.scrollContainer.controller('mdVirtualRepeatContainer').scrollTo(offset);
  14235. }
  14236. function notFoundVisible () {
  14237. return !ctrl.matches.length && !ctrl.loading && ctrl.scope.searchText && hasFocus && !ctrl.scope.selectedItem;
  14238. }
  14239. /**
  14240. * Starts the query to gather the results for the current searchText. Attempts to return cached
  14241. * results first, then forwards the process to `fetchResults` if necessary.
  14242. */
  14243. function handleQuery () {
  14244. var searchText = $scope.searchText,
  14245. term = searchText.toLowerCase();
  14246. //-- if results are cached, pull in cached results
  14247. if (!$scope.noCache && cache[ term ]) {
  14248. ctrl.matches = cache[ term ];
  14249. updateMessages();
  14250. } else {
  14251. fetchResults(searchText);
  14252. }
  14253. if (hasFocus) ctrl.hidden = shouldHide();
  14254. }
  14255. /**
  14256. * If there is only one matching item and the search text matches its display value exactly,
  14257. * automatically select that item. Note: This function is only called if the user uses the
  14258. * `md-select-on-match` flag.
  14259. */
  14260. function selectItemOnMatch () {
  14261. var searchText = $scope.searchText,
  14262. matches = ctrl.matches,
  14263. item = matches[ 0 ];
  14264. if (matches.length === 1) getDisplayValue(item).then(function (displayValue) {
  14265. if (searchText == displayValue) select(0);
  14266. });
  14267. }
  14268. }
  14269. MdAutocompleteCtrl.$inject = ["$scope", "$element", "$mdUtil", "$mdConstant", "$mdTheming", "$window", "$animate", "$rootElement", "$attrs", "$q"];
  14270. })();
  14271. (function(){
  14272. "use strict";
  14273. angular
  14274. .module('material.components.autocomplete')
  14275. .directive('mdAutocomplete', MdAutocomplete);
  14276. /**
  14277. * @ngdoc directive
  14278. * @name mdAutocomplete
  14279. * @module material.components.autocomplete
  14280. *
  14281. * @description
  14282. * `<md-autocomplete>` is a special input component with a drop-down of all possible matches to a
  14283. * custom query. This component allows you to provide real-time suggestions as the user types
  14284. * in the input area.
  14285. *
  14286. * To start, you will need to specify the required parameters and provide a template for your
  14287. * results. The content inside `md-autocomplete` will be treated as a template.
  14288. *
  14289. * In more complex cases, you may want to include other content such as a message to display when
  14290. * no matches were found. You can do this by wrapping your template in `md-item-template` and
  14291. * adding a tag for `md-not-found`. An example of this is shown below.
  14292. *
  14293. * ### Validation
  14294. *
  14295. * You can use `ng-messages` to include validation the same way that you would normally validate;
  14296. * however, if you want to replicate a standard input with a floating label, you will have to
  14297. * do the following:
  14298. *
  14299. * - Make sure that your template is wrapped in `md-item-template`
  14300. * - Add your `ng-messages` code inside of `md-autocomplete`
  14301. * - Add your validation properties to `md-autocomplete` (ie. `required`)
  14302. * - Add a `name` to `md-autocomplete` (to be used on the generated `input`)
  14303. *
  14304. * There is an example below of how this should look.
  14305. *
  14306. *
  14307. * @param {expression} md-items An expression in the format of `item in items` to iterate over
  14308. * matches for your search.
  14309. * @param {expression=} md-selected-item-change An expression to be run each time a new item is
  14310. * selected
  14311. * @param {expression=} md-search-text-change An expression to be run each time the search text
  14312. * updates
  14313. * @param {string=} md-search-text A model to bind the search query text to
  14314. * @param {object=} md-selected-item A model to bind the selected item to
  14315. * @param {string=} md-item-text An expression that will convert your object to a single string.
  14316. * @param {string=} placeholder Placeholder text that will be forwarded to the input.
  14317. * @param {boolean=} md-no-cache Disables the internal caching that happens in autocomplete
  14318. * @param {boolean=} ng-disabled Determines whether or not to disable the input field
  14319. * @param {number=} md-min-length Specifies the minimum length of text before autocomplete will
  14320. * make suggestions
  14321. * @param {number=} md-delay Specifies the amount of time (in milliseconds) to wait before looking
  14322. * for results
  14323. * @param {boolean=} md-autofocus If true, will immediately focus the input element
  14324. * @param {boolean=} md-autoselect If true, the first item will be selected by default
  14325. * @param {string=} md-menu-class This will be applied to the dropdown menu for styling
  14326. * @param {string=} md-floating-label This will add a floating label to autocomplete and wrap it in
  14327. * `md-input-container`
  14328. * @param {string=} md-input-name The name attribute given to the input element to be used with
  14329. * FormController
  14330. * @param {string=} md-input-id An ID to be added to the input element
  14331. * @param {number=} md-input-minlength The minimum length for the input's value for validation
  14332. * @param {number=} md-input-maxlength The maximum length for the input's value for validation
  14333. * @param {boolean=} md-select-on-match When set, autocomplete will automatically select exact
  14334. * the item if the search text is an exact match
  14335. *
  14336. * @usage
  14337. * ###Basic Example
  14338. * <hljs lang="html">
  14339. * <md-autocomplete
  14340. * md-selected-item="selectedItem"
  14341. * md-search-text="searchText"
  14342. * md-items="item in getMatches(searchText)"
  14343. * md-item-text="item.display">
  14344. * <span md-highlight-text="searchText">{{item.display}}</span>
  14345. * </md-autocomplete>
  14346. * </hljs>
  14347. *
  14348. * ###Example with "not found" message
  14349. * <hljs lang="html">
  14350. * <md-autocomplete
  14351. * md-selected-item="selectedItem"
  14352. * md-search-text="searchText"
  14353. * md-items="item in getMatches(searchText)"
  14354. * md-item-text="item.display">
  14355. * <md-item-template>
  14356. * <span md-highlight-text="searchText">{{item.display}}</span>
  14357. * </md-item-template>
  14358. * <md-not-found>
  14359. * No matches found.
  14360. * </md-not-found>
  14361. * </md-autocomplete>
  14362. * </hljs>
  14363. *
  14364. * In this example, our code utilizes `md-item-template` and `md-not-found` to specify the
  14365. * different parts that make up our component.
  14366. *
  14367. * ### Example with validation
  14368. * <hljs lang="html">
  14369. * <form name="autocompleteForm">
  14370. * <md-autocomplete
  14371. * required
  14372. * md-input-name="autocomplete"
  14373. * md-selected-item="selectedItem"
  14374. * md-search-text="searchText"
  14375. * md-items="item in getMatches(searchText)"
  14376. * md-item-text="item.display">
  14377. * <md-item-template>
  14378. * <span md-highlight-text="searchText">{{item.display}}</span>
  14379. * </md-item-template>
  14380. * <div ng-messages="autocompleteForm.autocomplete.$error">
  14381. * <div ng-message="required">This field is required</div>
  14382. * </div>
  14383. * </md-autocomplete>
  14384. * </form>
  14385. * </hljs>
  14386. *
  14387. * In this example, our code utilizes `md-item-template` and `md-not-found` to specify the
  14388. * different parts that make up our component.
  14389. */
  14390. function MdAutocomplete () {
  14391. return {
  14392. controller: 'MdAutocompleteCtrl',
  14393. controllerAs: '$mdAutocompleteCtrl',
  14394. scope: {
  14395. inputName: '@mdInputName',
  14396. inputMinlength: '@mdInputMinlength',
  14397. inputMaxlength: '@mdInputMaxlength',
  14398. searchText: '=?mdSearchText',
  14399. selectedItem: '=?mdSelectedItem',
  14400. itemsExpr: '@mdItems',
  14401. itemText: '&mdItemText',
  14402. placeholder: '@placeholder',
  14403. noCache: '=?mdNoCache',
  14404. selectOnMatch: '=?mdSelectOnMatch',
  14405. itemChange: '&?mdSelectedItemChange',
  14406. textChange: '&?mdSearchTextChange',
  14407. minLength: '=?mdMinLength',
  14408. delay: '=?mdDelay',
  14409. autofocus: '=?mdAutofocus',
  14410. floatingLabel: '@?mdFloatingLabel',
  14411. autoselect: '=?mdAutoselect',
  14412. menuClass: '@?mdMenuClass',
  14413. inputId: '@?mdInputId'
  14414. },
  14415. template: function (element, attr) {
  14416. var noItemsTemplate = getNoItemsTemplate(),
  14417. itemTemplate = getItemTemplate(),
  14418. leftover = element.html();
  14419. return '\
  14420. <md-autocomplete-wrap\
  14421. layout="row"\
  14422. ng-class="{ \'md-whiteframe-z1\': !floatingLabel, \'md-menu-showing\': !$mdAutocompleteCtrl.hidden }"\
  14423. role="listbox">\
  14424. ' + getInputElement() + '\
  14425. <md-progress-linear\
  14426. ng-if="$mdAutocompleteCtrl.loading && !$mdAutocompleteCtrl.hidden"\
  14427. md-mode="indeterminate"></md-progress-linear>\
  14428. <md-virtual-repeat-container\
  14429. md-auto-shrink\
  14430. md-auto-shrink-min="1"\
  14431. ng-hide="$mdAutocompleteCtrl.hidden && !$mdAutocompleteCtrl.notFoundVisible()"\
  14432. class="md-autocomplete-suggestions-container md-whiteframe-z1"\
  14433. role="presentation">\
  14434. <ul class="md-autocomplete-suggestions"\
  14435. ng-class="::menuClass"\
  14436. id="ul-{{$mdAutocompleteCtrl.id}}"\
  14437. ng-mouseenter="$mdAutocompleteCtrl.listEnter()"\
  14438. ng-mouseleave="$mdAutocompleteCtrl.listLeave()"\
  14439. ng-mouseup="$mdAutocompleteCtrl.mouseUp()">\
  14440. <li md-virtual-repeat="item in $mdAutocompleteCtrl.matches"\
  14441. ng-class="{ selected: $index === $mdAutocompleteCtrl.index }"\
  14442. ng-click="$mdAutocompleteCtrl.select($index)"\
  14443. md-extra-name="$mdAutocompleteCtrl.itemName">\
  14444. ' + itemTemplate + '\
  14445. </li>' + noItemsTemplate + '\
  14446. </ul>\
  14447. </md-virtual-repeat-container>\
  14448. </md-autocomplete-wrap>\
  14449. <aria-status\
  14450. class="md-visually-hidden"\
  14451. role="status"\
  14452. aria-live="assertive">\
  14453. <p ng-repeat="message in $mdAutocompleteCtrl.messages track by $index" ng-if="message">{{message}}</p>\
  14454. </aria-status>';
  14455. function getItemTemplate() {
  14456. var templateTag = element.find('md-item-template').detach(),
  14457. html = templateTag.length ? templateTag.html() : element.html();
  14458. if (!templateTag.length) element.empty();
  14459. return html;
  14460. }
  14461. function getNoItemsTemplate() {
  14462. var templateTag = element.find('md-not-found').detach(),
  14463. template = templateTag.length ? templateTag.html() : '';
  14464. return template
  14465. ? '<li ng-if="$mdAutocompleteCtrl.notFoundVisible()"\
  14466. md-autocomplete-parent-scope>' + template + '</li>'
  14467. : '';
  14468. }
  14469. function getInputElement () {
  14470. if (attr.mdFloatingLabel) {
  14471. return '\
  14472. <md-input-container flex ng-if="floatingLabel">\
  14473. <label>{{floatingLabel}}</label>\
  14474. <input type="search"\
  14475. id="{{ inputId || \'fl-input-\' + $mdAutocompleteCtrl.id }}"\
  14476. name="{{inputName}}"\
  14477. autocomplete="off"\
  14478. ng-required="$mdAutocompleteCtrl.isRequired"\
  14479. ng-minlength="inputMinlength"\
  14480. ng-maxlength="inputMaxlength"\
  14481. ng-disabled="$mdAutocompleteCtrl.isDisabled"\
  14482. ng-model="$mdAutocompleteCtrl.scope.searchText"\
  14483. ng-keydown="$mdAutocompleteCtrl.keydown($event)"\
  14484. ng-blur="$mdAutocompleteCtrl.blur()"\
  14485. ng-focus="$mdAutocompleteCtrl.focus()"\
  14486. aria-owns="ul-{{$mdAutocompleteCtrl.id}}"\
  14487. aria-label="{{floatingLabel}}"\
  14488. aria-autocomplete="list"\
  14489. aria-haspopup="true"\
  14490. aria-activedescendant=""\
  14491. aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\
  14492. <div md-autocomplete-parent-scope md-autocomplete-replace>' + leftover + '</div>\
  14493. </md-input-container>';
  14494. } else {
  14495. return '\
  14496. <input flex type="search"\
  14497. id="{{ inputId || \'input-\' + $mdAutocompleteCtrl.id }}"\
  14498. name="{{inputName}}"\
  14499. ng-if="!floatingLabel"\
  14500. autocomplete="off"\
  14501. ng-required="$mdAutocompleteCtrl.isRequired"\
  14502. ng-disabled="$mdAutocompleteCtrl.isDisabled"\
  14503. ng-model="$mdAutocompleteCtrl.scope.searchText"\
  14504. ng-keydown="$mdAutocompleteCtrl.keydown($event)"\
  14505. ng-blur="$mdAutocompleteCtrl.blur()"\
  14506. ng-focus="$mdAutocompleteCtrl.focus()"\
  14507. placeholder="{{placeholder}}"\
  14508. aria-owns="ul-{{$mdAutocompleteCtrl.id}}"\
  14509. aria-label="{{placeholder}}"\
  14510. aria-autocomplete="list"\
  14511. aria-haspopup="true"\
  14512. aria-activedescendant=""\
  14513. aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\
  14514. <button\
  14515. type="button"\
  14516. tabindex="-1"\
  14517. ng-if="$mdAutocompleteCtrl.scope.searchText && !$mdAutocompleteCtrl.isDisabled"\
  14518. ng-click="$mdAutocompleteCtrl.clear()">\
  14519. <md-icon md-svg-icon="md-close"></md-icon>\
  14520. <span class="md-visually-hidden">Clear</span>\
  14521. </button>\
  14522. ';
  14523. }
  14524. }
  14525. }
  14526. };
  14527. }
  14528. })();
  14529. (function(){
  14530. "use strict";
  14531. angular
  14532. .module('material.components.autocomplete')
  14533. .controller('MdHighlightCtrl', MdHighlightCtrl);
  14534. function MdHighlightCtrl ($scope, $element, $attrs) {
  14535. this.init = init;
  14536. function init (termExpr, unsafeTextExpr) {
  14537. var text = null,
  14538. regex = null,
  14539. flags = $attrs.mdHighlightFlags || '',
  14540. watcher = $scope.$watch(function($scope) {
  14541. return {
  14542. term: termExpr($scope),
  14543. unsafeText: unsafeTextExpr($scope)
  14544. };
  14545. }, function (state, prevState) {
  14546. if (text === null || state.unsafeText !== prevState.unsafeText) {
  14547. text = angular.element('<div>').text(state.unsafeText).html()
  14548. }
  14549. if (regex === null || state.term !== prevState.term) {
  14550. regex = getRegExp(state.term, flags);
  14551. }
  14552. $element.html(text.replace(regex, '<span class="highlight">$&</span>'));
  14553. }, true);
  14554. $element.on('$destroy', function () { watcher(); });
  14555. }
  14556. function sanitize (term) {
  14557. return term && term.replace(/[\\\^\$\*\+\?\.\(\)\|\{}\[\]]/g, '\\$&');
  14558. }
  14559. function getRegExp (text, flags) {
  14560. var str = '';
  14561. if (flags.indexOf('^') >= 1) str += '^';
  14562. str += text;
  14563. if (flags.indexOf('$') >= 1) str += '$';
  14564. return new RegExp(sanitize(str), flags.replace(/[\$\^]/g, ''));
  14565. }
  14566. }
  14567. MdHighlightCtrl.$inject = ["$scope", "$element", "$attrs"];
  14568. })();
  14569. (function(){
  14570. "use strict";
  14571. angular
  14572. .module('material.components.autocomplete')
  14573. .directive('mdHighlightText', MdHighlight);
  14574. /**
  14575. * @ngdoc directive
  14576. * @name mdHighlightText
  14577. * @module material.components.autocomplete
  14578. *
  14579. * @description
  14580. * The `md-highlight-text` directive allows you to specify text that should be highlighted within
  14581. * an element. Highlighted text will be wrapped in `<span class="highlight"></span>` which can
  14582. * be styled through CSS. Please note that child elements may not be used with this directive.
  14583. *
  14584. * @param {string} md-highlight-text A model to be searched for
  14585. * @param {string=} md-highlight-flags A list of flags (loosely based on JavaScript RexExp flags).
  14586. * #### **Supported flags**:
  14587. * - `g`: Find all matches within the provided text
  14588. * - `i`: Ignore case when searching for matches
  14589. * - `$`: Only match if the text ends with the search term
  14590. * - `^`: Only match if the text begins with the search term
  14591. *
  14592. * @usage
  14593. * <hljs lang="html">
  14594. * <input placeholder="Enter a search term..." ng-model="searchTerm" type="text" />
  14595. * <ul>
  14596. * <li ng-repeat="result in results" md-highlight-text="searchTerm">
  14597. * {{result.text}}
  14598. * </li>
  14599. * </ul>
  14600. * </hljs>
  14601. */
  14602. function MdHighlight ($interpolate, $parse) {
  14603. return {
  14604. terminal: true,
  14605. controller: 'MdHighlightCtrl',
  14606. compile: function mdHighlightCompile(tElement, tAttr) {
  14607. var termExpr = $parse(tAttr.mdHighlightText);
  14608. var unsafeTextExpr = $interpolate(tElement.html());
  14609. return function mdHighlightLink(scope, element, attr, ctrl) {
  14610. ctrl.init(termExpr, unsafeTextExpr);
  14611. };
  14612. }
  14613. };
  14614. }
  14615. MdHighlight.$inject = ["$interpolate", "$parse"];
  14616. })();
  14617. (function(){
  14618. "use strict";
  14619. angular
  14620. .module('material.components.autocomplete')
  14621. .directive('mdAutocompleteParentScope', MdAutocompleteParentScope);
  14622. function MdAutocompleteParentScope ($compile) {
  14623. return {
  14624. restrict: 'A',
  14625. terminal: true,
  14626. link: postLink,
  14627. scope: false
  14628. };
  14629. function postLink (scope, element, attr) {
  14630. var ctrl = scope.$parent.$mdAutocompleteCtrl;
  14631. // TODO: transclude self might make it possible to do this without
  14632. // re-compiling, which is slow.
  14633. $compile(element.contents())(ctrl.parent);
  14634. if (attr.hasOwnProperty('mdAutocompleteReplace')) {
  14635. element.after(element.contents());
  14636. element.remove();
  14637. }
  14638. }
  14639. }
  14640. MdAutocompleteParentScope.$inject = ["$compile"];
  14641. })();
  14642. (function(){
  14643. "use strict";
  14644. angular
  14645. .module('material.components.chips')
  14646. .directive('mdChip', MdChip);
  14647. /**
  14648. * @ngdoc directive
  14649. * @name mdChip
  14650. * @module material.components.chips
  14651. *
  14652. * @description
  14653. * `<md-chip>` is a component used within `<md-chips>` and is responsible for rendering individual
  14654. * chips.
  14655. *
  14656. *
  14657. * @usage
  14658. * <hljs lang="html">
  14659. * <md-chip>{{$chip}}</md-chip>
  14660. * </hljs>
  14661. *
  14662. */
  14663. // This hint text is hidden within a chip but used by screen readers to
  14664. // inform the user how they can interact with a chip.
  14665. var DELETE_HINT_TEMPLATE = '\
  14666. <span ng-if="!$mdChipsCtrl.readonly" class="md-visually-hidden">\
  14667. {{$mdChipsCtrl.deleteHint}}\
  14668. </span>';
  14669. /**
  14670. * MDChip Directive Definition
  14671. *
  14672. * @param $mdTheming
  14673. * @param $mdInkRipple
  14674. * @ngInject
  14675. */
  14676. function MdChip($mdTheming, $mdUtil) {
  14677. convertTemplates();
  14678. return {
  14679. restrict: 'E',
  14680. require: '^?mdChips',
  14681. compile: compile
  14682. };
  14683. function compile(element, attr) {
  14684. // Append the delete template
  14685. element.append($mdUtil.processTemplate(DELETE_HINT_TEMPLATE));
  14686. return function postLink(scope, element, attr, ctrl) {
  14687. element.addClass('md-chip');
  14688. $mdTheming(element);
  14689. if (ctrl) angular.element(element[0].querySelector('.md-chip-content'))
  14690. .on('blur', function () {
  14691. ctrl.selectedChip = -1;
  14692. });
  14693. };
  14694. }
  14695. function convertTemplates() {
  14696. DELETE_HINT_TEMPLATE = $mdUtil.processTemplate(DELETE_HINT_TEMPLATE);
  14697. }
  14698. }
  14699. MdChip.$inject = ["$mdTheming", "$mdUtil"];
  14700. })();
  14701. (function(){
  14702. "use strict";
  14703. angular
  14704. .module('material.components.chips')
  14705. .directive('mdChipRemove', MdChipRemove);
  14706. /**
  14707. * @ngdoc directive
  14708. * @name mdChipRemove
  14709. * @module material.components.chips
  14710. *
  14711. * @description
  14712. * `<md-chip-remove>`
  14713. * Designates an element to be used as the delete button for a chip. This
  14714. * element is passed as a child of the `md-chips` element.
  14715. *
  14716. * @usage
  14717. * <hljs lang="html">
  14718. * <md-chips><button md-chip-remove>DEL</button></md-chips>
  14719. * </hljs>
  14720. */
  14721. /**
  14722. * MdChipRemove Directive Definition.
  14723. *
  14724. * @param $compile
  14725. * @param $timeout
  14726. * @returns {{restrict: string, require: string[], link: Function, scope: boolean}}
  14727. * @constructor
  14728. */
  14729. function MdChipRemove ($timeout) {
  14730. return {
  14731. restrict: 'A',
  14732. require: '^mdChips',
  14733. scope: false,
  14734. link: postLink
  14735. };
  14736. function postLink(scope, element, attr, ctrl) {
  14737. element.on('click', function(event) {
  14738. scope.$apply(function() {
  14739. ctrl.removeChip(scope.$$replacedScope.$index);
  14740. });
  14741. });
  14742. // Child elements aren't available until after a $timeout tick as they are hidden by an
  14743. // `ng-if`. see http://goo.gl/zIWfuw
  14744. $timeout(function() {
  14745. element.attr({ tabindex: -1, ariaHidden: true });
  14746. element.find('button').attr('tabindex', '-1');
  14747. });
  14748. }
  14749. }
  14750. MdChipRemove.$inject = ["$timeout"];
  14751. })();
  14752. (function(){
  14753. "use strict";
  14754. angular
  14755. .module('material.components.chips')
  14756. .directive('mdChipTransclude', MdChipTransclude);
  14757. function MdChipTransclude ($compile) {
  14758. return {
  14759. restrict: 'EA',
  14760. terminal: true,
  14761. link: link,
  14762. scope: false
  14763. };
  14764. function link (scope, element, attr) {
  14765. var ctrl = scope.$parent.$mdChipsCtrl,
  14766. newScope = ctrl.parent.$new(false, ctrl.parent);
  14767. newScope.$$replacedScope = scope;
  14768. newScope.$chip = scope.$chip;
  14769. newScope.$index = scope.$index;
  14770. newScope.$mdChipsCtrl = ctrl;
  14771. var newHtml = ctrl.$scope.$eval(attr.mdChipTransclude);
  14772. element.html(newHtml);
  14773. $compile(element.contents())(newScope);
  14774. }
  14775. }
  14776. MdChipTransclude.$inject = ["$compile"];
  14777. })();
  14778. (function(){
  14779. "use strict";
  14780. angular
  14781. .module('material.components.chips')
  14782. .controller('MdChipsCtrl', MdChipsCtrl);
  14783. /**
  14784. * Controller for the MdChips component. Responsible for adding to and
  14785. * removing from the list of chips, marking chips as selected, and binding to
  14786. * the models of various input components.
  14787. *
  14788. * @param $scope
  14789. * @param $mdConstant
  14790. * @param $log
  14791. * @param $element
  14792. * @constructor
  14793. */
  14794. function MdChipsCtrl ($scope, $mdConstant, $log, $element, $timeout) {
  14795. /** @type {$timeout} **/
  14796. this.$timeout = $timeout;
  14797. /** @type {Object} */
  14798. this.$mdConstant = $mdConstant;
  14799. /** @type {angular.$scope} */
  14800. this.$scope = $scope;
  14801. /** @type {angular.$scope} */
  14802. this.parent = $scope.$parent;
  14803. /** @type {$log} */
  14804. this.$log = $log;
  14805. /** @type {$element} */
  14806. this.$element = $element;
  14807. /** @type {angular.NgModelController} */
  14808. this.ngModelCtrl = null;
  14809. /** @type {angular.NgModelController} */
  14810. this.userInputNgModelCtrl = null;
  14811. /** @type {Element} */
  14812. this.userInputElement = null;
  14813. /** @type {Array.<Object>} */
  14814. this.items = [];
  14815. /** @type {number} */
  14816. this.selectedChip = -1;
  14817. /** @type {boolean} */
  14818. this.hasAutocomplete = false;
  14819. /**
  14820. * Hidden hint text for how to delete a chip. Used to give context to screen readers.
  14821. * @type {string}
  14822. */
  14823. this.deleteHint = 'Press delete to remove this chip.';
  14824. /**
  14825. * Hidden label for the delete button. Used to give context to screen readers.
  14826. * @type {string}
  14827. */
  14828. this.deleteButtonLabel = 'Remove';
  14829. /**
  14830. * Model used by the input element.
  14831. * @type {string}
  14832. */
  14833. this.chipBuffer = '';
  14834. /**
  14835. * Whether to use the onAppend expression to transform the chip buffer
  14836. * before appending it to the list.
  14837. * @type {boolean}
  14838. */
  14839. this.useOnAppend = false;
  14840. /**
  14841. * Whether to use the onSelect expression to notify the component's user
  14842. * after selecting a chip from the list.
  14843. * @type {boolean}
  14844. */
  14845. this.useOnSelect = false;
  14846. }
  14847. MdChipsCtrl.$inject = ["$scope", "$mdConstant", "$log", "$element", "$timeout"];
  14848. /**
  14849. * Handles the keydown event on the input element: <enter> appends the
  14850. * buffer to the chip list, while backspace removes the last chip in the list
  14851. * if the current buffer is empty.
  14852. * @param event
  14853. */
  14854. MdChipsCtrl.prototype.inputKeydown = function(event) {
  14855. var chipBuffer = this.getChipBuffer();
  14856. switch (event.keyCode) {
  14857. case this.$mdConstant.KEY_CODE.ENTER:
  14858. if ((this.hasAutocomplete && this.requireMatch) || !chipBuffer) break;
  14859. event.preventDefault();
  14860. this.appendChip(chipBuffer);
  14861. this.resetChipBuffer();
  14862. break;
  14863. case this.$mdConstant.KEY_CODE.BACKSPACE:
  14864. if (chipBuffer) break;
  14865. event.preventDefault();
  14866. event.stopPropagation();
  14867. if (this.items.length) this.selectAndFocusChipSafe(this.items.length - 1);
  14868. break;
  14869. }
  14870. };
  14871. /**
  14872. * Handles the keydown event on the chip elements: backspace removes the selected chip, arrow
  14873. * keys switch which chips is active
  14874. * @param event
  14875. */
  14876. MdChipsCtrl.prototype.chipKeydown = function (event) {
  14877. if (this.getChipBuffer()) return;
  14878. switch (event.keyCode) {
  14879. case this.$mdConstant.KEY_CODE.BACKSPACE:
  14880. case this.$mdConstant.KEY_CODE.DELETE:
  14881. if (this.selectedChip < 0) return;
  14882. event.preventDefault();
  14883. this.removeAndSelectAdjacentChip(this.selectedChip);
  14884. break;
  14885. case this.$mdConstant.KEY_CODE.LEFT_ARROW:
  14886. event.preventDefault();
  14887. if (this.selectedChip < 0) this.selectedChip = this.items.length;
  14888. if (this.items.length) this.selectAndFocusChipSafe(this.selectedChip - 1);
  14889. break;
  14890. case this.$mdConstant.KEY_CODE.RIGHT_ARROW:
  14891. event.preventDefault();
  14892. this.selectAndFocusChipSafe(this.selectedChip + 1);
  14893. break;
  14894. case this.$mdConstant.KEY_CODE.ESCAPE:
  14895. case this.$mdConstant.KEY_CODE.TAB:
  14896. if (this.selectedChip < 0) return;
  14897. event.preventDefault();
  14898. this.onFocus();
  14899. break;
  14900. }
  14901. };
  14902. /**
  14903. * Get the input's placeholder - uses `placeholder` when list is empty and `secondary-placeholder`
  14904. * when the list is non-empty. If `secondary-placeholder` is not provided, `placeholder` is used
  14905. * always.
  14906. */
  14907. MdChipsCtrl.prototype.getPlaceholder = function() {
  14908. // Allow `secondary-placeholder` to be blank.
  14909. var useSecondary = (this.items.length &&
  14910. (this.secondaryPlaceholder == '' || this.secondaryPlaceholder));
  14911. return useSecondary ? this.placeholder : this.secondaryPlaceholder;
  14912. };
  14913. /**
  14914. * Removes chip at {@code index} and selects the adjacent chip.
  14915. * @param index
  14916. */
  14917. MdChipsCtrl.prototype.removeAndSelectAdjacentChip = function(index) {
  14918. var selIndex = this.getAdjacentChipIndex(index);
  14919. this.removeChip(index);
  14920. this.$timeout(angular.bind(this, function () {
  14921. this.selectAndFocusChipSafe(selIndex);
  14922. }));
  14923. };
  14924. /**
  14925. * Sets the selected chip index to -1.
  14926. */
  14927. MdChipsCtrl.prototype.resetSelectedChip = function() {
  14928. this.selectedChip = -1;
  14929. };
  14930. /**
  14931. * Gets the index of an adjacent chip to select after deletion. Adjacency is
  14932. * determined as the next chip in the list, unless the target chip is the
  14933. * last in the list, then it is the chip immediately preceding the target. If
  14934. * there is only one item in the list, -1 is returned (select none).
  14935. * The number returned is the index to select AFTER the target has been
  14936. * removed.
  14937. * If the current chip is not selected, then -1 is returned to select none.
  14938. */
  14939. MdChipsCtrl.prototype.getAdjacentChipIndex = function(index) {
  14940. var len = this.items.length - 1;
  14941. return (len == 0) ? -1 :
  14942. (index == len) ? index -1 : index;
  14943. };
  14944. /**
  14945. * Append the contents of the buffer to the chip list. This method will first
  14946. * call out to the md-on-append method, if provided
  14947. * @param newChip
  14948. */
  14949. MdChipsCtrl.prototype.appendChip = function(newChip) {
  14950. if (this.useOnAppend && this.onAppend) {
  14951. newChip = this.onAppend({'$chip': newChip});
  14952. }
  14953. if (this.items.indexOf(newChip) + 1) return;
  14954. this.items.push(newChip);
  14955. };
  14956. /**
  14957. * Sets whether to use the md-on-append expression. This expression is
  14958. * bound to scope and controller in {@code MdChipsDirective} as
  14959. * {@code onAppend}. Due to the nature of directive scope bindings, the
  14960. * controller cannot know on its own/from the scope whether an expression was
  14961. * actually provided.
  14962. */
  14963. MdChipsCtrl.prototype.useOnAppendExpression = function() {
  14964. this.useOnAppend = true;
  14965. };
  14966. /**
  14967. * Sets whether to use the md-on-remove expression. This expression is
  14968. * bound to scope and controller in {@code MdChipsDirective} as
  14969. * {@code onRemove}. Due to the nature of directive scope bindings, the
  14970. * controller cannot know on its own/from the scope whether an expression was
  14971. * actually provided.
  14972. */
  14973. MdChipsCtrl.prototype.useOnRemoveExpression = function() {
  14974. this.useOnRemove = true;
  14975. };
  14976. /*
  14977. * Sets whether to use the md-on-select expression. This expression is
  14978. * bound to scope and controller in {@code MdChipsDirective} as
  14979. * {@code onSelect}. Due to the nature of directive scope bindings, the
  14980. * controller cannot know on its own/from the scope whether an expression was
  14981. * actually provided.
  14982. */
  14983. MdChipsCtrl.prototype.useOnSelectExpression = function() {
  14984. this.useOnSelect = true;
  14985. };
  14986. /**
  14987. * Gets the input buffer. The input buffer can be the model bound to the
  14988. * default input item {@code this.chipBuffer}, the {@code selectedItem}
  14989. * model of an {@code md-autocomplete}, or, through some magic, the model
  14990. * bound to any inpput or text area element found within a
  14991. * {@code md-input-container} element.
  14992. * @return {Object|string}
  14993. */
  14994. MdChipsCtrl.prototype.getChipBuffer = function() {
  14995. return !this.userInputElement ? this.chipBuffer :
  14996. this.userInputNgModelCtrl ? this.userInputNgModelCtrl.$viewValue :
  14997. this.userInputElement[0].value;
  14998. };
  14999. /**
  15000. * Resets the input buffer for either the internal input or user provided input element.
  15001. */
  15002. MdChipsCtrl.prototype.resetChipBuffer = function() {
  15003. if (this.userInputElement) {
  15004. if (this.userInputNgModelCtrl) {
  15005. this.userInputNgModelCtrl.$setViewValue('');
  15006. this.userInputNgModelCtrl.$render();
  15007. } else {
  15008. this.userInputElement[0].value = '';
  15009. }
  15010. } else {
  15011. this.chipBuffer = '';
  15012. }
  15013. };
  15014. /**
  15015. * Removes the chip at the given index.
  15016. * @param index
  15017. */
  15018. MdChipsCtrl.prototype.removeChip = function(index) {
  15019. var removed = this.items.splice(index, 1);
  15020. if (removed && removed.length && this.useOnRemove && this.onRemove) {
  15021. this.onRemove({ '$chip': removed[0], '$index': index });
  15022. }
  15023. };
  15024. MdChipsCtrl.prototype.removeChipAndFocusInput = function (index) {
  15025. this.removeChip(index);
  15026. this.onFocus();
  15027. };
  15028. /**
  15029. * Selects the chip at `index`,
  15030. * @param index
  15031. */
  15032. MdChipsCtrl.prototype.selectAndFocusChipSafe = function(index) {
  15033. if (!this.items.length) {
  15034. this.selectChip(-1);
  15035. this.onFocus();
  15036. return;
  15037. }
  15038. if (index === this.items.length) return this.onFocus();
  15039. index = Math.max(index, 0);
  15040. index = Math.min(index, this.items.length - 1);
  15041. this.selectChip(index);
  15042. this.focusChip(index);
  15043. };
  15044. /**
  15045. * Marks the chip at the given index as selected.
  15046. * @param index
  15047. */
  15048. MdChipsCtrl.prototype.selectChip = function(index) {
  15049. if (index >= -1 && index <= this.items.length) {
  15050. this.selectedChip = index;
  15051. // Fire the onSelect if provided
  15052. if (this.useOnSelect && this.onSelect) {
  15053. this.onSelect({'$chip': this.items[this.selectedChip] });
  15054. }
  15055. } else {
  15056. this.$log.warn('Selected Chip index out of bounds; ignoring.');
  15057. }
  15058. };
  15059. /**
  15060. * Selects the chip at `index` and gives it focus.
  15061. * @param index
  15062. */
  15063. MdChipsCtrl.prototype.selectAndFocusChip = function(index) {
  15064. this.selectChip(index);
  15065. if (index != -1) {
  15066. this.focusChip(index);
  15067. }
  15068. };
  15069. /**
  15070. * Call `focus()` on the chip at `index`
  15071. */
  15072. MdChipsCtrl.prototype.focusChip = function(index) {
  15073. this.$element[0].querySelector('md-chip[index="' + index + '"] .md-chip-content').focus();
  15074. };
  15075. /**
  15076. * Configures the required interactions with the ngModel Controller.
  15077. * Specifically, set {@code this.items} to the {@code NgModelCtrl#$viewVale}.
  15078. * @param ngModelCtrl
  15079. */
  15080. MdChipsCtrl.prototype.configureNgModel = function(ngModelCtrl) {
  15081. this.ngModelCtrl = ngModelCtrl;
  15082. var self = this;
  15083. ngModelCtrl.$render = function() {
  15084. // model is updated. do something.
  15085. self.items = self.ngModelCtrl.$viewValue;
  15086. };
  15087. };
  15088. MdChipsCtrl.prototype.onFocus = function () {
  15089. var input = this.$element[0].querySelector('input');
  15090. input && input.focus();
  15091. this.resetSelectedChip();
  15092. };
  15093. MdChipsCtrl.prototype.onInputFocus = function () {
  15094. this.inputHasFocus = true;
  15095. this.resetSelectedChip();
  15096. };
  15097. MdChipsCtrl.prototype.onInputBlur = function () {
  15098. this.inputHasFocus = false;
  15099. };
  15100. /**
  15101. * Configure event bindings on a user-provided input element.
  15102. * @param inputElement
  15103. */
  15104. MdChipsCtrl.prototype.configureUserInput = function(inputElement) {
  15105. this.userInputElement = inputElement;
  15106. // Find the NgModelCtrl for the input element
  15107. var ngModelCtrl = inputElement.controller('ngModel');
  15108. // `.controller` will look in the parent as well.
  15109. if (ngModelCtrl != this.ngModelCtrl) {
  15110. this.userInputNgModelCtrl = ngModelCtrl;
  15111. }
  15112. var scope = this.$scope;
  15113. var ctrl = this;
  15114. // Run all of the events using evalAsync because a focus may fire a blur in the same digest loop
  15115. var scopeApplyFn = function(event, fn) {
  15116. scope.$evalAsync(angular.bind(ctrl, fn, event));
  15117. };
  15118. // Bind to keydown and focus events of input
  15119. inputElement
  15120. .attr({ tabindex: 0 })
  15121. .on('keydown', function(event) { scopeApplyFn(event, ctrl.inputKeydown) })
  15122. .on('focus', function(event) { scopeApplyFn(event, ctrl.onInputFocus) })
  15123. .on('blur', function(event) { scopeApplyFn(event, ctrl.onInputBlur) })
  15124. };
  15125. MdChipsCtrl.prototype.configureAutocomplete = function(ctrl) {
  15126. this.hasAutocomplete = true;
  15127. ctrl.registerSelectedItemWatcher(angular.bind(this, function (item) {
  15128. if (item) {
  15129. this.appendChip(item);
  15130. this.resetChipBuffer();
  15131. }
  15132. }));
  15133. this.$element.find('input')
  15134. .on('focus',angular.bind(this, this.onInputFocus) )
  15135. .on('blur', angular.bind(this, this.onInputBlur) );
  15136. };
  15137. MdChipsCtrl.prototype.hasFocus = function () {
  15138. return this.inputHasFocus || this.selectedChip >= 0;
  15139. };
  15140. })();
  15141. (function(){
  15142. "use strict";
  15143. angular
  15144. .module('material.components.chips')
  15145. .directive('mdChips', MdChips);
  15146. /**
  15147. * @ngdoc directive
  15148. * @name mdChips
  15149. * @module material.components.chips
  15150. *
  15151. * @description
  15152. * `<md-chips>` is an input component for building lists of strings or objects. The list items are
  15153. * displayed as 'chips'. This component can make use of an `<input>` element or an
  15154. * `<md-autocomplete>` element.
  15155. *
  15156. * <strong>Custom `<md-chip-template>` template</strong>
  15157. * A custom template may be provided to render the content of each chip. This is achieved by
  15158. * specifying an `<md-chip-template>` element as a child of `<md-chips>`. Note: Any attributes on
  15159. * `<md-chip-template>` will be dropped as only the innerHTML is used for the chip template. The
  15160. * variables `$chip` and `$index` are available in the scope of `<md-chip-template>`, representing
  15161. * the chip object and its index in the list of chips, respectively.
  15162. * To override the chip delete control, include an element (ideally a button) with the attribute
  15163. * `md-chip-remove`. A click listener to remove the chip will be added automatically. The element
  15164. * is also placed as a sibling to the chip content (on which there are also click listeners) to
  15165. * avoid a nested ng-click situation.
  15166. *
  15167. * <h3> Pending Features </h3>
  15168. * <ul style="padding-left:20px;">
  15169. *
  15170. * <ul>Style
  15171. * <li>Colours for hover, press states (ripple?).</li>
  15172. * </ul>
  15173. *
  15174. * <ul>Validation
  15175. * <li>allow a validation callback</li>
  15176. * <li>hilighting style for invalid chips</li>
  15177. * </ul>
  15178. *
  15179. * <ul>Item mutation
  15180. * <li>Support `
  15181. * <md-chip-edit>` template, show/hide the edit element on tap/click? double tap/double
  15182. * click?
  15183. * </li>
  15184. * </ul>
  15185. *
  15186. * <ul>Truncation and Disambiguation (?)
  15187. * <li>Truncate chip text where possible, but do not truncate entries such that two are
  15188. * indistinguishable.</li>
  15189. * </ul>
  15190. *
  15191. * <ul>Drag and Drop
  15192. * <li>Drag and drop chips between related `<md-chips>` elements.
  15193. * </li>
  15194. * </ul>
  15195. * </ul>
  15196. *
  15197. * <span style="font-size:.8em;text-align:center">
  15198. * Warning: This component is a WORK IN PROGRESS. If you use it now,
  15199. * it will probably break on you in the future.
  15200. * </span>
  15201. *
  15202. * @param {string=|object=} ng-model A model to bind the list of items to
  15203. * @param {string=} placeholder Placeholder text that will be forwarded to the input.
  15204. * @param {string=} secondary-placeholder Placeholder text that will be forwarded to the input,
  15205. * displayed when there is at least on item in the list
  15206. * @param {boolean=} readonly Disables list manipulation (deleting or adding list items), hiding
  15207. * the input and delete buttons
  15208. * @param {expression} md-on-append An expression that when called expects you to return an object
  15209. * representation of the chip input string.
  15210. * @param {expression=} md-on-remove An expression which will be called when a chip has been
  15211. * removed.
  15212. * @param {expression=} md-on-select An expression which will be called when a chip is selected.
  15213. * @param {string=} delete-hint A string read by screen readers instructing users that pressing
  15214. * the delete key will remove the chip.
  15215. * @param {string=} delete-button-label A label for the delete button. Also hidden and read by
  15216. * screen readers.
  15217. *
  15218. * @usage
  15219. * <hljs lang="html">
  15220. * <md-chips
  15221. * ng-model="myItems"
  15222. * placeholder="Add an item"
  15223. * readonly="isReadOnly">
  15224. * </md-chips>
  15225. * </hljs>
  15226. *
  15227. */
  15228. var MD_CHIPS_TEMPLATE = '\
  15229. <md-chips-wrap\
  15230. ng-if="!$mdChipsCtrl.readonly || $mdChipsCtrl.items.length > 0"\
  15231. ng-keydown="$mdChipsCtrl.chipKeydown($event)"\
  15232. ng-class="{ \'md-focused\': $mdChipsCtrl.hasFocus(), \'md-readonly\': !$mdChipsCtrl.ngModelCtrl }"\
  15233. class="md-chips">\
  15234. <md-chip ng-repeat="$chip in $mdChipsCtrl.items"\
  15235. index="{{$index}}"\
  15236. ng-class="{\'md-focused\': $mdChipsCtrl.selectedChip == $index, \'md-readonly\': $mdChipsCtrl.readonly}">\
  15237. <div class="md-chip-content"\
  15238. tabindex="-1"\
  15239. aria-hidden="true"\
  15240. ng-focus="!$mdChipsCtrl.readonly && $mdChipsCtrl.selectChip($index)"\
  15241. md-chip-transclude="$mdChipsCtrl.chipContentsTemplate"></div>\
  15242. <div ng-if="!$mdChipsCtrl.readonly"\
  15243. class="md-chip-remove-container"\
  15244. md-chip-transclude="$mdChipsCtrl.chipRemoveTemplate"></div>\
  15245. </md-chip>\
  15246. <div ng-if="!$mdChipsCtrl.readonly && $mdChipsCtrl.ngModelCtrl"\
  15247. class="md-chip-input-container"\
  15248. md-chip-transclude="$mdChipsCtrl.chipInputTemplate"></div>\
  15249. </div>\
  15250. </md-chips-wrap>';
  15251. var CHIP_INPUT_TEMPLATE = '\
  15252. <input\
  15253. tabindex="0"\
  15254. placeholder="{{$mdChipsCtrl.getPlaceholder()}}"\
  15255. aria-label="{{$mdChipsCtrl.getPlaceholder()}}"\
  15256. ng-model="$mdChipsCtrl.chipBuffer"\
  15257. ng-focus="$mdChipsCtrl.onInputFocus()"\
  15258. ng-blur="$mdChipsCtrl.onInputBlur()"\
  15259. ng-keydown="$mdChipsCtrl.inputKeydown($event)">';
  15260. var CHIP_DEFAULT_TEMPLATE = '\
  15261. <span>{{$chip}}</span>';
  15262. var CHIP_REMOVE_TEMPLATE = '\
  15263. <button\
  15264. class="md-chip-remove"\
  15265. ng-if="!$mdChipsCtrl.readonly"\
  15266. ng-click="$mdChipsCtrl.removeChipAndFocusInput($$replacedScope.$index)"\
  15267. type="button"\
  15268. aria-hidden="true"\
  15269. tabindex="-1">\
  15270. <md-icon md-svg-icon="md-close"></md-icon>\
  15271. <span class="md-visually-hidden">\
  15272. {{$mdChipsCtrl.deleteButtonLabel}}\
  15273. </span>\
  15274. </button>';
  15275. /**
  15276. * MDChips Directive Definition
  15277. */
  15278. function MdChips ($mdTheming, $mdUtil, $compile, $log, $timeout) {
  15279. // Run our templates through $mdUtil.processTemplate() to allow custom start/end symbols
  15280. convertTemplates();
  15281. return {
  15282. template: function(element, attrs) {
  15283. // Clone the element into an attribute. By prepending the attribute
  15284. // name with '$', Angular won't write it into the DOM. The cloned
  15285. // element propagates to the link function via the attrs argument,
  15286. // where various contained-elements can be consumed.
  15287. attrs['$mdUserTemplate'] = element.clone();
  15288. return MD_CHIPS_TEMPLATE;
  15289. },
  15290. require: ['mdChips'],
  15291. restrict: 'E',
  15292. controller: 'MdChipsCtrl',
  15293. controllerAs: '$mdChipsCtrl',
  15294. bindToController: true,
  15295. compile: compile,
  15296. scope: {
  15297. readonly: '=readonly',
  15298. placeholder: '@',
  15299. secondaryPlaceholder: '@',
  15300. onAppend: '&mdOnAppend',
  15301. onRemove: '&mdOnRemove',
  15302. onSelect: '&mdOnSelect',
  15303. deleteHint: '@',
  15304. deleteButtonLabel: '@',
  15305. requireMatch: '=?mdRequireMatch'
  15306. }
  15307. };
  15308. /**
  15309. * Builds the final template for `md-chips` and returns the postLink function.
  15310. *
  15311. * Building the template involves 3 key components:
  15312. * static chips
  15313. * chip template
  15314. * input control
  15315. *
  15316. * If no `ng-model` is provided, only the static chip work needs to be done.
  15317. *
  15318. * If no user-passed `md-chip-template` exists, the default template is used. This resulting
  15319. * template is appended to the chip content element.
  15320. *
  15321. * The remove button may be overridden by passing an element with an md-chip-remove attribute.
  15322. *
  15323. * If an `input` or `md-autocomplete` element is provided by the caller, it is set aside for
  15324. * transclusion later. The transclusion happens in `postLink` as the parent scope is required.
  15325. * If no user input is provided, a default one is appended to the input container node in the
  15326. * template.
  15327. *
  15328. * Static Chips (i.e. `md-chip` elements passed from the caller) are gathered and set aside for
  15329. * transclusion in the `postLink` function.
  15330. *
  15331. *
  15332. * @param element
  15333. * @param attr
  15334. * @returns {Function}
  15335. */
  15336. function compile(element, attr) {
  15337. // Grab the user template from attr and reset the attribute to null.
  15338. var userTemplate = attr['$mdUserTemplate'];
  15339. attr['$mdUserTemplate'] = null;
  15340. // Set the chip remove, chip contents and chip input templates. The link function will put
  15341. // them on the scope for transclusion later.
  15342. var chipRemoveTemplate = getTemplateByQuery('md-chips>*[md-chip-remove]') || CHIP_REMOVE_TEMPLATE,
  15343. chipContentsTemplate = getTemplateByQuery('md-chips>md-chip-template') || CHIP_DEFAULT_TEMPLATE,
  15344. chipInputTemplate = getTemplateByQuery('md-chips>md-autocomplete')
  15345. || getTemplateByQuery('md-chips>input')
  15346. || CHIP_INPUT_TEMPLATE,
  15347. staticChips = userTemplate.find('md-chip');
  15348. // Warn of malformed template. See #2545
  15349. if (userTemplate[0].querySelector('md-chip-template>*[md-chip-remove]')) {
  15350. $log.warn('invalid placement of md-chip-remove within md-chip-template.');
  15351. }
  15352. function getTemplateByQuery (query) {
  15353. if (!attr.ngModel) return;
  15354. var element = userTemplate[0].querySelector(query);
  15355. return element && element.outerHTML;
  15356. }
  15357. /**
  15358. * Configures controller and transcludes.
  15359. */
  15360. return function postLink(scope, element, attrs, controllers) {
  15361. $mdUtil.initOptionalProperties(scope, attr);
  15362. $mdTheming(element);
  15363. var mdChipsCtrl = controllers[0];
  15364. mdChipsCtrl.chipContentsTemplate = chipContentsTemplate;
  15365. mdChipsCtrl.chipRemoveTemplate = chipRemoveTemplate;
  15366. mdChipsCtrl.chipInputTemplate = chipInputTemplate;
  15367. element
  15368. .attr({ ariaHidden: true, tabindex: -1 })
  15369. .on('focus', function () { mdChipsCtrl.onFocus(); });
  15370. if (attr.ngModel) {
  15371. mdChipsCtrl.configureNgModel(element.controller('ngModel'));
  15372. // If an `md-on-append` attribute was set, tell the controller to use the expression
  15373. // when appending chips.
  15374. if (attrs.mdOnAppend) mdChipsCtrl.useOnAppendExpression();
  15375. // If an `md-on-remove` attribute was set, tell the controller to use the expression
  15376. // when removing chips.
  15377. if (attrs.mdOnRemove) mdChipsCtrl.useOnRemoveExpression();
  15378. // If an `md-on-select` attribute was set, tell the controller to use the expression
  15379. // when selecting chips.
  15380. if (attrs.mdOnSelect) mdChipsCtrl.useOnSelectExpression();
  15381. // The md-autocomplete and input elements won't be compiled until after this directive
  15382. // is complete (due to their nested nature). Wait a tick before looking for them to
  15383. // configure the controller.
  15384. if (chipInputTemplate != CHIP_INPUT_TEMPLATE) {
  15385. // The autocomplete will not appear until the readonly attribute is not true (i.e.
  15386. // false or undefined), so we have to watch the readonly and then on the next tick
  15387. // after the chip transclusion has run, we can configure the autocomplete and user
  15388. // input.
  15389. scope.$watch('$mdChipsCtrl.readonly', function(readonly) {
  15390. if (!readonly) {
  15391. $mdUtil.nextTick(function(){
  15392. if (chipInputTemplate.indexOf('<md-autocomplete') === 0)
  15393. mdChipsCtrl
  15394. .configureAutocomplete(element.find('md-autocomplete')
  15395. .controller('mdAutocomplete'));
  15396. mdChipsCtrl.configureUserInput(element.find('input'));
  15397. });
  15398. }
  15399. });
  15400. }
  15401. }
  15402. // Compile with the parent's scope and prepend any static chips to the wrapper.
  15403. if (staticChips.length > 0) {
  15404. var compiledStaticChips = $compile(staticChips.clone())(scope.$parent);
  15405. $timeout(function() { element.find('md-chips-wrap').prepend(compiledStaticChips); });
  15406. }
  15407. };
  15408. }
  15409. function convertTemplates() {
  15410. MD_CHIPS_TEMPLATE = $mdUtil.processTemplate(MD_CHIPS_TEMPLATE);
  15411. CHIP_INPUT_TEMPLATE = $mdUtil.processTemplate(CHIP_INPUT_TEMPLATE);
  15412. CHIP_DEFAULT_TEMPLATE = $mdUtil.processTemplate(CHIP_DEFAULT_TEMPLATE);
  15413. CHIP_REMOVE_TEMPLATE = $mdUtil.processTemplate(CHIP_REMOVE_TEMPLATE);
  15414. }
  15415. }
  15416. MdChips.$inject = ["$mdTheming", "$mdUtil", "$compile", "$log", "$timeout"];
  15417. })();
  15418. (function(){
  15419. "use strict";
  15420. angular
  15421. .module('material.components.chips')
  15422. .controller('MdContactChipsCtrl', MdContactChipsCtrl);
  15423. /**
  15424. * Controller for the MdContactChips component
  15425. * @constructor
  15426. */
  15427. function MdContactChipsCtrl () {
  15428. /** @type {Object} */
  15429. this.selectedItem = null;
  15430. /** @type {string} */
  15431. this.searchText = '';
  15432. }
  15433. MdContactChipsCtrl.prototype.queryContact = function(searchText) {
  15434. var results = this.contactQuery({'$query': searchText});
  15435. return this.filterSelected ?
  15436. results.filter(angular.bind(this, this.filterSelectedContacts)) : results;
  15437. };
  15438. MdContactChipsCtrl.prototype.itemName = function(item) {
  15439. return item[this.contactName];
  15440. };
  15441. MdContactChipsCtrl.prototype.filterSelectedContacts = function(contact) {
  15442. return this.contacts.indexOf(contact) == -1;
  15443. };
  15444. })();
  15445. (function(){
  15446. "use strict";
  15447. angular
  15448. .module('material.components.chips')
  15449. .directive('mdContactChips', MdContactChips);
  15450. /**
  15451. * @ngdoc directive
  15452. * @name mdContactChips
  15453. * @module material.components.chips
  15454. *
  15455. * @description
  15456. * `<md-contact-chips>` is an input component based on `md-chips` and makes use of an
  15457. * `md-autocomplete` element. The component allows the caller to supply a query expression which
  15458. * returns a list of possible contacts. The user can select one of these and add it to the list of
  15459. * chips.
  15460. *
  15461. * You may also use the `md-highlight-text` directive along with it's parameters to control the
  15462. * appearance of the matched text inside of the contacts' autocomplete popup.
  15463. *
  15464. * @param {string=|object=} ng-model A model to bind the list of items to
  15465. * @param {string=} placeholder Placeholder text that will be forwarded to the input.
  15466. * @param {string=} secondary-placeholder Placeholder text that will be forwarded to the input,
  15467. * displayed when there is at least on item in the list
  15468. * @param {expression} md-contacts An expression expected to return contacts matching the search
  15469. * test, `$query`.
  15470. * @param {string} md-contact-name The field name of the contact object representing the
  15471. * contact's name.
  15472. * @param {string} md-contact-email The field name of the contact object representing the
  15473. * contact's email address.
  15474. * @param {string} md-contact-image The field name of the contact object representing the
  15475. * contact's image.
  15476. *
  15477. *
  15478. * // The following attribute has been removed but may come back.
  15479. * @param {expression=} filter-selected Whether to filter selected contacts from the list of
  15480. * suggestions shown in the autocomplete.
  15481. *
  15482. *
  15483. *
  15484. * @usage
  15485. * <hljs lang="html">
  15486. * <md-contact-chips
  15487. * ng-model="ctrl.contacts"
  15488. * md-contacts="ctrl.querySearch($query)"
  15489. * md-contact-name="name"
  15490. * md-contact-image="image"
  15491. * md-contact-email="email"
  15492. * placeholder="To">
  15493. * </md-contact-chips>
  15494. * </hljs>
  15495. *
  15496. */
  15497. var MD_CONTACT_CHIPS_TEMPLATE = '\
  15498. <md-chips class="md-contact-chips"\
  15499. ng-model="$mdContactChipsCtrl.contacts"\
  15500. md-require-match="$mdContactChipsCtrl.requireMatch"\
  15501. md-autocomplete-snap>\
  15502. <md-autocomplete\
  15503. md-menu-class="md-contact-chips-suggestions"\
  15504. md-selected-item="$mdContactChipsCtrl.selectedItem"\
  15505. md-search-text="$mdContactChipsCtrl.searchText"\
  15506. md-items="item in $mdContactChipsCtrl.queryContact($mdContactChipsCtrl.searchText)"\
  15507. md-item-text="$mdContactChipsCtrl.itemName(item)"\
  15508. md-no-cache="true"\
  15509. md-autoselect\
  15510. placeholder="{{$mdContactChipsCtrl.contacts.length == 0 ?\
  15511. $mdContactChipsCtrl.placeholder : $mdContactChipsCtrl.secondaryPlaceholder}}">\
  15512. <div class="md-contact-suggestion">\
  15513. <img \
  15514. ng-src="{{item[$mdContactChipsCtrl.contactImage]}}"\
  15515. alt="{{item[$mdContactChipsCtrl.contactName]}}" />\
  15516. <span class="md-contact-name" md-highlight-text="$mdContactChipsCtrl.searchText"\
  15517. md-highlight-flags="{{$mdContactChipsCtrl.highlightFlags}}">\
  15518. {{item[$mdContactChipsCtrl.contactName]}}\
  15519. </span>\
  15520. <span class="md-contact-email" >{{item[$mdContactChipsCtrl.contactEmail]}}</span>\
  15521. </div>\
  15522. </md-autocomplete>\
  15523. <md-chip-template>\
  15524. <div class="md-contact-avatar">\
  15525. <img \
  15526. ng-src="{{$chip[$mdContactChipsCtrl.contactImage]}}"\
  15527. alt="{{$chip[$mdContactChipsCtrl.contactName]}}" />\
  15528. </div>\
  15529. <div class="md-contact-name">\
  15530. {{$chip[$mdContactChipsCtrl.contactName]}}\
  15531. </div>\
  15532. </md-chip-template>\
  15533. </md-chips>';
  15534. /**
  15535. * MDContactChips Directive Definition
  15536. *
  15537. * @param $mdTheming
  15538. * @returns {*}
  15539. * @ngInject
  15540. */
  15541. function MdContactChips($mdTheming, $mdUtil) {
  15542. return {
  15543. template: function(element, attrs) {
  15544. return MD_CONTACT_CHIPS_TEMPLATE;
  15545. },
  15546. restrict: 'E',
  15547. controller: 'MdContactChipsCtrl',
  15548. controllerAs: '$mdContactChipsCtrl',
  15549. bindToController: true,
  15550. compile: compile,
  15551. scope: {
  15552. contactQuery: '&mdContacts',
  15553. placeholder: '@',
  15554. secondaryPlaceholder: '@',
  15555. contactName: '@mdContactName',
  15556. contactImage: '@mdContactImage',
  15557. contactEmail: '@mdContactEmail',
  15558. contacts: '=ngModel',
  15559. requireMatch: '=?mdRequireMatch',
  15560. highlightFlags: '@?mdHighlightFlags'
  15561. }
  15562. };
  15563. function compile(element, attr) {
  15564. return function postLink(scope, element, attrs, controllers) {
  15565. $mdUtil.initOptionalProperties(scope, attr);
  15566. $mdTheming(element);
  15567. element.attr('tabindex', '-1');
  15568. };
  15569. }
  15570. }
  15571. MdContactChips.$inject = ["$mdTheming", "$mdUtil"];
  15572. })();
  15573. (function(){
  15574. "use strict";
  15575. angular
  15576. .module('material.components.icon')
  15577. .directive('mdIcon', ['$mdIcon', '$mdTheming', '$mdAria', mdIconDirective]);
  15578. /**
  15579. * @ngdoc directive
  15580. * @name mdIcon
  15581. * @module material.components.icon
  15582. *
  15583. * @restrict E
  15584. *
  15585. * @description
  15586. * The `md-icon` directive makes it easier to use vector-based icons in your app (as opposed to
  15587. * raster-based icons types like PNG). The directive supports both icon fonts and SVG icons.
  15588. *
  15589. * Icons should be consider view-only elements that should not be used directly as buttons; instead nest a `<md-icon>`
  15590. * inside a `md-button` to add hover and click features.
  15591. *
  15592. * ### Icon fonts
  15593. * Icon fonts are a technique in which you use a font where the glyphs in the font are
  15594. * your icons instead of text. Benefits include a straightforward way to bundle everything into a
  15595. * single HTTP request, simple scaling, easy color changing, and more.
  15596. *
  15597. * `md-icon` let's you consume an icon font by letting you reference specific icons in that font
  15598. * by name rather than character code.
  15599. *
  15600. * ### SVG
  15601. * For SVGs, the problem with using `<img>` or a CSS `background-image` is that you can't take
  15602. * advantage of some SVG features, such as styling specific parts of the icon with CSS or SVG
  15603. * animation.
  15604. *
  15605. * `md-icon` makes it easier to use SVG icons by *inlining* the SVG into an `<svg>` element in the
  15606. * document. The most straightforward way of referencing an SVG icon is via URL, just like a
  15607. * traditional `<img>`. `$mdIconProvider`, as a convenience, let's you _name_ an icon so you can
  15608. * reference it by name instead of URL throughout your templates.
  15609. *
  15610. * Additionally, you may not want to make separate HTTP requests for every icon, so you can bundle
  15611. * your SVG icons together and pre-load them with $mdIconProvider as an icon set. An icon set can
  15612. * also be given a name, which acts as a namespace for individual icons, so you can reference them
  15613. * like `"social:cake"`.
  15614. *
  15615. * When using SVGs, both external SVGs (via URLs) or sets of SVGs [from icon sets] can be
  15616. * easily loaded and used.When use font-icons, developers must following three (3) simple steps:
  15617. *
  15618. * <ol>
  15619. * <li>Load the font library. e.g.<br/>
  15620. * &lt;link href="https://fonts.googleapis.com/icon?family=Material+Icons"
  15621. * rel="stylesheet"&gt;
  15622. * </li>
  15623. * <li> Use either (a) font-icon class names or (b) font ligatures to render the font glyph by using its textual name</li>
  15624. * <li> Use &lt;md-icon md-font-icon="classname" /&gt; or <br/>
  15625. * use &lt;md-icon md-font-set="font library classname or alias"&gt; textual_name &lt;/md-icon&gt; or <br/>
  15626. * use &lt;md-icon md-font-set="font library classname or alias"&gt; numerical_character_reference &lt;/md-icon&gt;
  15627. * </li>
  15628. * </ol>
  15629. *
  15630. * Full details for these steps can be found:
  15631. *
  15632. * <ul>
  15633. * <li>http://google.github.io/material-design-icons/</li>
  15634. * <li>http://google.github.io/material-design-icons/#icon-font-for-the-web</li>
  15635. * </ul>
  15636. *
  15637. * The Material Design icon style <code>.material-icons</code> and the icon font references are published in
  15638. * Material Design Icons:
  15639. *
  15640. * <ul>
  15641. * <li>http://www.google.com/design/icons/</li>
  15642. * <li>https://www.google.com/design/icons/#ic_accessibility</li>
  15643. * </ul>
  15644. *
  15645. * <h2 id="material_design_icons">Material Design Icons</h2>
  15646. * Using the Material Design Icon-Selector, developers can easily and quickly search for a Material Design font-icon and
  15647. * determine its textual name and character reference code. Click on any icon to see the slide-up information
  15648. * panel with details regarding a SVG download or information on the font-icon usage.
  15649. *
  15650. * <a href="https://www.google.com/design/icons/#ic_accessibility" target="_blank" style="border-bottom:none;">
  15651. * <img src="https://cloud.githubusercontent.com/assets/210413/7902490/fe8dd14c-0780-11e5-98fb-c821cc6475e6.png"
  15652. * aria-label="Material Design Icon-Selector" style="max-width:75%;padding-left:10%">
  15653. * </a>
  15654. *
  15655. * <span class="image_caption">
  15656. * Click on the image above to link to the
  15657. * <a href="https://www.google.com/design/icons/#ic_accessibility" target="_blank">Material Design Icon-Selector</a>.
  15658. * </span>
  15659. *
  15660. * @param {string} md-font-icon String name of CSS icon associated with the font-face will be used
  15661. * to render the icon. Requires the fonts and the named CSS styles to be preloaded.
  15662. * @param {string} md-font-set CSS style name associated with the font library; which will be assigned as
  15663. * the class for the font-icon ligature. This value may also be an alias that is used to lookup the classname;
  15664. * internally use `$mdIconProvider.fontSet(<alias>)` to determine the style name.
  15665. * @param {string} md-svg-src String URL (or expression) used to load, cache, and display an
  15666. * external SVG.
  15667. * @param {string} md-svg-icon md-svg-icon String name used for lookup of the icon from the internal cache;
  15668. * interpolated strings or expressions may also be used. Specific set names can be used with
  15669. * the syntax `<set name>:<icon name>`.<br/><br/>
  15670. * To use icon sets, developers are required to pre-register the sets using the `$mdIconProvider` service.
  15671. * @param {string=} aria-label Labels icon for accessibility. If an empty string is provided, icon
  15672. * will be hidden from accessibility layer with `aria-hidden="true"`. If there's no aria-label on the icon
  15673. * nor a label on the parent element, a warning will be logged to the console.
  15674. * @param {string=} alt Labels icon for accessibility. If an empty string is provided, icon
  15675. * will be hidden from accessibility layer with `aria-hidden="true"`. If there's no alt on the icon
  15676. * nor a label on the parent element, a warning will be logged to the console. *
  15677. * @usage
  15678. * When using SVGs:
  15679. * <hljs lang="html">
  15680. *
  15681. * <!-- Icon ID; may contain optional icon set prefix; icons must registered using $mdIconProvider -->
  15682. * <md-icon md-svg-icon="social:android" aria-label="android " ></md-icon>
  15683. *
  15684. * <!-- Icon urls; may be preloaded in templateCache -->
  15685. * <md-icon md-svg-src="/android.svg" aria-label="android " ></md-icon>
  15686. * <md-icon md-svg-src="{{ getAndroid() }}" aria-label="android " ></md-icon>
  15687. *
  15688. * </hljs>
  15689. *
  15690. * Use the <code>$mdIconProvider</code> to configure your application with
  15691. * svg iconsets.
  15692. *
  15693. * <hljs lang="js">
  15694. * angular.module('appSvgIconSets', ['ngMaterial'])
  15695. * .controller('DemoCtrl', function($scope) {})
  15696. * .config(function($mdIconProvider) {
  15697. * $mdIconProvider
  15698. * .iconSet('social', 'img/icons/sets/social-icons.svg', 24)
  15699. * .defaultIconSet('img/icons/sets/core-icons.svg', 24);
  15700. * });
  15701. * </hljs>
  15702. *
  15703. *
  15704. * When using Font Icons with classnames:
  15705. * <hljs lang="html">
  15706. *
  15707. * <md-icon md-font-icon="android" aria-label="android" ></md-icon>
  15708. * <md-icon class="icon_home" aria-label="Home" ></md-icon>
  15709. *
  15710. * </hljs>
  15711. *
  15712. * When using Material Font Icons with ligatures:
  15713. * <hljs lang="html">
  15714. * <!-- For Material Design Icons -->
  15715. * <!-- The class '.material-icons' is auto-added if a style has NOT been specified -->
  15716. * <md-icon> face </md-icon>
  15717. * <md-icon md-font-set="material-icons"> face </md-icon>
  15718. * <md-icon> #xE87C; </md-icon>
  15719. * <!-- The class '.material-icons' must be manually added if other styles are also specified-->
  15720. * <md-icon class="material-icons md-light md-48"> face </md-icon>
  15721. * </hljs>
  15722. *
  15723. * When using other Font-Icon libraries:
  15724. *
  15725. * <hljs lang="js">
  15726. * // Specify a font-icon style alias
  15727. * angular.config(function($mdIconProvider) {
  15728. * $mdIconProvider.fontSet('fa', 'fontawesome');
  15729. * });
  15730. * </hljs>
  15731. *
  15732. * <hljs lang="html">
  15733. * <md-icon md-font-set="fa">email</md-icon>
  15734. * </hljs>
  15735. *
  15736. */
  15737. function mdIconDirective($mdIcon, $mdTheming, $mdAria ) {
  15738. return {
  15739. scope: {
  15740. fontSet : '@mdFontSet',
  15741. fontIcon: '@mdFontIcon',
  15742. svgIcon : '@mdSvgIcon',
  15743. svgSrc : '@mdSvgSrc'
  15744. },
  15745. restrict: 'E',
  15746. link : postLink
  15747. };
  15748. /**
  15749. * Directive postLink
  15750. * Supports embedded SVGs, font-icons, & external SVGs
  15751. */
  15752. function postLink(scope, element, attr) {
  15753. $mdTheming(element);
  15754. prepareForFontIcon();
  15755. // If using a font-icon, then the textual name of the icon itself
  15756. // provides the aria-label.
  15757. var label = attr.alt || scope.fontIcon || scope.svgIcon || element.text();
  15758. var attrName = attr.$normalize(attr.$attr.mdSvgIcon || attr.$attr.mdSvgSrc || '');
  15759. if ( !attr['aria-label'] ) {
  15760. if (label != '' && !parentsHaveText() ) {
  15761. $mdAria.expect(element, 'aria-label', label);
  15762. $mdAria.expect(element, 'role', 'img');
  15763. } else if ( !element.text() ) {
  15764. // If not a font-icon with ligature, then
  15765. // hide from the accessibility layer.
  15766. $mdAria.expect(element, 'aria-hidden', 'true');
  15767. }
  15768. }
  15769. if (attrName) {
  15770. // Use either pre-configured SVG or URL source, respectively.
  15771. attr.$observe(attrName, function(attrVal) {
  15772. element.empty();
  15773. if (attrVal) {
  15774. $mdIcon(attrVal).then(function(svg) {
  15775. element.append(svg);
  15776. });
  15777. }
  15778. });
  15779. }
  15780. function parentsHaveText() {
  15781. var parent = element.parent();
  15782. if (parent.attr('aria-label') || parent.text()) {
  15783. return true;
  15784. }
  15785. else if(parent.parent().attr('aria-label') || parent.parent().text()) {
  15786. return true;
  15787. }
  15788. return false;
  15789. }
  15790. function prepareForFontIcon () {
  15791. if (!scope.svgIcon && !scope.svgSrc) {
  15792. if (scope.fontIcon) {
  15793. element.addClass('md-font ' + scope.fontIcon);
  15794. }
  15795. if (scope.fontSet) {
  15796. element.addClass($mdIcon.fontSet(scope.fontSet));
  15797. }
  15798. if (shouldUseDefaultFontSet()) {
  15799. element.addClass($mdIcon.fontSet());
  15800. }
  15801. }
  15802. function shouldUseDefaultFontSet() {
  15803. return !scope.fontIcon && !scope.fontSet;
  15804. }
  15805. }
  15806. }
  15807. }
  15808. })();
  15809. (function(){
  15810. "use strict";
  15811. angular
  15812. .module('material.components.icon' )
  15813. .provider('$mdIcon', MdIconProvider);
  15814. /**
  15815. * @ngdoc service
  15816. * @name $mdIconProvider
  15817. * @module material.components.icon
  15818. *
  15819. * @description
  15820. * `$mdIconProvider` is used only to register icon IDs with URLs. These configuration features allow
  15821. * icons and icon sets to be pre-registered and associated with source URLs **before** the `<md-icon />`
  15822. * directives are compiled.
  15823. *
  15824. * If using font-icons, the developer is repsonsible for loading the fonts.
  15825. *
  15826. * If using SVGs, loading of the actual svg files are deferred to on-demand requests and are loaded
  15827. * internally by the `$mdIcon` service using the `$http` service. When an SVG is requested by name/ID,
  15828. * the `$mdIcon` service searches its registry for the associated source URL;
  15829. * that URL is used to on-demand load and parse the SVG dynamically.
  15830. *
  15831. * @usage
  15832. * <hljs lang="js">
  15833. * app.config(function($mdIconProvider) {
  15834. *
  15835. * // Configure URLs for icons specified by [set:]id.
  15836. *
  15837. * $mdIconProvider
  15838. * .defaultFontSet( 'fontawesome' )
  15839. * .defaultIconSet('my/app/icons.svg') // Register a default set of SVG icons
  15840. * .iconSet('social', 'my/app/social.svg') // Register a named icon set of SVGs
  15841. * .icon('android', 'my/app/android.svg') // Register a specific icon (by name)
  15842. * .icon('work:chair', 'my/app/chair.svg'); // Register icon in a specific set
  15843. * });
  15844. * </hljs>
  15845. *
  15846. * SVG icons and icon sets can be easily pre-loaded and cached using either (a) a build process or (b) a runtime
  15847. * **startup** process (shown below):
  15848. *
  15849. * <hljs lang="js">
  15850. * app.config(function($mdIconProvider) {
  15851. *
  15852. * // Register a default set of SVG icon definitions
  15853. * $mdIconProvider.defaultIconSet('my/app/icons.svg')
  15854. *
  15855. * })
  15856. * .run(function($http, $templateCache){
  15857. *
  15858. * // Pre-fetch icons sources by URL and cache in the $templateCache...
  15859. * // subsequent $http calls will look there first.
  15860. *
  15861. * var urls = [ 'imy/app/icons.svg', 'img/icons/android.svg'];
  15862. *
  15863. * angular.forEach(urls, function(url) {
  15864. * $http.get(url, {cache: $templateCache});
  15865. * });
  15866. *
  15867. * });
  15868. *
  15869. * </hljs>
  15870. *
  15871. * NOTE: the loaded SVG data is subsequently cached internally for future requests.
  15872. *
  15873. */
  15874. /**
  15875. * @ngdoc method
  15876. * @name $mdIconProvider#icon
  15877. *
  15878. * @description
  15879. * Register a source URL for a specific icon name; the name may include optional 'icon set' name prefix.
  15880. * These icons will later be retrieved from the cache using `$mdIcon( <icon name> )`
  15881. *
  15882. * @param {string} id Icon name/id used to register the icon
  15883. * @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
  15884. * data or as part of the lookup in `$templateCache` if pre-loading was configured.
  15885. * @param {number=} viewBoxSize Sets the width and height the icon's viewBox.
  15886. * It is ignored for icons with an existing viewBox. Default size is 24.
  15887. *
  15888. * @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
  15889. *
  15890. * @usage
  15891. * <hljs lang="js">
  15892. * app.config(function($mdIconProvider) {
  15893. *
  15894. * // Configure URLs for icons specified by [set:]id.
  15895. *
  15896. * $mdIconProvider
  15897. * .icon('android', 'my/app/android.svg') // Register a specific icon (by name)
  15898. * .icon('work:chair', 'my/app/chair.svg'); // Register icon in a specific set
  15899. * });
  15900. * </hljs>
  15901. *
  15902. */
  15903. /**
  15904. * @ngdoc method
  15905. * @name $mdIconProvider#iconSet
  15906. *
  15907. * @description
  15908. * Register a source URL for a 'named' set of icons; group of SVG definitions where each definition
  15909. * has an icon id. Individual icons can be subsequently retrieved from this cached set using
  15910. * `$mdIcon(<icon set name>:<icon name>)`
  15911. *
  15912. * @param {string} id Icon name/id used to register the iconset
  15913. * @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
  15914. * data or as part of the lookup in `$templateCache` if pre-loading was configured.
  15915. * @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
  15916. * It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
  15917. * Default value is 24.
  15918. *
  15919. * @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
  15920. *
  15921. *
  15922. * @usage
  15923. * <hljs lang="js">
  15924. * app.config(function($mdIconProvider) {
  15925. *
  15926. * // Configure URLs for icons specified by [set:]id.
  15927. *
  15928. * $mdIconProvider
  15929. * .iconSet('social', 'my/app/social.svg') // Register a named icon set
  15930. * });
  15931. * </hljs>
  15932. *
  15933. */
  15934. /**
  15935. * @ngdoc method
  15936. * @name $mdIconProvider#defaultIconSet
  15937. *
  15938. * @description
  15939. * Register a source URL for the default 'named' set of icons. Unless explicitly registered,
  15940. * subsequent lookups of icons will failover to search this 'default' icon set.
  15941. * Icon can be retrieved from this cached, default set using `$mdIcon(<name>)`
  15942. *
  15943. * @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
  15944. * data or as part of the lookup in `$templateCache` if pre-loading was configured.
  15945. * @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
  15946. * It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
  15947. * Default value is 24.
  15948. *
  15949. * @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
  15950. *
  15951. * @usage
  15952. * <hljs lang="js">
  15953. * app.config(function($mdIconProvider) {
  15954. *
  15955. * // Configure URLs for icons specified by [set:]id.
  15956. *
  15957. * $mdIconProvider
  15958. * .defaultIconSet( 'my/app/social.svg' ) // Register a default icon set
  15959. * });
  15960. * </hljs>
  15961. *
  15962. */
  15963. /**
  15964. * @ngdoc method
  15965. * @name $mdIconProvider#defaultFontSet
  15966. *
  15967. * @description
  15968. * When using Font-Icons, Angular Material assumes the the Material Design icons will be used and automatically
  15969. * configures the default font-set == 'material-icons'. Note that the font-set references the font-icon library
  15970. * class style that should be applied to the `<md-icon>`.
  15971. *
  15972. * Configuring the default means that the attributes
  15973. * `md-font-set="material-icons"` or `class="material-icons"` do not need to be explicitly declared on the
  15974. * `<md-icon>` markup. For example:
  15975. *
  15976. * `<md-icon> face </md-icon>`
  15977. * will render as
  15978. * `<span class="material-icons"> face </span>`, and
  15979. *
  15980. * `<md-icon md-font-set="fa"> face </md-icon>`
  15981. * will render as
  15982. * `<span class="fa"> face </span>`
  15983. *
  15984. * @param {string} name of the font-library style that should be applied to the md-icon DOM element
  15985. *
  15986. * @usage
  15987. * <hljs lang="js">
  15988. * app.config(function($mdIconProvider) {
  15989. * $mdIconProvider.defaultFontSet( 'fontawesome' );
  15990. * });
  15991. * </hljs>
  15992. *
  15993. */
  15994. /**
  15995. * @ngdoc method
  15996. * @name $mdIconProvider#defaultViewBoxSize
  15997. *
  15998. * @description
  15999. * While `<md-icon />` markup can also be style with sizing CSS, this method configures
  16000. * the default width **and** height used for all icons; unless overridden by specific CSS.
  16001. * The default sizing is (24px, 24px).
  16002. * @param {number=} viewBoxSize Sets the width and height of the viewBox for an icon or an icon set.
  16003. * All icons in a set should be the same size. The default value is 24.
  16004. *
  16005. * @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
  16006. *
  16007. * @usage
  16008. * <hljs lang="js">
  16009. * app.config(function($mdIconProvider) {
  16010. *
  16011. * // Configure URLs for icons specified by [set:]id.
  16012. *
  16013. * $mdIconProvider
  16014. * .defaultViewBoxSize(36) // Register a default icon size (width == height)
  16015. * });
  16016. * </hljs>
  16017. *
  16018. */
  16019. var config = {
  16020. defaultViewBoxSize: 24,
  16021. defaultFontSet: 'material-icons',
  16022. fontSets : [ ]
  16023. };
  16024. function MdIconProvider() { }
  16025. MdIconProvider.prototype = {
  16026. icon : function (id, url, viewBoxSize) {
  16027. if ( id.indexOf(':') == -1 ) id = '$default:' + id;
  16028. config[id] = new ConfigurationItem(url, viewBoxSize );
  16029. return this;
  16030. },
  16031. iconSet : function (id, url, viewBoxSize) {
  16032. config[id] = new ConfigurationItem(url, viewBoxSize );
  16033. return this;
  16034. },
  16035. defaultIconSet : function (url, viewBoxSize) {
  16036. var setName = '$default';
  16037. if ( !config[setName] ) {
  16038. config[setName] = new ConfigurationItem(url, viewBoxSize );
  16039. }
  16040. config[setName].viewBoxSize = viewBoxSize || config.defaultViewBoxSize;
  16041. return this;
  16042. },
  16043. defaultViewBoxSize : function (viewBoxSize) {
  16044. config.defaultViewBoxSize = viewBoxSize;
  16045. return this;
  16046. },
  16047. /**
  16048. * Register an alias name associated with a font-icon library style ;
  16049. */
  16050. fontSet : function fontSet(alias, className) {
  16051. config.fontSets.push({
  16052. alias : alias,
  16053. fontSet : className || alias
  16054. });
  16055. return this;
  16056. },
  16057. /**
  16058. * Specify a default style name associated with a font-icon library
  16059. * fallback to Material Icons.
  16060. *
  16061. */
  16062. defaultFontSet : function defaultFontSet(className) {
  16063. config.defaultFontSet = !className ? '' : className;
  16064. return this;
  16065. },
  16066. defaultIconSize : function defaultIconSize(iconSize) {
  16067. config.defaultIconSize = iconSize;
  16068. return this;
  16069. },
  16070. preloadIcons: function ($templateCache) {
  16071. var iconProvider = this;
  16072. var svgRegistry = [
  16073. {
  16074. id : 'md-tabs-arrow',
  16075. url: 'md-tabs-arrow.svg',
  16076. svg: '<svg version="1.1" x="0px" y="0px" viewBox="0 0 24 24"><g><polygon points="15.4,7.4 14,6 8,12 14,18 15.4,16.6 10.8,12 "/></g></svg>'
  16077. },
  16078. {
  16079. id : 'md-close',
  16080. url: 'md-close.svg',
  16081. svg: '<svg version="1.1" x="0px" y="0px" viewBox="0 0 24 24"><g><path d="M19 6.41l-1.41-1.41-5.59 5.59-5.59-5.59-1.41 1.41 5.59 5.59-5.59 5.59 1.41 1.41 5.59-5.59 5.59 5.59 1.41-1.41-5.59-5.59z"/></g></svg>'
  16082. },
  16083. {
  16084. id: 'md-cancel',
  16085. url: 'md-cancel.svg',
  16086. svg: '<svg version="1.1" x="0px" y="0px" viewBox="0 0 24 24"><g><path d="M12 2c-5.53 0-10 4.47-10 10s4.47 10 10 10 10-4.47 10-10-4.47-10-10-10zm5 13.59l-1.41 1.41-3.59-3.59-3.59 3.59-1.41-1.41 3.59-3.59-3.59-3.59 1.41-1.41 3.59 3.59 3.59-3.59 1.41 1.41-3.59 3.59 3.59 3.59z"/></g></svg>'
  16087. },
  16088. {
  16089. id: 'md-menu',
  16090. url: 'md-menu.svg',
  16091. svg: '<svg version="1.1" x="0px" y="0px" viewBox="0 0 24 24"><path d="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z" /></svg>'
  16092. },
  16093. {
  16094. id: 'md-toggle-arrow',
  16095. url: 'md-toggle-arrow-svg',
  16096. svg: '<svg version="1.1" x="0px" y="0px" viewBox="0 0 48 48"><path d="M24 16l-12 12 2.83 2.83 9.17-9.17 9.17 9.17 2.83-2.83z"/><path d="M0 0h48v48h-48z" fill="none"/></svg>'
  16097. },
  16098. {
  16099. id: 'md-calendar',
  16100. url: 'md-calendar.svg',
  16101. svg: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 3h-1V1h-2v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11zM7 10h5v5H7z"/></svg>'
  16102. }
  16103. ];
  16104. svgRegistry.forEach(function(asset){
  16105. iconProvider.icon(asset.id, asset.url);
  16106. $templateCache.put(asset.url, asset.svg);
  16107. });
  16108. },
  16109. $get : ['$http', '$q', '$log', '$templateCache', function($http, $q, $log, $templateCache) {
  16110. this.preloadIcons($templateCache);
  16111. return MdIconService(config, $http, $q, $log, $templateCache);
  16112. }]
  16113. };
  16114. /**
  16115. * Configuration item stored in the Icon registry; used for lookups
  16116. * to load if not already cached in the `loaded` cache
  16117. */
  16118. function ConfigurationItem(url, viewBoxSize) {
  16119. this.url = url;
  16120. this.viewBoxSize = viewBoxSize || config.defaultViewBoxSize;
  16121. }
  16122. /**
  16123. * @ngdoc service
  16124. * @name $mdIcon
  16125. * @module material.components.icon
  16126. *
  16127. * @description
  16128. * The `$mdIcon` service is a function used to lookup SVG icons.
  16129. *
  16130. * @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
  16131. * 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
  16132. * performed. The Id may be a unique icon ID or may include an iconSet ID prefix.
  16133. *
  16134. * For the **id** query to work properly, this means that all id-to-URL mappings must have been previously configured
  16135. * using the `$mdIconProvider`.
  16136. *
  16137. * @returns {obj} Clone of the initial SVG DOM element; which was created from the SVG markup in the SVG data file.
  16138. *
  16139. * @usage
  16140. * <hljs lang="js">
  16141. * function SomeDirective($mdIcon) {
  16142. *
  16143. * // See if the icon has already been loaded, if not
  16144. * // then lookup the icon from the registry cache, load and cache
  16145. * // it for future requests.
  16146. * // NOTE: ID queries require configuration with $mdIconProvider
  16147. *
  16148. * $mdIcon('android').then(function(iconEl) { element.append(iconEl); });
  16149. * $mdIcon('work:chair').then(function(iconEl) { element.append(iconEl); });
  16150. *
  16151. * // Load and cache the external SVG using a URL
  16152. *
  16153. * $mdIcon('img/icons/android.svg').then(function(iconEl) {
  16154. * element.append(iconEl);
  16155. * });
  16156. * };
  16157. * </hljs>
  16158. *
  16159. * NOTE: The `<md-icon /> ` directive internally uses the `$mdIcon` service to query, loaded, and instantiate
  16160. * SVG DOM elements.
  16161. */
  16162. /* @ngInject */
  16163. function MdIconService(config, $http, $q, $log, $templateCache) {
  16164. var iconCache = {};
  16165. var urlRegex = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/i;
  16166. Icon.prototype = { clone : cloneSVG, prepare: prepareAndStyle };
  16167. getIcon.fontSet = findRegisteredFontSet;
  16168. // Publish service...
  16169. return getIcon;
  16170. /**
  16171. * Actual $mdIcon service is essentially a lookup function
  16172. */
  16173. function getIcon(id) {
  16174. id = id || '';
  16175. // If already loaded and cached, use a clone of the cached icon.
  16176. // Otherwise either load by URL, or lookup in the registry and then load by URL, and cache.
  16177. if ( iconCache[id] ) return $q.when( iconCache[id].clone() );
  16178. if ( urlRegex.test(id) ) return loadByURL(id).then( cacheIcon(id) );
  16179. if ( id.indexOf(':') == -1 ) id = '$default:' + id;
  16180. var load = config[id] ? loadByID : loadFromIconSet;
  16181. return load(id)
  16182. .then( cacheIcon(id) );
  16183. }
  16184. /**
  16185. * Lookup registered fontSet style using its alias...
  16186. * If not found,
  16187. */
  16188. function findRegisteredFontSet(alias) {
  16189. var useDefault = angular.isUndefined(alias) || !(alias && alias.length);
  16190. if ( useDefault ) return config.defaultFontSet;
  16191. var result = alias;
  16192. angular.forEach(config.fontSets, function(it){
  16193. if ( it.alias == alias ) result = it.fontSet || result;
  16194. });
  16195. return result;
  16196. }
  16197. /**
  16198. * Prepare and cache the loaded icon for the specified `id`
  16199. */
  16200. function cacheIcon( id ) {
  16201. return function updateCache( icon ) {
  16202. iconCache[id] = isIcon(icon) ? icon : new Icon(icon, config[id]);
  16203. return iconCache[id].clone();
  16204. };
  16205. }
  16206. /**
  16207. * Lookup the configuration in the registry, if !registered throw an error
  16208. * otherwise load the icon [on-demand] using the registered URL.
  16209. *
  16210. */
  16211. function loadByID(id) {
  16212. var iconConfig = config[id];
  16213. return loadByURL(iconConfig.url).then(function(icon) {
  16214. return new Icon(icon, iconConfig);
  16215. });
  16216. }
  16217. /**
  16218. * Loads the file as XML and uses querySelector( <id> ) to find
  16219. * the desired node...
  16220. */
  16221. function loadFromIconSet(id) {
  16222. var setName = id.substring(0, id.lastIndexOf(':')) || '$default';
  16223. var iconSetConfig = config[setName];
  16224. return !iconSetConfig ? announceIdNotFound(id) : loadByURL(iconSetConfig.url).then(extractFromSet);
  16225. function extractFromSet(set) {
  16226. var iconName = id.slice(id.lastIndexOf(':') + 1);
  16227. var icon = set.querySelector('#' + iconName);
  16228. return !icon ? announceIdNotFound(id) : new Icon(icon, iconSetConfig);
  16229. }
  16230. function announceIdNotFound(id) {
  16231. var msg = 'icon ' + id + ' not found';
  16232. $log.warn(msg);
  16233. return $q.reject(msg || id);
  16234. }
  16235. }
  16236. /**
  16237. * Load the icon by URL (may use the $templateCache).
  16238. * Extract the data for later conversion to Icon
  16239. */
  16240. function loadByURL(url) {
  16241. return $http
  16242. .get(url, { cache: $templateCache })
  16243. .then(function(response) {
  16244. return angular.element('<div>').append(response.data).find('svg')[0];
  16245. }).catch(announceNotFound);
  16246. }
  16247. /**
  16248. * Catch HTTP or generic errors not related to incorrect icon IDs.
  16249. */
  16250. function announceNotFound(err) {
  16251. var msg = angular.isString(err) ? err : (err.message || err.data || err.statusText);
  16252. $log.warn(msg);
  16253. return $q.reject(msg);
  16254. }
  16255. /**
  16256. * Check target signature to see if it is an Icon instance.
  16257. */
  16258. function isIcon(target) {
  16259. return angular.isDefined(target.element) && angular.isDefined(target.config);
  16260. }
  16261. /**
  16262. * Define the Icon class
  16263. */
  16264. function Icon(el, config) {
  16265. if (el.tagName != 'svg') {
  16266. el = angular.element('<svg xmlns="http://www.w3.org/2000/svg">').append(el)[0];
  16267. }
  16268. // Inject the namespace if not available...
  16269. if ( !el.getAttribute('xmlns') ) {
  16270. el.setAttribute('xmlns', "http://www.w3.org/2000/svg");
  16271. }
  16272. this.element = el;
  16273. this.config = config;
  16274. this.prepare();
  16275. }
  16276. /**
  16277. * Prepare the DOM element that will be cached in the
  16278. * loaded iconCache store.
  16279. */
  16280. function prepareAndStyle() {
  16281. var viewBoxSize = this.config ? this.config.viewBoxSize : config.defaultViewBoxSize;
  16282. angular.forEach({
  16283. 'fit' : '',
  16284. 'height': '100%',
  16285. 'width' : '100%',
  16286. 'preserveAspectRatio': 'xMidYMid meet',
  16287. 'viewBox' : this.element.getAttribute('viewBox') || ('0 0 ' + viewBoxSize + ' ' + viewBoxSize)
  16288. }, function(val, attr) {
  16289. this.element.setAttribute(attr, val);
  16290. }, this);
  16291. angular.forEach({
  16292. 'pointer-events' : 'none',
  16293. 'display' : 'block'
  16294. }, function(val, style) {
  16295. this.element.style[style] = val;
  16296. }, this);
  16297. }
  16298. /**
  16299. * Clone the Icon DOM element.
  16300. */
  16301. function cloneSVG(){
  16302. return this.element.cloneNode(true);
  16303. }
  16304. }
  16305. MdIconService.$inject = ["config", "$http", "$q", "$log", "$templateCache"];
  16306. })();
  16307. (function(){
  16308. "use strict";
  16309. angular
  16310. .module('material.components.menu')
  16311. .controller('mdMenuCtrl', MenuController);
  16312. /**
  16313. * @ngInject
  16314. */
  16315. function MenuController($mdMenu, $attrs, $element, $scope, $mdUtil, $timeout) {
  16316. var menuContainer;
  16317. var self = this;
  16318. var triggerElement;
  16319. this.nestLevel = parseInt($attrs.mdNestLevel, 10) || 0;
  16320. /**
  16321. * Called by our linking fn to provide access to the menu-content
  16322. * element removed during link
  16323. */
  16324. this.init = function init(setMenuContainer, opts) {
  16325. opts = opts || {};
  16326. menuContainer = setMenuContainer;
  16327. // Default element for ARIA attributes has the ngClick or ngMouseenter expression
  16328. triggerElement = $element[0].querySelector('[ng-click],[ng-mouseenter]');
  16329. this.isInMenuBar = opts.isInMenuBar;
  16330. this.nestedMenus = $mdUtil.nodesToArray(menuContainer[0].querySelectorAll('.md-nested-menu'));
  16331. this.enableHoverListener();
  16332. menuContainer.on('$mdInterimElementRemove', function() {
  16333. self.isOpen = false;
  16334. });
  16335. };
  16336. this.enableHoverListener = function() {
  16337. $scope.$on('$mdMenuOpen', function(event, el) {
  16338. if (menuContainer[0].contains(el[0])) {
  16339. self.currentlyOpenMenu = el.controller('mdMenu');
  16340. self.isAlreadyOpening = false;
  16341. self.currentlyOpenMenu.registerContainerProxy(self.triggerContainerProxy.bind(self));
  16342. }
  16343. });
  16344. $scope.$on('$mdMenuClose', function(event, el) {
  16345. if (menuContainer[0].contains(el[0])) {
  16346. self.currentlyOpenMenu = undefined;
  16347. }
  16348. });
  16349. var menuItems = angular.element($mdUtil.nodesToArray(menuContainer[0].querySelectorAll('md-menu-item')));
  16350. var openMenuTimeout;
  16351. menuItems.on('mouseenter', function(event) {
  16352. if (self.isAlreadyOpening) return;
  16353. var nestedMenu = (
  16354. event.target.querySelector('md-menu')
  16355. || $mdUtil.getClosest(event.target, 'MD-MENU')
  16356. );
  16357. openMenuTimeout = $timeout(function() {
  16358. if (nestedMenu) {
  16359. nestedMenu = angular.element(nestedMenu).controller('mdMenu');
  16360. }
  16361. if (self.currentlyOpenMenu && self.currentlyOpenMenu != nestedMenu) {
  16362. var closeTo = self.nestLevel + 1;
  16363. self.currentlyOpenMenu.close(true, { closeTo: closeTo });
  16364. } else if (nestedMenu && !nestedMenu.isOpen && nestedMenu.open) {
  16365. self.isAlreadyOpening = true;
  16366. nestedMenu.open();
  16367. }
  16368. }, nestedMenu ? 100 : 250);
  16369. var focusableTarget = event.currentTarget.querySelector('[tabindex]');
  16370. focusableTarget && focusableTarget.focus();
  16371. });
  16372. menuItems.on('mouseleave', function(event) {
  16373. if (openMenuTimeout) {
  16374. $timeout.cancel(openMenuTimeout);
  16375. openMenuTimeout = undefined;
  16376. }
  16377. });
  16378. };
  16379. /**
  16380. * Uses the $mdMenu interim element service to open the menu contents
  16381. */
  16382. this.open = function openMenu(ev) {
  16383. ev && ev.stopPropagation();
  16384. ev && ev.preventDefault();
  16385. if (self.isOpen) return;
  16386. self.isOpen = true;
  16387. triggerElement = triggerElement || (ev ? ev.target : $element[0]);
  16388. $scope.$emit('$mdMenuOpen', $element);
  16389. $mdMenu.show({
  16390. scope: $scope,
  16391. mdMenuCtrl: self,
  16392. nestLevel: self.nestLevel,
  16393. element: menuContainer,
  16394. target: triggerElement,
  16395. preserveElement: self.isInMenuBar || self.nestedMenus.length > 0,
  16396. parent: self.isInMenuBar ? $element : 'body'
  16397. });
  16398. }
  16399. // Expose a open function to the child scope for html to use
  16400. $scope.$mdOpenMenu = this.open;
  16401. $scope.$watch(function() { return self.isOpen; }, function(isOpen) {
  16402. if (isOpen) {
  16403. triggerElement.setAttribute('aria-expanded', 'true');
  16404. $element[0].classList.add('md-open');
  16405. angular.forEach(self.nestedMenus, function(el) {
  16406. el.classList.remove('md-open');
  16407. });
  16408. } else {
  16409. triggerElement && triggerElement.setAttribute('aria-expanded', 'false');
  16410. $element[0].classList.remove('md-open');
  16411. }
  16412. $scope.$mdMenuIsOpen = self.isOpen;
  16413. });
  16414. this.focusMenuContainer = function focusMenuContainer() {
  16415. var focusTarget = menuContainer[0].querySelector('[md-menu-focus-target]');
  16416. if (!focusTarget) focusTarget = menuContainer[0].querySelector('.md-button');
  16417. focusTarget.focus();
  16418. };
  16419. this.registerContainerProxy = function registerContainerProxy(handler) {
  16420. this.containerProxy = handler;
  16421. };
  16422. this.triggerContainerProxy = function triggerContainerProxy(ev) {
  16423. this.containerProxy && this.containerProxy(ev);
  16424. };
  16425. // Use the $mdMenu interim element service to close the menu contents
  16426. this.close = function closeMenu(skipFocus, closeOpts) {
  16427. if ( !self.isOpen ) return;
  16428. self.isOpen = false;
  16429. $scope.$emit('$mdMenuClose', $element);
  16430. $mdMenu.hide(null, closeOpts);
  16431. if (!skipFocus) {
  16432. var el = self.restoreFocusTo || $element.find('button')[0];
  16433. if (el instanceof angular.element) el = el[0];
  16434. el.focus();
  16435. }
  16436. }
  16437. /**
  16438. * Build a nice object out of our string attribute which specifies the
  16439. * target mode for left and top positioning
  16440. */
  16441. this.positionMode = function positionMode() {
  16442. var attachment = ($attrs.mdPositionMode || 'target').split(' ');
  16443. // If attachment is a single item, duplicate it for our second value.
  16444. // ie. 'target' -> 'target target'
  16445. if (attachment.length == 1) {
  16446. attachment.push(attachment[0]);
  16447. }
  16448. return {
  16449. left: attachment[0],
  16450. top: attachment[1]
  16451. };
  16452. }
  16453. /**
  16454. * Build a nice object out of our string attribute which specifies
  16455. * the offset of top and left in pixels.
  16456. */
  16457. this.offsets = function offsets() {
  16458. var position = ($attrs.mdOffset || '0 0').split(' ').map(parseFloat);
  16459. if (position.length == 2) {
  16460. return {
  16461. left: position[0],
  16462. top: position[1]
  16463. };
  16464. } else if (position.length == 1) {
  16465. return {
  16466. top: position[0],
  16467. left: position[0]
  16468. };
  16469. } else {
  16470. throw Error('Invalid offsets specified. Please follow format <x, y> or <n>');
  16471. }
  16472. }
  16473. }
  16474. MenuController.$inject = ["$mdMenu", "$attrs", "$element", "$scope", "$mdUtil", "$timeout"];
  16475. })();
  16476. (function(){
  16477. "use strict";
  16478. /**
  16479. * @ngdoc directive
  16480. * @name mdMenu
  16481. * @module material.components.menu
  16482. * @restrict E
  16483. * @description
  16484. *
  16485. * Menus are elements that open when clicked. They are useful for displaying
  16486. * additional options within the context of an action.
  16487. *
  16488. * Every `md-menu` must specify exactly two child elements. The first element is what is
  16489. * left in the DOM and is used to open the menu. This element is called the trigger element.
  16490. * The trigger element's scope has access to `$mdOpenMenu($event)`
  16491. * which it may call to open the menu. By passing $event as argument, the
  16492. * corresponding event is stopped from propagating up the DOM-tree.
  16493. *
  16494. * The second element is the `md-menu-content` element which represents the
  16495. * contents of the menu when it is open. Typically this will contain `md-menu-item`s,
  16496. * but you can do custom content as well.
  16497. *
  16498. * <hljs lang="html">
  16499. * <md-menu>
  16500. * <!-- Trigger element is a md-button with an icon -->
  16501. * <md-button ng-click="$mdOpenMenu($event)" class="md-icon-button" aria-label="Open sample menu">
  16502. * <md-icon md-svg-icon="call:phone"></md-icon>
  16503. * </md-button>
  16504. * <md-menu-content>
  16505. * <md-menu-item><md-button ng-click="doSomething()">Do Something</md-button></md-menu-item>
  16506. * </md-menu-content>
  16507. * </md-menu>
  16508. * </hljs>
  16509. * ## Sizing Menus
  16510. *
  16511. * The width of the menu when it is open may be specified by specifying a `width`
  16512. * attribute on the `md-menu-content` element.
  16513. * See the [Material Design Spec](http://www.google.com/design/spec/components/menus.html#menus-specs)
  16514. * for more information.
  16515. *
  16516. *
  16517. * ## Aligning Menus
  16518. *
  16519. * When a menu opens, it is important that the content aligns with the trigger element.
  16520. * Failure to align menus can result in jarring experiences for users as content
  16521. * suddenly shifts. To help with this, `md-menu` provides serveral APIs to help
  16522. * with alignment.
  16523. *
  16524. * ### Target Mode
  16525. *
  16526. * By default, `md-menu` will attempt to align the `md-menu-content` by aligning
  16527. * designated child elements in both the trigger and the menu content.
  16528. *
  16529. * To specify the alignment element in the `trigger` you can use the `md-menu-origin`
  16530. * attribute on a child element. If no `md-menu-origin` is specified, the `md-menu`
  16531. * will be used as the origin element.
  16532. *
  16533. * Similarly, the `md-menu-content` may specify a `md-menu-align-target` for a
  16534. * `md-menu-item` to specify the node that it should try and align with.
  16535. *
  16536. * In this example code, we specify an icon to be our origin element, and an
  16537. * icon in our menu content to be our alignment target. This ensures that both
  16538. * icons are aligned when the menu opens.
  16539. *
  16540. * <hljs lang="html">
  16541. * <md-menu>
  16542. * <md-button ng-click="$mdOpenMenu($event)" class="md-icon-button" aria-label="Open some menu">
  16543. * <md-icon md-menu-origin md-svg-icon="call:phone"></md-icon>
  16544. * </md-button>
  16545. * <md-menu-content>
  16546. * <md-menu-item>
  16547. * <md-button ng-click="doSomething()" aria-label="Do something">
  16548. * <md-icon md-menu-align-target md-svg-icon="call:phone"></md-icon>
  16549. * Do Something
  16550. * </md-button>
  16551. * </md-menu-item>
  16552. * </md-menu-content>
  16553. * </md-menu>
  16554. * </hljs>
  16555. *
  16556. * Sometimes we want to specify alignment on the right side of an element, for example
  16557. * if we have a menu on the right side a toolbar, we want to right align our menu content.
  16558. *
  16559. * We can specify the origin by using the `md-position-mode` attribute on both
  16560. * the `x` and `y` axis. Right now only the `x-axis` has more than one option.
  16561. * You may specify the default mode of `target target` or
  16562. * `target-right target` to specify a right-oriented alignment target. See the
  16563. * position section of the demos for more examples.
  16564. *
  16565. * ### Menu Offsets
  16566. *
  16567. * It is sometimes unavoidable to need to have a deeper level of control for
  16568. * the positioning of a menu to ensure perfect alignment. `md-menu` provides
  16569. * the `md-offset` attribute to allow pixel level specificty of adjusting the
  16570. * exact positioning.
  16571. *
  16572. * This offset is provided in the format of `x y` or `n` where `n` will be used
  16573. * in both the `x` and `y` axis.
  16574. *
  16575. * For example, to move a menu by `2px` from the top, we can use:
  16576. * <hljs lang="html">
  16577. * <md-menu md-offset="2 0">
  16578. * <!-- menu-content -->
  16579. * </md-menu>
  16580. * </hljs>
  16581. *
  16582. * @usage
  16583. * <hljs lang="html">
  16584. * <md-menu>
  16585. * <md-button ng-click="$mdOpenMenu($event)" class="md-icon-button">
  16586. * <md-icon md-svg-icon="call:phone"></md-icon>
  16587. * </md-button>
  16588. * <md-menu-content>
  16589. * <md-menu-item><md-button ng-click="doSomething()">Do Something</md-button></md-menu-item>
  16590. * </md-menu-content>
  16591. * </md-menu>
  16592. * </hljs>
  16593. *
  16594. * @param {string} md-po*ition-mode The position mode in the form of
  16595. * `x`, `y`. Default value is `target`,`target`. Right now the `x` axis
  16596. * also suppports `target-right`.
  16597. * @param {string} md-offset An offset to apply to the dropdown after positioning
  16598. * `x`, `y`. Default value is `0`,`0`.
  16599. *
  16600. */
  16601. angular
  16602. .module('material.components.menu')
  16603. .directive('mdMenu', MenuDirective);
  16604. /**
  16605. * @ngInject
  16606. */
  16607. function MenuDirective($mdUtil) {
  16608. var INVALID_PREFIX = 'Invalid HTML for md-menu: ';
  16609. return {
  16610. restrict: 'E',
  16611. require: ['mdMenu', '?^mdMenuBar'],
  16612. controller: 'mdMenuCtrl', // empty function to be built by link
  16613. scope: true,
  16614. compile: compile
  16615. };
  16616. function compile(templateElement) {
  16617. templateElement.addClass('md-menu');
  16618. var triggerElement = templateElement.children()[0];
  16619. if (!triggerElement.hasAttribute('ng-click')) {
  16620. triggerElement = triggerElement.querySelector('[ng-click],[ng-mouseenter]') || triggerElement;
  16621. }
  16622. if (triggerElement && (
  16623. triggerElement.nodeName == 'MD-BUTTON' ||
  16624. triggerElement.nodeName == 'BUTTON'
  16625. ) && !triggerElement.hasAttribute('type')) {
  16626. triggerElement.setAttribute('type', 'button');
  16627. }
  16628. if (templateElement.children().length != 2) {
  16629. throw Error(INVALID_PREFIX + 'Expected two children elements.');
  16630. }
  16631. // Default element for ARIA attributes has the ngClick or ngMouseenter expression
  16632. triggerElement && triggerElement.setAttribute('aria-haspopup', 'true');
  16633. var nestedMenus = templateElement[0].querySelectorAll('md-menu');
  16634. var nestingDepth = parseInt(templateElement[0].getAttribute('md-nest-level'), 10) || 0;
  16635. if (nestedMenus) {
  16636. angular.forEach($mdUtil.nodesToArray(nestedMenus), function(menuEl) {
  16637. if (!menuEl.hasAttribute('md-position-mode')) {
  16638. menuEl.setAttribute('md-position-mode', 'cascade');
  16639. }
  16640. menuEl.classList.add('md-nested-menu');
  16641. menuEl.setAttribute('md-nest-level', nestingDepth + 1);
  16642. menuEl.setAttribute('role', 'menu');
  16643. });
  16644. }
  16645. return link;
  16646. }
  16647. function link(scope, element, attrs, ctrls) {
  16648. var mdMenuCtrl = ctrls[0];
  16649. var isInMenuBar = ctrls[1] != undefined;
  16650. // Move everything into a md-menu-container and pass it to the controller
  16651. var menuContainer = angular.element(
  16652. '<div class="md-open-menu-container md-whiteframe-z2"></div>'
  16653. );
  16654. var menuContents = element.children()[1];
  16655. menuContainer.append(menuContents);
  16656. if (isInMenuBar) {
  16657. element.append(menuContainer);
  16658. menuContainer[0].style.display = 'none';
  16659. }
  16660. mdMenuCtrl.init(menuContainer, { isInMenuBar: isInMenuBar });
  16661. scope.$on('$destroy', function() {
  16662. menuContainer.remove();
  16663. mdMenuCtrl.close();
  16664. });
  16665. }
  16666. }
  16667. MenuDirective.$inject = ["$mdUtil"];
  16668. })();
  16669. (function(){
  16670. "use strict";
  16671. angular
  16672. .module('material.components.menu')
  16673. .provider('$mdMenu', MenuProvider);
  16674. /*
  16675. * Interim element provider for the menu.
  16676. * Handles behavior for a menu while it is open, including:
  16677. * - handling animating the menu opening/closing
  16678. * - handling key/mouse events on the menu element
  16679. * - handling enabling/disabling scroll while the menu is open
  16680. * - handling redrawing during resizes and orientation changes
  16681. *
  16682. */
  16683. function MenuProvider($$interimElementProvider) {
  16684. var MENU_EDGE_MARGIN = 8;
  16685. menuDefaultOptions.$inject = ["$mdUtil", "$mdTheming", "$mdConstant", "$document", "$window", "$q", "$$rAF", "$animateCss", "$animate", "$timeout"];
  16686. return $$interimElementProvider('$mdMenu')
  16687. .setDefaults({
  16688. methods: ['target'],
  16689. options: menuDefaultOptions
  16690. });
  16691. /* @ngInject */
  16692. function menuDefaultOptions($mdUtil, $mdTheming, $mdConstant, $document, $window, $q, $$rAF, $animateCss, $animate, $timeout) {
  16693. var animator = $mdUtil.dom.animator;
  16694. return {
  16695. parent: 'body',
  16696. onShow: onShow,
  16697. onRemove: onRemove,
  16698. hasBackdrop: true,
  16699. disableParentScroll: true,
  16700. skipCompile: true,
  16701. preserveScope: true,
  16702. skipHide: true,
  16703. themable: true
  16704. };
  16705. /**
  16706. * Show modal backdrop element...
  16707. * @returns {function(): void} A function that removes this backdrop
  16708. */
  16709. function showBackdrop(scope, element, options) {
  16710. if (options.nestLevel) return angular.noop;
  16711. // If we are not within a dialog...
  16712. if (options.disableParentScroll && !$mdUtil.getClosest(options.target, 'MD-DIALOG')) {
  16713. // !! DO this before creating the backdrop; since disableScrollAround()
  16714. // configures the scroll offset; which is used by mdBackDrop postLink()
  16715. options.restoreScroll = $mdUtil.disableScrollAround(options.element, options.parent);
  16716. } else {
  16717. options.disableParentScroll = false;
  16718. }
  16719. if (options.hasBackdrop) {
  16720. options.backdrop = $mdUtil.createBackdrop(scope, "md-menu-backdrop md-click-catcher");
  16721. $animate.enter(options.backdrop, options.parent);
  16722. }
  16723. /**
  16724. * Hide and destroys the backdrop created by showBackdrop()
  16725. */
  16726. return function hideBackdrop() {
  16727. if (options.backdrop) {
  16728. // Override duration to immediately remove invisible backdrop
  16729. options.backdrop.off('click');
  16730. $animate.leave(options.backdrop, {duration:0});
  16731. }
  16732. if (options.disableParentScroll) {
  16733. options.restoreScroll();
  16734. }
  16735. };
  16736. }
  16737. /**
  16738. * Removing the menu element from the DOM and remove all associated evetn listeners
  16739. * and backdrop
  16740. */
  16741. function onRemove(scope, element, opts) {
  16742. opts.cleanupInteraction();
  16743. opts.cleanupResizing();
  16744. opts.hideBackdrop();
  16745. return $animateCss(element, {addClass: 'md-leave'})
  16746. .start()
  16747. .then(function() {
  16748. element.removeClass('md-active');
  16749. detachElement(element, opts);
  16750. opts.alreadyOpen = false;
  16751. });
  16752. }
  16753. /**
  16754. * Inserts and configures the staged Menu element into the DOM, positioning it,
  16755. * and wiring up various interaction events
  16756. */
  16757. function onShow(scope, element, opts) {
  16758. sanitizeAndConfigure(opts);
  16759. // Wire up theming on our menu element
  16760. $mdTheming.inherit(opts.menuContentEl, opts.target);
  16761. // Register various listeners to move menu on resize/orientation change
  16762. opts.cleanupResizing = startRepositioningOnResize();
  16763. opts.hideBackdrop = showBackdrop(scope, element, opts);
  16764. // Return the promise for when our menu is done animating in
  16765. return showMenu()
  16766. .then(function(response) {
  16767. opts.alreadyOpen = true;
  16768. opts.cleanupInteraction = activateInteraction();
  16769. return response;
  16770. });
  16771. /**
  16772. * Place the menu into the DOM and call positioning related functions
  16773. */
  16774. function showMenu() {
  16775. if (!opts.preserveElement) {
  16776. opts.parent.append(element);
  16777. } else {
  16778. element[0].style.display = '';
  16779. }
  16780. return $q(function(resolve) {
  16781. var position = calculateMenuPosition(element, opts);
  16782. element.removeClass('md-leave');
  16783. // Animate the menu scaling, and opacity [from its position origin (default == top-left)]
  16784. // to normal scale.
  16785. $animateCss(element, {
  16786. addClass: 'md-active',
  16787. from: animator.toCss(position),
  16788. to: animator.toCss({transform: ''})
  16789. })
  16790. .start()
  16791. .then(resolve);
  16792. });
  16793. }
  16794. /**
  16795. * Check for valid opts and set some sane defaults
  16796. */
  16797. function sanitizeAndConfigure() {
  16798. if (!opts.target) {
  16799. throw Error(
  16800. '$mdMenu.show() expected a target to animate from in options.target'
  16801. );
  16802. }
  16803. angular.extend(opts, {
  16804. alreadyOpen: false,
  16805. isRemoved: false,
  16806. target: angular.element(opts.target), //make sure it's not a naked dom node
  16807. parent: angular.element(opts.parent),
  16808. menuContentEl: angular.element(element[0].querySelector('md-menu-content'))
  16809. });
  16810. }
  16811. /**
  16812. * Configure various resize listeners for screen changes
  16813. */
  16814. function startRepositioningOnResize() {
  16815. var repositionMenu = (function(target, options) {
  16816. return $$rAF.throttle(function() {
  16817. if (opts.isRemoved) return;
  16818. var position = calculateMenuPosition(target, options);
  16819. target.css(animator.toCss(position));
  16820. });
  16821. })(element, opts);
  16822. $window.addEventListener('resize', repositionMenu);
  16823. $window.addEventListener('orientationchange', repositionMenu);
  16824. return function stopRepositioningOnResize() {
  16825. // Disable resizing handlers
  16826. $window.removeEventListener('resize', repositionMenu);
  16827. $window.removeEventListener('orientationchange', repositionMenu);
  16828. }
  16829. }
  16830. /**
  16831. * Activate interaction on the menu. Wire up keyboard listerns for
  16832. * clicks, keypresses, backdrop closing, etc.
  16833. */
  16834. function activateInteraction() {
  16835. element.addClass('md-clickable');
  16836. // close on backdrop click
  16837. if (opts.backdrop) opts.backdrop.on('click', onBackdropClick);
  16838. // Wire up keyboard listeners.
  16839. // - Close on escape,
  16840. // - focus next item on down arrow,
  16841. // - focus prev item on up
  16842. opts.menuContentEl.on('keydown', onMenuKeyDown);
  16843. opts.menuContentEl[0].addEventListener('click', captureClickListener, true);
  16844. // kick off initial focus in the menu on the first element
  16845. var focusTarget = opts.menuContentEl[0].querySelector('[md-menu-focus-target]') ||
  16846. opts.menuContentEl[0].firstElementChild.querySelector('[tabindex]') ||
  16847. opts.menuContentEl[0].firstElementChild.firstElementChild;
  16848. focusTarget.focus();
  16849. return function cleanupInteraction() {
  16850. element.removeClass('md-clickable');
  16851. if (opts.backdrop) opts.backdrop.off('click', onBackdropClick);
  16852. opts.menuContentEl.off('keydown', onMenuKeyDown);
  16853. opts.menuContentEl[0].removeEventListener('click', captureClickListener, true);
  16854. };
  16855. // ************************************
  16856. // internal functions
  16857. // ************************************
  16858. function onMenuKeyDown(ev) {
  16859. var handled;
  16860. var keyCodes = $mdConstant.KEY_CODE;
  16861. switch (ev.keyCode) {
  16862. case $mdConstant.KEY_CODE.ESCAPE:
  16863. opts.mdMenuCtrl.close(true, { closeAll: true });
  16864. handled = true;
  16865. break;
  16866. case $mdConstant.KEY_CODE.UP_ARROW:
  16867. if (!focusMenuItem(ev, opts.menuContentEl, opts, -1)) {
  16868. opts.mdMenuCtrl.triggerContainerProxy(ev);
  16869. }
  16870. handled = true;
  16871. break;
  16872. case $mdConstant.KEY_CODE.DOWN_ARROW:
  16873. if (!focusMenuItem(ev, opts.menuContentEl, opts, 1)) {
  16874. opts.mdMenuCtrl.triggerContainerProxy(ev);
  16875. }
  16876. handled = true;
  16877. break;
  16878. case $mdConstant.KEY_CODE.LEFT_ARROW:
  16879. if (opts.nestLevel) {
  16880. opts.mdMenuCtrl.close();
  16881. } else {
  16882. opts.mdMenuCtrl.triggerContainerProxy(ev);
  16883. }
  16884. handled = true;
  16885. break;
  16886. case $mdConstant.KEY_CODE.RIGHT_ARROW:
  16887. var parentMenu = $mdUtil.getClosest(ev.target, 'MD-MENU');
  16888. if (parentMenu && parentMenu != opts.parent[0]) {
  16889. ev.target.click();
  16890. } else {
  16891. opts.mdMenuCtrl.triggerContainerProxy(ev);
  16892. }
  16893. handled = true;
  16894. break;
  16895. }
  16896. if (handled) {
  16897. ev.preventDefault();
  16898. ev.stopImmediatePropagation();
  16899. }
  16900. }
  16901. function onBackdropClick(e) {
  16902. e.preventDefault();
  16903. e.stopPropagation();
  16904. scope.$apply(function() {
  16905. opts.mdMenuCtrl.close(true, { closeAll: true });
  16906. });
  16907. }
  16908. // Close menu on menu item click, if said menu-item is not disabled
  16909. function captureClickListener(e) {
  16910. var target = e.target;
  16911. // Traverse up the event until we get to the menuContentEl to see if
  16912. // there is an ng-click and that the ng-click is not disabled
  16913. do {
  16914. if (target == opts.menuContentEl[0]) return;
  16915. if (hasAnyAttribute(target, ['ng-click', 'ng-href', 'ui-sref']) ||
  16916. target.nodeName == 'BUTTON' || target.nodeName == 'MD-BUTTON') {
  16917. var closestMenu = $mdUtil.getClosest(target, 'MD-MENU');
  16918. if (!target.hasAttribute('disabled') && (!closestMenu || closestMenu == opts.parent[0])) {
  16919. close();
  16920. }
  16921. break;
  16922. }
  16923. } while (target = target.parentNode)
  16924. function close() {
  16925. scope.$apply(function() {
  16926. opts.mdMenuCtrl.close(true, { closeAll: true });
  16927. });
  16928. }
  16929. function hasAnyAttribute(target, attrs) {
  16930. if (!target) return false;
  16931. for (var i = 0, attr; attr = attrs[i]; ++i) {
  16932. var altForms = [attr, 'data-' + attr, 'x-' + attr];
  16933. for (var j = 0, rawAttr; rawAttr = altForms[j]; ++j) {
  16934. if (target.hasAttribute(rawAttr)) {
  16935. return true;
  16936. }
  16937. }
  16938. }
  16939. return false;
  16940. }
  16941. }
  16942. opts.menuContentEl[0].addEventListener('click', captureClickListener, true);
  16943. return function cleanupInteraction() {
  16944. element.removeClass('md-clickable');
  16945. opts.menuContentEl.off('keydown');
  16946. opts.menuContentEl[0].removeEventListener('click', captureClickListener, true);
  16947. };
  16948. }
  16949. }
  16950. /**
  16951. * Takes a keypress event and focuses the next/previous menu
  16952. * item from the emitting element
  16953. * @param {event} e - The origin keypress event
  16954. * @param {angular.element} menuEl - The menu element
  16955. * @param {object} opts - The interim element options for the mdMenu
  16956. * @param {number} direction - The direction to move in (+1 = next, -1 = prev)
  16957. */
  16958. function focusMenuItem(e, menuEl, opts, direction) {
  16959. var currentItem = $mdUtil.getClosest(e.target, 'MD-MENU-ITEM');
  16960. var items = $mdUtil.nodesToArray(menuEl[0].children);
  16961. var currentIndex = items.indexOf(currentItem);
  16962. // Traverse through our elements in the specified direction (+/-1) and try to
  16963. // focus them until we find one that accepts focus
  16964. var didFocus;
  16965. for (var i = currentIndex + direction; i >= 0 && i < items.length; i = i + direction) {
  16966. var focusTarget = items[i].querySelector('.md-button');
  16967. didFocus = attemptFocus(focusTarget);
  16968. if (didFocus) {
  16969. break;
  16970. }
  16971. }
  16972. return didFocus;
  16973. }
  16974. /**
  16975. * Attempts to focus an element. Checks whether that element is the currently
  16976. * focused element after attempting.
  16977. * @param {HTMLElement} el - the element to attempt focus on
  16978. * @returns {bool} - whether the element was successfully focused
  16979. */
  16980. function attemptFocus(el) {
  16981. if (el && el.getAttribute('tabindex') != -1) {
  16982. el.focus();
  16983. return ($document[0].activeElement == el);
  16984. }
  16985. }
  16986. /**
  16987. * Use browser to remove this element without triggering a $destory event
  16988. */
  16989. function detachElement(element, opts) {
  16990. if (!opts.preserveElement) {
  16991. if (toNode(element).parentNode === toNode(opts.parent)) {
  16992. toNode(opts.parent).removeChild(toNode(element));
  16993. }
  16994. } else {
  16995. toNode(element).style.display = 'none';
  16996. }
  16997. }
  16998. /**
  16999. * Computes menu position and sets the style on the menu container
  17000. * @param {HTMLElement} el - the menu container element
  17001. * @param {object} opts - the interim element options object
  17002. */
  17003. function calculateMenuPosition(el, opts) {
  17004. var containerNode = el[0],
  17005. openMenuNode = el[0].firstElementChild,
  17006. openMenuNodeRect = openMenuNode.getBoundingClientRect(),
  17007. boundryNode = $document[0].body,
  17008. boundryNodeRect = boundryNode.getBoundingClientRect();
  17009. var menuStyle = $window.getComputedStyle(openMenuNode);
  17010. var originNode = opts.target[0].querySelector('[md-menu-origin]') || opts.target[0],
  17011. originNodeRect = originNode.getBoundingClientRect();
  17012. var bounds = {
  17013. left: boundryNodeRect.left + MENU_EDGE_MARGIN,
  17014. top: Math.max(boundryNodeRect.top, 0) + MENU_EDGE_MARGIN,
  17015. bottom: Math.max(boundryNodeRect.bottom, Math.max(boundryNodeRect.top, 0) + boundryNodeRect.height) - MENU_EDGE_MARGIN,
  17016. right: boundryNodeRect.right - MENU_EDGE_MARGIN
  17017. };
  17018. var alignTarget, alignTargetRect, existingOffsets;
  17019. var positionMode = opts.mdMenuCtrl.positionMode();
  17020. if (positionMode.top == 'target' || positionMode.left == 'target' || positionMode.left == 'target-right') {
  17021. // TODO: Allow centering on an arbitrary node, for now center on first menu-item's child
  17022. alignTarget = firstVisibleChild();
  17023. if (!alignTarget) {
  17024. throw Error('Error positioning menu. No visible children.');
  17025. }
  17026. alignTarget = alignTarget.firstElementChild || alignTarget;
  17027. alignTarget = alignTarget.querySelector('[md-menu-align-target]') || alignTarget;
  17028. alignTargetRect = alignTarget.getBoundingClientRect();
  17029. existingOffsets = {
  17030. top: parseFloat(containerNode.style.top || 0),
  17031. left: parseFloat(containerNode.style.left || 0)
  17032. };
  17033. }
  17034. var position = {};
  17035. var transformOrigin = 'top ';
  17036. switch (positionMode.top) {
  17037. case 'target':
  17038. position.top = existingOffsets.top + originNodeRect.top - alignTargetRect.top;
  17039. break;
  17040. case 'cascade':
  17041. position.top = originNodeRect.top - parseFloat(menuStyle.paddingTop) - originNode.style.top;
  17042. break;
  17043. case 'bottom':
  17044. position.top = originNodeRect.top + originNodeRect.height;
  17045. break;
  17046. default:
  17047. throw new Error('Invalid target mode "' + positionMode.top + '" specified for md-menu on Y axis.');
  17048. }
  17049. switch (positionMode.left) {
  17050. case 'target':
  17051. position.left = existingOffsets.left + originNodeRect.left - alignTargetRect.left;
  17052. transformOrigin += 'left';
  17053. break;
  17054. case 'target-right':
  17055. position.left = originNodeRect.right - openMenuNodeRect.width + (openMenuNodeRect.right - alignTargetRect.right);
  17056. transformOrigin += 'right';
  17057. break;
  17058. case 'cascade':
  17059. var willFitRight = (originNodeRect.right + openMenuNodeRect.width) < bounds.right;
  17060. position.left = willFitRight ? originNodeRect.right - originNode.style.left : originNodeRect.left - originNode.style.left - openMenuNodeRect.width;
  17061. transformOrigin += willFitRight ? 'left' : 'right';
  17062. break;
  17063. case 'left':
  17064. position.left = originNodeRect.left;
  17065. transformOrigin += 'left';
  17066. break;
  17067. default:
  17068. throw new Error('Invalid target mode "' + positionMode.left + '" specified for md-menu on X axis.');
  17069. }
  17070. var offsets = opts.mdMenuCtrl.offsets();
  17071. position.top += offsets.top;
  17072. position.left += offsets.left;
  17073. clamp(position);
  17074. var scaleX = Math.round(100 * Math.min(originNodeRect.width / containerNode.offsetWidth, 1.0)) / 100;
  17075. var scaleY = Math.round(100 * Math.min(originNodeRect.height / containerNode.offsetHeight, 1.0)) / 100;
  17076. return {
  17077. top: Math.round(position.top),
  17078. left: Math.round(position.left),
  17079. // Animate a scale out if we aren't just repositioning
  17080. transform: !opts.alreadyOpen ? $mdUtil.supplant('scale({0},{1})', [scaleX, scaleY]) : undefined,
  17081. transformOrigin: transformOrigin
  17082. };
  17083. /**
  17084. * Clamps the repositioning of the menu within the confines of
  17085. * bounding element (often the screen/body)
  17086. */
  17087. function clamp(pos) {
  17088. pos.top = Math.max(Math.min(pos.top, bounds.bottom - containerNode.offsetHeight), bounds.top);
  17089. pos.left = Math.max(Math.min(pos.left, bounds.right - containerNode.offsetWidth), bounds.left);
  17090. }
  17091. /**
  17092. * Gets the first visible child in the openMenuNode
  17093. * Necessary incase menu nodes are being dynamically hidden
  17094. */
  17095. function firstVisibleChild() {
  17096. for (var i = 0; i < openMenuNode.children.length; ++i) {
  17097. if ($window.getComputedStyle(openMenuNode.children[i]).display != 'none') {
  17098. return openMenuNode.children[i];
  17099. }
  17100. }
  17101. }
  17102. }
  17103. }
  17104. function toNode(el) {
  17105. if (el instanceof angular.element) {
  17106. el = el[0];
  17107. }
  17108. return el;
  17109. }
  17110. }
  17111. MenuProvider.$inject = ["$$interimElementProvider"];
  17112. })();
  17113. (function(){
  17114. "use strict";
  17115. angular
  17116. .module('material.components.menuBar')
  17117. .controller('MenuBarController', MenuBarController);
  17118. var BOUND_MENU_METHODS = ['handleKeyDown', 'handleMenuHover', 'scheduleOpenHoveredMenu', 'cancelScheduledOpen'];
  17119. /**
  17120. * @ngInject
  17121. */
  17122. function MenuBarController($scope, $element, $attrs, $mdConstant, $document, $mdUtil, $timeout) {
  17123. this.$element = $element;
  17124. this.$attrs = $attrs;
  17125. this.$mdConstant = $mdConstant;
  17126. this.$mdUtil = $mdUtil;
  17127. this.$document = $document;
  17128. this.$scope = $scope;
  17129. this.$timeout = $timeout;
  17130. var self = this;
  17131. angular.forEach(BOUND_MENU_METHODS, function(methodName) {
  17132. self[methodName] = angular.bind(self, self[methodName]);
  17133. });
  17134. }
  17135. MenuBarController.$inject = ["$scope", "$element", "$attrs", "$mdConstant", "$document", "$mdUtil", "$timeout"];
  17136. MenuBarController.prototype.init = function() {
  17137. var $element = this.$element;
  17138. var $mdUtil = this.$mdUtil;
  17139. var $scope = this.$scope;
  17140. var self = this;
  17141. $element.on('keydown', this.handleKeyDown);
  17142. this.parentToolbar = $mdUtil.getClosest($element, 'MD-TOOLBAR');
  17143. $scope.$on('$mdMenuOpen', function(event, el) {
  17144. if (self.getMenus().indexOf(el[0]) != -1) {
  17145. $element[0].classList.add('md-open');
  17146. el[0].classList.add('md-open');
  17147. self.currentlyOpenMenu = el.controller('mdMenu');
  17148. self.currentlyOpenMenu.registerContainerProxy(self.handleKeyDown);
  17149. self.enableOpenOnHover();
  17150. }
  17151. });
  17152. $scope.$on('$mdMenuClose', function(event, el) {
  17153. var rootMenus = self.getMenus();
  17154. if (rootMenus.indexOf(el[0]) != -1) {
  17155. $element[0].classList.remove('md-open');
  17156. el[0].classList.remove('md-open');
  17157. }
  17158. if ($element[0].contains(el[0])) {
  17159. var parentMenu = el[0];
  17160. while (parentMenu && rootMenus.indexOf(parentMenu) == -1) {
  17161. parentMenu = $mdUtil.getClosest(parentMenu, 'MD-MENU', true);
  17162. }
  17163. if (parentMenu) {
  17164. parentMenu.querySelector('button').focus();
  17165. self.currentlyOpenMenu = undefined;
  17166. self.disableOpenOnHover();
  17167. self.setKeyboardMode(true);
  17168. }
  17169. }
  17170. });
  17171. angular
  17172. .element(this.getMenus())
  17173. .on('mouseenter', this.handleMenuHover);
  17174. this.setKeyboardMode(true);
  17175. };
  17176. MenuBarController.prototype.setKeyboardMode = function(enabled) {
  17177. if (enabled) this.$element[0].classList.add('md-keyboard-mode');
  17178. else this.$element[0].classList.remove('md-keyboard-mode');
  17179. };
  17180. MenuBarController.prototype.enableOpenOnHover = function() {
  17181. if (this.openOnHoverEnabled) return;
  17182. this.openOnHoverEnabled = true;
  17183. var $element = this.$element;
  17184. var parentToolbar;
  17185. if (parentToolbar = this.parentToolbar) {
  17186. parentToolbar.dataset.mdRestoreStyle = parentToolbar.getAttribute('style');
  17187. parentToolbar.style.position = 'relative';
  17188. parentToolbar.style.zIndex = 100;
  17189. }
  17190. };
  17191. MenuBarController.prototype.handleMenuHover = function(e) {
  17192. this.setKeyboardMode(false);
  17193. if (this.openOnHoverEnabled) {
  17194. this.scheduleOpenHoveredMenu(e);
  17195. }
  17196. };
  17197. MenuBarController.prototype.disableOpenOnHover = function() {
  17198. if (!this.openOnHoverEnabled) return;
  17199. this.openOnHoverEnabled = false;
  17200. var parentToolbar;
  17201. if (parentToolbar = this.parentToolbar) {
  17202. parentToolbar.setAttribute('style', parentToolbar.dataset.mdRestoreStyle || '');
  17203. }
  17204. };
  17205. MenuBarController.prototype.scheduleOpenHoveredMenu = function(e) {
  17206. var menuEl = angular.element(e.currentTarget);
  17207. var menuCtrl = menuEl.controller('mdMenu');
  17208. this.setKeyboardMode(false);
  17209. this.scheduleOpenMenu(menuCtrl);
  17210. };
  17211. MenuBarController.prototype.scheduleOpenMenu = function(menuCtrl) {
  17212. var self = this;
  17213. var $timeout = this.$timeout;
  17214. if (menuCtrl != self.currentlyOpenMenu) {
  17215. $timeout.cancel(self.pendingMenuOpen);
  17216. self.pendingMenuOpen = $timeout(function() {
  17217. self.pendingMenuOpen = undefined;
  17218. if (self.currentlyOpenMenu) {
  17219. self.currentlyOpenMenu.close(true, { closeAll: true });
  17220. }
  17221. menuCtrl.open();
  17222. }, 200, false);
  17223. }
  17224. }
  17225. MenuBarController.prototype.handleKeyDown = function(e) {
  17226. var keyCodes = this.$mdConstant.KEY_CODE;
  17227. var currentMenu = this.currentlyOpenMenu;
  17228. var wasOpen = currentMenu && currentMenu.isOpen;
  17229. this.setKeyboardMode(true);
  17230. var handled;
  17231. switch (e.keyCode) {
  17232. case keyCodes.DOWN_ARROW:
  17233. if (currentMenu) {
  17234. currentMenu.focusMenuContainer();
  17235. } else {
  17236. this.openFocusedMenu();
  17237. }
  17238. handled = true;
  17239. break;
  17240. case keyCodes.UP_ARROW:
  17241. currentMenu && currentMenu.close();
  17242. handled = true;
  17243. break;
  17244. case keyCodes.LEFT_ARROW:
  17245. var newMenu = this.focusMenu(-1);
  17246. if (wasOpen) {
  17247. var newMenuCtrl = angular.element(newMenu).controller('mdMenu');
  17248. this.scheduleOpenMenu(newMenuCtrl);
  17249. }
  17250. handled = true;
  17251. break;
  17252. case keyCodes.RIGHT_ARROW:
  17253. var newMenu = this.focusMenu(+1);
  17254. if (wasOpen) {
  17255. var newMenuCtrl = angular.element(newMenu).controller('mdMenu');
  17256. this.scheduleOpenMenu(newMenuCtrl);
  17257. }
  17258. handled = true;
  17259. break;
  17260. }
  17261. if (handled) {
  17262. e && e.preventDefault && e.preventDefault();
  17263. e && e.stopImmediatePropagation && e.stopImmediatePropagation();
  17264. }
  17265. };
  17266. MenuBarController.prototype.focusMenu = function(direction) {
  17267. var menus = this.getMenus();
  17268. var focusedIndex = this.getFocusedMenuIndex();
  17269. if (focusedIndex == -1) { focusedIndex = this.getOpenMenuIndex(); }
  17270. var changed = false;
  17271. if (focusedIndex == -1) { focusedIndex = 0; }
  17272. else if (
  17273. direction < 0 && focusedIndex > 0 ||
  17274. direction > 0 && focusedIndex < menus.length - direction
  17275. ) {
  17276. focusedIndex += direction;
  17277. changed = true;
  17278. }
  17279. if (changed) {
  17280. menus[focusedIndex].querySelector('button').focus();
  17281. return menus[focusedIndex];
  17282. }
  17283. };
  17284. MenuBarController.prototype.openFocusedMenu = function() {
  17285. var menu = this.getFocusedMenu();
  17286. menu && angular.element(menu).controller('mdMenu').open();
  17287. };
  17288. MenuBarController.prototype.getMenus = function() {
  17289. var $element = this.$element;
  17290. return this.$mdUtil.nodesToArray($element[0].children)
  17291. .filter(function(el) { return el.nodeName == 'MD-MENU'; });
  17292. };
  17293. MenuBarController.prototype.getFocusedMenu = function() {
  17294. return this.getMenus()[this.getFocusedMenuIndex()];
  17295. };
  17296. MenuBarController.prototype.getFocusedMenuIndex = function() {
  17297. var $mdUtil = this.$mdUtil;
  17298. var $element = this.$element;
  17299. var focusedEl = $mdUtil.getClosest(
  17300. this.$document[0].activeElement,
  17301. 'MD-MENU'
  17302. );
  17303. if (!focusedEl) return -1;
  17304. var focusedIndex = this.getMenus().indexOf(focusedEl);
  17305. return focusedIndex;
  17306. };
  17307. MenuBarController.prototype.getOpenMenuIndex = function() {
  17308. var menus = this.getMenus();
  17309. for (var i = 0; i < menus.length; ++i) {
  17310. if (menus[i].classList.contains('md-open')) return i;
  17311. }
  17312. return -1;
  17313. };
  17314. })();
  17315. (function(){
  17316. "use strict";
  17317. /**
  17318. * @ngdoc directive
  17319. * @name mdMenuBar
  17320. * @module material.components.menu-bar
  17321. * @restrict E
  17322. * @description
  17323. *
  17324. * Menu bars are containers that hold multiple menus. They change the behavior and appearence
  17325. * of the `md-menu` directive to behave similar to an operating system provided menu.
  17326. *
  17327. * @usage
  17328. * <hljs lang="html">
  17329. * <md-menu-bar>
  17330. * <md-menu>
  17331. * <button ng-click="$mdOpenMenu()">
  17332. * File
  17333. * </button>
  17334. * <md-menu-content>
  17335. * <md-menu-item>
  17336. * <md-button ng-click="ctrl.sampleAction('share', $event)">
  17337. * Share...
  17338. * </md-button>
  17339. * </md-menu-item>
  17340. * <md-menu-divider></md-menu-divider>
  17341. * <md-menu-item>
  17342. * <md-menu-item>
  17343. * <md-menu>
  17344. * <md-button ng-click="$mdOpenMenu()">New</md-button>
  17345. * <md-menu-content>
  17346. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Document', $event)">Document</md-button></md-menu-item>
  17347. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Spreadsheet', $event)">Spreadsheet</md-button></md-menu-item>
  17348. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Presentation', $event)">Presentation</md-button></md-menu-item>
  17349. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Form', $event)">Form</md-button></md-menu-item>
  17350. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Drawing', $event)">Drawing</md-button></md-menu-item>
  17351. * </md-menu-content>
  17352. * </md-menu>
  17353. * </md-menu-item>
  17354. * </md-menu-content>
  17355. * </md-menu>
  17356. * </md-menu-bar>
  17357. * </hljs>
  17358. *
  17359. * ## Menu Bar Controls
  17360. *
  17361. * You may place `md-menu-items` that function as controls within menu bars.
  17362. * There are two modes that are exposed via the `type` attribute of the `md-menu-item`.
  17363. * `type="checkbox"` will function as a boolean control for the `ng-model` attribute of the
  17364. * `md-menu-item`. `type="radio"` will function like a radio button, setting the `ngModel`
  17365. * to the `string` value of the `value` attribute. If you need non-string values, you can use
  17366. * `ng-value` to provide an expression (this is similar to how angular's native `input[type=radio]` works.
  17367. *
  17368. * <hljs lang="html">
  17369. * <md-menu-bar>
  17370. * <md-menu>
  17371. * <button ng-click="$mdOpenMenu()">
  17372. * Sample Menu
  17373. * </button>
  17374. * <md-menu-content>
  17375. * <md-menu-item type="checkbox" ng-model="settings.allowChanges">Allow changes</md-menu-item>
  17376. * <md-menu-divider></md-menu-divider>
  17377. * <md-menu-item type="radio" ng-model="settings.mode" ng-value="1">Mode 1</md-menu-item>
  17378. * <md-menu-item type="radio" ng-model="settings.mode" ng-value="1">Mode 2</md-menu-item>
  17379. * <md-menu-item type="radio" ng-model="settings.mode" ng-value="1">Mode 3</md-menu-item>
  17380. * </md-menu-content>
  17381. * </md-menu>
  17382. * </md-menu-bar>
  17383. * </hljs>
  17384. *
  17385. *
  17386. * ### Nesting Menus
  17387. *
  17388. * Menus may be nested within menu bars. This is commonly called cascading menus.
  17389. * To nest a menu place the nested menu inside the content of the `md-menu-item`.
  17390. * <hljs lang="html">
  17391. * <md-menu-item>
  17392. * <md-menu>
  17393. * <button ng-click="$mdOpenMenu()">New</md-button>
  17394. * <md-menu-content>
  17395. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Document', $event)">Document</md-button></md-menu-item>
  17396. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Spreadsheet', $event)">Spreadsheet</md-button></md-menu-item>
  17397. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Presentation', $event)">Presentation</md-button></md-menu-item>
  17398. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Form', $event)">Form</md-button></md-menu-item>
  17399. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Drawing', $event)">Drawing</md-button></md-menu-item>
  17400. * </md-menu-content>
  17401. * </md-menu>
  17402. * </md-menu-item>
  17403. * </hljs>
  17404. *
  17405. */
  17406. angular
  17407. .module('material.components.menuBar')
  17408. .directive('mdMenuBar', MenuBarDirective);
  17409. /**
  17410. *
  17411. * @ngInjdect
  17412. */
  17413. function MenuBarDirective($mdUtil, $mdTheming) {
  17414. return {
  17415. restrict: 'E',
  17416. require: 'mdMenuBar',
  17417. controller: 'MenuBarController',
  17418. compile: function compile(templateEl, templateAttrs) {
  17419. if (!templateAttrs.ariaRole) {
  17420. templateEl[0].setAttribute('role', 'menubar');
  17421. }
  17422. angular.forEach(templateEl[0].children, function(menuEl) {
  17423. if (menuEl.nodeName == 'MD-MENU') {
  17424. if (!menuEl.hasAttribute('md-position-mode')) {
  17425. menuEl.setAttribute('md-position-mode', 'left bottom');
  17426. }
  17427. menuEl.setAttribute('role', 'menu');
  17428. var contentEls = $mdUtil.nodesToArray(menuEl.querySelectorAll('md-menu-content'));
  17429. angular.forEach(contentEls, function(contentEl) {
  17430. contentEl.classList.add('md-menu-bar-menu');
  17431. contentEl.classList.add('md-dense');
  17432. if (!contentEl.hasAttribute('width')) {
  17433. contentEl.setAttribute('width', 5);
  17434. }
  17435. });
  17436. }
  17437. });
  17438. return function postLink(scope, el, attrs, ctrl) {
  17439. $mdTheming(scope, el);
  17440. ctrl.init();
  17441. };
  17442. }
  17443. };
  17444. }
  17445. MenuBarDirective.$inject = ["$mdUtil", "$mdTheming"];
  17446. })();
  17447. (function(){
  17448. "use strict";
  17449. angular
  17450. .module('material.components.menuBar')
  17451. .directive('mdMenuDivider', MenuDividerDirective);
  17452. function MenuDividerDirective() {
  17453. return {
  17454. restrict: 'E',
  17455. compile: function(templateEl, templateAttrs) {
  17456. if (!templateAttrs.role) {
  17457. templateEl[0].setAttribute('role', 'separator');
  17458. }
  17459. }
  17460. };
  17461. }
  17462. })();
  17463. (function(){
  17464. "use strict";
  17465. angular
  17466. .module('material.components.menuBar')
  17467. .controller('MenuItemController', MenuItemController);
  17468. /**
  17469. * @ngInject
  17470. */
  17471. function MenuItemController($scope, $element, $attrs) {
  17472. this.$element = $element;
  17473. this.$attrs = $attrs;
  17474. this.$scope = $scope;
  17475. }
  17476. MenuItemController.$inject = ["$scope", "$element", "$attrs"];
  17477. MenuItemController.prototype.init = function(ngModel) {
  17478. var $element = this.$element;
  17479. var $attrs = this.$attrs;
  17480. this.ngModel = ngModel;
  17481. if ($attrs.type == 'checkbox' || $attrs.type == 'radio') {
  17482. this.mode = $attrs.type;
  17483. this.iconEl = $element[0].children[0];
  17484. this.buttonEl = $element[0].children[1];
  17485. if (ngModel) this.initClickListeners();
  17486. }
  17487. };
  17488. MenuItemController.prototype.initClickListeners = function() {
  17489. var ngModel = this.ngModel;
  17490. var $scope = this.$scope;
  17491. var $attrs = this.$attrs;
  17492. var $element = this.$element;
  17493. var mode = this.mode;
  17494. this.handleClick = angular.bind(this, this.handleClick);
  17495. var icon = this.iconEl
  17496. var button = angular.element(this.buttonEl);
  17497. var handleClick = this.handleClick;
  17498. $attrs.$observe('disabled', setDisabled);
  17499. setDisabled($attrs.disabled);
  17500. ngModel.$render = function render() {
  17501. if (isSelected()) {
  17502. icon.style.display = '';
  17503. $element.attr('aria-checked', 'true');
  17504. } else {
  17505. icon.style.display = 'none';
  17506. $element.attr('aria-checked', 'false');
  17507. }
  17508. };
  17509. $scope.$$postDigest(ngModel.$render);
  17510. function isSelected() {
  17511. if (mode == 'radio') {
  17512. var val = $attrs.ngValue ? $scope.$eval($attrs.ngValue) : $attrs.value;
  17513. return ngModel.$modelValue == val;
  17514. } else {
  17515. return ngModel.$modelValue;
  17516. }
  17517. }
  17518. function setDisabled(disabled) {
  17519. if (disabled) {
  17520. button.off('click', handleClick);
  17521. } else {
  17522. button.on('click', handleClick);
  17523. }
  17524. }
  17525. };
  17526. MenuItemController.prototype.handleClick = function(e) {
  17527. var mode = this.mode;
  17528. var ngModel = this.ngModel;
  17529. var $attrs = this.$attrs;
  17530. var newVal;
  17531. if (mode == 'checkbox') {
  17532. newVal = !ngModel.$modelValue;
  17533. } else if (mode == 'radio') {
  17534. newVal = $attrs.ngValue ? this.$scope.$eval($attrs.ngValue) : $attrs.value;
  17535. }
  17536. ngModel.$setViewValue(newVal);
  17537. ngModel.$render();
  17538. };
  17539. })();
  17540. (function(){
  17541. "use strict";
  17542. angular
  17543. .module('material.components.menuBar')
  17544. .directive('mdMenuItem', MenuItemDirective);
  17545. /**
  17546. *
  17547. * @ngInjdect
  17548. */
  17549. function MenuItemDirective() {
  17550. return {
  17551. require: ['mdMenuItem', '?ngModel'],
  17552. compile: function(templateEl, templateAttrs) {
  17553. if (templateAttrs.type == 'checkbox' || templateAttrs.type == 'radio') {
  17554. var text = templateEl[0].textContent;
  17555. var buttonEl = angular.element('<md-button type="button"></md-button>');
  17556. buttonEl.html(text);
  17557. buttonEl.attr('tabindex', '0');
  17558. templateEl.html('');
  17559. templateEl.append(angular.element('<md-icon md-svg-icon="check"></md-icon>'));
  17560. templateEl.append(buttonEl);
  17561. templateEl[0].classList.add('md-indent');
  17562. setDefault('role', (templateAttrs.type == 'checkbox') ? 'menuitemcheckbox' : 'menuitemradio');
  17563. angular.forEach(['ng-disabled'], moveAttrToButton);
  17564. } else {
  17565. setDefault('role', 'menuitem');
  17566. }
  17567. return function(scope, el, attrs, ctrls) {
  17568. var ctrl = ctrls[0];
  17569. var ngModel = ctrls[1];
  17570. ctrl.init(ngModel);
  17571. };
  17572. function setDefault(attr, val) {
  17573. if (!templateEl[0].hasAttribute(attr)) {
  17574. templateEl[0].setAttribute(attr, val);
  17575. }
  17576. }
  17577. function moveAttrToButton(attr) {
  17578. if (templateEl[0].hasAttribute(attr)) {
  17579. var val = templateEl[0].getAttribute(attr);
  17580. buttonEl[0].setAttribute(attr, val);
  17581. templateEl[0].removeAttribute(attr);
  17582. }
  17583. }
  17584. },
  17585. controller: 'MenuItemController'
  17586. };
  17587. }
  17588. })();
  17589. (function(){
  17590. "use strict";
  17591. /**
  17592. * @ngdoc directive
  17593. * @name mdTab
  17594. * @module material.components.tabs
  17595. *
  17596. * @restrict E
  17597. *
  17598. * @description
  17599. * Use the `<md-tab>` a nested directive used within `<md-tabs>` to specify a tab with a **label** and optional *view content*.
  17600. *
  17601. * If the `label` attribute is not specified, then an optional `<md-tab-label>` tag can be used to specify more
  17602. * complex tab header markup. If neither the **label** nor the **md-tab-label** are specified, then the nested
  17603. * markup of the `<md-tab>` is used as the tab header markup.
  17604. *
  17605. * Please note that if you use `<md-tab-label>`, your content **MUST** be wrapped in the `<md-tab-body>` tag. This
  17606. * is to define a clear separation between the tab content and the tab label.
  17607. *
  17608. * If a tab **label** has been identified, then any **non-**`<md-tab-label>` markup
  17609. * will be considered tab content and will be transcluded to the internal `<div class="md-tabs-content">` container.
  17610. *
  17611. * This container is used by the TabsController to show/hide the active tab's content view. This synchronization is
  17612. * automatically managed by the internal TabsController whenever the tab selection changes. Selection changes can
  17613. * be initiated via data binding changes, programmatic invocation, or user gestures.
  17614. *
  17615. * @param {string=} label Optional attribute to specify a simple string as the tab label
  17616. * @param {boolean=} disabled If present, disabled tab selection.
  17617. * @param {expression=} md-on-deselect Expression to be evaluated after the tab has been de-selected.
  17618. * @param {expression=} md-on-select Expression to be evaluated after the tab has been selected.
  17619. *
  17620. *
  17621. * @usage
  17622. *
  17623. * <hljs lang="html">
  17624. * <md-tab label="" disabled="" md-on-select="" md-on-deselect="" >
  17625. * <h3>My Tab content</h3>
  17626. * </md-tab>
  17627. *
  17628. * <md-tab >
  17629. * <md-tab-label>
  17630. * <h3>My Tab content</h3>
  17631. * </md-tab-label>
  17632. * <md-tab-body>
  17633. * <p>
  17634. * Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,
  17635. * totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
  17636. * dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit,
  17637. * sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
  17638. * </p>
  17639. * </md-tab-body>
  17640. * </md-tab>
  17641. * </hljs>
  17642. *
  17643. */
  17644. angular
  17645. .module('material.components.tabs')
  17646. .directive('mdTab', MdTab);
  17647. function MdTab () {
  17648. return {
  17649. require: '^?mdTabs',
  17650. terminal: true,
  17651. compile: function (element, attr) {
  17652. var label = element.find('md-tab-label'),
  17653. body = element.find('md-tab-body');
  17654. if (label.length == 0) {
  17655. label = angular.element('<md-tab-label></md-tab-label>');
  17656. if (attr.label) label.text(attr.label);
  17657. else label.append(element.contents());
  17658. }
  17659. if (body.length == 0) {
  17660. var contents = element.contents().detach();
  17661. body = angular.element('<md-tab-body></md-tab-body>');
  17662. body.append(contents);
  17663. }
  17664. element.append(label);
  17665. if (body.html()) element.append(body);
  17666. return postLink;
  17667. },
  17668. scope: {
  17669. active: '=?mdActive',
  17670. disabled: '=?ngDisabled',
  17671. select: '&?mdOnSelect',
  17672. deselect: '&?mdOnDeselect'
  17673. }
  17674. };
  17675. function postLink (scope, element, attr, ctrl) {
  17676. if (!ctrl) return;
  17677. var index = ctrl.getTabElementIndex(element),
  17678. body = element.find('md-tab-body').eq(0).remove(),
  17679. label = element.find('md-tab-label').eq(0).remove(),
  17680. data = ctrl.insertTab({
  17681. scope: scope,
  17682. parent: scope.$parent,
  17683. index: index,
  17684. element: element,
  17685. template: body.html(),
  17686. label: label.html()
  17687. }, index);
  17688. scope.select = scope.select || angular.noop;
  17689. scope.deselect = scope.deselect || angular.noop;
  17690. scope.$watch('active', function (active) { if (active) ctrl.select(data.getIndex()); });
  17691. scope.$watch('disabled', function () { ctrl.refreshIndex(); });
  17692. scope.$watch(
  17693. function () {
  17694. return ctrl.getTabElementIndex(element);
  17695. },
  17696. function (newIndex) {
  17697. data.index = newIndex;
  17698. ctrl.updateTabOrder();
  17699. }
  17700. );
  17701. scope.$on('$destroy', function () { ctrl.removeTab(data); });
  17702. }
  17703. }
  17704. })();
  17705. (function(){
  17706. "use strict";
  17707. angular
  17708. .module('material.components.tabs')
  17709. .directive('mdTabItem', MdTabItem);
  17710. function MdTabItem () {
  17711. return {
  17712. require: '^?mdTabs',
  17713. link: function link (scope, element, attr, ctrl) {
  17714. if (!ctrl) return;
  17715. ctrl.attachRipple(scope, element);
  17716. }
  17717. };
  17718. }
  17719. })();
  17720. (function(){
  17721. "use strict";
  17722. angular
  17723. .module('material.components.tabs')
  17724. .directive('mdTabLabel', MdTabLabel);
  17725. function MdTabLabel () {
  17726. return { terminal: true };
  17727. }
  17728. })();
  17729. (function(){
  17730. "use strict";
  17731. angular.module('material.components.tabs')
  17732. .directive('mdTabScroll', MdTabScroll);
  17733. function MdTabScroll ($parse) {
  17734. return {
  17735. restrict: 'A',
  17736. compile: function ($element, attr) {
  17737. var fn = $parse(attr.mdTabScroll, null, true);
  17738. return function ngEventHandler (scope, element) {
  17739. element.on('mousewheel', function (event) {
  17740. scope.$apply(function () { fn(scope, { $event: event }); });
  17741. });
  17742. };
  17743. }
  17744. }
  17745. }
  17746. MdTabScroll.$inject = ["$parse"];
  17747. })();
  17748. (function(){
  17749. "use strict";
  17750. angular
  17751. .module('material.components.tabs')
  17752. .controller('MdTabsController', MdTabsController);
  17753. /**
  17754. * @ngInject
  17755. */
  17756. function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipple,
  17757. $mdUtil, $animateCss, $attrs, $compile, $mdTheming) {
  17758. // define private properties
  17759. var ctrl = this,
  17760. locked = false,
  17761. elements = getElements(),
  17762. queue = [],
  17763. destroyed = false,
  17764. loaded = false;
  17765. // define one-way bindings
  17766. defineOneWayBinding('stretchTabs', handleStretchTabs);
  17767. // define public properties with change handlers
  17768. defineProperty('focusIndex', handleFocusIndexChange, ctrl.selectedIndex || 0);
  17769. defineProperty('offsetLeft', handleOffsetChange, 0);
  17770. defineProperty('hasContent', handleHasContent, false);
  17771. defineProperty('maxTabWidth', handleMaxTabWidth, getMaxTabWidth());
  17772. defineProperty('shouldPaginate', handleShouldPaginate, false);
  17773. // define boolean attributes
  17774. defineBooleanAttribute('noInkBar', handleInkBar);
  17775. defineBooleanAttribute('dynamicHeight', handleDynamicHeight);
  17776. defineBooleanAttribute('noPagination');
  17777. defineBooleanAttribute('swipeContent');
  17778. defineBooleanAttribute('noDisconnect');
  17779. defineBooleanAttribute('autoselect');
  17780. defineBooleanAttribute('centerTabs', handleCenterTabs);
  17781. defineBooleanAttribute('enableDisconnect');
  17782. // define public properties
  17783. ctrl.scope = $scope;
  17784. ctrl.parent = $scope.$parent;
  17785. ctrl.tabs = [];
  17786. ctrl.lastSelectedIndex = null;
  17787. ctrl.hasFocus = false;
  17788. ctrl.lastClick = true;
  17789. ctrl.shouldCenterTabs = shouldCenterTabs();
  17790. // define public methods
  17791. ctrl.updatePagination = $mdUtil.debounce(updatePagination, 100);
  17792. ctrl.redirectFocus = redirectFocus;
  17793. ctrl.attachRipple = attachRipple;
  17794. ctrl.insertTab = insertTab;
  17795. ctrl.removeTab = removeTab;
  17796. ctrl.select = select;
  17797. ctrl.scroll = scroll;
  17798. ctrl.nextPage = nextPage;
  17799. ctrl.previousPage = previousPage;
  17800. ctrl.keydown = keydown;
  17801. ctrl.canPageForward = canPageForward;
  17802. ctrl.canPageBack = canPageBack;
  17803. ctrl.refreshIndex = refreshIndex;
  17804. ctrl.incrementIndex = incrementIndex;
  17805. ctrl.getTabElementIndex = getTabElementIndex;
  17806. ctrl.updateInkBarStyles = $mdUtil.debounce(updateInkBarStyles, 100);
  17807. ctrl.updateTabOrder = $mdUtil.debounce(updateTabOrder, 100);
  17808. init();
  17809. /**
  17810. * Perform initialization for the controller, setup events and watcher(s)
  17811. */
  17812. function init () {
  17813. ctrl.selectedIndex = ctrl.selectedIndex || 0;
  17814. compileTemplate();
  17815. configureWatchers();
  17816. bindEvents();
  17817. $mdTheming($element);
  17818. $mdUtil.nextTick(function () {
  17819. updateHeightFromContent();
  17820. adjustOffset();
  17821. updateInkBarStyles();
  17822. ctrl.tabs[ ctrl.selectedIndex ] && ctrl.tabs[ ctrl.selectedIndex ].scope.select();
  17823. loaded = true;
  17824. updatePagination();
  17825. });
  17826. }
  17827. /**
  17828. * Compiles the template provided by the user. This is passed as an attribute from the tabs
  17829. * directive's template function.
  17830. */
  17831. function compileTemplate () {
  17832. var template = $attrs.$mdTabsTemplate,
  17833. element = angular.element(elements.data);
  17834. element.html(template);
  17835. $compile(element.contents())(ctrl.parent);
  17836. delete $attrs.$mdTabsTemplate;
  17837. }
  17838. /**
  17839. * Binds events used by the tabs component.
  17840. */
  17841. function bindEvents () {
  17842. angular.element($window).on('resize', handleWindowResize);
  17843. $scope.$on('$destroy', cleanup);
  17844. }
  17845. /**
  17846. * Configure watcher(s) used by Tabs
  17847. */
  17848. function configureWatchers () {
  17849. $scope.$watch('$mdTabsCtrl.selectedIndex', handleSelectedIndexChange);
  17850. }
  17851. /**
  17852. * Creates a one-way binding manually rather than relying on Angular's isolated scope
  17853. * @param key
  17854. * @param handler
  17855. */
  17856. function defineOneWayBinding (key, handler) {
  17857. var attr = $attrs.$normalize('md-' + key);
  17858. if (handler) defineProperty(key, handler);
  17859. $attrs.$observe(attr, function (newValue) { ctrl[ key ] = newValue; });
  17860. }
  17861. /**
  17862. * Defines boolean attributes with default value set to true. (ie. md-stretch-tabs with no value
  17863. * will be treated as being truthy)
  17864. * @param key
  17865. * @param handler
  17866. */
  17867. function defineBooleanAttribute (key, handler) {
  17868. var attr = $attrs.$normalize('md-' + key);
  17869. if (handler) defineProperty(key, handler);
  17870. if ($attrs.hasOwnProperty(attr)) updateValue($attrs[attr]);
  17871. $attrs.$observe(attr, updateValue);
  17872. function updateValue (newValue) {
  17873. ctrl[ key ] = newValue !== 'false';
  17874. }
  17875. }
  17876. /**
  17877. * Remove any events defined by this controller
  17878. */
  17879. function cleanup () {
  17880. destroyed = true;
  17881. angular.element($window).off('resize', handleWindowResize);
  17882. }
  17883. // Change handlers
  17884. /**
  17885. * Toggles stretch tabs class and updates inkbar when tab stretching changes
  17886. * @param stretchTabs
  17887. */
  17888. function handleStretchTabs (stretchTabs) {
  17889. angular.element(elements.wrapper).toggleClass('md-stretch-tabs', shouldStretchTabs());
  17890. updateInkBarStyles();
  17891. }
  17892. function handleCenterTabs (newValue) {
  17893. ctrl.shouldCenterTabs = shouldCenterTabs();
  17894. }
  17895. function handleMaxTabWidth (newWidth, oldWidth) {
  17896. if (newWidth !== oldWidth) {
  17897. $mdUtil.nextTick(ctrl.updateInkBarStyles);
  17898. }
  17899. }
  17900. function handleShouldPaginate (newValue, oldValue) {
  17901. if (newValue !== oldValue) {
  17902. ctrl.maxTabWidth = getMaxTabWidth();
  17903. ctrl.shouldCenterTabs = shouldCenterTabs();
  17904. $mdUtil.nextTick(function () {
  17905. ctrl.maxTabWidth = getMaxTabWidth();
  17906. adjustOffset(ctrl.selectedIndex);
  17907. });
  17908. }
  17909. }
  17910. /**
  17911. * Add/remove the `md-no-tab-content` class depending on `ctrl.hasContent`
  17912. * @param hasContent
  17913. */
  17914. function handleHasContent (hasContent) {
  17915. $element[ hasContent ? 'removeClass' : 'addClass' ]('md-no-tab-content');
  17916. }
  17917. /**
  17918. * Apply ctrl.offsetLeft to the paging element when it changes
  17919. * @param left
  17920. */
  17921. function handleOffsetChange (left) {
  17922. var newValue = ctrl.shouldCenterTabs ? '' : '-' + left + 'px';
  17923. angular.element(elements.paging).css($mdConstant.CSS.TRANSFORM, 'translate3d(' + newValue + ', 0, 0)');
  17924. $scope.$broadcast('$mdTabsPaginationChanged');
  17925. }
  17926. /**
  17927. * Update the UI whenever `ctrl.focusIndex` is updated
  17928. * @param newIndex
  17929. * @param oldIndex
  17930. */
  17931. function handleFocusIndexChange (newIndex, oldIndex) {
  17932. if (newIndex === oldIndex) return;
  17933. if (!elements.tabs[ newIndex ]) return;
  17934. adjustOffset();
  17935. redirectFocus();
  17936. }
  17937. /**
  17938. * Update the UI whenever the selected index changes. Calls user-defined select/deselect methods.
  17939. * @param newValue
  17940. * @param oldValue
  17941. */
  17942. function handleSelectedIndexChange (newValue, oldValue) {
  17943. if (newValue === oldValue) return;
  17944. ctrl.selectedIndex = getNearestSafeIndex(newValue);
  17945. ctrl.lastSelectedIndex = oldValue;
  17946. ctrl.updateInkBarStyles();
  17947. updateHeightFromContent();
  17948. adjustOffset(newValue);
  17949. $scope.$broadcast('$mdTabsChanged');
  17950. ctrl.tabs[ oldValue ] && ctrl.tabs[ oldValue ].scope.deselect();
  17951. ctrl.tabs[ newValue ] && ctrl.tabs[ newValue ].scope.select();
  17952. }
  17953. function getTabElementIndex(tabEl){
  17954. var tabs = $element[0].getElementsByTagName('md-tab');
  17955. return Array.prototype.indexOf.call(tabs, tabEl[0]);
  17956. }
  17957. /**
  17958. * Queues up a call to `handleWindowResize` when a resize occurs while the tabs component is
  17959. * hidden.
  17960. */
  17961. function handleResizeWhenVisible () {
  17962. // if there is already a watcher waiting for resize, do nothing
  17963. if (handleResizeWhenVisible.watcher) return;
  17964. // otherwise, we will abuse the $watch function to check for visible
  17965. handleResizeWhenVisible.watcher = $scope.$watch(function () {
  17966. // since we are checking for DOM size, we use $mdUtil.nextTick() to wait for after the DOM updates
  17967. $mdUtil.nextTick(function () {
  17968. // if the watcher has already run (ie. multiple digests in one cycle), do nothing
  17969. if (!handleResizeWhenVisible.watcher) return;
  17970. if ($element.prop('offsetParent')) {
  17971. handleResizeWhenVisible.watcher();
  17972. handleResizeWhenVisible.watcher = null;
  17973. // we have to trigger our own $apply so that the DOM bindings will update
  17974. handleWindowResize();
  17975. }
  17976. }, false);
  17977. });
  17978. }
  17979. // Event handlers / actions
  17980. /**
  17981. * Handle user keyboard interactions
  17982. * @param event
  17983. */
  17984. function keydown (event) {
  17985. switch (event.keyCode) {
  17986. case $mdConstant.KEY_CODE.LEFT_ARROW:
  17987. event.preventDefault();
  17988. incrementIndex(-1, true);
  17989. break;
  17990. case $mdConstant.KEY_CODE.RIGHT_ARROW:
  17991. event.preventDefault();
  17992. incrementIndex(1, true);
  17993. break;
  17994. case $mdConstant.KEY_CODE.SPACE:
  17995. case $mdConstant.KEY_CODE.ENTER:
  17996. event.preventDefault();
  17997. if (!locked) ctrl.selectedIndex = ctrl.focusIndex;
  17998. break;
  17999. }
  18000. ctrl.lastClick = false;
  18001. }
  18002. /**
  18003. * Update the selected index and trigger a click event on the original `md-tab` element in order
  18004. * to fire user-added click events.
  18005. * @param index
  18006. */
  18007. function select (index) {
  18008. if (!locked) ctrl.focusIndex = ctrl.selectedIndex = index;
  18009. ctrl.lastClick = true;
  18010. // nextTick is required to prevent errors in user-defined click events
  18011. $mdUtil.nextTick(function () {
  18012. ctrl.tabs[ index ].element.triggerHandler('click');
  18013. }, false);
  18014. }
  18015. /**
  18016. * When pagination is on, this makes sure the selected index is in view.
  18017. * @param event
  18018. */
  18019. function scroll (event) {
  18020. if (!ctrl.shouldPaginate) return;
  18021. event.preventDefault();
  18022. ctrl.offsetLeft = fixOffset(ctrl.offsetLeft - event.wheelDelta);
  18023. }
  18024. /**
  18025. * Slides the tabs over approximately one page forward.
  18026. */
  18027. function nextPage () {
  18028. var viewportWidth = elements.canvas.clientWidth,
  18029. totalWidth = viewportWidth + ctrl.offsetLeft,
  18030. i, tab;
  18031. for (i = 0; i < elements.tabs.length; i++) {
  18032. tab = elements.tabs[ i ];
  18033. if (tab.offsetLeft + tab.offsetWidth > totalWidth) break;
  18034. }
  18035. ctrl.offsetLeft = fixOffset(tab.offsetLeft);
  18036. }
  18037. /**
  18038. * Slides the tabs over approximately one page backward.
  18039. */
  18040. function previousPage () {
  18041. var i, tab;
  18042. for (i = 0; i < elements.tabs.length; i++) {
  18043. tab = elements.tabs[ i ];
  18044. if (tab.offsetLeft + tab.offsetWidth >= ctrl.offsetLeft) break;
  18045. }
  18046. ctrl.offsetLeft = fixOffset(tab.offsetLeft + tab.offsetWidth - elements.canvas.clientWidth);
  18047. }
  18048. /**
  18049. * Update size calculations when the window is resized.
  18050. */
  18051. function handleWindowResize () {
  18052. $scope.$apply(function () {
  18053. ctrl.lastSelectedIndex = ctrl.selectedIndex;
  18054. ctrl.offsetLeft = fixOffset(ctrl.offsetLeft);
  18055. $mdUtil.nextTick(ctrl.updateInkBarStyles, false);
  18056. $mdUtil.nextTick(updatePagination);
  18057. });
  18058. }
  18059. function handleInkBar (hide) {
  18060. angular.element(elements.inkBar).toggleClass('ng-hide', hide);
  18061. }
  18062. /**
  18063. * Toggle dynamic height class when value changes
  18064. * @param value
  18065. */
  18066. function handleDynamicHeight (value) {
  18067. $element.toggleClass('md-dynamic-height', value);
  18068. }
  18069. /**
  18070. * Remove a tab from the data and select the nearest valid tab.
  18071. * @param tabData
  18072. */
  18073. function removeTab (tabData) {
  18074. if (destroyed) return;
  18075. var selectedIndex = ctrl.selectedIndex,
  18076. tab = ctrl.tabs.splice(tabData.getIndex(), 1)[ 0 ];
  18077. refreshIndex();
  18078. // when removing a tab, if the selected index did not change, we have to manually trigger the
  18079. // tab select/deselect events
  18080. if (ctrl.selectedIndex === selectedIndex) {
  18081. tab.scope.deselect();
  18082. ctrl.tabs[ ctrl.selectedIndex ] && ctrl.tabs[ ctrl.selectedIndex ].scope.select();
  18083. }
  18084. $mdUtil.nextTick(function () {
  18085. updatePagination();
  18086. ctrl.offsetLeft = fixOffset(ctrl.offsetLeft);
  18087. });
  18088. }
  18089. /**
  18090. * Create an entry in the tabs array for a new tab at the specified index.
  18091. * @param tabData
  18092. * @param index
  18093. * @returns {*}
  18094. */
  18095. function insertTab (tabData, index) {
  18096. var hasLoaded = loaded;
  18097. var proto = {
  18098. getIndex: function () { return ctrl.tabs.indexOf(tab); },
  18099. isActive: function () { return this.getIndex() === ctrl.selectedIndex; },
  18100. isLeft: function () { return this.getIndex() < ctrl.selectedIndex; },
  18101. isRight: function () { return this.getIndex() > ctrl.selectedIndex; },
  18102. shouldRender: function () { return !ctrl.noDisconnect || this.isActive(); },
  18103. hasFocus: function () {
  18104. return !ctrl.lastClick
  18105. && ctrl.hasFocus && this.getIndex() === ctrl.focusIndex;
  18106. },
  18107. id: $mdUtil.nextUid()
  18108. },
  18109. tab = angular.extend(proto, tabData);
  18110. if (angular.isDefined(index)) {
  18111. ctrl.tabs.splice(index, 0, tab);
  18112. } else {
  18113. ctrl.tabs.push(tab);
  18114. }
  18115. processQueue();
  18116. updateHasContent();
  18117. $mdUtil.nextTick(function () {
  18118. updatePagination();
  18119. // if autoselect is enabled, select the newly added tab
  18120. if (hasLoaded && ctrl.autoselect) $mdUtil.nextTick(function () {
  18121. $mdUtil.nextTick(function () { select(ctrl.tabs.indexOf(tab)); });
  18122. });
  18123. });
  18124. return tab;
  18125. }
  18126. // Getter methods
  18127. /**
  18128. * Gathers references to all of the DOM elements used by this controller.
  18129. * @returns {{}}
  18130. */
  18131. function getElements () {
  18132. var elements = {};
  18133. // gather tab bar elements
  18134. elements.wrapper = $element[ 0 ].getElementsByTagName('md-tabs-wrapper')[ 0 ];
  18135. elements.data = $element[ 0 ].getElementsByTagName('md-tab-data')[ 0 ];
  18136. elements.canvas = elements.wrapper.getElementsByTagName('md-tabs-canvas')[ 0 ];
  18137. elements.paging = elements.canvas.getElementsByTagName('md-pagination-wrapper')[ 0 ];
  18138. elements.tabs = elements.paging.getElementsByTagName('md-tab-item');
  18139. elements.dummies = elements.canvas.getElementsByTagName('md-dummy-tab');
  18140. elements.inkBar = elements.paging.getElementsByTagName('md-ink-bar')[ 0 ];
  18141. // gather tab content elements
  18142. elements.contentsWrapper = $element[ 0 ].getElementsByTagName('md-tabs-content-wrapper')[ 0 ];
  18143. elements.contents = elements.contentsWrapper.getElementsByTagName('md-tab-content');
  18144. return elements;
  18145. }
  18146. /**
  18147. * Determines whether or not the left pagination arrow should be enabled.
  18148. * @returns {boolean}
  18149. */
  18150. function canPageBack () {
  18151. return ctrl.offsetLeft > 0;
  18152. }
  18153. /**
  18154. * Determines whether or not the right pagination arrow should be enabled.
  18155. * @returns {*|boolean}
  18156. */
  18157. function canPageForward () {
  18158. var lastTab = elements.tabs[ elements.tabs.length - 1 ];
  18159. return lastTab && lastTab.offsetLeft + lastTab.offsetWidth > elements.canvas.clientWidth +
  18160. ctrl.offsetLeft;
  18161. }
  18162. /**
  18163. * Determines if the UI should stretch the tabs to fill the available space.
  18164. * @returns {*}
  18165. */
  18166. function shouldStretchTabs () {
  18167. switch (ctrl.stretchTabs) {
  18168. case 'always':
  18169. return true;
  18170. case 'never':
  18171. return false;
  18172. default:
  18173. return !ctrl.shouldPaginate
  18174. && $window.matchMedia('(max-width: 600px)').matches;
  18175. }
  18176. }
  18177. /**
  18178. * Determines if the tabs should appear centered.
  18179. * @returns {string|boolean}
  18180. */
  18181. function shouldCenterTabs () {
  18182. return ctrl.centerTabs && !ctrl.shouldPaginate;
  18183. }
  18184. /**
  18185. * Determines if pagination is necessary to display the tabs within the available space.
  18186. * @returns {boolean}
  18187. */
  18188. function shouldPaginate () {
  18189. if (ctrl.noPagination || !loaded) return false;
  18190. var canvasWidth = Math.min($element.prop('clientWidth'), ctrl.maxTabWidth);
  18191. angular.forEach(elements.dummies, function (tab) { canvasWidth -= tab.offsetWidth; });
  18192. return canvasWidth < 0;
  18193. }
  18194. /**
  18195. * Finds the nearest tab index that is available. This is primarily used for when the active
  18196. * tab is removed.
  18197. * @param newIndex
  18198. * @returns {*}
  18199. */
  18200. function getNearestSafeIndex (newIndex) {
  18201. if (newIndex === -1) return -1;
  18202. var maxOffset = Math.max(ctrl.tabs.length - newIndex, newIndex),
  18203. i, tab;
  18204. for (i = 0; i <= maxOffset; i++) {
  18205. tab = ctrl.tabs[ newIndex + i ];
  18206. if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
  18207. tab = ctrl.tabs[ newIndex - i ];
  18208. if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
  18209. }
  18210. return newIndex;
  18211. }
  18212. // Utility methods
  18213. /**
  18214. * Defines a property using a getter and setter in order to trigger a change handler without
  18215. * using `$watch` to observe changes.
  18216. * @param key
  18217. * @param handler
  18218. * @param value
  18219. */
  18220. function defineProperty (key, handler, value) {
  18221. Object.defineProperty(ctrl, key, {
  18222. get: function () { return value; },
  18223. set: function (newValue) {
  18224. var oldValue = value;
  18225. value = newValue;
  18226. handler && handler(newValue, oldValue);
  18227. }
  18228. });
  18229. }
  18230. /**
  18231. * Updates whether or not pagination should be displayed.
  18232. */
  18233. function updatePagination () {
  18234. ctrl.shouldPaginate = shouldPaginate();
  18235. }
  18236. function getMaxTabWidth () {
  18237. return $element.prop('clientWidth');
  18238. }
  18239. /**
  18240. * Re-orders the tabs and updates the selected and focus indexes to their new positions.
  18241. * This is triggered by `tabDirective.js` when the user's tabs have been re-ordered.
  18242. */
  18243. function updateTabOrder () {
  18244. var selectedItem = ctrl.tabs[ ctrl.selectedIndex ],
  18245. focusItem = ctrl.tabs[ ctrl.focusIndex ];
  18246. ctrl.tabs = ctrl.tabs.sort(function (a, b) {
  18247. return a.index - b.index;
  18248. });
  18249. ctrl.selectedIndex = ctrl.tabs.indexOf(selectedItem);
  18250. ctrl.focusIndex = ctrl.tabs.indexOf(focusItem);
  18251. }
  18252. /**
  18253. * This moves the selected or focus index left or right. This is used by the keydown handler.
  18254. * @param inc
  18255. */
  18256. function incrementIndex (inc, focus) {
  18257. var newIndex,
  18258. key = focus ? 'focusIndex' : 'selectedIndex',
  18259. index = ctrl[ key ];
  18260. for (newIndex = index + inc;
  18261. ctrl.tabs[ newIndex ] && ctrl.tabs[ newIndex ].scope.disabled;
  18262. newIndex += inc) {}
  18263. if (ctrl.tabs[ newIndex ]) {
  18264. ctrl[ key ] = newIndex;
  18265. }
  18266. }
  18267. /**
  18268. * This is used to forward focus to dummy elements. This method is necessary to avoid aniation
  18269. * issues when attempting to focus an item that is out of view.
  18270. */
  18271. function redirectFocus () {
  18272. elements.dummies[ ctrl.focusIndex ].focus();
  18273. }
  18274. /**
  18275. * Forces the pagination to move the focused tab into view.
  18276. */
  18277. function adjustOffset (index) {
  18278. if (index == null) index = ctrl.focusIndex;
  18279. if (!elements.tabs[ index ]) return;
  18280. if (ctrl.shouldCenterTabs) return;
  18281. var tab = elements.tabs[ index ],
  18282. left = tab.offsetLeft,
  18283. right = tab.offsetWidth + left;
  18284. ctrl.offsetLeft = Math.max(ctrl.offsetLeft, fixOffset(right - elements.canvas.clientWidth));
  18285. ctrl.offsetLeft = Math.min(ctrl.offsetLeft, fixOffset(left));
  18286. }
  18287. /**
  18288. * Iterates through all queued functions and clears the queue. This is used for functions that
  18289. * are called before the UI is ready, such as size calculations.
  18290. */
  18291. function processQueue () {
  18292. queue.forEach(function (func) { $mdUtil.nextTick(func); });
  18293. queue = [];
  18294. }
  18295. /**
  18296. * Determines if the tab content area is needed.
  18297. */
  18298. function updateHasContent () {
  18299. var hasContent = false;
  18300. angular.forEach(ctrl.tabs, function (tab) {
  18301. if (tab.template) hasContent = true;
  18302. });
  18303. ctrl.hasContent = hasContent;
  18304. }
  18305. /**
  18306. * Moves the indexes to their nearest valid values.
  18307. */
  18308. function refreshIndex () {
  18309. ctrl.selectedIndex = getNearestSafeIndex(ctrl.selectedIndex);
  18310. ctrl.focusIndex = getNearestSafeIndex(ctrl.focusIndex);
  18311. }
  18312. /**
  18313. * Calculates the content height of the current tab.
  18314. * @returns {*}
  18315. */
  18316. function updateHeightFromContent () {
  18317. if (!ctrl.dynamicHeight) return $element.css('height', '');
  18318. if (!ctrl.tabs.length) return queue.push(updateHeightFromContent);
  18319. var tabContent = elements.contents[ ctrl.selectedIndex ],
  18320. contentHeight = tabContent ? tabContent.offsetHeight : 0,
  18321. tabsHeight = elements.wrapper.offsetHeight,
  18322. newHeight = contentHeight + tabsHeight,
  18323. currentHeight = $element.prop('clientHeight');
  18324. if (currentHeight === newHeight) return;
  18325. // Lock during animation so the user can't change tabs
  18326. locked = true;
  18327. var fromHeight = { height: currentHeight + 'px'},
  18328. toHeight = { height: newHeight + 'px' };
  18329. // Set the height to the current, specific pixel height to fix a bug on iOS where the height
  18330. // first animates to 0, then back to the proper height causing a visual glitch
  18331. $element.css(fromHeight);
  18332. // Animate the height from the old to the new
  18333. $animateCss($element, {
  18334. from: fromHeight,
  18335. to: toHeight,
  18336. easing: 'cubic-bezier(0.35, 0, 0.25, 1)',
  18337. duration: 0.5
  18338. }).start().done(function () {
  18339. // Then (to fix the same iOS issue as above), disable transitions and remove the specific
  18340. // pixel height so the height can size with browser width/content changes, etc.
  18341. $element.css({
  18342. transition: 'none',
  18343. height: ''
  18344. });
  18345. // In the next tick, re-allow transitions (if we do it all at once, $element.css is "smart"
  18346. // enough to batch it for us instead of doing it immediately, which undoes the original
  18347. // transition: none)
  18348. $mdUtil.nextTick(function() {
  18349. $element.css('transition', '');
  18350. });
  18351. // And unlock so tab changes can occur
  18352. locked = false;
  18353. });
  18354. }
  18355. /**
  18356. * Repositions the ink bar to the selected tab.
  18357. * @returns {*}
  18358. */
  18359. function updateInkBarStyles () {
  18360. if (!elements.tabs[ ctrl.selectedIndex ]) {
  18361. angular.element(elements.inkBar).css({ left: 'auto', right: 'auto' });
  18362. return;
  18363. }
  18364. if (!ctrl.tabs.length) return queue.push(ctrl.updateInkBarStyles);
  18365. // if the element is not visible, we will not be able to calculate sizes until it is
  18366. // we should treat that as a resize event rather than just updating the ink bar
  18367. if (!$element.prop('offsetParent')) return handleResizeWhenVisible();
  18368. var index = ctrl.selectedIndex,
  18369. totalWidth = elements.paging.offsetWidth,
  18370. tab = elements.tabs[ index ],
  18371. left = tab.offsetLeft,
  18372. right = totalWidth - left - tab.offsetWidth,
  18373. tabWidth;
  18374. if (ctrl.shouldCenterTabs) {
  18375. tabWidth = Array.prototype.slice.call(elements.tabs).reduce(function (value, element) {
  18376. return value + element.offsetWidth;
  18377. }, 0);
  18378. if (totalWidth > tabWidth) $mdUtil.nextTick(updateInkBarStyles, false);
  18379. }
  18380. updateInkBarClassName();
  18381. angular.element(elements.inkBar).css({ left: left + 'px', right: right + 'px' });
  18382. }
  18383. /**
  18384. * Adds left/right classes so that the ink bar will animate properly.
  18385. */
  18386. function updateInkBarClassName () {
  18387. var newIndex = ctrl.selectedIndex,
  18388. oldIndex = ctrl.lastSelectedIndex,
  18389. ink = angular.element(elements.inkBar);
  18390. if (!angular.isNumber(oldIndex)) return;
  18391. ink
  18392. .toggleClass('md-left', newIndex < oldIndex)
  18393. .toggleClass('md-right', newIndex > oldIndex);
  18394. }
  18395. /**
  18396. * Takes an offset value and makes sure that it is within the min/max allowed values.
  18397. * @param value
  18398. * @returns {*}
  18399. */
  18400. function fixOffset (value) {
  18401. if (!elements.tabs.length || !ctrl.shouldPaginate) return 0;
  18402. var lastTab = elements.tabs[ elements.tabs.length - 1 ],
  18403. totalWidth = lastTab.offsetLeft + lastTab.offsetWidth;
  18404. value = Math.max(0, value);
  18405. value = Math.min(totalWidth - elements.canvas.clientWidth, value);
  18406. return value;
  18407. }
  18408. /**
  18409. * Attaches a ripple to the tab item element.
  18410. * @param scope
  18411. * @param element
  18412. */
  18413. function attachRipple (scope, element) {
  18414. var options = { colorElement: angular.element(elements.inkBar) };
  18415. $mdTabInkRipple.attach(scope, element, options);
  18416. }
  18417. }
  18418. MdTabsController.$inject = ["$scope", "$element", "$window", "$mdConstant", "$mdTabInkRipple", "$mdUtil", "$animateCss", "$attrs", "$compile", "$mdTheming"];
  18419. })();
  18420. (function(){
  18421. "use strict";
  18422. /**
  18423. * @ngdoc directive
  18424. * @name mdTabs
  18425. * @module material.components.tabs
  18426. *
  18427. * @restrict E
  18428. *
  18429. * @description
  18430. * The `<md-tabs>` directive serves as the container for 1..n `<md-tab>` child directives to produces a Tabs components.
  18431. * In turn, the nested `<md-tab>` directive is used to specify a tab label for the **header button** and a [optional] tab view
  18432. * content that will be associated with each tab button.
  18433. *
  18434. * Below is the markup for its simplest usage:
  18435. *
  18436. * <hljs lang="html">
  18437. * <md-tabs>
  18438. * <md-tab label="Tab #1"></md-tab>
  18439. * <md-tab label="Tab #2"></md-tab>
  18440. * <md-tab label="Tab #3"></md-tab>
  18441. * </md-tabs>
  18442. * </hljs>
  18443. *
  18444. * Tabs supports three (3) usage scenarios:
  18445. *
  18446. * 1. Tabs (buttons only)
  18447. * 2. Tabs with internal view content
  18448. * 3. Tabs with external view content
  18449. *
  18450. * **Tab-only** support is useful when tab buttons are used for custom navigation regardless of any other components, content, or views.
  18451. * **Tabs with internal views** are the traditional usages where each tab has associated view content and the view switching is managed internally by the Tabs component.
  18452. * **Tabs with external view content** is often useful when content associated with each tab is independently managed and data-binding notifications announce tab selection changes.
  18453. *
  18454. * Additional features also include:
  18455. *
  18456. * * Content can include any markup.
  18457. * * If a tab is disabled while active/selected, then the next tab will be auto-selected.
  18458. *
  18459. * ### Explanation of tab stretching
  18460. *
  18461. * 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.
  18462. *
  18463. * On mobile devices, tabs will be expanded to fill the available horizontal space. When this happens, all tabs will become the same size.
  18464. *
  18465. * On desktops, by default, stretching will never occur.
  18466. *
  18467. * This default behavior can be overridden through the `md-stretch-tabs` attribute. Here is a table showing when stretching will occur:
  18468. *
  18469. * `md-stretch-tabs` | mobile | desktop
  18470. * ------------------|-----------|--------
  18471. * `auto` | stretched | ---
  18472. * `always` | stretched | stretched
  18473. * `never` | --- | ---
  18474. *
  18475. * @param {integer=} md-selected Index of the active/selected tab
  18476. * @param {boolean=} md-no-ink If present, disables ink ripple effects.
  18477. * @param {boolean=} md-no-bar If present, disables the selection ink bar.
  18478. * @param {string=} md-align-tabs Attribute to indicate position of tab buttons: `bottom` or `top`; default is `top`
  18479. * @param {string=} md-stretch-tabs Attribute to indicate whether or not to stretch tabs: `auto`, `always`, or `never`; default is `auto`
  18480. * @param {boolean=} md-dynamic-height When enabled, the tab wrapper will resize based on the contents of the selected tab
  18481. * @param {boolean=} md-center-tabs When enabled, tabs will be centered provided there is no need for pagination
  18482. * @param {boolean=} md-no-pagination When enabled, pagination will remain off
  18483. * @param {boolean=} md-swipe-content When enabled, swipe gestures will be enabled for the content area to jump between tabs
  18484. * @param {boolean=} md-no-disconnect If your tab content has background tasks (ie. event listeners), you will want to include this to prevent the scope from being disconnected
  18485. * @param {boolean=} md-autoselect When present, any tabs added after the initial load will be automatically selected
  18486. *
  18487. * @usage
  18488. * <hljs lang="html">
  18489. * <md-tabs md-selected="selectedIndex" >
  18490. * <img ng-src="img/angular.png" class="centered">
  18491. * <md-tab
  18492. * ng-repeat="tab in tabs | orderBy:predicate:reversed"
  18493. * md-on-select="onTabSelected(tab)"
  18494. * md-on-deselect="announceDeselected(tab)"
  18495. * ng-disabled="tab.disabled">
  18496. * <md-tab-label>
  18497. * {{tab.title}}
  18498. * <img src="img/removeTab.png" ng-click="removeTab(tab)" class="delete">
  18499. * </md-tab-label>
  18500. * <md-tab-body>
  18501. * {{tab.content}}
  18502. * </md-tab-body>
  18503. * </md-tab>
  18504. * </md-tabs>
  18505. * </hljs>
  18506. *
  18507. */
  18508. angular
  18509. .module('material.components.tabs')
  18510. .directive('mdTabs', MdTabs);
  18511. function MdTabs () {
  18512. return {
  18513. scope: {
  18514. selectedIndex: '=?mdSelected'
  18515. },
  18516. template: function (element, attr) {
  18517. attr[ "$mdTabsTemplate" ] = element.html();
  18518. return '\
  18519. <md-tabs-wrapper>\
  18520. <md-tab-data></md-tab-data>\
  18521. <md-prev-button\
  18522. tabindex="-1"\
  18523. role="button"\
  18524. aria-label="Previous Page"\
  18525. aria-disabled="{{!$mdTabsCtrl.canPageBack()}}"\
  18526. ng-class="{ \'md-disabled\': !$mdTabsCtrl.canPageBack() }"\
  18527. ng-if="$mdTabsCtrl.shouldPaginate"\
  18528. ng-click="$mdTabsCtrl.previousPage()">\
  18529. <md-icon md-svg-icon="md-tabs-arrow"></md-icon>\
  18530. </md-prev-button>\
  18531. <md-next-button\
  18532. tabindex="-1"\
  18533. role="button"\
  18534. aria-label="Next Page"\
  18535. aria-disabled="{{!$mdTabsCtrl.canPageForward()}}"\
  18536. ng-class="{ \'md-disabled\': !$mdTabsCtrl.canPageForward() }"\
  18537. ng-if="$mdTabsCtrl.shouldPaginate"\
  18538. ng-click="$mdTabsCtrl.nextPage()">\
  18539. <md-icon md-svg-icon="md-tabs-arrow"></md-icon>\
  18540. </md-next-button>\
  18541. <md-tabs-canvas\
  18542. tabindex="0"\
  18543. aria-activedescendant="tab-item-{{$mdTabsCtrl.tabs[$mdTabsCtrl.focusIndex].id}}"\
  18544. ng-focus="$mdTabsCtrl.redirectFocus()"\
  18545. ng-class="{\
  18546. \'md-paginated\': $mdTabsCtrl.shouldPaginate,\
  18547. \'md-center-tabs\': $mdTabsCtrl.shouldCenterTabs\
  18548. }"\
  18549. ng-keydown="$mdTabsCtrl.keydown($event)"\
  18550. role="tablist">\
  18551. <md-pagination-wrapper\
  18552. ng-class="{ \'md-center-tabs\': $mdTabsCtrl.shouldCenterTabs }"\
  18553. md-tab-scroll="$mdTabsCtrl.scroll($event)">\
  18554. <md-tab-item\
  18555. tabindex="-1"\
  18556. class="md-tab"\
  18557. style="max-width: {{ $mdTabsCtrl.maxTabWidth + \'px\' }}"\
  18558. ng-repeat="tab in $mdTabsCtrl.tabs"\
  18559. role="tab"\
  18560. aria-controls="tab-content-{{::tab.id}}"\
  18561. aria-selected="{{tab.isActive()}}"\
  18562. aria-disabled="{{tab.scope.disabled || \'false\'}}"\
  18563. ng-click="$mdTabsCtrl.select(tab.getIndex())"\
  18564. ng-class="{\
  18565. \'md-active\': tab.isActive(),\
  18566. \'md-focused\': tab.hasFocus(),\
  18567. \'md-disabled\': tab.scope.disabled\
  18568. }"\
  18569. ng-disabled="tab.scope.disabled"\
  18570. md-swipe-left="$mdTabsCtrl.nextPage()"\
  18571. md-swipe-right="$mdTabsCtrl.previousPage()"\
  18572. md-tabs-template="::tab.label"\
  18573. md-scope="::tab.parent"></md-tab-item>\
  18574. <md-ink-bar></md-ink-bar>\
  18575. </md-pagination-wrapper>\
  18576. <div class="md-visually-hidden md-dummy-wrapper">\
  18577. <md-dummy-tab\
  18578. class="md-tab"\
  18579. tabindex="-1"\
  18580. id="tab-item-{{::tab.id}}"\
  18581. role="tab"\
  18582. aria-controls="tab-content-{{::tab.id}}"\
  18583. aria-selected="{{tab.isActive()}}"\
  18584. aria-disabled="{{tab.scope.disabled || \'false\'}}"\
  18585. ng-focus="$mdTabsCtrl.hasFocus = true"\
  18586. ng-blur="$mdTabsCtrl.hasFocus = false"\
  18587. ng-repeat="tab in $mdTabsCtrl.tabs"\
  18588. md-tabs-template="::tab.label"\
  18589. md-scope="::tab.parent"></md-dummy-tab>\
  18590. </div>\
  18591. </md-tabs-canvas>\
  18592. </md-tabs-wrapper>\
  18593. <md-tabs-content-wrapper ng-show="$mdTabsCtrl.hasContent && $mdTabsCtrl.selectedIndex >= 0">\
  18594. <md-tab-content\
  18595. id="tab-content-{{::tab.id}}"\
  18596. role="tabpanel"\
  18597. aria-labelledby="tab-item-{{::tab.id}}"\
  18598. md-swipe-left="$mdTabsCtrl.swipeContent && $mdTabsCtrl.incrementIndex(1)"\
  18599. md-swipe-right="$mdTabsCtrl.swipeContent && $mdTabsCtrl.incrementIndex(-1)"\
  18600. ng-if="$mdTabsCtrl.hasContent"\
  18601. ng-repeat="(index, tab) in $mdTabsCtrl.tabs"\
  18602. ng-class="{\
  18603. \'md-no-transition\': $mdTabsCtrl.lastSelectedIndex == null,\
  18604. \'md-active\': tab.isActive(),\
  18605. \'md-left\': tab.isLeft(),\
  18606. \'md-right\': tab.isRight(),\
  18607. \'md-no-scroll\': $mdTabsCtrl.dynamicHeight\
  18608. }">\
  18609. <div\
  18610. md-tabs-template="::tab.template"\
  18611. md-connected-if="tab.isActive()"\
  18612. md-scope="::tab.parent"\
  18613. ng-if="$mdTabsCtrl.enableDisconnect || tab.shouldRender()"></div>\
  18614. </md-tab-content>\
  18615. </md-tabs-content-wrapper>\
  18616. ';
  18617. },
  18618. controller: 'MdTabsController',
  18619. controllerAs: '$mdTabsCtrl',
  18620. bindToController: true
  18621. };
  18622. }
  18623. })();
  18624. (function(){
  18625. "use strict";
  18626. angular
  18627. .module('material.components.tabs')
  18628. .directive('mdTabsTemplate', MdTabsTemplate);
  18629. function MdTabsTemplate ($compile, $mdUtil) {
  18630. return {
  18631. restrict: 'A',
  18632. link: link,
  18633. scope: {
  18634. template: '=mdTabsTemplate',
  18635. connected: '=?mdConnectedIf',
  18636. compileScope: '=mdScope'
  18637. },
  18638. require: '^?mdTabs'
  18639. };
  18640. function link (scope, element, attr, ctrl) {
  18641. if (!ctrl) return;
  18642. var compileScope = ctrl.enableDisconnect ? scope.compileScope.$new() : scope.compileScope;
  18643. element.html(scope.template);
  18644. $compile(element.contents())(compileScope);
  18645. element.on('DOMSubtreeModified', function () {
  18646. ctrl.updatePagination();
  18647. ctrl.updateInkBarStyles();
  18648. });
  18649. return $mdUtil.nextTick(handleScope);
  18650. function handleScope () {
  18651. scope.$watch('connected', function (value) { value === false ? disconnect() : reconnect(); });
  18652. scope.$on('$destroy', reconnect);
  18653. }
  18654. function disconnect () {
  18655. if (ctrl.enableDisconnect) $mdUtil.disconnectScope(compileScope);
  18656. }
  18657. function reconnect () {
  18658. if (ctrl.enableDisconnect) $mdUtil.reconnectScope(compileScope);
  18659. }
  18660. }
  18661. }
  18662. MdTabsTemplate.$inject = ["$compile", "$mdUtil"];
  18663. })();
  18664. (function(){
  18665. angular.module("material.core").constant("$MD_THEME_CSS", "md-autocomplete.md-THEME_NAME-theme { background: '{{background-50}}'; } md-autocomplete.md-THEME_NAME-theme[disabled] { background: '{{background-100}}'; } 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-suggestions-container.md-THEME_NAME-theme { background: '{{background-50}}'; } .md-autocomplete-suggestions-container.md-THEME_NAME-theme li { color: '{{background-900}}'; } .md-autocomplete-suggestions-container.md-THEME_NAME-theme li .highlight { color: '{{background-600}}'; } .md-autocomplete-suggestions-container.md-THEME_NAME-theme li:hover, .md-autocomplete-suggestions-container.md-THEME_NAME-theme li.selected { background: '{{background-200}}'; }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}}'; } md-bottom-sheet.md-THEME_NAME-theme .md-subheader { color: '{{foreground-1}}'; }a.md-button.md-THEME_NAME-theme:not([disabled]):hover, .md-button.md-THEME_NAME-theme:not([disabled]):hover { background-color: '{{background-500-0.2}}'; }a.md-button.md-THEME_NAME-theme:not([disabled]).md-focused, .md-button.md-THEME_NAME-theme:not([disabled]).md-focused { background-color: '{{background-500-0.2}}'; }a.md-button.md-THEME_NAME-theme:not([disabled]).md-icon-button:hover, .md-button.md-THEME_NAME-theme:not([disabled]).md-icon-button:hover { background-color: transparent; }a.md-button.md-THEME_NAME-theme.md-fab, .md-button.md-THEME_NAME-theme.md-fab { background-color: '{{accent-color}}'; color: '{{accent-contrast}}'; } a.md-button.md-THEME_NAME-theme.md-fab md-icon, .md-button.md-THEME_NAME-theme.md-fab md-icon { color: '{{accent-contrast}}'; } a.md-button.md-THEME_NAME-theme.md-fab:not([disabled]):hover, .md-button.md-THEME_NAME-theme.md-fab:not([disabled]):hover { background-color: '{{accent-color}}'; } a.md-button.md-THEME_NAME-theme.md-fab:not([disabled]).md-focused, .md-button.md-THEME_NAME-theme.md-fab:not([disabled]).md-focused { background-color: '{{accent-A700}}'; }a.md-button.md-THEME_NAME-theme.md-primary, .md-button.md-THEME_NAME-theme.md-primary { color: '{{primary-color}}'; } a.md-button.md-THEME_NAME-theme.md-primary.md-raised, a.md-button.md-THEME_NAME-theme.md-primary.md-fab, .md-button.md-THEME_NAME-theme.md-primary.md-raised, .md-button.md-THEME_NAME-theme.md-primary.md-fab { color: '{{primary-contrast}}'; background-color: '{{primary-color}}'; } a.md-button.md-THEME_NAME-theme.md-primary.md-raised:not([disabled]) md-icon, a.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, .md-button.md-THEME_NAME-theme.md-primary.md-fab:not([disabled]) md-icon { color: '{{primary-contrast}}'; } a.md-button.md-THEME_NAME-theme.md-primary.md-raised:not([disabled]):hover, a.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]):hover, .md-button.md-THEME_NAME-theme.md-primary.md-fab:not([disabled]):hover { background-color: '{{primary-color}}'; } a.md-button.md-THEME_NAME-theme.md-primary.md-raised:not([disabled]).md-focused, a.md-button.md-THEME_NAME-theme.md-primary.md-fab:not([disabled]).md-focused, .md-button.md-THEME_NAME-theme.md-primary.md-raised:not([disabled]).md-focused, .md-button.md-THEME_NAME-theme.md-primary.md-fab:not([disabled]).md-focused { background-color: '{{primary-600}}'; } a.md-button.md-THEME_NAME-theme.md-primary:not([disabled]) md-icon, .md-button.md-THEME_NAME-theme.md-primary:not([disabled]) md-icon { color: '{{primary-color}}'; }a.md-button.md-THEME_NAME-theme.md-fab, .md-button.md-THEME_NAME-theme.md-fab { background-color: '{{accent-color}}'; color: '{{accent-contrast}}'; } a.md-button.md-THEME_NAME-theme.md-fab:not([disabled]) .md-icon, .md-button.md-THEME_NAME-theme.md-fab:not([disabled]) .md-icon { color: '{{accent-contrast}}'; } a.md-button.md-THEME_NAME-theme.md-fab:not([disabled]):hover, .md-button.md-THEME_NAME-theme.md-fab:not([disabled]):hover { background-color: '{{accent-color}}'; } a.md-button.md-THEME_NAME-theme.md-fab:not([disabled]).md-focused, .md-button.md-THEME_NAME-theme.md-fab:not([disabled]).md-focused { background-color: '{{accent-A700}}'; }a.md-button.md-THEME_NAME-theme.md-raised, .md-button.md-THEME_NAME-theme.md-raised { color: '{{background-contrast}}'; background-color: '{{background-50}}'; } a.md-button.md-THEME_NAME-theme.md-raised:not([disabled]) .md-icon, .md-button.md-THEME_NAME-theme.md-raised:not([disabled]) .md-icon { color: '{{background-contrast}}'; } a.md-button.md-THEME_NAME-theme.md-raised:not([disabled]):hover, .md-button.md-THEME_NAME-theme.md-raised:not([disabled]):hover { background-color: '{{background-50}}'; } a.md-button.md-THEME_NAME-theme.md-raised:not([disabled]).md-focused, .md-button.md-THEME_NAME-theme.md-raised:not([disabled]).md-focused { background-color: '{{background-200}}'; }a.md-button.md-THEME_NAME-theme.md-warn, .md-button.md-THEME_NAME-theme.md-warn { color: '{{warn-color}}'; } a.md-button.md-THEME_NAME-theme.md-warn.md-raised, a.md-button.md-THEME_NAME-theme.md-warn.md-fab, .md-button.md-THEME_NAME-theme.md-warn.md-raised, .md-button.md-THEME_NAME-theme.md-warn.md-fab { color: '{{warn-contrast}}'; background-color: '{{warn-color}}'; } a.md-button.md-THEME_NAME-theme.md-warn.md-raised:not([disabled]) md-icon, a.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, .md-button.md-THEME_NAME-theme.md-warn.md-fab:not([disabled]) md-icon { color: '{{warn-contrast}}'; } a.md-button.md-THEME_NAME-theme.md-warn.md-raised:not([disabled]):hover, a.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]):hover, .md-button.md-THEME_NAME-theme.md-warn.md-fab:not([disabled]):hover { background-color: '{{warn-color}}'; } a.md-button.md-THEME_NAME-theme.md-warn.md-raised:not([disabled]).md-focused, a.md-button.md-THEME_NAME-theme.md-warn.md-fab:not([disabled]).md-focused, .md-button.md-THEME_NAME-theme.md-warn.md-raised:not([disabled]).md-focused, .md-button.md-THEME_NAME-theme.md-warn.md-fab:not([disabled]).md-focused { background-color: '{{warn-700}}'; } a.md-button.md-THEME_NAME-theme.md-warn:not([disabled]) md-icon, .md-button.md-THEME_NAME-theme.md-warn:not([disabled]) md-icon { color: '{{warn-color}}'; }a.md-button.md-THEME_NAME-theme.md-accent, .md-button.md-THEME_NAME-theme.md-accent { color: '{{accent-color}}'; } a.md-button.md-THEME_NAME-theme.md-accent.md-raised, a.md-button.md-THEME_NAME-theme.md-accent.md-fab, .md-button.md-THEME_NAME-theme.md-accent.md-raised, .md-button.md-THEME_NAME-theme.md-accent.md-fab { color: '{{accent-contrast}}'; background-color: '{{accent-color}}'; } a.md-button.md-THEME_NAME-theme.md-accent.md-raised:not([disabled]) md-icon, a.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, .md-button.md-THEME_NAME-theme.md-accent.md-fab:not([disabled]) md-icon { color: '{{accent-contrast}}'; } a.md-button.md-THEME_NAME-theme.md-accent.md-raised:not([disabled]):hover, a.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]):hover, .md-button.md-THEME_NAME-theme.md-accent.md-fab:not([disabled]):hover { background-color: '{{accent-color}}'; } a.md-button.md-THEME_NAME-theme.md-accent.md-raised:not([disabled]).md-focused, a.md-button.md-THEME_NAME-theme.md-accent.md-fab:not([disabled]).md-focused, .md-button.md-THEME_NAME-theme.md-accent.md-raised:not([disabled]).md-focused, .md-button.md-THEME_NAME-theme.md-accent.md-fab:not([disabled]).md-focused { background-color: '{{accent-700}}'; } a.md-button.md-THEME_NAME-theme.md-accent:not([disabled]) md-icon, .md-button.md-THEME_NAME-theme.md-accent:not([disabled]) md-icon { color: '{{accent-color}}'; }a.md-button.md-THEME_NAME-theme[disabled], a.md-button.md-THEME_NAME-theme.md-raised[disabled], a.md-button.md-THEME_NAME-theme.md-fab[disabled], a.md-button.md-THEME_NAME-theme.md-accent[disabled], a.md-button.md-THEME_NAME-theme.md-warn[disabled], .md-button.md-THEME_NAME-theme[disabled], .md-button.md-THEME_NAME-theme.md-raised[disabled], .md-button.md-THEME_NAME-theme.md-fab[disabled], .md-button.md-THEME_NAME-theme.md-accent[disabled], .md-button.md-THEME_NAME-theme.md-warn[disabled] { color: '{{foreground-3}}'; cursor: not-allowed; } a.md-button.md-THEME_NAME-theme[disabled] md-icon, a.md-button.md-THEME_NAME-theme.md-raised[disabled] md-icon, a.md-button.md-THEME_NAME-theme.md-fab[disabled] md-icon, a.md-button.md-THEME_NAME-theme.md-accent[disabled] md-icon, a.md-button.md-THEME_NAME-theme.md-warn[disabled] md-icon, .md-button.md-THEME_NAME-theme[disabled] md-icon, .md-button.md-THEME_NAME-theme.md-raised[disabled] md-icon, .md-button.md-THEME_NAME-theme.md-fab[disabled] md-icon, .md-button.md-THEME_NAME-theme.md-accent[disabled] md-icon, .md-button.md-THEME_NAME-theme.md-warn[disabled] md-icon { color: '{{foreground-3}}'; }a.md-button.md-THEME_NAME-theme.md-raised[disabled], a.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-fab[disabled] { background-color: '{{foreground-4}}'; }a.md-button.md-THEME_NAME-theme[disabled], .md-button.md-THEME_NAME-theme[disabled] { background-color: transparent; }md-card.md-THEME_NAME-theme { background-color: '{{background-color}}'; border-radius: 2px; } md-card.md-THEME_NAME-theme .md-card-image { border-radius: 2px 2px 0 0; }md-checkbox.md-THEME_NAME-theme .md-ripple { color: '{{accent-600}}'; }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-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: '{{background-200}}'; }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-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: '{{background-200}}'; }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-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] .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-label { color: '{{foreground-3}}'; }md-chips.md-THEME_NAME-theme .md-chips { box-shadow: 0 1px '{{background-300}}'; } md-chips.md-THEME_NAME-theme .md-chips.md-focused { box-shadow: 0 2px '{{primary-color}}'; }md-chips.md-THEME_NAME-theme .md-chip { background: '{{background-300}}'; color: '{{background-800}}'; } 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-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-color}}'; }/** Theme styles for mdCalendar. */.md-calendar.md-THEME_NAME-theme { color: '{{foreground-2}}'; } .md-calendar.md-THEME_NAME-theme tr:last-child td { border-bottom-color: '{{background-200}}'; }.md-THEME_NAME-theme .md-calendar-day-header { background: '{{background-200}}'; color: '{{foreground-2}}'; }.md-THEME_NAME-theme .md-calendar-date.md-calendar-date-today { color: '{{primary-500}}'; } .md-THEME_NAME-theme .md-calendar-date.md-calendar-date-today.md-calendar-date-disabled { color: '{{primary-500-0.6}}'; }.md-THEME_NAME-theme .md-calendar-date.md-focus .md-calendar-date-selection-indicator { background: '{{background-300}}'; }.md-THEME_NAME-theme .md-calendar-date-selection-indicator:hover { background: '{{background-300}}'; }.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}}'; }.md-THEME_NAME-theme .md-calendar-date-disabled, .md-THEME_NAME-theme .md-calendar-month-label-disabled { color: '{{background-400}}'; }/** Theme styles for mdDatepicker. */md-datepicker.md-THEME_NAME-theme { background: white; }.md-THEME_NAME-theme .md-datepicker-input-container { border-bottom-color: '{{background-300}}'; } .md-THEME_NAME-theme .md-datepicker-input-container.md-datepicker-focused { border-bottom-color: '{{primary-500}}'; } .md-THEME_NAME-theme .md-datepicker-input-container.md-datepicker-invalid { border-bottom-color: '{{warn-500}}'; }.md-THEME_NAME-theme .md-datepicker-calendar-pane { border-color: '{{background-300}}'; }.md-THEME_NAME-theme .md-datepicker-triangle-button:hover .md-datepicker-expand-triangle { border-top-color: '{{foreground-2}}'; }.md-THEME_NAME-theme .md-datepicker-open .md-datepicker-calendar-icon { fill: '{{primary-500}}'; }.md-THEME_NAME-theme .md-datepicker-calendar { background: white; }md-dialog.md-THEME_NAME-theme { border-radius: 4px; background-color: '{{background-color}}'; } md-dialog.md-THEME_NAME-theme.md-content-overflow .md-actions { border-top-color: '{{foreground-4}}'; }md-divider.md-THEME_NAME-theme { border-top-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}}'; text-shadow: '{{foreground-shadow}}'; } md-input-container.md-THEME_NAME-theme .md-input::-webkit-input-placeholder, md-input-container.md-THEME_NAME-theme .md-input::-moz-placeholder, md-input-container.md-THEME_NAME-theme .md-input:-moz-placeholder, md-input-container.md-THEME_NAME-theme .md-input:-ms-input-placeholder { color: '{{foreground-3}}'; }md-input-container.md-THEME_NAME-theme > md-icon { color: '{{foreground-1}}'; }md-input-container.md-THEME_NAME-theme label, md-input-container.md-THEME_NAME-theme .md-placeholder { text-shadow: '{{foreground-shadow}}'; color: '{{foreground-3}}'; }md-input-container.md-THEME_NAME-theme ng-messages, md-input-container.md-THEME_NAME-theme [ng-message], md-input-container.md-THEME_NAME-theme [data-ng-message], md-input-container.md-THEME_NAME-theme [x-ng-message] { color: '{{warn-500}}'; }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 { border-color: '{{primary-500}}'; }md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused label { color: '{{primary-500}}'; }md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused md-icon { color: '{{primary-500}}'; }md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused.md-accent .md-input { border-color: '{{accent-500}}'; }md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused.md-accent label { color: '{{accent-500}}'; }md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused.md-warn .md-input { border-color: '{{warn-500}}'; }md-input-container.md-THEME_NAME-theme:not(.md-input-invalid).md-input-focused.md-warn label { color: '{{warn-500}}'; }md-input-container.md-THEME_NAME-theme.md-input-invalid .md-input { border-color: '{{warn-500}}'; }md-input-container.md-THEME_NAME-theme.md-input-invalid.md-input-focused label { color: '{{warn-500}}'; }md-input-container.md-THEME_NAME-theme.md-input-invalid ng-message, md-input-container.md-THEME_NAME-theme.md-input-invalid data-ng-message, md-input-container.md-THEME_NAME-theme.md-input-invalid x-ng-message, md-input-container.md-THEME_NAME-theme.md-input-invalid [ng-message], md-input-container.md-THEME_NAME-theme.md-input-invalid [data-ng-message], md-input-container.md-THEME_NAME-theme.md-input-invalid [x-ng-message], md-input-container.md-THEME_NAME-theme.md-input-invalid .md-char-counter { color: '{{warn-500}}'; }md-input-container.md-THEME_NAME-theme .md-input[disabled], [disabled] md-input-container.md-THEME_NAME-theme .md-input { border-bottom-color: transparent; color: '{{foreground-3}}'; background-image: linear-gradient(to right, '{{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-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-list.md-THEME_NAME-theme md-list-item button { background-color: '{{background-color}}'; } md-list.md-THEME_NAME-theme md-list-item button.md-button:not([disabled]):hover { background-color: '{{background-color}}'; }md-menu-content.md-THEME_NAME-theme { background-color: '{{background-color}}'; } md-menu-content.md-THEME_NAME-theme md-menu-divider { background-color: '{{foreground-4}}'; }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:hover, md-menu-bar.md-THEME_NAME-theme:not(.md-keyboard-mode):not(.md-open) md-menu button:focus { background: transparent; }md-menu-content.md-THEME_NAME-theme .md-menu > .md-button:after { color: '{{foreground-2}}'; }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-color}}'; color: '{{foreground-1}}'; } md-toolbar.md-THEME_NAME-theme.md-menu-toolbar md-toolbar-filler { background-color: '{{primary-color}}'; color: '{{primary-contrast}}'; } md-toolbar.md-THEME_NAME-theme.md-menu-toolbar md-toolbar-filler md-icon { color: '{{primary-contrast}}'; }md-progress-circular.md-THEME_NAME-theme { background-color: transparent; } md-progress-circular.md-THEME_NAME-theme .md-inner .md-gap { border-top-color: '{{primary-color}}'; border-bottom-color: '{{primary-color}}'; } md-progress-circular.md-THEME_NAME-theme .md-inner .md-left .md-half-circle, md-progress-circular.md-THEME_NAME-theme .md-inner .md-right .md-half-circle { border-top-color: '{{primary-color}}'; } md-progress-circular.md-THEME_NAME-theme .md-inner .md-right .md-half-circle { border-right-color: '{{primary-color}}'; } md-progress-circular.md-THEME_NAME-theme .md-inner .md-left .md-half-circle { border-left-color: '{{primary-color}}'; } md-progress-circular.md-THEME_NAME-theme.md-warn .md-inner .md-gap { border-top-color: '{{warn-color}}'; border-bottom-color: '{{warn-color}}'; } md-progress-circular.md-THEME_NAME-theme.md-warn .md-inner .md-left .md-half-circle, md-progress-circular.md-THEME_NAME-theme.md-warn .md-inner .md-right .md-half-circle { border-top-color: '{{warn-color}}'; } md-progress-circular.md-THEME_NAME-theme.md-warn .md-inner .md-right .md-half-circle { border-right-color: '{{warn-color}}'; } md-progress-circular.md-THEME_NAME-theme.md-warn .md-inner .md-left .md-half-circle { border-left-color: '{{warn-color}}'; } md-progress-circular.md-THEME_NAME-theme.md-accent .md-inner .md-gap { border-top-color: '{{accent-color}}'; border-bottom-color: '{{accent-color}}'; } md-progress-circular.md-THEME_NAME-theme.md-accent .md-inner .md-left .md-half-circle, md-progress-circular.md-THEME_NAME-theme.md-accent .md-inner .md-right .md-half-circle { border-top-color: '{{accent-color}}'; } md-progress-circular.md-THEME_NAME-theme.md-accent .md-inner .md-right .md-half-circle { border-right-color: '{{accent-color}}'; } md-progress-circular.md-THEME_NAME-theme.md-accent .md-inner .md-left .md-half-circle { border-left-color: '{{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-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-600}}'; }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, 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 { background-color: '{{primary-color-0.87}}'; }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, 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 { border-color: '{{primary-color-0.87}}'; }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, 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 { color: '{{primary-color-0.87}}'; }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, 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 { color: '{{primary-600}}'; }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, 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 { background-color: '{{warn-color-0.87}}'; }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, 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 { border-color: '{{warn-color-0.87}}'; }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, 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 { color: '{{warn-color-0.87}}'; }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, 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 { color: '{{warn-600}}'; }md-radio-group.md-THEME_NAME-theme[disabled], md-radio-button.md-THEME_NAME-theme[disabled] { color: '{{foreground-3}}'; } md-radio-group.md-THEME_NAME-theme[disabled] .md-container .md-off, md-radio-button.md-THEME_NAME-theme[disabled] .md-container .md-off { border-color: '{{foreground-3}}'; } md-radio-group.md-THEME_NAME-theme[disabled] .md-container .md-on, md-radio-button.md-THEME_NAME-theme[disabled] .md-container .md-on { border-color: '{{foreground-3}}'; }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:not([disabled]).md-primary .md-container:before { background-color: '{{primary-color-0.26}}'; }md-radio-group.md-THEME_NAME-theme.md-focused:not(:empty) .md-checked.md-primary .md-container:before { background-color: '{{warn-color-0.26}}'; }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.ng-invalid.ng-dirty .md-select-value { color: '{{warn-500}}' !important; border-bottom-color: '{{warn-500}}' !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-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-value { color: '{{foreground-3}}'; } md-select.md-THEME_NAME-theme[disabled] .md-select-value.md-select-placeholder { color: '{{foreground-3}}'; }md-select-menu.md-THEME_NAME-theme md-option[disabled] { color: '{{foreground-3}}'; }md-select-menu.md-THEME_NAME-theme md-optgroup { color: '{{foreground-2}}'; } md-select-menu.md-THEME_NAME-theme md-optgroup md-option { color: '{{foreground-1}}'; }md-select-menu.md-THEME_NAME-theme md-option[selected] { color: '{{primary-500}}'; } md-select-menu.md-THEME_NAME-theme md-option[selected]:focus { color: '{{primary-600}}'; } md-select-menu.md-THEME_NAME-theme md-option[selected].md-accent { color: '{{accent-500}}'; } md-select-menu.md-THEME_NAME-theme md-option[selected].md-accent:focus { color: '{{accent-600}}'; }md-select-menu.md-THEME_NAME-theme md-option:focus:not([selected]) { background: '{{background-200}}'; }md-sidenav.md-THEME_NAME-theme { background-color: '{{background-color}}'; }md-slider.md-THEME_NAME-theme .md-track { background-color: '{{foreground-3}}'; }md-slider.md-THEME_NAME-theme .md-track-ticks { background-color: '{{foreground-4}}'; }md-slider.md-THEME_NAME-theme .md-focus-thumb { background-color: '{{foreground-2}}'; }md-slider.md-THEME_NAME-theme .md-focus-ring { background-color: '{{accent-color}}'; }md-slider.md-THEME_NAME-theme .md-disabled-thumb { border-color: '{{background-color}}'; }md-slider.md-THEME_NAME-theme.md-min .md-thumb:after { background-color: '{{background-color}}'; }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-thumb-text { color: '{{accent-contrast}}'; }md-slider.md-THEME_NAME-theme.md-warn .md-focus-ring { background-color: '{{warn-color}}'; }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-thumb-text { color: '{{warn-contrast}}'; }md-slider.md-THEME_NAME-theme.md-primary .md-focus-ring { background-color: '{{primary-color}}'; }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-thumb-text { color: '{{primary-contrast}}'; }md-slider.md-THEME_NAME-theme[disabled] .md-thumb:after { border-color: '{{foreground-3}}'; }md-slider.md-THEME_NAME-theme[disabled]:not(.md-min) .md-thumb:after { background-color: '{{foreground-3}}'; }.md-subheader.md-THEME_NAME-theme { color: '{{ foreground-2-0.23 }}'; background-color: '{{background-color}}'; } .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-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-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-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-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] { color: '{{foreground-3}}'; } md-tabs.md-THEME_NAME-theme .md-tab.md-active, md-tabs.md-THEME_NAME-theme .md-tab.md-focused { 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-100}}'; }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]) { color: '{{accent-100}}'; } 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-focused { 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]) { 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-focused { 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]) { 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-focused { 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]) { 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-focused { 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]) { color: '{{accent-100}}'; } 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-focused { 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]) { 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-focused { 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 { background-color: #323232; color: '{{background-50}}'; } md-toast.md-THEME_NAME-theme .md-button { color: '{{background-50}}'; } md-toast.md-THEME_NAME-theme .md-button.md-highlight { color: '{{primary-A200}}'; } md-toast.md-THEME_NAME-theme .md-button.md-highlight.md-accent { color: '{{accent-A200}}'; } md-toast.md-THEME_NAME-theme .md-button.md-highlight.md-warn { color: '{{warn-A200}}'; }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}}'; } md-toolbar.md-THEME_NAME-theme:not(.md-menu-toolbar) .md-button { color: '{{primary-contrast}}'; } 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-warn { background-color: '{{warn-color}}'; color: '{{warn-contrast}}'; }md-tooltip.md-THEME_NAME-theme { color: '{{background-A100}}'; } md-tooltip.md-THEME_NAME-theme .md-background { background-color: '{{foreground-2}}'; }");
  18666. })();
  18667. })(window, window.angular);