angular-strap.compat.js 177 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474
  1. /**
  2. * angular-strap
  3. * @version v2.3.9 - 2016-06-10
  4. * @link http://mgcrea.github.io/angular-strap
  5. * @author Olivier Louvignes <olivier@mg-crea.com> (https://github.com/mgcrea)
  6. * @license MIT License, http://www.opensource.org/licenses/MIT
  7. */
  8. (function(window, document, undefined) {
  9. 'use strict';
  10. bsCompilerService.$inject = ["$q", "$http", "$injector", "$compile", "$controller", "$templateCache"];
  11. angular.module('mgcrea.ngStrap.typeahead', [ 'mgcrea.ngStrap.tooltip', 'mgcrea.ngStrap.helpers.parseOptions' ]).provider('$bsTypeahead', function() {
  12. var defaults = this.defaults = {
  13. animation: 'am-fade',
  14. prefixClass: 'typeahead',
  15. prefixEvent: '$typeahead',
  16. placement: 'bottom-left',
  17. templateUrl: 'typeahead/typeahead.tpl.html',
  18. trigger: 'focus',
  19. container: false,
  20. keyboard: true,
  21. html: false,
  22. delay: 0,
  23. minLength: 1,
  24. filter: 'bsAsyncFilter',
  25. limit: 6,
  26. autoSelect: false,
  27. comparator: '',
  28. trimValue: true
  29. };
  30. this.$get = ["$window", "$rootScope", "$bsTooltip", "$$rAF", "$timeout", function($window, $rootScope, $tooltip, $$rAF, $timeout) {
  31. function TypeaheadFactory(element, controller, config) {
  32. var $typeahead = {};
  33. var options = angular.extend({}, defaults, config);
  34. $typeahead = $tooltip(element, options);
  35. var parentScope = config.scope;
  36. var scope = $typeahead.$scope;
  37. scope.$resetMatches = function() {
  38. scope.$matches = [];
  39. scope.$activeIndex = options.autoSelect ? 0 : -1;
  40. };
  41. scope.$resetMatches();
  42. scope.$activate = function(index) {
  43. scope.$$postDigest(function() {
  44. $typeahead.activate(index);
  45. });
  46. };
  47. scope.$select = function(index, evt) {
  48. scope.$$postDigest(function() {
  49. $typeahead.select(index);
  50. });
  51. };
  52. scope.$isVisible = function() {
  53. return $typeahead.$isVisible();
  54. };
  55. $typeahead.update = function(matches) {
  56. scope.$matches = matches;
  57. if (scope.$activeIndex >= matches.length) {
  58. scope.$activeIndex = options.autoSelect ? 0 : -1;
  59. }
  60. safeDigest(scope);
  61. $$rAF($typeahead.$applyPlacement);
  62. };
  63. $typeahead.activate = function(index) {
  64. scope.$activeIndex = index;
  65. };
  66. $typeahead.select = function(index) {
  67. if (index === -1) return;
  68. var value = scope.$matches[index].value;
  69. controller.$setViewValue(value);
  70. controller.$render();
  71. scope.$resetMatches();
  72. if (parentScope) parentScope.$digest();
  73. scope.$emit(options.prefixEvent + '.select', value, index, $typeahead);
  74. if (angular.isDefined(options.onSelect) && angular.isFunction(options.onSelect)) {
  75. options.onSelect(value, index, $typeahead);
  76. }
  77. };
  78. $typeahead.$isVisible = function() {
  79. if (!options.minLength || !controller) {
  80. return !!scope.$matches.length;
  81. }
  82. return scope.$matches.length && angular.isString(controller.$viewValue) && controller.$viewValue.length >= options.minLength;
  83. };
  84. $typeahead.$getIndex = function(value) {
  85. var index;
  86. for (index = scope.$matches.length; index--; ) {
  87. if (angular.equals(scope.$matches[index].value, value)) break;
  88. }
  89. return index;
  90. };
  91. $typeahead.$onMouseDown = function(evt) {
  92. evt.preventDefault();
  93. evt.stopPropagation();
  94. };
  95. $typeahead.$onKeyDown = function(evt) {
  96. if (!/(38|40|13)/.test(evt.keyCode)) return;
  97. if ($typeahead.$isVisible() && !(evt.keyCode === 13 && scope.$activeIndex === -1)) {
  98. evt.preventDefault();
  99. evt.stopPropagation();
  100. }
  101. if (evt.keyCode === 13 && scope.$matches.length) {
  102. $typeahead.select(scope.$activeIndex);
  103. } else if (evt.keyCode === 38 && scope.$activeIndex > 0) {
  104. scope.$activeIndex--;
  105. } else if (evt.keyCode === 40 && scope.$activeIndex < scope.$matches.length - 1) {
  106. scope.$activeIndex++;
  107. } else if (angular.isUndefined(scope.$activeIndex)) {
  108. scope.$activeIndex = 0;
  109. }
  110. scope.$digest();
  111. };
  112. var show = $typeahead.show;
  113. $typeahead.show = function() {
  114. show();
  115. $timeout(function() {
  116. if ($typeahead.$element) {
  117. $typeahead.$element.on('mousedown', $typeahead.$onMouseDown);
  118. if (options.keyboard) {
  119. if (element) element.on('keydown', $typeahead.$onKeyDown);
  120. }
  121. }
  122. }, 0, false);
  123. };
  124. var hide = $typeahead.hide;
  125. $typeahead.hide = function() {
  126. if ($typeahead.$element) $typeahead.$element.off('mousedown', $typeahead.$onMouseDown);
  127. if (options.keyboard) {
  128. if (element) element.off('keydown', $typeahead.$onKeyDown);
  129. }
  130. if (!options.autoSelect) {
  131. $typeahead.activate(-1);
  132. }
  133. hide();
  134. };
  135. return $typeahead;
  136. }
  137. function safeDigest(scope) {
  138. scope.$$phase || scope.$root && scope.$root.$$phase || scope.$digest();
  139. }
  140. TypeaheadFactory.defaults = defaults;
  141. return TypeaheadFactory;
  142. } ];
  143. }).filter('bsAsyncFilter', ["$filter", function($filter) {
  144. return function(array, expression, comparator) {
  145. if (array && angular.isFunction(array.then)) {
  146. return array.then(function(results) {
  147. return $filter('filter')(results, expression, comparator);
  148. });
  149. }
  150. return $filter('filter')(array, expression, comparator);
  151. };
  152. } ]).directive('bsTypeahead', ["$window", "$parse", "$q", "$bsTypeahead", "$bsParseOptions", function($window, $parse, $q, $typeahead, $parseOptions) {
  153. var defaults = $typeahead.defaults;
  154. return {
  155. restrict: 'EAC',
  156. require: 'ngModel',
  157. link: function postLink(scope, element, attr, controller) {
  158. element.off('change');
  159. var options = {
  160. scope: scope
  161. };
  162. angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'placement', 'container', 'delay', 'trigger', 'keyboard', 'html', 'animation', 'filter', 'limit', 'minLength', 'watchOptions', 'selectMode', 'autoSelect', 'comparator', 'id', 'prefixEvent', 'prefixClass' ], function(key) {
  163. if (angular.isDefined(attr[key])) options[key] = attr[key];
  164. });
  165. var falseValueRegExp = /^(false|0|)$/i;
  166. angular.forEach([ 'html', 'container', 'trimValue', 'filter' ], function(key) {
  167. if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) options[key] = false;
  168. });
  169. angular.forEach([ 'onBeforeShow', 'onShow', 'onBeforeHide', 'onHide', 'onSelect' ], function(key) {
  170. var bsKey = 'bs' + key.charAt(0).toUpperCase() + key.slice(1);
  171. if (angular.isDefined(attr[bsKey])) {
  172. options[key] = scope.$eval(attr[bsKey]);
  173. }
  174. });
  175. if (!element.attr('autocomplete')) element.attr('autocomplete', 'off');
  176. var filter = angular.isDefined(options.filter) ? options.filter : defaults.filter;
  177. var limit = options.limit || defaults.limit;
  178. var comparator = options.comparator || defaults.comparator;
  179. var bsOptions = attr.bsOptions;
  180. if (filter) {
  181. bsOptions += ' | ' + filter + ':$viewValue';
  182. if (comparator) bsOptions += ':' + comparator;
  183. }
  184. if (limit) bsOptions += ' | limitTo:' + limit;
  185. var parsedOptions = $parseOptions(bsOptions);
  186. var typeahead = $typeahead(element, controller, options);
  187. if (options.watchOptions) {
  188. var watchedOptions = parsedOptions.$match[7].replace(/\|.+/, '').replace(/\(.*\)/g, '').trim();
  189. scope.$watchCollection(watchedOptions, function(newValue, oldValue) {
  190. parsedOptions.valuesFn(scope, controller).then(function(values) {
  191. typeahead.update(values);
  192. controller.$render();
  193. });
  194. });
  195. }
  196. scope.$watch(attr.ngModel, function(newValue, oldValue) {
  197. scope.$modelValue = newValue;
  198. parsedOptions.valuesFn(scope, controller).then(function(values) {
  199. if (options.selectMode && !values.length && newValue.length > 0) {
  200. controller.$setViewValue(controller.$viewValue.substring(0, controller.$viewValue.length - 1));
  201. return;
  202. }
  203. if (values.length > limit) values = values.slice(0, limit);
  204. typeahead.update(values);
  205. controller.$render();
  206. });
  207. });
  208. controller.$formatters.push(function(modelValue) {
  209. var displayValue = parsedOptions.displayValue(modelValue);
  210. if (displayValue) {
  211. return displayValue;
  212. }
  213. if (angular.isDefined(modelValue) && typeof modelValue !== 'object') {
  214. return modelValue;
  215. }
  216. return '';
  217. });
  218. controller.$render = function() {
  219. if (controller.$isEmpty(controller.$viewValue)) {
  220. return element.val('');
  221. }
  222. var index = typeahead.$getIndex(controller.$modelValue);
  223. var selected = index !== -1 ? typeahead.$scope.$matches[index].label : controller.$viewValue;
  224. selected = angular.isObject(selected) ? parsedOptions.displayValue(selected) : selected;
  225. var value = selected ? selected.toString().replace(/<(?:.|\n)*?>/gm, '') : '';
  226. var ss = element[0].selectionStart;
  227. var sd = element[0].selectionEnd;
  228. element.val(options.trimValue === false ? value : value.trim());
  229. element[0].setSelectionRange(ss, sd);
  230. };
  231. scope.$on('$destroy', function() {
  232. if (typeahead) typeahead.destroy();
  233. options = null;
  234. typeahead = null;
  235. });
  236. }
  237. };
  238. } ]);
  239. angular.module('mgcrea.ngStrap.tab', []).provider('$bsTab', function() {
  240. var defaults = this.defaults = {
  241. animation: 'am-fade',
  242. template: 'tab/tab.tpl.html',
  243. navClass: 'nav-tabs',
  244. activeClass: 'active'
  245. };
  246. var controller = this.controller = function($scope, $element, $attrs) {
  247. var self = this;
  248. self.$options = angular.copy(defaults);
  249. angular.forEach([ 'animation', 'navClass', 'activeClass' ], function(key) {
  250. if (angular.isDefined($attrs[key])) self.$options[key] = $attrs[key];
  251. });
  252. $scope.$navClass = self.$options.navClass;
  253. $scope.$activeClass = self.$options.activeClass;
  254. self.$panes = $scope.$panes = [];
  255. self.$activePaneChangeListeners = self.$viewChangeListeners = [];
  256. self.$push = function(pane) {
  257. if (angular.isUndefined(self.$panes.$active)) {
  258. $scope.$setActive(pane.name || 0);
  259. }
  260. self.$panes.push(pane);
  261. };
  262. self.$remove = function(pane) {
  263. var index = self.$panes.indexOf(pane);
  264. var active = self.$panes.$active;
  265. var activeIndex;
  266. if (angular.isString(active)) {
  267. activeIndex = self.$panes.map(function(pane) {
  268. return pane.name;
  269. }).indexOf(active);
  270. } else {
  271. activeIndex = self.$panes.$active;
  272. }
  273. self.$panes.splice(index, 1);
  274. if (index < activeIndex) {
  275. activeIndex--;
  276. } else if (index === activeIndex && activeIndex === self.$panes.length) {
  277. activeIndex--;
  278. }
  279. if (activeIndex >= 0 && activeIndex < self.$panes.length) {
  280. self.$setActive(self.$panes[activeIndex].name || activeIndex);
  281. } else {
  282. self.$setActive();
  283. }
  284. };
  285. self.$setActive = $scope.$setActive = function(value) {
  286. self.$panes.$active = value;
  287. self.$activePaneChangeListeners.forEach(function(fn) {
  288. fn();
  289. });
  290. };
  291. self.$isActive = $scope.$isActive = function($pane, $index) {
  292. return self.$panes.$active === $pane.name || self.$panes.$active === $index;
  293. };
  294. };
  295. this.$get = function() {
  296. var $tab = {};
  297. $tab.defaults = defaults;
  298. $tab.controller = controller;
  299. return $tab;
  300. };
  301. }).directive('bsTabs', ["$window", "$animate", "$bsTab", "$parse", function($window, $animate, $tab, $parse) {
  302. var defaults = $tab.defaults;
  303. return {
  304. require: [ '?ngModel', 'bsTabs' ],
  305. transclude: true,
  306. scope: true,
  307. controller: [ '$scope', '$element', '$attrs', $tab.controller ],
  308. templateUrl: function(element, attr) {
  309. return attr.template || defaults.template;
  310. },
  311. link: function postLink(scope, element, attrs, controllers) {
  312. var ngModelCtrl = controllers[0];
  313. var bsTabsCtrl = controllers[1];
  314. if (ngModelCtrl) {
  315. bsTabsCtrl.$activePaneChangeListeners.push(function() {
  316. ngModelCtrl.$setViewValue(bsTabsCtrl.$panes.$active);
  317. });
  318. ngModelCtrl.$formatters.push(function(modelValue) {
  319. bsTabsCtrl.$setActive(modelValue);
  320. return modelValue;
  321. });
  322. }
  323. if (attrs.bsActivePane) {
  324. var parsedBsActivePane = $parse(attrs.bsActivePane);
  325. bsTabsCtrl.$activePaneChangeListeners.push(function() {
  326. parsedBsActivePane.assign(scope, bsTabsCtrl.$panes.$active);
  327. });
  328. scope.$watch(attrs.bsActivePane, function(newValue, oldValue) {
  329. bsTabsCtrl.$setActive(newValue);
  330. }, true);
  331. }
  332. }
  333. };
  334. } ]).directive('bsPane', ["$window", "$animate", "$sce", function($window, $animate, $sce) {
  335. return {
  336. require: [ '^?ngModel', '^bsTabs' ],
  337. scope: true,
  338. link: function postLink(scope, element, attrs, controllers) {
  339. var bsTabsCtrl = controllers[1];
  340. element.addClass('tab-pane');
  341. attrs.$observe('title', function(newValue, oldValue) {
  342. scope.title = $sce.trustAsHtml(newValue);
  343. });
  344. scope.name = attrs.name;
  345. if (bsTabsCtrl.$options.animation) {
  346. element.addClass(bsTabsCtrl.$options.animation);
  347. }
  348. attrs.$observe('disabled', function(newValue, oldValue) {
  349. scope.disabled = scope.$eval(newValue);
  350. });
  351. bsTabsCtrl.$push(scope);
  352. scope.$on('$destroy', function() {
  353. bsTabsCtrl.$remove(scope);
  354. });
  355. function render() {
  356. var index = bsTabsCtrl.$panes.indexOf(scope);
  357. $animate[bsTabsCtrl.$isActive(scope, index) ? 'addClass' : 'removeClass'](element, bsTabsCtrl.$options.activeClass);
  358. }
  359. bsTabsCtrl.$activePaneChangeListeners.push(function() {
  360. render();
  361. });
  362. render();
  363. }
  364. };
  365. } ]);
  366. angular.module('mgcrea.ngStrap.tooltip', [ 'mgcrea.ngStrap.core', 'mgcrea.ngStrap.helpers.dimensions' ]).provider('$bsTooltip', function() {
  367. var defaults = this.defaults = {
  368. animation: 'am-fade',
  369. customClass: '',
  370. prefixClass: 'tooltip',
  371. prefixEvent: 'tooltip',
  372. container: false,
  373. target: false,
  374. placement: 'top',
  375. templateUrl: 'tooltip/tooltip.tpl.html',
  376. template: '',
  377. titleTemplate: false,
  378. trigger: 'hover focus',
  379. keyboard: false,
  380. html: false,
  381. show: false,
  382. title: '',
  383. type: '',
  384. delay: 0,
  385. autoClose: false,
  386. bsEnabled: true,
  387. mouseDownPreventDefault: true,
  388. mouseDownStopPropagation: true,
  389. viewport: {
  390. selector: 'body',
  391. padding: 0
  392. }
  393. };
  394. this.$get = ["$window", "$rootScope", "$bsCompiler", "$q", "$templateCache", "$http", "$animate", "$sce", "bsDimensions", "$$rAF", "$timeout", function($window, $rootScope, $bsCompiler, $q, $templateCache, $http, $animate, $sce, dimensions, $$rAF, $timeout) {
  395. var isNative = /(ip[ao]d|iphone|android)/gi.test($window.navigator.userAgent);
  396. var isTouch = 'createTouch' in $window.document && isNative;
  397. var $body = angular.element($window.document);
  398. function TooltipFactory(element, config) {
  399. var $tooltip = {};
  400. var options = $tooltip.$options = angular.extend({}, defaults, config);
  401. var promise = $tooltip.$promise = $bsCompiler.compile(options);
  402. var scope = $tooltip.$scope = options.scope && options.scope.$new() || $rootScope.$new();
  403. var nodeName = element[0].nodeName.toLowerCase();
  404. if (options.delay && angular.isString(options.delay)) {
  405. var split = options.delay.split(',').map(parseFloat);
  406. options.delay = split.length > 1 ? {
  407. show: split[0],
  408. hide: split[1]
  409. } : split[0];
  410. }
  411. $tooltip.$id = options.id || element.attr('id') || '';
  412. if (options.title) {
  413. scope.title = $sce.trustAsHtml(options.title);
  414. }
  415. scope.$setEnabled = function(isEnabled) {
  416. scope.$$postDigest(function() {
  417. $tooltip.setEnabled(isEnabled);
  418. });
  419. };
  420. scope.$hide = function() {
  421. scope.$$postDigest(function() {
  422. $tooltip.hide();
  423. });
  424. };
  425. scope.$show = function() {
  426. scope.$$postDigest(function() {
  427. $tooltip.show();
  428. });
  429. };
  430. scope.$toggle = function() {
  431. scope.$$postDigest(function() {
  432. $tooltip.toggle();
  433. });
  434. };
  435. $tooltip.$isShown = scope.$isShown = false;
  436. var timeout;
  437. var hoverState;
  438. var compileData;
  439. var tipElement;
  440. var tipContainer;
  441. var tipScope;
  442. promise.then(function(data) {
  443. compileData = data;
  444. $tooltip.init();
  445. });
  446. $tooltip.init = function() {
  447. if (options.delay && angular.isNumber(options.delay)) {
  448. options.delay = {
  449. show: options.delay,
  450. hide: options.delay
  451. };
  452. }
  453. if (options.container === 'self') {
  454. tipContainer = element;
  455. } else if (angular.isElement(options.container)) {
  456. tipContainer = options.container;
  457. } else if (options.container) {
  458. tipContainer = findElement(options.container);
  459. }
  460. bindTriggerEvents();
  461. if (options.target) {
  462. options.target = angular.isElement(options.target) ? options.target : findElement(options.target);
  463. }
  464. if (options.show) {
  465. scope.$$postDigest(function() {
  466. if (options.trigger === 'focus') {
  467. element[0].focus();
  468. } else {
  469. $tooltip.show();
  470. }
  471. });
  472. }
  473. };
  474. $tooltip.destroy = function() {
  475. unbindTriggerEvents();
  476. destroyTipElement();
  477. scope.$destroy();
  478. };
  479. $tooltip.enter = function() {
  480. clearTimeout(timeout);
  481. hoverState = 'in';
  482. if (!options.delay || !options.delay.show) {
  483. return $tooltip.show();
  484. }
  485. timeout = setTimeout(function() {
  486. if (hoverState === 'in') $tooltip.show();
  487. }, options.delay.show);
  488. };
  489. $tooltip.show = function() {
  490. if (!options.bsEnabled || $tooltip.$isShown) return;
  491. scope.$emit(options.prefixEvent + '.show.before', $tooltip);
  492. if (angular.isDefined(options.onBeforeShow) && angular.isFunction(options.onBeforeShow)) {
  493. options.onBeforeShow($tooltip);
  494. }
  495. var parent;
  496. var after;
  497. if (options.container) {
  498. parent = tipContainer;
  499. if (tipContainer[0].lastChild) {
  500. after = angular.element(tipContainer[0].lastChild);
  501. } else {
  502. after = null;
  503. }
  504. } else {
  505. parent = null;
  506. after = element;
  507. }
  508. if (tipElement) destroyTipElement();
  509. tipScope = $tooltip.$scope.$new();
  510. tipElement = $tooltip.$element = compileData.link(tipScope, function(clonedElement, scope) {});
  511. tipElement.css({
  512. top: '-9999px',
  513. left: '-9999px',
  514. right: 'auto',
  515. display: 'block',
  516. visibility: 'hidden'
  517. });
  518. if (options.animation) tipElement.addClass(options.animation);
  519. if (options.type) tipElement.addClass(options.prefixClass + '-' + options.type);
  520. if (options.customClass) tipElement.addClass(options.customClass);
  521. if (after) {
  522. after.after(tipElement);
  523. } else {
  524. parent.prepend(tipElement);
  525. }
  526. $tooltip.$isShown = scope.$isShown = true;
  527. safeDigest(scope);
  528. $tooltip.$applyPlacement();
  529. if (angular.version.minor <= 2) {
  530. $animate.enter(tipElement, parent, after, enterAnimateCallback);
  531. } else {
  532. $animate.enter(tipElement, parent, after).then(enterAnimateCallback);
  533. }
  534. safeDigest(scope);
  535. $$rAF(function() {
  536. if (tipElement) tipElement.css({
  537. visibility: 'visible'
  538. });
  539. if (options.keyboard) {
  540. if (options.trigger !== 'focus') {
  541. $tooltip.focus();
  542. }
  543. bindKeyboardEvents();
  544. }
  545. });
  546. if (options.autoClose) {
  547. bindAutoCloseEvents();
  548. }
  549. };
  550. function enterAnimateCallback() {
  551. scope.$emit(options.prefixEvent + '.show', $tooltip);
  552. if (angular.isDefined(options.onShow) && angular.isFunction(options.onShow)) {
  553. options.onShow($tooltip);
  554. }
  555. }
  556. $tooltip.leave = function() {
  557. clearTimeout(timeout);
  558. hoverState = 'out';
  559. if (!options.delay || !options.delay.hide) {
  560. return $tooltip.hide();
  561. }
  562. timeout = setTimeout(function() {
  563. if (hoverState === 'out') {
  564. $tooltip.hide();
  565. }
  566. }, options.delay.hide);
  567. };
  568. var _blur;
  569. var _tipToHide;
  570. $tooltip.hide = function(blur) {
  571. if (!$tooltip.$isShown) return;
  572. scope.$emit(options.prefixEvent + '.hide.before', $tooltip);
  573. if (angular.isDefined(options.onBeforeHide) && angular.isFunction(options.onBeforeHide)) {
  574. options.onBeforeHide($tooltip);
  575. }
  576. _blur = blur;
  577. _tipToHide = tipElement;
  578. if (angular.version.minor <= 2) {
  579. $animate.leave(tipElement, leaveAnimateCallback);
  580. } else {
  581. $animate.leave(tipElement).then(leaveAnimateCallback);
  582. }
  583. $tooltip.$isShown = scope.$isShown = false;
  584. safeDigest(scope);
  585. if (options.keyboard && tipElement !== null) {
  586. unbindKeyboardEvents();
  587. }
  588. if (options.autoClose && tipElement !== null) {
  589. unbindAutoCloseEvents();
  590. }
  591. };
  592. function leaveAnimateCallback() {
  593. scope.$emit(options.prefixEvent + '.hide', $tooltip);
  594. if (angular.isDefined(options.onHide) && angular.isFunction(options.onHide)) {
  595. options.onHide($tooltip);
  596. }
  597. if (tipElement === _tipToHide) {
  598. if (_blur && options.trigger === 'focus') {
  599. return element[0].blur();
  600. }
  601. destroyTipElement();
  602. }
  603. }
  604. $tooltip.toggle = function(evt) {
  605. if (evt) {
  606. evt.preventDefault();
  607. }
  608. if ($tooltip.$isShown) {
  609. $tooltip.leave();
  610. } else {
  611. $tooltip.enter();
  612. }
  613. };
  614. $tooltip.focus = function() {
  615. tipElement[0].focus();
  616. };
  617. $tooltip.setEnabled = function(isEnabled) {
  618. options.bsEnabled = isEnabled;
  619. };
  620. $tooltip.setViewport = function(viewport) {
  621. options.viewport = viewport;
  622. };
  623. $tooltip.$applyPlacement = function() {
  624. if (!tipElement) return;
  625. var placement = options.placement;
  626. var autoToken = /\s?auto?\s?/i;
  627. var autoPlace = autoToken.test(placement);
  628. if (autoPlace) {
  629. placement = placement.replace(autoToken, '') || defaults.placement;
  630. }
  631. tipElement.addClass(options.placement);
  632. var elementPosition = getPosition();
  633. var tipWidth = tipElement.prop('offsetWidth');
  634. var tipHeight = tipElement.prop('offsetHeight');
  635. $tooltip.$viewport = options.viewport && findElement(options.viewport.selector || options.viewport);
  636. if (autoPlace) {
  637. var originalPlacement = placement;
  638. var viewportPosition = getPosition($tooltip.$viewport);
  639. if (/bottom/.test(originalPlacement) && elementPosition.bottom + tipHeight > viewportPosition.bottom) {
  640. placement = originalPlacement.replace('bottom', 'top');
  641. } else if (/top/.test(originalPlacement) && elementPosition.top - tipHeight < viewportPosition.top) {
  642. placement = originalPlacement.replace('top', 'bottom');
  643. }
  644. if (/left/.test(originalPlacement) && elementPosition.left - tipWidth < viewportPosition.left) {
  645. placement = placement.replace('left', 'right');
  646. } else if (/right/.test(originalPlacement) && elementPosition.right + tipWidth > viewportPosition.width) {
  647. placement = placement.replace('right', 'left');
  648. }
  649. tipElement.removeClass(originalPlacement).addClass(placement);
  650. }
  651. var tipPosition = getCalculatedOffset(placement, elementPosition, tipWidth, tipHeight);
  652. applyPlacement(tipPosition, placement);
  653. };
  654. $tooltip.$onKeyUp = function(evt) {
  655. if (evt.which === 27 && $tooltip.$isShown) {
  656. $tooltip.hide();
  657. evt.stopPropagation();
  658. }
  659. };
  660. $tooltip.$onFocusKeyUp = function(evt) {
  661. if (evt.which === 27) {
  662. element[0].blur();
  663. evt.stopPropagation();
  664. }
  665. };
  666. $tooltip.$onFocusElementMouseDown = function(evt) {
  667. if (options.mouseDownPreventDefault) {
  668. evt.preventDefault();
  669. }
  670. if (options.mouseDownStopPropagation) {
  671. evt.stopPropagation();
  672. }
  673. if ($tooltip.$isShown) {
  674. element[0].blur();
  675. } else {
  676. element[0].focus();
  677. }
  678. };
  679. function bindTriggerEvents() {
  680. var triggers = options.trigger.split(' ');
  681. angular.forEach(triggers, function(trigger) {
  682. if (trigger === 'click' || trigger === 'contextmenu') {
  683. element.on(trigger, $tooltip.toggle);
  684. } else if (trigger !== 'manual') {
  685. element.on(trigger === 'hover' ? 'mouseenter' : 'focus', $tooltip.enter);
  686. element.on(trigger === 'hover' ? 'mouseleave' : 'blur', $tooltip.leave);
  687. if (nodeName === 'button' && trigger !== 'hover') {
  688. element.on(isTouch ? 'touchstart' : 'mousedown', $tooltip.$onFocusElementMouseDown);
  689. }
  690. }
  691. });
  692. }
  693. function unbindTriggerEvents() {
  694. var triggers = options.trigger.split(' ');
  695. for (var i = triggers.length; i--; ) {
  696. var trigger = triggers[i];
  697. if (trigger === 'click' || trigger === 'contextmenu') {
  698. element.off(trigger, $tooltip.toggle);
  699. } else if (trigger !== 'manual') {
  700. element.off(trigger === 'hover' ? 'mouseenter' : 'focus', $tooltip.enter);
  701. element.off(trigger === 'hover' ? 'mouseleave' : 'blur', $tooltip.leave);
  702. if (nodeName === 'button' && trigger !== 'hover') {
  703. element.off(isTouch ? 'touchstart' : 'mousedown', $tooltip.$onFocusElementMouseDown);
  704. }
  705. }
  706. }
  707. }
  708. function bindKeyboardEvents() {
  709. if (options.trigger !== 'focus') {
  710. tipElement.on('keyup', $tooltip.$onKeyUp);
  711. } else {
  712. element.on('keyup', $tooltip.$onFocusKeyUp);
  713. }
  714. }
  715. function unbindKeyboardEvents() {
  716. if (options.trigger !== 'focus') {
  717. tipElement.off('keyup', $tooltip.$onKeyUp);
  718. } else {
  719. element.off('keyup', $tooltip.$onFocusKeyUp);
  720. }
  721. }
  722. var _autoCloseEventsBinded = false;
  723. function bindAutoCloseEvents() {
  724. $timeout(function() {
  725. tipElement.on('click', stopEventPropagation);
  726. $body.on('click', $tooltip.hide);
  727. _autoCloseEventsBinded = true;
  728. }, 0, false);
  729. }
  730. function unbindAutoCloseEvents() {
  731. if (_autoCloseEventsBinded) {
  732. tipElement.off('click', stopEventPropagation);
  733. $body.off('click', $tooltip.hide);
  734. _autoCloseEventsBinded = false;
  735. }
  736. }
  737. function stopEventPropagation(event) {
  738. event.stopPropagation();
  739. }
  740. function getPosition($element) {
  741. $element = $element || (options.target || element);
  742. var el = $element[0];
  743. var isBody = el.tagName === 'BODY';
  744. var elRect = el.getBoundingClientRect();
  745. var rect = {};
  746. for (var p in elRect) {
  747. rect[p] = elRect[p];
  748. }
  749. if (rect.width === null) {
  750. rect = angular.extend({}, rect, {
  751. width: elRect.right - elRect.left,
  752. height: elRect.bottom - elRect.top
  753. });
  754. }
  755. var elOffset = isBody ? {
  756. top: 0,
  757. left: 0
  758. } : dimensions.offset(el);
  759. var scroll = {
  760. scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.prop('scrollTop') || 0
  761. };
  762. var outerDims = isBody ? {
  763. width: document.documentElement.clientWidth,
  764. height: $window.innerHeight
  765. } : null;
  766. return angular.extend({}, rect, scroll, outerDims, elOffset);
  767. }
  768. function getCalculatedOffset(placement, position, actualWidth, actualHeight) {
  769. var offset;
  770. var split = placement.split('-');
  771. switch (split[0]) {
  772. case 'right':
  773. offset = {
  774. top: position.top + position.height / 2 - actualHeight / 2,
  775. left: position.left + position.width
  776. };
  777. break;
  778. case 'bottom':
  779. offset = {
  780. top: position.top + position.height,
  781. left: position.left + position.width / 2 - actualWidth / 2
  782. };
  783. break;
  784. case 'left':
  785. offset = {
  786. top: position.top + position.height / 2 - actualHeight / 2,
  787. left: position.left - actualWidth
  788. };
  789. break;
  790. default:
  791. offset = {
  792. top: position.top - actualHeight,
  793. left: position.left + position.width / 2 - actualWidth / 2
  794. };
  795. break;
  796. }
  797. if (!split[1]) {
  798. return offset;
  799. }
  800. if (split[0] === 'top' || split[0] === 'bottom') {
  801. switch (split[1]) {
  802. case 'left':
  803. offset.left = position.left;
  804. break;
  805. case 'right':
  806. offset.left = position.left + position.width - actualWidth;
  807. break;
  808. default:
  809. break;
  810. }
  811. } else if (split[0] === 'left' || split[0] === 'right') {
  812. switch (split[1]) {
  813. case 'top':
  814. offset.top = position.top - actualHeight + position.height;
  815. break;
  816. case 'bottom':
  817. offset.top = position.top;
  818. break;
  819. default:
  820. break;
  821. }
  822. }
  823. return offset;
  824. }
  825. function applyPlacement(offset, placement) {
  826. var tip = tipElement[0];
  827. var width = tip.offsetWidth;
  828. var height = tip.offsetHeight;
  829. var marginTop = parseInt(dimensions.css(tip, 'margin-top'), 10);
  830. var marginLeft = parseInt(dimensions.css(tip, 'margin-left'), 10);
  831. if (isNaN(marginTop)) marginTop = 0;
  832. if (isNaN(marginLeft)) marginLeft = 0;
  833. offset.top = offset.top + marginTop;
  834. offset.left = offset.left + marginLeft;
  835. dimensions.setOffset(tip, angular.extend({
  836. using: function(props) {
  837. tipElement.css({
  838. top: Math.round(props.top) + 'px',
  839. left: Math.round(props.left) + 'px',
  840. right: ''
  841. });
  842. }
  843. }, offset), 0);
  844. var actualWidth = tip.offsetWidth;
  845. var actualHeight = tip.offsetHeight;
  846. if (placement === 'top' && actualHeight !== height) {
  847. offset.top = offset.top + height - actualHeight;
  848. }
  849. if (/top-left|top-right|bottom-left|bottom-right/.test(placement)) return;
  850. var delta = getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight);
  851. if (delta.left) {
  852. offset.left += delta.left;
  853. } else {
  854. offset.top += delta.top;
  855. }
  856. dimensions.setOffset(tip, offset);
  857. if (/top|right|bottom|left/.test(placement)) {
  858. var isVertical = /top|bottom/.test(placement);
  859. var arrowDelta = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight;
  860. var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight';
  861. replaceArrow(arrowDelta, tip[arrowOffsetPosition], isVertical);
  862. }
  863. }
  864. function getViewportAdjustedDelta(placement, position, actualWidth, actualHeight) {
  865. var delta = {
  866. top: 0,
  867. left: 0
  868. };
  869. if (!$tooltip.$viewport) return delta;
  870. var viewportPadding = options.viewport && options.viewport.padding || 0;
  871. var viewportDimensions = getPosition($tooltip.$viewport);
  872. if (/right|left/.test(placement)) {
  873. var topEdgeOffset = position.top - viewportPadding - viewportDimensions.scroll;
  874. var bottomEdgeOffset = position.top + viewportPadding - viewportDimensions.scroll + actualHeight;
  875. if (topEdgeOffset < viewportDimensions.top) {
  876. delta.top = viewportDimensions.top - topEdgeOffset;
  877. } else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) {
  878. delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset;
  879. }
  880. } else {
  881. var leftEdgeOffset = position.left - viewportPadding;
  882. var rightEdgeOffset = position.left + viewportPadding + actualWidth;
  883. if (leftEdgeOffset < viewportDimensions.left) {
  884. delta.left = viewportDimensions.left - leftEdgeOffset;
  885. } else if (rightEdgeOffset > viewportDimensions.right) {
  886. delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset;
  887. }
  888. }
  889. return delta;
  890. }
  891. function replaceArrow(delta, dimension, isHorizontal) {
  892. var $arrow = findElement('.tooltip-arrow, .arrow', tipElement[0]);
  893. $arrow.css(isHorizontal ? 'left' : 'top', 50 * (1 - delta / dimension) + '%').css(isHorizontal ? 'top' : 'left', '');
  894. }
  895. function destroyTipElement() {
  896. clearTimeout(timeout);
  897. if ($tooltip.$isShown && tipElement !== null) {
  898. if (options.autoClose) {
  899. unbindAutoCloseEvents();
  900. }
  901. if (options.keyboard) {
  902. unbindKeyboardEvents();
  903. }
  904. }
  905. if (tipScope) {
  906. tipScope.$destroy();
  907. tipScope = null;
  908. }
  909. if (tipElement) {
  910. tipElement.remove();
  911. tipElement = $tooltip.$element = null;
  912. }
  913. }
  914. return $tooltip;
  915. }
  916. function safeDigest(scope) {
  917. scope.$$phase || scope.$root && scope.$root.$$phase || scope.$digest();
  918. }
  919. function findElement(query, element) {
  920. return angular.element((element || document).querySelectorAll(query));
  921. }
  922. return TooltipFactory;
  923. } ];
  924. }).directive('bsTooltip', ["$window", "$location", "$sce", "$parse", "$bsTooltip", "$$rAF", function($window, $location, $sce, $parse, $tooltip, $$rAF) {
  925. return {
  926. restrict: 'EAC',
  927. scope: true,
  928. link: function postLink(scope, element, attr, transclusion) {
  929. var tooltip;
  930. var options = {
  931. scope: scope
  932. };
  933. angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'titleTemplate', 'placement', 'container', 'delay', 'trigger', 'html', 'animation', 'backdropAnimation', 'type', 'customClass', 'id' ], function(key) {
  934. if (angular.isDefined(attr[key])) options[key] = attr[key];
  935. });
  936. var falseValueRegExp = /^(false|0|)$/i;
  937. angular.forEach([ 'html', 'container' ], function(key) {
  938. if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) {
  939. options[key] = false;
  940. }
  941. });
  942. angular.forEach([ 'onBeforeShow', 'onShow', 'onBeforeHide', 'onHide' ], function(key) {
  943. var bsKey = 'bs' + key.charAt(0).toUpperCase() + key.slice(1);
  944. if (angular.isDefined(attr[bsKey])) {
  945. options[key] = scope.$eval(attr[bsKey]);
  946. }
  947. });
  948. var dataTarget = element.attr('data-target');
  949. if (angular.isDefined(dataTarget)) {
  950. if (falseValueRegExp.test(dataTarget)) {
  951. options.target = false;
  952. } else {
  953. options.target = dataTarget;
  954. }
  955. }
  956. if (!scope.hasOwnProperty('title')) {
  957. scope.title = '';
  958. }
  959. attr.$observe('title', function(newValue) {
  960. if (angular.isDefined(newValue) || !scope.hasOwnProperty('title')) {
  961. var oldValue = scope.title;
  962. scope.title = $sce.trustAsHtml(newValue);
  963. if (angular.isDefined(oldValue)) {
  964. $$rAF(function() {
  965. if (tooltip) tooltip.$applyPlacement();
  966. });
  967. }
  968. }
  969. });
  970. attr.$observe('disabled', function(newValue) {
  971. if (newValue && tooltip.$isShown) {
  972. tooltip.hide();
  973. }
  974. });
  975. if (attr.bsTooltip) {
  976. scope.$watch(attr.bsTooltip, function(newValue, oldValue) {
  977. if (angular.isObject(newValue)) {
  978. angular.extend(scope, newValue);
  979. } else {
  980. scope.title = newValue;
  981. }
  982. if (angular.isDefined(oldValue)) {
  983. $$rAF(function() {
  984. if (tooltip) tooltip.$applyPlacement();
  985. });
  986. }
  987. }, true);
  988. }
  989. if (attr.bsShow) {
  990. scope.$watch(attr.bsShow, function(newValue, oldValue) {
  991. if (!tooltip || !angular.isDefined(newValue)) return;
  992. if (angular.isString(newValue)) newValue = !!newValue.match(/true|,?(tooltip),?/i);
  993. if (newValue === true) {
  994. tooltip.show();
  995. } else {
  996. tooltip.hide();
  997. }
  998. });
  999. }
  1000. if (attr.bsEnabled) {
  1001. scope.$watch(attr.bsEnabled, function(newValue, oldValue) {
  1002. if (!tooltip || !angular.isDefined(newValue)) return;
  1003. if (angular.isString(newValue)) newValue = !!newValue.match(/true|1|,?(tooltip),?/i);
  1004. if (newValue === false) {
  1005. tooltip.setEnabled(false);
  1006. } else {
  1007. tooltip.setEnabled(true);
  1008. }
  1009. });
  1010. }
  1011. if (attr.viewport) {
  1012. scope.$watch(attr.viewport, function(newValue) {
  1013. if (!tooltip || !angular.isDefined(newValue)) return;
  1014. tooltip.setViewport(newValue);
  1015. });
  1016. }
  1017. tooltip = $tooltip(element, options);
  1018. scope.$on('$destroy', function() {
  1019. if (tooltip) tooltip.destroy();
  1020. options = null;
  1021. tooltip = null;
  1022. });
  1023. }
  1024. };
  1025. } ]);
  1026. angular.module('mgcrea.ngStrap.timepicker', [ 'mgcrea.ngStrap.helpers.dateParser', 'mgcrea.ngStrap.helpers.dateFormatter', 'mgcrea.ngStrap.tooltip' ]).provider('$bsTimepicker', function() {
  1027. var defaults = this.defaults = {
  1028. animation: 'am-fade',
  1029. defaultDate: 'auto',
  1030. prefixClass: 'timepicker',
  1031. placement: 'bottom-left',
  1032. templateUrl: 'timepicker/timepicker.tpl.html',
  1033. trigger: 'focus',
  1034. container: false,
  1035. keyboard: true,
  1036. html: false,
  1037. delay: 0,
  1038. useNative: true,
  1039. timeType: 'date',
  1040. timeFormat: 'shortTime',
  1041. timezone: null,
  1042. modelTimeFormat: null,
  1043. autoclose: false,
  1044. minTime: -Infinity,
  1045. maxTime: +Infinity,
  1046. length: 5,
  1047. hourStep: 1,
  1048. minuteStep: 5,
  1049. secondStep: 5,
  1050. roundDisplay: false,
  1051. iconUp: 'glyphicon glyphicon-chevron-up',
  1052. iconDown: 'glyphicon glyphicon-chevron-down',
  1053. arrowBehavior: 'pager'
  1054. };
  1055. this.$get = ["$window", "$document", "$rootScope", "$sce", "$bsDateFormatter", "$bsTooltip", "$timeout", function($window, $document, $rootScope, $sce, $dateFormatter, $tooltip, $timeout) {
  1056. var isNative = /(ip[ao]d|iphone|android)/gi.test($window.navigator.userAgent);
  1057. var isTouch = 'createTouch' in $window.document && isNative;
  1058. if (!defaults.lang) {
  1059. defaults.lang = $dateFormatter.getDefaultLocale();
  1060. }
  1061. function timepickerFactory(element, controller, config) {
  1062. var $timepicker = $tooltip(element, angular.extend({}, defaults, config));
  1063. var parentScope = config.scope;
  1064. var options = $timepicker.$options;
  1065. var scope = $timepicker.$scope;
  1066. var lang = options.lang;
  1067. var formatDate = function(date, format, timezone) {
  1068. return $dateFormatter.formatDate(date, format, lang, timezone);
  1069. };
  1070. function floorMinutes(time) {
  1071. var coeff = 1e3 * 60 * options.minuteStep;
  1072. return new Date(Math.floor(time.getTime() / coeff) * coeff);
  1073. }
  1074. var selectedIndex = 0;
  1075. var defaultDate = options.roundDisplay ? floorMinutes(new Date()) : new Date();
  1076. var startDate = controller.$dateValue || defaultDate;
  1077. var viewDate = {
  1078. hour: startDate.getHours(),
  1079. meridian: startDate.getHours() < 12,
  1080. minute: startDate.getMinutes(),
  1081. second: startDate.getSeconds(),
  1082. millisecond: startDate.getMilliseconds()
  1083. };
  1084. var format = $dateFormatter.getDatetimeFormat(options.timeFormat, lang);
  1085. var hoursFormat = $dateFormatter.hoursFormat(format);
  1086. var timeSeparator = $dateFormatter.timeSeparator(format);
  1087. var minutesFormat = $dateFormatter.minutesFormat(format);
  1088. var secondsFormat = $dateFormatter.secondsFormat(format);
  1089. var showSeconds = $dateFormatter.showSeconds(format);
  1090. var showAM = $dateFormatter.showAM(format);
  1091. scope.$iconUp = options.iconUp;
  1092. scope.$iconDown = options.iconDown;
  1093. scope.$select = function(date, index) {
  1094. $timepicker.select(date, index);
  1095. };
  1096. scope.$moveIndex = function(value, index) {
  1097. $timepicker.$moveIndex(value, index);
  1098. };
  1099. scope.$switchMeridian = function(date) {
  1100. $timepicker.switchMeridian(date);
  1101. };
  1102. $timepicker.update = function(date) {
  1103. if (angular.isDate(date) && !isNaN(date.getTime())) {
  1104. $timepicker.$date = date;
  1105. angular.extend(viewDate, {
  1106. hour: date.getHours(),
  1107. minute: date.getMinutes(),
  1108. second: date.getSeconds(),
  1109. millisecond: date.getMilliseconds()
  1110. });
  1111. $timepicker.$build();
  1112. } else if (!$timepicker.$isBuilt) {
  1113. $timepicker.$build();
  1114. }
  1115. };
  1116. $timepicker.select = function(date, index, keep) {
  1117. if (!controller.$dateValue || isNaN(controller.$dateValue.getTime())) {
  1118. controller.$dateValue = options.defaultDate === 'today' ? new Date() : new Date(1970, 0, 1);
  1119. }
  1120. if (!angular.isDate(date)) date = new Date(date);
  1121. if (index === 0) controller.$dateValue.setHours(date.getHours()); else if (index === 1) controller.$dateValue.setMinutes(date.getMinutes()); else if (index === 2) controller.$dateValue.setSeconds(date.getSeconds());
  1122. controller.$setViewValue(angular.copy(controller.$dateValue));
  1123. controller.$render();
  1124. if (options.autoclose && !keep) {
  1125. $timeout(function() {
  1126. $timepicker.hide(true);
  1127. });
  1128. }
  1129. };
  1130. $timepicker.switchMeridian = function(date) {
  1131. if (!controller.$dateValue || isNaN(controller.$dateValue.getTime())) {
  1132. return;
  1133. }
  1134. var hours = (date || controller.$dateValue).getHours();
  1135. controller.$dateValue.setHours(hours < 12 ? hours + 12 : hours - 12);
  1136. controller.$setViewValue(angular.copy(controller.$dateValue));
  1137. controller.$render();
  1138. };
  1139. $timepicker.$build = function() {
  1140. var i;
  1141. var midIndex = scope.midIndex = parseInt(options.length / 2, 10);
  1142. var hours = [];
  1143. var hour;
  1144. for (i = 0; i < options.length; i++) {
  1145. hour = new Date(1970, 0, 1, viewDate.hour - (midIndex - i) * options.hourStep);
  1146. hours.push({
  1147. date: hour,
  1148. label: formatDate(hour, hoursFormat),
  1149. selected: $timepicker.$date && $timepicker.$isSelected(hour, 0),
  1150. disabled: $timepicker.$isDisabled(hour, 0)
  1151. });
  1152. }
  1153. var minutes = [];
  1154. var minute;
  1155. for (i = 0; i < options.length; i++) {
  1156. minute = new Date(1970, 0, 1, 0, viewDate.minute - (midIndex - i) * options.minuteStep);
  1157. minutes.push({
  1158. date: minute,
  1159. label: formatDate(minute, minutesFormat),
  1160. selected: $timepicker.$date && $timepicker.$isSelected(minute, 1),
  1161. disabled: $timepicker.$isDisabled(minute, 1)
  1162. });
  1163. }
  1164. var seconds = [];
  1165. var second;
  1166. for (i = 0; i < options.length; i++) {
  1167. second = new Date(1970, 0, 1, 0, 0, viewDate.second - (midIndex - i) * options.secondStep);
  1168. seconds.push({
  1169. date: second,
  1170. label: formatDate(second, secondsFormat),
  1171. selected: $timepicker.$date && $timepicker.$isSelected(second, 2),
  1172. disabled: $timepicker.$isDisabled(second, 2)
  1173. });
  1174. }
  1175. var rows = [];
  1176. for (i = 0; i < options.length; i++) {
  1177. if (showSeconds) {
  1178. rows.push([ hours[i], minutes[i], seconds[i] ]);
  1179. } else {
  1180. rows.push([ hours[i], minutes[i] ]);
  1181. }
  1182. }
  1183. scope.rows = rows;
  1184. scope.showSeconds = showSeconds;
  1185. scope.showAM = showAM;
  1186. scope.isAM = ($timepicker.$date || hours[midIndex].date).getHours() < 12;
  1187. scope.timeSeparator = timeSeparator;
  1188. $timepicker.$isBuilt = true;
  1189. };
  1190. $timepicker.$isSelected = function(date, index) {
  1191. if (!$timepicker.$date) return false; else if (index === 0) {
  1192. return date.getHours() === $timepicker.$date.getHours();
  1193. } else if (index === 1) {
  1194. return date.getMinutes() === $timepicker.$date.getMinutes();
  1195. } else if (index === 2) {
  1196. return date.getSeconds() === $timepicker.$date.getSeconds();
  1197. }
  1198. };
  1199. $timepicker.$isDisabled = function(date, index) {
  1200. var selectedTime;
  1201. if (index === 0) {
  1202. selectedTime = date.getTime() + viewDate.minute * 6e4 + viewDate.second * 1e3;
  1203. } else if (index === 1) {
  1204. selectedTime = date.getTime() + viewDate.hour * 36e5 + viewDate.second * 1e3;
  1205. } else if (index === 2) {
  1206. selectedTime = date.getTime() + viewDate.hour * 36e5 + viewDate.minute * 6e4;
  1207. }
  1208. return selectedTime < options.minTime * 1 || selectedTime > options.maxTime * 1;
  1209. };
  1210. scope.$arrowAction = function(value, index) {
  1211. if (options.arrowBehavior === 'picker') {
  1212. $timepicker.$setTimeByStep(value, index);
  1213. } else {
  1214. $timepicker.$moveIndex(value, index);
  1215. }
  1216. };
  1217. $timepicker.$setTimeByStep = function(value, index) {
  1218. var newDate = new Date($timepicker.$date || startDate);
  1219. var hours = newDate.getHours();
  1220. var minutes = newDate.getMinutes();
  1221. var seconds = newDate.getSeconds();
  1222. if (index === 0) {
  1223. newDate.setHours(hours - parseInt(options.hourStep, 10) * value);
  1224. } else if (index === 1) {
  1225. newDate.setMinutes(minutes - parseInt(options.minuteStep, 10) * value);
  1226. } else if (index === 2) {
  1227. newDate.setSeconds(seconds - parseInt(options.secondStep, 10) * value);
  1228. }
  1229. $timepicker.select(newDate, index, true);
  1230. };
  1231. $timepicker.$moveIndex = function(value, index) {
  1232. var targetDate;
  1233. if (index === 0) {
  1234. targetDate = new Date(1970, 0, 1, viewDate.hour + value * options.length, viewDate.minute, viewDate.second);
  1235. angular.extend(viewDate, {
  1236. hour: targetDate.getHours()
  1237. });
  1238. } else if (index === 1) {
  1239. targetDate = new Date(1970, 0, 1, viewDate.hour, viewDate.minute + value * options.length * options.minuteStep, viewDate.second);
  1240. angular.extend(viewDate, {
  1241. minute: targetDate.getMinutes()
  1242. });
  1243. } else if (index === 2) {
  1244. targetDate = new Date(1970, 0, 1, viewDate.hour, viewDate.minute, viewDate.second + value * options.length * options.secondStep);
  1245. angular.extend(viewDate, {
  1246. second: targetDate.getSeconds()
  1247. });
  1248. }
  1249. $timepicker.$build();
  1250. };
  1251. $timepicker.$onMouseDown = function(evt) {
  1252. if (evt.target.nodeName.toLowerCase() !== 'input') evt.preventDefault();
  1253. evt.stopPropagation();
  1254. if (isTouch) {
  1255. var targetEl = angular.element(evt.target);
  1256. if (targetEl[0].nodeName.toLowerCase() !== 'button') {
  1257. targetEl = targetEl.parent();
  1258. }
  1259. targetEl.triggerHandler('click');
  1260. }
  1261. };
  1262. $timepicker.$onKeyDown = function(evt) {
  1263. if (!/(38|37|39|40|13)/.test(evt.keyCode) || evt.shiftKey || evt.altKey) return;
  1264. evt.preventDefault();
  1265. evt.stopPropagation();
  1266. if (evt.keyCode === 13) {
  1267. $timepicker.hide(true);
  1268. return;
  1269. }
  1270. var newDate = new Date($timepicker.$date);
  1271. var hours = newDate.getHours();
  1272. var hoursLength = formatDate(newDate, hoursFormat).length;
  1273. var minutes = newDate.getMinutes();
  1274. var minutesLength = formatDate(newDate, minutesFormat).length;
  1275. var seconds = newDate.getSeconds();
  1276. var secondsLength = formatDate(newDate, secondsFormat).length;
  1277. var sepLength = 1;
  1278. var lateralMove = /(37|39)/.test(evt.keyCode);
  1279. var count = 2 + showSeconds * 1 + showAM * 1;
  1280. if (lateralMove) {
  1281. if (evt.keyCode === 37) selectedIndex = selectedIndex < 1 ? count - 1 : selectedIndex - 1; else if (evt.keyCode === 39) selectedIndex = selectedIndex < count - 1 ? selectedIndex + 1 : 0;
  1282. }
  1283. var selectRange = [ 0, hoursLength ];
  1284. var incr = 0;
  1285. if (evt.keyCode === 38) incr = -1;
  1286. if (evt.keyCode === 40) incr = +1;
  1287. var isSeconds = selectedIndex === 2 && showSeconds;
  1288. var isMeridian = selectedIndex === 2 && !showSeconds || selectedIndex === 3 && showSeconds;
  1289. if (selectedIndex === 0) {
  1290. newDate.setHours(hours + incr * parseInt(options.hourStep, 10));
  1291. hoursLength = formatDate(newDate, hoursFormat).length;
  1292. selectRange = [ 0, hoursLength ];
  1293. } else if (selectedIndex === 1) {
  1294. newDate.setMinutes(minutes + incr * parseInt(options.minuteStep, 10));
  1295. minutesLength = formatDate(newDate, minutesFormat).length;
  1296. selectRange = [ hoursLength + sepLength, minutesLength ];
  1297. } else if (isSeconds) {
  1298. newDate.setSeconds(seconds + incr * parseInt(options.secondStep, 10));
  1299. secondsLength = formatDate(newDate, secondsFormat).length;
  1300. selectRange = [ hoursLength + sepLength + minutesLength + sepLength, secondsLength ];
  1301. } else if (isMeridian) {
  1302. if (!lateralMove) $timepicker.switchMeridian();
  1303. selectRange = [ hoursLength + sepLength + minutesLength + sepLength + (secondsLength + sepLength) * showSeconds, 2 ];
  1304. }
  1305. $timepicker.select(newDate, selectedIndex, true);
  1306. createSelection(selectRange[0], selectRange[1]);
  1307. parentScope.$digest();
  1308. };
  1309. function createSelection(start, length) {
  1310. var end = start + length;
  1311. if (element[0].createTextRange) {
  1312. var selRange = element[0].createTextRange();
  1313. selRange.collapse(true);
  1314. selRange.moveStart('character', start);
  1315. selRange.moveEnd('character', end);
  1316. selRange.select();
  1317. } else if (element[0].setSelectionRange) {
  1318. element[0].setSelectionRange(start, end);
  1319. } else if (angular.isUndefined(element[0].selectionStart)) {
  1320. element[0].selectionStart = start;
  1321. element[0].selectionEnd = end;
  1322. }
  1323. }
  1324. function focusElement() {
  1325. element[0].focus();
  1326. }
  1327. var _init = $timepicker.init;
  1328. $timepicker.init = function() {
  1329. if (isNative && options.useNative) {
  1330. element.prop('type', 'time');
  1331. element.css('-webkit-appearance', 'textfield');
  1332. return;
  1333. } else if (isTouch) {
  1334. element.prop('type', 'text');
  1335. element.attr('readonly', 'true');
  1336. element.on('click', focusElement);
  1337. }
  1338. _init();
  1339. };
  1340. var _destroy = $timepicker.destroy;
  1341. $timepicker.destroy = function() {
  1342. if (isNative && options.useNative) {
  1343. element.off('click', focusElement);
  1344. }
  1345. _destroy();
  1346. };
  1347. var _show = $timepicker.show;
  1348. $timepicker.show = function() {
  1349. if (!isTouch && element.attr('readonly') || element.attr('disabled')) return;
  1350. _show();
  1351. $timeout(function() {
  1352. if ($timepicker.$element) $timepicker.$element.on(isTouch ? 'touchstart' : 'mousedown', $timepicker.$onMouseDown);
  1353. if (options.keyboard) {
  1354. if (element) element.on('keydown', $timepicker.$onKeyDown);
  1355. }
  1356. }, 0, false);
  1357. };
  1358. var _hide = $timepicker.hide;
  1359. $timepicker.hide = function(blur) {
  1360. if (!$timepicker.$isShown) return;
  1361. if ($timepicker.$element) $timepicker.$element.off(isTouch ? 'touchstart' : 'mousedown', $timepicker.$onMouseDown);
  1362. if (options.keyboard) {
  1363. if (element) element.off('keydown', $timepicker.$onKeyDown);
  1364. }
  1365. _hide(blur);
  1366. };
  1367. return $timepicker;
  1368. }
  1369. timepickerFactory.defaults = defaults;
  1370. return timepickerFactory;
  1371. } ];
  1372. }).directive('bsTimepicker', ["$window", "$parse", "$q", "$bsDateFormatter", "$bsDateParser", "$bsTimepicker", function($window, $parse, $q, $dateFormatter, $dateParser, $timepicker) {
  1373. var defaults = $timepicker.defaults;
  1374. var isNative = /(ip[ao]d|iphone|android)/gi.test($window.navigator.userAgent);
  1375. return {
  1376. restrict: 'EAC',
  1377. require: 'ngModel',
  1378. link: function postLink(scope, element, attr, controller) {
  1379. var options = {
  1380. scope: scope
  1381. };
  1382. angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'placement', 'container', 'delay', 'trigger', 'keyboard', 'html', 'animation', 'autoclose', 'timeType', 'timeFormat', 'timezone', 'modelTimeFormat', 'useNative', 'hourStep', 'minuteStep', 'secondStep', 'length', 'arrowBehavior', 'iconUp', 'iconDown', 'roundDisplay', 'id', 'prefixClass', 'prefixEvent', 'defaultDate' ], function(key) {
  1383. if (angular.isDefined(attr[key])) options[key] = attr[key];
  1384. });
  1385. var falseValueRegExp = /^(false|0|)$/i;
  1386. angular.forEach([ 'html', 'container', 'autoclose', 'useNative', 'roundDisplay' ], function(key) {
  1387. if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) {
  1388. options[key] = false;
  1389. }
  1390. });
  1391. angular.forEach([ 'onBeforeShow', 'onShow', 'onBeforeHide', 'onHide' ], function(key) {
  1392. var bsKey = 'bs' + key.charAt(0).toUpperCase() + key.slice(1);
  1393. if (angular.isDefined(attr[bsKey])) {
  1394. options[key] = scope.$eval(attr[bsKey]);
  1395. }
  1396. });
  1397. if (isNative && (options.useNative || defaults.useNative)) options.timeFormat = 'HH:mm';
  1398. var timepicker = $timepicker(element, controller, options);
  1399. options = timepicker.$options;
  1400. var lang = options.lang;
  1401. var formatDate = function(date, format, timezone) {
  1402. return $dateFormatter.formatDate(date, format, lang, timezone);
  1403. };
  1404. if (attr.bsShow) {
  1405. scope.$watch(attr.bsShow, function(newValue, oldValue) {
  1406. if (!timepicker || !angular.isDefined(newValue)) return;
  1407. if (angular.isString(newValue)) newValue = !!newValue.match(/true|,?(timepicker),?/i);
  1408. if (newValue === true) {
  1409. timepicker.show();
  1410. } else {
  1411. timepicker.hide();
  1412. }
  1413. });
  1414. }
  1415. var dateParser = $dateParser({
  1416. format: options.timeFormat,
  1417. lang: lang
  1418. });
  1419. angular.forEach([ 'minTime', 'maxTime' ], function(key) {
  1420. if (angular.isDefined(attr[key])) {
  1421. attr.$observe(key, function(newValue) {
  1422. timepicker.$options[key] = dateParser.getTimeForAttribute(key, newValue);
  1423. if (!isNaN(timepicker.$options[key])) timepicker.$build();
  1424. validateAgainstMinMaxTime(controller.$dateValue);
  1425. });
  1426. }
  1427. });
  1428. scope.$watch(attr.ngModel, function(newValue, oldValue) {
  1429. timepicker.update(controller.$dateValue);
  1430. }, true);
  1431. function validateAgainstMinMaxTime(parsedTime) {
  1432. if (!angular.isDate(parsedTime)) return;
  1433. var isMinValid = isNaN(options.minTime) || new Date(parsedTime.getTime()).setFullYear(1970, 0, 1) >= options.minTime;
  1434. var isMaxValid = isNaN(options.maxTime) || new Date(parsedTime.getTime()).setFullYear(1970, 0, 1) <= options.maxTime;
  1435. var isValid = isMinValid && isMaxValid;
  1436. controller.$setValidity('date', isValid);
  1437. controller.$setValidity('min', isMinValid);
  1438. controller.$setValidity('max', isMaxValid);
  1439. if (!isValid) {
  1440. return;
  1441. }
  1442. controller.$dateValue = parsedTime;
  1443. }
  1444. controller.$parsers.unshift(function(viewValue) {
  1445. var date;
  1446. if (!viewValue) {
  1447. controller.$setValidity('date', true);
  1448. return null;
  1449. }
  1450. var parsedTime = angular.isDate(viewValue) ? viewValue : dateParser.parse(viewValue, controller.$dateValue);
  1451. if (!parsedTime || isNaN(parsedTime.getTime())) {
  1452. controller.$setValidity('date', false);
  1453. return undefined;
  1454. }
  1455. validateAgainstMinMaxTime(parsedTime);
  1456. if (options.timeType === 'string') {
  1457. date = dateParser.timezoneOffsetAdjust(parsedTime, options.timezone, true);
  1458. return formatDate(date, options.modelTimeFormat || options.timeFormat);
  1459. }
  1460. date = dateParser.timezoneOffsetAdjust(controller.$dateValue, options.timezone, true);
  1461. if (options.timeType === 'number') {
  1462. return date.getTime();
  1463. } else if (options.timeType === 'unix') {
  1464. return date.getTime() / 1e3;
  1465. } else if (options.timeType === 'iso') {
  1466. return date.toISOString();
  1467. }
  1468. return new Date(date);
  1469. });
  1470. controller.$formatters.push(function(modelValue) {
  1471. var date;
  1472. if (angular.isUndefined(modelValue) || modelValue === null) {
  1473. date = NaN;
  1474. } else if (angular.isDate(modelValue)) {
  1475. date = modelValue;
  1476. } else if (options.timeType === 'string') {
  1477. date = dateParser.parse(modelValue, null, options.modelTimeFormat);
  1478. } else if (options.timeType === 'unix') {
  1479. date = new Date(modelValue * 1e3);
  1480. } else {
  1481. date = new Date(modelValue);
  1482. }
  1483. controller.$dateValue = dateParser.timezoneOffsetAdjust(date, options.timezone);
  1484. return getTimeFormattedString();
  1485. });
  1486. controller.$render = function() {
  1487. element.val(getTimeFormattedString());
  1488. };
  1489. function getTimeFormattedString() {
  1490. return !controller.$dateValue || isNaN(controller.$dateValue.getTime()) ? '' : formatDate(controller.$dateValue, options.timeFormat);
  1491. }
  1492. scope.$on('$destroy', function() {
  1493. if (timepicker) timepicker.destroy();
  1494. options = null;
  1495. timepicker = null;
  1496. });
  1497. }
  1498. };
  1499. } ]);
  1500. angular.module('mgcrea.ngStrap.scrollspy', [ 'mgcrea.ngStrap.helpers.debounce', 'mgcrea.ngStrap.helpers.dimensions' ]).provider('$bsScrollspy', function() {
  1501. var spies = this.$$spies = {};
  1502. var defaults = this.defaults = {
  1503. debounce: 150,
  1504. throttle: 100,
  1505. offset: 100
  1506. };
  1507. this.$get = ["$window", "$document", "$rootScope", "bsDimensions", "bsDebounce", "bsThrottle", function($window, $document, $rootScope, dimensions, debounce, throttle) {
  1508. var windowEl = angular.element($window);
  1509. var docEl = angular.element($document.prop('documentElement'));
  1510. var bodyEl = angular.element($window.document.body);
  1511. function nodeName(element, name) {
  1512. return element[0].nodeName && element[0].nodeName.toLowerCase() === name.toLowerCase();
  1513. }
  1514. function ScrollSpyFactory(config) {
  1515. var options = angular.extend({}, defaults, config);
  1516. if (!options.element) options.element = bodyEl;
  1517. var isWindowSpy = nodeName(options.element, 'body');
  1518. var scrollEl = isWindowSpy ? windowEl : options.element;
  1519. var scrollId = isWindowSpy ? 'window' : options.id;
  1520. if (spies[scrollId]) {
  1521. spies[scrollId].$$count++;
  1522. return spies[scrollId];
  1523. }
  1524. var $scrollspy = {};
  1525. var unbindViewContentLoaded;
  1526. var unbindIncludeContentLoaded;
  1527. var trackedElements = $scrollspy.$trackedElements = [];
  1528. var sortedElements = [];
  1529. var activeTarget;
  1530. var debouncedCheckPosition;
  1531. var throttledCheckPosition;
  1532. var debouncedCheckOffsets;
  1533. var viewportHeight;
  1534. var scrollTop;
  1535. $scrollspy.init = function() {
  1536. this.$$count = 1;
  1537. debouncedCheckPosition = debounce(this.checkPosition, options.debounce);
  1538. throttledCheckPosition = throttle(this.checkPosition, options.throttle);
  1539. scrollEl.on('click', this.checkPositionWithEventLoop);
  1540. windowEl.on('resize', debouncedCheckPosition);
  1541. scrollEl.on('scroll', throttledCheckPosition);
  1542. debouncedCheckOffsets = debounce(this.checkOffsets, options.debounce);
  1543. unbindViewContentLoaded = $rootScope.$on('$viewContentLoaded', debouncedCheckOffsets);
  1544. unbindIncludeContentLoaded = $rootScope.$on('$includeContentLoaded', debouncedCheckOffsets);
  1545. debouncedCheckOffsets();
  1546. if (scrollId) {
  1547. spies[scrollId] = $scrollspy;
  1548. }
  1549. };
  1550. $scrollspy.destroy = function() {
  1551. this.$$count--;
  1552. if (this.$$count > 0) {
  1553. return;
  1554. }
  1555. scrollEl.off('click', this.checkPositionWithEventLoop);
  1556. windowEl.off('resize', debouncedCheckPosition);
  1557. scrollEl.off('scroll', throttledCheckPosition);
  1558. unbindViewContentLoaded();
  1559. unbindIncludeContentLoaded();
  1560. if (scrollId) {
  1561. delete spies[scrollId];
  1562. }
  1563. };
  1564. $scrollspy.checkPosition = function() {
  1565. if (!sortedElements.length) return;
  1566. scrollTop = (isWindowSpy ? $window.pageYOffset : scrollEl.prop('scrollTop')) || 0;
  1567. viewportHeight = Math.max($window.innerHeight, docEl.prop('clientHeight'));
  1568. if (scrollTop < sortedElements[0].offsetTop && activeTarget !== sortedElements[0].target) {
  1569. return $scrollspy.$activateElement(sortedElements[0]);
  1570. }
  1571. for (var i = sortedElements.length; i--; ) {
  1572. if (angular.isUndefined(sortedElements[i].offsetTop) || sortedElements[i].offsetTop === null) continue;
  1573. if (activeTarget === sortedElements[i].target) continue;
  1574. if (scrollTop < sortedElements[i].offsetTop) continue;
  1575. if (sortedElements[i + 1] && scrollTop > sortedElements[i + 1].offsetTop) continue;
  1576. return $scrollspy.$activateElement(sortedElements[i]);
  1577. }
  1578. };
  1579. $scrollspy.checkPositionWithEventLoop = function() {
  1580. setTimeout($scrollspy.checkPosition, 1);
  1581. };
  1582. $scrollspy.$activateElement = function(element) {
  1583. if (activeTarget) {
  1584. var activeElement = $scrollspy.$getTrackedElement(activeTarget);
  1585. if (activeElement) {
  1586. activeElement.source.removeClass('active');
  1587. if (nodeName(activeElement.source, 'li') && nodeName(activeElement.source.parent().parent(), 'li')) {
  1588. activeElement.source.parent().parent().removeClass('active');
  1589. }
  1590. }
  1591. }
  1592. activeTarget = element.target;
  1593. element.source.addClass('active');
  1594. if (nodeName(element.source, 'li') && nodeName(element.source.parent().parent(), 'li')) {
  1595. element.source.parent().parent().addClass('active');
  1596. }
  1597. };
  1598. $scrollspy.$getTrackedElement = function(target) {
  1599. return trackedElements.filter(function(obj) {
  1600. return obj.target === target;
  1601. })[0];
  1602. };
  1603. $scrollspy.checkOffsets = function() {
  1604. angular.forEach(trackedElements, function(trackedElement) {
  1605. var targetElement = document.querySelector(trackedElement.target);
  1606. trackedElement.offsetTop = targetElement ? dimensions.offset(targetElement).top : null;
  1607. if (options.offset && trackedElement.offsetTop !== null) trackedElement.offsetTop -= options.offset * 1;
  1608. });
  1609. sortedElements = trackedElements.filter(function(el) {
  1610. return el.offsetTop !== null;
  1611. }).sort(function(a, b) {
  1612. return a.offsetTop - b.offsetTop;
  1613. });
  1614. debouncedCheckPosition();
  1615. };
  1616. $scrollspy.trackElement = function(target, source) {
  1617. trackedElements.push({
  1618. target: target,
  1619. source: source
  1620. });
  1621. };
  1622. $scrollspy.untrackElement = function(target, source) {
  1623. var toDelete;
  1624. for (var i = trackedElements.length; i--; ) {
  1625. if (trackedElements[i].target === target && trackedElements[i].source === source) {
  1626. toDelete = i;
  1627. break;
  1628. }
  1629. }
  1630. trackedElements.splice(toDelete, 1);
  1631. };
  1632. $scrollspy.activate = function(i) {
  1633. trackedElements[i].addClass('active');
  1634. };
  1635. $scrollspy.init();
  1636. return $scrollspy;
  1637. }
  1638. return ScrollSpyFactory;
  1639. } ];
  1640. }).directive('bsScrollspy', ["$rootScope", "bsDebounce", "bsDimensions", "$bsScrollspy", function($rootScope, debounce, dimensions, $scrollspy) {
  1641. return {
  1642. restrict: 'EAC',
  1643. link: function postLink(scope, element, attr) {
  1644. var options = {
  1645. scope: scope
  1646. };
  1647. angular.forEach([ 'offset', 'target' ], function(key) {
  1648. if (angular.isDefined(attr[key])) options[key] = attr[key];
  1649. });
  1650. var scrollspy = $scrollspy(options);
  1651. scrollspy.trackElement(options.target, element);
  1652. scope.$on('$destroy', function() {
  1653. if (scrollspy) {
  1654. scrollspy.untrackElement(options.target, element);
  1655. scrollspy.destroy();
  1656. }
  1657. options = null;
  1658. scrollspy = null;
  1659. });
  1660. }
  1661. };
  1662. } ]).directive('bsScrollspyList', ["$rootScope", "bsDebounce", "bsDimensions", "$bsScrollspy", function($rootScope, debounce, dimensions, $scrollspy) {
  1663. return {
  1664. restrict: 'A',
  1665. compile: function postLink(element, attr) {
  1666. var children = element[0].querySelectorAll('li > a[href]');
  1667. angular.forEach(children, function(child) {
  1668. var childEl = angular.element(child);
  1669. childEl.parent().attr('bs-scrollspy', '').attr('data-target', childEl.attr('href'));
  1670. });
  1671. }
  1672. };
  1673. } ]);
  1674. angular.module('mgcrea.ngStrap.select', [ 'mgcrea.ngStrap.tooltip', 'mgcrea.ngStrap.helpers.parseOptions' ]).provider('$bsSelect', function() {
  1675. var defaults = this.defaults = {
  1676. animation: 'am-fade',
  1677. prefixClass: 'select',
  1678. prefixEvent: '$select',
  1679. placement: 'bottom-left',
  1680. templateUrl: 'select/select.tpl.html',
  1681. trigger: 'focus',
  1682. container: false,
  1683. keyboard: true,
  1684. html: false,
  1685. delay: 0,
  1686. multiple: false,
  1687. allNoneButtons: false,
  1688. sort: true,
  1689. caretHtml: '&nbsp;<span class="caret"></span>',
  1690. placeholder: 'Choose among the following...',
  1691. allText: 'All',
  1692. noneText: 'None',
  1693. maxLength: 3,
  1694. maxLengthHtml: 'selected',
  1695. iconCheckmark: 'glyphicon glyphicon-ok',
  1696. toggle: false
  1697. };
  1698. this.$get = ["$window", "$document", "$rootScope", "$bsTooltip", "$timeout", function($window, $document, $rootScope, $tooltip, $timeout) {
  1699. var isNative = /(ip[ao]d|iphone|android)/gi.test($window.navigator.userAgent);
  1700. var isTouch = 'createTouch' in $window.document && isNative;
  1701. function SelectFactory(element, controller, config) {
  1702. var $select = {};
  1703. var options = angular.extend({}, defaults, config);
  1704. $select = $tooltip(element, options);
  1705. var scope = $select.$scope;
  1706. scope.$matches = [];
  1707. if (options.multiple) {
  1708. scope.$activeIndex = [];
  1709. } else {
  1710. scope.$activeIndex = -1;
  1711. }
  1712. scope.$isMultiple = options.multiple;
  1713. scope.$showAllNoneButtons = options.allNoneButtons && options.multiple;
  1714. scope.$iconCheckmark = options.iconCheckmark;
  1715. scope.$allText = options.allText;
  1716. scope.$noneText = options.noneText;
  1717. scope.$activate = function(index) {
  1718. scope.$$postDigest(function() {
  1719. $select.activate(index);
  1720. });
  1721. };
  1722. scope.$select = function(index, evt) {
  1723. scope.$$postDigest(function() {
  1724. $select.select(index);
  1725. });
  1726. };
  1727. scope.$isVisible = function() {
  1728. return $select.$isVisible();
  1729. };
  1730. scope.$isActive = function(index) {
  1731. return $select.$isActive(index);
  1732. };
  1733. scope.$selectAll = function() {
  1734. for (var i = 0; i < scope.$matches.length; i++) {
  1735. if (!scope.$isActive(i)) {
  1736. scope.$select(i);
  1737. }
  1738. }
  1739. };
  1740. scope.$selectNone = function() {
  1741. for (var i = 0; i < scope.$matches.length; i++) {
  1742. if (scope.$isActive(i)) {
  1743. scope.$select(i);
  1744. }
  1745. }
  1746. };
  1747. $select.update = function(matches) {
  1748. scope.$matches = matches;
  1749. $select.$updateActiveIndex();
  1750. };
  1751. $select.activate = function(index) {
  1752. if (options.multiple) {
  1753. if ($select.$isActive(index)) {
  1754. scope.$activeIndex.splice(scope.$activeIndex.indexOf(index), 1);
  1755. } else {
  1756. scope.$activeIndex.push(index);
  1757. }
  1758. if (options.sort) scope.$activeIndex.sort(function(a, b) {
  1759. return a - b;
  1760. });
  1761. } else {
  1762. scope.$activeIndex = index;
  1763. }
  1764. return scope.$activeIndex;
  1765. };
  1766. $select.select = function(index) {
  1767. if (angular.isUndefined(index) || index < 0 || index >= scope.$matches.length) {
  1768. return;
  1769. }
  1770. var value = scope.$matches[index].value;
  1771. scope.$apply(function() {
  1772. $select.activate(index);
  1773. if (options.multiple) {
  1774. controller.$setViewValue(scope.$activeIndex.map(function(index) {
  1775. if (angular.isUndefined(scope.$matches[index])) {
  1776. return null;
  1777. }
  1778. return scope.$matches[index].value;
  1779. }));
  1780. } else {
  1781. if (options.toggle) {
  1782. controller.$setViewValue(value === controller.$modelValue ? undefined : value);
  1783. } else {
  1784. controller.$setViewValue(value);
  1785. }
  1786. $select.hide();
  1787. }
  1788. });
  1789. scope.$emit(options.prefixEvent + '.select', value, index, $select);
  1790. if (angular.isDefined(options.onSelect) && angular.isFunction(options.onSelect)) {
  1791. options.onSelect(value, index, $select);
  1792. }
  1793. };
  1794. $select.$updateActiveIndex = function() {
  1795. if (options.multiple) {
  1796. if (angular.isArray(controller.$modelValue)) {
  1797. scope.$activeIndex = controller.$modelValue.map(function(value) {
  1798. return $select.$getIndex(value);
  1799. });
  1800. } else {
  1801. scope.$activeIndex = [];
  1802. }
  1803. } else {
  1804. if (angular.isDefined(controller.$modelValue) && scope.$matches.length) {
  1805. scope.$activeIndex = $select.$getIndex(controller.$modelValue);
  1806. } else {
  1807. scope.$activeIndex = -1;
  1808. }
  1809. }
  1810. };
  1811. $select.$isVisible = function() {
  1812. if (!options.minLength || !controller) {
  1813. return scope.$matches.length;
  1814. }
  1815. return scope.$matches.length && controller.$viewValue.length >= options.minLength;
  1816. };
  1817. $select.$isActive = function(index) {
  1818. if (options.multiple) {
  1819. return scope.$activeIndex.indexOf(index) !== -1;
  1820. }
  1821. return scope.$activeIndex === index;
  1822. };
  1823. $select.$getIndex = function(value) {
  1824. var index;
  1825. for (index = scope.$matches.length; index--; ) {
  1826. if (angular.equals(scope.$matches[index].value, value)) break;
  1827. }
  1828. return index;
  1829. };
  1830. $select.$onMouseDown = function(evt) {
  1831. evt.preventDefault();
  1832. evt.stopPropagation();
  1833. if (isTouch) {
  1834. var targetEl = angular.element(evt.target);
  1835. targetEl.triggerHandler('click');
  1836. }
  1837. };
  1838. $select.$onKeyDown = function(evt) {
  1839. if (!/(9|13|38|40)/.test(evt.keyCode)) return;
  1840. if (evt.keyCode !== 9) {
  1841. evt.preventDefault();
  1842. evt.stopPropagation();
  1843. }
  1844. if (options.multiple && evt.keyCode === 9) {
  1845. return $select.hide();
  1846. }
  1847. if (!options.multiple && (evt.keyCode === 13 || evt.keyCode === 9)) {
  1848. return $select.select(scope.$activeIndex);
  1849. }
  1850. if (!options.multiple) {
  1851. if (evt.keyCode === 38 && scope.$activeIndex > 0) scope.$activeIndex--; else if (evt.keyCode === 38 && scope.$activeIndex < 0) scope.$activeIndex = scope.$matches.length - 1; else if (evt.keyCode === 40 && scope.$activeIndex < scope.$matches.length - 1) scope.$activeIndex++; else if (angular.isUndefined(scope.$activeIndex)) scope.$activeIndex = 0;
  1852. scope.$digest();
  1853. }
  1854. };
  1855. $select.$isIE = function() {
  1856. var ua = $window.navigator.userAgent;
  1857. return ua.indexOf('MSIE ') > 0 || ua.indexOf('Trident/') > 0 || ua.indexOf('Edge/') > 0;
  1858. };
  1859. $select.$selectScrollFix = function(e) {
  1860. if ($document[0].activeElement.tagName === 'UL') {
  1861. e.preventDefault();
  1862. e.stopImmediatePropagation();
  1863. e.target.focus();
  1864. }
  1865. };
  1866. var _show = $select.show;
  1867. $select.show = function() {
  1868. _show();
  1869. if (options.multiple) {
  1870. $select.$element.addClass('select-multiple');
  1871. }
  1872. $timeout(function() {
  1873. $select.$element.on(isTouch ? 'touchstart' : 'mousedown', $select.$onMouseDown);
  1874. if (options.keyboard) {
  1875. element.on('keydown', $select.$onKeyDown);
  1876. }
  1877. }, 0, false);
  1878. };
  1879. var _hide = $select.hide;
  1880. $select.hide = function() {
  1881. if (!options.multiple && angular.isUndefined(controller.$modelValue)) {
  1882. scope.$activeIndex = -1;
  1883. }
  1884. $select.$element.off(isTouch ? 'touchstart' : 'mousedown', $select.$onMouseDown);
  1885. if (options.keyboard) {
  1886. element.off('keydown', $select.$onKeyDown);
  1887. }
  1888. _hide(true);
  1889. };
  1890. return $select;
  1891. }
  1892. SelectFactory.defaults = defaults;
  1893. return SelectFactory;
  1894. } ];
  1895. }).directive('bsSelect', ["$window", "$parse", "$q", "$bsSelect", "$bsParseOptions", function($window, $parse, $q, $select, $parseOptions) {
  1896. var defaults = $select.defaults;
  1897. return {
  1898. restrict: 'EAC',
  1899. require: 'ngModel',
  1900. link: function postLink(scope, element, attr, controller) {
  1901. var options = {
  1902. scope: scope,
  1903. placeholder: defaults.placeholder
  1904. };
  1905. angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'placement', 'container', 'delay', 'trigger', 'keyboard', 'html', 'animation', 'placeholder', 'allNoneButtons', 'maxLength', 'maxLengthHtml', 'allText', 'noneText', 'iconCheckmark', 'autoClose', 'id', 'sort', 'caretHtml', 'prefixClass', 'prefixEvent', 'toggle' ], function(key) {
  1906. if (angular.isDefined(attr[key])) options[key] = attr[key];
  1907. });
  1908. var falseValueRegExp = /^(false|0|)$/i;
  1909. angular.forEach([ 'html', 'container', 'allNoneButtons', 'sort' ], function(key) {
  1910. if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) {
  1911. options[key] = false;
  1912. }
  1913. });
  1914. angular.forEach([ 'onBeforeShow', 'onShow', 'onBeforeHide', 'onHide', 'onSelect' ], function(key) {
  1915. var bsKey = 'bs' + key.charAt(0).toUpperCase() + key.slice(1);
  1916. if (angular.isDefined(attr[bsKey])) {
  1917. options[key] = scope.$eval(attr[bsKey]);
  1918. }
  1919. });
  1920. var dataMultiple = element.attr('data-multiple');
  1921. if (angular.isDefined(dataMultiple)) {
  1922. if (falseValueRegExp.test(dataMultiple)) {
  1923. options.multiple = false;
  1924. } else {
  1925. options.multiple = dataMultiple;
  1926. }
  1927. }
  1928. if (element[0].nodeName.toLowerCase() === 'select') {
  1929. var inputEl = element;
  1930. inputEl.css('display', 'none');
  1931. element = angular.element('<button type="button" class="btn btn-default"></button>');
  1932. inputEl.after(element);
  1933. }
  1934. var parsedOptions = $parseOptions(attr.bsOptions);
  1935. var select = $select(element, controller, options);
  1936. if (select.$isIE()) {
  1937. element[0].addEventListener('blur', select.$selectScrollFix);
  1938. }
  1939. var watchedOptions = parsedOptions.$match[7].replace(/\|.+/, '').trim();
  1940. scope.$watch(watchedOptions, function(newValue, oldValue) {
  1941. parsedOptions.valuesFn(scope, controller).then(function(values) {
  1942. select.update(values);
  1943. controller.$render();
  1944. });
  1945. }, true);
  1946. scope.$watch(attr.ngModel, function(newValue, oldValue) {
  1947. select.$updateActiveIndex();
  1948. controller.$render();
  1949. }, true);
  1950. controller.$render = function() {
  1951. var selected;
  1952. var index;
  1953. if (options.multiple && angular.isArray(controller.$modelValue)) {
  1954. selected = controller.$modelValue.map(function(value) {
  1955. index = select.$getIndex(value);
  1956. return index !== -1 ? select.$scope.$matches[index].label : false;
  1957. }).filter(angular.isDefined);
  1958. if (selected.length > (options.maxLength || defaults.maxLength)) {
  1959. selected = selected.length + ' ' + (options.maxLengthHtml || defaults.maxLengthHtml);
  1960. } else {
  1961. selected = selected.join(', ');
  1962. }
  1963. } else {
  1964. index = select.$getIndex(controller.$modelValue);
  1965. selected = index !== -1 ? select.$scope.$matches[index].label : false;
  1966. }
  1967. element.html((selected || options.placeholder) + (options.caretHtml || defaults.caretHtml));
  1968. };
  1969. if (options.multiple) {
  1970. controller.$isEmpty = function(value) {
  1971. return !value || value.length === 0;
  1972. };
  1973. }
  1974. scope.$on('$destroy', function() {
  1975. if (select) select.destroy();
  1976. options = null;
  1977. select = null;
  1978. });
  1979. }
  1980. };
  1981. } ]);
  1982. angular.module('mgcrea.ngStrap.popover', [ 'mgcrea.ngStrap.tooltip' ]).provider('$bsPopover', function() {
  1983. var defaults = this.defaults = {
  1984. animation: 'am-fade',
  1985. customClass: '',
  1986. container: false,
  1987. target: false,
  1988. placement: 'right',
  1989. templateUrl: 'popover/popover.tpl.html',
  1990. contentTemplate: false,
  1991. trigger: 'click',
  1992. keyboard: true,
  1993. html: false,
  1994. title: '',
  1995. content: '',
  1996. delay: 0,
  1997. autoClose: false
  1998. };
  1999. this.$get = ["$bsTooltip", function($tooltip) {
  2000. function PopoverFactory(element, config) {
  2001. var options = angular.extend({}, defaults, config);
  2002. var $popover = $tooltip(element, options);
  2003. if (options.content) {
  2004. $popover.$scope.content = options.content;
  2005. }
  2006. return $popover;
  2007. }
  2008. return PopoverFactory;
  2009. } ];
  2010. }).directive('bsPopover', ["$window", "$sce", "$bsPopover", function($window, $sce, $popover) {
  2011. var requestAnimationFrame = $window.requestAnimationFrame || $window.setTimeout;
  2012. return {
  2013. restrict: 'EAC',
  2014. scope: true,
  2015. link: function postLink(scope, element, attr) {
  2016. var popover;
  2017. var options = {
  2018. scope: scope
  2019. };
  2020. angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'contentTemplate', 'placement', 'container', 'delay', 'trigger', 'html', 'animation', 'customClass', 'autoClose', 'id', 'prefixClass', 'prefixEvent' ], function(key) {
  2021. if (angular.isDefined(attr[key])) options[key] = attr[key];
  2022. });
  2023. var falseValueRegExp = /^(false|0|)$/i;
  2024. angular.forEach([ 'html', 'container', 'autoClose' ], function(key) {
  2025. if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) options[key] = false;
  2026. });
  2027. angular.forEach([ 'onBeforeShow', 'onShow', 'onBeforeHide', 'onHide' ], function(key) {
  2028. var bsKey = 'bs' + key.charAt(0).toUpperCase() + key.slice(1);
  2029. if (angular.isDefined(attr[bsKey])) {
  2030. options[key] = scope.$eval(attr[bsKey]);
  2031. }
  2032. });
  2033. var dataTarget = element.attr('data-target');
  2034. if (angular.isDefined(dataTarget)) {
  2035. if (falseValueRegExp.test(dataTarget)) {
  2036. options.target = false;
  2037. } else {
  2038. options.target = dataTarget;
  2039. }
  2040. }
  2041. angular.forEach([ 'title', 'content' ], function(key) {
  2042. if (attr[key]) {
  2043. attr.$observe(key, function(newValue, oldValue) {
  2044. scope[key] = $sce.trustAsHtml(newValue);
  2045. if (angular.isDefined(oldValue)) {
  2046. requestAnimationFrame(function() {
  2047. if (popover) popover.$applyPlacement();
  2048. });
  2049. }
  2050. });
  2051. }
  2052. });
  2053. if (attr.bsPopover) {
  2054. scope.$watch(attr.bsPopover, function(newValue, oldValue) {
  2055. if (angular.isObject(newValue)) {
  2056. angular.extend(scope, newValue);
  2057. } else {
  2058. scope.content = newValue;
  2059. }
  2060. if (angular.isDefined(oldValue)) {
  2061. requestAnimationFrame(function() {
  2062. if (popover) popover.$applyPlacement();
  2063. });
  2064. }
  2065. }, true);
  2066. }
  2067. if (attr.bsShow) {
  2068. scope.$watch(attr.bsShow, function(newValue, oldValue) {
  2069. if (!popover || !angular.isDefined(newValue)) return;
  2070. if (angular.isString(newValue)) newValue = !!newValue.match(/true|,?(popover),?/i);
  2071. if (newValue === true) {
  2072. popover.show();
  2073. } else {
  2074. popover.hide();
  2075. }
  2076. });
  2077. }
  2078. if (attr.viewport) {
  2079. scope.$watch(attr.viewport, function(newValue) {
  2080. if (!popover || !angular.isDefined(newValue)) return;
  2081. popover.setViewport(newValue);
  2082. });
  2083. }
  2084. popover = $popover(element, options);
  2085. scope.$on('$destroy', function() {
  2086. if (popover) popover.destroy();
  2087. options = null;
  2088. popover = null;
  2089. });
  2090. }
  2091. };
  2092. } ]);
  2093. angular.module('mgcrea.ngStrap.navbar', []).provider('$bsNavbar', function() {
  2094. var defaults = this.defaults = {
  2095. activeClass: 'active',
  2096. routeAttr: 'data-match-route',
  2097. strict: false
  2098. };
  2099. this.$get = function() {
  2100. return {
  2101. defaults: defaults
  2102. };
  2103. };
  2104. }).directive('bsNavbar', ["$window", "$location", "$bsNavbar", function($window, $location, $navbar) {
  2105. var defaults = $navbar.defaults;
  2106. return {
  2107. restrict: 'A',
  2108. link: function postLink(scope, element, attr, controller) {
  2109. var options = angular.copy(defaults);
  2110. angular.forEach(Object.keys(defaults), function(key) {
  2111. if (angular.isDefined(attr[key])) options[key] = attr[key];
  2112. });
  2113. scope.$watch(function() {
  2114. return $location.path();
  2115. }, function(newValue, oldValue) {
  2116. var liElements = element[0].querySelectorAll('li[' + options.routeAttr + ']');
  2117. angular.forEach(liElements, function(li) {
  2118. var liElement = angular.element(li);
  2119. var pattern = liElement.attr(options.routeAttr).replace('/', '\\/');
  2120. if (options.strict) {
  2121. pattern = '^' + pattern + '$';
  2122. }
  2123. var regexp = new RegExp(pattern, 'i');
  2124. if (regexp.test(newValue)) {
  2125. liElement.addClass(options.activeClass);
  2126. } else {
  2127. liElement.removeClass(options.activeClass);
  2128. }
  2129. });
  2130. });
  2131. }
  2132. };
  2133. } ]);
  2134. angular.module('mgcrea.ngStrap.modal', [ 'mgcrea.ngStrap.core', 'mgcrea.ngStrap.helpers.dimensions' ]).provider('$bsModal', function() {
  2135. var defaults = this.defaults = {
  2136. animation: 'am-fade',
  2137. backdropAnimation: 'am-fade',
  2138. customClass: '',
  2139. prefixClass: 'modal',
  2140. prefixEvent: 'modal',
  2141. placement: 'top',
  2142. templateUrl: 'modal/modal.tpl.html',
  2143. template: '',
  2144. contentTemplate: false,
  2145. container: false,
  2146. element: null,
  2147. backdrop: true,
  2148. keyboard: true,
  2149. html: false,
  2150. show: true,
  2151. size: null
  2152. };
  2153. this.$get = ["$window", "$rootScope", "$bsCompiler", "$animate", "$timeout", "$sce", "bsDimensions", function($window, $rootScope, $bsCompiler, $animate, $timeout, $sce, dimensions) {
  2154. var forEach = angular.forEach;
  2155. var requestAnimationFrame = $window.requestAnimationFrame || $window.setTimeout;
  2156. var bodyElement = angular.element($window.document.body);
  2157. var backdropCount = 0;
  2158. var dialogBaseZindex = 1050;
  2159. var backdropBaseZindex = 1040;
  2160. var validSizes = {
  2161. lg: 'modal-lg',
  2162. sm: 'modal-sm'
  2163. };
  2164. function ModalFactory(config) {
  2165. var $modal = {};
  2166. var options = $modal.$options = angular.extend({}, defaults, config);
  2167. var promise = $modal.$promise = $bsCompiler.compile(options);
  2168. var scope = $modal.$scope = options.scope && options.scope.$new() || $rootScope.$new();
  2169. if (!options.element && !options.container) {
  2170. options.container = 'body';
  2171. }
  2172. $modal.$id = options.id || options.element && options.element.attr('id') || '';
  2173. forEach([ 'title', 'content' ], function(key) {
  2174. if (options[key]) scope[key] = $sce.trustAsHtml(options[key]);
  2175. });
  2176. scope.$hide = function() {
  2177. scope.$$postDigest(function() {
  2178. $modal.hide();
  2179. });
  2180. };
  2181. scope.$show = function() {
  2182. scope.$$postDigest(function() {
  2183. $modal.show();
  2184. });
  2185. };
  2186. scope.$toggle = function() {
  2187. scope.$$postDigest(function() {
  2188. $modal.toggle();
  2189. });
  2190. };
  2191. $modal.$isShown = scope.$isShown = false;
  2192. var compileData;
  2193. var modalElement;
  2194. var modalScope;
  2195. var backdropElement = angular.element('<div class="' + options.prefixClass + '-backdrop"/>');
  2196. backdropElement.css({
  2197. position: 'fixed',
  2198. top: '0px',
  2199. left: '0px',
  2200. bottom: '0px',
  2201. right: '0px'
  2202. });
  2203. promise.then(function(data) {
  2204. compileData = data;
  2205. $modal.init();
  2206. });
  2207. $modal.init = function() {
  2208. if (options.show) {
  2209. scope.$$postDigest(function() {
  2210. $modal.show();
  2211. });
  2212. }
  2213. };
  2214. $modal.destroy = function() {
  2215. destroyModalElement();
  2216. if (backdropElement) {
  2217. backdropElement.remove();
  2218. backdropElement = null;
  2219. }
  2220. scope.$destroy();
  2221. };
  2222. $modal.show = function() {
  2223. if ($modal.$isShown) return;
  2224. var parent;
  2225. var after;
  2226. if (angular.isElement(options.container)) {
  2227. parent = options.container;
  2228. after = options.container[0].lastChild ? angular.element(options.container[0].lastChild) : null;
  2229. } else {
  2230. if (options.container) {
  2231. parent = findElement(options.container);
  2232. after = parent[0] && parent[0].lastChild ? angular.element(parent[0].lastChild) : null;
  2233. } else {
  2234. parent = null;
  2235. after = options.element;
  2236. }
  2237. }
  2238. if (modalElement) destroyModalElement();
  2239. modalScope = $modal.$scope.$new();
  2240. modalElement = $modal.$element = compileData.link(modalScope, function(clonedElement, scope) {});
  2241. if (options.backdrop) {
  2242. modalElement.css({
  2243. 'z-index': dialogBaseZindex + backdropCount * 20
  2244. });
  2245. backdropElement.css({
  2246. 'z-index': backdropBaseZindex + backdropCount * 20
  2247. });
  2248. backdropCount++;
  2249. }
  2250. if (scope.$emit(options.prefixEvent + '.show.before', $modal).defaultPrevented) {
  2251. return;
  2252. }
  2253. if (angular.isDefined(options.onBeforeShow) && angular.isFunction(options.onBeforeShow)) {
  2254. options.onBeforeShow($modal);
  2255. }
  2256. modalElement.css({
  2257. display: 'block'
  2258. }).addClass(options.placement);
  2259. if (options.customClass) {
  2260. modalElement.addClass(options.customClass);
  2261. }
  2262. if (options.size && validSizes[options.size]) {
  2263. angular.element(findElement('.modal-dialog', modalElement[0])).addClass(validSizes[options.size]);
  2264. }
  2265. if (options.animation) {
  2266. if (options.backdrop) {
  2267. backdropElement.addClass(options.backdropAnimation);
  2268. }
  2269. modalElement.addClass(options.animation);
  2270. }
  2271. if (options.backdrop) {
  2272. $animate.enter(backdropElement, bodyElement, null);
  2273. }
  2274. if (angular.version.minor <= 2) {
  2275. $animate.enter(modalElement, parent, after, enterAnimateCallback);
  2276. } else {
  2277. $animate.enter(modalElement, parent, after).then(enterAnimateCallback);
  2278. }
  2279. $modal.$isShown = scope.$isShown = true;
  2280. safeDigest(scope);
  2281. var el = modalElement[0];
  2282. requestAnimationFrame(function() {
  2283. el.focus();
  2284. });
  2285. bodyElement.addClass(options.prefixClass + '-open');
  2286. if (options.animation) {
  2287. bodyElement.addClass(options.prefixClass + '-with-' + options.animation);
  2288. }
  2289. bindBackdropEvents();
  2290. bindKeyboardEvents();
  2291. };
  2292. function enterAnimateCallback() {
  2293. scope.$emit(options.prefixEvent + '.show', $modal);
  2294. if (angular.isDefined(options.onShow) && angular.isFunction(options.onShow)) {
  2295. options.onShow($modal);
  2296. }
  2297. }
  2298. $modal.hide = function() {
  2299. if (!$modal.$isShown) return;
  2300. if (scope.$emit(options.prefixEvent + '.hide.before', $modal).defaultPrevented) {
  2301. return;
  2302. }
  2303. if (angular.isDefined(options.onBeforeHide) && angular.isFunction(options.onBeforeHide)) {
  2304. options.onBeforeHide($modal);
  2305. }
  2306. if (angular.version.minor <= 2) {
  2307. $animate.leave(modalElement, leaveAnimateCallback);
  2308. } else {
  2309. $animate.leave(modalElement).then(leaveAnimateCallback);
  2310. }
  2311. if (options.backdrop) {
  2312. backdropCount--;
  2313. $animate.leave(backdropElement);
  2314. }
  2315. $modal.$isShown = scope.$isShown = false;
  2316. safeDigest(scope);
  2317. unbindBackdropEvents();
  2318. unbindKeyboardEvents();
  2319. };
  2320. function leaveAnimateCallback() {
  2321. scope.$emit(options.prefixEvent + '.hide', $modal);
  2322. if (angular.isDefined(options.onHide) && angular.isFunction(options.onHide)) {
  2323. options.onHide($modal);
  2324. }
  2325. bodyElement.removeClass(options.prefixClass + '-open');
  2326. if (options.animation) {
  2327. bodyElement.removeClass(options.prefixClass + '-with-' + options.animation);
  2328. }
  2329. }
  2330. $modal.toggle = function() {
  2331. if ($modal.$isShown) {
  2332. $modal.hide();
  2333. } else {
  2334. $modal.show();
  2335. }
  2336. };
  2337. $modal.focus = function() {
  2338. modalElement[0].focus();
  2339. };
  2340. $modal.$onKeyUp = function(evt) {
  2341. if (evt.which === 27 && $modal.$isShown) {
  2342. $modal.hide();
  2343. evt.stopPropagation();
  2344. }
  2345. };
  2346. function bindBackdropEvents() {
  2347. if (options.backdrop) {
  2348. modalElement.on('click', hideOnBackdropClick);
  2349. backdropElement.on('click', hideOnBackdropClick);
  2350. backdropElement.on('wheel', preventEventDefault);
  2351. }
  2352. }
  2353. function unbindBackdropEvents() {
  2354. if (options.backdrop) {
  2355. modalElement.off('click', hideOnBackdropClick);
  2356. backdropElement.off('click', hideOnBackdropClick);
  2357. backdropElement.off('wheel', preventEventDefault);
  2358. }
  2359. }
  2360. function bindKeyboardEvents() {
  2361. if (options.keyboard) {
  2362. modalElement.on('keyup', $modal.$onKeyUp);
  2363. }
  2364. }
  2365. function unbindKeyboardEvents() {
  2366. if (options.keyboard) {
  2367. modalElement.off('keyup', $modal.$onKeyUp);
  2368. }
  2369. }
  2370. function hideOnBackdropClick(evt) {
  2371. if (evt.target !== evt.currentTarget) return;
  2372. if (options.backdrop === 'static') {
  2373. $modal.focus();
  2374. } else {
  2375. $modal.hide();
  2376. }
  2377. }
  2378. function preventEventDefault(evt) {
  2379. evt.preventDefault();
  2380. }
  2381. function destroyModalElement() {
  2382. if ($modal.$isShown && modalElement !== null) {
  2383. unbindBackdropEvents();
  2384. unbindKeyboardEvents();
  2385. }
  2386. if (modalScope) {
  2387. modalScope.$destroy();
  2388. modalScope = null;
  2389. }
  2390. if (modalElement) {
  2391. modalElement.remove();
  2392. modalElement = $modal.$element = null;
  2393. }
  2394. }
  2395. return $modal;
  2396. }
  2397. function safeDigest(scope) {
  2398. scope.$$phase || scope.$root && scope.$root.$$phase || scope.$digest();
  2399. }
  2400. function findElement(query, element) {
  2401. return angular.element((element || document).querySelectorAll(query));
  2402. }
  2403. return ModalFactory;
  2404. } ];
  2405. }).directive('bsModal', ["$window", "$sce", "$parse", "$bsModal", function($window, $sce, $parse, $modal) {
  2406. return {
  2407. restrict: 'EAC',
  2408. scope: true,
  2409. link: function postLink(scope, element, attr, transclusion) {
  2410. var options = {
  2411. scope: scope,
  2412. element: element,
  2413. show: false
  2414. };
  2415. angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'contentTemplate', 'placement', 'backdrop', 'keyboard', 'html', 'container', 'animation', 'backdropAnimation', 'id', 'prefixEvent', 'prefixClass', 'customClass', 'modalClass', 'size' ], function(key) {
  2416. if (angular.isDefined(attr[key])) options[key] = attr[key];
  2417. });
  2418. if (options.modalClass) {
  2419. options.customClass = options.modalClass;
  2420. }
  2421. var falseValueRegExp = /^(false|0|)$/i;
  2422. angular.forEach([ 'backdrop', 'keyboard', 'html', 'container' ], function(key) {
  2423. if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) options[key] = false;
  2424. });
  2425. angular.forEach([ 'onBeforeShow', 'onShow', 'onBeforeHide', 'onHide' ], function(key) {
  2426. var bsKey = 'bs' + key.charAt(0).toUpperCase() + key.slice(1);
  2427. if (angular.isDefined(attr[bsKey])) {
  2428. options[key] = scope.$eval(attr[bsKey]);
  2429. }
  2430. });
  2431. angular.forEach([ 'title', 'content' ], function(key) {
  2432. if (attr[key]) {
  2433. attr.$observe(key, function(newValue, oldValue) {
  2434. scope[key] = $sce.trustAsHtml(newValue);
  2435. });
  2436. }
  2437. });
  2438. if (attr.bsModal) {
  2439. scope.$watch(attr.bsModal, function(newValue, oldValue) {
  2440. if (angular.isObject(newValue)) {
  2441. angular.extend(scope, newValue);
  2442. } else {
  2443. scope.content = newValue;
  2444. }
  2445. }, true);
  2446. }
  2447. var modal = $modal(options);
  2448. element.on(attr.trigger || 'click', modal.toggle);
  2449. scope.$on('$destroy', function() {
  2450. if (modal) modal.destroy();
  2451. options = null;
  2452. modal = null;
  2453. });
  2454. }
  2455. };
  2456. } ]);
  2457. angular.module('mgcrea.ngStrap.dropdown', [ 'mgcrea.ngStrap.tooltip' ]).provider('$bsDropdown', function() {
  2458. var defaults = this.defaults = {
  2459. animation: 'am-fade',
  2460. prefixClass: 'dropdown',
  2461. prefixEvent: 'dropdown',
  2462. placement: 'bottom-left',
  2463. templateUrl: 'dropdown/dropdown.tpl.html',
  2464. trigger: 'click',
  2465. container: false,
  2466. keyboard: true,
  2467. html: false,
  2468. delay: 0
  2469. };
  2470. this.$get = ["$window", "$rootScope", "$bsTooltip", "$timeout", function($window, $rootScope, $tooltip, $timeout) {
  2471. var bodyEl = angular.element($window.document.body);
  2472. var matchesSelector = Element.prototype.matchesSelector || Element.prototype.webkitMatchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.oMatchesSelector;
  2473. function DropdownFactory(element, config) {
  2474. var $dropdown = {};
  2475. var options = angular.extend({}, defaults, config);
  2476. $dropdown.$scope = options.scope && options.scope.$new() || $rootScope.$new();
  2477. $dropdown = $tooltip(element, options);
  2478. var parentEl = element.parent();
  2479. $dropdown.$onKeyDown = function(evt) {
  2480. if (!/(38|40)/.test(evt.keyCode)) return;
  2481. evt.preventDefault();
  2482. evt.stopPropagation();
  2483. var items = angular.element($dropdown.$element[0].querySelectorAll('li:not(.divider) a'));
  2484. if (!items.length) return;
  2485. var index;
  2486. angular.forEach(items, function(el, i) {
  2487. if (matchesSelector && matchesSelector.call(el, ':focus')) index = i;
  2488. });
  2489. if (evt.keyCode === 38 && index > 0) index--; else if (evt.keyCode === 40 && index < items.length - 1) index++; else if (angular.isUndefined(index)) index = 0;
  2490. items.eq(index)[0].focus();
  2491. };
  2492. var show = $dropdown.show;
  2493. $dropdown.show = function() {
  2494. show();
  2495. $timeout(function() {
  2496. if (options.keyboard && $dropdown.$element) $dropdown.$element.on('keydown', $dropdown.$onKeyDown);
  2497. bodyEl.on('click', onBodyClick);
  2498. }, 0, false);
  2499. if (parentEl.hasClass('dropdown')) parentEl.addClass('open');
  2500. };
  2501. var hide = $dropdown.hide;
  2502. $dropdown.hide = function() {
  2503. if (!$dropdown.$isShown) return;
  2504. if (options.keyboard && $dropdown.$element) $dropdown.$element.off('keydown', $dropdown.$onKeyDown);
  2505. bodyEl.off('click', onBodyClick);
  2506. if (parentEl.hasClass('dropdown')) parentEl.removeClass('open');
  2507. hide();
  2508. };
  2509. var destroy = $dropdown.destroy;
  2510. $dropdown.destroy = function() {
  2511. bodyEl.off('click', onBodyClick);
  2512. destroy();
  2513. };
  2514. function onBodyClick(evt) {
  2515. if (evt.target === element[0]) return;
  2516. return evt.target !== element[0] && $dropdown.hide();
  2517. }
  2518. return $dropdown;
  2519. }
  2520. return DropdownFactory;
  2521. } ];
  2522. }).directive('bsDropdown', ["$window", "$sce", "$bsDropdown", function($window, $sce, $dropdown) {
  2523. return {
  2524. restrict: 'EAC',
  2525. scope: true,
  2526. compile: function(tElement, tAttrs) {
  2527. if (!tAttrs.bsDropdown) {
  2528. var nextSibling = tElement[0].nextSibling;
  2529. while (nextSibling && nextSibling.nodeType !== 1) {
  2530. nextSibling = nextSibling.nextSibling;
  2531. }
  2532. if (nextSibling && nextSibling.className.split(' ').indexOf('dropdown-menu') >= 0) {
  2533. tAttrs.template = nextSibling.outerHTML;
  2534. tAttrs.templateUrl = undefined;
  2535. nextSibling.parentNode.removeChild(nextSibling);
  2536. }
  2537. }
  2538. return function postLink(scope, element, attr) {
  2539. var options = {
  2540. scope: scope
  2541. };
  2542. angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'placement', 'container', 'delay', 'trigger', 'keyboard', 'html', 'animation', 'id', 'autoClose' ], function(key) {
  2543. if (angular.isDefined(tAttrs[key])) options[key] = tAttrs[key];
  2544. });
  2545. var falseValueRegExp = /^(false|0|)$/i;
  2546. angular.forEach([ 'html', 'container' ], function(key) {
  2547. if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) options[key] = false;
  2548. });
  2549. angular.forEach([ 'onBeforeShow', 'onShow', 'onBeforeHide', 'onHide' ], function(key) {
  2550. var bsKey = 'bs' + key.charAt(0).toUpperCase() + key.slice(1);
  2551. if (angular.isDefined(attr[bsKey])) {
  2552. options[key] = scope.$eval(attr[bsKey]);
  2553. }
  2554. });
  2555. if (attr.bsDropdown) {
  2556. scope.$watch(attr.bsDropdown, function(newValue, oldValue) {
  2557. scope.content = newValue;
  2558. }, true);
  2559. }
  2560. var dropdown = $dropdown(element, options);
  2561. if (attr.bsShow) {
  2562. scope.$watch(attr.bsShow, function(newValue, oldValue) {
  2563. if (!dropdown || !angular.isDefined(newValue)) return;
  2564. if (angular.isString(newValue)) newValue = !!newValue.match(/true|,?(dropdown),?/i);
  2565. if (newValue === true) {
  2566. dropdown.show();
  2567. } else {
  2568. dropdown.hide();
  2569. }
  2570. });
  2571. }
  2572. scope.$on('$destroy', function() {
  2573. if (dropdown) dropdown.destroy();
  2574. options = null;
  2575. dropdown = null;
  2576. });
  2577. };
  2578. }
  2579. };
  2580. } ]);
  2581. if (angular.version.minor < 3 && angular.version.dot < 14) {
  2582. angular.module('ng').factory('$$rAF', ["$window", "$timeout", function($window, $timeout) {
  2583. var requestAnimationFrame = $window.requestAnimationFrame || $window.webkitRequestAnimationFrame || $window.mozRequestAnimationFrame;
  2584. var cancelAnimationFrame = $window.cancelAnimationFrame || $window.webkitCancelAnimationFrame || $window.mozCancelAnimationFrame || $window.webkitCancelRequestAnimationFrame;
  2585. var rafSupported = !!requestAnimationFrame;
  2586. var raf = rafSupported ? function(fn) {
  2587. var id = requestAnimationFrame(fn);
  2588. return function() {
  2589. cancelAnimationFrame(id);
  2590. };
  2591. } : function(fn) {
  2592. var timer = $timeout(fn, 16.66, false);
  2593. return function() {
  2594. $timeout.cancel(timer);
  2595. };
  2596. };
  2597. raf.supported = rafSupported;
  2598. return raf;
  2599. } ]);
  2600. }
  2601. angular.module('mgcrea.ngStrap.helpers.parseOptions', []).provider('$bsParseOptions', function() {
  2602. var defaults = this.defaults = {
  2603. regexp: /^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/
  2604. };
  2605. this.$get = ["$parse", "$q", function($parse, $q) {
  2606. function ParseOptionsFactory(attr, config) {
  2607. var $parseOptions = {};
  2608. var options = angular.extend({}, defaults, config);
  2609. $parseOptions.$values = [];
  2610. var match;
  2611. var displayFn;
  2612. var valueName;
  2613. var keyName;
  2614. var groupByFn;
  2615. var valueFn;
  2616. var valuesFn;
  2617. $parseOptions.init = function() {
  2618. $parseOptions.$match = match = attr.match(options.regexp);
  2619. displayFn = $parse(match[2] || match[1]);
  2620. valueName = match[4] || match[6];
  2621. keyName = match[5];
  2622. groupByFn = $parse(match[3] || '');
  2623. valueFn = $parse(match[2] ? match[1] : valueName);
  2624. valuesFn = $parse(match[7]);
  2625. };
  2626. $parseOptions.valuesFn = function(scope, controller) {
  2627. return $q.when(valuesFn(scope, controller)).then(function(values) {
  2628. if (!angular.isArray(values)) {
  2629. values = [];
  2630. }
  2631. $parseOptions.$values = values.length ? parseValues(values, scope) : [];
  2632. return $parseOptions.$values;
  2633. });
  2634. };
  2635. $parseOptions.displayValue = function(modelValue) {
  2636. var scope = {};
  2637. scope[valueName] = modelValue;
  2638. return displayFn(scope);
  2639. };
  2640. function parseValues(values, scope) {
  2641. return values.map(function(match, index) {
  2642. var locals = {};
  2643. var label;
  2644. var value;
  2645. locals[valueName] = match;
  2646. label = displayFn(scope, locals);
  2647. value = valueFn(scope, locals);
  2648. return {
  2649. label: label,
  2650. value: value,
  2651. index: index
  2652. };
  2653. });
  2654. }
  2655. $parseOptions.init();
  2656. return $parseOptions;
  2657. }
  2658. return ParseOptionsFactory;
  2659. } ];
  2660. });
  2661. angular.module('mgcrea.ngStrap.helpers.dimensions', []).factory('bsDimensions', function() {
  2662. var fn = {};
  2663. var nodeName = fn.nodeName = function(element, name) {
  2664. return element.nodeName && element.nodeName.toLowerCase() === name.toLowerCase();
  2665. };
  2666. fn.css = function(element, prop, extra) {
  2667. var value;
  2668. if (element.currentStyle) {
  2669. value = element.currentStyle[prop];
  2670. } else if (window.getComputedStyle) {
  2671. value = window.getComputedStyle(element)[prop];
  2672. } else {
  2673. value = element.style[prop];
  2674. }
  2675. return extra === true ? parseFloat(value) || 0 : value;
  2676. };
  2677. fn.offset = function(element) {
  2678. var boxRect = element.getBoundingClientRect();
  2679. var docElement = element.ownerDocument;
  2680. return {
  2681. width: boxRect.width || element.offsetWidth,
  2682. height: boxRect.height || element.offsetHeight,
  2683. top: boxRect.top + (window.pageYOffset || docElement.documentElement.scrollTop) - (docElement.documentElement.clientTop || 0),
  2684. left: boxRect.left + (window.pageXOffset || docElement.documentElement.scrollLeft) - (docElement.documentElement.clientLeft || 0)
  2685. };
  2686. };
  2687. fn.setOffset = function(element, options, i) {
  2688. var curPosition;
  2689. var curLeft;
  2690. var curCSSTop;
  2691. var curTop;
  2692. var curOffset;
  2693. var curCSSLeft;
  2694. var calculatePosition;
  2695. var position = fn.css(element, 'position');
  2696. var curElem = angular.element(element);
  2697. var props = {};
  2698. if (position === 'static') {
  2699. element.style.position = 'relative';
  2700. }
  2701. curOffset = fn.offset(element);
  2702. curCSSTop = fn.css(element, 'top');
  2703. curCSSLeft = fn.css(element, 'left');
  2704. calculatePosition = (position === 'absolute' || position === 'fixed') && (curCSSTop + curCSSLeft).indexOf('auto') > -1;
  2705. if (calculatePosition) {
  2706. curPosition = fn.position(element);
  2707. curTop = curPosition.top;
  2708. curLeft = curPosition.left;
  2709. } else {
  2710. curTop = parseFloat(curCSSTop) || 0;
  2711. curLeft = parseFloat(curCSSLeft) || 0;
  2712. }
  2713. if (angular.isFunction(options)) {
  2714. options = options.call(element, i, curOffset);
  2715. }
  2716. if (options.top !== null) {
  2717. props.top = options.top - curOffset.top + curTop;
  2718. }
  2719. if (options.left !== null) {
  2720. props.left = options.left - curOffset.left + curLeft;
  2721. }
  2722. if ('using' in options) {
  2723. options.using.call(curElem, props);
  2724. } else {
  2725. curElem.css({
  2726. top: props.top + 'px',
  2727. left: props.left + 'px'
  2728. });
  2729. }
  2730. };
  2731. fn.position = function(element) {
  2732. var offsetParentRect = {
  2733. top: 0,
  2734. left: 0
  2735. };
  2736. var offsetParentEl;
  2737. var offset;
  2738. if (fn.css(element, 'position') === 'fixed') {
  2739. offset = element.getBoundingClientRect();
  2740. } else {
  2741. offsetParentEl = offsetParentElement(element);
  2742. offset = fn.offset(element);
  2743. if (!nodeName(offsetParentEl, 'html')) {
  2744. offsetParentRect = fn.offset(offsetParentEl);
  2745. }
  2746. offsetParentRect.top += fn.css(offsetParentEl, 'borderTopWidth', true);
  2747. offsetParentRect.left += fn.css(offsetParentEl, 'borderLeftWidth', true);
  2748. }
  2749. return {
  2750. width: element.offsetWidth,
  2751. height: element.offsetHeight,
  2752. top: offset.top - offsetParentRect.top - fn.css(element, 'marginTop', true),
  2753. left: offset.left - offsetParentRect.left - fn.css(element, 'marginLeft', true)
  2754. };
  2755. };
  2756. function offsetParentElement(element) {
  2757. var docElement = element.ownerDocument;
  2758. var offsetParent = element.offsetParent || docElement;
  2759. if (nodeName(offsetParent, '#document')) return docElement.documentElement;
  2760. while (offsetParent && !nodeName(offsetParent, 'html') && fn.css(offsetParent, 'position') === 'static') {
  2761. offsetParent = offsetParent.offsetParent;
  2762. }
  2763. return offsetParent || docElement.documentElement;
  2764. }
  2765. fn.height = function(element, outer) {
  2766. var value = element.offsetHeight;
  2767. if (outer) {
  2768. value += fn.css(element, 'marginTop', true) + fn.css(element, 'marginBottom', true);
  2769. } else {
  2770. value -= fn.css(element, 'paddingTop', true) + fn.css(element, 'paddingBottom', true) + fn.css(element, 'borderTopWidth', true) + fn.css(element, 'borderBottomWidth', true);
  2771. }
  2772. return value;
  2773. };
  2774. fn.width = function(element, outer) {
  2775. var value = element.offsetWidth;
  2776. if (outer) {
  2777. value += fn.css(element, 'marginLeft', true) + fn.css(element, 'marginRight', true);
  2778. } else {
  2779. value -= fn.css(element, 'paddingLeft', true) + fn.css(element, 'paddingRight', true) + fn.css(element, 'borderLeftWidth', true) + fn.css(element, 'borderRightWidth', true);
  2780. }
  2781. return value;
  2782. };
  2783. return fn;
  2784. });
  2785. angular.module('mgcrea.ngStrap.helpers.debounce', []).factory('bsDebounce', ["$timeout", function($timeout) {
  2786. return function(func, wait, immediate) {
  2787. var timeout = null;
  2788. return function() {
  2789. var context = this;
  2790. var args = arguments;
  2791. var callNow = immediate && !timeout;
  2792. if (timeout) {
  2793. $timeout.cancel(timeout);
  2794. }
  2795. timeout = $timeout(function later() {
  2796. timeout = null;
  2797. if (!immediate) {
  2798. func.apply(context, args);
  2799. }
  2800. }, wait, false);
  2801. if (callNow) {
  2802. func.apply(context, args);
  2803. }
  2804. return timeout;
  2805. };
  2806. };
  2807. } ]).factory('bsThrottle', ["$timeout", function($timeout) {
  2808. return function(func, wait, options) {
  2809. var timeout = null;
  2810. if (!options) options = {};
  2811. return function() {
  2812. var context = this;
  2813. var args = arguments;
  2814. if (!timeout) {
  2815. if (options.leading !== false) {
  2816. func.apply(context, args);
  2817. }
  2818. timeout = $timeout(function later() {
  2819. timeout = null;
  2820. if (options.trailing !== false) {
  2821. func.apply(context, args);
  2822. }
  2823. }, wait, false);
  2824. }
  2825. };
  2826. };
  2827. } ]);
  2828. angular.module('mgcrea.ngStrap.helpers.dateParser', []).provider('$bsDateParser', ["$localeProvider", function($localeProvider) {
  2829. function ParseDate() {
  2830. this.year = 1970;
  2831. this.month = 0;
  2832. this.day = 1;
  2833. this.hours = 0;
  2834. this.minutes = 0;
  2835. this.seconds = 0;
  2836. this.milliseconds = 0;
  2837. }
  2838. ParseDate.prototype.setMilliseconds = function(value) {
  2839. this.milliseconds = value;
  2840. };
  2841. ParseDate.prototype.setSeconds = function(value) {
  2842. this.seconds = value;
  2843. };
  2844. ParseDate.prototype.setMinutes = function(value) {
  2845. this.minutes = value;
  2846. };
  2847. ParseDate.prototype.setHours = function(value) {
  2848. this.hours = value;
  2849. };
  2850. ParseDate.prototype.getHours = function() {
  2851. return this.hours;
  2852. };
  2853. ParseDate.prototype.setDate = function(value) {
  2854. this.day = value;
  2855. };
  2856. ParseDate.prototype.setMonth = function(value) {
  2857. this.month = value;
  2858. };
  2859. ParseDate.prototype.setFullYear = function(value) {
  2860. this.year = value;
  2861. };
  2862. ParseDate.prototype.fromDate = function(value) {
  2863. this.year = value.getFullYear();
  2864. this.month = value.getMonth();
  2865. this.day = value.getDate();
  2866. this.hours = value.getHours();
  2867. this.minutes = value.getMinutes();
  2868. this.seconds = value.getSeconds();
  2869. this.milliseconds = value.getMilliseconds();
  2870. return this;
  2871. };
  2872. ParseDate.prototype.toDate = function() {
  2873. return new Date(this.year, this.month, this.day, this.hours, this.minutes, this.seconds, this.milliseconds);
  2874. };
  2875. var proto = ParseDate.prototype;
  2876. function noop() {}
  2877. function isNumeric(n) {
  2878. return !isNaN(parseFloat(n)) && isFinite(n);
  2879. }
  2880. function indexOfCaseInsensitive(array, value) {
  2881. var len = array.length;
  2882. var str = value.toString().toLowerCase();
  2883. for (var i = 0; i < len; i++) {
  2884. if (array[i].toLowerCase() === str) {
  2885. return i;
  2886. }
  2887. }
  2888. return -1;
  2889. }
  2890. var defaults = this.defaults = {
  2891. format: 'shortDate',
  2892. strict: false
  2893. };
  2894. this.$get = ["$locale", "dateFilter", function($locale, dateFilter) {
  2895. var DateParserFactory = function(config) {
  2896. var options = angular.extend({}, defaults, config);
  2897. var $dateParser = {};
  2898. var regExpMap = {
  2899. sss: '[0-9]{3}',
  2900. ss: '[0-5][0-9]',
  2901. s: options.strict ? '[1-5]?[0-9]' : '[0-9]|[0-5][0-9]',
  2902. mm: '[0-5][0-9]',
  2903. m: options.strict ? '[1-5]?[0-9]' : '[0-9]|[0-5][0-9]',
  2904. HH: '[01][0-9]|2[0-3]',
  2905. H: options.strict ? '1?[0-9]|2[0-3]' : '[01]?[0-9]|2[0-3]',
  2906. hh: '[0][1-9]|[1][012]',
  2907. h: options.strict ? '[1-9]|1[012]' : '0?[1-9]|1[012]',
  2908. a: 'AM|PM',
  2909. EEEE: $locale.DATETIME_FORMATS.DAY.join('|'),
  2910. EEE: $locale.DATETIME_FORMATS.SHORTDAY.join('|'),
  2911. dd: '0[1-9]|[12][0-9]|3[01]',
  2912. d: options.strict ? '[1-9]|[1-2][0-9]|3[01]' : '0?[1-9]|[1-2][0-9]|3[01]',
  2913. MMMM: $locale.DATETIME_FORMATS.MONTH.join('|'),
  2914. MMM: $locale.DATETIME_FORMATS.SHORTMONTH.join('|'),
  2915. MM: '0[1-9]|1[012]',
  2916. M: options.strict ? '[1-9]|1[012]' : '0?[1-9]|1[012]',
  2917. yyyy: '[1]{1}[0-9]{3}|[2]{1}[0-9]{3}',
  2918. yy: '[0-9]{2}',
  2919. y: options.strict ? '-?(0|[1-9][0-9]{0,3})' : '-?0*[0-9]{1,4}'
  2920. };
  2921. var setFnMap = {
  2922. sss: proto.setMilliseconds,
  2923. ss: proto.setSeconds,
  2924. s: proto.setSeconds,
  2925. mm: proto.setMinutes,
  2926. m: proto.setMinutes,
  2927. HH: proto.setHours,
  2928. H: proto.setHours,
  2929. hh: proto.setHours,
  2930. h: proto.setHours,
  2931. EEEE: noop,
  2932. EEE: noop,
  2933. dd: proto.setDate,
  2934. d: proto.setDate,
  2935. a: function(value) {
  2936. var hours = this.getHours() % 12;
  2937. return this.setHours(value.match(/pm/i) ? hours + 12 : hours);
  2938. },
  2939. MMMM: function(value) {
  2940. return this.setMonth(indexOfCaseInsensitive($locale.DATETIME_FORMATS.MONTH, value));
  2941. },
  2942. MMM: function(value) {
  2943. return this.setMonth(indexOfCaseInsensitive($locale.DATETIME_FORMATS.SHORTMONTH, value));
  2944. },
  2945. MM: function(value) {
  2946. return this.setMonth(1 * value - 1);
  2947. },
  2948. M: function(value) {
  2949. return this.setMonth(1 * value - 1);
  2950. },
  2951. yyyy: proto.setFullYear,
  2952. yy: function(value) {
  2953. return this.setFullYear(2e3 + 1 * value);
  2954. },
  2955. y: function(value) {
  2956. return 1 * value <= 50 && value.length === 2 ? this.setFullYear(2e3 + 1 * value) : this.setFullYear(1 * value);
  2957. }
  2958. };
  2959. var regex;
  2960. var setMap;
  2961. $dateParser.init = function() {
  2962. $dateParser.$format = $locale.DATETIME_FORMATS[options.format] || options.format;
  2963. regex = regExpForFormat($dateParser.$format);
  2964. setMap = setMapForFormat($dateParser.$format);
  2965. };
  2966. $dateParser.isValid = function(date) {
  2967. if (angular.isDate(date)) return !isNaN(date.getTime());
  2968. return regex.test(date);
  2969. };
  2970. $dateParser.parse = function(value, baseDate, format, timezone) {
  2971. if (format) format = $locale.DATETIME_FORMATS[format] || format;
  2972. if (angular.isDate(value)) value = dateFilter(value, format || $dateParser.$format, timezone);
  2973. var formatRegex = format ? regExpForFormat(format) : regex;
  2974. var formatSetMap = format ? setMapForFormat(format) : setMap;
  2975. var matches = formatRegex.exec(value);
  2976. if (!matches) return false;
  2977. var date = baseDate && !isNaN(baseDate.getTime()) ? new ParseDate().fromDate(baseDate) : new ParseDate().fromDate(new Date(1970, 0, 1, 0));
  2978. for (var i = 0; i < matches.length - 1; i++) {
  2979. if (formatSetMap[i]) formatSetMap[i].call(date, matches[i + 1]);
  2980. }
  2981. var newDate = date.toDate();
  2982. if (parseInt(date.day, 10) !== newDate.getDate()) {
  2983. return false;
  2984. }
  2985. return newDate;
  2986. };
  2987. $dateParser.getDateForAttribute = function(key, value) {
  2988. var date;
  2989. if (value === 'today') {
  2990. var today = new Date();
  2991. date = new Date(today.getFullYear(), today.getMonth(), today.getDate() + (key === 'maxDate' ? 1 : 0), 0, 0, 0, key === 'minDate' ? 0 : -1);
  2992. } else if (angular.isString(value) && value.match(/^".+"$/)) {
  2993. date = new Date(value.substr(1, value.length - 2));
  2994. } else if (isNumeric(value)) {
  2995. date = new Date(parseInt(value, 10));
  2996. } else if (angular.isString(value) && value.length === 0) {
  2997. date = key === 'minDate' ? -Infinity : +Infinity;
  2998. } else {
  2999. date = new Date(value);
  3000. }
  3001. return date;
  3002. };
  3003. $dateParser.getTimeForAttribute = function(key, value) {
  3004. var time;
  3005. if (value === 'now') {
  3006. time = new Date().setFullYear(1970, 0, 1);
  3007. } else if (angular.isString(value) && value.match(/^".+"$/)) {
  3008. time = new Date(value.substr(1, value.length - 2)).setFullYear(1970, 0, 1);
  3009. } else if (isNumeric(value)) {
  3010. time = new Date(parseInt(value, 10)).setFullYear(1970, 0, 1);
  3011. } else if (angular.isString(value) && value.length === 0) {
  3012. time = key === 'minTime' ? -Infinity : +Infinity;
  3013. } else {
  3014. time = $dateParser.parse(value, new Date(1970, 0, 1, 0));
  3015. }
  3016. return time;
  3017. };
  3018. $dateParser.daylightSavingAdjust = function(date) {
  3019. if (!date) {
  3020. return null;
  3021. }
  3022. date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
  3023. return date;
  3024. };
  3025. $dateParser.timezoneOffsetAdjust = function(date, timezone, undo) {
  3026. if (!date) {
  3027. return null;
  3028. }
  3029. if (timezone && timezone === 'UTC') {
  3030. date = new Date(date.getTime());
  3031. date.setMinutes(date.getMinutes() + (undo ? -1 : 1) * date.getTimezoneOffset());
  3032. }
  3033. return date;
  3034. };
  3035. function regExpForFormat(format) {
  3036. var re = buildDateAbstractRegex(format);
  3037. return buildDateParseRegex(re);
  3038. }
  3039. function buildDateAbstractRegex(format) {
  3040. var escapedFormat = escapeReservedSymbols(format);
  3041. var escapedLiteralFormat = escapedFormat.replace(/''/g, '\\\'');
  3042. var literalRegex = /('(?:\\'|.)*?')/;
  3043. var formatParts = escapedLiteralFormat.split(literalRegex);
  3044. var dateElements = Object.keys(regExpMap);
  3045. var dateRegexParts = [];
  3046. angular.forEach(formatParts, function(part) {
  3047. if (isFormatStringLiteral(part)) {
  3048. part = trimLiteralEscapeChars(part);
  3049. } else {
  3050. for (var i = 0; i < dateElements.length; i++) {
  3051. part = part.split(dateElements[i]).join('${' + i + '}');
  3052. }
  3053. }
  3054. dateRegexParts.push(part);
  3055. });
  3056. return dateRegexParts.join('');
  3057. }
  3058. function escapeReservedSymbols(text) {
  3059. return text.replace(/\\/g, '[\\\\]').replace(/-/g, '[-]').replace(/\./g, '[.]').replace(/\*/g, '[*]').replace(/\+/g, '[+]').replace(/\?/g, '[?]').replace(/\$/g, '[$]').replace(/\^/g, '[^]').replace(/\//g, '[/]').replace(/\\s/g, '[\\s]');
  3060. }
  3061. function isFormatStringLiteral(text) {
  3062. return /^'.*'$/.test(text);
  3063. }
  3064. function trimLiteralEscapeChars(text) {
  3065. return text.replace(/^'(.*)'$/, '$1');
  3066. }
  3067. function buildDateParseRegex(abstractRegex) {
  3068. var dateElements = Object.keys(regExpMap);
  3069. var re = abstractRegex;
  3070. for (var i = 0; i < dateElements.length; i++) {
  3071. re = re.split('${' + i + '}').join('(' + regExpMap[dateElements[i]] + ')');
  3072. }
  3073. return new RegExp('^' + re + '$', [ 'i' ]);
  3074. }
  3075. function setMapForFormat(format) {
  3076. var re = buildDateAbstractRegex(format);
  3077. return buildDateParseValuesMap(re);
  3078. }
  3079. function buildDateParseValuesMap(abstractRegex) {
  3080. var dateElements = Object.keys(regExpMap);
  3081. var valuesRegex = new RegExp('\\${(\\d+)}', 'g');
  3082. var valuesMatch;
  3083. var keyIndex;
  3084. var valueKey;
  3085. var valueFunction;
  3086. var valuesFunctionMap = [];
  3087. while ((valuesMatch = valuesRegex.exec(abstractRegex)) !== null) {
  3088. keyIndex = valuesMatch[1];
  3089. valueKey = dateElements[keyIndex];
  3090. valueFunction = setFnMap[valueKey];
  3091. valuesFunctionMap.push(valueFunction);
  3092. }
  3093. return valuesFunctionMap;
  3094. }
  3095. $dateParser.init();
  3096. return $dateParser;
  3097. };
  3098. return DateParserFactory;
  3099. } ];
  3100. } ]);
  3101. angular.module('mgcrea.ngStrap.helpers.dateFormatter', []).service('$bsDateFormatter', ["$locale", "dateFilter", function($locale, dateFilter) {
  3102. this.getDefaultLocale = function() {
  3103. return $locale.id;
  3104. };
  3105. this.getDatetimeFormat = function(format, lang) {
  3106. return $locale.DATETIME_FORMATS[format] || format;
  3107. };
  3108. this.weekdaysShort = function(lang) {
  3109. return $locale.DATETIME_FORMATS.SHORTDAY;
  3110. };
  3111. function splitTimeFormat(format) {
  3112. return /(h+)([:\.])?(m+)([:\.])?(s*)[ ]?(a?)/i.exec(format).slice(1);
  3113. }
  3114. this.hoursFormat = function(timeFormat) {
  3115. return splitTimeFormat(timeFormat)[0];
  3116. };
  3117. this.minutesFormat = function(timeFormat) {
  3118. return splitTimeFormat(timeFormat)[2];
  3119. };
  3120. this.secondsFormat = function(timeFormat) {
  3121. return splitTimeFormat(timeFormat)[4];
  3122. };
  3123. this.timeSeparator = function(timeFormat) {
  3124. return splitTimeFormat(timeFormat)[1];
  3125. };
  3126. this.showSeconds = function(timeFormat) {
  3127. return !!splitTimeFormat(timeFormat)[4];
  3128. };
  3129. this.showAM = function(timeFormat) {
  3130. return !!splitTimeFormat(timeFormat)[5];
  3131. };
  3132. this.formatDate = function(date, format, lang, timezone) {
  3133. return dateFilter(date, format, timezone);
  3134. };
  3135. } ]);
  3136. angular.module('mgcrea.ngStrap.core', []).service('$bsCompiler', bsCompilerService);
  3137. function bsCompilerService($q, $http, $injector, $compile, $controller, $templateCache) {
  3138. this.compile = function(options) {
  3139. if (options.template && /\.html$/.test(options.template)) {
  3140. console.warn('Deprecated use of `template` option to pass a file. Please use the `templateUrl` option instead.');
  3141. options.templateUrl = options.template;
  3142. options.template = '';
  3143. }
  3144. var templateUrl = options.templateUrl;
  3145. var template = options.template || '';
  3146. var controller = options.controller;
  3147. var controllerAs = options.controllerAs;
  3148. var resolve = angular.copy(options.resolve || {});
  3149. var locals = angular.copy(options.locals || {});
  3150. var transformTemplate = options.transformTemplate || angular.identity;
  3151. var bindToController = options.bindToController;
  3152. angular.forEach(resolve, function(value, key) {
  3153. if (angular.isString(value)) {
  3154. resolve[key] = $injector.get(value);
  3155. } else {
  3156. resolve[key] = $injector.invoke(value);
  3157. }
  3158. });
  3159. angular.extend(resolve, locals);
  3160. if (template) {
  3161. resolve.$template = $q.when(template);
  3162. } else if (templateUrl) {
  3163. resolve.$template = fetchTemplate(templateUrl);
  3164. } else {
  3165. throw new Error('Missing `template` / `templateUrl` option.');
  3166. }
  3167. if (options.titleTemplate) {
  3168. resolve.$template = $q.all([ resolve.$template, fetchTemplate(options.titleTemplate) ]).then(function(templates) {
  3169. var templateEl = angular.element(templates[0]);
  3170. findElement('[ng-bind="title"]', templateEl[0]).removeAttr('ng-bind').html(templates[1]);
  3171. return templateEl[0].outerHTML;
  3172. });
  3173. }
  3174. if (options.contentTemplate) {
  3175. resolve.$template = $q.all([ resolve.$template, fetchTemplate(options.contentTemplate) ]).then(function(templates) {
  3176. var templateEl = angular.element(templates[0]);
  3177. var contentEl = findElement('[ng-bind="content"]', templateEl[0]).removeAttr('ng-bind').html(templates[1]);
  3178. if (!options.templateUrl) contentEl.next().remove();
  3179. return templateEl[0].outerHTML;
  3180. });
  3181. }
  3182. return $q.all(resolve).then(function(locals) {
  3183. var template = transformTemplate(locals.$template);
  3184. if (options.html) {
  3185. template = template.replace(/ng-bind="/gi, 'ng-bind-html="');
  3186. }
  3187. var element = angular.element('<div>').html(template.trim()).contents();
  3188. var linkFn = $compile(element);
  3189. return {
  3190. locals: locals,
  3191. element: element,
  3192. link: function link(scope) {
  3193. locals.$scope = scope;
  3194. if (controller) {
  3195. var invokeCtrl = $controller(controller, locals, true);
  3196. if (bindToController) {
  3197. angular.extend(invokeCtrl.instance, locals);
  3198. }
  3199. var ctrl = angular.isObject(invokeCtrl) ? invokeCtrl : invokeCtrl();
  3200. element.data('$ngControllerController', ctrl);
  3201. element.children().data('$ngControllerController', ctrl);
  3202. if (controllerAs) {
  3203. scope[controllerAs] = ctrl;
  3204. }
  3205. }
  3206. return linkFn.apply(null, arguments);
  3207. }
  3208. };
  3209. });
  3210. };
  3211. function findElement(query, element) {
  3212. return angular.element((element || document).querySelectorAll(query));
  3213. }
  3214. var fetchPromises = {};
  3215. function fetchTemplate(template) {
  3216. if (fetchPromises[template]) return fetchPromises[template];
  3217. return fetchPromises[template] = $http.get(template, {
  3218. cache: $templateCache
  3219. }).then(function(res) {
  3220. return res.data;
  3221. });
  3222. }
  3223. }
  3224. angular.module('mgcrea.ngStrap.datepicker', [ 'mgcrea.ngStrap.helpers.dateParser', 'mgcrea.ngStrap.helpers.dateFormatter', 'mgcrea.ngStrap.tooltip' ]).provider('$bsDatepicker', function() {
  3225. var defaults = this.defaults = {
  3226. animation: 'am-fade',
  3227. prefixClass: 'datepicker',
  3228. placement: 'bottom-left',
  3229. templateUrl: 'datepicker/datepicker.tpl.html',
  3230. trigger: 'focus',
  3231. container: false,
  3232. keyboard: true,
  3233. html: false,
  3234. delay: 0,
  3235. useNative: false,
  3236. dateType: 'date',
  3237. dateFormat: 'shortDate',
  3238. timezone: null,
  3239. modelDateFormat: null,
  3240. dayFormat: 'dd',
  3241. monthFormat: 'MMM',
  3242. yearFormat: 'yyyy',
  3243. monthTitleFormat: 'MMMM yyyy',
  3244. yearTitleFormat: 'yyyy',
  3245. strictFormat: false,
  3246. autoclose: false,
  3247. minDate: -Infinity,
  3248. maxDate: +Infinity,
  3249. startView: 0,
  3250. minView: 0,
  3251. startWeek: 0,
  3252. daysOfWeekDisabled: '',
  3253. hasToday: false,
  3254. hasClear: false,
  3255. iconLeft: 'glyphicon glyphicon-chevron-left',
  3256. iconRight: 'glyphicon glyphicon-chevron-right'
  3257. };
  3258. this.$get = ["$window", "$document", "$rootScope", "$sce", "$bsDateFormatter", "bsDatepickerViews", "$bsTooltip", "$timeout", function($window, $document, $rootScope, $sce, $dateFormatter, datepickerViews, $tooltip, $timeout) {
  3259. var isNative = /(ip[ao]d|iphone|android)/gi.test($window.navigator.userAgent);
  3260. var isTouch = 'createTouch' in $window.document && isNative;
  3261. if (!defaults.lang) defaults.lang = $dateFormatter.getDefaultLocale();
  3262. function DatepickerFactory(element, controller, config) {
  3263. var $datepicker = $tooltip(element, angular.extend({}, defaults, config));
  3264. var parentScope = config.scope;
  3265. var options = $datepicker.$options;
  3266. var scope = $datepicker.$scope;
  3267. if (options.startView) options.startView -= options.minView;
  3268. var pickerViews = datepickerViews($datepicker);
  3269. $datepicker.$views = pickerViews.views;
  3270. var viewDate = pickerViews.viewDate;
  3271. scope.$mode = options.startView;
  3272. scope.$iconLeft = options.iconLeft;
  3273. scope.$iconRight = options.iconRight;
  3274. scope.$hasToday = options.hasToday;
  3275. scope.$hasClear = options.hasClear;
  3276. var $picker = $datepicker.$views[scope.$mode];
  3277. scope.$select = function(date) {
  3278. $datepicker.select(date);
  3279. };
  3280. scope.$selectPane = function(value) {
  3281. $datepicker.$selectPane(value);
  3282. };
  3283. scope.$toggleMode = function() {
  3284. $datepicker.setMode((scope.$mode + 1) % $datepicker.$views.length);
  3285. };
  3286. scope.$setToday = function() {
  3287. if (options.autoclose) {
  3288. $datepicker.setMode(0);
  3289. $datepicker.select(new Date());
  3290. } else {
  3291. $datepicker.select(new Date(), true);
  3292. }
  3293. };
  3294. scope.$clear = function() {
  3295. if (options.autoclose) {
  3296. $datepicker.setMode(0);
  3297. $datepicker.select(null);
  3298. } else {
  3299. $datepicker.select(null, true);
  3300. }
  3301. };
  3302. $datepicker.update = function(date) {
  3303. if (angular.isDate(date) && !isNaN(date.getTime())) {
  3304. $datepicker.$date = date;
  3305. $picker.update.call($picker, date);
  3306. }
  3307. $datepicker.$build(true);
  3308. };
  3309. $datepicker.updateDisabledDates = function(dateRanges) {
  3310. options.disabledDateRanges = dateRanges;
  3311. for (var i = 0, l = scope.rows.length; i < l; i++) {
  3312. angular.forEach(scope.rows[i], $datepicker.$setDisabledEl);
  3313. }
  3314. };
  3315. $datepicker.select = function(date, keep) {
  3316. if (angular.isDate(date)) {
  3317. if (!angular.isDate(controller.$dateValue) || isNaN(controller.$dateValue.getTime())) {
  3318. controller.$dateValue = new Date(date);
  3319. }
  3320. } else {
  3321. controller.$dateValue = null;
  3322. }
  3323. if (!scope.$mode || keep) {
  3324. controller.$setViewValue(angular.copy(date));
  3325. controller.$render();
  3326. if (options.autoclose && !keep) {
  3327. $timeout(function() {
  3328. $datepicker.hide(true);
  3329. });
  3330. }
  3331. } else {
  3332. angular.extend(viewDate, {
  3333. year: date.getFullYear(),
  3334. month: date.getMonth(),
  3335. date: date.getDate()
  3336. });
  3337. $datepicker.setMode(scope.$mode - 1);
  3338. $datepicker.$build();
  3339. }
  3340. };
  3341. $datepicker.setMode = function(mode) {
  3342. scope.$mode = mode;
  3343. $picker = $datepicker.$views[scope.$mode];
  3344. $datepicker.$build();
  3345. };
  3346. $datepicker.$build = function(pristine) {
  3347. if (pristine === true && $picker.built) return;
  3348. if (pristine === false && !$picker.built) return;
  3349. $picker.build.call($picker);
  3350. };
  3351. $datepicker.$updateSelected = function() {
  3352. for (var i = 0, l = scope.rows.length; i < l; i++) {
  3353. angular.forEach(scope.rows[i], updateSelected);
  3354. }
  3355. };
  3356. $datepicker.$isSelected = function(date) {
  3357. return $picker.isSelected(date);
  3358. };
  3359. $datepicker.$setDisabledEl = function(el) {
  3360. el.disabled = $picker.isDisabled(el.date);
  3361. };
  3362. $datepicker.$selectPane = function(value) {
  3363. var steps = $picker.steps;
  3364. var targetDate = new Date(Date.UTC(viewDate.year + (steps.year || 0) * value, viewDate.month + (steps.month || 0) * value, 1));
  3365. angular.extend(viewDate, {
  3366. year: targetDate.getUTCFullYear(),
  3367. month: targetDate.getUTCMonth(),
  3368. date: targetDate.getUTCDate()
  3369. });
  3370. $datepicker.$build();
  3371. };
  3372. $datepicker.$onMouseDown = function(evt) {
  3373. evt.preventDefault();
  3374. evt.stopPropagation();
  3375. if (isTouch) {
  3376. var targetEl = angular.element(evt.target);
  3377. if (targetEl[0].nodeName.toLowerCase() !== 'button') {
  3378. targetEl = targetEl.parent();
  3379. }
  3380. targetEl.triggerHandler('click');
  3381. }
  3382. };
  3383. $datepicker.$onKeyDown = function(evt) {
  3384. if (!/(38|37|39|40|13)/.test(evt.keyCode) || evt.shiftKey || evt.altKey) return;
  3385. evt.preventDefault();
  3386. evt.stopPropagation();
  3387. if (evt.keyCode === 13) {
  3388. if (!scope.$mode) {
  3389. $datepicker.hide(true);
  3390. } else {
  3391. scope.$apply(function() {
  3392. $datepicker.setMode(scope.$mode - 1);
  3393. });
  3394. }
  3395. return;
  3396. }
  3397. $picker.onKeyDown(evt);
  3398. parentScope.$digest();
  3399. };
  3400. function updateSelected(el) {
  3401. el.selected = $datepicker.$isSelected(el.date);
  3402. }
  3403. function focusElement() {
  3404. element[0].focus();
  3405. }
  3406. var _init = $datepicker.init;
  3407. $datepicker.init = function() {
  3408. if (isNative && options.useNative) {
  3409. element.prop('type', 'date');
  3410. element.css('-webkit-appearance', 'textfield');
  3411. return;
  3412. } else if (isTouch) {
  3413. element.prop('type', 'text');
  3414. element.attr('readonly', 'true');
  3415. element.on('click', focusElement);
  3416. }
  3417. _init();
  3418. };
  3419. var _destroy = $datepicker.destroy;
  3420. $datepicker.destroy = function() {
  3421. if (isNative && options.useNative) {
  3422. element.off('click', focusElement);
  3423. }
  3424. _destroy();
  3425. };
  3426. var _show = $datepicker.show;
  3427. $datepicker.show = function() {
  3428. if (!isTouch && element.attr('readonly') || element.attr('disabled')) return;
  3429. _show();
  3430. $timeout(function() {
  3431. if (!$datepicker.$isShown) return;
  3432. $datepicker.$element.on(isTouch ? 'touchstart' : 'mousedown', $datepicker.$onMouseDown);
  3433. if (options.keyboard) {
  3434. element.on('keydown', $datepicker.$onKeyDown);
  3435. }
  3436. }, 0, false);
  3437. };
  3438. var _hide = $datepicker.hide;
  3439. $datepicker.hide = function(blur) {
  3440. if (!$datepicker.$isShown) return;
  3441. $datepicker.$element.off(isTouch ? 'touchstart' : 'mousedown', $datepicker.$onMouseDown);
  3442. if (options.keyboard) {
  3443. element.off('keydown', $datepicker.$onKeyDown);
  3444. }
  3445. _hide(blur);
  3446. };
  3447. return $datepicker;
  3448. }
  3449. DatepickerFactory.defaults = defaults;
  3450. return DatepickerFactory;
  3451. } ];
  3452. }).directive('bsDatepicker', ["$window", "$parse", "$q", "$bsDateFormatter", "$bsDateParser", "$bsDatepicker", function($window, $parse, $q, $dateFormatter, $dateParser, $datepicker) {
  3453. var isNative = /(ip[ao]d|iphone|android)/gi.test($window.navigator.userAgent);
  3454. return {
  3455. restrict: 'EAC',
  3456. require: 'ngModel',
  3457. link: function postLink(scope, element, attr, controller) {
  3458. var options = {
  3459. scope: scope
  3460. };
  3461. angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'placement', 'container', 'delay', 'trigger', 'html', 'animation', 'autoclose', 'dateType', 'dateFormat', 'timezone', 'modelDateFormat', 'dayFormat', 'strictFormat', 'startWeek', 'startDate', 'useNative', 'lang', 'startView', 'minView', 'iconLeft', 'iconRight', 'daysOfWeekDisabled', 'id', 'prefixClass', 'prefixEvent', 'hasToday', 'hasClear' ], function(key) {
  3462. if (angular.isDefined(attr[key])) options[key] = attr[key];
  3463. });
  3464. var falseValueRegExp = /^(false|0|)$/i;
  3465. angular.forEach([ 'html', 'container', 'autoclose', 'useNative', 'hasToday', 'hasClear' ], function(key) {
  3466. if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) {
  3467. options[key] = false;
  3468. }
  3469. });
  3470. angular.forEach([ 'onBeforeShow', 'onShow', 'onBeforeHide', 'onHide' ], function(key) {
  3471. var bsKey = 'bs' + key.charAt(0).toUpperCase() + key.slice(1);
  3472. if (angular.isDefined(attr[bsKey])) {
  3473. options[key] = scope.$eval(attr[bsKey]);
  3474. }
  3475. });
  3476. var datepicker = $datepicker(element, controller, options);
  3477. options = datepicker.$options;
  3478. if (isNative && options.useNative) options.dateFormat = 'yyyy-MM-dd';
  3479. var lang = options.lang;
  3480. var formatDate = function(date, format) {
  3481. return $dateFormatter.formatDate(date, format, lang);
  3482. };
  3483. var dateParser = $dateParser({
  3484. format: options.dateFormat,
  3485. lang: lang,
  3486. strict: options.strictFormat
  3487. });
  3488. if (attr.bsShow) {
  3489. scope.$watch(attr.bsShow, function(newValue, oldValue) {
  3490. if (!datepicker || !angular.isDefined(newValue)) return;
  3491. if (angular.isString(newValue)) newValue = !!newValue.match(/true|,?(datepicker),?/i);
  3492. if (newValue === true) {
  3493. datepicker.show();
  3494. } else {
  3495. datepicker.hide();
  3496. }
  3497. });
  3498. }
  3499. angular.forEach([ 'minDate', 'maxDate' ], function(key) {
  3500. if (angular.isDefined(attr[key])) {
  3501. attr.$observe(key, function(newValue) {
  3502. datepicker.$options[key] = dateParser.getDateForAttribute(key, newValue);
  3503. if (!isNaN(datepicker.$options[key])) datepicker.$build(false);
  3504. validateAgainstMinMaxDate(controller.$dateValue);
  3505. });
  3506. }
  3507. });
  3508. if (angular.isDefined(attr.dateFormat)) {
  3509. attr.$observe('dateFormat', function(newValue) {
  3510. datepicker.$options.dateFormat = newValue;
  3511. });
  3512. }
  3513. scope.$watch(attr.ngModel, function(newValue, oldValue) {
  3514. datepicker.update(controller.$dateValue);
  3515. }, true);
  3516. function normalizeDateRanges(ranges) {
  3517. if (!ranges || !ranges.length) return null;
  3518. return ranges;
  3519. }
  3520. if (angular.isDefined(attr.disabledDates)) {
  3521. scope.$watch(attr.disabledDates, function(disabledRanges, previousValue) {
  3522. disabledRanges = normalizeDateRanges(disabledRanges);
  3523. previousValue = normalizeDateRanges(previousValue);
  3524. if (disabledRanges) {
  3525. datepicker.updateDisabledDates(disabledRanges);
  3526. }
  3527. });
  3528. }
  3529. function validateAgainstMinMaxDate(parsedDate) {
  3530. if (!angular.isDate(parsedDate)) return;
  3531. var isMinValid = isNaN(datepicker.$options.minDate) || parsedDate.getTime() >= datepicker.$options.minDate;
  3532. var isMaxValid = isNaN(datepicker.$options.maxDate) || parsedDate.getTime() <= datepicker.$options.maxDate;
  3533. var isValid = isMinValid && isMaxValid;
  3534. controller.$setValidity('date', isValid);
  3535. controller.$setValidity('min', isMinValid);
  3536. controller.$setValidity('max', isMaxValid);
  3537. if (isValid) controller.$dateValue = parsedDate;
  3538. }
  3539. controller.$parsers.unshift(function(viewValue) {
  3540. var date;
  3541. if (!viewValue) {
  3542. controller.$setValidity('date', true);
  3543. return null;
  3544. }
  3545. var parsedDate = dateParser.parse(viewValue, controller.$dateValue);
  3546. if (!parsedDate || isNaN(parsedDate.getTime())) {
  3547. controller.$setValidity('date', false);
  3548. return;
  3549. }
  3550. validateAgainstMinMaxDate(parsedDate);
  3551. if (options.dateType === 'string') {
  3552. date = dateParser.timezoneOffsetAdjust(parsedDate, options.timezone, true);
  3553. return formatDate(date, options.modelDateFormat || options.dateFormat);
  3554. }
  3555. date = dateParser.timezoneOffsetAdjust(controller.$dateValue, options.timezone, true);
  3556. if (options.dateType === 'number') {
  3557. return date.getTime();
  3558. } else if (options.dateType === 'unix') {
  3559. return date.getTime() / 1e3;
  3560. } else if (options.dateType === 'iso') {
  3561. return date.toISOString();
  3562. }
  3563. return new Date(date);
  3564. });
  3565. controller.$formatters.push(function(modelValue) {
  3566. var date;
  3567. if (angular.isUndefined(modelValue) || modelValue === null) {
  3568. date = NaN;
  3569. } else if (angular.isDate(modelValue)) {
  3570. date = modelValue;
  3571. } else if (options.dateType === 'string') {
  3572. date = dateParser.parse(modelValue, null, options.modelDateFormat);
  3573. } else if (options.dateType === 'unix') {
  3574. date = new Date(modelValue * 1e3);
  3575. } else {
  3576. date = new Date(modelValue);
  3577. }
  3578. controller.$dateValue = dateParser.timezoneOffsetAdjust(date, options.timezone);
  3579. return getDateFormattedString();
  3580. });
  3581. controller.$render = function() {
  3582. element.val(getDateFormattedString());
  3583. };
  3584. function getDateFormattedString() {
  3585. return !controller.$dateValue || isNaN(controller.$dateValue.getTime()) ? '' : formatDate(controller.$dateValue, options.dateFormat);
  3586. }
  3587. scope.$on('$destroy', function() {
  3588. if (datepicker) datepicker.destroy();
  3589. options = null;
  3590. datepicker = null;
  3591. });
  3592. }
  3593. };
  3594. } ]).provider('bsDatepickerViews', function() {
  3595. function split(arr, size) {
  3596. var arrays = [];
  3597. while (arr.length > 0) {
  3598. arrays.push(arr.splice(0, size));
  3599. }
  3600. return arrays;
  3601. }
  3602. function mod(n, m) {
  3603. return (n % m + m) % m;
  3604. }
  3605. this.$get = ["$bsDateFormatter", "$bsDateParser", "$sce", function($dateFormatter, $dateParser, $sce) {
  3606. return function(picker) {
  3607. var scope = picker.$scope;
  3608. var options = picker.$options;
  3609. var lang = options.lang;
  3610. var formatDate = function(date, format) {
  3611. return $dateFormatter.formatDate(date, format, lang);
  3612. };
  3613. var dateParser = $dateParser({
  3614. format: options.dateFormat,
  3615. lang: lang,
  3616. strict: options.strictFormat
  3617. });
  3618. var weekDaysMin = $dateFormatter.weekdaysShort(lang);
  3619. var weekDaysLabels = weekDaysMin.slice(options.startWeek).concat(weekDaysMin.slice(0, options.startWeek));
  3620. var weekDaysLabelsHtml = $sce.trustAsHtml('<th class="dow text-center">' + weekDaysLabels.join('</th><th class="dow text-center">') + '</th>');
  3621. var startDate = picker.$date || (options.startDate ? dateParser.getDateForAttribute('startDate', options.startDate) : new Date());
  3622. var viewDate = {
  3623. year: startDate.getFullYear(),
  3624. month: startDate.getMonth(),
  3625. date: startDate.getDate()
  3626. };
  3627. var views = [ {
  3628. format: options.dayFormat,
  3629. split: 7,
  3630. steps: {
  3631. month: 1
  3632. },
  3633. update: function(date, force) {
  3634. if (!this.built || force || date.getFullYear() !== viewDate.year || date.getMonth() !== viewDate.month) {
  3635. angular.extend(viewDate, {
  3636. year: picker.$date.getFullYear(),
  3637. month: picker.$date.getMonth(),
  3638. date: picker.$date.getDate()
  3639. });
  3640. picker.$build();
  3641. } else if (date.getDate() !== viewDate.date || date.getDate() === 1) {
  3642. viewDate.date = picker.$date.getDate();
  3643. picker.$updateSelected();
  3644. }
  3645. },
  3646. build: function() {
  3647. var firstDayOfMonth = new Date(viewDate.year, viewDate.month, 1);
  3648. var firstDayOfMonthOffset = firstDayOfMonth.getTimezoneOffset();
  3649. var firstDate = new Date(+firstDayOfMonth - mod(firstDayOfMonth.getDay() - options.startWeek, 7) * 864e5);
  3650. var firstDateOffset = firstDate.getTimezoneOffset();
  3651. var today = dateParser.timezoneOffsetAdjust(new Date(), options.timezone).toDateString();
  3652. if (firstDateOffset !== firstDayOfMonthOffset) firstDate = new Date(+firstDate + (firstDateOffset - firstDayOfMonthOffset) * 6e4);
  3653. var days = [];
  3654. var day;
  3655. for (var i = 0; i < 42; i++) {
  3656. day = dateParser.daylightSavingAdjust(new Date(firstDate.getFullYear(), firstDate.getMonth(), firstDate.getDate() + i));
  3657. days.push({
  3658. date: day,
  3659. isToday: day.toDateString() === today,
  3660. label: formatDate(day, this.format),
  3661. selected: picker.$date && this.isSelected(day),
  3662. muted: day.getMonth() !== viewDate.month,
  3663. disabled: this.isDisabled(day)
  3664. });
  3665. }
  3666. scope.title = formatDate(firstDayOfMonth, options.monthTitleFormat);
  3667. scope.showLabels = true;
  3668. scope.labels = weekDaysLabelsHtml;
  3669. scope.rows = split(days, this.split);
  3670. scope.isTodayDisabled = this.isDisabled(new Date());
  3671. this.built = true;
  3672. },
  3673. isSelected: function(date) {
  3674. return picker.$date && date.getFullYear() === picker.$date.getFullYear() && date.getMonth() === picker.$date.getMonth() && date.getDate() === picker.$date.getDate();
  3675. },
  3676. isDisabled: function(date) {
  3677. var time = date.getTime();
  3678. if (time < options.minDate || time > options.maxDate) return true;
  3679. if (options.daysOfWeekDisabled.indexOf(date.getDay()) !== -1) return true;
  3680. if (options.disabledDateRanges) {
  3681. for (var i = 0; i < options.disabledDateRanges.length; i++) {
  3682. if (time >= options.disabledDateRanges[i].start && time <= options.disabledDateRanges[i].end) {
  3683. return true;
  3684. }
  3685. }
  3686. }
  3687. return false;
  3688. },
  3689. onKeyDown: function(evt) {
  3690. if (!picker.$date) {
  3691. return;
  3692. }
  3693. var actualTime = picker.$date.getTime();
  3694. var newDate;
  3695. if (evt.keyCode === 37) newDate = new Date(actualTime - 1 * 864e5); else if (evt.keyCode === 38) newDate = new Date(actualTime - 7 * 864e5); else if (evt.keyCode === 39) newDate = new Date(actualTime + 1 * 864e5); else if (evt.keyCode === 40) newDate = new Date(actualTime + 7 * 864e5);
  3696. if (!this.isDisabled(newDate)) picker.select(newDate, true);
  3697. }
  3698. }, {
  3699. name: 'month',
  3700. format: options.monthFormat,
  3701. split: 4,
  3702. steps: {
  3703. year: 1
  3704. },
  3705. update: function(date, force) {
  3706. if (!this.built || date.getFullYear() !== viewDate.year) {
  3707. angular.extend(viewDate, {
  3708. year: picker.$date.getFullYear(),
  3709. month: picker.$date.getMonth(),
  3710. date: picker.$date.getDate()
  3711. });
  3712. picker.$build();
  3713. } else if (date.getMonth() !== viewDate.month) {
  3714. angular.extend(viewDate, {
  3715. month: picker.$date.getMonth(),
  3716. date: picker.$date.getDate()
  3717. });
  3718. picker.$updateSelected();
  3719. }
  3720. },
  3721. build: function() {
  3722. var months = [];
  3723. var month;
  3724. for (var i = 0; i < 12; i++) {
  3725. month = new Date(viewDate.year, i, 1);
  3726. months.push({
  3727. date: month,
  3728. label: formatDate(month, this.format),
  3729. selected: picker.$isSelected(month),
  3730. disabled: this.isDisabled(month)
  3731. });
  3732. }
  3733. scope.title = formatDate(month, options.yearTitleFormat);
  3734. scope.showLabels = false;
  3735. scope.rows = split(months, this.split);
  3736. this.built = true;
  3737. },
  3738. isSelected: function(date) {
  3739. return picker.$date && date.getFullYear() === picker.$date.getFullYear() && date.getMonth() === picker.$date.getMonth();
  3740. },
  3741. isDisabled: function(date) {
  3742. var lastDate = +new Date(date.getFullYear(), date.getMonth() + 1, 0);
  3743. return lastDate < options.minDate || date.getTime() > options.maxDate;
  3744. },
  3745. onKeyDown: function(evt) {
  3746. if (!picker.$date) {
  3747. return;
  3748. }
  3749. var actualMonth = picker.$date.getMonth();
  3750. var newDate = new Date(picker.$date);
  3751. if (evt.keyCode === 37) newDate.setMonth(actualMonth - 1); else if (evt.keyCode === 38) newDate.setMonth(actualMonth - 4); else if (evt.keyCode === 39) newDate.setMonth(actualMonth + 1); else if (evt.keyCode === 40) newDate.setMonth(actualMonth + 4);
  3752. if (!this.isDisabled(newDate)) picker.select(newDate, true);
  3753. }
  3754. }, {
  3755. name: 'year',
  3756. format: options.yearFormat,
  3757. split: 4,
  3758. steps: {
  3759. year: 12
  3760. },
  3761. update: function(date, force) {
  3762. if (!this.built || force || parseInt(date.getFullYear() / 20, 10) !== parseInt(viewDate.year / 20, 10)) {
  3763. angular.extend(viewDate, {
  3764. year: picker.$date.getFullYear(),
  3765. month: picker.$date.getMonth(),
  3766. date: picker.$date.getDate()
  3767. });
  3768. picker.$build();
  3769. } else if (date.getFullYear() !== viewDate.year) {
  3770. angular.extend(viewDate, {
  3771. year: picker.$date.getFullYear(),
  3772. month: picker.$date.getMonth(),
  3773. date: picker.$date.getDate()
  3774. });
  3775. picker.$updateSelected();
  3776. }
  3777. },
  3778. build: function() {
  3779. var firstYear = viewDate.year - viewDate.year % (this.split * 3);
  3780. var years = [];
  3781. var year;
  3782. for (var i = 0; i < 12; i++) {
  3783. year = new Date(firstYear + i, 0, 1);
  3784. years.push({
  3785. date: year,
  3786. label: formatDate(year, this.format),
  3787. selected: picker.$isSelected(year),
  3788. disabled: this.isDisabled(year)
  3789. });
  3790. }
  3791. scope.title = years[0].label + '-' + years[years.length - 1].label;
  3792. scope.showLabels = false;
  3793. scope.rows = split(years, this.split);
  3794. this.built = true;
  3795. },
  3796. isSelected: function(date) {
  3797. return picker.$date && date.getFullYear() === picker.$date.getFullYear();
  3798. },
  3799. isDisabled: function(date) {
  3800. var lastDate = +new Date(date.getFullYear() + 1, 0, 0);
  3801. return lastDate < options.minDate || date.getTime() > options.maxDate;
  3802. },
  3803. onKeyDown: function(evt) {
  3804. if (!picker.$date) {
  3805. return;
  3806. }
  3807. var actualYear = picker.$date.getFullYear();
  3808. var newDate = new Date(picker.$date);
  3809. if (evt.keyCode === 37) newDate.setYear(actualYear - 1); else if (evt.keyCode === 38) newDate.setYear(actualYear - 4); else if (evt.keyCode === 39) newDate.setYear(actualYear + 1); else if (evt.keyCode === 40) newDate.setYear(actualYear + 4);
  3810. if (!this.isDisabled(newDate)) picker.select(newDate, true);
  3811. }
  3812. } ];
  3813. return {
  3814. views: options.minView ? Array.prototype.slice.call(views, options.minView) : views,
  3815. viewDate: viewDate
  3816. };
  3817. };
  3818. } ];
  3819. });
  3820. angular.module('mgcrea.ngStrap.button', []).provider('$bsButton', function() {
  3821. var defaults = this.defaults = {
  3822. activeClass: 'active',
  3823. toggleEvent: 'click'
  3824. };
  3825. this.$get = function() {
  3826. return {
  3827. defaults: defaults
  3828. };
  3829. };
  3830. }).directive('bsCheckboxGroup', function() {
  3831. return {
  3832. restrict: 'A',
  3833. require: 'ngModel',
  3834. compile: function postLink(element, attr) {
  3835. element.attr('data-toggle', 'buttons');
  3836. element.removeAttr('ng-model');
  3837. var children = element[0].querySelectorAll('input[type="checkbox"]');
  3838. angular.forEach(children, function(child) {
  3839. var childEl = angular.element(child);
  3840. childEl.attr('bs-checkbox', '');
  3841. childEl.attr('ng-model', attr.ngModel + '.' + childEl.attr('value'));
  3842. });
  3843. }
  3844. };
  3845. }).directive('bsCheckbox', ["$bsButton", "$$rAF", function($button, $$rAF) {
  3846. var defaults = $button.defaults;
  3847. var constantValueRegExp = /^(true|false|\d+)$/;
  3848. return {
  3849. restrict: 'A',
  3850. require: 'ngModel',
  3851. link: function postLink(scope, element, attr, controller) {
  3852. var options = defaults;
  3853. var isInput = element[0].nodeName === 'INPUT';
  3854. var activeElement = isInput ? element.parent() : element;
  3855. var trueValue = angular.isDefined(attr.trueValue) ? attr.trueValue : true;
  3856. if (constantValueRegExp.test(attr.trueValue)) {
  3857. trueValue = scope.$eval(attr.trueValue);
  3858. }
  3859. var falseValue = angular.isDefined(attr.falseValue) ? attr.falseValue : false;
  3860. if (constantValueRegExp.test(attr.falseValue)) {
  3861. falseValue = scope.$eval(attr.falseValue);
  3862. }
  3863. var hasExoticValues = typeof trueValue !== 'boolean' || typeof falseValue !== 'boolean';
  3864. if (hasExoticValues) {
  3865. controller.$parsers.push(function(viewValue) {
  3866. return viewValue ? trueValue : falseValue;
  3867. });
  3868. controller.$formatters.push(function(modelValue) {
  3869. return angular.equals(modelValue, trueValue);
  3870. });
  3871. scope.$watch(attr.ngModel, function(newValue, oldValue) {
  3872. controller.$render();
  3873. });
  3874. }
  3875. controller.$render = function() {
  3876. var isActive = angular.equals(controller.$modelValue, trueValue);
  3877. $$rAF(function() {
  3878. if (isInput) element[0].checked = isActive;
  3879. activeElement.toggleClass(options.activeClass, isActive);
  3880. });
  3881. };
  3882. element.bind(options.toggleEvent, function() {
  3883. scope.$apply(function() {
  3884. if (!isInput) {
  3885. controller.$setViewValue(!activeElement.hasClass('active'));
  3886. }
  3887. if (!hasExoticValues) {
  3888. controller.$render();
  3889. }
  3890. });
  3891. });
  3892. }
  3893. };
  3894. } ]).directive('bsRadioGroup', function() {
  3895. return {
  3896. restrict: 'A',
  3897. require: 'ngModel',
  3898. compile: function postLink(element, attr) {
  3899. element.attr('data-toggle', 'buttons');
  3900. element.removeAttr('ng-model');
  3901. var children = element[0].querySelectorAll('input[type="radio"]');
  3902. angular.forEach(children, function(child) {
  3903. angular.element(child).attr('bs-radio', '');
  3904. angular.element(child).attr('ng-model', attr.ngModel);
  3905. });
  3906. }
  3907. };
  3908. }).directive('bsRadio', ["$bsButton", "$$rAF", function($button, $$rAF) {
  3909. var defaults = $button.defaults;
  3910. var constantValueRegExp = /^(true|false|\d+)$/;
  3911. return {
  3912. restrict: 'A',
  3913. require: 'ngModel',
  3914. link: function postLink(scope, element, attr, controller) {
  3915. var options = defaults;
  3916. var isInput = element[0].nodeName === 'INPUT';
  3917. var activeElement = isInput ? element.parent() : element;
  3918. var value;
  3919. attr.$observe('value', function(v) {
  3920. if (typeof v !== 'boolean' && constantValueRegExp.test(v)) {
  3921. value = scope.$eval(v);
  3922. } else {
  3923. value = v;
  3924. }
  3925. controller.$render();
  3926. });
  3927. controller.$render = function() {
  3928. var isActive = angular.equals(controller.$modelValue, value);
  3929. $$rAF(function() {
  3930. if (isInput) element[0].checked = isActive;
  3931. activeElement.toggleClass(options.activeClass, isActive);
  3932. });
  3933. };
  3934. element.bind(options.toggleEvent, function() {
  3935. scope.$apply(function() {
  3936. controller.$setViewValue(value);
  3937. controller.$render();
  3938. });
  3939. });
  3940. }
  3941. };
  3942. } ]);
  3943. angular.module('mgcrea.ngStrap.collapse', []).provider('$bsCollapse', function() {
  3944. var defaults = this.defaults = {
  3945. animation: 'am-collapse',
  3946. disallowToggle: false,
  3947. activeClass: 'in',
  3948. startCollapsed: false,
  3949. allowMultiple: false
  3950. };
  3951. var controller = this.controller = function($scope, $element, $attrs) {
  3952. var self = this;
  3953. self.$options = angular.copy(defaults);
  3954. angular.forEach([ 'animation', 'disallowToggle', 'activeClass', 'startCollapsed', 'allowMultiple' ], function(key) {
  3955. if (angular.isDefined($attrs[key])) self.$options[key] = $attrs[key];
  3956. });
  3957. var falseValueRegExp = /^(false|0|)$/i;
  3958. angular.forEach([ 'disallowToggle', 'startCollapsed', 'allowMultiple' ], function(key) {
  3959. if (angular.isDefined($attrs[key]) && falseValueRegExp.test($attrs[key])) {
  3960. self.$options[key] = false;
  3961. }
  3962. });
  3963. self.$toggles = [];
  3964. self.$targets = [];
  3965. self.$viewChangeListeners = [];
  3966. self.$registerToggle = function(element) {
  3967. self.$toggles.push(element);
  3968. };
  3969. self.$registerTarget = function(element) {
  3970. self.$targets.push(element);
  3971. };
  3972. self.$unregisterToggle = function(element) {
  3973. var index = self.$toggles.indexOf(element);
  3974. self.$toggles.splice(index, 1);
  3975. };
  3976. self.$unregisterTarget = function(element) {
  3977. var index = self.$targets.indexOf(element);
  3978. self.$targets.splice(index, 1);
  3979. if (self.$options.allowMultiple) {
  3980. deactivateItem(element);
  3981. }
  3982. fixActiveItemIndexes(index);
  3983. self.$viewChangeListeners.forEach(function(fn) {
  3984. fn();
  3985. });
  3986. };
  3987. self.$targets.$active = !self.$options.startCollapsed ? [ 0 ] : [];
  3988. self.$setActive = $scope.$setActive = function(value) {
  3989. if (angular.isArray(value)) {
  3990. self.$targets.$active = value;
  3991. } else if (!self.$options.disallowToggle && isActive(value)) {
  3992. deactivateItem(value);
  3993. } else {
  3994. activateItem(value);
  3995. }
  3996. self.$viewChangeListeners.forEach(function(fn) {
  3997. fn();
  3998. });
  3999. };
  4000. self.$activeIndexes = function() {
  4001. if (self.$options.allowMultiple) {
  4002. return self.$targets.$active;
  4003. }
  4004. return self.$targets.$active.length === 1 ? self.$targets.$active[0] : -1;
  4005. };
  4006. function fixActiveItemIndexes(index) {
  4007. var activeIndexes = self.$targets.$active;
  4008. for (var i = 0; i < activeIndexes.length; i++) {
  4009. if (index < activeIndexes[i]) {
  4010. activeIndexes[i] = activeIndexes[i] - 1;
  4011. }
  4012. if (activeIndexes[i] === self.$targets.length) {
  4013. activeIndexes[i] = self.$targets.length - 1;
  4014. }
  4015. }
  4016. }
  4017. function isActive(value) {
  4018. var activeItems = self.$targets.$active;
  4019. return activeItems.indexOf(value) !== -1;
  4020. }
  4021. function deactivateItem(value) {
  4022. var index = self.$targets.$active.indexOf(value);
  4023. if (index !== -1) {
  4024. self.$targets.$active.splice(index, 1);
  4025. }
  4026. }
  4027. function activateItem(value) {
  4028. if (!self.$options.allowMultiple) {
  4029. self.$targets.$active.splice(0, 1);
  4030. }
  4031. if (self.$targets.$active.indexOf(value) === -1) {
  4032. self.$targets.$active.push(value);
  4033. }
  4034. }
  4035. };
  4036. this.$get = function() {
  4037. var $collapse = {};
  4038. $collapse.defaults = defaults;
  4039. $collapse.controller = controller;
  4040. return $collapse;
  4041. };
  4042. }).directive('bsCollapse', ["$window", "$animate", "$bsCollapse", function($window, $animate, $collapse) {
  4043. return {
  4044. require: [ '?ngModel', 'bsCollapse' ],
  4045. controller: [ '$scope', '$element', '$attrs', $collapse.controller ],
  4046. link: function postLink(scope, element, attrs, controllers) {
  4047. var ngModelCtrl = controllers[0];
  4048. var bsCollapseCtrl = controllers[1];
  4049. if (ngModelCtrl) {
  4050. bsCollapseCtrl.$viewChangeListeners.push(function() {
  4051. ngModelCtrl.$setViewValue(bsCollapseCtrl.$activeIndexes());
  4052. });
  4053. ngModelCtrl.$formatters.push(function(modelValue) {
  4054. if (angular.isArray(modelValue)) {
  4055. bsCollapseCtrl.$setActive(modelValue);
  4056. } else {
  4057. var activeIndexes = bsCollapseCtrl.$activeIndexes();
  4058. if (angular.isArray(activeIndexes)) {
  4059. if (activeIndexes.indexOf(modelValue * 1) === -1) {
  4060. bsCollapseCtrl.$setActive(modelValue * 1);
  4061. }
  4062. } else if (activeIndexes !== modelValue * 1) {
  4063. bsCollapseCtrl.$setActive(modelValue * 1);
  4064. }
  4065. }
  4066. return modelValue;
  4067. });
  4068. }
  4069. }
  4070. };
  4071. } ]).directive('bsCollapseToggle', function() {
  4072. return {
  4073. require: [ '^?ngModel', '^bsCollapse' ],
  4074. link: function postLink(scope, element, attrs, controllers) {
  4075. var bsCollapseCtrl = controllers[1];
  4076. element.attr('data-toggle', 'collapse');
  4077. bsCollapseCtrl.$registerToggle(element);
  4078. scope.$on('$destroy', function() {
  4079. bsCollapseCtrl.$unregisterToggle(element);
  4080. });
  4081. element.on('click', function() {
  4082. if (!attrs.disabled) {
  4083. var index = attrs.bsCollapseToggle && attrs.bsCollapseToggle !== 'bs-collapse-toggle' ? attrs.bsCollapseToggle : bsCollapseCtrl.$toggles.indexOf(element);
  4084. bsCollapseCtrl.$setActive(index * 1);
  4085. scope.$apply();
  4086. }
  4087. });
  4088. }
  4089. };
  4090. }).directive('bsCollapseTarget', ["$animate", function($animate) {
  4091. return {
  4092. require: [ '^?ngModel', '^bsCollapse' ],
  4093. link: function postLink(scope, element, attrs, controllers) {
  4094. var bsCollapseCtrl = controllers[1];
  4095. element.addClass('collapse');
  4096. if (bsCollapseCtrl.$options.animation) {
  4097. element.addClass(bsCollapseCtrl.$options.animation);
  4098. }
  4099. bsCollapseCtrl.$registerTarget(element);
  4100. scope.$on('$destroy', function() {
  4101. bsCollapseCtrl.$unregisterTarget(element);
  4102. });
  4103. function render() {
  4104. var index = bsCollapseCtrl.$targets.indexOf(element);
  4105. var active = bsCollapseCtrl.$activeIndexes();
  4106. var action = 'removeClass';
  4107. if (angular.isArray(active)) {
  4108. if (active.indexOf(index) !== -1) {
  4109. action = 'addClass';
  4110. }
  4111. } else if (index === active) {
  4112. action = 'addClass';
  4113. }
  4114. $animate[action](element, bsCollapseCtrl.$options.activeClass);
  4115. }
  4116. bsCollapseCtrl.$viewChangeListeners.push(function() {
  4117. render();
  4118. });
  4119. render();
  4120. }
  4121. };
  4122. } ]);
  4123. angular.module('mgcrea.ngStrap.aside', [ 'mgcrea.ngStrap.modal' ]).provider('$bsAside', function() {
  4124. var defaults = this.defaults = {
  4125. animation: 'am-fade-and-slide-right',
  4126. prefixClass: 'aside',
  4127. prefixEvent: 'aside',
  4128. placement: 'right',
  4129. templateUrl: 'aside/aside.tpl.html',
  4130. contentTemplate: false,
  4131. container: false,
  4132. element: null,
  4133. backdrop: true,
  4134. keyboard: true,
  4135. html: false,
  4136. show: true
  4137. };
  4138. this.$get = ["$bsModal", function($modal) {
  4139. function AsideFactory(config) {
  4140. var $aside = {};
  4141. var options = angular.extend({}, defaults, config);
  4142. $aside = $modal(options);
  4143. return $aside;
  4144. }
  4145. return AsideFactory;
  4146. } ];
  4147. }).directive('bsAside', ["$window", "$sce", "$bsAside", function($window, $sce, $aside) {
  4148. return {
  4149. restrict: 'EAC',
  4150. scope: true,
  4151. link: function postLink(scope, element, attr, transclusion) {
  4152. var options = {
  4153. scope: scope,
  4154. element: element,
  4155. show: false
  4156. };
  4157. angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'contentTemplate', 'placement', 'backdrop', 'keyboard', 'html', 'container', 'animation' ], function(key) {
  4158. if (angular.isDefined(attr[key])) options[key] = attr[key];
  4159. });
  4160. var falseValueRegExp = /^(false|0|)$/i;
  4161. angular.forEach([ 'backdrop', 'keyboard', 'html', 'container' ], function(key) {
  4162. if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) options[key] = false;
  4163. });
  4164. angular.forEach([ 'onBeforeShow', 'onShow', 'onBeforeHide', 'onHide' ], function(key) {
  4165. var bsKey = 'bs' + key.charAt(0).toUpperCase() + key.slice(1);
  4166. if (angular.isDefined(attr[bsKey])) {
  4167. options[key] = scope.$eval(attr[bsKey]);
  4168. }
  4169. });
  4170. angular.forEach([ 'title', 'content' ], function(key) {
  4171. if (attr[key]) {
  4172. attr.$observe(key, function(newValue, oldValue) {
  4173. scope[key] = $sce.trustAsHtml(newValue);
  4174. });
  4175. }
  4176. });
  4177. if (attr.bsAside) {
  4178. scope.$watch(attr.bsAside, function(newValue, oldValue) {
  4179. if (angular.isObject(newValue)) {
  4180. angular.extend(scope, newValue);
  4181. } else {
  4182. scope.content = newValue;
  4183. }
  4184. }, true);
  4185. }
  4186. var aside = $aside(options);
  4187. element.on(attr.trigger || 'click', aside.toggle);
  4188. scope.$on('$destroy', function() {
  4189. if (aside) aside.destroy();
  4190. options = null;
  4191. aside = null;
  4192. });
  4193. }
  4194. };
  4195. } ]);
  4196. angular.module('mgcrea.ngStrap.alert', [ 'mgcrea.ngStrap.modal' ]).provider('$bsAlert', function() {
  4197. var defaults = this.defaults = {
  4198. animation: 'am-fade',
  4199. prefixClass: 'alert',
  4200. prefixEvent: 'alert',
  4201. placement: null,
  4202. templateUrl: 'alert/alert.tpl.html',
  4203. container: false,
  4204. element: null,
  4205. backdrop: false,
  4206. keyboard: true,
  4207. show: true,
  4208. duration: false,
  4209. type: false,
  4210. dismissable: true
  4211. };
  4212. this.$get = ["$bsModal", "$timeout", function($modal, $timeout) {
  4213. function AlertFactory(config) {
  4214. var $alert = {};
  4215. var options = angular.extend({}, defaults, config);
  4216. $alert = $modal(options);
  4217. $alert.$scope.dismissable = !!options.dismissable;
  4218. if (options.type) {
  4219. $alert.$scope.type = options.type;
  4220. }
  4221. var show = $alert.show;
  4222. if (options.duration) {
  4223. $alert.show = function() {
  4224. show();
  4225. $timeout(function() {
  4226. $alert.hide();
  4227. }, options.duration * 1e3);
  4228. };
  4229. }
  4230. return $alert;
  4231. }
  4232. return AlertFactory;
  4233. } ];
  4234. }).directive('bsAlert', ["$window", "$sce", "$bsAlert", function($window, $sce, $alert) {
  4235. return {
  4236. restrict: 'EAC',
  4237. scope: true,
  4238. link: function postLink(scope, element, attr, transclusion) {
  4239. var options = {
  4240. scope: scope,
  4241. element: element,
  4242. show: false
  4243. };
  4244. angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'placement', 'keyboard', 'html', 'container', 'animation', 'duration', 'dismissable' ], function(key) {
  4245. if (angular.isDefined(attr[key])) options[key] = attr[key];
  4246. });
  4247. var falseValueRegExp = /^(false|0|)$/i;
  4248. angular.forEach([ 'keyboard', 'html', 'container', 'dismissable' ], function(key) {
  4249. if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) options[key] = false;
  4250. });
  4251. angular.forEach([ 'onBeforeShow', 'onShow', 'onBeforeHide', 'onHide' ], function(key) {
  4252. var bsKey = 'bs' + key.charAt(0).toUpperCase() + key.slice(1);
  4253. if (angular.isDefined(attr[bsKey])) {
  4254. options[key] = scope.$eval(attr[bsKey]);
  4255. }
  4256. });
  4257. if (!scope.hasOwnProperty('title')) {
  4258. scope.title = '';
  4259. }
  4260. angular.forEach([ 'title', 'content', 'type' ], function(key) {
  4261. if (attr[key]) {
  4262. attr.$observe(key, function(newValue, oldValue) {
  4263. scope[key] = $sce.trustAsHtml(newValue);
  4264. });
  4265. }
  4266. });
  4267. if (attr.bsAlert) {
  4268. scope.$watch(attr.bsAlert, function(newValue, oldValue) {
  4269. if (angular.isObject(newValue)) {
  4270. angular.extend(scope, newValue);
  4271. } else {
  4272. scope.content = newValue;
  4273. }
  4274. }, true);
  4275. }
  4276. var alert = $alert(options);
  4277. element.on(attr.trigger || 'click', alert.toggle);
  4278. scope.$on('$destroy', function() {
  4279. if (alert) alert.destroy();
  4280. options = null;
  4281. alert = null;
  4282. });
  4283. }
  4284. };
  4285. } ]);
  4286. angular.module('mgcrea.ngStrap.affix', [ 'mgcrea.ngStrap.helpers.dimensions', 'mgcrea.ngStrap.helpers.debounce' ]).provider('$bsAffix', function() {
  4287. var defaults = this.defaults = {
  4288. offsetTop: 'auto',
  4289. inlineStyles: true
  4290. };
  4291. this.$get = ["$window", "bsDebounce", "bsDimensions", function($window, debounce, dimensions) {
  4292. var bodyEl = angular.element($window.document.body);
  4293. var windowEl = angular.element($window);
  4294. function AffixFactory(element, config) {
  4295. var $affix = {};
  4296. var options = angular.extend({}, defaults, config);
  4297. var targetEl = options.target;
  4298. var reset = 'affix affix-top affix-bottom';
  4299. var setWidth = false;
  4300. var initialAffixTop = 0;
  4301. var initialOffsetTop = 0;
  4302. var offsetTop = 0;
  4303. var offsetBottom = 0;
  4304. var affixed = null;
  4305. var unpin = null;
  4306. var parent = element.parent();
  4307. if (options.offsetParent) {
  4308. if (options.offsetParent.match(/^\d+$/)) {
  4309. for (var i = 0; i < options.offsetParent * 1 - 1; i++) {
  4310. parent = parent.parent();
  4311. }
  4312. } else {
  4313. parent = angular.element(options.offsetParent);
  4314. }
  4315. }
  4316. $affix.init = function() {
  4317. this.$parseOffsets();
  4318. initialOffsetTop = dimensions.offset(element[0]).top + initialAffixTop;
  4319. setWidth = !element[0].style.width;
  4320. targetEl.on('scroll', this.checkPosition);
  4321. targetEl.on('click', this.checkPositionWithEventLoop);
  4322. windowEl.on('resize', this.$debouncedOnResize);
  4323. this.checkPosition();
  4324. this.checkPositionWithEventLoop();
  4325. };
  4326. $affix.destroy = function() {
  4327. targetEl.off('scroll', this.checkPosition);
  4328. targetEl.off('click', this.checkPositionWithEventLoop);
  4329. windowEl.off('resize', this.$debouncedOnResize);
  4330. };
  4331. $affix.checkPositionWithEventLoop = function() {
  4332. setTimeout($affix.checkPosition, 1);
  4333. };
  4334. $affix.checkPosition = function() {
  4335. var scrollTop = getScrollTop();
  4336. var position = dimensions.offset(element[0]);
  4337. var elementHeight = dimensions.height(element[0]);
  4338. var affix = getRequiredAffixClass(unpin, position, elementHeight);
  4339. if (affixed === affix) return;
  4340. affixed = affix;
  4341. if (affix === 'top') {
  4342. unpin = null;
  4343. if (setWidth) {
  4344. element.css('width', '');
  4345. }
  4346. if (options.inlineStyles) {
  4347. element.css('position', options.offsetParent ? '' : 'relative');
  4348. element.css('top', '');
  4349. }
  4350. } else if (affix === 'bottom') {
  4351. if (options.offsetUnpin) {
  4352. unpin = -(options.offsetUnpin * 1);
  4353. } else {
  4354. unpin = position.top - scrollTop;
  4355. }
  4356. if (setWidth) {
  4357. element.css('width', '');
  4358. }
  4359. if (options.inlineStyles) {
  4360. element.css('position', options.offsetParent ? '' : 'relative');
  4361. element.css('top', options.offsetParent ? '' : bodyEl[0].offsetHeight - offsetBottom - elementHeight - initialOffsetTop + 'px');
  4362. }
  4363. } else {
  4364. unpin = null;
  4365. if (setWidth) {
  4366. element.css('width', element[0].offsetWidth + 'px');
  4367. }
  4368. if (options.inlineStyles) {
  4369. element.css('position', 'fixed');
  4370. element.css('top', initialAffixTop + 'px');
  4371. }
  4372. }
  4373. element.removeClass(reset).addClass('affix' + (affix !== 'middle' ? '-' + affix : ''));
  4374. };
  4375. $affix.$onResize = function() {
  4376. $affix.$parseOffsets();
  4377. $affix.checkPosition();
  4378. };
  4379. $affix.$debouncedOnResize = debounce($affix.$onResize, 50);
  4380. $affix.$parseOffsets = function() {
  4381. var initialPosition = element.css('position');
  4382. if (options.inlineStyles) {
  4383. element.css('position', options.offsetParent ? '' : 'relative');
  4384. }
  4385. if (options.offsetTop) {
  4386. if (options.offsetTop === 'auto') {
  4387. options.offsetTop = '+0';
  4388. }
  4389. if (options.offsetTop.match(/^[-+]\d+$/)) {
  4390. initialAffixTop = -options.offsetTop * 1;
  4391. if (options.offsetParent) {
  4392. offsetTop = dimensions.offset(parent[0]).top + options.offsetTop * 1;
  4393. } else {
  4394. offsetTop = dimensions.offset(element[0]).top - dimensions.css(element[0], 'marginTop', true) + options.offsetTop * 1;
  4395. }
  4396. } else {
  4397. offsetTop = options.offsetTop * 1;
  4398. }
  4399. }
  4400. if (options.offsetBottom) {
  4401. if (options.offsetParent && options.offsetBottom.match(/^[-+]\d+$/)) {
  4402. offsetBottom = getScrollHeight() - (dimensions.offset(parent[0]).top + dimensions.height(parent[0])) + options.offsetBottom * 1 + 1;
  4403. } else {
  4404. offsetBottom = options.offsetBottom * 1;
  4405. }
  4406. }
  4407. if (options.inlineStyles) {
  4408. element.css('position', initialPosition);
  4409. }
  4410. };
  4411. function getRequiredAffixClass(_unpin, position, elementHeight) {
  4412. var scrollTop = getScrollTop();
  4413. var scrollHeight = getScrollHeight();
  4414. if (scrollTop <= offsetTop) {
  4415. return 'top';
  4416. } else if (_unpin !== null && scrollTop + _unpin <= position.top) {
  4417. return 'middle';
  4418. } else if (offsetBottom !== null && position.top + elementHeight + initialAffixTop >= scrollHeight - offsetBottom) {
  4419. return 'bottom';
  4420. }
  4421. return 'middle';
  4422. }
  4423. function getScrollTop() {
  4424. return targetEl[0] === $window ? $window.pageYOffset : targetEl[0].scrollTop;
  4425. }
  4426. function getScrollHeight() {
  4427. return targetEl[0] === $window ? $window.document.body.scrollHeight : targetEl[0].scrollHeight;
  4428. }
  4429. $affix.init();
  4430. return $affix;
  4431. }
  4432. return AffixFactory;
  4433. } ];
  4434. }).directive('bsAffix', ["$bsAffix", "$window", function($affix, $window) {
  4435. return {
  4436. restrict: 'EAC',
  4437. require: '^?bsAffixTarget',
  4438. link: function postLink(scope, element, attr, affixTarget) {
  4439. var options = {
  4440. scope: scope,
  4441. target: affixTarget ? affixTarget.$element : angular.element($window)
  4442. };
  4443. angular.forEach([ 'offsetTop', 'offsetBottom', 'offsetParent', 'offsetUnpin', 'inlineStyles' ], function(key) {
  4444. if (angular.isDefined(attr[key])) {
  4445. var option = attr[key];
  4446. if (/true/i.test(option)) option = true;
  4447. if (/false/i.test(option)) option = false;
  4448. options[key] = option;
  4449. }
  4450. });
  4451. var affix = $affix(element, options);
  4452. scope.$on('$destroy', function() {
  4453. if (affix) affix.destroy();
  4454. options = null;
  4455. affix = null;
  4456. });
  4457. }
  4458. };
  4459. } ]).directive('bsAffixTarget', function() {
  4460. return {
  4461. controller: ["$element", function($element) {
  4462. this.$element = $element;
  4463. } ]
  4464. };
  4465. });
  4466. angular.module('mgcrea.ngStrap', [ 'mgcrea.ngStrap.modal', 'mgcrea.ngStrap.aside', 'mgcrea.ngStrap.alert', 'mgcrea.ngStrap.button', 'mgcrea.ngStrap.select', 'mgcrea.ngStrap.datepicker', 'mgcrea.ngStrap.timepicker', 'mgcrea.ngStrap.navbar', 'mgcrea.ngStrap.tooltip', 'mgcrea.ngStrap.popover', 'mgcrea.ngStrap.dropdown', 'mgcrea.ngStrap.typeahead', 'mgcrea.ngStrap.scrollspy', 'mgcrea.ngStrap.affix', 'mgcrea.ngStrap.tab', 'mgcrea.ngStrap.collapse' ]);
  4467. })(window, document);