angular-material.js 763 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595
  1. /*!
  2. * Angular Material Design
  3. * https://github.com/angular/material
  4. * @license MIT
  5. * v0.11.4
  6. */
  7. (function( window, angular, undefined ){
  8. "use strict";
  9. (function(){
  10. "use strict";
  11. angular.module('ngMaterial', ["ng","ngAnimate","ngAria","material.core","material.core.gestures","material.core.layout","material.core.theming.palette","material.core.theming","material.core.animate","material.components.autocomplete","material.components.backdrop","material.components.bottomSheet","material.components.button","material.components.card","material.components.checkbox","material.components.chips","material.components.content","material.components.dialog","material.components.divider","material.components.datepicker","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.radioButton","material.components.progressLinear","material.components.select","material.components.sidenav","material.components.slider","material.components.sticky","material.components.subheader","material.components.swipe","material.components.switch","material.components.toast","material.components.tabs","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.core.animate',
  23. 'material.core.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 (angular.isDefined(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 (angular.isDefined(attrs[normalizedName])) {
  448. unwatchFns.push(
  449. attrs.$observe(normalizedName, angular.bind(void 0, watchFn, mediaName)));
  450. }
  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. findFocusTarget: function(containerEl, attributeVal) {
  564. var AUTO_FOCUS = '[md-autofocus]';
  565. var elToFocus;
  566. elToFocus = scanForFocusable(containerEl, attributeVal || AUTO_FOCUS);
  567. if ( !elToFocus && attributeVal != AUTO_FOCUS) {
  568. // Scan for deprecated attribute
  569. elToFocus = scanForFocusable(containerEl, '[md-auto-focus]');
  570. if ( !elToFocus ) {
  571. // Scan for fallback to 'universal' API
  572. elToFocus = scanForFocusable(containerEl, AUTO_FOCUS);
  573. }
  574. }
  575. return elToFocus;
  576. /**
  577. * Can target and nested children for specified Selector (attribute)
  578. * whose value may be an expression that evaluates to True/False.
  579. */
  580. function scanForFocusable(target, selector) {
  581. var elFound, items = target[0].querySelectorAll(selector);
  582. // Find the last child element with the focus attribute
  583. if ( items && items.length ){
  584. var EXP_ATTR = /\s*\[?([\-a-z]*)\]?\s*/i;
  585. var matches = EXP_ATTR.exec(selector);
  586. var attribute = matches ? matches[1] : null;
  587. items.length && angular.forEach(items, function(it) {
  588. it = angular.element(it);
  589. // If the expression evaluates to FALSE, then it is not focusable target
  590. var focusExpression = it[0].getAttribute(attribute);
  591. var isFocusable = !focusExpression || !$mdUtil.validateScope(it) ? true :
  592. (it.scope().$eval(focusExpression) !== false );
  593. if (isFocusable) elFound = it;
  594. });
  595. }
  596. return elFound;
  597. }
  598. },
  599. // Disables scroll around the passed element.
  600. disableScrollAround: function(element, parent) {
  601. $mdUtil.disableScrollAround._count = $mdUtil.disableScrollAround._count || 0;
  602. ++$mdUtil.disableScrollAround._count;
  603. if ($mdUtil.disableScrollAround._enableScrolling) return $mdUtil.disableScrollAround._enableScrolling;
  604. element = angular.element(element);
  605. var body = $document[0].body,
  606. restoreBody = disableBodyScroll(),
  607. restoreElement = disableElementScroll(parent);
  608. return $mdUtil.disableScrollAround._enableScrolling = function() {
  609. if (!--$mdUtil.disableScrollAround._count) {
  610. restoreBody();
  611. restoreElement();
  612. delete $mdUtil.disableScrollAround._enableScrolling;
  613. }
  614. };
  615. // Creates a virtual scrolling mask to absorb touchmove, keyboard, scrollbar clicking, and wheel events
  616. function disableElementScroll(element) {
  617. element = angular.element(element || body)[0];
  618. var zIndex = 50;
  619. var scrollMask = angular.element(
  620. '<div class="md-scroll-mask" style="z-index: ' + zIndex + '">' +
  621. ' <div class="md-scroll-mask-bar"></div>' +
  622. '</div>');
  623. element.appendChild(scrollMask[0]);
  624. scrollMask.on('wheel', preventDefault);
  625. scrollMask.on('touchmove', preventDefault);
  626. $document.on('keydown', disableKeyNav);
  627. return function restoreScroll() {
  628. scrollMask.off('wheel');
  629. scrollMask.off('touchmove');
  630. scrollMask[0].parentNode.removeChild(scrollMask[0]);
  631. $document.off('keydown', disableKeyNav);
  632. delete $mdUtil.disableScrollAround._enableScrolling;
  633. };
  634. // Prevent keypresses from elements inside the body
  635. // used to stop the keypresses that could cause the page to scroll
  636. // (arrow keys, spacebar, tab, etc).
  637. function disableKeyNav(e) {
  638. //-- temporarily removed this logic, will possibly re-add at a later date
  639. //if (!element[0].contains(e.target)) {
  640. // e.preventDefault();
  641. // e.stopImmediatePropagation();
  642. //}
  643. }
  644. function preventDefault(e) {
  645. e.preventDefault();
  646. }
  647. }
  648. // Converts the body to a position fixed block and translate it to the proper scroll
  649. // position
  650. function disableBodyScroll() {
  651. var htmlNode = body.parentNode;
  652. var restoreHtmlStyle = htmlNode.getAttribute('style') || '';
  653. var restoreBodyStyle = body.getAttribute('style') || '';
  654. var scrollOffset = $mdUtil.scrollTop(body);
  655. var clientWidth = body.clientWidth;
  656. if (body.scrollHeight > body.clientHeight) {
  657. applyStyles(body, {
  658. position: 'fixed',
  659. width: '100%',
  660. top: -scrollOffset + 'px'
  661. });
  662. applyStyles(htmlNode, {
  663. overflowY: 'scroll'
  664. });
  665. }
  666. if (body.clientWidth < clientWidth) applyStyles(body, {overflow: 'hidden'});
  667. return function restoreScroll() {
  668. body.setAttribute('style', restoreBodyStyle);
  669. htmlNode.setAttribute('style', restoreHtmlStyle);
  670. body.scrollTop = scrollOffset;
  671. };
  672. }
  673. function applyStyles(el, styles) {
  674. for (var key in styles) {
  675. el.style[key] = styles[key];
  676. }
  677. }
  678. },
  679. enableScrolling: function() {
  680. var method = this.disableScrollAround._enableScrolling;
  681. method && method();
  682. },
  683. floatingScrollbars: function() {
  684. if (this.floatingScrollbars.cached === undefined) {
  685. var tempNode = angular.element('<div style="width: 100%; z-index: -1; position: absolute; height: 35px; overflow-y: scroll"><div style="height: 60;"></div></div>');
  686. $document[0].body.appendChild(tempNode[0]);
  687. this.floatingScrollbars.cached = (tempNode[0].offsetWidth == tempNode[0].childNodes[0].offsetWidth);
  688. tempNode.remove();
  689. }
  690. return this.floatingScrollbars.cached;
  691. },
  692. // Mobile safari only allows you to set focus in click event listeners...
  693. forceFocus: function(element) {
  694. var node = element[0] || element;
  695. document.addEventListener('click', function focusOnClick(ev) {
  696. if (ev.target === node && ev.$focus) {
  697. node.focus();
  698. ev.stopImmediatePropagation();
  699. ev.preventDefault();
  700. node.removeEventListener('click', focusOnClick);
  701. }
  702. }, true);
  703. var newEvent = document.createEvent('MouseEvents');
  704. newEvent.initMouseEvent('click', false, true, window, {}, 0, 0, 0, 0,
  705. false, false, false, false, 0, null);
  706. newEvent.$material = true;
  707. newEvent.$focus = true;
  708. node.dispatchEvent(newEvent);
  709. },
  710. /**
  711. * facade to build md-backdrop element with desired styles
  712. * NOTE: Use $compile to trigger backdrop postLink function
  713. */
  714. createBackdrop: function(scope, addClass) {
  715. return $compile($mdUtil.supplant('<md-backdrop class="{0}">', [addClass]))(scope);
  716. },
  717. /**
  718. * supplant() method from Crockford's `Remedial Javascript`
  719. * Equivalent to use of $interpolate; without dependency on
  720. * interpolation symbols and scope. Note: the '{<token>}' can
  721. * be property names, property chains, or array indices.
  722. */
  723. supplant: function(template, values, pattern) {
  724. pattern = pattern || /\{([^\{\}]*)\}/g;
  725. return template.replace(pattern, function(a, b) {
  726. var p = b.split('.'),
  727. r = values;
  728. try {
  729. for (var s in p) {
  730. if (p.hasOwnProperty(s) ) {
  731. r = r[p[s]];
  732. }
  733. }
  734. } catch (e) {
  735. r = a;
  736. }
  737. return (typeof r === 'string' || typeof r === 'number') ? r : a;
  738. });
  739. },
  740. fakeNgModel: function() {
  741. return {
  742. $fake: true,
  743. $setTouched: angular.noop,
  744. $setViewValue: function(value) {
  745. this.$viewValue = value;
  746. this.$render(value);
  747. this.$viewChangeListeners.forEach(function(cb) {
  748. cb();
  749. });
  750. },
  751. $isEmpty: function(value) {
  752. return ('' + value).length === 0;
  753. },
  754. $parsers: [],
  755. $formatters: [],
  756. $viewChangeListeners: [],
  757. $render: angular.noop
  758. };
  759. },
  760. // Returns a function, that, as long as it continues to be invoked, will not
  761. // be triggered. The function will be called after it stops being called for
  762. // N milliseconds.
  763. // @param wait Integer value of msecs to delay (since last debounce reset); default value 10 msecs
  764. // @param invokeApply should the $timeout trigger $digest() dirty checking
  765. debounce: function(func, wait, scope, invokeApply) {
  766. var timer;
  767. return function debounced() {
  768. var context = scope,
  769. args = Array.prototype.slice.call(arguments);
  770. $timeout.cancel(timer);
  771. timer = $timeout(function() {
  772. timer = undefined;
  773. func.apply(context, args);
  774. }, wait || 10, invokeApply);
  775. };
  776. },
  777. // Returns a function that can only be triggered every `delay` milliseconds.
  778. // In other words, the function will not be called unless it has been more
  779. // than `delay` milliseconds since the last call.
  780. throttle: function throttle(func, delay) {
  781. var recent;
  782. return function throttled() {
  783. var context = this;
  784. var args = arguments;
  785. var now = $mdUtil.now();
  786. if (!recent || (now - recent > delay)) {
  787. func.apply(context, args);
  788. recent = now;
  789. }
  790. };
  791. },
  792. /**
  793. * Measures the number of milliseconds taken to run the provided callback
  794. * function. Uses a high-precision timer if available.
  795. */
  796. time: function time(cb) {
  797. var start = $mdUtil.now();
  798. cb();
  799. return $mdUtil.now() - start;
  800. },
  801. /**
  802. * Create an implicit getter that caches its `getter()`
  803. * lookup value
  804. */
  805. valueOnUse : function (scope, key, getter) {
  806. var value = null, args = Array.prototype.slice.call(arguments);
  807. var params = (args.length > 3) ? args.slice(3) : [ ];
  808. Object.defineProperty(scope, key, {
  809. get: function () {
  810. if (value === null) value = getter.apply(scope, params);
  811. return value;
  812. }
  813. });
  814. },
  815. /**
  816. * Get a unique ID.
  817. *
  818. * @returns {string} an unique numeric string
  819. */
  820. nextUid: function() {
  821. return '' + nextUniqueId++;
  822. },
  823. /**
  824. * By default AngularJS attaches information about binding and scopes to DOM nodes,
  825. * and adds CSS classes to data-bound elements. But this information is NOT available
  826. * when `$compileProvider.debugInfoEnabled(false);`
  827. *
  828. * @see https://docs.angularjs.org/guide/production
  829. */
  830. validateScope : function(element) {
  831. var hasScope = element && angular.isDefined(element.scope());
  832. if ( !hasScope ) {
  833. $log.warn("element.scope() is not available when 'debug mode' == false. @see https://docs.angularjs.org/guide/production!");
  834. }
  835. return hasScope;
  836. },
  837. // Stop watchers and events from firing on a scope without destroying it,
  838. // by disconnecting it from its parent and its siblings' linked lists.
  839. disconnectScope: function disconnectScope(scope) {
  840. if (!scope) return;
  841. // we can't destroy the root scope or a scope that has been already destroyed
  842. if (scope.$root === scope) return;
  843. if (scope.$$destroyed) return;
  844. var parent = scope.$parent;
  845. scope.$$disconnected = true;
  846. // See Scope.$destroy
  847. if (parent.$$childHead === scope) parent.$$childHead = scope.$$nextSibling;
  848. if (parent.$$childTail === scope) parent.$$childTail = scope.$$prevSibling;
  849. if (scope.$$prevSibling) scope.$$prevSibling.$$nextSibling = scope.$$nextSibling;
  850. if (scope.$$nextSibling) scope.$$nextSibling.$$prevSibling = scope.$$prevSibling;
  851. scope.$$nextSibling = scope.$$prevSibling = null;
  852. },
  853. // Undo the effects of disconnectScope above.
  854. reconnectScope: function reconnectScope(scope) {
  855. if (!scope) return;
  856. // we can't disconnect the root node or scope already disconnected
  857. if (scope.$root === scope) return;
  858. if (!scope.$$disconnected) return;
  859. var child = scope;
  860. var parent = child.$parent;
  861. child.$$disconnected = false;
  862. // See Scope.$new for this logic...
  863. child.$$prevSibling = parent.$$childTail;
  864. if (parent.$$childHead) {
  865. parent.$$childTail.$$nextSibling = child;
  866. parent.$$childTail = child;
  867. } else {
  868. parent.$$childHead = parent.$$childTail = child;
  869. }
  870. },
  871. /*
  872. * getClosest replicates jQuery.closest() to walk up the DOM tree until it finds a matching nodeName
  873. *
  874. * @param el Element to start walking the DOM from
  875. * @param tagName Tag name to find closest to el, such as 'form'
  876. */
  877. getClosest: function getClosest(el, tagName, onlyParent) {
  878. if (el instanceof angular.element) el = el[0];
  879. tagName = tagName.toUpperCase();
  880. if (onlyParent) el = el.parentNode;
  881. if (!el) return null;
  882. do {
  883. if (el.nodeName === tagName) {
  884. return el;
  885. }
  886. } while (el = el.parentNode);
  887. return null;
  888. },
  889. /**
  890. * Build polyfill for the Node.contains feature (if needed)
  891. */
  892. elementContains: function(node, child) {
  893. var hasContains = (window.Node && window.Node.prototype && Node.prototype.contains);
  894. var findFn = hasContains ? angular.bind(node, node.contains) : angular.bind(node, function(arg) {
  895. // compares the positions of two nodes and returns a bitmask
  896. return (node === child) || !!(this.compareDocumentPosition(arg) & 16)
  897. });
  898. return findFn(child);
  899. },
  900. /**
  901. * Functional equivalent for $element.filter(‘md-bottom-sheet’)
  902. * useful with interimElements where the element and its container are important...
  903. *
  904. * @param {[]} elements to scan
  905. * @param {string} name of node to find (e.g. 'md-dialog')
  906. * @param {boolean=} optional flag to allow deep scans; defaults to 'false'.
  907. * @param {boolean=} optional flag to enable log warnings; defaults to false
  908. */
  909. extractElementByName: function(element, nodeName, scanDeep, warnNotFound) {
  910. var found = scanTree(element);
  911. if (!found && !!warnNotFound) {
  912. $log.warn( $mdUtil.supplant("Unable to find node '{0}' in element '{1}'.",[nodeName, element[0].outerHTML]) );
  913. }
  914. return angular.element(found || element);
  915. /**
  916. * Breadth-First tree scan for element with matching `nodeName`
  917. */
  918. function scanTree(element) {
  919. return scanLevel(element) || (!!scanDeep ? scanChildren(element) : null);
  920. }
  921. /**
  922. * Case-insensitive scan of current elements only (do not descend).
  923. */
  924. function scanLevel(element) {
  925. if ( element ) {
  926. for (var i = 0, len = element.length; i < len; i++) {
  927. if (element[i].nodeName.toLowerCase() === nodeName) {
  928. return element[i];
  929. }
  930. }
  931. }
  932. return null;
  933. }
  934. /**
  935. * Scan children of specified node
  936. */
  937. function scanChildren(element) {
  938. var found;
  939. if ( element ) {
  940. for (var i = 0, len = element.length; i < len; i++) {
  941. var target = element[i];
  942. if ( !found ) {
  943. for (var j = 0, numChild = target.childNodes.length; j < numChild; j++) {
  944. found = found || scanTree([target.childNodes[j]]);
  945. }
  946. }
  947. }
  948. }
  949. return found;
  950. }
  951. },
  952. /**
  953. * Give optional properties with no value a boolean true if attr provided or false otherwise
  954. */
  955. initOptionalProperties: function(scope, attr, defaults) {
  956. defaults = defaults || {};
  957. angular.forEach(scope.$$isolateBindings, function(binding, key) {
  958. if (binding.optional && angular.isUndefined(scope[key])) {
  959. var attrIsDefined = angular.isDefined(attr[binding.attrName]);
  960. scope[key] = angular.isDefined(defaults[key]) ? defaults[key] : attrIsDefined;
  961. }
  962. });
  963. },
  964. /**
  965. * Alternative to $timeout calls with 0 delay.
  966. * nextTick() coalesces all calls within a single frame
  967. * to minimize $digest thrashing
  968. *
  969. * @param callback
  970. * @param digest
  971. * @returns {*}
  972. */
  973. nextTick: function(callback, digest, scope) {
  974. //-- grab function reference for storing state details
  975. var nextTick = $mdUtil.nextTick;
  976. var timeout = nextTick.timeout;
  977. var queue = nextTick.queue || [];
  978. //-- add callback to the queue
  979. queue.push(callback);
  980. //-- set default value for digest
  981. if (digest == null) digest = true;
  982. //-- store updated digest/queue values
  983. nextTick.digest = nextTick.digest || digest;
  984. nextTick.queue = queue;
  985. //-- either return existing timeout or create a new one
  986. return timeout || (nextTick.timeout = $timeout(processQueue, 0, false));
  987. /**
  988. * Grab a copy of the current queue
  989. * Clear the queue for future use
  990. * Process the existing queue
  991. * Trigger digest if necessary
  992. */
  993. function processQueue() {
  994. var skip = scope && scope.$$destroyed;
  995. var queue = !skip ? nextTick.queue : [];
  996. var digest = !skip ? nextTick.digest : null;
  997. nextTick.queue = [];
  998. nextTick.timeout = null;
  999. nextTick.digest = false;
  1000. queue.forEach(function(callback) {
  1001. callback();
  1002. });
  1003. if (digest) $rootScope.$digest();
  1004. }
  1005. },
  1006. /**
  1007. * Processes a template and replaces the start/end symbols if the application has
  1008. * overriden them.
  1009. *
  1010. * @param template The template to process whose start/end tags may be replaced.
  1011. * @returns {*}
  1012. */
  1013. processTemplate: function(template) {
  1014. if (usesStandardSymbols) {
  1015. return template;
  1016. } else {
  1017. if (!template || !angular.isString(template)) return template;
  1018. return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);
  1019. }
  1020. }
  1021. };
  1022. // Instantiate other namespace utility methods
  1023. $mdUtil.dom.animator = $$mdAnimate($mdUtil);
  1024. return $mdUtil;
  1025. function getNode(el) {
  1026. return el[0] || el;
  1027. }
  1028. }
  1029. UtilFactory.$inject = ["$document", "$timeout", "$compile", "$rootScope", "$$mdAnimate", "$interpolate", "$log"];
  1030. /*
  1031. * Since removing jQuery from the demos, some code that uses `element.focus()` is broken.
  1032. * We need to add `element.focus()`, because it's testable unlike `element[0].focus`.
  1033. */
  1034. angular.element.prototype.focus = angular.element.prototype.focus || function() {
  1035. if (this.length) {
  1036. this[0].focus();
  1037. }
  1038. return this;
  1039. };
  1040. angular.element.prototype.blur = angular.element.prototype.blur || function() {
  1041. if (this.length) {
  1042. this[0].blur();
  1043. }
  1044. return this;
  1045. };
  1046. })();
  1047. (function(){
  1048. "use strict";
  1049. angular.module('material.core')
  1050. .service('$mdAria', AriaService);
  1051. /*
  1052. * @ngInject
  1053. */
  1054. function AriaService($$rAF, $log, $window) {
  1055. return {
  1056. expect: expect,
  1057. expectAsync: expectAsync,
  1058. expectWithText: expectWithText
  1059. };
  1060. /**
  1061. * Check if expected attribute has been specified on the target element or child
  1062. * @param element
  1063. * @param attrName
  1064. * @param {optional} defaultValue What to set the attr to if no value is found
  1065. */
  1066. function expect(element, attrName, defaultValue) {
  1067. var node = angular.element(element)[0] || element;
  1068. // if node exists and neither it nor its children have the attribute
  1069. if (node &&
  1070. ((!node.hasAttribute(attrName) ||
  1071. node.getAttribute(attrName).length === 0) &&
  1072. !childHasAttribute(node, attrName))) {
  1073. defaultValue = angular.isString(defaultValue) ? defaultValue.trim() : '';
  1074. if (defaultValue.length) {
  1075. element.attr(attrName, defaultValue);
  1076. } else {
  1077. $log.warn('ARIA: Attribute "', attrName, '", required for accessibility, is missing on node:', node);
  1078. }
  1079. }
  1080. }
  1081. function expectAsync(element, attrName, defaultValueGetter) {
  1082. // Problem: when retrieving the element's contents synchronously to find the label,
  1083. // the text may not be defined yet in the case of a binding.
  1084. // There is a higher chance that a binding will be defined if we wait one frame.
  1085. $$rAF(function() {
  1086. expect(element, attrName, defaultValueGetter());
  1087. });
  1088. }
  1089. function expectWithText(element, attrName) {
  1090. expectAsync(element, attrName, function() {
  1091. return getText(element);
  1092. });
  1093. }
  1094. function getText(element) {
  1095. return element.text().trim();
  1096. }
  1097. function childHasAttribute(node, attrName) {
  1098. var hasChildren = node.hasChildNodes(),
  1099. hasAttr = false;
  1100. function isHidden(el) {
  1101. var style = el.currentStyle ? el.currentStyle : $window.getComputedStyle(el);
  1102. return (style.display === 'none');
  1103. }
  1104. if(hasChildren) {
  1105. var children = node.childNodes;
  1106. for(var i=0; i<children.length; i++){
  1107. var child = children[i];
  1108. if(child.nodeType === 1 && child.hasAttribute(attrName)) {
  1109. if(!isHidden(child)){
  1110. hasAttr = true;
  1111. }
  1112. }
  1113. }
  1114. }
  1115. return hasAttr;
  1116. }
  1117. }
  1118. AriaService.$inject = ["$$rAF", "$log", "$window"];
  1119. })();
  1120. (function(){
  1121. "use strict";
  1122. angular
  1123. .module('material.core')
  1124. .service('$mdCompiler', mdCompilerService);
  1125. function mdCompilerService($q, $http, $injector, $compile, $controller, $templateCache) {
  1126. /* jshint validthis: true */
  1127. /*
  1128. * @ngdoc service
  1129. * @name $mdCompiler
  1130. * @module material.core
  1131. * @description
  1132. * The $mdCompiler service is an abstraction of angular's compiler, that allows the developer
  1133. * to easily compile an element with a templateUrl, controller, and locals.
  1134. *
  1135. * @usage
  1136. * <hljs lang="js">
  1137. * $mdCompiler.compile({
  1138. * templateUrl: 'modal.html',
  1139. * controller: 'ModalCtrl',
  1140. * locals: {
  1141. * modal: myModalInstance;
  1142. * }
  1143. * }).then(function(compileData) {
  1144. * compileData.element; // modal.html's template in an element
  1145. * compileData.link(myScope); //attach controller & scope to element
  1146. * });
  1147. * </hljs>
  1148. */
  1149. /*
  1150. * @ngdoc method
  1151. * @name $mdCompiler#compile
  1152. * @description A helper to compile an HTML template/templateUrl with a given controller,
  1153. * locals, and scope.
  1154. * @param {object} options An options object, with the following properties:
  1155. *
  1156. * - `controller` - `{(string=|function()=}` Controller fn that should be associated with
  1157. * newly created scope or the name of a registered controller if passed as a string.
  1158. * - `controllerAs` - `{string=}` A controller alias name. If present the controller will be
  1159. * published to scope under the `controllerAs` name.
  1160. * - `template` - `{string=}` An html template as a string.
  1161. * - `templateUrl` - `{string=}` A path to an html template.
  1162. * - `transformTemplate` - `{function(template)=}` A function which transforms the template after
  1163. * it is loaded. It will be given the template string as a parameter, and should
  1164. * return a a new string representing the transformed template.
  1165. * - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should
  1166. * be injected into the controller. If any of these dependencies are promises, the compiler
  1167. * will wait for them all to be resolved, or if one is rejected before the controller is
  1168. * instantiated `compile()` will fail..
  1169. * * `key` - `{string}`: a name of a dependency to be injected into the controller.
  1170. * * `factory` - `{string|function}`: If `string` then it is an alias for a service.
  1171. * Otherwise if function, then it is injected and the return value is treated as the
  1172. * dependency. If the result is a promise, it is resolved before its value is
  1173. * injected into the controller.
  1174. *
  1175. * @returns {object=} promise A promise, which will be resolved with a `compileData` object.
  1176. * `compileData` has the following properties:
  1177. *
  1178. * - `element` - `{element}`: an uncompiled element matching the provided template.
  1179. * - `link` - `{function(scope)}`: A link function, which, when called, will compile
  1180. * the element and instantiate the provided controller (if given).
  1181. * - `locals` - `{object}`: The locals which will be passed into the controller once `link` is
  1182. * called. If `bindToController` is true, they will be coppied to the ctrl instead
  1183. * - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in.
  1184. */
  1185. this.compile = function(options) {
  1186. var templateUrl = options.templateUrl;
  1187. var template = options.template || '';
  1188. var controller = options.controller;
  1189. var controllerAs = options.controllerAs;
  1190. var resolve = angular.extend({}, options.resolve || {});
  1191. var locals = angular.extend({}, options.locals || {});
  1192. var transformTemplate = options.transformTemplate || angular.identity;
  1193. var bindToController = options.bindToController;
  1194. // Take resolve values and invoke them.
  1195. // Resolves can either be a string (value: 'MyRegisteredAngularConst'),
  1196. // or an invokable 'factory' of sorts: (value: function ValueGetter($dependency) {})
  1197. angular.forEach(resolve, function(value, key) {
  1198. if (angular.isString(value)) {
  1199. resolve[key] = $injector.get(value);
  1200. } else {
  1201. resolve[key] = $injector.invoke(value);
  1202. }
  1203. });
  1204. //Add the locals, which are just straight values to inject
  1205. //eg locals: { three: 3 }, will inject three into the controller
  1206. angular.extend(resolve, locals);
  1207. if (templateUrl) {
  1208. resolve.$template = $http.get(templateUrl, {cache: $templateCache})
  1209. .then(function(response) {
  1210. return response.data;
  1211. });
  1212. } else {
  1213. resolve.$template = $q.when(template);
  1214. }
  1215. // Wait for all the resolves to finish if they are promises
  1216. return $q.all(resolve).then(function(locals) {
  1217. var compiledData;
  1218. var template = transformTemplate(locals.$template);
  1219. var element = options.element || angular.element('<div>').html(template.trim()).contents();
  1220. var linkFn = $compile(element);
  1221. // Return a linking function that can be used later when the element is ready
  1222. return compiledData = {
  1223. locals: locals,
  1224. element: element,
  1225. link: function link(scope) {
  1226. locals.$scope = scope;
  1227. //Instantiate controller if it exists, because we have scope
  1228. if (controller) {
  1229. var invokeCtrl = $controller(controller, locals, true);
  1230. if (bindToController) {
  1231. angular.extend(invokeCtrl.instance, locals);
  1232. }
  1233. var ctrl = invokeCtrl();
  1234. //See angular-route source for this logic
  1235. element.data('$ngControllerController', ctrl);
  1236. element.children().data('$ngControllerController', ctrl);
  1237. if (controllerAs) {
  1238. scope[controllerAs] = ctrl;
  1239. }
  1240. // Publish reference to this controller
  1241. compiledData.controller = ctrl;
  1242. }
  1243. return linkFn(scope);
  1244. }
  1245. };
  1246. });
  1247. };
  1248. }
  1249. mdCompilerService.$inject = ["$q", "$http", "$injector", "$compile", "$controller", "$templateCache"];
  1250. })();
  1251. (function(){
  1252. "use strict";
  1253. var HANDLERS = {};
  1254. /* The state of the current 'pointer'
  1255. * The pointer represents the state of the current touch.
  1256. * It contains normalized x and y coordinates from DOM events,
  1257. * as well as other information abstracted from the DOM.
  1258. */
  1259. var pointer, lastPointer, forceSkipClickHijack = false;
  1260. /**
  1261. * The position of the most recent click if that click was on a label element.
  1262. * @type {{x: number, y: number}?}
  1263. */
  1264. var lastLabelClickPos = null;
  1265. // Used to attach event listeners once when multiple ng-apps are running.
  1266. var isInitialized = false;
  1267. angular
  1268. .module('material.core.gestures', [ ])
  1269. .provider('$mdGesture', MdGestureProvider)
  1270. .factory('$$MdGestureHandler', MdGestureHandler)
  1271. .run( attachToDocument );
  1272. /**
  1273. * @ngdoc service
  1274. * @name $mdGestureProvider
  1275. * @module material.core.gestures
  1276. *
  1277. * @description
  1278. * In some scenarios on Mobile devices (without jQuery), the click events should NOT be hijacked.
  1279. * `$mdGestureProvider` is used to configure the Gesture module to ignore or skip click hijacking on mobile
  1280. * devices.
  1281. *
  1282. * <hljs lang="js">
  1283. * app.config(function($mdGestureProvider) {
  1284. *
  1285. * // For mobile devices without jQuery loaded, do not
  1286. * // intercept click events during the capture phase.
  1287. * $mdGestureProvider.skipClickHijack();
  1288. *
  1289. * });
  1290. * </hljs>
  1291. *
  1292. */
  1293. function MdGestureProvider() { }
  1294. MdGestureProvider.prototype = {
  1295. // Publish access to setter to configure a variable BEFORE the
  1296. // $mdGesture service is instantiated...
  1297. skipClickHijack: function() {
  1298. return forceSkipClickHijack = true;
  1299. },
  1300. /**
  1301. * $get is used to build an instance of $mdGesture
  1302. * @ngInject
  1303. */
  1304. $get : ["$$MdGestureHandler", "$$rAF", "$timeout", function($$MdGestureHandler, $$rAF, $timeout) {
  1305. return new MdGesture($$MdGestureHandler, $$rAF, $timeout);
  1306. }]
  1307. };
  1308. /**
  1309. * MdGesture factory construction function
  1310. * @ngInject
  1311. */
  1312. function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
  1313. var userAgent = navigator.userAgent || navigator.vendor || window.opera;
  1314. var isIos = userAgent.match(/ipad|iphone|ipod/i);
  1315. var isAndroid = userAgent.match(/android/i);
  1316. var hasJQuery = (typeof window.jQuery !== 'undefined') && (angular.element === window.jQuery);
  1317. var self = {
  1318. handler: addHandler,
  1319. register: register,
  1320. // On mobile w/out jQuery, we normally intercept clicks. Should we skip that?
  1321. isHijackingClicks: (isIos || isAndroid) && !hasJQuery && !forceSkipClickHijack
  1322. };
  1323. if (self.isHijackingClicks) {
  1324. self.handler('click', {
  1325. options: {
  1326. maxDistance: 6
  1327. },
  1328. onEnd: function (ev, pointer) {
  1329. if (pointer.distance < this.state.options.maxDistance) {
  1330. this.dispatchEvent(ev, 'click');
  1331. }
  1332. }
  1333. });
  1334. }
  1335. /*
  1336. * Register an element to listen for a handler.
  1337. * This allows an element to override the default options for a handler.
  1338. * Additionally, some handlers like drag and hold only dispatch events if
  1339. * the domEvent happens inside an element that's registered to listen for these events.
  1340. *
  1341. * @see GestureHandler for how overriding of default options works.
  1342. * @example $mdGesture.register(myElement, 'drag', { minDistance: 20, horziontal: false })
  1343. */
  1344. function register(element, handlerName, options) {
  1345. var handler = HANDLERS[handlerName.replace(/^\$md./, '')];
  1346. if (!handler) {
  1347. throw new Error('Failed to register element with handler ' + handlerName + '. ' +
  1348. 'Available handlers: ' + Object.keys(HANDLERS).join(', '));
  1349. }
  1350. return handler.registerElement(element, options);
  1351. }
  1352. /*
  1353. * add a handler to $mdGesture. see below.
  1354. */
  1355. function addHandler(name, definition) {
  1356. var handler = new $$MdGestureHandler(name);
  1357. angular.extend(handler, definition);
  1358. HANDLERS[name] = handler;
  1359. return self;
  1360. }
  1361. /*
  1362. * Register handlers. These listen to touch/start/move events, interpret them,
  1363. * and dispatch gesture events depending on options & conditions. These are all
  1364. * instances of GestureHandler.
  1365. * @see GestureHandler
  1366. */
  1367. return self
  1368. /*
  1369. * The press handler dispatches an event on touchdown/touchend.
  1370. * It's a simple abstraction of touch/mouse/pointer start and end.
  1371. */
  1372. .handler('press', {
  1373. onStart: function (ev, pointer) {
  1374. this.dispatchEvent(ev, '$md.pressdown');
  1375. },
  1376. onEnd: function (ev, pointer) {
  1377. this.dispatchEvent(ev, '$md.pressup');
  1378. }
  1379. })
  1380. /*
  1381. * The hold handler dispatches an event if the user keeps their finger within
  1382. * the same <maxDistance> area for <delay> ms.
  1383. * The hold handler will only run if a parent of the touch target is registered
  1384. * to listen for hold events through $mdGesture.register()
  1385. */
  1386. .handler('hold', {
  1387. options: {
  1388. maxDistance: 6,
  1389. delay: 500
  1390. },
  1391. onCancel: function () {
  1392. $timeout.cancel(this.state.timeout);
  1393. },
  1394. onStart: function (ev, pointer) {
  1395. // For hold, require a parent to be registered with $mdGesture.register()
  1396. // Because we prevent scroll events, this is necessary.
  1397. if (!this.state.registeredParent) return this.cancel();
  1398. this.state.pos = {x: pointer.x, y: pointer.y};
  1399. this.state.timeout = $timeout(angular.bind(this, function holdDelayFn() {
  1400. this.dispatchEvent(ev, '$md.hold');
  1401. this.cancel(); //we're done!
  1402. }), this.state.options.delay, false);
  1403. },
  1404. onMove: function (ev, pointer) {
  1405. // Don't scroll while waiting for hold.
  1406. // If we don't preventDefault touchmove events here, Android will assume we don't
  1407. // want to listen to anymore touch events. It will start scrolling and stop sending
  1408. // touchmove events.
  1409. ev.preventDefault();
  1410. // If the user moves greater than <maxDistance> pixels, stop the hold timer
  1411. // set in onStart
  1412. var dx = this.state.pos.x - pointer.x;
  1413. var dy = this.state.pos.y - pointer.y;
  1414. if (Math.sqrt(dx * dx + dy * dy) > this.options.maxDistance) {
  1415. this.cancel();
  1416. }
  1417. },
  1418. onEnd: function () {
  1419. this.onCancel();
  1420. }
  1421. })
  1422. /*
  1423. * The drag handler dispatches a drag event if the user holds and moves his finger greater than
  1424. * <minDistance> px in the x or y direction, depending on options.horizontal.
  1425. * The drag will be cancelled if the user moves his finger greater than <minDistance>*<cancelMultiplier> in
  1426. * the perpindicular direction. Eg if the drag is horizontal and the user moves his finger <minDistance>*<cancelMultiplier>
  1427. * pixels vertically, this handler won't consider the move part of a drag.
  1428. */
  1429. .handler('drag', {
  1430. options: {
  1431. minDistance: 6,
  1432. horizontal: true,
  1433. cancelMultiplier: 1.5
  1434. },
  1435. onStart: function (ev) {
  1436. // For drag, require a parent to be registered with $mdGesture.register()
  1437. if (!this.state.registeredParent) this.cancel();
  1438. },
  1439. onMove: function (ev, pointer) {
  1440. var shouldStartDrag, shouldCancel;
  1441. // Don't scroll while deciding if this touchmove qualifies as a drag event.
  1442. // If we don't preventDefault touchmove events here, Android will assume we don't
  1443. // want to listen to anymore touch events. It will start scrolling and stop sending
  1444. // touchmove events.
  1445. ev.preventDefault();
  1446. if (!this.state.dragPointer) {
  1447. if (this.state.options.horizontal) {
  1448. shouldStartDrag = Math.abs(pointer.distanceX) > this.state.options.minDistance;
  1449. shouldCancel = Math.abs(pointer.distanceY) > this.state.options.minDistance * this.state.options.cancelMultiplier;
  1450. } else {
  1451. shouldStartDrag = Math.abs(pointer.distanceY) > this.state.options.minDistance;
  1452. shouldCancel = Math.abs(pointer.distanceX) > this.state.options.minDistance * this.state.options.cancelMultiplier;
  1453. }
  1454. if (shouldStartDrag) {
  1455. // Create a new pointer representing this drag, starting at this point where the drag started.
  1456. this.state.dragPointer = makeStartPointer(ev);
  1457. updatePointerState(ev, this.state.dragPointer);
  1458. this.dispatchEvent(ev, '$md.dragstart', this.state.dragPointer);
  1459. } else if (shouldCancel) {
  1460. this.cancel();
  1461. }
  1462. } else {
  1463. this.dispatchDragMove(ev);
  1464. }
  1465. },
  1466. // Only dispatch dragmove events every frame; any more is unnecessray
  1467. dispatchDragMove: $$rAF.throttle(function (ev) {
  1468. // Make sure the drag didn't stop while waiting for the next frame
  1469. if (this.state.isRunning) {
  1470. updatePointerState(ev, this.state.dragPointer);
  1471. this.dispatchEvent(ev, '$md.drag', this.state.dragPointer);
  1472. }
  1473. }),
  1474. onEnd: function (ev, pointer) {
  1475. if (this.state.dragPointer) {
  1476. updatePointerState(ev, this.state.dragPointer);
  1477. this.dispatchEvent(ev, '$md.dragend', this.state.dragPointer);
  1478. }
  1479. }
  1480. })
  1481. /*
  1482. * The swipe handler will dispatch a swipe event if, on the end of a touch,
  1483. * the velocity and distance were high enough.
  1484. * TODO: add vertical swiping with a `horizontal` option similar to the drag handler.
  1485. */
  1486. .handler('swipe', {
  1487. options: {
  1488. minVelocity: 0.65,
  1489. minDistance: 10
  1490. },
  1491. onEnd: function (ev, pointer) {
  1492. if (Math.abs(pointer.velocityX) > this.state.options.minVelocity &&
  1493. Math.abs(pointer.distanceX) > this.state.options.minDistance) {
  1494. var eventType = pointer.directionX == 'left' ? '$md.swipeleft' : '$md.swiperight';
  1495. this.dispatchEvent(ev, eventType);
  1496. }
  1497. }
  1498. });
  1499. }
  1500. MdGesture.$inject = ["$$MdGestureHandler", "$$rAF", "$timeout"];
  1501. /**
  1502. * MdGestureHandler
  1503. * A GestureHandler is an object which is able to dispatch custom dom events
  1504. * based on native dom {touch,pointer,mouse}{start,move,end} events.
  1505. *
  1506. * A gesture will manage its lifecycle through the start,move,end, and cancel
  1507. * functions, which are called by native dom events.
  1508. *
  1509. * A gesture has the concept of 'options' (eg a swipe's required velocity), which can be
  1510. * overridden by elements registering through $mdGesture.register()
  1511. */
  1512. function GestureHandler (name) {
  1513. this.name = name;
  1514. this.state = {};
  1515. }
  1516. function MdGestureHandler() {
  1517. var hasJQuery = (typeof window.jQuery !== 'undefined') && (angular.element === window.jQuery);
  1518. GestureHandler.prototype = {
  1519. options: {},
  1520. // jQuery listeners don't work with custom DOMEvents, so we have to dispatch events
  1521. // differently when jQuery is loaded
  1522. dispatchEvent: hasJQuery ? jQueryDispatchEvent : nativeDispatchEvent,
  1523. // These are overridden by the registered handler
  1524. onStart: angular.noop,
  1525. onMove: angular.noop,
  1526. onEnd: angular.noop,
  1527. onCancel: angular.noop,
  1528. // onStart sets up a new state for the handler, which includes options from the
  1529. // nearest registered parent element of ev.target.
  1530. start: function (ev, pointer) {
  1531. if (this.state.isRunning) return;
  1532. var parentTarget = this.getNearestParent(ev.target);
  1533. // Get the options from the nearest registered parent
  1534. var parentTargetOptions = parentTarget && parentTarget.$mdGesture[this.name] || {};
  1535. this.state = {
  1536. isRunning: true,
  1537. // Override the default options with the nearest registered parent's options
  1538. options: angular.extend({}, this.options, parentTargetOptions),
  1539. // Pass in the registered parent node to the state so the onStart listener can use
  1540. registeredParent: parentTarget
  1541. };
  1542. this.onStart(ev, pointer);
  1543. },
  1544. move: function (ev, pointer) {
  1545. if (!this.state.isRunning) return;
  1546. this.onMove(ev, pointer);
  1547. },
  1548. end: function (ev, pointer) {
  1549. if (!this.state.isRunning) return;
  1550. this.onEnd(ev, pointer);
  1551. this.state.isRunning = false;
  1552. },
  1553. cancel: function (ev, pointer) {
  1554. this.onCancel(ev, pointer);
  1555. this.state = {};
  1556. },
  1557. // Find and return the nearest parent element that has been registered to
  1558. // listen for this handler via $mdGesture.register(element, 'handlerName').
  1559. getNearestParent: function (node) {
  1560. var current = node;
  1561. while (current) {
  1562. if ((current.$mdGesture || {})[this.name]) {
  1563. return current;
  1564. }
  1565. current = current.parentNode;
  1566. }
  1567. return null;
  1568. },
  1569. // Called from $mdGesture.register when an element reigsters itself with a handler.
  1570. // Store the options the user gave on the DOMElement itself. These options will
  1571. // be retrieved with getNearestParent when the handler starts.
  1572. registerElement: function (element, options) {
  1573. var self = this;
  1574. element[0].$mdGesture = element[0].$mdGesture || {};
  1575. element[0].$mdGesture[this.name] = options || {};
  1576. element.on('$destroy', onDestroy);
  1577. return onDestroy;
  1578. function onDestroy() {
  1579. delete element[0].$mdGesture[self.name];
  1580. element.off('$destroy', onDestroy);
  1581. }
  1582. }
  1583. };
  1584. return GestureHandler;
  1585. /*
  1586. * Dispatch an event with jQuery
  1587. * TODO: Make sure this sends bubbling events
  1588. *
  1589. * @param srcEvent the original DOM touch event that started this.
  1590. * @param eventType the name of the custom event to send (eg 'click' or '$md.drag')
  1591. * @param eventPointer the pointer object that matches this event.
  1592. */
  1593. function jQueryDispatchEvent(srcEvent, eventType, eventPointer) {
  1594. eventPointer = eventPointer || pointer;
  1595. var eventObj = new angular.element.Event(eventType);
  1596. eventObj.$material = true;
  1597. eventObj.pointer = eventPointer;
  1598. eventObj.srcEvent = srcEvent;
  1599. angular.extend(eventObj, {
  1600. clientX: eventPointer.x,
  1601. clientY: eventPointer.y,
  1602. screenX: eventPointer.x,
  1603. screenY: eventPointer.y,
  1604. pageX: eventPointer.x,
  1605. pageY: eventPointer.y,
  1606. ctrlKey: srcEvent.ctrlKey,
  1607. altKey: srcEvent.altKey,
  1608. shiftKey: srcEvent.shiftKey,
  1609. metaKey: srcEvent.metaKey
  1610. });
  1611. angular.element(eventPointer.target).trigger(eventObj);
  1612. }
  1613. /*
  1614. * NOTE: nativeDispatchEvent is very performance sensitive.
  1615. * @param srcEvent the original DOM touch event that started this.
  1616. * @param eventType the name of the custom event to send (eg 'click' or '$md.drag')
  1617. * @param eventPointer the pointer object that matches this event.
  1618. */
  1619. function nativeDispatchEvent(srcEvent, eventType, eventPointer) {
  1620. eventPointer = eventPointer || pointer;
  1621. var eventObj;
  1622. if (eventType === 'click') {
  1623. eventObj = document.createEvent('MouseEvents');
  1624. eventObj.initMouseEvent(
  1625. 'click', true, true, window, srcEvent.detail,
  1626. eventPointer.x, eventPointer.y, eventPointer.x, eventPointer.y,
  1627. srcEvent.ctrlKey, srcEvent.altKey, srcEvent.shiftKey, srcEvent.metaKey,
  1628. srcEvent.button, srcEvent.relatedTarget || null
  1629. );
  1630. } else {
  1631. eventObj = document.createEvent('CustomEvent');
  1632. eventObj.initCustomEvent(eventType, true, true, {});
  1633. }
  1634. eventObj.$material = true;
  1635. eventObj.pointer = eventPointer;
  1636. eventObj.srcEvent = srcEvent;
  1637. eventPointer.target.dispatchEvent(eventObj);
  1638. }
  1639. }
  1640. /**
  1641. * Attach Gestures: hook document and check shouldHijack clicks
  1642. * @ngInject
  1643. */
  1644. function attachToDocument( $mdGesture, $$MdGestureHandler ) {
  1645. // Polyfill document.contains for IE11.
  1646. // TODO: move to util
  1647. document.contains || (document.contains = function (node) {
  1648. return document.body.contains(node);
  1649. });
  1650. if (!isInitialized && $mdGesture.isHijackingClicks ) {
  1651. /*
  1652. * If hijack clicks is true, we preventDefault any click that wasn't
  1653. * sent by ngMaterial. This is because on older Android & iOS, a false, or 'ghost',
  1654. * click event will be sent ~400ms after a touchend event happens.
  1655. * The only way to know if this click is real is to prevent any normal
  1656. * click events, and add a flag to events sent by material so we know not to prevent those.
  1657. *
  1658. * Two exceptions to click events that should be prevented are:
  1659. * - click events sent by the keyboard (eg form submit)
  1660. * - events that originate from an Ionic app
  1661. */
  1662. document.addEventListener('click', function clickHijacker(ev) {
  1663. var isKeyClick = ev.clientX === 0 && ev.clientY === 0;
  1664. if (!isKeyClick && !ev.$material && !ev.isIonicTap
  1665. && !isInputEventFromLabelClick(ev)) {
  1666. ev.preventDefault();
  1667. ev.stopPropagation();
  1668. lastLabelClickPos = null;
  1669. } else {
  1670. lastLabelClickPos = null;
  1671. if (ev.target.tagName.toLowerCase() == 'label') {
  1672. lastLabelClickPos = {x: ev.x, y: ev.y};
  1673. }
  1674. }
  1675. }, true);
  1676. isInitialized = true;
  1677. }
  1678. // Listen to all events to cover all platforms.
  1679. var START_EVENTS = 'mousedown touchstart pointerdown';
  1680. var MOVE_EVENTS = 'mousemove touchmove pointermove';
  1681. var END_EVENTS = 'mouseup mouseleave touchend touchcancel pointerup pointercancel';
  1682. angular.element(document)
  1683. .on(START_EVENTS, gestureStart)
  1684. .on(MOVE_EVENTS, gestureMove)
  1685. .on(END_EVENTS, gestureEnd)
  1686. // For testing
  1687. .on('$$mdGestureReset', function gestureClearCache () {
  1688. lastPointer = pointer = null;
  1689. });
  1690. /*
  1691. * When a DOM event happens, run all registered gesture handlers' lifecycle
  1692. * methods which match the DOM event.
  1693. * Eg when a 'touchstart' event happens, runHandlers('start') will call and
  1694. * run `handler.cancel()` and `handler.start()` on all registered handlers.
  1695. */
  1696. function runHandlers(handlerEvent, event) {
  1697. var handler;
  1698. for (var name in HANDLERS) {
  1699. handler = HANDLERS[name];
  1700. if( handler instanceof $$MdGestureHandler ) {
  1701. if (handlerEvent === 'start') {
  1702. // Run cancel to reset any handlers' state
  1703. handler.cancel();
  1704. }
  1705. handler[handlerEvent](event, pointer);
  1706. }
  1707. }
  1708. }
  1709. /*
  1710. * gestureStart vets if a start event is legitimate (and not part of a 'ghost click' from iOS/Android)
  1711. * If it is legitimate, we initiate the pointer state and mark the current pointer's type
  1712. * For example, for a touchstart event, mark the current pointer as a 'touch' pointer, so mouse events
  1713. * won't effect it.
  1714. */
  1715. function gestureStart(ev) {
  1716. // If we're already touched down, abort
  1717. if (pointer) return;
  1718. var now = +Date.now();
  1719. // iOS & old android bug: after a touch event, a click event is sent 350 ms later.
  1720. // If <400ms have passed, don't allow an event of a different type than the previous event
  1721. if (lastPointer && !typesMatch(ev, lastPointer) && (now - lastPointer.endTime < 1500)) {
  1722. return;
  1723. }
  1724. pointer = makeStartPointer(ev);
  1725. runHandlers('start', ev);
  1726. }
  1727. /*
  1728. * If a move event happens of the right type, update the pointer and run all the move handlers.
  1729. * "of the right type": if a mousemove happens but our pointer started with a touch event, do nothing.
  1730. */
  1731. function gestureMove(ev) {
  1732. if (!pointer || !typesMatch(ev, pointer)) return;
  1733. updatePointerState(ev, pointer);
  1734. runHandlers('move', ev);
  1735. }
  1736. /*
  1737. * If an end event happens of the right type, update the pointer, run endHandlers, and save the pointer as 'lastPointer'
  1738. */
  1739. function gestureEnd(ev) {
  1740. if (!pointer || !typesMatch(ev, pointer)) return;
  1741. updatePointerState(ev, pointer);
  1742. pointer.endTime = +Date.now();
  1743. runHandlers('end', ev);
  1744. lastPointer = pointer;
  1745. pointer = null;
  1746. }
  1747. }
  1748. attachToDocument.$inject = ["$mdGesture", "$$MdGestureHandler"];
  1749. // ********************
  1750. // Module Functions
  1751. // ********************
  1752. /*
  1753. * Initiate the pointer. x, y, and the pointer's type.
  1754. */
  1755. function makeStartPointer(ev) {
  1756. var point = getEventPoint(ev);
  1757. var startPointer = {
  1758. startTime: +Date.now(),
  1759. target: ev.target,
  1760. // 'p' for pointer events, 'm' for mouse, 't' for touch
  1761. type: ev.type.charAt(0)
  1762. };
  1763. startPointer.startX = startPointer.x = point.pageX;
  1764. startPointer.startY = startPointer.y = point.pageY;
  1765. return startPointer;
  1766. }
  1767. /*
  1768. * return whether the pointer's type matches the event's type.
  1769. * Eg if a touch event happens but the pointer has a mouse type, return false.
  1770. */
  1771. function typesMatch(ev, pointer) {
  1772. return ev && pointer && ev.type.charAt(0) === pointer.type;
  1773. }
  1774. /**
  1775. * Gets whether the given event is an input event that was caused by clicking on an
  1776. * associated label element.
  1777. *
  1778. * This is necessary because the browser will, upon clicking on a label element, fire an
  1779. * *extra* click event on its associated input (if any). mdGesture is able to flag the label
  1780. * click as with `$material` correctly, but not the second input click.
  1781. *
  1782. * In order to determine whether an input event is from a label click, we compare the (x, y) for
  1783. * the event to the (x, y) for the most recent label click (which is cleared whenever a non-label
  1784. * click occurs). Unfortunately, there are no event properties that tie the input and the label
  1785. * together (such as relatedTarget).
  1786. *
  1787. * @param {MouseEvent} event
  1788. * @returns {boolean}
  1789. */
  1790. function isInputEventFromLabelClick(event) {
  1791. return lastLabelClickPos
  1792. && lastLabelClickPos.x == event.x
  1793. && lastLabelClickPos.y == event.y;
  1794. }
  1795. /*
  1796. * Update the given pointer based upon the given DOMEvent.
  1797. * Distance, velocity, direction, duration, etc
  1798. */
  1799. function updatePointerState(ev, pointer) {
  1800. var point = getEventPoint(ev);
  1801. var x = pointer.x = point.pageX;
  1802. var y = pointer.y = point.pageY;
  1803. pointer.distanceX = x - pointer.startX;
  1804. pointer.distanceY = y - pointer.startY;
  1805. pointer.distance = Math.sqrt(
  1806. pointer.distanceX * pointer.distanceX + pointer.distanceY * pointer.distanceY
  1807. );
  1808. pointer.directionX = pointer.distanceX > 0 ? 'right' : pointer.distanceX < 0 ? 'left' : '';
  1809. pointer.directionY = pointer.distanceY > 0 ? 'up' : pointer.distanceY < 0 ? 'down' : '';
  1810. pointer.duration = +Date.now() - pointer.startTime;
  1811. pointer.velocityX = pointer.distanceX / pointer.duration;
  1812. pointer.velocityY = pointer.distanceY / pointer.duration;
  1813. }
  1814. /*
  1815. * Normalize the point where the DOM event happened whether it's touch or mouse.
  1816. * @returns point event obj with pageX and pageY on it.
  1817. */
  1818. function getEventPoint(ev) {
  1819. ev = ev.originalEvent || ev; // support jQuery events
  1820. return (ev.touches && ev.touches[0]) ||
  1821. (ev.changedTouches && ev.changedTouches[0]) ||
  1822. ev;
  1823. }
  1824. })();
  1825. (function(){
  1826. "use strict";
  1827. angular.module('material.core')
  1828. .provider('$$interimElement', InterimElementProvider);
  1829. /*
  1830. * @ngdoc service
  1831. * @name $$interimElement
  1832. * @module material.core
  1833. *
  1834. * @description
  1835. *
  1836. * Factory that contructs `$$interimElement.$service` services.
  1837. * Used internally in material design for elements that appear on screen temporarily.
  1838. * The service provides a promise-like API for interacting with the temporary
  1839. * elements.
  1840. *
  1841. * ```js
  1842. * app.service('$mdToast', function($$interimElement) {
  1843. * var $mdToast = $$interimElement(toastDefaultOptions);
  1844. * return $mdToast;
  1845. * });
  1846. * ```
  1847. * @param {object=} defaultOptions Options used by default for the `show` method on the service.
  1848. *
  1849. * @returns {$$interimElement.$service}
  1850. *
  1851. */
  1852. function InterimElementProvider() {
  1853. createInterimElementProvider.$get = InterimElementFactory;
  1854. InterimElementFactory.$inject = ["$document", "$q", "$$q", "$rootScope", "$timeout", "$rootElement", "$animate", "$mdUtil", "$mdCompiler", "$mdTheming", "$log"];
  1855. return createInterimElementProvider;
  1856. /**
  1857. * Returns a new provider which allows configuration of a new interimElement
  1858. * service. Allows configuration of default options & methods for options,
  1859. * as well as configuration of 'preset' methods (eg dialog.basic(): basic is a preset method)
  1860. */
  1861. function createInterimElementProvider(interimFactoryName) {
  1862. var EXPOSED_METHODS = ['onHide', 'onShow', 'onRemove'];
  1863. var customMethods = {};
  1864. var providerConfig = {
  1865. presets: {}
  1866. };
  1867. var provider = {
  1868. setDefaults: setDefaults,
  1869. addPreset: addPreset,
  1870. addMethod: addMethod,
  1871. $get: factory
  1872. };
  1873. /**
  1874. * all interim elements will come with the 'build' preset
  1875. */
  1876. provider.addPreset('build', {
  1877. methods: ['controller', 'controllerAs', 'resolve',
  1878. 'template', 'templateUrl', 'themable', 'transformTemplate', 'parent']
  1879. });
  1880. factory.$inject = ["$$interimElement", "$injector"];
  1881. return provider;
  1882. /**
  1883. * Save the configured defaults to be used when the factory is instantiated
  1884. */
  1885. function setDefaults(definition) {
  1886. providerConfig.optionsFactory = definition.options;
  1887. providerConfig.methods = (definition.methods || []).concat(EXPOSED_METHODS);
  1888. return provider;
  1889. }
  1890. /**
  1891. * Add a method to the factory that isn't specific to any interim element operations
  1892. */
  1893. function addMethod(name, fn) {
  1894. customMethods[name] = fn;
  1895. return provider;
  1896. }
  1897. /**
  1898. * Save the configured preset to be used when the factory is instantiated
  1899. */
  1900. function addPreset(name, definition) {
  1901. definition = definition || {};
  1902. definition.methods = definition.methods || [];
  1903. definition.options = definition.options || function() { return {}; };
  1904. if (/^cancel|hide|show$/.test(name)) {
  1905. throw new Error("Preset '" + name + "' in " + interimFactoryName + " is reserved!");
  1906. }
  1907. if (definition.methods.indexOf('_options') > -1) {
  1908. throw new Error("Method '_options' in " + interimFactoryName + " is reserved!");
  1909. }
  1910. providerConfig.presets[name] = {
  1911. methods: definition.methods.concat(EXPOSED_METHODS),
  1912. optionsFactory: definition.options,
  1913. argOption: definition.argOption
  1914. };
  1915. return provider;
  1916. }
  1917. /**
  1918. * Create a factory that has the given methods & defaults implementing interimElement
  1919. */
  1920. /* @ngInject */
  1921. function factory($$interimElement, $injector) {
  1922. var defaultMethods;
  1923. var defaultOptions;
  1924. var interimElementService = $$interimElement();
  1925. /*
  1926. * publicService is what the developer will be using.
  1927. * It has methods hide(), cancel(), show(), build(), and any other
  1928. * presets which were set during the config phase.
  1929. */
  1930. var publicService = {
  1931. hide: interimElementService.hide,
  1932. cancel: interimElementService.cancel,
  1933. show: showInterimElement,
  1934. // Special internal method to destroy an interim element without animations
  1935. // used when navigation changes causes a $scope.$destroy() action
  1936. destroy : destroyInterimElement
  1937. };
  1938. defaultMethods = providerConfig.methods || [];
  1939. // This must be invoked after the publicService is initialized
  1940. defaultOptions = invokeFactory(providerConfig.optionsFactory, {});
  1941. // Copy over the simple custom methods
  1942. angular.forEach(customMethods, function(fn, name) {
  1943. publicService[name] = fn;
  1944. });
  1945. angular.forEach(providerConfig.presets, function(definition, name) {
  1946. var presetDefaults = invokeFactory(definition.optionsFactory, {});
  1947. var presetMethods = (definition.methods || []).concat(defaultMethods);
  1948. // Every interimElement built with a preset has a field called `$type`,
  1949. // which matches the name of the preset.
  1950. // Eg in preset 'confirm', options.$type === 'confirm'
  1951. angular.extend(presetDefaults, { $type: name });
  1952. // This creates a preset class which has setter methods for every
  1953. // method given in the `.addPreset()` function, as well as every
  1954. // method given in the `.setDefaults()` function.
  1955. //
  1956. // @example
  1957. // .setDefaults({
  1958. // methods: ['hasBackdrop', 'clickOutsideToClose', 'escapeToClose', 'targetEvent'],
  1959. // options: dialogDefaultOptions
  1960. // })
  1961. // .addPreset('alert', {
  1962. // methods: ['title', 'ok'],
  1963. // options: alertDialogOptions
  1964. // })
  1965. //
  1966. // Set values will be passed to the options when interimElement.show() is called.
  1967. function Preset(opts) {
  1968. this._options = angular.extend({}, presetDefaults, opts);
  1969. }
  1970. angular.forEach(presetMethods, function(name) {
  1971. Preset.prototype[name] = function(value) {
  1972. this._options[name] = value;
  1973. return this;
  1974. };
  1975. });
  1976. // Create shortcut method for one-linear methods
  1977. if (definition.argOption) {
  1978. var methodName = 'show' + name.charAt(0).toUpperCase() + name.slice(1);
  1979. publicService[methodName] = function(arg) {
  1980. var config = publicService[name](arg);
  1981. return publicService.show(config);
  1982. };
  1983. }
  1984. // eg $mdDialog.alert() will return a new alert preset
  1985. publicService[name] = function(arg) {
  1986. // If argOption is supplied, eg `argOption: 'content'`, then we assume
  1987. // if the argument is not an options object then it is the `argOption` option.
  1988. //
  1989. // @example `$mdToast.simple('hello')` // sets options.content to hello
  1990. // // because argOption === 'content'
  1991. if (arguments.length && definition.argOption &&
  1992. !angular.isObject(arg) && !angular.isArray(arg)) {
  1993. return (new Preset())[definition.argOption](arg);
  1994. } else {
  1995. return new Preset(arg);
  1996. }
  1997. };
  1998. });
  1999. return publicService;
  2000. /**
  2001. *
  2002. */
  2003. function showInterimElement(opts) {
  2004. // opts is either a preset which stores its options on an _options field,
  2005. // or just an object made up of options
  2006. opts = opts || { };
  2007. if (opts._options) opts = opts._options;
  2008. return interimElementService.show(
  2009. angular.extend({}, defaultOptions, opts)
  2010. );
  2011. }
  2012. /**
  2013. * Special method to hide and destroy an interimElement WITHOUT
  2014. * any 'leave` or hide animations ( an immediate force hide/remove )
  2015. *
  2016. * NOTE: This calls the onRemove() subclass method for each component...
  2017. * which must have code to respond to `options.$destroy == true`
  2018. */
  2019. function destroyInterimElement(opts) {
  2020. return interimElementService.destroy(opts);
  2021. }
  2022. /**
  2023. * Helper to call $injector.invoke with a local of the factory name for
  2024. * this provider.
  2025. * If an $mdDialog is providing options for a dialog and tries to inject
  2026. * $mdDialog, a circular dependency error will happen.
  2027. * We get around that by manually injecting $mdDialog as a local.
  2028. */
  2029. function invokeFactory(factory, defaultVal) {
  2030. var locals = {};
  2031. locals[interimFactoryName] = publicService;
  2032. return $injector.invoke(factory || function() { return defaultVal; }, {}, locals);
  2033. }
  2034. }
  2035. }
  2036. /* @ngInject */
  2037. function InterimElementFactory($document, $q, $$q, $rootScope, $timeout, $rootElement, $animate,
  2038. $mdUtil, $mdCompiler, $mdTheming, $log ) {
  2039. return function createInterimElementService() {
  2040. var SHOW_CANCELLED = false;
  2041. /*
  2042. * @ngdoc service
  2043. * @name $$interimElement.$service
  2044. *
  2045. * @description
  2046. * A service used to control inserting and removing an element into the DOM.
  2047. *
  2048. */
  2049. var service, stack = [];
  2050. // Publish instance $$interimElement service;
  2051. // ... used as $mdDialog, $mdToast, $mdMenu, and $mdSelect
  2052. return service = {
  2053. show: show,
  2054. hide: hide,
  2055. cancel: cancel,
  2056. destroy : destroy
  2057. };
  2058. /*
  2059. * @ngdoc method
  2060. * @name $$interimElement.$service#show
  2061. * @kind function
  2062. *
  2063. * @description
  2064. * Adds the `$interimElement` to the DOM and returns a special promise that will be resolved or rejected
  2065. * with hide or cancel, respectively. To external cancel/hide, developers should use the
  2066. *
  2067. * @param {*} options is hashMap of settings
  2068. * @returns a Promise
  2069. *
  2070. */
  2071. function show(options) {
  2072. options = options || {};
  2073. var interimElement = new InterimElement(options || {});
  2074. var hideExisting = !options.skipHide && stack.length ? service.hide() : $q.when(true);
  2075. // This hide()s only the current interim element before showing the next, new one
  2076. // NOTE: this is not reversible (e.g. interim elements are not stackable)
  2077. hideExisting.finally(function() {
  2078. stack.push(interimElement);
  2079. interimElement
  2080. .show()
  2081. .catch(function( reason ) {
  2082. //$log.error("InterimElement.show() error: " + reason );
  2083. return reason;
  2084. });
  2085. });
  2086. // Return a promise that will be resolved when the interim
  2087. // element is hidden or cancelled...
  2088. return interimElement.deferred.promise;
  2089. }
  2090. /*
  2091. * @ngdoc method
  2092. * @name $$interimElement.$service#hide
  2093. * @kind function
  2094. *
  2095. * @description
  2096. * Removes the `$interimElement` from the DOM and resolves the promise returned from `show`
  2097. *
  2098. * @param {*} resolveParam Data to resolve the promise with
  2099. * @returns a Promise that will be resolved after the element has been removed.
  2100. *
  2101. */
  2102. function hide(reason, options) {
  2103. if ( !stack.length ) return $q.when(reason);
  2104. options = options || {};
  2105. if (options.closeAll) {
  2106. var promise = $q.all(stack.reverse().map(closeElement));
  2107. stack = [];
  2108. return promise;
  2109. } else if (options.closeTo !== undefined) {
  2110. return $q.all(stack.splice(options.closeTo).map(closeElement));
  2111. } else {
  2112. var interim = stack.pop();
  2113. return closeElement(interim);
  2114. }
  2115. function closeElement(interim) {
  2116. interim
  2117. .remove(reason, false, options || { })
  2118. .catch(function( reason ) {
  2119. //$log.error("InterimElement.hide() error: " + reason );
  2120. return reason;
  2121. });
  2122. return interim.deferred.promise;
  2123. }
  2124. }
  2125. /*
  2126. * @ngdoc method
  2127. * @name $$interimElement.$service#cancel
  2128. * @kind function
  2129. *
  2130. * @description
  2131. * Removes the `$interimElement` from the DOM and rejects the promise returned from `show`
  2132. *
  2133. * @param {*} reason Data to reject the promise with
  2134. * @returns Promise that will be resolved after the element has been removed.
  2135. *
  2136. */
  2137. function cancel(reason, options) {
  2138. var interim = stack.shift();
  2139. if ( !interim ) return $q.when(reason);
  2140. interim
  2141. .remove(reason, true, options || { })
  2142. .catch(function( reason ) {
  2143. //$log.error("InterimElement.cancel() error: " + reason );
  2144. return reason;
  2145. });
  2146. return interim.deferred.promise;
  2147. }
  2148. /*
  2149. * Special method to quick-remove the interim element without animations
  2150. */
  2151. function destroy() {
  2152. var interim = stack.shift();
  2153. return interim ? interim.remove(SHOW_CANCELLED, false, {'$destroy':true}) :
  2154. $q.when(SHOW_CANCELLED);
  2155. }
  2156. /*
  2157. * Internal Interim Element Object
  2158. * Used internally to manage the DOM element and related data
  2159. */
  2160. function InterimElement(options) {
  2161. var self, element, showAction = $q.when(true);
  2162. options = configureScopeAndTransitions(options);
  2163. return self = {
  2164. options : options,
  2165. deferred: $q.defer(),
  2166. show : createAndTransitionIn,
  2167. remove : transitionOutAndRemove
  2168. };
  2169. /**
  2170. * Compile, link, and show this interim element
  2171. * Use optional autoHided and transition-in effects
  2172. */
  2173. function createAndTransitionIn() {
  2174. return $q(function(resolve, reject){
  2175. compileElement(options)
  2176. .then(function( compiledData ) {
  2177. element = linkElement( compiledData, options );
  2178. showAction = showElement(element, options, compiledData.controller)
  2179. .then(resolve, rejectAll );
  2180. }, rejectAll);
  2181. function rejectAll(fault) {
  2182. // Force the '$md<xxx>.show()' promise to reject
  2183. self.deferred.reject(fault);
  2184. // Continue rejection propagation
  2185. reject(fault);
  2186. }
  2187. });
  2188. }
  2189. /**
  2190. * After the show process has finished/rejected:
  2191. * - announce 'removing',
  2192. * - perform the transition-out, and
  2193. * - perform optional clean up scope.
  2194. */
  2195. function transitionOutAndRemove(response, isCancelled, opts) {
  2196. // abort if the show() and compile failed
  2197. if ( !element ) return $q.when(false);
  2198. options = angular.extend(options || {}, opts || {});
  2199. options.cancelAutoHide && options.cancelAutoHide();
  2200. options.element.triggerHandler('$mdInterimElementRemove');
  2201. if ( options.$destroy === true ) {
  2202. return hideElement(options.element, options);
  2203. } else {
  2204. $q.when(showAction)
  2205. .finally(function() {
  2206. hideElement(options.element, options).then(function() {
  2207. (isCancelled && rejectAll(response)) || resolveAll(response);
  2208. }, rejectAll);
  2209. });
  2210. return self.deferred.promise;
  2211. }
  2212. /**
  2213. * The `show()` returns a promise that will be resolved when the interim
  2214. * element is hidden or cancelled...
  2215. */
  2216. function resolveAll(response) {
  2217. self.deferred.resolve(response);
  2218. }
  2219. /**
  2220. * Force the '$md<xxx>.show()' promise to reject
  2221. */
  2222. function rejectAll(fault) {
  2223. self.deferred.reject(fault);
  2224. }
  2225. }
  2226. /**
  2227. * Prepare optional isolated scope and prepare $animate with default enter and leave
  2228. * transitions for the new element instance.
  2229. */
  2230. function configureScopeAndTransitions(options) {
  2231. options = options || { };
  2232. if ( options.template ) {
  2233. options.template = $mdUtil.processTemplate(options.template);
  2234. }
  2235. return angular.extend({
  2236. preserveScope: false,
  2237. cancelAutoHide : angular.noop,
  2238. scope: options.scope || $rootScope.$new(options.isolateScope),
  2239. /**
  2240. * Default usage to enable $animate to transition-in; can be easily overridden via 'options'
  2241. */
  2242. onShow: function transitionIn(scope, element, options) {
  2243. return $animate.enter(element, options.parent);
  2244. },
  2245. /**
  2246. * Default usage to enable $animate to transition-out; can be easily overridden via 'options'
  2247. */
  2248. onRemove: function transitionOut(scope, element) {
  2249. // Element could be undefined if a new element is shown before
  2250. // the old one finishes compiling.
  2251. return element && $animate.leave(element) || $q.when();
  2252. }
  2253. }, options );
  2254. }
  2255. /**
  2256. * Compile an element with a templateUrl, controller, and locals
  2257. */
  2258. function compileElement(options) {
  2259. var compiled = !options.skipCompile ? $mdCompiler.compile(options) : null;
  2260. return compiled || $q(function (resolve) {
  2261. resolve({
  2262. locals: {},
  2263. link: function () {
  2264. return options.element;
  2265. }
  2266. });
  2267. });
  2268. }
  2269. /**
  2270. * Link an element with compiled configuration
  2271. */
  2272. function linkElement(compileData, options){
  2273. angular.extend(compileData.locals, options);
  2274. var element = compileData.link(options.scope);
  2275. // Search for parent at insertion time, if not specified
  2276. options.element = element;
  2277. options.parent = findParent(element, options);
  2278. if (options.themable) $mdTheming(element);
  2279. return element;
  2280. }
  2281. /**
  2282. * Search for parent at insertion time, if not specified
  2283. */
  2284. function findParent(element, options) {
  2285. var parent = options.parent;
  2286. // Search for parent at insertion time, if not specified
  2287. if (angular.isFunction(parent)) {
  2288. parent = parent(options.scope, element, options);
  2289. } else if (angular.isString(parent)) {
  2290. parent = angular.element($document[0].querySelector(parent));
  2291. } else {
  2292. parent = angular.element(parent);
  2293. }
  2294. // If parent querySelector/getter function fails, or it's just null,
  2295. // find a default.
  2296. if (!(parent || {}).length) {
  2297. var el;
  2298. if ($rootElement[0] && $rootElement[0].querySelector) {
  2299. el = $rootElement[0].querySelector(':not(svg) > body');
  2300. }
  2301. if (!el) el = $rootElement[0];
  2302. if (el.nodeName == '#comment') {
  2303. el = $document[0].body;
  2304. }
  2305. return angular.element(el);
  2306. }
  2307. return parent;
  2308. }
  2309. /**
  2310. * If auto-hide is enabled, start timer and prepare cancel function
  2311. */
  2312. function startAutoHide() {
  2313. var autoHideTimer, cancelAutoHide = angular.noop;
  2314. if (options.hideDelay) {
  2315. autoHideTimer = $timeout(service.hide, options.hideDelay) ;
  2316. cancelAutoHide = function() {
  2317. $timeout.cancel(autoHideTimer);
  2318. }
  2319. }
  2320. // Cache for subsequent use
  2321. options.cancelAutoHide = function() {
  2322. cancelAutoHide();
  2323. options.cancelAutoHide = undefined;
  2324. }
  2325. }
  2326. /**
  2327. * Show the element ( with transitions), notify complete and start
  2328. * optional auto-Hide
  2329. */
  2330. function showElement(element, options, controller) {
  2331. // Trigger onShowing callback before the `show()` starts
  2332. var notifyShowing = options.onShowing || angular.noop;
  2333. // Trigger onComplete callback when the `show()` finishes
  2334. var notifyComplete = options.onComplete || angular.noop;
  2335. return $q(function (resolve, reject) {
  2336. try {
  2337. notifyShowing(options.scope, element, options);
  2338. // Start transitionIn
  2339. $q.when(options.onShow(options.scope, element, options, controller))
  2340. .then(function () {
  2341. notifyComplete(options.scope, element, options);
  2342. startAutoHide();
  2343. resolve(element);
  2344. }, reject );
  2345. } catch(e) {
  2346. reject(e.message);
  2347. }
  2348. });
  2349. }
  2350. function hideElement(element, options) {
  2351. var announceRemoving = options.onRemoving || angular.noop;
  2352. return $$q(function (resolve, reject) {
  2353. try {
  2354. // Start transitionIn
  2355. var action = $$q.when( options.onRemove(options.scope, element, options) || true );
  2356. // Trigger callback *before* the remove operation starts
  2357. announceRemoving(element, action);
  2358. if ( options.$destroy == true ) {
  2359. // For $destroy, onRemove should be synchronous
  2360. resolve(element);
  2361. } else {
  2362. // Wait until transition-out is done
  2363. action.then(function () {
  2364. if (!options.preserveScope && options.scope ) {
  2365. options.scope.$destroy();
  2366. }
  2367. resolve(element);
  2368. }, reject );
  2369. }
  2370. } catch(e) {
  2371. reject(e.message);
  2372. }
  2373. });
  2374. }
  2375. }
  2376. };
  2377. }
  2378. }
  2379. })();
  2380. (function(){
  2381. "use strict";
  2382. /**
  2383. * @ngdoc module
  2384. * @name material.core.componentRegistry
  2385. *
  2386. * @description
  2387. * A component instance registration service.
  2388. * Note: currently this as a private service in the SideNav component.
  2389. */
  2390. angular.module('material.core')
  2391. .factory('$mdComponentRegistry', ComponentRegistry);
  2392. /*
  2393. * @private
  2394. * @ngdoc factory
  2395. * @name ComponentRegistry
  2396. * @module material.core.componentRegistry
  2397. *
  2398. */
  2399. function ComponentRegistry($log, $q) {
  2400. var self;
  2401. var instances = [ ];
  2402. var pendings = { };
  2403. return self = {
  2404. /**
  2405. * Used to print an error when an instance for a handle isn't found.
  2406. */
  2407. notFoundError: function(handle) {
  2408. $log.error('No instance found for handle', handle);
  2409. },
  2410. /**
  2411. * Return all registered instances as an array.
  2412. */
  2413. getInstances: function() {
  2414. return instances;
  2415. },
  2416. /**
  2417. * Get a registered instance.
  2418. * @param handle the String handle to look up for a registered instance.
  2419. */
  2420. get: function(handle) {
  2421. if ( !isValidID(handle) ) return null;
  2422. var i, j, instance;
  2423. for(i = 0, j = instances.length; i < j; i++) {
  2424. instance = instances[i];
  2425. if(instance.$$mdHandle === handle) {
  2426. return instance;
  2427. }
  2428. }
  2429. return null;
  2430. },
  2431. /**
  2432. * Register an instance.
  2433. * @param instance the instance to register
  2434. * @param handle the handle to identify the instance under.
  2435. */
  2436. register: function(instance, handle) {
  2437. if ( !handle ) return angular.noop;
  2438. instance.$$mdHandle = handle;
  2439. instances.push(instance);
  2440. resolveWhen();
  2441. return deregister;
  2442. /**
  2443. * Remove registration for an instance
  2444. */
  2445. function deregister() {
  2446. var index = instances.indexOf(instance);
  2447. if (index !== -1) {
  2448. instances.splice(index, 1);
  2449. }
  2450. }
  2451. /**
  2452. * Resolve any pending promises for this instance
  2453. */
  2454. function resolveWhen() {
  2455. var dfd = pendings[handle];
  2456. if ( dfd ) {
  2457. dfd.resolve( instance );
  2458. delete pendings[handle];
  2459. }
  2460. }
  2461. },
  2462. /**
  2463. * Async accessor to registered component instance
  2464. * If not available then a promise is created to notify
  2465. * all listeners when the instance is registered.
  2466. */
  2467. when : function(handle) {
  2468. if ( isValidID(handle) ) {
  2469. var deferred = $q.defer();
  2470. var instance = self.get(handle);
  2471. if ( instance ) {
  2472. deferred.resolve( instance );
  2473. } else {
  2474. pendings[handle] = deferred;
  2475. }
  2476. return deferred.promise;
  2477. }
  2478. return $q.reject("Invalid `md-component-id` value.");
  2479. }
  2480. };
  2481. function isValidID(handle){
  2482. return handle && (handle !== "");
  2483. }
  2484. }
  2485. ComponentRegistry.$inject = ["$log", "$q"];
  2486. })();
  2487. (function(){
  2488. "use strict";
  2489. (function() {
  2490. 'use strict';
  2491. var $mdUtil, $interpolate;
  2492. var SUFFIXES = /(-gt)?-(sm|md|lg)/g;
  2493. var WHITESPACE = /\s+/g;
  2494. var FLEX_OPTIONS = ['grow', 'initial', 'auto', 'none'];
  2495. var LAYOUT_OPTIONS = ['row', 'column'];
  2496. var ALIGNMENT_OPTIONS = [
  2497. "start start", "start center", "start end",
  2498. "center", "center center", "center start", "center end",
  2499. "end", "end center", "end start", "end end",
  2500. "space-around", "space-around center", "space-around start", "space-around end",
  2501. "space-between", "space-between center", "space-between start", "space-between end"
  2502. ];
  2503. var config = {
  2504. /**
  2505. * Enable directive attribute-to-class conversions
  2506. */
  2507. enabled: true,
  2508. /**
  2509. * After translation to classname equivalents, remove the
  2510. * original Layout attribute
  2511. */
  2512. removeAttributes : true,
  2513. /**
  2514. * List of mediaQuery breakpoints and associated suffixes
  2515. *
  2516. * [
  2517. * { suffix: "sm", mediaQuery: "screen and (max-width: 599px)" },
  2518. * { suffix: "md", mediaQuery: "screen and (min-width: 600px) and (max-width: 959px)" }
  2519. * ]
  2520. */
  2521. breakpoints: []
  2522. };
  2523. /**
  2524. * The original ngMaterial Layout solution used attribute selectors and CSS.
  2525. *
  2526. * ```html
  2527. * <div layout="column"> My Content </div>
  2528. * ```
  2529. *
  2530. * ```css
  2531. * [layout] {
  2532. * box-sizing: border-box;
  2533. * display:flex;
  2534. * }
  2535. * [layout=column] {
  2536. * flex-direction : column
  2537. * }
  2538. * ```
  2539. *
  2540. * Use of attribute selectors creates significant performance impacts in some
  2541. * browsers... mainly IE.
  2542. *
  2543. * This module registers directives that allow the same layout attributes to be
  2544. * interpreted and converted to class selectors. The directive will add equivalent classes to each element that
  2545. * contains a Layout directive.
  2546. *
  2547. * ```html
  2548. * <div layout="column" class="layout layout-column"> My Content </div>
  2549. *```
  2550. *
  2551. * ```css
  2552. * .layout {
  2553. * box-sizing: border-box;
  2554. * display:flex;
  2555. * }
  2556. * .layout-column {
  2557. * flex-direction : column
  2558. * }
  2559. * ```
  2560. */
  2561. angular.module('material.core.layout', ['ng'])
  2562. .directive('mdLayoutCss', disableLayoutDirective )
  2563. .directive('layout', attributeWithObserve('layout'))
  2564. .directive('layoutSm', attributeWithObserve('layout-sm'))
  2565. .directive('layoutGtSm', attributeWithObserve('layout-gt-sm'))
  2566. .directive('layoutMd', attributeWithObserve('layout-md'))
  2567. .directive('layoutGtMd', attributeWithObserve('layout-gt-md'))
  2568. .directive('layoutLg', attributeWithObserve('layout-lg'))
  2569. .directive('layoutGtLg', attributeWithObserve('layout-gt-lg'))
  2570. .directive('flex', attributeWithObserve('flex'))
  2571. .directive('flexSm', attributeWithObserve('flex-sm'))
  2572. .directive('flexGtSm', attributeWithObserve('flex-gt-sm'))
  2573. .directive('flexMd', attributeWithObserve('flex-md'))
  2574. .directive('flexGtMd', attributeWithObserve('flex-gt-md'))
  2575. .directive('flexLg', attributeWithObserve('flex-lg'))
  2576. .directive('flexGtLg', attributeWithObserve('flex-gt-lg'))
  2577. .directive('flexOrder', attributeWithObserve('flex-order'))
  2578. .directive('flexOrderSm', attributeWithObserve('flex-order-sm'))
  2579. .directive('flexOrderGtSm', attributeWithObserve('flex-order-gt-sm'))
  2580. .directive('flexOrderMd', attributeWithObserve('flex-order-md'))
  2581. .directive('flexOrderGtMd', attributeWithObserve('flex-order-gt-md'))
  2582. .directive('flexOrderLg', attributeWithObserve('flex-order-lg'))
  2583. .directive('flexOrderGtLg', attributeWithObserve('flex-order-gt-lg'))
  2584. .directive('flexOffset', attributeWithObserve('flex-offset'))
  2585. .directive('flexOffsetSm', attributeWithObserve('flex-offset-sm'))
  2586. .directive('flexOffsetGtSm', attributeWithObserve('flex-offset-gt-sm'))
  2587. .directive('flexOffsetMd', attributeWithObserve('flex-offset-md'))
  2588. .directive('flexOffsetGtMd', attributeWithObserve('flex-offset-gt-md'))
  2589. .directive('flexOffsetLg', attributeWithObserve('flex-offset-lg'))
  2590. .directive('flexOffsetGtLg', attributeWithObserve('flex-offset-gt-lg'))
  2591. .directive('layoutAlign', attributeWithObserve('layout-align'))
  2592. .directive('layoutAlignSm', attributeWithObserve('layout-align-sm'))
  2593. .directive('layoutAlignGtSm', attributeWithObserve('layout-align-gt-sm'))
  2594. .directive('layoutAlignMd', attributeWithObserve('layout-align-md'))
  2595. .directive('layoutAlignGtMd', attributeWithObserve('layout-align-gt-md'))
  2596. .directive('layoutAlignLg', attributeWithObserve('layout-align-lg'))
  2597. .directive('layoutAlignGtLg', attributeWithObserve('layout-align-gt-lg'))
  2598. // Attribute directives with no value(s)
  2599. .directive('hide', attributeWithoutValue('hide'))
  2600. .directive('hideSm', attributeWithoutValue('hide-sm'))
  2601. .directive('hideGtSm', attributeWithoutValue('hide-gt-sm'))
  2602. .directive('hideMd', attributeWithoutValue('hide-md'))
  2603. .directive('hideGtMd', attributeWithoutValue('hide-gt-md'))
  2604. .directive('hideLg', attributeWithoutValue('hide-lg'))
  2605. .directive('hideGtLg', attributeWithoutValue('hide-gt-lg'))
  2606. .directive('show', attributeWithoutValue('show'))
  2607. .directive('showSm', attributeWithoutValue('show-sm'))
  2608. .directive('showGtSm', attributeWithoutValue('show-gt-sm'))
  2609. .directive('showMd', attributeWithoutValue('show-md'))
  2610. .directive('showGtMd', attributeWithoutValue('show-gt-md'))
  2611. .directive('showLg', attributeWithoutValue('show-lg'))
  2612. .directive('showGtLg', attributeWithoutValue('show-gt-lg'))
  2613. // Attribute directives with no value(s) and NO breakpoints
  2614. .directive('layoutMargin', attributeWithoutValue('layout-margin'))
  2615. .directive('layoutPadding', attributeWithoutValue('layout-padding'))
  2616. .directive('layoutWrap', attributeWithoutValue('layout-wrap'))
  2617. .directive('layoutNoWrap', attributeWithoutValue('layout-no-wrap'))
  2618. .directive('layoutFill', attributeWithoutValue('layout-fill'))
  2619. // !! Deprecated attributes: use the `-lt` (aka less-than) notations
  2620. .directive('layoutLtMd', warnAttrNotSupported('layout-lt-md', true))
  2621. .directive('layoutLtLg', warnAttrNotSupported('layout-lt-lg', true))
  2622. .directive('flexLtMd', warnAttrNotSupported('flex-lt-md', true))
  2623. .directive('flexLtLg', warnAttrNotSupported('flex-lt-lg', true))
  2624. .directive('layoutAlignLtMd', warnAttrNotSupported('layout-align-lt-md'))
  2625. .directive('layoutAlignLtLg', warnAttrNotSupported('layout-align-lt-lg'))
  2626. .directive('flexOrderLtMd', warnAttrNotSupported('flex-order-lt-md'))
  2627. .directive('flexOrderLtLg', warnAttrNotSupported('flex-order-lt-lg'))
  2628. .directive('offsetLtMd', warnAttrNotSupported('flex-offset-lt-md'))
  2629. .directive('offsetLtLg', warnAttrNotSupported('flex-offset-lt-lg'))
  2630. .directive('hideLtMd', warnAttrNotSupported('hide-lt-md'))
  2631. .directive('hideLtLg', warnAttrNotSupported('hide-lt-lg'))
  2632. .directive('showLtMd', warnAttrNotSupported('show-lt-md'))
  2633. .directive('showLtLg', warnAttrNotSupported('show-lt-lg'));
  2634. /**
  2635. * Special directive that will disable ALL Layout conversions of layout
  2636. * attribute(s) to classname(s).
  2637. *
  2638. * <link rel="stylesheet" href="angular-material.min.css">
  2639. * <link rel="stylesheet" href="angular-material.layout.css">
  2640. *
  2641. * <body md-layout-css>
  2642. * ...
  2643. * </body>
  2644. *
  2645. * Note: Using md-layout-css directive requires the developer to load the Material
  2646. * Layout Attribute stylesheet (which only uses attribute selectors):
  2647. *
  2648. * `angular-material.layout.css`
  2649. *
  2650. * Another option is to use the LayoutProvider to configure and disable the attribute
  2651. * conversions; this would obviate the use of the `md-layout-css` directive
  2652. *
  2653. */
  2654. function disableLayoutDirective() {
  2655. return {
  2656. restrict : 'A',
  2657. priority : '900',
  2658. compile : function(element, attr) {
  2659. config.enabled = false;
  2660. return angular.noop;
  2661. }
  2662. };
  2663. }
  2664. // *********************************************************************************
  2665. //
  2666. // These functions create registration functions for ngMaterial Layout attribute directives
  2667. // This provides easy translation to switch ngMaterial attribute selectors to
  2668. // CLASS selectors and directives; which has huge performance implications
  2669. // for IE Browsers
  2670. //
  2671. // *********************************************************************************
  2672. /**
  2673. * Creates a directive registration function where a possible dynamic attribute
  2674. * value will be observed/watched.
  2675. * @param {string} className attribute name; eg `layout-gt-md` with value ="row"
  2676. */
  2677. function attributeWithObserve(className) {
  2678. return ['$mdUtil', '$interpolate', function(_$mdUtil_, _$interpolate_) {
  2679. $mdUtil = _$mdUtil_;
  2680. $interpolate = _$interpolate_;
  2681. return {
  2682. restrict: 'A',
  2683. compile: function(element, attr) {
  2684. var linkFn;
  2685. if (config.enabled) {
  2686. // immediately replace static (non-interpolated) invalid values...
  2687. validateAttributeValue( className,
  2688. getNormalizedAttrValue(className, attr, ""),
  2689. buildUpdateFn(element, className, attr)
  2690. );
  2691. linkFn = translateWithValueToCssClass;
  2692. }
  2693. // Use for postLink to account for transforms after ng-transclude.
  2694. return linkFn || angular.noop;
  2695. }
  2696. };
  2697. }];
  2698. /**
  2699. * Add as transformed class selector(s), then
  2700. * remove the deprecated attribute selector
  2701. */
  2702. function translateWithValueToCssClass(scope, element, attrs) {
  2703. var updateFn = updateClassWithValue(element, className, attrs);
  2704. var unwatch = attrs.$observe(attrs.$normalize(className), updateFn);
  2705. updateFn(getNormalizedAttrValue(className, attrs, ""));
  2706. scope.$on("$destroy", function() { unwatch() });
  2707. if (config.removeAttributes) element.removeAttr(className);
  2708. }
  2709. }
  2710. /**
  2711. * Creates a registration function for ngMaterial Layout attribute directive.
  2712. * This is a `simple` transpose of attribute usage to class usage; where we ignore
  2713. * any attribute value
  2714. */
  2715. function attributeWithoutValue(className) {
  2716. return ['$interpolate', function(_$interpolate_) {
  2717. $interpolate = _$interpolate_;
  2718. return {
  2719. restrict: 'A',
  2720. compile: function(element, attr) {
  2721. var linkFn;
  2722. if (config.enabled) {
  2723. // immediately replace static (non-interpolated) invalid values...
  2724. validateAttributeValue( className,
  2725. getNormalizedAttrValue(className, attr, ""),
  2726. buildUpdateFn(element, className, attr)
  2727. );
  2728. translateToCssClass(null, element);
  2729. // Use for postLink to account for transforms after ng-transclude.
  2730. linkFn = translateToCssClass;
  2731. }
  2732. return linkFn || angular.noop;
  2733. }
  2734. };
  2735. }];
  2736. /**
  2737. * Add as transformed class selector, then
  2738. * remove the deprecated attribute selector
  2739. */
  2740. function translateToCssClass(scope, element) {
  2741. element.addClass(className);
  2742. if (config.removeAttributes) {
  2743. // After link-phase, remove deprecated layout attribute selector
  2744. element.removeAttr(className);
  2745. }
  2746. }
  2747. }
  2748. /**
  2749. * After link-phase, do NOT remove deprecated layout attribute selector.
  2750. * Instead watch the attribute so interpolated data-bindings to layout
  2751. * selectors will continue to be supported.
  2752. *
  2753. * $observe() the className and update with new class (after removing the last one)
  2754. *
  2755. * e.g. `layout="{{layoutDemo.direction}}"` will update...
  2756. *
  2757. * NOTE: The value must match one of the specified styles in the CSS.
  2758. * For example `flex-gt-md="{{size}}` where `scope.size == 47` will NOT work since
  2759. * only breakpoints for 0, 5, 10, 15... 100, 33, 34, 66, 67 are defined.
  2760. *
  2761. */
  2762. function updateClassWithValue(element, className) {
  2763. var lastClass;
  2764. return function updateClassFn(newValue) {
  2765. var value = validateAttributeValue(className, newValue || "");
  2766. if ( angular.isDefined(value) ) {
  2767. element.removeClass(lastClass);
  2768. lastClass = !value ? className : className + "-" + value.replace(WHITESPACE, "-")
  2769. element.addClass(lastClass);
  2770. }
  2771. };
  2772. }
  2773. /**
  2774. * Provide console warning that this layout attribute has been deprecated
  2775. *
  2776. */
  2777. function warnAttrNotSupported(className) {
  2778. var parts = className.split("-");
  2779. return ["$log", function($log) {
  2780. $log.warn(className + "has been deprecated. Please use a `" + parts[0] + "-gt-<xxx>` variant.");
  2781. return angular.noop;
  2782. }];
  2783. }
  2784. /**
  2785. * For the Layout attribute value, validate or replace with default
  2786. * fallback value
  2787. */
  2788. function validateAttributeValue(className, value, updateFn) {
  2789. var origValue = value;
  2790. if (!needsInterpolation(value)) {
  2791. switch (className.replace(SUFFIXES,"")) {
  2792. case 'layout' :
  2793. if ( !findIn(value, LAYOUT_OPTIONS) ) {
  2794. value = LAYOUT_OPTIONS[0]; // 'row';
  2795. }
  2796. break;
  2797. case 'flex' :
  2798. if (!findIn(value, FLEX_OPTIONS)) {
  2799. if (isNaN(value)) {
  2800. value = '';
  2801. }
  2802. }
  2803. break;
  2804. case 'flex-offset' :
  2805. case 'flex-order' :
  2806. if (!value || isNaN(+value)) {
  2807. value = '0';
  2808. }
  2809. break;
  2810. case 'layout-align' :
  2811. if (!findIn(value, ALIGNMENT_OPTIONS, "-")) {
  2812. value = ALIGNMENT_OPTIONS[0]; // 'start-start';
  2813. }
  2814. break;
  2815. case 'layout-padding' :
  2816. case 'layout-margin' :
  2817. case 'layout-fill' :
  2818. case 'layout-wrap' :
  2819. case 'layout-no-wrap' :
  2820. value = '';
  2821. break;
  2822. }
  2823. if (value != origValue) {
  2824. (updateFn || angular.noop)(value);
  2825. }
  2826. }
  2827. return value;
  2828. }
  2829. /**
  2830. * Replace current attribute value with fallback value
  2831. */
  2832. function buildUpdateFn(element, className, attrs) {
  2833. return function updateAttrValue(fallback) {
  2834. if (!needsInterpolation(fallback)) {
  2835. element.attr(className, fallback);
  2836. attrs[attrs.$normalize(className)] = fallback;
  2837. }
  2838. };
  2839. }
  2840. /**
  2841. * See if the original value has interpolation symbols:
  2842. * e.g. flex-gt-md="{{triggerPoint}}"
  2843. */
  2844. function needsInterpolation(value) {
  2845. return (value || "").indexOf($interpolate.startSymbol()) > -1;
  2846. }
  2847. function getNormalizedAttrValue(className, attrs, defaultVal) {
  2848. var normalizedAttr = attrs.$normalize(className);
  2849. return attrs[normalizedAttr] ? attrs[normalizedAttr].replace(WHITESPACE, "-") : defaultVal || null;
  2850. }
  2851. function findIn(item, list, replaceWith) {
  2852. item = replaceWith && item ? item.replace(WHITESPACE, replaceWith) : item;
  2853. var found = false;
  2854. if (item) {
  2855. list.forEach(function(it) {
  2856. it = replaceWith ? it.replace(WHITESPACE, replaceWith) : it;
  2857. found = found || (it === item);
  2858. });
  2859. }
  2860. return found;
  2861. }
  2862. })();
  2863. })();
  2864. (function(){
  2865. "use strict";
  2866. (function() {
  2867. 'use strict';
  2868. /**
  2869. * @ngdoc service
  2870. * @name $mdButtonInkRipple
  2871. * @module material.core
  2872. *
  2873. * @description
  2874. * Provides ripple effects for md-button. See $mdInkRipple service for all possible configuration options.
  2875. *
  2876. * @param {object=} scope Scope within the current context
  2877. * @param {object=} element The element the ripple effect should be applied to
  2878. * @param {object=} options (Optional) Configuration options to override the default ripple configuration
  2879. */
  2880. angular.module('material.core')
  2881. .factory('$mdButtonInkRipple', MdButtonInkRipple);
  2882. function MdButtonInkRipple($mdInkRipple) {
  2883. return {
  2884. attach: function attachRipple(scope, element, options) {
  2885. options = angular.extend(optionsForElement(element), options);
  2886. return $mdInkRipple.attach(scope, element, options);
  2887. }
  2888. };
  2889. function optionsForElement(element) {
  2890. if (element.hasClass('md-icon-button')) {
  2891. return {
  2892. isMenuItem: element.hasClass('md-menu-item'),
  2893. fitRipple: true,
  2894. center: true
  2895. };
  2896. } else {
  2897. return {
  2898. isMenuItem: element.hasClass('md-menu-item'),
  2899. dimBackground: true
  2900. }
  2901. }
  2902. };
  2903. }
  2904. MdButtonInkRipple.$inject = ["$mdInkRipple"];;
  2905. })();
  2906. })();
  2907. (function(){
  2908. "use strict";
  2909. (function() {
  2910. 'use strict';
  2911. /**
  2912. * @ngdoc service
  2913. * @name $mdCheckboxInkRipple
  2914. * @module material.core
  2915. *
  2916. * @description
  2917. * Provides ripple effects for md-checkbox. See $mdInkRipple service for all possible configuration options.
  2918. *
  2919. * @param {object=} scope Scope within the current context
  2920. * @param {object=} element The element the ripple effect should be applied to
  2921. * @param {object=} options (Optional) Configuration options to override the defaultripple configuration
  2922. */
  2923. angular.module('material.core')
  2924. .factory('$mdCheckboxInkRipple', MdCheckboxInkRipple);
  2925. function MdCheckboxInkRipple($mdInkRipple) {
  2926. return {
  2927. attach: attach
  2928. };
  2929. function attach(scope, element, options) {
  2930. return $mdInkRipple.attach(scope, element, angular.extend({
  2931. center: true,
  2932. dimBackground: false,
  2933. fitRipple: true
  2934. }, options));
  2935. };
  2936. }
  2937. MdCheckboxInkRipple.$inject = ["$mdInkRipple"];;
  2938. })();
  2939. })();
  2940. (function(){
  2941. "use strict";
  2942. (function() {
  2943. 'use strict';
  2944. /**
  2945. * @ngdoc service
  2946. * @name $mdListInkRipple
  2947. * @module material.core
  2948. *
  2949. * @description
  2950. * Provides ripple effects for md-list. See $mdInkRipple service for all possible configuration options.
  2951. *
  2952. * @param {object=} scope Scope within the current context
  2953. * @param {object=} element The element the ripple effect should be applied to
  2954. * @param {object=} options (Optional) Configuration options to override the defaultripple configuration
  2955. */
  2956. angular.module('material.core')
  2957. .factory('$mdListInkRipple', MdListInkRipple);
  2958. function MdListInkRipple($mdInkRipple) {
  2959. return {
  2960. attach: attach
  2961. };
  2962. function attach(scope, element, options) {
  2963. return $mdInkRipple.attach(scope, element, angular.extend({
  2964. center: false,
  2965. dimBackground: true,
  2966. outline: false,
  2967. rippleSize: 'full'
  2968. }, options));
  2969. };
  2970. }
  2971. MdListInkRipple.$inject = ["$mdInkRipple"];;
  2972. })();
  2973. })();
  2974. (function(){
  2975. "use strict";
  2976. angular.module('material.core')
  2977. .factory('$mdInkRipple', InkRippleService)
  2978. .directive('mdInkRipple', InkRippleDirective)
  2979. .directive('mdNoInk', attrNoDirective)
  2980. .directive('mdNoBar', attrNoDirective)
  2981. .directive('mdNoStretch', attrNoDirective);
  2982. var DURATION = 450;
  2983. /**
  2984. * Directive used to add ripples to any element
  2985. * @ngInject
  2986. */
  2987. function InkRippleDirective ($mdButtonInkRipple, $mdCheckboxInkRipple) {
  2988. return {
  2989. controller: angular.noop,
  2990. link: function (scope, element, attr) {
  2991. attr.hasOwnProperty('mdInkRippleCheckbox')
  2992. ? $mdCheckboxInkRipple.attach(scope, element)
  2993. : $mdButtonInkRipple.attach(scope, element);
  2994. }
  2995. };
  2996. }
  2997. InkRippleDirective.$inject = ["$mdButtonInkRipple", "$mdCheckboxInkRipple"];
  2998. /**
  2999. * Service for adding ripples to any element
  3000. * @ngInject
  3001. */
  3002. function InkRippleService ($injector) {
  3003. return { attach: attach };
  3004. function attach (scope, element, options) {
  3005. if (element.controller('mdNoInk')) return angular.noop;
  3006. return $injector.instantiate(InkRippleCtrl, {
  3007. $scope: scope,
  3008. $element: element,
  3009. rippleOptions: options
  3010. });
  3011. }
  3012. }
  3013. InkRippleService.$inject = ["$injector"];
  3014. /**
  3015. * Controller used by the ripple service in order to apply ripples
  3016. * @ngInject
  3017. */
  3018. function InkRippleCtrl ($scope, $element, rippleOptions, $window, $timeout, $mdUtil) {
  3019. this.$window = $window;
  3020. this.$timeout = $timeout;
  3021. this.$mdUtil = $mdUtil;
  3022. this.$scope = $scope;
  3023. this.$element = $element;
  3024. this.options = rippleOptions;
  3025. this.mousedown = false;
  3026. this.ripples = [];
  3027. this.timeout = null; // Stores a reference to the most-recent ripple timeout
  3028. this.lastRipple = null;
  3029. $mdUtil.valueOnUse(this, 'container', this.createContainer);
  3030. $mdUtil.valueOnUse(this, 'background', this.getColor, 0.5);
  3031. this.color = this.getColor(1);
  3032. this.$element.addClass('md-ink-ripple');
  3033. // attach method for unit tests
  3034. ($element.controller('mdInkRipple') || {}).createRipple = angular.bind(this, this.createRipple);
  3035. ($element.controller('mdInkRipple') || {}).setColor = angular.bind(this, this.setColor);
  3036. this.bindEvents();
  3037. }
  3038. InkRippleCtrl.$inject = ["$scope", "$element", "rippleOptions", "$window", "$timeout", "$mdUtil"];
  3039. /**
  3040. * Returns the color that the ripple should be (either based on CSS or hard-coded)
  3041. * @returns {string}
  3042. */
  3043. InkRippleCtrl.prototype.getColor = function () {
  3044. return this._parseColor(this.$element.attr('md-ink-ripple'))
  3045. || this._parseColor(getElementColor.call(this));
  3046. /**
  3047. * Finds the color element and returns its text color for use as default ripple color
  3048. * @returns {string}
  3049. */
  3050. function getElementColor () {
  3051. var colorElement = this.options.colorElement && this.options.colorElement[ 0 ];
  3052. colorElement = colorElement || this.$element[ 0 ];
  3053. return colorElement ? this.$window.getComputedStyle(colorElement).color : 'rgb(0,0,0)';
  3054. }
  3055. };
  3056. /**
  3057. * Takes a string color and converts it to RGBA format
  3058. * @param color {string}
  3059. * @param [multiplier] {int}
  3060. * @returns {string}
  3061. */
  3062. InkRippleCtrl.prototype._parseColor = function parseColor (color, multiplier) {
  3063. multiplier = multiplier || 1;
  3064. if (!color) return;
  3065. if (color.indexOf('rgba') === 0) return color.replace(/\d?\.?\d*\s*\)\s*$/, (0.1 * multiplier).toString() + ')');
  3066. if (color.indexOf('rgb') === 0) return rgbToRGBA(color);
  3067. if (color.indexOf('#') === 0) return hexToRGBA(color);
  3068. /**
  3069. * Converts hex value to RGBA string
  3070. * @param color {string}
  3071. * @returns {string}
  3072. */
  3073. function hexToRGBA (color) {
  3074. var hex = color[ 0 ] === '#' ? color.substr(1) : color,
  3075. dig = hex.length / 3,
  3076. red = hex.substr(0, dig),
  3077. green = hex.substr(dig, dig),
  3078. blue = hex.substr(dig * 2);
  3079. if (dig === 1) {
  3080. red += red;
  3081. green += green;
  3082. blue += blue;
  3083. }
  3084. return 'rgba(' + parseInt(red, 16) + ',' + parseInt(green, 16) + ',' + parseInt(blue, 16) + ',0.1)';
  3085. }
  3086. /**
  3087. * Converts an RGB color to RGBA
  3088. * @param color {string}
  3089. * @returns {string}
  3090. */
  3091. function rgbToRGBA (color) {
  3092. return color.replace(')', ', 0.1)').replace('(', 'a(');
  3093. }
  3094. };
  3095. /**
  3096. * Binds events to the root element for
  3097. */
  3098. InkRippleCtrl.prototype.bindEvents = function () {
  3099. this.$element.on('mousedown', angular.bind(this, this.handleMousedown));
  3100. this.$element.on('mouseup', angular.bind(this, this.handleMouseup));
  3101. this.$element.on('mouseleave', angular.bind(this, this.handleMouseup));
  3102. };
  3103. /**
  3104. * Create a new ripple on every mousedown event from the root element
  3105. * @param event {MouseEvent}
  3106. */
  3107. InkRippleCtrl.prototype.handleMousedown = function (event) {
  3108. if ( this.mousedown ) return;
  3109. this.setColor(window.getComputedStyle(this.$element[0])['color']);
  3110. // When jQuery is loaded, we have to get the original event
  3111. if (event.hasOwnProperty('originalEvent')) event = event.originalEvent;
  3112. this.mousedown = true;
  3113. if (this.options.center) {
  3114. this.createRipple(this.container.prop('clientWidth') / 2, this.container.prop('clientWidth') / 2);
  3115. } else {
  3116. this.createRipple(event.layerX, event.layerY);
  3117. }
  3118. };
  3119. /**
  3120. * Either remove or unlock any remaining ripples when the user mouses off of the element (either by
  3121. * mouseup or mouseleave event)
  3122. */
  3123. InkRippleCtrl.prototype.handleMouseup = function () {
  3124. if ( this.mousedown || this.lastRipple ) {
  3125. var ctrl = this;
  3126. this.mousedown = false;
  3127. this.$mdUtil.nextTick(function () {
  3128. ctrl.clearRipples();
  3129. }, false);
  3130. }
  3131. };
  3132. /**
  3133. * Cycles through all ripples and attempts to remove them.
  3134. * Depending on logic within `fadeInComplete`, some removals will be postponed.
  3135. */
  3136. InkRippleCtrl.prototype.clearRipples = function () {
  3137. for (var i = 0; i < this.ripples.length; i++) {
  3138. this.fadeInComplete(this.ripples[ i ]);
  3139. }
  3140. };
  3141. /**
  3142. * Creates the ripple container element
  3143. * @returns {*}
  3144. */
  3145. InkRippleCtrl.prototype.createContainer = function () {
  3146. var container = angular.element('<div class="md-ripple-container"></div>');
  3147. this.$element.append(container);
  3148. return container;
  3149. };
  3150. InkRippleCtrl.prototype.clearTimeout = function () {
  3151. if (this.timeout) {
  3152. this.$timeout.cancel(this.timeout);
  3153. this.timeout = null;
  3154. }
  3155. };
  3156. InkRippleCtrl.prototype.isRippleAllowed = function () {
  3157. var element = this.$element[0];
  3158. do {
  3159. if (!element.tagName || element.tagName === 'BODY') break;
  3160. if (element && element.hasAttribute && element.hasAttribute('disabled')) return false;
  3161. } while (element = element.parentNode);
  3162. return true;
  3163. };
  3164. /**
  3165. * Creates a new ripple and adds it to the container. Also tracks ripple in `this.ripples`.
  3166. * @param left
  3167. * @param top
  3168. */
  3169. InkRippleCtrl.prototype.createRipple = function (left, top) {
  3170. if (!this.isRippleAllowed()) return;
  3171. var ctrl = this;
  3172. var ripple = angular.element('<div class="md-ripple"></div>');
  3173. var width = this.$element.prop('clientWidth');
  3174. var height = this.$element.prop('clientHeight');
  3175. var x = Math.max(Math.abs(width - left), left) * 2;
  3176. var y = Math.max(Math.abs(height - top), top) * 2;
  3177. var size = getSize(this.options.fitRipple, x, y);
  3178. ripple.css({
  3179. left: left + 'px',
  3180. top: top + 'px',
  3181. background: 'black',
  3182. width: size + 'px',
  3183. height: size + 'px',
  3184. backgroundColor: rgbaToRGB(this.color),
  3185. borderColor: rgbaToRGB(this.color)
  3186. });
  3187. this.lastRipple = ripple;
  3188. // we only want one timeout to be running at a time
  3189. this.clearTimeout();
  3190. this.timeout = this.$timeout(function () {
  3191. ctrl.clearTimeout();
  3192. if (!ctrl.mousedown) ctrl.fadeInComplete(ripple);
  3193. }, DURATION * 0.35, false);
  3194. if (this.options.dimBackground) this.container.css({ backgroundColor: this.background });
  3195. this.container.append(ripple);
  3196. this.ripples.push(ripple);
  3197. ripple.addClass('md-ripple-placed');
  3198. this.$mdUtil.nextTick(function () {
  3199. ripple.addClass('md-ripple-scaled md-ripple-active');
  3200. ctrl.$timeout(function () {
  3201. ctrl.clearRipples();
  3202. }, DURATION, false);
  3203. }, false);
  3204. function rgbaToRGB (color) {
  3205. return color
  3206. ? color.replace('rgba', 'rgb').replace(/,[^\),]+\)/, ')')
  3207. : 'rgb(0,0,0)';
  3208. }
  3209. function getSize (fit, x, y) {
  3210. return fit
  3211. ? Math.max(x, y)
  3212. : Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
  3213. }
  3214. };
  3215. InkRippleCtrl.prototype.setColor = function (color) {
  3216. this.color = this._parseColor(color);
  3217. };
  3218. /**
  3219. * Either kicks off the fade-out animation or queues the element for removal on mouseup
  3220. * @param ripple
  3221. */
  3222. InkRippleCtrl.prototype.fadeInComplete = function (ripple) {
  3223. if (this.lastRipple === ripple) {
  3224. if (!this.timeout && !this.mousedown) {
  3225. this.removeRipple(ripple);
  3226. }
  3227. } else {
  3228. this.removeRipple(ripple);
  3229. }
  3230. };
  3231. /**
  3232. * Kicks off the animation for removing a ripple
  3233. * @param ripple {Element}
  3234. */
  3235. InkRippleCtrl.prototype.removeRipple = function (ripple) {
  3236. var ctrl = this;
  3237. var index = this.ripples.indexOf(ripple);
  3238. if (index < 0) return;
  3239. this.ripples.splice(this.ripples.indexOf(ripple), 1);
  3240. ripple.removeClass('md-ripple-active');
  3241. if (this.ripples.length === 0) this.container.css({ backgroundColor: '' });
  3242. // use a 2-second timeout in order to allow for the animation to finish
  3243. // we don't actually care how long the animation takes
  3244. this.$timeout(function () {
  3245. ctrl.fadeOutComplete(ripple);
  3246. }, DURATION, false);
  3247. };
  3248. /**
  3249. * Removes the provided ripple from the DOM
  3250. * @param ripple
  3251. */
  3252. InkRippleCtrl.prototype.fadeOutComplete = function (ripple) {
  3253. ripple.remove();
  3254. this.lastRipple = null;
  3255. };
  3256. /**
  3257. * Used to create an empty directive. This is used to track flag-directives whose children may have
  3258. * functionality based on them.
  3259. *
  3260. * Example: `md-no-ink` will potentially be used by all child directives.
  3261. */
  3262. function attrNoDirective () {
  3263. return { controller: angular.noop };
  3264. }
  3265. })();
  3266. (function(){
  3267. "use strict";
  3268. (function() {
  3269. 'use strict';
  3270. /**
  3271. * @ngdoc service
  3272. * @name $mdTabInkRipple
  3273. * @module material.core
  3274. *
  3275. * @description
  3276. * Provides ripple effects for md-tabs. See $mdInkRipple service for all possible configuration options.
  3277. *
  3278. * @param {object=} scope Scope within the current context
  3279. * @param {object=} element The element the ripple effect should be applied to
  3280. * @param {object=} options (Optional) Configuration options to override the defaultripple configuration
  3281. */
  3282. angular.module('material.core')
  3283. .factory('$mdTabInkRipple', MdTabInkRipple);
  3284. function MdTabInkRipple($mdInkRipple) {
  3285. return {
  3286. attach: attach
  3287. };
  3288. function attach(scope, element, options) {
  3289. return $mdInkRipple.attach(scope, element, angular.extend({
  3290. center: false,
  3291. dimBackground: true,
  3292. outline: false,
  3293. rippleSize: 'full'
  3294. }, options));
  3295. };
  3296. }
  3297. MdTabInkRipple.$inject = ["$mdInkRipple"];;
  3298. })();
  3299. })();
  3300. (function(){
  3301. "use strict";
  3302. angular.module('material.core.theming.palette', [])
  3303. .constant('$mdColorPalette', {
  3304. 'red': {
  3305. '50': '#ffebee',
  3306. '100': '#ffcdd2',
  3307. '200': '#ef9a9a',
  3308. '300': '#e57373',
  3309. '400': '#ef5350',
  3310. '500': '#f44336',
  3311. '600': '#e53935',
  3312. '700': '#d32f2f',
  3313. '800': '#c62828',
  3314. '900': '#b71c1c',
  3315. 'A100': '#ff8a80',
  3316. 'A200': '#ff5252',
  3317. 'A400': '#ff1744',
  3318. 'A700': '#d50000',
  3319. 'contrastDefaultColor': 'light',
  3320. 'contrastDarkColors': '50 100 200 300 A100',
  3321. 'contrastStrongLightColors': '400 500 600 700 A200 A400 A700'
  3322. },
  3323. 'pink': {
  3324. '50': '#fce4ec',
  3325. '100': '#f8bbd0',
  3326. '200': '#f48fb1',
  3327. '300': '#f06292',
  3328. '400': '#ec407a',
  3329. '500': '#e91e63',
  3330. '600': '#d81b60',
  3331. '700': '#c2185b',
  3332. '800': '#ad1457',
  3333. '900': '#880e4f',
  3334. 'A100': '#ff80ab',
  3335. 'A200': '#ff4081',
  3336. 'A400': '#f50057',
  3337. 'A700': '#c51162',
  3338. 'contrastDefaultColor': 'light',
  3339. 'contrastDarkColors': '50 100 200 A100',
  3340. 'contrastStrongLightColors': '500 600 A200 A400 A700'
  3341. },
  3342. 'purple': {
  3343. '50': '#f3e5f5',
  3344. '100': '#e1bee7',
  3345. '200': '#ce93d8',
  3346. '300': '#ba68c8',
  3347. '400': '#ab47bc',
  3348. '500': '#9c27b0',
  3349. '600': '#8e24aa',
  3350. '700': '#7b1fa2',
  3351. '800': '#6a1b9a',
  3352. '900': '#4a148c',
  3353. 'A100': '#ea80fc',
  3354. 'A200': '#e040fb',
  3355. 'A400': '#d500f9',
  3356. 'A700': '#aa00ff',
  3357. 'contrastDefaultColor': 'light',
  3358. 'contrastDarkColors': '50 100 200 A100',
  3359. 'contrastStrongLightColors': '300 400 A200 A400 A700'
  3360. },
  3361. 'deep-purple': {
  3362. '50': '#ede7f6',
  3363. '100': '#d1c4e9',
  3364. '200': '#b39ddb',
  3365. '300': '#9575cd',
  3366. '400': '#7e57c2',
  3367. '500': '#673ab7',
  3368. '600': '#5e35b1',
  3369. '700': '#512da8',
  3370. '800': '#4527a0',
  3371. '900': '#311b92',
  3372. 'A100': '#b388ff',
  3373. 'A200': '#7c4dff',
  3374. 'A400': '#651fff',
  3375. 'A700': '#6200ea',
  3376. 'contrastDefaultColor': 'light',
  3377. 'contrastDarkColors': '50 100 200 A100',
  3378. 'contrastStrongLightColors': '300 400 A200'
  3379. },
  3380. 'indigo': {
  3381. '50': '#e8eaf6',
  3382. '100': '#c5cae9',
  3383. '200': '#9fa8da',
  3384. '300': '#7986cb',
  3385. '400': '#5c6bc0',
  3386. '500': '#3f51b5',
  3387. '600': '#3949ab',
  3388. '700': '#303f9f',
  3389. '800': '#283593',
  3390. '900': '#1a237e',
  3391. 'A100': '#8c9eff',
  3392. 'A200': '#536dfe',
  3393. 'A400': '#3d5afe',
  3394. 'A700': '#304ffe',
  3395. 'contrastDefaultColor': 'light',
  3396. 'contrastDarkColors': '50 100 200 A100',
  3397. 'contrastStrongLightColors': '300 400 A200 A400'
  3398. },
  3399. 'blue': {
  3400. '50': '#e3f2fd',
  3401. '100': '#bbdefb',
  3402. '200': '#90caf9',
  3403. '300': '#64b5f6',
  3404. '400': '#42a5f5',
  3405. '500': '#2196f3',
  3406. '600': '#1e88e5',
  3407. '700': '#1976d2',
  3408. '800': '#1565c0',
  3409. '900': '#0d47a1',
  3410. 'A100': '#82b1ff',
  3411. 'A200': '#448aff',
  3412. 'A400': '#2979ff',
  3413. 'A700': '#2962ff',
  3414. 'contrastDefaultColor': 'light',
  3415. 'contrastDarkColors': '50 100 200 300 400 A100',
  3416. 'contrastStrongLightColors': '500 600 700 A200 A400 A700'
  3417. },
  3418. 'light-blue': {
  3419. '50': '#e1f5fe',
  3420. '100': '#b3e5fc',
  3421. '200': '#81d4fa',
  3422. '300': '#4fc3f7',
  3423. '400': '#29b6f6',
  3424. '500': '#03a9f4',
  3425. '600': '#039be5',
  3426. '700': '#0288d1',
  3427. '800': '#0277bd',
  3428. '900': '#01579b',
  3429. 'A100': '#80d8ff',
  3430. 'A200': '#40c4ff',
  3431. 'A400': '#00b0ff',
  3432. 'A700': '#0091ea',
  3433. 'contrastDefaultColor': 'dark',
  3434. 'contrastLightColors': '600 700 800 900 A700',
  3435. 'contrastStrongLightColors': '600 700 800 A700'
  3436. },
  3437. 'cyan': {
  3438. '50': '#e0f7fa',
  3439. '100': '#b2ebf2',
  3440. '200': '#80deea',
  3441. '300': '#4dd0e1',
  3442. '400': '#26c6da',
  3443. '500': '#00bcd4',
  3444. '600': '#00acc1',
  3445. '700': '#0097a7',
  3446. '800': '#00838f',
  3447. '900': '#006064',
  3448. 'A100': '#84ffff',
  3449. 'A200': '#18ffff',
  3450. 'A400': '#00e5ff',
  3451. 'A700': '#00b8d4',
  3452. 'contrastDefaultColor': 'dark',
  3453. 'contrastLightColors': '700 800 900',
  3454. 'contrastStrongLightColors': '700 800 900'
  3455. },
  3456. 'teal': {
  3457. '50': '#e0f2f1',
  3458. '100': '#b2dfdb',
  3459. '200': '#80cbc4',
  3460. '300': '#4db6ac',
  3461. '400': '#26a69a',
  3462. '500': '#009688',
  3463. '600': '#00897b',
  3464. '700': '#00796b',
  3465. '800': '#00695c',
  3466. '900': '#004d40',
  3467. 'A100': '#a7ffeb',
  3468. 'A200': '#64ffda',
  3469. 'A400': '#1de9b6',
  3470. 'A700': '#00bfa5',
  3471. 'contrastDefaultColor': 'dark',
  3472. 'contrastLightColors': '500 600 700 800 900',
  3473. 'contrastStrongLightColors': '500 600 700'
  3474. },
  3475. 'green': {
  3476. '50': '#e8f5e9',
  3477. '100': '#c8e6c9',
  3478. '200': '#a5d6a7',
  3479. '300': '#81c784',
  3480. '400': '#66bb6a',
  3481. '500': '#4caf50',
  3482. '600': '#43a047',
  3483. '700': '#388e3c',
  3484. '800': '#2e7d32',
  3485. '900': '#1b5e20',
  3486. 'A100': '#b9f6ca',
  3487. 'A200': '#69f0ae',
  3488. 'A400': '#00e676',
  3489. 'A700': '#00c853',
  3490. 'contrastDefaultColor': 'dark',
  3491. 'contrastLightColors': '600 700 800 900',
  3492. 'contrastStrongLightColors': '600 700'
  3493. },
  3494. 'light-green': {
  3495. '50': '#f1f8e9',
  3496. '100': '#dcedc8',
  3497. '200': '#c5e1a5',
  3498. '300': '#aed581',
  3499. '400': '#9ccc65',
  3500. '500': '#8bc34a',
  3501. '600': '#7cb342',
  3502. '700': '#689f38',
  3503. '800': '#558b2f',
  3504. '900': '#33691e',
  3505. 'A100': '#ccff90',
  3506. 'A200': '#b2ff59',
  3507. 'A400': '#76ff03',
  3508. 'A700': '#64dd17',
  3509. 'contrastDefaultColor': 'dark',
  3510. 'contrastLightColors': '700 800 900',
  3511. 'contrastStrongLightColors': '700 800 900'
  3512. },
  3513. 'lime': {
  3514. '50': '#f9fbe7',
  3515. '100': '#f0f4c3',
  3516. '200': '#e6ee9c',
  3517. '300': '#dce775',
  3518. '400': '#d4e157',
  3519. '500': '#cddc39',
  3520. '600': '#c0ca33',
  3521. '700': '#afb42b',
  3522. '800': '#9e9d24',
  3523. '900': '#827717',
  3524. 'A100': '#f4ff81',
  3525. 'A200': '#eeff41',
  3526. 'A400': '#c6ff00',
  3527. 'A700': '#aeea00',
  3528. 'contrastDefaultColor': 'dark',
  3529. 'contrastLightColors': '900',
  3530. 'contrastStrongLightColors': '900'
  3531. },
  3532. 'yellow': {
  3533. '50': '#fffde7',
  3534. '100': '#fff9c4',
  3535. '200': '#fff59d',
  3536. '300': '#fff176',
  3537. '400': '#ffee58',
  3538. '500': '#ffeb3b',
  3539. '600': '#fdd835',
  3540. '700': '#fbc02d',
  3541. '800': '#f9a825',
  3542. '900': '#f57f17',
  3543. 'A100': '#ffff8d',
  3544. 'A200': '#ffff00',
  3545. 'A400': '#ffea00',
  3546. 'A700': '#ffd600',
  3547. 'contrastDefaultColor': 'dark'
  3548. },
  3549. 'amber': {
  3550. '50': '#fff8e1',
  3551. '100': '#ffecb3',
  3552. '200': '#ffe082',
  3553. '300': '#ffd54f',
  3554. '400': '#ffca28',
  3555. '500': '#ffc107',
  3556. '600': '#ffb300',
  3557. '700': '#ffa000',
  3558. '800': '#ff8f00',
  3559. '900': '#ff6f00',
  3560. 'A100': '#ffe57f',
  3561. 'A200': '#ffd740',
  3562. 'A400': '#ffc400',
  3563. 'A700': '#ffab00',
  3564. 'contrastDefaultColor': 'dark'
  3565. },
  3566. 'orange': {
  3567. '50': '#fff3e0',
  3568. '100': '#ffe0b2',
  3569. '200': '#ffcc80',
  3570. '300': '#ffb74d',
  3571. '400': '#ffa726',
  3572. '500': '#ff9800',
  3573. '600': '#fb8c00',
  3574. '700': '#f57c00',
  3575. '800': '#ef6c00',
  3576. '900': '#e65100',
  3577. 'A100': '#ffd180',
  3578. 'A200': '#ffab40',
  3579. 'A400': '#ff9100',
  3580. 'A700': '#ff6d00',
  3581. 'contrastDefaultColor': 'dark',
  3582. 'contrastLightColors': '800 900',
  3583. 'contrastStrongLightColors': '800 900'
  3584. },
  3585. 'deep-orange': {
  3586. '50': '#fbe9e7',
  3587. '100': '#ffccbc',
  3588. '200': '#ffab91',
  3589. '300': '#ff8a65',
  3590. '400': '#ff7043',
  3591. '500': '#ff5722',
  3592. '600': '#f4511e',
  3593. '700': '#e64a19',
  3594. '800': '#d84315',
  3595. '900': '#bf360c',
  3596. 'A100': '#ff9e80',
  3597. 'A200': '#ff6e40',
  3598. 'A400': '#ff3d00',
  3599. 'A700': '#dd2c00',
  3600. 'contrastDefaultColor': 'light',
  3601. 'contrastDarkColors': '50 100 200 300 400 A100 A200',
  3602. 'contrastStrongLightColors': '500 600 700 800 900 A400 A700'
  3603. },
  3604. 'brown': {
  3605. '50': '#efebe9',
  3606. '100': '#d7ccc8',
  3607. '200': '#bcaaa4',
  3608. '300': '#a1887f',
  3609. '400': '#8d6e63',
  3610. '500': '#795548',
  3611. '600': '#6d4c41',
  3612. '700': '#5d4037',
  3613. '800': '#4e342e',
  3614. '900': '#3e2723',
  3615. 'A100': '#d7ccc8',
  3616. 'A200': '#bcaaa4',
  3617. 'A400': '#8d6e63',
  3618. 'A700': '#5d4037',
  3619. 'contrastDefaultColor': 'light',
  3620. 'contrastDarkColors': '50 100 200',
  3621. 'contrastStrongLightColors': '300 400'
  3622. },
  3623. 'grey': {
  3624. '50': '#fafafa',
  3625. '100': '#f5f5f5',
  3626. '200': '#eeeeee',
  3627. '300': '#e0e0e0',
  3628. '400': '#bdbdbd',
  3629. '500': '#9e9e9e',
  3630. '600': '#757575',
  3631. '700': '#616161',
  3632. '800': '#424242',
  3633. '900': '#212121',
  3634. '1000': '#000000',
  3635. 'A100': '#ffffff',
  3636. 'A200': '#eeeeee',
  3637. 'A400': '#bdbdbd',
  3638. 'A700': '#616161',
  3639. 'contrastDefaultColor': 'dark',
  3640. 'contrastLightColors': '600 700 800 900'
  3641. },
  3642. 'blue-grey': {
  3643. '50': '#eceff1',
  3644. '100': '#cfd8dc',
  3645. '200': '#b0bec5',
  3646. '300': '#90a4ae',
  3647. '400': '#78909c',
  3648. '500': '#607d8b',
  3649. '600': '#546e7a',
  3650. '700': '#455a64',
  3651. '800': '#37474f',
  3652. '900': '#263238',
  3653. 'A100': '#cfd8dc',
  3654. 'A200': '#b0bec5',
  3655. 'A400': '#78909c',
  3656. 'A700': '#455a64',
  3657. 'contrastDefaultColor': 'light',
  3658. 'contrastDarkColors': '50 100 200 300',
  3659. 'contrastStrongLightColors': '400 500'
  3660. }
  3661. });
  3662. })();
  3663. (function(){
  3664. "use strict";
  3665. angular.module('material.core.theming', ['material.core.theming.palette'])
  3666. .directive('mdTheme', ThemingDirective)
  3667. .directive('mdThemable', ThemableDirective)
  3668. .provider('$mdTheming', ThemingProvider)
  3669. .run(generateThemes);
  3670. /**
  3671. * @ngdoc service
  3672. * @name $mdThemingProvider
  3673. * @module material.core.theming
  3674. *
  3675. * @description Provider to configure the `$mdTheming` service.
  3676. */
  3677. /**
  3678. * @ngdoc method
  3679. * @name $mdThemingProvider#setDefaultTheme
  3680. * @param {string} themeName Default theme name to be applied to elements. Default value is `default`.
  3681. */
  3682. /**
  3683. * @ngdoc method
  3684. * @name $mdThemingProvider#alwaysWatchTheme
  3685. * @param {boolean} watch Whether or not to always watch themes for changes and re-apply
  3686. * classes when they change. Default is `false`. Enabling can reduce performance.
  3687. */
  3688. /* Some Example Valid Theming Expressions
  3689. * =======================================
  3690. *
  3691. * Intention group expansion: (valid for primary, accent, warn, background)
  3692. *
  3693. * {{primary-100}} - grab shade 100 from the primary palette
  3694. * {{primary-100-0.7}} - grab shade 100, apply opacity of 0.7
  3695. * {{primary-100-contrast}} - grab shade 100's contrast color
  3696. * {{primary-hue-1}} - grab the shade assigned to hue-1 from the primary palette
  3697. * {{primary-hue-1-0.7}} - apply 0.7 opacity to primary-hue-1
  3698. * {{primary-color}} - Generates .md-hue-1, .md-hue-2, .md-hue-3 with configured shades set for each hue
  3699. * {{primary-color-0.7}} - Apply 0.7 opacity to each of the above rules
  3700. * {{primary-contrast}} - Generates .md-hue-1, .md-hue-2, .md-hue-3 with configured contrast (ie. text) color shades set for each hue
  3701. * {{primary-contrast-0.7}} - Apply 0.7 opacity to each of the above rules
  3702. *
  3703. * Foreground expansion: Applies rgba to black/white foreground text
  3704. *
  3705. * {{foreground-1}} - used for primary text
  3706. * {{foreground-2}} - used for secondary text/divider
  3707. * {{foreground-3}} - used for disabled text
  3708. * {{foreground-4}} - used for dividers
  3709. *
  3710. */
  3711. // In memory generated CSS rules; registered by theme.name
  3712. var GENERATED = { };
  3713. // In memory storage of defined themes and color palettes (both loaded by CSS, and user specified)
  3714. var PALETTES;
  3715. var THEMES;
  3716. var DARK_FOREGROUND = {
  3717. name: 'dark',
  3718. '1': 'rgba(0,0,0,0.87)',
  3719. '2': 'rgba(0,0,0,0.54)',
  3720. '3': 'rgba(0,0,0,0.26)',
  3721. '4': 'rgba(0,0,0,0.12)'
  3722. };
  3723. var LIGHT_FOREGROUND = {
  3724. name: 'light',
  3725. '1': 'rgba(255,255,255,1.0)',
  3726. '2': 'rgba(255,255,255,0.7)',
  3727. '3': 'rgba(255,255,255,0.3)',
  3728. '4': 'rgba(255,255,255,0.12)'
  3729. };
  3730. var DARK_SHADOW = '1px 1px 0px rgba(0,0,0,0.4), -1px -1px 0px rgba(0,0,0,0.4)';
  3731. var LIGHT_SHADOW = '';
  3732. var DARK_CONTRAST_COLOR = colorToRgbaArray('rgba(0,0,0,0.87)');
  3733. var LIGHT_CONTRAST_COLOR = colorToRgbaArray('rgba(255,255,255,0.87');
  3734. var STRONG_LIGHT_CONTRAST_COLOR = colorToRgbaArray('rgb(255,255,255)');
  3735. var THEME_COLOR_TYPES = ['primary', 'accent', 'warn', 'background'];
  3736. var DEFAULT_COLOR_TYPE = 'primary';
  3737. // A color in a theme will use these hues by default, if not specified by user.
  3738. var LIGHT_DEFAULT_HUES = {
  3739. 'accent': {
  3740. 'default': 'A200',
  3741. 'hue-1': 'A100',
  3742. 'hue-2': 'A400',
  3743. 'hue-3': 'A700'
  3744. },
  3745. 'background': {
  3746. 'default': 'A100',
  3747. 'hue-1': '300',
  3748. 'hue-2': '800',
  3749. 'hue-3': '900'
  3750. }
  3751. };
  3752. var DARK_DEFAULT_HUES = {
  3753. 'background': {
  3754. 'default': '800',
  3755. 'hue-1': '600',
  3756. 'hue-2': '300',
  3757. 'hue-3': '900'
  3758. }
  3759. };
  3760. THEME_COLOR_TYPES.forEach(function(colorType) {
  3761. // Color types with unspecified default hues will use these default hue values
  3762. var defaultDefaultHues = {
  3763. 'default': '500',
  3764. 'hue-1': '300',
  3765. 'hue-2': '800',
  3766. 'hue-3': 'A100'
  3767. };
  3768. if (!LIGHT_DEFAULT_HUES[colorType]) LIGHT_DEFAULT_HUES[colorType] = defaultDefaultHues;
  3769. if (!DARK_DEFAULT_HUES[colorType]) DARK_DEFAULT_HUES[colorType] = defaultDefaultHues;
  3770. });
  3771. var VALID_HUE_VALUES = [
  3772. '50', '100', '200', '300', '400', '500', '600',
  3773. '700', '800', '900', 'A100', 'A200', 'A400', 'A700'
  3774. ];
  3775. function ThemingProvider($mdColorPalette) {
  3776. PALETTES = { };
  3777. THEMES = { };
  3778. var themingProvider;
  3779. var defaultTheme = 'default';
  3780. var alwaysWatchTheme = false;
  3781. // Load JS Defined Palettes
  3782. angular.extend(PALETTES, $mdColorPalette);
  3783. // Default theme defined in core.js
  3784. ThemingService.$inject = ["$rootScope", "$log"];
  3785. return themingProvider = {
  3786. definePalette: definePalette,
  3787. extendPalette: extendPalette,
  3788. theme: registerTheme,
  3789. setDefaultTheme: function(theme) {
  3790. defaultTheme = theme;
  3791. },
  3792. alwaysWatchTheme: function(alwaysWatch) {
  3793. alwaysWatchTheme = alwaysWatch;
  3794. },
  3795. $get: ThemingService,
  3796. _LIGHT_DEFAULT_HUES: LIGHT_DEFAULT_HUES,
  3797. _DARK_DEFAULT_HUES: DARK_DEFAULT_HUES,
  3798. _PALETTES: PALETTES,
  3799. _THEMES: THEMES,
  3800. _parseRules: parseRules,
  3801. _rgba: rgba
  3802. };
  3803. // Example: $mdThemingProvider.definePalette('neonRed', { 50: '#f5fafa', ... });
  3804. function definePalette(name, map) {
  3805. map = map || {};
  3806. PALETTES[name] = checkPaletteValid(name, map);
  3807. return themingProvider;
  3808. }
  3809. // Returns an new object which is a copy of a given palette `name` with variables from
  3810. // `map` overwritten
  3811. // Example: var neonRedMap = $mdThemingProvider.extendPalette('red', { 50: '#f5fafafa' });
  3812. function extendPalette(name, map) {
  3813. return checkPaletteValid(name, angular.extend({}, PALETTES[name] || {}, map) );
  3814. }
  3815. // Make sure that palette has all required hues
  3816. function checkPaletteValid(name, map) {
  3817. var missingColors = VALID_HUE_VALUES.filter(function(field) {
  3818. return !map[field];
  3819. });
  3820. if (missingColors.length) {
  3821. throw new Error("Missing colors %1 in palette %2!"
  3822. .replace('%1', missingColors.join(', '))
  3823. .replace('%2', name));
  3824. }
  3825. return map;
  3826. }
  3827. // Register a theme (which is a collection of color palettes to use with various states
  3828. // ie. warn, accent, primary )
  3829. // Optionally inherit from an existing theme
  3830. // $mdThemingProvider.theme('custom-theme').primaryPalette('red');
  3831. function registerTheme(name, inheritFrom) {
  3832. if (THEMES[name]) return THEMES[name];
  3833. inheritFrom = inheritFrom || 'default';
  3834. var parentTheme = typeof inheritFrom === 'string' ? THEMES[inheritFrom] : inheritFrom;
  3835. var theme = new Theme(name);
  3836. if (parentTheme) {
  3837. angular.forEach(parentTheme.colors, function(color, colorType) {
  3838. theme.colors[colorType] = {
  3839. name: color.name,
  3840. // Make sure a COPY of the hues is given to the child color,
  3841. // not the same reference.
  3842. hues: angular.extend({}, color.hues)
  3843. };
  3844. });
  3845. }
  3846. THEMES[name] = theme;
  3847. return theme;
  3848. }
  3849. function Theme(name) {
  3850. var self = this;
  3851. self.name = name;
  3852. self.colors = {};
  3853. self.dark = setDark;
  3854. setDark(false);
  3855. function setDark(isDark) {
  3856. isDark = arguments.length === 0 ? true : !!isDark;
  3857. // If no change, abort
  3858. if (isDark === self.isDark) return;
  3859. self.isDark = isDark;
  3860. self.foregroundPalette = self.isDark ? LIGHT_FOREGROUND : DARK_FOREGROUND;
  3861. self.foregroundShadow = self.isDark ? DARK_SHADOW : LIGHT_SHADOW;
  3862. // Light and dark themes have different default hues.
  3863. // Go through each existing color type for this theme, and for every
  3864. // hue value that is still the default hue value from the previous light/dark setting,
  3865. // set it to the default hue value from the new light/dark setting.
  3866. var newDefaultHues = self.isDark ? DARK_DEFAULT_HUES : LIGHT_DEFAULT_HUES;
  3867. var oldDefaultHues = self.isDark ? LIGHT_DEFAULT_HUES : DARK_DEFAULT_HUES;
  3868. angular.forEach(newDefaultHues, function(newDefaults, colorType) {
  3869. var color = self.colors[colorType];
  3870. var oldDefaults = oldDefaultHues[colorType];
  3871. if (color) {
  3872. for (var hueName in color.hues) {
  3873. if (color.hues[hueName] === oldDefaults[hueName]) {
  3874. color.hues[hueName] = newDefaults[hueName];
  3875. }
  3876. }
  3877. }
  3878. });
  3879. return self;
  3880. }
  3881. THEME_COLOR_TYPES.forEach(function(colorType) {
  3882. var defaultHues = (self.isDark ? DARK_DEFAULT_HUES : LIGHT_DEFAULT_HUES)[colorType];
  3883. self[colorType + 'Palette'] = function setPaletteType(paletteName, hues) {
  3884. var color = self.colors[colorType] = {
  3885. name: paletteName,
  3886. hues: angular.extend({}, defaultHues, hues)
  3887. };
  3888. Object.keys(color.hues).forEach(function(name) {
  3889. if (!defaultHues[name]) {
  3890. throw new Error("Invalid hue name '%1' in theme %2's %3 color %4. Available hue names: %4"
  3891. .replace('%1', name)
  3892. .replace('%2', self.name)
  3893. .replace('%3', paletteName)
  3894. .replace('%4', Object.keys(defaultHues).join(', '))
  3895. );
  3896. }
  3897. });
  3898. Object.keys(color.hues).map(function(key) {
  3899. return color.hues[key];
  3900. }).forEach(function(hueValue) {
  3901. if (VALID_HUE_VALUES.indexOf(hueValue) == -1) {
  3902. throw new Error("Invalid hue value '%1' in theme %2's %3 color %4. Available hue values: %5"
  3903. .replace('%1', hueValue)
  3904. .replace('%2', self.name)
  3905. .replace('%3', colorType)
  3906. .replace('%4', paletteName)
  3907. .replace('%5', VALID_HUE_VALUES.join(', '))
  3908. );
  3909. }
  3910. });
  3911. return self;
  3912. };
  3913. self[colorType + 'Color'] = function() {
  3914. var args = Array.prototype.slice.call(arguments);
  3915. console.warn('$mdThemingProviderTheme.' + colorType + 'Color() has been deprecated. ' +
  3916. 'Use $mdThemingProviderTheme.' + colorType + 'Palette() instead.');
  3917. return self[colorType + 'Palette'].apply(self, args);
  3918. };
  3919. });
  3920. }
  3921. /**
  3922. * @ngdoc service
  3923. * @name $mdTheming
  3924. *
  3925. * @description
  3926. *
  3927. * Service that makes an element apply theming related classes to itself.
  3928. *
  3929. * ```js
  3930. * app.directive('myFancyDirective', function($mdTheming) {
  3931. * return {
  3932. * restrict: 'e',
  3933. * link: function(scope, el, attrs) {
  3934. * $mdTheming(el);
  3935. * }
  3936. * };
  3937. * });
  3938. * ```
  3939. * @param {el=} element to apply theming to
  3940. */
  3941. /* @ngInject */
  3942. function ThemingService($rootScope, $log) {
  3943. applyTheme.inherit = function(el, parent) {
  3944. var ctrl = parent.controller('mdTheme');
  3945. var attrThemeValue = el.attr('md-theme-watch');
  3946. if ( (alwaysWatchTheme || angular.isDefined(attrThemeValue)) && attrThemeValue != 'false') {
  3947. var deregisterWatch = $rootScope.$watch(function() {
  3948. return ctrl && ctrl.$mdTheme || (defaultTheme == 'default' ? '' : defaultTheme);
  3949. }, changeTheme);
  3950. el.on('$destroy', deregisterWatch);
  3951. } else {
  3952. var theme = ctrl && ctrl.$mdTheme || (defaultTheme == 'default' ? '' : defaultTheme);
  3953. changeTheme(theme);
  3954. }
  3955. function changeTheme(theme) {
  3956. if (!theme) return;
  3957. if (!registered(theme)) {
  3958. $log.warn('Attempted to use unregistered theme \'' + theme + '\'. ' +
  3959. 'Register it with $mdThemingProvider.theme().');
  3960. }
  3961. var oldTheme = el.data('$mdThemeName');
  3962. if (oldTheme) el.removeClass('md-' + oldTheme +'-theme');
  3963. el.addClass('md-' + theme + '-theme');
  3964. el.data('$mdThemeName', theme);
  3965. if (ctrl) {
  3966. el.data('$mdThemeController', ctrl);
  3967. }
  3968. }
  3969. };
  3970. applyTheme.THEMES = angular.extend({}, THEMES);
  3971. applyTheme.defaultTheme = function() { return defaultTheme; };
  3972. applyTheme.registered = registered;
  3973. return applyTheme;
  3974. function registered(themeName) {
  3975. if (themeName === undefined || themeName === '') return true;
  3976. return applyTheme.THEMES[themeName] !== undefined;
  3977. }
  3978. function applyTheme(scope, el) {
  3979. // Allow us to be invoked via a linking function signature.
  3980. if (el === undefined) {
  3981. el = scope;
  3982. scope = undefined;
  3983. }
  3984. if (scope === undefined) {
  3985. scope = $rootScope;
  3986. }
  3987. applyTheme.inherit(el, el);
  3988. }
  3989. }
  3990. }
  3991. ThemingProvider.$inject = ["$mdColorPalette"];
  3992. function ThemingDirective($mdTheming, $interpolate, $log) {
  3993. return {
  3994. priority: 100,
  3995. link: {
  3996. pre: function(scope, el, attrs) {
  3997. var ctrl = {
  3998. $setTheme: function(theme) {
  3999. if (!$mdTheming.registered(theme)) {
  4000. $log.warn('attempted to use unregistered theme \'' + theme + '\'');
  4001. }
  4002. ctrl.$mdTheme = theme;
  4003. }
  4004. };
  4005. el.data('$mdThemeController', ctrl);
  4006. ctrl.$setTheme($interpolate(attrs.mdTheme)(scope));
  4007. attrs.$observe('mdTheme', ctrl.$setTheme);
  4008. }
  4009. }
  4010. };
  4011. }
  4012. ThemingDirective.$inject = ["$mdTheming", "$interpolate", "$log"];
  4013. function ThemableDirective($mdTheming) {
  4014. return $mdTheming;
  4015. }
  4016. ThemableDirective.$inject = ["$mdTheming"];
  4017. function parseRules(theme, colorType, rules) {
  4018. checkValidPalette(theme, colorType);
  4019. rules = rules.replace(/THEME_NAME/g, theme.name);
  4020. var generatedRules = [];
  4021. var color = theme.colors[colorType];
  4022. var themeNameRegex = new RegExp('.md-' + theme.name + '-theme', 'g');
  4023. // Matches '{{ primary-color }}', etc
  4024. var hueRegex = new RegExp('(\'|")?{{\\s*(' + colorType + ')-(color|contrast)-?(\\d\\.?\\d*)?\\s*}}(\"|\')?','g');
  4025. var simpleVariableRegex = /'?"?\{\{\s*([a-zA-Z]+)-(A?\d+|hue\-[0-3]|shadow)-?(\d\.?\d*)?(contrast)?\s*\}\}'?"?/g;
  4026. var palette = PALETTES[color.name];
  4027. // find and replace simple variables where we use a specific hue, not an entire palette
  4028. // eg. "{{primary-100}}"
  4029. //\(' + THEME_COLOR_TYPES.join('\|') + '\)'
  4030. rules = rules.replace(simpleVariableRegex, function(match, colorType, hue, opacity, contrast) {
  4031. if (colorType === 'foreground') {
  4032. if (hue == 'shadow') {
  4033. return theme.foregroundShadow;
  4034. } else {
  4035. return theme.foregroundPalette[hue] || theme.foregroundPalette['1'];
  4036. }
  4037. }
  4038. if (hue.indexOf('hue') === 0) {
  4039. hue = theme.colors[colorType].hues[hue];
  4040. }
  4041. return rgba( (PALETTES[ theme.colors[colorType].name ][hue] || '')[contrast ? 'contrast' : 'value'], opacity );
  4042. });
  4043. // For each type, generate rules for each hue (ie. default, md-hue-1, md-hue-2, md-hue-3)
  4044. angular.forEach(color.hues, function(hueValue, hueName) {
  4045. var newRule = rules
  4046. .replace(hueRegex, function(match, _, colorType, hueType, opacity) {
  4047. return rgba(palette[hueValue][hueType === 'color' ? 'value' : 'contrast'], opacity);
  4048. });
  4049. if (hueName !== 'default') {
  4050. newRule = newRule.replace(themeNameRegex, '.md-' + theme.name + '-theme.md-' + hueName);
  4051. }
  4052. // Don't apply a selector rule to the default theme, making it easier to override
  4053. // styles of the base-component
  4054. if (theme.name == 'default') {
  4055. newRule = newRule.replace(/((\w|\.|-)+)\.md-default-theme((\.|\w|-|:|\(|\)|\[|\]|"|'|=)*)/g, '$&, $1$3');
  4056. }
  4057. generatedRules.push(newRule);
  4058. });
  4059. return generatedRules;
  4060. }
  4061. // Generate our themes at run time given the state of THEMES and PALETTES
  4062. function generateThemes($injector) {
  4063. var head = document.getElementsByTagName('head')[0];
  4064. var firstChild = head ? head.firstElementChild : null;
  4065. var themeCss = $injector.has('$MD_THEME_CSS') ? $injector.get('$MD_THEME_CSS') : '';
  4066. if ( !firstChild ) return;
  4067. if (themeCss.length === 0) return; // no rules, so no point in running this expensive task
  4068. // Expose contrast colors for palettes to ensure that text is always readable
  4069. angular.forEach(PALETTES, sanitizePalette);
  4070. // MD_THEME_CSS is a string generated by the build process that includes all the themable
  4071. // components as templates
  4072. // Break the CSS into individual rules
  4073. var rulesByType = {};
  4074. var rules = themeCss
  4075. .split(/\}(?!(\}|'|"|;))/)
  4076. .filter(function(rule) { return rule && rule.length; })
  4077. .map(function(rule) { return rule.trim() + '}'; });
  4078. var ruleMatchRegex = new RegExp('md-(' + THEME_COLOR_TYPES.join('|') + ')', 'g');
  4079. THEME_COLOR_TYPES.forEach(function(type) {
  4080. rulesByType[type] = '';
  4081. });
  4082. // Sort the rules based on type, allowing us to do color substitution on a per-type basis
  4083. rules.forEach(function(rule) {
  4084. var match = rule.match(ruleMatchRegex);
  4085. // First: test that if the rule has '.md-accent', it goes into the accent set of rules
  4086. for (var i = 0, type; type = THEME_COLOR_TYPES[i]; i++) {
  4087. if (rule.indexOf('.md-' + type) > -1) {
  4088. return rulesByType[type] += rule;
  4089. }
  4090. }
  4091. // If no eg 'md-accent' class is found, try to just find 'accent' in the rule and guess from
  4092. // there
  4093. for (i = 0; type = THEME_COLOR_TYPES[i]; i++) {
  4094. if (rule.indexOf(type) > -1) {
  4095. return rulesByType[type] += rule;
  4096. }
  4097. }
  4098. // Default to the primary array
  4099. return rulesByType[DEFAULT_COLOR_TYPE] += rule;
  4100. });
  4101. // For each theme, use the color palettes specified for
  4102. // `primary`, `warn` and `accent` to generate CSS rules.
  4103. angular.forEach(THEMES, function(theme) {
  4104. if ( !GENERATED[theme.name] ) {
  4105. THEME_COLOR_TYPES.forEach(function(colorType) {
  4106. var styleStrings = parseRules(theme, colorType, rulesByType[colorType]);
  4107. while (styleStrings.length) {
  4108. var style = document.createElement('style');
  4109. style.setAttribute('type', 'text/css');
  4110. style.appendChild(document.createTextNode(styleStrings.shift()));
  4111. head.insertBefore(style, firstChild);
  4112. }
  4113. });
  4114. if (theme.colors.primary.name == theme.colors.accent.name) {
  4115. console.warn("$mdThemingProvider: Using the same palette for primary and" +
  4116. " accent. This violates the material design spec.");
  4117. }
  4118. GENERATED[theme.name] = true;
  4119. }
  4120. });
  4121. // *************************
  4122. // Internal functions
  4123. // *************************
  4124. // The user specifies a 'default' contrast color as either light or dark,
  4125. // then explicitly lists which hues are the opposite contrast (eg. A100 has dark, A200 has light)
  4126. function sanitizePalette(palette) {
  4127. var defaultContrast = palette.contrastDefaultColor;
  4128. var lightColors = palette.contrastLightColors || [];
  4129. var strongLightColors = palette.contrastStrongLightColors || [];
  4130. var darkColors = palette.contrastDarkColors || [];
  4131. // These colors are provided as space-separated lists
  4132. if (typeof lightColors === 'string') lightColors = lightColors.split(' ');
  4133. if (typeof strongLightColors === 'string') strongLightColors = strongLightColors.split(' ');
  4134. if (typeof darkColors === 'string') darkColors = darkColors.split(' ');
  4135. // Cleanup after ourselves
  4136. delete palette.contrastDefaultColor;
  4137. delete palette.contrastLightColors;
  4138. delete palette.contrastStrongLightColors;
  4139. delete palette.contrastDarkColors;
  4140. // Change { 'A100': '#fffeee' } to { 'A100': { value: '#fffeee', contrast:DARK_CONTRAST_COLOR }
  4141. angular.forEach(palette, function(hueValue, hueName) {
  4142. if (angular.isObject(hueValue)) return; // Already converted
  4143. // Map everything to rgb colors
  4144. var rgbValue = colorToRgbaArray(hueValue);
  4145. if (!rgbValue) {
  4146. throw new Error("Color %1, in palette %2's hue %3, is invalid. Hex or rgb(a) color expected."
  4147. .replace('%1', hueValue)
  4148. .replace('%2', palette.name)
  4149. .replace('%3', hueName));
  4150. }
  4151. palette[hueName] = {
  4152. value: rgbValue,
  4153. contrast: getContrastColor()
  4154. };
  4155. function getContrastColor() {
  4156. if (defaultContrast === 'light') {
  4157. if (darkColors.indexOf(hueName) > -1) {
  4158. return DARK_CONTRAST_COLOR;
  4159. } else {
  4160. return strongLightColors.indexOf(hueName) > -1 ? STRONG_LIGHT_CONTRAST_COLOR
  4161. : LIGHT_CONTRAST_COLOR;
  4162. }
  4163. } else {
  4164. if (lightColors.indexOf(hueName) > -1) {
  4165. return strongLightColors.indexOf(hueName) > -1 ? STRONG_LIGHT_CONTRAST_COLOR
  4166. : LIGHT_CONTRAST_COLOR;
  4167. } else {
  4168. return DARK_CONTRAST_COLOR;
  4169. }
  4170. }
  4171. }
  4172. });
  4173. }
  4174. }
  4175. generateThemes.$inject = ["$injector"];
  4176. function checkValidPalette(theme, colorType) {
  4177. // If theme attempts to use a palette that doesnt exist, throw error
  4178. if (!PALETTES[ (theme.colors[colorType] || {}).name ]) {
  4179. throw new Error(
  4180. "You supplied an invalid color palette for theme %1's %2 palette. Available palettes: %3"
  4181. .replace('%1', theme.name)
  4182. .replace('%2', colorType)
  4183. .replace('%3', Object.keys(PALETTES).join(', '))
  4184. );
  4185. }
  4186. }
  4187. function colorToRgbaArray(clr) {
  4188. if (angular.isArray(clr) && clr.length == 3) return clr;
  4189. if (/^rgb/.test(clr)) {
  4190. return clr.replace(/(^\s*rgba?\(|\)\s*$)/g, '').split(',').map(function(value, i) {
  4191. return i == 3 ? parseFloat(value, 10) : parseInt(value, 10);
  4192. });
  4193. }
  4194. if (clr.charAt(0) == '#') clr = clr.substring(1);
  4195. if (!/^([a-fA-F0-9]{3}){1,2}$/g.test(clr)) return;
  4196. var dig = clr.length / 3;
  4197. var red = clr.substr(0, dig);
  4198. var grn = clr.substr(dig, dig);
  4199. var blu = clr.substr(dig * 2);
  4200. if (dig === 1) {
  4201. red += red;
  4202. grn += grn;
  4203. blu += blu;
  4204. }
  4205. return [parseInt(red, 16), parseInt(grn, 16), parseInt(blu, 16)];
  4206. }
  4207. function rgba(rgbArray, opacity) {
  4208. if ( !rgbArray ) return "rgb('0,0,0')";
  4209. if (rgbArray.length == 4) {
  4210. rgbArray = angular.copy(rgbArray);
  4211. opacity ? rgbArray.pop() : opacity = rgbArray.pop();
  4212. }
  4213. return opacity && (typeof opacity == 'number' || (typeof opacity == 'string' && opacity.length)) ?
  4214. 'rgba(' + rgbArray.join(',') + ',' + opacity + ')' :
  4215. 'rgb(' + rgbArray.join(',') + ')';
  4216. }
  4217. })();
  4218. (function(){
  4219. "use strict";
  4220. // Polyfill angular < 1.4 (provide $animateCss)
  4221. angular
  4222. .module('material.core')
  4223. .factory('$$mdAnimate', ["$q", "$timeout", "$mdConstant", "$animateCss", function($q, $timeout, $mdConstant, $animateCss){
  4224. // Since $$mdAnimate is injected into $mdUtil... use a wrapper function
  4225. // to subsequently inject $mdUtil as an argument to the AnimateDomUtils
  4226. return function($mdUtil) {
  4227. return AnimateDomUtils( $mdUtil, $q, $timeout, $mdConstant, $animateCss);
  4228. };
  4229. }]);
  4230. /**
  4231. * Factory function that requires special injections
  4232. */
  4233. function AnimateDomUtils($mdUtil, $q, $timeout, $mdConstant, $animateCss) {
  4234. var self;
  4235. return self = {
  4236. /**
  4237. *
  4238. */
  4239. translate3d : function( target, from, to, options ) {
  4240. return $animateCss(target,{
  4241. from:from,
  4242. to:to,
  4243. addClass:options.transitionInClass
  4244. })
  4245. .start()
  4246. .then(function(){
  4247. // Resolve with reverser function...
  4248. return reverseTranslate;
  4249. });
  4250. /**
  4251. * Specific reversal of the request translate animation above...
  4252. */
  4253. function reverseTranslate (newFrom) {
  4254. return $animateCss(target, {
  4255. to: newFrom || from,
  4256. addClass: options.transitionOutClass,
  4257. removeClass: options.transitionInClass
  4258. }).start();
  4259. }
  4260. },
  4261. /**
  4262. * Listen for transitionEnd event (with optional timeout)
  4263. * Announce completion or failure via promise handlers
  4264. */
  4265. waitTransitionEnd: function (element, opts) {
  4266. var TIMEOUT = 3000; // fallback is 3 secs
  4267. return $q(function(resolve, reject){
  4268. opts = opts || { };
  4269. var timer = $timeout(finished, opts.timeout || TIMEOUT);
  4270. element.on($mdConstant.CSS.TRANSITIONEND, finished);
  4271. /**
  4272. * Upon timeout or transitionEnd, reject or resolve (respectively) this promise.
  4273. * NOTE: Make sure this transitionEnd didn't bubble up from a child
  4274. */
  4275. function finished(ev) {
  4276. if ( ev && ev.target !== element[0]) return;
  4277. if ( ev ) $timeout.cancel(timer);
  4278. element.off($mdConstant.CSS.TRANSITIONEND, finished);
  4279. // Never reject since ngAnimate may cause timeouts due missed transitionEnd events
  4280. resolve();
  4281. }
  4282. });
  4283. },
  4284. /**
  4285. * Calculate the zoom transform from dialog to origin.
  4286. *
  4287. * We use this to set the dialog position immediately;
  4288. * then the md-transition-in actually translates back to
  4289. * `translate3d(0,0,0) scale(1.0)`...
  4290. *
  4291. * NOTE: all values are rounded to the nearest integer
  4292. */
  4293. calculateZoomToOrigin: function (element, originator) {
  4294. var origin = originator.element;
  4295. var zoomTemplate = "translate3d( {centerX}px, {centerY}px, 0 ) scale( {scaleX}, {scaleY} )";
  4296. var buildZoom = angular.bind(null, $mdUtil.supplant, zoomTemplate);
  4297. var zoomStyle = buildZoom({centerX: 0, centerY: 0, scaleX: 0.5, scaleY: 0.5});
  4298. if (origin) {
  4299. var originBnds = self.clientRect(origin) || self.copyRect(originator.bounds);
  4300. var dialogRect = self.copyRect(element[0].getBoundingClientRect());
  4301. var dialogCenterPt = self.centerPointFor(dialogRect);
  4302. var originCenterPt = self.centerPointFor(originBnds);
  4303. // Build the transform to zoom from the dialog center to the origin center
  4304. zoomStyle = buildZoom({
  4305. centerX: originCenterPt.x - dialogCenterPt.x,
  4306. centerY: originCenterPt.y - dialogCenterPt.y,
  4307. scaleX: Math.round(100 * Math.min(0.5, originBnds.width / dialogRect.width))/100,
  4308. scaleY: Math.round(100 * Math.min(0.5, originBnds.height / dialogRect.height))/100
  4309. });
  4310. }
  4311. return zoomStyle;
  4312. },
  4313. /**
  4314. * Enhance raw values to represent valid css stylings...
  4315. */
  4316. toCss : function( raw ) {
  4317. var css = { };
  4318. var lookups = 'left top right bottom width height x y min-width min-height max-width max-height';
  4319. angular.forEach(raw, function(value,key) {
  4320. if ( angular.isUndefined(value) ) return;
  4321. if ( lookups.indexOf(key) >= 0 ) {
  4322. css[key] = value + 'px';
  4323. } else {
  4324. switch (key) {
  4325. case 'transition':
  4326. convertToVendor(key, $mdConstant.CSS.TRANSITION, value);
  4327. break;
  4328. case 'transform':
  4329. convertToVendor(key, $mdConstant.CSS.TRANSFORM, value);
  4330. break;
  4331. case 'transformOrigin':
  4332. convertToVendor(key, $mdConstant.CSS.TRANSFORM_ORIGIN, value);
  4333. break;
  4334. }
  4335. }
  4336. });
  4337. return css;
  4338. function convertToVendor(key, vendor, value) {
  4339. angular.forEach(vendor.split(' '), function (key) {
  4340. css[key] = value;
  4341. });
  4342. }
  4343. },
  4344. /**
  4345. * Convert the translate CSS value to key/value pair(s).
  4346. */
  4347. toTransformCss: function (transform, addTransition, transition) {
  4348. var css = {};
  4349. angular.forEach($mdConstant.CSS.TRANSFORM.split(' '), function (key) {
  4350. css[key] = transform;
  4351. });
  4352. if (addTransition) {
  4353. transition = transition || "all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) !important";
  4354. css['transition'] = transition;
  4355. }
  4356. return css;
  4357. },
  4358. /**
  4359. * Clone the Rect and calculate the height/width if needed
  4360. */
  4361. copyRect: function (source, destination) {
  4362. if (!source) return null;
  4363. destination = destination || {};
  4364. angular.forEach('left top right bottom width height'.split(' '), function (key) {
  4365. destination[key] = Math.round(source[key])
  4366. });
  4367. destination.width = destination.width || (destination.right - destination.left);
  4368. destination.height = destination.height || (destination.bottom - destination.top);
  4369. return destination;
  4370. },
  4371. /**
  4372. * Calculate ClientRect of element; return null if hidden or zero size
  4373. */
  4374. clientRect: function (element) {
  4375. var bounds = angular.element(element)[0].getBoundingClientRect();
  4376. var isPositiveSizeClientRect = function (rect) {
  4377. return rect && (rect.width > 0) && (rect.height > 0);
  4378. };
  4379. // If the event origin element has zero size, it has probably been hidden.
  4380. return isPositiveSizeClientRect(bounds) ? self.copyRect(bounds) : null;
  4381. },
  4382. /**
  4383. * Calculate 'rounded' center point of Rect
  4384. */
  4385. centerPointFor: function (targetRect) {
  4386. return {
  4387. x: Math.round(targetRect.left + (targetRect.width / 2)),
  4388. y: Math.round(targetRect.top + (targetRect.height / 2))
  4389. }
  4390. }
  4391. };
  4392. };
  4393. })();
  4394. (function(){
  4395. "use strict";
  4396. "use strict";
  4397. if (angular.version.minor >= 4) {
  4398. angular.module('material.core.animate', []);
  4399. } else {
  4400. (function() {
  4401. var forEach = angular.forEach;
  4402. var WEBKIT = angular.isDefined(document.documentElement.style.WebkitAppearance);
  4403. var TRANSITION_PROP = WEBKIT ? 'WebkitTransition' : 'transition';
  4404. var ANIMATION_PROP = WEBKIT ? 'WebkitAnimation' : 'animation';
  4405. var PREFIX = WEBKIT ? '-webkit-' : '';
  4406. var TRANSITION_EVENTS = (WEBKIT ? 'webkitTransitionEnd ' : '') + 'transitionend';
  4407. var ANIMATION_EVENTS = (WEBKIT ? 'webkitAnimationEnd ' : '') + 'animationend';
  4408. var $$ForceReflowFactory = ['$document', function($document) {
  4409. return function() {
  4410. return $document[0].body.clientWidth + 1;
  4411. }
  4412. }];
  4413. var $$rAFMutexFactory = ['$$rAF', function($$rAF) {
  4414. return function() {
  4415. var passed = false;
  4416. $$rAF(function() {
  4417. passed = true;
  4418. });
  4419. return function(fn) {
  4420. passed ? fn() : $$rAF(fn);
  4421. };
  4422. };
  4423. }];
  4424. var $$AnimateRunnerFactory = ['$q', '$$rAFMutex', function($q, $$rAFMutex) {
  4425. var INITIAL_STATE = 0;
  4426. var DONE_PENDING_STATE = 1;
  4427. var DONE_COMPLETE_STATE = 2;
  4428. function AnimateRunner(host) {
  4429. this.setHost(host);
  4430. this._doneCallbacks = [];
  4431. this._runInAnimationFrame = $$rAFMutex();
  4432. this._state = 0;
  4433. }
  4434. AnimateRunner.prototype = {
  4435. setHost: function(host) {
  4436. this.host = host || {};
  4437. },
  4438. done: function(fn) {
  4439. if (this._state === DONE_COMPLETE_STATE) {
  4440. fn();
  4441. } else {
  4442. this._doneCallbacks.push(fn);
  4443. }
  4444. },
  4445. progress: angular.noop,
  4446. getPromise: function() {
  4447. if (!this.promise) {
  4448. var self = this;
  4449. this.promise = $q(function(resolve, reject) {
  4450. self.done(function(status) {
  4451. status === false ? reject() : resolve();
  4452. });
  4453. });
  4454. }
  4455. return this.promise;
  4456. },
  4457. then: function(resolveHandler, rejectHandler) {
  4458. return this.getPromise().then(resolveHandler, rejectHandler);
  4459. },
  4460. 'catch': function(handler) {
  4461. return this.getPromise()['catch'](handler);
  4462. },
  4463. 'finally': function(handler) {
  4464. return this.getPromise()['finally'](handler);
  4465. },
  4466. pause: function() {
  4467. if (this.host.pause) {
  4468. this.host.pause();
  4469. }
  4470. },
  4471. resume: function() {
  4472. if (this.host.resume) {
  4473. this.host.resume();
  4474. }
  4475. },
  4476. end: function() {
  4477. if (this.host.end) {
  4478. this.host.end();
  4479. }
  4480. this._resolve(true);
  4481. },
  4482. cancel: function() {
  4483. if (this.host.cancel) {
  4484. this.host.cancel();
  4485. }
  4486. this._resolve(false);
  4487. },
  4488. complete: function(response) {
  4489. var self = this;
  4490. if (self._state === INITIAL_STATE) {
  4491. self._state = DONE_PENDING_STATE;
  4492. self._runInAnimationFrame(function() {
  4493. self._resolve(response);
  4494. });
  4495. }
  4496. },
  4497. _resolve: function(response) {
  4498. if (this._state !== DONE_COMPLETE_STATE) {
  4499. forEach(this._doneCallbacks, function(fn) {
  4500. fn(response);
  4501. });
  4502. this._doneCallbacks.length = 0;
  4503. this._state = DONE_COMPLETE_STATE;
  4504. }
  4505. }
  4506. };
  4507. return AnimateRunner;
  4508. }];
  4509. angular
  4510. .module('material.core.animate', [])
  4511. .factory('$$forceReflow', $$ForceReflowFactory)
  4512. .factory('$$AnimateRunner', $$AnimateRunnerFactory)
  4513. .factory('$$rAFMutex', $$rAFMutexFactory)
  4514. .factory('$animateCss', ['$window', '$$rAF', '$$AnimateRunner', '$$forceReflow', '$$jqLite', '$timeout',
  4515. function($window, $$rAF, $$AnimateRunner, $$forceReflow, $$jqLite, $timeout) {
  4516. function init(element, options) {
  4517. var temporaryStyles = [];
  4518. var node = getDomNode(element);
  4519. if (options.transitionStyle) {
  4520. temporaryStyles.push([PREFIX + 'transition', options.transitionStyle]);
  4521. }
  4522. if (options.keyframeStyle) {
  4523. temporaryStyles.push([PREFIX + 'animation', options.keyframeStyle]);
  4524. }
  4525. if (options.delay) {
  4526. temporaryStyles.push([PREFIX + 'transition-delay', options.delay + 's']);
  4527. }
  4528. if (options.duration) {
  4529. temporaryStyles.push([PREFIX + 'transition-duration', options.duration + 's']);
  4530. }
  4531. var hasCompleteStyles = options.keyframeStyle ||
  4532. (options.to && (options.duration > 0 || options.transitionStyle));
  4533. var hasCompleteClasses = !!options.addClass || !!options.removeClass;
  4534. var hasCompleteAnimation = hasCompleteStyles || hasCompleteClasses;
  4535. blockTransition(element, true);
  4536. applyAnimationFromStyles(element, options);
  4537. var animationClosed = false;
  4538. var events, eventFn;
  4539. return {
  4540. close: $window.close,
  4541. start: function() {
  4542. var runner = new $$AnimateRunner();
  4543. waitUntilQuiet(function() {
  4544. blockTransition(element, false);
  4545. if (!hasCompleteAnimation) {
  4546. return close();
  4547. }
  4548. forEach(temporaryStyles, function(entry) {
  4549. var key = entry[0];
  4550. var value = entry[1];
  4551. node.style[camelCase(key)] = value;
  4552. });
  4553. applyClasses(element, options);
  4554. var timings = computeTimings(element);
  4555. if (timings.duration === 0) {
  4556. return close();
  4557. }
  4558. var moreStyles = [];
  4559. if (options.easing) {
  4560. if (timings.transitionDuration) {
  4561. moreStyles.push([PREFIX + 'transition-timing-function', options.easing]);
  4562. }
  4563. if (timings.animationDuration) {
  4564. moreStyles.push([PREFIX + 'animation-timing-function', options.easing]);
  4565. }
  4566. }
  4567. if (options.delay && timings.animationDelay) {
  4568. moreStyles.push([PREFIX + 'animation-delay', options.delay + 's']);
  4569. }
  4570. if (options.duration && timings.animationDuration) {
  4571. moreStyles.push([PREFIX + 'animation-duration', options.duration + 's']);
  4572. }
  4573. forEach(moreStyles, function(entry) {
  4574. var key = entry[0];
  4575. var value = entry[1];
  4576. node.style[camelCase(key)] = value;
  4577. temporaryStyles.push(entry);
  4578. });
  4579. var maxDelay = timings.delay;
  4580. var maxDelayTime = maxDelay * 1000;
  4581. var maxDuration = timings.duration;
  4582. var maxDurationTime = maxDuration * 1000;
  4583. var startTime = Date.now();
  4584. events = [];
  4585. if (timings.transitionDuration) {
  4586. events.push(TRANSITION_EVENTS);
  4587. }
  4588. if (timings.animationDuration) {
  4589. events.push(ANIMATION_EVENTS);
  4590. }
  4591. events = events.join(' ');
  4592. eventFn = function(event) {
  4593. event.stopPropagation();
  4594. var ev = event.originalEvent || event;
  4595. var timeStamp = ev.timeStamp || Date.now();
  4596. var elapsedTime = parseFloat(ev.elapsedTime.toFixed(3));
  4597. if (Math.max(timeStamp - startTime, 0) >= maxDelayTime && elapsedTime >= maxDuration) {
  4598. close();
  4599. }
  4600. };
  4601. element.on(events, eventFn);
  4602. applyAnimationToStyles(element, options);
  4603. $timeout(close, maxDelayTime + maxDurationTime * 1.5, false);
  4604. });
  4605. return runner;
  4606. function close() {
  4607. if (animationClosed) return;
  4608. animationClosed = true;
  4609. if (events && eventFn) {
  4610. element.off(events, eventFn);
  4611. }
  4612. applyClasses(element, options);
  4613. applyAnimationStyles(element, options);
  4614. forEach(temporaryStyles, function(entry) {
  4615. node.style[camelCase(entry[0])] = '';
  4616. });
  4617. runner.complete(true);
  4618. return runner;
  4619. }
  4620. }
  4621. }
  4622. }
  4623. function applyClasses(element, options) {
  4624. if (options.addClass) {
  4625. $$jqLite.addClass(element, options.addClass);
  4626. options.addClass = null;
  4627. }
  4628. if (options.removeClass) {
  4629. $$jqLite.removeClass(element, options.removeClass);
  4630. options.removeClass = null;
  4631. }
  4632. }
  4633. function computeTimings(element) {
  4634. var node = getDomNode(element);
  4635. var cs = $window.getComputedStyle(node)
  4636. var tdr = parseMaxTime(cs[prop('transitionDuration')]);
  4637. var adr = parseMaxTime(cs[prop('animationDuration')]);
  4638. var tdy = parseMaxTime(cs[prop('transitionDelay')]);
  4639. var ady = parseMaxTime(cs[prop('animationDelay')]);
  4640. adr *= (parseInt(cs[prop('animationIterationCount')], 10) || 1);
  4641. var duration = Math.max(adr, tdr);
  4642. var delay = Math.max(ady, tdy);
  4643. return {
  4644. duration: duration,
  4645. delay: delay,
  4646. animationDuration: adr,
  4647. transitionDuration: tdr,
  4648. animationDelay: ady,
  4649. transitionDelay: tdy
  4650. };
  4651. function prop(key) {
  4652. return WEBKIT ? 'Webkit' + key.charAt(0).toUpperCase() + key.substr(1)
  4653. : key;
  4654. }
  4655. }
  4656. function parseMaxTime(str) {
  4657. var maxValue = 0;
  4658. var values = (str || "").split(/\s*,\s*/);
  4659. forEach(values, function(value) {
  4660. // it's always safe to consider only second values and omit `ms` values since
  4661. // getComputedStyle will always handle the conversion for us
  4662. if (value.charAt(value.length - 1) == 's') {
  4663. value = value.substring(0, value.length - 1);
  4664. }
  4665. value = parseFloat(value) || 0;
  4666. maxValue = maxValue ? Math.max(value, maxValue) : value;
  4667. });
  4668. return maxValue;
  4669. }
  4670. var cancelLastRAFRequest;
  4671. var rafWaitQueue = [];
  4672. function waitUntilQuiet(callback) {
  4673. if (cancelLastRAFRequest) {
  4674. cancelLastRAFRequest(); //cancels the request
  4675. }
  4676. rafWaitQueue.push(callback);
  4677. cancelLastRAFRequest = $$rAF(function() {
  4678. cancelLastRAFRequest = null;
  4679. // DO NOT REMOVE THIS LINE OR REFACTOR OUT THE `pageWidth` variable.
  4680. // PLEASE EXAMINE THE `$$forceReflow` service to understand why.
  4681. var pageWidth = $$forceReflow();
  4682. // we use a for loop to ensure that if the queue is changed
  4683. // during this looping then it will consider new requests
  4684. for (var i = 0; i < rafWaitQueue.length; i++) {
  4685. rafWaitQueue[i](pageWidth);
  4686. }
  4687. rafWaitQueue.length = 0;
  4688. });
  4689. }
  4690. function applyAnimationStyles(element, options) {
  4691. applyAnimationFromStyles(element, options);
  4692. applyAnimationToStyles(element, options);
  4693. }
  4694. function applyAnimationFromStyles(element, options) {
  4695. if (options.from) {
  4696. element.css(options.from);
  4697. options.from = null;
  4698. }
  4699. }
  4700. function applyAnimationToStyles(element, options) {
  4701. if (options.to) {
  4702. element.css(options.to);
  4703. options.to = null;
  4704. }
  4705. }
  4706. function getDomNode(element) {
  4707. for (var i = 0; i < element.length; i++) {
  4708. if (element[i].nodeType === 1) return element[i];
  4709. }
  4710. }
  4711. function blockTransition(element, bool) {
  4712. var node = getDomNode(element);
  4713. var key = camelCase(PREFIX + 'transition-delay');
  4714. node.style[key] = bool ? '-9999s' : '';
  4715. }
  4716. return init;
  4717. }]);
  4718. /**
  4719. * Older browsers [FF31] expect camelCase
  4720. * property keys.
  4721. * e.g.
  4722. * animation-duration --> animationDuration
  4723. */
  4724. function camelCase(str) {
  4725. return str.replace(/-[a-z]/g, function(str) {
  4726. return str.charAt(1).toUpperCase();
  4727. });
  4728. }
  4729. })();
  4730. }
  4731. })();
  4732. (function(){
  4733. "use strict";
  4734. /**
  4735. * @ngdoc module
  4736. * @name material.components.autocomplete
  4737. */
  4738. /*
  4739. * @see js folder for autocomplete implementation
  4740. */
  4741. angular.module('material.components.autocomplete', [
  4742. 'material.core',
  4743. 'material.components.icon',
  4744. 'material.components.virtualRepeat'
  4745. ]);
  4746. })();
  4747. (function(){
  4748. "use strict";
  4749. /*
  4750. * @ngdoc module
  4751. * @name material.components.backdrop
  4752. * @description Backdrop
  4753. */
  4754. /**
  4755. * @ngdoc directive
  4756. * @name mdBackdrop
  4757. * @module material.components.backdrop
  4758. *
  4759. * @restrict E
  4760. *
  4761. * @description
  4762. * `<md-backdrop>` is a backdrop element used by other components, such as dialog and bottom sheet.
  4763. * Apply class `opaque` to make the backdrop use the theme backdrop color.
  4764. *
  4765. */
  4766. angular
  4767. .module('material.components.backdrop', ['material.core'])
  4768. .directive('mdBackdrop', ["$mdTheming", "$animate", "$rootElement", "$window", "$log", "$$rAF", "$document", function BackdropDirective($mdTheming, $animate, $rootElement, $window, $log, $$rAF, $document) {
  4769. var ERROR_CSS_POSITION = "<md-backdrop> may not work properly in a scrolled, static-positioned parent container.";
  4770. return {
  4771. restrict: 'E',
  4772. link: postLink
  4773. };
  4774. function postLink(scope, element, attrs) {
  4775. // If body scrolling has been disabled using mdUtil.disableBodyScroll(),
  4776. // adjust the 'backdrop' height to account for the fixed 'body' top offset
  4777. var body = $window.getComputedStyle($document[0].body);
  4778. if (body.position == 'fixed') {
  4779. var hViewport = parseInt(body.height, 10) + Math.abs(parseInt(body.top, 10));
  4780. element.css({
  4781. height: hViewport + 'px'
  4782. });
  4783. }
  4784. // backdrop may be outside the $rootElement, tell ngAnimate to animate regardless
  4785. if ($animate.pin) $animate.pin(element, $rootElement);
  4786. $$rAF(function () {
  4787. // Often $animate.enter() is used to append the backDrop element
  4788. // so let's wait until $animate is done...
  4789. var parent = element.parent()[0];
  4790. if (parent) {
  4791. var styles = $window.getComputedStyle(parent);
  4792. if (styles.position == 'static') {
  4793. // backdrop uses position:absolute and will not work properly with parent position:static (default)
  4794. $log.warn(ERROR_CSS_POSITION);
  4795. }
  4796. }
  4797. $mdTheming.inherit(element, element.parent());
  4798. });
  4799. }
  4800. }]);
  4801. })();
  4802. (function(){
  4803. "use strict";
  4804. /**
  4805. * @ngdoc module
  4806. * @name material.components.bottomSheet
  4807. * @description
  4808. * BottomSheet
  4809. */
  4810. angular
  4811. .module('material.components.bottomSheet', [
  4812. 'material.core',
  4813. 'material.components.backdrop'
  4814. ])
  4815. .directive('mdBottomSheet', MdBottomSheetDirective)
  4816. .provider('$mdBottomSheet', MdBottomSheetProvider);
  4817. /* @ngInject */
  4818. function MdBottomSheetDirective($mdBottomSheet) {
  4819. return {
  4820. restrict: 'E',
  4821. link : function postLink(scope, element, attr) {
  4822. // When navigation force destroys an interimElement, then
  4823. // listen and $destroy() that interim instance...
  4824. scope.$on('$destroy', function() {
  4825. $mdBottomSheet.destroy();
  4826. });
  4827. }
  4828. };
  4829. }
  4830. MdBottomSheetDirective.$inject = ["$mdBottomSheet"];
  4831. /**
  4832. * @ngdoc service
  4833. * @name $mdBottomSheet
  4834. * @module material.components.bottomSheet
  4835. *
  4836. * @description
  4837. * `$mdBottomSheet` opens a bottom sheet over the app and provides a simple promise API.
  4838. *
  4839. * ## Restrictions
  4840. *
  4841. * - The bottom sheet's template must have an outer `<md-bottom-sheet>` element.
  4842. * - Add the `md-grid` class to the bottom sheet for a grid layout.
  4843. * - Add the `md-list` class to the bottom sheet for a list layout.
  4844. *
  4845. * @usage
  4846. * <hljs lang="html">
  4847. * <div ng-controller="MyController">
  4848. * <md-button ng-click="openBottomSheet()">
  4849. * Open a Bottom Sheet!
  4850. * </md-button>
  4851. * </div>
  4852. * </hljs>
  4853. * <hljs lang="js">
  4854. * var app = angular.module('app', ['ngMaterial']);
  4855. * app.controller('MyController', function($scope, $mdBottomSheet) {
  4856. * $scope.openBottomSheet = function() {
  4857. * $mdBottomSheet.show({
  4858. * template: '<md-bottom-sheet>Hello!</md-bottom-sheet>'
  4859. * });
  4860. * };
  4861. * });
  4862. * </hljs>
  4863. */
  4864. /**
  4865. * @ngdoc method
  4866. * @name $mdBottomSheet#show
  4867. *
  4868. * @description
  4869. * Show a bottom sheet with the specified options.
  4870. *
  4871. * @param {object} options An options object, with the following properties:
  4872. *
  4873. * - `templateUrl` - `{string=}`: The url of an html template file that will
  4874. * be used as the content of the bottom sheet. Restrictions: the template must
  4875. * have an outer `md-bottom-sheet` element.
  4876. * - `template` - `{string=}`: Same as templateUrl, except this is an actual
  4877. * template string.
  4878. * - `scope` - `{object=}`: the scope to link the template / controller to. If none is specified, it will create a new child scope.
  4879. * This scope will be destroyed when the bottom sheet is removed unless `preserveScope` is set to true.
  4880. * - `preserveScope` - `{boolean=}`: whether to preserve the scope when the element is removed. Default is false
  4881. * - `controller` - `{string=}`: The controller to associate with this bottom sheet.
  4882. * - `locals` - `{string=}`: An object containing key/value pairs. The keys will
  4883. * be used as names of values to inject into the controller. For example,
  4884. * `locals: {three: 3}` would inject `three` into the controller with the value
  4885. * of 3.
  4886. * - `clickOutsideToClose` - `{boolean=}`: Whether the user can click outside the bottom sheet to
  4887. * close it. Default true.
  4888. * - `escapeToClose` - `{boolean=}`: Whether the user can press escape to close the bottom sheet.
  4889. * Default true.
  4890. * - `resolve` - `{object=}`: Similar to locals, except it takes promises as values
  4891. * and the bottom sheet will not open until the promises resolve.
  4892. * - `controllerAs` - `{string=}`: An alias to assign the controller to on the scope.
  4893. * - `parent` - `{element=}`: The element to append the bottom sheet to. The `parent` may be a `function`, `string`,
  4894. * `object`, or null. Defaults to appending to the body of the root element (or the root element) of the application.
  4895. * e.g. angular.element(document.getElementById('content')) or "#content"
  4896. * - `disableParentScroll` - `{boolean=}`: Whether to disable scrolling while the bottom sheet is open.
  4897. * Default true.
  4898. *
  4899. * @returns {promise} A promise that can be resolved with `$mdBottomSheet.hide()` or
  4900. * rejected with `$mdBottomSheet.cancel()`.
  4901. */
  4902. /**
  4903. * @ngdoc method
  4904. * @name $mdBottomSheet#hide
  4905. *
  4906. * @description
  4907. * Hide the existing bottom sheet and resolve the promise returned from
  4908. * `$mdBottomSheet.show()`. This call will close the most recently opened/current bottomsheet (if any).
  4909. *
  4910. * @param {*=} response An argument for the resolved promise.
  4911. *
  4912. */
  4913. /**
  4914. * @ngdoc method
  4915. * @name $mdBottomSheet#cancel
  4916. *
  4917. * @description
  4918. * Hide the existing bottom sheet and reject the promise returned from
  4919. * `$mdBottomSheet.show()`.
  4920. *
  4921. * @param {*=} response An argument for the rejected promise.
  4922. *
  4923. */
  4924. function MdBottomSheetProvider($$interimElementProvider) {
  4925. // how fast we need to flick down to close the sheet, pixels/ms
  4926. var CLOSING_VELOCITY = 0.5;
  4927. var PADDING = 80; // same as css
  4928. bottomSheetDefaults.$inject = ["$animate", "$mdConstant", "$mdUtil", "$mdTheming", "$mdBottomSheet", "$rootElement", "$mdGesture"];
  4929. return $$interimElementProvider('$mdBottomSheet')
  4930. .setDefaults({
  4931. methods: ['disableParentScroll', 'escapeToClose', 'clickOutsideToClose'],
  4932. options: bottomSheetDefaults
  4933. });
  4934. /* @ngInject */
  4935. function bottomSheetDefaults($animate, $mdConstant, $mdUtil, $mdTheming, $mdBottomSheet, $rootElement, $mdGesture) {
  4936. var backdrop;
  4937. return {
  4938. themable: true,
  4939. onShow: onShow,
  4940. onRemove: onRemove,
  4941. escapeToClose: true,
  4942. clickOutsideToClose: true,
  4943. disableParentScroll: true
  4944. };
  4945. function onShow(scope, element, options, controller) {
  4946. element = $mdUtil.extractElementByName(element, 'md-bottom-sheet');
  4947. // Add a backdrop that will close on click
  4948. backdrop = $mdUtil.createBackdrop(scope, "md-bottom-sheet-backdrop md-opaque");
  4949. if (options.clickOutsideToClose) {
  4950. backdrop.on('click', function() {
  4951. $mdUtil.nextTick($mdBottomSheet.cancel,true);
  4952. });
  4953. }
  4954. $mdTheming.inherit(backdrop, options.parent);
  4955. $animate.enter(backdrop, options.parent, null);
  4956. var bottomSheet = new BottomSheet(element, options.parent);
  4957. options.bottomSheet = bottomSheet;
  4958. $mdTheming.inherit(bottomSheet.element, options.parent);
  4959. if (options.disableParentScroll) {
  4960. options.restoreScroll = $mdUtil.disableScrollAround(bottomSheet.element, options.parent);
  4961. }
  4962. return $animate.enter(bottomSheet.element, options.parent)
  4963. .then(function() {
  4964. var focusable = $mdUtil.findFocusTarget(element) || angular.element(
  4965. element[0].querySelector('button') ||
  4966. element[0].querySelector('a') ||
  4967. element[0].querySelector('[ng-click]')
  4968. );
  4969. focusable.focus();
  4970. if (options.escapeToClose) {
  4971. options.rootElementKeyupCallback = function(e) {
  4972. if (e.keyCode === $mdConstant.KEY_CODE.ESCAPE) {
  4973. $mdUtil.nextTick($mdBottomSheet.cancel,true);
  4974. }
  4975. };
  4976. $rootElement.on('keyup', options.rootElementKeyupCallback);
  4977. }
  4978. });
  4979. }
  4980. function onRemove(scope, element, options) {
  4981. var bottomSheet = options.bottomSheet;
  4982. $animate.leave(backdrop);
  4983. return $animate.leave(bottomSheet.element).then(function() {
  4984. if (options.disableParentScroll) {
  4985. options.restoreScroll();
  4986. delete options.restoreScroll;
  4987. }
  4988. bottomSheet.cleanup();
  4989. });
  4990. }
  4991. /**
  4992. * BottomSheet class to apply bottom-sheet behavior to an element
  4993. */
  4994. function BottomSheet(element, parent) {
  4995. var deregister = $mdGesture.register(parent, 'drag', { horizontal: false });
  4996. parent.on('$md.dragstart', onDragStart)
  4997. .on('$md.drag', onDrag)
  4998. .on('$md.dragend', onDragEnd);
  4999. return {
  5000. element: element,
  5001. cleanup: function cleanup() {
  5002. deregister();
  5003. parent.off('$md.dragstart', onDragStart);
  5004. parent.off('$md.drag', onDrag);
  5005. parent.off('$md.dragend', onDragEnd);
  5006. }
  5007. };
  5008. function onDragStart(ev) {
  5009. // Disable transitions on transform so that it feels fast
  5010. element.css($mdConstant.CSS.TRANSITION_DURATION, '0ms');
  5011. }
  5012. function onDrag(ev) {
  5013. var transform = ev.pointer.distanceY;
  5014. if (transform < 5) {
  5015. // Slow down drag when trying to drag up, and stop after PADDING
  5016. transform = Math.max(-PADDING, transform / 2);
  5017. }
  5018. element.css($mdConstant.CSS.TRANSFORM, 'translate3d(0,' + (PADDING + transform) + 'px,0)');
  5019. }
  5020. function onDragEnd(ev) {
  5021. if (ev.pointer.distanceY > 0 &&
  5022. (ev.pointer.distanceY > 20 || Math.abs(ev.pointer.velocityY) > CLOSING_VELOCITY)) {
  5023. var distanceRemaining = element.prop('offsetHeight') - ev.pointer.distanceY;
  5024. var transitionDuration = Math.min(distanceRemaining / ev.pointer.velocityY * 0.75, 500);
  5025. element.css($mdConstant.CSS.TRANSITION_DURATION, transitionDuration + 'ms');
  5026. $mdUtil.nextTick($mdBottomSheet.cancel,true);
  5027. } else {
  5028. element.css($mdConstant.CSS.TRANSITION_DURATION, '');
  5029. element.css($mdConstant.CSS.TRANSFORM, '');
  5030. }
  5031. }
  5032. }
  5033. }
  5034. }
  5035. MdBottomSheetProvider.$inject = ["$$interimElementProvider"];
  5036. })();
  5037. (function(){
  5038. "use strict";
  5039. /**
  5040. * @ngdoc module
  5041. * @name material.components.button
  5042. * @description
  5043. *
  5044. * Button
  5045. */
  5046. angular
  5047. .module('material.components.button', [ 'material.core' ])
  5048. .directive('mdButton', MdButtonDirective);
  5049. /**
  5050. * @ngdoc directive
  5051. * @name mdButton
  5052. * @module material.components.button
  5053. *
  5054. * @restrict E
  5055. *
  5056. * @description
  5057. * `<md-button>` is a button directive with optional ink ripples (default enabled).
  5058. *
  5059. * If you supply a `href` or `ng-href` attribute, it will become an `<a>` element. Otherwise, it will
  5060. * become a `<button>` element. As per the [Material Design specifications](http://www.google.com/design/spec/style/color.html#color-ui-color-application)
  5061. * the FAB button background is filled with the accent color [by default]. The primary color palette may be used with
  5062. * the `md-primary` class.
  5063. *
  5064. * @param {boolean=} md-no-ink If present, disable ripple ink effects.
  5065. * @param {expression=} ng-disabled En/Disable based on the expression
  5066. * @param {string=} md-ripple-size Overrides the default ripple size logic. Options: `full`, `partial`, `auto`
  5067. * @param {string=} aria-label Adds alternative text to button for accessibility, useful for icon buttons.
  5068. * If no default text is found, a warning will be logged.
  5069. *
  5070. * @usage
  5071. *
  5072. * Regular buttons:
  5073. *
  5074. * <hljs lang="html">
  5075. * <md-button> Flat Button </md-button>
  5076. * <md-button href="http://google.com"> Flat link </md-button>
  5077. * <md-button class="md-raised"> Raised Button </md-button>
  5078. * <md-button ng-disabled="true"> Disabled Button </md-button>
  5079. * <md-button>
  5080. * <md-icon md-svg-src="your/icon.svg"></md-icon>
  5081. * Register Now
  5082. * </md-button>
  5083. * </hljs>
  5084. *
  5085. * FAB buttons:
  5086. *
  5087. * <hljs lang="html">
  5088. * <md-button class="md-fab" aria-label="FAB">
  5089. * <md-icon md-svg-src="your/icon.svg"></md-icon>
  5090. * </md-button>
  5091. * <!-- mini-FAB -->
  5092. * <md-button class="md-fab md-mini" aria-label="Mini FAB">
  5093. * <md-icon md-svg-src="your/icon.svg"></md-icon>
  5094. * </md-button>
  5095. * <!-- Button with SVG Icon -->
  5096. * <md-button class="md-icon-button" aria-label="Custom Icon Button">
  5097. * <md-icon md-svg-icon="path/to/your.svg"></md-icon>
  5098. * </md-button>
  5099. * </hljs>
  5100. */
  5101. function MdButtonDirective($mdButtonInkRipple, $mdTheming, $mdAria, $timeout) {
  5102. return {
  5103. restrict: 'EA',
  5104. replace: true,
  5105. transclude: true,
  5106. template: getTemplate,
  5107. link: postLink
  5108. };
  5109. function isAnchor(attr) {
  5110. return angular.isDefined(attr.href) || angular.isDefined(attr.ngHref) || angular.isDefined(attr.ngLink) || angular.isDefined(attr.uiSref);
  5111. }
  5112. function getTemplate(element, attr) {
  5113. return isAnchor(attr) ?
  5114. '<a class="md-button" ng-transclude></a>' :
  5115. '<button class="md-button" ng-transclude></button>';
  5116. }
  5117. function postLink(scope, element, attr) {
  5118. var node = element[0];
  5119. $mdTheming(element);
  5120. $mdButtonInkRipple.attach(scope, element);
  5121. var elementHasText = node.textContent.trim();
  5122. if (!elementHasText) {
  5123. $mdAria.expect(element, 'aria-label');
  5124. }
  5125. // For anchor elements, we have to set tabindex manually when the
  5126. // element is disabled
  5127. if (isAnchor(attr) && angular.isDefined(attr.ngDisabled) ) {
  5128. scope.$watch(attr.ngDisabled, function(isDisabled) {
  5129. element.attr('tabindex', isDisabled ? -1 : 0);
  5130. });
  5131. }
  5132. // disabling click event when disabled is true
  5133. element.on('click', function(e){
  5134. if (attr.disabled === true) {
  5135. e.preventDefault();
  5136. e.stopImmediatePropagation();
  5137. }
  5138. });
  5139. // restrict focus styles to the keyboard
  5140. scope.mouseActive = false;
  5141. element.on('mousedown', function() {
  5142. scope.mouseActive = true;
  5143. $timeout(function(){
  5144. scope.mouseActive = false;
  5145. }, 100);
  5146. })
  5147. .on('focus', function() {
  5148. if (scope.mouseActive === false) {
  5149. element.addClass('md-focused');
  5150. }
  5151. })
  5152. .on('blur', function(ev) {
  5153. element.removeClass('md-focused');
  5154. });
  5155. }
  5156. }
  5157. MdButtonDirective.$inject = ["$mdButtonInkRipple", "$mdTheming", "$mdAria", "$timeout"];
  5158. })();
  5159. (function(){
  5160. "use strict";
  5161. /**
  5162. * @ngdoc module
  5163. * @name material.components.card
  5164. *
  5165. * @description
  5166. * Card components.
  5167. */
  5168. angular.module('material.components.card', [
  5169. 'material.core'
  5170. ])
  5171. .directive('mdCard', mdCardDirective);
  5172. /**
  5173. * @ngdoc directive
  5174. * @name mdCard
  5175. * @module material.components.card
  5176. *
  5177. * @restrict E
  5178. *
  5179. * @description
  5180. * The `<md-card>` directive is a container element used within `<md-content>` containers.
  5181. *
  5182. * An image included as a direct descendant will fill the card's width, while the `<md-card-content>`
  5183. * container will wrap text content and provide padding. An `<md-card-footer>` element can be
  5184. * optionally included to put content flush against the bottom edge of the card.
  5185. *
  5186. * Action buttons can be included in an element with the `.md-actions` class, also used in `md-dialog`.
  5187. * You can then position buttons using layout attributes.
  5188. *
  5189. * Cards have constant width and variable heights; where the maximum height is limited to what can
  5190. * fit within a single view on a platform, but it can temporarily expand as needed.
  5191. *
  5192. * @usage
  5193. * ### Card with optional footer
  5194. * <hljs lang="html">
  5195. * <md-card>
  5196. * <img src="card-image.png" class="md-card-image" alt="image caption">
  5197. * <md-card-content>
  5198. * <h2>Card headline</h2>
  5199. * <p>Card content</p>
  5200. * </md-card-content>
  5201. * <md-card-footer>
  5202. * Card footer
  5203. * </md-card-footer>
  5204. * </md-card>
  5205. * </hljs>
  5206. *
  5207. * ### Card with actions
  5208. * <hljs lang="html">
  5209. * <md-card>
  5210. * <img src="card-image.png" class="md-card-image" alt="image caption">
  5211. * <md-card-content>
  5212. * <h2>Card headline</h2>
  5213. * <p>Card content</p>
  5214. * </md-card-content>
  5215. * <div class="md-actions" layout="row" layout-align="end center">
  5216. * <md-button>Action 1</md-button>
  5217. * <md-button>Action 2</md-button>
  5218. * </div>
  5219. * </md-card>
  5220. * </hljs>
  5221. *
  5222. */
  5223. function mdCardDirective($mdTheming) {
  5224. return {
  5225. restrict: 'E',
  5226. link: function($scope, $element, $attr) {
  5227. $mdTheming($element);
  5228. }
  5229. };
  5230. }
  5231. mdCardDirective.$inject = ["$mdTheming"];
  5232. })();
  5233. (function(){
  5234. "use strict";
  5235. /**
  5236. * @ngdoc module
  5237. * @name material.components.checkbox
  5238. * @description Checkbox module!
  5239. */
  5240. angular
  5241. .module('material.components.checkbox', ['material.core'])
  5242. .directive('mdCheckbox', MdCheckboxDirective);
  5243. /**
  5244. * @ngdoc directive
  5245. * @name mdCheckbox
  5246. * @module material.components.checkbox
  5247. * @restrict E
  5248. *
  5249. * @description
  5250. * The checkbox directive is used like the normal [angular checkbox](https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D).
  5251. *
  5252. * As per the [material design spec](http://www.google.com/design/spec/style/color.html#color-ui-color-application)
  5253. * the checkbox is in the accent color by default. The primary color palette may be used with
  5254. * the `md-primary` class.
  5255. *
  5256. * @param {string} ng-model Assignable angular expression to data-bind to.
  5257. * @param {string=} name Property name of the form under which the control is published.
  5258. * @param {expression=} ng-true-value The value to which the expression should be set when selected.
  5259. * @param {expression=} ng-false-value The value to which the expression should be set when not selected.
  5260. * @param {string=} ng-change Angular expression to be executed when input changes due to user interaction with the input element.
  5261. * @param {boolean=} md-no-ink Use of attribute indicates use of ripple ink effects
  5262. * @param {string=} aria-label Adds label to checkbox for accessibility.
  5263. * Defaults to checkbox's text. If no default text is found, a warning will be logged.
  5264. *
  5265. * @usage
  5266. * <hljs lang="html">
  5267. * <md-checkbox ng-model="isChecked" aria-label="Finished?">
  5268. * Finished ?
  5269. * </md-checkbox>
  5270. *
  5271. * <md-checkbox md-no-ink ng-model="hasInk" aria-label="No Ink Effects">
  5272. * No Ink Effects
  5273. * </md-checkbox>
  5274. *
  5275. * <md-checkbox ng-disabled="true" ng-model="isDisabled" aria-label="Disabled">
  5276. * Disabled
  5277. * </md-checkbox>
  5278. *
  5279. * </hljs>
  5280. *
  5281. */
  5282. function MdCheckboxDirective(inputDirective, $mdAria, $mdConstant, $mdTheming, $mdUtil, $timeout) {
  5283. inputDirective = inputDirective[0];
  5284. var CHECKED_CSS = 'md-checked';
  5285. return {
  5286. restrict: 'E',
  5287. transclude: true,
  5288. require: '?ngModel',
  5289. priority: 210, // Run before ngAria
  5290. template:
  5291. '<div class="md-container" md-ink-ripple md-ink-ripple-checkbox>' +
  5292. '<div class="md-icon"></div>' +
  5293. '</div>' +
  5294. '<div ng-transclude class="md-label"></div>',
  5295. compile: compile
  5296. };
  5297. // **********************************************************
  5298. // Private Methods
  5299. // **********************************************************
  5300. function compile (tElement, tAttrs) {
  5301. tAttrs.type = 'checkbox';
  5302. tAttrs.tabindex = tAttrs.tabindex || '0';
  5303. tElement.attr('role', tAttrs.type);
  5304. // Attach a click handler in compile in order to immediately stop propagation
  5305. // (especially for ng-click) when the checkbox is disabled.
  5306. tElement.on('click', function(event) {
  5307. if (this.hasAttribute('disabled')) {
  5308. event.stopImmediatePropagation();
  5309. }
  5310. });
  5311. return function postLink(scope, element, attr, ngModelCtrl) {
  5312. ngModelCtrl = ngModelCtrl || $mdUtil.fakeNgModel();
  5313. $mdTheming(element);
  5314. if (attr.ngChecked) {
  5315. scope.$watch(
  5316. scope.$eval.bind(scope, attr.ngChecked),
  5317. ngModelCtrl.$setViewValue.bind(ngModelCtrl)
  5318. );
  5319. }
  5320. $$watchExpr('ngDisabled', 'tabindex', {
  5321. true: '-1',
  5322. false: attr.tabindex
  5323. });
  5324. $mdAria.expectWithText(element, 'aria-label');
  5325. // Reuse the original input[type=checkbox] directive from Angular core.
  5326. // This is a bit hacky as we need our own event listener and own render
  5327. // function.
  5328. inputDirective.link.pre(scope, {
  5329. on: angular.noop,
  5330. 0: {}
  5331. }, attr, [ngModelCtrl]);
  5332. scope.mouseActive = false;
  5333. element.on('click', listener)
  5334. .on('keypress', keypressHandler)
  5335. .on('mousedown', function() {
  5336. scope.mouseActive = true;
  5337. $timeout(function() {
  5338. scope.mouseActive = false;
  5339. }, 100);
  5340. })
  5341. .on('focus', function() {
  5342. if (scope.mouseActive === false) {
  5343. element.addClass('md-focused');
  5344. }
  5345. })
  5346. .on('blur', function() {
  5347. element.removeClass('md-focused');
  5348. });
  5349. ngModelCtrl.$render = render;
  5350. function $$watchExpr(expr, htmlAttr, valueOpts) {
  5351. if (attr[expr]) {
  5352. scope.$watch(attr[expr], function(val) {
  5353. if (valueOpts[val]) {
  5354. element.attr(htmlAttr, valueOpts[val]);
  5355. }
  5356. });
  5357. }
  5358. }
  5359. function keypressHandler(ev) {
  5360. var keyCode = ev.which || ev.keyCode;
  5361. if (keyCode === $mdConstant.KEY_CODE.SPACE || keyCode === $mdConstant.KEY_CODE.ENTER) {
  5362. ev.preventDefault();
  5363. if (!element.hasClass('md-focused')) {
  5364. element.addClass('md-focused');
  5365. }
  5366. listener(ev);
  5367. }
  5368. }
  5369. function listener(ev) {
  5370. if (element[0].hasAttribute('disabled')) {
  5371. return;
  5372. }
  5373. scope.$apply(function() {
  5374. // Toggle the checkbox value...
  5375. var viewValue = attr.ngChecked ? attr.checked : !ngModelCtrl.$viewValue;
  5376. ngModelCtrl.$setViewValue( viewValue, ev && ev.type);
  5377. ngModelCtrl.$render();
  5378. });
  5379. }
  5380. function render() {
  5381. if(ngModelCtrl.$viewValue) {
  5382. element.addClass(CHECKED_CSS);
  5383. } else {
  5384. element.removeClass(CHECKED_CSS);
  5385. }
  5386. }
  5387. };
  5388. }
  5389. }
  5390. MdCheckboxDirective.$inject = ["inputDirective", "$mdAria", "$mdConstant", "$mdTheming", "$mdUtil", "$timeout"];
  5391. })();
  5392. (function(){
  5393. "use strict";
  5394. /**
  5395. * @ngdoc module
  5396. * @name material.components.chips
  5397. */
  5398. /*
  5399. * @see js folder for chips implementation
  5400. */
  5401. angular.module('material.components.chips', [
  5402. 'material.core',
  5403. 'material.components.autocomplete'
  5404. ]);
  5405. })();
  5406. (function(){
  5407. "use strict";
  5408. /**
  5409. * @ngdoc module
  5410. * @name material.components.content
  5411. *
  5412. * @description
  5413. * Scrollable content
  5414. */
  5415. angular.module('material.components.content', [
  5416. 'material.core'
  5417. ])
  5418. .directive('mdContent', mdContentDirective);
  5419. /**
  5420. * @ngdoc directive
  5421. * @name mdContent
  5422. * @module material.components.content
  5423. *
  5424. * @restrict E
  5425. *
  5426. * @description
  5427. * The `<md-content>` directive is a container element useful for scrollable content
  5428. *
  5429. * @usage
  5430. *
  5431. * - Add the `[layout-padding]` attribute to make the content padded.
  5432. *
  5433. * <hljs lang="html">
  5434. * <md-content layout-padding>
  5435. * Lorem ipsum dolor sit amet, ne quod novum mei.
  5436. * </md-content>
  5437. * </hljs>
  5438. *
  5439. */
  5440. function mdContentDirective($mdTheming) {
  5441. return {
  5442. restrict: 'E',
  5443. controller: ['$scope', '$element', ContentController],
  5444. link: function(scope, element, attr) {
  5445. var node = element[0];
  5446. $mdTheming(element);
  5447. scope.$broadcast('$mdContentLoaded', element);
  5448. iosScrollFix(element[0]);
  5449. }
  5450. };
  5451. function ContentController($scope, $element) {
  5452. this.$scope = $scope;
  5453. this.$element = $element;
  5454. }
  5455. }
  5456. mdContentDirective.$inject = ["$mdTheming"];
  5457. function iosScrollFix(node) {
  5458. // IOS FIX:
  5459. // If we scroll where there is no more room for the webview to scroll,
  5460. // by default the webview itself will scroll up and down, this looks really
  5461. // bad. So if we are scrolling to the very top or bottom, add/subtract one
  5462. angular.element(node).on('$md.pressdown', function(ev) {
  5463. // Only touch events
  5464. if (ev.pointer.type !== 't') return;
  5465. // Don't let a child content's touchstart ruin it for us.
  5466. if (ev.$materialScrollFixed) return;
  5467. ev.$materialScrollFixed = true;
  5468. if (node.scrollTop === 0) {
  5469. node.scrollTop = 1;
  5470. } else if (node.scrollHeight === node.scrollTop + node.offsetHeight) {
  5471. node.scrollTop -= 1;
  5472. }
  5473. });
  5474. }
  5475. })();
  5476. (function(){
  5477. "use strict";
  5478. /**
  5479. * @ngdoc module
  5480. * @name material.components.dialog
  5481. */
  5482. angular
  5483. .module('material.components.dialog', [
  5484. 'material.core',
  5485. 'material.components.backdrop'
  5486. ])
  5487. .directive('mdDialog', MdDialogDirective)
  5488. .provider('$mdDialog', MdDialogProvider);
  5489. function MdDialogDirective($$rAF, $mdTheming, $mdDialog) {
  5490. return {
  5491. restrict: 'E',
  5492. link: function(scope, element, attr) {
  5493. $mdTheming(element);
  5494. $$rAF(function() {
  5495. var images;
  5496. var content = element[0].querySelector('md-dialog-content');
  5497. if (content) {
  5498. images = content.getElementsByTagName('img');
  5499. addOverflowClass();
  5500. //-- delayed image loading may impact scroll height, check after images are loaded
  5501. angular.element(images).on('load', addOverflowClass);
  5502. }
  5503. scope.$on('$destroy', function() {
  5504. $mdDialog.destroy();
  5505. });
  5506. /**
  5507. *
  5508. */
  5509. function addOverflowClass() {
  5510. element.toggleClass('md-content-overflow', content.scrollHeight > content.clientHeight);
  5511. }
  5512. });
  5513. }
  5514. };
  5515. }
  5516. MdDialogDirective.$inject = ["$$rAF", "$mdTheming", "$mdDialog"];
  5517. /**
  5518. * @ngdoc service
  5519. * @name $mdDialog
  5520. * @module material.components.dialog
  5521. *
  5522. * @description
  5523. * `$mdDialog` opens a dialog over the app to inform users about critical information or require
  5524. * them to make decisions. There are two approaches for setup: a simple promise API
  5525. * and regular object syntax.
  5526. *
  5527. * ## Restrictions
  5528. *
  5529. * - The dialog is always given an isolate scope.
  5530. * - The dialog's template must have an outer `<md-dialog>` element.
  5531. * Inside, use an `<md-dialog-content>` element for the dialog's content, and use
  5532. * an element with class `md-actions` for the dialog's actions.
  5533. * - Dialogs must cover the entire application to keep interactions inside of them.
  5534. * Use the `parent` option to change where dialogs are appended.
  5535. *
  5536. * ## Sizing
  5537. * - Complex dialogs can be sized with `flex="percentage"`, i.e. `flex="66"`.
  5538. * - Default max-width is 80% of the `rootElement` or `parent`.
  5539. *
  5540. * ## Css
  5541. * - `.md-dialog-content` - class that sets the padding on the content as the spec file
  5542. *
  5543. * @usage
  5544. * <hljs lang="html">
  5545. * <div ng-app="demoApp" ng-controller="EmployeeController">
  5546. * <div>
  5547. * <md-button ng-click="showAlert()" class="md-raised md-warn">
  5548. * Employee Alert!
  5549. * </md-button>
  5550. * </div>
  5551. * <div>
  5552. * <md-button ng-click="showDialog($event)" class="md-raised">
  5553. * Custom Dialog
  5554. * </md-button>
  5555. * </div>
  5556. * <div>
  5557. * <md-button ng-click="closeAlert()" ng-disabled="!hasAlert()" class="md-raised">
  5558. * Close Alert
  5559. * </md-button>
  5560. * </div>
  5561. * <div>
  5562. * <md-button ng-click="showGreeting($event)" class="md-raised md-primary" >
  5563. * Greet Employee
  5564. * </md-button>
  5565. * </div>
  5566. * </div>
  5567. * </hljs>
  5568. *
  5569. * ### JavaScript: object syntax
  5570. * <hljs lang="js">
  5571. * (function(angular, undefined){
  5572. * "use strict";
  5573. *
  5574. * angular
  5575. * .module('demoApp', ['ngMaterial'])
  5576. * .controller('AppCtrl', AppController);
  5577. *
  5578. * function AppController($scope, $mdDialog) {
  5579. * var alert;
  5580. * $scope.showAlert = showAlert;
  5581. * $scope.showDialog = showDialog;
  5582. * $scope.items = [1, 2, 3];
  5583. *
  5584. * // Internal method
  5585. * function showAlert() {
  5586. * alert = $mdDialog.alert({
  5587. * title: 'Attention',
  5588. * content: 'This is an example of how easy dialogs can be!',
  5589. * ok: 'Close'
  5590. * });
  5591. *
  5592. * $mdDialog
  5593. * .show( alert )
  5594. * .finally(function() {
  5595. * alert = undefined;
  5596. * });
  5597. * }
  5598. *
  5599. * function showDialog($event) {
  5600. * var parentEl = angular.element(document.body);
  5601. * $mdDialog.show({
  5602. * parent: parentEl,
  5603. * targetEvent: $event,
  5604. * template:
  5605. * '<md-dialog aria-label="List dialog">' +
  5606. * ' <md-dialog-content>'+
  5607. * ' <md-list>'+
  5608. * ' <md-list-item ng-repeat="item in items">'+
  5609. * ' <p>Number {{item}}</p>' +
  5610. * ' </md-item>'+
  5611. * ' </md-list>'+
  5612. * ' </md-dialog-content>' +
  5613. * ' <div class="md-actions">' +
  5614. * ' <md-button ng-click="closeDialog()" class="md-primary">' +
  5615. * ' Close Dialog' +
  5616. * ' </md-button>' +
  5617. * ' </div>' +
  5618. * '</md-dialog>',
  5619. * locals: {
  5620. * items: $scope.items
  5621. * },
  5622. * controller: DialogController
  5623. * });
  5624. * function DialogController($scope, $mdDialog, items) {
  5625. * $scope.items = items;
  5626. * $scope.closeDialog = function() {
  5627. * $mdDialog.hide();
  5628. * }
  5629. * }
  5630. * }
  5631. * }
  5632. * })(angular);
  5633. * </hljs>
  5634. *
  5635. * ### JavaScript: promise API syntax, custom dialog template
  5636. * <hljs lang="js">
  5637. * (function(angular, undefined){
  5638. * "use strict";
  5639. *
  5640. * angular
  5641. * .module('demoApp', ['ngMaterial'])
  5642. * .controller('EmployeeController', EmployeeEditor)
  5643. * .controller('GreetingController', GreetingController);
  5644. *
  5645. * // Fictitious Employee Editor to show how to use simple and complex dialogs.
  5646. *
  5647. * function EmployeeEditor($scope, $mdDialog) {
  5648. * var alert;
  5649. *
  5650. * $scope.showAlert = showAlert;
  5651. * $scope.closeAlert = closeAlert;
  5652. * $scope.showGreeting = showCustomGreeting;
  5653. *
  5654. * $scope.hasAlert = function() { return !!alert };
  5655. * $scope.userName = $scope.userName || 'Bobby';
  5656. *
  5657. * // Dialog #1 - Show simple alert dialog and cache
  5658. * // reference to dialog instance
  5659. *
  5660. * function showAlert() {
  5661. * alert = $mdDialog.alert()
  5662. * .title('Attention, ' + $scope.userName)
  5663. * .content('This is an example of how easy dialogs can be!')
  5664. * .ok('Close');
  5665. *
  5666. * $mdDialog
  5667. * .show( alert )
  5668. * .finally(function() {
  5669. * alert = undefined;
  5670. * });
  5671. * }
  5672. *
  5673. * // Close the specified dialog instance and resolve with 'finished' flag
  5674. * // Normally this is not needed, just use '$mdDialog.hide()' to close
  5675. * // the most recent dialog popup.
  5676. *
  5677. * function closeAlert() {
  5678. * $mdDialog.hide( alert, "finished" );
  5679. * alert = undefined;
  5680. * }
  5681. *
  5682. * // Dialog #2 - Demonstrate more complex dialogs construction and popup.
  5683. *
  5684. * function showCustomGreeting($event) {
  5685. * $mdDialog.show({
  5686. * targetEvent: $event,
  5687. * template:
  5688. * '<md-dialog>' +
  5689. *
  5690. * ' <md-dialog-content>Hello {{ employee }}!</md-dialog-content>' +
  5691. *
  5692. * ' <div class="md-actions">' +
  5693. * ' <md-button ng-click="closeDialog()" class="md-primary">' +
  5694. * ' Close Greeting' +
  5695. * ' </md-button>' +
  5696. * ' </div>' +
  5697. * '</md-dialog>',
  5698. * controller: 'GreetingController',
  5699. * onComplete: afterShowAnimation,
  5700. * locals: { employee: $scope.userName }
  5701. * });
  5702. *
  5703. * // When the 'enter' animation finishes...
  5704. *
  5705. * function afterShowAnimation(scope, element, options) {
  5706. * // post-show code here: DOM element focus, etc.
  5707. * }
  5708. * }
  5709. *
  5710. * // Dialog #3 - Demonstrate use of ControllerAs and passing $scope to dialog
  5711. * // Here we used ng-controller="GreetingController as vm" and
  5712. * // $scope.vm === <controller instance>
  5713. *
  5714. * function showCustomGreeting() {
  5715. *
  5716. * $mdDialog.show({
  5717. * clickOutsideToClose: true,
  5718. *
  5719. * scope: $scope, // use parent scope in template
  5720. * preserveScope: true, // do not forget this if use parent scope
  5721. * // Since GreetingController is instantiated with ControllerAs syntax
  5722. * // AND we are passing the parent '$scope' to the dialog, we MUST
  5723. * // use 'vm.<xxx>' in the template markup
  5724. *
  5725. * template: '<md-dialog>' +
  5726. * ' <md-dialog-content>' +
  5727. * ' Hi There {{vm.employee}}' +
  5728. * ' </md-dialog-content>' +
  5729. * '</md-dialog>',
  5730. *
  5731. * controller: function DialogController($scope, $mdDialog) {
  5732. * $scope.closeDialog = function() {
  5733. * $mdDialog.hide();
  5734. * }
  5735. * }
  5736. * });
  5737. * }
  5738. *
  5739. * }
  5740. *
  5741. * // Greeting controller used with the more complex 'showCustomGreeting()' custom dialog
  5742. *
  5743. * function GreetingController($scope, $mdDialog, employee) {
  5744. * // Assigned from construction <code>locals</code> options...
  5745. * $scope.employee = employee;
  5746. *
  5747. * $scope.closeDialog = function() {
  5748. * // Easily hides most recent dialog shown...
  5749. * // no specific instance reference is needed.
  5750. * $mdDialog.hide();
  5751. * };
  5752. * }
  5753. *
  5754. * })(angular);
  5755. * </hljs>
  5756. */
  5757. /**
  5758. * @ngdoc method
  5759. * @name $mdDialog#alert
  5760. *
  5761. * @description
  5762. * Builds a preconfigured dialog with the specified message.
  5763. *
  5764. * @returns {obj} an `$mdDialogPreset` with the chainable configuration methods:
  5765. *
  5766. * - $mdDialogPreset#title(string) - sets title to string
  5767. * - $mdDialogPreset#content(string) - sets content / message to string
  5768. * - $mdDialogPreset#ok(string) - sets okay button text to string
  5769. * - $mdDialogPreset#theme(string) - sets the theme of the dialog
  5770. *
  5771. */
  5772. /**
  5773. * @ngdoc method
  5774. * @name $mdDialog#confirm
  5775. *
  5776. * @description
  5777. * Builds a preconfigured dialog with the specified message. You can call show and the promise returned
  5778. * will be resolved only if the user clicks the confirm action on the dialog.
  5779. *
  5780. * @returns {obj} an `$mdDialogPreset` with the chainable configuration methods:
  5781. *
  5782. * Additionally, it supports the following methods:
  5783. *
  5784. * - $mdDialogPreset#title(string) - sets title to string
  5785. * - $mdDialogPreset#content(string) - sets content / message to string
  5786. * - $mdDialogPreset#ok(string) - sets okay button text to string
  5787. * - $mdDialogPreset#cancel(string) - sets cancel button text to string
  5788. * - $mdDialogPreset#theme(string) - sets the theme of the dialog
  5789. *
  5790. */
  5791. /**
  5792. * @ngdoc method
  5793. * @name $mdDialog#show
  5794. *
  5795. * @description
  5796. * Show a dialog with the specified options.
  5797. *
  5798. * @param {object} optionsOrPreset Either provide an `$mdDialogPreset` returned from `alert()`, and
  5799. * `confirm()`, or an options object with the following properties:
  5800. * - `templateUrl` - `{string=}`: The url of a template that will be used as the content
  5801. * of the dialog.
  5802. * - `template` - `{string=}`: Same as templateUrl, except this is an actual template string.
  5803. * - `targetEvent` - `{DOMClickEvent=}`: A click's event object. When passed in as an option,
  5804. * the location of the click will be used as the starting point for the opening animation
  5805. * of the the dialog.
  5806. * - `scope` - `{object=}`: the scope to link the template / controller to. If none is specified,
  5807. * it will create a new isolate scope.
  5808. * This scope will be destroyed when the dialog is removed unless `preserveScope` is set to true.
  5809. * - `preserveScope` - `{boolean=}`: whether to preserve the scope when the element is removed. Default is false
  5810. * - `disableParentScroll` - `{boolean=}`: Whether to disable scrolling while the dialog is open.
  5811. * Default true.
  5812. * - `hasBackdrop` - `{boolean=}`: Whether there should be an opaque backdrop behind the dialog.
  5813. * Default true.
  5814. * - `clickOutsideToClose` - `{boolean=}`: Whether the user can click outside the dialog to
  5815. * close it. Default false.
  5816. * - `escapeToClose` - `{boolean=}`: Whether the user can press escape to close the dialog.
  5817. * Default true.
  5818. * - `focusOnOpen` - `{boolean=}`: An option to override focus behavior on open. Only disable if
  5819. * focusing some other way, as focus management is required for dialogs to be accessible.
  5820. * Defaults to true.
  5821. * - `controller` - `{string=}`: The controller to associate with the dialog. The controller
  5822. * will be injected with the local `$mdDialog`, which passes along a scope for the dialog.
  5823. * - `locals` - `{object=}`: An object containing key/value pairs. The keys will be used as names
  5824. * of values to inject into the controller. For example, `locals: {three: 3}` would inject
  5825. * `three` into the controller, with the value 3. If `bindToController` is true, they will be
  5826. * copied to the controller instead.
  5827. * - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in.
  5828. * These values will not be available until after initialization.
  5829. * - `resolve` - `{object=}`: Similar to locals, except it takes promises as values, and the
  5830. * dialog will not open until all of the promises resolve.
  5831. * - `controllerAs` - `{string=}`: An alias to assign the controller to on the scope.
  5832. * - `parent` - `{element=}`: The element to append the dialog to. Defaults to appending
  5833. * to the root element of the application.
  5834. * - `onShowing` `{function=} Callback function used to announce the show() action is
  5835. * starting.
  5836. * - `onComplete` `{function=}`: Callback function used to announce when the show() action is
  5837. * finished.
  5838. * - `onRemoving` `{function=} Callback function used to announce the close/hide() action is
  5839. * starting. This allows developers to run custom animations in parallel the close animations.
  5840. *
  5841. * @returns {promise} A promise that can be resolved with `$mdDialog.hide()` or
  5842. * rejected with `$mdDialog.cancel()`.
  5843. */
  5844. /**
  5845. * @ngdoc method
  5846. * @name $mdDialog#hide
  5847. *
  5848. * @description
  5849. * Hide an existing dialog and resolve the promise returned from `$mdDialog.show()`.
  5850. *
  5851. * @param {*=} response An argument for the resolved promise.
  5852. *
  5853. * @returns {promise} A promise that is resolved when the dialog has been closed.
  5854. */
  5855. /**
  5856. * @ngdoc method
  5857. * @name $mdDialog#cancel
  5858. *
  5859. * @description
  5860. * Hide an existing dialog and reject the promise returned from `$mdDialog.show()`.
  5861. *
  5862. * @param {*=} response An argument for the rejected promise.
  5863. *
  5864. * @returns {promise} A promise that is resolved when the dialog has been closed.
  5865. */
  5866. function MdDialogProvider($$interimElementProvider) {
  5867. advancedDialogOptions.$inject = ["$mdDialog", "$mdTheming"];
  5868. dialogDefaultOptions.$inject = ["$mdDialog", "$mdAria", "$mdUtil", "$mdConstant", "$animate", "$document", "$window", "$rootElement"];
  5869. return $$interimElementProvider('$mdDialog')
  5870. .setDefaults({
  5871. methods: ['disableParentScroll', 'hasBackdrop', 'clickOutsideToClose', 'escapeToClose', 'targetEvent', 'parent'],
  5872. options: dialogDefaultOptions
  5873. })
  5874. .addPreset('alert', {
  5875. methods: ['title', 'content', 'ariaLabel', 'ok', 'theme', 'css'],
  5876. options: advancedDialogOptions
  5877. })
  5878. .addPreset('confirm', {
  5879. methods: ['title', 'content', 'ariaLabel', 'ok', 'cancel', 'theme', 'css'],
  5880. options: advancedDialogOptions
  5881. });
  5882. /* @ngInject */
  5883. function advancedDialogOptions($mdDialog, $mdTheming) {
  5884. return {
  5885. template: [
  5886. '<md-dialog md-theme="{{ dialog.theme }}" aria-label="{{ dialog.ariaLabel }}" ng-class="dialog.css">',
  5887. ' <md-dialog-content class="md-dialog-content" role="document" tabIndex="-1">',
  5888. ' <h2 class="md-title">{{ dialog.title }}</h2>',
  5889. ' <div class="md-dialog-content-body" md-template="::dialog.mdContent"></div>',
  5890. ' </md-dialog-content>',
  5891. ' <div class="md-actions">',
  5892. ' <md-button ng-if="dialog.$type == \'confirm\'"' +
  5893. ' ng-click="dialog.abort()" class="md-primary">',
  5894. ' {{ dialog.cancel }}',
  5895. ' </md-button>',
  5896. ' <md-button ng-click="dialog.hide()" class="md-primary" md-autofocus="dialog.$type!=\'confirm\'">',
  5897. ' {{ dialog.ok }}',
  5898. ' </md-button>',
  5899. ' </div>',
  5900. '</md-dialog>'
  5901. ].join('').replace(/\s\s+/g, ''),
  5902. controller: function mdDialogCtrl() {
  5903. this.hide = function() {
  5904. $mdDialog.hide(true);
  5905. };
  5906. this.abort = function() {
  5907. $mdDialog.cancel();
  5908. };
  5909. },
  5910. controllerAs: 'dialog',
  5911. bindToController: true,
  5912. theme: $mdTheming.defaultTheme()
  5913. };
  5914. }
  5915. /* @ngInject */
  5916. function dialogDefaultOptions($mdDialog, $mdAria, $mdUtil, $mdConstant, $animate, $document, $window, $rootElement) {
  5917. return {
  5918. hasBackdrop: true,
  5919. isolateScope: true,
  5920. onShow: onShow,
  5921. onRemove: onRemove,
  5922. clickOutsideToClose: false,
  5923. escapeToClose: true,
  5924. targetEvent: null,
  5925. focusOnOpen: true,
  5926. disableParentScroll: true,
  5927. transformTemplate: function(template) {
  5928. return '<div class="md-dialog-container">' + validatedTemplate(template) + '</div>';
  5929. /**
  5930. * The specified template should contain a <md-dialog> wrapper element....
  5931. */
  5932. function validatedTemplate(template) {
  5933. template || ""
  5934. return /<\/md-dialog>/g.test(template) ? template : "<md-dialog>" + template + "</md-dialog>";
  5935. }
  5936. }
  5937. };
  5938. /**
  5939. * Show method for dialogs
  5940. */
  5941. function onShow(scope, element, options, controller) {
  5942. angular.element($document[0].body).addClass('md-dialog-is-showing');
  5943. wrapSimpleContent();
  5944. captureSourceAndParent(element, options);
  5945. configureAria(element.find('md-dialog'), options);
  5946. showBackdrop(scope, element, options);
  5947. return dialogPopIn(element, options)
  5948. .then(function() {
  5949. activateListeners(element, options);
  5950. lockScreenReader(element, options);
  5951. focusOnOpen();
  5952. });
  5953. /**
  5954. * For alerts, focus on content... otherwise focus on
  5955. * the close button (or equivalent)
  5956. */
  5957. function focusOnOpen() {
  5958. if (options.focusOnOpen) {
  5959. var target = $mdUtil.findFocusTarget(element) || findCloseButton();
  5960. target.focus();
  5961. }
  5962. /**
  5963. * If no element with class dialog-close, try to find the last
  5964. * button child in md-actions and assume it is a close button
  5965. */
  5966. function findCloseButton() {
  5967. var closeButton = element[0].querySelector('.dialog-close');
  5968. if (!closeButton) {
  5969. var actionButtons = element[0].querySelectorAll('.md-actions button');
  5970. closeButton = actionButtons[actionButtons.length - 1];
  5971. }
  5972. return angular.element(closeButton);
  5973. }
  5974. }
  5975. /**
  5976. * Wrap any simple content [specified via .content("")] in <p></p> tags.
  5977. * otherwise accept HTML content within the dialog content area...
  5978. * NOTE: Dialog uses the md-template directive to safely inject HTML content.
  5979. */
  5980. function wrapSimpleContent() {
  5981. if ( controller ) {
  5982. var HTML_END_TAG = /<\/[\w-]*>/gm;
  5983. var content = controller.content || options.content || "";
  5984. var hasHTML = HTML_END_TAG.test(content);
  5985. if (!hasHTML) {
  5986. content = $mdUtil.supplant("<p>{0}</p>", [content]);
  5987. }
  5988. // Publish updated dialog content body... to be compiled by mdTemplate directive
  5989. controller.mdContent = content;
  5990. }
  5991. }
  5992. }
  5993. /**
  5994. * Remove function for all dialogs
  5995. */
  5996. function onRemove(scope, element, options) {
  5997. options.deactivateListeners();
  5998. options.unlockScreenReader();
  5999. options.hideBackdrop(options.$destroy);
  6000. // For navigation $destroy events, do a quick, non-animated removal,
  6001. // but for normal closes (from clicks, etc) animate the removal
  6002. return !!options.$destroy ? detachAndClean() : animateRemoval().then( detachAndClean );
  6003. /**
  6004. * For normal closes, animate the removal.
  6005. * For forced closes (like $destroy events), skip the animations
  6006. */
  6007. function animateRemoval() {
  6008. return dialogPopOut(element, options);
  6009. }
  6010. /**
  6011. * Detach the element
  6012. */
  6013. function detachAndClean() {
  6014. angular.element($document[0].body).removeClass('md-dialog-is-showing');
  6015. element.remove();
  6016. if (!options.$destroy) options.origin.focus();
  6017. }
  6018. }
  6019. /**
  6020. * Capture originator/trigger element information (if available)
  6021. * and the parent container for the dialog; defaults to the $rootElement
  6022. * unless overridden in the options.parent
  6023. */
  6024. function captureSourceAndParent(element, options) {
  6025. options.origin = angular.extend({
  6026. element: null,
  6027. bounds: null,
  6028. focus: angular.noop
  6029. }, options.origin || {});
  6030. var source = angular.element((options.targetEvent || {}).target);
  6031. if (source && source.length) {
  6032. // Compute and save the target element's bounding rect, so that if the
  6033. // element is hidden when the dialog closes, we can shrink the dialog
  6034. // back to the same position it expanded from.
  6035. options.origin.element = source;
  6036. options.origin.bounds = source[0].getBoundingClientRect();
  6037. options.origin.focus = function() {
  6038. source.focus();
  6039. }
  6040. }
  6041. // If the parent specifier is a simple string selector, then query for
  6042. // the DOM element.
  6043. if ( angular.isString(options.parent) ) {
  6044. var simpleSelector = options.parent,
  6045. container = $document[0].querySelectorAll(simpleSelector);
  6046. options.parent = container.length ? container[0] : null;
  6047. }
  6048. // If we have a reference to a raw dom element, always wrap it in jqLite
  6049. options.parent = angular.element(options.parent || $rootElement);
  6050. }
  6051. /**
  6052. * Listen for escape keys and outside clicks to auto close
  6053. */
  6054. function activateListeners(element, options) {
  6055. var window = angular.element($window);
  6056. var onWindowResize = $mdUtil.debounce(function(){
  6057. stretchDialogContainerToViewport(element, options);
  6058. }, 60);
  6059. var removeListeners = [];
  6060. var smartClose = function() {
  6061. // Only 'confirm' dialogs have a cancel button... escape/clickOutside will
  6062. // cancel or fallback to hide.
  6063. var closeFn = ( options.$type == 'alert' ) ? $mdDialog.hide : $mdDialog.cancel;
  6064. $mdUtil.nextTick(closeFn, true);
  6065. };
  6066. if (options.escapeToClose) {
  6067. var target = options.parent;
  6068. var keyHandlerFn = function(ev) {
  6069. if (ev.keyCode === $mdConstant.KEY_CODE.ESCAPE) {
  6070. ev.stopPropagation();
  6071. ev.preventDefault();
  6072. smartClose();
  6073. }
  6074. };
  6075. // Add keydown listeners
  6076. element.on('keydown', keyHandlerFn);
  6077. target.on('keydown', keyHandlerFn);
  6078. window.on('resize', onWindowResize);
  6079. // Queue remove listeners function
  6080. removeListeners.push(function() {
  6081. element.off('keydown', keyHandlerFn);
  6082. target.off('keydown', keyHandlerFn);
  6083. window.off('resize', onWindowResize);
  6084. });
  6085. }
  6086. if (options.clickOutsideToClose) {
  6087. var target = element;
  6088. var sourceElem;
  6089. // Keep track of the element on which the mouse originally went down
  6090. // so that we can only close the backdrop when the 'click' started on it.
  6091. // A simple 'click' handler does not work,
  6092. // it sets the target object as the element the mouse went down on.
  6093. var mousedownHandler = function(ev) {
  6094. sourceElem = ev.target;
  6095. };
  6096. // We check if our original element and the target is the backdrop
  6097. // because if the original was the backdrop and the target was inside the dialog
  6098. // we don't want to dialog to close.
  6099. var mouseupHandler = function(ev) {
  6100. if (sourceElem === target[0] && ev.target === target[0]) {
  6101. ev.stopPropagation();
  6102. ev.preventDefault();
  6103. smartClose();
  6104. }
  6105. };
  6106. // Add listeners
  6107. target.on('mousedown', mousedownHandler);
  6108. target.on('mouseup', mouseupHandler);
  6109. // Queue remove listeners function
  6110. removeListeners.push(function() {
  6111. target.off('mousedown', mousedownHandler);
  6112. target.off('mouseup', mouseupHandler);
  6113. });
  6114. }
  6115. // Attach specific `remove` listener handler
  6116. options.deactivateListeners = function() {
  6117. removeListeners.forEach(function(removeFn) {
  6118. removeFn();
  6119. });
  6120. options.deactivateListeners = null;
  6121. };
  6122. }
  6123. /**
  6124. * Show modal backdrop element...
  6125. */
  6126. function showBackdrop(scope, element, options) {
  6127. if (options.disableParentScroll) {
  6128. // !! DO this before creating the backdrop; since disableScrollAround()
  6129. // configures the scroll offset; which is used by mdBackDrop postLink()
  6130. options.restoreScroll = $mdUtil.disableScrollAround(element, options.parent);
  6131. }
  6132. if (options.hasBackdrop) {
  6133. options.backdrop = $mdUtil.createBackdrop(scope, "md-dialog-backdrop md-opaque");
  6134. $animate.enter(options.backdrop, options.parent);
  6135. }
  6136. /**
  6137. * Hide modal backdrop element...
  6138. */
  6139. options.hideBackdrop = function hideBackdrop($destroy) {
  6140. if (options.backdrop) {
  6141. if ( !!$destroy ) options.backdrop.remove();
  6142. else $animate.leave(options.backdrop);
  6143. }
  6144. if (options.disableParentScroll) {
  6145. options.restoreScroll();
  6146. delete options.restoreScroll;
  6147. }
  6148. options.hideBackdrop = null;
  6149. }
  6150. }
  6151. /**
  6152. * Inject ARIA-specific attributes appropriate for Dialogs
  6153. */
  6154. function configureAria(element, options) {
  6155. var role = (options.$type === 'alert') ? 'alertdialog' : 'dialog';
  6156. var dialogContent = element.find('md-dialog-content');
  6157. var dialogId = element.attr('id') || ('dialog_' + $mdUtil.nextUid());
  6158. element.attr({
  6159. 'role': role,
  6160. 'tabIndex': '-1'
  6161. });
  6162. if (dialogContent.length === 0) {
  6163. dialogContent = element;
  6164. }
  6165. dialogContent.attr('id', dialogId);
  6166. element.attr('aria-describedby', dialogId);
  6167. if (options.ariaLabel) {
  6168. $mdAria.expect(element, 'aria-label', options.ariaLabel);
  6169. }
  6170. else {
  6171. $mdAria.expectAsync(element, 'aria-label', function() {
  6172. var words = dialogContent.text().split(/\s+/);
  6173. if (words.length > 3) words = words.slice(0, 3).concat('...');
  6174. return words.join(' ');
  6175. });
  6176. }
  6177. }
  6178. /**
  6179. * Prevents screen reader interaction behind modal window
  6180. * on swipe interfaces
  6181. */
  6182. function lockScreenReader(element, options) {
  6183. var isHidden = true;
  6184. // get raw DOM node
  6185. walkDOM(element[0]);
  6186. options.unlockScreenReader = function() {
  6187. isHidden = false;
  6188. walkDOM(element[0]);
  6189. options.unlockScreenReader = null;
  6190. };
  6191. /**
  6192. * Walk DOM to apply or remove aria-hidden on sibling nodes
  6193. * and parent sibling nodes
  6194. *
  6195. */
  6196. function walkDOM(element) {
  6197. while (element.parentNode) {
  6198. if (element === document.body) {
  6199. return;
  6200. }
  6201. var children = element.parentNode.children;
  6202. for (var i = 0; i < children.length; i++) {
  6203. // skip over child if it is an ascendant of the dialog
  6204. // or a script or style tag
  6205. if (element !== children[i] && !isNodeOneOf(children[i], ['SCRIPT', 'STYLE'])) {
  6206. children[i].setAttribute('aria-hidden', isHidden);
  6207. }
  6208. }
  6209. walkDOM(element = element.parentNode);
  6210. }
  6211. }
  6212. }
  6213. /**
  6214. * Ensure the dialog container fill-stretches to the viewport
  6215. */
  6216. function stretchDialogContainerToViewport(container, options) {
  6217. var isFixed = $window.getComputedStyle($document[0].body).position == 'fixed';
  6218. var backdrop = options.backdrop ? $window.getComputedStyle(options.backdrop[0]) : null;
  6219. var height = backdrop ? Math.min($document[0].body.clientHeight, Math.ceil(Math.abs(parseInt(backdrop.height, 10)))) : 0;
  6220. container.css({
  6221. top: (isFixed ? $mdUtil.scrollTop(options.parent) : 0) + 'px',
  6222. height: height ? height + 'px' : '100%'
  6223. });
  6224. return container;
  6225. }
  6226. /**
  6227. * Dialog open and pop-in animation
  6228. */
  6229. function dialogPopIn(container, options) {
  6230. // Add the `md-dialog-container` to the DOM
  6231. options.parent.append(container);
  6232. stretchDialogContainerToViewport(container, options);
  6233. var dialogEl = container.find('md-dialog');
  6234. var animator = $mdUtil.dom.animator;
  6235. var buildTranslateToOrigin = animator.calculateZoomToOrigin;
  6236. var translateOptions = {transitionInClass: 'md-transition-in', transitionOutClass: 'md-transition-out'};
  6237. var from = animator.toTransformCss(buildTranslateToOrigin(dialogEl, options.origin));
  6238. var to = animator.toTransformCss(""); // defaults to center display (or parent or $rootElement)
  6239. return animator
  6240. .translate3d(dialogEl, from, to, translateOptions)
  6241. .then(function(animateReversal) {
  6242. // Build a reversal translate function synched to this translation...
  6243. options.reverseAnimate = function() {
  6244. delete options.reverseAnimate;
  6245. return animateReversal(
  6246. animator.toTransformCss(
  6247. // in case the origin element has moved or is hidden,
  6248. // let's recalculate the translateCSS
  6249. buildTranslateToOrigin(dialogEl, options.origin)
  6250. )
  6251. );
  6252. };
  6253. return true;
  6254. });
  6255. }
  6256. /**
  6257. * Dialog close and pop-out animation
  6258. */
  6259. function dialogPopOut(container, options) {
  6260. return options.reverseAnimate();
  6261. }
  6262. /**
  6263. * Utility function to filter out raw DOM nodes
  6264. */
  6265. function isNodeOneOf(elem, nodeTypeArray) {
  6266. if (nodeTypeArray.indexOf(elem.nodeName) !== -1) {
  6267. return true;
  6268. }
  6269. }
  6270. }
  6271. }
  6272. MdDialogProvider.$inject = ["$$interimElementProvider"];
  6273. })();
  6274. (function(){
  6275. "use strict";
  6276. /**
  6277. * @ngdoc module
  6278. * @name material.components.divider
  6279. * @description Divider module!
  6280. */
  6281. angular.module('material.components.divider', [
  6282. 'material.core'
  6283. ])
  6284. .directive('mdDivider', MdDividerDirective);
  6285. /**
  6286. * @ngdoc directive
  6287. * @name mdDivider
  6288. * @module material.components.divider
  6289. * @restrict E
  6290. *
  6291. * @description
  6292. * 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.
  6293. *
  6294. * @param {boolean=} md-inset Add this attribute to activate the inset divider style.
  6295. * @usage
  6296. * <hljs lang="html">
  6297. * <md-divider></md-divider>
  6298. *
  6299. * <md-divider md-inset></md-divider>
  6300. * </hljs>
  6301. *
  6302. */
  6303. function MdDividerDirective($mdTheming) {
  6304. return {
  6305. restrict: 'E',
  6306. link: $mdTheming
  6307. };
  6308. }
  6309. MdDividerDirective.$inject = ["$mdTheming"];
  6310. })();
  6311. (function(){
  6312. "use strict";
  6313. (function() {
  6314. 'use strict';
  6315. /**
  6316. * @ngdoc module
  6317. * @name material.components.datepicker
  6318. * @description Datepicker
  6319. */
  6320. angular.module('material.components.datepicker', [
  6321. 'material.core',
  6322. 'material.components.icon',
  6323. 'material.components.virtualRepeat'
  6324. ]).directive('mdCalendar', calendarDirective);
  6325. // POST RELEASE
  6326. // TODO(jelbourn): Mac Cmd + left / right == Home / End
  6327. // TODO(jelbourn): Clicking on the month label opens the month-picker.
  6328. // TODO(jelbourn): Minimum and maximum date
  6329. // TODO(jelbourn): Refactor month element creation to use cloneNode (performance).
  6330. // TODO(jelbourn): Define virtual scrolling constants (compactness) users can override.
  6331. // TODO(jelbourn): Animated month transition on ng-model change (virtual-repeat)
  6332. // TODO(jelbourn): Scroll snapping (virtual repeat)
  6333. // TODO(jelbourn): Remove superfluous row from short months (virtual-repeat)
  6334. // TODO(jelbourn): Month headers stick to top when scrolling.
  6335. // TODO(jelbourn): Previous month opacity is lowered when partially scrolled out of view.
  6336. // TODO(jelbourn): Support md-calendar standalone on a page (as a tabstop w/ aria-live
  6337. // announcement and key handling).
  6338. // Read-only calendar (not just date-picker).
  6339. /**
  6340. * Height of one calendar month tbody. This must be made known to the virtual-repeat and is
  6341. * subsequently used for scrolling to specific months.
  6342. */
  6343. var TBODY_HEIGHT = 265;
  6344. /**
  6345. * Height of a calendar month with a single row. This is needed to calculate the offset for
  6346. * rendering an extra month in virtual-repeat that only contains one row.
  6347. */
  6348. var TBODY_SINGLE_ROW_HEIGHT = 45;
  6349. function calendarDirective() {
  6350. return {
  6351. template:
  6352. '<table aria-hidden="true" class="md-calendar-day-header"><thead></thead></table>' +
  6353. '<div class="md-calendar-scroll-mask">' +
  6354. '<md-virtual-repeat-container class="md-calendar-scroll-container" ' +
  6355. 'md-offset-size="' + (TBODY_SINGLE_ROW_HEIGHT - TBODY_HEIGHT) + '">' +
  6356. '<table role="grid" tabindex="0" class="md-calendar" aria-readonly="true">' +
  6357. '<tbody role="rowgroup" md-virtual-repeat="i in ctrl.items" md-calendar-month ' +
  6358. 'md-month-offset="$index" class="md-calendar-month" ' +
  6359. 'md-start-index="ctrl.getSelectedMonthIndex()" ' +
  6360. 'md-item-size="' + TBODY_HEIGHT + '"></tbody>' +
  6361. '</table>' +
  6362. '</md-virtual-repeat-container>' +
  6363. '</div>',
  6364. scope: {
  6365. minDate: '=mdMinDate',
  6366. maxDate: '=mdMaxDate',
  6367. },
  6368. require: ['ngModel', 'mdCalendar'],
  6369. controller: CalendarCtrl,
  6370. controllerAs: 'ctrl',
  6371. bindToController: true,
  6372. link: function(scope, element, attrs, controllers) {
  6373. var ngModelCtrl = controllers[0];
  6374. var mdCalendarCtrl = controllers[1];
  6375. mdCalendarCtrl.configureNgModel(ngModelCtrl);
  6376. }
  6377. };
  6378. }
  6379. /** Class applied to the selected date cell/. */
  6380. var SELECTED_DATE_CLASS = 'md-calendar-selected-date';
  6381. /** Class applied to the focused date cell/. */
  6382. var FOCUSED_DATE_CLASS = 'md-focus';
  6383. /** Next identifier for calendar instance. */
  6384. var nextUniqueId = 0;
  6385. /** The first renderable date in the virtual-scrolling calendar (for all instances). */
  6386. var firstRenderableDate = null;
  6387. /**
  6388. * Controller for the mdCalendar component.
  6389. * @ngInject @constructor
  6390. */
  6391. function CalendarCtrl($element, $attrs, $scope, $animate, $q, $mdConstant,
  6392. $mdTheming, $$mdDateUtil, $mdDateLocale, $mdInkRipple, $mdUtil) {
  6393. $mdTheming($element);
  6394. /**
  6395. * Dummy array-like object for virtual-repeat to iterate over. The length is the total
  6396. * number of months that can be viewed. This is shorter than ideal because of (potential)
  6397. * Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=1181658.
  6398. */
  6399. this.items = {length: 2000};
  6400. if (this.maxDate && this.minDate) {
  6401. // Limit the number of months if min and max dates are set.
  6402. var numMonths = $$mdDateUtil.getMonthDistance(this.minDate, this.maxDate) + 1;
  6403. numMonths = Math.max(numMonths, 1);
  6404. // Add an additional month as the final dummy month for rendering purposes.
  6405. numMonths += 1;
  6406. this.items.length = numMonths;
  6407. }
  6408. /** @final {!angular.$animate} */
  6409. this.$animate = $animate;
  6410. /** @final {!angular.$q} */
  6411. this.$q = $q;
  6412. /** @final */
  6413. this.$mdInkRipple = $mdInkRipple;
  6414. /** @final */
  6415. this.$mdUtil = $mdUtil;
  6416. /** @final */
  6417. this.keyCode = $mdConstant.KEY_CODE;
  6418. /** @final */
  6419. this.dateUtil = $$mdDateUtil;
  6420. /** @final */
  6421. this.dateLocale = $mdDateLocale;
  6422. /** @final {!angular.JQLite} */
  6423. this.$element = $element;
  6424. /** @final {!angular.Scope} */
  6425. this.$scope = $scope;
  6426. /** @final {HTMLElement} */
  6427. this.calendarElement = $element[0].querySelector('.md-calendar');
  6428. /** @final {HTMLElement} */
  6429. this.calendarScroller = $element[0].querySelector('.md-virtual-repeat-scroller');
  6430. /** @final {Date} */
  6431. this.today = this.dateUtil.createDateAtMidnight();
  6432. /** @type {Date} */
  6433. this.firstRenderableDate = this.dateUtil.incrementMonths(this.today, -this.items.length / 2);
  6434. if (this.minDate && this.minDate > this.firstRenderableDate) {
  6435. this.firstRenderableDate = this.minDate;
  6436. } else if (this.maxDate) {
  6437. // Calculate the difference between the start date and max date.
  6438. // Subtract 1 because it's an inclusive difference and 1 for the final dummy month.
  6439. //
  6440. var monthDifference = this.items.length - 2;
  6441. this.firstRenderableDate = this.dateUtil.incrementMonths(this.maxDate, -(this.items.length - 2));
  6442. }
  6443. /** @final {number} Unique ID for this calendar instance. */
  6444. this.id = nextUniqueId++;
  6445. /** @type {!angular.NgModelController} */
  6446. this.ngModelCtrl = null;
  6447. /**
  6448. * The selected date. Keep track of this separately from the ng-model value so that we
  6449. * can know, when the ng-model value changes, what the previous value was before its updated
  6450. * in the component's UI.
  6451. *
  6452. * @type {Date}
  6453. */
  6454. this.selectedDate = null;
  6455. /**
  6456. * The date that is currently focused or showing in the calendar. This will initially be set
  6457. * to the ng-model value if set, otherwise to today. It will be updated as the user navigates
  6458. * to other months. The cell corresponding to the displayDate does not necesarily always have
  6459. * focus in the document (such as for cases when the user is scrolling the calendar).
  6460. * @type {Date}
  6461. */
  6462. this.displayDate = null;
  6463. /**
  6464. * The date that has or should have focus.
  6465. * @type {Date}
  6466. */
  6467. this.focusDate = null;
  6468. /** @type {boolean} */
  6469. this.isInitialized = false;
  6470. /** @type {boolean} */
  6471. this.isMonthTransitionInProgress = false;
  6472. // Unless the user specifies so, the calendar should not be a tab stop.
  6473. // This is necessary because ngAria might add a tabindex to anything with an ng-model
  6474. // (based on whether or not the user has turned that particular feature on/off).
  6475. if (!$attrs['tabindex']) {
  6476. $element.attr('tabindex', '-1');
  6477. }
  6478. var self = this;
  6479. /**
  6480. * Handles a click event on a date cell.
  6481. * Created here so that every cell can use the same function instance.
  6482. * @this {HTMLTableCellElement} The cell that was clicked.
  6483. */
  6484. this.cellClickHandler = function() {
  6485. var cellElement = this;
  6486. if (this.hasAttribute('data-timestamp')) {
  6487. $scope.$apply(function() {
  6488. var timestamp = Number(cellElement.getAttribute('data-timestamp'));
  6489. self.setNgModelValue(self.dateUtil.createDateAtMidnight(timestamp));
  6490. });
  6491. }
  6492. };
  6493. this.attachCalendarEventListeners();
  6494. }
  6495. CalendarCtrl.$inject = ["$element", "$attrs", "$scope", "$animate", "$q", "$mdConstant", "$mdTheming", "$$mdDateUtil", "$mdDateLocale", "$mdInkRipple", "$mdUtil"];
  6496. /*** Initialization ***/
  6497. /**
  6498. * Sets up the controller's reference to ngModelController.
  6499. * @param {!angular.NgModelController} ngModelCtrl
  6500. */
  6501. CalendarCtrl.prototype.configureNgModel = function(ngModelCtrl) {
  6502. this.ngModelCtrl = ngModelCtrl;
  6503. var self = this;
  6504. ngModelCtrl.$render = function() {
  6505. self.changeSelectedDate(self.ngModelCtrl.$viewValue);
  6506. };
  6507. };
  6508. /**
  6509. * Initialize the calendar by building the months that are initially visible.
  6510. * Initialization should occur after the ngModel value is known.
  6511. */
  6512. CalendarCtrl.prototype.buildInitialCalendarDisplay = function() {
  6513. this.buildWeekHeader();
  6514. this.hideVerticalScrollbar();
  6515. this.displayDate = this.selectedDate || this.today;
  6516. this.isInitialized = true;
  6517. };
  6518. /**
  6519. * Hides the vertical scrollbar on the calendar scroller by setting the width on the
  6520. * calendar scroller and the `overflow: hidden` wrapper around the scroller, and then setting
  6521. * a padding-right on the scroller equal to the width of the browser's scrollbar.
  6522. *
  6523. * This will cause a reflow.
  6524. */
  6525. CalendarCtrl.prototype.hideVerticalScrollbar = function() {
  6526. var element = this.$element[0];
  6527. var scrollMask = element.querySelector('.md-calendar-scroll-mask');
  6528. var scroller = this.calendarScroller;
  6529. var headerWidth = element.querySelector('.md-calendar-day-header').clientWidth;
  6530. var scrollbarWidth = scroller.offsetWidth - scroller.clientWidth;
  6531. scrollMask.style.width = headerWidth + 'px';
  6532. scroller.style.width = (headerWidth + scrollbarWidth) + 'px';
  6533. scroller.style.paddingRight = scrollbarWidth + 'px';
  6534. };
  6535. /** Attach event listeners for the calendar. */
  6536. CalendarCtrl.prototype.attachCalendarEventListeners = function() {
  6537. // Keyboard interaction.
  6538. this.$element.on('keydown', angular.bind(this, this.handleKeyEvent));
  6539. };
  6540. /*** User input handling ***/
  6541. /**
  6542. * Handles a key event in the calendar with the appropriate action. The action will either
  6543. * be to select the focused date or to navigate to focus a new date.
  6544. * @param {KeyboardEvent} event
  6545. */
  6546. CalendarCtrl.prototype.handleKeyEvent = function(event) {
  6547. var self = this;
  6548. this.$scope.$apply(function() {
  6549. // Capture escape and emit back up so that a wrapping component
  6550. // (such as a date-picker) can decide to close.
  6551. if (event.which == self.keyCode.ESCAPE || event.which == self.keyCode.TAB) {
  6552. self.$scope.$emit('md-calendar-close');
  6553. if (event.which == self.keyCode.TAB) {
  6554. event.preventDefault();
  6555. }
  6556. return;
  6557. }
  6558. // Remaining key events fall into two categories: selection and navigation.
  6559. // Start by checking if this is a selection event.
  6560. if (event.which === self.keyCode.ENTER) {
  6561. self.setNgModelValue(self.displayDate);
  6562. event.preventDefault();
  6563. return;
  6564. }
  6565. // Selection isn't occuring, so the key event is either navigation or nothing.
  6566. var date = self.getFocusDateFromKeyEvent(event);
  6567. if (date) {
  6568. date = self.boundDateByMinAndMax(date);
  6569. event.preventDefault();
  6570. event.stopPropagation();
  6571. // Since this is a keyboard interaction, actually give the newly focused date keyboard
  6572. // focus after the been brought into view.
  6573. self.changeDisplayDate(date).then(function () {
  6574. self.focus(date);
  6575. });
  6576. }
  6577. });
  6578. };
  6579. /**
  6580. * Gets the date to focus as the result of a key event.
  6581. * @param {KeyboardEvent} event
  6582. * @returns {Date} Date to navigate to, or null if the key does not match a calendar shortcut.
  6583. */
  6584. CalendarCtrl.prototype.getFocusDateFromKeyEvent = function(event) {
  6585. var dateUtil = this.dateUtil;
  6586. var keyCode = this.keyCode;
  6587. switch (event.which) {
  6588. case keyCode.RIGHT_ARROW: return dateUtil.incrementDays(this.displayDate, 1);
  6589. case keyCode.LEFT_ARROW: return dateUtil.incrementDays(this.displayDate, -1);
  6590. case keyCode.DOWN_ARROW:
  6591. return event.metaKey ?
  6592. dateUtil.incrementMonths(this.displayDate, 1) :
  6593. dateUtil.incrementDays(this.displayDate, 7);
  6594. case keyCode.UP_ARROW:
  6595. return event.metaKey ?
  6596. dateUtil.incrementMonths(this.displayDate, -1) :
  6597. dateUtil.incrementDays(this.displayDate, -7);
  6598. case keyCode.PAGE_DOWN: return dateUtil.incrementMonths(this.displayDate, 1);
  6599. case keyCode.PAGE_UP: return dateUtil.incrementMonths(this.displayDate, -1);
  6600. case keyCode.HOME: return dateUtil.getFirstDateOfMonth(this.displayDate);
  6601. case keyCode.END: return dateUtil.getLastDateOfMonth(this.displayDate);
  6602. default: return null;
  6603. }
  6604. };
  6605. /**
  6606. * Gets the "index" of the currently selected date as it would be in the virtual-repeat.
  6607. * @returns {number}
  6608. */
  6609. CalendarCtrl.prototype.getSelectedMonthIndex = function() {
  6610. return this.dateUtil.getMonthDistance(this.firstRenderableDate,
  6611. this.selectedDate || this.today);
  6612. };
  6613. /**
  6614. * Scrolls to the month of the given date.
  6615. * @param {Date} date
  6616. */
  6617. CalendarCtrl.prototype.scrollToMonth = function(date) {
  6618. if (!this.dateUtil.isValidDate(date)) {
  6619. return;
  6620. }
  6621. var monthDistance = this.dateUtil.getMonthDistance(this.firstRenderableDate, date);
  6622. this.calendarScroller.scrollTop = monthDistance * TBODY_HEIGHT;
  6623. };
  6624. /**
  6625. * Sets the ng-model value for the calendar and emits a change event.
  6626. * @param {Date} date
  6627. */
  6628. CalendarCtrl.prototype.setNgModelValue = function(date) {
  6629. this.$scope.$emit('md-calendar-change', date);
  6630. this.ngModelCtrl.$setViewValue(date);
  6631. this.ngModelCtrl.$render();
  6632. };
  6633. /**
  6634. * Focus the cell corresponding to the given date.
  6635. * @param {Date=} opt_date
  6636. */
  6637. CalendarCtrl.prototype.focus = function(opt_date) {
  6638. var date = opt_date || this.selectedDate || this.today;
  6639. var previousFocus = this.calendarElement.querySelector('.md-focus');
  6640. if (previousFocus) {
  6641. previousFocus.classList.remove(FOCUSED_DATE_CLASS);
  6642. }
  6643. var cellId = this.getDateId(date);
  6644. var cell = document.getElementById(cellId);
  6645. if (cell) {
  6646. cell.classList.add(FOCUSED_DATE_CLASS);
  6647. cell.focus();
  6648. } else {
  6649. this.focusDate = date;
  6650. }
  6651. };
  6652. /**
  6653. * If a date exceeds minDate or maxDate, returns date matching minDate or maxDate, respectively.
  6654. * Otherwise, returns the date.
  6655. * @param {Date} date
  6656. * @return {Date}
  6657. */
  6658. CalendarCtrl.prototype.boundDateByMinAndMax = function(date) {
  6659. var boundDate = date;
  6660. if (this.minDate && date < this.minDate) {
  6661. boundDate = new Date(this.minDate.getTime());
  6662. }
  6663. if (this.maxDate && date > this.maxDate) {
  6664. boundDate = new Date(this.maxDate.getTime());
  6665. }
  6666. return boundDate;
  6667. };
  6668. /*** Updating the displayed / selected date ***/
  6669. /**
  6670. * Change the selected date in the calendar (ngModel value has already been changed).
  6671. * @param {Date} date
  6672. */
  6673. CalendarCtrl.prototype.changeSelectedDate = function(date) {
  6674. var self = this;
  6675. var previousSelectedDate = this.selectedDate;
  6676. this.selectedDate = date;
  6677. this.changeDisplayDate(date).then(function() {
  6678. // Remove the selected class from the previously selected date, if any.
  6679. if (previousSelectedDate) {
  6680. var prevDateCell =
  6681. document.getElementById(self.getDateId(previousSelectedDate));
  6682. if (prevDateCell) {
  6683. prevDateCell.classList.remove(SELECTED_DATE_CLASS);
  6684. prevDateCell.setAttribute('aria-selected', 'false');
  6685. }
  6686. }
  6687. // Apply the select class to the new selected date if it is set.
  6688. if (date) {
  6689. var dateCell = document.getElementById(self.getDateId(date));
  6690. if (dateCell) {
  6691. dateCell.classList.add(SELECTED_DATE_CLASS);
  6692. dateCell.setAttribute('aria-selected', 'true');
  6693. }
  6694. }
  6695. });
  6696. };
  6697. /**
  6698. * Change the date that is being shown in the calendar. If the given date is in a different
  6699. * month, the displayed month will be transitioned.
  6700. * @param {Date} date
  6701. */
  6702. CalendarCtrl.prototype.changeDisplayDate = function(date) {
  6703. // Initialization is deferred until this function is called because we want to reflect
  6704. // the starting value of ngModel.
  6705. if (!this.isInitialized) {
  6706. this.buildInitialCalendarDisplay();
  6707. return this.$q.when();
  6708. }
  6709. // If trying to show an invalid date or a transition is in progress, do nothing.
  6710. if (!this.dateUtil.isValidDate(date) || this.isMonthTransitionInProgress) {
  6711. return this.$q.when();
  6712. }
  6713. this.isMonthTransitionInProgress = true;
  6714. var animationPromise = this.animateDateChange(date);
  6715. this.displayDate = date;
  6716. var self = this;
  6717. animationPromise.then(function() {
  6718. self.isMonthTransitionInProgress = false;
  6719. });
  6720. return animationPromise;
  6721. };
  6722. /**
  6723. * Animates the transition from the calendar's current month to the given month.
  6724. * @param {Date} date
  6725. * @returns {angular.$q.Promise} The animation promise.
  6726. */
  6727. CalendarCtrl.prototype.animateDateChange = function(date) {
  6728. this.scrollToMonth(date);
  6729. return this.$q.when();
  6730. };
  6731. /*** Constructing the calendar table ***/
  6732. /**
  6733. * Builds and appends a day-of-the-week header to the calendar.
  6734. * This should only need to be called once during initialization.
  6735. */
  6736. CalendarCtrl.prototype.buildWeekHeader = function() {
  6737. var firstDayOfWeek = this.dateLocale.firstDayOfWeek;
  6738. var shortDays = this.dateLocale.shortDays;
  6739. var row = document.createElement('tr');
  6740. for (var i = 0; i < 7; i++) {
  6741. var th = document.createElement('th');
  6742. th.textContent = shortDays[(i + firstDayOfWeek) % 7];
  6743. row.appendChild(th);
  6744. }
  6745. this.$element.find('thead').append(row);
  6746. };
  6747. /**
  6748. * Gets an identifier for a date unique to the calendar instance for internal
  6749. * purposes. Not to be displayed.
  6750. * @param {Date} date
  6751. * @returns {string}
  6752. */
  6753. CalendarCtrl.prototype.getDateId = function(date) {
  6754. return [
  6755. 'md',
  6756. this.id,
  6757. date.getFullYear(),
  6758. date.getMonth(),
  6759. date.getDate()
  6760. ].join('-');
  6761. };
  6762. })();
  6763. })();
  6764. (function(){
  6765. "use strict";
  6766. (function() {
  6767. 'use strict';
  6768. angular.module('material.components.datepicker')
  6769. .directive('mdCalendarMonth', mdCalendarMonthDirective);
  6770. /**
  6771. * Private directive consumed by md-calendar. Having this directive lets the calender use
  6772. * md-virtual-repeat and also cleanly separates the month DOM construction functions from
  6773. * the rest of the calendar controller logic.
  6774. */
  6775. function mdCalendarMonthDirective() {
  6776. return {
  6777. require: ['^^mdCalendar', 'mdCalendarMonth'],
  6778. scope: {offset: '=mdMonthOffset'},
  6779. controller: CalendarMonthCtrl,
  6780. controllerAs: 'mdMonthCtrl',
  6781. bindToController: true,
  6782. link: function(scope, element, attrs, controllers) {
  6783. var calendarCtrl = controllers[0];
  6784. var monthCtrl = controllers[1];
  6785. monthCtrl.calendarCtrl = calendarCtrl;
  6786. monthCtrl.generateContent();
  6787. // The virtual-repeat re-uses the same DOM elements, so there are only a limited number
  6788. // of repeated items that are linked, and then those elements have their bindings updataed.
  6789. // Since the months are not generated by bindings, we simply regenerate the entire thing
  6790. // when the binding (offset) changes.
  6791. scope.$watch(function() { return monthCtrl.offset; }, function(offset, oldOffset) {
  6792. if (offset != oldOffset) {
  6793. monthCtrl.generateContent();
  6794. }
  6795. });
  6796. }
  6797. };
  6798. }
  6799. /** Class applied to the cell for today. */
  6800. var TODAY_CLASS = 'md-calendar-date-today';
  6801. /** Class applied to the selected date cell/. */
  6802. var SELECTED_DATE_CLASS = 'md-calendar-selected-date';
  6803. /** Class applied to the focused date cell/. */
  6804. var FOCUSED_DATE_CLASS = 'md-focus';
  6805. /**
  6806. * Controller for a single calendar month.
  6807. * @ngInject @constructor
  6808. */
  6809. function CalendarMonthCtrl($element, $$mdDateUtil, $mdDateLocale) {
  6810. this.dateUtil = $$mdDateUtil;
  6811. this.dateLocale = $mdDateLocale;
  6812. this.$element = $element;
  6813. this.calendarCtrl = null;
  6814. /**
  6815. * Number of months from the start of the month "items" that the currently rendered month
  6816. * occurs. Set via angular data binding.
  6817. * @type {number}
  6818. */
  6819. this.offset;
  6820. /**
  6821. * Date cell to focus after appending the month to the document.
  6822. * @type {HTMLElement}
  6823. */
  6824. this.focusAfterAppend = null;
  6825. }
  6826. CalendarMonthCtrl.$inject = ["$element", "$$mdDateUtil", "$mdDateLocale"];
  6827. /** Generate and append the content for this month to the directive element. */
  6828. CalendarMonthCtrl.prototype.generateContent = function() {
  6829. var calendarCtrl = this.calendarCtrl;
  6830. var date = this.dateUtil.incrementMonths(calendarCtrl.firstRenderableDate, this.offset);
  6831. this.$element.empty();
  6832. this.$element.append(this.buildCalendarForMonth(date));
  6833. if (this.focusAfterAppend) {
  6834. this.focusAfterAppend.classList.add(FOCUSED_DATE_CLASS);
  6835. this.focusAfterAppend.focus();
  6836. this.focusAfterAppend = null;
  6837. }
  6838. };
  6839. /**
  6840. * Creates a single cell to contain a date in the calendar with all appropriate
  6841. * attributes and classes added. If a date is given, the cell content will be set
  6842. * based on the date.
  6843. * @param {Date=} opt_date
  6844. * @returns {HTMLElement}
  6845. */
  6846. CalendarMonthCtrl.prototype.buildDateCell = function(opt_date) {
  6847. var calendarCtrl = this.calendarCtrl;
  6848. // TODO(jelbourn): cloneNode is likely a faster way of doing this.
  6849. var cell = document.createElement('td');
  6850. cell.tabIndex = -1;
  6851. cell.classList.add('md-calendar-date');
  6852. cell.setAttribute('role', 'gridcell');
  6853. if (opt_date) {
  6854. cell.setAttribute('tabindex', '-1');
  6855. cell.setAttribute('aria-label', this.dateLocale.longDateFormatter(opt_date));
  6856. cell.id = calendarCtrl.getDateId(opt_date);
  6857. // Use `data-timestamp` attribute because IE10 does not support the `dataset` property.
  6858. cell.setAttribute('data-timestamp', opt_date.getTime());
  6859. // TODO(jelourn): Doing these comparisons for class addition during generation might be slow.
  6860. // It may be better to finish the construction and then query the node and add the class.
  6861. if (this.dateUtil.isSameDay(opt_date, calendarCtrl.today)) {
  6862. cell.classList.add(TODAY_CLASS);
  6863. }
  6864. if (this.dateUtil.isValidDate(calendarCtrl.selectedDate) &&
  6865. this.dateUtil.isSameDay(opt_date, calendarCtrl.selectedDate)) {
  6866. cell.classList.add(SELECTED_DATE_CLASS);
  6867. cell.setAttribute('aria-selected', 'true');
  6868. }
  6869. var cellText = this.dateLocale.dates[opt_date.getDate()];
  6870. if (this.dateUtil.isDateWithinRange(opt_date,
  6871. this.calendarCtrl.minDate, this.calendarCtrl.maxDate)) {
  6872. // Add a indicator for select, hover, and focus states.
  6873. var selectionIndicator = document.createElement('span');
  6874. cell.appendChild(selectionIndicator);
  6875. selectionIndicator.classList.add('md-calendar-date-selection-indicator');
  6876. selectionIndicator.textContent = cellText;
  6877. cell.addEventListener('click', calendarCtrl.cellClickHandler);
  6878. if (calendarCtrl.focusDate && this.dateUtil.isSameDay(opt_date, calendarCtrl.focusDate)) {
  6879. this.focusAfterAppend = cell;
  6880. }
  6881. } else {
  6882. cell.classList.add('md-calendar-date-disabled');
  6883. cell.textContent = cellText;
  6884. }
  6885. }
  6886. return cell;
  6887. };
  6888. /**
  6889. * Builds a `tr` element for the calendar grid.
  6890. * @param rowNumber The week number within the month.
  6891. * @returns {HTMLElement}
  6892. */
  6893. CalendarMonthCtrl.prototype.buildDateRow = function(rowNumber) {
  6894. var row = document.createElement('tr');
  6895. row.setAttribute('role', 'row');
  6896. // Because of an NVDA bug (with Firefox), the row needs an aria-label in order
  6897. // to prevent the entire row being read aloud when the user moves between rows.
  6898. // See http://community.nvda-project.org/ticket/4643.
  6899. row.setAttribute('aria-label', this.dateLocale.weekNumberFormatter(rowNumber));
  6900. return row;
  6901. };
  6902. /**
  6903. * Builds the <tbody> content for the given date's month.
  6904. * @param {Date=} opt_dateInMonth
  6905. * @returns {DocumentFragment} A document fragment containing the <tr> elements.
  6906. */
  6907. CalendarMonthCtrl.prototype.buildCalendarForMonth = function(opt_dateInMonth) {
  6908. var date = this.dateUtil.isValidDate(opt_dateInMonth) ? opt_dateInMonth : new Date();
  6909. var firstDayOfMonth = this.dateUtil.getFirstDateOfMonth(date);
  6910. var firstDayOfTheWeek = this.getLocaleDay_(firstDayOfMonth);
  6911. var numberOfDaysInMonth = this.dateUtil.getNumberOfDaysInMonth(date);
  6912. // Store rows for the month in a document fragment so that we can append them all at once.
  6913. var monthBody = document.createDocumentFragment();
  6914. var rowNumber = 1;
  6915. var row = this.buildDateRow(rowNumber);
  6916. monthBody.appendChild(row);
  6917. // If this is the final month in the list of items, only the first week should render,
  6918. // so we should return immediately after the first row is complete and has been
  6919. // attached to the body.
  6920. var isFinalMonth = this.offset === this.calendarCtrl.items.length - 1;
  6921. // Add a label for the month. If the month starts on a Sun/Mon/Tues, the month label
  6922. // goes on a row above the first of the month. Otherwise, the month label takes up the first
  6923. // two cells of the first row.
  6924. var blankCellOffset = 0;
  6925. var monthLabelCell = document.createElement('td');
  6926. monthLabelCell.classList.add('md-calendar-month-label');
  6927. // If the entire month is after the max date, render the label as a disabled state.
  6928. if (this.calendarCtrl.maxDate && firstDayOfMonth > this.calendarCtrl.maxDate) {
  6929. monthLabelCell.classList.add('md-calendar-month-label-disabled');
  6930. }
  6931. monthLabelCell.textContent = this.dateLocale.monthHeaderFormatter(date);
  6932. if (firstDayOfTheWeek <= 2) {
  6933. monthLabelCell.setAttribute('colspan', '7');
  6934. var monthLabelRow = this.buildDateRow();
  6935. monthLabelRow.appendChild(monthLabelCell);
  6936. monthBody.insertBefore(monthLabelRow, row);
  6937. if (isFinalMonth) {
  6938. return monthBody;
  6939. }
  6940. } else {
  6941. blankCellOffset = 2;
  6942. monthLabelCell.setAttribute('colspan', '2');
  6943. row.appendChild(monthLabelCell);
  6944. }
  6945. // Add a blank cell for each day of the week that occurs before the first of the month.
  6946. // For example, if the first day of the month is a Tuesday, add blank cells for Sun and Mon.
  6947. // The blankCellOffset is needed in cases where the first N cells are used by the month label.
  6948. for (var i = blankCellOffset; i < firstDayOfTheWeek; i++) {
  6949. row.appendChild(this.buildDateCell());
  6950. }
  6951. // Add a cell for each day of the month, keeping track of the day of the week so that
  6952. // we know when to start a new row.
  6953. var dayOfWeek = firstDayOfTheWeek;
  6954. var iterationDate = firstDayOfMonth;
  6955. for (var d = 1; d <= numberOfDaysInMonth; d++) {
  6956. // If we've reached the end of the week, start a new row.
  6957. if (dayOfWeek === 7) {
  6958. // We've finished the first row, so we're done if this is the final month.
  6959. if (isFinalMonth) {
  6960. return monthBody;
  6961. }
  6962. dayOfWeek = 0;
  6963. rowNumber++;
  6964. row = this.buildDateRow(rowNumber);
  6965. monthBody.appendChild(row);
  6966. }
  6967. iterationDate.setDate(d);
  6968. var cell = this.buildDateCell(iterationDate);
  6969. row.appendChild(cell);
  6970. dayOfWeek++;
  6971. }
  6972. // Ensure that the last row of the month has 7 cells.
  6973. while (row.childNodes.length < 7) {
  6974. row.appendChild(this.buildDateCell());
  6975. }
  6976. // Ensure that all months have 6 rows. This is necessary for now because the virtual-repeat
  6977. // requires that all items have exactly the same height.
  6978. while (monthBody.childNodes.length < 6) {
  6979. var whitespaceRow = this.buildDateRow();
  6980. for (var i = 0; i < 7; i++) {
  6981. whitespaceRow.appendChild(this.buildDateCell());
  6982. }
  6983. monthBody.appendChild(whitespaceRow);
  6984. }
  6985. return monthBody;
  6986. };
  6987. /**
  6988. * Gets the day-of-the-week index for a date for the current locale.
  6989. * @private
  6990. * @param {Date} date
  6991. * @returns {number} The column index of the date in the calendar.
  6992. */
  6993. CalendarMonthCtrl.prototype.getLocaleDay_ = function(date) {
  6994. return (date.getDay() + (7 - this.dateLocale.firstDayOfWeek)) % 7
  6995. };
  6996. })();
  6997. })();
  6998. (function(){
  6999. "use strict";
  7000. (function() {
  7001. 'use strict';
  7002. /**
  7003. * @ngdoc service
  7004. * @name $mdDateLocaleProvider
  7005. * @module material.components.datepicker
  7006. *
  7007. * @description
  7008. * The `$mdDateLocaleProvider` is the provider that creates the `$mdDateLocale` service.
  7009. * This provider that allows the user to specify messages, formatters, and parsers for date
  7010. * internationalization. The `$mdDateLocale` service itself is consumed by Angular Material
  7011. * components that that deal with dates.
  7012. *
  7013. * @property {(Array<string>)=} months Array of month names (in order).
  7014. * @property {(Array<string>)=} shortMonths Array of abbreviated month names.
  7015. * @property {(Array<string>)=} days Array of the days of the week (in order).
  7016. * @property {(Array<string>)=} shortDays Array of abbreviated dayes of the week.
  7017. * @property {(Array<string>)=} dates Array of dates of the month. Only necessary for locales
  7018. * using a numeral system other than [1, 2, 3...].
  7019. * @property {(Array<string>)=} firstDayOfWeek The first day of the week. Sunday = 0, Monday = 1,
  7020. * etc.
  7021. * @property {(function(string): Date)=} parseDate Function to parse a date object from a string.
  7022. * @property {(function(Date): string)=} formatDate Function to format a date object to a string.
  7023. * @property {(function(Date): string)=} monthHeaderFormatter Function that returns the label for
  7024. * a month given a date.
  7025. * @property {(function(number): string)=} weekNumberFormatter Function that returns a label for
  7026. * a week given the week number.
  7027. * @property {(string)=} msgCalendar Translation of the label "Calendar" for the current locale.
  7028. * @property {(string)=} msgOpenCalendar Translation of the button label "Open calendar" for the
  7029. * current locale.
  7030. *
  7031. * @usage
  7032. * <hljs lang="js">
  7033. * myAppModule.config(function($mdDateLocaleProvider) {
  7034. *
  7035. * // Example of a French localization.
  7036. * $mdDateLocaleProvider.months = ['janvier', 'février', 'mars', ...];
  7037. * $mdDateLocaleProvider.shortMonths = ['janv', 'févr', 'mars', ...];
  7038. * $mdDateLocaleProvider.days = ['dimanche', 'lundi', 'mardi', ...];
  7039. * $mdDateLocaleProvider.shortDays = ['Di', 'Lu', 'Ma', ...];
  7040. *
  7041. * // Can change week display to start on Monday.
  7042. * $mdDateLocaleProvider.firstDayOfWeek = 1;
  7043. *
  7044. * // Optional.
  7045. * $mdDateLocaleProvider.dates = [1, 2, 3, 4, 5, 6, ...];
  7046. *
  7047. * // Example uses moment.js to parse and format dates.
  7048. * $mdDateLocaleProvider.parseDate = function(dateString) {
  7049. * var m = moment(dateString, 'L', true);
  7050. * return m.isValid() ? m.toDate() : new Date(NaN);
  7051. * };
  7052. *
  7053. * $mdDateLocaleProvider.formatDate = function(date) {
  7054. * return moment(date).format('L');
  7055. * };
  7056. *
  7057. * $mdDateLocaleProvider.monthHeaderFormatter = function(date) {
  7058. * return myShortMonths[date.getMonth()] + ' ' + date.getFullYear();
  7059. * };
  7060. *
  7061. * // In addition to date display, date components also need localized messages
  7062. * // for aria-labels for screen-reader users.
  7063. *
  7064. * $mdDateLocaleProvider.weekNumberFormatter = function(weekNumber) {
  7065. * return 'Semaine ' + weekNumber;
  7066. * };
  7067. *
  7068. * $mdDateLocaleProvider.msgCalendar = 'Calendrier';
  7069. * $mdDateLocaleProvider.msgOpenCalendar = 'Ouvrir le calendrier';
  7070. *
  7071. * });
  7072. * </hljs>
  7073. *
  7074. */
  7075. angular.module('material.components.datepicker').config(["$provide", function($provide) {
  7076. // TODO(jelbourn): Assert provided values are correctly formatted. Need assertions.
  7077. /** @constructor */
  7078. function DateLocaleProvider() {
  7079. /** Array of full month names. E.g., ['January', 'Febuary', ...] */
  7080. this.months = null;
  7081. /** Array of abbreviated month names. E.g., ['Jan', 'Feb', ...] */
  7082. this.shortMonths = null;
  7083. /** Array of full day of the week names. E.g., ['Monday', 'Tuesday', ...] */
  7084. this.days = null;
  7085. /** Array of abbreviated dat of the week names. E.g., ['M', 'T', ...] */
  7086. this.shortDays = null;
  7087. /** Array of dates of a month (1 - 31). Characters might be different in some locales. */
  7088. this.dates = null;
  7089. /** Index of the first day of the week. 0 = Sunday, 1 = Monday, etc. */
  7090. this.firstDayOfWeek = 0;
  7091. /**
  7092. * Function that converts the date portion of a Date to a string.
  7093. * @type {(function(Date): string)}
  7094. */
  7095. this.formatDate = null;
  7096. /**
  7097. * Function that converts a date string to a Date object (the date portion)
  7098. * @type {function(string): Date}
  7099. */
  7100. this.parseDate = null;
  7101. /**
  7102. * Function that formats a Date into a month header string.
  7103. * @type {function(Date): string}
  7104. */
  7105. this.monthHeaderFormatter = null;
  7106. /**
  7107. * Function that formats a week number into a label for the week.
  7108. * @type {function(number): string}
  7109. */
  7110. this.weekNumberFormatter = null;
  7111. /**
  7112. * Function that formats a date into a long aria-label that is read
  7113. * when the focused date changes.
  7114. * @type {function(Date): string}
  7115. */
  7116. this.longDateFormatter = null;
  7117. /**
  7118. * ARIA label for the calendar "dialog" used in the datepicker.
  7119. * @type {string}
  7120. */
  7121. this.msgCalendar = '';
  7122. /**
  7123. * ARIA label for the datepicker's "Open calendar" buttons.
  7124. * @type {string}
  7125. */
  7126. this.msgOpenCalendar = '';
  7127. }
  7128. /**
  7129. * Factory function that returns an instance of the dateLocale service.
  7130. * @ngInject
  7131. * @param $locale
  7132. * @returns {DateLocale}
  7133. */
  7134. DateLocaleProvider.prototype.$get = function($locale) {
  7135. /**
  7136. * Default date-to-string formatting function.
  7137. * @param {!Date} date
  7138. * @returns {string}
  7139. */
  7140. function defaultFormatDate(date) {
  7141. if (!date) {
  7142. return '';
  7143. }
  7144. // All of the dates created through ng-material *should* be set to midnight.
  7145. // If we encounter a date where the localeTime shows at 11pm instead of midnight,
  7146. // we have run into an issue with DST where we need to increment the hour by one:
  7147. // var d = new Date(1992, 9, 8, 0, 0, 0);
  7148. // d.toLocaleString(); // == "10/7/1992, 11:00:00 PM"
  7149. var localeTime = date.toLocaleTimeString();
  7150. var formatDate = date;
  7151. if (date.getHours() == 0 &&
  7152. (localeTime.indexOf('11:') !== -1 || localeTime.indexOf('23:') !== -1)) {
  7153. formatDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 1, 0, 0);
  7154. }
  7155. return formatDate.toLocaleDateString();
  7156. }
  7157. /**
  7158. * Default string-to-date parsing function.
  7159. * @param {string} dateString
  7160. * @returns {!Date}
  7161. */
  7162. function defaultParseDate(dateString) {
  7163. return new Date(dateString);
  7164. }
  7165. /**
  7166. * Default function to determine whether a string makes sense to be
  7167. * parsed to a Date object.
  7168. *
  7169. * This is very permissive and is just a basic sanity check to ensure that
  7170. * things like single integers aren't able to be parsed into dates.
  7171. * @param {string} dateString
  7172. * @returns {boolean}
  7173. */
  7174. function defaultIsDateComplete(dateString) {
  7175. dateString = dateString.trim();
  7176. // Looks for three chunks of content (either numbers or text) separated
  7177. // by delimiters.
  7178. var re = /^(([a-zA-Z]{3,}|[0-9]{1,4})([ \.,]+|[\/\-])){2}([a-zA-Z]{3,}|[0-9]{1,4})$/;
  7179. return re.test(dateString);
  7180. }
  7181. /**
  7182. * Default date-to-string formatter to get a month header.
  7183. * @param {!Date} date
  7184. * @returns {string}
  7185. */
  7186. function defaultMonthHeaderFormatter(date) {
  7187. return service.shortMonths[date.getMonth()] + ' ' + date.getFullYear();
  7188. }
  7189. /**
  7190. * Default week number formatter.
  7191. * @param number
  7192. * @returns {string}
  7193. */
  7194. function defaultWeekNumberFormatter(number) {
  7195. return 'Week ' + number;
  7196. }
  7197. /**
  7198. * Default formatter for date cell aria-labels.
  7199. * @param {!Date} date
  7200. * @returns {string}
  7201. */
  7202. function defaultLongDateFormatter(date) {
  7203. // Example: 'Thursday June 18 2015'
  7204. return [
  7205. service.days[date.getDay()],
  7206. service.months[date.getMonth()],
  7207. service.dates[date.getDate()],
  7208. date.getFullYear()
  7209. ].join(' ');
  7210. }
  7211. // The default "short" day strings are the first character of each day,
  7212. // e.g., "Monday" => "M".
  7213. var defaultShortDays = $locale.DATETIME_FORMATS.DAY.map(function(day) {
  7214. return day[0];
  7215. });
  7216. // The default dates are simply the numbers 1 through 31.
  7217. var defaultDates = Array(32);
  7218. for (var i = 1; i <= 31; i++) {
  7219. defaultDates[i] = i;
  7220. }
  7221. // Default ARIA messages are in English (US).
  7222. var defaultMsgCalendar = 'Calendar';
  7223. var defaultMsgOpenCalendar = 'Open calendar';
  7224. var service = {
  7225. months: this.months || $locale.DATETIME_FORMATS.MONTH,
  7226. shortMonths: this.shortMonths || $locale.DATETIME_FORMATS.SHORTMONTH,
  7227. days: this.days || $locale.DATETIME_FORMATS.DAY,
  7228. shortDays: this.shortDays || defaultShortDays,
  7229. dates: this.dates || defaultDates,
  7230. firstDayOfWeek: this.firstDayOfWeek || 0,
  7231. formatDate: this.formatDate || defaultFormatDate,
  7232. parseDate: this.parseDate || defaultParseDate,
  7233. isDateComplete: this.isDateComplete || defaultIsDateComplete,
  7234. monthHeaderFormatter: this.monthHeaderFormatter || defaultMonthHeaderFormatter,
  7235. weekNumberFormatter: this.weekNumberFormatter || defaultWeekNumberFormatter,
  7236. longDateFormatter: this.longDateFormatter || defaultLongDateFormatter,
  7237. msgCalendar: this.msgCalendar || defaultMsgCalendar,
  7238. msgOpenCalendar: this.msgOpenCalendar || defaultMsgOpenCalendar
  7239. };
  7240. return service;
  7241. };
  7242. DateLocaleProvider.prototype.$get.$inject = ["$locale"];
  7243. $provide.provider('$mdDateLocale', new DateLocaleProvider());
  7244. }]);
  7245. })();
  7246. })();
  7247. (function(){
  7248. "use strict";
  7249. (function() {
  7250. 'use strict';
  7251. // POST RELEASE
  7252. // TODO(jelbourn): Demo that uses moment.js
  7253. // TODO(jelbourn): make sure this plays well with validation and ngMessages.
  7254. // TODO(jelbourn): calendar pane doesn't open up outside of visible viewport.
  7255. // TODO(jelbourn): forward more attributes to the internal input (required, autofocus, etc.)
  7256. // TODO(jelbourn): something better for mobile (calendar panel takes up entire screen?)
  7257. // TODO(jelbourn): input behavior (masking? auto-complete?)
  7258. // TODO(jelbourn): UTC mode
  7259. // TODO(jelbourn): RTL
  7260. angular.module('material.components.datepicker')
  7261. .directive('mdDatepicker', datePickerDirective);
  7262. /**
  7263. * @ngdoc directive
  7264. * @name mdDatepicker
  7265. * @module material.components.datepicker
  7266. *
  7267. * @param {Date} ng-model The component's model. Expects a JavaScript Date object.
  7268. * @param {expression=} ng-change Expression evaluated when the model value changes.
  7269. * @param {Date=} md-min-date Expression representing a min date (inclusive).
  7270. * @param {Date=} md-max-date Expression representing a max date (inclusive).
  7271. * @param {boolean=} disabled Whether the datepicker is disabled.
  7272. * @param {boolean=} required Whether a value is required for the datepicker.
  7273. *
  7274. * @description
  7275. * `<md-datepicker>` is a component used to select a single date.
  7276. * For information on how to configure internationalization for the date picker,
  7277. * see `$mdDateLocaleProvider`.
  7278. *
  7279. * This component supports [ngMessages](https://docs.angularjs.org/api/ngMessages/directive/ngMessages).
  7280. * Supported attributes are:
  7281. * * `required`: whether a required date is not set.
  7282. * * `mindate`: whether the selected date is before the minimum allowed date.
  7283. * * `maxdate`: whether the selected date is after the maximum allowed date.
  7284. *
  7285. * @usage
  7286. * <hljs lang="html">
  7287. * <md-datepicker ng-model="birthday"></md-datepicker>
  7288. * </hljs>
  7289. *
  7290. */
  7291. function datePickerDirective() {
  7292. return {
  7293. template:
  7294. // Buttons are not in the tab order because users can open the calendar via keyboard
  7295. // interaction on the text input, and multiple tab stops for one component (picker)
  7296. // may be confusing.
  7297. '<md-button class="md-datepicker-button md-icon-button" type="button" ' +
  7298. 'tabindex="-1" aria-hidden="true" ' +
  7299. 'ng-click="ctrl.openCalendarPane($event)">' +
  7300. '<md-icon class="md-datepicker-calendar-icon" md-svg-icon="md-calendar"></md-icon>' +
  7301. '</md-button>' +
  7302. '<div class="md-datepicker-input-container" ' +
  7303. 'ng-class="{\'md-datepicker-focused\': ctrl.isFocused}">' +
  7304. '<input class="md-datepicker-input" aria-haspopup="true" ' +
  7305. 'ng-focus="ctrl.setFocused(true)" ng-blur="ctrl.setFocused(false)">' +
  7306. '<md-button type="button" md-no-ink ' +
  7307. 'class="md-datepicker-triangle-button md-icon-button" ' +
  7308. 'ng-click="ctrl.openCalendarPane($event)" ' +
  7309. 'aria-label="{{::ctrl.dateLocale.msgOpenCalendar}}">' +
  7310. '<div class="md-datepicker-expand-triangle"></div>' +
  7311. '</md-button>' +
  7312. '</div>' +
  7313. // This pane will be detached from here and re-attached to the document body.
  7314. '<div class="md-datepicker-calendar-pane md-whiteframe-z1">' +
  7315. '<div class="md-datepicker-input-mask">' +
  7316. '<div class="md-datepicker-input-mask-opaque"></div>' +
  7317. '</div>' +
  7318. '<div class="md-datepicker-calendar">' +
  7319. '<md-calendar role="dialog" aria-label="{{::ctrl.dateLocale.msgCalendar}}" ' +
  7320. 'md-min-date="ctrl.minDate" md-max-date="ctrl.maxDate"' +
  7321. 'ng-model="ctrl.date" ng-if="ctrl.isCalendarOpen">' +
  7322. '</md-calendar>' +
  7323. '</div>' +
  7324. '</div>',
  7325. require: ['ngModel', 'mdDatepicker'],
  7326. scope: {
  7327. minDate: '=mdMinDate',
  7328. maxDate: '=mdMaxDate',
  7329. placeholder: '@mdPlaceholder'
  7330. },
  7331. controller: DatePickerCtrl,
  7332. controllerAs: 'ctrl',
  7333. bindToController: true,
  7334. link: function(scope, element, attr, controllers) {
  7335. var ngModelCtrl = controllers[0];
  7336. var mdDatePickerCtrl = controllers[1];
  7337. mdDatePickerCtrl.configureNgModel(ngModelCtrl);
  7338. }
  7339. };
  7340. }
  7341. /** Additional offset for the input's `size` attribute, which is updated based on its content. */
  7342. var EXTRA_INPUT_SIZE = 3;
  7343. /** Class applied to the container if the date is invalid. */
  7344. var INVALID_CLASS = 'md-datepicker-invalid';
  7345. /** Default time in ms to debounce input event by. */
  7346. var DEFAULT_DEBOUNCE_INTERVAL = 500;
  7347. /**
  7348. * Height of the calendar pane used to check if the pane is going outside the boundary of
  7349. * the viewport. See calendar.scss for how $md-calendar-height is computed; an extra 20px is
  7350. * also added to space the pane away from the exact edge of the screen.
  7351. *
  7352. * This is computed statically now, but can be changed to be measured if the circumstances
  7353. * of calendar sizing are changed.
  7354. */
  7355. var CALENDAR_PANE_HEIGHT = 368;
  7356. /**
  7357. * Width of the calendar pane used to check if the pane is going outside the boundary of
  7358. * the viewport. See calendar.scss for how $md-calendar-width is computed; an extra 20px is
  7359. * also added to space the pane away from the exact edge of the screen.
  7360. *
  7361. * This is computed statically now, but can be changed to be measured if the circumstances
  7362. * of calendar sizing are changed.
  7363. */
  7364. var CALENDAR_PANE_WIDTH = 360;
  7365. /**
  7366. * Controller for md-datepicker.
  7367. *
  7368. * @ngInject @constructor
  7369. */
  7370. function DatePickerCtrl($scope, $element, $attrs, $compile, $timeout, $window,
  7371. $mdConstant, $mdTheming, $mdUtil, $mdDateLocale, $$mdDateUtil, $$rAF) {
  7372. /** @final */
  7373. this.$compile = $compile;
  7374. /** @final */
  7375. this.$timeout = $timeout;
  7376. /** @final */
  7377. this.$window = $window;
  7378. /** @final */
  7379. this.dateLocale = $mdDateLocale;
  7380. /** @final */
  7381. this.dateUtil = $$mdDateUtil;
  7382. /** @final */
  7383. this.$mdConstant = $mdConstant;
  7384. /* @final */
  7385. this.$mdUtil = $mdUtil;
  7386. /** @final */
  7387. this.$$rAF = $$rAF;
  7388. /** @type {!angular.NgModelController} */
  7389. this.ngModelCtrl = null;
  7390. /** @type {HTMLInputElement} */
  7391. this.inputElement = $element[0].querySelector('input');
  7392. /** @final {!angular.JQLite} */
  7393. this.ngInputElement = angular.element(this.inputElement);
  7394. /** @type {HTMLElement} */
  7395. this.inputContainer = $element[0].querySelector('.md-datepicker-input-container');
  7396. /** @type {HTMLElement} Floating calendar pane. */
  7397. this.calendarPane = $element[0].querySelector('.md-datepicker-calendar-pane');
  7398. /** @type {HTMLElement} Calendar icon button. */
  7399. this.calendarButton = $element[0].querySelector('.md-datepicker-button');
  7400. /**
  7401. * Element covering everything but the input in the top of the floating calendar pane.
  7402. * @type {HTMLElement}
  7403. */
  7404. this.inputMask = $element[0].querySelector('.md-datepicker-input-mask-opaque');
  7405. /** @final {!angular.JQLite} */
  7406. this.$element = $element;
  7407. /** @final {!angular.Attributes} */
  7408. this.$attrs = $attrs;
  7409. /** @final {!angular.Scope} */
  7410. this.$scope = $scope;
  7411. /** @type {Date} */
  7412. this.date = null;
  7413. /** @type {boolean} */
  7414. this.isFocused = false;
  7415. /** @type {boolean} */
  7416. this.isDisabled;
  7417. this.setDisabled($element[0].disabled || angular.isString($attrs['disabled']));
  7418. /** @type {boolean} Whether the date-picker's calendar pane is open. */
  7419. this.isCalendarOpen = false;
  7420. /**
  7421. * Element from which the calendar pane was opened. Keep track of this so that we can return
  7422. * focus to it when the pane is closed.
  7423. * @type {HTMLElement}
  7424. */
  7425. this.calendarPaneOpenedFrom = null;
  7426. this.calendarPane.id = 'md-date-pane' + $mdUtil.nextUid();
  7427. $mdTheming($element);
  7428. /** Pre-bound click handler is saved so that the event listener can be removed. */
  7429. this.bodyClickHandler = angular.bind(this, this.handleBodyClick);
  7430. /** Pre-bound resize handler so that the event listener can be removed. */
  7431. this.windowResizeHandler = $mdUtil.debounce(angular.bind(this, this.closeCalendarPane), 100);
  7432. // Unless the user specifies so, the datepicker should not be a tab stop.
  7433. // This is necessary because ngAria might add a tabindex to anything with an ng-model
  7434. // (based on whether or not the user has turned that particular feature on/off).
  7435. if (!$attrs['tabindex']) {
  7436. $element.attr('tabindex', '-1');
  7437. }
  7438. this.installPropertyInterceptors();
  7439. this.attachChangeListeners();
  7440. this.attachInteractionListeners();
  7441. var self = this;
  7442. $scope.$on('$destroy', function() {
  7443. self.detachCalendarPane();
  7444. });
  7445. }
  7446. DatePickerCtrl.$inject = ["$scope", "$element", "$attrs", "$compile", "$timeout", "$window", "$mdConstant", "$mdTheming", "$mdUtil", "$mdDateLocale", "$$mdDateUtil", "$$rAF"];
  7447. /**
  7448. * Sets up the controller's reference to ngModelController.
  7449. * @param {!angular.NgModelController} ngModelCtrl
  7450. */
  7451. DatePickerCtrl.prototype.configureNgModel = function(ngModelCtrl) {
  7452. this.ngModelCtrl = ngModelCtrl;
  7453. var self = this;
  7454. ngModelCtrl.$render = function() {
  7455. self.date = self.ngModelCtrl.$viewValue;
  7456. self.inputElement.value = self.dateLocale.formatDate(self.date);
  7457. self.resizeInputElement();
  7458. self.setErrorFlags();
  7459. };
  7460. };
  7461. /**
  7462. * Attach event listeners for both the text input and the md-calendar.
  7463. * Events are used instead of ng-model so that updates don't infinitely update the other
  7464. * on a change. This should also be more performant than using a $watch.
  7465. */
  7466. DatePickerCtrl.prototype.attachChangeListeners = function() {
  7467. var self = this;
  7468. self.$scope.$on('md-calendar-change', function(event, date) {
  7469. self.ngModelCtrl.$setViewValue(date);
  7470. self.date = date;
  7471. self.inputElement.value = self.dateLocale.formatDate(date);
  7472. self.closeCalendarPane();
  7473. self.resizeInputElement();
  7474. self.inputContainer.classList.remove(INVALID_CLASS);
  7475. });
  7476. self.ngInputElement.on('input', angular.bind(self, self.resizeInputElement));
  7477. // TODO(chenmike): Add ability for users to specify this interval.
  7478. self.ngInputElement.on('input', self.$mdUtil.debounce(self.handleInputEvent,
  7479. DEFAULT_DEBOUNCE_INTERVAL, self));
  7480. };
  7481. /** Attach event listeners for user interaction. */
  7482. DatePickerCtrl.prototype.attachInteractionListeners = function() {
  7483. var self = this;
  7484. var $scope = this.$scope;
  7485. var keyCodes = this.$mdConstant.KEY_CODE;
  7486. // Add event listener through angular so that we can triggerHandler in unit tests.
  7487. self.ngInputElement.on('keydown', function(event) {
  7488. if (event.altKey && event.keyCode == keyCodes.DOWN_ARROW) {
  7489. self.openCalendarPane(event);
  7490. $scope.$digest();
  7491. }
  7492. });
  7493. $scope.$on('md-calendar-close', function() {
  7494. self.closeCalendarPane();
  7495. });
  7496. };
  7497. /**
  7498. * Capture properties set to the date-picker and imperitively handle internal changes.
  7499. * This is done to avoid setting up additional $watches.
  7500. */
  7501. DatePickerCtrl.prototype.installPropertyInterceptors = function() {
  7502. var self = this;
  7503. if (this.$attrs['ngDisabled']) {
  7504. // The expression is to be evaluated against the directive element's scope and not
  7505. // the directive's isolate scope.
  7506. var scope = this.$mdUtil.validateScope(this.$element) ? this.$element.scope() : null;
  7507. if ( scope ) {
  7508. scope.$watch(this.$attrs['ngDisabled'], function(isDisabled) {
  7509. self.setDisabled(isDisabled);
  7510. });
  7511. }
  7512. }
  7513. Object.defineProperty(this, 'placeholder', {
  7514. get: function() { return self.inputElement.placeholder; },
  7515. set: function(value) { self.inputElement.placeholder = value || ''; }
  7516. });
  7517. };
  7518. /**
  7519. * Sets whether the date-picker is disabled.
  7520. * @param {boolean} isDisabled
  7521. */
  7522. DatePickerCtrl.prototype.setDisabled = function(isDisabled) {
  7523. this.isDisabled = isDisabled;
  7524. this.inputElement.disabled = isDisabled;
  7525. this.calendarButton.disabled = isDisabled;
  7526. };
  7527. /**
  7528. * Sets the custom ngModel.$error flags to be consumed by ngMessages. Flags are:
  7529. * - mindate: whether the selected date is before the minimum date.
  7530. * - maxdate: whether the selected flag is after the maximum date.
  7531. */
  7532. DatePickerCtrl.prototype.setErrorFlags = function() {
  7533. if (this.dateUtil.isValidDate(this.date)) {
  7534. if (this.dateUtil.isValidDate(this.minDate)) {
  7535. this.ngModelCtrl.$error['mindate'] = this.date < this.minDate;
  7536. }
  7537. if (this.dateUtil.isValidDate(this.maxDate)) {
  7538. this.ngModelCtrl.$error['maxdate'] = this.date > this.maxDate;
  7539. }
  7540. }
  7541. };
  7542. /** Resizes the input element based on the size of its content. */
  7543. DatePickerCtrl.prototype.resizeInputElement = function() {
  7544. this.inputElement.size = this.inputElement.value.length + EXTRA_INPUT_SIZE;
  7545. };
  7546. /**
  7547. * Sets the model value if the user input is a valid date.
  7548. * Adds an invalid class to the input element if not.
  7549. */
  7550. DatePickerCtrl.prototype.handleInputEvent = function() {
  7551. var inputString = this.inputElement.value;
  7552. var parsedDate = this.dateLocale.parseDate(inputString);
  7553. this.dateUtil.setDateTimeToMidnight(parsedDate);
  7554. if (inputString === '') {
  7555. this.ngModelCtrl.$setViewValue(null);
  7556. this.date = null;
  7557. this.inputContainer.classList.remove(INVALID_CLASS);
  7558. } else if (this.dateUtil.isValidDate(parsedDate) &&
  7559. this.dateLocale.isDateComplete(inputString) &&
  7560. this.dateUtil.isDateWithinRange(parsedDate, this.minDate, this.maxDate)) {
  7561. this.ngModelCtrl.$setViewValue(parsedDate);
  7562. this.date = parsedDate;
  7563. this.inputContainer.classList.remove(INVALID_CLASS);
  7564. } else {
  7565. // If there's an input string, it's an invalid date.
  7566. this.inputContainer.classList.toggle(INVALID_CLASS, inputString);
  7567. }
  7568. };
  7569. /** Position and attach the floating calendar to the document. */
  7570. DatePickerCtrl.prototype.attachCalendarPane = function() {
  7571. var calendarPane = this.calendarPane;
  7572. calendarPane.style.transform = '';
  7573. this.$element.addClass('md-datepicker-open');
  7574. var elementRect = this.inputContainer.getBoundingClientRect();
  7575. var bodyRect = document.body.getBoundingClientRect();
  7576. // Check to see if the calendar pane would go off the screen. If so, adjust position
  7577. // accordingly to keep it within the viewport.
  7578. var paneTop = elementRect.top - bodyRect.top;
  7579. var paneLeft = elementRect.left - bodyRect.left;
  7580. var viewportTop = document.body.scrollTop;
  7581. var viewportBottom = viewportTop + this.$window.innerHeight;
  7582. var viewportLeft = document.body.scrollLeft;
  7583. var viewportRight = document.body.scrollLeft + this.$window.innerWidth;
  7584. // If the right edge of the pane would be off the screen and shifting it left by the
  7585. // difference would not go past the left edge of the screen. If the calendar pane is too
  7586. // big to fit on the screen at all, move it to the left of the screen and scale the entire
  7587. // element down to fit.
  7588. if (paneLeft + CALENDAR_PANE_WIDTH > viewportRight) {
  7589. if (viewportRight - CALENDAR_PANE_WIDTH > 0) {
  7590. paneLeft = viewportRight - CALENDAR_PANE_WIDTH;
  7591. } else {
  7592. paneLeft = viewportLeft;
  7593. var scale = this.$window.innerWidth / CALENDAR_PANE_WIDTH;
  7594. calendarPane.style.transform = 'scale(' + scale + ')';
  7595. }
  7596. calendarPane.classList.add('md-datepicker-pos-adjusted');
  7597. }
  7598. // If the bottom edge of the pane would be off the screen and shifting it up by the
  7599. // difference would not go past the top edge of the screen.
  7600. if (paneTop + CALENDAR_PANE_HEIGHT > viewportBottom &&
  7601. viewportBottom - CALENDAR_PANE_HEIGHT > viewportTop) {
  7602. paneTop = viewportBottom - CALENDAR_PANE_HEIGHT;
  7603. calendarPane.classList.add('md-datepicker-pos-adjusted');
  7604. }
  7605. calendarPane.style.left = paneLeft + 'px';
  7606. calendarPane.style.top = paneTop + 'px';
  7607. document.body.appendChild(calendarPane);
  7608. // The top of the calendar pane is a transparent box that shows the text input underneath.
  7609. // Since the pane is floating, though, the page underneath the pane *adjacent* to the input is
  7610. // also shown unless we cover it up. The inputMask does this by filling up the remaining space
  7611. // based on the width of the input.
  7612. this.inputMask.style.left = elementRect.width + 'px';
  7613. // Add CSS class after one frame to trigger open animation.
  7614. this.$$rAF(function() {
  7615. calendarPane.classList.add('md-pane-open');
  7616. });
  7617. };
  7618. /** Detach the floating calendar pane from the document. */
  7619. DatePickerCtrl.prototype.detachCalendarPane = function() {
  7620. this.$element.removeClass('md-datepicker-open');
  7621. this.calendarPane.classList.remove('md-pane-open');
  7622. this.calendarPane.classList.remove('md-datepicker-pos-adjusted');
  7623. if (this.calendarPane.parentNode) {
  7624. // Use native DOM removal because we do not want any of the angular state of this element
  7625. // to be disposed.
  7626. this.calendarPane.parentNode.removeChild(this.calendarPane);
  7627. }
  7628. };
  7629. /**
  7630. * Open the floating calendar pane.
  7631. * @param {Event} event
  7632. */
  7633. DatePickerCtrl.prototype.openCalendarPane = function(event) {
  7634. if (!this.isCalendarOpen && !this.isDisabled) {
  7635. this.isCalendarOpen = true;
  7636. this.calendarPaneOpenedFrom = event.target;
  7637. this.attachCalendarPane();
  7638. this.focusCalendar();
  7639. // Because the calendar pane is attached directly to the body, it is possible that the
  7640. // rest of the component (input, etc) is in a different scrolling container, such as
  7641. // an md-content. This means that, if the container is scrolled, the pane would remain
  7642. // stationary. To remedy this, we disable scrolling while the calendar pane is open, which
  7643. // also matches the native behavior for things like `<select>` on Mac and Windows.
  7644. this.$mdUtil.disableScrollAround(this.calendarPane);
  7645. // Attach click listener inside of a timeout because, if this open call was triggered by a
  7646. // click, we don't want it to be immediately propogated up to the body and handled.
  7647. var self = this;
  7648. this.$mdUtil.nextTick(function() {
  7649. document.body.addEventListener('click', self.bodyClickHandler);
  7650. }, false);
  7651. window.addEventListener('resize', this.windowResizeHandler);
  7652. }
  7653. };
  7654. /** Close the floating calendar pane. */
  7655. DatePickerCtrl.prototype.closeCalendarPane = function() {
  7656. if (this.isCalendarOpen) {
  7657. this.isCalendarOpen = false;
  7658. this.detachCalendarPane();
  7659. this.calendarPaneOpenedFrom.focus();
  7660. this.calendarPaneOpenedFrom = null;
  7661. this.$mdUtil.enableScrolling();
  7662. document.body.removeEventListener('click', this.bodyClickHandler);
  7663. window.removeEventListener('resize', this.windowResizeHandler);
  7664. }
  7665. };
  7666. /** Gets the controller instance for the calendar in the floating pane. */
  7667. DatePickerCtrl.prototype.getCalendarCtrl = function() {
  7668. return angular.element(this.calendarPane.querySelector('md-calendar')).controller('mdCalendar');
  7669. };
  7670. /** Focus the calendar in the floating pane. */
  7671. DatePickerCtrl.prototype.focusCalendar = function() {
  7672. // Use a timeout in order to allow the calendar to be rendered, as it is gated behind an ng-if.
  7673. var self = this;
  7674. this.$mdUtil.nextTick(function() {
  7675. self.getCalendarCtrl().focus();
  7676. }, false);
  7677. };
  7678. /**
  7679. * Sets whether the input is currently focused.
  7680. * @param {boolean} isFocused
  7681. */
  7682. DatePickerCtrl.prototype.setFocused = function(isFocused) {
  7683. this.isFocused = isFocused;
  7684. };
  7685. /**
  7686. * Handles a click on the document body when the floating calendar pane is open.
  7687. * Closes the floating calendar pane if the click is not inside of it.
  7688. * @param {MouseEvent} event
  7689. */
  7690. DatePickerCtrl.prototype.handleBodyClick = function(event) {
  7691. if (this.isCalendarOpen) {
  7692. // TODO(jelbourn): way want to also include the md-datepicker itself in this check.
  7693. var isInCalendar = this.$mdUtil.getClosest(event.target, 'md-calendar');
  7694. if (!isInCalendar) {
  7695. this.closeCalendarPane();
  7696. }
  7697. this.$scope.$digest();
  7698. }
  7699. };
  7700. })();
  7701. })();
  7702. (function(){
  7703. "use strict";
  7704. (function() {
  7705. 'use strict';
  7706. /**
  7707. * Utility for performing date calculations to facilitate operation of the calendar and
  7708. * datepicker.
  7709. */
  7710. angular.module('material.components.datepicker').factory('$$mdDateUtil', function() {
  7711. return {
  7712. getFirstDateOfMonth: getFirstDateOfMonth,
  7713. getNumberOfDaysInMonth: getNumberOfDaysInMonth,
  7714. getDateInNextMonth: getDateInNextMonth,
  7715. getDateInPreviousMonth: getDateInPreviousMonth,
  7716. isInNextMonth: isInNextMonth,
  7717. isInPreviousMonth: isInPreviousMonth,
  7718. getDateMidpoint: getDateMidpoint,
  7719. isSameMonthAndYear: isSameMonthAndYear,
  7720. getWeekOfMonth: getWeekOfMonth,
  7721. incrementDays: incrementDays,
  7722. incrementMonths: incrementMonths,
  7723. getLastDateOfMonth: getLastDateOfMonth,
  7724. isSameDay: isSameDay,
  7725. getMonthDistance: getMonthDistance,
  7726. isValidDate: isValidDate,
  7727. setDateTimeToMidnight: setDateTimeToMidnight,
  7728. createDateAtMidnight: createDateAtMidnight,
  7729. isDateWithinRange: isDateWithinRange
  7730. };
  7731. /**
  7732. * Gets the first day of the month for the given date's month.
  7733. * @param {Date} date
  7734. * @returns {Date}
  7735. */
  7736. function getFirstDateOfMonth(date) {
  7737. return new Date(date.getFullYear(), date.getMonth(), 1);
  7738. }
  7739. /**
  7740. * Gets the number of days in the month for the given date's month.
  7741. * @param date
  7742. * @returns {number}
  7743. */
  7744. function getNumberOfDaysInMonth(date) {
  7745. return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
  7746. }
  7747. /**
  7748. * Get an arbitrary date in the month after the given date's month.
  7749. * @param date
  7750. * @returns {Date}
  7751. */
  7752. function getDateInNextMonth(date) {
  7753. return new Date(date.getFullYear(), date.getMonth() + 1, 1);
  7754. }
  7755. /**
  7756. * Get an arbitrary date in the month before the given date's month.
  7757. * @param date
  7758. * @returns {Date}
  7759. */
  7760. function getDateInPreviousMonth(date) {
  7761. return new Date(date.getFullYear(), date.getMonth() - 1, 1);
  7762. }
  7763. /**
  7764. * Gets whether two dates have the same month and year.
  7765. * @param {Date} d1
  7766. * @param {Date} d2
  7767. * @returns {boolean}
  7768. */
  7769. function isSameMonthAndYear(d1, d2) {
  7770. return d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth();
  7771. }
  7772. /**
  7773. * Gets whether two dates are the same day (not not necesarily the same time).
  7774. * @param {Date} d1
  7775. * @param {Date} d2
  7776. * @returns {boolean}
  7777. */
  7778. function isSameDay(d1, d2) {
  7779. return d1.getDate() == d2.getDate() && isSameMonthAndYear(d1, d2);
  7780. }
  7781. /**
  7782. * Gets whether a date is in the month immediately after some date.
  7783. * @param {Date} startDate The date from which to compare.
  7784. * @param {Date} endDate The date to check.
  7785. * @returns {boolean}
  7786. */
  7787. function isInNextMonth(startDate, endDate) {
  7788. var nextMonth = getDateInNextMonth(startDate);
  7789. return isSameMonthAndYear(nextMonth, endDate);
  7790. }
  7791. /**
  7792. * Gets whether a date is in the month immediately before some date.
  7793. * @param {Date} startDate The date from which to compare.
  7794. * @param {Date} endDate The date to check.
  7795. * @returns {boolean}
  7796. */
  7797. function isInPreviousMonth(startDate, endDate) {
  7798. var previousMonth = getDateInPreviousMonth(startDate);
  7799. return isSameMonthAndYear(endDate, previousMonth);
  7800. }
  7801. /**
  7802. * Gets the midpoint between two dates.
  7803. * @param {Date} d1
  7804. * @param {Date} d2
  7805. * @returns {Date}
  7806. */
  7807. function getDateMidpoint(d1, d2) {
  7808. return createDateAtMidnight((d1.getTime() + d2.getTime()) / 2);
  7809. }
  7810. /**
  7811. * Gets the week of the month that a given date occurs in.
  7812. * @param {Date} date
  7813. * @returns {number} Index of the week of the month (zero-based).
  7814. */
  7815. function getWeekOfMonth(date) {
  7816. var firstDayOfMonth = getFirstDateOfMonth(date);
  7817. return Math.floor((firstDayOfMonth.getDay() + date.getDate() - 1) / 7);
  7818. }
  7819. /**
  7820. * Gets a new date incremented by the given number of days. Number of days can be negative.
  7821. * @param {Date} date
  7822. * @param {number} numberOfDays
  7823. * @returns {Date}
  7824. */
  7825. function incrementDays(date, numberOfDays) {
  7826. return new Date(date.getFullYear(), date.getMonth(), date.getDate() + numberOfDays);
  7827. }
  7828. /**
  7829. * Gets a new date incremented by the given number of months. Number of months can be negative.
  7830. * If the date of the given month does not match the target month, the date will be set to the
  7831. * last day of the month.
  7832. * @param {Date} date
  7833. * @param {number} numberOfMonths
  7834. * @returns {Date}
  7835. */
  7836. function incrementMonths(date, numberOfMonths) {
  7837. // If the same date in the target month does not actually exist, the Date object will
  7838. // automatically advance *another* month by the number of missing days.
  7839. // For example, if you try to go from Jan. 30 to Feb. 30, you'll end up on March 2.
  7840. // So, we check if the month overflowed and go to the last day of the target month instead.
  7841. var dateInTargetMonth = new Date(date.getFullYear(), date.getMonth() + numberOfMonths, 1);
  7842. var numberOfDaysInMonth = getNumberOfDaysInMonth(dateInTargetMonth);
  7843. if (numberOfDaysInMonth < date.getDate()) {
  7844. dateInTargetMonth.setDate(numberOfDaysInMonth);
  7845. } else {
  7846. dateInTargetMonth.setDate(date.getDate());
  7847. }
  7848. return dateInTargetMonth;
  7849. }
  7850. /**
  7851. * Get the integer distance between two months. This *only* considers the month and year
  7852. * portion of the Date instances.
  7853. *
  7854. * @param {Date} start
  7855. * @param {Date} end
  7856. * @returns {number} Number of months between `start` and `end`. If `end` is before `start`
  7857. * chronologically, this number will be negative.
  7858. */
  7859. function getMonthDistance(start, end) {
  7860. return (12 * (end.getFullYear() - start.getFullYear())) + (end.getMonth() - start.getMonth());
  7861. }
  7862. /**
  7863. * Gets the last day of the month for the given date.
  7864. * @param {Date} date
  7865. * @returns {Date}
  7866. */
  7867. function getLastDateOfMonth(date) {
  7868. return new Date(date.getFullYear(), date.getMonth(), getNumberOfDaysInMonth(date));
  7869. }
  7870. /**
  7871. * Checks whether a date is valid.
  7872. * @param {Date} date
  7873. * @return {boolean} Whether the date is a valid Date.
  7874. */
  7875. function isValidDate(date) {
  7876. return date != null && date.getTime && !isNaN(date.getTime());
  7877. }
  7878. /**
  7879. * Sets a date's time to midnight.
  7880. * @param {Date} date
  7881. */
  7882. function setDateTimeToMidnight(date) {
  7883. if (isValidDate(date)) {
  7884. date.setHours(0, 0, 0, 0);
  7885. }
  7886. }
  7887. /**
  7888. * Creates a date with the time set to midnight.
  7889. * Drop-in replacement for two forms of the Date constructor:
  7890. * 1. No argument for Date representing now.
  7891. * 2. Single-argument value representing number of seconds since Unix Epoch.
  7892. * @param {number=} opt_value
  7893. * @return {Date} New date with time set to midnight.
  7894. */
  7895. function createDateAtMidnight(opt_value) {
  7896. var date;
  7897. if (angular.isUndefined(opt_value)) {
  7898. date = new Date();
  7899. } else {
  7900. date = new Date(opt_value);
  7901. }
  7902. setDateTimeToMidnight(date);
  7903. return date;
  7904. }
  7905. /**
  7906. * Checks if a date is within a min and max range.
  7907. * If minDate or maxDate are not dates, they are ignored.
  7908. * @param {Date} date
  7909. * @param {Date} minDate
  7910. * @param {Date} maxDate
  7911. */
  7912. function isDateWithinRange(date, minDate, maxDate) {
  7913. return (!angular.isDate(minDate) || minDate <= date) &&
  7914. (!angular.isDate(maxDate) || maxDate >= date);
  7915. }
  7916. });
  7917. })();
  7918. })();
  7919. (function(){
  7920. "use strict";
  7921. (function() {
  7922. 'use strict';
  7923. /**
  7924. * @ngdoc module
  7925. * @name material.components.fabActions
  7926. */
  7927. angular
  7928. .module('material.components.fabActions', ['material.core'])
  7929. .directive('mdFabActions', MdFabActionsDirective);
  7930. /**
  7931. * @ngdoc directive
  7932. * @name mdFabActions
  7933. * @module material.components.fabActions
  7934. *
  7935. * @restrict E
  7936. *
  7937. * @description
  7938. * The `<md-fab-actions>` directive is used inside of a `<md-fab-speed-dial>` or
  7939. * `<md-fab-toolbar>` directive to mark an element (or elements) as the actions and setup the
  7940. * proper event listeners.
  7941. *
  7942. * @usage
  7943. * See the `<md-fab-speed-dial>` or `<md-fab-toolbar>` directives for example usage.
  7944. */
  7945. function MdFabActionsDirective() {
  7946. return {
  7947. restrict: 'E',
  7948. require: ['^?mdFabSpeedDial', '^?mdFabToolbar'],
  7949. compile: function(element, attributes) {
  7950. var children = element.children();
  7951. var hasNgRepeat = false;
  7952. angular.forEach(['', 'data-', 'x-'], function(prefix) {
  7953. hasNgRepeat = hasNgRepeat || (children.attr(prefix + 'ng-repeat') ? true : false);
  7954. });
  7955. // Support both ng-repeat and static content
  7956. if (hasNgRepeat) {
  7957. children.addClass('md-fab-action-item');
  7958. } else {
  7959. // Wrap every child in a new div and add a class that we can scale/fling independently
  7960. children.wrap('<div class="md-fab-action-item">');
  7961. }
  7962. }
  7963. }
  7964. }
  7965. })();
  7966. })();
  7967. (function(){
  7968. "use strict";
  7969. (function() {
  7970. 'use strict';
  7971. angular.module('material.components.fabShared', ['material.core'])
  7972. .controller('FabController', FabController);
  7973. function FabController($scope, $element, $animate, $mdUtil, $mdConstant) {
  7974. var vm = this;
  7975. // NOTE: We use async evals below to avoid conflicts with any existing digest loops
  7976. vm.open = function() {
  7977. $scope.$evalAsync("vm.isOpen = true");
  7978. };
  7979. vm.close = function() {
  7980. // Async eval to avoid conflicts with existing digest loops
  7981. $scope.$evalAsync("vm.isOpen = false");
  7982. // Focus the trigger when the element closes so users can still tab to the next item
  7983. $element.find('md-fab-trigger')[0].focus();
  7984. };
  7985. // Toggle the open/close state when the trigger is clicked
  7986. vm.toggle = function() {
  7987. $scope.$evalAsync("vm.isOpen = !vm.isOpen");
  7988. };
  7989. setupDefaults();
  7990. setupListeners();
  7991. setupWatchers();
  7992. fireInitialAnimations();
  7993. function setupDefaults() {
  7994. // Set the default direction to 'down' if none is specified
  7995. vm.direction = vm.direction || 'down';
  7996. // Set the default to be closed
  7997. vm.isOpen = vm.isOpen || false;
  7998. // Start the keyboard interaction at the first action
  7999. resetActionIndex();
  8000. }
  8001. var events = [];
  8002. function setupListeners() {
  8003. var eventTypes = [
  8004. 'mousedown', 'mouseup', 'click', 'touchstart', 'touchend', 'focusin', 'focusout'
  8005. ];
  8006. // Add our listeners
  8007. angular.forEach(eventTypes, function(eventType) {
  8008. $element.on(eventType, parseEvents);
  8009. });
  8010. // Remove our listeners when destroyed
  8011. $scope.$on('$destroy', function() {
  8012. angular.forEach(eventTypes, function(eventType) {
  8013. $element.off(eventType, parseEvents);
  8014. });
  8015. // remove any attached keyboard handlers in case element is removed while
  8016. // speed dial is open
  8017. disableKeyboard();
  8018. });
  8019. }
  8020. function resetEvents() {
  8021. events = [];
  8022. }
  8023. function equalsEvents(toCheck) {
  8024. var isEqual, strippedCheck, moreToCheck;
  8025. // Quick check to make sure we don't get stuck in an infinite loop
  8026. var numTests = 0;
  8027. do {
  8028. // Strip out the question mark
  8029. strippedCheck = toCheck.map(function(event) {
  8030. return event.replace('?', '')
  8031. });
  8032. // Check if they are equal
  8033. isEqual = angular.equals(events, strippedCheck);
  8034. // If not, check to see if removing an optional event makes them equal
  8035. if (!isEqual) {
  8036. toCheck = removeOptionalEvent(toCheck);
  8037. moreToCheck = (toCheck.length >= events.length && toCheck.length !== strippedCheck.length);
  8038. }
  8039. }
  8040. while (numTests < 10 && !isEqual && moreToCheck);
  8041. return isEqual;
  8042. }
  8043. function removeOptionalEvent(events) {
  8044. var foundOptional = false;
  8045. return events.filter(function(event) {
  8046. // If we have not found an optional one, keep searching
  8047. if (!foundOptional && event.indexOf('?') !== -1) {
  8048. foundOptional = true;
  8049. // If we find an optional one, remove only that one and keep going
  8050. return false;
  8051. }
  8052. return true;
  8053. });
  8054. }
  8055. function parseEvents(latestEvent) {
  8056. events.push(latestEvent.type);
  8057. // Handle desktop click
  8058. if (equalsEvents(['mousedown', 'focusout?', 'focusin?', 'mouseup', 'click'])) {
  8059. handleItemClick(latestEvent);
  8060. resetEvents();
  8061. return;
  8062. }
  8063. // Handle mobile click/tap (and keyboard enter)
  8064. if (equalsEvents(['touchstart?', 'touchend?', 'click'])) {
  8065. handleItemClick(latestEvent);
  8066. resetEvents();
  8067. return;
  8068. }
  8069. // Handle tab keys (focusin)
  8070. if (equalsEvents(['focusin'])) {
  8071. vm.open();
  8072. resetEvents();
  8073. return;
  8074. }
  8075. // Handle tab keys (focusout)
  8076. if (equalsEvents(['focusout'])) {
  8077. vm.close();
  8078. resetEvents();
  8079. return;
  8080. }
  8081. eventUnhandled();
  8082. }
  8083. /*
  8084. * No event was handled, so setup a timeout to clear the events
  8085. *
  8086. * TODO: Use $mdUtil.debounce()?
  8087. */
  8088. var resetEventsTimeout;
  8089. function eventUnhandled() {
  8090. if (resetEventsTimeout) {
  8091. window.clearTimeout(resetEventsTimeout);
  8092. }
  8093. resetEventsTimeout = window.setTimeout(function() {
  8094. resetEvents();
  8095. }, 250);
  8096. }
  8097. function resetActionIndex() {
  8098. vm.currentActionIndex = -1;
  8099. }
  8100. function setupWatchers() {
  8101. // Watch for changes to the direction and update classes/attributes
  8102. $scope.$watch('vm.direction', function(newDir, oldDir) {
  8103. // Add the appropriate classes so we can target the direction in the CSS
  8104. $animate.removeClass($element, 'md-' + oldDir);
  8105. $animate.addClass($element, 'md-' + newDir);
  8106. // Reset the action index since it may have changed
  8107. resetActionIndex();
  8108. });
  8109. var trigger, actions;
  8110. // Watch for changes to md-open
  8111. $scope.$watch('vm.isOpen', function(isOpen) {
  8112. // Reset the action index since it may have changed
  8113. resetActionIndex();
  8114. // We can't get the trigger/actions outside of the watch because the component hasn't been
  8115. // linked yet, so we wait until the first watch fires to cache them.
  8116. if (!trigger || !actions) {
  8117. trigger = getTriggerElement();
  8118. actions = getActionsElement();
  8119. }
  8120. if (isOpen) {
  8121. enableKeyboard();
  8122. } else {
  8123. disableKeyboard();
  8124. }
  8125. var toAdd = isOpen ? 'md-is-open' : '';
  8126. var toRemove = isOpen ? '' : 'md-is-open';
  8127. // Set the proper ARIA attributes
  8128. trigger.attr('aria-haspopup', true);
  8129. trigger.attr('aria-expanded', isOpen);
  8130. actions.attr('aria-hidden', !isOpen);
  8131. // Animate the CSS classes
  8132. $animate.setClass($element, toAdd, toRemove);
  8133. });
  8134. }
  8135. // Fire the animations once in a separate digest loop to initialize them
  8136. function fireInitialAnimations() {
  8137. $mdUtil.nextTick(function() {
  8138. $animate.addClass($element, 'md-noop');
  8139. });
  8140. }
  8141. function enableKeyboard() {
  8142. angular.element(document).on('keydown', keyPressed);
  8143. }
  8144. function disableKeyboard() {
  8145. angular.element(document).off('keydown', keyPressed);
  8146. }
  8147. function keyPressed(event) {
  8148. switch (event.which) {
  8149. case $mdConstant.KEY_CODE.SPACE: event.preventDefault(); return false;
  8150. case $mdConstant.KEY_CODE.ESCAPE: vm.close(); event.preventDefault(); return false;
  8151. case $mdConstant.KEY_CODE.LEFT_ARROW: doKeyLeft(event); return false;
  8152. case $mdConstant.KEY_CODE.UP_ARROW: doKeyUp(event); return false;
  8153. case $mdConstant.KEY_CODE.RIGHT_ARROW: doKeyRight(event); return false;
  8154. case $mdConstant.KEY_CODE.DOWN_ARROW: doKeyDown(event); return false;
  8155. }
  8156. }
  8157. function doActionPrev(event) {
  8158. focusAction(event, -1);
  8159. }
  8160. function doActionNext(event) {
  8161. focusAction(event, 1);
  8162. }
  8163. function focusAction(event, direction) {
  8164. // Grab all of the actions
  8165. var actions = getActionsElement()[0].querySelectorAll('.md-fab-action-item');
  8166. // Disable all other actions for tabbing
  8167. angular.forEach(actions, function(action) {
  8168. angular.element(angular.element(action).children()[0]).attr('tabindex', -1);
  8169. });
  8170. // Increment/decrement the counter with restrictions
  8171. vm.currentActionIndex = vm.currentActionIndex + direction;
  8172. vm.currentActionIndex = Math.min(actions.length - 1, vm.currentActionIndex);
  8173. vm.currentActionIndex = Math.max(0, vm.currentActionIndex);
  8174. // Focus the element
  8175. var focusElement = angular.element(actions[vm.currentActionIndex]).children()[0];
  8176. angular.element(focusElement).attr('tabindex', 0);
  8177. focusElement.focus();
  8178. // Make sure the event doesn't bubble and cause something else
  8179. event.preventDefault();
  8180. event.stopImmediatePropagation();
  8181. }
  8182. function doKeyLeft(event) {
  8183. if (vm.direction === 'left') {
  8184. doActionNext(event);
  8185. } else {
  8186. doActionPrev(event);
  8187. }
  8188. }
  8189. function doKeyUp(event) {
  8190. if (vm.direction === 'down') {
  8191. doActionPrev(event);
  8192. } else {
  8193. doActionNext(event);
  8194. }
  8195. }
  8196. function doKeyRight(event) {
  8197. if (vm.direction === 'left') {
  8198. doActionPrev(event);
  8199. } else {
  8200. doActionNext(event);
  8201. }
  8202. }
  8203. function doKeyDown(event) {
  8204. if (vm.direction === 'up') {
  8205. doActionPrev(event);
  8206. } else {
  8207. doActionNext(event);
  8208. }
  8209. }
  8210. function isTrigger(element) {
  8211. return $mdUtil.getClosest(element, 'md-fab-trigger');
  8212. }
  8213. function isAction(element) {
  8214. return $mdUtil.getClosest(element, 'md-fab-actions');
  8215. }
  8216. function handleItemClick(event) {
  8217. if (isTrigger(event.target)) {
  8218. vm.toggle();
  8219. }
  8220. if (isAction(event.target)) {
  8221. vm.close();
  8222. }
  8223. }
  8224. function getTriggerElement() {
  8225. return $element.find('md-fab-trigger');
  8226. }
  8227. function getActionsElement() {
  8228. return $element.find('md-fab-actions');
  8229. }
  8230. }
  8231. FabController.$inject = ["$scope", "$element", "$animate", "$mdUtil", "$mdConstant"];
  8232. })();
  8233. })();
  8234. (function(){
  8235. "use strict";
  8236. (function() {
  8237. 'use strict';
  8238. /**
  8239. * @ngdoc module
  8240. * @name material.components.fabSpeedDial
  8241. */
  8242. angular
  8243. // Declare our module
  8244. .module('material.components.fabSpeedDial', [
  8245. 'material.core',
  8246. 'material.components.fabShared',
  8247. 'material.components.fabTrigger',
  8248. 'material.components.fabActions'
  8249. ])
  8250. // Register our directive
  8251. .directive('mdFabSpeedDial', MdFabSpeedDialDirective)
  8252. // Register our custom animations
  8253. .animation('.md-fling', MdFabSpeedDialFlingAnimation)
  8254. .animation('.md-scale', MdFabSpeedDialScaleAnimation)
  8255. // Register a service for each animation so that we can easily inject them into unit tests
  8256. .service('mdFabSpeedDialFlingAnimation', MdFabSpeedDialFlingAnimation)
  8257. .service('mdFabSpeedDialScaleAnimation', MdFabSpeedDialScaleAnimation);
  8258. /**
  8259. * @ngdoc directive
  8260. * @name mdFabSpeedDial
  8261. * @module material.components.fabSpeedDial
  8262. *
  8263. * @restrict E
  8264. *
  8265. * @description
  8266. * The `<md-fab-speed-dial>` directive is used to present a series of popup elements (usually
  8267. * `<md-button>`s) for quick access to common actions.
  8268. *
  8269. * There are currently two animations available by applying one of the following classes to
  8270. * the component:
  8271. *
  8272. * - `md-fling` - The speed dial items appear from underneath the trigger and move into their
  8273. * appropriate positions.
  8274. * - `md-scale` - The speed dial items appear in their proper places by scaling from 0% to 100%.
  8275. *
  8276. * You may also easily position the trigger by applying one one of the following classes to the
  8277. * `<md-fab-speed-dial>` element:
  8278. * - `md-fab-top-left`
  8279. * - `md-fab-top-right`
  8280. * - `md-fab-bottom-left`
  8281. * - `md-fab-bottom-right`
  8282. *
  8283. * These CSS classes use `position: absolute`, so you need to ensure that the container element
  8284. * also uses `position: absolute` or `position: relative` in order for them to work.
  8285. *
  8286. * Additionally, you may use the standard `ng-mouseenter` and `ng-mouseleave` directives to
  8287. * open or close the speed dial. However, if you wish to allow users to hover over the empty
  8288. * space where the actions will appear, you must also add the `md-hover-full` class to the speed
  8289. * dial element. Without this, the hover effect will only occur on top of the trigger.
  8290. *
  8291. * @usage
  8292. * <hljs lang="html">
  8293. * <md-fab-speed-dial md-direction="up" class="md-fling">
  8294. * <md-fab-trigger>
  8295. * <md-button aria-label="Add..."><md-icon icon="/img/icons/plus.svg"></md-icon></md-button>
  8296. * </md-fab-trigger>
  8297. *
  8298. * <md-fab-actions>
  8299. * <md-button aria-label="Add User">
  8300. * <md-icon icon="/img/icons/user.svg"></md-icon>
  8301. * </md-button>
  8302. *
  8303. * <md-button aria-label="Add Group">
  8304. * <md-icon icon="/img/icons/group.svg"></md-icon>
  8305. * </md-button>
  8306. * </md-fab-actions>
  8307. * </md-fab-speed-dial>
  8308. * </hljs>
  8309. *
  8310. * @param {string} md-direction From which direction you would like the speed dial to appear
  8311. * relative to the trigger element.
  8312. * @param {expression=} md-open Programmatically control whether or not the speed-dial is visible.
  8313. */
  8314. function MdFabSpeedDialDirective() {
  8315. return {
  8316. restrict: 'E',
  8317. scope: {
  8318. direction: '@?mdDirection',
  8319. isOpen: '=?mdOpen'
  8320. },
  8321. bindToController: true,
  8322. controller: 'FabController',
  8323. controllerAs: 'vm',
  8324. link: FabSpeedDialLink
  8325. };
  8326. function FabSpeedDialLink(scope, element) {
  8327. // Prepend an element to hold our CSS variables so we can use them in the animations below
  8328. element.prepend('<div class="md-css-variables"></div>');
  8329. }
  8330. }
  8331. function MdFabSpeedDialFlingAnimation() {
  8332. function runAnimation(element) {
  8333. var el = element[0];
  8334. var ctrl = element.controller('mdFabSpeedDial');
  8335. var items = el.querySelectorAll('.md-fab-action-item');
  8336. // Grab our trigger element
  8337. var triggerElement = el.querySelector('md-fab-trigger');
  8338. // Grab our element which stores CSS variables
  8339. var variablesElement = el.querySelector('.md-css-variables');
  8340. // Setup JS variables based on our CSS variables
  8341. var startZIndex = parseInt(window.getComputedStyle(variablesElement).zIndex);
  8342. // Always reset the items to their natural position/state
  8343. angular.forEach(items, function(item, index) {
  8344. var styles = item.style;
  8345. styles.transform = styles.webkitTransform = '';
  8346. styles.transitionDelay = '';
  8347. styles.opacity = 1;
  8348. // Make the items closest to the trigger have the highest z-index
  8349. styles.zIndex = (items.length - index) + startZIndex;
  8350. });
  8351. // Set the trigger to be above all of the actions so they disappear behind it.
  8352. triggerElement.style.zIndex = startZIndex + items.length + 1;
  8353. // If the control is closed, hide the items behind the trigger
  8354. if (!ctrl.isOpen) {
  8355. angular.forEach(items, function(item, index) {
  8356. var newPosition, axis;
  8357. var styles = item.style;
  8358. switch (ctrl.direction) {
  8359. case 'up':
  8360. newPosition = item.scrollHeight * (index + 1);
  8361. axis = 'Y';
  8362. break;
  8363. case 'down':
  8364. newPosition = -item.scrollHeight * (index + 1);
  8365. axis = 'Y';
  8366. break;
  8367. case 'left':
  8368. newPosition = item.scrollWidth * (index + 1);
  8369. axis = 'X';
  8370. break;
  8371. case 'right':
  8372. newPosition = -item.scrollWidth * (index + 1);
  8373. axis = 'X';
  8374. break;
  8375. }
  8376. var newTranslate = 'translate' + axis + '(' + newPosition + 'px)';
  8377. styles.transform = styles.webkitTransform = newTranslate;
  8378. });
  8379. }
  8380. }
  8381. return {
  8382. addClass: function(element, className, done) {
  8383. if (element.hasClass('md-fling')) {
  8384. runAnimation(element);
  8385. done();
  8386. }
  8387. },
  8388. removeClass: function(element, className, done) {
  8389. runAnimation(element);
  8390. done();
  8391. }
  8392. }
  8393. }
  8394. function MdFabSpeedDialScaleAnimation() {
  8395. var delay = 65;
  8396. function runAnimation(element) {
  8397. var el = element[0];
  8398. var ctrl = element.controller('mdFabSpeedDial');
  8399. var items = el.querySelectorAll('.md-fab-action-item');
  8400. // Grab our element which stores CSS variables
  8401. var variablesElement = el.querySelector('.md-css-variables');
  8402. // Setup JS variables based on our CSS variables
  8403. var startZIndex = parseInt(window.getComputedStyle(variablesElement).zIndex);
  8404. // Always reset the items to their natural position/state
  8405. angular.forEach(items, function(item, index) {
  8406. var styles = item.style,
  8407. offsetDelay = index * delay;
  8408. styles.opacity = ctrl.isOpen ? 1 : 0;
  8409. styles.transform = styles.webkitTransform = ctrl.isOpen ? 'scale(1)' : 'scale(0)';
  8410. styles.transitionDelay = (ctrl.isOpen ? offsetDelay : (items.length - offsetDelay)) + 'ms';
  8411. // Make the items closest to the trigger have the highest z-index
  8412. styles.zIndex = (items.length - index) + startZIndex;
  8413. });
  8414. }
  8415. return {
  8416. addClass: function(element, className, done) {
  8417. runAnimation(element);
  8418. done();
  8419. },
  8420. removeClass: function(element, className, done) {
  8421. runAnimation(element);
  8422. done();
  8423. }
  8424. }
  8425. }
  8426. })();
  8427. })();
  8428. (function(){
  8429. "use strict";
  8430. (function() {
  8431. 'use strict';
  8432. /**
  8433. * @ngdoc module
  8434. * @name material.components.fabToolbar
  8435. */
  8436. angular
  8437. // Declare our module
  8438. .module('material.components.fabToolbar', [
  8439. 'material.core',
  8440. 'material.components.fabShared',
  8441. 'material.components.fabTrigger',
  8442. 'material.components.fabActions'
  8443. ])
  8444. // Register our directive
  8445. .directive('mdFabToolbar', MdFabToolbarDirective)
  8446. // Register our custom animations
  8447. .animation('.md-fab-toolbar', MdFabToolbarAnimation)
  8448. // Register a service for the animation so that we can easily inject it into unit tests
  8449. .service('mdFabToolbarAnimation', MdFabToolbarAnimation);
  8450. /**
  8451. * @ngdoc directive
  8452. * @name mdFabToolbar
  8453. * @module material.components.fabToolbar
  8454. *
  8455. * @restrict E
  8456. *
  8457. * @description
  8458. *
  8459. * The `<md-fab-toolbar>` directive is used present a toolbar of elements (usually `<md-button>`s)
  8460. * for quick access to common actions when a floating action button is activated (via click or
  8461. * keyboard navigation).
  8462. *
  8463. * You may also easily position the trigger by applying one one of the following classes to the
  8464. * `<md-fab-toolbar>` element:
  8465. * - `md-fab-top-left`
  8466. * - `md-fab-top-right`
  8467. * - `md-fab-bottom-left`
  8468. * - `md-fab-bottom-right`
  8469. *
  8470. * These CSS classes use `position: absolute`, so you need to ensure that the container element
  8471. * also uses `position: absolute` or `position: relative` in order for them to work.
  8472. *
  8473. * @usage
  8474. *
  8475. * <hljs lang="html">
  8476. * <md-fab-toolbar md-direction='left'>
  8477. * <md-fab-trigger>
  8478. * <md-button aria-label="Add..."><md-icon icon="/img/icons/plus.svg"></md-icon></md-button>
  8479. * </md-fab-trigger>
  8480. *
  8481. * <md-fab-actions>
  8482. * <md-button aria-label="Add User">
  8483. * <md-icon icon="/img/icons/user.svg"></md-icon>
  8484. * </md-button>
  8485. *
  8486. * <md-button aria-label="Add Group">
  8487. * <md-icon icon="/img/icons/group.svg"></md-icon>
  8488. * </md-button>
  8489. * </md-fab-actions>
  8490. * </md-fab-toolbar>
  8491. * </hljs>
  8492. *
  8493. * @param {string} md-direction From which direction you would like the toolbar items to appear
  8494. * relative to the trigger element. Supports `left` and `right` directions.
  8495. * @param {expression=} md-open Programmatically control whether or not the toolbar is visible.
  8496. */
  8497. function MdFabToolbarDirective() {
  8498. return {
  8499. restrict: 'E',
  8500. transclude: true,
  8501. template: '<div class="md-fab-toolbar-wrapper">' +
  8502. ' <div class="md-fab-toolbar-content" ng-transclude></div>' +
  8503. '</div>',
  8504. scope: {
  8505. direction: '@?mdDirection',
  8506. isOpen: '=?mdOpen'
  8507. },
  8508. bindToController: true,
  8509. controller: 'FabController',
  8510. controllerAs: 'vm',
  8511. link: link
  8512. };
  8513. function link(scope, element, attributes) {
  8514. // Add the base class for animations
  8515. element.addClass('md-fab-toolbar');
  8516. // Prepend the background element to the trigger's button
  8517. element.find('md-fab-trigger').find('button')
  8518. .prepend('<div class="md-fab-toolbar-background"></div>');
  8519. }
  8520. }
  8521. function MdFabToolbarAnimation() {
  8522. function runAnimation(element, className, done) {
  8523. // If no className was specified, don't do anything
  8524. if (!className) {
  8525. return;
  8526. }
  8527. var el = element[0];
  8528. var ctrl = element.controller('mdFabToolbar');
  8529. // Grab the relevant child elements
  8530. var backgroundElement = el.querySelector('.md-fab-toolbar-background');
  8531. var triggerElement = el.querySelector('md-fab-trigger button');
  8532. var toolbarElement = el.querySelector('md-toolbar');
  8533. var iconElement = el.querySelector('md-fab-trigger button md-icon');
  8534. var actions = element.find('md-fab-actions').children();
  8535. // If we have both elements, use them to position the new background
  8536. if (triggerElement && backgroundElement) {
  8537. // Get our variables
  8538. var color = window.getComputedStyle(triggerElement).getPropertyValue('background-color');
  8539. var width = el.offsetWidth;
  8540. var height = el.offsetHeight;
  8541. // Make it twice as big as it should be since we scale from the center
  8542. var scale = 2 * (width / triggerElement.offsetWidth);
  8543. // Set some basic styles no matter what animation we're doing
  8544. backgroundElement.style.backgroundColor = color;
  8545. backgroundElement.style.borderRadius = width + 'px';
  8546. // If we're open
  8547. if (ctrl.isOpen) {
  8548. // Turn on toolbar pointer events when closed
  8549. toolbarElement.style.pointerEvents = 'initial';
  8550. backgroundElement.style.width = triggerElement.offsetWidth + 'px';
  8551. backgroundElement.style.height = triggerElement.offsetHeight + 'px';
  8552. backgroundElement.style.transform = 'scale(' + scale + ')';
  8553. // Set the next close animation to have the proper delays
  8554. backgroundElement.style.transitionDelay = '0ms';
  8555. iconElement && (iconElement.style.transitionDelay = '.3s');
  8556. // Apply a transition delay to actions
  8557. angular.forEach(actions, function(action, index) {
  8558. action.style.transitionDelay = (actions.length - index) * 25 + 'ms';
  8559. });
  8560. } else {
  8561. // Turn off toolbar pointer events when closed
  8562. toolbarElement.style.pointerEvents = 'none';
  8563. // Scale it back down to the trigger's size
  8564. backgroundElement.style.transform = 'scale(1)';
  8565. // Reset the position
  8566. backgroundElement.style.top = '0';
  8567. if (element.hasClass('md-right')) {
  8568. backgroundElement.style.left = '0';
  8569. backgroundElement.style.right = null;
  8570. }
  8571. if (element.hasClass('md-left')) {
  8572. backgroundElement.style.right = '0';
  8573. backgroundElement.style.left = null;
  8574. }
  8575. // Set the next open animation to have the proper delays
  8576. backgroundElement.style.transitionDelay = '200ms';
  8577. iconElement && (iconElement.style.transitionDelay = '0ms');
  8578. // Apply a transition delay to actions
  8579. angular.forEach(actions, function(action, index) {
  8580. action.style.transitionDelay = 200 + (index * 25) + 'ms';
  8581. });
  8582. }
  8583. }
  8584. }
  8585. return {
  8586. addClass: function(element, className, done) {
  8587. runAnimation(element, className, done);
  8588. done();
  8589. },
  8590. removeClass: function(element, className, done) {
  8591. runAnimation(element, className, done);
  8592. done();
  8593. }
  8594. }
  8595. }
  8596. })();
  8597. })();
  8598. (function(){
  8599. "use strict";
  8600. (function() {
  8601. 'use strict';
  8602. /**
  8603. * @ngdoc module
  8604. * @name material.components.fabTrigger
  8605. */
  8606. angular
  8607. .module('material.components.fabTrigger', ['material.core'])
  8608. .directive('mdFabTrigger', MdFabTriggerDirective);
  8609. /**
  8610. * @ngdoc directive
  8611. * @name mdFabTrigger
  8612. * @module material.components.fabSpeedDial
  8613. *
  8614. * @restrict E
  8615. *
  8616. * @description
  8617. * The `<md-fab-trigger>` directive is used inside of a `<md-fab-speed-dial>` or
  8618. * `<md-fab-toolbar>` directive to mark an element (or elements) as the trigger and setup the
  8619. * proper event listeners.
  8620. *
  8621. * @usage
  8622. * See the `<md-fab-speed-dial>` or `<md-fab-toolbar>` directives for example usage.
  8623. */
  8624. function MdFabTriggerDirective() {
  8625. // TODO: Remove this completely?
  8626. return {
  8627. restrict: 'E',
  8628. require: ['^?mdFabSpeedDial', '^?mdFabToolbar']
  8629. };
  8630. }
  8631. })();
  8632. })();
  8633. (function(){
  8634. "use strict";
  8635. /**
  8636. * @ngdoc module
  8637. * @name material.components.gridList
  8638. */
  8639. angular.module('material.components.gridList', ['material.core'])
  8640. .directive('mdGridList', GridListDirective)
  8641. .directive('mdGridTile', GridTileDirective)
  8642. .directive('mdGridTileFooter', GridTileCaptionDirective)
  8643. .directive('mdGridTileHeader', GridTileCaptionDirective)
  8644. .factory('$mdGridLayout', GridLayoutFactory);
  8645. /**
  8646. * @ngdoc directive
  8647. * @name mdGridList
  8648. * @module material.components.gridList
  8649. * @restrict E
  8650. * @description
  8651. * Grid lists are an alternative to standard list views. Grid lists are distinct
  8652. * from grids used for layouts and other visual presentations.
  8653. *
  8654. * A grid list is best suited to presenting a homogenous data type, typically
  8655. * images, and is optimized for visual comprehension and differentiating between
  8656. * like data types.
  8657. *
  8658. * A grid list is a continuous element consisting of tessellated, regular
  8659. * subdivisions called cells that contain tiles (`md-grid-tile`).
  8660. *
  8661. * <img src="//material-design.storage.googleapis.com/publish/v_2/material_ext_publish/0Bx4BSt6jniD7OVlEaXZ5YmU1Xzg/components_grids_usage2.png"
  8662. * style="width: 300px; height: auto; margin-right: 16px;" alt="Concept of grid explained visually">
  8663. * <img src="//material-design.storage.googleapis.com/publish/v_2/material_ext_publish/0Bx4BSt6jniD7VGhsOE5idWlJWXM/components_grids_usage3.png"
  8664. * style="width: 300px; height: auto;" alt="Grid concepts legend">
  8665. *
  8666. * Cells are arrayed vertically and horizontally within the grid.
  8667. *
  8668. * Tiles hold content and can span one or more cells vertically or horizontally.
  8669. *
  8670. * ### Responsive Attributes
  8671. *
  8672. * The `md-grid-list` directive supports "responsive" attributes, which allow
  8673. * different `md-cols`, `md-gutter` and `md-row-height` values depending on the
  8674. * currently matching media query (as defined in `$mdConstant.MEDIA`).
  8675. *
  8676. * In order to set a responsive attribute, first define the fallback value with
  8677. * the standard attribute name, then add additional attributes with the
  8678. * following convention: `{base-attribute-name}-{media-query-name}="{value}"`
  8679. * (ie. `md-cols-lg="8"`)
  8680. *
  8681. * @param {number} md-cols Number of columns in the grid.
  8682. * @param {string} md-row-height One of
  8683. * <ul>
  8684. * <li>CSS length - Fixed height rows (eg. `8px` or `1rem`)</li>
  8685. * <li>`{width}:{height}` - Ratio of width to height (eg.
  8686. * `md-row-height="16:9"`)</li>
  8687. * <li>`"fit"` - Height will be determined by subdividing the available
  8688. * height by the number of rows</li>
  8689. * </ul>
  8690. * @param {string=} md-gutter The amount of space between tiles in CSS units
  8691. * (default 1px)
  8692. * @param {expression=} md-on-layout Expression to evaluate after layout. Event
  8693. * object is available as `$event`, and contains performance information.
  8694. *
  8695. * @usage
  8696. * Basic:
  8697. * <hljs lang="html">
  8698. * <md-grid-list md-cols="5" md-gutter="1em" md-row-height="4:3">
  8699. * <md-grid-tile></md-grid-tile>
  8700. * </md-grid-list>
  8701. * </hljs>
  8702. *
  8703. * Fixed-height rows:
  8704. * <hljs lang="html">
  8705. * <md-grid-list md-cols="4" md-row-height="200px" ...>
  8706. * <md-grid-tile></md-grid-tile>
  8707. * </md-grid-list>
  8708. * </hljs>
  8709. *
  8710. * Fit rows:
  8711. * <hljs lang="html">
  8712. * <md-grid-list md-cols="4" md-row-height="fit" style="height: 400px;" ...>
  8713. * <md-grid-tile></md-grid-tile>
  8714. * </md-grid-list>
  8715. * </hljs>
  8716. *
  8717. * Using responsive attributes:
  8718. * <hljs lang="html">
  8719. * <md-grid-list
  8720. * md-cols-sm="2"
  8721. * md-cols-md="4"
  8722. * md-cols-lg="8"
  8723. * md-cols-gt-lg="12"
  8724. * ...>
  8725. * <md-grid-tile></md-grid-tile>
  8726. * </md-grid-list>
  8727. * </hljs>
  8728. */
  8729. function GridListDirective($interpolate, $mdConstant, $mdGridLayout, $mdMedia) {
  8730. return {
  8731. restrict: 'E',
  8732. controller: GridListController,
  8733. scope: {
  8734. mdOnLayout: '&'
  8735. },
  8736. link: postLink
  8737. };
  8738. function postLink(scope, element, attrs, ctrl) {
  8739. // Apply semantics
  8740. element.attr('role', 'list');
  8741. // Provide the controller with a way to trigger layouts.
  8742. ctrl.layoutDelegate = layoutDelegate;
  8743. var invalidateLayout = angular.bind(ctrl, ctrl.invalidateLayout),
  8744. unwatchAttrs = watchMedia();
  8745. scope.$on('$destroy', unwatchMedia);
  8746. /**
  8747. * Watches for changes in media, invalidating layout as necessary.
  8748. */
  8749. function watchMedia() {
  8750. for (var mediaName in $mdConstant.MEDIA) {
  8751. $mdMedia(mediaName); // initialize
  8752. $mdMedia.getQuery($mdConstant.MEDIA[mediaName])
  8753. .addListener(invalidateLayout);
  8754. }
  8755. return $mdMedia.watchResponsiveAttributes(
  8756. ['md-cols', 'md-row-height', 'md-gutter'], attrs, layoutIfMediaMatch);
  8757. }
  8758. function unwatchMedia() {
  8759. ctrl.layoutDelegate = angular.noop;
  8760. unwatchAttrs();
  8761. for (var mediaName in $mdConstant.MEDIA) {
  8762. $mdMedia.getQuery($mdConstant.MEDIA[mediaName])
  8763. .removeListener(invalidateLayout);
  8764. }
  8765. }
  8766. /**
  8767. * Performs grid layout if the provided mediaName matches the currently
  8768. * active media type.
  8769. */
  8770. function layoutIfMediaMatch(mediaName) {
  8771. if (mediaName == null) {
  8772. // TODO(shyndman): It would be nice to only layout if we have
  8773. // instances of attributes using this media type
  8774. ctrl.invalidateLayout();
  8775. } else if ($mdMedia(mediaName)) {
  8776. ctrl.invalidateLayout();
  8777. }
  8778. }
  8779. var lastLayoutProps;
  8780. /**
  8781. * Invokes the layout engine, and uses its results to lay out our
  8782. * tile elements.
  8783. *
  8784. * @param {boolean} tilesInvalidated Whether tiles have been
  8785. * added/removed/moved since the last layout. This is to avoid situations
  8786. * where tiles are replaced with properties identical to their removed
  8787. * counterparts.
  8788. */
  8789. function layoutDelegate(tilesInvalidated) {
  8790. var tiles = getTileElements();
  8791. var props = {
  8792. tileSpans: getTileSpans(tiles),
  8793. colCount: getColumnCount(),
  8794. rowMode: getRowMode(),
  8795. rowHeight: getRowHeight(),
  8796. gutter: getGutter()
  8797. };
  8798. if (!tilesInvalidated && angular.equals(props, lastLayoutProps)) {
  8799. return;
  8800. }
  8801. var performance =
  8802. $mdGridLayout(props.colCount, props.tileSpans, tiles)
  8803. .map(function(tilePositions, rowCount) {
  8804. return {
  8805. grid: {
  8806. element: element,
  8807. style: getGridStyle(props.colCount, rowCount,
  8808. props.gutter, props.rowMode, props.rowHeight)
  8809. },
  8810. tiles: tilePositions.map(function(ps, i) {
  8811. return {
  8812. element: angular.element(tiles[i]),
  8813. style: getTileStyle(ps.position, ps.spans,
  8814. props.colCount, rowCount,
  8815. props.gutter, props.rowMode, props.rowHeight)
  8816. }
  8817. })
  8818. }
  8819. })
  8820. .reflow()
  8821. .performance();
  8822. // Report layout
  8823. scope.mdOnLayout({
  8824. $event: {
  8825. performance: performance
  8826. }
  8827. });
  8828. lastLayoutProps = props;
  8829. }
  8830. // Use $interpolate to do some simple string interpolation as a convenience.
  8831. var startSymbol = $interpolate.startSymbol();
  8832. var endSymbol = $interpolate.endSymbol();
  8833. // Returns an expression wrapped in the interpolator's start and end symbols.
  8834. function expr(exprStr) {
  8835. return startSymbol + exprStr + endSymbol;
  8836. }
  8837. // The amount of space a single 1x1 tile would take up (either width or height), used as
  8838. // a basis for other calculations. This consists of taking the base size percent (as would be
  8839. // if evenly dividing the size between cells), and then subtracting the size of one gutter.
  8840. // However, since there are no gutters on the edges, each tile only uses a fration
  8841. // (gutterShare = numGutters / numCells) of the gutter size. (Imagine having one gutter per
  8842. // tile, and then breaking up the extra gutter on the edge evenly among the cells).
  8843. var UNIT = $interpolate(expr('share') + '% - (' + expr('gutter') + ' * ' + expr('gutterShare') + ')');
  8844. // The horizontal or vertical position of a tile, e.g., the 'top' or 'left' property value.
  8845. // The position comes the size of a 1x1 tile plus gutter for each previous tile in the
  8846. // row/column (offset).
  8847. var POSITION = $interpolate('calc((' + expr('unit') + ' + ' + expr('gutter') + ') * ' + expr('offset') + ')');
  8848. // The actual size of a tile, e.g., width or height, taking rowSpan or colSpan into account.
  8849. // This is computed by multiplying the base unit by the rowSpan/colSpan, and then adding back
  8850. // in the space that the gutter would normally have used (which was already accounted for in
  8851. // the base unit calculation).
  8852. var DIMENSION = $interpolate('calc((' + expr('unit') + ') * ' + expr('span') + ' + (' + expr('span') + ' - 1) * ' + expr('gutter') + ')');
  8853. /**
  8854. * Gets the styles applied to a tile element described by the given parameters.
  8855. * @param {{row: number, col: number}} position The row and column indices of the tile.
  8856. * @param {{row: number, col: number}} spans The rowSpan and colSpan of the tile.
  8857. * @param {number} colCount The number of columns.
  8858. * @param {number} rowCount The number of rows.
  8859. * @param {string} gutter The amount of space between tiles. This will be something like
  8860. * '5px' or '2em'.
  8861. * @param {string} rowMode The row height mode. Can be one of:
  8862. * 'fixed': all rows have a fixed size, given by rowHeight,
  8863. * 'ratio': row height defined as a ratio to width, or
  8864. * 'fit': fit to the grid-list element height, divinding evenly among rows.
  8865. * @param {string|number} rowHeight The height of a row. This is only used for 'fixed' mode and
  8866. * for 'ratio' mode. For 'ratio' mode, this is the *ratio* of width-to-height (e.g., 0.75).
  8867. * @returns {Object} Map of CSS properties to be applied to the style element. Will define
  8868. * values for top, left, width, height, marginTop, and paddingTop.
  8869. */
  8870. function getTileStyle(position, spans, colCount, rowCount, gutter, rowMode, rowHeight) {
  8871. // TODO(shyndman): There are style caching opportunities here.
  8872. // Percent of the available horizontal space that one column takes up.
  8873. var hShare = (1 / colCount) * 100;
  8874. // Fraction of the gutter size that each column takes up.
  8875. var hGutterShare = (colCount - 1) / colCount;
  8876. // Base horizontal size of a column.
  8877. var hUnit = UNIT({share: hShare, gutterShare: hGutterShare, gutter: gutter});
  8878. // The width and horizontal position of each tile is always calculated the same way, but the
  8879. // height and vertical position depends on the rowMode.
  8880. var style = {
  8881. left: POSITION({ unit: hUnit, offset: position.col, gutter: gutter }),
  8882. width: DIMENSION({ unit: hUnit, span: spans.col, gutter: gutter }),
  8883. // resets
  8884. paddingTop: '',
  8885. marginTop: '',
  8886. top: '',
  8887. height: ''
  8888. };
  8889. switch (rowMode) {
  8890. case 'fixed':
  8891. // In fixed mode, simply use the given rowHeight.
  8892. style.top = POSITION({ unit: rowHeight, offset: position.row, gutter: gutter });
  8893. style.height = DIMENSION({ unit: rowHeight, span: spans.row, gutter: gutter });
  8894. break;
  8895. case 'ratio':
  8896. // Percent of the available vertical space that one row takes up. Here, rowHeight holds
  8897. // the ratio value. For example, if the width:height ratio is 4:3, rowHeight = 1.333.
  8898. var vShare = hShare / rowHeight;
  8899. // Base veritcal size of a row.
  8900. var vUnit = UNIT({ share: vShare, gutterShare: hGutterShare, gutter: gutter });
  8901. // padidngTop and marginTop are used to maintain the given aspect ratio, as
  8902. // a percentage-based value for these properties is applied to the *width* of the
  8903. // containing block. See http://www.w3.org/TR/CSS2/box.html#margin-properties
  8904. style.paddingTop = DIMENSION({ unit: vUnit, span: spans.row, gutter: gutter});
  8905. style.marginTop = POSITION({ unit: vUnit, offset: position.row, gutter: gutter });
  8906. break;
  8907. case 'fit':
  8908. // Fraction of the gutter size that each column takes up.
  8909. var vGutterShare = (rowCount - 1) / rowCount;
  8910. // Percent of the available vertical space that one row takes up.
  8911. var vShare = (1 / rowCount) * 100;
  8912. // Base vertical size of a row.
  8913. var vUnit = UNIT({share: vShare, gutterShare: vGutterShare, gutter: gutter});
  8914. style.top = POSITION({unit: vUnit, offset: position.row, gutter: gutter});
  8915. style.height = DIMENSION({unit: vUnit, span: spans.row, gutter: gutter});
  8916. break;
  8917. }
  8918. return style;
  8919. }
  8920. function getGridStyle(colCount, rowCount, gutter, rowMode, rowHeight) {
  8921. var style = {};
  8922. switch(rowMode) {
  8923. case 'fixed':
  8924. style.height = DIMENSION({ unit: rowHeight, span: rowCount, gutter: gutter });
  8925. style.paddingBottom = '';
  8926. break;
  8927. case 'ratio':
  8928. // rowHeight is width / height
  8929. var hGutterShare = colCount === 1 ? 0 : (colCount - 1) / colCount,
  8930. hShare = (1 / colCount) * 100,
  8931. vShare = hShare * (1 / rowHeight),
  8932. vUnit = UNIT({ share: vShare, gutterShare: hGutterShare, gutter: gutter });
  8933. style.height = '';
  8934. style.paddingBottom = DIMENSION({ unit: vUnit, span: rowCount, gutter: gutter});
  8935. break;
  8936. case 'fit':
  8937. // noop, as the height is user set
  8938. break;
  8939. }
  8940. return style;
  8941. }
  8942. function getTileElements() {
  8943. return [].filter.call(element.children(), function(ele) {
  8944. return ele.tagName == 'MD-GRID-TILE' && !ele.$$mdDestroyed;
  8945. });
  8946. }
  8947. /**
  8948. * Gets an array of objects containing the rowspan and colspan for each tile.
  8949. * @returns {Array<{row: number, col: number}>}
  8950. */
  8951. function getTileSpans(tileElements) {
  8952. return [].map.call(tileElements, function(ele) {
  8953. var ctrl = angular.element(ele).controller('mdGridTile');
  8954. return {
  8955. row: parseInt(
  8956. $mdMedia.getResponsiveAttribute(ctrl.$attrs, 'md-rowspan'), 10) || 1,
  8957. col: parseInt(
  8958. $mdMedia.getResponsiveAttribute(ctrl.$attrs, 'md-colspan'), 10) || 1
  8959. };
  8960. });
  8961. }
  8962. function getColumnCount() {
  8963. var colCount = parseInt($mdMedia.getResponsiveAttribute(attrs, 'md-cols'), 10);
  8964. if (isNaN(colCount)) {
  8965. throw 'md-grid-list: md-cols attribute was not found, or contained a non-numeric value';
  8966. }
  8967. return colCount;
  8968. }
  8969. function getGutter() {
  8970. return applyDefaultUnit($mdMedia.getResponsiveAttribute(attrs, 'md-gutter') || 1);
  8971. }
  8972. function getRowHeight() {
  8973. var rowHeight = $mdMedia.getResponsiveAttribute(attrs, 'md-row-height');
  8974. switch (getRowMode()) {
  8975. case 'fixed':
  8976. return applyDefaultUnit(rowHeight);
  8977. case 'ratio':
  8978. var whRatio = rowHeight.split(':');
  8979. return parseFloat(whRatio[0]) / parseFloat(whRatio[1]);
  8980. case 'fit':
  8981. return 0; // N/A
  8982. }
  8983. }
  8984. function getRowMode() {
  8985. var rowHeight = $mdMedia.getResponsiveAttribute(attrs, 'md-row-height');
  8986. if (rowHeight == 'fit') {
  8987. return 'fit';
  8988. } else if (rowHeight.indexOf(':') !== -1) {
  8989. return 'ratio';
  8990. } else {
  8991. return 'fixed';
  8992. }
  8993. }
  8994. function applyDefaultUnit(val) {
  8995. return /\D$/.test(val) ? val : val + 'px';
  8996. }
  8997. }
  8998. }
  8999. GridListDirective.$inject = ["$interpolate", "$mdConstant", "$mdGridLayout", "$mdMedia"];
  9000. /* @ngInject */
  9001. function GridListController($mdUtil) {
  9002. this.layoutInvalidated = false;
  9003. this.tilesInvalidated = false;
  9004. this.$timeout_ = $mdUtil.nextTick;
  9005. this.layoutDelegate = angular.noop;
  9006. }
  9007. GridListController.$inject = ["$mdUtil"];
  9008. GridListController.prototype = {
  9009. invalidateTiles: function() {
  9010. this.tilesInvalidated = true;
  9011. this.invalidateLayout();
  9012. },
  9013. invalidateLayout: function() {
  9014. if (this.layoutInvalidated) {
  9015. return;
  9016. }
  9017. this.layoutInvalidated = true;
  9018. this.$timeout_(angular.bind(this, this.layout));
  9019. },
  9020. layout: function() {
  9021. try {
  9022. this.layoutDelegate(this.tilesInvalidated);
  9023. } finally {
  9024. this.layoutInvalidated = false;
  9025. this.tilesInvalidated = false;
  9026. }
  9027. }
  9028. };
  9029. /* @ngInject */
  9030. function GridLayoutFactory($mdUtil) {
  9031. var defaultAnimator = GridTileAnimator;
  9032. /**
  9033. * Set the reflow animator callback
  9034. */
  9035. GridLayout.animateWith = function(customAnimator) {
  9036. defaultAnimator = !angular.isFunction(customAnimator) ? GridTileAnimator : customAnimator;
  9037. };
  9038. return GridLayout;
  9039. /**
  9040. * Publish layout function
  9041. */
  9042. function GridLayout(colCount, tileSpans) {
  9043. var self, layoutInfo, gridStyles, layoutTime, mapTime, reflowTime;
  9044. layoutTime = $mdUtil.time(function() {
  9045. layoutInfo = calculateGridFor(colCount, tileSpans);
  9046. });
  9047. return self = {
  9048. /**
  9049. * An array of objects describing each tile's position in the grid.
  9050. */
  9051. layoutInfo: function() {
  9052. return layoutInfo;
  9053. },
  9054. /**
  9055. * Maps grid positioning to an element and a set of styles using the
  9056. * provided updateFn.
  9057. */
  9058. map: function(updateFn) {
  9059. mapTime = $mdUtil.time(function() {
  9060. var info = self.layoutInfo();
  9061. gridStyles = updateFn(info.positioning, info.rowCount);
  9062. });
  9063. return self;
  9064. },
  9065. /**
  9066. * Default animator simply sets the element.css( <styles> ). An alternate
  9067. * animator can be provided as an argument. The function has the following
  9068. * signature:
  9069. *
  9070. * function({grid: {element: JQLite, style: Object}, tiles: Array<{element: JQLite, style: Object}>)
  9071. */
  9072. reflow: function(animatorFn) {
  9073. reflowTime = $mdUtil.time(function() {
  9074. var animator = animatorFn || defaultAnimator;
  9075. animator(gridStyles.grid, gridStyles.tiles);
  9076. });
  9077. return self;
  9078. },
  9079. /**
  9080. * Timing for the most recent layout run.
  9081. */
  9082. performance: function() {
  9083. return {
  9084. tileCount: tileSpans.length,
  9085. layoutTime: layoutTime,
  9086. mapTime: mapTime,
  9087. reflowTime: reflowTime,
  9088. totalTime: layoutTime + mapTime + reflowTime
  9089. };
  9090. }
  9091. };
  9092. }
  9093. /**
  9094. * Default Gridlist animator simple sets the css for each element;
  9095. * NOTE: any transitions effects must be manually set in the CSS.
  9096. * e.g.
  9097. *
  9098. * md-grid-tile {
  9099. * transition: all 700ms ease-out 50ms;
  9100. * }
  9101. *
  9102. */
  9103. function GridTileAnimator(grid, tiles) {
  9104. grid.element.css(grid.style);
  9105. tiles.forEach(function(t) {
  9106. t.element.css(t.style);
  9107. })
  9108. }
  9109. /**
  9110. * Calculates the positions of tiles.
  9111. *
  9112. * The algorithm works as follows:
  9113. * An Array<Number> with length colCount (spaceTracker) keeps track of
  9114. * available tiling positions, where elements of value 0 represents an
  9115. * empty position. Space for a tile is reserved by finding a sequence of
  9116. * 0s with length <= than the tile's colspan. When such a space has been
  9117. * found, the occupied tile positions are incremented by the tile's
  9118. * rowspan value, as these positions have become unavailable for that
  9119. * many rows.
  9120. *
  9121. * If the end of a row has been reached without finding space for the
  9122. * tile, spaceTracker's elements are each decremented by 1 to a minimum
  9123. * of 0. Rows are searched in this fashion until space is found.
  9124. */
  9125. function calculateGridFor(colCount, tileSpans) {
  9126. var curCol = 0,
  9127. curRow = 0,
  9128. spaceTracker = newSpaceTracker();
  9129. return {
  9130. positioning: tileSpans.map(function(spans, i) {
  9131. return {
  9132. spans: spans,
  9133. position: reserveSpace(spans, i)
  9134. };
  9135. }),
  9136. rowCount: curRow + Math.max.apply(Math, spaceTracker)
  9137. };
  9138. function reserveSpace(spans, i) {
  9139. if (spans.col > colCount) {
  9140. throw 'md-grid-list: Tile at position ' + i + ' has a colspan ' +
  9141. '(' + spans.col + ') that exceeds the column count ' +
  9142. '(' + colCount + ')';
  9143. }
  9144. var start = 0,
  9145. end = 0;
  9146. // TODO(shyndman): This loop isn't strictly necessary if you can
  9147. // determine the minimum number of rows before a space opens up. To do
  9148. // this, recognize that you've iterated across an entire row looking for
  9149. // space, and if so fast-forward by the minimum rowSpan count. Repeat
  9150. // until the required space opens up.
  9151. while (end - start < spans.col) {
  9152. if (curCol >= colCount) {
  9153. nextRow();
  9154. continue;
  9155. }
  9156. start = spaceTracker.indexOf(0, curCol);
  9157. if (start === -1 || (end = findEnd(start + 1)) === -1) {
  9158. start = end = 0;
  9159. nextRow();
  9160. continue;
  9161. }
  9162. curCol = end + 1;
  9163. }
  9164. adjustRow(start, spans.col, spans.row);
  9165. curCol = start + spans.col;
  9166. return {
  9167. col: start,
  9168. row: curRow
  9169. };
  9170. }
  9171. function nextRow() {
  9172. curCol = 0;
  9173. curRow++;
  9174. adjustRow(0, colCount, -1); // Decrement row spans by one
  9175. }
  9176. function adjustRow(from, cols, by) {
  9177. for (var i = from; i < from + cols; i++) {
  9178. spaceTracker[i] = Math.max(spaceTracker[i] + by, 0);
  9179. }
  9180. }
  9181. function findEnd(start) {
  9182. var i;
  9183. for (i = start; i < spaceTracker.length; i++) {
  9184. if (spaceTracker[i] !== 0) {
  9185. return i;
  9186. }
  9187. }
  9188. if (i === spaceTracker.length) {
  9189. return i;
  9190. }
  9191. }
  9192. function newSpaceTracker() {
  9193. var tracker = [];
  9194. for (var i = 0; i < colCount; i++) {
  9195. tracker.push(0);
  9196. }
  9197. return tracker;
  9198. }
  9199. }
  9200. }
  9201. GridLayoutFactory.$inject = ["$mdUtil"];
  9202. /**
  9203. * @ngdoc directive
  9204. * @name mdGridTile
  9205. * @module material.components.gridList
  9206. * @restrict E
  9207. * @description
  9208. * Tiles contain the content of an `md-grid-list`. They span one or more grid
  9209. * cells vertically or horizontally, and use `md-grid-tile-{footer,header}` to
  9210. * display secondary content.
  9211. *
  9212. * ### Responsive Attributes
  9213. *
  9214. * The `md-grid-tile` directive supports "responsive" attributes, which allow
  9215. * different `md-rowspan` and `md-colspan` values depending on the currently
  9216. * matching media query (as defined in `$mdConstant.MEDIA`).
  9217. *
  9218. * In order to set a responsive attribute, first define the fallback value with
  9219. * the standard attribute name, then add additional attributes with the
  9220. * following convention: `{base-attribute-name}-{media-query-name}="{value}"`
  9221. * (ie. `md-colspan-sm="4"`)
  9222. *
  9223. * @param {number=} md-colspan The number of columns to span (default 1). Cannot
  9224. * exceed the number of columns in the grid. Supports interpolation.
  9225. * @param {number=} md-rowspan The number of rows to span (default 1). Supports
  9226. * interpolation.
  9227. *
  9228. * @usage
  9229. * With header:
  9230. * <hljs lang="html">
  9231. * <md-grid-tile>
  9232. * <md-grid-tile-header>
  9233. * <h3>This is a header</h3>
  9234. * </md-grid-tile-header>
  9235. * </md-grid-tile>
  9236. * </hljs>
  9237. *
  9238. * With footer:
  9239. * <hljs lang="html">
  9240. * <md-grid-tile>
  9241. * <md-grid-tile-footer>
  9242. * <h3>This is a footer</h3>
  9243. * </md-grid-tile-footer>
  9244. * </md-grid-tile>
  9245. * </hljs>
  9246. *
  9247. * Spanning multiple rows/columns:
  9248. * <hljs lang="html">
  9249. * <md-grid-tile md-colspan="2" md-rowspan="3">
  9250. * </md-grid-tile>
  9251. * </hljs>
  9252. *
  9253. * Responsive attributes:
  9254. * <hljs lang="html">
  9255. * <md-grid-tile md-colspan="1" md-colspan-sm="3" md-colspan-md="5">
  9256. * </md-grid-tile>
  9257. * </hljs>
  9258. */
  9259. function GridTileDirective($mdMedia) {
  9260. return {
  9261. restrict: 'E',
  9262. require: '^mdGridList',
  9263. template: '<figure ng-transclude></figure>',
  9264. transclude: true,
  9265. scope: {},
  9266. // Simple controller that exposes attributes to the grid directive
  9267. controller: ["$attrs", function($attrs) {
  9268. this.$attrs = $attrs;
  9269. }],
  9270. link: postLink
  9271. };
  9272. function postLink(scope, element, attrs, gridCtrl) {
  9273. // Apply semantics
  9274. element.attr('role', 'listitem');
  9275. // If our colspan or rowspan changes, trigger a layout
  9276. var unwatchAttrs = $mdMedia.watchResponsiveAttributes(['md-colspan', 'md-rowspan'],
  9277. attrs, angular.bind(gridCtrl, gridCtrl.invalidateLayout));
  9278. // Tile registration/deregistration
  9279. gridCtrl.invalidateTiles();
  9280. scope.$on('$destroy', function() {
  9281. // Mark the tile as destroyed so it is no longer considered in layout,
  9282. // even if the DOM element sticks around (like during a leave animation)
  9283. element[0].$$mdDestroyed = true;
  9284. unwatchAttrs();
  9285. gridCtrl.invalidateLayout();
  9286. });
  9287. if (angular.isDefined(scope.$parent.$index)) {
  9288. scope.$watch(function() { return scope.$parent.$index; },
  9289. function indexChanged(newIdx, oldIdx) {
  9290. if (newIdx === oldIdx) {
  9291. return;
  9292. }
  9293. gridCtrl.invalidateTiles();
  9294. });
  9295. }
  9296. }
  9297. }
  9298. GridTileDirective.$inject = ["$mdMedia"];
  9299. function GridTileCaptionDirective() {
  9300. return {
  9301. template: '<figcaption ng-transclude></figcaption>',
  9302. transclude: true
  9303. };
  9304. }
  9305. })();
  9306. (function(){
  9307. "use strict";
  9308. /**
  9309. * @ngdoc module
  9310. * @name material.components.icon
  9311. * @description
  9312. * Icon
  9313. */
  9314. angular.module('material.components.icon', [
  9315. 'material.core'
  9316. ]);
  9317. })();
  9318. (function(){
  9319. "use strict";
  9320. /**
  9321. * @ngdoc module
  9322. * @name material.components.input
  9323. */
  9324. angular.module('material.components.input', [
  9325. 'material.core'
  9326. ])
  9327. .directive('mdInputContainer', mdInputContainerDirective)
  9328. .directive('label', labelDirective)
  9329. .directive('input', inputTextareaDirective)
  9330. .directive('textarea', inputTextareaDirective)
  9331. .directive('mdMaxlength', mdMaxlengthDirective)
  9332. .directive('placeholder', placeholderDirective)
  9333. .directive('ngMessages', ngMessagesDirective);
  9334. /**
  9335. * @ngdoc directive
  9336. * @name mdInputContainer
  9337. * @module material.components.input
  9338. *
  9339. * @restrict E
  9340. *
  9341. * @description
  9342. * `<md-input-container>` is the parent of any input or textarea element.
  9343. *
  9344. * Input and textarea elements will not behave properly unless the md-input-container
  9345. * parent is provided.
  9346. *
  9347. * @param md-is-error {expression=} When the given expression evaluates to true, the input container
  9348. * will go into error state. Defaults to erroring if the input has been touched and is invalid.
  9349. * @param md-no-float {boolean=} When present, placeholders will not be converted to floating
  9350. * labels.
  9351. *
  9352. * @usage
  9353. * <hljs lang="html">
  9354. *
  9355. * <md-input-container>
  9356. * <label>Username</label>
  9357. * <input type="text" ng-model="user.name">
  9358. * </md-input-container>
  9359. *
  9360. * <md-input-container>
  9361. * <label>Description</label>
  9362. * <textarea ng-model="user.description"></textarea>
  9363. * </md-input-container>
  9364. *
  9365. * </hljs>
  9366. */
  9367. function mdInputContainerDirective($mdTheming, $parse) {
  9368. ContainerCtrl.$inject = ["$scope", "$element", "$attrs"];
  9369. return {
  9370. restrict: 'E',
  9371. link: postLink,
  9372. controller: ContainerCtrl
  9373. };
  9374. function postLink(scope, element, attr) {
  9375. $mdTheming(element);
  9376. }
  9377. function ContainerCtrl($scope, $element, $attrs) {
  9378. var self = this;
  9379. self.isErrorGetter = $attrs.mdIsError && $parse($attrs.mdIsError);
  9380. self.delegateClick = function() {
  9381. self.input.focus();
  9382. };
  9383. self.element = $element;
  9384. self.setFocused = function(isFocused) {
  9385. $element.toggleClass('md-input-focused', !!isFocused);
  9386. };
  9387. self.setHasValue = function(hasValue) {
  9388. $element.toggleClass('md-input-has-value', !!hasValue);
  9389. };
  9390. self.setHasMessages = function(hasMessages) {
  9391. $element.toggleClass('md-input-has-messages', !!hasMessages);
  9392. };
  9393. self.setHasPlaceholder = function(hasPlaceholder) {
  9394. $element.toggleClass('md-input-has-placeholder', !!hasPlaceholder);
  9395. };
  9396. self.setInvalid = function(isInvalid) {
  9397. $element.toggleClass('md-input-invalid', !!isInvalid);
  9398. };
  9399. $scope.$watch(function() {
  9400. return self.label && self.input;
  9401. }, function(hasLabelAndInput) {
  9402. if (hasLabelAndInput && !self.label.attr('for')) {
  9403. self.label.attr('for', self.input.attr('id'));
  9404. }
  9405. });
  9406. }
  9407. }
  9408. mdInputContainerDirective.$inject = ["$mdTheming", "$parse"];
  9409. function labelDirective() {
  9410. return {
  9411. restrict: 'E',
  9412. require: '^?mdInputContainer',
  9413. link: function(scope, element, attr, containerCtrl) {
  9414. if (!containerCtrl || attr.mdNoFloat) return;
  9415. containerCtrl.label = element;
  9416. scope.$on('$destroy', function() {
  9417. containerCtrl.label = null;
  9418. });
  9419. }
  9420. };
  9421. }
  9422. /**
  9423. * @ngdoc directive
  9424. * @name mdInput
  9425. * @restrict E
  9426. * @module material.components.input
  9427. *
  9428. * @description
  9429. * Use the `<input>` or the `<textarea>` as a child of an `<md-input-container>`.
  9430. *
  9431. * @param {number=} md-maxlength The maximum number of characters allowed in this input. If this is
  9432. * specified, a character counter will be shown underneath the input.<br/><br/>
  9433. * The purpose of **`md-maxlength`** is exactly to show the max length counter text. If you don't
  9434. * want the counter text and only need "plain" validation, you can use the "simple" `ng-maxlength`
  9435. * or maxlength attributes.
  9436. * @param {string=} aria-label Aria-label is required when no label is present. A warning message
  9437. * will be logged in the console if not present.
  9438. * @param {string=} placeholder An alternative approach to using aria-label when the label is not
  9439. * PRESENT. The placeholder text is copied to the aria-label attribute.
  9440. * @param md-no-autogrow {boolean=} When present, textareas will not grow automatically.
  9441. * @param md-detect-hidden {boolean=} When present, textareas will be sized properly when they are revealed after being hidden. This is off by default for performance reasons because it guarantees a reflow every digest cycle.
  9442. *
  9443. * @usage
  9444. * <hljs lang="html">
  9445. * <md-input-container>
  9446. * <label>Color</label>
  9447. * <input type="text" ng-model="color" required md-maxlength="10">
  9448. * </md-input-container>
  9449. * </hljs>
  9450. * <h3>With Errors</h3>
  9451. *
  9452. * <hljs lang="html">
  9453. * <form name="userForm">
  9454. * <md-input-container>
  9455. * <label>Last Name</label>
  9456. * <input name="lastName" ng-model="lastName" required md-maxlength="10" minlength="4">
  9457. * <div ng-messages="userForm.lastName.$error" ng-show="userForm.lastName.$dirty">
  9458. * <div ng-message="required">This is required!</div>
  9459. * <div ng-message="md-maxlength">That's too long!</div>
  9460. * <div ng-message="minlength">That's too short!</div>
  9461. * </div>
  9462. * </md-input-container>
  9463. * <md-input-container>
  9464. * <label>Biography</label>
  9465. * <textarea name="bio" ng-model="biography" required md-maxlength="150"></textarea>
  9466. * <div ng-messages="userForm.bio.$error" ng-show="userForm.bio.$dirty">
  9467. * <div ng-message="required">This is required!</div>
  9468. * <div ng-message="md-maxlength">That's too long!</div>
  9469. * </div>
  9470. * </md-input-container>
  9471. * <md-input-container>
  9472. * <input aria-label='title' ng-model='title'>
  9473. * </md-input-container>
  9474. * <md-input-container>
  9475. * <input placeholder='title' ng-model='title'>
  9476. * </md-input-container>
  9477. * </form>
  9478. * </hljs>
  9479. *
  9480. * Requires [ngMessages](https://docs.angularjs.org/api/ngMessages).
  9481. * Behaves like the [AngularJS input directive](https://docs.angularjs.org/api/ng/directive/input).
  9482. *
  9483. */
  9484. function inputTextareaDirective($mdUtil, $window, $mdAria) {
  9485. return {
  9486. restrict: 'E',
  9487. require: ['^?mdInputContainer', '?ngModel'],
  9488. link: postLink
  9489. };
  9490. function postLink(scope, element, attr, ctrls) {
  9491. var containerCtrl = ctrls[0];
  9492. var hasNgModel = !!ctrls[1];
  9493. var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel();
  9494. var isReadonly = angular.isDefined(attr.readonly);
  9495. if (!containerCtrl) return;
  9496. if (containerCtrl.input) {
  9497. throw new Error("<md-input-container> can only have *one* <input>, <textarea> or <md-select> child element!");
  9498. }
  9499. containerCtrl.input = element;
  9500. if (!containerCtrl.label) {
  9501. $mdAria.expect(element, 'aria-label', element.attr('placeholder'));
  9502. }
  9503. element.addClass('md-input');
  9504. if (!element.attr('id')) {
  9505. element.attr('id', 'input_' + $mdUtil.nextUid());
  9506. }
  9507. if (element[0].tagName.toLowerCase() === 'textarea') {
  9508. setupTextarea();
  9509. }
  9510. // If the input doesn't have an ngModel, it may have a static value. For that case,
  9511. // we have to do one initial check to determine if the container should be in the
  9512. // "has a value" state.
  9513. if (!hasNgModel) {
  9514. inputCheckValue();
  9515. }
  9516. var isErrorGetter = containerCtrl.isErrorGetter || function() {
  9517. return ngModelCtrl.$invalid && ngModelCtrl.$touched;
  9518. };
  9519. scope.$watch(isErrorGetter, containerCtrl.setInvalid);
  9520. ngModelCtrl.$parsers.push(ngModelPipelineCheckValue);
  9521. ngModelCtrl.$formatters.push(ngModelPipelineCheckValue);
  9522. element.on('input', inputCheckValue);
  9523. if (!isReadonly) {
  9524. element
  9525. .on('focus', function(ev) {
  9526. containerCtrl.setFocused(true);
  9527. })
  9528. .on('blur', function(ev) {
  9529. containerCtrl.setFocused(false);
  9530. inputCheckValue();
  9531. });
  9532. }
  9533. //ngModelCtrl.$setTouched();
  9534. //if( ngModelCtrl.$invalid ) containerCtrl.setInvalid();
  9535. scope.$on('$destroy', function() {
  9536. containerCtrl.setFocused(false);
  9537. containerCtrl.setHasValue(false);
  9538. containerCtrl.input = null;
  9539. });
  9540. /**
  9541. *
  9542. */
  9543. function ngModelPipelineCheckValue(arg) {
  9544. containerCtrl.setHasValue(!ngModelCtrl.$isEmpty(arg));
  9545. return arg;
  9546. }
  9547. function inputCheckValue() {
  9548. // An input's value counts if its length > 0,
  9549. // or if the input's validity state says it has bad input (eg string in a number input)
  9550. containerCtrl.setHasValue(element.val().length > 0 || (element[0].validity || {}).badInput);
  9551. }
  9552. function setupTextarea() {
  9553. if (angular.isDefined(element.attr('md-no-autogrow'))) {
  9554. return;
  9555. }
  9556. var node = element[0];
  9557. var container = containerCtrl.element[0];
  9558. var min_rows = NaN;
  9559. var lineHeight = null;
  9560. // can't check if height was or not explicity set,
  9561. // so rows attribute will take precedence if present
  9562. if (node.hasAttribute('rows')) {
  9563. min_rows = parseInt(node.getAttribute('rows'));
  9564. }
  9565. var onChangeTextarea = $mdUtil.debounce(growTextarea, 1);
  9566. function pipelineListener(value) {
  9567. onChangeTextarea();
  9568. return value;
  9569. }
  9570. if (ngModelCtrl) {
  9571. ngModelCtrl.$formatters.push(pipelineListener);
  9572. ngModelCtrl.$viewChangeListeners.push(pipelineListener);
  9573. } else {
  9574. onChangeTextarea();
  9575. }
  9576. element.on('keydown input', onChangeTextarea);
  9577. if (isNaN(min_rows)) {
  9578. element.attr('rows', '1');
  9579. element.on('scroll', onScroll);
  9580. }
  9581. angular.element($window).on('resize', onChangeTextarea);
  9582. scope.$on('$destroy', function() {
  9583. angular.element($window).off('resize', onChangeTextarea);
  9584. });
  9585. function growTextarea() {
  9586. // sets the md-input-container height to avoid jumping around
  9587. container.style.height = container.offsetHeight + 'px';
  9588. // temporarily disables element's flex so its height 'runs free'
  9589. element.addClass('md-no-flex');
  9590. if (isNaN(min_rows)) {
  9591. node.style.height = "auto";
  9592. node.scrollTop = 0;
  9593. var height = getHeight();
  9594. if (height) node.style.height = height + 'px';
  9595. } else {
  9596. node.setAttribute("rows", 1);
  9597. if (!lineHeight) {
  9598. node.style.minHeight = '0';
  9599. lineHeight = element.prop('clientHeight');
  9600. node.style.minHeight = null;
  9601. }
  9602. var rows = Math.max(min_rows, Math.round(node.scrollHeight / lineHeight));
  9603. node.setAttribute("rows", rows);
  9604. }
  9605. // reset everything back to normal
  9606. element.removeClass('md-no-flex');
  9607. container.style.height = 'auto';
  9608. }
  9609. function getHeight() {
  9610. var line = node.scrollHeight - node.offsetHeight;
  9611. return node.offsetHeight + (line > 0 ? line : 0);
  9612. }
  9613. function onScroll(e) {
  9614. node.scrollTop = 0;
  9615. // for smooth new line adding
  9616. var line = node.scrollHeight - node.offsetHeight;
  9617. var height = node.offsetHeight + line;
  9618. node.style.height = height + 'px';
  9619. }
  9620. // Attach a watcher to detect when the textarea gets shown.
  9621. if (angular.isDefined(element.attr('md-detect-hidden'))) {
  9622. var handleHiddenChange = function() {
  9623. var wasHidden = false;
  9624. return function() {
  9625. var isHidden = node.offsetHeight === 0;
  9626. if (isHidden === false && wasHidden === true) {
  9627. growTextarea();
  9628. }
  9629. wasHidden = isHidden;
  9630. };
  9631. }();
  9632. // Check every digest cycle whether the visibility of the textarea has changed.
  9633. // Queue up to run after the digest cycle is complete.
  9634. scope.$watch(function() {
  9635. $mdUtil.nextTick(handleHiddenChange, false);
  9636. return true;
  9637. });
  9638. }
  9639. }
  9640. }
  9641. }
  9642. inputTextareaDirective.$inject = ["$mdUtil", "$window", "$mdAria"];
  9643. function mdMaxlengthDirective($animate) {
  9644. return {
  9645. restrict: 'A',
  9646. require: ['ngModel', '^mdInputContainer'],
  9647. link: postLink
  9648. };
  9649. function postLink(scope, element, attr, ctrls) {
  9650. var maxlength;
  9651. var ngModelCtrl = ctrls[0];
  9652. var containerCtrl = ctrls[1];
  9653. var charCountEl = angular.element('<div class="md-char-counter">');
  9654. var input = angular.element(containerCtrl.element[0].querySelector('[md-maxlength]'));
  9655. // Stop model from trimming. This makes it so whitespace
  9656. // over the maxlength still counts as invalid.
  9657. attr.$set('ngTrim', 'false');
  9658. var ngMessagesSelectors = [
  9659. 'ng-messages',
  9660. 'data-ng-messages',
  9661. 'x-ng-messages',
  9662. '[ng-messages]',
  9663. '[data-ng-messages]',
  9664. '[x-ng-messages]'
  9665. ];
  9666. var ngMessages = containerCtrl.element[0].querySelector(ngMessagesSelectors.join(','));
  9667. // If we have an ngMessages container, put the counter at the top; otherwise, put it after the
  9668. // input so it will be positioned properly in the SCSS
  9669. if (ngMessages) {
  9670. angular.element(ngMessages).prepend(charCountEl);
  9671. } else {
  9672. input.after(charCountEl);
  9673. }
  9674. ngModelCtrl.$formatters.push(renderCharCount);
  9675. ngModelCtrl.$viewChangeListeners.push(renderCharCount);
  9676. element.on('input keydown keyup', function() {
  9677. renderCharCount(); //make sure it's called with no args
  9678. });
  9679. scope.$watch(attr.mdMaxlength, function(value) {
  9680. maxlength = value;
  9681. if (angular.isNumber(value) && value > 0) {
  9682. if (!charCountEl.parent().length) {
  9683. $animate.enter(charCountEl, containerCtrl.element, input);
  9684. }
  9685. renderCharCount();
  9686. } else {
  9687. $animate.leave(charCountEl);
  9688. }
  9689. });
  9690. ngModelCtrl.$validators['md-maxlength'] = function(modelValue, viewValue) {
  9691. if (!angular.isNumber(maxlength) || maxlength < 0) {
  9692. return true;
  9693. }
  9694. return ( modelValue || element.val() || viewValue || '' ).length <= maxlength;
  9695. };
  9696. function renderCharCount(value) {
  9697. // Force the value into a string since it may be a number,
  9698. // which does not have a length property.
  9699. charCountEl.text(String(element.val() || value || '').length + '/' + maxlength);
  9700. return value;
  9701. }
  9702. }
  9703. }
  9704. mdMaxlengthDirective.$inject = ["$animate"];
  9705. function placeholderDirective($log) {
  9706. return {
  9707. restrict: 'A',
  9708. require: '^^?mdInputContainer',
  9709. priority: 200,
  9710. link: postLink
  9711. };
  9712. function postLink(scope, element, attr, inputContainer) {
  9713. // If there is no input container, just return
  9714. if (!inputContainer) return;
  9715. var label = inputContainer.element.find('label');
  9716. var hasNoFloat = angular.isDefined(inputContainer.element.attr('md-no-float'));
  9717. // If we have a label, or they specify the md-no-float attribute, just return
  9718. if ((label && label.length) || hasNoFloat) {
  9719. // Add a placeholder class so we can target it in the CSS
  9720. inputContainer.setHasPlaceholder(true);
  9721. return;
  9722. }
  9723. // Otherwise, grab/remove the placeholder
  9724. var placeholderText = attr.placeholder;
  9725. element.removeAttr('placeholder');
  9726. // And add the placeholder text as a separate label
  9727. if (inputContainer.input && inputContainer.input[0].nodeName != 'MD-SELECT') {
  9728. var placeholder = '<label ng-click="delegateClick()">' + placeholderText + '</label>';
  9729. inputContainer.element.addClass('md-icon-float');
  9730. inputContainer.element.prepend(placeholder);
  9731. }
  9732. }
  9733. }
  9734. placeholderDirective.$inject = ["$log"];
  9735. function ngMessagesDirective() {
  9736. return {
  9737. restrict: 'EA',
  9738. link: postLink,
  9739. // This is optional because we don't want target *all* ngMessage instances, just those inside of
  9740. // mdInputContainer.
  9741. require: '^^?mdInputContainer'
  9742. };
  9743. function postLink(scope, element, attr, inputContainer) {
  9744. // If we are not a child of an input container, don't do anything
  9745. if (!inputContainer) return;
  9746. // Tell our parent input container we have messages so we can set the proper classes
  9747. inputContainer.setHasMessages(true);
  9748. // When destroyed, inform our input container
  9749. scope.$on('$destroy', function() {
  9750. inputContainer.setHasMessages(false);
  9751. });
  9752. }
  9753. }
  9754. })();
  9755. (function(){
  9756. "use strict";
  9757. /**
  9758. * @ngdoc module
  9759. * @name material.components.list
  9760. * @description
  9761. * List module
  9762. */
  9763. angular.module('material.components.list', [
  9764. 'material.core'
  9765. ])
  9766. .controller('MdListController', MdListController)
  9767. .directive('mdList', mdListDirective)
  9768. .directive('mdListItem', mdListItemDirective);
  9769. /**
  9770. * @ngdoc directive
  9771. * @name mdList
  9772. * @module material.components.list
  9773. *
  9774. * @restrict E
  9775. *
  9776. * @description
  9777. * The `<md-list>` directive is a list container for 1..n `<md-list-item>` tags.
  9778. *
  9779. * @usage
  9780. * <hljs lang="html">
  9781. * <md-list>
  9782. * <md-list-item class="md-2-line" ng-repeat="item in todos">
  9783. * <md-checkbox ng-model="item.done"></md-checkbox>
  9784. * <div class="md-list-item-text">
  9785. * <h3>{{item.title}}</h3>
  9786. * <p>{{item.description}}</p>
  9787. * </div>
  9788. * </md-list-item>
  9789. * </md-list>
  9790. * </hljs>
  9791. */
  9792. function mdListDirective($mdTheming) {
  9793. return {
  9794. restrict: 'E',
  9795. compile: function(tEl) {
  9796. tEl[0].setAttribute('role', 'list');
  9797. return $mdTheming;
  9798. }
  9799. };
  9800. }
  9801. mdListDirective.$inject = ["$mdTheming"];
  9802. /**
  9803. * @ngdoc directive
  9804. * @name mdListItem
  9805. * @module material.components.list
  9806. *
  9807. * @restrict E
  9808. *
  9809. * @description
  9810. * The `<md-list-item>` directive is a container intended for row items in a `<md-list>` container.
  9811. *
  9812. * ## CSS
  9813. * `.md-avatar` - class for image avatars
  9814. *
  9815. * `.md-avatar-icon` - class for icon avatars
  9816. *
  9817. * `.md-offset` - on content without an avatar
  9818. *
  9819. * @usage
  9820. * <hljs lang="html">
  9821. * <md-list>
  9822. * <md-list-item>
  9823. * <img class="md-avatar" ng-src="path/to/img"/>
  9824. * <span>Item content in list</span>
  9825. * </md-list-item>
  9826. * <md-list-item>
  9827. * <md-icon class="md-avatar-icon" md-svg-icon="communication:phone"></md-icon>
  9828. * <span>Item content in list</span>
  9829. * </md-list-item>
  9830. * </md-list>
  9831. * </hljs>
  9832. *
  9833. */
  9834. function mdListItemDirective($mdAria, $mdConstant, $mdUtil, $timeout) {
  9835. var proxiedTypes = ['md-checkbox', 'md-switch'];
  9836. return {
  9837. restrict: 'E',
  9838. controller: 'MdListController',
  9839. compile: function(tEl, tAttrs) {
  9840. // Check for proxy controls (no ng-click on parent, and a control inside)
  9841. var secondaryItem = tEl[0].querySelector('.md-secondary');
  9842. var hasProxiedElement;
  9843. var proxyElement;
  9844. tEl[0].setAttribute('role', 'listitem');
  9845. if (!tAttrs.ngClick) {
  9846. for (var i = 0, type; type = proxiedTypes[i]; ++i) {
  9847. if (proxyElement = tEl[0].querySelector(type)) {
  9848. hasProxiedElement = true;
  9849. break;
  9850. }
  9851. }
  9852. if (hasProxiedElement) {
  9853. wrapIn('div');
  9854. } else if (!tEl[0].querySelector('md-button')) {
  9855. tEl.addClass('md-no-proxy');
  9856. }
  9857. } else {
  9858. wrapIn('button');
  9859. }
  9860. setupToggleAria();
  9861. function setupToggleAria() {
  9862. var toggleTypes = ['md-switch', 'md-checkbox'];
  9863. var toggle;
  9864. for (var i = 0, toggleType; toggleType = toggleTypes[i]; ++i) {
  9865. if (toggle = tEl.find(toggleType)[0]) {
  9866. if (!toggle.hasAttribute('aria-label')) {
  9867. var p = tEl.find('p')[0];
  9868. if (!p) return;
  9869. toggle.setAttribute('aria-label', 'Toggle ' + p.textContent);
  9870. }
  9871. }
  9872. }
  9873. }
  9874. function wrapIn(type) {
  9875. var container;
  9876. if (type == 'div') {
  9877. container = angular.element('<div class="md-no-style md-list-item-inner">');
  9878. container.append(tEl.contents());
  9879. tEl.addClass('md-proxy-focus');
  9880. } else {
  9881. container = angular.element('<md-button class="md-no-style"><div class="md-list-item-inner"></div></md-button>');
  9882. var copiedAttrs = ['ng-click', 'aria-label', 'ng-disabled'];
  9883. angular.forEach(copiedAttrs, function(attr) {
  9884. if (tEl[0].hasAttribute(attr)) {
  9885. container[0].setAttribute(attr, tEl[0].getAttribute(attr));
  9886. tEl[0].removeAttribute(attr);
  9887. }
  9888. });
  9889. container.children().eq(0).append(tEl.contents());
  9890. }
  9891. tEl[0].setAttribute('tabindex', '-1');
  9892. tEl.append(container);
  9893. if (secondaryItem && secondaryItem.hasAttribute('ng-click')) {
  9894. $mdAria.expect(secondaryItem, 'aria-label');
  9895. var buttonWrapper = angular.element('<md-button class="md-secondary-container md-icon-button">');
  9896. buttonWrapper.attr('ng-click', secondaryItem.getAttribute('ng-click'));
  9897. secondaryItem.removeAttribute('ng-click');
  9898. secondaryItem.setAttribute('tabindex', '-1');
  9899. secondaryItem.classList.remove('md-secondary');
  9900. buttonWrapper.append(secondaryItem);
  9901. secondaryItem = buttonWrapper[0];
  9902. }
  9903. // Check for a secondary item and move it outside
  9904. if ( secondaryItem && (
  9905. secondaryItem.hasAttribute('ng-click') ||
  9906. ( tAttrs.ngClick &&
  9907. isProxiedElement(secondaryItem) )
  9908. )) {
  9909. tEl.addClass('md-with-secondary');
  9910. tEl.append(secondaryItem);
  9911. }
  9912. }
  9913. function isProxiedElement(el) {
  9914. return proxiedTypes.indexOf(el.nodeName.toLowerCase()) != -1;
  9915. }
  9916. return postLink;
  9917. function postLink($scope, $element, $attr, ctrl) {
  9918. var proxies = [],
  9919. firstChild = $element[0].firstElementChild,
  9920. hasClick = firstChild && firstChild.hasAttribute('ng-click');
  9921. computeProxies();
  9922. computeClickable();
  9923. if ($element.hasClass('md-proxy-focus') && proxies.length) {
  9924. angular.forEach(proxies, function(proxy) {
  9925. proxy = angular.element(proxy);
  9926. $scope.mouseActive = false;
  9927. proxy.on('mousedown', function() {
  9928. $scope.mouseActive = true;
  9929. $timeout(function(){
  9930. $scope.mouseActive = false;
  9931. }, 100);
  9932. })
  9933. .on('focus', function() {
  9934. if ($scope.mouseActive === false) { $element.addClass('md-focused'); }
  9935. proxy.on('blur', function proxyOnBlur() {
  9936. $element.removeClass('md-focused');
  9937. proxy.off('blur', proxyOnBlur);
  9938. });
  9939. });
  9940. });
  9941. }
  9942. function computeProxies() {
  9943. var children = $element.children();
  9944. if (children.length && !children[0].hasAttribute('ng-click')) {
  9945. angular.forEach(proxiedTypes, function(type) {
  9946. angular.forEach(firstChild.querySelectorAll(type), function(child) {
  9947. proxies.push(child);
  9948. });
  9949. });
  9950. }
  9951. }
  9952. function computeClickable() {
  9953. if (proxies.length || hasClick) {
  9954. $element.addClass('md-clickable');
  9955. ctrl.attachRipple($scope, angular.element($element[0].querySelector('.md-no-style')));
  9956. }
  9957. }
  9958. if (!hasClick && !proxies.length) {
  9959. firstChild && firstChild.addEventListener('keypress', function(e) {
  9960. if (e.target.nodeName != 'INPUT' && e.target.nodeName != 'TEXTAREA') {
  9961. var keyCode = e.which || e.keyCode;
  9962. if (keyCode == $mdConstant.KEY_CODE.SPACE) {
  9963. if (firstChild) {
  9964. firstChild.click();
  9965. e.preventDefault();
  9966. e.stopPropagation();
  9967. }
  9968. }
  9969. }
  9970. });
  9971. }
  9972. $element.off('click');
  9973. $element.off('keypress');
  9974. if (proxies.length && firstChild) {
  9975. $element.children().eq(0).on('click', function(e) {
  9976. var parentButton = $mdUtil.getClosest(e.target, 'BUTTON');
  9977. if (!parentButton && firstChild.contains(e.target)) {
  9978. angular.forEach(proxies, function(proxy) {
  9979. if (e.target !== proxy && !proxy.contains(e.target)) {
  9980. angular.element(proxy).triggerHandler('click');
  9981. }
  9982. });
  9983. }
  9984. });
  9985. }
  9986. }
  9987. }
  9988. };
  9989. }
  9990. mdListItemDirective.$inject = ["$mdAria", "$mdConstant", "$mdUtil", "$timeout"];
  9991. /*
  9992. * @private
  9993. * @ngdoc controller
  9994. * @name MdListController
  9995. * @module material.components.list
  9996. *
  9997. */
  9998. function MdListController($scope, $element, $mdListInkRipple) {
  9999. var ctrl = this;
  10000. ctrl.attachRipple = attachRipple;
  10001. function attachRipple (scope, element) {
  10002. var options = {};
  10003. $mdListInkRipple.attach(scope, element, options);
  10004. }
  10005. }
  10006. MdListController.$inject = ["$scope", "$element", "$mdListInkRipple"];
  10007. })();
  10008. (function(){
  10009. "use strict";
  10010. /**
  10011. * @ngdoc module
  10012. * @name material.components.menu
  10013. */
  10014. angular.module('material.components.menu', [
  10015. 'material.core',
  10016. 'material.components.backdrop'
  10017. ]);
  10018. })();
  10019. (function(){
  10020. "use strict";
  10021. /**
  10022. * @ngdoc module
  10023. * @name material.components.menu-bar
  10024. */
  10025. angular.module('material.components.menuBar', [
  10026. 'material.core',
  10027. 'material.components.menu'
  10028. ]);
  10029. })();
  10030. (function(){
  10031. "use strict";
  10032. /**
  10033. * @ngdoc module
  10034. * @name material.components.progressCircular
  10035. * @description Circular Progress module!
  10036. */
  10037. angular.module('material.components.progressCircular', [
  10038. 'material.core'
  10039. ])
  10040. .directive('mdProgressCircular', MdProgressCircularDirective);
  10041. /**
  10042. * @ngdoc directive
  10043. * @name mdProgressCircular
  10044. * @module material.components.progressCircular
  10045. * @restrict E
  10046. *
  10047. * @description
  10048. * The circular progress directive is used to make loading content in your app as delightful and
  10049. * painless as possible by minimizing the amount of visual change a user sees before they can view
  10050. * and interact with content.
  10051. *
  10052. * For operations where the percentage of the operation completed can be determined, use a
  10053. * determinate indicator. They give users a quick sense of how long an operation will take.
  10054. *
  10055. * For operations where the user is asked to wait a moment while something finishes up, and it’s
  10056. * not necessary to expose what's happening behind the scenes and how long it will take, use an
  10057. * indeterminate indicator.
  10058. *
  10059. * @param {string} md-mode Select from one of two modes: **'determinate'** and **'indeterminate'**.
  10060. *
  10061. * Note: if the `md-mode` value is set as undefined or specified as not 1 of the two (2) valid modes, then `.ng-hide`
  10062. * will be auto-applied as a style to the component.
  10063. *
  10064. * Note: if not configured, the `md-mode="indeterminate"` will be auto injected as an attribute.
  10065. * If `value=""` is also specified, however, then `md-mode="determinate"` would be auto-injected instead.
  10066. * @param {number=} value In determinate mode, this number represents the percentage of the
  10067. * circular progress. Default: 0
  10068. * @param {number=} md-diameter This specifies the diamter of the circular progress. The value
  10069. * may be a percentage (eg '25%') or a pixel-size value (eg '48'). If this attribute is
  10070. * not present then a default value of '48px' is assumed.
  10071. *
  10072. * @usage
  10073. * <hljs lang="html">
  10074. * <md-progress-circular md-mode="determinate" value="..."></md-progress-circular>
  10075. *
  10076. * <md-progress-circular md-mode="determinate" ng-value="..."></md-progress-circular>
  10077. *
  10078. * <md-progress-circular md-mode="determinate" value="..." md-diameter="100"></md-progress-circular>
  10079. *
  10080. * <md-progress-circular md-mode="indeterminate"></md-progress-circular>
  10081. * </hljs>
  10082. */
  10083. function MdProgressCircularDirective($mdTheming, $mdUtil, $log) {
  10084. var DEFAULT_PROGRESS_SIZE = 100;
  10085. var DEFAULT_SCALING = 0.5;
  10086. var MODE_DETERMINATE = "determinate",
  10087. MODE_INDETERMINATE = "indeterminate";
  10088. return {
  10089. restrict: 'E',
  10090. scope : true,
  10091. template:
  10092. // The progress 'circle' is composed of two half-circles: the left side and the right
  10093. // side. Each side has CSS applied to 'fill-in' the half-circle to the appropriate progress.
  10094. '<div class="md-spinner-wrapper">' +
  10095. '<div class="md-inner">' +
  10096. '<div class="md-gap"></div>' +
  10097. '<div class="md-left">' +
  10098. '<div class="md-half-circle"></div>' +
  10099. '</div>' +
  10100. '<div class="md-right">' +
  10101. '<div class="md-half-circle"></div>' +
  10102. '</div>' +
  10103. '</div>' +
  10104. '</div>',
  10105. compile: compile
  10106. };
  10107. function compile(tElement) {
  10108. // The javascript in this file is mainly responsible for setting the correct aria attributes.
  10109. // The animation of the progress spinner is done entirely with just CSS.
  10110. tElement.attr('aria-valuemin', 0);
  10111. tElement.attr('aria-valuemax', 100);
  10112. tElement.attr('role', 'progressbar');
  10113. return postLink;
  10114. }
  10115. function postLink(scope, element, attr) {
  10116. $mdTheming(element);
  10117. var circle = element;
  10118. var spinnerWrapper = angular.element(element.children()[0]);
  10119. var lastMode, toVendorCSS = $mdUtil.dom.animator.toCss;
  10120. element.attr('md-mode', mode());
  10121. updateScale();
  10122. validateMode();
  10123. watchAttributes();
  10124. /**
  10125. * Watch the value and md-mode attributes
  10126. */
  10127. function watchAttributes() {
  10128. attr.$observe('value', function(value) {
  10129. var percentValue = clamp(value);
  10130. element.attr('aria-valuenow', percentValue);
  10131. if (mode() == MODE_DETERMINATE) {
  10132. animateIndicator(percentValue);
  10133. }
  10134. });
  10135. attr.$observe('mdMode',function(mode){
  10136. switch( mode ) {
  10137. case MODE_DETERMINATE:
  10138. case MODE_INDETERMINATE:
  10139. spinnerWrapper.removeClass('ng-hide');
  10140. spinnerWrapper.removeClass( lastMode );
  10141. spinnerWrapper.addClass( lastMode = "md-mode-" + mode );
  10142. break;
  10143. default:
  10144. spinnerWrapper.removeClass( lastMode );
  10145. spinnerWrapper.addClass('ng-hide');
  10146. lastMode = undefined;
  10147. break;
  10148. }
  10149. });
  10150. }
  10151. /**
  10152. * Update size/scaling of the progress indicator
  10153. * Watch the "value" and "md-mode" attributes
  10154. */
  10155. function updateScale() {
  10156. circle.css(toVendorCSS({
  10157. transform : $mdUtil.supplant('scale( {0} )',[getDiameterRatio()])
  10158. }));
  10159. }
  10160. /**
  10161. * Auto-defaults the mode to either `determinate` or `indeterminate` mode; if not specified
  10162. */
  10163. function validateMode() {
  10164. if ( angular.isUndefined(attr.mdMode) ) {
  10165. var hasValue = angular.isDefined(attr.value);
  10166. var mode = hasValue ? MODE_DETERMINATE : MODE_INDETERMINATE;
  10167. var info = "Auto-adding the missing md-mode='{0}' to the ProgressCircular element";
  10168. $log.debug( $mdUtil.supplant(info, [mode]) );
  10169. element.attr("md-mode",mode);
  10170. attr['mdMode'] = mode;
  10171. }
  10172. }
  10173. var leftC, rightC, gap;
  10174. /**
  10175. * Manually animate the Determinate indicator based on the specified
  10176. * percentage value (0-100).
  10177. *
  10178. * Note: this animation was previously done using SCSS.
  10179. * - generated 54K of styles
  10180. * - use attribute selectors which had poor performances in IE
  10181. */
  10182. function animateIndicator(value) {
  10183. if ( !mode() ) return;
  10184. leftC = leftC || angular.element(element[0].querySelector('.md-left > .md-half-circle'));
  10185. rightC = rightC || angular.element(element[0].querySelector('.md-right > .md-half-circle'));
  10186. gap = gap || angular.element(element[0].querySelector('.md-gap'));
  10187. var gapStyles = removeEmptyValues({
  10188. borderBottomColor: (value <= 50) ? "transparent !important" : "",
  10189. transition: (value <= 50) ? "" : "borderBottomColor 0.1s linear"
  10190. }),
  10191. leftStyles = removeEmptyValues({
  10192. transition: (value <= 50) ? "transform 0.1s linear" : "",
  10193. transform: $mdUtil.supplant("rotate({0}deg)", [value <= 50 ? 135 : (((value - 50) / 50 * 180) + 135)])
  10194. }),
  10195. rightStyles = removeEmptyValues({
  10196. transition: (value >= 50) ? "transform 0.1s linear" : "",
  10197. transform: $mdUtil.supplant("rotate({0}deg)", [value >= 50 ? 45 : (value / 50 * 180 - 135)])
  10198. });
  10199. leftC.css(toVendorCSS(leftStyles));
  10200. rightC.css(toVendorCSS(rightStyles));
  10201. gap.css(toVendorCSS(gapStyles));
  10202. }
  10203. /**
  10204. * We will scale the progress circle based on the default diameter.
  10205. *
  10206. * Determine the diameter percentage (defaults to 100%)
  10207. * May be express as float, percentage, or integer
  10208. */
  10209. function getDiameterRatio() {
  10210. if ( !attr.mdDiameter ) return DEFAULT_SCALING;
  10211. var match = /([0-9]*)%/.exec(attr.mdDiameter);
  10212. var value = Math.max(0, (match && match[1]/100) || parseFloat(attr.mdDiameter));
  10213. // should return ratio; DEFAULT_PROGRESS_SIZE === 100px is default size
  10214. return (value > 1) ? value / DEFAULT_PROGRESS_SIZE : value;
  10215. }
  10216. /**
  10217. * Is the md-mode a valid option?
  10218. */
  10219. function mode() {
  10220. var value = (attr.mdMode || "").trim();
  10221. if ( value ) {
  10222. switch(value) {
  10223. case MODE_DETERMINATE :
  10224. case MODE_INDETERMINATE :
  10225. break;
  10226. default:
  10227. value = undefined;
  10228. break;
  10229. }
  10230. }
  10231. return value;
  10232. }
  10233. }
  10234. /**
  10235. * Clamps the value to be between 0 and 100.
  10236. * @param {number} value The value to clamp.
  10237. * @returns {number}
  10238. */
  10239. function clamp(value) {
  10240. return Math.max(0, Math.min(value || 0, 100));
  10241. }
  10242. function removeEmptyValues(target) {
  10243. for (var key in target) {
  10244. if (target.hasOwnProperty(key)) {
  10245. if ( target[key] == "" ) delete target[key];
  10246. }
  10247. }
  10248. return target;
  10249. }
  10250. }
  10251. MdProgressCircularDirective.$inject = ["$mdTheming", "$mdUtil", "$log"];
  10252. })();
  10253. (function(){
  10254. "use strict";
  10255. /**
  10256. * @ngdoc module
  10257. * @name material.components.radioButton
  10258. * @description radioButton module!
  10259. */
  10260. angular.module('material.components.radioButton', [
  10261. 'material.core'
  10262. ])
  10263. .directive('mdRadioGroup', mdRadioGroupDirective)
  10264. .directive('mdRadioButton', mdRadioButtonDirective);
  10265. /**
  10266. * @ngdoc directive
  10267. * @module material.components.radioButton
  10268. * @name mdRadioGroup
  10269. *
  10270. * @restrict E
  10271. *
  10272. * @description
  10273. * The `<md-radio-group>` directive identifies a grouping
  10274. * container for the 1..n grouped radio buttons; specified using nested
  10275. * `<md-radio-button>` tags.
  10276. *
  10277. * As per the [material design spec](http://www.google.com/design/spec/style/color.html#color-ui-color-application)
  10278. * the radio button is in the accent color by default. The primary color palette may be used with
  10279. * the `md-primary` class.
  10280. *
  10281. * Note: `<md-radio-group>` and `<md-radio-button>` handle tabindex differently
  10282. * than the native `<input type='radio'>` controls. Whereas the native controls
  10283. * force the user to tab through all the radio buttons, `<md-radio-group>`
  10284. * is focusable, and by default the `<md-radio-button>`s are not.
  10285. *
  10286. * @param {string} ng-model Assignable angular expression to data-bind to.
  10287. * @param {boolean=} md-no-ink Use of attribute indicates flag to disable ink ripple effects.
  10288. *
  10289. * @usage
  10290. * <hljs lang="html">
  10291. * <md-radio-group ng-model="selected">
  10292. *
  10293. * <md-radio-button
  10294. * ng-repeat="d in colorOptions"
  10295. * ng-value="d.value" aria-label="{{ d.label }}">
  10296. *
  10297. * {{ d.label }}
  10298. *
  10299. * </md-radio-button>
  10300. *
  10301. * </md-radio-group>
  10302. * </hljs>
  10303. *
  10304. */
  10305. function mdRadioGroupDirective($mdUtil, $mdConstant, $mdTheming, $timeout) {
  10306. RadioGroupController.prototype = createRadioGroupControllerProto();
  10307. return {
  10308. restrict: 'E',
  10309. controller: ['$element', RadioGroupController],
  10310. require: ['mdRadioGroup', '?ngModel'],
  10311. link: { pre: linkRadioGroup }
  10312. };
  10313. function linkRadioGroup(scope, element, attr, ctrls) {
  10314. $mdTheming(element);
  10315. var rgCtrl = ctrls[0];
  10316. var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel();
  10317. rgCtrl.init(ngModelCtrl);
  10318. scope.mouseActive = false;
  10319. element.attr({
  10320. 'role': 'radiogroup',
  10321. 'tabIndex': element.attr('tabindex') || '0'
  10322. })
  10323. .on('keydown', keydownListener)
  10324. .on('mousedown', function(event) {
  10325. scope.mouseActive = true;
  10326. $timeout(function() {
  10327. scope.mouseActive = false;
  10328. }, 100);
  10329. })
  10330. .on('focus', function() {
  10331. if(scope.mouseActive === false) { rgCtrl.$element.addClass('md-focused'); }
  10332. })
  10333. .on('blur', function() { rgCtrl.$element.removeClass('md-focused'); });
  10334. /**
  10335. *
  10336. */
  10337. function setFocus() {
  10338. if (!element.hasClass('md-focused')) { element.addClass('md-focused'); }
  10339. }
  10340. /**
  10341. *
  10342. */
  10343. function keydownListener(ev) {
  10344. var keyCode = ev.which || ev.keyCode;
  10345. switch(keyCode) {
  10346. case $mdConstant.KEY_CODE.LEFT_ARROW:
  10347. case $mdConstant.KEY_CODE.UP_ARROW:
  10348. ev.preventDefault();
  10349. rgCtrl.selectPrevious();
  10350. setFocus();
  10351. break;
  10352. case $mdConstant.KEY_CODE.RIGHT_ARROW:
  10353. case $mdConstant.KEY_CODE.DOWN_ARROW:
  10354. ev.preventDefault();
  10355. rgCtrl.selectNext();
  10356. setFocus();
  10357. break;
  10358. case $mdConstant.KEY_CODE.ENTER:
  10359. var form = angular.element($mdUtil.getClosest(element[0], 'form'));
  10360. if (form.length > 0) {
  10361. form.triggerHandler('submit');
  10362. }
  10363. break;
  10364. }
  10365. }
  10366. }
  10367. function RadioGroupController($element) {
  10368. this._radioButtonRenderFns = [];
  10369. this.$element = $element;
  10370. }
  10371. function createRadioGroupControllerProto() {
  10372. return {
  10373. init: function(ngModelCtrl) {
  10374. this._ngModelCtrl = ngModelCtrl;
  10375. this._ngModelCtrl.$render = angular.bind(this, this.render);
  10376. },
  10377. add: function(rbRender) {
  10378. this._radioButtonRenderFns.push(rbRender);
  10379. },
  10380. remove: function(rbRender) {
  10381. var index = this._radioButtonRenderFns.indexOf(rbRender);
  10382. if (index !== -1) {
  10383. this._radioButtonRenderFns.splice(index, 1);
  10384. }
  10385. },
  10386. render: function() {
  10387. this._radioButtonRenderFns.forEach(function(rbRender) {
  10388. rbRender();
  10389. });
  10390. },
  10391. setViewValue: function(value, eventType) {
  10392. this._ngModelCtrl.$setViewValue(value, eventType);
  10393. // update the other radio buttons as well
  10394. this.render();
  10395. },
  10396. getViewValue: function() {
  10397. return this._ngModelCtrl.$viewValue;
  10398. },
  10399. selectNext: function() {
  10400. return changeSelectedButton(this.$element, 1);
  10401. },
  10402. selectPrevious: function() {
  10403. return changeSelectedButton(this.$element, -1);
  10404. },
  10405. setActiveDescendant: function (radioId) {
  10406. this.$element.attr('aria-activedescendant', radioId);
  10407. }
  10408. };
  10409. }
  10410. /**
  10411. * Change the radio group's selected button by a given increment.
  10412. * If no button is selected, select the first button.
  10413. */
  10414. function changeSelectedButton(parent, increment) {
  10415. // Coerce all child radio buttons into an array, then wrap then in an iterator
  10416. var buttons = $mdUtil.iterator(parent[0].querySelectorAll('md-radio-button'), true);
  10417. if (buttons.count()) {
  10418. var validate = function (button) {
  10419. // If disabled, then NOT valid
  10420. return !angular.element(button).attr("disabled");
  10421. };
  10422. var selected = parent[0].querySelector('md-radio-button.md-checked');
  10423. var target = buttons[increment < 0 ? 'previous' : 'next'](selected, validate) || buttons.first();
  10424. // Activate radioButton's click listener (triggerHandler won't create a real click event)
  10425. angular.element(target).triggerHandler('click');
  10426. }
  10427. }
  10428. }
  10429. mdRadioGroupDirective.$inject = ["$mdUtil", "$mdConstant", "$mdTheming", "$timeout"];
  10430. /**
  10431. * @ngdoc directive
  10432. * @module material.components.radioButton
  10433. * @name mdRadioButton
  10434. *
  10435. * @restrict E
  10436. *
  10437. * @description
  10438. * The `<md-radio-button>`directive is the child directive required to be used within `<md-radio-group>` elements.
  10439. *
  10440. * While similar to the `<input type="radio" ng-model="" value="">` directive,
  10441. * the `<md-radio-button>` directive provides ink effects, ARIA support, and
  10442. * supports use within named radio groups.
  10443. *
  10444. * @param {string} ngModel Assignable angular expression to data-bind to.
  10445. * @param {string=} ngChange Angular expression to be executed when input changes due to user
  10446. * interaction with the input element.
  10447. * @param {string} ngValue Angular expression which sets the value to which the expression should
  10448. * be set when selected.
  10449. * @param {string} value The value to which the expression should be set when selected.
  10450. * @param {string=} name Property name of the form under which the control is published.
  10451. * @param {string=} aria-label Adds label to radio button for accessibility.
  10452. * Defaults to radio button's text. If no text content is available, a warning will be logged.
  10453. *
  10454. * @usage
  10455. * <hljs lang="html">
  10456. *
  10457. * <md-radio-button value="1" aria-label="Label 1">
  10458. * Label 1
  10459. * </md-radio-button>
  10460. *
  10461. * <md-radio-button ng-model="color" ng-value="specialValue" aria-label="Green">
  10462. * Green
  10463. * </md-radio-button>
  10464. *
  10465. * </hljs>
  10466. *
  10467. */
  10468. function mdRadioButtonDirective($mdAria, $mdUtil, $mdTheming) {
  10469. var CHECKED_CSS = 'md-checked';
  10470. return {
  10471. restrict: 'E',
  10472. require: '^mdRadioGroup',
  10473. transclude: true,
  10474. template: '<div class="md-container" md-ink-ripple md-ink-ripple-checkbox>' +
  10475. '<div class="md-off"></div>' +
  10476. '<div class="md-on"></div>' +
  10477. '</div>' +
  10478. '<div ng-transclude class="md-label"></div>',
  10479. link: link
  10480. };
  10481. function link(scope, element, attr, rgCtrl) {
  10482. var lastChecked;
  10483. $mdTheming(element);
  10484. configureAria(element, scope);
  10485. initialize();
  10486. /**
  10487. *
  10488. */
  10489. function initialize(controller) {
  10490. if ( !rgCtrl ) {
  10491. throw 'RadioGroupController not found.';
  10492. }
  10493. rgCtrl.add(render);
  10494. attr.$observe('value', render);
  10495. element
  10496. .on('click', listener)
  10497. .on('$destroy', function() {
  10498. rgCtrl.remove(render);
  10499. });
  10500. }
  10501. /**
  10502. *
  10503. */
  10504. function listener(ev) {
  10505. if (element[0].hasAttribute('disabled')) return;
  10506. scope.$apply(function() {
  10507. rgCtrl.setViewValue(attr.value, ev && ev.type);
  10508. });
  10509. }
  10510. /**
  10511. * Add or remove the `.md-checked` class from the RadioButton (and conditionally its parent).
  10512. * Update the `aria-activedescendant` attribute.
  10513. */
  10514. function render() {
  10515. var checked = (rgCtrl.getViewValue() == attr.value);
  10516. if (checked === lastChecked) {
  10517. return;
  10518. }
  10519. lastChecked = checked;
  10520. element.attr('aria-checked', checked);
  10521. if (checked) {
  10522. markParentAsChecked(true);
  10523. element.addClass(CHECKED_CSS);
  10524. rgCtrl.setActiveDescendant(element.attr('id'));
  10525. } else {
  10526. markParentAsChecked(false);
  10527. element.removeClass(CHECKED_CSS);
  10528. }
  10529. /**
  10530. * If the radioButton is inside a div, then add class so highlighting will work...
  10531. */
  10532. function markParentAsChecked(addClass ) {
  10533. if ( element.parent()[0].nodeName != "MD-RADIO-GROUP") {
  10534. element.parent()[ !!addClass ? 'addClass' : 'removeClass'](CHECKED_CSS);
  10535. }
  10536. }
  10537. }
  10538. /**
  10539. * Inject ARIA-specific attributes appropriate for each radio button
  10540. */
  10541. function configureAria( element, scope ){
  10542. scope.ariaId = buildAriaID();
  10543. element.attr({
  10544. 'id' : scope.ariaId,
  10545. 'role' : 'radio',
  10546. 'aria-checked' : 'false'
  10547. });
  10548. $mdAria.expectWithText(element, 'aria-label');
  10549. /**
  10550. * Build a unique ID for each radio button that will be used with aria-activedescendant.
  10551. * Preserve existing ID if already specified.
  10552. * @returns {*|string}
  10553. */
  10554. function buildAriaID() {
  10555. return attr.id || ( 'radio' + "_" + $mdUtil.nextUid() );
  10556. }
  10557. }
  10558. }
  10559. }
  10560. mdRadioButtonDirective.$inject = ["$mdAria", "$mdUtil", "$mdTheming"];
  10561. })();
  10562. (function(){
  10563. "use strict";
  10564. /**
  10565. * @ngdoc module
  10566. * @name material.components.progressLinear
  10567. * @description Linear Progress module!
  10568. */
  10569. angular.module('material.components.progressLinear', [
  10570. 'material.core'
  10571. ])
  10572. .directive('mdProgressLinear', MdProgressLinearDirective);
  10573. /**
  10574. * @ngdoc directive
  10575. * @name mdProgressLinear
  10576. * @module material.components.progressLinear
  10577. * @restrict E
  10578. *
  10579. * @description
  10580. * The linear progress directive is used to make loading content
  10581. * in your app as delightful and painless as possible by minimizing
  10582. * the amount of visual change a user sees before they can view
  10583. * and interact with content.
  10584. *
  10585. * Each operation should only be represented by one activity indicator
  10586. * For example: one refresh operation should not display both a
  10587. * refresh bar and an activity circle.
  10588. *
  10589. * For operations where the percentage of the operation completed
  10590. * can be determined, use a determinate indicator. They give users
  10591. * a quick sense of how long an operation will take.
  10592. *
  10593. * For operations where the user is asked to wait a moment while
  10594. * something finishes up, and it’s not necessary to expose what's
  10595. * happening behind the scenes and how long it will take, use an
  10596. * indeterminate indicator.
  10597. *
  10598. * @param {string} md-mode Select from one of four modes: determinate, indeterminate, buffer or query.
  10599. *
  10600. * Note: if the `md-mode` value is set as undefined or specified as 1 of the four (4) valid modes, then `.ng-hide`
  10601. * will be auto-applied as a style to the component.
  10602. *
  10603. * Note: if not configured, the `md-mode="indeterminate"` will be auto injected as an attribute. If `value=""` is also specified, however,
  10604. * then `md-mode="determinate"` would be auto-injected instead.
  10605. * @param {number=} value In determinate and buffer modes, this number represents the percentage of the primary progress bar. Default: 0
  10606. * @param {number=} md-buffer-value In the buffer mode, this number represents the percentage of the secondary progress bar. Default: 0
  10607. *
  10608. * @usage
  10609. * <hljs lang="html">
  10610. * <md-progress-linear md-mode="determinate" value="..."></md-progress-linear>
  10611. *
  10612. * <md-progress-linear md-mode="determinate" ng-value="..."></md-progress-linear>
  10613. *
  10614. * <md-progress-linear md-mode="indeterminate"></md-progress-linear>
  10615. *
  10616. * <md-progress-linear md-mode="buffer" value="..." md-buffer-value="..."></md-progress-linear>
  10617. *
  10618. * <md-progress-linear md-mode="query"></md-progress-linear>
  10619. * </hljs>
  10620. */
  10621. function MdProgressLinearDirective($mdTheming, $mdUtil, $log) {
  10622. var MODE_DETERMINATE = "determinate",
  10623. MODE_INDETERMINATE = "indeterminate",
  10624. MODE_BUFFER = "buffer",
  10625. MODE_QUERY = "query";
  10626. return {
  10627. restrict: 'E',
  10628. template: '<div class="md-container">' +
  10629. '<div class="md-dashed"></div>' +
  10630. '<div class="md-bar md-bar1"></div>' +
  10631. '<div class="md-bar md-bar2"></div>' +
  10632. '</div>',
  10633. compile: compile
  10634. };
  10635. function compile(tElement, tAttrs, transclude) {
  10636. tElement.attr('aria-valuemin', 0);
  10637. tElement.attr('aria-valuemax', 100);
  10638. tElement.attr('role', 'progressbar');
  10639. return postLink;
  10640. }
  10641. function postLink(scope, element, attr) {
  10642. $mdTheming(element);
  10643. var lastMode, toVendorCSS = $mdUtil.dom.animator.toCss;
  10644. var bar1 = angular.element(element[0].querySelector('.md-bar1')),
  10645. bar2 = angular.element(element[0].querySelector('.md-bar2')),
  10646. container = angular.element(element[0].querySelector('.md-container'));
  10647. element.attr('md-mode', mode());
  10648. validateMode();
  10649. watchAttributes();
  10650. /**
  10651. * Watch the value, md-buffer-value, and md-mode attributes
  10652. */
  10653. function watchAttributes() {
  10654. attr.$observe('value', function(value) {
  10655. var percentValue = clamp(value);
  10656. element.attr('aria-valuenow', percentValue);
  10657. if (mode() != MODE_QUERY) animateIndicator(bar2, percentValue);
  10658. });
  10659. attr.$observe('mdBufferValue', function(value) {
  10660. animateIndicator(bar1, clamp(value));
  10661. });
  10662. attr.$observe('mdMode',function(mode){
  10663. switch( mode ) {
  10664. case MODE_QUERY:
  10665. case MODE_BUFFER:
  10666. case MODE_DETERMINATE:
  10667. case MODE_INDETERMINATE:
  10668. container.removeClass( 'ng-hide' + ' ' + lastMode );
  10669. container.addClass( lastMode = "md-mode-" + mode );
  10670. break;
  10671. default:
  10672. container.removeClass( lastMode );
  10673. container.addClass('ng-hide');
  10674. lastMode = undefined;
  10675. break;
  10676. }
  10677. });
  10678. }
  10679. /**
  10680. * Auto-defaults the mode to either `determinate` or `indeterminate` mode; if not specified
  10681. */
  10682. function validateMode() {
  10683. if ( angular.isUndefined(attr.mdMode) ) {
  10684. var hasValue = angular.isDefined(attr.value);
  10685. var mode = hasValue ? MODE_DETERMINATE : MODE_INDETERMINATE;
  10686. var info = "Auto-adding the missing md-mode='{0}' to the ProgressLinear element";
  10687. $log.debug( $mdUtil.supplant(info, [mode]) );
  10688. element.attr("md-mode",mode);
  10689. attr['mdMode'] = mode;
  10690. }
  10691. }
  10692. /**
  10693. * Is the md-mode a valid option?
  10694. */
  10695. function mode() {
  10696. var value = (attr.mdMode || "").trim();
  10697. if ( value ) {
  10698. switch(value) {
  10699. case MODE_DETERMINATE:
  10700. case MODE_INDETERMINATE:
  10701. case MODE_BUFFER:
  10702. case MODE_QUERY:
  10703. break;
  10704. default:
  10705. value = undefined;
  10706. break;
  10707. }
  10708. }
  10709. return value;
  10710. }
  10711. /**
  10712. * Manually set CSS to animate the Determinate indicator based on the specified
  10713. * percentage value (0-100).
  10714. */
  10715. function animateIndicator(target, value) {
  10716. if ( !mode() ) return;
  10717. var to = $mdUtil.supplant("translateX({0}%) scale({1},1)", [ (value-100)/2, value/100 ]);
  10718. var styles = toVendorCSS({ transform : to });
  10719. angular.element(target).css( styles );
  10720. }
  10721. }
  10722. /**
  10723. * Clamps the value to be between 0 and 100.
  10724. * @param {number} value The value to clamp.
  10725. * @returns {number}
  10726. */
  10727. function clamp(value) {
  10728. return Math.max(0, Math.min(value || 0, 100));
  10729. }
  10730. }
  10731. MdProgressLinearDirective.$inject = ["$mdTheming", "$mdUtil", "$log"];
  10732. })();
  10733. (function(){
  10734. "use strict";
  10735. /**
  10736. * @ngdoc module
  10737. * @name material.components.select
  10738. */
  10739. /***************************************************
  10740. ### TODO ###
  10741. **DOCUMENTATION AND DEMOS**
  10742. - [ ] ng-model with child mdOptions (basic)
  10743. - [ ] ng-model="foo" ng-model-options="{ trackBy: '$value.id' }" for objects
  10744. - [ ] mdOption with value
  10745. - [ ] Usage with input inside
  10746. ### TODO - POST RC1 ###
  10747. - [ ] Abstract placement logic in $mdSelect service to $mdMenu service
  10748. ***************************************************/
  10749. var SELECT_EDGE_MARGIN = 8;
  10750. var selectNextId = 0;
  10751. angular.module('material.components.select', [
  10752. 'material.core',
  10753. 'material.components.backdrop'
  10754. ])
  10755. .directive('mdSelect', SelectDirective)
  10756. .directive('mdSelectMenu', SelectMenuDirective)
  10757. .directive('mdOption', OptionDirective)
  10758. .directive('mdOptgroup', OptgroupDirective)
  10759. .provider('$mdSelect', SelectProvider);
  10760. /**
  10761. * @ngdoc directive
  10762. * @name mdSelect
  10763. * @restrict E
  10764. * @module material.components.select
  10765. *
  10766. * @description Displays a select box, bound to an ng-model.
  10767. *
  10768. * @param {expression} ng-model The model!
  10769. * @param {boolean=} multiple Whether it's multiple.
  10770. * @param {expression=} md-on-close Expression to be evaluated when the select is closed.
  10771. * @param {string=} placeholder Placeholder hint text.
  10772. * @param {string=} aria-label Optional label for accessibility. Only necessary if no placeholder or
  10773. * explicit label is present.
  10774. * @param {string=} md-container-class Class list to get applied to the `.md-select-menu-container`
  10775. * element (for custom styling).
  10776. *
  10777. * @usage
  10778. * With a placeholder (label and aria-label are added dynamically)
  10779. * <hljs lang="html">
  10780. * <md-input-container>
  10781. * <md-select
  10782. * ng-model="someModel"
  10783. * placeholder="Select a state">
  10784. * <md-option ng-value="opt" ng-repeat="opt in neighborhoods2">{{ opt }}</md-option>
  10785. * </md-select>
  10786. * </md-input-container>
  10787. * </hljs>
  10788. *
  10789. * With an explicit label
  10790. * <hljs lang="html">
  10791. * <md-input-container>
  10792. * <label>State</label>
  10793. * <md-select
  10794. * ng-model="someModel">
  10795. * <md-option ng-value="opt" ng-repeat="opt in neighborhoods2">{{ opt }}</md-option>
  10796. * </md-select>
  10797. * </md-input-container>
  10798. * </hljs>
  10799. */
  10800. function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $parse) {
  10801. return {
  10802. restrict: 'E',
  10803. require: ['^?mdInputContainer', 'mdSelect', 'ngModel', '?^form'],
  10804. compile: compile,
  10805. controller: function() {
  10806. } // empty placeholder controller to be initialized in link
  10807. };
  10808. function compile(element, attr) {
  10809. // add the select value that will hold our placeholder or selected option value
  10810. var valueEl = angular.element('<md-select-value><span></span></md-select-value>');
  10811. valueEl.append('<span class="md-select-icon" aria-hidden="true"></span>');
  10812. valueEl.addClass('md-select-value');
  10813. if (!valueEl[0].hasAttribute('id')) {
  10814. valueEl.attr('id', 'select_value_label_' + $mdUtil.nextUid());
  10815. }
  10816. // There's got to be an md-content inside. If there's not one, let's add it.
  10817. if (!element.find('md-content').length) {
  10818. element.append(angular.element('<md-content>').append(element.contents()));
  10819. }
  10820. // Add progress spinner for md-options-loading
  10821. if (attr.mdOnOpen) {
  10822. // Show progress indicator while loading async
  10823. // Use ng-hide for `display:none` so the indicator does not interfere with the options list
  10824. element
  10825. .find('md-content')
  10826. .prepend(angular.element(
  10827. '<div>' +
  10828. ' <md-progress-circular md-mode="{{progressMode}}" ng-hide="$$loadingAsyncDone"></md-progress-circular>' +
  10829. '</div>'
  10830. ));
  10831. // Hide list [of item options] while loading async
  10832. element
  10833. .find('md-option')
  10834. .attr('ng-show', '$$loadingAsyncDone');
  10835. }
  10836. if (attr.name) {
  10837. var autofillClone = angular.element('<select class="md-visually-hidden">');
  10838. autofillClone.attr({
  10839. 'name': '.' + attr.name,
  10840. 'ng-model': attr.ngModel,
  10841. 'aria-hidden': 'true',
  10842. 'tabindex': '-1'
  10843. });
  10844. var opts = element.find('md-option');
  10845. angular.forEach(opts, function(el) {
  10846. var newEl = angular.element('<option>' + el.innerHTML + '</option>');
  10847. if (el.hasAttribute('ng-value')) newEl.attr('ng-value', el.getAttribute('ng-value'));
  10848. else if (el.hasAttribute('value')) newEl.attr('value', el.getAttribute('value'));
  10849. autofillClone.append(newEl);
  10850. });
  10851. element.parent().append(autofillClone);
  10852. }
  10853. // Use everything that's left inside element.contents() as the contents of the menu
  10854. var multiple = angular.isDefined(attr.multiple) ? 'multiple' : '';
  10855. var selectTemplate = '' +
  10856. '<div class="md-select-menu-container">' +
  10857. '<md-select-menu {0}>{1}</md-select-menu>' +
  10858. '</div>';
  10859. selectTemplate = $mdUtil.supplant(selectTemplate, [multiple, element.html()]);
  10860. element.empty().append(valueEl);
  10861. attr.tabindex = attr.tabindex || '0';
  10862. return function postLink(scope, element, attr, ctrls) {
  10863. var isDisabled;
  10864. var containerCtrl = ctrls[0];
  10865. var mdSelectCtrl = ctrls[1];
  10866. var ngModelCtrl = ctrls[2];
  10867. var formCtrl = ctrls[3];
  10868. // grab a reference to the select menu value label
  10869. var valueEl = element.find('md-select-value');
  10870. var isReadonly = angular.isDefined(attr.readonly);
  10871. if (containerCtrl) {
  10872. var isErrorGetter = containerCtrl.isErrorGetter || function() {
  10873. return ngModelCtrl.$invalid && ngModelCtrl.$touched;
  10874. };
  10875. if (containerCtrl.input) {
  10876. throw new Error("<md-input-container> can only have *one* child <input>, <textarea> or <select> element!");
  10877. }
  10878. containerCtrl.input = element;
  10879. if (!containerCtrl.label) {
  10880. $mdAria.expect(element, 'aria-label', element.attr('placeholder'));
  10881. }
  10882. scope.$watch(isErrorGetter, containerCtrl.setInvalid);
  10883. }
  10884. var selectContainer, selectScope, selectMenuCtrl;
  10885. createSelect();
  10886. $mdTheming(element);
  10887. if (attr.name && formCtrl) {
  10888. var selectEl = element.parent()[0].querySelector('select[name=".' + attr.name + '"]');
  10889. var controller = angular.element(selectEl).controller();
  10890. if (controller) {
  10891. formCtrl.$removeControl(controller);
  10892. }
  10893. }
  10894. if (formCtrl) {
  10895. $mdUtil.nextTick(function() {
  10896. formCtrl.$setPristine();
  10897. });
  10898. }
  10899. var originalRender = ngModelCtrl.$render;
  10900. ngModelCtrl.$render = function() {
  10901. originalRender();
  10902. syncLabelText();
  10903. inputCheckValue();
  10904. };
  10905. attr.$observe('placeholder', ngModelCtrl.$render);
  10906. mdSelectCtrl.setLabelText = function(text) {
  10907. mdSelectCtrl.setIsPlaceholder(!text);
  10908. // Use placeholder attribute, otherwise fallback to the md-input-container label
  10909. var tmpPlaceholder = attr.placeholder || (containerCtrl && containerCtrl.label ? containerCtrl.label.text() : '');
  10910. text = text || tmpPlaceholder || '';
  10911. var target = valueEl.children().eq(0);
  10912. target.text(text);
  10913. };
  10914. mdSelectCtrl.setIsPlaceholder = function(isPlaceholder) {
  10915. if (isPlaceholder) {
  10916. valueEl.addClass('md-select-placeholder');
  10917. if (containerCtrl && containerCtrl.label) {
  10918. containerCtrl.label.addClass('md-placeholder md-static');
  10919. }
  10920. } else {
  10921. valueEl.removeClass('md-select-placeholder');
  10922. if (containerCtrl && containerCtrl.label) {
  10923. containerCtrl.label.removeClass('md-placeholder');
  10924. }
  10925. }
  10926. };
  10927. if (!isReadonly) {
  10928. element
  10929. .on('focus', function(ev) {
  10930. // only set focus on if we don't currently have a selected value. This avoids the "bounce"
  10931. // on the label transition because the focus will immediately switch to the open menu.
  10932. if (containerCtrl && containerCtrl.element.hasClass('md-input-has-value')) {
  10933. containerCtrl.setFocused(true);
  10934. }
  10935. })
  10936. .on('blur', function(ev) {
  10937. containerCtrl && containerCtrl.setFocused(false);
  10938. inputCheckValue();
  10939. });
  10940. }
  10941. mdSelectCtrl.triggerClose = function() {
  10942. $parse(attr.mdOnClose)(scope);
  10943. };
  10944. scope.$$postDigest(function() {
  10945. setAriaLabel();
  10946. syncLabelText();
  10947. });
  10948. function setAriaLabel() {
  10949. var labelText = element.attr('placeholder');
  10950. if (!labelText && containerCtrl && containerCtrl.label) {
  10951. labelText = containerCtrl.label.text();
  10952. }
  10953. $mdAria.expect(element, 'aria-label', labelText);
  10954. }
  10955. function syncLabelText() {
  10956. if (selectContainer) {
  10957. selectMenuCtrl = selectMenuCtrl || selectContainer.find('md-select-menu').controller('mdSelectMenu');
  10958. mdSelectCtrl.setLabelText(selectMenuCtrl.selectedLabels());
  10959. }
  10960. }
  10961. var deregisterWatcher;
  10962. attr.$observe('ngMultiple', function(val) {
  10963. if (deregisterWatcher) deregisterWatcher();
  10964. var parser = $parse(val);
  10965. deregisterWatcher = scope.$watch(function() {
  10966. return parser(scope);
  10967. }, function(multiple, prevVal) {
  10968. if (multiple === undefined && prevVal === undefined) return; // assume compiler did a good job
  10969. if (multiple) {
  10970. element.attr('multiple', 'multiple');
  10971. } else {
  10972. element.removeAttr('multiple');
  10973. }
  10974. if (selectContainer) {
  10975. selectMenuCtrl.setMultiple(multiple);
  10976. originalRender = ngModelCtrl.$render;
  10977. ngModelCtrl.$render = function() {
  10978. originalRender();
  10979. syncLabelText();
  10980. };
  10981. selectMenuCtrl.refreshViewValue();
  10982. ngModelCtrl.$render();
  10983. }
  10984. });
  10985. });
  10986. attr.$observe('disabled', function(disabled) {
  10987. if (angular.isString(disabled)) {
  10988. disabled = true;
  10989. }
  10990. // Prevent click event being registered twice
  10991. if (isDisabled !== undefined && isDisabled === disabled) {
  10992. return;
  10993. }
  10994. isDisabled = disabled;
  10995. if (disabled) {
  10996. element.attr({'tabindex': -1, 'aria-disabled': 'true'});
  10997. element.off('click', openSelect);
  10998. element.off('keydown', handleKeypress);
  10999. } else {
  11000. element.attr({'tabindex': attr.tabindex, 'aria-disabled': 'false'});
  11001. element.on('click', openSelect);
  11002. element.on('keydown', handleKeypress);
  11003. }
  11004. });
  11005. if (!attr.disabled && !attr.ngDisabled) {
  11006. element.attr({'tabindex': attr.tabindex, 'aria-disabled': 'false'});
  11007. element.on('click', openSelect);
  11008. element.on('keydown', handleKeypress);
  11009. }
  11010. var ariaAttrs = {
  11011. role: 'combobox',
  11012. 'aria-expanded': 'false'
  11013. };
  11014. if (!element[0].hasAttribute('id')) {
  11015. ariaAttrs.id = 'select_' + $mdUtil.nextUid();
  11016. }
  11017. element.attr(ariaAttrs);
  11018. scope.$on('$destroy', function() {
  11019. $mdSelect
  11020. .destroy()
  11021. .finally(function() {
  11022. if ( selectContainer ) {
  11023. selectContainer.remove();
  11024. }
  11025. if (containerCtrl) {
  11026. containerCtrl.setFocused(false);
  11027. containerCtrl.setHasValue(false);
  11028. containerCtrl.input = null;
  11029. }
  11030. });
  11031. });
  11032. function inputCheckValue() {
  11033. // The select counts as having a value if one or more options are selected,
  11034. // or if the input's validity state says it has bad input (eg string in a number input)
  11035. containerCtrl && containerCtrl.setHasValue(selectMenuCtrl.selectedLabels().length > 0 || (element[0].validity || {}).badInput);
  11036. }
  11037. // Create a fake select to find out the label value
  11038. function createSelect() {
  11039. selectContainer = angular.element(selectTemplate);
  11040. var selectEl = selectContainer.find('md-select-menu');
  11041. selectEl.data('$ngModelController', ngModelCtrl);
  11042. selectEl.data('$mdSelectController', mdSelectCtrl);
  11043. selectScope = scope.$new();
  11044. $mdTheming.inherit(selectContainer, element);
  11045. if (element.attr('md-container-class')) {
  11046. var value = selectContainer[0].getAttribute('class') + ' ' + element.attr('md-container-class');
  11047. selectContainer[0].setAttribute('class', value);
  11048. }
  11049. selectContainer = $compile(selectContainer)(selectScope);
  11050. selectMenuCtrl = selectContainer.find('md-select-menu').controller('mdSelectMenu');
  11051. }
  11052. function handleKeypress(e) {
  11053. var allowedCodes = [32, 13, 38, 40];
  11054. if (allowedCodes.indexOf(e.keyCode) != -1) {
  11055. // prevent page scrolling on interaction
  11056. e.preventDefault();
  11057. openSelect(e);
  11058. } else {
  11059. if (e.keyCode <= 90 && e.keyCode >= 31) {
  11060. e.preventDefault();
  11061. var node = selectMenuCtrl.optNodeForKeyboardSearch(e);
  11062. if (!node) return;
  11063. var optionCtrl = angular.element(node).controller('mdOption');
  11064. if (!selectMenuCtrl.isMultiple) {
  11065. selectMenuCtrl.deselect(Object.keys(selectMenuCtrl.selected)[0]);
  11066. }
  11067. selectMenuCtrl.select(optionCtrl.hashKey, optionCtrl.value);
  11068. selectMenuCtrl.refreshViewValue();
  11069. ngModelCtrl.$render();
  11070. }
  11071. }
  11072. }
  11073. function openSelect() {
  11074. selectScope.isOpen = true;
  11075. $mdSelect.show({
  11076. scope: selectScope,
  11077. preserveScope: true,
  11078. skipCompile: true,
  11079. element: selectContainer,
  11080. target: element[0],
  11081. hasBackdrop: true,
  11082. loadingAsync: attr.mdOnOpen ? scope.$eval(attr.mdOnOpen) || true : false
  11083. }).then(function() {
  11084. selectScope.isOpen = false;
  11085. });
  11086. }
  11087. };
  11088. }
  11089. }
  11090. SelectDirective.$inject = ["$mdSelect", "$mdUtil", "$mdTheming", "$mdAria", "$compile", "$parse"];
  11091. function SelectMenuDirective($parse, $mdUtil, $mdTheming) {
  11092. SelectMenuController.$inject = ["$scope", "$attrs", "$element"];
  11093. return {
  11094. restrict: 'E',
  11095. require: ['mdSelectMenu', '?ngModel'],
  11096. controller: SelectMenuController,
  11097. link: {pre: preLink}
  11098. };
  11099. // We use preLink instead of postLink to ensure that the select is initialized before
  11100. // its child options run postLink.
  11101. function preLink(scope, element, attr, ctrls) {
  11102. var selectCtrl = ctrls[0];
  11103. var ngModel = ctrls[1];
  11104. $mdTheming(element);
  11105. element.on('click', clickListener);
  11106. element.on('keypress', keyListener);
  11107. if (ngModel) selectCtrl.init(ngModel);
  11108. configureAria();
  11109. function configureAria() {
  11110. element.attr({
  11111. 'id': 'select_menu_' + $mdUtil.nextUid(),
  11112. 'role': 'listbox',
  11113. 'aria-multiselectable': (selectCtrl.isMultiple ? 'true' : 'false')
  11114. });
  11115. }
  11116. function keyListener(e) {
  11117. if (e.keyCode == 13 || e.keyCode == 32) {
  11118. clickListener(e);
  11119. }
  11120. }
  11121. function clickListener(ev) {
  11122. var option = $mdUtil.getClosest(ev.target, 'md-option');
  11123. var optionCtrl = option && angular.element(option).data('$mdOptionController');
  11124. if (!option || !optionCtrl) return;
  11125. if (option.hasAttribute('disabled')) {
  11126. ev.stopImmediatePropagation();
  11127. return false;
  11128. }
  11129. var optionHashKey = selectCtrl.hashGetter(optionCtrl.value);
  11130. var isSelected = angular.isDefined(selectCtrl.selected[optionHashKey]);
  11131. scope.$apply(function() {
  11132. if (selectCtrl.isMultiple) {
  11133. if (isSelected) {
  11134. selectCtrl.deselect(optionHashKey);
  11135. } else {
  11136. selectCtrl.select(optionHashKey, optionCtrl.value);
  11137. }
  11138. } else {
  11139. if (!isSelected) {
  11140. selectCtrl.deselect(Object.keys(selectCtrl.selected)[0]);
  11141. selectCtrl.select(optionHashKey, optionCtrl.value);
  11142. }
  11143. }
  11144. selectCtrl.refreshViewValue();
  11145. });
  11146. }
  11147. }
  11148. function SelectMenuController($scope, $attrs, $element) {
  11149. var self = this;
  11150. self.isMultiple = angular.isDefined($attrs.multiple);
  11151. // selected is an object with keys matching all of the selected options' hashed values
  11152. self.selected = {};
  11153. // options is an object with keys matching every option's hash value,
  11154. // and values matching every option's controller.
  11155. self.options = {};
  11156. $scope.$watch(function() {
  11157. return self.options;
  11158. }, function() {
  11159. self.ngModel.$render();
  11160. }, true);
  11161. var deregisterCollectionWatch;
  11162. self.setMultiple = function(isMultiple) {
  11163. var ngModel = self.ngModel;
  11164. self.isMultiple = isMultiple;
  11165. if (deregisterCollectionWatch) deregisterCollectionWatch();
  11166. if (self.isMultiple) {
  11167. ngModel.$validators['md-multiple'] = validateArray;
  11168. ngModel.$render = renderMultiple;
  11169. // watchCollection on the model because by default ngModel only watches the model's
  11170. // reference. This allowed the developer to also push and pop from their array.
  11171. $scope.$watchCollection($attrs.ngModel, function(value) {
  11172. if (validateArray(value)) renderMultiple(value);
  11173. self.ngModel.$setPristine();
  11174. });
  11175. } else {
  11176. delete ngModel.$validators['md-multiple'];
  11177. ngModel.$render = renderSingular;
  11178. }
  11179. function validateArray(modelValue, viewValue) {
  11180. // If a value is truthy but not an array, reject it.
  11181. // If value is undefined/falsy, accept that it's an empty array.
  11182. return angular.isArray(modelValue || viewValue || []);
  11183. }
  11184. };
  11185. var searchStr = '';
  11186. var clearSearchTimeout, optNodes, optText;
  11187. var CLEAR_SEARCH_AFTER = 300;
  11188. self.optNodeForKeyboardSearch = function(e) {
  11189. clearSearchTimeout && clearTimeout(clearSearchTimeout);
  11190. clearSearchTimeout = setTimeout(function() {
  11191. clearSearchTimeout = undefined;
  11192. searchStr = '';
  11193. optText = undefined;
  11194. optNodes = undefined;
  11195. }, CLEAR_SEARCH_AFTER);
  11196. searchStr += String.fromCharCode(e.keyCode);
  11197. var search = new RegExp('^' + searchStr, 'i');
  11198. if (!optNodes) {
  11199. optNodes = $element.find('md-option');
  11200. optText = new Array(optNodes.length);
  11201. angular.forEach(optNodes, function(el, i) {
  11202. optText[i] = el.textContent.trim();
  11203. });
  11204. }
  11205. for (var i = 0; i < optText.length; ++i) {
  11206. if (search.test(optText[i])) {
  11207. return optNodes[i];
  11208. }
  11209. }
  11210. };
  11211. self.init = function(ngModel) {
  11212. self.ngModel = ngModel;
  11213. // Allow users to provide `ng-model="foo" ng-model-options="{trackBy: 'foo.id'}"` so
  11214. // that we can properly compare objects set on the model to the available options
  11215. if (ngModel.$options && ngModel.$options.trackBy) {
  11216. var trackByLocals = {};
  11217. var trackByParsed = $parse(ngModel.$options.trackBy);
  11218. self.hashGetter = function(value, valueScope) {
  11219. trackByLocals.$value = value;
  11220. return trackByParsed(valueScope || $scope, trackByLocals);
  11221. };
  11222. // If the user doesn't provide a trackBy, we automatically generate an id for every
  11223. // value passed in
  11224. } else {
  11225. self.hashGetter = function getHashValue(value) {
  11226. if (angular.isObject(value)) {
  11227. return 'object_' + (value.$$mdSelectId || (value.$$mdSelectId = ++selectNextId));
  11228. }
  11229. return value;
  11230. };
  11231. }
  11232. self.setMultiple(self.isMultiple);
  11233. };
  11234. self.selectedLabels = function() {
  11235. var selectedOptionEls = $mdUtil.nodesToArray($element[0].querySelectorAll('md-option[selected]'));
  11236. if (selectedOptionEls.length) {
  11237. return selectedOptionEls.map(function(el) {
  11238. return el.textContent;
  11239. }).join(', ');
  11240. } else {
  11241. return '';
  11242. }
  11243. };
  11244. self.select = function(hashKey, hashedValue) {
  11245. var option = self.options[hashKey];
  11246. option && option.setSelected(true);
  11247. self.selected[hashKey] = hashedValue;
  11248. };
  11249. self.deselect = function(hashKey) {
  11250. var option = self.options[hashKey];
  11251. option && option.setSelected(false);
  11252. delete self.selected[hashKey];
  11253. };
  11254. self.addOption = function(hashKey, optionCtrl) {
  11255. if (angular.isDefined(self.options[hashKey])) {
  11256. throw new Error('Duplicate md-option values are not allowed in a select. ' +
  11257. 'Duplicate value "' + optionCtrl.value + '" found.');
  11258. }
  11259. self.options[hashKey] = optionCtrl;
  11260. // If this option's value was already in our ngModel, go ahead and select it.
  11261. if (angular.isDefined(self.selected[hashKey])) {
  11262. self.select(hashKey, optionCtrl.value);
  11263. self.refreshViewValue();
  11264. }
  11265. };
  11266. self.removeOption = function(hashKey) {
  11267. delete self.options[hashKey];
  11268. // Don't deselect an option when it's removed - the user's ngModel should be allowed
  11269. // to have values that do not match a currently available option.
  11270. };
  11271. self.refreshViewValue = function() {
  11272. var values = [];
  11273. var option;
  11274. for (var hashKey in self.selected) {
  11275. // If this hashKey has an associated option, push that option's value to the model.
  11276. if ((option = self.options[hashKey])) {
  11277. values.push(option.value);
  11278. } else {
  11279. // Otherwise, the given hashKey has no associated option, and we got it
  11280. // from an ngModel value at an earlier time. Push the unhashed value of
  11281. // this hashKey to the model.
  11282. // This allows the developer to put a value in the model that doesn't yet have
  11283. // an associated option.
  11284. values.push(self.selected[hashKey]);
  11285. }
  11286. }
  11287. self.ngModel.$setViewValue(self.isMultiple ? values : values[0]);
  11288. };
  11289. function renderMultiple() {
  11290. var newSelectedValues = self.ngModel.$modelValue || self.ngModel.$viewValue || [];
  11291. if (!angular.isArray(newSelectedValues)) return;
  11292. var oldSelected = Object.keys(self.selected);
  11293. var newSelectedHashes = newSelectedValues.map(self.hashGetter);
  11294. var deselected = oldSelected.filter(function(hash) {
  11295. return newSelectedHashes.indexOf(hash) === -1;
  11296. });
  11297. deselected.forEach(self.deselect);
  11298. newSelectedHashes.forEach(function(hashKey, i) {
  11299. self.select(hashKey, newSelectedValues[i]);
  11300. });
  11301. }
  11302. function renderSingular() {
  11303. var value = self.ngModel.$viewValue || self.ngModel.$modelValue;
  11304. Object.keys(self.selected).forEach(self.deselect);
  11305. self.select(self.hashGetter(value), value);
  11306. }
  11307. }
  11308. }
  11309. SelectMenuDirective.$inject = ["$parse", "$mdUtil", "$mdTheming"];
  11310. function OptionDirective($mdButtonInkRipple, $mdUtil) {
  11311. OptionController.$inject = ["$element"];
  11312. return {
  11313. restrict: 'E',
  11314. require: ['mdOption', '^^mdSelectMenu'],
  11315. controller: OptionController,
  11316. compile: compile
  11317. };
  11318. function compile(element, attr) {
  11319. // Manual transclusion to avoid the extra inner <span> that ng-transclude generates
  11320. element.append(angular.element('<div class="md-text">').append(element.contents()));
  11321. element.attr('tabindex', attr.tabindex || '0');
  11322. return postLink;
  11323. }
  11324. function postLink(scope, element, attr, ctrls) {
  11325. var optionCtrl = ctrls[0];
  11326. var selectCtrl = ctrls[1];
  11327. if (angular.isDefined(attr.ngValue)) {
  11328. scope.$watch(attr.ngValue, setOptionValue);
  11329. } else if (angular.isDefined(attr.value)) {
  11330. setOptionValue(attr.value);
  11331. } else {
  11332. scope.$watch(function() {
  11333. return element.text();
  11334. }, setOptionValue);
  11335. }
  11336. attr.$observe('disabled', function(disabled) {
  11337. if (disabled) {
  11338. element.attr('tabindex', '-1');
  11339. } else {
  11340. element.attr('tabindex', '0');
  11341. }
  11342. });
  11343. scope.$$postDigest(function() {
  11344. attr.$observe('selected', function(selected) {
  11345. if (!angular.isDefined(selected)) return;
  11346. if (typeof selected == 'string') selected = true;
  11347. if (selected) {
  11348. if (!selectCtrl.isMultiple) {
  11349. selectCtrl.deselect(Object.keys(selectCtrl.selected)[0]);
  11350. }
  11351. selectCtrl.select(optionCtrl.hashKey, optionCtrl.value);
  11352. } else {
  11353. selectCtrl.deselect(optionCtrl.hashKey);
  11354. }
  11355. selectCtrl.refreshViewValue();
  11356. selectCtrl.ngModel.$render();
  11357. });
  11358. });
  11359. $mdButtonInkRipple.attach(scope, element);
  11360. configureAria();
  11361. function setOptionValue(newValue, oldValue) {
  11362. var oldHashKey = selectCtrl.hashGetter(oldValue, scope);
  11363. var newHashKey = selectCtrl.hashGetter(newValue, scope);
  11364. optionCtrl.hashKey = newHashKey;
  11365. optionCtrl.value = newValue;
  11366. selectCtrl.removeOption(oldHashKey, optionCtrl);
  11367. selectCtrl.addOption(newHashKey, optionCtrl);
  11368. }
  11369. scope.$on('$destroy', function() {
  11370. selectCtrl.removeOption(optionCtrl.hashKey, optionCtrl);
  11371. });
  11372. function configureAria() {
  11373. var ariaAttrs = {
  11374. 'role': 'option',
  11375. 'aria-selected': 'false'
  11376. };
  11377. if (!element[0].hasAttribute('id')) {
  11378. ariaAttrs.id = 'select_option_' + $mdUtil.nextUid();
  11379. }
  11380. element.attr(ariaAttrs);
  11381. }
  11382. }
  11383. function OptionController($element) {
  11384. this.selected = false;
  11385. this.setSelected = function(isSelected) {
  11386. if (isSelected && !this.selected) {
  11387. $element.attr({
  11388. 'selected': 'selected',
  11389. 'aria-selected': 'true'
  11390. });
  11391. } else if (!isSelected && this.selected) {
  11392. $element.removeAttr('selected');
  11393. $element.attr('aria-selected', 'false');
  11394. }
  11395. this.selected = isSelected;
  11396. };
  11397. }
  11398. }
  11399. OptionDirective.$inject = ["$mdButtonInkRipple", "$mdUtil"];
  11400. function OptgroupDirective() {
  11401. return {
  11402. restrict: 'E',
  11403. compile: compile
  11404. };
  11405. function compile(el, attrs) {
  11406. var labelElement = el.find('label');
  11407. if (!labelElement.length) {
  11408. labelElement = angular.element('<label>');
  11409. el.prepend(labelElement);
  11410. }
  11411. if (attrs.label) labelElement.text(attrs.label);
  11412. }
  11413. }
  11414. function SelectProvider($$interimElementProvider) {
  11415. selectDefaultOptions.$inject = ["$mdSelect", "$mdConstant", "$mdUtil", "$window", "$q", "$$rAF", "$animateCss", "$animate"];
  11416. return $$interimElementProvider('$mdSelect')
  11417. .setDefaults({
  11418. methods: ['target'],
  11419. options: selectDefaultOptions
  11420. });
  11421. /* @ngInject */
  11422. function selectDefaultOptions($mdSelect, $mdConstant, $mdUtil, $window, $q, $$rAF, $animateCss, $animate) {
  11423. var ERRROR_TARGET_EXPECTED = "$mdSelect.show() expected a target element in options.target but got '{0}'!";
  11424. var animator = $mdUtil.dom.animator;
  11425. return {
  11426. parent: 'body',
  11427. themable: true,
  11428. onShow: onShow,
  11429. onRemove: onRemove,
  11430. hasBackdrop: true,
  11431. disableParentScroll: true
  11432. };
  11433. /**
  11434. * Interim-element onRemove logic....
  11435. */
  11436. function onRemove(scope, element, opts) {
  11437. opts = opts || { };
  11438. opts.cleanupInteraction();
  11439. opts.cleanupResizing();
  11440. opts.hideBackdrop();
  11441. // For navigation $destroy events, do a quick, non-animated removal,
  11442. // but for normal closes (from clicks, etc) animate the removal
  11443. return (opts.$destroy === true) ? detachAndClean() : animateRemoval().then( detachAndClean );
  11444. /**
  11445. * For normal closes (eg clicks), animate the removal.
  11446. * For forced closes (like $destroy events from navigation),
  11447. * skip the animations
  11448. */
  11449. function animateRemoval() {
  11450. return $animateCss(element, {addClass: 'md-leave'}).start();
  11451. }
  11452. /**
  11453. * Detach the element and cleanup prior changes
  11454. */
  11455. function detachAndClean() {
  11456. configureAria(opts.target, false);
  11457. element.attr('opacity', 0);
  11458. element.removeClass('md-active');
  11459. detachElement(element, opts);
  11460. announceClosed(opts);
  11461. if (!opts.$destroy && opts.restoreFocus) {
  11462. opts.target.focus();
  11463. }
  11464. }
  11465. }
  11466. /**
  11467. * Interim-element onShow logic....
  11468. */
  11469. function onShow(scope, element, opts) {
  11470. watchAsyncLoad();
  11471. sanitizeAndConfigure(scope, opts);
  11472. configureAria(opts.target);
  11473. opts.hideBackdrop = showBackdrop(scope, element, opts);
  11474. return showDropDown(scope, element, opts)
  11475. .then(function(response) {
  11476. opts.alreadyOpen = true;
  11477. opts.cleanupInteraction = activateInteraction();
  11478. opts.cleanupResizing = activateResizing();
  11479. return response;
  11480. }, opts.hideBackdrop);
  11481. // ************************************
  11482. // Closure Functions
  11483. // ************************************
  11484. /**
  11485. * Attach the select DOM element(s) and animate to the correct positions
  11486. * and scalings...
  11487. */
  11488. function showDropDown(scope, element, opts) {
  11489. opts.parent.append(element);
  11490. return $q(function(resolve, reject) {
  11491. try {
  11492. $animateCss(element, {removeClass: 'md-leave', duration: 0})
  11493. .start()
  11494. .then(positionAndFocusMenu)
  11495. .then(resolve);
  11496. } catch (e) {
  11497. reject(e);
  11498. }
  11499. });
  11500. }
  11501. /**
  11502. * Initialize container and dropDown menu positions/scale, then animate
  11503. * to show... and autoFocus.
  11504. */
  11505. function positionAndFocusMenu() {
  11506. return $q(function(resolve) {
  11507. if (opts.isRemoved) return $q.reject(false);
  11508. var info = calculateMenuPositions(scope, element, opts);
  11509. info.container.element.css(animator.toCss(info.container.styles));
  11510. info.dropDown.element.css(animator.toCss(info.dropDown.styles));
  11511. $$rAF(function() {
  11512. element.addClass('md-active');
  11513. info.dropDown.element.css(animator.toCss({transform: ''}));
  11514. autoFocus(opts.focusedNode);
  11515. resolve();
  11516. });
  11517. });
  11518. }
  11519. /**
  11520. * Show modal backdrop element...
  11521. */
  11522. function showBackdrop(scope, element, options) {
  11523. // If we are not within a dialog...
  11524. if (options.disableParentScroll && !$mdUtil.getClosest(options.target, 'MD-DIALOG')) {
  11525. // !! DO this before creating the backdrop; since disableScrollAround()
  11526. // configures the scroll offset; which is used by mdBackDrop postLink()
  11527. options.restoreScroll = $mdUtil.disableScrollAround(options.element, options.parent);
  11528. } else {
  11529. options.disableParentScroll = false;
  11530. }
  11531. if (options.hasBackdrop) {
  11532. // Override duration to immediately show invisible backdrop
  11533. options.backdrop = $mdUtil.createBackdrop(scope, "md-select-backdrop md-click-catcher");
  11534. $animate.enter(options.backdrop, options.parent, null, {duration: 0});
  11535. }
  11536. /**
  11537. * Hide modal backdrop element...
  11538. */
  11539. return function hideBackdrop() {
  11540. if (options.backdrop) options.backdrop.remove();
  11541. if (options.disableParentScroll) options.restoreScroll();
  11542. delete options.restoreScroll;
  11543. }
  11544. }
  11545. /**
  11546. *
  11547. */
  11548. function autoFocus(focusedNode) {
  11549. if (focusedNode && !focusedNode.hasAttribute('disabled')) {
  11550. focusedNode.focus();
  11551. }
  11552. }
  11553. /**
  11554. * Check for valid opts and set some sane defaults
  11555. */
  11556. function sanitizeAndConfigure(scope, options) {
  11557. var selectEl = element.find('md-select-menu');
  11558. if (!options.target) {
  11559. throw new Error($mdUtil.supplant(ERRROR_TARGET_EXPECTED, [options.target]));
  11560. }
  11561. angular.extend(options, {
  11562. isRemoved: false,
  11563. target: angular.element(options.target), //make sure it's not a naked dom node
  11564. parent: angular.element(options.parent),
  11565. selectEl: selectEl,
  11566. contentEl: element.find('md-content'),
  11567. optionNodes: selectEl[0].getElementsByTagName('md-option')
  11568. });
  11569. }
  11570. /**
  11571. * Configure various resize listeners for screen changes
  11572. */
  11573. function activateResizing() {
  11574. var debouncedOnResize = (function(scope, target, options) {
  11575. return function() {
  11576. if (options.isRemoved) return;
  11577. var updates = calculateMenuPositions(scope, target, options);
  11578. var container = updates.container;
  11579. var dropDown = updates.dropDown;
  11580. container.element.css(animator.toCss(container.styles));
  11581. dropDown.element.css(animator.toCss(dropDown.styles));
  11582. };
  11583. })(scope, element, opts);
  11584. var window = angular.element($window);
  11585. window.on('resize', debouncedOnResize);
  11586. window.on('orientationchange', debouncedOnResize);
  11587. // Publish deactivation closure...
  11588. return function deactivateResizing() {
  11589. // Disable resizing handlers
  11590. window.off('resize', debouncedOnResize);
  11591. window.off('orientationchange', debouncedOnResize);
  11592. }
  11593. }
  11594. /**
  11595. * If asynchronously loading, watch and update internal
  11596. * '$$loadingAsyncDone' flag
  11597. */
  11598. function watchAsyncLoad() {
  11599. if (opts.loadingAsync && !opts.isRemoved) {
  11600. scope.$$loadingAsyncDone = false;
  11601. scope.progressMode = 'indeterminate';
  11602. $q.when(opts.loadingAsync)
  11603. .then(function() {
  11604. scope.$$loadingAsyncDone = true;
  11605. scope.progressMode = '';
  11606. delete opts.loadingAsync;
  11607. }).then(function() {
  11608. $$rAF(positionAndFocusMenu);
  11609. })
  11610. }
  11611. }
  11612. /**
  11613. *
  11614. */
  11615. function activateInteraction() {
  11616. if (opts.isRemoved) return;
  11617. var dropDown = opts.selectEl;
  11618. var selectCtrl = dropDown.controller('mdSelectMenu') || {};
  11619. element.addClass('md-clickable');
  11620. // Close on backdrop click
  11621. opts.backdrop && opts.backdrop.on('click', onBackdropClick);
  11622. // Escape to close
  11623. // Cycling of options, and closing on enter
  11624. dropDown.on('keydown', onMenuKeyDown);
  11625. dropDown.on('mouseup', checkCloseMenu);
  11626. return function cleanupInteraction() {
  11627. opts.backdrop && opts.backdrop.off('click', onBackdropClick);
  11628. dropDown.off('keydown', onMenuKeyDown);
  11629. dropDown.off('mouseup', checkCloseMenu);
  11630. element.removeClass('md-clickable');
  11631. opts.isRemoved = true;
  11632. };
  11633. // ************************************
  11634. // Closure Functions
  11635. // ************************************
  11636. function onBackdropClick(e) {
  11637. e.preventDefault();
  11638. e.stopPropagation();
  11639. opts.restoreFocus = false;
  11640. $mdUtil.nextTick($mdSelect.hide, true);
  11641. }
  11642. function onMenuKeyDown(ev) {
  11643. var keyCodes = $mdConstant.KEY_CODE;
  11644. switch (ev.keyCode) {
  11645. case keyCodes.UP_ARROW:
  11646. return focusPrevOption();
  11647. break;
  11648. case keyCodes.DOWN_ARROW:
  11649. return focusNextOption();
  11650. break;
  11651. case keyCodes.SPACE:
  11652. case keyCodes.ENTER:
  11653. var option = $mdUtil.getClosest(ev.target, 'md-option');
  11654. if (option) {
  11655. dropDown.triggerHandler({
  11656. type: 'click',
  11657. target: option
  11658. });
  11659. ev.preventDefault();
  11660. }
  11661. checkCloseMenu(ev);
  11662. break;
  11663. case keyCodes.TAB:
  11664. case keyCodes.ESCAPE:
  11665. ev.preventDefault();
  11666. opts.restoreFocus = true;
  11667. $mdUtil.nextTick($mdSelect.hide, true);
  11668. break;
  11669. default:
  11670. if (ev.keyCode >= 31 && ev.keyCode <= 90) {
  11671. var optNode = dropDown.controller('mdSelectMenu').optNodeForKeyboardSearch(ev);
  11672. opts.focusedNode = optNode || opts.focusedNode;
  11673. optNode && optNode.focus();
  11674. }
  11675. }
  11676. }
  11677. function focusOption(direction) {
  11678. var optionsArray = $mdUtil.nodesToArray(opts.optionNodes);
  11679. var index = optionsArray.indexOf(opts.focusedNode);
  11680. var newOption;
  11681. do {
  11682. if (index === -1) {
  11683. // We lost the previously focused element, reset to first option
  11684. index = 0;
  11685. } else if (direction === 'next' && index < optionsArray.length - 1) {
  11686. index++;
  11687. } else if (direction === 'prev' && index > 0) {
  11688. index--;
  11689. }
  11690. newOption = optionsArray[index];
  11691. if (newOption.hasAttribute('disabled')) newOption = undefined;
  11692. } while (!newOption && index < optionsArray.length - 1 && index > 0)
  11693. newOption && newOption.focus();
  11694. opts.focusedNode = newOption;
  11695. }
  11696. function focusNextOption() {
  11697. focusOption('next');
  11698. }
  11699. function focusPrevOption() {
  11700. focusOption('prev');
  11701. }
  11702. function checkCloseMenu(ev) {
  11703. if (ev && ( ev.type == 'mouseup') && (ev.currentTarget != dropDown[0])) return;
  11704. if ( mouseOnScrollbar() ) return;
  11705. if (!selectCtrl.isMultiple) {
  11706. opts.restoreFocus = true;
  11707. $mdUtil.nextTick(function() {
  11708. $mdSelect.hide(selectCtrl.ngModel.$viewValue);
  11709. }, true);
  11710. }
  11711. /**
  11712. * check if the mouseup event was on a scrollbar
  11713. */
  11714. function mouseOnScrollbar() {
  11715. var clickOnScrollbar = false;
  11716. if (ev && (ev.currentTarget.children.length > 0)) {
  11717. var child = ev.currentTarget.children[0];
  11718. var hasScrollbar = child.scrollHeight > child.clientHeight;
  11719. if (hasScrollbar && child.children.length > 0) {
  11720. var relPosX = ev.pageX - ev.currentTarget.getBoundingClientRect().left;
  11721. if (relPosX > child.querySelector('md-option').offsetWidth)
  11722. clickOnScrollbar = true;
  11723. }
  11724. }
  11725. return clickOnScrollbar;
  11726. }
  11727. }
  11728. }
  11729. }
  11730. /**
  11731. *
  11732. */
  11733. function configureAria(element, isExpanded) {
  11734. isExpanded = angular.isUndefined(isExpanded) ? 'true' : 'false';
  11735. element && element.attr('aria-expanded', isExpanded);
  11736. }
  11737. /**
  11738. * To notify listeners that the Select menu has closed,
  11739. * trigger the [optional] user-defined expression
  11740. */
  11741. function announceClosed(opts) {
  11742. var mdSelect = opts.selectEl.controller('mdSelect');
  11743. if (mdSelect) {
  11744. var menuController = opts.selectEl.controller('mdSelectMenu');
  11745. mdSelect.setLabelText(menuController.selectedLabels());
  11746. mdSelect.triggerClose();
  11747. }
  11748. }
  11749. /**
  11750. * Use browser to remove this element without triggering a $destroy event
  11751. */
  11752. function detachElement(element, opts) {
  11753. if (element[0].parentNode === opts.parent[0]) {
  11754. opts.parent[0].removeChild(element[0]);
  11755. }
  11756. }
  11757. /**
  11758. * Calculate the
  11759. */
  11760. function calculateMenuPositions(scope, element, opts) {
  11761. var optionNodes,
  11762. containerNode = element[0],
  11763. targetNode = opts.target[0].firstElementChild, // target the label
  11764. parentNode = opts.parent[0],
  11765. selectNode = opts.selectEl[0],
  11766. contentNode = opts.contentEl[0],
  11767. parentRect = parentNode.getBoundingClientRect(),
  11768. targetRect = targetNode.getBoundingClientRect(),
  11769. shouldOpenAroundTarget = false,
  11770. bounds = {
  11771. left: parentRect.left + SELECT_EDGE_MARGIN,
  11772. top: SELECT_EDGE_MARGIN,
  11773. bottom: parentRect.height - SELECT_EDGE_MARGIN,
  11774. right: parentRect.width - SELECT_EDGE_MARGIN - ($mdUtil.floatingScrollbars() ? 16 : 0)
  11775. },
  11776. spaceAvailable = {
  11777. top: targetRect.top - bounds.top,
  11778. left: targetRect.left - bounds.left,
  11779. right: bounds.right - (targetRect.left + targetRect.width),
  11780. bottom: bounds.bottom - (targetRect.top + targetRect.height)
  11781. },
  11782. maxWidth = parentRect.width - SELECT_EDGE_MARGIN * 2,
  11783. isScrollable = contentNode.scrollHeight > contentNode.offsetHeight,
  11784. selectedNode = selectNode.querySelector('md-option[selected]'),
  11785. optionNodes = selectNode.getElementsByTagName('md-option'),
  11786. optgroupNodes = selectNode.getElementsByTagName('md-optgroup');
  11787. var loading = isPromiseLike(opts.loadingAsync);
  11788. var centeredNode;
  11789. if (!loading) {
  11790. // If a selected node, center around that
  11791. if (selectedNode) {
  11792. centeredNode = selectedNode;
  11793. // If there are option groups, center around the first option group
  11794. } else if (optgroupNodes.length) {
  11795. centeredNode = optgroupNodes[0];
  11796. // Otherwise - if we are not loading async - center around the first optionNode
  11797. } else if (optionNodes.length) {
  11798. centeredNode = optionNodes[0];
  11799. // In case there are no options, center on whatever's in there... (eg progress indicator)
  11800. } else {
  11801. centeredNode = contentNode.firstElementChild || contentNode;
  11802. }
  11803. } else {
  11804. // If loading, center on progress indicator
  11805. centeredNode = contentNode.firstElementChild || contentNode;
  11806. }
  11807. if (contentNode.offsetWidth > maxWidth) {
  11808. contentNode.style['max-width'] = maxWidth + 'px';
  11809. }
  11810. if (shouldOpenAroundTarget) {
  11811. contentNode.style['min-width'] = targetRect.width + 'px';
  11812. }
  11813. // Remove padding before we compute the position of the menu
  11814. if (isScrollable) {
  11815. selectNode.classList.add('md-overflow');
  11816. }
  11817. var focusedNode = centeredNode;
  11818. if ((focusedNode.tagName || '').toUpperCase() === 'MD-OPTGROUP') {
  11819. focusedNode = optionNodes[0] || contentNode.firstElementChild || contentNode;
  11820. centeredNode = focusedNode;
  11821. }
  11822. // Cache for autoFocus()
  11823. opts.focusedNode = focusedNode;
  11824. // Get the selectMenuRect *after* max-width is possibly set above
  11825. var selectMenuRect = selectNode.getBoundingClientRect();
  11826. var centeredRect = getOffsetRect(centeredNode);
  11827. if (centeredNode) {
  11828. var centeredStyle = $window.getComputedStyle(centeredNode);
  11829. centeredRect.paddingLeft = parseInt(centeredStyle.paddingLeft, 10) || 0;
  11830. centeredRect.paddingRight = parseInt(centeredStyle.paddingRight, 10) || 0;
  11831. }
  11832. if (isScrollable) {
  11833. var scrollBuffer = contentNode.offsetHeight / 2;
  11834. contentNode.scrollTop = centeredRect.top + centeredRect.height / 2 - scrollBuffer;
  11835. if (spaceAvailable.top < scrollBuffer) {
  11836. contentNode.scrollTop = Math.min(
  11837. centeredRect.top,
  11838. contentNode.scrollTop + scrollBuffer - spaceAvailable.top
  11839. );
  11840. } else if (spaceAvailable.bottom < scrollBuffer) {
  11841. contentNode.scrollTop = Math.max(
  11842. centeredRect.top + centeredRect.height - selectMenuRect.height,
  11843. contentNode.scrollTop - scrollBuffer + spaceAvailable.bottom
  11844. );
  11845. }
  11846. }
  11847. var left, top, transformOrigin, minWidth;
  11848. if (shouldOpenAroundTarget) {
  11849. left = targetRect.left;
  11850. top = targetRect.top + targetRect.height;
  11851. transformOrigin = '50% 0';
  11852. if (top + selectMenuRect.height > bounds.bottom) {
  11853. top = targetRect.top - selectMenuRect.height;
  11854. transformOrigin = '50% 100%';
  11855. }
  11856. } else {
  11857. left = (targetRect.left + centeredRect.left - centeredRect.paddingLeft) + 2;
  11858. top = Math.floor(targetRect.top + targetRect.height / 2 - centeredRect.height / 2 -
  11859. centeredRect.top + contentNode.scrollTop) + 2;
  11860. transformOrigin = (centeredRect.left + targetRect.width / 2) + 'px ' +
  11861. (centeredRect.top + centeredRect.height / 2 - contentNode.scrollTop) + 'px 0px';
  11862. minWidth = targetRect.width + centeredRect.paddingLeft + centeredRect.paddingRight;
  11863. }
  11864. // Keep left and top within the window
  11865. var containerRect = containerNode.getBoundingClientRect();
  11866. var scaleX = Math.round(100 * Math.min(targetRect.width / selectMenuRect.width, 1.0)) / 100;
  11867. var scaleY = Math.round(100 * Math.min(targetRect.height / selectMenuRect.height, 1.0)) / 100;
  11868. return {
  11869. container: {
  11870. element: angular.element(containerNode),
  11871. styles: {
  11872. left: Math.floor(clamp(bounds.left, left, bounds.right - containerRect.width)),
  11873. top: Math.floor(clamp(bounds.top, top, bounds.bottom - containerRect.height)),
  11874. 'min-width': minWidth
  11875. }
  11876. },
  11877. dropDown: {
  11878. element: angular.element(selectNode),
  11879. styles: {
  11880. transformOrigin: transformOrigin,
  11881. transform: !opts.alreadyOpen ? $mdUtil.supplant('scale({0},{1})', [scaleX, scaleY]) : ""
  11882. }
  11883. }
  11884. };
  11885. }
  11886. }
  11887. function isPromiseLike(obj) {
  11888. return obj && angular.isFunction(obj.then);
  11889. }
  11890. function clamp(min, n, max) {
  11891. return Math.max(min, Math.min(n, max));
  11892. }
  11893. function getOffsetRect(node) {
  11894. return node ? {
  11895. left: node.offsetLeft,
  11896. top: node.offsetTop,
  11897. width: node.offsetWidth,
  11898. height: node.offsetHeight
  11899. } : {left: 0, top: 0, width: 0, height: 0};
  11900. }
  11901. }
  11902. SelectProvider.$inject = ["$$interimElementProvider"];
  11903. })();
  11904. (function(){
  11905. "use strict";
  11906. /**
  11907. * @ngdoc module
  11908. * @name material.components.sidenav
  11909. *
  11910. * @description
  11911. * A Sidenav QP component.
  11912. */
  11913. angular
  11914. .module('material.components.sidenav', [
  11915. 'material.core',
  11916. 'material.components.backdrop'
  11917. ])
  11918. .factory('$mdSidenav', SidenavService )
  11919. .directive('mdSidenav', SidenavDirective)
  11920. .directive('mdSidenavFocus', SidenavFocusDirective)
  11921. .controller('$mdSidenavController', SidenavController);
  11922. /**
  11923. * @ngdoc service
  11924. * @name $mdSidenav
  11925. * @module material.components.sidenav
  11926. *
  11927. * @description
  11928. * `$mdSidenav` makes it easy to interact with multiple sidenavs
  11929. * in an app.
  11930. *
  11931. * @usage
  11932. * <hljs lang="js">
  11933. * // Async lookup for sidenav instance; will resolve when the instance is available
  11934. * $mdSidenav(componentId).then(function(instance) {
  11935. * $log.debug( componentId + "is now ready" );
  11936. * });
  11937. * // Async toggle the given sidenav;
  11938. * // when instance is known ready and lazy lookup is not needed.
  11939. * $mdSidenav(componentId)
  11940. * .toggle()
  11941. * .then(function(){
  11942. * $log.debug('toggled');
  11943. * });
  11944. * // Async open the given sidenav
  11945. * $mdSidenav(componentId)
  11946. * .open()
  11947. * .then(function(){
  11948. * $log.debug('opened');
  11949. * });
  11950. * // Async close the given sidenav
  11951. * $mdSidenav(componentId)
  11952. * .close()
  11953. * .then(function(){
  11954. * $log.debug('closed');
  11955. * });
  11956. * // Sync check to see if the specified sidenav is set to be open
  11957. * $mdSidenav(componentId).isOpen();
  11958. * // Sync check to whether given sidenav is locked open
  11959. * // If this is true, the sidenav will be open regardless of close()
  11960. * $mdSidenav(componentId).isLockedOpen();
  11961. * </hljs>
  11962. */
  11963. function SidenavService($mdComponentRegistry, $q) {
  11964. return function(handle) {
  11965. // Lookup the controller instance for the specified sidNav instance
  11966. var self;
  11967. var errorMsg = "SideNav '" + handle + "' is not available!";
  11968. var instance = $mdComponentRegistry.get(handle);
  11969. if(!instance) {
  11970. $mdComponentRegistry.notFoundError(handle);
  11971. }
  11972. return self = {
  11973. // -----------------
  11974. // Sync methods
  11975. // -----------------
  11976. isOpen: function() {
  11977. return instance && instance.isOpen();
  11978. },
  11979. isLockedOpen: function() {
  11980. return instance && instance.isLockedOpen();
  11981. },
  11982. // -----------------
  11983. // Async methods
  11984. // -----------------
  11985. toggle: function() {
  11986. return instance ? instance.toggle() : $q.reject(errorMsg);
  11987. },
  11988. open: function() {
  11989. return instance ? instance.open() : $q.reject(errorMsg);
  11990. },
  11991. close: function() {
  11992. return instance ? instance.close() : $q.reject(errorMsg);
  11993. },
  11994. then : function( callbackFn ) {
  11995. var promise = instance ? $q.when(instance) : waitForInstance();
  11996. return promise.then( callbackFn || angular.noop );
  11997. }
  11998. };
  11999. /**
  12000. * Deferred lookup of component instance using $component registry
  12001. */
  12002. function waitForInstance() {
  12003. return $mdComponentRegistry
  12004. .when(handle)
  12005. .then(function( it ){
  12006. instance = it;
  12007. return it;
  12008. });
  12009. }
  12010. };
  12011. }
  12012. SidenavService.$inject = ["$mdComponentRegistry", "$q"];
  12013. /**
  12014. * @ngdoc directive
  12015. * @name mdSidenavFocus
  12016. * @module material.components.sidenav
  12017. *
  12018. * @restrict A
  12019. *
  12020. * @description
  12021. * `mdSidenavFocus` provides a way to specify the focused element when a sidenav opens.
  12022. * This is completely optional, as the sidenav itself is focused by default.
  12023. *
  12024. * @usage
  12025. * <hljs lang="html">
  12026. * <md-sidenav>
  12027. * <form>
  12028. * <md-input-container>
  12029. * <label for="testInput">Label</label>
  12030. * <input id="testInput" type="text" md-sidenav-focus>
  12031. * </md-input-container>
  12032. * </form>
  12033. * </md-sidenav>
  12034. * </hljs>
  12035. **/
  12036. function SidenavFocusDirective() {
  12037. return {
  12038. restrict: 'A',
  12039. require: '^mdSidenav',
  12040. link: function(scope, element, attr, sidenavCtrl) {
  12041. // @see $mdUtil.findFocusTarget(...)
  12042. }
  12043. };
  12044. }
  12045. /**
  12046. * @ngdoc directive
  12047. * @name mdSidenav
  12048. * @module material.components.sidenav
  12049. * @restrict E
  12050. *
  12051. * @description
  12052. *
  12053. * A Sidenav component that can be opened and closed programatically.
  12054. *
  12055. * By default, upon opening it will slide out on top of the main content area.
  12056. *
  12057. * For keyboard and screen reader accessibility, focus is sent to the sidenav wrapper by default.
  12058. * It can be overridden with the `md-autofocus` directive on the child element you want focused.
  12059. *
  12060. * @usage
  12061. * <hljs lang="html">
  12062. * <div layout="row" ng-controller="MyController">
  12063. * <md-sidenav md-component-id="left" class="md-sidenav-left">
  12064. * Left Nav!
  12065. * </md-sidenav>
  12066. *
  12067. * <md-content>
  12068. * Center Content
  12069. * <md-button ng-click="openLeftMenu()">
  12070. * Open Left Menu
  12071. * </md-button>
  12072. * </md-content>
  12073. *
  12074. * <md-sidenav md-component-id="right"
  12075. * md-is-locked-open="$mdMedia('min-width: 333px')"
  12076. * class="md-sidenav-right">
  12077. * <form>
  12078. * <md-input-container>
  12079. * <label for="testInput">Test input</label>
  12080. * <input id="testInput" type="text"
  12081. * ng-model="data" md-autofocus>
  12082. * </md-input-container>
  12083. * </form>
  12084. * </md-sidenav>
  12085. * </div>
  12086. * </hljs>
  12087. *
  12088. * <hljs lang="js">
  12089. * var app = angular.module('myApp', ['ngMaterial']);
  12090. * app.controller('MyController', function($scope, $mdSidenav) {
  12091. * $scope.openLeftMenu = function() {
  12092. * $mdSidenav('left').toggle();
  12093. * };
  12094. * });
  12095. * </hljs>
  12096. *
  12097. * @param {expression=} md-is-open A model bound to whether the sidenav is opened.
  12098. * @param {string=} md-component-id componentId to use with $mdSidenav service.
  12099. * @param {expression=} md-is-locked-open When this expression evalutes to true,
  12100. * the sidenav 'locks open': it falls into the content's flow instead
  12101. * of appearing over it. This overrides the `is-open` attribute.
  12102. *
  12103. * The $mdMedia() service is exposed to the is-locked-open attribute, which
  12104. * can be given a media query or one of the `sm`, `gt-sm`, `md`, `gt-md`, `lg` or `gt-lg` presets.
  12105. * Examples:
  12106. *
  12107. * - `<md-sidenav md-is-locked-open="shouldLockOpen"></md-sidenav>`
  12108. * - `<md-sidenav md-is-locked-open="$mdMedia('min-width: 1000px')"></md-sidenav>`
  12109. * - `<md-sidenav md-is-locked-open="$mdMedia('sm')"></md-sidenav>` (locks open on small screens)
  12110. */
  12111. function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate, $compile, $parse, $log, $q, $document) {
  12112. return {
  12113. restrict: 'E',
  12114. scope: {
  12115. isOpen: '=?mdIsOpen'
  12116. },
  12117. controller: '$mdSidenavController',
  12118. compile: function(element) {
  12119. element.addClass('md-closed');
  12120. element.attr('tabIndex', '-1');
  12121. return postLink;
  12122. }
  12123. };
  12124. /**
  12125. * Directive Post Link function...
  12126. */
  12127. function postLink(scope, element, attr, sidenavCtrl) {
  12128. var lastParentOverFlow;
  12129. var triggeringElement = null;
  12130. var promise = $q.when(true);
  12131. var isLockedOpenParsed = $parse(attr.mdIsLockedOpen);
  12132. var isLocked = function() {
  12133. return isLockedOpenParsed(scope.$parent, {
  12134. $media: function(arg) {
  12135. $log.warn("$media is deprecated for is-locked-open. Use $mdMedia instead.");
  12136. return $mdMedia(arg);
  12137. },
  12138. $mdMedia: $mdMedia
  12139. });
  12140. };
  12141. var backdrop = $mdUtil.createBackdrop(scope, "md-sidenav-backdrop md-opaque ng-enter");
  12142. $mdTheming.inherit(backdrop, element);
  12143. element.on('$destroy', function() {
  12144. backdrop.remove();
  12145. sidenavCtrl.destroy();
  12146. });
  12147. scope.$on('$destroy', function(){
  12148. backdrop.remove()
  12149. });
  12150. scope.$watch(isLocked, updateIsLocked);
  12151. scope.$watch('isOpen', updateIsOpen);
  12152. // Publish special accessor for the Controller instance
  12153. sidenavCtrl.$toggleOpen = toggleOpen;
  12154. /**
  12155. * Toggle the DOM classes to indicate `locked`
  12156. * @param isLocked
  12157. */
  12158. function updateIsLocked(isLocked, oldValue) {
  12159. scope.isLockedOpen = isLocked;
  12160. if (isLocked === oldValue) {
  12161. element.toggleClass('md-locked-open', !!isLocked);
  12162. } else {
  12163. $animate[isLocked ? 'addClass' : 'removeClass'](element, 'md-locked-open');
  12164. }
  12165. backdrop.toggleClass('md-locked-open', !!isLocked);
  12166. }
  12167. /**
  12168. * Toggle the SideNav view and attach/detach listeners
  12169. * @param isOpen
  12170. */
  12171. function updateIsOpen(isOpen) {
  12172. // Support deprecated md-sidenav-focus attribute as fallback
  12173. var focusEl = $mdUtil.findFocusTarget(element) || $mdUtil.findFocusTarget(element,'[md-sidenav-focus]') || element;
  12174. var parent = element.parent();
  12175. parent[isOpen ? 'on' : 'off']('keydown', onKeyDown);
  12176. backdrop[isOpen ? 'on' : 'off']('click', close);
  12177. if ( isOpen ) {
  12178. // Capture upon opening..
  12179. triggeringElement = $document[0].activeElement;
  12180. }
  12181. disableParentScroll(isOpen);
  12182. return promise = $q.all([
  12183. isOpen ? $animate.enter(backdrop, parent) : $animate.leave(backdrop),
  12184. $animate[isOpen ? 'removeClass' : 'addClass'](element, 'md-closed')
  12185. ])
  12186. .then(function() {
  12187. // Perform focus when animations are ALL done...
  12188. if (scope.isOpen) {
  12189. focusEl && focusEl.focus();
  12190. }
  12191. });
  12192. }
  12193. /**
  12194. * Prevent parent scrolling (when the SideNav is open)
  12195. */
  12196. function disableParentScroll(disabled) {
  12197. var parent = element.parent();
  12198. if ( disabled && !lastParentOverFlow ) {
  12199. lastParentOverFlow = parent.css('overflow');
  12200. parent.css('overflow', 'hidden');
  12201. } else if (angular.isDefined(lastParentOverFlow)) {
  12202. parent.css('overflow', lastParentOverFlow);
  12203. lastParentOverFlow = undefined;
  12204. }
  12205. }
  12206. /**
  12207. * Toggle the sideNav view and publish a promise to be resolved when
  12208. * the view animation finishes.
  12209. *
  12210. * @param isOpen
  12211. * @returns {*}
  12212. */
  12213. function toggleOpen( isOpen ) {
  12214. if (scope.isOpen == isOpen ) {
  12215. return $q.when(true);
  12216. } else {
  12217. return $q(function(resolve){
  12218. // Toggle value to force an async `updateIsOpen()` to run
  12219. scope.isOpen = isOpen;
  12220. $mdUtil.nextTick(function() {
  12221. // When the current `updateIsOpen()` animation finishes
  12222. promise.then(function(result) {
  12223. if ( !scope.isOpen ) {
  12224. // reset focus to originating element (if available) upon close
  12225. triggeringElement && triggeringElement.focus();
  12226. triggeringElement = null;
  12227. }
  12228. resolve(result);
  12229. });
  12230. });
  12231. });
  12232. }
  12233. }
  12234. /**
  12235. * Auto-close sideNav when the `escape` key is pressed.
  12236. * @param evt
  12237. */
  12238. function onKeyDown(ev) {
  12239. var isEscape = (ev.keyCode === $mdConstant.KEY_CODE.ESCAPE);
  12240. return isEscape ? close(ev) : $q.when(true);
  12241. }
  12242. /**
  12243. * With backdrop `clicks` or `escape` key-press, immediately
  12244. * apply the CSS close transition... Then notify the controller
  12245. * to close() and perform its own actions.
  12246. */
  12247. function close(ev) {
  12248. ev.preventDefault();
  12249. ev.stopPropagation();
  12250. return sidenavCtrl.close();
  12251. }
  12252. }
  12253. }
  12254. SidenavDirective.$inject = ["$mdMedia", "$mdUtil", "$mdConstant", "$mdTheming", "$animate", "$compile", "$parse", "$log", "$q", "$document"];
  12255. /*
  12256. * @private
  12257. * @ngdoc controller
  12258. * @name SidenavController
  12259. * @module material.components.sidenav
  12260. *
  12261. */
  12262. function SidenavController($scope, $element, $attrs, $mdComponentRegistry, $q) {
  12263. var self = this;
  12264. // Use Default internal method until overridden by directive postLink
  12265. // Synchronous getters
  12266. self.isOpen = function() { return !!$scope.isOpen; };
  12267. self.isLockedOpen = function() { return !!$scope.isLockedOpen; };
  12268. // Async actions
  12269. self.open = function() { return self.$toggleOpen( true ); };
  12270. self.close = function() { return self.$toggleOpen( false ); };
  12271. self.toggle = function() { return self.$toggleOpen( !$scope.isOpen ); };
  12272. self.$toggleOpen = function(value) { return $q.when($scope.isOpen = value); };
  12273. self.destroy = $mdComponentRegistry.register(self, $attrs.mdComponentId);
  12274. }
  12275. SidenavController.$inject = ["$scope", "$element", "$attrs", "$mdComponentRegistry", "$q"];
  12276. })();
  12277. (function(){
  12278. "use strict";
  12279. /**
  12280. * @ngdoc module
  12281. * @name material.components.slider
  12282. */
  12283. angular.module('material.components.slider', [
  12284. 'material.core'
  12285. ])
  12286. .directive('mdSlider', SliderDirective);
  12287. /**
  12288. * @ngdoc directive
  12289. * @name mdSlider
  12290. * @module material.components.slider
  12291. * @restrict E
  12292. * @description
  12293. * The `<md-slider>` component allows the user to choose from a range of
  12294. * values.
  12295. *
  12296. * As per the [material design spec](http://www.google.com/design/spec/style/color.html#color-ui-color-application)
  12297. * the slider is in the accent color by default. The primary color palette may be used with
  12298. * the `md-primary` class.
  12299. *
  12300. * It has two modes: 'normal' mode, where the user slides between a wide range
  12301. * of values, and 'discrete' mode, where the user slides between only a few
  12302. * select values.
  12303. *
  12304. * To enable discrete mode, add the `md-discrete` attribute to a slider,
  12305. * and use the `step` attribute to change the distance between
  12306. * values the user is allowed to pick.
  12307. *
  12308. * @usage
  12309. * <h4>Normal Mode</h4>
  12310. * <hljs lang="html">
  12311. * <md-slider ng-model="myValue" min="5" max="500">
  12312. * </md-slider>
  12313. * </hljs>
  12314. * <h4>Discrete Mode</h4>
  12315. * <hljs lang="html">
  12316. * <md-slider md-discrete ng-model="myDiscreteValue" step="10" min="10" max="130">
  12317. * </md-slider>
  12318. * </hljs>
  12319. *
  12320. * @param {boolean=} md-discrete Whether to enable discrete mode.
  12321. * @param {number=} step The distance between values the user is allowed to pick. Default 1.
  12322. * @param {number=} min The minimum value the user is allowed to pick. Default 0.
  12323. * @param {number=} max The maximum value the user is allowed to pick. Default 100.
  12324. */
  12325. function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdTheming, $mdGesture, $parse, $log) {
  12326. return {
  12327. scope: {},
  12328. require: '?ngModel',
  12329. template:
  12330. '<div class="md-slider-wrapper">' +
  12331. '<div class="md-track-container">' +
  12332. '<div class="md-track"></div>' +
  12333. '<div class="md-track md-track-fill"></div>' +
  12334. '<div class="md-track-ticks"></div>' +
  12335. '</div>' +
  12336. '<div class="md-thumb-container">' +
  12337. '<div class="md-thumb"></div>' +
  12338. '<div class="md-focus-thumb"></div>' +
  12339. '<div class="md-focus-ring"></div>' +
  12340. '<div class="md-sign">' +
  12341. '<span class="md-thumb-text"></span>' +
  12342. '</div>' +
  12343. '<div class="md-disabled-thumb"></div>' +
  12344. '</div>' +
  12345. '</div>',
  12346. compile: compile
  12347. };
  12348. // **********************************************************
  12349. // Private Methods
  12350. // **********************************************************
  12351. function compile (tElement, tAttrs) {
  12352. tElement.attr({
  12353. tabIndex: 0,
  12354. role: 'slider'
  12355. });
  12356. $mdAria.expect(tElement, 'aria-label');
  12357. return postLink;
  12358. }
  12359. function postLink(scope, element, attr, ngModelCtrl) {
  12360. $mdTheming(element);
  12361. ngModelCtrl = ngModelCtrl || {
  12362. // Mock ngModelController if it doesn't exist to give us
  12363. // the minimum functionality needed
  12364. $setViewValue: function(val) {
  12365. this.$viewValue = val;
  12366. this.$viewChangeListeners.forEach(function(cb) { cb(); });
  12367. },
  12368. $parsers: [],
  12369. $formatters: [],
  12370. $viewChangeListeners: []
  12371. };
  12372. var isDisabledGetter = angular.noop;
  12373. if (attr.disabled != null) {
  12374. isDisabledGetter = function() { return true; };
  12375. } else if (attr.ngDisabled) {
  12376. isDisabledGetter = angular.bind(null, $parse(attr.ngDisabled), scope.$parent);
  12377. }
  12378. var thumb = angular.element(element[0].querySelector('.md-thumb'));
  12379. var thumbText = angular.element(element[0].querySelector('.md-thumb-text'));
  12380. var thumbContainer = thumb.parent();
  12381. var trackContainer = angular.element(element[0].querySelector('.md-track-container'));
  12382. var activeTrack = angular.element(element[0].querySelector('.md-track-fill'));
  12383. var tickContainer = angular.element(element[0].querySelector('.md-track-ticks'));
  12384. var throttledRefreshDimensions = $mdUtil.throttle(refreshSliderDimensions, 5000);
  12385. // Default values, overridable by attrs
  12386. angular.isDefined(attr.min) ? attr.$observe('min', updateMin) : updateMin(0);
  12387. angular.isDefined(attr.max) ? attr.$observe('max', updateMax) : updateMax(100);
  12388. angular.isDefined(attr.step)? attr.$observe('step', updateStep) : updateStep(1);
  12389. // We have to manually stop the $watch on ngDisabled because it exists
  12390. // on the parent scope, and won't be automatically destroyed when
  12391. // the component is destroyed.
  12392. var stopDisabledWatch = angular.noop;
  12393. if (attr.ngDisabled) {
  12394. stopDisabledWatch = scope.$parent.$watch(attr.ngDisabled, updateAriaDisabled);
  12395. }
  12396. $mdGesture.register(element, 'drag');
  12397. element
  12398. .on('keydown', keydownListener)
  12399. .on('$md.pressdown', onPressDown)
  12400. .on('$md.pressup', onPressUp)
  12401. .on('$md.dragstart', onDragStart)
  12402. .on('$md.drag', onDrag)
  12403. .on('$md.dragend', onDragEnd);
  12404. // On resize, recalculate the slider's dimensions and re-render
  12405. function updateAll() {
  12406. refreshSliderDimensions();
  12407. ngModelRender();
  12408. redrawTicks();
  12409. }
  12410. setTimeout(updateAll, 0);
  12411. var debouncedUpdateAll = $$rAF.throttle(updateAll);
  12412. angular.element($window).on('resize', debouncedUpdateAll);
  12413. scope.$on('$destroy', function() {
  12414. angular.element($window).off('resize', debouncedUpdateAll);
  12415. stopDisabledWatch();
  12416. });
  12417. ngModelCtrl.$render = ngModelRender;
  12418. ngModelCtrl.$viewChangeListeners.push(ngModelRender);
  12419. ngModelCtrl.$formatters.push(minMaxValidator);
  12420. ngModelCtrl.$formatters.push(stepValidator);
  12421. /**
  12422. * Attributes
  12423. */
  12424. var min;
  12425. var max;
  12426. var step;
  12427. function updateMin(value) {
  12428. min = parseFloat(value);
  12429. element.attr('aria-valuemin', value);
  12430. updateAll();
  12431. }
  12432. function updateMax(value) {
  12433. max = parseFloat(value);
  12434. element.attr('aria-valuemax', value);
  12435. updateAll();
  12436. }
  12437. function updateStep(value) {
  12438. step = parseFloat(value);
  12439. redrawTicks();
  12440. }
  12441. function updateAriaDisabled(isDisabled) {
  12442. element.attr('aria-disabled', !!isDisabled);
  12443. }
  12444. // Draw the ticks with canvas.
  12445. // The alternative to drawing ticks with canvas is to draw one element for each tick,
  12446. // which could quickly become a performance bottleneck.
  12447. var tickCanvas, tickCtx;
  12448. function redrawTicks() {
  12449. if (!angular.isDefined(attr.mdDiscrete)) return;
  12450. if ( angular.isUndefined(step) ) return;
  12451. if ( step <= 0 ) {
  12452. var msg = 'Slider step value must be greater than zero when in discrete mode';
  12453. $log.error(msg);
  12454. throw new Error(msg);
  12455. }
  12456. var numSteps = Math.floor( (max - min) / step );
  12457. if (!tickCanvas) {
  12458. tickCanvas = angular.element('<canvas style="position:absolute;">');
  12459. tickContainer.append(tickCanvas);
  12460. var trackTicksStyle = $window.getComputedStyle(tickContainer[0]);
  12461. tickCtx = tickCanvas[0].getContext('2d');
  12462. tickCtx.fillStyle = trackTicksStyle.backgroundColor || 'black';
  12463. }
  12464. var dimensions = getSliderDimensions();
  12465. tickCanvas[0].width = dimensions.width;
  12466. tickCanvas[0].height = dimensions.height;
  12467. var distance;
  12468. for (var i = 0; i <= numSteps; i++) {
  12469. distance = Math.floor(dimensions.width * (i / numSteps));
  12470. tickCtx.fillRect(distance - 1, 0, 2, dimensions.height);
  12471. }
  12472. }
  12473. /**
  12474. * Refreshing Dimensions
  12475. */
  12476. var sliderDimensions = {};
  12477. refreshSliderDimensions();
  12478. function refreshSliderDimensions() {
  12479. sliderDimensions = trackContainer[0].getBoundingClientRect();
  12480. }
  12481. function getSliderDimensions() {
  12482. throttledRefreshDimensions();
  12483. return sliderDimensions;
  12484. }
  12485. /**
  12486. * left/right arrow listener
  12487. */
  12488. function keydownListener(ev) {
  12489. if(element[0].hasAttribute('disabled')) {
  12490. return;
  12491. }
  12492. var changeAmount;
  12493. if (ev.keyCode === $mdConstant.KEY_CODE.LEFT_ARROW) {
  12494. changeAmount = -step;
  12495. } else if (ev.keyCode === $mdConstant.KEY_CODE.RIGHT_ARROW) {
  12496. changeAmount = step;
  12497. }
  12498. if (changeAmount) {
  12499. if (ev.metaKey || ev.ctrlKey || ev.altKey) {
  12500. changeAmount *= 4;
  12501. }
  12502. ev.preventDefault();
  12503. ev.stopPropagation();
  12504. scope.$evalAsync(function() {
  12505. setModelValue(ngModelCtrl.$viewValue + changeAmount);
  12506. });
  12507. }
  12508. }
  12509. /**
  12510. * ngModel setters and validators
  12511. */
  12512. function setModelValue(value) {
  12513. ngModelCtrl.$setViewValue( minMaxValidator(stepValidator(value)) );
  12514. }
  12515. function ngModelRender() {
  12516. if (isNaN(ngModelCtrl.$viewValue)) {
  12517. ngModelCtrl.$viewValue = ngModelCtrl.$modelValue;
  12518. }
  12519. var percent = (ngModelCtrl.$viewValue - min) / (max - min);
  12520. scope.modelValue = ngModelCtrl.$viewValue;
  12521. element.attr('aria-valuenow', ngModelCtrl.$viewValue);
  12522. setSliderPercent(percent);
  12523. thumbText.text( ngModelCtrl.$viewValue );
  12524. }
  12525. function minMaxValidator(value) {
  12526. if (angular.isNumber(value)) {
  12527. return Math.max(min, Math.min(max, value));
  12528. }
  12529. }
  12530. function stepValidator(value) {
  12531. if (angular.isNumber(value)) {
  12532. var formattedValue = (Math.round(value / step) * step);
  12533. // Format to 3 digits after the decimal point - fixes #2015.
  12534. return (Math.round(formattedValue * 1000) / 1000);
  12535. }
  12536. }
  12537. /**
  12538. * @param percent 0-1
  12539. */
  12540. function setSliderPercent(percent) {
  12541. var percentStr = (percent * 100) + '%';
  12542. activeTrack.css('width', percentStr);
  12543. thumbContainer.css('left',percentStr);
  12544. element.toggleClass('md-min', percent === 0);
  12545. element.toggleClass('md-max', percent === 1);
  12546. }
  12547. /**
  12548. * Slide listeners
  12549. */
  12550. var isDragging = false;
  12551. var isDiscrete = angular.isDefined(attr.mdDiscrete);
  12552. function onPressDown(ev) {
  12553. if (isDisabledGetter()) return;
  12554. element.addClass('md-active');
  12555. element[0].focus();
  12556. refreshSliderDimensions();
  12557. var exactVal = percentToValue( positionToPercent( ev.pointer.x ));
  12558. var closestVal = minMaxValidator( stepValidator(exactVal) );
  12559. scope.$apply(function() {
  12560. setModelValue( closestVal );
  12561. setSliderPercent( valueToPercent(closestVal));
  12562. });
  12563. }
  12564. function onPressUp(ev) {
  12565. if (isDisabledGetter()) return;
  12566. element.removeClass('md-dragging md-active');
  12567. var exactVal = percentToValue( positionToPercent( ev.pointer.x ));
  12568. var closestVal = minMaxValidator( stepValidator(exactVal) );
  12569. scope.$apply(function() {
  12570. setModelValue(closestVal);
  12571. ngModelRender();
  12572. });
  12573. }
  12574. function onDragStart(ev) {
  12575. if (isDisabledGetter()) return;
  12576. isDragging = true;
  12577. ev.stopPropagation();
  12578. element.addClass('md-dragging');
  12579. setSliderFromEvent(ev);
  12580. }
  12581. function onDrag(ev) {
  12582. if (!isDragging) return;
  12583. ev.stopPropagation();
  12584. setSliderFromEvent(ev);
  12585. }
  12586. function onDragEnd(ev) {
  12587. if (!isDragging) return;
  12588. ev.stopPropagation();
  12589. isDragging = false;
  12590. }
  12591. function setSliderFromEvent(ev) {
  12592. // While panning discrete, update only the
  12593. // visual positioning but not the model value.
  12594. if ( isDiscrete ) adjustThumbPosition( ev.pointer.x );
  12595. else doSlide( ev.pointer.x );
  12596. }
  12597. /**
  12598. * Slide the UI by changing the model value
  12599. * @param x
  12600. */
  12601. function doSlide( x ) {
  12602. scope.$evalAsync( function() {
  12603. setModelValue( percentToValue( positionToPercent(x) ));
  12604. });
  12605. }
  12606. /**
  12607. * Slide the UI without changing the model (while dragging/panning)
  12608. * @param x
  12609. */
  12610. function adjustThumbPosition( x ) {
  12611. var exactVal = percentToValue( positionToPercent( x ));
  12612. var closestVal = minMaxValidator( stepValidator(exactVal) );
  12613. setSliderPercent( positionToPercent(x) );
  12614. thumbText.text( closestVal );
  12615. }
  12616. /**
  12617. * Convert horizontal position on slider to percentage value of offset from beginning...
  12618. * @param x
  12619. * @returns {number}
  12620. */
  12621. function positionToPercent( x ) {
  12622. return Math.max(0, Math.min(1, (x - sliderDimensions.left) / (sliderDimensions.width)));
  12623. }
  12624. /**
  12625. * Convert percentage offset on slide to equivalent model value
  12626. * @param percent
  12627. * @returns {*}
  12628. */
  12629. function percentToValue( percent ) {
  12630. return (min + percent * (max - min));
  12631. }
  12632. function valueToPercent( val ) {
  12633. return (val - min)/(max - min);
  12634. }
  12635. }
  12636. }
  12637. SliderDirective.$inject = ["$$rAF", "$window", "$mdAria", "$mdUtil", "$mdConstant", "$mdTheming", "$mdGesture", "$parse", "$log"];
  12638. })();
  12639. (function(){
  12640. "use strict";
  12641. /**
  12642. * @ngdoc module
  12643. * @name material.components.sticky
  12644. * @description
  12645. * Sticky effects for md
  12646. *
  12647. */
  12648. angular
  12649. .module('material.components.sticky', [
  12650. 'material.core',
  12651. 'material.components.content'
  12652. ])
  12653. .factory('$mdSticky', MdSticky);
  12654. /**
  12655. * @ngdoc service
  12656. * @name $mdSticky
  12657. * @module material.components.sticky
  12658. *
  12659. * @description
  12660. * The `$mdSticky`service provides a mixin to make elements sticky.
  12661. *
  12662. * @returns A `$mdSticky` function that takes three arguments:
  12663. * - `scope`
  12664. * - `element`: The element that will be 'sticky'
  12665. * - `elementClone`: A clone of the element, that will be shown
  12666. * when the user starts scrolling past the original element.
  12667. * If not provided, it will use the result of `element.clone()`.
  12668. */
  12669. function MdSticky($document, $mdConstant, $$rAF, $mdUtil) {
  12670. var browserStickySupport = checkStickySupport();
  12671. /**
  12672. * Registers an element as sticky, used internally by directives to register themselves
  12673. */
  12674. return function registerStickyElement(scope, element, stickyClone) {
  12675. var contentCtrl = element.controller('mdContent');
  12676. if (!contentCtrl) return;
  12677. if (browserStickySupport) {
  12678. element.css({
  12679. position: browserStickySupport,
  12680. top: 0,
  12681. 'z-index': 2
  12682. });
  12683. } else {
  12684. var $$sticky = contentCtrl.$element.data('$$sticky');
  12685. if (!$$sticky) {
  12686. $$sticky = setupSticky(contentCtrl);
  12687. contentCtrl.$element.data('$$sticky', $$sticky);
  12688. }
  12689. var deregister = $$sticky.add(element, stickyClone || element.clone());
  12690. scope.$on('$destroy', deregister);
  12691. }
  12692. };
  12693. function setupSticky(contentCtrl) {
  12694. var contentEl = contentCtrl.$element;
  12695. // Refresh elements is very expensive, so we use the debounced
  12696. // version when possible.
  12697. var debouncedRefreshElements = $$rAF.throttle(refreshElements);
  12698. // setupAugmentedScrollEvents gives us `$scrollstart` and `$scroll`,
  12699. // more reliable than `scroll` on android.
  12700. setupAugmentedScrollEvents(contentEl);
  12701. contentEl.on('$scrollstart', debouncedRefreshElements);
  12702. contentEl.on('$scroll', onScroll);
  12703. var self;
  12704. return self = {
  12705. prev: null,
  12706. current: null, //the currently stickied item
  12707. next: null,
  12708. items: [],
  12709. add: add,
  12710. refreshElements: refreshElements
  12711. };
  12712. /***************
  12713. * Public
  12714. ***************/
  12715. // Add an element and its sticky clone to this content's sticky collection
  12716. function add(element, stickyClone) {
  12717. stickyClone.addClass('md-sticky-clone');
  12718. var item = {
  12719. element: element,
  12720. clone: stickyClone
  12721. };
  12722. self.items.push(item);
  12723. $mdUtil.nextTick(function() {
  12724. contentEl.prepend(item.clone);
  12725. });
  12726. debouncedRefreshElements();
  12727. return function remove() {
  12728. self.items.forEach(function(item, index) {
  12729. if (item.element[0] === element[0]) {
  12730. self.items.splice(index, 1);
  12731. item.clone.remove();
  12732. }
  12733. });
  12734. debouncedRefreshElements();
  12735. };
  12736. }
  12737. function refreshElements() {
  12738. // Sort our collection of elements by their current position in the DOM.
  12739. // We need to do this because our elements' order of being added may not
  12740. // be the same as their order of display.
  12741. self.items.forEach(refreshPosition);
  12742. self.items = self.items.sort(function(a, b) {
  12743. return a.top < b.top ? -1 : 1;
  12744. });
  12745. // Find which item in the list should be active,
  12746. // based upon the content's current scroll position
  12747. var item;
  12748. var currentScrollTop = contentEl.prop('scrollTop');
  12749. for (var i = self.items.length - 1; i >= 0; i--) {
  12750. if (currentScrollTop > self.items[i].top) {
  12751. item = self.items[i];
  12752. break;
  12753. }
  12754. }
  12755. setCurrentItem(item);
  12756. }
  12757. /***************
  12758. * Private
  12759. ***************/
  12760. // Find the `top` of an item relative to the content element,
  12761. // and also the height.
  12762. function refreshPosition(item) {
  12763. // Find the top of an item by adding to the offsetHeight until we reach the
  12764. // content element.
  12765. var current = item.element[0];
  12766. item.top = 0;
  12767. item.left = 0;
  12768. while (current && current !== contentEl[0]) {
  12769. item.top += current.offsetTop;
  12770. item.left += current.offsetLeft;
  12771. current = current.offsetParent;
  12772. }
  12773. item.height = item.element.prop('offsetHeight');
  12774. item.clone.css('margin-left', item.left + 'px');
  12775. if ($mdUtil.floatingScrollbars()) {
  12776. item.clone.css('margin-right', '0');
  12777. }
  12778. }
  12779. // As we scroll, push in and select the correct sticky element.
  12780. function onScroll() {
  12781. var scrollTop = contentEl.prop('scrollTop');
  12782. var isScrollingDown = scrollTop > (onScroll.prevScrollTop || 0);
  12783. // Store the previous scroll so we know which direction we are scrolling
  12784. onScroll.prevScrollTop = scrollTop;
  12785. //
  12786. // AT TOP (not scrolling)
  12787. //
  12788. if (scrollTop === 0) {
  12789. // If we're at the top, just clear the current item and return
  12790. setCurrentItem(null);
  12791. return;
  12792. }
  12793. //
  12794. // SCROLLING DOWN (going towards the next item)
  12795. //
  12796. if (isScrollingDown) {
  12797. // If we've scrolled down past the next item's position, sticky it and return
  12798. if (self.next && self.next.top <= scrollTop) {
  12799. setCurrentItem(self.next);
  12800. return;
  12801. }
  12802. // If the next item is close to the current one, push the current one up out of the way
  12803. if (self.current && self.next && self.next.top - scrollTop <= self.next.height) {
  12804. translate(self.current, scrollTop + (self.next.top - self.next.height - scrollTop));
  12805. return;
  12806. }
  12807. }
  12808. //
  12809. // SCROLLING UP (not at the top & not scrolling down; must be scrolling up)
  12810. //
  12811. if (!isScrollingDown) {
  12812. // If we've scrolled up past the previous item's position, sticky it and return
  12813. if (self.current && self.prev && scrollTop < self.current.top) {
  12814. setCurrentItem(self.prev);
  12815. return;
  12816. }
  12817. // If the next item is close to the current one, pull the current one down into view
  12818. if (self.next && self.current && (scrollTop >= (self.next.top - self.current.height))) {
  12819. translate(self.current, scrollTop + (self.next.top - scrollTop - self.current.height));
  12820. return;
  12821. }
  12822. }
  12823. //
  12824. // Otherwise, just move the current item to the proper place (scrolling up or down)
  12825. //
  12826. if (self.current) {
  12827. translate(self.current, scrollTop);
  12828. }
  12829. }
  12830. function setCurrentItem(item) {
  12831. if (self.current === item) return;
  12832. // Deactivate currently active item
  12833. if (self.current) {
  12834. translate(self.current, null);
  12835. setStickyState(self.current, null);
  12836. }
  12837. // Activate new item if given
  12838. if (item) {
  12839. setStickyState(item, 'active');
  12840. }
  12841. self.current = item;
  12842. var index = self.items.indexOf(item);
  12843. // If index === -1, index + 1 = 0. It works out.
  12844. self.next = self.items[index + 1];
  12845. self.prev = self.items[index - 1];
  12846. setStickyState(self.next, 'next');
  12847. setStickyState(self.prev, 'prev');
  12848. }
  12849. function setStickyState(item, state) {
  12850. if (!item || item.state === state) return;
  12851. if (item.state) {
  12852. item.clone.attr('sticky-prev-state', item.state);
  12853. item.element.attr('sticky-prev-state', item.state);
  12854. }
  12855. item.clone.attr('sticky-state', state);
  12856. item.element.attr('sticky-state', state);
  12857. item.state = state;
  12858. }
  12859. function translate(item, amount) {
  12860. if (!item) return;
  12861. if (amount === null || amount === undefined) {
  12862. if (item.translateY) {
  12863. item.translateY = null;
  12864. item.clone.css($mdConstant.CSS.TRANSFORM, '');
  12865. }
  12866. } else {
  12867. item.translateY = amount;
  12868. item.clone.css(
  12869. $mdConstant.CSS.TRANSFORM,
  12870. 'translate3d(' + item.left + 'px,' + amount + 'px,0)'
  12871. );
  12872. }
  12873. }
  12874. }
  12875. // Function to check for browser sticky support
  12876. function checkStickySupport($el) {
  12877. var stickyProp;
  12878. var testEl = angular.element('<div>');
  12879. $document[0].body.appendChild(testEl[0]);
  12880. var stickyProps = ['sticky', '-webkit-sticky'];
  12881. for (var i = 0; i < stickyProps.length; ++i) {
  12882. testEl.css({position: stickyProps[i], top: 0, 'z-index': 2});
  12883. if (testEl.css('position') == stickyProps[i]) {
  12884. stickyProp = stickyProps[i];
  12885. break;
  12886. }
  12887. }
  12888. testEl.remove();
  12889. return stickyProp;
  12890. }
  12891. // Android 4.4 don't accurately give scroll events.
  12892. // To fix this problem, we setup a fake scroll event. We say:
  12893. // > If a scroll or touchmove event has happened in the last DELAY milliseconds,
  12894. // then send a `$scroll` event every animationFrame.
  12895. // Additionally, we add $scrollstart and $scrollend events.
  12896. function setupAugmentedScrollEvents(element) {
  12897. var SCROLL_END_DELAY = 200;
  12898. var isScrolling;
  12899. var lastScrollTime;
  12900. element.on('scroll touchmove', function() {
  12901. if (!isScrolling) {
  12902. isScrolling = true;
  12903. $$rAF.throttle(loopScrollEvent);
  12904. element.triggerHandler('$scrollstart');
  12905. }
  12906. element.triggerHandler('$scroll');
  12907. lastScrollTime = +$mdUtil.now();
  12908. });
  12909. function loopScrollEvent() {
  12910. if (+$mdUtil.now() - lastScrollTime > SCROLL_END_DELAY) {
  12911. isScrolling = false;
  12912. element.triggerHandler('$scrollend');
  12913. } else {
  12914. element.triggerHandler('$scroll');
  12915. $$rAF.throttle(loopScrollEvent);
  12916. }
  12917. }
  12918. }
  12919. }
  12920. MdSticky.$inject = ["$document", "$mdConstant", "$$rAF", "$mdUtil"];
  12921. })();
  12922. (function(){
  12923. "use strict";
  12924. /**
  12925. * @ngdoc module
  12926. * @name material.components.subheader
  12927. * @description
  12928. * SubHeader module
  12929. *
  12930. * Subheaders are special list tiles that delineate distinct sections of a
  12931. * list or grid list and are typically related to the current filtering or
  12932. * sorting criteria. Subheader tiles are either displayed inline with tiles or
  12933. * can be associated with content, for example, in an adjacent column.
  12934. *
  12935. * Upon scrolling, subheaders remain pinned to the top of the screen and remain
  12936. * pinned until pushed on or off screen by the next subheader. @see [Material
  12937. * Design Specifications](https://www.google.com/design/spec/components/subheaders.html)
  12938. *
  12939. * > To improve the visual grouping of content, use the system color for your subheaders.
  12940. *
  12941. */
  12942. angular
  12943. .module('material.components.subheader', [
  12944. 'material.core',
  12945. 'material.components.sticky'
  12946. ])
  12947. .directive('mdSubheader', MdSubheaderDirective);
  12948. /**
  12949. * @ngdoc directive
  12950. * @name mdSubheader
  12951. * @module material.components.subheader
  12952. *
  12953. * @restrict E
  12954. *
  12955. * @description
  12956. * The `<md-subheader>` directive is a subheader for a section. By default it is sticky.
  12957. * You can make it not sticky by applying the `md-no-sticky` class to the subheader.
  12958. *
  12959. *
  12960. * @usage
  12961. * <hljs lang="html">
  12962. * <md-subheader>Online Friends</md-subheader>
  12963. * </hljs>
  12964. */
  12965. function MdSubheaderDirective($mdSticky, $compile, $mdTheming, $mdUtil) {
  12966. return {
  12967. restrict: 'E',
  12968. replace: true,
  12969. transclude: true,
  12970. template: (
  12971. '<div class="md-subheader">' +
  12972. ' <div class="md-subheader-inner">' +
  12973. ' <span class="md-subheader-content"></span>' +
  12974. ' </div>' +
  12975. '</div>'
  12976. ),
  12977. link: function postLink(scope, element, attr, controllers, transclude) {
  12978. $mdTheming(element);
  12979. var outerHTML = element[0].outerHTML;
  12980. function getContent(el) {
  12981. return angular.element(el[0].querySelector('.md-subheader-content'));
  12982. }
  12983. // Transclude the user-given contents of the subheader
  12984. // the conventional way.
  12985. transclude(scope, function(clone) {
  12986. getContent(element).append(clone);
  12987. });
  12988. // Create another clone, that uses the outer and inner contents
  12989. // of the element, that will be 'stickied' as the user scrolls.
  12990. if (!element.hasClass('md-no-sticky')) {
  12991. transclude(scope, function(clone) {
  12992. // If the user adds an ng-if or ng-repeat directly to the md-subheader element, the
  12993. // compiled clone below will only be a comment tag (since they replace their elements with
  12994. // a comment) which cannot be properly passed to the $mdSticky; so we wrap it in our own
  12995. // DIV to ensure we have something $mdSticky can use
  12996. var wrapperHtml = '<div class="md-subheader-wrapper">' + outerHTML + '</div>';
  12997. var stickyClone = $compile(wrapperHtml)(scope);
  12998. // Append the sticky
  12999. $mdSticky(scope, element, stickyClone);
  13000. // Delay initialization until after any `ng-if`/`ng-repeat`/etc has finished before
  13001. // attempting to create the clone
  13002. $mdUtil.nextTick(function() {
  13003. getContent(stickyClone).append(clone);
  13004. });
  13005. });
  13006. }
  13007. }
  13008. }
  13009. }
  13010. MdSubheaderDirective.$inject = ["$mdSticky", "$compile", "$mdTheming", "$mdUtil"];
  13011. })();
  13012. (function(){
  13013. "use strict";
  13014. /**
  13015. * @ngdoc module
  13016. * @name material.components.swipe
  13017. * @description Swipe module!
  13018. */
  13019. /**
  13020. * @ngdoc directive
  13021. * @module material.components.swipe
  13022. * @name mdSwipeLeft
  13023. *
  13024. * @restrict A
  13025. *
  13026. * @description
  13027. * The md-swipe-left directives allows you to specify custom behavior when an element is swiped
  13028. * left.
  13029. *
  13030. * @usage
  13031. * <hljs lang="html">
  13032. * <div md-swipe-left="onSwipeLeft()">Swipe me left!</div>
  13033. * </hljs>
  13034. */
  13035. /**
  13036. * @ngdoc directive
  13037. * @module material.components.swipe
  13038. * @name mdSwipeRight
  13039. *
  13040. * @restrict A
  13041. *
  13042. * @description
  13043. * The md-swipe-right directives allows you to specify custom behavior when an element is swiped
  13044. * right.
  13045. *
  13046. * @usage
  13047. * <hljs lang="html">
  13048. * <div md-swipe-right="onSwipeRight()">Swipe me right!</div>
  13049. * </hljs>
  13050. */
  13051. angular.module('material.components.swipe', ['material.core'])
  13052. .directive('mdSwipeLeft', getDirective('SwipeLeft'))
  13053. .directive('mdSwipeRight', getDirective('SwipeRight'));
  13054. function getDirective(name) {
  13055. var directiveName = 'md' + name;
  13056. var eventName = '$md.' + name.toLowerCase();
  13057. DirectiveFactory.$inject = ["$parse"];
  13058. return DirectiveFactory;
  13059. /* @ngInject */
  13060. function DirectiveFactory($parse) {
  13061. return { restrict: 'A', link: postLink };
  13062. function postLink(scope, element, attr) {
  13063. var fn = $parse(attr[directiveName]);
  13064. element.on(eventName, function(ev) {
  13065. scope.$apply(function() { fn(scope, { $event: ev }); });
  13066. });
  13067. }
  13068. }
  13069. }
  13070. })();
  13071. (function(){
  13072. "use strict";
  13073. /**
  13074. * @private
  13075. * @ngdoc module
  13076. * @name material.components.switch
  13077. */
  13078. angular.module('material.components.switch', [
  13079. 'material.core',
  13080. 'material.components.checkbox'
  13081. ])
  13082. .directive('mdSwitch', MdSwitch);
  13083. /**
  13084. * @private
  13085. * @ngdoc directive
  13086. * @module material.components.switch
  13087. * @name mdSwitch
  13088. * @restrict E
  13089. *
  13090. * The switch directive is used very much like the normal [angular checkbox](https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D).
  13091. *
  13092. * As per the [material design spec](http://www.google.com/design/spec/style/color.html#color-ui-color-application)
  13093. * the switch is in the accent color by default. The primary color palette may be used with
  13094. * the `md-primary` class.
  13095. *
  13096. * @param {string} ng-model Assignable angular expression to data-bind to.
  13097. * @param {string=} name Property name of the form under which the control is published.
  13098. * @param {expression=} ng-true-value The value to which the expression should be set when selected.
  13099. * @param {expression=} ng-false-value The value to which the expression should be set when not selected.
  13100. * @param {string=} ng-change Angular expression to be executed when input changes due to user interaction with the input element.
  13101. * @param {boolean=} md-no-ink Use of attribute indicates use of ripple ink effects.
  13102. * @param {string=} aria-label Publish the button label used by screen-readers for accessibility. Defaults to the switch's text.
  13103. *
  13104. * @usage
  13105. * <hljs lang="html">
  13106. * <md-switch ng-model="isActive" aria-label="Finished?">
  13107. * Finished ?
  13108. * </md-switch>
  13109. *
  13110. * <md-switch md-no-ink ng-model="hasInk" aria-label="No Ink Effects">
  13111. * No Ink Effects
  13112. * </md-switch>
  13113. *
  13114. * <md-switch ng-disabled="true" ng-model="isDisabled" aria-label="Disabled">
  13115. * Disabled
  13116. * </md-switch>
  13117. *
  13118. * </hljs>
  13119. */
  13120. function MdSwitch(mdCheckboxDirective, $mdUtil, $mdConstant, $parse, $$rAF, $mdGesture) {
  13121. var checkboxDirective = mdCheckboxDirective[0];
  13122. return {
  13123. restrict: 'E',
  13124. priority: 210, // Run before ngAria
  13125. transclude: true,
  13126. template:
  13127. '<div class="md-container">' +
  13128. '<div class="md-bar"></div>' +
  13129. '<div class="md-thumb-container">' +
  13130. '<div class="md-thumb" md-ink-ripple md-ink-ripple-checkbox></div>' +
  13131. '</div>'+
  13132. '</div>' +
  13133. '<div ng-transclude class="md-label"></div>',
  13134. require: '?ngModel',
  13135. compile: mdSwitchCompile
  13136. };
  13137. function mdSwitchCompile(element, attr) {
  13138. var checkboxLink = checkboxDirective.compile(element, attr);
  13139. // No transition on initial load.
  13140. element.addClass('md-dragging');
  13141. return function (scope, element, attr, ngModel) {
  13142. ngModel = ngModel || $mdUtil.fakeNgModel();
  13143. var disabledGetter = null;
  13144. if (attr.disabled != null) {
  13145. disabledGetter = function() { return true; };
  13146. } else if (attr.ngDisabled) {
  13147. disabledGetter = $parse(attr.ngDisabled);
  13148. }
  13149. var thumbContainer = angular.element(element[0].querySelector('.md-thumb-container'));
  13150. var switchContainer = angular.element(element[0].querySelector('.md-container'));
  13151. // no transition on initial load
  13152. $$rAF(function() {
  13153. element.removeClass('md-dragging');
  13154. });
  13155. checkboxLink(scope, element, attr, ngModel);
  13156. if (disabledGetter) {
  13157. scope.$watch(disabledGetter, function(isDisabled) {
  13158. element.attr('tabindex', isDisabled ? -1 : 0);
  13159. });
  13160. }
  13161. // These events are triggered by setup drag
  13162. $mdGesture.register(switchContainer, 'drag');
  13163. switchContainer
  13164. .on('$md.dragstart', onDragStart)
  13165. .on('$md.drag', onDrag)
  13166. .on('$md.dragend', onDragEnd);
  13167. var drag;
  13168. function onDragStart(ev) {
  13169. // Don't go if the switch is disabled.
  13170. if (disabledGetter && disabledGetter(scope)) return;
  13171. ev.stopPropagation();
  13172. element.addClass('md-dragging');
  13173. drag = {width: thumbContainer.prop('offsetWidth')};
  13174. element.removeClass('transition');
  13175. }
  13176. function onDrag(ev) {
  13177. if (!drag) return;
  13178. ev.stopPropagation();
  13179. ev.srcEvent && ev.srcEvent.preventDefault();
  13180. var percent = ev.pointer.distanceX / drag.width;
  13181. //if checked, start from right. else, start from left
  13182. var translate = ngModel.$viewValue ? 1 + percent : percent;
  13183. // Make sure the switch stays inside its bounds, 0-1%
  13184. translate = Math.max(0, Math.min(1, translate));
  13185. thumbContainer.css($mdConstant.CSS.TRANSFORM, 'translate3d(' + (100*translate) + '%,0,0)');
  13186. drag.translate = translate;
  13187. }
  13188. function onDragEnd(ev) {
  13189. if (!drag) return;
  13190. ev.stopPropagation();
  13191. element.removeClass('md-dragging');
  13192. thumbContainer.css($mdConstant.CSS.TRANSFORM, '');
  13193. // We changed if there is no distance (this is a click a click),
  13194. // or if the drag distance is >50% of the total.
  13195. var isChanged = ngModel.$viewValue ? drag.translate > 0.5 : drag.translate < 0.5;
  13196. if (isChanged) {
  13197. applyModelValue(!ngModel.$viewValue);
  13198. }
  13199. drag = null;
  13200. }
  13201. function applyModelValue(newValue) {
  13202. scope.$apply(function() {
  13203. ngModel.$setViewValue(newValue);
  13204. ngModel.$render();
  13205. });
  13206. }
  13207. };
  13208. }
  13209. }
  13210. MdSwitch.$inject = ["mdCheckboxDirective", "$mdUtil", "$mdConstant", "$parse", "$$rAF", "$mdGesture"];
  13211. })();
  13212. (function(){
  13213. "use strict";
  13214. /**
  13215. * @ngdoc module
  13216. * @name material.components.toast
  13217. * @description
  13218. * Toast
  13219. */
  13220. angular.module('material.components.toast', [
  13221. 'material.core',
  13222. 'material.components.button'
  13223. ])
  13224. .directive('mdToast', MdToastDirective)
  13225. .provider('$mdToast', MdToastProvider);
  13226. /* @ngInject */
  13227. function MdToastDirective($mdToast) {
  13228. return {
  13229. restrict: 'E',
  13230. link: function postLink(scope, element, attr) {
  13231. // When navigation force destroys an interimElement, then
  13232. // listen and $destroy() that interim instance...
  13233. scope.$on('$destroy', function() {
  13234. $mdToast.destroy();
  13235. });
  13236. }
  13237. };
  13238. }
  13239. MdToastDirective.$inject = ["$mdToast"];
  13240. /**
  13241. * @ngdoc service
  13242. * @name $mdToast
  13243. * @module material.components.toast
  13244. *
  13245. * @description
  13246. * `$mdToast` is a service to build a toast notification on any position
  13247. * on the screen with an optional duration, and provides a simple promise API.
  13248. *
  13249. *
  13250. * ## Restrictions on custom toasts
  13251. * - The toast's template must have an outer `<md-toast>` element.
  13252. * - For a toast action, use element with class `md-action`.
  13253. * - Add the class `md-capsule` for curved corners.
  13254. *
  13255. * @usage
  13256. * <hljs lang="html">
  13257. * <div ng-controller="MyController">
  13258. * <md-button ng-click="openToast()">
  13259. * Open a Toast!
  13260. * </md-button>
  13261. * </div>
  13262. * </hljs>
  13263. *
  13264. * <hljs lang="js">
  13265. * var app = angular.module('app', ['ngMaterial']);
  13266. * app.controller('MyController', function($scope, $mdToast) {
  13267. * $scope.openToast = function($event) {
  13268. * $mdToast.show($mdToast.simple().content('Hello!'));
  13269. * // Could also do $mdToast.showSimple('Hello');
  13270. * };
  13271. * });
  13272. * </hljs>
  13273. */
  13274. /**
  13275. * @ngdoc method
  13276. * @name $mdToast#showSimple
  13277. *
  13278. * @description
  13279. * Convenience method which builds and shows a simple toast.
  13280. *
  13281. * @returns {promise} A promise that can be resolved with `$mdToast.hide()` or
  13282. * rejected with `$mdToast.cancel()`.
  13283. *
  13284. */
  13285. /**
  13286. * @ngdoc method
  13287. * @name $mdToast#simple
  13288. *
  13289. * @description
  13290. * Builds a preconfigured toast.
  13291. *
  13292. * @returns {obj} a `$mdToastPreset` with the chainable configuration methods:
  13293. *
  13294. * - $mdToastPreset#content(string) - sets toast content to string
  13295. * - $mdToastPreset#action(string) - adds an action button. If clicked the promise (returned from `show()`) will resolve
  13296. * with value 'ok'; otherwise it promise is resolved with 'true' after a hideDelay timeout.
  13297. * - $mdToastPreset#highlightAction(boolean) - sets action button to be highlighted
  13298. * - $mdToastPreset#capsule(boolean) - adds 'md-capsule' class to the toast (curved corners)
  13299. * - $mdToastPreset#theme(string) - sets the theme on the toast to theme (default is `$mdThemingProvider`'s default theme)
  13300. */
  13301. /**
  13302. * @ngdoc method
  13303. * @name $mdToast#updateContent
  13304. *
  13305. * @description
  13306. * Updates the content of an existing toast. Useful for updating things like counts, etc.
  13307. *
  13308. */
  13309. /**
  13310. * @ngdoc method
  13311. * @name $mdToast#build
  13312. *
  13313. * @description
  13314. * Creates a custom `$mdToastPreset` that you can configure.
  13315. *
  13316. * @returns {obj} a `$mdToastPreset` with the chainable configuration methods for shows' options (see below).
  13317. */
  13318. /**
  13319. * @ngdoc method
  13320. * @name $mdToast#show
  13321. *
  13322. * @description Shows the toast.
  13323. *
  13324. * @param {object} optionsOrPreset Either provide an `$mdToastPreset` returned from `simple()`
  13325. * and `build()`, or an options object with the following properties:
  13326. *
  13327. * - `templateUrl` - `{string=}`: The url of an html template file that will
  13328. * be used as the content of the toast. Restrictions: the template must
  13329. * have an outer `md-toast` element.
  13330. * - `template` - `{string=}`: Same as templateUrl, except this is an actual
  13331. * template string.
  13332. * - `scope` - `{object=}`: the scope to link the template / controller to. If none is specified, it will create a new child scope.
  13333. * This scope will be destroyed when the toast is removed unless `preserveScope` is set to true.
  13334. * - `preserveScope` - `{boolean=}`: whether to preserve the scope when the element is removed. Default is false
  13335. * - `hideDelay` - `{number=}`: How many milliseconds the toast should stay
  13336. * active before automatically closing. Set to 0 or false to have the toast stay open until
  13337. * closed manually. Default: 3000.
  13338. * - `position` - `{string=}`: Where to place the toast. Available: any combination
  13339. * of 'bottom', 'left', 'top', 'right', 'fit'. Default: 'bottom left'.
  13340. * - `controller` - `{string=}`: The controller to associate with this toast.
  13341. * The controller will be injected the local `$mdToast.hide( )`, which is a function
  13342. * used to hide the toast.
  13343. * - `locals` - `{string=}`: An object containing key/value pairs. The keys will
  13344. * be used as names of values to inject into the controller. For example,
  13345. * `locals: {three: 3}` would inject `three` into the controller with the value
  13346. * of 3.
  13347. * - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in. These values will not be available until after initialization.
  13348. * - `resolve` - `{object=}`: Similar to locals, except it takes promises as values
  13349. * and the toast will not open until the promises resolve.
  13350. * - `controllerAs` - `{string=}`: An alias to assign the controller to on the scope.
  13351. * - `parent` - `{element=}`: The element to append the toast to. Defaults to appending
  13352. * to the root element of the application.
  13353. *
  13354. * @returns {promise} A promise that can be resolved with `$mdToast.hide()` or
  13355. * rejected with `$mdToast.cancel()`. `$mdToast.hide()` will resolve either with a Boolean
  13356. * value == 'true' or the value passed as an argument to `$mdToast.hide()`.
  13357. * And `$mdToast.cancel()` will resolve the promise with a Boolean value == 'false'
  13358. */
  13359. /**
  13360. * @ngdoc method
  13361. * @name $mdToast#hide
  13362. *
  13363. * @description
  13364. * Hide an existing toast and resolve the promise returned from `$mdToast.show()`.
  13365. *
  13366. * @param {*=} response An argument for the resolved promise.
  13367. *
  13368. * @returns {promise} a promise that is called when the existing element is removed from the DOM.
  13369. * The promise is resolved with either a Boolean value == 'true' or the value passed as the
  13370. * argument to `.hide()`.
  13371. *
  13372. */
  13373. /**
  13374. * @ngdoc method
  13375. * @name $mdToast#cancel
  13376. *
  13377. * @description
  13378. * Hide the existing toast and reject the promise returned from
  13379. * `$mdToast.show()`.
  13380. *
  13381. * @param {*=} response An argument for the rejected promise.
  13382. *
  13383. * @returns {promise} a promise that is called when the existing element is removed from the DOM
  13384. * The promise is resolved with a Boolean value == 'false'.
  13385. *
  13386. */
  13387. function MdToastProvider($$interimElementProvider) {
  13388. // Differentiate promise resolves: hide timeout (value == true) and hide action clicks (value == ok).
  13389. var ACTION_RESOLVE = 'ok';
  13390. var activeToastContent;
  13391. var $mdToast = $$interimElementProvider('$mdToast')
  13392. .setDefaults({
  13393. methods: ['position', 'hideDelay', 'capsule', 'parent' ],
  13394. options: toastDefaultOptions
  13395. })
  13396. .addPreset('simple', {
  13397. argOption: 'content',
  13398. methods: ['content', 'action', 'highlightAction', 'theme', 'parent'],
  13399. options: /* @ngInject */ ["$mdToast", "$mdTheming", function($mdToast, $mdTheming) {
  13400. var opts = {
  13401. template: [
  13402. '<md-toast md-theme="{{ toast.theme }}" ng-class="{\'md-capsule\': toast.capsule}">',
  13403. '<span flex>{{ toast.content }}</span>',
  13404. '<md-button class="md-action" ng-if="toast.action" ng-click="toast.resolve()" ng-class="{\'md-highlight\': toast.highlightAction}">',
  13405. '{{ toast.action }}',
  13406. '</md-button>',
  13407. '</md-toast>'
  13408. ].join(''),
  13409. controller: /* @ngInject */ ["$scope", function mdToastCtrl($scope) {
  13410. var self = this;
  13411. $scope.$watch(function() { return activeToastContent; }, function() {
  13412. self.content = activeToastContent;
  13413. });
  13414. this.resolve = function() {
  13415. $mdToast.hide( ACTION_RESOLVE );
  13416. };
  13417. }],
  13418. theme: $mdTheming.defaultTheme(),
  13419. controllerAs: 'toast',
  13420. bindToController: true
  13421. };
  13422. return opts;
  13423. }]
  13424. })
  13425. .addMethod('updateContent', function(newContent) {
  13426. activeToastContent = newContent;
  13427. });
  13428. toastDefaultOptions.$inject = ["$animate", "$mdToast", "$mdUtil"];
  13429. return $mdToast;
  13430. /* @ngInject */
  13431. function toastDefaultOptions($animate, $mdToast, $mdUtil) {
  13432. var SWIPE_EVENTS = '$md.swipeleft $md.swiperight';
  13433. return {
  13434. onShow: onShow,
  13435. onRemove: onRemove,
  13436. position: 'bottom left',
  13437. themable: true,
  13438. hideDelay: 3000
  13439. };
  13440. function onShow(scope, element, options) {
  13441. activeToastContent = options.content;
  13442. element = $mdUtil.extractElementByName(element, 'md-toast', true);
  13443. options.onSwipe = function(ev, gesture) {
  13444. //Add swipeleft/swiperight class to element so it can animate correctly
  13445. element.addClass('md-' + ev.type.replace('$md.',''));
  13446. $mdUtil.nextTick($mdToast.cancel);
  13447. };
  13448. options.openClass = toastOpenClass(options.position);
  13449. // 'top left' -> 'md-top md-left'
  13450. options.parent.addClass(options.openClass);
  13451. element.on(SWIPE_EVENTS, options.onSwipe);
  13452. element.addClass(options.position.split(' ').map(function(pos) {
  13453. return 'md-' + pos;
  13454. }).join(' '));
  13455. return $animate.enter(element, options.parent);
  13456. }
  13457. function onRemove(scope, element, options) {
  13458. element.off(SWIPE_EVENTS, options.onSwipe);
  13459. options.parent.removeClass(options.openClass);
  13460. return (options.$destroy == true) ? element.remove() : $animate.leave(element);
  13461. }
  13462. function toastOpenClass(position) {
  13463. return 'md-toast-open-' +
  13464. (position.indexOf('top') > -1 ? 'top' : 'bottom');
  13465. }
  13466. }
  13467. }
  13468. MdToastProvider.$inject = ["$$interimElementProvider"];
  13469. })();
  13470. (function(){
  13471. "use strict";
  13472. /**
  13473. * @ngdoc module
  13474. * @name material.components.tabs
  13475. * @description
  13476. *
  13477. * Tabs, created with the `<md-tabs>` directive provide *tabbed* navigation with different styles.
  13478. * The Tabs component consists of clickable tabs that are aligned horizontally side-by-side.
  13479. *
  13480. * Features include support for:
  13481. *
  13482. * - static or dynamic tabs,
  13483. * - responsive designs,
  13484. * - accessibility support (ARIA),
  13485. * - tab pagination,
  13486. * - external or internal tab content,
  13487. * - focus indicators and arrow-key navigations,
  13488. * - programmatic lookup and access to tab controllers, and
  13489. * - dynamic transitions through different tab contents.
  13490. *
  13491. */
  13492. /*
  13493. * @see js folder for tabs implementation
  13494. */
  13495. angular.module('material.components.tabs', [
  13496. 'material.core',
  13497. 'material.components.icon'
  13498. ]);
  13499. })();
  13500. (function(){
  13501. "use strict";
  13502. /**
  13503. * @ngdoc module
  13504. * @name material.components.toolbar
  13505. */
  13506. angular.module('material.components.toolbar', [
  13507. 'material.core',
  13508. 'material.components.content'
  13509. ])
  13510. .directive('mdToolbar', mdToolbarDirective);
  13511. /**
  13512. * @ngdoc directive
  13513. * @name mdToolbar
  13514. * @module material.components.toolbar
  13515. * @restrict E
  13516. * @description
  13517. * `md-toolbar` is used to place a toolbar in your app.
  13518. *
  13519. * Toolbars are usually used above a content area to display the title of the
  13520. * current page, and show relevant action buttons for that page.
  13521. *
  13522. * You can change the height of the toolbar by adding either the
  13523. * `md-medium-tall` or `md-tall` class to the toolbar.
  13524. *
  13525. * @usage
  13526. * <hljs lang="html">
  13527. * <div layout="column" layout-fill>
  13528. * <md-toolbar>
  13529. *
  13530. * <div class="md-toolbar-tools">
  13531. * <span>My App's Title</span>
  13532. *
  13533. * <!-- fill up the space between left and right area -->
  13534. * <span flex></span>
  13535. *
  13536. * <md-button>
  13537. * Right Bar Button
  13538. * </md-button>
  13539. * </div>
  13540. *
  13541. * </md-toolbar>
  13542. * <md-content>
  13543. * Hello!
  13544. * </md-content>
  13545. * </div>
  13546. * </hljs>
  13547. *
  13548. * @param {boolean=} md-scroll-shrink Whether the header should shrink away as
  13549. * the user scrolls down, and reveal itself as the user scrolls up.
  13550. *
  13551. * _**Note (1):** for scrollShrink to work, the toolbar must be a sibling of a
  13552. * `md-content` element, placed before it. See the scroll shrink demo._
  13553. *
  13554. * _**Note (2):** The `md-scroll-shrink` attribute is only parsed on component
  13555. * initialization, it does not watch for scope changes._
  13556. *
  13557. *
  13558. * @param {number=} md-shrink-speed-factor How much to change the speed of the toolbar's
  13559. * shrinking by. For example, if 0.25 is given then the toolbar will shrink
  13560. * at one fourth the rate at which the user scrolls down. Default 0.5.
  13561. */
  13562. function mdToolbarDirective($$rAF, $mdConstant, $mdUtil, $mdTheming, $animate) {
  13563. var translateY = angular.bind(null, $mdUtil.supplant, 'translate3d(0,{0}px,0)');
  13564. return {
  13565. restrict: 'E',
  13566. link: function(scope, element, attr) {
  13567. $mdTheming(element);
  13568. if (angular.isDefined(attr.mdScrollShrink)) {
  13569. setupScrollShrink();
  13570. }
  13571. function setupScrollShrink() {
  13572. var toolbarHeight;
  13573. var contentElement;
  13574. var disableScrollShrink = angular.noop;
  13575. // Current "y" position of scroll
  13576. // Store the last scroll top position
  13577. var y = 0;
  13578. var prevScrollTop = 0;
  13579. var shrinkSpeedFactor = attr.mdShrinkSpeedFactor || 0.5;
  13580. var debouncedContentScroll = $$rAF.throttle(onContentScroll);
  13581. var debouncedUpdateHeight = $mdUtil.debounce(updateToolbarHeight, 5 * 1000);
  13582. // Wait for $mdContentLoaded event from mdContent directive.
  13583. // If the mdContent element is a sibling of our toolbar, hook it up
  13584. // to scroll events.
  13585. scope.$on('$mdContentLoaded', onMdContentLoad);
  13586. // If the toolbar is used inside an ng-if statement, we may miss the
  13587. // $mdContentLoaded event, so we attempt to fake it if we have a
  13588. // md-content close enough.
  13589. attr.$observe('mdScrollShrink', onChangeScrollShrink);
  13590. // If the scope is destroyed (which could happen with ng-if), make sure
  13591. // to disable scroll shrinking again
  13592. scope.$on('$destroy', disableScrollShrink);
  13593. /**
  13594. *
  13595. */
  13596. function onChangeScrollShrink(shrinkWithScroll) {
  13597. var closestContent = element.parent().find('md-content');
  13598. // If we have a content element, fake the call; this might still fail
  13599. // if the content element isn't a sibling of the toolbar
  13600. if (!contentElement && closestContent.length) {
  13601. onMdContentLoad(null, closestContent);
  13602. }
  13603. // Evaluate the expression
  13604. shrinkWithScroll = scope.$eval(shrinkWithScroll);
  13605. // Disable only if the attribute's expression evaluates to false
  13606. if (shrinkWithScroll === false) {
  13607. disableScrollShrink();
  13608. } else {
  13609. disableScrollShrink = enableScrollShrink();
  13610. }
  13611. }
  13612. /**
  13613. *
  13614. */
  13615. function onMdContentLoad($event, newContentEl) {
  13616. // Toolbar and content must be siblings
  13617. if (newContentEl && element.parent()[0] === newContentEl.parent()[0]) {
  13618. // unhook old content event listener if exists
  13619. if (contentElement) {
  13620. contentElement.off('scroll', debouncedContentScroll);
  13621. }
  13622. contentElement = newContentEl;
  13623. disableScrollShrink = enableScrollShrink();
  13624. }
  13625. }
  13626. /**
  13627. *
  13628. */
  13629. function onContentScroll(e) {
  13630. var scrollTop = e ? e.target.scrollTop : prevScrollTop;
  13631. debouncedUpdateHeight();
  13632. y = Math.min(
  13633. toolbarHeight / shrinkSpeedFactor,
  13634. Math.max(0, y + scrollTop - prevScrollTop)
  13635. );
  13636. element.css($mdConstant.CSS.TRANSFORM, translateY([-y * shrinkSpeedFactor]));
  13637. contentElement.css($mdConstant.CSS.TRANSFORM, translateY([(toolbarHeight - y) * shrinkSpeedFactor]));
  13638. prevScrollTop = scrollTop;
  13639. $mdUtil.nextTick(function() {
  13640. var hasWhiteFrame = element.hasClass('md-whiteframe-z1');
  13641. if (hasWhiteFrame && !y) {
  13642. $animate.removeClass(element, 'md-whiteframe-z1');
  13643. } else if (!hasWhiteFrame && y) {
  13644. $animate.addClass(element, 'md-whiteframe-z1');
  13645. }
  13646. });
  13647. }
  13648. /**
  13649. *
  13650. */
  13651. function enableScrollShrink() {
  13652. if (!contentElement) return angular.noop; // no md-content
  13653. contentElement.on('scroll', debouncedContentScroll);
  13654. contentElement.attr('scroll-shrink', 'true');
  13655. $$rAF(updateToolbarHeight);
  13656. return function disableScrollShrink() {
  13657. contentElement.off('scroll', debouncedContentScroll);
  13658. contentElement.attr('scroll-shrink', 'false');
  13659. $$rAF(updateToolbarHeight);
  13660. }
  13661. }
  13662. /**
  13663. *
  13664. */
  13665. function updateToolbarHeight() {
  13666. toolbarHeight = element.prop('offsetHeight');
  13667. // Add a negative margin-top the size of the toolbar to the content el.
  13668. // The content will start transformed down the toolbarHeight amount,
  13669. // so everything looks normal.
  13670. //
  13671. // As the user scrolls down, the content will be transformed up slowly
  13672. // to put the content underneath where the toolbar was.
  13673. var margin = (-toolbarHeight * shrinkSpeedFactor) + 'px';
  13674. contentElement.css({
  13675. "margin-top": margin,
  13676. "margin-bottom": margin
  13677. });
  13678. onContentScroll();
  13679. }
  13680. }
  13681. }
  13682. };
  13683. }
  13684. mdToolbarDirective.$inject = ["$$rAF", "$mdConstant", "$mdUtil", "$mdTheming", "$animate"];
  13685. })();
  13686. (function(){
  13687. "use strict";
  13688. /**
  13689. * @ngdoc module
  13690. * @name material.components.tooltip
  13691. */
  13692. angular
  13693. .module('material.components.tooltip', [ 'material.core' ])
  13694. .directive('mdTooltip', MdTooltipDirective);
  13695. /**
  13696. * @ngdoc directive
  13697. * @name mdTooltip
  13698. * @module material.components.tooltip
  13699. * @description
  13700. * Tooltips are used to describe elements that are interactive and primarily graphical (not textual).
  13701. *
  13702. * Place a `<md-tooltip>` as a child of the element it describes.
  13703. *
  13704. * A tooltip will activate when the user focuses, hovers over, or touches the parent.
  13705. *
  13706. * @usage
  13707. * <hljs lang="html">
  13708. * <md-button class="md-fab md-accent" aria-label="Play">
  13709. * <md-tooltip>
  13710. * Play Music
  13711. * </md-tooltip>
  13712. * <md-icon icon="img/icons/ic_play_arrow_24px.svg"></md-icon>
  13713. * </md-button>
  13714. * </hljs>
  13715. *
  13716. * @param {expression=} md-visible Boolean bound to whether the tooltip is
  13717. * currently visible.
  13718. * @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.
  13719. * @param {string=} md-direction Which direction would you like the tooltip to go? Supports left, right, top, and bottom. Defaults to bottom.
  13720. * @param {boolean=} md-autohide If present or provided with a boolean value, the tooltip will hide on mouse leave, regardless of focus
  13721. */
  13722. function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdTheming, $rootElement,
  13723. $animate, $q) {
  13724. var TOOLTIP_SHOW_DELAY = 300;
  13725. var TOOLTIP_WINDOW_EDGE_SPACE = 8;
  13726. return {
  13727. restrict: 'E',
  13728. transclude: true,
  13729. priority:210, // Before ngAria
  13730. template: '<div class="md-background"></div>' +
  13731. '<div class="md-content" ng-transclude></div>',
  13732. scope: {
  13733. visible: '=?mdVisible',
  13734. delay: '=?mdDelay',
  13735. autohide: '=?mdAutohide'
  13736. },
  13737. link: postLink
  13738. };
  13739. function postLink(scope, element, attr) {
  13740. $mdTheming(element);
  13741. var parent = getParentWithPointerEvents(),
  13742. background = angular.element(element[0].getElementsByClassName('md-background')[0]),
  13743. content = angular.element(element[0].getElementsByClassName('md-content')[0]),
  13744. direction = attr.mdDirection,
  13745. current = getNearestContentElement(),
  13746. tooltipParent = angular.element(current || document.body),
  13747. debouncedOnResize = $$rAF.throttle(function () { if (scope.visible) positionTooltip(); });
  13748. // Initialize element
  13749. setDefaults();
  13750. manipulateElement();
  13751. bindEvents();
  13752. configureWatchers();
  13753. addAriaLabel();
  13754. function setDefaults () {
  13755. if (!angular.isDefined(attr.mdDelay)) scope.delay = TOOLTIP_SHOW_DELAY;
  13756. }
  13757. function configureWatchers () {
  13758. scope.$on('$destroy', function() {
  13759. scope.visible = false;
  13760. element.remove();
  13761. angular.element($window).off('resize', debouncedOnResize);
  13762. });
  13763. scope.$watch('visible', function (isVisible) {
  13764. if (isVisible) showTooltip();
  13765. else hideTooltip();
  13766. });
  13767. }
  13768. function addAriaLabel () {
  13769. if (!parent.attr('aria-label') && !parent.text().trim()) {
  13770. parent.attr('aria-label', element.text().trim());
  13771. }
  13772. }
  13773. function manipulateElement () {
  13774. element.detach();
  13775. element.attr('role', 'tooltip');
  13776. }
  13777. /**
  13778. * Scan up dom hierarchy for enabled parent;
  13779. */
  13780. function getParentWithPointerEvents () {
  13781. var parent = element.parent();
  13782. // jqLite might return a non-null, but still empty, parent; so check for parent and length
  13783. while (hasComputedStyleValue('pointer-events','none', parent)) {
  13784. parent = parent.parent();
  13785. }
  13786. return parent;
  13787. }
  13788. function getNearestContentElement () {
  13789. var current = element.parent()[0];
  13790. // Look for the nearest parent md-content, stopping at the rootElement.
  13791. while (current && current !== $rootElement[0] && current !== document.body) {
  13792. current = current.parentNode;
  13793. }
  13794. return current;
  13795. }
  13796. function hasComputedStyleValue(key, value, target) {
  13797. var hasValue = false;
  13798. if ( target && target.length ) {
  13799. key = attr.$normalize(key);
  13800. target = target[0] || element[0];
  13801. var computedStyles = $window.getComputedStyle(target);
  13802. hasValue = angular.isDefined(computedStyles[key]) && (computedStyles[key] == value);
  13803. }
  13804. return hasValue;
  13805. }
  13806. function bindEvents () {
  13807. var mouseActive = false;
  13808. var ngWindow = angular.element($window);
  13809. // Store whether the element was focused when the window loses focus.
  13810. var windowBlurHandler = function() {
  13811. elementFocusedOnWindowBlur = document.activeElement === parent[0];
  13812. };
  13813. var elementFocusedOnWindowBlur = false;
  13814. ngWindow.on('blur', windowBlurHandler);
  13815. scope.$on('$destroy', function() {
  13816. ngWindow.off('blur', windowBlurHandler);
  13817. });
  13818. var enterHandler = function(e) {
  13819. // Prevent the tooltip from showing when the window is receiving focus.
  13820. if (e.type === 'focus' && elementFocusedOnWindowBlur) {
  13821. elementFocusedOnWindowBlur = false;
  13822. return;
  13823. }
  13824. parent.on('blur mouseleave touchend touchcancel', leaveHandler );
  13825. setVisible(true);
  13826. };
  13827. var leaveHandler = function () {
  13828. var autohide = scope.hasOwnProperty('autohide') ? scope.autohide : attr.hasOwnProperty('mdAutohide');
  13829. if (autohide || mouseActive || ($document[0].activeElement !== parent[0]) ) {
  13830. parent.off('blur mouseleave touchend touchcancel', leaveHandler );
  13831. parent.triggerHandler("blur");
  13832. setVisible(false);
  13833. }
  13834. mouseActive = false;
  13835. };
  13836. // to avoid `synthetic clicks` we listen to mousedown instead of `click`
  13837. parent.on('mousedown', function() { mouseActive = true; });
  13838. parent.on('focus mouseenter touchstart', enterHandler );
  13839. angular.element($window).on('resize', debouncedOnResize);
  13840. }
  13841. function setVisible (value) {
  13842. setVisible.value = !!value;
  13843. if (!setVisible.queued) {
  13844. if (value) {
  13845. setVisible.queued = true;
  13846. $timeout(function() {
  13847. scope.visible = setVisible.value;
  13848. setVisible.queued = false;
  13849. }, scope.delay);
  13850. } else {
  13851. $mdUtil.nextTick(function() { scope.visible = false; });
  13852. }
  13853. }
  13854. }
  13855. function showTooltip() {
  13856. // Insert the element before positioning it, so we can get the position
  13857. // and check if we should display it
  13858. tooltipParent.append(element);
  13859. // Check if we should display it or not.
  13860. // This handles hide-* and show-* along with any user defined css
  13861. if ( hasComputedStyleValue('display','none') ) {
  13862. scope.visible = false;
  13863. element.detach();
  13864. return;
  13865. }
  13866. positionTooltip();
  13867. angular.forEach([element, background, content], function (element) {
  13868. $animate.addClass(element, 'md-show');
  13869. });
  13870. }
  13871. function hideTooltip() {
  13872. var promises = [];
  13873. angular.forEach([element, background, content], function (it) {
  13874. if (it.parent() && it.hasClass('md-show')) {
  13875. promises.push($animate.removeClass(it, 'md-show'));
  13876. }
  13877. });
  13878. $q.all(promises)
  13879. .then(function () {
  13880. if (!scope.visible) element.detach();
  13881. });
  13882. }
  13883. function positionTooltip() {
  13884. var tipRect = $mdUtil.offsetRect(element, tooltipParent);
  13885. var parentRect = $mdUtil.offsetRect(parent, tooltipParent);
  13886. var newPosition = getPosition(direction);
  13887. // If the user provided a direction, just nudge the tooltip onto the screen
  13888. // Otherwise, recalculate based on 'top' since default is 'bottom'
  13889. if (direction) {
  13890. newPosition = fitInParent(newPosition);
  13891. } else if (newPosition.top > element.prop('offsetParent').scrollHeight - tipRect.height - TOOLTIP_WINDOW_EDGE_SPACE) {
  13892. newPosition = fitInParent(getPosition('top'));
  13893. }
  13894. element.css({top: newPosition.top + 'px', left: newPosition.left + 'px'});
  13895. positionBackground();
  13896. function positionBackground () {
  13897. var size = direction === 'left' || direction === 'right'
  13898. ? Math.sqrt(Math.pow(tipRect.width, 2) + Math.pow(tipRect.height / 2, 2)) * 2
  13899. : Math.sqrt(Math.pow(tipRect.width / 2, 2) + Math.pow(tipRect.height, 2)) * 2,
  13900. position = direction === 'left' ? { left: 100, top: 50 }
  13901. : direction === 'right' ? { left: 0, top: 50 }
  13902. : direction === 'top' ? { left: 50, top: 100 }
  13903. : { left: 50, top: 0 };
  13904. background.css({
  13905. width: size + 'px',
  13906. height: size + 'px',
  13907. left: position.left + '%',
  13908. top: position.top + '%'
  13909. });
  13910. }
  13911. function fitInParent (pos) {
  13912. var newPosition = { left: pos.left, top: pos.top };
  13913. newPosition.left = Math.min( newPosition.left, tooltipParent.prop('scrollWidth') - tipRect.width - TOOLTIP_WINDOW_EDGE_SPACE );
  13914. newPosition.left = Math.max( newPosition.left, TOOLTIP_WINDOW_EDGE_SPACE );
  13915. newPosition.top = Math.min( newPosition.top, tooltipParent.prop('scrollHeight') - tipRect.height - TOOLTIP_WINDOW_EDGE_SPACE );
  13916. newPosition.top = Math.max( newPosition.top, TOOLTIP_WINDOW_EDGE_SPACE );
  13917. return newPosition;
  13918. }
  13919. function getPosition (dir) {
  13920. return dir === 'left'
  13921. ? { left: parentRect.left - tipRect.width - TOOLTIP_WINDOW_EDGE_SPACE,
  13922. top: parentRect.top + parentRect.height / 2 - tipRect.height / 2 }
  13923. : dir === 'right'
  13924. ? { left: parentRect.left + parentRect.width + TOOLTIP_WINDOW_EDGE_SPACE,
  13925. top: parentRect.top + parentRect.height / 2 - tipRect.height / 2 }
  13926. : dir === 'top'
  13927. ? { left: parentRect.left + parentRect.width / 2 - tipRect.width / 2,
  13928. top: parentRect.top - tipRect.height - TOOLTIP_WINDOW_EDGE_SPACE }
  13929. : { left: parentRect.left + parentRect.width / 2 - tipRect.width / 2,
  13930. top: parentRect.top + parentRect.height + TOOLTIP_WINDOW_EDGE_SPACE };
  13931. }
  13932. }
  13933. }
  13934. }
  13935. MdTooltipDirective.$inject = ["$timeout", "$window", "$$rAF", "$document", "$mdUtil", "$mdTheming", "$rootElement", "$animate", "$q"];
  13936. })();
  13937. (function(){
  13938. "use strict";
  13939. /**
  13940. * @ngdoc module
  13941. * @name material.components.virtualRepeat
  13942. */
  13943. angular.module('material.components.virtualRepeat', [
  13944. 'material.core'
  13945. ])
  13946. .directive('mdVirtualRepeatContainer', VirtualRepeatContainerDirective)
  13947. .directive('mdVirtualRepeat', VirtualRepeatDirective);
  13948. /**
  13949. * @ngdoc directive
  13950. * @name mdVirtualRepeatContainer
  13951. * @module material.components.virtualRepeat
  13952. * @restrict E
  13953. * @description
  13954. * `md-virtual-repeat-container` provides the scroll container for md-virtual-repeat.
  13955. *
  13956. * Virtual repeat is a limited substitute for ng-repeat that renders only
  13957. * enough dom nodes to fill the container and recycling them as the user scrolls.
  13958. *
  13959. * @usage
  13960. * <hljs lang="html">
  13961. *
  13962. * <md-virtual-repeat-container md-top-index="topIndex">
  13963. * <div md-virtual-repeat="i in items" md-item-size="20">Hello {{i}}!</div>
  13964. * </md-virtual-repeat-container>
  13965. * </hljs>
  13966. *
  13967. * @param {number=} md-top-index Binds the index of the item that is at the top of the scroll
  13968. * container to $scope. It can both read and set the scroll position.
  13969. * @param {boolean=} md-orient-horizontal Whether the container should scroll horizontally
  13970. * (defaults to orientation and scrolling vertically).
  13971. * @param {boolean=} md-auto-shrink When present, the container will shrink to fit
  13972. * the number of items when that number is less than its original size.
  13973. * @param {number=} md-auto-shrink-min Minimum number of items that md-auto-shrink
  13974. * will shrink to (default: 0).
  13975. */
  13976. function VirtualRepeatContainerDirective() {
  13977. return {
  13978. controller: VirtualRepeatContainerController,
  13979. template: virtualRepeatContainerTemplate,
  13980. compile: function virtualRepeatContainerCompile($element, $attrs) {
  13981. $element
  13982. .addClass('md-virtual-repeat-container')
  13983. .addClass($attrs.hasOwnProperty('mdOrientHorizontal')
  13984. ? 'md-orient-horizontal'
  13985. : 'md-orient-vertical');
  13986. }
  13987. };
  13988. }
  13989. function virtualRepeatContainerTemplate($element) {
  13990. return '<div class="md-virtual-repeat-scroller">' +
  13991. '<div class="md-virtual-repeat-sizer"></div>' +
  13992. '<div class="md-virtual-repeat-offsetter">' +
  13993. $element[0].innerHTML +
  13994. '</div></div>';
  13995. }
  13996. /**
  13997. * Maximum size, in pixels, that can be explicitly set to an element. The actual value varies
  13998. * between browsers, but IE11 has the very lowest size at a mere 1,533,917px. Ideally we could
  13999. * *compute* this value, but Firefox always reports an element to have a size of zero if it
  14000. * goes over the max, meaning that we'd have to binary search for the value.
  14001. * @const {number}
  14002. */
  14003. var MAX_ELEMENT_SIZE = 1533917;
  14004. /**
  14005. * Number of additional elements to render above and below the visible area inside
  14006. * of the virtual repeat container. A higher number results in less flicker when scrolling
  14007. * very quickly in Safari, but comes with a higher rendering and dirty-checking cost.
  14008. * @const {number}
  14009. */
  14010. var NUM_EXTRA = 3;
  14011. /** @ngInject */
  14012. function VirtualRepeatContainerController($$rAF, $parse, $scope, $element, $attrs) {
  14013. this.$scope = $scope;
  14014. this.$element = $element;
  14015. this.$attrs = $attrs;
  14016. /** @type {number} The width or height of the container */
  14017. this.size = 0;
  14018. /** @type {number} The scroll width or height of the scroller */
  14019. this.scrollSize = 0;
  14020. /** @type {number} The scrollLeft or scrollTop of the scroller */
  14021. this.scrollOffset = 0;
  14022. /** @type {boolean} Whether the scroller is oriented horizontally */
  14023. this.horizontal = this.$attrs.hasOwnProperty('mdOrientHorizontal');
  14024. /** @type {!VirtualRepeatController} The repeater inside of this container */
  14025. this.repeater = null;
  14026. /** @type {boolean} Whether auto-shrink is enabled */
  14027. this.autoShrink = this.$attrs.hasOwnProperty('mdAutoShrink');
  14028. /** @type {number} Minimum number of items to auto-shrink to */
  14029. this.autoShrinkMin = parseInt(this.$attrs.mdAutoShrinkMin, 10) || 0;
  14030. /** @type {?number} Original container size when shrank */
  14031. this.originalSize = null;
  14032. /** @type {number} Amount to offset the total scroll size by. */
  14033. this.offsetSize = parseInt(this.$attrs.mdOffsetSize, 10) || 0;
  14034. if (this.$attrs.mdTopIndex) {
  14035. /** @type {function(angular.Scope): number} Binds to topIndex on Angular scope */
  14036. this.bindTopIndex = $parse(this.$attrs.mdTopIndex);
  14037. /** @type {number} The index of the item that is at the top of the scroll container */
  14038. this.topIndex = this.bindTopIndex(this.$scope);
  14039. if (!angular.isDefined(this.topIndex)) {
  14040. this.topIndex = 0;
  14041. this.bindTopIndex.assign(this.$scope, 0);
  14042. }
  14043. this.$scope.$watch(this.bindTopIndex, angular.bind(this, function(newIndex) {
  14044. if (newIndex !== this.topIndex) {
  14045. this.scrollToIndex(newIndex);
  14046. }
  14047. }));
  14048. } else {
  14049. this.topIndex = 0;
  14050. }
  14051. this.scroller = $element[0].getElementsByClassName('md-virtual-repeat-scroller')[0];
  14052. this.sizer = this.scroller.getElementsByClassName('md-virtual-repeat-sizer')[0];
  14053. this.offsetter = this.scroller.getElementsByClassName('md-virtual-repeat-offsetter')[0];
  14054. $$rAF(angular.bind(this, this.updateSize));
  14055. // TODO: Come up with a more robust (But hopefully also quick!) way of
  14056. // detecting that we're not visible.
  14057. if ($attrs.ngHide) {
  14058. $scope.$watch($attrs.ngHide, angular.bind(this, function(hidden) {
  14059. if (!hidden) {
  14060. $$rAF(angular.bind(this, this.updateSize));
  14061. }
  14062. }));
  14063. }
  14064. }
  14065. VirtualRepeatContainerController.$inject = ["$$rAF", "$parse", "$scope", "$element", "$attrs"];
  14066. /** Called by the md-virtual-repeat inside of the container at startup. */
  14067. VirtualRepeatContainerController.prototype.register = function(repeaterCtrl) {
  14068. this.repeater = repeaterCtrl;
  14069. angular.element(this.scroller)
  14070. .on('scroll wheel touchmove touchend', angular.bind(this, this.handleScroll_));
  14071. };
  14072. /** @return {boolean} Whether the container is configured for horizontal scrolling. */
  14073. VirtualRepeatContainerController.prototype.isHorizontal = function() {
  14074. return this.horizontal;
  14075. };
  14076. /** @return {number} The size (width or height) of the container. */
  14077. VirtualRepeatContainerController.prototype.getSize = function() {
  14078. return this.size;
  14079. };
  14080. /**
  14081. * Resizes the container.
  14082. * @private
  14083. * @param {number} The new size to set.
  14084. */
  14085. VirtualRepeatContainerController.prototype.setSize_ = function(size) {
  14086. this.size = size;
  14087. this.$element[0].style[this.isHorizontal() ? 'width' : 'height'] = size + 'px';
  14088. };
  14089. /** Instructs the container to re-measure its size. */
  14090. VirtualRepeatContainerController.prototype.updateSize = function() {
  14091. if (this.originalSize) return;
  14092. this.size = this.isHorizontal()
  14093. ? this.$element[0].clientWidth
  14094. : this.$element[0].clientHeight;
  14095. this.repeater && this.repeater.containerUpdated();
  14096. };
  14097. /** @return {number} The container's scrollHeight or scrollWidth. */
  14098. VirtualRepeatContainerController.prototype.getScrollSize = function() {
  14099. return this.scrollSize;
  14100. };
  14101. /**
  14102. * Sets the scroller element to the specified size.
  14103. * @private
  14104. * @param {number} size The new size.
  14105. */
  14106. VirtualRepeatContainerController.prototype.sizeScroller_ = function(size) {
  14107. var dimension = this.isHorizontal() ? 'width' : 'height';
  14108. var crossDimension = this.isHorizontal() ? 'height' : 'width';
  14109. // If the size falls within the browser's maximum explicit size for a single element, we can
  14110. // set the size and be done. Otherwise, we have to create children that add up the the desired
  14111. // size.
  14112. if (size < MAX_ELEMENT_SIZE) {
  14113. this.sizer.style[dimension] = size + 'px';
  14114. } else {
  14115. // Clear any existing dimensions.
  14116. this.sizer.innerHTML = '';
  14117. this.sizer.style[dimension] = 'auto';
  14118. this.sizer.style[crossDimension] = 'auto';
  14119. // Divide the total size we have to render into N max-size pieces.
  14120. var numChildren = Math.floor(size / MAX_ELEMENT_SIZE);
  14121. // Element template to clone for each max-size piece.
  14122. var sizerChild = document.createElement('div');
  14123. sizerChild.style[dimension] = MAX_ELEMENT_SIZE + 'px';
  14124. sizerChild.style[crossDimension] = '1px';
  14125. for (var i = 0; i < numChildren; i++) {
  14126. this.sizer.appendChild(sizerChild.cloneNode(false));
  14127. }
  14128. // Re-use the element template for the remainder.
  14129. sizerChild.style[dimension] = (size - (numChildren * MAX_ELEMENT_SIZE)) + 'px';
  14130. this.sizer.appendChild(sizerChild);
  14131. }
  14132. };
  14133. /**
  14134. * If auto-shrinking is enabled, shrinks or unshrinks as appropriate.
  14135. * @private
  14136. * @param {number} size The new size.
  14137. */
  14138. VirtualRepeatContainerController.prototype.autoShrink_ = function(size) {
  14139. var shrinkSize = Math.max(size, this.autoShrinkMin * this.repeater.getItemSize());
  14140. if (this.autoShrink && shrinkSize !== this.size) {
  14141. if (shrinkSize < (this.originalSize || this.size)) {
  14142. if (!this.originalSize) {
  14143. this.originalSize = this.size;
  14144. }
  14145. this.setSize_(shrinkSize);
  14146. } else if (this.originalSize) {
  14147. this.setSize_(this.originalSize);
  14148. this.originalSize = null;
  14149. }
  14150. }
  14151. };
  14152. /**
  14153. * Sets the scrollHeight or scrollWidth. Called by the repeater based on
  14154. * its item count and item size.
  14155. * @param {number} itemsSize The total size of the items.
  14156. */
  14157. VirtualRepeatContainerController.prototype.setScrollSize = function(itemsSize) {
  14158. var size = itemsSize + this.offsetSize;
  14159. if (this.scrollSize === size) return;
  14160. this.sizeScroller_(size);
  14161. this.autoShrink_(size);
  14162. this.scrollSize = size;
  14163. };
  14164. /** @return {number} The container's current scroll offset. */
  14165. VirtualRepeatContainerController.prototype.getScrollOffset = function() {
  14166. return this.scrollOffset;
  14167. };
  14168. /**
  14169. * Scrolls to a given scrollTop position.
  14170. * @param {number} position
  14171. */
  14172. VirtualRepeatContainerController.prototype.scrollTo = function(position) {
  14173. this.scroller[this.isHorizontal() ? 'scrollLeft' : 'scrollTop'] = position;
  14174. this.handleScroll_();
  14175. };
  14176. /**
  14177. * Scrolls the item with the given index to the top of the scroll container.
  14178. * @param {number} index
  14179. */
  14180. VirtualRepeatContainerController.prototype.scrollToIndex = function(index) {
  14181. var itemSize = this.repeater.getItemSize();
  14182. var itemsLength = this.repeater.itemsLength;
  14183. if(index > itemsLength) {
  14184. index = itemsLength - 1;
  14185. }
  14186. this.scrollTo(itemSize * index);
  14187. };
  14188. VirtualRepeatContainerController.prototype.resetScroll = function() {
  14189. this.scrollTo(0);
  14190. };
  14191. VirtualRepeatContainerController.prototype.handleScroll_ = function() {
  14192. var offset = this.isHorizontal() ? this.scroller.scrollLeft : this.scroller.scrollTop;
  14193. if (offset === this.scrollOffset) return;
  14194. var itemSize = this.repeater.getItemSize();
  14195. if (!itemSize) return;
  14196. var numItems = Math.max(0, Math.floor(offset / itemSize) - NUM_EXTRA);
  14197. var transform = this.isHorizontal() ? 'translateX(' : 'translateY(';
  14198. transform += (numItems * itemSize) + 'px)';
  14199. this.scrollOffset = offset;
  14200. this.offsetter.style.webkitTransform = transform;
  14201. this.offsetter.style.transform = transform;
  14202. if (this.bindTopIndex) {
  14203. var topIndex = Math.floor(offset / itemSize);
  14204. if (topIndex !== this.topIndex && topIndex < this.repeater.itemsLength) {
  14205. this.topIndex = topIndex;
  14206. this.bindTopIndex.assign(this.$scope, topIndex);
  14207. if (!this.$scope.$root.$$phase) this.$scope.$digest();
  14208. }
  14209. }
  14210. this.repeater.containerUpdated();
  14211. };
  14212. /**
  14213. * @ngdoc directive
  14214. * @name mdVirtualRepeat
  14215. * @module material.components.virtualRepeat
  14216. * @restrict A
  14217. * @priority 1000
  14218. * @description
  14219. * `md-virtual-repeat` specifies an element to repeat using virtual scrolling.
  14220. *
  14221. * Virtual repeat is a limited substitute for ng-repeat that renders only
  14222. * enough dom nodes to fill the container and recycling them as the user scrolls.
  14223. * Arrays, but not objects are supported for iteration.
  14224. * Track by, as alias, and (key, value) syntax are not supported.
  14225. *
  14226. * @usage
  14227. * <hljs lang="html">
  14228. * <md-virtual-repeat-container>
  14229. * <div md-virtual-repeat="i in items">Hello {{i}}!</div>
  14230. * </md-virtual-repeat-container>
  14231. *
  14232. * <md-virtual-repeat-container md-orient-horizontal>
  14233. * <div md-virtual-repeat="i in items" md-item-size="20">Hello {{i}}!</div>
  14234. * </md-virtual-repeat-container>
  14235. * </hljs>
  14236. *
  14237. * @param {number=} md-item-size The height or width of the repeated elements (which must be
  14238. * identical for each element). Optional. Will attempt to read the size from the dom if missing,
  14239. * but still assumes that all repeated nodes have same height or width.
  14240. * @param {string=} md-extra-name Evaluates to an additional name to which the current iterated item
  14241. * can be assigned on the repeated scope (needed for use in `md-autocomplete`).
  14242. * @param {boolean=} md-on-demand When present, treats the md-virtual-repeat argument as an object
  14243. * that can fetch rows rather than an array.
  14244. *
  14245. * **NOTE:** This object must implement the following interface with two (2) methods:
  14246. *
  14247. * - `getItemAtIndex: function(index) [object]` The item at that index or null if it is not yet
  14248. * loaded (it should start downloading the item in that case).
  14249. * - `getLength: function() [number]` The data length to which the repeater container
  14250. * should be sized. Ideally, when the count is known, this method should return it.
  14251. * Otherwise, return a higher number than the currently loaded items to produce an
  14252. * infinite-scroll behavior.
  14253. */
  14254. function VirtualRepeatDirective($parse) {
  14255. return {
  14256. controller: VirtualRepeatController,
  14257. priority: 1000,
  14258. require: ['mdVirtualRepeat', '^^mdVirtualRepeatContainer'],
  14259. restrict: 'A',
  14260. terminal: true,
  14261. transclude: 'element',
  14262. compile: function VirtualRepeatCompile($element, $attrs) {
  14263. var expression = $attrs.mdVirtualRepeat;
  14264. var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)\s*$/);
  14265. var repeatName = match[1];
  14266. var repeatListExpression = $parse(match[2]);
  14267. var extraName = $attrs.mdExtraName && $parse($attrs.mdExtraName);
  14268. return function VirtualRepeatLink($scope, $element, $attrs, ctrl, $transclude) {
  14269. ctrl[0].link_(ctrl[1], $transclude, repeatName, repeatListExpression, extraName);
  14270. };
  14271. }
  14272. };
  14273. }
  14274. VirtualRepeatDirective.$inject = ["$parse"];
  14275. /** @ngInject */
  14276. function VirtualRepeatController($scope, $element, $attrs, $browser, $document, $$rAF) {
  14277. this.$scope = $scope;
  14278. this.$element = $element;
  14279. this.$attrs = $attrs;
  14280. this.$browser = $browser;
  14281. this.$document = $document;
  14282. this.$$rAF = $$rAF;
  14283. /** @type {boolean} Whether we are in on-demand mode. */
  14284. this.onDemand = $attrs.hasOwnProperty('mdOnDemand');
  14285. /** @type {!Function} Backup reference to $browser.$$checkUrlChange */
  14286. this.browserCheckUrlChange = $browser.$$checkUrlChange;
  14287. /** @type {number} Most recent starting repeat index (based on scroll offset) */
  14288. this.newStartIndex = 0;
  14289. /** @type {number} Most recent ending repeat index (based on scroll offset) */
  14290. this.newEndIndex = 0;
  14291. /** @type {number} Most recent end visible index (based on scroll offset) */
  14292. this.newVisibleEnd = 0;
  14293. /** @type {number} Previous starting repeat index (based on scroll offset) */
  14294. this.startIndex = 0;
  14295. /** @type {number} Previous ending repeat index (based on scroll offset) */
  14296. this.endIndex = 0;
  14297. // TODO: measure width/height of first element from dom if not provided.
  14298. // getComputedStyle?
  14299. /** @type {?number} Height/width of repeated elements. */
  14300. this.itemSize = $scope.$eval($attrs.mdItemSize) || null;
  14301. /** @type {boolean} Whether this is the first time that items are rendered. */
  14302. this.isFirstRender = true;
  14303. /** @type {number} Most recently seen length of items. */
  14304. this.itemsLength = 0;
  14305. /**
  14306. * @type {!Function} Unwatch callback for item size (when md-items-size is
  14307. * not specified), or angular.noop otherwise.
  14308. */
  14309. this.unwatchItemSize_ = angular.noop;
  14310. /**
  14311. * Presently rendered blocks by repeat index.
  14312. * @type {Object<number, !VirtualRepeatController.Block}
  14313. */
  14314. this.blocks = {};
  14315. /** @type {Array<!VirtualRepeatController.Block>} A pool of presently unused blocks. */
  14316. this.pooledBlocks = [];
  14317. }
  14318. VirtualRepeatController.$inject = ["$scope", "$element", "$attrs", "$browser", "$document", "$$rAF"];
  14319. /**
  14320. * An object representing a repeated item.
  14321. * @typedef {{element: !jqLite, new: boolean, scope: !angular.Scope}}
  14322. */
  14323. VirtualRepeatController.Block;
  14324. /**
  14325. * Called at startup by the md-virtual-repeat postLink function.
  14326. * @param {!VirtualRepeatContainerController} container The container's controller.
  14327. * @param {!Function} transclude The repeated element's bound transclude function.
  14328. * @param {string} repeatName The left hand side of the repeat expression, indicating
  14329. * the name for each item in the array.
  14330. * @param {!Function} repeatListExpression A compiled expression based on the right hand side
  14331. * of the repeat expression. Points to the array to repeat over.
  14332. * @param {string|undefined} extraName The optional extra repeatName.
  14333. */
  14334. VirtualRepeatController.prototype.link_ =
  14335. function(container, transclude, repeatName, repeatListExpression, extraName) {
  14336. this.container = container;
  14337. this.transclude = transclude;
  14338. this.repeatName = repeatName;
  14339. this.rawRepeatListExpression = repeatListExpression;
  14340. this.extraName = extraName;
  14341. this.sized = false;
  14342. this.repeatListExpression = angular.bind(this, this.repeatListExpression_);
  14343. this.container.register(this);
  14344. };
  14345. /** @private Attempts to set itemSize by measuring a repeated element in the dom */
  14346. VirtualRepeatController.prototype.readItemSize_ = function() {
  14347. if (this.itemSize) {
  14348. // itemSize was successfully read in a different asynchronous call.
  14349. return;
  14350. }
  14351. this.items = this.repeatListExpression(this.$scope);
  14352. this.parentNode = this.$element[0].parentNode;
  14353. var block = this.getBlock_(0);
  14354. if (!block.element[0].parentNode) {
  14355. this.parentNode.appendChild(block.element[0]);
  14356. }
  14357. this.itemSize = block.element[0][
  14358. this.container.isHorizontal() ? 'offsetWidth' : 'offsetHeight'] || null;
  14359. this.blocks[0] = block;
  14360. this.poolBlock_(0);
  14361. if (this.itemSize) {
  14362. this.containerUpdated();
  14363. }
  14364. };
  14365. /**
  14366. * Returns the user-specified repeat list, transforming it into an array-like
  14367. * object in the case of infinite scroll/dynamic load mode.
  14368. * @param {!angular.Scope} The scope.
  14369. * @return {!Array|!Object} An array or array-like object for iteration.
  14370. */
  14371. VirtualRepeatController.prototype.repeatListExpression_ = function(scope) {
  14372. var repeatList = this.rawRepeatListExpression(scope);
  14373. if (this.onDemand && repeatList) {
  14374. var virtualList = new VirtualRepeatModelArrayLike(repeatList);
  14375. virtualList.$$includeIndexes(this.newStartIndex, this.newVisibleEnd);
  14376. return virtualList;
  14377. } else {
  14378. return repeatList;
  14379. }
  14380. };
  14381. /**
  14382. * Called by the container. Informs us that the containers scroll or size has
  14383. * changed.
  14384. */
  14385. VirtualRepeatController.prototype.containerUpdated = function() {
  14386. // If itemSize is unknown, attempt to measure it.
  14387. if (!this.itemSize) {
  14388. this.unwatchItemSize_ = this.$scope.$watchCollection(
  14389. this.repeatListExpression,
  14390. angular.bind(this, function(items) {
  14391. if (items && items.length) {
  14392. this.$$rAF(angular.bind(this, this.readItemSize_));
  14393. }
  14394. }));
  14395. if (!this.$scope.$root.$$phase) this.$scope.$digest();
  14396. return;
  14397. } else if (!this.sized) {
  14398. this.items = this.repeatListExpression(this.$scope);
  14399. }
  14400. if (!this.sized) {
  14401. this.unwatchItemSize_();
  14402. this.sized = true;
  14403. this.$scope.$watchCollection(this.repeatListExpression,
  14404. angular.bind(this, this.virtualRepeatUpdate_));
  14405. }
  14406. this.updateIndexes_();
  14407. if (this.newStartIndex !== this.startIndex ||
  14408. this.newEndIndex !== this.endIndex ||
  14409. this.container.getScrollOffset() > this.container.getScrollSize()) {
  14410. if (this.items instanceof VirtualRepeatModelArrayLike) {
  14411. this.items.$$includeIndexes(this.newStartIndex, this.newEndIndex);
  14412. }
  14413. this.virtualRepeatUpdate_(this.items, this.items);
  14414. }
  14415. };
  14416. /**
  14417. * Called by the container. Returns the size of a single repeated item.
  14418. * @return {?number} Size of a repeated item.
  14419. */
  14420. VirtualRepeatController.prototype.getItemSize = function() {
  14421. return this.itemSize;
  14422. };
  14423. /**
  14424. * Updates the order and visible offset of repeated blocks in response to scrolling
  14425. * or items updates.
  14426. * @private
  14427. */
  14428. VirtualRepeatController.prototype.virtualRepeatUpdate_ = function(items, oldItems) {
  14429. var itemsLength = items && items.length || 0;
  14430. var lengthChanged = false;
  14431. // If the number of items shrank, scroll up to the top.
  14432. if (this.items && itemsLength < this.items.length && this.container.getScrollOffset() !== 0) {
  14433. this.items = items;
  14434. this.container.resetScroll();
  14435. return;
  14436. }
  14437. if (itemsLength !== this.itemsLength) {
  14438. lengthChanged = true;
  14439. this.itemsLength = itemsLength;
  14440. }
  14441. this.items = items;
  14442. if (items !== oldItems || lengthChanged) {
  14443. this.updateIndexes_();
  14444. }
  14445. this.parentNode = this.$element[0].parentNode;
  14446. if (lengthChanged) {
  14447. this.container.setScrollSize(itemsLength * this.itemSize);
  14448. }
  14449. if (this.isFirstRender) {
  14450. this.isFirstRender = false;
  14451. var startIndex = this.$attrs.mdStartIndex ?
  14452. this.$scope.$eval(this.$attrs.mdStartIndex) :
  14453. this.container.topIndex;
  14454. this.container.scrollToIndex(startIndex);
  14455. }
  14456. // Detach and pool any blocks that are no longer in the viewport.
  14457. Object.keys(this.blocks).forEach(function(blockIndex) {
  14458. var index = parseInt(blockIndex, 10);
  14459. if (index < this.newStartIndex || index >= this.newEndIndex) {
  14460. this.poolBlock_(index);
  14461. }
  14462. }, this);
  14463. // Add needed blocks.
  14464. // For performance reasons, temporarily block browser url checks as we digest
  14465. // the restored block scopes ($$checkUrlChange reads window.location to
  14466. // check for changes and trigger route change, etc, which we don't need when
  14467. // trying to scroll at 60fps).
  14468. this.$browser.$$checkUrlChange = angular.noop;
  14469. var i, block,
  14470. newStartBlocks = [],
  14471. newEndBlocks = [];
  14472. // Collect blocks at the top.
  14473. for (i = this.newStartIndex; i < this.newEndIndex && this.blocks[i] == null; i++) {
  14474. block = this.getBlock_(i);
  14475. this.updateBlock_(block, i);
  14476. newStartBlocks.push(block);
  14477. }
  14478. // Update blocks that are already rendered.
  14479. for (; this.blocks[i] != null; i++) {
  14480. this.updateBlock_(this.blocks[i], i);
  14481. }
  14482. var maxIndex = i - 1;
  14483. // Collect blocks at the end.
  14484. for (; i < this.newEndIndex; i++) {
  14485. block = this.getBlock_(i);
  14486. this.updateBlock_(block, i);
  14487. newEndBlocks.push(block);
  14488. }
  14489. // Attach collected blocks to the document.
  14490. if (newStartBlocks.length) {
  14491. this.parentNode.insertBefore(
  14492. this.domFragmentFromBlocks_(newStartBlocks),
  14493. this.$element[0].nextSibling);
  14494. }
  14495. if (newEndBlocks.length) {
  14496. this.parentNode.insertBefore(
  14497. this.domFragmentFromBlocks_(newEndBlocks),
  14498. this.blocks[maxIndex] && this.blocks[maxIndex].element[0].nextSibling);
  14499. }
  14500. // Restore $$checkUrlChange.
  14501. this.$browser.$$checkUrlChange = this.browserCheckUrlChange;
  14502. this.startIndex = this.newStartIndex;
  14503. this.endIndex = this.newEndIndex;
  14504. };
  14505. /**
  14506. * @param {number} index Where the block is to be in the repeated list.
  14507. * @return {!VirtualRepeatController.Block} A new or pooled block to place at the specified index.
  14508. * @private
  14509. */
  14510. VirtualRepeatController.prototype.getBlock_ = function(index) {
  14511. if (this.pooledBlocks.length) {
  14512. return this.pooledBlocks.pop();
  14513. }
  14514. var block;
  14515. this.transclude(angular.bind(this, function(clone, scope) {
  14516. block = {
  14517. element: clone,
  14518. new: true,
  14519. scope: scope
  14520. };
  14521. this.updateScope_(scope, index);
  14522. this.parentNode.appendChild(clone[0]);
  14523. }));
  14524. return block;
  14525. };
  14526. /**
  14527. * Updates and if not in a digest cycle, digests the specified block's scope to the data
  14528. * at the specified index.
  14529. * @param {!VirtualRepeatController.Block} block The block whose scope should be updated.
  14530. * @param {number} index The index to set.
  14531. * @private
  14532. */
  14533. VirtualRepeatController.prototype.updateBlock_ = function(block, index) {
  14534. this.blocks[index] = block;
  14535. if (!block.new &&
  14536. (block.scope.$index === index && block.scope[this.repeatName] === this.items[index])) {
  14537. return;
  14538. }
  14539. block.new = false;
  14540. // Update and digest the block's scope.
  14541. this.updateScope_(block.scope, index);
  14542. // Perform digest before reattaching the block.
  14543. // Any resulting synchronous dom mutations should be much faster as a result.
  14544. // This might break some directives, but I'm going to try it for now.
  14545. if (!this.$scope.$root.$$phase) {
  14546. block.scope.$digest();
  14547. }
  14548. };
  14549. /**
  14550. * Updates scope to the data at the specified index.
  14551. * @param {!angular.Scope} scope The scope which should be updated.
  14552. * @param {number} index The index to set.
  14553. * @private
  14554. */
  14555. VirtualRepeatController.prototype.updateScope_ = function(scope, index) {
  14556. scope.$index = index;
  14557. scope[this.repeatName] = this.items && this.items[index];
  14558. if (this.extraName) scope[this.extraName(this.$scope)] = this.items[index];
  14559. };
  14560. /**
  14561. * Pools the block at the specified index (Pulls its element out of the dom and stores it).
  14562. * @param {number} index The index at which the block to pool is stored.
  14563. * @private
  14564. */
  14565. VirtualRepeatController.prototype.poolBlock_ = function(index) {
  14566. this.pooledBlocks.push(this.blocks[index]);
  14567. this.parentNode.removeChild(this.blocks[index].element[0]);
  14568. delete this.blocks[index];
  14569. };
  14570. /**
  14571. * Produces a dom fragment containing the elements from the list of blocks.
  14572. * @param {!Array<!VirtualRepeatController.Block>} blocks The blocks whose elements
  14573. * should be added to the document fragment.
  14574. * @return {DocumentFragment}
  14575. * @private
  14576. */
  14577. VirtualRepeatController.prototype.domFragmentFromBlocks_ = function(blocks) {
  14578. var fragment = this.$document[0].createDocumentFragment();
  14579. blocks.forEach(function(block) {
  14580. fragment.appendChild(block.element[0]);
  14581. });
  14582. return fragment;
  14583. };
  14584. /**
  14585. * Updates start and end indexes based on length of repeated items and container size.
  14586. * @private
  14587. */
  14588. VirtualRepeatController.prototype.updateIndexes_ = function() {
  14589. var itemsLength = this.items ? this.items.length : 0;
  14590. var containerLength = Math.ceil(this.container.getSize() / this.itemSize);
  14591. this.newStartIndex = Math.max(0, Math.min(
  14592. itemsLength - containerLength,
  14593. Math.floor(this.container.getScrollOffset() / this.itemSize)));
  14594. this.newVisibleEnd = this.newStartIndex + containerLength + NUM_EXTRA;
  14595. this.newEndIndex = Math.min(itemsLength, this.newVisibleEnd);
  14596. this.newStartIndex = Math.max(0, this.newStartIndex - NUM_EXTRA);
  14597. };
  14598. /**
  14599. * This VirtualRepeatModelArrayLike class enforces the interface requirements
  14600. * for infinite scrolling within a mdVirtualRepeatContainer. An object with this
  14601. * interface must implement the following interface with two (2) methods:
  14602. *
  14603. * getItemAtIndex: function(index) -> item at that index or null if it is not yet
  14604. * loaded (It should start downloading the item in that case).
  14605. *
  14606. * getLength: function() -> number The data legnth to which the repeater container
  14607. * should be sized. Ideally, when the count is known, this method should return it.
  14608. * Otherwise, return a higher number than the currently loaded items to produce an
  14609. * infinite-scroll behavior.
  14610. *
  14611. * @usage
  14612. * <hljs lang="html">
  14613. * <md-virtual-repeat-container md-orient-horizontal>
  14614. * <div md-virtual-repeat="i in items" md-on-demand>
  14615. * Hello {{i}}!
  14616. * </div>
  14617. * </md-virtual-repeat-container>
  14618. * </hljs>
  14619. *
  14620. */
  14621. function VirtualRepeatModelArrayLike(model) {
  14622. if (!angular.isFunction(model.getItemAtIndex) ||
  14623. !angular.isFunction(model.getLength)) {
  14624. throw Error('When md-on-demand is enabled, the Object passed to md-virtual-repeat must implement ' +
  14625. 'functions getItemAtIndex() and getLength() ');
  14626. }
  14627. this.model = model;
  14628. }
  14629. VirtualRepeatModelArrayLike.prototype.$$includeIndexes = function(start, end) {
  14630. for (var i = start; i < end; i++) {
  14631. if (!this.hasOwnProperty(i)) {
  14632. this[i] = this.model.getItemAtIndex(i);
  14633. }
  14634. }
  14635. this.length = this.model.getLength();
  14636. };
  14637. function abstractMethod() {
  14638. throw Error('Non-overridden abstract method called.');
  14639. }
  14640. })();
  14641. (function(){
  14642. "use strict";
  14643. /**
  14644. * @ngdoc module
  14645. * @name material.components.whiteframe
  14646. */
  14647. angular.module('material.components.whiteframe', []);
  14648. })();
  14649. (function(){
  14650. "use strict";
  14651. angular
  14652. .module('material.components.autocomplete')
  14653. .controller('MdAutocompleteCtrl', MdAutocompleteCtrl);
  14654. var ITEM_HEIGHT = 41,
  14655. MAX_HEIGHT = 5.5 * ITEM_HEIGHT,
  14656. MENU_PADDING = 8;
  14657. function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming, $window,
  14658. $animate, $rootElement, $attrs, $q) {
  14659. //-- private variables
  14660. var ctrl = this,
  14661. itemParts = $scope.itemsExpr.split(/ in /i),
  14662. itemExpr = itemParts[ 1 ],
  14663. elements = null,
  14664. cache = {},
  14665. noBlur = false,
  14666. selectedItemWatchers = [],
  14667. hasFocus = false,
  14668. lastCount = 0;
  14669. //-- public variables with handlers
  14670. defineProperty('hidden', handleHiddenChange, true);
  14671. //-- public variables
  14672. ctrl.scope = $scope;
  14673. ctrl.parent = $scope.$parent;
  14674. ctrl.itemName = itemParts[ 0 ];
  14675. ctrl.matches = [];
  14676. ctrl.loading = false;
  14677. ctrl.hidden = true;
  14678. ctrl.index = null;
  14679. ctrl.messages = [];
  14680. ctrl.id = $mdUtil.nextUid();
  14681. ctrl.isDisabled = null;
  14682. ctrl.isRequired = null;
  14683. ctrl.hasNotFound = false;
  14684. //-- public methods
  14685. ctrl.keydown = keydown;
  14686. ctrl.blur = blur;
  14687. ctrl.focus = focus;
  14688. ctrl.clear = clearValue;
  14689. ctrl.select = select;
  14690. ctrl.listEnter = onListEnter;
  14691. ctrl.listLeave = onListLeave;
  14692. ctrl.mouseUp = onMouseup;
  14693. ctrl.getCurrentDisplayValue = getCurrentDisplayValue;
  14694. ctrl.registerSelectedItemWatcher = registerSelectedItemWatcher;
  14695. ctrl.unregisterSelectedItemWatcher = unregisterSelectedItemWatcher;
  14696. ctrl.notFoundVisible = notFoundVisible;
  14697. ctrl.loadingIsVisible = loadingIsVisible;
  14698. return init();
  14699. //-- initialization methods
  14700. /**
  14701. * Initialize the controller, setup watchers, gather elements
  14702. */
  14703. function init () {
  14704. $mdUtil.initOptionalProperties($scope, $attrs, { searchText: null, selectedItem: null });
  14705. $mdTheming($element);
  14706. configureWatchers();
  14707. $mdUtil.nextTick(function () {
  14708. gatherElements();
  14709. moveDropdown();
  14710. focusElement();
  14711. $element.on('focus', focusElement);
  14712. });
  14713. }
  14714. /**
  14715. * Calculates the dropdown's position and applies the new styles to the menu element
  14716. * @returns {*}
  14717. */
  14718. function positionDropdown () {
  14719. if (!elements) return $mdUtil.nextTick(positionDropdown, false, $scope);
  14720. var hrect = elements.wrap.getBoundingClientRect(),
  14721. vrect = elements.snap.getBoundingClientRect(),
  14722. root = elements.root.getBoundingClientRect(),
  14723. top = vrect.bottom - root.top,
  14724. bot = root.bottom - vrect.top,
  14725. left = hrect.left - root.left,
  14726. width = hrect.width,
  14727. styles = {
  14728. left: left + 'px',
  14729. minWidth: width + 'px',
  14730. maxWidth: Math.max(hrect.right - root.left, root.right - hrect.left) - MENU_PADDING + 'px'
  14731. };
  14732. if (top > bot && root.height - hrect.bottom - MENU_PADDING < MAX_HEIGHT) {
  14733. styles.top = 'auto';
  14734. styles.bottom = bot + 'px';
  14735. styles.maxHeight = Math.min(MAX_HEIGHT, hrect.top - root.top - MENU_PADDING) + 'px';
  14736. } else {
  14737. styles.top = top + 'px';
  14738. styles.bottom = 'auto';
  14739. styles.maxHeight = Math.min(MAX_HEIGHT, root.bottom - hrect.bottom - MENU_PADDING) + 'px';
  14740. }
  14741. elements.$.scrollContainer.css(styles);
  14742. $mdUtil.nextTick(correctHorizontalAlignment, false);
  14743. /**
  14744. * Makes sure that the menu doesn't go off of the screen on either side.
  14745. */
  14746. function correctHorizontalAlignment () {
  14747. var dropdown = elements.scrollContainer.getBoundingClientRect(),
  14748. styles = {};
  14749. if (dropdown.right > root.right - MENU_PADDING) {
  14750. styles.left = (hrect.right - dropdown.width) + 'px';
  14751. }
  14752. elements.$.scrollContainer.css(styles);
  14753. }
  14754. }
  14755. /**
  14756. * Moves the dropdown menu to the body tag in order to avoid z-index and overflow issues.
  14757. */
  14758. function moveDropdown () {
  14759. if (!elements.$.root.length) return;
  14760. $mdTheming(elements.$.scrollContainer);
  14761. elements.$.scrollContainer.detach();
  14762. elements.$.root.append(elements.$.scrollContainer);
  14763. if ($animate.pin) $animate.pin(elements.$.scrollContainer, $rootElement);
  14764. }
  14765. /**
  14766. * Sends focus to the input element.
  14767. */
  14768. function focusElement () {
  14769. if ($scope.autofocus) elements.input.focus();
  14770. }
  14771. /**
  14772. * Sets up any watchers used by autocomplete
  14773. */
  14774. function configureWatchers () {
  14775. var wait = parseInt($scope.delay, 10) || 0;
  14776. $attrs.$observe('disabled', function (value) { ctrl.isDisabled = value; });
  14777. $attrs.$observe('required', function (value) { ctrl.isRequired = value !== null; });
  14778. $scope.$watch('searchText', wait ? $mdUtil.debounce(handleSearchText, wait) : handleSearchText);
  14779. $scope.$watch('selectedItem', selectedItemChange);
  14780. angular.element($window).on('resize', positionDropdown);
  14781. $scope.$on('$destroy', cleanup);
  14782. }
  14783. /**
  14784. * Removes any events or leftover elements created by this controller
  14785. */
  14786. function cleanup () {
  14787. angular.element($window).off('resize', positionDropdown);
  14788. if ( elements ){
  14789. var items = 'ul scroller scrollContainer input'.split(' ');
  14790. angular.forEach(items, function(key){
  14791. elements.$[key].remove();
  14792. });
  14793. }
  14794. }
  14795. /**
  14796. * Gathers all of the elements needed for this controller
  14797. */
  14798. function gatherElements () {
  14799. elements = {
  14800. main: $element[0],
  14801. scrollContainer: $element[0].getElementsByClassName('md-virtual-repeat-container')[0],
  14802. scroller: $element[0].getElementsByClassName('md-virtual-repeat-scroller')[0],
  14803. ul: $element.find('ul')[0],
  14804. input: $element.find('input')[0],
  14805. wrap: $element.find('md-autocomplete-wrap')[0],
  14806. root: document.body
  14807. };
  14808. elements.li = elements.ul.getElementsByTagName('li');
  14809. elements.snap = getSnapTarget();
  14810. elements.$ = getAngularElements(elements);
  14811. }
  14812. /**
  14813. * Finds the element that the menu will base its position on
  14814. * @returns {*}
  14815. */
  14816. function getSnapTarget () {
  14817. for (var element = $element; element.length; element = element.parent()) {
  14818. if (angular.isDefined(element.attr('md-autocomplete-snap'))) return element[ 0 ];
  14819. }
  14820. return elements.wrap;
  14821. }
  14822. /**
  14823. * Gathers angular-wrapped versions of each element
  14824. * @param elements
  14825. * @returns {{}}
  14826. */
  14827. function getAngularElements (elements) {
  14828. var obj = {};
  14829. for (var key in elements) {
  14830. if (elements.hasOwnProperty(key)) obj[ key ] = angular.element(elements[ key ]);
  14831. }
  14832. return obj;
  14833. }
  14834. //-- event/change handlers
  14835. /**
  14836. * Handles changes to the `hidden` property.
  14837. * @param hidden
  14838. * @param oldHidden
  14839. */
  14840. function handleHiddenChange (hidden, oldHidden) {
  14841. if (!hidden && oldHidden) {
  14842. positionDropdown();
  14843. if (elements) {
  14844. $mdUtil.nextTick(function () {
  14845. $mdUtil.disableScrollAround(elements.ul);
  14846. }, false, $scope);
  14847. }
  14848. } else if (hidden && !oldHidden) {
  14849. $mdUtil.nextTick(function () {
  14850. $mdUtil.enableScrolling();
  14851. }, false, $scope);
  14852. }
  14853. }
  14854. /**
  14855. * When the user mouses over the dropdown menu, ignore blur events.
  14856. */
  14857. function onListEnter () {
  14858. noBlur = true;
  14859. }
  14860. /**
  14861. * When the user's mouse leaves the menu, blur events may hide the menu again.
  14862. */
  14863. function onListLeave () {
  14864. noBlur = false;
  14865. ctrl.hidden = shouldHide();
  14866. }
  14867. /**
  14868. * When the mouse button is released, send focus back to the input field.
  14869. */
  14870. function onMouseup () {
  14871. elements.input.focus();
  14872. }
  14873. /**
  14874. * Handles changes to the selected item.
  14875. * @param selectedItem
  14876. * @param previousSelectedItem
  14877. */
  14878. function selectedItemChange (selectedItem, previousSelectedItem) {
  14879. if (selectedItem) {
  14880. getDisplayValue(selectedItem).then(function (val) {
  14881. $scope.searchText = val;
  14882. handleSelectedItemChange(selectedItem, previousSelectedItem);
  14883. });
  14884. }
  14885. if (selectedItem !== previousSelectedItem) announceItemChange();
  14886. }
  14887. /**
  14888. * Use the user-defined expression to announce changes each time a new item is selected
  14889. */
  14890. function announceItemChange () {
  14891. angular.isFunction($scope.itemChange) && $scope.itemChange(getItemAsNameVal($scope.selectedItem));
  14892. }
  14893. /**
  14894. * Use the user-defined expression to announce changes each time the search text is changed
  14895. */
  14896. function announceTextChange () {
  14897. angular.isFunction($scope.textChange) && $scope.textChange();
  14898. }
  14899. /**
  14900. * Calls any external watchers listening for the selected item. Used in conjunction with
  14901. * `registerSelectedItemWatcher`.
  14902. * @param selectedItem
  14903. * @param previousSelectedItem
  14904. */
  14905. function handleSelectedItemChange (selectedItem, previousSelectedItem) {
  14906. selectedItemWatchers.forEach(function (watcher) { watcher(selectedItem, previousSelectedItem); });
  14907. }
  14908. /**
  14909. * Register a function to be called when the selected item changes.
  14910. * @param cb
  14911. */
  14912. function registerSelectedItemWatcher (cb) {
  14913. if (selectedItemWatchers.indexOf(cb) == -1) {
  14914. selectedItemWatchers.push(cb);
  14915. }
  14916. }
  14917. /**
  14918. * Unregister a function previously registered for selected item changes.
  14919. * @param cb
  14920. */
  14921. function unregisterSelectedItemWatcher (cb) {
  14922. var i = selectedItemWatchers.indexOf(cb);
  14923. if (i != -1) {
  14924. selectedItemWatchers.splice(i, 1);
  14925. }
  14926. }
  14927. /**
  14928. * Handles changes to the searchText property.
  14929. * @param searchText
  14930. * @param previousSearchText
  14931. */
  14932. function handleSearchText (searchText, previousSearchText) {
  14933. ctrl.index = getDefaultIndex();
  14934. // do nothing on init
  14935. if (searchText === previousSearchText) return;
  14936. getDisplayValue($scope.selectedItem).then(function (val) {
  14937. // clear selected item if search text no longer matches it
  14938. if (searchText !== val) {
  14939. $scope.selectedItem = null;
  14940. // trigger change event if available
  14941. if (searchText !== previousSearchText) announceTextChange();
  14942. // cancel results if search text is not long enough
  14943. if (!isMinLengthMet()) {
  14944. ctrl.matches = [];
  14945. setLoading(false);
  14946. updateMessages();
  14947. } else {
  14948. handleQuery();
  14949. }
  14950. }
  14951. });
  14952. }
  14953. /**
  14954. * Handles input blur event, determines if the dropdown should hide.
  14955. */
  14956. function blur () {
  14957. if (!noBlur) {
  14958. hasFocus = false;
  14959. ctrl.hidden = shouldHide();
  14960. }
  14961. }
  14962. function doBlur(forceBlur) {
  14963. if (forceBlur) {
  14964. noBlur = false;
  14965. }
  14966. elements.input.blur();
  14967. }
  14968. /**
  14969. * Handles input focus event, determines if the dropdown should show.
  14970. */
  14971. function focus () {
  14972. hasFocus = true;
  14973. //-- if searchText is null, let's force it to be a string
  14974. if (!angular.isString($scope.searchText)) $scope.searchText = '';
  14975. ctrl.hidden = shouldHide();
  14976. if (!ctrl.hidden) handleQuery();
  14977. }
  14978. /**
  14979. * Handles keyboard input.
  14980. * @param event
  14981. */
  14982. function keydown (event) {
  14983. switch (event.keyCode) {
  14984. case $mdConstant.KEY_CODE.DOWN_ARROW:
  14985. if (ctrl.loading) return;
  14986. event.stopPropagation();
  14987. event.preventDefault();
  14988. ctrl.index = Math.min(ctrl.index + 1, ctrl.matches.length - 1);
  14989. updateScroll();
  14990. updateMessages();
  14991. break;
  14992. case $mdConstant.KEY_CODE.UP_ARROW:
  14993. if (ctrl.loading) return;
  14994. event.stopPropagation();
  14995. event.preventDefault();
  14996. ctrl.index = ctrl.index < 0 ? ctrl.matches.length - 1 : Math.max(0, ctrl.index - 1);
  14997. updateScroll();
  14998. updateMessages();
  14999. break;
  15000. case $mdConstant.KEY_CODE.TAB:
  15001. case $mdConstant.KEY_CODE.ENTER:
  15002. if (ctrl.hidden || ctrl.loading || ctrl.index < 0 || ctrl.matches.length < 1) return;
  15003. event.stopPropagation();
  15004. event.preventDefault();
  15005. select(ctrl.index);
  15006. break;
  15007. case $mdConstant.KEY_CODE.ESCAPE:
  15008. event.stopPropagation();
  15009. event.preventDefault();
  15010. clearValue();
  15011. // Force the component to blur if they hit escape
  15012. doBlur(true);
  15013. break;
  15014. default:
  15015. }
  15016. }
  15017. //-- getters
  15018. /**
  15019. * Returns the minimum length needed to display the dropdown.
  15020. * @returns {*}
  15021. */
  15022. function getMinLength () {
  15023. return angular.isNumber($scope.minLength) ? $scope.minLength : 1;
  15024. }
  15025. /**
  15026. * Returns the display value for an item.
  15027. * @param item
  15028. * @returns {*}
  15029. */
  15030. function getDisplayValue (item) {
  15031. return $q.when(getItemText(item) || item);
  15032. /**
  15033. * Getter function to invoke user-defined expression (in the directive)
  15034. * to convert your object to a single string.
  15035. */
  15036. function getItemText (item) {
  15037. return (item && $scope.itemText) ? $scope.itemText(getItemAsNameVal(item)) : null;
  15038. }
  15039. }
  15040. /**
  15041. * Returns the locals object for compiling item templates.
  15042. * @param item
  15043. * @returns {{}}
  15044. */
  15045. function getItemAsNameVal (item) {
  15046. if (!item) return undefined;
  15047. var locals = {};
  15048. if (ctrl.itemName) locals[ ctrl.itemName ] = item;
  15049. return locals;
  15050. }
  15051. /**
  15052. * Returns the default index based on whether or not autoselect is enabled.
  15053. * @returns {number}
  15054. */
  15055. function getDefaultIndex () {
  15056. return $scope.autoselect ? 0 : -1;
  15057. }
  15058. /**
  15059. * Sets the loading parameter and updates the hidden state.
  15060. * @param value {boolean} Whether or not the component is currently loading.
  15061. */
  15062. function setLoading(value) {
  15063. if (ctrl.loading != value) {
  15064. ctrl.loading = value;
  15065. }
  15066. // Always refresh the hidden variable as something else might have changed
  15067. ctrl.hidden = shouldHide();
  15068. }
  15069. /**
  15070. * Determines if the menu should be hidden.
  15071. * @returns {boolean}
  15072. */
  15073. function shouldHide () {
  15074. if ((ctrl.loading && !hasMatches()) || hasSelection() || !hasFocus) {
  15075. return true;
  15076. }
  15077. return !shouldShow();
  15078. }
  15079. /**
  15080. * Determines if the menu should be shown.
  15081. * @returns {boolean}
  15082. */
  15083. function shouldShow() {
  15084. return (isMinLengthMet() && hasMatches()) || notFoundVisible();
  15085. }
  15086. /**
  15087. * Returns true if the search text has matches.
  15088. * @returns {boolean}
  15089. */
  15090. function hasMatches() {
  15091. return ctrl.matches.length ? true : false;
  15092. }
  15093. /**
  15094. * Returns true if the autocomplete has a valid selection.
  15095. * @returns {boolean}
  15096. */
  15097. function hasSelection() {
  15098. return ctrl.scope.selectedItem ? true : false;
  15099. }
  15100. /**
  15101. * Returns true if the loading indicator is, or should be, visible.
  15102. * @returns {boolean}
  15103. */
  15104. function loadingIsVisible() {
  15105. return ctrl.loading && !hasSelection();
  15106. }
  15107. /**
  15108. * Returns the display value of the current item.
  15109. * @returns {*}
  15110. */
  15111. function getCurrentDisplayValue () {
  15112. return getDisplayValue(ctrl.matches[ ctrl.index ]);
  15113. }
  15114. /**
  15115. * Determines if the minimum length is met by the search text.
  15116. * @returns {*}
  15117. */
  15118. function isMinLengthMet () {
  15119. return ($scope.searchText || '').length >= getMinLength();
  15120. }
  15121. //-- actions
  15122. /**
  15123. * Defines a public property with a handler and a default value.
  15124. * @param key
  15125. * @param handler
  15126. * @param value
  15127. */
  15128. function defineProperty (key, handler, value) {
  15129. Object.defineProperty(ctrl, key, {
  15130. get: function () { return value; },
  15131. set: function (newValue) {
  15132. var oldValue = value;
  15133. value = newValue;
  15134. handler(newValue, oldValue);
  15135. }
  15136. });
  15137. }
  15138. /**
  15139. * Selects the item at the given index.
  15140. * @param index
  15141. */
  15142. function select (index) {
  15143. //-- force form to update state for validation
  15144. $mdUtil.nextTick(function () {
  15145. getDisplayValue(ctrl.matches[ index ]).then(function (val) {
  15146. var ngModel = elements.$.input.controller('ngModel');
  15147. ngModel.$setViewValue(val);
  15148. ngModel.$render();
  15149. }).finally(function () {
  15150. $scope.selectedItem = ctrl.matches[ index ];
  15151. setLoading(false);
  15152. });
  15153. }, false);
  15154. }
  15155. /**
  15156. * Clears the searchText value and selected item.
  15157. */
  15158. function clearValue () {
  15159. // Set the loading to true so we don't see flashes of content
  15160. setLoading(true);
  15161. // Reset our variables
  15162. ctrl.index = 0;
  15163. ctrl.matches = [];
  15164. $scope.searchText = '';
  15165. // Tell the select to fire and select nothing
  15166. select(-1);
  15167. // Per http://www.w3schools.com/jsref/event_oninput.asp
  15168. var eventObj = document.createEvent('CustomEvent');
  15169. eventObj.initCustomEvent('input', true, true, { value: $scope.searchText });
  15170. elements.input.dispatchEvent(eventObj);
  15171. elements.input.focus();
  15172. }
  15173. /**
  15174. * Fetches the results for the provided search text.
  15175. * @param searchText
  15176. */
  15177. function fetchResults (searchText) {
  15178. var items = $scope.$parent.$eval(itemExpr),
  15179. term = searchText.toLowerCase();
  15180. if (angular.isArray(items)) {
  15181. handleResults(items);
  15182. } else if (items) {
  15183. setLoading(true);
  15184. $mdUtil.nextTick(function () {
  15185. if (items.success) items.success(handleResults);
  15186. if (items.then) items.then(handleResults);
  15187. if (items.finally) items.finally(function () {
  15188. setLoading(false);
  15189. });
  15190. },true, $scope);
  15191. }
  15192. function handleResults (matches) {
  15193. cache[ term ] = matches;
  15194. if ((searchText || '') !== ($scope.searchText || '')) return; //-- just cache the results if old request
  15195. ctrl.matches = matches;
  15196. ctrl.hidden = shouldHide();
  15197. if ($scope.selectOnMatch) selectItemOnMatch();
  15198. updateMessages();
  15199. positionDropdown();
  15200. }
  15201. }
  15202. /**
  15203. * Updates the ARIA messages
  15204. */
  15205. function updateMessages () {
  15206. getCurrentDisplayValue().then(function (msg) {
  15207. ctrl.messages = [ getCountMessage(), msg ];
  15208. });
  15209. }
  15210. /**
  15211. * Returns the ARIA message for how many results match the current query.
  15212. * @returns {*}
  15213. */
  15214. function getCountMessage () {
  15215. if (lastCount === ctrl.matches.length) return '';
  15216. lastCount = ctrl.matches.length;
  15217. switch (ctrl.matches.length) {
  15218. case 0:
  15219. return 'There are no matches available.';
  15220. case 1:
  15221. return 'There is 1 match available.';
  15222. default:
  15223. return 'There are ' + ctrl.matches.length + ' matches available.';
  15224. }
  15225. }
  15226. /**
  15227. * Makes sure that the focused element is within view.
  15228. */
  15229. function updateScroll () {
  15230. if (!elements.li[0]) return;
  15231. var height = elements.li[0].offsetHeight,
  15232. top = height * ctrl.index,
  15233. bot = top + height,
  15234. hgt = elements.scroller.clientHeight,
  15235. scrollTop = elements.scroller.scrollTop;
  15236. if (top < scrollTop) {
  15237. scrollTo(top);
  15238. } else if (bot > scrollTop + hgt) {
  15239. scrollTo(bot - hgt);
  15240. }
  15241. }
  15242. function scrollTo (offset) {
  15243. elements.$.scrollContainer.controller('mdVirtualRepeatContainer').scrollTo(offset);
  15244. }
  15245. function notFoundVisible () {
  15246. var textLength = (ctrl.scope.searchText || '').length;
  15247. return ctrl.hasNotFound && !hasMatches() && !ctrl.loading && textLength >= getMinLength() && hasFocus && !hasSelection();
  15248. }
  15249. /**
  15250. * Starts the query to gather the results for the current searchText. Attempts to return cached
  15251. * results first, then forwards the process to `fetchResults` if necessary.
  15252. */
  15253. function handleQuery () {
  15254. var searchText = $scope.searchText,
  15255. term = searchText.toLowerCase();
  15256. //-- if results are cached, pull in cached results
  15257. if (!$scope.noCache && cache[ term ]) {
  15258. ctrl.matches = cache[ term ];
  15259. updateMessages();
  15260. } else {
  15261. fetchResults(searchText);
  15262. }
  15263. ctrl.hidden = shouldHide();
  15264. }
  15265. /**
  15266. * If there is only one matching item and the search text matches its display value exactly,
  15267. * automatically select that item. Note: This function is only called if the user uses the
  15268. * `md-select-on-match` flag.
  15269. */
  15270. function selectItemOnMatch () {
  15271. var searchText = $scope.searchText,
  15272. matches = ctrl.matches,
  15273. item = matches[ 0 ];
  15274. if (matches.length === 1) getDisplayValue(item).then(function (displayValue) {
  15275. if (searchText == displayValue) select(0);
  15276. });
  15277. }
  15278. }
  15279. MdAutocompleteCtrl.$inject = ["$scope", "$element", "$mdUtil", "$mdConstant", "$mdTheming", "$window", "$animate", "$rootElement", "$attrs", "$q"];
  15280. })();
  15281. (function(){
  15282. "use strict";
  15283. angular
  15284. .module('material.components.autocomplete')
  15285. .directive('mdAutocomplete', MdAutocomplete);
  15286. /**
  15287. * @ngdoc directive
  15288. * @name mdAutocomplete
  15289. * @module material.components.autocomplete
  15290. *
  15291. * @description
  15292. * `<md-autocomplete>` is a special input component with a drop-down of all possible matches to a
  15293. * custom query. This component allows you to provide real-time suggestions as the user types
  15294. * in the input area.
  15295. *
  15296. * To start, you will need to specify the required parameters and provide a template for your
  15297. * results. The content inside `md-autocomplete` will be treated as a template.
  15298. *
  15299. * In more complex cases, you may want to include other content such as a message to display when
  15300. * no matches were found. You can do this by wrapping your template in `md-item-template` and
  15301. * adding a tag for `md-not-found`. An example of this is shown below.
  15302. *
  15303. * ### Validation
  15304. *
  15305. * You can use `ng-messages` to include validation the same way that you would normally validate;
  15306. * however, if you want to replicate a standard input with a floating label, you will have to
  15307. * do the following:
  15308. *
  15309. * - Make sure that your template is wrapped in `md-item-template`
  15310. * - Add your `ng-messages` code inside of `md-autocomplete`
  15311. * - Add your validation properties to `md-autocomplete` (ie. `required`)
  15312. * - Add a `name` to `md-autocomplete` (to be used on the generated `input`)
  15313. *
  15314. * There is an example below of how this should look.
  15315. *
  15316. *
  15317. * @param {expression} md-items An expression in the format of `item in items` to iterate over
  15318. * matches for your search.
  15319. * @param {expression=} md-selected-item-change An expression to be run each time a new item is
  15320. * selected
  15321. * @param {expression=} md-search-text-change An expression to be run each time the search text
  15322. * updates
  15323. * @param {expression=} md-search-text A model to bind the search query text to
  15324. * @param {object=} md-selected-item A model to bind the selected item to
  15325. * @param {expression=} md-item-text An expression that will convert your object to a single string.
  15326. * @param {string=} placeholder Placeholder text that will be forwarded to the input.
  15327. * @param {boolean=} md-no-cache Disables the internal caching that happens in autocomplete
  15328. * @param {boolean=} ng-disabled Determines whether or not to disable the input field
  15329. * @param {number=} md-min-length Specifies the minimum length of text before autocomplete will
  15330. * make suggestions
  15331. * @param {number=} md-delay Specifies the amount of time (in milliseconds) to wait before looking
  15332. * for results
  15333. * @param {boolean=} md-autofocus If true, will immediately focus the input element
  15334. * @param {boolean=} md-autoselect If true, the first item will be selected by default
  15335. * @param {string=} md-menu-class This will be applied to the dropdown menu for styling
  15336. * @param {string=} md-floating-label This will add a floating label to autocomplete and wrap it in
  15337. * `md-input-container`
  15338. * @param {string=} md-input-name The name attribute given to the input element to be used with
  15339. * FormController
  15340. * @param {string=} md-input-id An ID to be added to the input element
  15341. * @param {number=} md-input-minlength The minimum length for the input's value for validation
  15342. * @param {number=} md-input-maxlength The maximum length for the input's value for validation
  15343. * @param {boolean=} md-select-on-match When set, autocomplete will automatically select exact
  15344. * the item if the search text is an exact match
  15345. *
  15346. * @usage
  15347. * ### Basic Example
  15348. * <hljs lang="html">
  15349. * <md-autocomplete
  15350. * md-selected-item="selectedItem"
  15351. * md-search-text="searchText"
  15352. * md-items="item in getMatches(searchText)"
  15353. * md-item-text="item.display">
  15354. * <span md-highlight-text="searchText">{{item.display}}</span>
  15355. * </md-autocomplete>
  15356. * </hljs>
  15357. *
  15358. * ### Example with "not found" message
  15359. * <hljs lang="html">
  15360. * <md-autocomplete
  15361. * md-selected-item="selectedItem"
  15362. * md-search-text="searchText"
  15363. * md-items="item in getMatches(searchText)"
  15364. * md-item-text="item.display">
  15365. * <md-item-template>
  15366. * <span md-highlight-text="searchText">{{item.display}}</span>
  15367. * </md-item-template>
  15368. * <md-not-found>
  15369. * No matches found.
  15370. * </md-not-found>
  15371. * </md-autocomplete>
  15372. * </hljs>
  15373. *
  15374. * In this example, our code utilizes `md-item-template` and `md-not-found` to specify the
  15375. * different parts that make up our component.
  15376. *
  15377. * ### Example with validation
  15378. * <hljs lang="html">
  15379. * <form name="autocompleteForm">
  15380. * <md-autocomplete
  15381. * required
  15382. * md-input-name="autocomplete"
  15383. * md-selected-item="selectedItem"
  15384. * md-search-text="searchText"
  15385. * md-items="item in getMatches(searchText)"
  15386. * md-item-text="item.display">
  15387. * <md-item-template>
  15388. * <span md-highlight-text="searchText">{{item.display}}</span>
  15389. * </md-item-template>
  15390. * <div ng-messages="autocompleteForm.autocomplete.$error">
  15391. * <div ng-message="required">This field is required</div>
  15392. * </div>
  15393. * </md-autocomplete>
  15394. * </form>
  15395. * </hljs>
  15396. *
  15397. * In this example, our code utilizes `md-item-template` and `md-not-found` to specify the
  15398. * different parts that make up our component.
  15399. */
  15400. function MdAutocomplete () {
  15401. var hasNotFoundTemplate = false;
  15402. return {
  15403. controller: 'MdAutocompleteCtrl',
  15404. controllerAs: '$mdAutocompleteCtrl',
  15405. scope: {
  15406. inputName: '@mdInputName',
  15407. inputMinlength: '@mdInputMinlength',
  15408. inputMaxlength: '@mdInputMaxlength',
  15409. searchText: '=?mdSearchText',
  15410. selectedItem: '=?mdSelectedItem',
  15411. itemsExpr: '@mdItems',
  15412. itemText: '&mdItemText',
  15413. placeholder: '@placeholder',
  15414. noCache: '=?mdNoCache',
  15415. selectOnMatch: '=?mdSelectOnMatch',
  15416. itemChange: '&?mdSelectedItemChange',
  15417. textChange: '&?mdSearchTextChange',
  15418. minLength: '=?mdMinLength',
  15419. delay: '=?mdDelay',
  15420. autofocus: '=?mdAutofocus',
  15421. floatingLabel: '@?mdFloatingLabel',
  15422. autoselect: '=?mdAutoselect',
  15423. menuClass: '@?mdMenuClass',
  15424. inputId: '@?mdInputId'
  15425. },
  15426. link: function(scope, element, attrs, controller) {
  15427. controller.hasNotFound = hasNotFoundTemplate;
  15428. },
  15429. template: function (element, attr) {
  15430. var noItemsTemplate = getNoItemsTemplate(),
  15431. itemTemplate = getItemTemplate(),
  15432. leftover = element.html(),
  15433. tabindex = attr.tabindex;
  15434. if (noItemsTemplate) {
  15435. hasNotFoundTemplate = true;
  15436. }
  15437. if (attr.hasOwnProperty('tabindex')) {
  15438. element.attr('tabindex', '-1');
  15439. }
  15440. return '\
  15441. <md-autocomplete-wrap\
  15442. layout="row"\
  15443. ng-class="{ \'md-whiteframe-z1\': !floatingLabel, \'md-menu-showing\': !$mdAutocompleteCtrl.hidden }"\
  15444. role="listbox">\
  15445. ' + getInputElement() + '\
  15446. <md-progress-linear\
  15447. ng-if="$mdAutocompleteCtrl.loadingIsVisible()"\
  15448. md-mode="indeterminate"></md-progress-linear>\
  15449. <md-virtual-repeat-container\
  15450. md-auto-shrink\
  15451. md-auto-shrink-min="1"\
  15452. ng-hide="$mdAutocompleteCtrl.hidden"\
  15453. class="md-autocomplete-suggestions-container md-whiteframe-z1"\
  15454. role="presentation">\
  15455. <ul class="md-autocomplete-suggestions"\
  15456. ng-class="::menuClass"\
  15457. id="ul-{{$mdAutocompleteCtrl.id}}"\
  15458. ng-mouseenter="$mdAutocompleteCtrl.listEnter()"\
  15459. ng-mouseleave="$mdAutocompleteCtrl.listLeave()"\
  15460. ng-mouseup="$mdAutocompleteCtrl.mouseUp()">\
  15461. <li md-virtual-repeat="item in $mdAutocompleteCtrl.matches"\
  15462. ng-class="{ selected: $index === $mdAutocompleteCtrl.index }"\
  15463. ng-click="$mdAutocompleteCtrl.select($index)"\
  15464. md-extra-name="$mdAutocompleteCtrl.itemName">\
  15465. ' + itemTemplate + '\
  15466. </li>' + noItemsTemplate + '\
  15467. </ul>\
  15468. </md-virtual-repeat-container>\
  15469. </md-autocomplete-wrap>\
  15470. <aria-status\
  15471. class="md-visually-hidden"\
  15472. role="status"\
  15473. aria-live="assertive">\
  15474. <p ng-repeat="message in $mdAutocompleteCtrl.messages track by $index" ng-if="message">{{message}}</p>\
  15475. </aria-status>';
  15476. function getItemTemplate() {
  15477. var templateTag = element.find('md-item-template').detach(),
  15478. html = templateTag.length ? templateTag.html() : element.html();
  15479. if (!templateTag.length) element.empty();
  15480. return '<md-autocomplete-parent-scope md-autocomplete-replace>' + html + '</md-autocomplete-parent-scope>';
  15481. }
  15482. function getNoItemsTemplate() {
  15483. var templateTag = element.find('md-not-found').detach(),
  15484. template = templateTag.length ? templateTag.html() : '';
  15485. return template
  15486. ? '<li ng-if="$mdAutocompleteCtrl.notFoundVisible()"\
  15487. md-autocomplete-parent-scope>' + template + '</li>'
  15488. : '';
  15489. }
  15490. function getInputElement () {
  15491. if (attr.mdFloatingLabel) {
  15492. return '\
  15493. <md-input-container flex ng-if="floatingLabel">\
  15494. <label>{{floatingLabel}}</label>\
  15495. <input type="search"\
  15496. ' + (tabindex != null ? 'tabindex="' + tabindex + '"' : '') + '\
  15497. id="{{ inputId || \'fl-input-\' + $mdAutocompleteCtrl.id }}"\
  15498. name="{{inputName}}"\
  15499. autocomplete="off"\
  15500. ng-required="$mdAutocompleteCtrl.isRequired"\
  15501. ng-minlength="inputMinlength"\
  15502. ng-maxlength="inputMaxlength"\
  15503. ng-disabled="$mdAutocompleteCtrl.isDisabled"\
  15504. ng-model="$mdAutocompleteCtrl.scope.searchText"\
  15505. ng-keydown="$mdAutocompleteCtrl.keydown($event)"\
  15506. ng-blur="$mdAutocompleteCtrl.blur()"\
  15507. ng-focus="$mdAutocompleteCtrl.focus()"\
  15508. aria-owns="ul-{{$mdAutocompleteCtrl.id}}"\
  15509. aria-label="{{floatingLabel}}"\
  15510. aria-autocomplete="list"\
  15511. aria-haspopup="true"\
  15512. aria-activedescendant=""\
  15513. aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\
  15514. <div md-autocomplete-parent-scope md-autocomplete-replace>' + leftover + '</div>\
  15515. </md-input-container>';
  15516. } else {
  15517. return '\
  15518. <input flex type="search"\
  15519. ' + (tabindex != null ? 'tabindex="' + tabindex + '"' : '') + '\
  15520. id="{{ inputId || \'input-\' + $mdAutocompleteCtrl.id }}"\
  15521. name="{{inputName}}"\
  15522. ng-if="!floatingLabel"\
  15523. autocomplete="off"\
  15524. ng-required="$mdAutocompleteCtrl.isRequired"\
  15525. ng-disabled="$mdAutocompleteCtrl.isDisabled"\
  15526. ng-model="$mdAutocompleteCtrl.scope.searchText"\
  15527. ng-keydown="$mdAutocompleteCtrl.keydown($event)"\
  15528. ng-blur="$mdAutocompleteCtrl.blur()"\
  15529. ng-focus="$mdAutocompleteCtrl.focus()"\
  15530. placeholder="{{placeholder}}"\
  15531. aria-owns="ul-{{$mdAutocompleteCtrl.id}}"\
  15532. aria-label="{{placeholder}}"\
  15533. aria-autocomplete="list"\
  15534. aria-haspopup="true"\
  15535. aria-activedescendant=""\
  15536. aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\
  15537. <button\
  15538. type="button"\
  15539. tabindex="-1"\
  15540. ng-if="$mdAutocompleteCtrl.scope.searchText && !$mdAutocompleteCtrl.isDisabled"\
  15541. ng-click="$mdAutocompleteCtrl.clear()">\
  15542. <md-icon md-svg-icon="md-close"></md-icon>\
  15543. <span class="md-visually-hidden">Clear</span>\
  15544. </button>\
  15545. ';
  15546. }
  15547. }
  15548. }
  15549. };
  15550. }
  15551. })();
  15552. (function(){
  15553. "use strict";
  15554. angular
  15555. .module('material.components.autocomplete')
  15556. .directive('mdAutocompleteParentScope', MdAutocompleteItemScopeDirective);
  15557. function MdAutocompleteItemScopeDirective($compile, $mdUtil) {
  15558. return {
  15559. restrict: 'AE',
  15560. link: postLink,
  15561. terminal: true
  15562. };
  15563. function postLink(scope, element, attr) {
  15564. var ctrl = scope.$mdAutocompleteCtrl;
  15565. var newScope = ctrl.parent.$new();
  15566. var itemName = ctrl.itemName;
  15567. // Watch for changes to our scope's variables and copy them to the new scope
  15568. watchVariable('$index', '$index');
  15569. watchVariable('item', itemName);
  15570. // Recompile the contents with the new/modified scope
  15571. $compile(element.contents())(newScope);
  15572. // Replace it if required
  15573. if (attr.hasOwnProperty('mdAutocompleteReplace')) {
  15574. element.after(element.contents());
  15575. element.remove();
  15576. }
  15577. /**
  15578. * Creates a watcher for variables that are copied from the parent scope
  15579. * @param variable
  15580. * @param alias
  15581. */
  15582. function watchVariable(variable, alias) {
  15583. newScope[alias] = scope[variable];
  15584. scope.$watch(variable, function(value) {
  15585. $mdUtil.nextTick(function() {
  15586. newScope[alias] = value;
  15587. });
  15588. });
  15589. }
  15590. }
  15591. }
  15592. MdAutocompleteItemScopeDirective.$inject = ["$compile", "$mdUtil"];
  15593. })();
  15594. (function(){
  15595. "use strict";
  15596. angular
  15597. .module('material.components.autocomplete')
  15598. .controller('MdHighlightCtrl', MdHighlightCtrl);
  15599. function MdHighlightCtrl ($scope, $element, $attrs) {
  15600. this.init = init;
  15601. function init (termExpr, unsafeTextExpr) {
  15602. var text = null,
  15603. regex = null,
  15604. flags = $attrs.mdHighlightFlags || '',
  15605. watcher = $scope.$watch(function($scope) {
  15606. return {
  15607. term: termExpr($scope),
  15608. unsafeText: unsafeTextExpr($scope)
  15609. };
  15610. }, function (state, prevState) {
  15611. if (text === null || state.unsafeText !== prevState.unsafeText) {
  15612. text = angular.element('<div>').text(state.unsafeText).html()
  15613. }
  15614. if (regex === null || state.term !== prevState.term) {
  15615. regex = getRegExp(state.term, flags);
  15616. }
  15617. $element.html(text.replace(regex, '<span class="highlight">$&</span>'));
  15618. }, true);
  15619. $element.on('$destroy', function () { watcher(); });
  15620. }
  15621. function sanitize (term) {
  15622. return term && term.replace(/[\\\^\$\*\+\?\.\(\)\|\{}\[\]]/g, '\\$&');
  15623. }
  15624. function getRegExp (text, flags) {
  15625. var str = '';
  15626. if (flags.indexOf('^') >= 1) str += '^';
  15627. str += text;
  15628. if (flags.indexOf('$') >= 1) str += '$';
  15629. return new RegExp(sanitize(str), flags.replace(/[\$\^]/g, ''));
  15630. }
  15631. }
  15632. MdHighlightCtrl.$inject = ["$scope", "$element", "$attrs"];
  15633. })();
  15634. (function(){
  15635. "use strict";
  15636. angular
  15637. .module('material.components.autocomplete')
  15638. .directive('mdHighlightText', MdHighlight);
  15639. /**
  15640. * @ngdoc directive
  15641. * @name mdHighlightText
  15642. * @module material.components.autocomplete
  15643. *
  15644. * @description
  15645. * The `md-highlight-text` directive allows you to specify text that should be highlighted within
  15646. * an element. Highlighted text will be wrapped in `<span class="highlight"></span>` which can
  15647. * be styled through CSS. Please note that child elements may not be used with this directive.
  15648. *
  15649. * @param {string} md-highlight-text A model to be searched for
  15650. * @param {string=} md-highlight-flags A list of flags (loosely based on JavaScript RexExp flags).
  15651. * #### **Supported flags**:
  15652. * - `g`: Find all matches within the provided text
  15653. * - `i`: Ignore case when searching for matches
  15654. * - `$`: Only match if the text ends with the search term
  15655. * - `^`: Only match if the text begins with the search term
  15656. *
  15657. * @usage
  15658. * <hljs lang="html">
  15659. * <input placeholder="Enter a search term..." ng-model="searchTerm" type="text" />
  15660. * <ul>
  15661. * <li ng-repeat="result in results" md-highlight-text="searchTerm">
  15662. * {{result.text}}
  15663. * </li>
  15664. * </ul>
  15665. * </hljs>
  15666. */
  15667. function MdHighlight ($interpolate, $parse) {
  15668. return {
  15669. terminal: true,
  15670. controller: 'MdHighlightCtrl',
  15671. compile: function mdHighlightCompile(tElement, tAttr) {
  15672. var termExpr = $parse(tAttr.mdHighlightText);
  15673. var unsafeTextExpr = $interpolate(tElement.html());
  15674. return function mdHighlightLink(scope, element, attr, ctrl) {
  15675. ctrl.init(termExpr, unsafeTextExpr);
  15676. };
  15677. }
  15678. };
  15679. }
  15680. MdHighlight.$inject = ["$interpolate", "$parse"];
  15681. })();
  15682. (function(){
  15683. "use strict";
  15684. angular
  15685. .module('material.components.chips')
  15686. .directive('mdChip', MdChip);
  15687. /**
  15688. * @ngdoc directive
  15689. * @name mdChip
  15690. * @module material.components.chips
  15691. *
  15692. * @description
  15693. * `<md-chip>` is a component used within `<md-chips>` and is responsible for rendering individual
  15694. * chips.
  15695. *
  15696. *
  15697. * @usage
  15698. * <hljs lang="html">
  15699. * <md-chip>{{$chip}}</md-chip>
  15700. * </hljs>
  15701. *
  15702. */
  15703. // This hint text is hidden within a chip but used by screen readers to
  15704. // inform the user how they can interact with a chip.
  15705. var DELETE_HINT_TEMPLATE = '\
  15706. <span ng-if="!$mdChipsCtrl.readonly" class="md-visually-hidden">\
  15707. {{$mdChipsCtrl.deleteHint}}\
  15708. </span>';
  15709. /**
  15710. * MDChip Directive Definition
  15711. *
  15712. * @param $mdTheming
  15713. * @param $mdInkRipple
  15714. * @ngInject
  15715. */
  15716. function MdChip($mdTheming, $mdUtil) {
  15717. var hintTemplate = $mdUtil.processTemplate(DELETE_HINT_TEMPLATE);
  15718. return {
  15719. restrict: 'E',
  15720. require: '^?mdChips',
  15721. compile: compile
  15722. };
  15723. function compile(element, attr) {
  15724. // Append the delete template
  15725. element.append($mdUtil.processTemplate(hintTemplate));
  15726. return function postLink(scope, element, attr, ctrl) {
  15727. element.addClass('md-chip');
  15728. $mdTheming(element);
  15729. if (ctrl) angular.element(element[0].querySelector('.md-chip-content'))
  15730. .on('blur', function () {
  15731. ctrl.selectedChip = -1;
  15732. });
  15733. };
  15734. }
  15735. }
  15736. MdChip.$inject = ["$mdTheming", "$mdUtil"];
  15737. })();
  15738. (function(){
  15739. "use strict";
  15740. angular
  15741. .module('material.components.chips')
  15742. .directive('mdChipRemove', MdChipRemove);
  15743. /**
  15744. * @ngdoc directive
  15745. * @name mdChipRemove
  15746. * @module material.components.chips
  15747. *
  15748. * @description
  15749. * `<md-chip-remove>`
  15750. * Designates an element to be used as the delete button for a chip. This
  15751. * element is passed as a child of the `md-chips` element.
  15752. *
  15753. * @usage
  15754. * <hljs lang="html">
  15755. * <md-chips><button md-chip-remove>DEL</button></md-chips>
  15756. * </hljs>
  15757. */
  15758. /**
  15759. * MdChipRemove Directive Definition.
  15760. *
  15761. * @param $compile
  15762. * @param $timeout
  15763. * @returns {{restrict: string, require: string[], link: Function, scope: boolean}}
  15764. * @constructor
  15765. */
  15766. function MdChipRemove ($timeout) {
  15767. return {
  15768. restrict: 'A',
  15769. require: '^mdChips',
  15770. scope: false,
  15771. link: postLink
  15772. };
  15773. function postLink(scope, element, attr, ctrl) {
  15774. element.on('click', function(event) {
  15775. scope.$apply(function() {
  15776. ctrl.removeChip(scope.$$replacedScope.$index);
  15777. });
  15778. });
  15779. // Child elements aren't available until after a $timeout tick as they are hidden by an
  15780. // `ng-if`. see http://goo.gl/zIWfuw
  15781. $timeout(function() {
  15782. element.attr({ tabindex: -1, ariaHidden: true });
  15783. element.find('button').attr('tabindex', '-1');
  15784. });
  15785. }
  15786. }
  15787. MdChipRemove.$inject = ["$timeout"];
  15788. })();
  15789. (function(){
  15790. "use strict";
  15791. angular
  15792. .module('material.components.chips')
  15793. .directive('mdChipTransclude', MdChipTransclude);
  15794. function MdChipTransclude ($compile) {
  15795. return {
  15796. restrict: 'EA',
  15797. terminal: true,
  15798. link: link,
  15799. scope: false
  15800. };
  15801. function link (scope, element, attr) {
  15802. var ctrl = scope.$parent.$mdChipsCtrl,
  15803. newScope = ctrl.parent.$new(false, ctrl.parent);
  15804. newScope.$$replacedScope = scope;
  15805. newScope.$chip = scope.$chip;
  15806. newScope.$index = scope.$index;
  15807. newScope.$mdChipsCtrl = ctrl;
  15808. var newHtml = ctrl.$scope.$eval(attr.mdChipTransclude);
  15809. element.html(newHtml);
  15810. $compile(element.contents())(newScope);
  15811. }
  15812. }
  15813. MdChipTransclude.$inject = ["$compile"];
  15814. })();
  15815. (function(){
  15816. "use strict";
  15817. angular
  15818. .module('material.components.chips')
  15819. .controller('MdChipsCtrl', MdChipsCtrl);
  15820. /**
  15821. * Controller for the MdChips component. Responsible for adding to and
  15822. * removing from the list of chips, marking chips as selected, and binding to
  15823. * the models of various input components.
  15824. *
  15825. * @param $scope
  15826. * @param $mdConstant
  15827. * @param $log
  15828. * @param $element
  15829. * @constructor
  15830. */
  15831. function MdChipsCtrl ($scope, $mdConstant, $log, $element, $timeout) {
  15832. /** @type {$timeout} **/
  15833. this.$timeout = $timeout;
  15834. /** @type {Object} */
  15835. this.$mdConstant = $mdConstant;
  15836. /** @type {angular.$scope} */
  15837. this.$scope = $scope;
  15838. /** @type {angular.$scope} */
  15839. this.parent = $scope.$parent;
  15840. /** @type {$log} */
  15841. this.$log = $log;
  15842. /** @type {$element} */
  15843. this.$element = $element;
  15844. /** @type {angular.NgModelController} */
  15845. this.ngModelCtrl = null;
  15846. /** @type {angular.NgModelController} */
  15847. this.userInputNgModelCtrl = null;
  15848. /** @type {Element} */
  15849. this.userInputElement = null;
  15850. /** @type {Array.<Object>} */
  15851. this.items = [];
  15852. /** @type {number} */
  15853. this.selectedChip = -1;
  15854. /** @type {boolean} */
  15855. this.hasAutocomplete = false;
  15856. /**
  15857. * Hidden hint text for how to delete a chip. Used to give context to screen readers.
  15858. * @type {string}
  15859. */
  15860. this.deleteHint = 'Press delete to remove this chip.';
  15861. /**
  15862. * Hidden label for the delete button. Used to give context to screen readers.
  15863. * @type {string}
  15864. */
  15865. this.deleteButtonLabel = 'Remove';
  15866. /**
  15867. * Model used by the input element.
  15868. * @type {string}
  15869. */
  15870. this.chipBuffer = '';
  15871. /**
  15872. * Whether to use the onAppend expression to transform the chip buffer
  15873. * before appending it to the list.
  15874. * @type {boolean}
  15875. */
  15876. this.useOnAppend = false;
  15877. /**
  15878. * Whether to use the onSelect expression to notify the component's user
  15879. * after selecting a chip from the list.
  15880. * @type {boolean}
  15881. */
  15882. this.useOnSelect = false;
  15883. }
  15884. MdChipsCtrl.$inject = ["$scope", "$mdConstant", "$log", "$element", "$timeout"];
  15885. /**
  15886. * Handles the keydown event on the input element: <enter> appends the
  15887. * buffer to the chip list, while backspace removes the last chip in the list
  15888. * if the current buffer is empty.
  15889. * @param event
  15890. */
  15891. MdChipsCtrl.prototype.inputKeydown = function(event) {
  15892. var chipBuffer = this.getChipBuffer();
  15893. switch (event.keyCode) {
  15894. case this.$mdConstant.KEY_CODE.ENTER:
  15895. if ((this.hasAutocomplete && this.requireMatch) || !chipBuffer) break;
  15896. event.preventDefault();
  15897. this.appendChip(chipBuffer);
  15898. this.resetChipBuffer();
  15899. break;
  15900. case this.$mdConstant.KEY_CODE.BACKSPACE:
  15901. if (chipBuffer) break;
  15902. event.preventDefault();
  15903. event.stopPropagation();
  15904. if (this.items.length) this.selectAndFocusChipSafe(this.items.length - 1);
  15905. break;
  15906. }
  15907. };
  15908. /**
  15909. * Handles the keydown event on the chip elements: backspace removes the selected chip, arrow
  15910. * keys switch which chips is active
  15911. * @param event
  15912. */
  15913. MdChipsCtrl.prototype.chipKeydown = function (event) {
  15914. if (this.getChipBuffer()) return;
  15915. switch (event.keyCode) {
  15916. case this.$mdConstant.KEY_CODE.BACKSPACE:
  15917. case this.$mdConstant.KEY_CODE.DELETE:
  15918. if (this.selectedChip < 0) return;
  15919. event.preventDefault();
  15920. this.removeAndSelectAdjacentChip(this.selectedChip);
  15921. break;
  15922. case this.$mdConstant.KEY_CODE.LEFT_ARROW:
  15923. event.preventDefault();
  15924. if (this.selectedChip < 0) this.selectedChip = this.items.length;
  15925. if (this.items.length) this.selectAndFocusChipSafe(this.selectedChip - 1);
  15926. break;
  15927. case this.$mdConstant.KEY_CODE.RIGHT_ARROW:
  15928. event.preventDefault();
  15929. this.selectAndFocusChipSafe(this.selectedChip + 1);
  15930. break;
  15931. case this.$mdConstant.KEY_CODE.ESCAPE:
  15932. case this.$mdConstant.KEY_CODE.TAB:
  15933. if (this.selectedChip < 0) return;
  15934. event.preventDefault();
  15935. this.onFocus();
  15936. break;
  15937. }
  15938. };
  15939. /**
  15940. * Get the input's placeholder - uses `placeholder` when list is empty and `secondary-placeholder`
  15941. * when the list is non-empty. If `secondary-placeholder` is not provided, `placeholder` is used
  15942. * always.
  15943. */
  15944. MdChipsCtrl.prototype.getPlaceholder = function() {
  15945. // Allow `secondary-placeholder` to be blank.
  15946. var useSecondary = (this.items.length &&
  15947. (this.secondaryPlaceholder == '' || this.secondaryPlaceholder));
  15948. return useSecondary ? this.placeholder : this.secondaryPlaceholder;
  15949. };
  15950. /**
  15951. * Removes chip at {@code index} and selects the adjacent chip.
  15952. * @param index
  15953. */
  15954. MdChipsCtrl.prototype.removeAndSelectAdjacentChip = function(index) {
  15955. var selIndex = this.getAdjacentChipIndex(index);
  15956. this.removeChip(index);
  15957. this.$timeout(angular.bind(this, function () {
  15958. this.selectAndFocusChipSafe(selIndex);
  15959. }));
  15960. };
  15961. /**
  15962. * Sets the selected chip index to -1.
  15963. */
  15964. MdChipsCtrl.prototype.resetSelectedChip = function() {
  15965. this.selectedChip = -1;
  15966. };
  15967. /**
  15968. * Gets the index of an adjacent chip to select after deletion. Adjacency is
  15969. * determined as the next chip in the list, unless the target chip is the
  15970. * last in the list, then it is the chip immediately preceding the target. If
  15971. * there is only one item in the list, -1 is returned (select none).
  15972. * The number returned is the index to select AFTER the target has been
  15973. * removed.
  15974. * If the current chip is not selected, then -1 is returned to select none.
  15975. */
  15976. MdChipsCtrl.prototype.getAdjacentChipIndex = function(index) {
  15977. var len = this.items.length - 1;
  15978. return (len == 0) ? -1 :
  15979. (index == len) ? index -1 : index;
  15980. };
  15981. /**
  15982. * Append the contents of the buffer to the chip list. This method will first
  15983. * call out to the md-on-append method, if provided
  15984. * @param newChip
  15985. */
  15986. MdChipsCtrl.prototype.appendChip = function(newChip) {
  15987. if (this.useOnAppend && this.onAppend) {
  15988. newChip = this.onAppend({'$chip': newChip});
  15989. }
  15990. if (this.items.indexOf(newChip) + 1) return;
  15991. this.items.push(newChip);
  15992. };
  15993. /**
  15994. * Sets whether to use the md-on-append expression. This expression is
  15995. * bound to scope and controller in {@code MdChipsDirective} as
  15996. * {@code onAppend}. Due to the nature of directive scope bindings, the
  15997. * controller cannot know on its own/from the scope whether an expression was
  15998. * actually provided.
  15999. */
  16000. MdChipsCtrl.prototype.useOnAppendExpression = function() {
  16001. this.useOnAppend = true;
  16002. };
  16003. /**
  16004. * Sets whether to use the md-on-remove expression. This expression is
  16005. * bound to scope and controller in {@code MdChipsDirective} as
  16006. * {@code onRemove}. Due to the nature of directive scope bindings, the
  16007. * controller cannot know on its own/from the scope whether an expression was
  16008. * actually provided.
  16009. */
  16010. MdChipsCtrl.prototype.useOnRemoveExpression = function() {
  16011. this.useOnRemove = true;
  16012. };
  16013. /*
  16014. * Sets whether to use the md-on-select expression. This expression is
  16015. * bound to scope and controller in {@code MdChipsDirective} as
  16016. * {@code onSelect}. Due to the nature of directive scope bindings, the
  16017. * controller cannot know on its own/from the scope whether an expression was
  16018. * actually provided.
  16019. */
  16020. MdChipsCtrl.prototype.useOnSelectExpression = function() {
  16021. this.useOnSelect = true;
  16022. };
  16023. /**
  16024. * Gets the input buffer. The input buffer can be the model bound to the
  16025. * default input item {@code this.chipBuffer}, the {@code selectedItem}
  16026. * model of an {@code md-autocomplete}, or, through some magic, the model
  16027. * bound to any inpput or text area element found within a
  16028. * {@code md-input-container} element.
  16029. * @return {Object|string}
  16030. */
  16031. MdChipsCtrl.prototype.getChipBuffer = function() {
  16032. return !this.userInputElement ? this.chipBuffer :
  16033. this.userInputNgModelCtrl ? this.userInputNgModelCtrl.$viewValue :
  16034. this.userInputElement[0].value;
  16035. };
  16036. /**
  16037. * Resets the input buffer for either the internal input or user provided input element.
  16038. */
  16039. MdChipsCtrl.prototype.resetChipBuffer = function() {
  16040. if (this.userInputElement) {
  16041. if (this.userInputNgModelCtrl) {
  16042. this.userInputNgModelCtrl.$setViewValue('');
  16043. this.userInputNgModelCtrl.$render();
  16044. } else {
  16045. this.userInputElement[0].value = '';
  16046. }
  16047. } else {
  16048. this.chipBuffer = '';
  16049. }
  16050. };
  16051. /**
  16052. * Removes the chip at the given index.
  16053. * @param index
  16054. */
  16055. MdChipsCtrl.prototype.removeChip = function(index) {
  16056. var removed = this.items.splice(index, 1);
  16057. if (removed && removed.length && this.useOnRemove && this.onRemove) {
  16058. this.onRemove({ '$chip': removed[0], '$index': index });
  16059. }
  16060. };
  16061. MdChipsCtrl.prototype.removeChipAndFocusInput = function (index) {
  16062. this.removeChip(index);
  16063. this.onFocus();
  16064. };
  16065. /**
  16066. * Selects the chip at `index`,
  16067. * @param index
  16068. */
  16069. MdChipsCtrl.prototype.selectAndFocusChipSafe = function(index) {
  16070. if (!this.items.length) {
  16071. this.selectChip(-1);
  16072. this.onFocus();
  16073. return;
  16074. }
  16075. if (index === this.items.length) return this.onFocus();
  16076. index = Math.max(index, 0);
  16077. index = Math.min(index, this.items.length - 1);
  16078. this.selectChip(index);
  16079. this.focusChip(index);
  16080. };
  16081. /**
  16082. * Marks the chip at the given index as selected.
  16083. * @param index
  16084. */
  16085. MdChipsCtrl.prototype.selectChip = function(index) {
  16086. if (index >= -1 && index <= this.items.length) {
  16087. this.selectedChip = index;
  16088. // Fire the onSelect if provided
  16089. if (this.useOnSelect && this.onSelect) {
  16090. this.onSelect({'$chip': this.items[this.selectedChip] });
  16091. }
  16092. } else {
  16093. this.$log.warn('Selected Chip index out of bounds; ignoring.');
  16094. }
  16095. };
  16096. /**
  16097. * Selects the chip at `index` and gives it focus.
  16098. * @param index
  16099. */
  16100. MdChipsCtrl.prototype.selectAndFocusChip = function(index) {
  16101. this.selectChip(index);
  16102. if (index != -1) {
  16103. this.focusChip(index);
  16104. }
  16105. };
  16106. /**
  16107. * Call `focus()` on the chip at `index`
  16108. */
  16109. MdChipsCtrl.prototype.focusChip = function(index) {
  16110. this.$element[0].querySelector('md-chip[index="' + index + '"] .md-chip-content').focus();
  16111. };
  16112. /**
  16113. * Configures the required interactions with the ngModel Controller.
  16114. * Specifically, set {@code this.items} to the {@code NgModelCtrl#$viewVale}.
  16115. * @param ngModelCtrl
  16116. */
  16117. MdChipsCtrl.prototype.configureNgModel = function(ngModelCtrl) {
  16118. this.ngModelCtrl = ngModelCtrl;
  16119. var self = this;
  16120. ngModelCtrl.$render = function() {
  16121. // model is updated. do something.
  16122. self.items = self.ngModelCtrl.$viewValue;
  16123. };
  16124. };
  16125. MdChipsCtrl.prototype.onFocus = function () {
  16126. var input = this.$element[0].querySelector('input');
  16127. input && input.focus();
  16128. this.resetSelectedChip();
  16129. };
  16130. MdChipsCtrl.prototype.onInputFocus = function () {
  16131. this.inputHasFocus = true;
  16132. this.resetSelectedChip();
  16133. };
  16134. MdChipsCtrl.prototype.onInputBlur = function () {
  16135. this.inputHasFocus = false;
  16136. };
  16137. /**
  16138. * Configure event bindings on a user-provided input element.
  16139. * @param inputElement
  16140. */
  16141. MdChipsCtrl.prototype.configureUserInput = function(inputElement) {
  16142. this.userInputElement = inputElement;
  16143. // Find the NgModelCtrl for the input element
  16144. var ngModelCtrl = inputElement.controller('ngModel');
  16145. // `.controller` will look in the parent as well.
  16146. if (ngModelCtrl != this.ngModelCtrl) {
  16147. this.userInputNgModelCtrl = ngModelCtrl;
  16148. }
  16149. var scope = this.$scope;
  16150. var ctrl = this;
  16151. // Run all of the events using evalAsync because a focus may fire a blur in the same digest loop
  16152. var scopeApplyFn = function(event, fn) {
  16153. scope.$evalAsync(angular.bind(ctrl, fn, event));
  16154. };
  16155. // Bind to keydown and focus events of input
  16156. inputElement
  16157. .attr({ tabindex: 0 })
  16158. .on('keydown', function(event) { scopeApplyFn(event, ctrl.inputKeydown) })
  16159. .on('focus', function(event) { scopeApplyFn(event, ctrl.onInputFocus) })
  16160. .on('blur', function(event) { scopeApplyFn(event, ctrl.onInputBlur) })
  16161. };
  16162. MdChipsCtrl.prototype.configureAutocomplete = function(ctrl) {
  16163. if ( ctrl ){
  16164. this.hasAutocomplete = true;
  16165. ctrl.registerSelectedItemWatcher(angular.bind(this, function (item) {
  16166. if (item) {
  16167. this.appendChip(item);
  16168. this.resetChipBuffer();
  16169. }
  16170. }));
  16171. this.$element.find('input')
  16172. .on('focus',angular.bind(this, this.onInputFocus) )
  16173. .on('blur', angular.bind(this, this.onInputBlur) );
  16174. }
  16175. };
  16176. MdChipsCtrl.prototype.hasFocus = function () {
  16177. return this.inputHasFocus || this.selectedChip >= 0;
  16178. };
  16179. })();
  16180. (function(){
  16181. "use strict";
  16182. angular
  16183. .module('material.components.chips')
  16184. .directive('mdChips', MdChips);
  16185. /**
  16186. * @ngdoc directive
  16187. * @name mdChips
  16188. * @module material.components.chips
  16189. *
  16190. * @description
  16191. * `<md-chips>` is an input component for building lists of strings or objects. The list items are
  16192. * displayed as 'chips'. This component can make use of an `<input>` element or an
  16193. * `<md-autocomplete>` element.
  16194. *
  16195. * ### Custom templates
  16196. * A custom template may be provided to render the content of each chip. This is achieved by
  16197. * specifying an `<md-chip-template>` element containing the custom content as a child of
  16198. * `<md-chips>`.
  16199. *
  16200. * Note: Any attributes on
  16201. * `<md-chip-template>` will be dropped as only the innerHTML is used for the chip template. The
  16202. * variables `$chip` and `$index` are available in the scope of `<md-chip-template>`, representing
  16203. * the chip object and its index in the list of chips, respectively.
  16204. * To override the chip delete control, include an element (ideally a button) with the attribute
  16205. * `md-chip-remove`. A click listener to remove the chip will be added automatically. The element
  16206. * is also placed as a sibling to the chip content (on which there are also click listeners) to
  16207. * avoid a nested ng-click situation.
  16208. *
  16209. * <h3> Pending Features </h3>
  16210. * <ul style="padding-left:20px;">
  16211. *
  16212. * <ul>Style
  16213. * <li>Colours for hover, press states (ripple?).</li>
  16214. * </ul>
  16215. *
  16216. * <ul>Validation
  16217. * <li>allow a validation callback</li>
  16218. * <li>hilighting style for invalid chips</li>
  16219. * </ul>
  16220. *
  16221. * <ul>Item mutation
  16222. * <li>Support `
  16223. * <md-chip-edit>` template, show/hide the edit element on tap/click? double tap/double
  16224. * click?
  16225. * </li>
  16226. * </ul>
  16227. *
  16228. * <ul>Truncation and Disambiguation (?)
  16229. * <li>Truncate chip text where possible, but do not truncate entries such that two are
  16230. * indistinguishable.</li>
  16231. * </ul>
  16232. *
  16233. * <ul>Drag and Drop
  16234. * <li>Drag and drop chips between related `<md-chips>` elements.
  16235. * </li>
  16236. * </ul>
  16237. * </ul>
  16238. *
  16239. * <span style="font-size:.8em;text-align:center">
  16240. * Warning: This component is a WORK IN PROGRESS. If you use it now,
  16241. * it will probably break on you in the future.
  16242. * </span>
  16243. *
  16244. * @param {string=|object=} ng-model A model to bind the list of items to
  16245. * @param {string=} placeholder Placeholder text that will be forwarded to the input.
  16246. * @param {string=} secondary-placeholder Placeholder text that will be forwarded to the input,
  16247. * displayed when there is at least on item in the list
  16248. * @param {boolean=} readonly Disables list manipulation (deleting or adding list items), hiding
  16249. * the input and delete buttons
  16250. * @param {expression} md-on-append An expression that when called expects you to return an object
  16251. * representation of the chip input string.
  16252. * @param {expression=} md-on-remove An expression which will be called when a chip has been
  16253. * removed.
  16254. * @param {expression=} md-on-select An expression which will be called when a chip is selected.
  16255. * @param {string=} delete-hint A string read by screen readers instructing users that pressing
  16256. * the delete key will remove the chip.
  16257. * @param {string=} delete-button-label A label for the delete button. Also hidden and read by
  16258. * screen readers.
  16259. *
  16260. * @usage
  16261. * <hljs lang="html">
  16262. * <md-chips
  16263. * ng-model="myItems"
  16264. * placeholder="Add an item"
  16265. * readonly="isReadOnly">
  16266. * </md-chips>
  16267. * </hljs>
  16268. *
  16269. */
  16270. var MD_CHIPS_TEMPLATE = '\
  16271. <md-chips-wrap\
  16272. ng-if="!$mdChipsCtrl.readonly || $mdChipsCtrl.items.length > 0"\
  16273. ng-keydown="$mdChipsCtrl.chipKeydown($event)"\
  16274. ng-class="{ \'md-focused\': $mdChipsCtrl.hasFocus(), \'md-readonly\': !$mdChipsCtrl.ngModelCtrl }"\
  16275. class="md-chips">\
  16276. <md-chip ng-repeat="$chip in $mdChipsCtrl.items"\
  16277. index="{{$index}}"\
  16278. ng-class="{\'md-focused\': $mdChipsCtrl.selectedChip == $index, \'md-readonly\': $mdChipsCtrl.readonly}">\
  16279. <div class="md-chip-content"\
  16280. tabindex="-1"\
  16281. aria-hidden="true"\
  16282. ng-focus="!$mdChipsCtrl.readonly && $mdChipsCtrl.selectChip($index)"\
  16283. md-chip-transclude="$mdChipsCtrl.chipContentsTemplate"></div>\
  16284. <div ng-if="!$mdChipsCtrl.readonly"\
  16285. class="md-chip-remove-container"\
  16286. md-chip-transclude="$mdChipsCtrl.chipRemoveTemplate"></div>\
  16287. </md-chip>\
  16288. <div ng-if="!$mdChipsCtrl.readonly && $mdChipsCtrl.ngModelCtrl"\
  16289. class="md-chip-input-container"\
  16290. md-chip-transclude="$mdChipsCtrl.chipInputTemplate"></div>\
  16291. </div>\
  16292. </md-chips-wrap>';
  16293. var CHIP_INPUT_TEMPLATE = '\
  16294. <input\
  16295. tabindex="0"\
  16296. placeholder="{{$mdChipsCtrl.getPlaceholder()}}"\
  16297. aria-label="{{$mdChipsCtrl.getPlaceholder()}}"\
  16298. ng-model="$mdChipsCtrl.chipBuffer"\
  16299. ng-focus="$mdChipsCtrl.onInputFocus()"\
  16300. ng-blur="$mdChipsCtrl.onInputBlur()"\
  16301. ng-keydown="$mdChipsCtrl.inputKeydown($event)">';
  16302. var CHIP_DEFAULT_TEMPLATE = '\
  16303. <span>{{$chip}}</span>';
  16304. var CHIP_REMOVE_TEMPLATE = '\
  16305. <button\
  16306. class="md-chip-remove"\
  16307. ng-if="!$mdChipsCtrl.readonly"\
  16308. ng-click="$mdChipsCtrl.removeChipAndFocusInput($$replacedScope.$index)"\
  16309. type="button"\
  16310. aria-hidden="true"\
  16311. tabindex="-1">\
  16312. <md-icon md-svg-icon="md-close"></md-icon>\
  16313. <span class="md-visually-hidden">\
  16314. {{$mdChipsCtrl.deleteButtonLabel}}\
  16315. </span>\
  16316. </button>';
  16317. /**
  16318. * MDChips Directive Definition
  16319. */
  16320. function MdChips ($mdTheming, $mdUtil, $compile, $log, $timeout) {
  16321. // Run our templates through $mdUtil.processTemplate() to allow custom start/end symbols
  16322. var templates = getTemplates();
  16323. return {
  16324. template: function(element, attrs) {
  16325. // Clone the element into an attribute. By prepending the attribute
  16326. // name with '$', Angular won't write it into the DOM. The cloned
  16327. // element propagates to the link function via the attrs argument,
  16328. // where various contained-elements can be consumed.
  16329. attrs['$mdUserTemplate'] = element.clone();
  16330. return templates.chips;
  16331. },
  16332. require: ['mdChips'],
  16333. restrict: 'E',
  16334. controller: 'MdChipsCtrl',
  16335. controllerAs: '$mdChipsCtrl',
  16336. bindToController: true,
  16337. compile: compile,
  16338. scope: {
  16339. readonly: '=readonly',
  16340. placeholder: '@',
  16341. secondaryPlaceholder: '@',
  16342. onAppend: '&mdOnAppend',
  16343. onRemove: '&mdOnRemove',
  16344. onSelect: '&mdOnSelect',
  16345. deleteHint: '@',
  16346. deleteButtonLabel: '@',
  16347. requireMatch: '=?mdRequireMatch'
  16348. }
  16349. };
  16350. /**
  16351. * Builds the final template for `md-chips` and returns the postLink function.
  16352. *
  16353. * Building the template involves 3 key components:
  16354. * static chips
  16355. * chip template
  16356. * input control
  16357. *
  16358. * If no `ng-model` is provided, only the static chip work needs to be done.
  16359. *
  16360. * If no user-passed `md-chip-template` exists, the default template is used. This resulting
  16361. * template is appended to the chip content element.
  16362. *
  16363. * The remove button may be overridden by passing an element with an md-chip-remove attribute.
  16364. *
  16365. * If an `input` or `md-autocomplete` element is provided by the caller, it is set aside for
  16366. * transclusion later. The transclusion happens in `postLink` as the parent scope is required.
  16367. * If no user input is provided, a default one is appended to the input container node in the
  16368. * template.
  16369. *
  16370. * Static Chips (i.e. `md-chip` elements passed from the caller) are gathered and set aside for
  16371. * transclusion in the `postLink` function.
  16372. *
  16373. *
  16374. * @param element
  16375. * @param attr
  16376. * @returns {Function}
  16377. */
  16378. function compile(element, attr) {
  16379. // Grab the user template from attr and reset the attribute to null.
  16380. var userTemplate = attr['$mdUserTemplate'];
  16381. attr['$mdUserTemplate'] = null;
  16382. // Set the chip remove, chip contents and chip input templates. The link function will put
  16383. // them on the scope for transclusion later.
  16384. var chipRemoveTemplate = getTemplateByQuery('md-chips>*[md-chip-remove]') || templates.remove,
  16385. chipContentsTemplate = getTemplateByQuery('md-chips>md-chip-template') || templates.default,
  16386. chipInputTemplate = getTemplateByQuery('md-chips>md-autocomplete')
  16387. || getTemplateByQuery('md-chips>input')
  16388. || templates.input,
  16389. staticChips = userTemplate.find('md-chip');
  16390. // Warn of malformed template. See #2545
  16391. if (userTemplate[0].querySelector('md-chip-template>*[md-chip-remove]')) {
  16392. $log.warn('invalid placement of md-chip-remove within md-chip-template.');
  16393. }
  16394. function getTemplateByQuery (query) {
  16395. if (!attr.ngModel) return;
  16396. var element = userTemplate[0].querySelector(query);
  16397. return element && element.outerHTML;
  16398. }
  16399. /**
  16400. * Configures controller and transcludes.
  16401. */
  16402. return function postLink(scope, element, attrs, controllers) {
  16403. $mdUtil.initOptionalProperties(scope, attr);
  16404. $mdTheming(element);
  16405. var mdChipsCtrl = controllers[0];
  16406. mdChipsCtrl.chipContentsTemplate = chipContentsTemplate;
  16407. mdChipsCtrl.chipRemoveTemplate = chipRemoveTemplate;
  16408. mdChipsCtrl.chipInputTemplate = chipInputTemplate;
  16409. element
  16410. .attr({ ariaHidden: true, tabindex: -1 })
  16411. .on('focus', function () { mdChipsCtrl.onFocus(); });
  16412. if (attr.ngModel) {
  16413. mdChipsCtrl.configureNgModel(element.controller('ngModel'));
  16414. // If an `md-on-append` attribute was set, tell the controller to use the expression
  16415. // when appending chips.
  16416. if (attrs.mdOnAppend) mdChipsCtrl.useOnAppendExpression();
  16417. // If an `md-on-remove` attribute was set, tell the controller to use the expression
  16418. // when removing chips.
  16419. if (attrs.mdOnRemove) mdChipsCtrl.useOnRemoveExpression();
  16420. // If an `md-on-select` attribute was set, tell the controller to use the expression
  16421. // when selecting chips.
  16422. if (attrs.mdOnSelect) mdChipsCtrl.useOnSelectExpression();
  16423. // The md-autocomplete and input elements won't be compiled until after this directive
  16424. // is complete (due to their nested nature). Wait a tick before looking for them to
  16425. // configure the controller.
  16426. if (chipInputTemplate != templates.input) {
  16427. // The autocomplete will not appear until the readonly attribute is not true (i.e.
  16428. // false or undefined), so we have to watch the readonly and then on the next tick
  16429. // after the chip transclusion has run, we can configure the autocomplete and user
  16430. // input.
  16431. scope.$watch('$mdChipsCtrl.readonly', function(readonly) {
  16432. if (!readonly) {
  16433. $mdUtil.nextTick(function(){
  16434. if (chipInputTemplate.indexOf('<md-autocomplete') === 0)
  16435. mdChipsCtrl
  16436. .configureAutocomplete(element.find('md-autocomplete')
  16437. .controller('mdAutocomplete'));
  16438. mdChipsCtrl.configureUserInput(element.find('input'));
  16439. });
  16440. }
  16441. });
  16442. }
  16443. }
  16444. // Compile with the parent's scope and prepend any static chips to the wrapper.
  16445. if (staticChips.length > 0) {
  16446. var compiledStaticChips = $compile(staticChips.clone())(scope.$parent);
  16447. $timeout(function() { element.find('md-chips-wrap').prepend(compiledStaticChips); });
  16448. }
  16449. };
  16450. }
  16451. function getTemplates() {
  16452. return {
  16453. chips: $mdUtil.processTemplate(MD_CHIPS_TEMPLATE),
  16454. input: $mdUtil.processTemplate(CHIP_INPUT_TEMPLATE),
  16455. default: $mdUtil.processTemplate(CHIP_DEFAULT_TEMPLATE),
  16456. remove: $mdUtil.processTemplate(CHIP_REMOVE_TEMPLATE)
  16457. };
  16458. }
  16459. }
  16460. MdChips.$inject = ["$mdTheming", "$mdUtil", "$compile", "$log", "$timeout"];
  16461. })();
  16462. (function(){
  16463. "use strict";
  16464. angular
  16465. .module('material.components.chips')
  16466. .controller('MdContactChipsCtrl', MdContactChipsCtrl);
  16467. /**
  16468. * Controller for the MdContactChips component
  16469. * @constructor
  16470. */
  16471. function MdContactChipsCtrl () {
  16472. /** @type {Object} */
  16473. this.selectedItem = null;
  16474. /** @type {string} */
  16475. this.searchText = '';
  16476. }
  16477. MdContactChipsCtrl.prototype.queryContact = function(searchText) {
  16478. var results = this.contactQuery({'$query': searchText});
  16479. return this.filterSelected ?
  16480. results.filter(angular.bind(this, this.filterSelectedContacts)) : results;
  16481. };
  16482. MdContactChipsCtrl.prototype.itemName = function(item) {
  16483. return item[this.contactName];
  16484. };
  16485. MdContactChipsCtrl.prototype.filterSelectedContacts = function(contact) {
  16486. return this.contacts.indexOf(contact) == -1;
  16487. };
  16488. })();
  16489. (function(){
  16490. "use strict";
  16491. angular
  16492. .module('material.components.chips')
  16493. .directive('mdContactChips', MdContactChips);
  16494. /**
  16495. * @ngdoc directive
  16496. * @name mdContactChips
  16497. * @module material.components.chips
  16498. *
  16499. * @description
  16500. * `<md-contact-chips>` is an input component based on `md-chips` and makes use of an
  16501. * `md-autocomplete` element. The component allows the caller to supply a query expression which
  16502. * returns a list of possible contacts. The user can select one of these and add it to the list of
  16503. * chips.
  16504. *
  16505. * You may also use the `md-highlight-text` directive along with it's parameters to control the
  16506. * appearance of the matched text inside of the contacts' autocomplete popup.
  16507. *
  16508. * @param {string=|object=} ng-model A model to bind the list of items to
  16509. * @param {string=} placeholder Placeholder text that will be forwarded to the input.
  16510. * @param {string=} secondary-placeholder Placeholder text that will be forwarded to the input,
  16511. * displayed when there is at least on item in the list
  16512. * @param {expression} md-contacts An expression expected to return contacts matching the search
  16513. * test, `$query`.
  16514. * @param {string} md-contact-name The field name of the contact object representing the
  16515. * contact's name.
  16516. * @param {string} md-contact-email The field name of the contact object representing the
  16517. * contact's email address.
  16518. * @param {string} md-contact-image The field name of the contact object representing the
  16519. * contact's image.
  16520. *
  16521. *
  16522. * // The following attribute has been removed but may come back.
  16523. * @param {expression=} filter-selected Whether to filter selected contacts from the list of
  16524. * suggestions shown in the autocomplete.
  16525. *
  16526. *
  16527. *
  16528. * @usage
  16529. * <hljs lang="html">
  16530. * <md-contact-chips
  16531. * ng-model="ctrl.contacts"
  16532. * md-contacts="ctrl.querySearch($query)"
  16533. * md-contact-name="name"
  16534. * md-contact-image="image"
  16535. * md-contact-email="email"
  16536. * placeholder="To">
  16537. * </md-contact-chips>
  16538. * </hljs>
  16539. *
  16540. */
  16541. var MD_CONTACT_CHIPS_TEMPLATE = '\
  16542. <md-chips class="md-contact-chips"\
  16543. ng-model="$mdContactChipsCtrl.contacts"\
  16544. md-require-match="$mdContactChipsCtrl.requireMatch"\
  16545. md-autocomplete-snap>\
  16546. <md-autocomplete\
  16547. md-menu-class="md-contact-chips-suggestions"\
  16548. md-selected-item="$mdContactChipsCtrl.selectedItem"\
  16549. md-search-text="$mdContactChipsCtrl.searchText"\
  16550. md-items="item in $mdContactChipsCtrl.queryContact($mdContactChipsCtrl.searchText)"\
  16551. md-item-text="$mdContactChipsCtrl.itemName(item)"\
  16552. md-no-cache="true"\
  16553. md-autoselect\
  16554. placeholder="{{$mdContactChipsCtrl.contacts.length == 0 ?\
  16555. $mdContactChipsCtrl.placeholder : $mdContactChipsCtrl.secondaryPlaceholder}}">\
  16556. <div class="md-contact-suggestion">\
  16557. <img \
  16558. ng-src="{{item[$mdContactChipsCtrl.contactImage]}}"\
  16559. alt="{{item[$mdContactChipsCtrl.contactName]}}"\
  16560. ng-if="item[$mdContactChipsCtrl.contactImage]" />\
  16561. <span class="md-contact-name" md-highlight-text="$mdContactChipsCtrl.searchText"\
  16562. md-highlight-flags="{{$mdContactChipsCtrl.highlightFlags}}">\
  16563. {{item[$mdContactChipsCtrl.contactName]}}\
  16564. </span>\
  16565. <span class="md-contact-email" >{{item[$mdContactChipsCtrl.contactEmail]}}</span>\
  16566. </div>\
  16567. </md-autocomplete>\
  16568. <md-chip-template>\
  16569. <div class="md-contact-avatar">\
  16570. <img \
  16571. ng-src="{{$chip[$mdContactChipsCtrl.contactImage]}}"\
  16572. alt="{{$chip[$mdContactChipsCtrl.contactName]}}"\
  16573. ng-if="$chip[$mdContactChipsCtrl.contactImage]" />\
  16574. </div>\
  16575. <div class="md-contact-name">\
  16576. {{$chip[$mdContactChipsCtrl.contactName]}}\
  16577. </div>\
  16578. </md-chip-template>\
  16579. </md-chips>';
  16580. /**
  16581. * MDContactChips Directive Definition
  16582. *
  16583. * @param $mdTheming
  16584. * @returns {*}
  16585. * @ngInject
  16586. */
  16587. function MdContactChips($mdTheming, $mdUtil) {
  16588. return {
  16589. template: function(element, attrs) {
  16590. return MD_CONTACT_CHIPS_TEMPLATE;
  16591. },
  16592. restrict: 'E',
  16593. controller: 'MdContactChipsCtrl',
  16594. controllerAs: '$mdContactChipsCtrl',
  16595. bindToController: true,
  16596. compile: compile,
  16597. scope: {
  16598. contactQuery: '&mdContacts',
  16599. placeholder: '@',
  16600. secondaryPlaceholder: '@',
  16601. contactName: '@mdContactName',
  16602. contactImage: '@mdContactImage',
  16603. contactEmail: '@mdContactEmail',
  16604. contacts: '=ngModel',
  16605. requireMatch: '=?mdRequireMatch',
  16606. highlightFlags: '@?mdHighlightFlags'
  16607. }
  16608. };
  16609. function compile(element, attr) {
  16610. return function postLink(scope, element, attrs, controllers) {
  16611. $mdUtil.initOptionalProperties(scope, attr);
  16612. $mdTheming(element);
  16613. element.attr('tabindex', '-1');
  16614. };
  16615. }
  16616. }
  16617. MdContactChips.$inject = ["$mdTheming", "$mdUtil"];
  16618. })();
  16619. (function(){
  16620. "use strict";
  16621. angular
  16622. .module('material.components.icon')
  16623. .directive('mdIcon', ['$mdIcon', '$mdTheming', '$mdAria', mdIconDirective]);
  16624. /**
  16625. * @ngdoc directive
  16626. * @name mdIcon
  16627. * @module material.components.icon
  16628. *
  16629. * @restrict E
  16630. *
  16631. * @description
  16632. * The `md-icon` directive makes it easier to use vector-based icons in your app (as opposed to
  16633. * raster-based icons types like PNG). The directive supports both icon fonts and SVG icons.
  16634. *
  16635. * Icons should be consider view-only elements that should not be used directly as buttons; instead nest a `<md-icon>`
  16636. * inside a `md-button` to add hover and click features.
  16637. *
  16638. * ### Icon fonts
  16639. * Icon fonts are a technique in which you use a font where the glyphs in the font are
  16640. * your icons instead of text. Benefits include a straightforward way to bundle everything into a
  16641. * single HTTP request, simple scaling, easy color changing, and more.
  16642. *
  16643. * `md-icon` let's you consume an icon font by letting you reference specific icons in that font
  16644. * by name rather than character code.
  16645. *
  16646. * ### SVG
  16647. * For SVGs, the problem with using `<img>` or a CSS `background-image` is that you can't take
  16648. * advantage of some SVG features, such as styling specific parts of the icon with CSS or SVG
  16649. * animation.
  16650. *
  16651. * `md-icon` makes it easier to use SVG icons by *inlining* the SVG into an `<svg>` element in the
  16652. * document. The most straightforward way of referencing an SVG icon is via URL, just like a
  16653. * traditional `<img>`. `$mdIconProvider`, as a convenience, let's you _name_ an icon so you can
  16654. * reference it by name instead of URL throughout your templates.
  16655. *
  16656. * Additionally, you may not want to make separate HTTP requests for every icon, so you can bundle
  16657. * your SVG icons together and pre-load them with $mdIconProvider as an icon set. An icon set can
  16658. * also be given a name, which acts as a namespace for individual icons, so you can reference them
  16659. * like `"social:cake"`.
  16660. *
  16661. * When using SVGs, both external SVGs (via URLs) or sets of SVGs [from icon sets] can be
  16662. * easily loaded and used.When use font-icons, developers must following three (3) simple steps:
  16663. *
  16664. * <ol>
  16665. * <li>Load the font library. e.g.<br/>
  16666. * &lt;link href="https://fonts.googleapis.com/icon?family=Material+Icons"
  16667. * rel="stylesheet"&gt;
  16668. * </li>
  16669. * <li> Use either (a) font-icon class names or (b) font ligatures to render the font glyph by using its textual name</li>
  16670. * <li> Use &lt;md-icon md-font-icon="classname" /&gt; or <br/>
  16671. * use &lt;md-icon md-font-set="font library classname or alias"&gt; textual_name &lt;/md-icon&gt; or <br/>
  16672. * use &lt;md-icon md-font-set="font library classname or alias"&gt; numerical_character_reference &lt;/md-icon&gt;
  16673. * </li>
  16674. * </ol>
  16675. *
  16676. * Full details for these steps can be found:
  16677. *
  16678. * <ul>
  16679. * <li>http://google.github.io/material-design-icons/</li>
  16680. * <li>http://google.github.io/material-design-icons/#icon-font-for-the-web</li>
  16681. * </ul>
  16682. *
  16683. * The Material Design icon style <code>.material-icons</code> and the icon font references are published in
  16684. * Material Design Icons:
  16685. *
  16686. * <ul>
  16687. * <li>http://www.google.com/design/icons/</li>
  16688. * <li>https://www.google.com/design/icons/#ic_accessibility</li>
  16689. * </ul>
  16690. *
  16691. * <h2 id="material_design_icons">Material Design Icons</h2>
  16692. * Using the Material Design Icon-Selector, developers can easily and quickly search for a Material Design font-icon and
  16693. * determine its textual name and character reference code. Click on any icon to see the slide-up information
  16694. * panel with details regarding a SVG download or information on the font-icon usage.
  16695. *
  16696. * <a href="https://www.google.com/design/icons/#ic_accessibility" target="_blank" style="border-bottom:none;">
  16697. * <img src="https://cloud.githubusercontent.com/assets/210413/7902490/fe8dd14c-0780-11e5-98fb-c821cc6475e6.png"
  16698. * aria-label="Material Design Icon-Selector" style="max-width:75%;padding-left:10%">
  16699. * </a>
  16700. *
  16701. * <span class="image_caption">
  16702. * Click on the image above to link to the
  16703. * <a href="https://www.google.com/design/icons/#ic_accessibility" target="_blank">Material Design Icon-Selector</a>.
  16704. * </span>
  16705. *
  16706. * @param {string} md-font-icon String name of CSS icon associated with the font-face will be used
  16707. * to render the icon. Requires the fonts and the named CSS styles to be preloaded.
  16708. * @param {string} md-font-set CSS style name associated with the font library; which will be assigned as
  16709. * the class for the font-icon ligature. This value may also be an alias that is used to lookup the classname;
  16710. * internally use `$mdIconProvider.fontSet(<alias>)` to determine the style name.
  16711. * @param {string} md-svg-src String URL (or expression) used to load, cache, and display an
  16712. * external SVG.
  16713. * @param {string} md-svg-icon md-svg-icon String name used for lookup of the icon from the internal cache;
  16714. * interpolated strings or expressions may also be used. Specific set names can be used with
  16715. * the syntax `<set name>:<icon name>`.<br/><br/>
  16716. * To use icon sets, developers are required to pre-register the sets using the `$mdIconProvider` service.
  16717. * @param {string=} aria-label Labels icon for accessibility. If an empty string is provided, icon
  16718. * will be hidden from accessibility layer with `aria-hidden="true"`. If there's no aria-label on the icon
  16719. * nor a label on the parent element, a warning will be logged to the console.
  16720. * @param {string=} alt Labels icon for accessibility. If an empty string is provided, icon
  16721. * will be hidden from accessibility layer with `aria-hidden="true"`. If there's no alt on the icon
  16722. * nor a label on the parent element, a warning will be logged to the console.
  16723. *
  16724. * @usage
  16725. * When using SVGs:
  16726. * <hljs lang="html">
  16727. *
  16728. * <!-- Icon ID; may contain optional icon set prefix; icons must registered using $mdIconProvider -->
  16729. * <md-icon md-svg-icon="social:android" aria-label="android " ></md-icon>
  16730. *
  16731. * <!-- Icon urls; may be preloaded in templateCache -->
  16732. * <md-icon md-svg-src="/android.svg" aria-label="android " ></md-icon>
  16733. * <md-icon md-svg-src="{{ getAndroid() }}" aria-label="android " ></md-icon>
  16734. *
  16735. * </hljs>
  16736. *
  16737. * Use the <code>$mdIconProvider</code> to configure your application with
  16738. * svg iconsets.
  16739. *
  16740. * <hljs lang="js">
  16741. * angular.module('appSvgIconSets', ['ngMaterial'])
  16742. * .controller('DemoCtrl', function($scope) {})
  16743. * .config(function($mdIconProvider) {
  16744. * $mdIconProvider
  16745. * .iconSet('social', 'img/icons/sets/social-icons.svg', 24)
  16746. * .defaultIconSet('img/icons/sets/core-icons.svg', 24);
  16747. * });
  16748. * </hljs>
  16749. *
  16750. *
  16751. * When using Font Icons with classnames:
  16752. * <hljs lang="html">
  16753. *
  16754. * <md-icon md-font-icon="android" aria-label="android" ></md-icon>
  16755. * <md-icon class="icon_home" aria-label="Home" ></md-icon>
  16756. *
  16757. * </hljs>
  16758. *
  16759. * When using Material Font Icons with ligatures:
  16760. * <hljs lang="html">
  16761. * <!-- For Material Design Icons -->
  16762. * <!-- The class '.material-icons' is auto-added if a style has NOT been specified -->
  16763. * <md-icon> face </md-icon>
  16764. * <md-icon md-font-set="material-icons"> face </md-icon>
  16765. * <md-icon> #xE87C; </md-icon>
  16766. * <!-- The class '.material-icons' must be manually added if other styles are also specified-->
  16767. * <md-icon class="material-icons md-light md-48"> face </md-icon>
  16768. * </hljs>
  16769. *
  16770. * When using other Font-Icon libraries:
  16771. *
  16772. * <hljs lang="js">
  16773. * // Specify a font-icon style alias
  16774. * angular.config(function($mdIconProvider) {
  16775. * $mdIconProvider.fontSet('fa', 'fontawesome');
  16776. * });
  16777. * </hljs>
  16778. *
  16779. * <hljs lang="html">
  16780. * <md-icon md-font-set="fa">email</md-icon>
  16781. * </hljs>
  16782. *
  16783. */
  16784. function mdIconDirective($mdIcon, $mdTheming, $mdAria ) {
  16785. return {
  16786. scope: {
  16787. fontSet : '@mdFontSet',
  16788. fontIcon: '@mdFontIcon',
  16789. svgIcon : '@mdSvgIcon',
  16790. svgSrc : '@mdSvgSrc'
  16791. },
  16792. restrict: 'E',
  16793. link : postLink
  16794. };
  16795. /**
  16796. * Directive postLink
  16797. * Supports embedded SVGs, font-icons, & external SVGs
  16798. */
  16799. function postLink(scope, element, attr) {
  16800. $mdTheming(element);
  16801. prepareForFontIcon();
  16802. // If using a font-icon, then the textual name of the icon itself
  16803. // provides the aria-label.
  16804. var label = attr.alt || scope.fontIcon || scope.svgIcon || element.text();
  16805. var attrName = attr.$normalize(attr.$attr.mdSvgIcon || attr.$attr.mdSvgSrc || '');
  16806. if ( !attr['aria-label'] ) {
  16807. if (label != '' && !parentsHaveText() ) {
  16808. $mdAria.expect(element, 'aria-label', label);
  16809. $mdAria.expect(element, 'role', 'img');
  16810. } else if ( !element.text() ) {
  16811. // If not a font-icon with ligature, then
  16812. // hide from the accessibility layer.
  16813. $mdAria.expect(element, 'aria-hidden', 'true');
  16814. }
  16815. }
  16816. if (attrName) {
  16817. // Use either pre-configured SVG or URL source, respectively.
  16818. attr.$observe(attrName, function(attrVal) {
  16819. element.empty();
  16820. if (attrVal) {
  16821. $mdIcon(attrVal).then(function(svg) {
  16822. element.append(svg);
  16823. });
  16824. }
  16825. });
  16826. }
  16827. function parentsHaveText() {
  16828. var parent = element.parent();
  16829. if (parent.attr('aria-label') || parent.text()) {
  16830. return true;
  16831. }
  16832. else if(parent.parent().attr('aria-label') || parent.parent().text()) {
  16833. return true;
  16834. }
  16835. return false;
  16836. }
  16837. function prepareForFontIcon() {
  16838. if (!scope.svgIcon && !scope.svgSrc) {
  16839. if (scope.fontIcon) {
  16840. element.addClass('md-font ' + scope.fontIcon);
  16841. }
  16842. element.addClass($mdIcon.fontSet(scope.fontSet));
  16843. }
  16844. }
  16845. }
  16846. }
  16847. })();
  16848. (function(){
  16849. "use strict";
  16850. angular
  16851. .module('material.components.icon' )
  16852. .provider('$mdIcon', MdIconProvider);
  16853. /**
  16854. * @ngdoc service
  16855. * @name $mdIconProvider
  16856. * @module material.components.icon
  16857. *
  16858. * @description
  16859. * `$mdIconProvider` is used only to register icon IDs with URLs. These configuration features allow
  16860. * icons and icon sets to be pre-registered and associated with source URLs **before** the `<md-icon />`
  16861. * directives are compiled.
  16862. *
  16863. * If using font-icons, the developer is responsible for loading the fonts.
  16864. *
  16865. * If using SVGs, loading of the actual svg files are deferred to on-demand requests and are loaded
  16866. * internally by the `$mdIcon` service using the `$http` service. When an SVG is requested by name/ID,
  16867. * the `$mdIcon` service searches its registry for the associated source URL;
  16868. * that URL is used to on-demand load and parse the SVG dynamically.
  16869. *
  16870. * @usage
  16871. * <hljs lang="js">
  16872. * app.config(function($mdIconProvider) {
  16873. *
  16874. * // Configure URLs for icons specified by [set:]id.
  16875. *
  16876. * $mdIconProvider
  16877. * .defaultFontSet( 'fontawesome' )
  16878. * .defaultIconSet('my/app/icons.svg') // Register a default set of SVG icons
  16879. * .iconSet('social', 'my/app/social.svg') // Register a named icon set of SVGs
  16880. * .icon('android', 'my/app/android.svg') // Register a specific icon (by name)
  16881. * .icon('work:chair', 'my/app/chair.svg'); // Register icon in a specific set
  16882. * });
  16883. * </hljs>
  16884. *
  16885. * SVG icons and icon sets can be easily pre-loaded and cached using either (a) a build process or (b) a runtime
  16886. * **startup** process (shown below):
  16887. *
  16888. * <hljs lang="js">
  16889. * app.config(function($mdIconProvider) {
  16890. *
  16891. * // Register a default set of SVG icon definitions
  16892. * $mdIconProvider.defaultIconSet('my/app/icons.svg')
  16893. *
  16894. * })
  16895. * .run(function($http, $templateCache){
  16896. *
  16897. * // Pre-fetch icons sources by URL and cache in the $templateCache...
  16898. * // subsequent $http calls will look there first.
  16899. *
  16900. * var urls = [ 'imy/app/icons.svg', 'img/icons/android.svg'];
  16901. *
  16902. * angular.forEach(urls, function(url) {
  16903. * $http.get(url, {cache: $templateCache});
  16904. * });
  16905. *
  16906. * });
  16907. *
  16908. * </hljs>
  16909. *
  16910. * NOTE: the loaded SVG data is subsequently cached internally for future requests.
  16911. *
  16912. */
  16913. /**
  16914. * @ngdoc method
  16915. * @name $mdIconProvider#icon
  16916. *
  16917. * @description
  16918. * Register a source URL for a specific icon name; the name may include optional 'icon set' name prefix.
  16919. * These icons will later be retrieved from the cache using `$mdIcon( <icon name> )`
  16920. *
  16921. * @param {string} id Icon name/id used to register the icon
  16922. * @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
  16923. * data or as part of the lookup in `$templateCache` if pre-loading was configured.
  16924. * @param {number=} viewBoxSize Sets the width and height the icon's viewBox.
  16925. * It is ignored for icons with an existing viewBox. Default size is 24.
  16926. *
  16927. * @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
  16928. *
  16929. * @usage
  16930. * <hljs lang="js">
  16931. * app.config(function($mdIconProvider) {
  16932. *
  16933. * // Configure URLs for icons specified by [set:]id.
  16934. *
  16935. * $mdIconProvider
  16936. * .icon('android', 'my/app/android.svg') // Register a specific icon (by name)
  16937. * .icon('work:chair', 'my/app/chair.svg'); // Register icon in a specific set
  16938. * });
  16939. * </hljs>
  16940. *
  16941. */
  16942. /**
  16943. * @ngdoc method
  16944. * @name $mdIconProvider#iconSet
  16945. *
  16946. * @description
  16947. * Register a source URL for a 'named' set of icons; group of SVG definitions where each definition
  16948. * has an icon id. Individual icons can be subsequently retrieved from this cached set using
  16949. * `$mdIcon(<icon set name>:<icon name>)`
  16950. *
  16951. * @param {string} id Icon name/id used to register the iconset
  16952. * @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
  16953. * data or as part of the lookup in `$templateCache` if pre-loading was configured.
  16954. * @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
  16955. * It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
  16956. * Default value is 24.
  16957. *
  16958. * @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
  16959. *
  16960. *
  16961. * @usage
  16962. * <hljs lang="js">
  16963. * app.config(function($mdIconProvider) {
  16964. *
  16965. * // Configure URLs for icons specified by [set:]id.
  16966. *
  16967. * $mdIconProvider
  16968. * .iconSet('social', 'my/app/social.svg') // Register a named icon set
  16969. * });
  16970. * </hljs>
  16971. *
  16972. */
  16973. /**
  16974. * @ngdoc method
  16975. * @name $mdIconProvider#defaultIconSet
  16976. *
  16977. * @description
  16978. * Register a source URL for the default 'named' set of icons. Unless explicitly registered,
  16979. * subsequent lookups of icons will failover to search this 'default' icon set.
  16980. * Icon can be retrieved from this cached, default set using `$mdIcon(<name>)`
  16981. *
  16982. * @param {string} url specifies the external location for the data file. Used internally by `$http` to load the
  16983. * data or as part of the lookup in `$templateCache` if pre-loading was configured.
  16984. * @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
  16985. * It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
  16986. * Default value is 24.
  16987. *
  16988. * @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
  16989. *
  16990. * @usage
  16991. * <hljs lang="js">
  16992. * app.config(function($mdIconProvider) {
  16993. *
  16994. * // Configure URLs for icons specified by [set:]id.
  16995. *
  16996. * $mdIconProvider
  16997. * .defaultIconSet( 'my/app/social.svg' ) // Register a default icon set
  16998. * });
  16999. * </hljs>
  17000. *
  17001. */
  17002. /**
  17003. * @ngdoc method
  17004. * @name $mdIconProvider#defaultFontSet
  17005. *
  17006. * @description
  17007. * When using Font-Icons, Angular Material assumes the the Material Design icons will be used and automatically
  17008. * configures the default font-set == 'material-icons'. Note that the font-set references the font-icon library
  17009. * class style that should be applied to the `<md-icon>`.
  17010. *
  17011. * Configuring the default means that the attributes
  17012. * `md-font-set="material-icons"` or `class="material-icons"` do not need to be explicitly declared on the
  17013. * `<md-icon>` markup. For example:
  17014. *
  17015. * `<md-icon> face </md-icon>`
  17016. * will render as
  17017. * `<span class="material-icons"> face </span>`, and
  17018. *
  17019. * `<md-icon md-font-set="fa"> face </md-icon>`
  17020. * will render as
  17021. * `<span class="fa"> face </span>`
  17022. *
  17023. * @param {string} name of the font-library style that should be applied to the md-icon DOM element
  17024. *
  17025. * @usage
  17026. * <hljs lang="js">
  17027. * app.config(function($mdIconProvider) {
  17028. * $mdIconProvider.defaultFontSet( 'fontawesome' );
  17029. * });
  17030. * </hljs>
  17031. *
  17032. */
  17033. /**
  17034. * @ngdoc method
  17035. * @name $mdIconProvider#defaultViewBoxSize
  17036. *
  17037. * @description
  17038. * While `<md-icon />` markup can also be style with sizing CSS, this method configures
  17039. * the default width **and** height used for all icons; unless overridden by specific CSS.
  17040. * The default sizing is (24px, 24px).
  17041. * @param {number=} viewBoxSize Sets the width and height of the viewBox for an icon or an icon set.
  17042. * All icons in a set should be the same size. The default value is 24.
  17043. *
  17044. * @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
  17045. *
  17046. * @usage
  17047. * <hljs lang="js">
  17048. * app.config(function($mdIconProvider) {
  17049. *
  17050. * // Configure URLs for icons specified by [set:]id.
  17051. *
  17052. * $mdIconProvider
  17053. * .defaultViewBoxSize(36) // Register a default icon size (width == height)
  17054. * });
  17055. * </hljs>
  17056. *
  17057. */
  17058. var config = {
  17059. defaultViewBoxSize: 24,
  17060. defaultFontSet: 'material-icons',
  17061. fontSets : [ ]
  17062. };
  17063. function MdIconProvider() { }
  17064. MdIconProvider.prototype = {
  17065. icon : function (id, url, viewBoxSize) {
  17066. if ( id.indexOf(':') == -1 ) id = '$default:' + id;
  17067. config[id] = new ConfigurationItem(url, viewBoxSize );
  17068. return this;
  17069. },
  17070. iconSet : function (id, url, viewBoxSize) {
  17071. config[id] = new ConfigurationItem(url, viewBoxSize );
  17072. return this;
  17073. },
  17074. defaultIconSet : function (url, viewBoxSize) {
  17075. var setName = '$default';
  17076. if ( !config[setName] ) {
  17077. config[setName] = new ConfigurationItem(url, viewBoxSize );
  17078. }
  17079. config[setName].viewBoxSize = viewBoxSize || config.defaultViewBoxSize;
  17080. return this;
  17081. },
  17082. defaultViewBoxSize : function (viewBoxSize) {
  17083. config.defaultViewBoxSize = viewBoxSize;
  17084. return this;
  17085. },
  17086. /**
  17087. * Register an alias name associated with a font-icon library style ;
  17088. */
  17089. fontSet : function fontSet(alias, className) {
  17090. config.fontSets.push({
  17091. alias : alias,
  17092. fontSet : className || alias
  17093. });
  17094. return this;
  17095. },
  17096. /**
  17097. * Specify a default style name associated with a font-icon library
  17098. * fallback to Material Icons.
  17099. *
  17100. */
  17101. defaultFontSet : function defaultFontSet(className) {
  17102. config.defaultFontSet = !className ? '' : className;
  17103. return this;
  17104. },
  17105. defaultIconSize : function defaultIconSize(iconSize) {
  17106. config.defaultIconSize = iconSize;
  17107. return this;
  17108. },
  17109. preloadIcons: function ($templateCache) {
  17110. var iconProvider = this;
  17111. var svgRegistry = [
  17112. {
  17113. id : 'md-tabs-arrow',
  17114. url: 'md-tabs-arrow.svg',
  17115. 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>'
  17116. },
  17117. {
  17118. id : 'md-close',
  17119. url: 'md-close.svg',
  17120. 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>'
  17121. },
  17122. {
  17123. id: 'md-cancel',
  17124. url: 'md-cancel.svg',
  17125. 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>'
  17126. },
  17127. {
  17128. id: 'md-menu',
  17129. url: 'md-menu.svg',
  17130. svg: '<svg version="1.1" x="0px" y="0px" viewBox="0 0 24 24"><path d="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z" /></svg>'
  17131. },
  17132. {
  17133. id: 'md-toggle-arrow',
  17134. url: 'md-toggle-arrow-svg',
  17135. 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>'
  17136. },
  17137. {
  17138. id: 'md-calendar',
  17139. url: 'md-calendar.svg',
  17140. 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>'
  17141. }
  17142. ];
  17143. svgRegistry.forEach(function(asset){
  17144. iconProvider.icon(asset.id, asset.url);
  17145. $templateCache.put(asset.url, asset.svg);
  17146. });
  17147. },
  17148. $get : ['$http', '$q', '$log', '$templateCache', function($http, $q, $log, $templateCache) {
  17149. this.preloadIcons($templateCache);
  17150. return MdIconService(config, $http, $q, $log, $templateCache);
  17151. }]
  17152. };
  17153. /**
  17154. * Configuration item stored in the Icon registry; used for lookups
  17155. * to load if not already cached in the `loaded` cache
  17156. */
  17157. function ConfigurationItem(url, viewBoxSize) {
  17158. this.url = url;
  17159. this.viewBoxSize = viewBoxSize || config.defaultViewBoxSize;
  17160. }
  17161. /**
  17162. * @ngdoc service
  17163. * @name $mdIcon
  17164. * @module material.components.icon
  17165. *
  17166. * @description
  17167. * The `$mdIcon` service is a function used to lookup SVG icons.
  17168. *
  17169. * @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
  17170. * 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
  17171. * performed. The Id may be a unique icon ID or may include an iconSet ID prefix.
  17172. *
  17173. * For the **id** query to work properly, this means that all id-to-URL mappings must have been previously configured
  17174. * using the `$mdIconProvider`.
  17175. *
  17176. * @returns {obj} Clone of the initial SVG DOM element; which was created from the SVG markup in the SVG data file.
  17177. *
  17178. * @usage
  17179. * <hljs lang="js">
  17180. * function SomeDirective($mdIcon) {
  17181. *
  17182. * // See if the icon has already been loaded, if not
  17183. * // then lookup the icon from the registry cache, load and cache
  17184. * // it for future requests.
  17185. * // NOTE: ID queries require configuration with $mdIconProvider
  17186. *
  17187. * $mdIcon('android').then(function(iconEl) { element.append(iconEl); });
  17188. * $mdIcon('work:chair').then(function(iconEl) { element.append(iconEl); });
  17189. *
  17190. * // Load and cache the external SVG using a URL
  17191. *
  17192. * $mdIcon('img/icons/android.svg').then(function(iconEl) {
  17193. * element.append(iconEl);
  17194. * });
  17195. * };
  17196. * </hljs>
  17197. *
  17198. * NOTE: The `<md-icon /> ` directive internally uses the `$mdIcon` service to query, loaded, and instantiate
  17199. * SVG DOM elements.
  17200. */
  17201. /* @ngInject */
  17202. function MdIconService(config, $http, $q, $log, $templateCache) {
  17203. var iconCache = {};
  17204. var urlRegex = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/i;
  17205. Icon.prototype = { clone : cloneSVG, prepare: prepareAndStyle };
  17206. getIcon.fontSet = findRegisteredFontSet;
  17207. // Publish service...
  17208. return getIcon;
  17209. /**
  17210. * Actual $mdIcon service is essentially a lookup function
  17211. */
  17212. function getIcon(id) {
  17213. id = id || '';
  17214. // If already loaded and cached, use a clone of the cached icon.
  17215. // Otherwise either load by URL, or lookup in the registry and then load by URL, and cache.
  17216. if ( iconCache[id] ) return $q.when( iconCache[id].clone() );
  17217. if ( urlRegex.test(id) ) return loadByURL(id).then( cacheIcon(id) );
  17218. if ( id.indexOf(':') == -1 ) id = '$default:' + id;
  17219. var load = config[id] ? loadByID : loadFromIconSet;
  17220. return load(id)
  17221. .then( cacheIcon(id) );
  17222. }
  17223. /**
  17224. * Lookup registered fontSet style using its alias...
  17225. * If not found,
  17226. */
  17227. function findRegisteredFontSet(alias) {
  17228. var useDefault = angular.isUndefined(alias) || !(alias && alias.length);
  17229. if ( useDefault ) return config.defaultFontSet;
  17230. var result = alias;
  17231. angular.forEach(config.fontSets, function(it){
  17232. if ( it.alias == alias ) result = it.fontSet || result;
  17233. });
  17234. return result;
  17235. }
  17236. /**
  17237. * Prepare and cache the loaded icon for the specified `id`
  17238. */
  17239. function cacheIcon( id ) {
  17240. return function updateCache( icon ) {
  17241. iconCache[id] = isIcon(icon) ? icon : new Icon(icon, config[id]);
  17242. return iconCache[id].clone();
  17243. };
  17244. }
  17245. /**
  17246. * Lookup the configuration in the registry, if !registered throw an error
  17247. * otherwise load the icon [on-demand] using the registered URL.
  17248. *
  17249. */
  17250. function loadByID(id) {
  17251. var iconConfig = config[id];
  17252. return loadByURL(iconConfig.url).then(function(icon) {
  17253. return new Icon(icon, iconConfig);
  17254. });
  17255. }
  17256. /**
  17257. * Loads the file as XML and uses querySelector( <id> ) to find
  17258. * the desired node...
  17259. */
  17260. function loadFromIconSet(id) {
  17261. var setName = id.substring(0, id.lastIndexOf(':')) || '$default';
  17262. var iconSetConfig = config[setName];
  17263. return !iconSetConfig ? announceIdNotFound(id) : loadByURL(iconSetConfig.url).then(extractFromSet);
  17264. function extractFromSet(set) {
  17265. var iconName = id.slice(id.lastIndexOf(':') + 1);
  17266. var icon = set.querySelector('#' + iconName);
  17267. return !icon ? announceIdNotFound(id) : new Icon(icon, iconSetConfig);
  17268. }
  17269. function announceIdNotFound(id) {
  17270. var msg = 'icon ' + id + ' not found';
  17271. $log.warn(msg);
  17272. return $q.reject(msg || id);
  17273. }
  17274. }
  17275. /**
  17276. * Load the icon by URL (may use the $templateCache).
  17277. * Extract the data for later conversion to Icon
  17278. */
  17279. function loadByURL(url) {
  17280. return $http
  17281. .get(url, { cache: $templateCache })
  17282. .then(function(response) {
  17283. return angular.element('<div>').append(response.data).find('svg')[0];
  17284. }).catch(announceNotFound);
  17285. }
  17286. /**
  17287. * Catch HTTP or generic errors not related to incorrect icon IDs.
  17288. */
  17289. function announceNotFound(err) {
  17290. var msg = angular.isString(err) ? err : (err.message || err.data || err.statusText);
  17291. $log.warn(msg);
  17292. return $q.reject(msg);
  17293. }
  17294. /**
  17295. * Check target signature to see if it is an Icon instance.
  17296. */
  17297. function isIcon(target) {
  17298. return angular.isDefined(target.element) && angular.isDefined(target.config);
  17299. }
  17300. /**
  17301. * Define the Icon class
  17302. */
  17303. function Icon(el, config) {
  17304. if (el && el.tagName != 'svg') {
  17305. el = angular.element('<svg xmlns="http://www.w3.org/2000/svg">').append(el)[0];
  17306. }
  17307. // Inject the namespace if not available...
  17308. if ( !el.getAttribute('xmlns') ) {
  17309. el.setAttribute('xmlns', "http://www.w3.org/2000/svg");
  17310. }
  17311. this.element = el;
  17312. this.config = config;
  17313. this.prepare();
  17314. }
  17315. /**
  17316. * Prepare the DOM element that will be cached in the
  17317. * loaded iconCache store.
  17318. */
  17319. function prepareAndStyle() {
  17320. var viewBoxSize = this.config ? this.config.viewBoxSize : config.defaultViewBoxSize;
  17321. angular.forEach({
  17322. 'fit' : '',
  17323. 'height': '100%',
  17324. 'width' : '100%',
  17325. 'preserveAspectRatio': 'xMidYMid meet',
  17326. 'viewBox' : this.element.getAttribute('viewBox') || ('0 0 ' + viewBoxSize + ' ' + viewBoxSize)
  17327. }, function(val, attr) {
  17328. this.element.setAttribute(attr, val);
  17329. }, this);
  17330. angular.forEach({
  17331. 'pointer-events' : 'none',
  17332. 'display' : 'block'
  17333. }, function(val, style) {
  17334. this.element.style[style] = val;
  17335. }, this);
  17336. }
  17337. /**
  17338. * Clone the Icon DOM element.
  17339. */
  17340. function cloneSVG(){
  17341. return this.element.cloneNode(true);
  17342. }
  17343. }
  17344. MdIconService.$inject = ["config", "$http", "$q", "$log", "$templateCache"];
  17345. })();
  17346. (function(){
  17347. "use strict";
  17348. angular
  17349. .module('material.components.menu')
  17350. .controller('mdMenuCtrl', MenuController);
  17351. /**
  17352. * @ngInject
  17353. */
  17354. function MenuController($mdMenu, $attrs, $element, $scope, $mdUtil, $timeout) {
  17355. var menuContainer;
  17356. var self = this;
  17357. var triggerElement;
  17358. this.nestLevel = parseInt($attrs.mdNestLevel, 10) || 0;
  17359. /**
  17360. * Called by our linking fn to provide access to the menu-content
  17361. * element removed during link
  17362. */
  17363. this.init = function init(setMenuContainer, opts) {
  17364. opts = opts || {};
  17365. menuContainer = setMenuContainer;
  17366. // Default element for ARIA attributes has the ngClick or ngMouseenter expression
  17367. triggerElement = $element[0].querySelector('[ng-click],[ng-mouseenter]');
  17368. this.isInMenuBar = opts.isInMenuBar;
  17369. this.nestedMenus = $mdUtil.nodesToArray(menuContainer[0].querySelectorAll('.md-nested-menu'));
  17370. this.enableHoverListener();
  17371. menuContainer.on('$mdInterimElementRemove', function() {
  17372. self.isOpen = false;
  17373. });
  17374. };
  17375. this.enableHoverListener = function() {
  17376. $scope.$on('$mdMenuOpen', function(event, el) {
  17377. if (menuContainer[0].contains(el[0])) {
  17378. self.currentlyOpenMenu = el.controller('mdMenu');
  17379. self.isAlreadyOpening = false;
  17380. self.currentlyOpenMenu.registerContainerProxy(self.triggerContainerProxy.bind(self));
  17381. }
  17382. });
  17383. $scope.$on('$mdMenuClose', function(event, el) {
  17384. if (menuContainer[0].contains(el[0])) {
  17385. self.currentlyOpenMenu = undefined;
  17386. }
  17387. });
  17388. var menuItems = angular.element($mdUtil.nodesToArray(menuContainer[0].querySelectorAll('md-menu-item')));
  17389. var openMenuTimeout;
  17390. menuItems.on('mouseenter', function(event) {
  17391. if (self.isAlreadyOpening) return;
  17392. var nestedMenu = (
  17393. event.target.querySelector('md-menu')
  17394. || $mdUtil.getClosest(event.target, 'MD-MENU')
  17395. );
  17396. openMenuTimeout = $timeout(function() {
  17397. if (nestedMenu) {
  17398. nestedMenu = angular.element(nestedMenu).controller('mdMenu');
  17399. }
  17400. if (self.currentlyOpenMenu && self.currentlyOpenMenu != nestedMenu) {
  17401. var closeTo = self.nestLevel + 1;
  17402. self.currentlyOpenMenu.close(true, { closeTo: closeTo });
  17403. } else if (nestedMenu && !nestedMenu.isOpen && nestedMenu.open) {
  17404. self.isAlreadyOpening = true;
  17405. nestedMenu.open();
  17406. }
  17407. }, nestedMenu ? 100 : 250);
  17408. var focusableTarget = event.currentTarget.querySelector('button:not([disabled])');
  17409. focusableTarget && focusableTarget.focus();
  17410. });
  17411. menuItems.on('mouseleave', function(event) {
  17412. if (openMenuTimeout) {
  17413. $timeout.cancel(openMenuTimeout);
  17414. openMenuTimeout = undefined;
  17415. }
  17416. });
  17417. };
  17418. /**
  17419. * Uses the $mdMenu interim element service to open the menu contents
  17420. */
  17421. this.open = function openMenu(ev) {
  17422. ev && ev.stopPropagation();
  17423. ev && ev.preventDefault();
  17424. if (self.isOpen) return;
  17425. self.isOpen = true;
  17426. triggerElement = triggerElement || (ev ? ev.target : $element[0]);
  17427. $scope.$emit('$mdMenuOpen', $element);
  17428. $mdMenu.show({
  17429. scope: $scope,
  17430. mdMenuCtrl: self,
  17431. nestLevel: self.nestLevel,
  17432. element: menuContainer,
  17433. target: triggerElement,
  17434. preserveElement: self.isInMenuBar || self.nestedMenus.length > 0,
  17435. parent: self.isInMenuBar ? $element : 'body'
  17436. });
  17437. };
  17438. // Expose a open function to the child scope for html to use
  17439. $scope.$mdOpenMenu = this.open;
  17440. $scope.$watch(function() { return self.isOpen; }, function(isOpen) {
  17441. if (isOpen) {
  17442. triggerElement.setAttribute('aria-expanded', 'true');
  17443. $element[0].classList.add('md-open');
  17444. angular.forEach(self.nestedMenus, function(el) {
  17445. el.classList.remove('md-open');
  17446. });
  17447. } else {
  17448. triggerElement && triggerElement.setAttribute('aria-expanded', 'false');
  17449. $element[0].classList.remove('md-open');
  17450. }
  17451. $scope.$mdMenuIsOpen = self.isOpen;
  17452. });
  17453. this.focusMenuContainer = function focusMenuContainer() {
  17454. var focusTarget = menuContainer[0].querySelector('[md-menu-focus-target]');
  17455. if (!focusTarget) focusTarget = menuContainer[0].querySelector('.md-button');
  17456. focusTarget.focus();
  17457. };
  17458. this.registerContainerProxy = function registerContainerProxy(handler) {
  17459. this.containerProxy = handler;
  17460. };
  17461. this.triggerContainerProxy = function triggerContainerProxy(ev) {
  17462. this.containerProxy && this.containerProxy(ev);
  17463. };
  17464. this.destroy = function() {
  17465. return $mdMenu.destroy();
  17466. };
  17467. // Use the $mdMenu interim element service to close the menu contents
  17468. this.close = function closeMenu(skipFocus, closeOpts) {
  17469. if ( !self.isOpen ) return;
  17470. self.isOpen = false;
  17471. var eventDetails = angular.extend({}, closeOpts, { skipFocus: skipFocus });
  17472. $scope.$emit('$mdMenuClose', $element, eventDetails);
  17473. $mdMenu.hide(null, closeOpts);
  17474. if (!skipFocus) {
  17475. var el = self.restoreFocusTo || $element.find('button')[0];
  17476. if (el instanceof angular.element) el = el[0];
  17477. if (el) el.focus();
  17478. }
  17479. };
  17480. /**
  17481. * Build a nice object out of our string attribute which specifies the
  17482. * target mode for left and top positioning
  17483. */
  17484. this.positionMode = function positionMode() {
  17485. var attachment = ($attrs.mdPositionMode || 'target').split(' ');
  17486. // If attachment is a single item, duplicate it for our second value.
  17487. // ie. 'target' -> 'target target'
  17488. if (attachment.length == 1) {
  17489. attachment.push(attachment[0]);
  17490. }
  17491. return {
  17492. left: attachment[0],
  17493. top: attachment[1]
  17494. };
  17495. }
  17496. /**
  17497. * Build a nice object out of our string attribute which specifies
  17498. * the offset of top and left in pixels.
  17499. */
  17500. this.offsets = function offsets() {
  17501. var position = ($attrs.mdOffset || '0 0').split(' ').map(parseFloat);
  17502. if (position.length == 2) {
  17503. return {
  17504. left: position[0],
  17505. top: position[1]
  17506. };
  17507. } else if (position.length == 1) {
  17508. return {
  17509. top: position[0],
  17510. left: position[0]
  17511. };
  17512. } else {
  17513. throw Error('Invalid offsets specified. Please follow format <x, y> or <n>');
  17514. }
  17515. }
  17516. }
  17517. MenuController.$inject = ["$mdMenu", "$attrs", "$element", "$scope", "$mdUtil", "$timeout"];
  17518. })();
  17519. (function(){
  17520. "use strict";
  17521. /**
  17522. * @ngdoc directive
  17523. * @name mdMenu
  17524. * @module material.components.menu
  17525. * @restrict E
  17526. * @description
  17527. *
  17528. * Menus are elements that open when clicked. They are useful for displaying
  17529. * additional options within the context of an action.
  17530. *
  17531. * Every `md-menu` must specify exactly two child elements. The first element is what is
  17532. * left in the DOM and is used to open the menu. This element is called the trigger element.
  17533. * The trigger element's scope has access to `$mdOpenMenu($event)`
  17534. * which it may call to open the menu. By passing $event as argument, the
  17535. * corresponding event is stopped from propagating up the DOM-tree.
  17536. *
  17537. * The second element is the `md-menu-content` element which represents the
  17538. * contents of the menu when it is open. Typically this will contain `md-menu-item`s,
  17539. * but you can do custom content as well.
  17540. *
  17541. * <hljs lang="html">
  17542. * <md-menu>
  17543. * <!-- Trigger element is a md-button with an icon -->
  17544. * <md-button ng-click="$mdOpenMenu($event)" class="md-icon-button" aria-label="Open sample menu">
  17545. * <md-icon md-svg-icon="call:phone"></md-icon>
  17546. * </md-button>
  17547. * <md-menu-content>
  17548. * <md-menu-item><md-button ng-click="doSomething()">Do Something</md-button></md-menu-item>
  17549. * </md-menu-content>
  17550. * </md-menu>
  17551. * </hljs>
  17552. * ## Sizing Menus
  17553. *
  17554. * The width of the menu when it is open may be specified by specifying a `width`
  17555. * attribute on the `md-menu-content` element.
  17556. * See the [Material Design Spec](http://www.google.com/design/spec/components/menus.html#menus-specs)
  17557. * for more information.
  17558. *
  17559. *
  17560. * ## Aligning Menus
  17561. *
  17562. * When a menu opens, it is important that the content aligns with the trigger element.
  17563. * Failure to align menus can result in jarring experiences for users as content
  17564. * suddenly shifts. To help with this, `md-menu` provides serveral APIs to help
  17565. * with alignment.
  17566. *
  17567. * ### Target Mode
  17568. *
  17569. * By default, `md-menu` will attempt to align the `md-menu-content` by aligning
  17570. * designated child elements in both the trigger and the menu content.
  17571. *
  17572. * To specify the alignment element in the `trigger` you can use the `md-menu-origin`
  17573. * attribute on a child element. If no `md-menu-origin` is specified, the `md-menu`
  17574. * will be used as the origin element.
  17575. *
  17576. * Similarly, the `md-menu-content` may specify a `md-menu-align-target` for a
  17577. * `md-menu-item` to specify the node that it should try and align with.
  17578. *
  17579. * In this example code, we specify an icon to be our origin element, and an
  17580. * icon in our menu content to be our alignment target. This ensures that both
  17581. * icons are aligned when the menu opens.
  17582. *
  17583. * <hljs lang="html">
  17584. * <md-menu>
  17585. * <md-button ng-click="$mdOpenMenu($event)" class="md-icon-button" aria-label="Open some menu">
  17586. * <md-icon md-menu-origin md-svg-icon="call:phone"></md-icon>
  17587. * </md-button>
  17588. * <md-menu-content>
  17589. * <md-menu-item>
  17590. * <md-button ng-click="doSomething()" aria-label="Do something">
  17591. * <md-icon md-menu-align-target md-svg-icon="call:phone"></md-icon>
  17592. * Do Something
  17593. * </md-button>
  17594. * </md-menu-item>
  17595. * </md-menu-content>
  17596. * </md-menu>
  17597. * </hljs>
  17598. *
  17599. * Sometimes we want to specify alignment on the right side of an element, for example
  17600. * if we have a menu on the right side a toolbar, we want to right align our menu content.
  17601. *
  17602. * We can specify the origin by using the `md-position-mode` attribute on both
  17603. * the `x` and `y` axis. Right now only the `x-axis` has more than one option.
  17604. * You may specify the default mode of `target target` or
  17605. * `target-right target` to specify a right-oriented alignment target. See the
  17606. * position section of the demos for more examples.
  17607. *
  17608. * ### Menu Offsets
  17609. *
  17610. * It is sometimes unavoidable to need to have a deeper level of control for
  17611. * the positioning of a menu to ensure perfect alignment. `md-menu` provides
  17612. * the `md-offset` attribute to allow pixel level specificty of adjusting the
  17613. * exact positioning.
  17614. *
  17615. * This offset is provided in the format of `x y` or `n` where `n` will be used
  17616. * in both the `x` and `y` axis.
  17617. *
  17618. * For example, to move a menu by `2px` from the top, we can use:
  17619. * <hljs lang="html">
  17620. * <md-menu md-offset="2 0">
  17621. * <!-- menu-content -->
  17622. * </md-menu>
  17623. * </hljs>
  17624. *
  17625. * @usage
  17626. * <hljs lang="html">
  17627. * <md-menu>
  17628. * <md-button ng-click="$mdOpenMenu($event)" class="md-icon-button">
  17629. * <md-icon md-svg-icon="call:phone"></md-icon>
  17630. * </md-button>
  17631. * <md-menu-content>
  17632. * <md-menu-item><md-button ng-click="doSomething()">Do Something</md-button></md-menu-item>
  17633. * </md-menu-content>
  17634. * </md-menu>
  17635. * </hljs>
  17636. *
  17637. * @param {string} md-position-mode The position mode in the form of
  17638. * `x`, `y`. Default value is `target`,`target`. Right now the `x` axis
  17639. * also suppports `target-right`.
  17640. * @param {string} md-offset An offset to apply to the dropdown after positioning
  17641. * `x`, `y`. Default value is `0`,`0`.
  17642. *
  17643. */
  17644. angular
  17645. .module('material.components.menu')
  17646. .directive('mdMenu', MenuDirective);
  17647. /**
  17648. * @ngInject
  17649. */
  17650. function MenuDirective($mdUtil) {
  17651. var INVALID_PREFIX = 'Invalid HTML for md-menu: ';
  17652. return {
  17653. restrict: 'E',
  17654. require: ['mdMenu', '?^mdMenuBar'],
  17655. controller: 'mdMenuCtrl', // empty function to be built by link
  17656. scope: true,
  17657. compile: compile
  17658. };
  17659. function compile(templateElement) {
  17660. templateElement.addClass('md-menu');
  17661. var triggerElement = templateElement.children()[0];
  17662. if (!triggerElement.hasAttribute('ng-click')) {
  17663. triggerElement = triggerElement.querySelector('[ng-click],[ng-mouseenter]') || triggerElement;
  17664. }
  17665. if (triggerElement && (
  17666. triggerElement.nodeName == 'MD-BUTTON' ||
  17667. triggerElement.nodeName == 'BUTTON'
  17668. ) && !triggerElement.hasAttribute('type')) {
  17669. triggerElement.setAttribute('type', 'button');
  17670. }
  17671. if (templateElement.children().length != 2) {
  17672. throw Error(INVALID_PREFIX + 'Expected two children elements.');
  17673. }
  17674. // Default element for ARIA attributes has the ngClick or ngMouseenter expression
  17675. triggerElement && triggerElement.setAttribute('aria-haspopup', 'true');
  17676. var nestedMenus = templateElement[0].querySelectorAll('md-menu');
  17677. var nestingDepth = parseInt(templateElement[0].getAttribute('md-nest-level'), 10) || 0;
  17678. if (nestedMenus) {
  17679. angular.forEach($mdUtil.nodesToArray(nestedMenus), function(menuEl) {
  17680. if (!menuEl.hasAttribute('md-position-mode')) {
  17681. menuEl.setAttribute('md-position-mode', 'cascade');
  17682. }
  17683. menuEl.classList.add('md-nested-menu');
  17684. menuEl.setAttribute('md-nest-level', nestingDepth + 1);
  17685. menuEl.setAttribute('role', 'menu');
  17686. });
  17687. }
  17688. return link;
  17689. }
  17690. function link(scope, element, attrs, ctrls) {
  17691. var mdMenuCtrl = ctrls[0];
  17692. var isInMenuBar = ctrls[1] != undefined;
  17693. // Move everything into a md-menu-container and pass it to the controller
  17694. var menuContainer = angular.element(
  17695. '<div class="md-open-menu-container md-whiteframe-z2"></div>'
  17696. );
  17697. var menuContents = element.children()[1];
  17698. menuContainer.append(menuContents);
  17699. if (isInMenuBar) {
  17700. element.append(menuContainer);
  17701. menuContainer[0].style.display = 'none';
  17702. }
  17703. mdMenuCtrl.init(menuContainer, { isInMenuBar: isInMenuBar });
  17704. scope.$on('$destroy', function() {
  17705. mdMenuCtrl
  17706. .destroy()
  17707. .finally(function(){
  17708. menuContainer.remove();
  17709. });
  17710. });
  17711. }
  17712. }
  17713. MenuDirective.$inject = ["$mdUtil"];
  17714. })();
  17715. (function(){
  17716. "use strict";
  17717. angular
  17718. .module('material.components.menu')
  17719. .provider('$mdMenu', MenuProvider);
  17720. /*
  17721. * Interim element provider for the menu.
  17722. * Handles behavior for a menu while it is open, including:
  17723. * - handling animating the menu opening/closing
  17724. * - handling key/mouse events on the menu element
  17725. * - handling enabling/disabling scroll while the menu is open
  17726. * - handling redrawing during resizes and orientation changes
  17727. *
  17728. */
  17729. function MenuProvider($$interimElementProvider) {
  17730. var MENU_EDGE_MARGIN = 8;
  17731. menuDefaultOptions.$inject = ["$mdUtil", "$mdTheming", "$mdConstant", "$document", "$window", "$q", "$$rAF", "$animateCss", "$animate"];
  17732. return $$interimElementProvider('$mdMenu')
  17733. .setDefaults({
  17734. methods: ['target'],
  17735. options: menuDefaultOptions
  17736. });
  17737. /* @ngInject */
  17738. function menuDefaultOptions($mdUtil, $mdTheming, $mdConstant, $document, $window, $q, $$rAF, $animateCss, $animate) {
  17739. var animator = $mdUtil.dom.animator;
  17740. return {
  17741. parent: 'body',
  17742. onShow: onShow,
  17743. onRemove: onRemove,
  17744. hasBackdrop: true,
  17745. disableParentScroll: true,
  17746. skipCompile: true,
  17747. preserveScope: true,
  17748. skipHide: true,
  17749. themable: true
  17750. };
  17751. /**
  17752. * Show modal backdrop element...
  17753. * @returns {function(): void} A function that removes this backdrop
  17754. */
  17755. function showBackdrop(scope, element, options) {
  17756. if (options.nestLevel) return angular.noop;
  17757. // If we are not within a dialog...
  17758. if (options.disableParentScroll && !$mdUtil.getClosest(options.target, 'MD-DIALOG')) {
  17759. // !! DO this before creating the backdrop; since disableScrollAround()
  17760. // configures the scroll offset; which is used by mdBackDrop postLink()
  17761. options.restoreScroll = $mdUtil.disableScrollAround(options.element, options.parent);
  17762. } else {
  17763. options.disableParentScroll = false;
  17764. }
  17765. if (options.hasBackdrop) {
  17766. options.backdrop = $mdUtil.createBackdrop(scope, "md-menu-backdrop md-click-catcher");
  17767. $animate.enter(options.backdrop, options.parent);
  17768. }
  17769. /**
  17770. * Hide and destroys the backdrop created by showBackdrop()
  17771. */
  17772. return function hideBackdrop() {
  17773. if (options.backdrop) options.backdrop.remove();
  17774. if (options.disableParentScroll) options.restoreScroll();
  17775. };
  17776. }
  17777. /**
  17778. * Removing the menu element from the DOM and remove all associated evetn listeners
  17779. * and backdrop
  17780. */
  17781. function onRemove(scope, element, opts) {
  17782. opts.cleanupInteraction();
  17783. opts.cleanupResizing();
  17784. opts.hideBackdrop();
  17785. // For navigation $destroy events, do a quick, non-animated removal,
  17786. // but for normal closes (from clicks, etc) animate the removal
  17787. return (opts.$destroy === true) ? detachAndClean() : animateRemoval().then( detachAndClean );
  17788. /**
  17789. * For normal closes, animate the removal.
  17790. * For forced closes (like $destroy events), skip the animations
  17791. */
  17792. function animateRemoval() {
  17793. return $animateCss(element, {addClass: 'md-leave'}).start();
  17794. }
  17795. /**
  17796. * Detach the element
  17797. */
  17798. function detachAndClean() {
  17799. element.removeClass('md-active');
  17800. detachElement(element, opts);
  17801. opts.alreadyOpen = false;
  17802. }
  17803. }
  17804. /**
  17805. * Inserts and configures the staged Menu element into the DOM, positioning it,
  17806. * and wiring up various interaction events
  17807. */
  17808. function onShow(scope, element, opts) {
  17809. sanitizeAndConfigure(opts);
  17810. // Wire up theming on our menu element
  17811. $mdTheming.inherit(opts.menuContentEl, opts.target);
  17812. // Register various listeners to move menu on resize/orientation change
  17813. opts.cleanupResizing = startRepositioningOnResize();
  17814. opts.hideBackdrop = showBackdrop(scope, element, opts);
  17815. // Return the promise for when our menu is done animating in
  17816. return showMenu()
  17817. .then(function(response) {
  17818. opts.alreadyOpen = true;
  17819. opts.cleanupInteraction = activateInteraction();
  17820. return response;
  17821. });
  17822. /**
  17823. * Place the menu into the DOM and call positioning related functions
  17824. */
  17825. function showMenu() {
  17826. if (!opts.preserveElement) {
  17827. opts.parent.append(element);
  17828. } else {
  17829. element[0].style.display = '';
  17830. }
  17831. return $q(function(resolve) {
  17832. var position = calculateMenuPosition(element, opts);
  17833. element.removeClass('md-leave');
  17834. // Animate the menu scaling, and opacity [from its position origin (default == top-left)]
  17835. // to normal scale.
  17836. $animateCss(element, {
  17837. addClass: 'md-active',
  17838. from: animator.toCss(position),
  17839. to: animator.toCss({transform: ''})
  17840. })
  17841. .start()
  17842. .then(resolve);
  17843. });
  17844. }
  17845. /**
  17846. * Check for valid opts and set some sane defaults
  17847. */
  17848. function sanitizeAndConfigure() {
  17849. if (!opts.target) {
  17850. throw Error(
  17851. '$mdMenu.show() expected a target to animate from in options.target'
  17852. );
  17853. }
  17854. angular.extend(opts, {
  17855. alreadyOpen: false,
  17856. isRemoved: false,
  17857. target: angular.element(opts.target), //make sure it's not a naked dom node
  17858. parent: angular.element(opts.parent),
  17859. menuContentEl: angular.element(element[0].querySelector('md-menu-content'))
  17860. });
  17861. }
  17862. /**
  17863. * Configure various resize listeners for screen changes
  17864. */
  17865. function startRepositioningOnResize() {
  17866. var repositionMenu = (function(target, options) {
  17867. return $$rAF.throttle(function() {
  17868. if (opts.isRemoved) return;
  17869. var position = calculateMenuPosition(target, options);
  17870. target.css(animator.toCss(position));
  17871. });
  17872. })(element, opts);
  17873. $window.addEventListener('resize', repositionMenu);
  17874. $window.addEventListener('orientationchange', repositionMenu);
  17875. return function stopRepositioningOnResize() {
  17876. // Disable resizing handlers
  17877. $window.removeEventListener('resize', repositionMenu);
  17878. $window.removeEventListener('orientationchange', repositionMenu);
  17879. }
  17880. }
  17881. /**
  17882. * Activate interaction on the menu. Wire up keyboard listerns for
  17883. * clicks, keypresses, backdrop closing, etc.
  17884. */
  17885. function activateInteraction() {
  17886. element.addClass('md-clickable');
  17887. // close on backdrop click
  17888. if (opts.backdrop) opts.backdrop.on('click', onBackdropClick);
  17889. // Wire up keyboard listeners.
  17890. // - Close on escape,
  17891. // - focus next item on down arrow,
  17892. // - focus prev item on up
  17893. opts.menuContentEl.on('keydown', onMenuKeyDown);
  17894. opts.menuContentEl[0].addEventListener('click', captureClickListener, true);
  17895. // kick off initial focus in the menu on the first element
  17896. var focusTarget = opts.menuContentEl[0].querySelector('[md-menu-focus-target]');
  17897. if ( !focusTarget ) {
  17898. var firstChild = opts.menuContentEl[0].firstElementChild;
  17899. focusTarget = firstChild && (firstChild.querySelector('.md-button:not([disabled])') || firstChild.firstElementChild);
  17900. }
  17901. focusTarget && focusTarget.focus();
  17902. return function cleanupInteraction() {
  17903. element.removeClass('md-clickable');
  17904. if (opts.backdrop) opts.backdrop.off('click', onBackdropClick);
  17905. opts.menuContentEl.off('keydown', onMenuKeyDown);
  17906. opts.menuContentEl[0].removeEventListener('click', captureClickListener, true);
  17907. };
  17908. // ************************************
  17909. // internal functions
  17910. // ************************************
  17911. function onMenuKeyDown(ev) {
  17912. var handled;
  17913. switch (ev.keyCode) {
  17914. case $mdConstant.KEY_CODE.ESCAPE:
  17915. opts.mdMenuCtrl.close(false, { closeAll: true });
  17916. handled = true;
  17917. break;
  17918. case $mdConstant.KEY_CODE.UP_ARROW:
  17919. if (!focusMenuItem(ev, opts.menuContentEl, opts, -1)) {
  17920. opts.mdMenuCtrl.triggerContainerProxy(ev);
  17921. }
  17922. handled = true;
  17923. break;
  17924. case $mdConstant.KEY_CODE.DOWN_ARROW:
  17925. if (!focusMenuItem(ev, opts.menuContentEl, opts, 1)) {
  17926. opts.mdMenuCtrl.triggerContainerProxy(ev);
  17927. }
  17928. handled = true;
  17929. break;
  17930. case $mdConstant.KEY_CODE.LEFT_ARROW:
  17931. if (opts.nestLevel) {
  17932. opts.mdMenuCtrl.close();
  17933. } else {
  17934. opts.mdMenuCtrl.triggerContainerProxy(ev);
  17935. }
  17936. handled = true;
  17937. break;
  17938. case $mdConstant.KEY_CODE.RIGHT_ARROW:
  17939. var parentMenu = $mdUtil.getClosest(ev.target, 'MD-MENU');
  17940. if (parentMenu && parentMenu != opts.parent[0]) {
  17941. ev.target.click();
  17942. } else {
  17943. opts.mdMenuCtrl.triggerContainerProxy(ev);
  17944. }
  17945. handled = true;
  17946. break;
  17947. }
  17948. if (handled) {
  17949. ev.preventDefault();
  17950. ev.stopImmediatePropagation();
  17951. }
  17952. }
  17953. function onBackdropClick(e) {
  17954. e.preventDefault();
  17955. e.stopPropagation();
  17956. scope.$apply(function() {
  17957. opts.mdMenuCtrl.close(true, { closeAll: true });
  17958. });
  17959. }
  17960. // Close menu on menu item click, if said menu-item is not disabled
  17961. function captureClickListener(e) {
  17962. var target = e.target;
  17963. // Traverse up the event until we get to the menuContentEl to see if
  17964. // there is an ng-click and that the ng-click is not disabled
  17965. do {
  17966. if (target == opts.menuContentEl[0]) return;
  17967. if (hasAnyAttribute(target, ['ng-click', 'ng-href', 'ui-sref']) ||
  17968. target.nodeName == 'BUTTON' || target.nodeName == 'MD-BUTTON') {
  17969. var closestMenu = $mdUtil.getClosest(target, 'MD-MENU');
  17970. if (!target.hasAttribute('disabled') && (!closestMenu || closestMenu == opts.parent[0])) {
  17971. close();
  17972. }
  17973. break;
  17974. }
  17975. } while (target = target.parentNode)
  17976. function close() {
  17977. scope.$apply(function() {
  17978. opts.mdMenuCtrl.close(true, { closeAll: true });
  17979. });
  17980. }
  17981. function hasAnyAttribute(target, attrs) {
  17982. if (!target) return false;
  17983. for (var i = 0, attr; attr = attrs[i]; ++i) {
  17984. var altForms = [attr, 'data-' + attr, 'x-' + attr];
  17985. for (var j = 0, rawAttr; rawAttr = altForms[j]; ++j) {
  17986. if (target.hasAttribute(rawAttr)) {
  17987. return true;
  17988. }
  17989. }
  17990. }
  17991. return false;
  17992. }
  17993. }
  17994. opts.menuContentEl[0].addEventListener('click', captureClickListener, true);
  17995. return function cleanupInteraction() {
  17996. element.removeClass('md-clickable');
  17997. opts.menuContentEl.off('keydown');
  17998. opts.menuContentEl[0].removeEventListener('click', captureClickListener, true);
  17999. };
  18000. }
  18001. }
  18002. /**
  18003. * Takes a keypress event and focuses the next/previous menu
  18004. * item from the emitting element
  18005. * @param {event} e - The origin keypress event
  18006. * @param {angular.element} menuEl - The menu element
  18007. * @param {object} opts - The interim element options for the mdMenu
  18008. * @param {number} direction - The direction to move in (+1 = next, -1 = prev)
  18009. */
  18010. function focusMenuItem(e, menuEl, opts, direction) {
  18011. var currentItem = $mdUtil.getClosest(e.target, 'MD-MENU-ITEM');
  18012. var items = $mdUtil.nodesToArray(menuEl[0].children);
  18013. var currentIndex = items.indexOf(currentItem);
  18014. // Traverse through our elements in the specified direction (+/-1) and try to
  18015. // focus them until we find one that accepts focus
  18016. var didFocus;
  18017. for (var i = currentIndex + direction; i >= 0 && i < items.length; i = i + direction) {
  18018. var focusTarget = items[i].querySelector('.md-button');
  18019. didFocus = attemptFocus(focusTarget);
  18020. if (didFocus) {
  18021. break;
  18022. }
  18023. }
  18024. return didFocus;
  18025. }
  18026. /**
  18027. * Attempts to focus an element. Checks whether that element is the currently
  18028. * focused element after attempting.
  18029. * @param {HTMLElement} el - the element to attempt focus on
  18030. * @returns {bool} - whether the element was successfully focused
  18031. */
  18032. function attemptFocus(el) {
  18033. if (el && el.getAttribute('tabindex') != -1) {
  18034. el.focus();
  18035. return ($document[0].activeElement == el);
  18036. }
  18037. }
  18038. /**
  18039. * Use browser to remove this element without triggering a $destroy event
  18040. */
  18041. function detachElement(element, opts) {
  18042. if (!opts.preserveElement) {
  18043. if (toNode(element).parentNode === toNode(opts.parent)) {
  18044. toNode(opts.parent).removeChild(toNode(element));
  18045. }
  18046. } else {
  18047. toNode(element).style.display = 'none';
  18048. }
  18049. }
  18050. /**
  18051. * Computes menu position and sets the style on the menu container
  18052. * @param {HTMLElement} el - the menu container element
  18053. * @param {object} opts - the interim element options object
  18054. */
  18055. function calculateMenuPosition(el, opts) {
  18056. var containerNode = el[0],
  18057. openMenuNode = el[0].firstElementChild,
  18058. openMenuNodeRect = openMenuNode.getBoundingClientRect(),
  18059. boundryNode = $document[0].body,
  18060. boundryNodeRect = boundryNode.getBoundingClientRect();
  18061. var menuStyle = $window.getComputedStyle(openMenuNode);
  18062. var originNode = opts.target[0].querySelector('[md-menu-origin]') || opts.target[0],
  18063. originNodeRect = originNode.getBoundingClientRect();
  18064. var bounds = {
  18065. left: boundryNodeRect.left + MENU_EDGE_MARGIN,
  18066. top: Math.max(boundryNodeRect.top, 0) + MENU_EDGE_MARGIN,
  18067. bottom: Math.max(boundryNodeRect.bottom, Math.max(boundryNodeRect.top, 0) + boundryNodeRect.height) - MENU_EDGE_MARGIN,
  18068. right: boundryNodeRect.right - MENU_EDGE_MARGIN
  18069. };
  18070. var alignTarget, alignTargetRect = { top:0, left : 0, right:0, bottom:0 }, existingOffsets = { top:0, left : 0, right:0, bottom:0 };
  18071. var positionMode = opts.mdMenuCtrl.positionMode();
  18072. if (positionMode.top == 'target' || positionMode.left == 'target' || positionMode.left == 'target-right') {
  18073. alignTarget = firstVisibleChild();
  18074. if ( alignTarget ) {
  18075. // TODO: Allow centering on an arbitrary node, for now center on first menu-item's child
  18076. alignTarget = alignTarget.firstElementChild || alignTarget;
  18077. alignTarget = alignTarget.querySelector('[md-menu-align-target]') || alignTarget;
  18078. alignTargetRect = alignTarget.getBoundingClientRect();
  18079. existingOffsets = {
  18080. top: parseFloat(containerNode.style.top || 0),
  18081. left: parseFloat(containerNode.style.left || 0)
  18082. };
  18083. }
  18084. }
  18085. var position = {};
  18086. var transformOrigin = 'top ';
  18087. switch (positionMode.top) {
  18088. case 'target':
  18089. position.top = existingOffsets.top + originNodeRect.top - alignTargetRect.top;
  18090. break;
  18091. case 'cascade':
  18092. position.top = originNodeRect.top - parseFloat(menuStyle.paddingTop) - originNode.style.top;
  18093. break;
  18094. case 'bottom':
  18095. position.top = originNodeRect.top + originNodeRect.height;
  18096. break;
  18097. default:
  18098. throw new Error('Invalid target mode "' + positionMode.top + '" specified for md-menu on Y axis.');
  18099. }
  18100. switch (positionMode.left) {
  18101. case 'target':
  18102. position.left = existingOffsets.left + originNodeRect.left - alignTargetRect.left;
  18103. transformOrigin += 'left';
  18104. break;
  18105. case 'target-right':
  18106. position.left = originNodeRect.right - openMenuNodeRect.width + (openMenuNodeRect.right - alignTargetRect.right);
  18107. transformOrigin += 'right';
  18108. break;
  18109. case 'cascade':
  18110. var willFitRight = (originNodeRect.right + openMenuNodeRect.width) < bounds.right;
  18111. position.left = willFitRight ? originNodeRect.right - originNode.style.left : originNodeRect.left - originNode.style.left - openMenuNodeRect.width;
  18112. transformOrigin += willFitRight ? 'left' : 'right';
  18113. break;
  18114. case 'left':
  18115. position.left = originNodeRect.left;
  18116. transformOrigin += 'left';
  18117. break;
  18118. default:
  18119. throw new Error('Invalid target mode "' + positionMode.left + '" specified for md-menu on X axis.');
  18120. }
  18121. var offsets = opts.mdMenuCtrl.offsets();
  18122. position.top += offsets.top;
  18123. position.left += offsets.left;
  18124. clamp(position);
  18125. var scaleX = Math.round(100 * Math.min(originNodeRect.width / containerNode.offsetWidth, 1.0)) / 100;
  18126. var scaleY = Math.round(100 * Math.min(originNodeRect.height / containerNode.offsetHeight, 1.0)) / 100;
  18127. return {
  18128. top: Math.round(position.top),
  18129. left: Math.round(position.left),
  18130. // Animate a scale out if we aren't just repositioning
  18131. transform: !opts.alreadyOpen ? $mdUtil.supplant('scale({0},{1})', [scaleX, scaleY]) : undefined,
  18132. transformOrigin: transformOrigin
  18133. };
  18134. /**
  18135. * Clamps the repositioning of the menu within the confines of
  18136. * bounding element (often the screen/body)
  18137. */
  18138. function clamp(pos) {
  18139. pos.top = Math.max(Math.min(pos.top, bounds.bottom - containerNode.offsetHeight), bounds.top);
  18140. pos.left = Math.max(Math.min(pos.left, bounds.right - containerNode.offsetWidth), bounds.left);
  18141. }
  18142. /**
  18143. * Gets the first visible child in the openMenuNode
  18144. * Necessary incase menu nodes are being dynamically hidden
  18145. */
  18146. function firstVisibleChild() {
  18147. for (var i = 0; i < openMenuNode.children.length; ++i) {
  18148. if ($window.getComputedStyle(openMenuNode.children[i]).display != 'none') {
  18149. return openMenuNode.children[i];
  18150. }
  18151. }
  18152. }
  18153. }
  18154. }
  18155. function toNode(el) {
  18156. if (el instanceof angular.element) {
  18157. el = el[0];
  18158. }
  18159. return el;
  18160. }
  18161. }
  18162. MenuProvider.$inject = ["$$interimElementProvider"];
  18163. })();
  18164. (function(){
  18165. "use strict";
  18166. angular
  18167. .module('material.components.menuBar')
  18168. .controller('MenuBarController', MenuBarController);
  18169. var BOUND_MENU_METHODS = ['handleKeyDown', 'handleMenuHover', 'scheduleOpenHoveredMenu', 'cancelScheduledOpen'];
  18170. /**
  18171. * @ngInject
  18172. */
  18173. function MenuBarController($scope, $element, $attrs, $mdConstant, $document, $mdUtil, $timeout) {
  18174. this.$element = $element;
  18175. this.$attrs = $attrs;
  18176. this.$mdConstant = $mdConstant;
  18177. this.$mdUtil = $mdUtil;
  18178. this.$document = $document;
  18179. this.$scope = $scope;
  18180. this.$timeout = $timeout;
  18181. var self = this;
  18182. angular.forEach(BOUND_MENU_METHODS, function(methodName) {
  18183. self[methodName] = angular.bind(self, self[methodName]);
  18184. });
  18185. }
  18186. MenuBarController.$inject = ["$scope", "$element", "$attrs", "$mdConstant", "$document", "$mdUtil", "$timeout"];
  18187. MenuBarController.prototype.init = function() {
  18188. var $element = this.$element;
  18189. var $mdUtil = this.$mdUtil;
  18190. var $scope = this.$scope;
  18191. var self = this;
  18192. $element.on('keydown', this.handleKeyDown);
  18193. this.parentToolbar = $mdUtil.getClosest($element, 'MD-TOOLBAR');
  18194. $scope.$on('$mdMenuOpen', function(event, el) {
  18195. if (self.getMenus().indexOf(el[0]) != -1) {
  18196. $element[0].classList.add('md-open');
  18197. el[0].classList.add('md-open');
  18198. self.currentlyOpenMenu = el.controller('mdMenu');
  18199. self.currentlyOpenMenu.registerContainerProxy(self.handleKeyDown);
  18200. self.enableOpenOnHover();
  18201. }
  18202. });
  18203. $scope.$on('$mdMenuClose', function(event, el, opts) {
  18204. var rootMenus = self.getMenus();
  18205. if (rootMenus.indexOf(el[0]) != -1) {
  18206. $element[0].classList.remove('md-open');
  18207. el[0].classList.remove('md-open');
  18208. }
  18209. if (opts.closeAll) {
  18210. if ($element[0].contains(el[0])) {
  18211. var parentMenu = el[0];
  18212. while (parentMenu && rootMenus.indexOf(parentMenu) == -1) {
  18213. parentMenu = $mdUtil.getClosest(parentMenu, 'MD-MENU', true);
  18214. }
  18215. if (parentMenu) {
  18216. if (!opts.skipFocus) parentMenu.querySelector('button:not([disabled])').focus();
  18217. self.currentlyOpenMenu = undefined;
  18218. self.disableOpenOnHover();
  18219. self.setKeyboardMode(true);
  18220. }
  18221. }
  18222. }
  18223. });
  18224. angular
  18225. .element(this.getMenus())
  18226. .on('mouseenter', this.handleMenuHover);
  18227. this.setKeyboardMode(true);
  18228. };
  18229. MenuBarController.prototype.setKeyboardMode = function(enabled) {
  18230. if (enabled) this.$element[0].classList.add('md-keyboard-mode');
  18231. else this.$element[0].classList.remove('md-keyboard-mode');
  18232. };
  18233. MenuBarController.prototype.enableOpenOnHover = function() {
  18234. if (this.openOnHoverEnabled) return;
  18235. this.openOnHoverEnabled = true;
  18236. var parentToolbar;
  18237. if (parentToolbar = this.parentToolbar) {
  18238. parentToolbar.dataset.mdRestoreStyle = parentToolbar.getAttribute('style');
  18239. parentToolbar.style.position = 'relative';
  18240. parentToolbar.style.zIndex = 100;
  18241. }
  18242. };
  18243. MenuBarController.prototype.handleMenuHover = function(e) {
  18244. this.setKeyboardMode(false);
  18245. if (this.openOnHoverEnabled) {
  18246. this.scheduleOpenHoveredMenu(e);
  18247. }
  18248. };
  18249. MenuBarController.prototype.disableOpenOnHover = function() {
  18250. if (!this.openOnHoverEnabled) return;
  18251. this.openOnHoverEnabled = false;
  18252. var parentToolbar;
  18253. if (parentToolbar = this.parentToolbar) {
  18254. parentToolbar.setAttribute('style', parentToolbar.dataset.mdRestoreStyle || '');
  18255. }
  18256. };
  18257. MenuBarController.prototype.scheduleOpenHoveredMenu = function(e) {
  18258. var menuEl = angular.element(e.currentTarget);
  18259. var menuCtrl = menuEl.controller('mdMenu');
  18260. this.setKeyboardMode(false);
  18261. this.scheduleOpenMenu(menuCtrl);
  18262. };
  18263. MenuBarController.prototype.scheduleOpenMenu = function(menuCtrl) {
  18264. var self = this;
  18265. var $timeout = this.$timeout;
  18266. if (menuCtrl != self.currentlyOpenMenu) {
  18267. $timeout.cancel(self.pendingMenuOpen);
  18268. self.pendingMenuOpen = $timeout(function() {
  18269. self.pendingMenuOpen = undefined;
  18270. if (self.currentlyOpenMenu) {
  18271. self.currentlyOpenMenu.close(true, { closeAll: true });
  18272. }
  18273. menuCtrl.open();
  18274. }, 200, false);
  18275. }
  18276. };
  18277. MenuBarController.prototype.handleKeyDown = function(e) {
  18278. var keyCodes = this.$mdConstant.KEY_CODE;
  18279. var currentMenu = this.currentlyOpenMenu;
  18280. var wasOpen = currentMenu && currentMenu.isOpen;
  18281. this.setKeyboardMode(true);
  18282. var handled, newMenu, newMenuCtrl;
  18283. switch (e.keyCode) {
  18284. case keyCodes.DOWN_ARROW:
  18285. if (currentMenu) {
  18286. currentMenu.focusMenuContainer();
  18287. } else {
  18288. this.openFocusedMenu();
  18289. }
  18290. handled = true;
  18291. break;
  18292. case keyCodes.UP_ARROW:
  18293. currentMenu && currentMenu.close();
  18294. handled = true;
  18295. break;
  18296. case keyCodes.LEFT_ARROW:
  18297. newMenu = this.focusMenu(-1);
  18298. if (wasOpen) {
  18299. newMenuCtrl = angular.element(newMenu).controller('mdMenu');
  18300. this.scheduleOpenMenu(newMenuCtrl);
  18301. }
  18302. handled = true;
  18303. break;
  18304. case keyCodes.RIGHT_ARROW:
  18305. newMenu = this.focusMenu(+1);
  18306. if (wasOpen) {
  18307. newMenuCtrl = angular.element(newMenu).controller('mdMenu');
  18308. this.scheduleOpenMenu(newMenuCtrl);
  18309. }
  18310. handled = true;
  18311. break;
  18312. }
  18313. if (handled) {
  18314. e && e.preventDefault && e.preventDefault();
  18315. e && e.stopImmediatePropagation && e.stopImmediatePropagation();
  18316. }
  18317. };
  18318. MenuBarController.prototype.focusMenu = function(direction) {
  18319. var menus = this.getMenus();
  18320. var focusedIndex = this.getFocusedMenuIndex();
  18321. if (focusedIndex == -1) { focusedIndex = this.getOpenMenuIndex(); }
  18322. var changed = false;
  18323. if (focusedIndex == -1) { focusedIndex = 0; }
  18324. else if (
  18325. direction < 0 && focusedIndex > 0 ||
  18326. direction > 0 && focusedIndex < menus.length - direction
  18327. ) {
  18328. focusedIndex += direction;
  18329. changed = true;
  18330. }
  18331. if (changed) {
  18332. menus[focusedIndex].querySelector('button').focus();
  18333. return menus[focusedIndex];
  18334. }
  18335. };
  18336. MenuBarController.prototype.openFocusedMenu = function() {
  18337. var menu = this.getFocusedMenu();
  18338. menu && angular.element(menu).controller('mdMenu').open();
  18339. };
  18340. MenuBarController.prototype.getMenus = function() {
  18341. var $element = this.$element;
  18342. return this.$mdUtil.nodesToArray($element[0].children)
  18343. .filter(function(el) { return el.nodeName == 'MD-MENU'; });
  18344. };
  18345. MenuBarController.prototype.getFocusedMenu = function() {
  18346. return this.getMenus()[this.getFocusedMenuIndex()];
  18347. };
  18348. MenuBarController.prototype.getFocusedMenuIndex = function() {
  18349. var $mdUtil = this.$mdUtil;
  18350. var focusedEl = $mdUtil.getClosest(
  18351. this.$document[0].activeElement,
  18352. 'MD-MENU'
  18353. );
  18354. if (!focusedEl) return -1;
  18355. var focusedIndex = this.getMenus().indexOf(focusedEl);
  18356. return focusedIndex;
  18357. };
  18358. MenuBarController.prototype.getOpenMenuIndex = function() {
  18359. var menus = this.getMenus();
  18360. for (var i = 0; i < menus.length; ++i) {
  18361. if (menus[i].classList.contains('md-open')) return i;
  18362. }
  18363. return -1;
  18364. };
  18365. })();
  18366. (function(){
  18367. "use strict";
  18368. /**
  18369. * @ngdoc directive
  18370. * @name mdMenuBar
  18371. * @module material.components.menu-bar
  18372. * @restrict E
  18373. * @description
  18374. *
  18375. * Menu bars are containers that hold multiple menus. They change the behavior and appearence
  18376. * of the `md-menu` directive to behave similar to an operating system provided menu.
  18377. *
  18378. * @usage
  18379. * <hljs lang="html">
  18380. * <md-menu-bar>
  18381. * <md-menu>
  18382. * <button ng-click="$mdOpenMenu()">
  18383. * File
  18384. * </button>
  18385. * <md-menu-content>
  18386. * <md-menu-item>
  18387. * <md-button ng-click="ctrl.sampleAction('share', $event)">
  18388. * Share...
  18389. * </md-button>
  18390. * </md-menu-item>
  18391. * <md-menu-divider></md-menu-divider>
  18392. * <md-menu-item>
  18393. * <md-menu-item>
  18394. * <md-menu>
  18395. * <md-button ng-click="$mdOpenMenu()">New</md-button>
  18396. * <md-menu-content>
  18397. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Document', $event)">Document</md-button></md-menu-item>
  18398. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Spreadsheet', $event)">Spreadsheet</md-button></md-menu-item>
  18399. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Presentation', $event)">Presentation</md-button></md-menu-item>
  18400. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Form', $event)">Form</md-button></md-menu-item>
  18401. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Drawing', $event)">Drawing</md-button></md-menu-item>
  18402. * </md-menu-content>
  18403. * </md-menu>
  18404. * </md-menu-item>
  18405. * </md-menu-content>
  18406. * </md-menu>
  18407. * </md-menu-bar>
  18408. * </hljs>
  18409. *
  18410. * ## Menu Bar Controls
  18411. *
  18412. * You may place `md-menu-items` that function as controls within menu bars.
  18413. * There are two modes that are exposed via the `type` attribute of the `md-menu-item`.
  18414. * `type="checkbox"` will function as a boolean control for the `ng-model` attribute of the
  18415. * `md-menu-item`. `type="radio"` will function like a radio button, setting the `ngModel`
  18416. * to the `string` value of the `value` attribute. If you need non-string values, you can use
  18417. * `ng-value` to provide an expression (this is similar to how angular's native `input[type=radio]` works.
  18418. *
  18419. * <hljs lang="html">
  18420. * <md-menu-bar>
  18421. * <md-menu>
  18422. * <button ng-click="$mdOpenMenu()">
  18423. * Sample Menu
  18424. * </button>
  18425. * <md-menu-content>
  18426. * <md-menu-item type="checkbox" ng-model="settings.allowChanges">Allow changes</md-menu-item>
  18427. * <md-menu-divider></md-menu-divider>
  18428. * <md-menu-item type="radio" ng-model="settings.mode" ng-value="1">Mode 1</md-menu-item>
  18429. * <md-menu-item type="radio" ng-model="settings.mode" ng-value="1">Mode 2</md-menu-item>
  18430. * <md-menu-item type="radio" ng-model="settings.mode" ng-value="1">Mode 3</md-menu-item>
  18431. * </md-menu-content>
  18432. * </md-menu>
  18433. * </md-menu-bar>
  18434. * </hljs>
  18435. *
  18436. *
  18437. * ### Nesting Menus
  18438. *
  18439. * Menus may be nested within menu bars. This is commonly called cascading menus.
  18440. * To nest a menu place the nested menu inside the content of the `md-menu-item`.
  18441. * <hljs lang="html">
  18442. * <md-menu-item>
  18443. * <md-menu>
  18444. * <button ng-click="$mdOpenMenu()">New</md-button>
  18445. * <md-menu-content>
  18446. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Document', $event)">Document</md-button></md-menu-item>
  18447. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Spreadsheet', $event)">Spreadsheet</md-button></md-menu-item>
  18448. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Presentation', $event)">Presentation</md-button></md-menu-item>
  18449. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Form', $event)">Form</md-button></md-menu-item>
  18450. * <md-menu-item><md-button ng-click="ctrl.sampleAction('New Drawing', $event)">Drawing</md-button></md-menu-item>
  18451. * </md-menu-content>
  18452. * </md-menu>
  18453. * </md-menu-item>
  18454. * </hljs>
  18455. *
  18456. */
  18457. angular
  18458. .module('material.components.menuBar')
  18459. .directive('mdMenuBar', MenuBarDirective);
  18460. /**
  18461. *
  18462. * @ngInjdect
  18463. */
  18464. function MenuBarDirective($mdUtil, $mdTheming) {
  18465. return {
  18466. restrict: 'E',
  18467. require: 'mdMenuBar',
  18468. controller: 'MenuBarController',
  18469. compile: function compile(templateEl, templateAttrs) {
  18470. if (!templateAttrs.ariaRole) {
  18471. templateEl[0].setAttribute('role', 'menubar');
  18472. }
  18473. angular.forEach(templateEl[0].children, function(menuEl) {
  18474. if (menuEl.nodeName == 'MD-MENU') {
  18475. if (!menuEl.hasAttribute('md-position-mode')) {
  18476. menuEl.setAttribute('md-position-mode', 'left bottom');
  18477. }
  18478. menuEl.setAttribute('role', 'menu');
  18479. var contentEls = $mdUtil.nodesToArray(menuEl.querySelectorAll('md-menu-content'));
  18480. angular.forEach(contentEls, function(contentEl) {
  18481. contentEl.classList.add('md-menu-bar-menu');
  18482. contentEl.classList.add('md-dense');
  18483. if (!contentEl.hasAttribute('width')) {
  18484. contentEl.setAttribute('width', 5);
  18485. }
  18486. });
  18487. }
  18488. });
  18489. return function postLink(scope, el, attrs, ctrl) {
  18490. $mdTheming(scope, el);
  18491. ctrl.init();
  18492. };
  18493. }
  18494. };
  18495. }
  18496. MenuBarDirective.$inject = ["$mdUtil", "$mdTheming"];
  18497. })();
  18498. (function(){
  18499. "use strict";
  18500. angular
  18501. .module('material.components.menuBar')
  18502. .directive('mdMenuDivider', MenuDividerDirective);
  18503. function MenuDividerDirective() {
  18504. return {
  18505. restrict: 'E',
  18506. compile: function(templateEl, templateAttrs) {
  18507. if (!templateAttrs.role) {
  18508. templateEl[0].setAttribute('role', 'separator');
  18509. }
  18510. }
  18511. };
  18512. }
  18513. })();
  18514. (function(){
  18515. "use strict";
  18516. angular
  18517. .module('material.components.menuBar')
  18518. .controller('MenuItemController', MenuItemController);
  18519. /**
  18520. * @ngInject
  18521. */
  18522. function MenuItemController($scope, $element, $attrs) {
  18523. this.$element = $element;
  18524. this.$attrs = $attrs;
  18525. this.$scope = $scope;
  18526. }
  18527. MenuItemController.$inject = ["$scope", "$element", "$attrs"];
  18528. MenuItemController.prototype.init = function(ngModel) {
  18529. var $element = this.$element;
  18530. var $attrs = this.$attrs;
  18531. this.ngModel = ngModel;
  18532. if ($attrs.type == 'checkbox' || $attrs.type == 'radio') {
  18533. this.mode = $attrs.type;
  18534. this.iconEl = $element[0].children[0];
  18535. this.buttonEl = $element[0].children[1];
  18536. if (ngModel) this.initClickListeners();
  18537. }
  18538. };
  18539. MenuItemController.prototype.initClickListeners = function() {
  18540. var ngModel = this.ngModel;
  18541. var $scope = this.$scope;
  18542. var $attrs = this.$attrs;
  18543. var $element = this.$element;
  18544. var mode = this.mode;
  18545. this.handleClick = angular.bind(this, this.handleClick);
  18546. var icon = this.iconEl
  18547. var button = angular.element(this.buttonEl);
  18548. var handleClick = this.handleClick;
  18549. $attrs.$observe('disabled', setDisabled);
  18550. setDisabled($attrs.disabled);
  18551. ngModel.$render = function render() {
  18552. if (isSelected()) {
  18553. icon.style.display = '';
  18554. $element.attr('aria-checked', 'true');
  18555. } else {
  18556. icon.style.display = 'none';
  18557. $element.attr('aria-checked', 'false');
  18558. }
  18559. };
  18560. $scope.$$postDigest(ngModel.$render);
  18561. function isSelected() {
  18562. if (mode == 'radio') {
  18563. var val = $attrs.ngValue ? $scope.$eval($attrs.ngValue) : $attrs.value;
  18564. return ngModel.$modelValue == val;
  18565. } else {
  18566. return ngModel.$modelValue;
  18567. }
  18568. }
  18569. function setDisabled(disabled) {
  18570. if (disabled) {
  18571. button.off('click', handleClick);
  18572. } else {
  18573. button.on('click', handleClick);
  18574. }
  18575. }
  18576. };
  18577. MenuItemController.prototype.handleClick = function(e) {
  18578. var mode = this.mode;
  18579. var ngModel = this.ngModel;
  18580. var $attrs = this.$attrs;
  18581. var newVal;
  18582. if (mode == 'checkbox') {
  18583. newVal = !ngModel.$modelValue;
  18584. } else if (mode == 'radio') {
  18585. newVal = $attrs.ngValue ? this.$scope.$eval($attrs.ngValue) : $attrs.value;
  18586. }
  18587. ngModel.$setViewValue(newVal);
  18588. ngModel.$render();
  18589. };
  18590. })();
  18591. (function(){
  18592. "use strict";
  18593. angular
  18594. .module('material.components.menuBar')
  18595. .directive('mdMenuItem', MenuItemDirective);
  18596. /**
  18597. *
  18598. * @ngInjdect
  18599. */
  18600. function MenuItemDirective() {
  18601. return {
  18602. require: ['mdMenuItem', '?ngModel'],
  18603. compile: function(templateEl, templateAttrs) {
  18604. if (templateAttrs.type == 'checkbox' || templateAttrs.type == 'radio') {
  18605. var text = templateEl[0].textContent;
  18606. var buttonEl = angular.element('<md-button type="button"></md-button>');
  18607. buttonEl.html(text);
  18608. buttonEl.attr('tabindex', '0');
  18609. templateEl.html('');
  18610. templateEl.append(angular.element('<md-icon md-svg-icon="check"></md-icon>'));
  18611. templateEl.append(buttonEl);
  18612. templateEl[0].classList.add('md-indent');
  18613. setDefault('role', (templateAttrs.type == 'checkbox') ? 'menuitemcheckbox' : 'menuitemradio');
  18614. angular.forEach(['ng-disabled'], moveAttrToButton);
  18615. } else {
  18616. setDefault('role', 'menuitem');
  18617. }
  18618. return function(scope, el, attrs, ctrls) {
  18619. var ctrl = ctrls[0];
  18620. var ngModel = ctrls[1];
  18621. ctrl.init(ngModel);
  18622. };
  18623. function setDefault(attr, val) {
  18624. if (!templateEl[0].hasAttribute(attr)) {
  18625. templateEl[0].setAttribute(attr, val);
  18626. }
  18627. }
  18628. function moveAttrToButton(attr) {
  18629. if (templateEl[0].hasAttribute(attr)) {
  18630. var val = templateEl[0].getAttribute(attr);
  18631. buttonEl[0].setAttribute(attr, val);
  18632. templateEl[0].removeAttribute(attr);
  18633. }
  18634. }
  18635. },
  18636. controller: 'MenuItemController'
  18637. };
  18638. }
  18639. })();
  18640. (function(){
  18641. "use strict";
  18642. /**
  18643. * @ngdoc directive
  18644. * @name mdTab
  18645. * @module material.components.tabs
  18646. *
  18647. * @restrict E
  18648. *
  18649. * @description
  18650. * Use the `<md-tab>` a nested directive used within `<md-tabs>` to specify a tab with a **label** and optional *view content*.
  18651. *
  18652. * If the `label` attribute is not specified, then an optional `<md-tab-label>` tag can be used to specify more
  18653. * complex tab header markup. If neither the **label** nor the **md-tab-label** are specified, then the nested
  18654. * markup of the `<md-tab>` is used as the tab header markup.
  18655. *
  18656. * Please note that if you use `<md-tab-label>`, your content **MUST** be wrapped in the `<md-tab-body>` tag. This
  18657. * is to define a clear separation between the tab content and the tab label.
  18658. *
  18659. * If a tab **label** has been identified, then any **non-**`<md-tab-label>` markup
  18660. * will be considered tab content and will be transcluded to the internal `<div class="md-tabs-content">` container.
  18661. *
  18662. * This container is used by the TabsController to show/hide the active tab's content view. This synchronization is
  18663. * automatically managed by the internal TabsController whenever the tab selection changes. Selection changes can
  18664. * be initiated via data binding changes, programmatic invocation, or user gestures.
  18665. *
  18666. * @param {string=} label Optional attribute to specify a simple string as the tab label
  18667. * @param {boolean=} disabled If present, disabled tab selection.
  18668. * @param {expression=} md-on-deselect Expression to be evaluated after the tab has been de-selected.
  18669. * @param {expression=} md-on-select Expression to be evaluated after the tab has been selected.
  18670. * @param {boolean=} md-active When true, sets the active tab. Note: There can only be one active tab at a time.
  18671. *
  18672. *
  18673. * @usage
  18674. *
  18675. * <hljs lang="html">
  18676. * <md-tab label="" disabled="" md-on-select="" md-on-deselect="" >
  18677. * <h3>My Tab content</h3>
  18678. * </md-tab>
  18679. *
  18680. * <md-tab >
  18681. * <md-tab-label>
  18682. * <h3>My Tab content</h3>
  18683. * </md-tab-label>
  18684. * <md-tab-body>
  18685. * <p>
  18686. * Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium,
  18687. * totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae
  18688. * dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit,
  18689. * sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
  18690. * </p>
  18691. * </md-tab-body>
  18692. * </md-tab>
  18693. * </hljs>
  18694. *
  18695. */
  18696. angular
  18697. .module('material.components.tabs')
  18698. .directive('mdTab', MdTab);
  18699. function MdTab () {
  18700. return {
  18701. require: '^?mdTabs',
  18702. terminal: true,
  18703. compile: function (element, attr) {
  18704. var label = element.find('md-tab-label'),
  18705. body = element.find('md-tab-body');
  18706. if (label.length == 0) {
  18707. label = angular.element('<md-tab-label></md-tab-label>');
  18708. if (attr.label) label.text(attr.label);
  18709. else label.append(element.contents());
  18710. if (body.length == 0) {
  18711. var contents = element.contents().detach();
  18712. body = angular.element('<md-tab-body></md-tab-body>');
  18713. body.append(contents);
  18714. }
  18715. }
  18716. element.append(label);
  18717. if (body.html()) element.append(body);
  18718. return postLink;
  18719. },
  18720. scope: {
  18721. active: '=?mdActive',
  18722. disabled: '=?ngDisabled',
  18723. select: '&?mdOnSelect',
  18724. deselect: '&?mdOnDeselect'
  18725. }
  18726. };
  18727. function postLink (scope, element, attr, ctrl) {
  18728. if (!ctrl) return;
  18729. var index = ctrl.getTabElementIndex(element),
  18730. body = element.find('md-tab-body').eq(0).remove(),
  18731. label = element.find('md-tab-label').eq(0).remove(),
  18732. data = ctrl.insertTab({
  18733. scope: scope,
  18734. parent: scope.$parent,
  18735. index: index,
  18736. element: element,
  18737. template: body.html(),
  18738. label: label.html()
  18739. }, index);
  18740. scope.select = scope.select || angular.noop;
  18741. scope.deselect = scope.deselect || angular.noop;
  18742. scope.$watch('active', function (active) { if (active) ctrl.select(data.getIndex()); });
  18743. scope.$watch('disabled', function () { ctrl.refreshIndex(); });
  18744. scope.$watch(
  18745. function () {
  18746. return ctrl.getTabElementIndex(element);
  18747. },
  18748. function (newIndex) {
  18749. data.index = newIndex;
  18750. ctrl.updateTabOrder();
  18751. }
  18752. );
  18753. scope.$on('$destroy', function () { ctrl.removeTab(data); });
  18754. }
  18755. }
  18756. })();
  18757. (function(){
  18758. "use strict";
  18759. angular
  18760. .module('material.components.tabs')
  18761. .directive('mdTabItem', MdTabItem);
  18762. function MdTabItem () {
  18763. return {
  18764. require: '^?mdTabs',
  18765. link: function link (scope, element, attr, ctrl) {
  18766. if (!ctrl) return;
  18767. ctrl.attachRipple(scope, element);
  18768. }
  18769. };
  18770. }
  18771. })();
  18772. (function(){
  18773. "use strict";
  18774. angular
  18775. .module('material.components.tabs')
  18776. .directive('mdTabLabel', MdTabLabel);
  18777. function MdTabLabel () {
  18778. return { terminal: true };
  18779. }
  18780. })();
  18781. (function(){
  18782. "use strict";
  18783. angular.module('material.components.tabs')
  18784. .directive('mdTabScroll', MdTabScroll);
  18785. function MdTabScroll ($parse) {
  18786. return {
  18787. restrict: 'A',
  18788. compile: function ($element, attr) {
  18789. var fn = $parse(attr.mdTabScroll, null, true);
  18790. return function ngEventHandler (scope, element) {
  18791. element.on('mousewheel', function (event) {
  18792. scope.$apply(function () { fn(scope, { $event: event }); });
  18793. });
  18794. };
  18795. }
  18796. }
  18797. }
  18798. MdTabScroll.$inject = ["$parse"];
  18799. })();
  18800. (function(){
  18801. "use strict";
  18802. angular
  18803. .module('material.components.tabs')
  18804. .controller('MdTabsController', MdTabsController);
  18805. /**
  18806. * @ngInject
  18807. */
  18808. function MdTabsController ($scope, $element, $window, $mdConstant, $mdTabInkRipple,
  18809. $mdUtil, $animateCss, $attrs, $compile, $mdTheming) {
  18810. // define private properties
  18811. var ctrl = this,
  18812. locked = false,
  18813. elements = getElements(),
  18814. queue = [],
  18815. destroyed = false,
  18816. loaded = false;
  18817. // define one-way bindings
  18818. defineOneWayBinding('stretchTabs', handleStretchTabs);
  18819. // define public properties with change handlers
  18820. defineProperty('focusIndex', handleFocusIndexChange, ctrl.selectedIndex || 0);
  18821. defineProperty('offsetLeft', handleOffsetChange, 0);
  18822. defineProperty('hasContent', handleHasContent, false);
  18823. defineProperty('maxTabWidth', handleMaxTabWidth, getMaxTabWidth());
  18824. defineProperty('shouldPaginate', handleShouldPaginate, false);
  18825. // define boolean attributes
  18826. defineBooleanAttribute('noInkBar', handleInkBar);
  18827. defineBooleanAttribute('dynamicHeight', handleDynamicHeight);
  18828. defineBooleanAttribute('noPagination');
  18829. defineBooleanAttribute('swipeContent');
  18830. defineBooleanAttribute('noDisconnect');
  18831. defineBooleanAttribute('autoselect');
  18832. defineBooleanAttribute('centerTabs', handleCenterTabs, false);
  18833. defineBooleanAttribute('enableDisconnect');
  18834. // define public properties
  18835. ctrl.scope = $scope;
  18836. ctrl.parent = $scope.$parent;
  18837. ctrl.tabs = [];
  18838. ctrl.lastSelectedIndex = null;
  18839. ctrl.hasFocus = false;
  18840. ctrl.lastClick = true;
  18841. ctrl.shouldCenterTabs = shouldCenterTabs();
  18842. // define public methods
  18843. ctrl.updatePagination = $mdUtil.debounce(updatePagination, 100);
  18844. ctrl.redirectFocus = redirectFocus;
  18845. ctrl.attachRipple = attachRipple;
  18846. ctrl.insertTab = insertTab;
  18847. ctrl.removeTab = removeTab;
  18848. ctrl.select = select;
  18849. ctrl.scroll = scroll;
  18850. ctrl.nextPage = nextPage;
  18851. ctrl.previousPage = previousPage;
  18852. ctrl.keydown = keydown;
  18853. ctrl.canPageForward = canPageForward;
  18854. ctrl.canPageBack = canPageBack;
  18855. ctrl.refreshIndex = refreshIndex;
  18856. ctrl.incrementIndex = incrementIndex;
  18857. ctrl.getTabElementIndex = getTabElementIndex;
  18858. ctrl.updateInkBarStyles = $mdUtil.debounce(updateInkBarStyles, 100);
  18859. ctrl.updateTabOrder = $mdUtil.debounce(updateTabOrder, 100);
  18860. init();
  18861. /**
  18862. * Perform initialization for the controller, setup events and watcher(s)
  18863. */
  18864. function init () {
  18865. ctrl.selectedIndex = ctrl.selectedIndex || 0;
  18866. compileTemplate();
  18867. configureWatchers();
  18868. bindEvents();
  18869. $mdTheming($element);
  18870. $mdUtil.nextTick(function () {
  18871. updateHeightFromContent();
  18872. adjustOffset();
  18873. updateInkBarStyles();
  18874. ctrl.tabs[ ctrl.selectedIndex ] && ctrl.tabs[ ctrl.selectedIndex ].scope.select();
  18875. loaded = true;
  18876. updatePagination();
  18877. });
  18878. }
  18879. /**
  18880. * Compiles the template provided by the user. This is passed as an attribute from the tabs
  18881. * directive's template function.
  18882. */
  18883. function compileTemplate () {
  18884. var template = $attrs.$mdTabsTemplate,
  18885. element = angular.element(elements.data);
  18886. element.html(template);
  18887. $compile(element.contents())(ctrl.parent);
  18888. delete $attrs.$mdTabsTemplate;
  18889. }
  18890. /**
  18891. * Binds events used by the tabs component.
  18892. */
  18893. function bindEvents () {
  18894. angular.element($window).on('resize', handleWindowResize);
  18895. $scope.$on('$destroy', cleanup);
  18896. }
  18897. /**
  18898. * Configure watcher(s) used by Tabs
  18899. */
  18900. function configureWatchers () {
  18901. $scope.$watch('$mdTabsCtrl.selectedIndex', handleSelectedIndexChange);
  18902. }
  18903. /**
  18904. * Creates a one-way binding manually rather than relying on Angular's isolated scope
  18905. * @param key
  18906. * @param handler
  18907. */
  18908. function defineOneWayBinding (key, handler) {
  18909. var attr = $attrs.$normalize('md-' + key);
  18910. if (handler) defineProperty(key, handler);
  18911. $attrs.$observe(attr, function (newValue) { ctrl[ key ] = newValue; });
  18912. }
  18913. /**
  18914. * Defines boolean attributes with default value set to true. (ie. md-stretch-tabs with no value
  18915. * will be treated as being truthy)
  18916. * @param key
  18917. * @param handler
  18918. */
  18919. function defineBooleanAttribute (key, handler) {
  18920. var attr = $attrs.$normalize('md-' + key);
  18921. if (handler) defineProperty(key, handler);
  18922. if ($attrs.hasOwnProperty(attr)) updateValue($attrs[attr]);
  18923. $attrs.$observe(attr, updateValue);
  18924. function updateValue (newValue) {
  18925. ctrl[ key ] = newValue !== 'false';
  18926. }
  18927. }
  18928. /**
  18929. * Remove any events defined by this controller
  18930. */
  18931. function cleanup () {
  18932. destroyed = true;
  18933. angular.element($window).off('resize', handleWindowResize);
  18934. }
  18935. // Change handlers
  18936. /**
  18937. * Toggles stretch tabs class and updates inkbar when tab stretching changes
  18938. * @param stretchTabs
  18939. */
  18940. function handleStretchTabs (stretchTabs) {
  18941. angular.element(elements.wrapper).toggleClass('md-stretch-tabs', shouldStretchTabs());
  18942. updateInkBarStyles();
  18943. }
  18944. function handleCenterTabs (newValue) {
  18945. ctrl.shouldCenterTabs = shouldCenterTabs();
  18946. }
  18947. function handleMaxTabWidth (newWidth, oldWidth) {
  18948. if (newWidth !== oldWidth) {
  18949. $mdUtil.nextTick(ctrl.updateInkBarStyles);
  18950. }
  18951. }
  18952. function handleShouldPaginate (newValue, oldValue) {
  18953. if (newValue !== oldValue) {
  18954. ctrl.maxTabWidth = getMaxTabWidth();
  18955. ctrl.shouldCenterTabs = shouldCenterTabs();
  18956. $mdUtil.nextTick(function () {
  18957. ctrl.maxTabWidth = getMaxTabWidth();
  18958. adjustOffset(ctrl.selectedIndex);
  18959. });
  18960. }
  18961. }
  18962. /**
  18963. * Add/remove the `md-no-tab-content` class depending on `ctrl.hasContent`
  18964. * @param hasContent
  18965. */
  18966. function handleHasContent (hasContent) {
  18967. $element[ hasContent ? 'removeClass' : 'addClass' ]('md-no-tab-content');
  18968. }
  18969. /**
  18970. * Apply ctrl.offsetLeft to the paging element when it changes
  18971. * @param left
  18972. */
  18973. function handleOffsetChange (left) {
  18974. var newValue = ctrl.shouldCenterTabs ? '' : '-' + left + 'px';
  18975. angular.element(elements.paging).css($mdConstant.CSS.TRANSFORM, 'translate3d(' + newValue + ', 0, 0)');
  18976. $scope.$broadcast('$mdTabsPaginationChanged');
  18977. }
  18978. /**
  18979. * Update the UI whenever `ctrl.focusIndex` is updated
  18980. * @param newIndex
  18981. * @param oldIndex
  18982. */
  18983. function handleFocusIndexChange (newIndex, oldIndex) {
  18984. if (newIndex === oldIndex) return;
  18985. if (!elements.tabs[ newIndex ]) return;
  18986. adjustOffset();
  18987. redirectFocus();
  18988. }
  18989. /**
  18990. * Update the UI whenever the selected index changes. Calls user-defined select/deselect methods.
  18991. * @param newValue
  18992. * @param oldValue
  18993. */
  18994. function handleSelectedIndexChange (newValue, oldValue) {
  18995. if (newValue === oldValue) return;
  18996. ctrl.selectedIndex = getNearestSafeIndex(newValue);
  18997. ctrl.lastSelectedIndex = oldValue;
  18998. ctrl.updateInkBarStyles();
  18999. updateHeightFromContent();
  19000. adjustOffset(newValue);
  19001. $scope.$broadcast('$mdTabsChanged');
  19002. ctrl.tabs[ oldValue ] && ctrl.tabs[ oldValue ].scope.deselect();
  19003. ctrl.tabs[ newValue ] && ctrl.tabs[ newValue ].scope.select();
  19004. }
  19005. function getTabElementIndex(tabEl){
  19006. var tabs = $element[0].getElementsByTagName('md-tab');
  19007. return Array.prototype.indexOf.call(tabs, tabEl[0]);
  19008. }
  19009. /**
  19010. * Queues up a call to `handleWindowResize` when a resize occurs while the tabs component is
  19011. * hidden.
  19012. */
  19013. function handleResizeWhenVisible () {
  19014. // if there is already a watcher waiting for resize, do nothing
  19015. if (handleResizeWhenVisible.watcher) return;
  19016. // otherwise, we will abuse the $watch function to check for visible
  19017. handleResizeWhenVisible.watcher = $scope.$watch(function () {
  19018. // since we are checking for DOM size, we use $mdUtil.nextTick() to wait for after the DOM updates
  19019. $mdUtil.nextTick(function () {
  19020. // if the watcher has already run (ie. multiple digests in one cycle), do nothing
  19021. if (!handleResizeWhenVisible.watcher) return;
  19022. if ($element.prop('offsetParent')) {
  19023. handleResizeWhenVisible.watcher();
  19024. handleResizeWhenVisible.watcher = null;
  19025. handleWindowResize();
  19026. }
  19027. }, false);
  19028. });
  19029. }
  19030. // Event handlers / actions
  19031. /**
  19032. * Handle user keyboard interactions
  19033. * @param event
  19034. */
  19035. function keydown (event) {
  19036. switch (event.keyCode) {
  19037. case $mdConstant.KEY_CODE.LEFT_ARROW:
  19038. event.preventDefault();
  19039. incrementIndex(-1, true);
  19040. break;
  19041. case $mdConstant.KEY_CODE.RIGHT_ARROW:
  19042. event.preventDefault();
  19043. incrementIndex(1, true);
  19044. break;
  19045. case $mdConstant.KEY_CODE.SPACE:
  19046. case $mdConstant.KEY_CODE.ENTER:
  19047. event.preventDefault();
  19048. if (!locked) ctrl.selectedIndex = ctrl.focusIndex;
  19049. break;
  19050. }
  19051. ctrl.lastClick = false;
  19052. }
  19053. /**
  19054. * Update the selected index and trigger a click event on the original `md-tab` element in order
  19055. * to fire user-added click events.
  19056. * @param index
  19057. */
  19058. function select (index) {
  19059. if (!locked) ctrl.focusIndex = ctrl.selectedIndex = index;
  19060. ctrl.lastClick = true;
  19061. // nextTick is required to prevent errors in user-defined click events
  19062. $mdUtil.nextTick(function () {
  19063. ctrl.tabs[ index ].element.triggerHandler('click');
  19064. }, false);
  19065. }
  19066. /**
  19067. * When pagination is on, this makes sure the selected index is in view.
  19068. * @param event
  19069. */
  19070. function scroll (event) {
  19071. if (!ctrl.shouldPaginate) return;
  19072. event.preventDefault();
  19073. ctrl.offsetLeft = fixOffset(ctrl.offsetLeft - event.wheelDelta);
  19074. }
  19075. /**
  19076. * Slides the tabs over approximately one page forward.
  19077. */
  19078. function nextPage () {
  19079. var viewportWidth = elements.canvas.clientWidth,
  19080. totalWidth = viewportWidth + ctrl.offsetLeft,
  19081. i, tab;
  19082. for (i = 0; i < elements.tabs.length; i++) {
  19083. tab = elements.tabs[ i ];
  19084. if (tab.offsetLeft + tab.offsetWidth > totalWidth) break;
  19085. }
  19086. ctrl.offsetLeft = fixOffset(tab.offsetLeft);
  19087. }
  19088. /**
  19089. * Slides the tabs over approximately one page backward.
  19090. */
  19091. function previousPage () {
  19092. var i, tab;
  19093. for (i = 0; i < elements.tabs.length; i++) {
  19094. tab = elements.tabs[ i ];
  19095. if (tab.offsetLeft + tab.offsetWidth >= ctrl.offsetLeft) break;
  19096. }
  19097. ctrl.offsetLeft = fixOffset(tab.offsetLeft + tab.offsetWidth - elements.canvas.clientWidth);
  19098. }
  19099. /**
  19100. * Update size calculations when the window is resized.
  19101. */
  19102. function handleWindowResize () {
  19103. ctrl.lastSelectedIndex = ctrl.selectedIndex;
  19104. ctrl.offsetLeft = fixOffset(ctrl.offsetLeft);
  19105. $mdUtil.nextTick(function () {
  19106. ctrl.updateInkBarStyles();
  19107. updatePagination();
  19108. });
  19109. }
  19110. function handleInkBar (hide) {
  19111. angular.element(elements.inkBar).toggleClass('ng-hide', hide);
  19112. }
  19113. /**
  19114. * Toggle dynamic height class when value changes
  19115. * @param value
  19116. */
  19117. function handleDynamicHeight (value) {
  19118. $element.toggleClass('md-dynamic-height', value);
  19119. }
  19120. /**
  19121. * Remove a tab from the data and select the nearest valid tab.
  19122. * @param tabData
  19123. */
  19124. function removeTab (tabData) {
  19125. if (destroyed) return;
  19126. var selectedIndex = ctrl.selectedIndex,
  19127. tab = ctrl.tabs.splice(tabData.getIndex(), 1)[ 0 ];
  19128. refreshIndex();
  19129. // when removing a tab, if the selected index did not change, we have to manually trigger the
  19130. // tab select/deselect events
  19131. if (ctrl.selectedIndex === selectedIndex) {
  19132. tab.scope.deselect();
  19133. ctrl.tabs[ ctrl.selectedIndex ] && ctrl.tabs[ ctrl.selectedIndex ].scope.select();
  19134. }
  19135. $mdUtil.nextTick(function () {
  19136. updatePagination();
  19137. ctrl.offsetLeft = fixOffset(ctrl.offsetLeft);
  19138. });
  19139. }
  19140. /**
  19141. * Create an entry in the tabs array for a new tab at the specified index.
  19142. * @param tabData
  19143. * @param index
  19144. * @returns {*}
  19145. */
  19146. function insertTab (tabData, index) {
  19147. var hasLoaded = loaded;
  19148. var proto = {
  19149. getIndex: function () { return ctrl.tabs.indexOf(tab); },
  19150. isActive: function () { return this.getIndex() === ctrl.selectedIndex; },
  19151. isLeft: function () { return this.getIndex() < ctrl.selectedIndex; },
  19152. isRight: function () { return this.getIndex() > ctrl.selectedIndex; },
  19153. shouldRender: function () { return !ctrl.noDisconnect || this.isActive(); },
  19154. hasFocus: function () {
  19155. return !ctrl.lastClick
  19156. && ctrl.hasFocus && this.getIndex() === ctrl.focusIndex;
  19157. },
  19158. id: $mdUtil.nextUid()
  19159. },
  19160. tab = angular.extend(proto, tabData);
  19161. if (angular.isDefined(index)) {
  19162. ctrl.tabs.splice(index, 0, tab);
  19163. } else {
  19164. ctrl.tabs.push(tab);
  19165. }
  19166. processQueue();
  19167. updateHasContent();
  19168. $mdUtil.nextTick(function () {
  19169. updatePagination();
  19170. // if autoselect is enabled, select the newly added tab
  19171. if (hasLoaded && ctrl.autoselect) $mdUtil.nextTick(function () {
  19172. $mdUtil.nextTick(function () { select(ctrl.tabs.indexOf(tab)); });
  19173. });
  19174. });
  19175. return tab;
  19176. }
  19177. // Getter methods
  19178. /**
  19179. * Gathers references to all of the DOM elements used by this controller.
  19180. * @returns {{}}
  19181. */
  19182. function getElements () {
  19183. var elements = {};
  19184. // gather tab bar elements
  19185. elements.wrapper = $element[ 0 ].getElementsByTagName('md-tabs-wrapper')[ 0 ];
  19186. elements.data = $element[ 0 ].getElementsByTagName('md-tab-data')[ 0 ];
  19187. elements.canvas = elements.wrapper.getElementsByTagName('md-tabs-canvas')[ 0 ];
  19188. elements.paging = elements.canvas.getElementsByTagName('md-pagination-wrapper')[ 0 ];
  19189. elements.tabs = elements.paging.getElementsByTagName('md-tab-item');
  19190. elements.dummies = elements.canvas.getElementsByTagName('md-dummy-tab');
  19191. elements.inkBar = elements.paging.getElementsByTagName('md-ink-bar')[ 0 ];
  19192. // gather tab content elements
  19193. elements.contentsWrapper = $element[ 0 ].getElementsByTagName('md-tabs-content-wrapper')[ 0 ];
  19194. elements.contents = elements.contentsWrapper.getElementsByTagName('md-tab-content');
  19195. return elements;
  19196. }
  19197. /**
  19198. * Determines whether or not the left pagination arrow should be enabled.
  19199. * @returns {boolean}
  19200. */
  19201. function canPageBack () {
  19202. return ctrl.offsetLeft > 0;
  19203. }
  19204. /**
  19205. * Determines whether or not the right pagination arrow should be enabled.
  19206. * @returns {*|boolean}
  19207. */
  19208. function canPageForward () {
  19209. var lastTab = elements.tabs[ elements.tabs.length - 1 ];
  19210. return lastTab && lastTab.offsetLeft + lastTab.offsetWidth > elements.canvas.clientWidth +
  19211. ctrl.offsetLeft;
  19212. }
  19213. /**
  19214. * Determines if the UI should stretch the tabs to fill the available space.
  19215. * @returns {*}
  19216. */
  19217. function shouldStretchTabs () {
  19218. switch (ctrl.stretchTabs) {
  19219. case 'always':
  19220. return true;
  19221. case 'never':
  19222. return false;
  19223. default:
  19224. return !ctrl.shouldPaginate
  19225. && $window.matchMedia('(max-width: 600px)').matches;
  19226. }
  19227. }
  19228. /**
  19229. * Determines if the tabs should appear centered.
  19230. * @returns {string|boolean}
  19231. */
  19232. function shouldCenterTabs () {
  19233. return ctrl.centerTabs && !ctrl.shouldPaginate;
  19234. }
  19235. /**
  19236. * Determines if pagination is necessary to display the tabs within the available space.
  19237. * @returns {boolean}
  19238. */
  19239. function shouldPaginate () {
  19240. if (ctrl.noPagination || !loaded) return false;
  19241. var canvasWidth = $element.prop('clientWidth');
  19242. angular.forEach(elements.dummies, function (tab) { canvasWidth -= tab.offsetWidth; });
  19243. return canvasWidth < 0;
  19244. }
  19245. /**
  19246. * Finds the nearest tab index that is available. This is primarily used for when the active
  19247. * tab is removed.
  19248. * @param newIndex
  19249. * @returns {*}
  19250. */
  19251. function getNearestSafeIndex (newIndex) {
  19252. if (newIndex === -1) return -1;
  19253. var maxOffset = Math.max(ctrl.tabs.length - newIndex, newIndex),
  19254. i, tab;
  19255. for (i = 0; i <= maxOffset; i++) {
  19256. tab = ctrl.tabs[ newIndex + i ];
  19257. if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
  19258. tab = ctrl.tabs[ newIndex - i ];
  19259. if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
  19260. }
  19261. return newIndex;
  19262. }
  19263. // Utility methods
  19264. /**
  19265. * Defines a property using a getter and setter in order to trigger a change handler without
  19266. * using `$watch` to observe changes.
  19267. * @param key
  19268. * @param handler
  19269. * @param value
  19270. */
  19271. function defineProperty (key, handler, value) {
  19272. Object.defineProperty(ctrl, key, {
  19273. get: function () { return value; },
  19274. set: function (newValue) {
  19275. var oldValue = value;
  19276. value = newValue;
  19277. handler && handler(newValue, oldValue);
  19278. }
  19279. });
  19280. }
  19281. /**
  19282. * Updates whether or not pagination should be displayed.
  19283. */
  19284. function updatePagination () {
  19285. if (!shouldStretchTabs()) updatePagingWidth();
  19286. ctrl.maxTabWidth = getMaxTabWidth();
  19287. ctrl.shouldPaginate = shouldPaginate();
  19288. }
  19289. function updatePagingWidth() {
  19290. var width = 1;
  19291. angular.forEach(elements.dummies, function (element) { width += element.offsetWidth; });
  19292. angular.element(elements.paging).css('width', width + 'px');
  19293. }
  19294. function getMaxTabWidth () {
  19295. return $element.prop('clientWidth');
  19296. }
  19297. /**
  19298. * Re-orders the tabs and updates the selected and focus indexes to their new positions.
  19299. * This is triggered by `tabDirective.js` when the user's tabs have been re-ordered.
  19300. */
  19301. function updateTabOrder () {
  19302. var selectedItem = ctrl.tabs[ ctrl.selectedIndex ],
  19303. focusItem = ctrl.tabs[ ctrl.focusIndex ];
  19304. ctrl.tabs = ctrl.tabs.sort(function (a, b) {
  19305. return a.index - b.index;
  19306. });
  19307. ctrl.selectedIndex = ctrl.tabs.indexOf(selectedItem);
  19308. ctrl.focusIndex = ctrl.tabs.indexOf(focusItem);
  19309. }
  19310. /**
  19311. * This moves the selected or focus index left or right. This is used by the keydown handler.
  19312. * @param inc
  19313. */
  19314. function incrementIndex (inc, focus) {
  19315. var newIndex,
  19316. key = focus ? 'focusIndex' : 'selectedIndex',
  19317. index = ctrl[ key ];
  19318. for (newIndex = index + inc;
  19319. ctrl.tabs[ newIndex ] && ctrl.tabs[ newIndex ].scope.disabled;
  19320. newIndex += inc) {}
  19321. if (ctrl.tabs[ newIndex ]) {
  19322. ctrl[ key ] = newIndex;
  19323. }
  19324. }
  19325. /**
  19326. * This is used to forward focus to dummy elements. This method is necessary to avoid aniation
  19327. * issues when attempting to focus an item that is out of view.
  19328. */
  19329. function redirectFocus () {
  19330. elements.dummies[ ctrl.focusIndex ].focus();
  19331. }
  19332. /**
  19333. * Forces the pagination to move the focused tab into view.
  19334. */
  19335. function adjustOffset (index) {
  19336. if (index == null) index = ctrl.focusIndex;
  19337. if (!elements.tabs[ index ]) return;
  19338. if (ctrl.shouldCenterTabs) return;
  19339. var tab = elements.tabs[ index ],
  19340. left = tab.offsetLeft,
  19341. right = tab.offsetWidth + left;
  19342. ctrl.offsetLeft = Math.max(ctrl.offsetLeft, fixOffset(right - elements.canvas.clientWidth + 32 * 2));
  19343. ctrl.offsetLeft = Math.min(ctrl.offsetLeft, fixOffset(left));
  19344. }
  19345. /**
  19346. * Iterates through all queued functions and clears the queue. This is used for functions that
  19347. * are called before the UI is ready, such as size calculations.
  19348. */
  19349. function processQueue () {
  19350. queue.forEach(function (func) { $mdUtil.nextTick(func); });
  19351. queue = [];
  19352. }
  19353. /**
  19354. * Determines if the tab content area is needed.
  19355. */
  19356. function updateHasContent () {
  19357. var hasContent = false;
  19358. angular.forEach(ctrl.tabs, function (tab) {
  19359. if (tab.template) hasContent = true;
  19360. });
  19361. ctrl.hasContent = hasContent;
  19362. }
  19363. /**
  19364. * Moves the indexes to their nearest valid values.
  19365. */
  19366. function refreshIndex () {
  19367. ctrl.selectedIndex = getNearestSafeIndex(ctrl.selectedIndex);
  19368. ctrl.focusIndex = getNearestSafeIndex(ctrl.focusIndex);
  19369. }
  19370. /**
  19371. * Calculates the content height of the current tab.
  19372. * @returns {*}
  19373. */
  19374. function updateHeightFromContent () {
  19375. if (!ctrl.dynamicHeight) return $element.css('height', '');
  19376. if (!ctrl.tabs.length) return queue.push(updateHeightFromContent);
  19377. var tabContent = elements.contents[ ctrl.selectedIndex ],
  19378. contentHeight = tabContent ? tabContent.offsetHeight : 0,
  19379. tabsHeight = elements.wrapper.offsetHeight,
  19380. newHeight = contentHeight + tabsHeight,
  19381. currentHeight = $element.prop('offsetHeight');
  19382. // Adjusts calculations for when the buttons are bottom-aligned since this relies on absolute
  19383. // positioning. This should probably be cleaned up if a cleaner solution is possible.
  19384. if ($element.attr('md-align-tabs') === 'bottom') {
  19385. currentHeight -= tabsHeight;
  19386. newHeight -= tabsHeight;
  19387. // Need to include bottom border in these calculations
  19388. if ($element.attr('md-border-bottom') !== undefined) ++currentHeight;
  19389. }
  19390. if (currentHeight === newHeight) return;
  19391. // Lock during animation so the user can't change tabs
  19392. locked = true;
  19393. var fromHeight = { height: currentHeight + 'px' },
  19394. toHeight = { height: newHeight + 'px' };
  19395. // Set the height to the current, specific pixel height to fix a bug on iOS where the height
  19396. // first animates to 0, then back to the proper height causing a visual glitch
  19397. $element.css(fromHeight);
  19398. // Animate the height from the old to the new
  19399. $animateCss($element, {
  19400. from: fromHeight,
  19401. to: toHeight,
  19402. easing: 'cubic-bezier(0.35, 0, 0.25, 1)',
  19403. duration: 0.5
  19404. }).start().done(function () {
  19405. // Then (to fix the same iOS issue as above), disable transitions and remove the specific
  19406. // pixel height so the height can size with browser width/content changes, etc.
  19407. $element.css({
  19408. transition: 'none',
  19409. height: ''
  19410. });
  19411. // In the next tick, re-allow transitions (if we do it all at once, $element.css is "smart"
  19412. // enough to batch it for us instead of doing it immediately, which undoes the original
  19413. // transition: none)
  19414. $mdUtil.nextTick(function() {
  19415. $element.css('transition', '');
  19416. });
  19417. // And unlock so tab changes can occur
  19418. locked = false;
  19419. });
  19420. }
  19421. /**
  19422. * Repositions the ink bar to the selected tab.
  19423. * @returns {*}
  19424. */
  19425. function updateInkBarStyles () {
  19426. if (!elements.tabs[ ctrl.selectedIndex ]) {
  19427. angular.element(elements.inkBar).css({ left: 'auto', right: 'auto' });
  19428. return;
  19429. }
  19430. if (!ctrl.tabs.length) return queue.push(ctrl.updateInkBarStyles);
  19431. // if the element is not visible, we will not be able to calculate sizes until it is
  19432. // we should treat that as a resize event rather than just updating the ink bar
  19433. if (!$element.prop('offsetParent')) return handleResizeWhenVisible();
  19434. var index = ctrl.selectedIndex,
  19435. totalWidth = elements.paging.offsetWidth,
  19436. tab = elements.tabs[ index ],
  19437. left = tab.offsetLeft,
  19438. right = totalWidth - left - tab.offsetWidth,
  19439. tabWidth;
  19440. if (ctrl.shouldCenterTabs) {
  19441. tabWidth = Array.prototype.slice.call(elements.tabs).reduce(function (value, element) {
  19442. return value + element.offsetWidth;
  19443. }, 0);
  19444. if (totalWidth > tabWidth) $mdUtil.nextTick(updateInkBarStyles, false);
  19445. }
  19446. updateInkBarClassName();
  19447. angular.element(elements.inkBar).css({ left: left + 'px', right: right + 'px' });
  19448. }
  19449. /**
  19450. * Adds left/right classes so that the ink bar will animate properly.
  19451. */
  19452. function updateInkBarClassName () {
  19453. var newIndex = ctrl.selectedIndex,
  19454. oldIndex = ctrl.lastSelectedIndex,
  19455. ink = angular.element(elements.inkBar);
  19456. if (!angular.isNumber(oldIndex)) return;
  19457. ink
  19458. .toggleClass('md-left', newIndex < oldIndex)
  19459. .toggleClass('md-right', newIndex > oldIndex);
  19460. }
  19461. /**
  19462. * Takes an offset value and makes sure that it is within the min/max allowed values.
  19463. * @param value
  19464. * @returns {*}
  19465. */
  19466. function fixOffset (value) {
  19467. if (!elements.tabs.length || !ctrl.shouldPaginate) return 0;
  19468. var lastTab = elements.tabs[ elements.tabs.length - 1 ],
  19469. totalWidth = lastTab.offsetLeft + lastTab.offsetWidth;
  19470. value = Math.max(0, value);
  19471. value = Math.min(totalWidth - elements.canvas.clientWidth, value);
  19472. return value;
  19473. }
  19474. /**
  19475. * Attaches a ripple to the tab item element.
  19476. * @param scope
  19477. * @param element
  19478. */
  19479. function attachRipple (scope, element) {
  19480. var options = { colorElement: angular.element(elements.inkBar) };
  19481. $mdTabInkRipple.attach(scope, element, options);
  19482. }
  19483. }
  19484. MdTabsController.$inject = ["$scope", "$element", "$window", "$mdConstant", "$mdTabInkRipple", "$mdUtil", "$animateCss", "$attrs", "$compile", "$mdTheming"];
  19485. })();
  19486. (function(){
  19487. "use strict";
  19488. /**
  19489. * @ngdoc directive
  19490. * @name mdTabs
  19491. * @module material.components.tabs
  19492. *
  19493. * @restrict E
  19494. *
  19495. * @description
  19496. * The `<md-tabs>` directive serves as the container for 1..n `<md-tab>` child directives to produces a Tabs components.
  19497. * In turn, the nested `<md-tab>` directive is used to specify a tab label for the **header button** and a [optional] tab view
  19498. * content that will be associated with each tab button.
  19499. *
  19500. * Below is the markup for its simplest usage:
  19501. *
  19502. * <hljs lang="html">
  19503. * <md-tabs>
  19504. * <md-tab label="Tab #1"></md-tab>
  19505. * <md-tab label="Tab #2"></md-tab>
  19506. * <md-tab label="Tab #3"></md-tab>
  19507. * </md-tabs>
  19508. * </hljs>
  19509. *
  19510. * Tabs supports three (3) usage scenarios:
  19511. *
  19512. * 1. Tabs (buttons only)
  19513. * 2. Tabs with internal view content
  19514. * 3. Tabs with external view content
  19515. *
  19516. * **Tab-only** support is useful when tab buttons are used for custom navigation regardless of any other components, content, or views.
  19517. * **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.
  19518. * **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.
  19519. *
  19520. * Additional features also include:
  19521. *
  19522. * * Content can include any markup.
  19523. * * If a tab is disabled while active/selected, then the next tab will be auto-selected.
  19524. *
  19525. * ### Explanation of tab stretching
  19526. *
  19527. * 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.
  19528. *
  19529. * On mobile devices, tabs will be expanded to fill the available horizontal space. When this happens, all tabs will become the same size.
  19530. *
  19531. * On desktops, by default, stretching will never occur.
  19532. *
  19533. * This default behavior can be overridden through the `md-stretch-tabs` attribute. Here is a table showing when stretching will occur:
  19534. *
  19535. * `md-stretch-tabs` | mobile | desktop
  19536. * ------------------|-----------|--------
  19537. * `auto` | stretched | ---
  19538. * `always` | stretched | stretched
  19539. * `never` | --- | ---
  19540. *
  19541. * @param {integer=} md-selected Index of the active/selected tab
  19542. * @param {boolean=} md-no-ink If present, disables ink ripple effects.
  19543. * @param {boolean=} md-no-ink-bar If present, disables the selection ink bar.
  19544. * @param {string=} md-align-tabs Attribute to indicate position of tab buttons: `bottom` or `top`; default is `top`
  19545. * @param {string=} md-stretch-tabs Attribute to indicate whether or not to stretch tabs: `auto`, `always`, or `never`; default is `auto`
  19546. * @param {boolean=} md-dynamic-height When enabled, the tab wrapper will resize based on the contents of the selected tab
  19547. * @param {boolean=} md-center-tabs When enabled, tabs will be centered provided there is no need for pagination
  19548. * @param {boolean=} md-no-pagination When enabled, pagination will remain off
  19549. * @param {boolean=} md-swipe-content When enabled, swipe gestures will be enabled for the content area to jump between tabs
  19550. * @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
  19551. * @param {boolean=} md-autoselect When present, any tabs added after the initial load will be automatically selected
  19552. *
  19553. * @usage
  19554. * <hljs lang="html">
  19555. * <md-tabs md-selected="selectedIndex" >
  19556. * <img ng-src="img/angular.png" class="centered">
  19557. * <md-tab
  19558. * ng-repeat="tab in tabs | orderBy:predicate:reversed"
  19559. * md-on-select="onTabSelected(tab)"
  19560. * md-on-deselect="announceDeselected(tab)"
  19561. * ng-disabled="tab.disabled">
  19562. * <md-tab-label>
  19563. * {{tab.title}}
  19564. * <img src="img/removeTab.png" ng-click="removeTab(tab)" class="delete">
  19565. * </md-tab-label>
  19566. * <md-tab-body>
  19567. * {{tab.content}}
  19568. * </md-tab-body>
  19569. * </md-tab>
  19570. * </md-tabs>
  19571. * </hljs>
  19572. *
  19573. */
  19574. angular
  19575. .module('material.components.tabs')
  19576. .directive('mdTabs', MdTabs);
  19577. function MdTabs () {
  19578. return {
  19579. scope: {
  19580. selectedIndex: '=?mdSelected'
  19581. },
  19582. template: function (element, attr) {
  19583. attr[ "$mdTabsTemplate" ] = element.html();
  19584. return '' +
  19585. '<md-tabs-wrapper> ' +
  19586. '<md-tab-data></md-tab-data> ' +
  19587. '<md-prev-button ' +
  19588. 'tabindex="-1" ' +
  19589. 'role="button" ' +
  19590. 'aria-label="Previous Page" ' +
  19591. 'aria-disabled="{{!$mdTabsCtrl.canPageBack()}}" ' +
  19592. 'ng-class="{ \'md-disabled\': !$mdTabsCtrl.canPageBack() }" ' +
  19593. 'ng-if="$mdTabsCtrl.shouldPaginate" ' +
  19594. 'ng-click="$mdTabsCtrl.previousPage()"> ' +
  19595. '<md-icon md-svg-icon="md-tabs-arrow"></md-icon> ' +
  19596. '</md-prev-button> ' +
  19597. '<md-next-button ' +
  19598. 'tabindex="-1" ' +
  19599. 'role="button" ' +
  19600. 'aria-label="Next Page" ' +
  19601. 'aria-disabled="{{!$mdTabsCtrl.canPageForward()}}" ' +
  19602. 'ng-class="{ \'md-disabled\': !$mdTabsCtrl.canPageForward() }" ' +
  19603. 'ng-if="$mdTabsCtrl.shouldPaginate" ' +
  19604. 'ng-click="$mdTabsCtrl.nextPage()"> ' +
  19605. '<md-icon md-svg-icon="md-tabs-arrow"></md-icon> ' +
  19606. '</md-next-button> ' +
  19607. '<md-tabs-canvas ' +
  19608. 'tabindex="0" ' +
  19609. 'aria-activedescendant="tab-item-{{$mdTabsCtrl.tabs[$mdTabsCtrl.focusIndex].id}}" ' +
  19610. 'ng-focus="$mdTabsCtrl.redirectFocus()" ' +
  19611. 'ng-class="{ ' +
  19612. '\'md-paginated\': $mdTabsCtrl.shouldPaginate, ' +
  19613. '\'md-center-tabs\': $mdTabsCtrl.shouldCenterTabs ' +
  19614. '}" ' +
  19615. 'ng-keydown="$mdTabsCtrl.keydown($event)" ' +
  19616. 'role="tablist"> ' +
  19617. '<md-pagination-wrapper ' +
  19618. 'ng-class="{ \'md-center-tabs\': $mdTabsCtrl.shouldCenterTabs }" ' +
  19619. 'md-tab-scroll="$mdTabsCtrl.scroll($event)"> ' +
  19620. '<md-tab-item ' +
  19621. 'tabindex="-1" ' +
  19622. 'class="md-tab" ' +
  19623. 'style="max-width: {{ $mdTabsCtrl.maxTabWidth + \'px\' }}" ' +
  19624. 'ng-repeat="tab in $mdTabsCtrl.tabs" ' +
  19625. 'role="tab" ' +
  19626. 'aria-controls="tab-content-{{::tab.id}}" ' +
  19627. 'aria-selected="{{tab.isActive()}}" ' +
  19628. 'aria-disabled="{{tab.scope.disabled || \'false\'}}" ' +
  19629. 'ng-click="$mdTabsCtrl.select(tab.getIndex())" ' +
  19630. 'ng-class="{ ' +
  19631. '\'md-active\': tab.isActive(), ' +
  19632. '\'md-focused\': tab.hasFocus(), ' +
  19633. '\'md-disabled\': tab.scope.disabled ' +
  19634. '}" ' +
  19635. 'ng-disabled="tab.scope.disabled" ' +
  19636. 'md-swipe-left="$mdTabsCtrl.nextPage()" ' +
  19637. 'md-swipe-right="$mdTabsCtrl.previousPage()" ' +
  19638. 'md-tabs-template="::tab.label" ' +
  19639. 'md-scope="::tab.parent"></md-tab-item> ' +
  19640. '<md-ink-bar></md-ink-bar> ' +
  19641. '</md-pagination-wrapper> ' +
  19642. '<div class="md-visually-hidden md-dummy-wrapper"> ' +
  19643. '<md-dummy-tab ' +
  19644. 'class="md-tab" ' +
  19645. 'tabindex="-1" ' +
  19646. 'id="tab-item-{{::tab.id}}" ' +
  19647. 'role="tab" ' +
  19648. 'aria-controls="tab-content-{{::tab.id}}" ' +
  19649. 'aria-selected="{{tab.isActive()}}" ' +
  19650. 'aria-disabled="{{tab.scope.disabled || \'false\'}}" ' +
  19651. 'ng-focus="$mdTabsCtrl.hasFocus = true" ' +
  19652. 'ng-blur="$mdTabsCtrl.hasFocus = false" ' +
  19653. 'ng-repeat="tab in $mdTabsCtrl.tabs" ' +
  19654. 'md-tabs-template="::tab.label" ' +
  19655. 'md-scope="::tab.parent"></md-dummy-tab> ' +
  19656. '</div> ' +
  19657. '</md-tabs-canvas> ' +
  19658. '</md-tabs-wrapper> ' +
  19659. '<md-tabs-content-wrapper ng-show="$mdTabsCtrl.hasContent && $mdTabsCtrl.selectedIndex >= 0"> ' +
  19660. '<md-tab-content ' +
  19661. 'id="tab-content-{{::tab.id}}" ' +
  19662. 'role="tabpanel" ' +
  19663. 'aria-labelledby="tab-item-{{::tab.id}}" ' +
  19664. 'md-swipe-left="$mdTabsCtrl.swipeContent && $mdTabsCtrl.incrementIndex(1)" ' +
  19665. 'md-swipe-right="$mdTabsCtrl.swipeContent && $mdTabsCtrl.incrementIndex(-1)" ' +
  19666. 'ng-if="$mdTabsCtrl.hasContent" ' +
  19667. 'ng-repeat="(index, tab) in $mdTabsCtrl.tabs" ' +
  19668. 'ng-class="{ ' +
  19669. '\'md-no-transition\': $mdTabsCtrl.lastSelectedIndex == null, ' +
  19670. '\'md-active\': tab.isActive(), ' +
  19671. '\'md-left\': tab.isLeft(), ' +
  19672. '\'md-right\': tab.isRight(), ' +
  19673. '\'md-no-scroll\': $mdTabsCtrl.dynamicHeight ' +
  19674. '}"> ' +
  19675. '<div ' +
  19676. 'md-tabs-template="::tab.template" ' +
  19677. 'md-connected-if="tab.isActive()" ' +
  19678. 'md-scope="::tab.parent" ' +
  19679. 'ng-if="$mdTabsCtrl.enableDisconnect || tab.shouldRender()"></div> ' +
  19680. '</md-tab-content> ' +
  19681. '</md-tabs-content-wrapper>';
  19682. },
  19683. controller: 'MdTabsController',
  19684. controllerAs: '$mdTabsCtrl',
  19685. bindToController: true
  19686. };
  19687. }
  19688. })();
  19689. (function(){
  19690. "use strict";
  19691. angular
  19692. .module('material.components.tabs')
  19693. .directive('mdTabsTemplate', MdTabsTemplate);
  19694. function MdTabsTemplate ($compile, $mdUtil) {
  19695. return {
  19696. restrict: 'A',
  19697. link: link,
  19698. scope: {
  19699. template: '=mdTabsTemplate',
  19700. connected: '=?mdConnectedIf',
  19701. compileScope: '=mdScope'
  19702. },
  19703. require: '^?mdTabs'
  19704. };
  19705. function link (scope, element, attr, ctrl) {
  19706. if (!ctrl) return;
  19707. var compileScope = ctrl.enableDisconnect ? scope.compileScope.$new() : scope.compileScope;
  19708. element.html(scope.template);
  19709. $compile(element.contents())(compileScope);
  19710. element.on('DOMSubtreeModified', function () {
  19711. ctrl.updatePagination();
  19712. ctrl.updateInkBarStyles();
  19713. });
  19714. return $mdUtil.nextTick(handleScope);
  19715. function handleScope () {
  19716. scope.$watch('connected', function (value) { value === false ? disconnect() : reconnect(); });
  19717. scope.$on('$destroy', reconnect);
  19718. }
  19719. function disconnect () {
  19720. if (ctrl.enableDisconnect) $mdUtil.disconnectScope(compileScope);
  19721. }
  19722. function reconnect () {
  19723. if (ctrl.enableDisconnect) $mdUtil.reconnectScope(compileScope);
  19724. }
  19725. }
  19726. }
  19727. MdTabsTemplate.$inject = ["$compile", "$mdUtil"];
  19728. })();
  19729. (function(){
  19730. 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-ink-ripple { color: '{{foreground-2}}'; }md-checkbox.md-THEME_NAME-theme.md-checked .md-ink-ripple { color: '{{accent-color-0.87}}'; }md-checkbox.md-THEME_NAME-theme .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-ink-ripple { color: '{{foreground-2}}'; }md-checkbox.md-THEME_NAME-theme:not([disabled]).md-primary.md-checked .md-ink-ripple { color: '{{primary-color-0.87}}'; }md-checkbox.md-THEME_NAME-theme:not([disabled]).md-primary .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-ink-ripple { color: '{{foreground-2}}'; }md-checkbox.md-THEME_NAME-theme:not([disabled]).md-warn.md-checked .md-ink-ripple { color: '{{warn-color-0.87}}'; }md-checkbox.md-THEME_NAME-theme:not([disabled]).md-warn .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}}'; }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}}'; }/** Theme styles for mdCalendar. */.md-calendar.md-THEME_NAME-theme { color: '{{foreground-1}}'; } .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-hue-1}}'; color: '{{foreground-1}}'; }.md-THEME_NAME-theme .md-calendar-date.md-calendar-date-today .md-calendar-date-selection-indicator { border: 1px solid '{{primary-500}}'; }.md-THEME_NAME-theme .md-calendar-date.md-calendar-date-today.md-calendar-date-disabled { color: '{{primary-500-0.6}}'; }.md-THEME_NAME-theme .md-calendar-date.md-focus .md-calendar-date-selection-indicator { background: '{{background-hue-1}}'; }.md-THEME_NAME-theme .md-calendar-date-selection-indicator:hover { background: '{{background-hue-1}}'; }.md-THEME_NAME-theme .md-calendar-date.md-calendar-selected-date .md-calendar-date-selection-indicator, .md-THEME_NAME-theme .md-calendar-date.md-focus.md-calendar-selected-date .md-calendar-date-selection-indicator { background: '{{primary-500}}'; color: '{{primary-500-contrast}}'; border-color: transparent; }.md-THEME_NAME-theme .md-calendar-date-disabled, .md-THEME_NAME-theme .md-calendar-month-label-disabled { color: '{{foreground-3}}'; }/** Theme styles for mdDatepicker. */md-datepicker.md-THEME_NAME-theme { background: '{{background-color}}'; }.md-THEME_NAME-theme .md-datepicker-input { color: '{{background-contrast}}'; background: '{{background-color}}'; } .md-THEME_NAME-theme .md-datepicker-input::-webkit-input-placeholder, .md-THEME_NAME-theme .md-datepicker-input::-moz-placeholder, .md-THEME_NAME-theme .md-datepicker-input:-moz-placeholder, .md-THEME_NAME-theme .md-datepicker-input:-ms-input-placeholder { color: '{{foreground-3}}'; }.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 .md-datepicker-expand-triangle { border-top-color: '{{foreground-3}}'; }.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, .md-THEME_NAME-theme .md-datepicker-input-mask-opaque { background: '{{background-color}}'; }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 :not(.md-char-counter), md-input-container.md-THEME_NAME-theme [ng-messages] :not(.md-char-counter), md-input-container.md-THEME_NAME-theme ng-message :not(.md-char-counter), md-input-container.md-THEME_NAME-theme data-ng-message :not(.md-char-counter), md-input-container.md-THEME_NAME-theme x-ng-message :not(.md-char-counter), md-input-container.md-THEME_NAME-theme [ng-message] :not(.md-char-counter), md-input-container.md-THEME_NAME-theme [data-ng-message] :not(.md-char-counter), md-input-container.md-THEME_NAME-theme [x-ng-message] :not(.md-char-counter), md-input-container.md-THEME_NAME-theme [ng-message-exp] :not(.md-char-counter), md-input-container.md-THEME_NAME-theme [data-ng-message-exp] :not(.md-char-counter), md-input-container.md-THEME_NAME-theme [x-ng-message-exp] :not(.md-char-counter) { 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 [ng-message-exp], md-input-container.md-THEME_NAME-theme.md-input-invalid [data-ng-message-exp], md-input-container.md-THEME_NAME-theme.md-input-invalid [x-ng-message-exp], 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], md-input-container.md-THEME_NAME-theme .md-input [disabled] { 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-avatar-icon { background-color: '{{foreground-3}}'; color: '{{background-color}}'; }md-list.md-THEME_NAME-theme md-list-item > md-icon { color: '{{foreground-2}}'; } md-list.md-THEME_NAME-theme md-list-item > md-icon.md-highlight { color: '{{primary-color}}'; } md-list.md-THEME_NAME-theme md-list-item > md-icon.md-highlight.md-accent { color: '{{accent-color}}'; }md-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-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-checked .md-ink-ripple { color: '{{accent-color-0.26}}'; }md-radio-group.md-THEME_NAME-theme.md-primary .md-checked:not([disabled]) .md-ink-ripple, md-radio-group.md-THEME_NAME-theme .md-checked:not([disabled]).md-primary .md-ink-ripple { color: '{{primary-color-0.26}}'; }md-radio-group.md-THEME_NAME-theme .md-checked.md-primary .md-ink-ripple { color: '{{warn-color-0.26}}'; }md-radio-group.md-THEME_NAME-theme.md-focused:not(:empty) .md-checked .md-container:before { background-color: '{{accent-color-0.26}}'; }md-radio-group.md-THEME_NAME-theme.md-focused:not(:empty) .md-checked: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-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-select.md-THEME_NAME-theme[disabled] .md-select-value { border-bottom-color: transparent; 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-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-ink-ripple { color: '{{background-500}}'; }md-switch.md-THEME_NAME-theme .md-thumb { background-color: '{{background-50}}'; }md-switch.md-THEME_NAME-theme .md-bar { background-color: '{{background-500}}'; }md-switch.md-THEME_NAME-theme.md-checked .md-ink-ripple { color: '{{accent-color}}'; }md-switch.md-THEME_NAME-theme.md-checked .md-thumb { background-color: '{{accent-color}}'; }md-switch.md-THEME_NAME-theme.md-checked .md-bar { background-color: '{{accent-color-0.5}}'; }md-switch.md-THEME_NAME-theme.md-checked.md-focused .md-thumb:before { background-color: '{{accent-color-0.26}}'; }md-switch.md-THEME_NAME-theme.md-checked.md-primary .md-ink-ripple { color: '{{primary-color}}'; }md-switch.md-THEME_NAME-theme.md-checked.md-primary .md-thumb { background-color: '{{primary-color}}'; }md-switch.md-THEME_NAME-theme.md-checked.md-primary .md-bar { background-color: '{{primary-color-0.5}}'; }md-switch.md-THEME_NAME-theme.md-checked.md-primary.md-focused .md-thumb:before { background-color: '{{primary-color-0.26}}'; }md-switch.md-THEME_NAME-theme.md-checked.md-warn .md-ink-ripple { color: '{{warn-color}}'; }md-switch.md-THEME_NAME-theme.md-checked.md-warn .md-thumb { background-color: '{{warn-color}}'; }md-switch.md-THEME_NAME-theme.md-checked.md-warn .md-bar { background-color: '{{warn-color-0.5}}'; }md-switch.md-THEME_NAME-theme.md-checked.md-warn.md-focused .md-thumb:before { background-color: '{{warn-color-0.26}}'; }md-switch.md-THEME_NAME-theme[disabled] .md-thumb { background-color: '{{background-400}}'; }md-switch.md-THEME_NAME-theme[disabled] .md-bar { background-color: '{{foreground-4}}'; }md-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-tabs.md-THEME_NAME-theme md-tabs-wrapper { background-color: transparent; border-color: '{{foreground-4}}'; }md-tabs.md-THEME_NAME-theme .md-paginator md-icon { color: '{{primary-color}}'; }md-tabs.md-THEME_NAME-theme md-ink-bar { color: '{{accent-color}}'; background: '{{accent-color}}'; }md-tabs.md-THEME_NAME-theme .md-tab { color: '{{foreground-2}}'; } md-tabs.md-THEME_NAME-theme .md-tab[disabled], md-tabs.md-THEME_NAME-theme .md-tab[disabled] md-icon { color: '{{foreground-3}}'; } md-tabs.md-THEME_NAME-theme .md-tab.md-active, md-tabs.md-THEME_NAME-theme .md-tab.md-active md-icon, md-tabs.md-THEME_NAME-theme .md-tab.md-focused, md-tabs.md-THEME_NAME-theme .md-tab.md-focused md-icon { color: '{{primary-color}}'; } md-tabs.md-THEME_NAME-theme .md-tab.md-focused { background: '{{primary-color-0.1}}'; } md-tabs.md-THEME_NAME-theme .md-tab .md-ripple-container { color: '{{accent-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-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}}'; }");
  19731. })();
  19732. })(window, window.angular);