forked from mgcrea/angular-strap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.min.js
More file actions
9 lines (9 loc) · 5.55 KB
/
select.min.js
File metadata and controls
9 lines (9 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
/**
* angular-strap
* @version v2.2.4 - 2015-05-28
* @link http://mgcrea.github.io/angular-strap
* @author Olivier Louvignes <olivier@mg-crea.com> (https://github.com/mgcrea)
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
'use strict';angular.module('mgcrea.ngStrap.select',['mgcrea.ngStrap.tooltip','mgcrea.ngStrap.helpers.parseOptions']).provider('$select',function(){var e=this.defaults={animation:'am-fade',prefixClass:'select',prefixEvent:'$select',placement:'bottom-left',template:'select/select.tpl.html',trigger:'focus',container:!1,keyboard:!0,html:!1,delay:0,multiple:!1,allNoneButtons:!1,sort:!0,caretHtml:' <span class="caret"></span>',placeholder:'Choose among the following...',allText:'All',noneText:'None',maxLength:3,maxLengthHtml:'selected',iconCheckmark:'glyphicon glyphicon-ok'};this.$get=['$window','$document','$rootScope','$tooltip','$timeout',function(t,n,a,l,i){function o(t,n,a){var o={},c=angular.extend({},e,a);o=l(t,c);var u=o.$scope;u.$matches=[],u.$activeIndex=c.multiple?[]:-1,u.$isMultiple=c.multiple,u.$showAllNoneButtons=c.allNoneButtons&&c.multiple,u.$iconCheckmark=c.iconCheckmark,u.$allText=c.allText,u.$noneText=c.noneText,u.$activate=function(e){u.$$postDigest(function(){o.activate(e)})},u.$select=function(e,t){u.$$postDigest(function(){o.select(e)})},u.$isVisible=function(){return o.$isVisible()},u.$isActive=function(e){return o.$isActive(e)},u.$selectAll=function(){for(var e=0;e<u.$matches.length;e++)u.$isActive(e)||u.$select(e)},u.$selectNone=function(){for(var e=0;e<u.$matches.length;e++)u.$isActive(e)&&u.$select(e)},o.update=function(e){u.$matches=e,o.$updateActiveIndex()},o.activate=function(e){return c.multiple?(o.$isActive(e)?u.$activeIndex.splice(u.$activeIndex.indexOf(e),1):u.$activeIndex.push(e),c.sort&&u.$activeIndex.sort(function(e,t){return e-t})):u.$activeIndex=e,u.$activeIndex},o.select=function(e){var t=u.$matches[e].value;u.$apply(function(){o.activate(e),c.multiple?n.$setViewValue(u.$activeIndex.map(function(e){return u.$matches[e].value})):(n.$setViewValue(t),o.hide())}),u.$emit(c.prefixEvent+'.select',t,e,o)},o.$updateActiveIndex=function(){n.$modelValue&&u.$matches.length?u.$activeIndex=c.multiple&&angular.isArray(n.$modelValue)?n.$modelValue.map(function(e){return o.$getIndex(e)}):o.$getIndex(n.$modelValue):u.$activeIndex>=u.$matches.length&&(u.$activeIndex=c.multiple?[]:0)},o.$isVisible=function(){return c.minLength&&n?u.$matches.length&&n.$viewValue.length>=c.minLength:u.$matches.length},o.$isActive=function(e){return c.multiple?-1!==u.$activeIndex.indexOf(e):u.$activeIndex===e},o.$getIndex=function(e){var t=u.$matches.length,n=t;if(t){for(n=t;n--&&u.$matches[n].value!==e;);if(!(0>n))return n}},o.$onMouseDown=function(e){if(e.preventDefault(),e.stopPropagation(),r){var t=angular.element(e.target);t.triggerHandler('click')}},o.$onKeyDown=function(e){return/(9|13|38|40)/.test(e.keyCode)?(e.preventDefault(),e.stopPropagation(),c.multiple&&9===e.keyCode?o.hide():c.multiple||13!==e.keyCode&&9!==e.keyCode?void(c.multiple||(38===e.keyCode&&u.$activeIndex>0?u.$activeIndex--:38===e.keyCode&&u.$activeIndex<0?u.$activeIndex=u.$matches.length-1:40===e.keyCode&&u.$activeIndex<u.$matches.length-1?u.$activeIndex++:angular.isUndefined(u.$activeIndex)&&(u.$activeIndex=0),u.$digest())):o.select(u.$activeIndex)):void 0};var s=o.show;o.show=function(){s(),c.multiple&&o.$element.addClass('select-multiple'),i(function(){o.$element.on(r?'touchstart':'mousedown',o.$onMouseDown),c.keyboard&&t.on('keydown',o.$onKeyDown)},0,!1)};var $=o.hide;return o.hide=function(){c.multiple||n.$modelValue||(u.$activeIndex=-1),o.$element.off(r?'touchstart':'mousedown',o.$onMouseDown),c.keyboard&&t.off('keydown',o.$onKeyDown),$(!0)},o}var c=(angular.element(t.document.body),/(ip(a|o)d|iphone|android)/gi.test(t.navigator.userAgent)),r='createTouch'in t.document&&c;return o.defaults=e,o}]}).directive('bsSelect',['$window','$parse','$q','$select','$parseOptions',function(e,t,n,a,l){var i=a.defaults;return{restrict:'EAC',require:'ngModel',link:function(e,t,n,o){var c={scope:e,placeholder:i.placeholder};angular.forEach(['placement','container','delay','trigger','keyboard','html','animation','template','placeholder','allNoneButtons','maxLength','maxLengthHtml','allText','noneText','iconCheckmark','autoClose','id','sort','caretHtml','prefixClass','prefixEvent'],function(e){angular.isDefined(n[e])&&(c[e]=n[e])});var r=/^(false|0|)$/i;angular.forEach(['html','container','allNoneButtons','sort'],function(e){angular.isDefined(n[e])&&r.test(n[e])&&(c[e]=!1)});var u=t.attr('data-multiple');if(angular.isDefined(u)&&(c.multiple=r.test(u)?!1:u),'select'===t[0].nodeName.toLowerCase()){var s=t;s.css('display','none'),t=angular.element('<button type="button" class="btn btn-default"></button>'),s.after(t)}var $=l(n.bsOptions),d=a(t,o,c),m=$.$match[7].replace(/\|.+/,'').trim();e.$watchCollection(m,function(t,n){$.valuesFn(e,o).then(function(e){d.update(e),o.$render()})}),e.$watch(n.ngModel,function(e,t){d.$updateActiveIndex(),o.$render()},!0),o.$render=function(){var e,n;c.multiple&&angular.isArray(o.$modelValue)?(e=o.$modelValue.map(function(e){return n=d.$getIndex(e),angular.isDefined(n)?d.$scope.$matches[n].label:!1}).filter(angular.isDefined),e=e.length>(c.maxLength||i.maxLength)?e.length+' '+(c.maxLengthHtml||i.maxLengthHtml):e.join(', ')):(n=d.$getIndex(o.$modelValue),e=angular.isDefined(n)?d.$scope.$matches[n].label:!1),t.html((e?e:c.placeholder)+(c.caretHtml?c.caretHtml:i.caretHtml))},c.multiple&&(o.$isEmpty=function(e){return!e||0===e.length}),e.$on('$destroy',function(){d&&d.destroy(),c=null,d=null})}}}]);
//# sourceMappingURL=../modules/select.min.js.map