text: angular.module("oi.select",[]),angular.module("oi.select").provider("oiSelect",function(){return{options:{debounce:500,searchFilter:"oiSelectCloseIcon",dropdownFilter:"oiSelectHighlight",listFilter:"oiSelectAscSort",groupFilter:"oiSelectGroup",editItem:!1,newItem:!1,closeList:!0,saveTrigger:"enter tab blur",minlength:0},version:{full:"0.2.21",major:0,minor:2,dot:21},$get:function(){return{options:this.options,version:this.version}}}}).factory("oiSelectEscape",function(){var e=/[-\/\\^$*+?.()|[\]{}]/g,t="\\$&";return function(n){return String(n).replace(e,t)}}).factory("oiSelectEditItem",function(){return function(e,t,n,o){return o?"":n(e)}}).factory("oiUtils",["$document","$timeout",function(e,t){function n(e,t,n){for(var o=t;o&&o.ownerDocument&&11!==o.nodeType;){if(n){if(o===e)return!1;if(o.className.indexOf(n)>=0)return!0}else if(o===e)return!0;o=o.parentNode}return!1}function o(o,r){function i(e){return e&&"INPUT"!==e.target.nodeName?void 0:(d=!1,a=!1,c?void(d=!0):void t(function(){o.triggerHandler("blur")}))}function s(){a||(a=!0,t(function(){o.triggerHandler("focus")}))}function l(){c=!0}function u(e){c=!1;var s=e.target,l=n(o[0],s);d&&!l&&i(),l&&"INPUT"!==s.nodeName&&t(function(){r[0].focus()}),!l&&a&&(a=!1)}var a,c,d;return e[0].addEventListener("click",u,!0),o[0].addEventListener("mousedown",l,!0),o[0].addEventListener("blur",i,!0),r.on("focus",s),function(){e[0].removeEventListener("click",u,!0),o[0].removeEventListener("mousedown",l,!0),o[0].removeEventListener("blur",i,!0),r.off("focus",s)}}function r(e,t){var n,o,r,i,l,a;t&&(o=e.offsetHeight,r=u(t,"height","margin"),i=e.scrollTop||0,n=s(t).top-s(e).top+i,l=n,a=n-o+r,n+r>o+i?e.scrollTop=a:i>n&&(e.scrollTop=l))}function i(e,t,n,o,r){function i(e){return parseFloat(r[e])}for(var s=n===(o?"border":"content")?4:"width"===t?1:0,l=0,u=["Top","Right","Bottom","Left"];4>s;s+=2)"margin"===n&&(l+=i(n+u[s])),o?("content"===n&&(l-=i("padding"+u[s])),"margin"!==n&&(l-=i("border"+u[s]+"Width"))):(l+=i("padding"+u[s]),"padding"!==n&&(l+=i("border"+u[s]+"Width")));return l}function s(e){var t,n,o=e.getBoundingClientRect(),r=e&&e.ownerDocument;if(r)return t=r.documentElement,n=l(r),{top:o.top+n.pageYOffset-t.clientTop,left:o.left+n.pageXOffset-t.clientLeft}}function l(e){return null!=e&&e===e.window?e:9===e.nodeType&&e.defaultView}function u(e,t,n){var o=!0,r="width"===t?e.offsetWidth:e.offsetHeight,s=window.getComputedStyle(e,null),l=!1;if(0>=r||null==r){if(r=s[t],(0>r||null==r)&&(r=e.style[t]),f.test(r))return r;r=parseFloat(r)||0}return r+i(e,t,n||(l?"border":"content"),o,s)}function a(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t].length)return!1;return!0}function c(e,t,n,o,r){var i,s,l,u,a,c=r?[].concat(e):[];for(i=0,l=e.length;i<e.length;i++)for(u=n?n(e[i]):e[i],s=0;s<t.length;s++)if(a=o?o(t[s]):t[s],angular.equals(u,a,e,t,i,s)){r?c.splice(i+c.length-l,1):c.push(t[s]);break}return c}function d(e,t,n,o){var r={};return e.split(".").reduce(function(e,n,o,r){return e[n]=o<r.length-1?{}:t},r),o(n,r)}var p=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,f=new RegExp("^("+p+")(?!px)[a-z%]+$","i");return{contains:n,bindFocusBlur:o,scrollActiveOption:r,groupsIsEmpty:a,getValue:d,intersection:c}}]),angular.module("oi.select").directive("oiSelect",["$document","$q","$timeout","$parse","$interpolate","$injector","$filter","$animate","oiUtils","oiSelect",function(e,t,n,o,r,i,s,l,u,a){var c=/^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?(?:\s+disable\s+when\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/,d=/([^\(\)\s\|\s]*)\s*(\(.*\))?\s*(\|?\s*.+)?/;return{restrict:"AE",templateUrl:"src/template.html",require:"ngModel",scope:{},compile:function(e,p){var f=p.oiOptions,g=f?f.match(c):["","i","","","","i","","",""];if(!g)throw new Error("Expected expression in form of '_select_ (as _label_)? for (_key_,)?_value_ in _collection_'");var m=/ as /.test(g[0])&&g[1],h=g[2]||g[1],v=g[5]||g[7],$=g[6],w=g[3]||"",b=g[4]||"",y=g[9]||h,L=g[8].match(d),k=v,S=$;$&&(v="i",m=v+"."+(m||k),y=v+"."+$,h=v+"."+h,$=v+"."+$,w=w?v+"."+w:void 0,b=b?v+"."+b:void 0);var I,E,F,C,q,V,P,x,H=L[1],O=H+(L[3]||""),A=H+(L[2]||""),D=m&&o(m),_=o(h),T=o(w),N=o(b),M=o(O),Q=o(A),U=o(y),R=r(p.multiplePlaceholder||""),W=r(p.listPlaceholder||""),j=r(p.placeholder||""),B=o(p.oiSelectOptions),G=angular.version.major<=1&&angular.version.minor<=3;return function(e,r,c,d){function p(){gt&&r.removeClass("cleanMode"),gt=!1}function f(e,t){t=t||150,r.addClass(e),n(function(){r.removeClass(e)},t)}function m(){e.listItemHide=!0,e.inputHide=!1}function h(){var t=et(d.$modelValue);e.listItemHide=!t,e.inputHide=t}function w(t){e.query.length<pt.minlength||u.contains(r[0],t.target,"disabled")||e.output.length>=P&&u.contains(r[0],t.target,"select-dropdown")||(e.inputHide&&e.removeItem(0),!e.isOpen||!pt.closeList||"INPUT"===t.target.nodeName&&e.query.length?tt(e.query):(ot({query:pt.editItem&&!gt}),e.$evalAsync()))}function b(){e.isFocused||(e.isFocused=!0,c.disabled||(e.backspaceFocus=!1))}function y(){e.isFocused=!1,V||h(),L("blur")||ot(),e.$evalAsync()}function L(o,r){r||(r=o,o=e.query);var i,s=pt.saveTrigger.split(" ").indexOf(r)+1,l=pt.newItem&&o,u="blur"!==r?e.order[e.selectorPosition]:null;return s&&(l||u&&!Y(u))?(e.showLoader=!0,i=t.when(u||x(e.$parent,{$query:o})),i.then(function(o){if(void 0===o)return t.reject();e.addItem(o);var r=e.order.length-1;e.selectorPosition===r&&rt(lt,0),pt.newItemFn&&!u||n(angular.noop),ot()}).catch(function(){f("invalid-item"),e.showLoader=!1}),!0):void 0}function O(){var e=V&&et(d.$modelValue)?at:ut;st.attr("placeholder",e)}function A(t){return u.getValue(v,t,e.$parent,U)}function z(t){return u.getValue(v,t,e.$parent,D)}function X(t){return u.getValue(v,t,e.$parent,_)}function Y(t){return e.isEmptyList||u.getValue(v,t,e.$parent,N)}function J(t){return u.getValue(v,t,e.$parent,T)||""}function K(t){return u.getValue(H,t,e.$parent,M)}function Z(e){return e=e instanceof Array?e:e?[e]:[],e.filter(function(e){return void 0!==e&&(e instanceof Array&&e.length||D||X(e))})}function et(e){return!!Z(e).length}function tt(o,i,s){return e.isEmptyList=!1,void 0===s&&(s=!0),F&&mt&&n.cancel(F),F=n(function(){var l=Q(e.$parent,{$query:o,$selectedAs:i})||"";return e.selectorPosition="prompt"===pt.newItem?!1:0,o||i||(e.oldQuery=null),(l.$promise&&!l.$resolved||angular.isFunction(l.then))&&(mt=pt.debounce),e.showLoader=!0,t.when(l.$promise||l).then(function(t){if(s&&(e.groups={}),t&&$){var n=[];angular.forEach(t,function(e,t){if("$"!==t.toString().charAt(0)){var o={};o[S]=t,o[k]=e,n.push(o)}}),t=n}if(t){var l,a;if(i)l=u.intersection(t,i,z,null,!0),a=K(l);else{var c=V&&e.output||[],d=Lt(t,o,X,kt(e.$parent),r);l=u.intersection(d,c,A,A,!0),a=K(l)}if(!a.length&&(e.isEmptyList=!0,ct)){var p={};_.assign(p,ct),a=[p[v]]}s&&(e.groups=it(a))}return nt(),t}).finally(function(){e.showLoader=!1,pt.closeList&&!pt.cleanModel&&n(function(){rt(lt,0)})})},mt)}function nt(){var t,n,o,r=[],i=0;e.order=[],e.groupPos={};for(n in e.groups)e.groups.hasOwnProperty(n)&&"$"!=n.charAt(0)&&r.push(n);for(G&&r.sort(),t=0;t<r.length;t++)n=r[t],o=e.groups[n],e.order=e.order.concat(o),e.groupPos[n]=i,i+=o.length}function ot(t){t=t||{},e.oldQuery=null,e.backspaceFocus=!1,e.groups={},e.order=[],e.showLoader=!1,e.isOpen=!1,mt=0,t.query||(e.query=""),F&&n.cancel(F)}function rt(t,n){e.selectorPosition=n,u.scrollActiveOption(t[0],t.find("li")[n])}function it(e){for(var t,n,o={"":[]},r=0;r<e.length;r++)t=J(e[r]),(n=o[t])||(n=o[t]=[]),n.push(e[r]);return o}d.$isEmpty=function(e){return!et(e)};var st=r.find("input"),lt=angular.element(r[0].querySelector(".select-dropdown")),ut=j(e),at=R(e),ct=W(e),dt=B(e.$parent)||{},pt=angular.extend({cleanModel:"prompt"===dt.newItem},a.options,dt),ft=pt.editItem,gt="correct"===ft,mt=0;(ft===!0||"correct"===ft)&&(ft="oiSelectEditItem");var ht=ft?i.get(ft):angular.noop,vt=o(pt.removeItemFn);g=pt.searchFilter.split(":");var $t=s(g[0]),wt=o(g[1]);g=pt.dropdownFilter.split(":");var bt=s(g[0]),yt=o(g[1]);g=pt.listFilter.split(":");var Lt=s(g[0]),kt=o(g[1]);g=pt.groupFilter.split(":");var St=s(g[0]),It=o(g[1]);x=pt.newItemFn?o(pt.newItemFn):function(e,t){return(B(t)||{}).newItemModel||t.$query},!pt.cleanModel||ft&&!gt||r.addClass("cleanMode");var Et=u.bindFocusBlur(r,st);angular.isDefined(c.autofocus)&&n(function(){st[0].focus()}),angular.isDefined(c.readonly)&&st.attr("readonly",!0),angular.isDefined(c.tabindex)&&(st.attr("tabindex",c.tabindex),r[0].removeAttribute("tabindex")),pt.maxlength&&st.attr("maxlength",pt.maxlength),c.$observe("disabled",function(t){st.prop("disabled",t),V&&d.$modelValue&&d.$modelValue.length&&(e.inputHide=t)}),e.$on("$destroy",Et),e.$parent.$watch(c.multipleLimit,function(e){P=Number(e)||1/0}),e.$parent.$watch(c.multiple,function(e){V=void 0===e?angular.isDefined(c.multiple):e,r[V?"addClass":"removeClass"]("multiple")}),e.$parent.$watch(c.ngModel,function(n,o){var r=Z(n),i=t.when(r);O(),et(o)&&n!==o&&p(),V||h(),D&&et(n)&&(i=tt(null,n,!1).then(function(e){return u.intersection(r,e,null,z)}),F=null),V&&c.disabled&&!et(n)&&(e.inputHide=!1),i.then(function(t){e.output=t,t.length!==r.length&&e.removeItem(t.length)})}),e.$watch("query",function(t,n){L(t.slice(0,-1),t.slice(-1))||String(t).length<pt.minlength||(t===n||e.oldQuery&&!t||E||(lt[0].scrollTop=0,t?(tt(t),e.oldQuery=null):V&&(ot(),E=!0)),E=!1)}),e.$watch("groups",function(t){u.groupsIsEmpty(t)?e.isOpen=!1:e.isOpen||c.disabled||(e.isOpen=!0,e.isFocused=!0)}),e.$watch("isFocused",function(e){l[e?"addClass":"removeClass"](r,"focused",!G&&{tempClasses:"focused-animate"})}),e.$watch("isOpen",function(e){l[e?"addClass":"removeClass"](r,"open",!G&&{tempClasses:"open-animate"})}),e.$watch("isEmptyList",function(e){l[e?"addClass":"removeClass"](r,"emptyList",!G&&{tempClasses:"emptyList-animate"})}),e.$watch("showLoader",function(e){l[e?"addClass":"removeClass"](r,"loading",!G&&{tempClasses:"loading-animate"})}),e.addItem=function(t){if(C=e.query,!V||!u.intersection(e.output,[t],A,A).length){if(e.output.length>=P)return void f("limited");var n=e.groups[J(t)]=e.groups[J(t)]||[],o=D?z(t):t;n.splice(n.indexOf(t),1),V?d.$setViewValue(angular.isArray(d.$modelValue)?d.$modelValue.concat(o):[o]):(d.$setViewValue(o),h()),u.groupsIsEmpty(e.groups)&&(e.groups={}),V||pt.closeList||ot({query:!0}),p(),e.oldQuery=e.oldQuery||e.query,e.query="",e.backspaceFocus=!1}},e.removeItem=function(n){c.disabled||V&&0>n||(q=V?d.$modelValue[n]:d.$modelValue,t.when(vt(e.$parent,{$item:q})).then(function(){(V||e.inputHide)&&(V?(d.$modelValue.splice(n,1),d.$setViewValue([].concat(d.$modelValue))):(m(),pt.cleanModel&&d.$setViewValue(void 0)),(V||!e.backspaceFocus)&&(e.query=ht(q,C,X,gt,r)||""),V&&pt.closeList&&ot({query:!0}))}))},e.setSelection=function(t){I||e.selectorPosition===t?I=!1:rt(lt,t)},e.keyUp=function(t){switch(t.keyCode){case 8:e.query.length||V&&e.output.length||ot()}},e.keyDown=function(t){var n=0,o=e.order.length-1;switch(t.keyCode){case 38:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n,rt(lt,e.selectorPosition===n?o:e.selectorPosition-1),I=!0;break;case 40:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n-1,rt(lt,e.selectorPosition===o?n:e.selectorPosition+1),I=!0,e.query.length||e.isOpen||tt(),e.inputHide&&m();break;case 37:case 39:break;case 9:L("tab");break;case 13:L("enter"),t.preventDefault();break;case 32:L("space");break;case 27:V||(h(),pt.cleanModel&&d.$setViewValue(q)),ot();break;case 8:if(!e.query.length){if((!V||ft)&&(e.backspaceFocus=!0),e.backspaceFocus&&e.output&&(!V||e.output.length)){e.removeItem(e.output.length-1),ft&&t.preventDefault();break}e.backspaceFocus=!e.backspaceFocus;break}default:return e.inputHide&&m(),e.backspaceFocus=!1,!1}},e.getSearchLabel=function(t){var n=X(t);return $t(n,e.oldQuery||e.query,t,wt(e.$parent),r)},e.getDropdownLabel=function(t){var n=X(t);return bt(n,e.oldQuery||e.query,t,yt(e.$parent),r)},e.getGroupLabel=function(t,n){return St(t,e.oldQuery||e.query,n,It(e.$parent),r)},e.getDisableWhen=Y,ot(),r[0].addEventListener("click",w,!0),e.$on("$destroy",function(){r[0].removeEventListener("click",w,!0)}),r.on("focus",b),r.on("blur",y)}}}}]),angular.module("oi.select").filter("oiSelectGroup",["$sce",function(e){return function(t){return e.trustAsHtml(t)}}]).filter("oiSelectCloseIcon",["$sce",function(e){return function(t){var n='<span class="close select-search-list-item_selection-remove">×</span>';return e.trustAsHtml(t+n)}}]).filter("oiSelectHighlight",["$sce","oiSelectEscape",function(e,t){return function(n,o){var r;return o.length>0||angular.isNumber(o)?(n=n.toString(),o=t(o),r=n.replace(new RegExp(o,"gi"),"<strong>$&</strong>")):r=n,e.trustAsHtml(r)}}]).filter("oiSelectAscSort",["oiSelectEscape",function(e){function t(t,n,o,r){var i,s,l,u,a=[],c=[],d=[],p=[];if(n){for(n=e(n).toLocaleLowerCase(),i=0,l=!1;i<t.length;i++){if(l=o(t[i]).toLocaleLowerCase().match(new RegExp(n)),!l&&r&&(r.length||r.fields))for(s=0;s<r.length&&!l;s++)l=String(t[i][r[s]]).toLocaleLowerCase().match(new RegExp(n));l&&a.push(t[i])}for(i=0;i<a.length;i++)o(a[i]).toLocaleLowerCase().match(new RegExp("^"+n))?c.push(a[i]):d.push(a[i]);if(u=c.concat(d),r&&(r===!0||r.all)){e:for(i=0;i<t.length;i++){for(s=0;s<u.length;s++)if(t[i]===u[s])continue e;p.push(t[i])}u=u.concat(p)}}else u=[].concat(t);return u}return t}]).filter("none",function(){return function(e){return e}}),angular.module("oi.select").run(["$templateCache",function(e){e.put("src/template.html",'<div class=select-search><ul class=select-search-list><li class="btn btn-default btn-xs select-search-list-item select-search-list-item_selection" ng-hide=listItemHide ng-repeat="item in output track by $index" ng-class="{focused: backspaceFocus && $last}" ng-click=removeItem($index) ng-bind-html=getSearchLabel(item)></li><li class="select-search-list-item select-search-list-item_input" ng-class="{\'select-search-list-item_hide\': inputHide}"><input autocomplete=off ng-model=query ng-keyup=keyUp($event) ng-keydown=keyDown($event)></li><li class="select-search-list-item select-search-list-item_loader" ng-show=showLoader></li></ul></div><div class=select-dropdown ng-show=isOpen><ul ng-if=isOpen class=select-dropdown-optgroup ng-repeat="(group, options) in groups"><div class=select-dropdown-optgroup-header ng-if="group && options.length" ng-bind-html="getGroupLabel(group, options)"></div><li class=select-dropdown-optgroup-option ng-init="isDisabled = getDisableWhen(option)" ng-repeat="option in options" ng-class="{\'active\': selectorPosition === groupPos[group] + $index, \'disabled\': isDisabled, \'ungroup\': !group}" ng-click="isDisabled || addItem(option)" ng-mouseenter="setSelection(groupPos[group] + $index)" ng-bind-html=getDropdownLabel(option)></li></ul></div>')}]);