diff --git a/CHANGELOG.md b/CHANGELOG.md index d58be45..5c9c6f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ ## 0.2.13 + +#### Bug Fixes + +- **oi-select-options:** + - newItem = "prompt": fixed items saving + +## 0.2.13 #### Features diff --git a/README.md b/README.md index e135c87..2a3a2dc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ #oi.select — AngularJS directive of select element -**[Download 0.2.13](https://github.com/tamtakoe/oi.select/tree/master/dist)** +**[Download 0.2.14](https://github.com/tamtakoe/oi.select/tree/master/dist)** ## Features diff --git a/bower.json b/bower.json index 744d535..14360ee 100644 --- a/bower.json +++ b/bower.json @@ -3,7 +3,7 @@ "name": "https://github.com/tamtakoe" }, "name": "oi.select", - "version": "0.2.13", + "version": "0.2.14", "main": ["./dist/select-tpls.min.js", "./dist/select.min.css"], "dependencies": { "angular": ">=1.2", diff --git a/dist/select-tpls.js b/dist/select-tpls.js index 25814da..79d79c7 100644 --- a/dist/select-tpls.js +++ b/dist/select-tpls.js @@ -14,10 +14,10 @@ angular.module('oi.select') saveTrigger: 'enter' }, version: { - full: '0.2.13', + full: '0.2.14', major: 0, minor: 2, - dot: 13 + dot: 14 }, $get: function() { return { @@ -473,15 +473,21 @@ angular.module('oi.select') } }); + function valueChangedManually() { //case: clean model; prompt + editItem: 'correct'; initial value = defined/undefined + if (editItemIsCorrected) { + element.removeClass('cleanMode'); + } + editItemIsCorrected = false; + } + scope.$parent.$watch(attrs.ngModel, function(value, oldValue) { var output = value instanceof Array ? value : value ? [value]: [], promise = $q.when(output); modifyPlaceholder(); - if (value !== oldValue) { - editItemIsCorrected = false; - element.removeClass('cleanMode'); + if (oldValue && value !== oldValue) { + valueChangedManually(); } if (!multiple) { @@ -587,6 +593,8 @@ angular.module('oi.select') resetMatches({query: true}); } + valueChangedManually(); + scope.oldQuery = scope.oldQuery || scope.query; scope.query = ''; scope.backspaceFocus = false; @@ -913,7 +921,7 @@ angular.module('oi.select') .finally(function(){ scope.showLoader = false; - if (options.closeList) { + if (options.closeList && !options.cleanModel) { //case: prompt $timeout(function() { setOption(listElement, 0); }); diff --git a/dist/select-tpls.min.js b/dist/select-tpls.min.js index 14a0bd1..684d88d 100644 --- a/dist/select-tpls.min.js +++ b/dist/select-tpls.min.js @@ -1 +1 @@ -angular.module("oi.select",[]),angular.module("oi.select").provider("oiSelect",function(){return{options:{debounce:500,searchFilter:"oiSelectCloseIcon",dropdownFilter:"oiSelectHighlight",listFilter:"oiSelectAscSort",editItem:!1,newItem:!1,closeList:!0,saveTrigger:"enter"},version:{full:"0.2.13",major:0,minor:2,dot:13},$get:function(){return{options:this.options,version:this.version}}}}).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.classList.contains(n))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,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),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]),g.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){var t=[];return angular.forEach(e,function(e,n){"$"!==n.toString().charAt(0)&&t.push(e)}),t}function d(e,t,n,o,r){var i,s,l,u,a,c=r?[].concat(e):[];for(i=0,l=e.length;i=w&&u.contains(r[0],t.target,"select-dropdown")||(e.inputHide&&e.removeItem(0),!e.isOpen||!rt.closeList||"INPUT"===t.target.nodeName&&e.query.length?X(e.query):(G({query:rt.editItem&&!st}),e.$evalAsync()))}function S(){e.isFocused||(e.isFocused=!0,c.disabled||(e.backspaceFocus=!1))}function F(){e.isFocused=!1,$||y(),L("blur")||G(),e.$evalAsync()}function V(e){return rt.saveTrigger.split(" ").indexOf(e)+1}function L(o,r){r||(r=o,o=e.query);var i,s=V(r),l=rt.newItem&&o,u=e.order[e.selectorPosition];return s&&(l||u)?(e.showLoader=!0,i=t.when(u||b(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&&J(et,0),rt.newItemFn&&!u||n(angular.noop),G()}).catch(function(){p("invalid-item"),e.showLoader=!1}),!0):void 0}function P(){var e=$&&d.$modelValue&&d.$modelValue.length?nt:tt;Z.attr("placeholder",e)}function E(t){return u.getValue(I,t,e.$parent,T)}function R(t){return u.getValue(I,t,e.$parent,C)}function j(t){return String(u.getValue(I,t,e.$parent,x))}function W(t){return u.getValue(I,t,e.$parent,O)}function B(t){return u.getValue(I,t,e.$parent,H)||""}function z(t){return u.getValue(q,t,e.$parent,A)}function X(o,r){var i=D(e.$parent,{$query:o,$selectedAs:r})||"",s=0;return e.selectorPosition="prompt"===rt.newItem?!1:0,o||r||(e.oldQuery=null),m&&(i.$promise&&!i.$resolved||angular.isFunction(i.then))&&(n.cancel(m),s=rt.debounce),m=n(function(){return e.showLoader=!0,t.when(i.$promise||i).then(function(t){if(!t)return e.groups={},void Y();if(!r){var n=$?e.output:[],i=ft(u.objToArr(t),o,j,gt(e.$parent)),s=u.intersection(i,n,E,E,!0),l=z(s);e.groups=K(l),Y()}return t}).finally(function(){e.showLoader=!1,rt.closeList&&n(function(){J(et,0)})})},s)}function Y(){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(angular.version.major<=1&&angular.version.minor<=3&&r.sort(),t=0;t=w)return void p("limited");var n=e.groups[B(t)]=e.groups[B(t)]||[],o=C?R(t):t;n.splice(n.indexOf(t),1),$?d.$setViewValue(angular.isArray(d.$modelValue)?d.$modelValue.concat(o):[o]):(d.$setViewValue(o),y()),u.groupsIsEmpty(e.groups)&&(e.groups={}),$||rt.closeList||G({query:!0}),e.oldQuery=e.oldQuery||e.query,e.query="",e.backspaceFocus=!1}},e.removeItem=function(n){c.disabled||$&&0>n||t.when(ut(e.$parent,{$item:v})).then(function(){($||e.inputHide)&&($?(v=d.$modelValue[n],d.$modelValue.splice(n,1),d.$setViewValue([].concat(d.$modelValue))):(v=d.$modelValue,f(),rt.cleanModel&&d.$setViewValue(void 0)),($||!e.backspaceFocus)&&(e.query=lt(v,h,j,st)||""),$&&rt.closeList&&G({query:!0}))})},e.setSelection=function(t){Q||e.selectorPosition===t?Q=!1:J(et,t)},e.keyUp=function(t){switch(t.keyCode){case 8:e.query.length||$&&e.output.length||G()}},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,J(et,e.selectorPosition===n?o:e.selectorPosition-1),Q=!0;break;case 40:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n-1,J(et,e.selectorPosition===o?n:e.selectorPosition+1),Q=!0,e.query.length||e.isOpen||X(),e.inputHide&&f();break;case 37:case 39:break;case 13:L("enter"),t.preventDefault();break;case 32:L("space");break;case 27:$||(y(),rt.cleanModel&&d.$setViewValue(v)),G();break;case 8:if(!e.query.length){if((!$||it)&&(e.backspaceFocus=!0),e.backspaceFocus&&e.output&&(!$||e.output.length)){e.removeItem(e.output.length-1),it&&t.preventDefault();break}e.backspaceFocus=!e.backspaceFocus;break}default:return e.inputHide&&f(),e.backspaceFocus=!1,!1}},e.getSearchLabel=function(t){var n=j(t);return at(n,e.oldQuery||e.query,t,ct(e.$parent))},e.getDropdownLabel=function(t){var n=j(t);return dt(n,e.oldQuery||e.query,t,pt(e.$parent))},e.getDisableWhen=W,G(),r[0].addEventListener("click",k,!0),r.on("focus",S),r.on("blur",F)}}}}]),angular.module("oi.select").filter("oiSelectCloseIcon",["$sce",function(e){return function(t){var n='×';return e.trustAsHtml(t+n)}}]).filter("oiSelectHighlight",["$sce",function(e){return function(t,n){var o;return n.length>0||angular.isNumber(n)?(t=t.toString(),n=n.toString().replace(/\s+.*/,"").replace(/\\/g,"\\\\"),o=t.replace(new RegExp(n,"gi"),"$&")):o=t,e.trustAsHtml(o)}}]).filter("oiSelectAscSort",function(){function e(e,t,n,o){var r,i,s,l,u=[],a=[],c=[];if(t){for(t=String(t).replace(/\s+.*/,"").replace(/\\/g,"\\\\"),r=0,s=!1;r
')}]); \ No newline at end of file +angular.module("oi.select",[]),angular.module("oi.select").provider("oiSelect",function(){return{options:{debounce:500,searchFilter:"oiSelectCloseIcon",dropdownFilter:"oiSelectHighlight",listFilter:"oiSelectAscSort",editItem:!1,newItem:!1,closeList:!0,saveTrigger:"enter"},version:{full:"0.2.14",major:0,minor:2,dot:14},$get:function(){return{options:this.options,version:this.version}}}}).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.classList.contains(n))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,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),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]),g.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){var t=[];return angular.forEach(e,function(e,n){"$"!==n.toString().charAt(0)&&t.push(e)}),t}function d(e,t,n,o,r){var i,s,l,u,a,c=r?[].concat(e):[];for(i=0,l=e.length;i=w&&u.contains(r[0],t.target,"select-dropdown")||(e.inputHide&&e.removeItem(0),!e.isOpen||!it.closeList||"INPUT"===t.target.nodeName&&e.query.length?Y(e.query):(J({query:it.editItem&&!lt}),e.$evalAsync()))}function F(){e.isFocused||(e.isFocused=!0,c.disabled||(e.backspaceFocus=!1))}function V(){e.isFocused=!1,$||k(),P("blur")||J(),e.$evalAsync()}function L(e){return it.saveTrigger.split(" ").indexOf(e)+1}function P(o,r){r||(r=o,o=e.query);var i,s=L(r),l=it.newItem&&o,u=e.order[e.selectorPosition];return s&&(l||u)?(e.showLoader=!0,i=t.when(u||b(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&&K(tt,0),it.newItemFn&&!u||n(angular.noop),J()}).catch(function(){f("invalid-item"),e.showLoader=!1}),!0):void 0}function E(){var e=$&&d.$modelValue&&d.$modelValue.length?ot:nt;et.attr("placeholder",e)}function R(t){return u.getValue(I,t,e.$parent,T)}function j(t){return u.getValue(I,t,e.$parent,C)}function W(t){return String(u.getValue(I,t,e.$parent,x))}function B(t){return u.getValue(I,t,e.$parent,O)}function z(t){return u.getValue(I,t,e.$parent,H)||""}function X(t){return u.getValue(q,t,e.$parent,A)}function Y(o,r){var i=D(e.$parent,{$query:o,$selectedAs:r})||"",s=0;return e.selectorPosition="prompt"===it.newItem?!1:0,o||r||(e.oldQuery=null),m&&(i.$promise&&!i.$resolved||angular.isFunction(i.then))&&(n.cancel(m),s=it.debounce),m=n(function(){return e.showLoader=!0,t.when(i.$promise||i).then(function(t){if(!t)return e.groups={},void G();if(!r){var n=$?e.output:[],i=gt(u.objToArr(t),o,W,mt(e.$parent)),s=u.intersection(i,n,R,R,!0),l=X(s);e.groups=Z(l),G()}return t}).finally(function(){e.showLoader=!1,it.closeList&&!it.cleanModel&&n(function(){K(tt,0)})})},s)}function G(){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(angular.version.major<=1&&angular.version.minor<=3&&r.sort(),t=0;t=w)return void f("limited");var n=e.groups[z(t)]=e.groups[z(t)]||[],o=C?j(t):t;n.splice(n.indexOf(t),1),$?d.$setViewValue(angular.isArray(d.$modelValue)?d.$modelValue.concat(o):[o]):(d.$setViewValue(o),k()),u.groupsIsEmpty(e.groups)&&(e.groups={}),$||it.closeList||J({query:!0}),p(),e.oldQuery=e.oldQuery||e.query,e.query="",e.backspaceFocus=!1}},e.removeItem=function(n){c.disabled||$&&0>n||t.when(at(e.$parent,{$item:v})).then(function(){($||e.inputHide)&&($?(v=d.$modelValue[n],d.$modelValue.splice(n,1),d.$setViewValue([].concat(d.$modelValue))):(v=d.$modelValue,y(),it.cleanModel&&d.$setViewValue(void 0)),($||!e.backspaceFocus)&&(e.query=ut(v,h,W,lt)||""),$&&it.closeList&&J({query:!0}))})},e.setSelection=function(t){Q||e.selectorPosition===t?Q=!1:K(tt,t)},e.keyUp=function(t){switch(t.keyCode){case 8:e.query.length||$&&e.output.length||J()}},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,K(tt,e.selectorPosition===n?o:e.selectorPosition-1),Q=!0;break;case 40:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n-1,K(tt,e.selectorPosition===o?n:e.selectorPosition+1),Q=!0,e.query.length||e.isOpen||Y(),e.inputHide&&y();break;case 37:case 39:break;case 13:P("enter"),t.preventDefault();break;case 32:P("space");break;case 27:$||(k(),it.cleanModel&&d.$setViewValue(v)),J();break;case 8:if(!e.query.length){if((!$||st)&&(e.backspaceFocus=!0),e.backspaceFocus&&e.output&&(!$||e.output.length)){e.removeItem(e.output.length-1),st&&t.preventDefault();break}e.backspaceFocus=!e.backspaceFocus;break}default:return e.inputHide&&y(),e.backspaceFocus=!1,!1}},e.getSearchLabel=function(t){var n=W(t);return ct(n,e.oldQuery||e.query,t,dt(e.$parent))},e.getDropdownLabel=function(t){var n=W(t);return pt(n,e.oldQuery||e.query,t,ft(e.$parent))},e.getDisableWhen=B,J(),r[0].addEventListener("click",S,!0),r.on("focus",F),r.on("blur",V)}}}}]),angular.module("oi.select").filter("oiSelectCloseIcon",["$sce",function(e){return function(t){var n='×';return e.trustAsHtml(t+n)}}]).filter("oiSelectHighlight",["$sce",function(e){return function(t,n){var o;return n.length>0||angular.isNumber(n)?(t=t.toString(),n=n.toString().replace(/\s+.*/,"").replace(/\\/g,"\\\\"),o=t.replace(new RegExp(n,"gi"),"$&")):o=t,e.trustAsHtml(o)}}]).filter("oiSelectAscSort",function(){function e(e,t,n,o){var r,i,s,l,u=[],a=[],c=[];if(t){for(t=String(t).replace(/\s+.*/,"").replace(/\\/g,"\\\\"),r=0,s=!1;r
')}]); \ No newline at end of file diff --git a/dist/select.js b/dist/select.js index cf018e0..11fb070 100644 --- a/dist/select.js +++ b/dist/select.js @@ -14,10 +14,10 @@ angular.module('oi.select') saveTrigger: 'enter' }, version: { - full: '0.2.13', + full: '0.2.14', major: 0, minor: 2, - dot: 13 + dot: 14 }, $get: function() { return { @@ -473,15 +473,21 @@ angular.module('oi.select') } }); + function valueChangedManually() { //case: clean model; prompt + editItem: 'correct'; initial value = defined/undefined + if (editItemIsCorrected) { + element.removeClass('cleanMode'); + } + editItemIsCorrected = false; + } + scope.$parent.$watch(attrs.ngModel, function(value, oldValue) { var output = value instanceof Array ? value : value ? [value]: [], promise = $q.when(output); modifyPlaceholder(); - if (value !== oldValue) { - editItemIsCorrected = false; - element.removeClass('cleanMode'); + if (oldValue && value !== oldValue) { + valueChangedManually(); } if (!multiple) { @@ -587,6 +593,8 @@ angular.module('oi.select') resetMatches({query: true}); } + valueChangedManually(); + scope.oldQuery = scope.oldQuery || scope.query; scope.query = ''; scope.backspaceFocus = false; @@ -913,7 +921,7 @@ angular.module('oi.select') .finally(function(){ scope.showLoader = false; - if (options.closeList) { + if (options.closeList && !options.cleanModel) { //case: prompt $timeout(function() { setOption(listElement, 0); }); diff --git a/dist/select.min.js b/dist/select.min.js index a1611b5..af90170 100644 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1 +1 @@ -angular.module("oi.select",[]),angular.module("oi.select").provider("oiSelect",function(){return{options:{debounce:500,searchFilter:"oiSelectCloseIcon",dropdownFilter:"oiSelectHighlight",listFilter:"oiSelectAscSort",editItem:!1,newItem:!1,closeList:!0,saveTrigger:"enter"},version:{full:"0.2.13",major:0,minor:2,dot:13},$get:function(){return{options:this.options,version:this.version}}}}).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.classList.contains(n))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,c?void(d=!0):void t(function(){o.triggerHandler("blur")}))}function u(){a||(a=!0,t(function(){o.triggerHandler("focus")}))}function s(){c=!0}function l(e){c=!1;var u=e.target,s=n(o[0],u);d&&!s&&i(),s&&"INPUT"!==u.nodeName&&t(function(){r[0].focus()}),!s&&a&&(a=!1)}var a,c,d;return e[0].addEventListener("click",l,!0),o[0].addEventListener("mousedown",s,!0),o[0].addEventListener("blur",i,!0),r.on("focus",u),function(){e[0].removeEventListener("click",l),o[0].removeEventListener("mousedown",s,!0),o[0].removeEventListener("blur",i,!0),r.off("focus",u)}}function r(e,t){var n,o,r,i,s,a;t&&(o=e.offsetHeight,r=l(t,"height","margin"),i=e.scrollTop||0,n=u(t).top-u(e).top+i,s=n,a=n-o+r,n+r>o+i?e.scrollTop=a:i>n&&(e.scrollTop=s))}function i(e,t,n,o,r){function i(e){return parseFloat(r[e])}for(var u=n===(o?"border":"content")?4:"width"===t?1:0,s=0,l=["Top","Right","Bottom","Left"];4>u;u+=2)"margin"===n&&(s+=i(n+l[u])),o?("content"===n&&(s-=i("padding"+l[u])),"margin"!==n&&(s-=i("border"+l[u]+"Width"))):(s+=i("padding"+l[u]),"padding"!==n&&(s+=i("border"+l[u]+"Width")));return s}function u(e){var t,n,o=e.getBoundingClientRect(),r=e&&e.ownerDocument;if(r)return t=r.documentElement,n=s(r),{top:o.top+n.pageYOffset-t.clientTop,left:o.left+n.pageXOffset-t.clientLeft}}function s(e){return null!=e&&e===e.window?e:9===e.nodeType&&e.defaultView}function l(e,t,n){var o=!0,r="width"===t?e.offsetWidth:e.offsetHeight,u=window.getComputedStyle(e,null),s=!1;if(0>=r||null==r){if(r=u[t],(0>r||null==r)&&(r=e.style[t]),g.test(r))return r;r=parseFloat(r)||0}return r+i(e,t,n||(s?"border":"content"),o,u)}function a(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t].length)return!1;return!0}function c(e){var t=[];return angular.forEach(e,function(e,n){"$"!==n.toString().charAt(0)&&t.push(e)}),t}function d(e,t,n,o,r){var i,u,s,l,a,c=r?[].concat(e):[];for(i=0,s=e.length;i=w&&l.contains(r[0],t.target,"select-dropdown")||(e.inputHide&&e.removeItem(0),!e.isOpen||!rt.closeList||"INPUT"===t.target.nodeName&&e.query.length?X(e.query):(G({query:rt.editItem&&!ut}),e.$evalAsync()))}function V(){e.isFocused||(e.isFocused=!0,c.disabled||(e.backspaceFocus=!1))}function F(){e.isFocused=!1,$||b(),q("blur")||G(),e.$evalAsync()}function k(e){return rt.saveTrigger.split(" ").indexOf(e)+1}function q(o,r){r||(r=o,o=e.query);var i,u=k(r),s=rt.newItem&&o,l=e.order[e.selectorPosition];return u&&(s||l)?(e.showLoader=!0,i=t.when(l||y(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&&J(et,0),rt.newItemFn&&!l||n(angular.noop),G()}).catch(function(){p("invalid-item"),e.showLoader=!1}),!0):void 0}function L(){var e=$&&d.$modelValue&&d.$modelValue.length?nt:tt;Z.attr("placeholder",e)}function P(t){return l.getValue(S,t,e.$parent,D)}function U(t){return l.getValue(S,t,e.$parent,C)}function j(t){return String(l.getValue(S,t,e.$parent,A))}function B(t){return l.getValue(S,t,e.$parent,O)}function W(t){return l.getValue(S,t,e.$parent,H)||""}function z(t){return l.getValue(E,t,e.$parent,x)}function X(o,r){var i=T(e.$parent,{$query:o,$selectedAs:r})||"",u=0;return e.selectorPosition="prompt"===rt.newItem?!1:0,o||r||(e.oldQuery=null),m&&(i.$promise&&!i.$resolved||angular.isFunction(i.then))&&(n.cancel(m),u=rt.debounce),m=n(function(){return e.showLoader=!0,t.when(i.$promise||i).then(function(t){if(!t)return e.groups={},void Y();if(!r){var n=$?e.output:[],i=ft(l.objToArr(t),o,j,gt(e.$parent)),u=l.intersection(i,n,P,P,!0),s=z(u);e.groups=K(s),Y()}return t}).finally(function(){e.showLoader=!1,rt.closeList&&n(function(){J(et,0)})})},u)}function Y(){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(angular.version.major<=1&&angular.version.minor<=3&&r.sort(),t=0;t=w)return void p("limited");var n=e.groups[W(t)]=e.groups[W(t)]||[],o=C?U(t):t;n.splice(n.indexOf(t),1),$?d.$setViewValue(angular.isArray(d.$modelValue)?d.$modelValue.concat(o):[o]):(d.$setViewValue(o),b()),l.groupsIsEmpty(e.groups)&&(e.groups={}),$||rt.closeList||G({query:!0}),e.oldQuery=e.oldQuery||e.query,e.query="",e.backspaceFocus=!1}},e.removeItem=function(n){c.disabled||$&&0>n||t.when(lt(e.$parent,{$item:v})).then(function(){($||e.inputHide)&&($?(v=d.$modelValue[n],d.$modelValue.splice(n,1),d.$setViewValue([].concat(d.$modelValue))):(v=d.$modelValue,f(),rt.cleanModel&&d.$setViewValue(void 0)),($||!e.backspaceFocus)&&(e.query=st(v,h,j,ut)||""),$&&rt.closeList&&G({query:!0}))})},e.setSelection=function(t){Q||e.selectorPosition===t?Q=!1:J(et,t)},e.keyUp=function(t){switch(t.keyCode){case 8:e.query.length||$&&e.output.length||G()}},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,J(et,e.selectorPosition===n?o:e.selectorPosition-1),Q=!0;break;case 40:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n-1,J(et,e.selectorPosition===o?n:e.selectorPosition+1),Q=!0,e.query.length||e.isOpen||X(),e.inputHide&&f();break;case 37:case 39:break;case 13:q("enter"),t.preventDefault();break;case 32:q("space");break;case 27:$||(b(),rt.cleanModel&&d.$setViewValue(v)),G();break;case 8:if(!e.query.length){if((!$||it)&&(e.backspaceFocus=!0),e.backspaceFocus&&e.output&&(!$||e.output.length)){e.removeItem(e.output.length-1),it&&t.preventDefault();break}e.backspaceFocus=!e.backspaceFocus;break}default:return e.inputHide&&f(),e.backspaceFocus=!1,!1}},e.getSearchLabel=function(t){var n=j(t);return at(n,e.oldQuery||e.query,t,ct(e.$parent))},e.getDropdownLabel=function(t){var n=j(t);return dt(n,e.oldQuery||e.query,t,pt(e.$parent))},e.getDisableWhen=B,G(),r[0].addEventListener("click",I,!0),r.on("focus",V),r.on("blur",F)}}}}]),angular.module("oi.select").filter("oiSelectCloseIcon",["$sce",function(e){return function(t){var n='×';return e.trustAsHtml(t+n)}}]).filter("oiSelectHighlight",["$sce",function(e){return function(t,n){var o;return n.length>0||angular.isNumber(n)?(t=t.toString(),n=n.toString().replace(/\s+.*/,"").replace(/\\/g,"\\\\"),o=t.replace(new RegExp(n,"gi"),"$&")):o=t,e.trustAsHtml(o)}}]).filter("oiSelectAscSort",function(){function e(e,t,n,o){var r,i,u,s,l=[],a=[],c=[];if(t){for(t=String(t).replace(/\s+.*/,"").replace(/\\/g,"\\\\"),r=0,u=!1;ro+i?e.scrollTop=a:i>n&&(e.scrollTop=s))}function i(e,t,n,o,r){function i(e){return parseFloat(r[e])}for(var u=n===(o?"border":"content")?4:"width"===t?1:0,s=0,l=["Top","Right","Bottom","Left"];4>u;u+=2)"margin"===n&&(s+=i(n+l[u])),o?("content"===n&&(s-=i("padding"+l[u])),"margin"!==n&&(s-=i("border"+l[u]+"Width"))):(s+=i("padding"+l[u]),"padding"!==n&&(s+=i("border"+l[u]+"Width")));return s}function u(e){var t,n,o=e.getBoundingClientRect(),r=e&&e.ownerDocument;if(r)return t=r.documentElement,n=s(r),{top:o.top+n.pageYOffset-t.clientTop,left:o.left+n.pageXOffset-t.clientLeft}}function s(e){return null!=e&&e===e.window?e:9===e.nodeType&&e.defaultView}function l(e,t,n){var o=!0,r="width"===t?e.offsetWidth:e.offsetHeight,u=window.getComputedStyle(e,null),s=!1;if(0>=r||null==r){if(r=u[t],(0>r||null==r)&&(r=e.style[t]),g.test(r))return r;r=parseFloat(r)||0}return r+i(e,t,n||(s?"border":"content"),o,u)}function a(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t].length)return!1;return!0}function c(e){var t=[];return angular.forEach(e,function(e,n){"$"!==n.toString().charAt(0)&&t.push(e)}),t}function d(e,t,n,o,r){var i,u,s,l,a,c=r?[].concat(e):[];for(i=0,s=e.length;i=w&&l.contains(r[0],t.target,"select-dropdown")||(e.inputHide&&e.removeItem(0),!e.isOpen||!it.closeList||"INPUT"===t.target.nodeName&&e.query.length?Y(e.query):(J({query:it.editItem&&!st}),e.$evalAsync()))}function F(){e.isFocused||(e.isFocused=!0,c.disabled||(e.backspaceFocus=!1))}function k(){e.isFocused=!1,$||I(),L("blur")||J(),e.$evalAsync()}function q(e){return it.saveTrigger.split(" ").indexOf(e)+1}function L(o,r){r||(r=o,o=e.query);var i,u=q(r),s=it.newItem&&o,l=e.order[e.selectorPosition];return u&&(s||l)?(e.showLoader=!0,i=t.when(l||y(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&&K(tt,0),it.newItemFn&&!l||n(angular.noop),J()}).catch(function(){p("invalid-item"),e.showLoader=!1}),!0):void 0}function P(){var e=$&&d.$modelValue&&d.$modelValue.length?ot:nt;et.attr("placeholder",e)}function U(t){return l.getValue(S,t,e.$parent,D)}function j(t){return l.getValue(S,t,e.$parent,C)}function B(t){return String(l.getValue(S,t,e.$parent,A))}function W(t){return l.getValue(S,t,e.$parent,O)}function z(t){return l.getValue(S,t,e.$parent,H)||""}function X(t){return l.getValue(E,t,e.$parent,x)}function Y(o,r){var i=T(e.$parent,{$query:o,$selectedAs:r})||"",u=0;return e.selectorPosition="prompt"===it.newItem?!1:0,o||r||(e.oldQuery=null),m&&(i.$promise&&!i.$resolved||angular.isFunction(i.then))&&(n.cancel(m),u=it.debounce),m=n(function(){return e.showLoader=!0,t.when(i.$promise||i).then(function(t){if(!t)return e.groups={},void G();if(!r){var n=$?e.output:[],i=gt(l.objToArr(t),o,B,mt(e.$parent)),u=l.intersection(i,n,U,U,!0),s=X(u);e.groups=Z(s),G()}return t}).finally(function(){e.showLoader=!1,it.closeList&&!it.cleanModel&&n(function(){K(tt,0)})})},u)}function G(){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(angular.version.major<=1&&angular.version.minor<=3&&r.sort(),t=0;t=w)return void p("limited");var n=e.groups[z(t)]=e.groups[z(t)]||[],o=C?j(t):t;n.splice(n.indexOf(t),1),$?d.$setViewValue(angular.isArray(d.$modelValue)?d.$modelValue.concat(o):[o]):(d.$setViewValue(o),I()),l.groupsIsEmpty(e.groups)&&(e.groups={}),$||it.closeList||J({query:!0}),f(),e.oldQuery=e.oldQuery||e.query,e.query="",e.backspaceFocus=!1}},e.removeItem=function(n){c.disabled||$&&0>n||t.when(at(e.$parent,{$item:v})).then(function(){($||e.inputHide)&&($?(v=d.$modelValue[n],d.$modelValue.splice(n,1),d.$setViewValue([].concat(d.$modelValue))):(v=d.$modelValue,b(),it.cleanModel&&d.$setViewValue(void 0)),($||!e.backspaceFocus)&&(e.query=lt(v,h,B,st)||""),$&&it.closeList&&J({query:!0}))})},e.setSelection=function(t){Q||e.selectorPosition===t?Q=!1:K(tt,t)},e.keyUp=function(t){switch(t.keyCode){case 8:e.query.length||$&&e.output.length||J()}},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,K(tt,e.selectorPosition===n?o:e.selectorPosition-1),Q=!0;break;case 40:e.selectorPosition=angular.isNumber(e.selectorPosition)?e.selectorPosition:n-1,K(tt,e.selectorPosition===o?n:e.selectorPosition+1),Q=!0,e.query.length||e.isOpen||Y(),e.inputHide&&b();break;case 37:case 39:break;case 13:L("enter"),t.preventDefault();break;case 32:L("space");break;case 27:$||(I(),it.cleanModel&&d.$setViewValue(v)),J();break;case 8:if(!e.query.length){if((!$||ut)&&(e.backspaceFocus=!0),e.backspaceFocus&&e.output&&(!$||e.output.length)){e.removeItem(e.output.length-1),ut&&t.preventDefault();break}e.backspaceFocus=!e.backspaceFocus;break}default:return e.inputHide&&b(),e.backspaceFocus=!1,!1}},e.getSearchLabel=function(t){var n=B(t);return ct(n,e.oldQuery||e.query,t,dt(e.$parent))},e.getDropdownLabel=function(t){var n=B(t);return ft(n,e.oldQuery||e.query,t,pt(e.$parent))},e.getDisableWhen=W,J(),r[0].addEventListener("click",V,!0),r.on("focus",F),r.on("blur",k)}}}}]),angular.module("oi.select").filter("oiSelectCloseIcon",["$sce",function(e){return function(t){var n='×';return e.trustAsHtml(t+n)}}]).filter("oiSelectHighlight",["$sce",function(e){return function(t,n){var o;return n.length>0||angular.isNumber(n)?(t=t.toString(),n=n.toString().replace(/\s+.*/,"").replace(/\\/g,"\\\\"),o=t.replace(new RegExp(n,"gi"),"$&")):o=t,e.trustAsHtml(o)}}]).filter("oiSelectAscSort",function(){function e(e,t,n,o){var r,i,u,s,l=[],a=[],c=[];if(t){for(t=String(t).replace(/\s+.*/,"").replace(/\\/g,"\\\\"),r=0,u=!1;r