From b97ace1a141fdd970165e35e68d9b76fcca17bce Mon Sep 17 00:00:00 2001 From: Juan Pablo Solano Date: Thu, 18 Sep 2014 11:28:22 -0500 Subject: [PATCH 01/32] Replaces hash for 'javascript:;' in href To prevent the hash to reload the page --- src/select2/match-multiple.tpl.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/select2/match-multiple.tpl.html b/src/select2/match-multiple.tpl.html index d4a2217e7..53c8f21ae 100644 --- a/src/select2/match-multiple.tpl.html +++ b/src/select2/match-multiple.tpl.html @@ -7,6 +7,6 @@
  • - +
  • - \ No newline at end of file + From 64b6509495e1685e6aa9f6568126a36efdddfcbb Mon Sep 17 00:00:00 2001 From: Thomas Vervest Date: Mon, 6 Oct 2014 00:28:04 +0200 Subject: [PATCH 02/32] Fixed issues with asynchronous data sources (for example $resource) --- dist/select.css | 9 +- dist/{select.min.css => select.css.min.css} | 4 +- dist/select.js | 100 ++++++++++++++------ dist/select.js.min.js | 7 ++ dist/select.min.js | 7 -- src/select.js | 15 +-- 6 files changed, 99 insertions(+), 43 deletions(-) rename dist/{select.min.css => select.css.min.css} (84%) create mode 100755 dist/select.js.min.js delete mode 100755 dist/select.min.js diff --git a/dist/select.css b/dist/select.css index 43216a153..aed426c51 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.7.0 - 2014-09-09T01:02:43.612Z + * Version: 0.7.0 - 2014-10-05T22:23:08.004Z * License: MIT */ @@ -144,6 +144,13 @@ background-color: #428bca; } +.ui-select-bootstrap .ui-select-choices-row.disabled>a, +.ui-select-bootstrap .ui-select-choices-row.active.disabled>a { + color: #777; + cursor: not-allowed; + background-color: #fff; +} + /* fix hide/show angular animation */ .ui-select-match.ng-hide-add, .ui-select-search.ng-hide-add { diff --git a/dist/select.min.css b/dist/select.css.min.css similarity index 84% rename from dist/select.min.css rename to dist/select.css.min.css index 8b0c793e2..718b1d3c8 100644 --- a/dist/select.min.css +++ b/dist/select.css.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.7.0 - 2014-09-09T01:02:43.612Z + * Version: 0.7.0 - 2014-10-05T22:23:08.004Z * License: MIT - */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file + */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.js b/dist/select.js index ad1611186..a86f0f0fd 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.7.0 - 2014-09-09T01:02:43.608Z + * Version: 0.7.0 - 2014-10-05T22:23:07.998Z * License: MIT */ @@ -164,6 +164,7 @@ ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function ctrl.refreshDelay = undefined; // Initialized inside uiSelectChoices directive link function ctrl.multiple = false; // Initialized inside uiSelect directive link function + ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelect directive link function ctrl.isEmpty = function() { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; @@ -270,6 +271,7 @@ $scope.$watchCollection('$select.selected', function(selectedItems){ if (!selectedItems) return; var data = ctrl.parserResult.source($scope); + if (!data) return; var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;}); setItemsFn(filteredItems); }); @@ -307,24 +309,40 @@ return ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; }; + ctrl.isDisabled = function(itemScope) { + var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + var isDisabled = false; + var item; + + if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { + item = ctrl.items[itemIndex]; + isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value + item._uiSelectChoiceDisabled = isDisabled; // store this for later reference + } + + return isDisabled; + }; + // When the user clicks on an item inside the dropdown ctrl.select = function(item) { - var locals = {}; - locals[ctrl.parserResult.itemName] = item; + if (!item._uiSelectChoiceDisabled) { + var locals = {}; + locals[ctrl.parserResult.itemName] = item; - ctrl.onSelectCallback($scope, { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }); + ctrl.onSelectCallback($scope, { + $item: item, + $model: ctrl.parserResult.modelMapper($scope, locals) + }); - if(ctrl.multiple){ - ctrl.selected.push(item); - ctrl.sizeSearchInput(); - } else { - ctrl.selected = item; + if(ctrl.multiple){ + ctrl.selected.push(item); + ctrl.sizeSearchInput(); + } else { + ctrl.selected = item; + } + ctrl.close(); } - ctrl.close(); }; // Closes the dropdown @@ -338,6 +356,13 @@ } }; + // Toggle dropdown + ctrl.toggle = function(e) { + if (ctrl.open) ctrl.close(); else ctrl.activate(); + e.preventDefault(); + e.stopPropagation(); + }; + // Remove item from multiple select ctrl.removeChoice = function(index){ ctrl.selected.splice(index, 1); @@ -347,7 +372,7 @@ ctrl.getPlaceholder = function(){ //Refactor single? - if(ctrl.multiple && ctrl.selected.length) return; + if(ctrl.multiple && (ctrl.selected === undefined || ctrl.selected.length)) return; return ctrl.placeholder; }; @@ -550,6 +575,8 @@ var $select = ctrls[0]; var ngModel = ctrls[1]; + var searchInput = element.querySelectorAll('input.ui-select-search'); + $select.multiple = angular.isDefined(attrs.multiple); $select.onSelectCallback = $parse(attrs.onSelect); @@ -560,11 +587,13 @@ result; if ($select.multiple){ var resultMultiple = []; - for (var j = inputValue.length - 1; j >= 0; j--) { - locals = {}; - locals[$select.parserResult.itemName] = inputValue[j]; - result = $select.parserResult.modelMapper(scope, locals); - resultMultiple.unshift(result); + if (inputValue) { + for (var j = inputValue.length - 1; j >= 0; j--) { + locals = {}; + locals[$select.parserResult.itemName] = inputValue[j]; + result = $select.parserResult.modelMapper(scope, locals); + resultMultiple.unshift(result); + } } return resultMultiple; }else{ @@ -625,6 +654,21 @@ //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 var focusser = angular.element(""); + + if(attrs.tabindex){ + //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex + attrs.$observe('tabindex', function(value) { + //If we are using multiple, add tabindex to the search input + if($select.multiple){ + searchInput.attr("tabindex", value); + } else { + focusser.attr("tabindex", value); + } + //Remove the tabindex on the parent so that it is not focusable + element.removeAttr("tabindex"); + }); + } + $compile(focusser)(scope); $select.focusser = focusser; @@ -802,6 +846,8 @@ $select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult + $select.disableChoiceExpression = attrs.uiDisableChoice; + if(groupByExp) { var groups = element.querySelectorAll('.ui-select-choices-group'); if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); @@ -890,16 +936,16 @@ }); }()); -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html",""); -$templateCache.put("bootstrap/match-multiple.tpl.html",""); -$templateCache.put("bootstrap/match.tpl.html",""); +angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html",""); +$templateCache.put("bootstrap/match-multiple.tpl.html",""); +$templateCache.put("bootstrap/match.tpl.html",""); $templateCache.put("bootstrap/select-multiple.tpl.html","
    "); $templateCache.put("bootstrap/select.tpl.html","
    "); -$templateCache.put("select2/choices.tpl.html",""); -$templateCache.put("select2/match-multiple.tpl.html","
  • "); -$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); +$templateCache.put("select2/choices.tpl.html",""); +$templateCache.put("select2/match-multiple.tpl.html","
  • "); +$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); $templateCache.put("select2/select-multiple.tpl.html","
    "); $templateCache.put("select2/select.tpl.html","
    "); -$templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); +$templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); $templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file +$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.js.min.js b/dist/select.js.min.js new file mode 100755 index 000000000..b3da9c5d2 --- /dev/null +++ b/dist/select.js.min.js @@ -0,0 +1,7 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.7.0 - 2014-10-05T22:23:07.998Z + * License: MIT + */ +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,isControl:function(t){var c=t.which;switch(c){case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0&&d.activeIndex--;break;case e.TAB:d.multiple||d.select(d.items[d.activeIndex]);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){if(e){var c=d.parserResult.source(t);if(c){var s=c.filter(function(t){return e.indexOf(t)<0});a(s)}}})};var v;d.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s},d.select=function(e){if(!e._uiSelectChoiceDisabled){var c={};c[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,c)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close()}},d.close=function(){d.open&&(n(),d.open=!1,s(function(){d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput()},d.getPlaceholder=function(){return!d.multiple||void 0!==d.selected&&!d.selected.length?d.placeholder:void 0},d.sizeSearchInput=function(){var e=h[0],t=h.parent().parent()[0];h.css("width","10px"),s(function(){var c=t.clientWidth-e.offsetLeft-10;50>c&&(c=t.clientWidth),h.css("width",c+"px")},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&d.items.length>0&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&d.items.length>0&&u()}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1,d.activeIndex=0})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple),d.onSelectCallback=i(a.onSelect),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){var l=[];if(e)for(var i=e.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=e[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var v=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):v.attr("tabindex",e),n.removeAttr("tabindex")}),l(v)(c),d.focusser=v,d.multiple||(n.append(v),v.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),v.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$digest(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(v.val()),v.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),d.multiple?(c.$watchCollection("$select.selected",function(e){p.$setViewValue(e,null,!0)}),v.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",''),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js deleted file mode 100755 index 18691097b..000000000 --- a/dist/select.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.7.0 - 2014-09-09T01:02:43.608Z - * License: MIT - */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,isControl:function(t){var c=t.which;switch(c){case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){p.resetSearchInput&&(p.search=d,p.selected&&p.items.length&&!p.multiple&&(p.activeIndex=p.items.indexOf(p.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!p.open&&p.multiple?p.activate(!1,!0):p.activeIndex0&&p.activeIndex--;break;case e.TAB:p.multiple||p.select(p.items[p.activeIndex]);break;case e.ENTER:p.open?p.select(p.items[p.activeIndex]):p.activate(!1,!0);break;case e.ESC:p.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?u:n;case e.RIGHT:return~p.activeMatchIndex&&a!==n?r:(p.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),u):n;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var s=o(h[0]),l=p.selected.length,i=0,n=l-1,a=p.activeMatchIndex,r=p.activeMatchIndex+1,u=p.activeMatchIndex-1,d=a;return s>0||p.search.length&&t==e.RIGHT?!1:(p.close(),d=c(),p.activeMatchIndex=p.selected.length&&d!==!1?Math.min(n,Math.max(i,d)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[p.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=p.items.length?0:p.activeIndex,s(function(){p.search=e||p.search,h[0].focus()}))},p.findGroupByName=function(e){return p.groups&&p.groups.filter(function(t){return t.name===e})[0]},p.parseRepeatAttr=function(e,c){function s(e){p.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=p.findGroupByName(l);i?i.items.push(e):p.groups.push({name:l,items:[e]})}),p.items=[],p.groups.forEach(function(e){p.items=p.items.concat(e.items)})}function n(e){p.items=e}var a=c?s:n;p.parserResult=l.parse(e),p.isGrouped=!!c,p.itemProperty=p.parserResult.itemName,t.$watchCollection(p.parserResult.source,function(e){if(void 0===e||null===e)p.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(p.multiple){var t=e.filter(function(e){return p.selected.indexOf(e)<0});a(t)}else a(e);p.ngModel.$modelValue=null}}),p.multiple&&t.$watchCollection("$select.selected",function(e){if(e){var c=p.parserResult.source(t),s=c.filter(function(t){return e.indexOf(t)<0});a(s)}})};var v;p.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},p.refreshDelay))},p.setActiveItem=function(e){p.activeIndex=p.items.indexOf(e)},p.isActive=function(e){return p.items.indexOf(e[p.itemProperty])===p.activeIndex},p.select=function(e){var c={};c[p.parserResult.itemName]=e,p.onSelectCallback(t,{$item:e,$model:p.parserResult.modelMapper(t,c)}),p.multiple?(p.selected.push(e),p.sizeSearchInput()):p.selected=e,p.close()},p.close=function(){p.open&&(n(),p.open=!1,s(function(){p.focusser[0].focus()},0,!1))},p.removeChoice=function(e){p.selected.splice(e,1),p.activeMatchIndex=-1,p.sizeSearchInput()},p.getPlaceholder=function(){return p.multiple&&p.selected.length?void 0:p.placeholder},p.sizeSearchInput=function(){var e=h[0],t=h.parent().parent()[0];h.css("width","10px"),s(function(){var c=t.clientWidth-e.offsetLeft-10;50>c&&(c=t.clientWidth),h.css("width",c+"px")},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;p.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&p.items.length>0&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&p.items.length>0&&u()}),h.on("blur",function(){s(function(){p.activeMatchIndex=-1,p.activeIndex=0})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(p.close(),c.$digest())}var p=r[0],d=r[1];p.multiple=angular.isDefined(a.multiple),p.onSelectCallback=i(a.onSelect),d.$parsers.unshift(function(e){var t,s={};if(p.multiple){for(var l=[],i=e.length-1;i>=0;i--)s={},s[p.parserResult.itemName]=e[i],t=p.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[p.parserResult.itemName]=e,t=p.parserResult.modelMapper(c,s)}),d.$formatters.unshift(function(e){var t,s=p.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(p.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[p.parserResult.itemName]=e[n],t=p.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(p.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[p.parserResult.itemName]=s,t=p.parserResult.modelMapper(c,l),t==e};if(p.selected&&r(p.selected))return p.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),p.ngModel=d;var h=angular.element("");l(h)(c),p.focusser=h,p.multiple||(n.append(h),h.bind("focus",function(){c.$evalAsync(function(){p.focus=!0})}),h.bind("blur",function(){c.$evalAsync(function(){p.focus=!1})}),h.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),p.select(void 0),void c.$digest()):void(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),p.activate()),c.$digest()))}),h.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(p.activate(h.val()),h.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);p.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){p.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);p.resetSearchInput=void 0!==e?e:!0}),p.multiple?(c.$watchCollection("$select.selected",function(e){d.$setViewValue(e,null,!0)}),h.prop("disabled",!0)):c.$watch("$select.selected",function(e){d.$viewValue!==e&&d.$setViewValue(e)}),d.$render=function(){if(p.multiple&&!angular.isArray(d.$viewValue)){if(!angular.isUndefined(d.$viewValue)&&null!==d.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",d.$viewValue);p.selected=[]}p.selected=d.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var d=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",''),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/src/select.js b/src/select.js index abbdf8e22..e1df1163e 100644 --- a/src/select.js +++ b/src/select.js @@ -263,6 +263,7 @@ $scope.$watchCollection('$select.selected', function(selectedItems){ if (!selectedItems) return; var data = ctrl.parserResult.source($scope); + if (!data) return; var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;}); setItemsFn(filteredItems); }); @@ -363,7 +364,7 @@ ctrl.getPlaceholder = function(){ //Refactor single? - if(ctrl.multiple && ctrl.selected.length) return; + if(ctrl.multiple && (ctrl.selected === undefined || ctrl.selected.length)) return; return ctrl.placeholder; }; @@ -578,11 +579,13 @@ result; if ($select.multiple){ var resultMultiple = []; - for (var j = inputValue.length - 1; j >= 0; j--) { - locals = {}; - locals[$select.parserResult.itemName] = inputValue[j]; - result = $select.parserResult.modelMapper(scope, locals); - resultMultiple.unshift(result); + if (inputValue) { + for (var j = inputValue.length - 1; j >= 0; j--) { + locals = {}; + locals[$select.parserResult.itemName] = inputValue[j]; + result = $select.parserResult.modelMapper(scope, locals); + resultMultiple.unshift(result); + } } return resultMultiple; }else{ From fe941d814121a2f0daf5cc5857da67b545d5b84b Mon Sep 17 00:00:00 2001 From: Thomas Vervest Date: Mon, 6 Oct 2014 12:49:55 +0200 Subject: [PATCH 03/32] re-applied changes from angular-ui/ui-select#63 --- dist/select.css | 9 +- dist/{select.min.css => select.css.min.css} | 4 +- dist/select.js | 107 +++++++++++++++----- dist/select.js.min.js | 7 ++ dist/select.min.js | 7 -- src/select.js | 24 ++++- test/select.spec.js | 34 +++++++ 7 files changed, 156 insertions(+), 36 deletions(-) rename dist/{select.min.css => select.css.min.css} (84%) create mode 100755 dist/select.js.min.js delete mode 100755 dist/select.min.js diff --git a/dist/select.css b/dist/select.css index 43216a153..044d99241 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.7.0 - 2014-09-09T01:02:43.612Z + * Version: 0.7.0 - 2014-10-06T10:45:08.128Z * License: MIT */ @@ -144,6 +144,13 @@ background-color: #428bca; } +.ui-select-bootstrap .ui-select-choices-row.disabled>a, +.ui-select-bootstrap .ui-select-choices-row.active.disabled>a { + color: #777; + cursor: not-allowed; + background-color: #fff; +} + /* fix hide/show angular animation */ .ui-select-match.ng-hide-add, .ui-select-search.ng-hide-add { diff --git a/dist/select.min.css b/dist/select.css.min.css similarity index 84% rename from dist/select.min.css rename to dist/select.css.min.css index 8b0c793e2..c2cea258a 100644 --- a/dist/select.min.css +++ b/dist/select.css.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.7.0 - 2014-09-09T01:02:43.612Z + * Version: 0.7.0 - 2014-10-06T10:45:08.128Z * License: MIT - */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file + */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.js b/dist/select.js index ad1611186..5eef697f1 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.7.0 - 2014-09-09T01:02:43.608Z + * Version: 0.7.0 - 2014-10-06T10:45:08.127Z * License: MIT */ @@ -164,6 +164,7 @@ ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function ctrl.refreshDelay = undefined; // Initialized inside uiSelectChoices directive link function ctrl.multiple = false; // Initialized inside uiSelect directive link function + ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelect directive link function ctrl.isEmpty = function() { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; @@ -307,24 +308,45 @@ return ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; }; + ctrl.isDisabled = function(itemScope) { + var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + var isDisabled = false; + var item; + + if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) { + item = ctrl.items[itemIndex]; + isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value + item._uiSelectChoiceDisabled = isDisabled; // store this for later reference + } + + return isDisabled; + }; + // When the user clicks on an item inside the dropdown ctrl.select = function(item) { - var locals = {}; - locals[ctrl.parserResult.itemName] = item; + if (!item || !item._uiSelectChoiceDisabled) { + if(ctrl.tagging.isActivated && !item && ctrl.search.length > 0) { + // create new item on the fly + item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + } - ctrl.onSelectCallback($scope, { - $item: item, - $model: ctrl.parserResult.modelMapper($scope, locals) - }); + var locals = {}; + locals[ctrl.parserResult.itemName] = item; - if(ctrl.multiple){ - ctrl.selected.push(item); - ctrl.sizeSearchInput(); - } else { - ctrl.selected = item; + ctrl.onSelectCallback($scope, { + $item: item, + $model: ctrl.parserResult.modelMapper($scope, locals) + }); + + if(ctrl.multiple){ + ctrl.selected.push(item); + ctrl.sizeSearchInput(); + } else { + ctrl.selected = item; + } + ctrl.close(); } - ctrl.close(); }; // Closes the dropdown @@ -338,6 +360,13 @@ } }; + // Toggle dropdown + ctrl.toggle = function(e) { + if (ctrl.open) ctrl.close(); else ctrl.activate(); + e.preventDefault(); + e.stopPropagation(); + }; + // Remove item from multiple select ctrl.removeChoice = function(index){ ctrl.selected.splice(index, 1); @@ -371,7 +400,7 @@ break; case KEY.UP: if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode - else if (ctrl.activeIndex > 0) { ctrl.activeIndex--; } + else if (ctrl.activeIndex > 0 || (ctrl.search.length === 0 && ctrl.tagging.isActivated)) { ctrl.activeIndex--; } break; case KEY.TAB: //TODO: Que hacemos en modo multiple? @@ -550,6 +579,8 @@ var $select = ctrls[0]; var ngModel = ctrls[1]; + var searchInput = element.querySelectorAll('input.ui-select-search'); + $select.multiple = angular.isDefined(attrs.multiple); $select.onSelectCallback = $parse(attrs.onSelect); @@ -625,6 +656,21 @@ //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954 var focusser = angular.element(""); + + if(attrs.tabindex){ + //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex + attrs.$observe('tabindex', function(value) { + //If we are using multiple, add tabindex to the search input + if($select.multiple){ + searchInput.attr("tabindex", value); + } else { + focusser.attr("tabindex", value); + } + //Remove the tabindex on the parent so that it is not focusable + element.removeAttr("tabindex"); + }); + } + $compile(focusser)(scope); $select.focusser = focusser; @@ -695,6 +741,19 @@ $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; }); + attrs.$observe('tagging', function() { + if(attrs.tagging !== undefined) + { + // $eval() is needed otherwise we get a string instead of a function or a boolean + var taggingEval = scope.$eval(attrs.tagging); + $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined}; + } + else + { + $select.tagging = {isActivated: false, fct: undefined}; + } + }); + if ($select.multiple){ scope.$watchCollection('$select.selected', function(newValue) { //On v1.2.19 the 2nd and 3rd parameteres are ignored @@ -802,6 +861,8 @@ $select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult + $select.disableChoiceExpression = attrs.uiDisableChoice; + if(groupByExp) { var groups = element.querySelectorAll('.ui-select-choices-group'); if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); @@ -825,7 +886,7 @@ scope.$watch('$select.search', function(newValue) { if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = 0; + $select.activeIndex = $select.tagging.isActivated ? -1 : 0; $select.refresh(attrs.refresh); }); @@ -890,16 +951,16 @@ }); }()); -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
      0\">
    • 0\">
      {{$group.name}}
    "); -$templateCache.put("bootstrap/match-multiple.tpl.html",""); -$templateCache.put("bootstrap/match.tpl.html",""); +angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
      0\">
    • 0\">
      {{$group.name}}
    "); +$templateCache.put("bootstrap/match-multiple.tpl.html",""); +$templateCache.put("bootstrap/match.tpl.html",""); $templateCache.put("bootstrap/select-multiple.tpl.html","
    "); $templateCache.put("bootstrap/select.tpl.html","
    "); -$templateCache.put("select2/choices.tpl.html","
    • {{$group.name}}
    "); -$templateCache.put("select2/match-multiple.tpl.html","
  • "); -$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); +$templateCache.put("select2/choices.tpl.html","
    • {{$group.name}}
    "); +$templateCache.put("select2/match-multiple.tpl.html","
  • "); +$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); $templateCache.put("select2/select-multiple.tpl.html","
    "); $templateCache.put("select2/select.tpl.html","
    "); -$templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); +$templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); $templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file +$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.js.min.js b/dist/select.js.min.js new file mode 100755 index 000000000..0a4d2d5ea --- /dev/null +++ b/dist/select.js.min.js @@ -0,0 +1,7 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.7.0 - 2014-10-06T10:45:08.127Z + * License: MIT + */ +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,isControl:function(t){var c=t.which;switch(c){case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:d.multiple||d.select(d.items[d.activeIndex]);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){if(e){var c=d.parserResult.source(t),s=c.filter(function(t){return e.indexOf(t)<0});a(s)}})};var v;d.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s},d.select=function(e){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var c={};c[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,c)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close()}},d.close=function(){d.open&&(n(),d.open=!1,s(function(){d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput()},d.getPlaceholder=function(){return d.multiple&&d.selected.length?void 0:d.placeholder},d.sizeSearchInput=function(){var e=h[0],t=h.parent().parent()[0];h.css("width","10px"),s(function(){var c=t.clientWidth-e.offsetLeft-10;50>c&&(c=t.clientWidth),h.css("width",c+"px")},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&d.items.length>0&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&d.items.length>0&&u()}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1,d.activeIndex=0})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple),d.onSelectCallback=i(a.onSelect),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=e.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=e[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var v=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):v.attr("tabindex",e),n.removeAttr("tabindex")}),l(v)(c),d.focusser=v,d.multiple||(n.append(v),v.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),v.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$digest(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(v.val()),v.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),d.multiple?(c.$watchCollection("$select.selected",function(e){p.$setViewValue(e,null,!0)}),v.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",''),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js deleted file mode 100755 index 18691097b..000000000 --- a/dist/select.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.7.0 - 2014-09-09T01:02:43.608Z - * License: MIT - */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,isControl:function(t){var c=t.which;switch(c){case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){p.resetSearchInput&&(p.search=d,p.selected&&p.items.length&&!p.multiple&&(p.activeIndex=p.items.indexOf(p.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!p.open&&p.multiple?p.activate(!1,!0):p.activeIndex0&&p.activeIndex--;break;case e.TAB:p.multiple||p.select(p.items[p.activeIndex]);break;case e.ENTER:p.open?p.select(p.items[p.activeIndex]):p.activate(!1,!0);break;case e.ESC:p.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?u:n;case e.RIGHT:return~p.activeMatchIndex&&a!==n?r:(p.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),u):n;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var s=o(h[0]),l=p.selected.length,i=0,n=l-1,a=p.activeMatchIndex,r=p.activeMatchIndex+1,u=p.activeMatchIndex-1,d=a;return s>0||p.search.length&&t==e.RIGHT?!1:(p.close(),d=c(),p.activeMatchIndex=p.selected.length&&d!==!1?Math.min(n,Math.max(i,d)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[p.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=p.items.length?0:p.activeIndex,s(function(){p.search=e||p.search,h[0].focus()}))},p.findGroupByName=function(e){return p.groups&&p.groups.filter(function(t){return t.name===e})[0]},p.parseRepeatAttr=function(e,c){function s(e){p.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=p.findGroupByName(l);i?i.items.push(e):p.groups.push({name:l,items:[e]})}),p.items=[],p.groups.forEach(function(e){p.items=p.items.concat(e.items)})}function n(e){p.items=e}var a=c?s:n;p.parserResult=l.parse(e),p.isGrouped=!!c,p.itemProperty=p.parserResult.itemName,t.$watchCollection(p.parserResult.source,function(e){if(void 0===e||null===e)p.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(p.multiple){var t=e.filter(function(e){return p.selected.indexOf(e)<0});a(t)}else a(e);p.ngModel.$modelValue=null}}),p.multiple&&t.$watchCollection("$select.selected",function(e){if(e){var c=p.parserResult.source(t),s=c.filter(function(t){return e.indexOf(t)<0});a(s)}})};var v;p.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},p.refreshDelay))},p.setActiveItem=function(e){p.activeIndex=p.items.indexOf(e)},p.isActive=function(e){return p.items.indexOf(e[p.itemProperty])===p.activeIndex},p.select=function(e){var c={};c[p.parserResult.itemName]=e,p.onSelectCallback(t,{$item:e,$model:p.parserResult.modelMapper(t,c)}),p.multiple?(p.selected.push(e),p.sizeSearchInput()):p.selected=e,p.close()},p.close=function(){p.open&&(n(),p.open=!1,s(function(){p.focusser[0].focus()},0,!1))},p.removeChoice=function(e){p.selected.splice(e,1),p.activeMatchIndex=-1,p.sizeSearchInput()},p.getPlaceholder=function(){return p.multiple&&p.selected.length?void 0:p.placeholder},p.sizeSearchInput=function(){var e=h[0],t=h.parent().parent()[0];h.css("width","10px"),s(function(){var c=t.clientWidth-e.offsetLeft-10;50>c&&(c=t.clientWidth),h.css("width",c+"px")},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;p.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&p.items.length>0&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&p.items.length>0&&u()}),h.on("blur",function(){s(function(){p.activeMatchIndex=-1,p.activeIndex=0})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(p.close(),c.$digest())}var p=r[0],d=r[1];p.multiple=angular.isDefined(a.multiple),p.onSelectCallback=i(a.onSelect),d.$parsers.unshift(function(e){var t,s={};if(p.multiple){for(var l=[],i=e.length-1;i>=0;i--)s={},s[p.parserResult.itemName]=e[i],t=p.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[p.parserResult.itemName]=e,t=p.parserResult.modelMapper(c,s)}),d.$formatters.unshift(function(e){var t,s=p.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(p.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[p.parserResult.itemName]=e[n],t=p.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(p.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[p.parserResult.itemName]=s,t=p.parserResult.modelMapper(c,l),t==e};if(p.selected&&r(p.selected))return p.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),p.ngModel=d;var h=angular.element("");l(h)(c),p.focusser=h,p.multiple||(n.append(h),h.bind("focus",function(){c.$evalAsync(function(){p.focus=!0})}),h.bind("blur",function(){c.$evalAsync(function(){p.focus=!1})}),h.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),p.select(void 0),void c.$digest()):void(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),p.activate()),c.$digest()))}),h.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(p.activate(h.val()),h.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);p.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){p.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);p.resetSearchInput=void 0!==e?e:!0}),p.multiple?(c.$watchCollection("$select.selected",function(e){d.$setViewValue(e,null,!0)}),h.prop("disabled",!0)):c.$watch("$select.selected",function(e){d.$viewValue!==e&&d.$setViewValue(e)}),d.$render=function(){if(p.multiple&&!angular.isArray(d.$viewValue)){if(!angular.isUndefined(d.$viewValue)&&null!==d.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",d.$viewValue);p.selected=[]}p.selected=d.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var d=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",''),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/src/select.js b/src/select.js index abbdf8e22..254eddf1e 100644 --- a/src/select.js +++ b/src/select.js @@ -317,7 +317,12 @@ // When the user clicks on an item inside the dropdown ctrl.select = function(item) { - if (!item._uiSelectChoiceDisabled) { + if (!item || !item._uiSelectChoiceDisabled) { + if(ctrl.tagging.isActivated && !item && ctrl.search.length > 0) { + // create new item on the fly + item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + } + var locals = {}; locals[ctrl.parserResult.itemName] = item; @@ -387,7 +392,7 @@ break; case KEY.UP: if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode - else if (ctrl.activeIndex > 0) { ctrl.activeIndex--; } + else if (ctrl.activeIndex > 0 || (ctrl.search.length === 0 && ctrl.tagging.isActivated)) { ctrl.activeIndex--; } break; case KEY.TAB: //TODO: Que hacemos en modo multiple? @@ -728,6 +733,19 @@ $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; }); + attrs.$observe('tagging', function() { + if(attrs.tagging !== undefined) + { + // $eval() is needed otherwise we get a string instead of a function or a boolean + var taggingEval = scope.$eval(attrs.tagging); + $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined}; + } + else + { + $select.tagging = {isActivated: false, fct: undefined}; + } + }); + if ($select.multiple){ scope.$watchCollection('$select.selected', function(newValue) { //On v1.2.19 the 2nd and 3rd parameteres are ignored @@ -860,7 +878,7 @@ scope.$watch('$select.search', function(newValue) { if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = 0; + $select.activeIndex = $select.tagging.isActivated ? -1 : 0; $select.refresh(attrs.refresh); }); diff --git a/test/select.spec.js b/test/select.spec.js index f2f4f2690..17f404d72 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -67,6 +67,7 @@ describe('ui-select tests', function() { if (attrs.required !== undefined) { attrsHtml += ' ng-required="' + attrs.required + '"'; } if (attrs.theme !== undefined) { attrsHtml += ' theme="' + attrs.theme + '"'; } if (attrs.tabindex !== undefined) { attrsHtml += ' tabindex="' + attrs.tabindex + '"'; } + if (attrs.tagging !== undefined) { attrsHtml += ' tagging="' + attrs.tagging + '"'; } } return compileTemplate( @@ -246,6 +247,39 @@ describe('ui-select tests', function() { expect(isDropdownOpened(el3)).toEqual(true); }); + it('should allow tagging if the attribute says so', function() { + var el = createUiSelect({tagging: true}); + clickMatch(el); + + $(el).scope().$select.select("I don't exist"); + + expect($(el).scope().$select.selected).toEqual("I don't exist"); + }); + + it('should format new items using the tagging function when the attribute is a function', function() { + scope.taggingFunc = function (name) { + return { + name: name, + email: name + '@email.com', + group: 'Foo', + age: 12 + }; + }; + + var el = createUiSelect({tagging: 'taggingFunc'}); + clickMatch(el); + + $(el).scope().$select.search = 'idontexist'; + $(el).scope().$select.select(); + + expect($(el).scope().$select.selected).toEqual({ + name: 'idontexist', + email: 'idontexist@email.com', + group: 'Foo', + age: 12 + }); + }); + // See when an item that evaluates to false (such as "false" or "no") is selected, the placeholder is shown https://github.com/angular-ui/ui-select/pull/32 it('should not display the placeholder when item evaluates to false', function() { scope.items = ['false']; From 17a2e6e2db78de3956fb10d297aef601a14f06e3 Mon Sep 17 00:00:00 2001 From: Thomas Vervest Date: Mon, 6 Oct 2014 14:30:45 +0200 Subject: [PATCH 04/32] Fixed small bug where pressing enter would not save the tag --- dist/select.css | 2 +- dist/select.css.min.css | 2 +- dist/select.js | 4 ++-- dist/select.js.min.js | 4 ++-- src/select.js | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dist/select.css b/dist/select.css index 044d99241..e98302d0c 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.7.0 - 2014-10-06T10:45:08.128Z + * Version: 0.7.0 - 2014-10-06T12:29:59.832Z * License: MIT */ diff --git a/dist/select.css.min.css b/dist/select.css.min.css index c2cea258a..181465e97 100644 --- a/dist/select.css.min.css +++ b/dist/select.css.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.7.0 - 2014-10-06T10:45:08.128Z + * Version: 0.7.0 - 2014-10-06T12:29:59.832Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.js b/dist/select.js index 5eef697f1..8b9f1c3ab 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.7.0 - 2014-10-06T10:45:08.127Z + * Version: 0.7.0 - 2014-10-06T12:29:59.829Z * License: MIT */ @@ -499,7 +499,7 @@ processed = _handleMatchSelection(key); } - if (!processed && ctrl.items.length > 0) { + if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); } diff --git a/dist/select.js.min.js b/dist/select.js.min.js index 0a4d2d5ea..e99b45e53 100755 --- a/dist/select.js.min.js +++ b/dist/select.js.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.7.0 - 2014-10-06T10:45:08.127Z + * Version: 0.7.0 - 2014-10-06T12:29:59.829Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,isControl:function(t){var c=t.which;switch(c){case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:d.multiple||d.select(d.items[d.activeIndex]);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){if(e){var c=d.parserResult.source(t),s=c.filter(function(t){return e.indexOf(t)<0});a(s)}})};var v;d.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s},d.select=function(e){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var c={};c[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,c)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close()}},d.close=function(){d.open&&(n(),d.open=!1,s(function(){d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput()},d.getPlaceholder=function(){return d.multiple&&d.selected.length?void 0:d.placeholder},d.sizeSearchInput=function(){var e=h[0],t=h.parent().parent()[0];h.css("width","10px"),s(function(){var c=t.clientWidth-e.offsetLeft-10;50>c&&(c=t.clientWidth),h.css("width",c+"px")},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&d.items.length>0&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&d.items.length>0&&u()}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1,d.activeIndex=0})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple),d.onSelectCallback=i(a.onSelect),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=e.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=e[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var v=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):v.attr("tabindex",e),n.removeAttr("tabindex")}),l(v)(c),d.focusser=v,d.multiple||(n.append(v),v.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),v.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$digest(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(v.val()),v.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),d.multiple?(c.$watchCollection("$select.selected",function(e){p.$setViewValue(e,null,!0)}),v.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",''),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,isControl:function(t){var c=t.which;switch(c){case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:d.multiple||d.select(d.items[d.activeIndex]);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){if(e){var c=d.parserResult.source(t),s=c.filter(function(t){return e.indexOf(t)<0});a(s)}})};var v;d.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s},d.select=function(e){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var c={};c[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,c)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close()}},d.close=function(){d.open&&(n(),d.open=!1,s(function(){d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput()},d.getPlaceholder=function(){return d.multiple&&d.selected.length?void 0:d.placeholder},d.sizeSearchInput=function(){var e=h[0],t=h.parent().parent()[0];h.css("width","10px"),s(function(){var c=t.clientWidth-e.offsetLeft-10;50>c&&(c=t.clientWidth),h.css("width",c+"px")},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&d.items.length>0&&u()}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1,d.activeIndex=0})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple),d.onSelectCallback=i(a.onSelect),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=e.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=e[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var v=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):v.attr("tabindex",e),n.removeAttr("tabindex")}),l(v)(c),d.focusser=v,d.multiple||(n.append(v),v.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),v.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$digest(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(v.val()),v.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),d.multiple?(c.$watchCollection("$select.selected",function(e){p.$setViewValue(e,null,!0)}),v.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",''),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/src/select.js b/src/select.js index 254eddf1e..e16d1f7dc 100644 --- a/src/select.js +++ b/src/select.js @@ -491,7 +491,7 @@ processed = _handleMatchSelection(key); } - if (!processed && ctrl.items.length > 0) { + if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); } From 9ccfcc90898a28f299f4f8afcf630ef09ea3b7e8 Mon Sep 17 00:00:00 2001 From: Thomas Vervest Date: Tue, 7 Oct 2014 15:46:43 +0200 Subject: [PATCH 05/32] added initialisation value for tagging --- dist/select.css | 2 +- dist/select.css.min.css | 2 +- dist/select.js | 4 +++- dist/select.js.min.js | 4 ++-- src/select.js | 2 ++ 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dist/select.css b/dist/select.css index 2d9965720..7fa3aaf81 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.0 - 2014-10-07T13:28:21.748Z + * Version: 0.8.0 - 2014-10-07T13:45:31.567Z * License: MIT */ diff --git a/dist/select.css.min.css b/dist/select.css.min.css index 590d347bd..a313b8228 100644 --- a/dist/select.css.min.css +++ b/dist/select.css.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.0 - 2014-10-07T13:28:21.748Z + * Version: 0.8.0 - 2014-10-07T13:45:31.567Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.js b/dist/select.js index 6eda64c59..12a85e39e 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.0 - 2014-10-07T13:28:21.745Z + * Version: 0.8.0 - 2014-10-07T13:45:31.563Z * License: MIT */ @@ -587,6 +587,8 @@ $select.onSelectCallback = $parse(attrs.onSelect); + $select.tagging = {isActivated: false, fct: undefined}; + //From view --> model ngModel.$parsers.unshift(function (inputValue) { var locals = {}, diff --git a/dist/select.js.min.js b/dist/select.js.min.js index af85a345f..4ab930783 100755 --- a/dist/select.js.min.js +++ b/dist/select.js.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.0 - 2014-10-07T13:28:21.745Z + * Version: 0.8.0 - 2014-10-07T13:45:31.563Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,isControl:function(t){var c=t.which;switch(c){case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:d.multiple||d.select(d.items[d.activeIndex]);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){if(e.length){var c=d.parserResult.source(t);if(c){var s=c.filter(function(t){return e.indexOf(t)<0});a(s),d.sizeSearchInput()}}})};var v;d.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s},d.select=function(e){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var c={};c[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,c)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close()}},d.close=function(){d.open&&(n(),d.open=!1,s(function(){d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput()},d.getPlaceholder=function(){return!d.multiple||void 0!==d.selected&&!d.selected.length?d.placeholder:void 0},d.sizeSearchInput=function(){var e=h[0],t=h.parent().parent()[0];h.css("width","10px"),s(function(){var c=t.clientWidth-e.offsetLeft-10;50>c&&(c=t.clientWidth),h.css("width",c+"px")},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&d.items.length>0&&u()}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1,d.activeIndex=0})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple),d.onSelectCallback=i(a.onSelect),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=d.selected.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=d.selected[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var v=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):v.attr("tabindex",e),n.removeAttr("tabindex")}),l(v)(c),d.focusser=v,d.multiple||(n.append(v),v.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),v.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$digest(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(v.val()),v.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),d.multiple?(c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),v.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,isControl:function(t){var c=t.which;switch(c){case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:d.multiple||d.select(d.items[d.activeIndex]);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){if(e.length){var c=d.parserResult.source(t);if(c){var s=c.filter(function(t){return e.indexOf(t)<0});a(s),d.sizeSearchInput()}}})};var v;d.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s},d.select=function(e){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var c={};c[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,c)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close()}},d.close=function(){d.open&&(n(),d.open=!1,s(function(){d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput()},d.getPlaceholder=function(){return!d.multiple||void 0!==d.selected&&!d.selected.length?d.placeholder:void 0},d.sizeSearchInput=function(){var e=h[0],t=h.parent().parent()[0];h.css("width","10px"),s(function(){var c=t.clientWidth-e.offsetLeft-10;50>c&&(c=t.clientWidth),h.css("width",c+"px")},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&d.items.length>0&&u()}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1,d.activeIndex=0})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple),d.onSelectCallback=i(a.onSelect),d.tagging={isActivated:!1,fct:void 0},p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=d.selected.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=d.selected[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var v=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):v.attr("tabindex",e),n.removeAttr("tabindex")}),l(v)(c),d.focusser=v,d.multiple||(n.append(v),v.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),v.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$digest(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(v.val()),v.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),d.multiple?(c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),v.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/src/select.js b/src/select.js index 4611e69cd..bc3b7a9de 100644 --- a/src/select.js +++ b/src/select.js @@ -579,6 +579,8 @@ $select.onSelectCallback = $parse(attrs.onSelect); + $select.tagging = {isActivated: false, fct: undefined}; + //From view --> model ngModel.$parsers.unshift(function (inputValue) { var locals = {}, From a692a484f6b569e4695d56ef5c371016f8c458d3 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Wed, 8 Oct 2014 14:52:41 -0400 Subject: [PATCH 06/32] Fix case where undefined custom objects return isActive === true --- dist/select.js | 32 +++++++++++++++++--------------- src/select.js | 30 ++++++++++++++++-------------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/dist/select.js b/dist/select.js index 12a85e39e..a8a7ec4ca 100755 --- a/dist/select.js +++ b/dist/select.js @@ -158,7 +158,7 @@ ctrl.selected = undefined; ctrl.open = false; ctrl.focus = false; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; //Reference to input element used to handle focus events ctrl.disabled = undefined; // Initialized inside uiSelect directive link function ctrl.searchEnabled = undefined; // Initialized inside uiSelect directive link function ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function @@ -257,7 +257,7 @@ var filteredItems = items.filter(function(i) {return ctrl.selected.indexOf(i) < 0;}); setItemsFn(filteredItems); }else{ - setItemsFn(items); + setItemsFn(items); } ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters @@ -267,7 +267,7 @@ }); if (ctrl.multiple){ - //Remove already selected items + //Remove already selected items $scope.$watchCollection('$select.selected', function(selectedItems){ if (!selectedItems.length) return; var data = ctrl.parserResult.source($scope); @@ -307,7 +307,9 @@ }; ctrl.isActive = function(itemScope) { - return ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; + if ( typeof itemScope[ctrl.itemProperty] === 'undefined') { + return false; + } }; ctrl.isDisabled = function(itemScope) { @@ -357,7 +359,7 @@ _resetSearchInput(); ctrl.open = false; $timeout(function(){ - ctrl.focusser[0].focus(); + ctrl.focusser[0].focus(); },0,false); } }; @@ -427,7 +429,7 @@ // Handles selected options in "multiple" mode function _handleMatchSelection(key){ var caretPosition = _getCaretPosition(_searchInput[0]), - length = ctrl.selected.length, + length = ctrl.selected.length, // none = -1, first = 0, last = length-1, @@ -450,7 +452,7 @@ break; case KEY.RIGHT: // Open drop-down - if(!~ctrl.activeMatchIndex || curr === last){ + if(!~ctrl.activeMatchIndex || curr === last){ ctrl.activate(); return false; } @@ -473,7 +475,7 @@ return curr; } else return false; - } + } } newIndex = getNewActiveMatchIndex(); @@ -500,11 +502,11 @@ if(ctrl.multiple && KEY.isHorizontalMovement(key)){ processed = _handleMatchSelection(key); } - + if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); } - + if (processed && key != KEY.TAB) { //TODO Check si el tab selecciona aun correctamente //Crear test @@ -612,7 +614,7 @@ //From model --> view ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search + var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search locals = {}, result; if (data){ @@ -664,7 +666,7 @@ if(attrs.tabindex){ //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex attrs.$observe('tabindex', function(value) { - //If we are using multiple, add tabindex to the search input + //If we are using multiple, add tabindex to the search input if($select.multiple){ searchInput.attr("tabindex", value); } else { @@ -719,7 +721,7 @@ if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input focusser.val(''); scope.$digest(); @@ -857,7 +859,7 @@ if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); return function link(scope, element, attrs, $select, transcludeFn) { - + // var repeat = RepeatParser.parse(attrs.repeat); var groupByExp = attrs.groupBy; @@ -965,4 +967,4 @@ $templateCache.put("select2/select-multiple.tpl.html","
    "); $templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); $templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file +$templateCache.put("selectize/select.tpl.html","
    ");}]); diff --git a/src/select.js b/src/select.js index bc3b7a9de..449f75308 100644 --- a/src/select.js +++ b/src/select.js @@ -150,7 +150,7 @@ ctrl.selected = undefined; ctrl.open = false; ctrl.focus = false; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; //Reference to input element used to handle focus events ctrl.disabled = undefined; // Initialized inside uiSelect directive link function ctrl.searchEnabled = undefined; // Initialized inside uiSelect directive link function ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function @@ -249,7 +249,7 @@ var filteredItems = items.filter(function(i) {return ctrl.selected.indexOf(i) < 0;}); setItemsFn(filteredItems); }else{ - setItemsFn(items); + setItemsFn(items); } ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters @@ -259,7 +259,7 @@ }); if (ctrl.multiple){ - //Remove already selected items + //Remove already selected items $scope.$watchCollection('$select.selected', function(selectedItems){ if (!selectedItems.length) return; var data = ctrl.parserResult.source($scope); @@ -299,7 +299,9 @@ }; ctrl.isActive = function(itemScope) { - return ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; + if ( typeof itemScope[ctrl.itemProperty] === 'undefined') { + return false; + } }; ctrl.isDisabled = function(itemScope) { @@ -349,7 +351,7 @@ _resetSearchInput(); ctrl.open = false; $timeout(function(){ - ctrl.focusser[0].focus(); + ctrl.focusser[0].focus(); },0,false); } }; @@ -419,7 +421,7 @@ // Handles selected options in "multiple" mode function _handleMatchSelection(key){ var caretPosition = _getCaretPosition(_searchInput[0]), - length = ctrl.selected.length, + length = ctrl.selected.length, // none = -1, first = 0, last = length-1, @@ -442,7 +444,7 @@ break; case KEY.RIGHT: // Open drop-down - if(!~ctrl.activeMatchIndex || curr === last){ + if(!~ctrl.activeMatchIndex || curr === last){ ctrl.activate(); return false; } @@ -465,7 +467,7 @@ return curr; } else return false; - } + } } newIndex = getNewActiveMatchIndex(); @@ -492,11 +494,11 @@ if(ctrl.multiple && KEY.isHorizontalMovement(key)){ processed = _handleMatchSelection(key); } - + if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); } - + if (processed && key != KEY.TAB) { //TODO Check si el tab selecciona aun correctamente //Crear test @@ -604,7 +606,7 @@ //From model --> view ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search + var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search locals = {}, result; if (data){ @@ -656,7 +658,7 @@ if(attrs.tabindex){ //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex attrs.$observe('tabindex', function(value) { - //If we are using multiple, add tabindex to the search input + //If we are using multiple, add tabindex to the search input if($select.multiple){ searchInput.attr("tabindex", value); } else { @@ -711,7 +713,7 @@ if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input focusser.val(''); scope.$digest(); @@ -849,7 +851,7 @@ if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); return function link(scope, element, attrs, $select, transcludeFn) { - + // var repeat = RepeatParser.parse(attrs.repeat); var groupByExp = attrs.groupBy; From 03c4827035954fb9bda1129a2feb6256ced638f9 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Wed, 8 Oct 2014 14:54:39 -0400 Subject: [PATCH 07/32] Fix case where undefined custom objects return isActive === true --- dist/select.js | 32 +++++++++++++++++--------------- src/select.js | 30 ++++++++++++++++-------------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/dist/select.js b/dist/select.js index 8b9f1c3ab..accec4441 100755 --- a/dist/select.js +++ b/dist/select.js @@ -158,7 +158,7 @@ ctrl.selected = undefined; ctrl.open = false; ctrl.focus = false; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; //Reference to input element used to handle focus events ctrl.disabled = undefined; // Initialized inside uiSelect directive link function ctrl.searchEnabled = undefined; // Initialized inside uiSelect directive link function ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function @@ -257,7 +257,7 @@ var filteredItems = items.filter(function(i) {return ctrl.selected.indexOf(i) < 0;}); setItemsFn(filteredItems); }else{ - setItemsFn(items); + setItemsFn(items); } ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters @@ -267,7 +267,7 @@ }); if (ctrl.multiple){ - //Remove already selected items + //Remove already selected items $scope.$watchCollection('$select.selected', function(selectedItems){ if (!selectedItems) return; var data = ctrl.parserResult.source($scope); @@ -305,7 +305,9 @@ }; ctrl.isActive = function(itemScope) { - return ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; + if ( typeof itemScope[ctrl.itemProperty] === 'undefined') { + return false; + } }; ctrl.isDisabled = function(itemScope) { @@ -355,7 +357,7 @@ _resetSearchInput(); ctrl.open = false; $timeout(function(){ - ctrl.focusser[0].focus(); + ctrl.focusser[0].focus(); },0,false); } }; @@ -425,7 +427,7 @@ // Handles selected options in "multiple" mode function _handleMatchSelection(key){ var caretPosition = _getCaretPosition(_searchInput[0]), - length = ctrl.selected.length, + length = ctrl.selected.length, // none = -1, first = 0, last = length-1, @@ -448,7 +450,7 @@ break; case KEY.RIGHT: // Open drop-down - if(!~ctrl.activeMatchIndex || curr === last){ + if(!~ctrl.activeMatchIndex || curr === last){ ctrl.activate(); return false; } @@ -471,7 +473,7 @@ return curr; } else return false; - } + } } newIndex = getNewActiveMatchIndex(); @@ -498,11 +500,11 @@ if(ctrl.multiple && KEY.isHorizontalMovement(key)){ processed = _handleMatchSelection(key); } - + if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); } - + if (processed && key != KEY.TAB) { //TODO Check si el tab selecciona aun correctamente //Crear test @@ -608,7 +610,7 @@ //From model --> view ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search + var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search locals = {}, result; if (data){ @@ -660,7 +662,7 @@ if(attrs.tabindex){ //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex attrs.$observe('tabindex', function(value) { - //If we are using multiple, add tabindex to the search input + //If we are using multiple, add tabindex to the search input if($select.multiple){ searchInput.attr("tabindex", value); } else { @@ -715,7 +717,7 @@ if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input focusser.val(''); scope.$digest(); @@ -855,7 +857,7 @@ if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); return function link(scope, element, attrs, $select, transcludeFn) { - + // var repeat = RepeatParser.parse(attrs.repeat); var groupByExp = attrs.groupBy; @@ -963,4 +965,4 @@ $templateCache.put("select2/select-multiple.tpl.html","
    "); $templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); $templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file +$templateCache.put("selectize/select.tpl.html","
    ");}]); diff --git a/src/select.js b/src/select.js index e16d1f7dc..e452eaf5f 100644 --- a/src/select.js +++ b/src/select.js @@ -150,7 +150,7 @@ ctrl.selected = undefined; ctrl.open = false; ctrl.focus = false; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; //Reference to input element used to handle focus events ctrl.disabled = undefined; // Initialized inside uiSelect directive link function ctrl.searchEnabled = undefined; // Initialized inside uiSelect directive link function ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function @@ -249,7 +249,7 @@ var filteredItems = items.filter(function(i) {return ctrl.selected.indexOf(i) < 0;}); setItemsFn(filteredItems); }else{ - setItemsFn(items); + setItemsFn(items); } ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters @@ -259,7 +259,7 @@ }); if (ctrl.multiple){ - //Remove already selected items + //Remove already selected items $scope.$watchCollection('$select.selected', function(selectedItems){ if (!selectedItems) return; var data = ctrl.parserResult.source($scope); @@ -297,7 +297,9 @@ }; ctrl.isActive = function(itemScope) { - return ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; + if ( typeof itemScope[ctrl.itemProperty] === 'undefined') { + return false; + } }; ctrl.isDisabled = function(itemScope) { @@ -347,7 +349,7 @@ _resetSearchInput(); ctrl.open = false; $timeout(function(){ - ctrl.focusser[0].focus(); + ctrl.focusser[0].focus(); },0,false); } }; @@ -417,7 +419,7 @@ // Handles selected options in "multiple" mode function _handleMatchSelection(key){ var caretPosition = _getCaretPosition(_searchInput[0]), - length = ctrl.selected.length, + length = ctrl.selected.length, // none = -1, first = 0, last = length-1, @@ -440,7 +442,7 @@ break; case KEY.RIGHT: // Open drop-down - if(!~ctrl.activeMatchIndex || curr === last){ + if(!~ctrl.activeMatchIndex || curr === last){ ctrl.activate(); return false; } @@ -463,7 +465,7 @@ return curr; } else return false; - } + } } newIndex = getNewActiveMatchIndex(); @@ -490,11 +492,11 @@ if(ctrl.multiple && KEY.isHorizontalMovement(key)){ processed = _handleMatchSelection(key); } - + if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); } - + if (processed && key != KEY.TAB) { //TODO Check si el tab selecciona aun correctamente //Crear test @@ -600,7 +602,7 @@ //From model --> view ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search + var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search locals = {}, result; if (data){ @@ -652,7 +654,7 @@ if(attrs.tabindex){ //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex attrs.$observe('tabindex', function(value) { - //If we are using multiple, add tabindex to the search input + //If we are using multiple, add tabindex to the search input if($select.multiple){ searchInput.attr("tabindex", value); } else { @@ -707,7 +709,7 @@ if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input focusser.val(''); scope.$digest(); @@ -847,7 +849,7 @@ if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); return function link(scope, element, attrs, $select, transcludeFn) { - + // var repeat = RepeatParser.parse(attrs.repeat); var groupByExp = attrs.groupBy; From 0d2399ecde9f862508facdda5e332ac2f87b38c2 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Wed, 8 Oct 2014 14:56:03 -0400 Subject: [PATCH 08/32] Rollback whitespace changes --- dist/select.js | 26 +++++++++++++------------- src/select.js | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/dist/select.js b/dist/select.js index accec4441..e455a80cc 100755 --- a/dist/select.js +++ b/dist/select.js @@ -158,7 +158,7 @@ ctrl.selected = undefined; ctrl.open = false; ctrl.focus = false; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; //Reference to input element used to handle focus events ctrl.disabled = undefined; // Initialized inside uiSelect directive link function ctrl.searchEnabled = undefined; // Initialized inside uiSelect directive link function ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function @@ -257,7 +257,7 @@ var filteredItems = items.filter(function(i) {return ctrl.selected.indexOf(i) < 0;}); setItemsFn(filteredItems); }else{ - setItemsFn(items); + setItemsFn(items); } ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters @@ -267,7 +267,7 @@ }); if (ctrl.multiple){ - //Remove already selected items + //Remove already selected items $scope.$watchCollection('$select.selected', function(selectedItems){ if (!selectedItems) return; var data = ctrl.parserResult.source($scope); @@ -357,7 +357,7 @@ _resetSearchInput(); ctrl.open = false; $timeout(function(){ - ctrl.focusser[0].focus(); + ctrl.focusser[0].focus(); },0,false); } }; @@ -427,7 +427,7 @@ // Handles selected options in "multiple" mode function _handleMatchSelection(key){ var caretPosition = _getCaretPosition(_searchInput[0]), - length = ctrl.selected.length, + length = ctrl.selected.length, // none = -1, first = 0, last = length-1, @@ -450,7 +450,7 @@ break; case KEY.RIGHT: // Open drop-down - if(!~ctrl.activeMatchIndex || curr === last){ + if(!~ctrl.activeMatchIndex || curr === last){ ctrl.activate(); return false; } @@ -473,7 +473,7 @@ return curr; } else return false; - } + } } newIndex = getNewActiveMatchIndex(); @@ -500,11 +500,11 @@ if(ctrl.multiple && KEY.isHorizontalMovement(key)){ processed = _handleMatchSelection(key); } - + if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); } - + if (processed && key != KEY.TAB) { //TODO Check si el tab selecciona aun correctamente //Crear test @@ -610,7 +610,7 @@ //From model --> view ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search + var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search locals = {}, result; if (data){ @@ -662,7 +662,7 @@ if(attrs.tabindex){ //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex attrs.$observe('tabindex', function(value) { - //If we are using multiple, add tabindex to the search input + //If we are using multiple, add tabindex to the search input if($select.multiple){ searchInput.attr("tabindex", value); } else { @@ -717,7 +717,7 @@ if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input focusser.val(''); scope.$digest(); @@ -857,7 +857,7 @@ if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); return function link(scope, element, attrs, $select, transcludeFn) { - + // var repeat = RepeatParser.parse(attrs.repeat); var groupByExp = attrs.groupBy; diff --git a/src/select.js b/src/select.js index e452eaf5f..13923b4de 100644 --- a/src/select.js +++ b/src/select.js @@ -150,7 +150,7 @@ ctrl.selected = undefined; ctrl.open = false; ctrl.focus = false; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; //Reference to input element used to handle focus events ctrl.disabled = undefined; // Initialized inside uiSelect directive link function ctrl.searchEnabled = undefined; // Initialized inside uiSelect directive link function ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function @@ -249,7 +249,7 @@ var filteredItems = items.filter(function(i) {return ctrl.selected.indexOf(i) < 0;}); setItemsFn(filteredItems); }else{ - setItemsFn(items); + setItemsFn(items); } ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters @@ -259,7 +259,7 @@ }); if (ctrl.multiple){ - //Remove already selected items + //Remove already selected items $scope.$watchCollection('$select.selected', function(selectedItems){ if (!selectedItems) return; var data = ctrl.parserResult.source($scope); @@ -349,7 +349,7 @@ _resetSearchInput(); ctrl.open = false; $timeout(function(){ - ctrl.focusser[0].focus(); + ctrl.focusser[0].focus(); },0,false); } }; @@ -419,7 +419,7 @@ // Handles selected options in "multiple" mode function _handleMatchSelection(key){ var caretPosition = _getCaretPosition(_searchInput[0]), - length = ctrl.selected.length, + length = ctrl.selected.length, // none = -1, first = 0, last = length-1, @@ -442,7 +442,7 @@ break; case KEY.RIGHT: // Open drop-down - if(!~ctrl.activeMatchIndex || curr === last){ + if(!~ctrl.activeMatchIndex || curr === last){ ctrl.activate(); return false; } @@ -465,7 +465,7 @@ return curr; } else return false; - } + } } newIndex = getNewActiveMatchIndex(); @@ -492,11 +492,11 @@ if(ctrl.multiple && KEY.isHorizontalMovement(key)){ processed = _handleMatchSelection(key); } - + if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); } - + if (processed && key != KEY.TAB) { //TODO Check si el tab selecciona aun correctamente //Crear test @@ -602,7 +602,7 @@ //From model --> view ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search + var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search locals = {}, result; if (data){ @@ -654,7 +654,7 @@ if(attrs.tabindex){ //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex attrs.$observe('tabindex', function(value) { - //If we are using multiple, add tabindex to the search input + //If we are using multiple, add tabindex to the search input if($select.multiple){ searchInput.attr("tabindex", value); } else { @@ -709,7 +709,7 @@ if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input focusser.val(''); scope.$digest(); @@ -849,7 +849,7 @@ if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); return function link(scope, element, attrs, $select, transcludeFn) { - + // var repeat = RepeatParser.parse(attrs.repeat); var groupByExp = attrs.groupBy; From 8fa93b7bcd7e85f83033ac36feb2985eb445721f Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Fri, 17 Oct 2014 12:25:05 -0400 Subject: [PATCH 09/32] Rebuild source files post merge --- dist/select.css | 2 +- dist/select.js | 72 ++++++++++++--------- dist/select.js.min.js | 7 -- dist/{select.css.min.css => select.min.css} | 2 +- dist/select.min.js | 4 +- 5 files changed, 46 insertions(+), 41 deletions(-) delete mode 100755 dist/select.js.min.js rename dist/{select.css.min.css => select.min.css} (98%) diff --git a/dist/select.css b/dist/select.css index ae12d8ecc..6da6cec25 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-14T18:22:05.435Z + * Version: 0.8.3 - 2014-10-17T16:24:21.435Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index d27a2bd30..58e54061d 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-14T18:22:05.432Z + * Version: 0.8.3 - 2014-10-17T16:24:21.429Z * License: MIT */ @@ -59,7 +59,7 @@ * * jqLite find() is limited to lookups by tag name. * TODO This will change with future versions of AngularJS, to be removed when this happens - * +5 * * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 */ @@ -160,7 +160,7 @@ ctrl.selected = undefined; ctrl.open = false; ctrl.focus = false; - ctrl.focusser = undefined; //Reference to input element used to handle focus events + ctrl.focusser = undefined; //Reference to input element used to handle focus events ctrl.disabled = undefined; // Initialized inside uiSelect directive link function ctrl.searchEnabled = undefined; // Initialized inside uiSelect directive link function ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function @@ -260,7 +260,7 @@ var filteredItems = items.filter(function(i) {return ctrl.selected.indexOf(i) < 0;}); setItemsFn(filteredItems); }else{ - setItemsFn(items); + setItemsFn(items); } ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters @@ -270,14 +270,14 @@ }); if (ctrl.multiple){ - //Remove already selected items + //Remove already selected items $scope.$watchCollection('$select.selected', function(selectedItems){ var data = ctrl.parserResult.source($scope); if (!selectedItems.length) { - setItemsFn(data); + setItemsFn(data); }else{ var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;}); - setItemsFn(filteredItems); + setItemsFn(filteredItems); } ctrl.sizeSearchInput(); }); @@ -312,17 +312,11 @@ }; ctrl.isActive = function(itemScope) { -<<<<<<< HEAD - if ( typeof itemScope[ctrl.itemProperty] === 'undefined') { - return false; - } -======= return ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; ->>>>>>> master }; ctrl.isDisabled = function(itemScope) { - + if (!ctrl.open) return; var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); @@ -341,7 +335,12 @@ // When the user clicks on an item inside the dropdown ctrl.select = function(item, skipFocusser) { - if (item === undefined || !item._uiSelectChoiceDisabled) { + if (!item || !item._uiSelectChoiceDisabled) { + if(ctrl.tagging.isActivated && !item && ctrl.search.length > 0) { + // create new item on the fly + item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + } + var locals = {}; locals[ctrl.parserResult.itemName] = item; @@ -362,7 +361,7 @@ // Closes the dropdown ctrl.close = function(skipFocusser) { - if (!ctrl.open) return; + if (!ctrl.open) return; _resetSearchInput(); ctrl.open = false; if (!ctrl.multiple){ @@ -402,7 +401,7 @@ return ctrl.placeholder; }; - var containerSizeWatch; + var containerSizeWatch; ctrl.sizeSearchInput = function(){ var input = _searchInput[0], container = _searchInput.parent().parent()[0]; @@ -436,7 +435,7 @@ break; case KEY.UP: if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode - else if (ctrl.activeIndex > 0) { ctrl.activeIndex--; } + else if (ctrl.activeIndex > 0 || (ctrl.search.length === 0 && ctrl.tagging.isActivated)) { ctrl.activeIndex--; } break; case KEY.TAB: if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true); @@ -460,7 +459,7 @@ // Handles selected options in "multiple" mode function _handleMatchSelection(key){ var caretPosition = _getCaretPosition(_searchInput[0]), - length = ctrl.selected.length, + length = ctrl.selected.length, // none = -1, first = 0, last = length-1, @@ -483,7 +482,7 @@ break; case KEY.RIGHT: // Open drop-down - if(!~ctrl.activeMatchIndex || curr === last){ + if(!~ctrl.activeMatchIndex || curr === last){ ctrl.activate(); return false; } @@ -506,7 +505,7 @@ return curr; } else return false; - } + } } newIndex = getNewActiveMatchIndex(); @@ -534,10 +533,10 @@ processed = _handleMatchSelection(key); } - if (!processed && ctrl.items.length > 0) { + if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); } - + if (processed && key != KEY.TAB) { //TODO Check si el tab selecciona aun correctamente //Crear test @@ -643,7 +642,7 @@ //From model --> view ngModel.$formatters.unshift(function (inputValue) { - var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search + var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search locals = {}, result; if (data){ @@ -695,7 +694,7 @@ if(attrs.tabindex){ //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex attrs.$observe('tabindex', function(value) { - //If we are using multiple, add tabindex to the search input + //If we are using multiple, add tabindex to the search input if($select.multiple){ searchInput.attr("tabindex", value); } else { @@ -750,7 +749,7 @@ if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { return; } - + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input focusser.val(''); scope.$digest(); @@ -776,6 +775,19 @@ $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; }); + attrs.$observe('tagging', function() { + if(attrs.tagging !== undefined) + { + // $eval() is needed otherwise we get a string instead of a function or a boolean + var taggingEval = scope.$eval(attrs.tagging); + $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined}; + } + else + { + $select.tagging = {isActivated: false, fct: undefined}; + } + }); + if ($select.multiple){ scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { if (oldValue != newValue) @@ -879,7 +891,7 @@ if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); return function link(scope, element, attrs, $select, transcludeFn) { - + // var repeat = RepeatParser.parse(attrs.repeat); var groupByExp = attrs.groupBy; @@ -910,7 +922,7 @@ scope.$watch('$select.search', function(newValue) { if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = 0; + $select.activeIndex = $select.tagging.isActivated ? -1 : 0; $select.refresh(attrs.refresh); }); @@ -951,7 +963,7 @@ }); if($select.multiple){ - $select.sizeSearchInput(); + $select.sizeSearchInput(); } } @@ -987,4 +999,4 @@ $templateCache.put("select2/select-multiple.tpl.html","
    "); $templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); $templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); +$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.js.min.js b/dist/select.js.min.js deleted file mode 100755 index 4ab930783..000000000 --- a/dist/select.js.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.8.0 - 2014-10-07T13:45:31.563Z - * License: MIT - */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,isControl:function(t){var c=t.which;switch(c){case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:d.multiple||d.select(d.items[d.activeIndex]);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){if(e.length){var c=d.parserResult.source(t);if(c){var s=c.filter(function(t){return e.indexOf(t)<0});a(s),d.sizeSearchInput()}}})};var v;d.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s},d.select=function(e){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var c={};c[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,c)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close()}},d.close=function(){d.open&&(n(),d.open=!1,s(function(){d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput()},d.getPlaceholder=function(){return!d.multiple||void 0!==d.selected&&!d.selected.length?d.placeholder:void 0},d.sizeSearchInput=function(){var e=h[0],t=h.parent().parent()[0];h.css("width","10px"),s(function(){var c=t.clientWidth-e.offsetLeft-10;50>c&&(c=t.clientWidth),h.css("width",c+"px")},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&d.items.length>0&&u()}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1,d.activeIndex=0})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple),d.onSelectCallback=i(a.onSelect),d.tagging={isActivated:!1,fct:void 0},p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=d.selected.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=d.selected[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var v=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):v.attr("tabindex",e),n.removeAttr("tabindex")}),l(v)(c),d.focusser=v,d.multiple||(n.append(v),v.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),v.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$digest(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(v.val()),v.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),d.multiple?(c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),v.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/dist/select.css.min.css b/dist/select.min.css similarity index 98% rename from dist/select.css.min.css rename to dist/select.min.css index cdb6a4f6f..e9f2166ae 100644 --- a/dist/select.css.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-14T18:22:05.435Z + * Version: 0.8.3 - 2014-10-17T16:24:21.435Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 0402e2a11..dfc420c3a 100755 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-14T18:22:05.432Z + * Version: 0.8.3 - 2014-10-17T16:24:21.429Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var l=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!l)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:l[2],source:t(l[3]),trackByExp:l[4],modelMapper:t(l[1]||l[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,l){var s=e+" in "+(l?"$group.items":t);return c&&(s+=" track by "+c),s}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,l,s,i){function n(){p.resetSearchInput&&(p.search=d,p.selected&&p.items.length&&!p.multiple&&(p.activeIndex=p.items.indexOf(p.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!p.open&&p.multiple?p.activate(!1,!0):p.activeIndex0&&p.activeIndex--;break;case e.TAB:(!p.multiple||p.open)&&p.select(p.items[p.activeIndex],!0);break;case e.ENTER:p.open?p.select(p.items[p.activeIndex]):p.activate(!1,!0);break;case e.ESC:p.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~p.activeMatchIndex?u:n;case e.RIGHT:return~p.activeMatchIndex&&a!==n?r:(p.activate(),!1);case e.BACKSPACE:return~p.activeMatchIndex?(p.removeChoice(a),u):n;case e.DELETE:return~p.activeMatchIndex?(p.removeChoice(p.activeMatchIndex),a):!1}}var l=o(h[0]),s=p.selected.length,i=0,n=s-1,a=p.activeMatchIndex,r=p.activeMatchIndex+1,u=p.activeMatchIndex-1,d=a;return l>0||p.search.length&&t==e.RIGHT?!1:(p.close(),d=c(),p.activeMatchIndex=p.selected.length&&d!==!1?Math.min(n,Math.max(i,d)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var l=t[p.activeIndex],s=l.offsetTop+l.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;s>n?e[0].scrollTop+=s-n:s=p.items.length?0:p.activeIndex,l(function(){p.search=e||p.search,h[0].focus()}))},p.findGroupByName=function(e){return p.groups&&p.groups.filter(function(t){return t.name===e})[0]},p.parseRepeatAttr=function(e,c){function l(e){p.groups=[],angular.forEach(e,function(e){var l=t.$eval(c),s=angular.isFunction(l)?l(e):e[l],i=p.findGroupByName(s);i?i.items.push(e):p.groups.push({name:s,items:[e]})}),p.items=[],p.groups.forEach(function(e){p.items=p.items.concat(e.items)})}function n(e){p.items=e}var a=c?l:n;p.parserResult=s.parse(e),p.isGrouped=!!c,p.itemProperty=p.parserResult.itemName,t.$watchCollection(p.parserResult.source,function(e){if(void 0===e||null===e)p.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(p.multiple){var t=e.filter(function(e){return p.selected.indexOf(e)<0});a(t)}else a(e);p.ngModel.$modelValue=null}}),p.multiple&&t.$watchCollection("$select.selected",function(e){var c=p.parserResult.source(t);if(e.length){var l=c.filter(function(t){return e.indexOf(t)<0});a(l)}else a(c);p.sizeSearchInput()})};var v;p.refresh=function(e){void 0!==e&&(v&&l.cancel(v),v=l(function(){t.$eval(e)},p.refreshDelay))},p.setActiveItem=function(e){p.activeIndex=p.items.indexOf(e)},p.isActive=function(e){return p.open&&p.items.indexOf(e[p.itemProperty])===p.activeIndex},p.isDisabled=function(e){if(p.open){var t,c=p.items.indexOf(e[p.itemProperty]),l=!1;return c>=0&&!angular.isUndefined(p.disableChoiceExpression)&&(t=p.items[c],l=!!e.$eval(p.disableChoiceExpression),t._uiSelectChoiceDisabled=l),l}},p.select=function(e,c){if(void 0===e||!e._uiSelectChoiceDisabled){var l={};l[p.parserResult.itemName]=e,p.onSelectCallback(t,{$item:e,$model:p.parserResult.modelMapper(t,l)}),p.multiple?(p.selected.push(e),p.sizeSearchInput()):p.selected=e,p.close(c)}},p.close=function(e){p.open&&(n(),p.open=!1,p.multiple||l(function(){p.focusser.prop("disabled",!1),e||p.focusser[0].focus()},0,!1))},p.toggle=function(e){p.open?p.close():p.activate(),e.preventDefault(),e.stopPropagation()},p.removeChoice=function(e){var c=p.selected[e],l={};l[p.parserResult.itemName]=c,p.selected.splice(e,1),p.activeMatchIndex=-1,p.sizeSearchInput(),p.onRemoveCallback(t,{$item:c,$model:p.parserResult.modelMapper(t,l)})},p.getPlaceholder=function(){return p.multiple&&p.selected.length?void 0:p.placeholder};var f;p.sizeSearchInput=function(){var e=h[0],c=h.parent().parent()[0];h.css("width","10px");var s=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),h.css("width",t+"px")};l(function(){0!==c.clientWidth||f?f||s():f=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(s(),f(),f=null)})},0,!1)},h.on("keydown",function(c){var l=c.which;t.$apply(function(){var t=!1;p.multiple&&e.isHorizontalMovement(l)&&(t=r(l)),!t&&p.items.length>0&&(t=a(l)),t&&l!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(l)&&p.items.length>0&&u()}),h.on("blur",function(){l(function(){p.activeMatchIndex=-1})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,l,s,i){return{restrict:"EA",templateUrl:function(e,t){var l=t.theme||c.theme;return l+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(p.close(),c.$digest())}var p=r[0],d=r[1],h=n.querySelectorAll("input.ui-select-search");p.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,p.onSelectCallback=i(a.onSelect),p.onRemoveCallback=i(a.onRemove),d.$parsers.unshift(function(e){var t,l={};if(p.multiple){for(var s=[],i=p.selected.length-1;i>=0;i--)l={},l[p.parserResult.itemName]=p.selected[i],t=p.parserResult.modelMapper(c,l),s.unshift(t);return s}return l={},l[p.parserResult.itemName]=e,t=p.parserResult.modelMapper(c,l)}),d.$formatters.unshift(function(e){var t,l=p.parserResult.source(c,{$select:{search:""}}),s={};if(l){if(p.multiple){var i=[],n=function(e,l){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(s[p.parserResult.itemName]=e[n],t=p.parserResult.modelMapper(c,s),t==l)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(p.selected,e[a])||n(l,e[a]);return i}var r=function(l){return s[p.parserResult.itemName]=l,t=p.parserResult.modelMapper(c,s),t==e};if(p.selected&&r(p.selected))return p.selected;for(var o=l.length-1;o>=0;o--)if(r(l[o]))return l[o]}return e}),p.ngModel=d;var v=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){p.multiple?h.attr("tabindex",e):v.attr("tabindex",e),n.removeAttr("tabindex")}),s(v)(c),p.focusser=v,p.multiple||(n.append(v),v.bind("focus",function(){c.$evalAsync(function(){p.focus=!0})}),v.bind("blur",function(){c.$evalAsync(function(){p.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),p.select(void 0),void c.$apply()):void(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),p.activate()),c.$digest()))}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(p.activate(v.val()),v.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);p.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){p.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);p.resetSearchInput=void 0!==e?e:!0}),p.multiple?(c.$watchCollection(function(){return d.$modelValue},function(e,t){t!=e&&(d.$modelValue=null)}),c.$watchCollection("$select.selected",function(){d.$setViewValue(Date.now())}),v.prop("disabled",!0)):c.$watch("$select.selected",function(e){d.$viewValue!==e&&d.$setViewValue(e)}),d.$render=function(){if(p.multiple&&!angular.isArray(d.$viewValue)){if(!angular.isUndefined(d.$viewValue)&&null!==d.$viewValue)throw l("multiarr","Expected model value to be array but got '{0}'",d.$viewValue);p.selected=[]}p.selected=d.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw l("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var s=t.querySelectorAll(".ui-select-choices");if(s.removeAttr("ui-select-choices"),1!==s.length)throw l("transcluded","Expected 1 .ui-select-choices but got '{0}'.",s.length);n.querySelectorAll(".ui-select-choices").replaceWith(s)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,l){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(s,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(s,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var p=i.querySelectorAll(".ui-select-choices-row");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",p.length);p.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var d=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",d.length);d.attr("uis-transclude-append",""),l(i,r)(s),s.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=s.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,l,s){s(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,l=t.parent().attr("multiple");return c+(l?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,l,s){l.$observe("placeholder",function(t){s.placeholder=void 0!==t?t:e.placeholder}),s.multiple&&s.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){var c=d.parserResult.source(t);if(e.length){var s=c.filter(function(t){return e.indexOf(t)<0});a(s)}else a(c);d.sizeSearchInput()})};var v;d.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return d.open&&d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){if(d.open){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s}},d.select=function(e,c){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var s={};s[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,s)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close(c)}},d.close=function(e){d.open&&(n(),d.open=!1,d.multiple||s(function(){d.focusser.prop("disabled",!1),e||d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){var c=d.selected[e],s={};s[d.parserResult.itemName]=c,d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput(),d.onRemoveCallback(t,{$item:c,$model:d.parserResult.modelMapper(t,s)})},d.getPlaceholder=function(){return d.multiple&&d.selected.length?void 0:d.placeholder};var f;d.sizeSearchInput=function(){var e=h[0],c=h.parent().parent()[0];h.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),h.css("width",t+"px")};s(function(){0!==c.clientWidth||f?f||l():f=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),f(),f=null)})},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&d.items.length>0&&u()}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=i(a.onSelect),d.onRemoveCallback=i(a.onRemove),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=d.selected.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=d.selected[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var v=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):v.attr("tabindex",e),n.removeAttr("tabindex")}),l(v)(c),d.focusser=v,d.multiple||(n.append(v),v.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),v.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(v.val()),v.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),v.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file From 7be4c73ac36c15997bbdb22468e3968ec8d5a18a Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Fri, 17 Oct 2014 14:34:03 -0400 Subject: [PATCH 10/32] Re-introduce check to prevent unintentional "all active" return for not yet selected results list elements --- src/select.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/select.js b/src/select.js index 985c0a5fe..62540315b 100644 --- a/src/select.js +++ b/src/select.js @@ -304,6 +304,9 @@ }; ctrl.isActive = function(itemScope) { + if ( typeof itemScope[ctrl.itemProperty] === 'undefined') { + return false; + } return ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; }; From 9d89d472004b661ded70e04ccc55cd56a8753d4c Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Fri, 17 Oct 2014 16:37:27 -0400 Subject: [PATCH 11/32] Add auto-tokenization functionality and associated demo. --- dist/select.js | 45 ++++++++++- examples/demo-tagging.html | 152 +++++++++++++++++++++++++++++++++++++ examples/demo.js | 11 +++ 3 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 examples/demo-tagging.html diff --git a/dist/select.js b/dist/select.js index 58e54061d..f0d6d057e 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T16:24:21.429Z + * Version: 0.8.3 - 2014-10-17T18:44:25.084Z * License: MIT */ @@ -28,6 +28,10 @@ BACKSPACE: 8, DELETE: 46, COMMAND: 91, + + MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "SPACE" , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + }, + isControl: function (e) { var k = e.which; switch (k) { @@ -312,6 +316,9 @@ }; ctrl.isActive = function(itemScope) { + if ( typeof itemScope[ctrl.itemProperty] === 'undefined') { + return false; + } return ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; }; @@ -339,6 +346,11 @@ if(ctrl.tagging.isActivated && !item && ctrl.search.length > 0) { // create new item on the fly item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + // if(ctrl.taggingTokens.isActivated) { + // setTimeout(function() {}, 10); + // _resetSearchInput(); + + // } } var locals = {}; @@ -535,6 +547,15 @@ if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); + if ( ctrl.taggingTokens.isActivated ) { + for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { + console.log(ctrl.taggingTokens.tokens[i]) + if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) { + ctrl.select(null, true); + _searchInput.triggerHandler('tagged') + } + }; + } } if (processed && key != KEY.TAB) { @@ -551,6 +572,14 @@ }); + _searchInput.on('tagged', function() { + $timeout(function() { + console.log('tagged'); + debugger; + _resetSearchInput(); + }); + }); + _searchInput.on('blur', function() { $timeout(function() { ctrl.activeMatchIndex = -1; @@ -788,6 +817,18 @@ } }); + attrs.$observe('taggingTokens', function() { + if(attrs.tagging !== undefined && attrs.taggingTokens !== undefined) + { + var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',']; + $select.taggingTokens = {isActivated: true, tokens: tokens }; + } + else + { + $select.taggingTokens = {isActivated: false, tokens: undefined}; + } + }); + if ($select.multiple){ scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { if (oldValue != newValue) @@ -999,4 +1040,4 @@ $templateCache.put("select2/select-multiple.tpl.html","
    "); $templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); $templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file +$templateCache.put("selectize/select.tpl.html","
    ");}]); diff --git a/examples/demo-tagging.html b/examples/demo-tagging.html new file mode 100644 index 000000000..091e4fbde --- /dev/null +++ b/examples/demo-tagging.html @@ -0,0 +1,152 @@ + + + + + AngularJS ui-select + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

    Multi Selection Demos

    + +

    Simple String Tags

    + + {{$item}} + + {{color}} + + +

    Selected: {{multipleDemo.colors}}

    +
    +

    Object Tags

    + + {{$item.name}} <{{$item.email}}> + +
    + + email: {{person.email}} + age: + +
    +
    +

    Object Tags with Tokenization (Space, Forward Slash, Comma)

    + Note that the SPACE character can't be used literally, use the keyword SPACE + + {{$item.name}} <{{$item.email}}> + +
    + + email: {{person.email}} + age: + +
    +
    +

    Selected: {{multipleDemo.selectedPeople}}

    + +
    + + + diff --git a/examples/demo.js b/examples/demo.js index e0cd943a8..29355a1af 100644 --- a/examples/demo.js +++ b/examples/demo.js @@ -106,6 +106,17 @@ app.controller('DemoCtrl', function($scope, $http, $timeout) { }; }; + $scope.tagTransform = function (newTag) { + var item = { + name: newTag, + email: newTag+'@email.com', + age: 'unknown', + country: 'unknown' + }; + + return item; + }; + $scope.person = {}; $scope.people = [ { name: 'Adam', email: 'adam@email.com', age: 12, country: 'United States' }, From 516857c0a34a7b0c6a46c25957d7f055904d74a8 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Fri, 17 Oct 2014 16:38:00 -0400 Subject: [PATCH 12/32] Compiled assets --- dist/select.css | 2 +- dist/select.js | 42 ++---------------------------------------- dist/select.min.css | 2 +- dist/select.min.js | 4 ++-- 4 files changed, 6 insertions(+), 44 deletions(-) diff --git a/dist/select.css b/dist/select.css index 6da6cec25..bf45b9020 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T16:24:21.435Z + * Version: 0.8.3 - 2014-10-17T20:37:37.506Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index f0d6d057e..9cf899c51 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T18:44:25.084Z + * Version: 0.8.3 - 2014-10-17T20:37:37.502Z * License: MIT */ @@ -28,10 +28,6 @@ BACKSPACE: 8, DELETE: 46, COMMAND: 91, - - MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "SPACE" , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" - }, - isControl: function (e) { var k = e.which; switch (k) { @@ -346,11 +342,6 @@ if(ctrl.tagging.isActivated && !item && ctrl.search.length > 0) { // create new item on the fly item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; - // if(ctrl.taggingTokens.isActivated) { - // setTimeout(function() {}, 10); - // _resetSearchInput(); - - // } } var locals = {}; @@ -547,15 +538,6 @@ if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); - if ( ctrl.taggingTokens.isActivated ) { - for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { - console.log(ctrl.taggingTokens.tokens[i]) - if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) { - ctrl.select(null, true); - _searchInput.triggerHandler('tagged') - } - }; - } } if (processed && key != KEY.TAB) { @@ -572,14 +554,6 @@ }); - _searchInput.on('tagged', function() { - $timeout(function() { - console.log('tagged'); - debugger; - _resetSearchInput(); - }); - }); - _searchInput.on('blur', function() { $timeout(function() { ctrl.activeMatchIndex = -1; @@ -817,18 +791,6 @@ } }); - attrs.$observe('taggingTokens', function() { - if(attrs.tagging !== undefined && attrs.taggingTokens !== undefined) - { - var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',']; - $select.taggingTokens = {isActivated: true, tokens: tokens }; - } - else - { - $select.taggingTokens = {isActivated: false, tokens: undefined}; - } - }); - if ($select.multiple){ scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { if (oldValue != newValue) @@ -1040,4 +1002,4 @@ $templateCache.put("select2/select-multiple.tpl.html","
    "); $templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); $templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); +$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.min.css b/dist/select.min.css index e9f2166ae..5d63eb62c 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T16:24:21.435Z + * Version: 0.8.3 - 2014-10-17T20:37:37.506Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index dfc420c3a..40a92d43f 100755 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T16:24:21.429Z + * Version: 0.8.3 - 2014-10-17T20:37:37.502Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){var c=d.parserResult.source(t);if(e.length){var s=c.filter(function(t){return e.indexOf(t)<0});a(s)}else a(c);d.sizeSearchInput()})};var v;d.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return d.open&&d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){if(d.open){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s}},d.select=function(e,c){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var s={};s[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,s)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close(c)}},d.close=function(e){d.open&&(n(),d.open=!1,d.multiple||s(function(){d.focusser.prop("disabled",!1),e||d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){var c=d.selected[e],s={};s[d.parserResult.itemName]=c,d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput(),d.onRemoveCallback(t,{$item:c,$model:d.parserResult.modelMapper(t,s)})},d.getPlaceholder=function(){return d.multiple&&d.selected.length?void 0:d.placeholder};var f;d.sizeSearchInput=function(){var e=h[0],c=h.parent().parent()[0];h.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),h.css("width",t+"px")};s(function(){0!==c.clientWidth||f?f||l():f=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),f(),f=null)})},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&d.items.length>0&&u()}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=i(a.onSelect),d.onRemoveCallback=i(a.onRemove),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=d.selected.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=d.selected[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var v=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):v.attr("tabindex",e),n.removeAttr("tabindex")}),l(v)(c),d.focusser=v,d.multiple||(n.append(v),v.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),v.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(v.val()),v.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),v.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){var c=d.parserResult.source(t);if(e.length){var s=c.filter(function(t){return e.indexOf(t)<0});a(s)}else a(c);d.sizeSearchInput()})};var v;d.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return"undefined"==typeof e[d.itemProperty]?!1:d.open&&d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){if(d.open){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s}},d.select=function(e,c){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var s={};s[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,s)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close(c)}},d.close=function(e){d.open&&(n(),d.open=!1,d.multiple||s(function(){d.focusser.prop("disabled",!1),e||d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){var c=d.selected[e],s={};s[d.parserResult.itemName]=c,d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput(),d.onRemoveCallback(t,{$item:c,$model:d.parserResult.modelMapper(t,s)})},d.getPlaceholder=function(){return d.multiple&&d.selected.length?void 0:d.placeholder};var f;d.sizeSearchInput=function(){var e=h[0],c=h.parent().parent()[0];h.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),h.css("width",t+"px")};s(function(){0!==c.clientWidth||f?f||l():f=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),f(),f=null)})},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&d.items.length>0&&u()}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=i(a.onSelect),d.onRemoveCallback=i(a.onRemove),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=d.selected.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=d.selected[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var v=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):v.attr("tabindex",e),n.removeAttr("tabindex")}),l(v)(c),d.focusser=v,d.multiple||(n.append(v),v.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),v.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(v.val()),v.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),v.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file From 9d0abc4b49dc7d6f0c922ee51901b14cc974bcb0 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Fri, 17 Oct 2014 16:55:05 -0400 Subject: [PATCH 13/32] Move changes to appropriate files and make build pass --- dist/select.css | 2 +- dist/select.js | 41 ++++++++++++++++++++++++++++++++++++++--- dist/select.min.css | 2 +- dist/select.min.js | 4 ++-- src/select.js | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 7 deletions(-) diff --git a/dist/select.css b/dist/select.css index bf45b9020..3451d411c 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T20:37:37.506Z + * Version: 0.8.3 - 2014-10-17T20:52:51.091Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index 9cf899c51..0b63a155f 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,11 +1,10 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T20:37:37.502Z + * Version: 0.8.3 - 2014-10-17T20:52:51.088Z * License: MIT */ - (function () { "use strict"; @@ -28,6 +27,10 @@ BACKSPACE: 8, DELETE: 46, COMMAND: 91, + + MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "SPACE" , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + }, + isControl: function (e) { var k = e.which; switch (k) { @@ -342,6 +345,11 @@ if(ctrl.tagging.isActivated && !item && ctrl.search.length > 0) { // create new item on the fly item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + // if(ctrl.taggingTokens.isActivated) { + // setTimeout(function() {}, 10); + // _resetSearchInput(); + + // } } var locals = {}; @@ -538,6 +546,15 @@ if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); + if ( ctrl.taggingTokens.isActivated ) { + for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { + console.log(ctrl.taggingTokens.tokens[i]) + if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) { + ctrl.select(null, true); + _searchInput.triggerHandler('tagged') + } + }; + } } if (processed && key != KEY.TAB) { @@ -554,6 +571,12 @@ }); + _searchInput.on('tagged', function() { + $timeout(function() { + _resetSearchInput(); + }); + }); + _searchInput.on('blur', function() { $timeout(function() { ctrl.activeMatchIndex = -1; @@ -791,6 +814,18 @@ } }); + attrs.$observe('taggingTokens', function() { + if(attrs.tagging !== undefined && attrs.taggingTokens !== undefined) + { + var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',']; + $select.taggingTokens = {isActivated: true, tokens: tokens }; + } + else + { + $select.taggingTokens = {isActivated: false, tokens: undefined}; + } + }); + if ($select.multiple){ scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { if (oldValue != newValue) @@ -1002,4 +1037,4 @@ $templateCache.put("select2/select-multiple.tpl.html","
    "); $templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); $templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file +$templateCache.put("selectize/select.tpl.html","
    ");}]); diff --git a/dist/select.min.css b/dist/select.min.css index 5d63eb62c..6ca712604 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T20:37:37.506Z + * Version: 0.8.3 - 2014-10-17T20:52:51.091Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 40a92d43f..2c8865d6d 100755 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T20:37:37.502Z + * Version: 0.8.3 - 2014-10-17T20:52:51.088Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){var c=d.parserResult.source(t);if(e.length){var s=c.filter(function(t){return e.indexOf(t)<0});a(s)}else a(c);d.sizeSearchInput()})};var v;d.refresh=function(e){void 0!==e&&(v&&s.cancel(v),v=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return"undefined"==typeof e[d.itemProperty]?!1:d.open&&d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){if(d.open){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s}},d.select=function(e,c){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var s={};s[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,s)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close(c)}},d.close=function(e){d.open&&(n(),d.open=!1,d.multiple||s(function(){d.focusser.prop("disabled",!1),e||d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){var c=d.selected[e],s={};s[d.parserResult.itemName]=c,d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput(),d.onRemoveCallback(t,{$item:c,$model:d.parserResult.modelMapper(t,s)})},d.getPlaceholder=function(){return d.multiple&&d.selected.length?void 0:d.placeholder};var f;d.sizeSearchInput=function(){var e=h[0],c=h.parent().parent()[0];h.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),h.css("width",t+"px")};s(function(){0!==c.clientWidth||f?f||l():f=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),f(),f=null)})},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s)),t&&s!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(s)&&d.items.length>0&&u()}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=i(a.onSelect),d.onRemoveCallback=i(a.onRemove),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=d.selected.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=d.selected[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var v=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):v.attr("tabindex",e),n.removeAttr("tabindex")}),l(v)(c),d.focusser=v,d.multiple||(n.append(v),v.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),v.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(v.val()),v.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),v.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/src/select.js b/src/select.js index 62540315b..616592283 100644 --- a/src/select.js +++ b/src/select.js @@ -20,6 +20,10 @@ BACKSPACE: 8, DELETE: 46, COMMAND: 91, + + MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "SPACE" , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + }, + isControl: function (e) { var k = e.which; switch (k) { @@ -334,6 +338,11 @@ if(ctrl.tagging.isActivated && !item && ctrl.search.length > 0) { // create new item on the fly item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + // if(ctrl.taggingTokens.isActivated) { + // setTimeout(function() {}, 10); + // _resetSearchInput(); + + // } } var locals = {}; @@ -530,6 +539,15 @@ if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) { processed = _handleDropDownSelection(key); + if ( ctrl.taggingTokens.isActivated ) { + for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { + console.log(ctrl.taggingTokens.tokens[i]) + if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) { + ctrl.select(null, true); + _searchInput.triggerHandler('tagged') + } + }; + } } if (processed && key != KEY.TAB) { @@ -546,6 +564,12 @@ }); + _searchInput.on('tagged', function() { + $timeout(function() { + _resetSearchInput(); + }); + }); + _searchInput.on('blur', function() { $timeout(function() { ctrl.activeMatchIndex = -1; @@ -783,6 +807,18 @@ } }); + attrs.$observe('taggingTokens', function() { + if(attrs.tagging !== undefined && attrs.taggingTokens !== undefined) + { + var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',']; + $select.taggingTokens = {isActivated: true, tokens: tokens }; + } + else + { + $select.taggingTokens = {isActivated: false, tokens: undefined}; + } + }); + if ($select.multiple){ scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { if (oldValue != newValue) From 2580e0860365564c15a755bc0cc24c3ff49a8041 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Fri, 17 Oct 2014 16:58:07 -0400 Subject: [PATCH 14/32] Cleaning up logging, unused code --- dist/select.css | 2 +- dist/select.js | 9 ++------- dist/select.min.css | 2 +- dist/select.min.js | 2 +- src/select.js | 5 ----- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/dist/select.css b/dist/select.css index 3451d411c..8053c1fb2 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T20:52:51.091Z + * Version: 0.8.3 - 2014-10-17T20:56:08.746Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index 0b63a155f..36a3344f1 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T20:52:51.088Z + * Version: 0.8.3 - 2014-10-17T20:56:08.744Z * License: MIT */ @@ -345,11 +345,6 @@ if(ctrl.tagging.isActivated && !item && ctrl.search.length > 0) { // create new item on the fly item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; - // if(ctrl.taggingTokens.isActivated) { - // setTimeout(function() {}, 10); - // _resetSearchInput(); - - // } } var locals = {}; @@ -548,7 +543,6 @@ processed = _handleDropDownSelection(key); if ( ctrl.taggingTokens.isActivated ) { for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { - console.log(ctrl.taggingTokens.tokens[i]) if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) { ctrl.select(null, true); _searchInput.triggerHandler('tagged') @@ -1025,6 +1019,7 @@ }); }()); + angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
      0\">
    • 0\">
      {{$group.name}}
    "); $templateCache.put("bootstrap/match-multiple.tpl.html"," × "); $templateCache.put("bootstrap/match.tpl.html",""); diff --git a/dist/select.min.css b/dist/select.min.css index 6ca712604..77a29bd35 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T20:52:51.091Z + * Version: 0.8.3 - 2014-10-17T20:56:08.746Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 2c8865d6d..d590ef573 100755 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T20:52:51.088Z + * Version: 0.8.3 - 2014-10-17T20:56:08.744Z * License: MIT */ angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/src/select.js b/src/select.js index 616592283..d8db2648b 100644 --- a/src/select.js +++ b/src/select.js @@ -338,11 +338,6 @@ if(ctrl.tagging.isActivated && !item && ctrl.search.length > 0) { // create new item on the fly item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; - // if(ctrl.taggingTokens.isActivated) { - // setTimeout(function() {}, 10); - // _resetSearchInput(); - - // } } var locals = {}; From ec9341491325e0a040b441eb4c7d3275c5b0585d Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Mon, 20 Oct 2014 09:46:43 -0400 Subject: [PATCH 15/32] Code cleanup to pass jshint --- dist/select.css | 167 -------------------------------------------- dist/select.js | 8 +-- dist/select.min.css | 6 -- dist/select.min.js | 4 +- src/select.js | 5 +- 5 files changed, 8 insertions(+), 182 deletions(-) delete mode 100644 dist/select.css delete mode 100644 dist/select.min.css diff --git a/dist/select.css b/dist/select.css deleted file mode 100644 index 8053c1fb2..000000000 --- a/dist/select.css +++ /dev/null @@ -1,167 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T20:56:08.746Z - * License: MIT - */ - - -/* Style when highlighting a search. */ -.ui-select-highlight { - font-weight: bold; -} - -.ui-select-offscreen { - clip: rect(0 0 0 0) !important; - width: 1px !important; - height: 1px !important; - border: 0 !important; - margin: 0 !important; - padding: 0 !important; - overflow: hidden !important; - position: absolute !important; - outline: 0 !important; - left: 0px !important; - top: 0px !important; -} - -/* Select2 theme */ - -/* Mark invalid Select2 */ -.ng-dirty.ng-invalid > a.select2-choice { - border-color: #D44950; -} - -.select2-result-single { - padding-left: 0; -} - -/* Selectize theme */ - -/* Helper class to show styles when focus */ -.selectize-input.selectize-focus{ - border-color: #007FBB !important; -} - -/* Fix input width for Selectize theme */ -.selectize-control > .selectize-input > input { - width: 100%; -} - -/* Fix dropdown width for Selectize theme */ -.selectize-control > .selectize-dropdown { - width: 100%; -} - -/* Mark invalid Selectize */ -.ng-dirty.ng-invalid > div.selectize-input { - border-color: #D44950; -} - - -/* Bootstrap theme */ - -/* Helper class to show styles when focus */ -.btn-default-focus { - color: #333; - background-color: #EBEBEB; - border-color: #ADADAD; - text-decoration: none; - outline: 5px auto -webkit-focus-ring-color; - outline-offset: -2px; - box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); -} - - -/* Fix Bootstrap dropdown position when inside a input-group */ -.input-group > .ui-select-bootstrap.dropdown { - /* Instead of relative */ - position: static; -} - -.input-group > .ui-select-bootstrap > input.ui-select-search.form-control { - border-radius: 4px; /* FIXME hardcoded value :-/ */ - border-top-right-radius: 0; - border-bottom-right-radius: 0; -} - -.ui-select-bootstrap > .ui-select-match { - /* Instead of center because of .btn */ - text-align: left; -} - -.ui-select-bootstrap > .ui-select-match > .caret { - position: absolute; - top: 45%; - right: 15px; -} - -/* See Scrollable Menu with Bootstrap 3 http://stackoverflow.com/questions/19227496 */ -.ui-select-bootstrap > .ui-select-choices { - width: 100%; - height: auto; - max-height: 200px; - overflow-x: hidden; -} - -.ui-select-multiple.ui-select-bootstrap { - height: auto; - padding: .3em; -} - -.ui-select-multiple.ui-select-bootstrap input.ui-select-search { - background-color: transparent !important; /* To prevent double background when disabled */ - border: none; - outline: none; - height: 1.666666em; -} - -.ui-select-multiple.ui-select-bootstrap .ui-select-match .close { - font-size: 1.6em; - line-height: 0.75; -} - -.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{ - outline: 0; -} - -.ui-select-bootstrap .ui-select-choices-row>a { - display: block; - padding: 3px 20px; - clear: both; - font-weight: 400; - line-height: 1.42857143; - color: #333; - white-space: nowrap; -} - -.ui-select-bootstrap .ui-select-choices-row>a:hover, .ui-select-bootstrap .ui-select-choices-row>a:focus { - text-decoration: none; - color: #262626; - background-color: #f5f5f5; -} - -.ui-select-bootstrap .ui-select-choices-row.active>a { - color: #fff; - text-decoration: none; - outline: 0; - background-color: #428bca; -} - -.ui-select-bootstrap .ui-select-choices-row.disabled>a, -.ui-select-bootstrap .ui-select-choices-row.active.disabled>a { - color: #777; - cursor: not-allowed; - background-color: #fff; -} - -/* fix hide/show angular animation */ -.ui-select-match.ng-hide-add, -.ui-select-search.ng-hide-add { - display: none !important; -} - -/* Mark invalid Bootstrap */ -.ui-select-bootstrap.ng-dirty.ng-invalid > button.btn.ui-select-match { - border-color: #D44950; -} diff --git a/dist/select.js b/dist/select.js index 36a3344f1..31522b762 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,10 +1,11 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T20:56:08.744Z + * Version: 0.8.3 - 2014-10-20T13:46:05.676Z * License: MIT */ + (function () { "use strict"; @@ -545,9 +546,9 @@ for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) { ctrl.select(null, true); - _searchInput.triggerHandler('tagged') + _searchInput.triggerHandler('tagged'); } - }; + } } } @@ -1019,7 +1020,6 @@ }); }()); - angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
      0\">
    • 0\">
      {{$group.name}}
    "); $templateCache.put("bootstrap/match-multiple.tpl.html"," × "); $templateCache.put("bootstrap/match.tpl.html",""); diff --git a/dist/select.min.css b/dist/select.min.css deleted file mode 100644 index 77a29bd35..000000000 --- a/dist/select.min.css +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T20:56:08.746Z - * License: MIT - */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index d590ef573..06c695d06 100755 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-17T20:56:08.744Z + * Version: 0.8.3 - 2014-10-20T13:46:05.676Z * License: MIT */ -angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:"SPACE",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){var c=d.parserResult.source(t);if(e.length){var s=c.filter(function(t){return e.indexOf(t)<0});a(s)}else a(c);d.sizeSearchInput()})};var g;d.refresh=function(e){void 0!==e&&(g&&s.cancel(g),g=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return"undefined"==typeof e[d.itemProperty]?!1:d.open&&d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){if(d.open){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s}},d.select=function(e,c){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var s={};s[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,s)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close(c)}},d.close=function(e){d.open&&(n(),d.open=!1,d.multiple||s(function(){d.focusser.prop("disabled",!1),e||d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){var c=d.selected[e],s={};s[d.parserResult.itemName]=c,d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput(),d.onRemoveCallback(t,{$item:c,$model:d.parserResult.modelMapper(t,s)})},d.getPlaceholder=function(){return d.multiple&&d.selected.length?void 0:d.placeholder};var v;d.sizeSearchInput=function(){var e=h[0],c=h.parent().parent()[0];h.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),h.css("width",t+"px")};s(function(){0!==c.clientWidth||v?v||l():v=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),v(),v=null)})},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;if(d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s),d.taggingTokens.isActivated))for(var l=0;l0&&u()}),h.on("tagged",function(){s(function(){n()})}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=i(a.onSelect),d.onRemoveCallback=i(a.onRemove),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=d.selected.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=d.selected[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var g=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):g.attr("tabindex",e),n.removeAttr("tabindex")}),l(g)(c),d.focusser=g,d.multiple||(n.append(g),g.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),g.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),g.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),g.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(g.val()),g.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),a.$observe("taggingTokens",function(){if(void 0!==a.tagging&&void 0!==a.taggingTokens){var e=void 0!==a.taggingTokens?a.taggingTokens.split("|"):[","];d.taggingTokens={isActivated:!0,tokens:e}}else d.taggingTokens={isActivated:!1,tokens:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),g.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/src/select.js b/src/select.js index d8db2648b..7c798385e 100644 --- a/src/select.js +++ b/src/select.js @@ -536,12 +536,11 @@ processed = _handleDropDownSelection(key); if ( ctrl.taggingTokens.isActivated ) { for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { - console.log(ctrl.taggingTokens.tokens[i]) if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) { ctrl.select(null, true); - _searchInput.triggerHandler('tagged') + _searchInput.triggerHandler('tagged'); } - }; + } } } From b61bf9c36da40016985c777cd9f3828734152bc2 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Mon, 20 Oct 2014 09:48:48 -0400 Subject: [PATCH 16/32] Recompile CSS --- dist/select.css | 167 ++++++++++++++++++++++++++++++++++++++++++++ dist/select.js | 4 +- dist/select.min.css | 6 ++ dist/select.min.js | 2 +- 4 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 dist/select.css create mode 100644 dist/select.min.css diff --git a/dist/select.css b/dist/select.css new file mode 100644 index 000000000..22836f89a --- /dev/null +++ b/dist/select.css @@ -0,0 +1,167 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.8.3 - 2014-10-20T13:48:28.234Z + * License: MIT + */ + + +/* Style when highlighting a search. */ +.ui-select-highlight { + font-weight: bold; +} + +.ui-select-offscreen { + clip: rect(0 0 0 0) !important; + width: 1px !important; + height: 1px !important; + border: 0 !important; + margin: 0 !important; + padding: 0 !important; + overflow: hidden !important; + position: absolute !important; + outline: 0 !important; + left: 0px !important; + top: 0px !important; +} + +/* Select2 theme */ + +/* Mark invalid Select2 */ +.ng-dirty.ng-invalid > a.select2-choice { + border-color: #D44950; +} + +.select2-result-single { + padding-left: 0; +} + +/* Selectize theme */ + +/* Helper class to show styles when focus */ +.selectize-input.selectize-focus{ + border-color: #007FBB !important; +} + +/* Fix input width for Selectize theme */ +.selectize-control > .selectize-input > input { + width: 100%; +} + +/* Fix dropdown width for Selectize theme */ +.selectize-control > .selectize-dropdown { + width: 100%; +} + +/* Mark invalid Selectize */ +.ng-dirty.ng-invalid > div.selectize-input { + border-color: #D44950; +} + + +/* Bootstrap theme */ + +/* Helper class to show styles when focus */ +.btn-default-focus { + color: #333; + background-color: #EBEBEB; + border-color: #ADADAD; + text-decoration: none; + outline: 5px auto -webkit-focus-ring-color; + outline-offset: -2px; + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); +} + + +/* Fix Bootstrap dropdown position when inside a input-group */ +.input-group > .ui-select-bootstrap.dropdown { + /* Instead of relative */ + position: static; +} + +.input-group > .ui-select-bootstrap > input.ui-select-search.form-control { + border-radius: 4px; /* FIXME hardcoded value :-/ */ + border-top-right-radius: 0; + border-bottom-right-radius: 0; +} + +.ui-select-bootstrap > .ui-select-match { + /* Instead of center because of .btn */ + text-align: left; +} + +.ui-select-bootstrap > .ui-select-match > .caret { + position: absolute; + top: 45%; + right: 15px; +} + +/* See Scrollable Menu with Bootstrap 3 http://stackoverflow.com/questions/19227496 */ +.ui-select-bootstrap > .ui-select-choices { + width: 100%; + height: auto; + max-height: 200px; + overflow-x: hidden; +} + +.ui-select-multiple.ui-select-bootstrap { + height: auto; + padding: .3em; +} + +.ui-select-multiple.ui-select-bootstrap input.ui-select-search { + background-color: transparent !important; /* To prevent double background when disabled */ + border: none; + outline: none; + height: 1.666666em; +} + +.ui-select-multiple.ui-select-bootstrap .ui-select-match .close { + font-size: 1.6em; + line-height: 0.75; +} + +.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{ + outline: 0; +} + +.ui-select-bootstrap .ui-select-choices-row>a { + display: block; + padding: 3px 20px; + clear: both; + font-weight: 400; + line-height: 1.42857143; + color: #333; + white-space: nowrap; +} + +.ui-select-bootstrap .ui-select-choices-row>a:hover, .ui-select-bootstrap .ui-select-choices-row>a:focus { + text-decoration: none; + color: #262626; + background-color: #f5f5f5; +} + +.ui-select-bootstrap .ui-select-choices-row.active>a { + color: #fff; + text-decoration: none; + outline: 0; + background-color: #428bca; +} + +.ui-select-bootstrap .ui-select-choices-row.disabled>a, +.ui-select-bootstrap .ui-select-choices-row.active.disabled>a { + color: #777; + cursor: not-allowed; + background-color: #fff; +} + +/* fix hide/show angular animation */ +.ui-select-match.ng-hide-add, +.ui-select-search.ng-hide-add { + display: none !important; +} + +/* Mark invalid Bootstrap */ +.ui-select-bootstrap.ng-dirty.ng-invalid > button.btn.ui-select-match { + border-color: #D44950; +} diff --git a/dist/select.js b/dist/select.js index 31522b762..d3f00a2c1 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-20T13:46:05.676Z + * Version: 0.8.3 - 2014-10-20T13:48:28.231Z * License: MIT */ @@ -1032,4 +1032,4 @@ $templateCache.put("select2/select-multiple.tpl.html","
    "); $templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); $templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); +$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.min.css b/dist/select.min.css new file mode 100644 index 000000000..7c8199991 --- /dev/null +++ b/dist/select.min.css @@ -0,0 +1,6 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.8.3 - 2014-10-20T13:48:28.234Z + * License: MIT + */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 06c695d06..772086553 100755 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-20T13:46:05.676Z + * Version: 0.8.3 - 2014-10-20T13:48:28.231Z * License: MIT */ !function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:"SPACE",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){var c=d.parserResult.source(t);if(e.length){var s=c.filter(function(t){return e.indexOf(t)<0});a(s)}else a(c);d.sizeSearchInput()})};var g;d.refresh=function(e){void 0!==e&&(g&&s.cancel(g),g=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return"undefined"==typeof e[d.itemProperty]?!1:d.open&&d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){if(d.open){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s}},d.select=function(e,c){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var s={};s[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,s)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close(c)}},d.close=function(e){d.open&&(n(),d.open=!1,d.multiple||s(function(){d.focusser.prop("disabled",!1),e||d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){var c=d.selected[e],s={};s[d.parserResult.itemName]=c,d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput(),d.onRemoveCallback(t,{$item:c,$model:d.parserResult.modelMapper(t,s)})},d.getPlaceholder=function(){return d.multiple&&d.selected.length?void 0:d.placeholder};var v;d.sizeSearchInput=function(){var e=h[0],c=h.parent().parent()[0];h.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),h.css("width",t+"px")};s(function(){0!==c.clientWidth||v?v||l():v=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),v(),v=null)})},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;if(d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s),d.taggingTokens.isActivated))for(var l=0;l0&&u()}),h.on("tagged",function(){s(function(){n()})}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=i(a.onSelect),d.onRemoveCallback=i(a.onRemove),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=d.selected.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=d.selected[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var g=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):g.attr("tabindex",e),n.removeAttr("tabindex")}),l(g)(c),d.focusser=g,d.multiple||(n.append(g),g.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),g.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),g.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),g.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(g.val()),g.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),a.$observe("taggingTokens",function(){if(void 0!==a.tagging&&void 0!==a.taggingTokens){var e=void 0!==a.taggingTokens?a.taggingTokens.split("|"):[","];d.taggingTokens={isActivated:!0,tokens:e}}else d.taggingTokens={isActivated:!1,tokens:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),g.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file From eeea7103c45a470f4a8b20995021a4c1a4e71cb4 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Mon, 20 Oct 2014 12:06:59 -0400 Subject: [PATCH 17/32] Fix over-selection in dropdown --- dist/select.css | 2 +- dist/select.js | 12 ++++++++---- dist/select.min.css | 2 +- dist/select.min.js | 4 ++-- src/select.js | 10 +++++++--- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/dist/select.css b/dist/select.css index 22836f89a..25484f2a6 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-20T13:48:28.234Z + * Version: 0.8.3 - 2014-10-20T16:06:30.609Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index d3f00a2c1..c50db956a 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-20T13:48:28.231Z + * Version: 0.8.3 - 2014-10-20T16:06:30.607Z * License: MIT */ @@ -316,10 +316,14 @@ }; ctrl.isActive = function(itemScope) { - if ( typeof itemScope[ctrl.itemProperty] === 'undefined') { - return false; + var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + if ( ctrl.open && ( ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex ) ) { + var item = ctrl.items[itemIndex]; + if ( typeof item === 'undefined' ) { + return ctrl.open && false; + } } - return ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; + return ctrl.open && itemIndex === ctrl.activeIndex; }; ctrl.isDisabled = function(itemScope) { diff --git a/dist/select.min.css b/dist/select.min.css index 7c8199991..28d4cbe92 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-20T13:48:28.234Z + * Version: 0.8.3 - 2014-10-20T16:06:30.609Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 772086553..58f092161 100755 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-20T13:48:28.231Z + * Version: 0.8.3 - 2014-10-20T16:06:30.607Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:"SPACE",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){var c=d.parserResult.source(t);if(e.length){var s=c.filter(function(t){return e.indexOf(t)<0});a(s)}else a(c);d.sizeSearchInput()})};var g;d.refresh=function(e){void 0!==e&&(g&&s.cancel(g),g=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){return"undefined"==typeof e[d.itemProperty]?!1:d.open&&d.items.indexOf(e[d.itemProperty])===d.activeIndex},d.isDisabled=function(e){if(d.open){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s}},d.select=function(e,c){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var s={};s[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,s)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close(c)}},d.close=function(e){d.open&&(n(),d.open=!1,d.multiple||s(function(){d.focusser.prop("disabled",!1),e||d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){var c=d.selected[e],s={};s[d.parserResult.itemName]=c,d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput(),d.onRemoveCallback(t,{$item:c,$model:d.parserResult.modelMapper(t,s)})},d.getPlaceholder=function(){return d.multiple&&d.selected.length?void 0:d.placeholder};var v;d.sizeSearchInput=function(){var e=h[0],c=h.parent().parent()[0];h.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),h.css("width",t+"px")};s(function(){0!==c.clientWidth||v?v||l():v=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),v(),v=null)})},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;if(d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s),d.taggingTokens.isActivated))for(var l=0;l0&&u()}),h.on("tagged",function(){s(function(){n()})}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=i(a.onSelect),d.onRemoveCallback=i(a.onRemove),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=d.selected.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=d.selected[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var g=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):g.attr("tabindex",e),n.removeAttr("tabindex")}),l(g)(c),d.focusser=g,d.multiple||(n.append(g),g.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),g.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),g.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),g.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(g.val()),g.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),a.$observe("taggingTokens",function(){if(void 0!==a.tagging&&void 0!==a.taggingTokens){var e=void 0!==a.taggingTokens?a.taggingTokens.split("|"):[","];d.taggingTokens={isActivated:!0,tokens:e}}else d.taggingTokens={isActivated:!1,tokens:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),g.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:"SPACE",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){var c=d.parserResult.source(t);if(e.length){var s=c.filter(function(t){return e.indexOf(t)<0});a(s)}else a(c);d.sizeSearchInput()})};var g;d.refresh=function(e){void 0!==e&&(g&&s.cancel(g),g=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){var t=d.items.indexOf(e[d.itemProperty]);if(d.open&&d.items.indexOf(e[d.itemProperty])===d.activeIndex){var c=d.items[t];if("undefined"==typeof c)return d.open&&!1}return d.open&&t===d.activeIndex},d.isDisabled=function(e){if(d.open){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s}},d.select=function(e,c){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var s={};s[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,s)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close(c)}},d.close=function(e){d.open&&(n(),d.open=!1,d.multiple||s(function(){d.focusser.prop("disabled",!1),e||d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){var c=d.selected[e],s={};s[d.parserResult.itemName]=c,d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput(),d.onRemoveCallback(t,{$item:c,$model:d.parserResult.modelMapper(t,s)})},d.getPlaceholder=function(){return d.multiple&&d.selected.length?void 0:d.placeholder};var v;d.sizeSearchInput=function(){var e=h[0],c=h.parent().parent()[0];h.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),h.css("width",t+"px")};s(function(){0!==c.clientWidth||v?v||l():v=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),v(),v=null)})},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;if(d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s),d.taggingTokens.isActivated))for(var l=0;l0&&u()}),h.on("tagged",function(){s(function(){n()})}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=i(a.onSelect),d.onRemoveCallback=i(a.onRemove),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=d.selected.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=d.selected[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var g=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):g.attr("tabindex",e),n.removeAttr("tabindex")}),l(g)(c),d.focusser=g,d.multiple||(n.append(g),g.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),g.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),g.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),g.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(g.val()),g.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),a.$observe("taggingTokens",function(){if(void 0!==a.tagging&&void 0!==a.taggingTokens){var e=void 0!==a.taggingTokens?a.taggingTokens.split("|"):[","];d.taggingTokens={isActivated:!0,tokens:e}}else d.taggingTokens={isActivated:!1,tokens:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),g.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/src/select.js b/src/select.js index 7c798385e..b81030b2f 100644 --- a/src/select.js +++ b/src/select.js @@ -308,10 +308,14 @@ }; ctrl.isActive = function(itemScope) { - if ( typeof itemScope[ctrl.itemProperty] === 'undefined') { - return false; + var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + if ( ctrl.open && ( ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex ) ) { + var item = ctrl.items[itemIndex]; + if ( typeof item === 'undefined' ) { + return ctrl.open && false; + } } - return ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; + return ctrl.open && itemIndex === ctrl.activeIndex; }; ctrl.isDisabled = function(itemScope) { From e6a04b4beffa8229bd53c7af18c1dfe0e00b5a65 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Tue, 21 Oct 2014 18:02:12 -0400 Subject: [PATCH 18/32] Finish up demos, make tests pass, introduce distinction between tagging with labels in drop down and tagging without labels --- dist/select.css | 2 +- dist/select.js | 199 +++++++++++++++++++++++++++++++++---- dist/select.min.css | 2 +- dist/select.min.js | 4 +- examples/demo-tagging.html | 71 ++++--------- examples/demo.js | 2 + src/select.js | 197 ++++++++++++++++++++++++++++++++---- test/select.spec.js | 45 +++++---- 8 files changed, 409 insertions(+), 113 deletions(-) diff --git a/dist/select.css b/dist/select.css index 25484f2a6..69677f830 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-20T16:06:30.609Z + * Version: 0.8.3 - 2014-10-21T21:55:48.791Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index c50db956a..3988d6574 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-20T16:06:30.607Z + * Version: 0.8.3 - 2014-10-21T21:55:48.787Z * License: MIT */ @@ -149,8 +149,8 @@ * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested. */ .controller('uiSelectCtrl', - ['$scope', '$element', '$timeout', 'RepeatParser', 'uiSelectMinErr', - function($scope, $element, $timeout, RepeatParser, uiSelectMinErr) { + ['$scope', '$element', '$timeout', '$filter', 'RepeatParser', 'uiSelectMinErr', + function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr) { var ctrl = this; @@ -171,6 +171,7 @@ ctrl.refreshDelay = undefined; // Initialized inside uiSelectChoices directive link function ctrl.multiple = false; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelect directive link function + ctrl.$filter = $filter; ctrl.isEmpty = function() { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; @@ -280,8 +281,10 @@ if (!selectedItems.length) { setItemsFn(data); }else{ - var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;}); - setItemsFn(filteredItems); + if ( data !== undefined ) { + var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;}); + setItemsFn(filteredItems); + } } ctrl.sizeSearchInput(); }); @@ -317,12 +320,6 @@ ctrl.isActive = function(itemScope) { var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - if ( ctrl.open && ( ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex ) ) { - var item = ctrl.items[itemIndex]; - if ( typeof item === 'undefined' ) { - return ctrl.open && false; - } - } return ctrl.open && itemIndex === ctrl.activeIndex; }; @@ -343,13 +340,43 @@ return isDisabled; }; - // When the user clicks on an item inside the dropdown + // When the user selects an item with ENTER or clicks the dropdown ctrl.select = function(item, skipFocusser) { + if ( ! ctrl.items && ! ctrl.search ) return; + if (!item || !item._uiSelectChoiceDisabled) { - if(ctrl.tagging.isActivated && !item && ctrl.search.length > 0) { - // create new item on the fly - item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + if(ctrl.tagging.isActivated) { + // if taggingLabel is disabled, we pull from ctrl.search val + if ( ctrl.taggingLabel === false ) { + if ( ctrl.activeIndex < 0 ) { + item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + if ( ! angular.equals( ctrl.items[0], item ) ) { + item = item; + } else { + return; + } + } else { + // keyboard nav happened first, user selected from dropdown + item = ctrl.items[ctrl.activeIndex]; + } + } else { + // tagging always operates at index zero, taggingLabel === false pushes + // the ctrl.search value without having it injected + if ( ctrl.activeIndex === 0 ) { + // ctrl.tagging pushes items to ctrl.items, so we only have empty val + // for `item` if it is a detected duplicate + if ( item === undefined ) return; + // create new item on the fly + if ( ctrl.taggingLabel && ctrl.taggingLabel.length > 0 ) {} + item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : item.replace(ctrl.taggingLabel,''); + } + } + // search ctrl.selected for dupes potentially caused by tagging and return early if found + if ( ctrl.selected && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) { + ctrl.close(skipFocusser); + return; + } } var locals = {}; @@ -549,8 +576,11 @@ if ( ctrl.taggingTokens.isActivated ) { for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) { - ctrl.select(null, true); - _searchInput.triggerHandler('tagged'); + // make sure there is a new value to push via tagging + if ( ctrl.search.length > 0 ) { + ctrl.select(null, true); + _searchInput.triggerHandler('tagged'); + } } } } @@ -570,6 +600,104 @@ }); + _searchInput.on('keyup', function(e) { + // Push a "create new" item into array if there is a search string + if ( ctrl.tagging.isActivated && ctrl.search.length > 0 ) { + + // return early with these keys + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || KEY.isVerticalMovement(e.which) ) { + return; + } + // always reset the activeIndex to the first item when tagging + ctrl.activeIndex = ctrl.taggingLabel === false ? -1 : 0; + // taggingLabel === false bypasses all of this + if (ctrl.taggingLabel === false) return; + + var items = angular.copy( ctrl.items ); + var stashArr = angular.copy( ctrl.items ); + var newItem; + var item; + var hasTag = false; + var dupeIndex = -1; + var tagItems; + var tagItem; + + // case for object tagging via transform `ctrl.tagging.fct` function + if ( ctrl.tagging.fct !== undefined) { + tagItems = ctrl.$filter('filter')(items,{'isTag': true}); + if ( tagItems.length > 0 ) { + tagItem = tagItems[0]; + } + // remove the first element, if it has the `isTag` prop we generate a new one with each keyup, shaving the previous + if ( items.length > 0 && tagItem ) { + hasTag = true; + items = items.slice(1,items.length); + stashArr = stashArr.slice(1,stashArr.length); + } + newItem = ctrl.tagging.fct(ctrl.search); + newItem.isTag = true; + // verify the the tag doesn't match the value of an existing item + if ( stashArr.filter( function (origItem) { return angular.equals( origItem, ctrl.tagging.fct(ctrl.search) ); } ).length > 0 ) { + return; + } + // handle newItem string and stripping dupes in tagging string context + } else { + // find any tagging items already in the ctrl.items array and store them + tagItems = ctrl.$filter('filter')(items,function (item) { + return item.match(ctrl.taggingLabel); + }); + if ( tagItems.length > 0 ) { + tagItem = tagItems[0]; + } + item = items[0]; + // remove existing tag item if found (should only ever be one tag item) + if ( item !== undefined && items.length > 0 && tagItem ) { + hasTag = true; + items = items.slice(1,items.length); + stashArr = stashArr.slice(1,stashArr.length); + } + newItem = ctrl.search+' '+ctrl.taggingLabel; + if ( _findApproxDupe(ctrl.selected, ctrl.search) > -1 ) { + return; + } + // verify the the tag doesn't match the value of an existing item from + // the searched data set + if ( stashArr.filter( function (origItem) { return origItem.toUpperCase() === ctrl.search.toUpperCase(); }).length > 0 ) { + // if there is a tag from prev iteration, strip it / queue the change + // and return early + if ( hasTag ) { + items = stashArr; + $scope.$evalAsync( function () { + ctrl.activeIndex = 0; + ctrl.items = items; + }); + } + return; + } + if ( ctrl.selected.filter( function (selection) { return selection.toUpperCase() === ctrl.search.toUpperCase(); } ).length > 0 ) { + // if there is a tag from prev iteration, strip it + if ( hasTag ) { + ctrl.items = stashArr.slice(1,stashArr.length); + } + return; + } + } + if ( hasTag ) dupeIndex = _findApproxDupe(ctrl.selected, newItem); + // dupe found, shave the first item + if ( dupeIndex > -1 ) { + items = items.slice(dupeIndex+1,items.length-1); + } else { + items = []; + items.push(newItem); + items = items.concat(stashArr); + } + $scope.$evalAsync( function () { + ctrl.activeIndex = 0; + ctrl.items = items; + }); + } + }); + _searchInput.on('tagged', function() { $timeout(function() { _resetSearchInput(); @@ -582,6 +710,28 @@ }); }); + function _findApproxDupe(haystack, needle) { + var tempArr = angular.copy(haystack); + var dupeIndex = -1; + for (var i = 0; i a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 58f092161..7e17eb6e2 100755 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-20T16:06:30.607Z + * Version: 0.8.3 - 2014-10-21T21:55:48.787Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:"SPACE",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var s=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!s)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:s[2],source:t(s[3]),trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(t,c,s,l,i){function n(){d.resetSearchInput&&(d.search=p,d.selected&&d.items.length&&!d.multiple&&(d.activeIndex=d.items.indexOf(d.selected)))}function a(t){var c=!0;switch(t){case e.DOWN:!d.open&&d.multiple?d.activate(!1,!0):d.activeIndex0||0===d.search.length&&d.tagging.isActivated)&&d.activeIndex--;break;case e.TAB:(!d.multiple||d.open)&&d.select(d.items[d.activeIndex],!0);break;case e.ENTER:d.open?d.select(d.items[d.activeIndex]):d.activate(!1,!0);break;case e.ESC:d.close();break;default:c=!1}return c}function r(t){function c(){switch(t){case e.LEFT:return~d.activeMatchIndex?u:n;case e.RIGHT:return~d.activeMatchIndex&&a!==n?r:(d.activate(),!1);case e.BACKSPACE:return~d.activeMatchIndex?(d.removeChoice(a),u):n;case e.DELETE:return~d.activeMatchIndex?(d.removeChoice(d.activeMatchIndex),a):!1}}var s=o(h[0]),l=d.selected.length,i=0,n=l-1,a=d.activeMatchIndex,r=d.activeMatchIndex+1,u=d.activeMatchIndex-1,p=a;return s>0||d.search.length&&t==e.RIGHT?!1:(d.close(),p=c(),d.activeMatchIndex=d.selected.length&&p!==!1?Math.min(n,Math.max(i,p)):-1,!0)}function o(e){return angular.isNumber(e.selectionStart)?e.selectionStart:e.value.length}function u(){var e=c.querySelectorAll(".ui-select-choices-content"),t=e.querySelectorAll(".ui-select-choices-row");if(t.length<1)throw i("choices","Expected multiple .ui-select-choices-row but got '{0}'.",t.length);var s=t[d.activeIndex],l=s.offsetTop+s.clientHeight-e[0].scrollTop,n=e[0].offsetHeight;l>n?e[0].scrollTop+=l-n:l=d.items.length?0:d.activeIndex,s(function(){d.search=e||d.search,h[0].focus()}))},d.findGroupByName=function(e){return d.groups&&d.groups.filter(function(t){return t.name===e})[0]},d.parseRepeatAttr=function(e,c){function s(e){d.groups=[],angular.forEach(e,function(e){var s=t.$eval(c),l=angular.isFunction(s)?s(e):e[s],i=d.findGroupByName(l);i?i.items.push(e):d.groups.push({name:l,items:[e]})}),d.items=[],d.groups.forEach(function(e){d.items=d.items.concat(e.items)})}function n(e){d.items=e}var a=c?s:n;d.parserResult=l.parse(e),d.isGrouped=!!c,d.itemProperty=d.parserResult.itemName,t.$watchCollection(d.parserResult.source,function(e){if(void 0===e||null===e)d.items=[];else{if(!angular.isArray(e))throw i("items","Expected an array but got '{0}'.",e);if(d.multiple){var t=e.filter(function(e){return d.selected.indexOf(e)<0});a(t)}else a(e);d.ngModel.$modelValue=null}}),d.multiple&&t.$watchCollection("$select.selected",function(e){var c=d.parserResult.source(t);if(e.length){var s=c.filter(function(t){return e.indexOf(t)<0});a(s)}else a(c);d.sizeSearchInput()})};var g;d.refresh=function(e){void 0!==e&&(g&&s.cancel(g),g=s(function(){t.$eval(e)},d.refreshDelay))},d.setActiveItem=function(e){d.activeIndex=d.items.indexOf(e)},d.isActive=function(e){var t=d.items.indexOf(e[d.itemProperty]);if(d.open&&d.items.indexOf(e[d.itemProperty])===d.activeIndex){var c=d.items[t];if("undefined"==typeof c)return d.open&&!1}return d.open&&t===d.activeIndex},d.isDisabled=function(e){if(d.open){var t,c=d.items.indexOf(e[d.itemProperty]),s=!1;return c>=0&&!angular.isUndefined(d.disableChoiceExpression)&&(t=d.items[c],s=!!e.$eval(d.disableChoiceExpression),t._uiSelectChoiceDisabled=s),s}},d.select=function(e,c){if(!e||!e._uiSelectChoiceDisabled){d.tagging.isActivated&&!e&&d.search.length>0&&(e=void 0!==d.tagging.fct?d.tagging.fct(d.search):d.search);var s={};s[d.parserResult.itemName]=e,d.onSelectCallback(t,{$item:e,$model:d.parserResult.modelMapper(t,s)}),d.multiple?(d.selected.push(e),d.sizeSearchInput()):d.selected=e,d.close(c)}},d.close=function(e){d.open&&(n(),d.open=!1,d.multiple||s(function(){d.focusser.prop("disabled",!1),e||d.focusser[0].focus()},0,!1))},d.toggle=function(e){d.open?d.close():d.activate(),e.preventDefault(),e.stopPropagation()},d.removeChoice=function(e){var c=d.selected[e],s={};s[d.parserResult.itemName]=c,d.selected.splice(e,1),d.activeMatchIndex=-1,d.sizeSearchInput(),d.onRemoveCallback(t,{$item:c,$model:d.parserResult.modelMapper(t,s)})},d.getPlaceholder=function(){return d.multiple&&d.selected.length?void 0:d.placeholder};var v;d.sizeSearchInput=function(){var e=h[0],c=h.parent().parent()[0];h.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),h.css("width",t+"px")};s(function(){0!==c.clientWidth||v?v||l():v=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),v(),v=null)})},0,!1)},h.on("keydown",function(c){var s=c.which;t.$apply(function(){var t=!1;if(d.multiple&&e.isHorizontalMovement(s)&&(t=r(s)),!t&&(d.items.length>0||d.tagging.isActivated)&&(t=a(s),d.taggingTokens.isActivated))for(var l=0;l0&&u()}),h.on("tagged",function(){s(function(){n()})}),h.on("blur",function(){s(function(){d.activeMatchIndex=-1})}),t.$on("$destroy",function(){h.off("keydown blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,s,l,i){return{restrict:"EA",templateUrl:function(e,t){var s=t.theme||c.theme;return s+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=i(a.onSelect),d.onRemoveCallback=i(a.onRemove),p.$parsers.unshift(function(e){var t,s={};if(d.multiple){for(var l=[],i=d.selected.length-1;i>=0;i--)s={},s[d.parserResult.itemName]=d.selected[i],t=d.parserResult.modelMapper(c,s),l.unshift(t);return l}return s={},s[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,s)}),p.$formatters.unshift(function(e){var t,s=d.parserResult.source(c,{$select:{search:""}}),l={};if(s){if(d.multiple){var i=[],n=function(e,s){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==s)return i.unshift(e[n]),!0;return!1}};if(!e)return i;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(s,e[a]);return i}var r=function(s){return l[d.parserResult.itemName]=s,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=s.length-1;o>=0;o--)if(r(s[o]))return s[o]}return e}),d.ngModel=p;var g=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):g.attr("tabindex",e),n.removeAttr("tabindex")}),l(g)(c),d.focusser=g,d.multiple||(n.append(g),g.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),g.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),g.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),g.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(g.val()),g.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),a.$observe("taggingTokens",function(){if(void 0!==a.tagging&&void 0!==a.taggingTokens){var e=void 0!==a.taggingTokens?a.taggingTokens.split("|"):[","];d.taggingTokens={isActivated:!0,tokens:e}}else d.taggingTokens={isActivated:!1,tokens:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),g.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw s("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw s("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw s("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,i){if(!i.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,i,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=i.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=i.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),s(i,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,s,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,s=t.parent().attr("multiple");return c+(s?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:"SPACE",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var i=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,i){var l=e+" in "+(i?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","RepeatParser","uiSelectMinErr",function(t,c,i,l,s,n){function a(){h.resetSearchInput&&(h.search=g,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function r(t){var c=!0;switch(t){case e.DOWN:!h.open&&h.multiple?h.activate(!1,!0):h.activeIndex0||0===h.search.length&&h.tagging.isActivated)&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function o(t){function c(){switch(t){case e.LEFT:return~h.activeMatchIndex?o:n;case e.RIGHT:return~h.activeMatchIndex&&a!==n?r:(h.activate(),!1);case e.BACKSPACE:return~h.activeMatchIndex?(h.removeChoice(a),o):n;case e.DELETE:return~h.activeMatchIndex?(h.removeChoice(h.activeMatchIndex),a):!1}}var i=d(v[0]),l=h.selected.length,s=0,n=l-1,a=h.activeMatchIndex,r=h.activeMatchIndex+1,o=h.activeMatchIndex-1,u=a;return i>0||h.search.length&&t==e.RIGHT?!1:(h.close(),u=c(),h.activeMatchIndex=h.selected.length&&u!==!1?Math.min(n,Math.max(s,u)):-1,!0)}function u(e,t){for(var c=angular.copy(e),i=-1,l=0;ls?e[0].scrollTop+=l-s:l=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,v[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,c){function i(e){h.groups=[],angular.forEach(e,function(e){var i=t.$eval(c),l=angular.isFunction(i)?i(e):e[i],s=h.findGroupByName(l);s?s.items.push(e):h.groups.push({name:l,items:[e]})}),h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}var a=c?i:l;h.parserResult=s.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw n("items","Expected an array but got '{0}'.",e);if(h.multiple){var t=e.filter(function(e){return h.selected.indexOf(e)<0});a(t)}else a(e);h.ngModel.$modelValue=null}}),h.multiple&&t.$watchCollection("$select.selected",function(e){var c=h.parserResult.source(t);if(e.length){if(void 0!==c){var i=c.filter(function(t){return e.indexOf(t)<0});a(i)}}else a(c);h.sizeSearchInput()})};var f;h.refresh=function(e){void 0!==e&&(f&&i.cancel(f),f=i(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){var t=h.items.indexOf(e[h.itemProperty]);return h.open&&t===h.activeIndex},h.isDisabled=function(e){if(h.open){var t,c=h.items.indexOf(e[h.itemProperty]),i=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i}},h.select=function(e,c){if(!(!h.items&&!h.search||e&&e._uiSelectChoiceDisabled)){if(h.tagging.isActivated){if(h.taggingLabel===!1)if(h.activeIndex<0){if(e=void 0!==h.tagging.fct?h.tagging.fct(h.search):h.search,angular.equals(h.items[0],e))return;e=e}else e=h.items[h.activeIndex];else if(0===h.activeIndex){if(void 0===e)return;h.taggingLabel&&h.taggingLabel.length>0,e=void 0!==h.tagging.fct?h.tagging.fct(h.search):e.replace(h.taggingLabel,"")}if(h.selected&&h.selected.filter(function(t){return angular.equals(t,e)}).length>0)return h.close(c),void 0}var i={};i[h.parserResult.itemName]=e,h.onSelectCallback(t,{$item:e,$model:h.parserResult.modelMapper(t,i)}),h.multiple?(h.selected.push(e),h.sizeSearchInput()):h.selected=e,h.close(c)}},h.close=function(e){h.open&&(a(),h.open=!1,h.multiple||i(function(){h.focusser.prop("disabled",!1),e||h.focusser[0].focus()},0,!1))},h.toggle=function(e){h.open?h.close():h.activate(),e.preventDefault(),e.stopPropagation()},h.removeChoice=function(e){var c=h.selected[e],i={};i[h.parserResult.itemName]=c,h.selected.splice(e,1),h.activeMatchIndex=-1,h.sizeSearchInput(),h.onRemoveCallback(t,{$item:c,$model:h.parserResult.modelMapper(t,i)})},h.getPlaceholder=function(){return h.multiple&&h.selected.length?void 0:h.placeholder};var m;h.sizeSearchInput=function(){var e=v[0],c=v.parent().parent()[0];v.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),v.css("width",t+"px")};i(function(){0!==c.clientWidth||m?m||l():m=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),m(),m=null)})},0,!1)},v.on("keydown",function(c){var i=c.which;t.$apply(function(){var t=!1;if(h.multiple&&e.isHorizontalMovement(i)&&(t=o(i)),!t&&(h.items.length>0||h.tagging.isActivated)&&(t=r(i),h.taggingTokens.isActivated))for(var l=0;l0&&(h.select(null,!0),v.triggerHandler("tagged"));t&&i!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(i)&&h.items.length>0&&p()}),v.on("keyup",function(c){if(h.tagging.isActivated&&h.search.length>0){if(c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which))return;if(h.activeIndex=h.taggingLabel===!1?-1:0,h.taggingLabel===!1)return;var i,l,s,n,a=angular.copy(h.items),r=angular.copy(h.items),o=!1,d=-1;if(void 0!==h.tagging.fct){if(s=h.$filter("filter")(a,{isTag:!0}),s.length>0&&(n=s[0]),a.length>0&&n&&(o=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),i=h.tagging.fct(h.search),i.isTag=!0,r.filter(function(e){return angular.equals(e,h.tagging.fct(h.search))}).length>0)return}else{if(s=h.$filter("filter")(a,function(e){return e.match(h.taggingLabel)}),s.length>0&&(n=s[0]),l=a[0],void 0!==l&&a.length>0&&n&&(o=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),i=h.search+" "+h.taggingLabel,u(h.selected,h.search)>-1)return;if(r.filter(function(e){return e.toUpperCase()===h.search.toUpperCase()}).length>0)return o&&(a=r,t.$evalAsync(function(){h.activeIndex=0,h.items=a})),void 0;if(h.selected.filter(function(e){return e.toUpperCase()===h.search.toUpperCase()}).length>0)return o&&(h.items=r.slice(1,r.length)),void 0}o&&(d=u(h.selected,i)),d>-1?a=a.slice(d+1,a.length-1):(a=[],a.push(i),a=a.concat(r)),t.$evalAsync(function(){h.activeIndex=0,h.items=a})}}),v.on("tagged",function(){i(function(){a()})}),v.on("blur",function(){i(function(){h.activeMatchIndex=-1})}),t.$on("$destroy",function(){v.off("keyup keydown tagged blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,i,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||c.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=s(a.onSelect),d.onRemoveCallback=s(a.onRemove),p.$parsers.unshift(function(e){var t,i={};if(d.multiple){for(var l=[],s=d.selected.length-1;s>=0;s--)i={},i[d.parserResult.itemName]=d.selected[s],t=d.parserResult.modelMapper(c,i),l.unshift(t);return l}return i={},i[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,i)}),p.$formatters.unshift(function(e){var t,i=d.parserResult.source(c,{$select:{search:""}}),l={};if(i){if(d.multiple){var s=[],n=function(e,i){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==i)return s.unshift(e[n]),!0;return!1}};if(!e)return s;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(i,e[a]);return s}var r=function(i){return l[d.parserResult.itemName]=i,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=i.length-1;o>=0;o--)if(r(i[o]))return i[o]}return e}),d.ngModel=p;var g=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):g.attr("tabindex",e),n.removeAttr("tabindex")}),l(g)(c),d.focusser=g,d.multiple||(n.append(g),g.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),g.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),g.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),g.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(g.val()),g.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),a.$observe("taggingLabel",function(){void 0!==a.tagging&&void 0!==a.taggingLabel&&(d.taggingLabel="false"===a.taggingLabel?!1:void 0!==a.taggingLabel?a.taggingLabel:"(new)")}),a.$observe("taggingTokens",function(){if(void 0!==a.tagging&&void 0!==a.taggingTokens){var e=void 0!==a.taggingTokens?a.taggingTokens.split("|"):[","];d.taggingTokens={isActivated:!0,tokens:e}}else d.taggingTokens={isActivated:!1,tokens:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),g.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw i("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,s,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),i(s,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,i,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return c+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,i,l){i.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/examples/demo-tagging.html b/examples/demo-tagging.html index 091e4fbde..4edd62700 100644 --- a/examples/demo-tagging.html +++ b/examples/demo-tagging.html @@ -62,65 +62,28 @@ - - - - -

    Multi Selection Demos

    +

    Selected: {{multipleDemo.colors}}

    +
    -

    Simple String Tags

    - +

    Simple String Tags (No Labels)

    + {{$item}} {{color}} -

    Selected: {{multipleDemo.colors}}

    +

    Selected: {{multipleDemo.colors2}}


    +

    Object Tags

    {{$item.name}} <{{$item.email}}> @@ -132,19 +95,23 @@

    Object Tags

    +

    Selected: {{multipleDemo.selectedPeople}}

    +
    +

    Object Tags with Tokenization (Space, Forward Slash, Comma)

    Note that the SPACE character can't be used literally, use the keyword SPACE - + {{$item.name}} <{{$item.email}}> -
    +
    +
    email: {{person.email}} age:
    -

    Selected: {{multipleDemo.selectedPeople}}

    +

    Selected: {{multipleDemo.selectedPeople2}}

    diff --git a/examples/demo.js b/examples/demo.js index 29355a1af..402227995 100644 --- a/examples/demo.js +++ b/examples/demo.js @@ -135,7 +135,9 @@ app.controller('DemoCtrl', function($scope, $http, $timeout) { $scope.multipleDemo = {}; $scope.multipleDemo.colors = ['Blue','Red']; + $scope.multipleDemo.colors2 = ['Blue','Red']; $scope.multipleDemo.selectedPeople = [$scope.people[5], $scope.people[4]]; + $scope.multipleDemo.selectedPeople2 = $scope.multipleDemo.selectedPeople; $scope.multipleDemo.selectedPeopleWithGroupBy = [$scope.people[8], $scope.people[6]]; $scope.multipleDemo.selectedPeopleSimple = ['samantha@email.com','wladimir@email.com']; diff --git a/src/select.js b/src/select.js index b81030b2f..6c4d4f22c 100644 --- a/src/select.js +++ b/src/select.js @@ -141,8 +141,8 @@ * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested. */ .controller('uiSelectCtrl', - ['$scope', '$element', '$timeout', 'RepeatParser', 'uiSelectMinErr', - function($scope, $element, $timeout, RepeatParser, uiSelectMinErr) { + ['$scope', '$element', '$timeout', '$filter', 'RepeatParser', 'uiSelectMinErr', + function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr) { var ctrl = this; @@ -163,6 +163,7 @@ ctrl.refreshDelay = undefined; // Initialized inside uiSelectChoices directive link function ctrl.multiple = false; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelect directive link function + ctrl.$filter = $filter; ctrl.isEmpty = function() { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; @@ -272,8 +273,10 @@ if (!selectedItems.length) { setItemsFn(data); }else{ - var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;}); - setItemsFn(filteredItems); + if ( data !== undefined ) { + var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;}); + setItemsFn(filteredItems); + } } ctrl.sizeSearchInput(); }); @@ -309,12 +312,6 @@ ctrl.isActive = function(itemScope) { var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); - if ( ctrl.open && ( ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex ) ) { - var item = ctrl.items[itemIndex]; - if ( typeof item === 'undefined' ) { - return ctrl.open && false; - } - } return ctrl.open && itemIndex === ctrl.activeIndex; }; @@ -335,13 +332,43 @@ return isDisabled; }; - // When the user clicks on an item inside the dropdown + // When the user selects an item with ENTER or clicks the dropdown ctrl.select = function(item, skipFocusser) { + if ( ! ctrl.items && ! ctrl.search ) return; + if (!item || !item._uiSelectChoiceDisabled) { - if(ctrl.tagging.isActivated && !item && ctrl.search.length > 0) { - // create new item on the fly - item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + if(ctrl.tagging.isActivated) { + // if taggingLabel is disabled, we pull from ctrl.search val + if ( ctrl.taggingLabel === false ) { + if ( ctrl.activeIndex < 0 ) { + item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + if ( ! angular.equals( ctrl.items[0], item ) ) { + item = item; + } else { + return; + } + } else { + // keyboard nav happened first, user selected from dropdown + item = ctrl.items[ctrl.activeIndex]; + } + } else { + // tagging always operates at index zero, taggingLabel === false pushes + // the ctrl.search value without having it injected + if ( ctrl.activeIndex === 0 ) { + // ctrl.tagging pushes items to ctrl.items, so we only have empty val + // for `item` if it is a detected duplicate + if ( item === undefined ) return; + // create new item on the fly + if ( ctrl.taggingLabel && ctrl.taggingLabel.length > 0 ) {} + item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : item.replace(ctrl.taggingLabel,''); + } + } + // search ctrl.selected for dupes potentially caused by tagging and return early if found + if ( ctrl.selected && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) { + ctrl.close(skipFocusser); + return; + } } var locals = {}; @@ -541,8 +568,11 @@ if ( ctrl.taggingTokens.isActivated ) { for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) { - ctrl.select(null, true); - _searchInput.triggerHandler('tagged'); + // make sure there is a new value to push via tagging + if ( ctrl.search.length > 0 ) { + ctrl.select(null, true); + _searchInput.triggerHandler('tagged'); + } } } } @@ -562,6 +592,104 @@ }); + _searchInput.on('keyup', function(e) { + // Push a "create new" item into array if there is a search string + if ( ctrl.tagging.isActivated && ctrl.search.length > 0 ) { + + // return early with these keys + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || KEY.isVerticalMovement(e.which) ) { + return; + } + // always reset the activeIndex to the first item when tagging + ctrl.activeIndex = ctrl.taggingLabel === false ? -1 : 0; + // taggingLabel === false bypasses all of this + if (ctrl.taggingLabel === false) return; + + var items = angular.copy( ctrl.items ); + var stashArr = angular.copy( ctrl.items ); + var newItem; + var item; + var hasTag = false; + var dupeIndex = -1; + var tagItems; + var tagItem; + + // case for object tagging via transform `ctrl.tagging.fct` function + if ( ctrl.tagging.fct !== undefined) { + tagItems = ctrl.$filter('filter')(items,{'isTag': true}); + if ( tagItems.length > 0 ) { + tagItem = tagItems[0]; + } + // remove the first element, if it has the `isTag` prop we generate a new one with each keyup, shaving the previous + if ( items.length > 0 && tagItem ) { + hasTag = true; + items = items.slice(1,items.length); + stashArr = stashArr.slice(1,stashArr.length); + } + newItem = ctrl.tagging.fct(ctrl.search); + newItem.isTag = true; + // verify the the tag doesn't match the value of an existing item + if ( stashArr.filter( function (origItem) { return angular.equals( origItem, ctrl.tagging.fct(ctrl.search) ); } ).length > 0 ) { + return; + } + // handle newItem string and stripping dupes in tagging string context + } else { + // find any tagging items already in the ctrl.items array and store them + tagItems = ctrl.$filter('filter')(items,function (item) { + return item.match(ctrl.taggingLabel); + }); + if ( tagItems.length > 0 ) { + tagItem = tagItems[0]; + } + item = items[0]; + // remove existing tag item if found (should only ever be one tag item) + if ( item !== undefined && items.length > 0 && tagItem ) { + hasTag = true; + items = items.slice(1,items.length); + stashArr = stashArr.slice(1,stashArr.length); + } + newItem = ctrl.search+' '+ctrl.taggingLabel; + if ( _findApproxDupe(ctrl.selected, ctrl.search) > -1 ) { + return; + } + // verify the the tag doesn't match the value of an existing item from + // the searched data set + if ( stashArr.filter( function (origItem) { return origItem.toUpperCase() === ctrl.search.toUpperCase(); }).length > 0 ) { + // if there is a tag from prev iteration, strip it / queue the change + // and return early + if ( hasTag ) { + items = stashArr; + $scope.$evalAsync( function () { + ctrl.activeIndex = 0; + ctrl.items = items; + }); + } + return; + } + if ( ctrl.selected.filter( function (selection) { return selection.toUpperCase() === ctrl.search.toUpperCase(); } ).length > 0 ) { + // if there is a tag from prev iteration, strip it + if ( hasTag ) { + ctrl.items = stashArr.slice(1,stashArr.length); + } + return; + } + } + if ( hasTag ) dupeIndex = _findApproxDupe(ctrl.selected, newItem); + // dupe found, shave the first item + if ( dupeIndex > -1 ) { + items = items.slice(dupeIndex+1,items.length-1); + } else { + items = []; + items.push(newItem); + items = items.concat(stashArr); + } + $scope.$evalAsync( function () { + ctrl.activeIndex = 0; + ctrl.items = items; + }); + } + }); + _searchInput.on('tagged', function() { $timeout(function() { _resetSearchInput(); @@ -574,6 +702,28 @@ }); }); + function _findApproxDupe(haystack, needle) { + var tempArr = angular.copy(haystack); + var dupeIndex = -1; + for (var i = 0; i \ @@ -620,7 +621,7 @@ describe('ui-select tests', function() { scope.$digest(); expect(getMatchLabel(el)).toEqual('Samantha'); }); - + it('should format the model correctly using property of alias', function() { var el = compileTemplate( ' \ @@ -634,7 +635,7 @@ describe('ui-select tests', function() { clickItem(el, 'Samantha'); expect(scope.selection.selected).toBe('Samantha'); }); - + it('should parse the model correctly using property of alias', function() { var el = compileTemplate( ' \ @@ -649,7 +650,7 @@ describe('ui-select tests', function() { scope.$digest(); expect(getMatchLabel(el)).toEqual('Samantha'); }); - + it('should parse the model correctly using property of alias with async choices data', function() { var el = compileTemplate( ' \ @@ -688,13 +689,13 @@ describe('ui-select tests', function() { scope.$digest(); expect(getMatchLabel(el)).toEqual('Samantha'); }); - + it('should format the model correctly without alias', function() { var el = createUiSelect(); clickItem(el, 'Samantha'); expect(scope.selection.selected).toBe(scope.people[5]); }); - + it('should parse the model correctly without alias', function() { var el = createUiSelect(); scope.selection.selected = scope.people[5]; @@ -956,8 +957,8 @@ describe('ui-select tests', function() { scope.fetchFromServer = function(searching){ if (searching == 's') - return scope.people - + return scope.people + if (searching == 'o'){ scope.people = []; //To simulate cases were previously selected item isnt in the list anymore } @@ -1065,7 +1066,7 @@ describe('ui-select tests', function() { }); it('should set model as an empty array if ngModel isnt defined', function () { - + // scope.selection.selectedMultiple = []; var el = createUiSelectMultiple(); @@ -1151,7 +1152,7 @@ describe('ui-select tests', function() { triggerKeydown(searchInput, Key.Left); triggerKeydown(searchInput, Key.Backspace); expect(el.scope().$select.selected).toEqual([scope.people[4], scope.people[6]]); //Wladimir & Nicole - + expect(el.scope().$select.activeMatchIndex).toBe(0); }); @@ -1167,7 +1168,7 @@ describe('ui-select tests', function() { triggerKeydown(searchInput, Key.Left); triggerKeydown(searchInput, Key.Delete); expect(el.scope().$select.selected).toEqual([scope.people[4], scope.people[6]]); //Wladimir & Nicole - + expect(el.scope().$select.activeMatchIndex).toBe(1); }); @@ -1382,7 +1383,7 @@ describe('ui-select tests', function() { }); it('should format view value correctly when using single property binding and refresh funcion', function () { - + scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; var el = compileTemplate( @@ -1401,8 +1402,8 @@ describe('ui-select tests', function() { scope.fetchFromServer = function(searching){ if (searching == 'n') - return scope.people - + return scope.people + if (searching == 'o'){ scope.people = []; //To simulate cases were previously selected item isnt in the list anymore } @@ -1423,7 +1424,7 @@ describe('ui-select tests', function() { }); it('should watch changes for $select.selected and update formatted value correctly', function () { - + scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; var el = compileTemplate( @@ -1452,7 +1453,7 @@ describe('ui-select tests', function() { }); it('should change viewvalue only once when updating modelvalue', function () { - + scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; var el = compileTemplate( @@ -1479,7 +1480,7 @@ describe('ui-select tests', function() { it('should run $formatters when changing model directly', function () { - + scope.selection.selectedMultiple = ['wladimir@email.com', 'samantha@email.com']; var el = compileTemplate( From 67937477cb78ca95f215b010db6c9504dbc695d0 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Tue, 21 Oct 2014 18:41:45 -0400 Subject: [PATCH 19/32] Finalizes over-selection problem for `taggingLabel === false` being having ambiguous `ctrl.activeIndex` --- dist/select.css | 2 +- dist/select.js | 10 +++++++++- dist/select.min.css | 2 +- dist/select.min.js | 4 ++-- examples/demo-tagging.html | 3 ++- src/select.js | 8 ++++++++ 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/dist/select.css b/dist/select.css index 69677f830..bfb63da03 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-21T21:55:48.791Z + * Version: 0.8.3 - 2014-10-21T22:40:46.669Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index 3988d6574..0a5b2a3f6 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-21T21:55:48.787Z + * Version: 0.8.3 - 2014-10-21T22:40:46.668Z * License: MIT */ @@ -320,6 +320,9 @@ ctrl.isActive = function(itemScope) { var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + if ( ctrl.taggingLabel === false && ctrl.activeIndex === -1 ) { + return false; + } return ctrl.open && itemIndex === ctrl.activeIndex; }; @@ -601,6 +604,11 @@ }); _searchInput.on('keyup', function(e) { + if ( ! KEY.isVerticalMovement(e.which) ) { + $scope.$evalAsync( function () { + ctrl.activeIndex = ctrl.taggingLabel === false ? -1 : 0; + }); + } // Push a "create new" item into array if there is a search string if ( ctrl.tagging.isActivated && ctrl.search.length > 0 ) { diff --git a/dist/select.min.css b/dist/select.min.css index e6e4270bb..07b81abc6 100644 --- a/dist/select.min.css +++ b/dist/select.min.css @@ -1,6 +1,6 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-21T21:55:48.791Z + * Version: 0.8.3 - 2014-10-21T22:40:46.669Z * License: MIT */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js index 7e17eb6e2..b334ffd50 100755 --- a/dist/select.min.js +++ b/dist/select.min.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-21T21:55:48.787Z + * Version: 0.8.3 - 2014-10-21T22:40:46.668Z * License: MIT */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:"SPACE",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var i=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,i){var l=e+" in "+(i?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","RepeatParser","uiSelectMinErr",function(t,c,i,l,s,n){function a(){h.resetSearchInput&&(h.search=g,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function r(t){var c=!0;switch(t){case e.DOWN:!h.open&&h.multiple?h.activate(!1,!0):h.activeIndex0||0===h.search.length&&h.tagging.isActivated)&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function o(t){function c(){switch(t){case e.LEFT:return~h.activeMatchIndex?o:n;case e.RIGHT:return~h.activeMatchIndex&&a!==n?r:(h.activate(),!1);case e.BACKSPACE:return~h.activeMatchIndex?(h.removeChoice(a),o):n;case e.DELETE:return~h.activeMatchIndex?(h.removeChoice(h.activeMatchIndex),a):!1}}var i=d(v[0]),l=h.selected.length,s=0,n=l-1,a=h.activeMatchIndex,r=h.activeMatchIndex+1,o=h.activeMatchIndex-1,u=a;return i>0||h.search.length&&t==e.RIGHT?!1:(h.close(),u=c(),h.activeMatchIndex=h.selected.length&&u!==!1?Math.min(n,Math.max(s,u)):-1,!0)}function u(e,t){for(var c=angular.copy(e),i=-1,l=0;ls?e[0].scrollTop+=l-s:l=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,v[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,c){function i(e){h.groups=[],angular.forEach(e,function(e){var i=t.$eval(c),l=angular.isFunction(i)?i(e):e[i],s=h.findGroupByName(l);s?s.items.push(e):h.groups.push({name:l,items:[e]})}),h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}var a=c?i:l;h.parserResult=s.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw n("items","Expected an array but got '{0}'.",e);if(h.multiple){var t=e.filter(function(e){return h.selected.indexOf(e)<0});a(t)}else a(e);h.ngModel.$modelValue=null}}),h.multiple&&t.$watchCollection("$select.selected",function(e){var c=h.parserResult.source(t);if(e.length){if(void 0!==c){var i=c.filter(function(t){return e.indexOf(t)<0});a(i)}}else a(c);h.sizeSearchInput()})};var f;h.refresh=function(e){void 0!==e&&(f&&i.cancel(f),f=i(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){var t=h.items.indexOf(e[h.itemProperty]);return h.open&&t===h.activeIndex},h.isDisabled=function(e){if(h.open){var t,c=h.items.indexOf(e[h.itemProperty]),i=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i}},h.select=function(e,c){if(!(!h.items&&!h.search||e&&e._uiSelectChoiceDisabled)){if(h.tagging.isActivated){if(h.taggingLabel===!1)if(h.activeIndex<0){if(e=void 0!==h.tagging.fct?h.tagging.fct(h.search):h.search,angular.equals(h.items[0],e))return;e=e}else e=h.items[h.activeIndex];else if(0===h.activeIndex){if(void 0===e)return;h.taggingLabel&&h.taggingLabel.length>0,e=void 0!==h.tagging.fct?h.tagging.fct(h.search):e.replace(h.taggingLabel,"")}if(h.selected&&h.selected.filter(function(t){return angular.equals(t,e)}).length>0)return h.close(c),void 0}var i={};i[h.parserResult.itemName]=e,h.onSelectCallback(t,{$item:e,$model:h.parserResult.modelMapper(t,i)}),h.multiple?(h.selected.push(e),h.sizeSearchInput()):h.selected=e,h.close(c)}},h.close=function(e){h.open&&(a(),h.open=!1,h.multiple||i(function(){h.focusser.prop("disabled",!1),e||h.focusser[0].focus()},0,!1))},h.toggle=function(e){h.open?h.close():h.activate(),e.preventDefault(),e.stopPropagation()},h.removeChoice=function(e){var c=h.selected[e],i={};i[h.parserResult.itemName]=c,h.selected.splice(e,1),h.activeMatchIndex=-1,h.sizeSearchInput(),h.onRemoveCallback(t,{$item:c,$model:h.parserResult.modelMapper(t,i)})},h.getPlaceholder=function(){return h.multiple&&h.selected.length?void 0:h.placeholder};var m;h.sizeSearchInput=function(){var e=v[0],c=v.parent().parent()[0];v.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),v.css("width",t+"px")};i(function(){0!==c.clientWidth||m?m||l():m=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),m(),m=null)})},0,!1)},v.on("keydown",function(c){var i=c.which;t.$apply(function(){var t=!1;if(h.multiple&&e.isHorizontalMovement(i)&&(t=o(i)),!t&&(h.items.length>0||h.tagging.isActivated)&&(t=r(i),h.taggingTokens.isActivated))for(var l=0;l0&&(h.select(null,!0),v.triggerHandler("tagged"));t&&i!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(i)&&h.items.length>0&&p()}),v.on("keyup",function(c){if(h.tagging.isActivated&&h.search.length>0){if(c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which))return;if(h.activeIndex=h.taggingLabel===!1?-1:0,h.taggingLabel===!1)return;var i,l,s,n,a=angular.copy(h.items),r=angular.copy(h.items),o=!1,d=-1;if(void 0!==h.tagging.fct){if(s=h.$filter("filter")(a,{isTag:!0}),s.length>0&&(n=s[0]),a.length>0&&n&&(o=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),i=h.tagging.fct(h.search),i.isTag=!0,r.filter(function(e){return angular.equals(e,h.tagging.fct(h.search))}).length>0)return}else{if(s=h.$filter("filter")(a,function(e){return e.match(h.taggingLabel)}),s.length>0&&(n=s[0]),l=a[0],void 0!==l&&a.length>0&&n&&(o=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),i=h.search+" "+h.taggingLabel,u(h.selected,h.search)>-1)return;if(r.filter(function(e){return e.toUpperCase()===h.search.toUpperCase()}).length>0)return o&&(a=r,t.$evalAsync(function(){h.activeIndex=0,h.items=a})),void 0;if(h.selected.filter(function(e){return e.toUpperCase()===h.search.toUpperCase()}).length>0)return o&&(h.items=r.slice(1,r.length)),void 0}o&&(d=u(h.selected,i)),d>-1?a=a.slice(d+1,a.length-1):(a=[],a.push(i),a=a.concat(r)),t.$evalAsync(function(){h.activeIndex=0,h.items=a})}}),v.on("tagged",function(){i(function(){a()})}),v.on("blur",function(){i(function(){h.activeMatchIndex=-1})}),t.$on("$destroy",function(){v.off("keyup keydown tagged blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,i,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||c.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=s(a.onSelect),d.onRemoveCallback=s(a.onRemove),p.$parsers.unshift(function(e){var t,i={};if(d.multiple){for(var l=[],s=d.selected.length-1;s>=0;s--)i={},i[d.parserResult.itemName]=d.selected[s],t=d.parserResult.modelMapper(c,i),l.unshift(t);return l}return i={},i[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,i)}),p.$formatters.unshift(function(e){var t,i=d.parserResult.source(c,{$select:{search:""}}),l={};if(i){if(d.multiple){var s=[],n=function(e,i){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==i)return s.unshift(e[n]),!0;return!1}};if(!e)return s;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(i,e[a]);return s}var r=function(i){return l[d.parserResult.itemName]=i,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=i.length-1;o>=0;o--)if(r(i[o]))return i[o]}return e}),d.ngModel=p;var g=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):g.attr("tabindex",e),n.removeAttr("tabindex")}),l(g)(c),d.focusser=g,d.multiple||(n.append(g),g.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),g.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),g.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),g.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(g.val()),g.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),a.$observe("taggingLabel",function(){void 0!==a.tagging&&void 0!==a.taggingLabel&&(d.taggingLabel="false"===a.taggingLabel?!1:void 0!==a.taggingLabel?a.taggingLabel:"(new)")}),a.$observe("taggingTokens",function(){if(void 0!==a.tagging&&void 0!==a.taggingTokens){var e=void 0!==a.taggingTokens?a.taggingTokens.split("|"):[","];d.taggingTokens={isActivated:!0,tokens:e}}else d.taggingTokens={isActivated:!1,tokens:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),g.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw i("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,s,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),i(s,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,i,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return c+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,i,l){i.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:"SPACE",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var i=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,i){var l=e+" in "+(i?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","RepeatParser","uiSelectMinErr",function(t,c,i,l,s,n){function a(){h.resetSearchInput&&(h.search=g,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function r(t){var c=!0;switch(t){case e.DOWN:!h.open&&h.multiple?h.activate(!1,!0):h.activeIndex0||0===h.search.length&&h.tagging.isActivated)&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function o(t){function c(){switch(t){case e.LEFT:return~h.activeMatchIndex?o:n;case e.RIGHT:return~h.activeMatchIndex&&a!==n?r:(h.activate(),!1);case e.BACKSPACE:return~h.activeMatchIndex?(h.removeChoice(a),o):n;case e.DELETE:return~h.activeMatchIndex?(h.removeChoice(h.activeMatchIndex),a):!1}}var i=d(v[0]),l=h.selected.length,s=0,n=l-1,a=h.activeMatchIndex,r=h.activeMatchIndex+1,o=h.activeMatchIndex-1,u=a;return i>0||h.search.length&&t==e.RIGHT?!1:(h.close(),u=c(),h.activeMatchIndex=h.selected.length&&u!==!1?Math.min(n,Math.max(s,u)):-1,!0)}function u(e,t){for(var c=angular.copy(e),i=-1,l=0;ls?e[0].scrollTop+=l-s:l=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,v[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,c){function i(e){h.groups=[],angular.forEach(e,function(e){var i=t.$eval(c),l=angular.isFunction(i)?i(e):e[i],s=h.findGroupByName(l);s?s.items.push(e):h.groups.push({name:l,items:[e]})}),h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}var a=c?i:l;h.parserResult=s.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw n("items","Expected an array but got '{0}'.",e);if(h.multiple){var t=e.filter(function(e){return h.selected.indexOf(e)<0});a(t)}else a(e);h.ngModel.$modelValue=null}}),h.multiple&&t.$watchCollection("$select.selected",function(e){var c=h.parserResult.source(t);if(e.length){if(void 0!==c){var i=c.filter(function(t){return e.indexOf(t)<0});a(i)}}else a(c);h.sizeSearchInput()})};var f;h.refresh=function(e){void 0!==e&&(f&&i.cancel(f),f=i(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){var t=h.items.indexOf(e[h.itemProperty]);return h.taggingLabel===!1&&-1===h.activeIndex?!1:h.open&&t===h.activeIndex},h.isDisabled=function(e){if(h.open){var t,c=h.items.indexOf(e[h.itemProperty]),i=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i}},h.select=function(e,c){if(!(!h.items&&!h.search||e&&e._uiSelectChoiceDisabled)){if(h.tagging.isActivated){if(h.taggingLabel===!1)if(h.activeIndex<0){if(e=void 0!==h.tagging.fct?h.tagging.fct(h.search):h.search,angular.equals(h.items[0],e))return;e=e}else e=h.items[h.activeIndex];else if(0===h.activeIndex){if(void 0===e)return;h.taggingLabel&&h.taggingLabel.length>0,e=void 0!==h.tagging.fct?h.tagging.fct(h.search):e.replace(h.taggingLabel,"")}if(h.selected&&h.selected.filter(function(t){return angular.equals(t,e)}).length>0)return h.close(c),void 0}var i={};i[h.parserResult.itemName]=e,h.onSelectCallback(t,{$item:e,$model:h.parserResult.modelMapper(t,i)}),h.multiple?(h.selected.push(e),h.sizeSearchInput()):h.selected=e,h.close(c)}},h.close=function(e){h.open&&(a(),h.open=!1,h.multiple||i(function(){h.focusser.prop("disabled",!1),e||h.focusser[0].focus()},0,!1))},h.toggle=function(e){h.open?h.close():h.activate(),e.preventDefault(),e.stopPropagation()},h.removeChoice=function(e){var c=h.selected[e],i={};i[h.parserResult.itemName]=c,h.selected.splice(e,1),h.activeMatchIndex=-1,h.sizeSearchInput(),h.onRemoveCallback(t,{$item:c,$model:h.parserResult.modelMapper(t,i)})},h.getPlaceholder=function(){return h.multiple&&h.selected.length?void 0:h.placeholder};var m;h.sizeSearchInput=function(){var e=v[0],c=v.parent().parent()[0];v.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),v.css("width",t+"px")};i(function(){0!==c.clientWidth||m?m||l():m=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),m(),m=null)})},0,!1)},v.on("keydown",function(c){var i=c.which;t.$apply(function(){var t=!1;if(h.multiple&&e.isHorizontalMovement(i)&&(t=o(i)),!t&&(h.items.length>0||h.tagging.isActivated)&&(t=r(i),h.taggingTokens.isActivated))for(var l=0;l0&&(h.select(null,!0),v.triggerHandler("tagged"));t&&i!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(i)&&h.items.length>0&&p()}),v.on("keyup",function(c){if(e.isVerticalMovement(c.which)||t.$evalAsync(function(){h.activeIndex=h.taggingLabel===!1?-1:0}),h.tagging.isActivated&&h.search.length>0){if(c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which))return;if(h.activeIndex=h.taggingLabel===!1?-1:0,h.taggingLabel===!1)return;var i,l,s,n,a=angular.copy(h.items),r=angular.copy(h.items),o=!1,d=-1;if(void 0!==h.tagging.fct){if(s=h.$filter("filter")(a,{isTag:!0}),s.length>0&&(n=s[0]),a.length>0&&n&&(o=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),i=h.tagging.fct(h.search),i.isTag=!0,r.filter(function(e){return angular.equals(e,h.tagging.fct(h.search))}).length>0)return}else{if(s=h.$filter("filter")(a,function(e){return e.match(h.taggingLabel)}),s.length>0&&(n=s[0]),l=a[0],void 0!==l&&a.length>0&&n&&(o=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),i=h.search+" "+h.taggingLabel,u(h.selected,h.search)>-1)return;if(r.filter(function(e){return e.toUpperCase()===h.search.toUpperCase()}).length>0)return o&&(a=r,t.$evalAsync(function(){h.activeIndex=0,h.items=a})),void 0;if(h.selected.filter(function(e){return e.toUpperCase()===h.search.toUpperCase()}).length>0)return o&&(h.items=r.slice(1,r.length)),void 0}o&&(d=u(h.selected,i)),d>-1?a=a.slice(d+1,a.length-1):(a=[],a.push(i),a=a.concat(r)),t.$evalAsync(function(){h.activeIndex=0,h.items=a})}}),v.on("tagged",function(){i(function(){a()})}),v.on("blur",function(){i(function(){h.activeMatchIndex=-1})}),t.$on("$destroy",function(){v.off("keyup keydown tagged blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,i,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||c.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=s(a.onSelect),d.onRemoveCallback=s(a.onRemove),p.$parsers.unshift(function(e){var t,i={};if(d.multiple){for(var l=[],s=d.selected.length-1;s>=0;s--)i={},i[d.parserResult.itemName]=d.selected[s],t=d.parserResult.modelMapper(c,i),l.unshift(t);return l}return i={},i[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,i)}),p.$formatters.unshift(function(e){var t,i=d.parserResult.source(c,{$select:{search:""}}),l={};if(i){if(d.multiple){var s=[],n=function(e,i){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==i)return s.unshift(e[n]),!0;return!1}};if(!e)return s;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(i,e[a]);return s}var r=function(i){return l[d.parserResult.itemName]=i,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=i.length-1;o>=0;o--)if(r(i[o]))return i[o]}return e}),d.ngModel=p;var g=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):g.attr("tabindex",e),n.removeAttr("tabindex")}),l(g)(c),d.focusser=g,d.multiple||(n.append(g),g.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),g.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),g.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),g.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(g.val()),g.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),a.$observe("taggingLabel",function(){void 0!==a.tagging&&void 0!==a.taggingLabel&&(d.taggingLabel="false"===a.taggingLabel?!1:void 0!==a.taggingLabel?a.taggingLabel:"(new)")}),a.$observe("taggingTokens",function(){if(void 0!==a.tagging&&void 0!==a.taggingTokens){var e=void 0!==a.taggingTokens?a.taggingTokens.split("|"):[","];d.taggingTokens={isActivated:!0,tokens:e}}else d.taggingTokens={isActivated:!1,tokens:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),g.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw i("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,s,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),i(s,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,i,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return c+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,i,l){i.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file diff --git a/examples/demo-tagging.html b/examples/demo-tagging.html index 4edd62700..860fc6ea4 100644 --- a/examples/demo-tagging.html +++ b/examples/demo-tagging.html @@ -74,7 +74,8 @@

    Simple String Tags

    Selected: {{multipleDemo.colors}}


    -

    Simple String Tags (No Labels)

    +

    Simple String Tags

    +

    (Predictive Search Model / No Labels)

    {{$item}} diff --git a/src/select.js b/src/select.js index 6c4d4f22c..3f63dc445 100644 --- a/src/select.js +++ b/src/select.js @@ -312,6 +312,9 @@ ctrl.isActive = function(itemScope) { var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + if ( ctrl.taggingLabel === false && ctrl.activeIndex === -1 ) { + return false; + } return ctrl.open && itemIndex === ctrl.activeIndex; }; @@ -593,6 +596,11 @@ }); _searchInput.on('keyup', function(e) { + if ( ! KEY.isVerticalMovement(e.which) ) { + $scope.$evalAsync( function () { + ctrl.activeIndex = ctrl.taggingLabel === false ? -1 : 0; + }); + } // Push a "create new" item into array if there is a search string if ( ctrl.tagging.isActivated && ctrl.search.length > 0 ) { From 9c8d13f844ea46689334b8bf58d550fbcfcc12a1 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Wed, 22 Oct 2014 17:48:48 -0400 Subject: [PATCH 20/32] Clarify some things in the demo --- examples/demo-tagging.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/demo-tagging.html b/examples/demo-tagging.html index 860fc6ea4..aba6f9f92 100644 --- a/examples/demo-tagging.html +++ b/examples/demo-tagging.html @@ -65,6 +65,7 @@

    Tagging Demos

    Simple String Tags

    +

    (With Custom Tag Label)

    {{$item}} @@ -89,7 +90,8 @@

    Object Tags

    {{$item.name}} <{{$item.email}}> -
    +
    +
    email: {{person.email}} age: From 9a1db978a9d07ba8df8aed18e9a9c0072ca52227 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Mon, 27 Oct 2014 08:20:40 -0400 Subject: [PATCH 21/32] Cleanup --- examples/demo-tagging.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/demo-tagging.html b/examples/demo-tagging.html index aba6f9f92..909c05ec6 100644 --- a/examples/demo-tagging.html +++ b/examples/demo-tagging.html @@ -107,7 +107,7 @@

    Object Tags with Tokenization (Space, Forward Slash, Comma)

    {{$item.name}} <{{$item.email}}>
    -
    +
    email: {{person.email}} age: From 1590532e740e25e9fd5b8a567289100dae7ea136 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Mon, 27 Oct 2014 08:21:13 -0400 Subject: [PATCH 22/32] Removing dist files per @dimirc request --- dist/select.css | 167 ------ dist/select.js | 1210 ------------------------------------------- dist/select.min.css | 6 - dist/select.min.js | 7 - 4 files changed, 1390 deletions(-) delete mode 100644 dist/select.css delete mode 100755 dist/select.js delete mode 100644 dist/select.min.css delete mode 100755 dist/select.min.js diff --git a/dist/select.css b/dist/select.css deleted file mode 100644 index bfb63da03..000000000 --- a/dist/select.css +++ /dev/null @@ -1,167 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-21T22:40:46.669Z - * License: MIT - */ - - -/* Style when highlighting a search. */ -.ui-select-highlight { - font-weight: bold; -} - -.ui-select-offscreen { - clip: rect(0 0 0 0) !important; - width: 1px !important; - height: 1px !important; - border: 0 !important; - margin: 0 !important; - padding: 0 !important; - overflow: hidden !important; - position: absolute !important; - outline: 0 !important; - left: 0px !important; - top: 0px !important; -} - -/* Select2 theme */ - -/* Mark invalid Select2 */ -.ng-dirty.ng-invalid > a.select2-choice { - border-color: #D44950; -} - -.select2-result-single { - padding-left: 0; -} - -/* Selectize theme */ - -/* Helper class to show styles when focus */ -.selectize-input.selectize-focus{ - border-color: #007FBB !important; -} - -/* Fix input width for Selectize theme */ -.selectize-control > .selectize-input > input { - width: 100%; -} - -/* Fix dropdown width for Selectize theme */ -.selectize-control > .selectize-dropdown { - width: 100%; -} - -/* Mark invalid Selectize */ -.ng-dirty.ng-invalid > div.selectize-input { - border-color: #D44950; -} - - -/* Bootstrap theme */ - -/* Helper class to show styles when focus */ -.btn-default-focus { - color: #333; - background-color: #EBEBEB; - border-color: #ADADAD; - text-decoration: none; - outline: 5px auto -webkit-focus-ring-color; - outline-offset: -2px; - box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); -} - - -/* Fix Bootstrap dropdown position when inside a input-group */ -.input-group > .ui-select-bootstrap.dropdown { - /* Instead of relative */ - position: static; -} - -.input-group > .ui-select-bootstrap > input.ui-select-search.form-control { - border-radius: 4px; /* FIXME hardcoded value :-/ */ - border-top-right-radius: 0; - border-bottom-right-radius: 0; -} - -.ui-select-bootstrap > .ui-select-match { - /* Instead of center because of .btn */ - text-align: left; -} - -.ui-select-bootstrap > .ui-select-match > .caret { - position: absolute; - top: 45%; - right: 15px; -} - -/* See Scrollable Menu with Bootstrap 3 http://stackoverflow.com/questions/19227496 */ -.ui-select-bootstrap > .ui-select-choices { - width: 100%; - height: auto; - max-height: 200px; - overflow-x: hidden; -} - -.ui-select-multiple.ui-select-bootstrap { - height: auto; - padding: .3em; -} - -.ui-select-multiple.ui-select-bootstrap input.ui-select-search { - background-color: transparent !important; /* To prevent double background when disabled */ - border: none; - outline: none; - height: 1.666666em; -} - -.ui-select-multiple.ui-select-bootstrap .ui-select-match .close { - font-size: 1.6em; - line-height: 0.75; -} - -.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{ - outline: 0; -} - -.ui-select-bootstrap .ui-select-choices-row>a { - display: block; - padding: 3px 20px; - clear: both; - font-weight: 400; - line-height: 1.42857143; - color: #333; - white-space: nowrap; -} - -.ui-select-bootstrap .ui-select-choices-row>a:hover, .ui-select-bootstrap .ui-select-choices-row>a:focus { - text-decoration: none; - color: #262626; - background-color: #f5f5f5; -} - -.ui-select-bootstrap .ui-select-choices-row.active>a { - color: #fff; - text-decoration: none; - outline: 0; - background-color: #428bca; -} - -.ui-select-bootstrap .ui-select-choices-row.disabled>a, -.ui-select-bootstrap .ui-select-choices-row.active.disabled>a { - color: #777; - cursor: not-allowed; - background-color: #fff; -} - -/* fix hide/show angular animation */ -.ui-select-match.ng-hide-add, -.ui-select-search.ng-hide-add { - display: none !important; -} - -/* Mark invalid Bootstrap */ -.ui-select-bootstrap.ng-dirty.ng-invalid > button.btn.ui-select-match { - border-color: #D44950; -} diff --git a/dist/select.js b/dist/select.js deleted file mode 100755 index 0a5b2a3f6..000000000 --- a/dist/select.js +++ /dev/null @@ -1,1210 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-21T22:40:46.668Z - * License: MIT - */ - - -(function () { - "use strict"; - - var KEY = { - TAB: 9, - ENTER: 13, - ESC: 27, - SPACE: 32, - LEFT: 37, - UP: 38, - RIGHT: 39, - DOWN: 40, - SHIFT: 16, - CTRL: 17, - ALT: 18, - PAGE_UP: 33, - PAGE_DOWN: 34, - HOME: 36, - END: 35, - BACKSPACE: 8, - DELETE: 46, - COMMAND: 91, - - MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "SPACE" , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" - }, - - isControl: function (e) { - var k = e.which; - switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; - } - - if (e.metaKey) return true; - - return false; - }, - isFunctionKey: function (k) { - k = k.which ? k.which : k; - return k >= 112 && k <= 123; - }, - isVerticalMovement: function (k){ - return ~[KEY.UP, KEY.DOWN].indexOf(k); - }, - isHorizontalMovement: function (k){ - return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); - } - }; - - /** - * Add querySelectorAll() to jqLite. - * - * jqLite find() is limited to lookups by tag name. - * TODO This will change with future versions of AngularJS, to be removed when this happens -5 * - * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 - * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 - */ - if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function(selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; - } - - angular.module('ui.select', []) - - .constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - placeholder: '', // Empty by default, like HTML tag "); - - if(attrs.tabindex){ - //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex - attrs.$observe('tabindex', function(value) { - //If we are using multiple, add tabindex to the search input - if($select.multiple){ - searchInput.attr("tabindex", value); - } else { - focusser.attr("tabindex", value); - } - //Remove the tabindex on the parent so that it is not focusable - element.removeAttr("tabindex"); - }); - } - - $compile(focusser)(scope); - $select.focusser = focusser; - - if (!$select.multiple){ - - element.append(focusser); - focusser.bind("focus", function(){ - scope.$evalAsync(function(){ - $select.focus = true; - }); - }); - focusser.bind("blur", function(){ - scope.$evalAsync(function(){ - $select.focus = false; - }); - }); - focusser.bind("keydown", function(e){ - - if (e.which === KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } - - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { - return; - } - - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } - - scope.$digest(); - }); - - focusser.bind("keyup input", function(e){ - - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { - return; - } - - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input - focusser.val(''); - scope.$digest(); - - }); - - } - - - scope.$watch('searchEnabled', function() { - var searchEnabled = scope.$eval(attrs.searchEnabled); - $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : true; - }); - - attrs.$observe('disabled', function() { - // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string - $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; - }); - - attrs.$observe('resetSearchInput', function() { - // $eval() is needed otherwise we get a string instead of a boolean - var resetSearchInput = scope.$eval(attrs.resetSearchInput); - $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; - }); - - attrs.$observe('tagging', function() { - if(attrs.tagging !== undefined) - { - // $eval() is needed otherwise we get a string instead of a function or a boolean - var taggingEval = scope.$eval(attrs.tagging); - $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined}; - } - else - { - $select.tagging = {isActivated: false, fct: undefined}; - } - }); - - attrs.$observe('taggingLabel', function() { - if(attrs.tagging !== undefined && attrs.taggingLabel !== undefined) - { - // check eval for FALSE, in this case, we disable the labels - // associated with tagging - if ( attrs.taggingLabel === 'false' ) { - $select.taggingLabel = false; - } else { - $select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)'; - } - } - }); - - attrs.$observe('taggingTokens', function() { - if(attrs.tagging !== undefined && attrs.taggingTokens !== undefined) - { - var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',']; - $select.taggingTokens = {isActivated: true, tokens: tokens }; - } - else - { - $select.taggingTokens = {isActivated: false, tokens: undefined}; - } - }); - - if ($select.multiple){ - scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { - if (oldValue != newValue) - ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters - }); - scope.$watchCollection('$select.selected', function() { - ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes - }); - focusser.prop('disabled', true); //Focusser isn't needed if multiple - }else{ - scope.$watch('$select.selected', function(newValue) { - if (ngModel.$viewValue !== newValue) { - ngModel.$setViewValue(newValue); - } - }); - } - - ngModel.$render = function() { - if($select.multiple){ - // Make sure that model value is array - if(!angular.isArray(ngModel.$viewValue)){ - // Have tolerance for null or undefined values - if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ - $select.selected = []; - } else { - throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); - } - } - } - $select.selected = ngModel.$viewValue; - }; - - function onDocumentClick(e) { - var contains = false; - - if (window.jQuery) { - // Firefox 3.6 does not support element.contains() - // See Node.contains https://developer.mozilla.org/en-US/docs/Web/API/Node.contains - contains = window.jQuery.contains(element[0], e.target); - } else { - contains = element[0].contains(e.target); - } - - if (!contains) { - $select.close(); - scope.$digest(); - } - } - - // See Click everywhere but here event http://stackoverflow.com/questions/12931369 - $document.on('click', onDocumentClick); - - scope.$on('$destroy', function() { - $document.off('click', onDocumentClick); - }); - - // Move transcluded elements to their correct position in main template - transcludeFn(scope, function(clone) { - // See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html - - // One day jqLite will be replaced by jQuery and we will be able to write: - // var transcludedElement = clone.filter('.my-class') - // instead of creating a hackish DOM element: - var transcluded = angular.element('
    ').append(clone); - - var transcludedMatch = transcluded.querySelectorAll('.ui-select-match'); - transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr - if (transcludedMatch.length !== 1) { - throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", transcludedMatch.length); - } - element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch); - - var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices'); - transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr - if (transcludedChoices.length !== 1) { - throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length); - } - element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices); - }); - } - }; - }]) - - .directive('uiSelectChoices', - ['uiSelectConfig', 'RepeatParser', 'uiSelectMinErr', '$compile', - function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - return theme + '/choices.tpl.html'; - }, - - compile: function(tElement, tAttrs) { - - if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); - - return function link(scope, element, attrs, $select, transcludeFn) { - - // var repeat = RepeatParser.parse(attrs.repeat); - var groupByExp = attrs.groupBy; - - $select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult - - $select.disableChoiceExpression = attrs.uiDisableChoice; - - if(groupByExp) { - var groups = element.querySelectorAll('.ui-select-choices-group'); - if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); - groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); - } - - var choices = element.querySelectorAll('.ui-select-choices-row'); - if (choices.length !== 1) { - throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length); - } - - choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') - .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ')'); - - var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); - if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); - rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat - - $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend - - scope.$watch('$select.search', function(newValue) { - if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = $select.tagging.isActivated ? -1 : 0; - $select.refresh(attrs.refresh); - }); - - attrs.$observe('refreshDelay', function() { - // $eval() is needed otherwise we get a string instead of a number - var refreshDelay = scope.$eval(attrs.refreshDelay); - $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; - }); - }; - } - }; - }]) - // Recreates old behavior of ng-transclude. Used internally. - .directive('uisTranscludeAppend', function () { - return { - link: function (scope, element, attrs, ctrl, transclude) { - transclude(scope, function (clone) { - element.append(clone); - }); - } - }; - }) - .directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) { - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - var multi = tElement.parent().attr('multiple'); - return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); - }, - link: function(scope, element, attrs, $select) { - attrs.$observe('placeholder', function(placeholder) { - $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; - }); - - if($select.multiple){ - $select.sizeSearchInput(); - } - - } - }; - }]) - - /** - * Highlights text that matches $select.search. - * - * Taken from AngularUI Bootstrap Typeahead - * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 - */ - .filter('highlight', function() { - function escapeRegexp(queryToEscape) { - return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); - } - - return function(matchItem, query) { - return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; - }; - }); -}()); - -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
      0\">
    • 0\">
      {{$group.name}}
    "); -$templateCache.put("bootstrap/match-multiple.tpl.html"," × "); -$templateCache.put("bootstrap/match.tpl.html",""); -$templateCache.put("bootstrap/select-multiple.tpl.html","
    "); -$templateCache.put("bootstrap/select.tpl.html","
    "); -$templateCache.put("select2/choices.tpl.html","
    • {{$group.name}}
    "); -$templateCache.put("select2/match-multiple.tpl.html","
  • "); -$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); -$templateCache.put("select2/select-multiple.tpl.html","
    "); -$templateCache.put("select2/select.tpl.html","
    "); -$templateCache.put("selectize/choices.tpl.html","
    {{$group.name}}
    "); -$templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.min.css b/dist/select.min.css deleted file mode 100644 index 07b81abc6..000000000 --- a/dist/select.min.css +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-21T22:40:46.669Z - * License: MIT - */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js deleted file mode 100755 index b334ffd50..000000000 --- a/dist/select.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-10-21T22:40:46.668Z - * License: MIT - */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:"SPACE",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var i=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,i){var l=e+" in "+(i?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","RepeatParser","uiSelectMinErr",function(t,c,i,l,s,n){function a(){h.resetSearchInput&&(h.search=g,h.selected&&h.items.length&&!h.multiple&&(h.activeIndex=h.items.indexOf(h.selected)))}function r(t){var c=!0;switch(t){case e.DOWN:!h.open&&h.multiple?h.activate(!1,!0):h.activeIndex0||0===h.search.length&&h.tagging.isActivated)&&h.activeIndex--;break;case e.TAB:(!h.multiple||h.open)&&h.select(h.items[h.activeIndex],!0);break;case e.ENTER:h.open?h.select(h.items[h.activeIndex]):h.activate(!1,!0);break;case e.ESC:h.close();break;default:c=!1}return c}function o(t){function c(){switch(t){case e.LEFT:return~h.activeMatchIndex?o:n;case e.RIGHT:return~h.activeMatchIndex&&a!==n?r:(h.activate(),!1);case e.BACKSPACE:return~h.activeMatchIndex?(h.removeChoice(a),o):n;case e.DELETE:return~h.activeMatchIndex?(h.removeChoice(h.activeMatchIndex),a):!1}}var i=d(v[0]),l=h.selected.length,s=0,n=l-1,a=h.activeMatchIndex,r=h.activeMatchIndex+1,o=h.activeMatchIndex-1,u=a;return i>0||h.search.length&&t==e.RIGHT?!1:(h.close(),u=c(),h.activeMatchIndex=h.selected.length&&u!==!1?Math.min(n,Math.max(s,u)):-1,!0)}function u(e,t){for(var c=angular.copy(e),i=-1,l=0;ls?e[0].scrollTop+=l-s:l=h.items.length?0:h.activeIndex,i(function(){h.search=e||h.search,v[0].focus()}))},h.findGroupByName=function(e){return h.groups&&h.groups.filter(function(t){return t.name===e})[0]},h.parseRepeatAttr=function(e,c){function i(e){h.groups=[],angular.forEach(e,function(e){var i=t.$eval(c),l=angular.isFunction(i)?i(e):e[i],s=h.findGroupByName(l);s?s.items.push(e):h.groups.push({name:l,items:[e]})}),h.items=[],h.groups.forEach(function(e){h.items=h.items.concat(e.items)})}function l(e){h.items=e}var a=c?i:l;h.parserResult=s.parse(e),h.isGrouped=!!c,h.itemProperty=h.parserResult.itemName,t.$watchCollection(h.parserResult.source,function(e){if(void 0===e||null===e)h.items=[];else{if(!angular.isArray(e))throw n("items","Expected an array but got '{0}'.",e);if(h.multiple){var t=e.filter(function(e){return h.selected.indexOf(e)<0});a(t)}else a(e);h.ngModel.$modelValue=null}}),h.multiple&&t.$watchCollection("$select.selected",function(e){var c=h.parserResult.source(t);if(e.length){if(void 0!==c){var i=c.filter(function(t){return e.indexOf(t)<0});a(i)}}else a(c);h.sizeSearchInput()})};var f;h.refresh=function(e){void 0!==e&&(f&&i.cancel(f),f=i(function(){t.$eval(e)},h.refreshDelay))},h.setActiveItem=function(e){h.activeIndex=h.items.indexOf(e)},h.isActive=function(e){var t=h.items.indexOf(e[h.itemProperty]);return h.taggingLabel===!1&&-1===h.activeIndex?!1:h.open&&t===h.activeIndex},h.isDisabled=function(e){if(h.open){var t,c=h.items.indexOf(e[h.itemProperty]),i=!1;return c>=0&&!angular.isUndefined(h.disableChoiceExpression)&&(t=h.items[c],i=!!e.$eval(h.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i}},h.select=function(e,c){if(!(!h.items&&!h.search||e&&e._uiSelectChoiceDisabled)){if(h.tagging.isActivated){if(h.taggingLabel===!1)if(h.activeIndex<0){if(e=void 0!==h.tagging.fct?h.tagging.fct(h.search):h.search,angular.equals(h.items[0],e))return;e=e}else e=h.items[h.activeIndex];else if(0===h.activeIndex){if(void 0===e)return;h.taggingLabel&&h.taggingLabel.length>0,e=void 0!==h.tagging.fct?h.tagging.fct(h.search):e.replace(h.taggingLabel,"")}if(h.selected&&h.selected.filter(function(t){return angular.equals(t,e)}).length>0)return h.close(c),void 0}var i={};i[h.parserResult.itemName]=e,h.onSelectCallback(t,{$item:e,$model:h.parserResult.modelMapper(t,i)}),h.multiple?(h.selected.push(e),h.sizeSearchInput()):h.selected=e,h.close(c)}},h.close=function(e){h.open&&(a(),h.open=!1,h.multiple||i(function(){h.focusser.prop("disabled",!1),e||h.focusser[0].focus()},0,!1))},h.toggle=function(e){h.open?h.close():h.activate(),e.preventDefault(),e.stopPropagation()},h.removeChoice=function(e){var c=h.selected[e],i={};i[h.parserResult.itemName]=c,h.selected.splice(e,1),h.activeMatchIndex=-1,h.sizeSearchInput(),h.onRemoveCallback(t,{$item:c,$model:h.parserResult.modelMapper(t,i)})},h.getPlaceholder=function(){return h.multiple&&h.selected.length?void 0:h.placeholder};var m;h.sizeSearchInput=function(){var e=v[0],c=v.parent().parent()[0];v.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),v.css("width",t+"px")};i(function(){0!==c.clientWidth||m?m||l():m=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),m(),m=null)})},0,!1)},v.on("keydown",function(c){var i=c.which;t.$apply(function(){var t=!1;if(h.multiple&&e.isHorizontalMovement(i)&&(t=o(i)),!t&&(h.items.length>0||h.tagging.isActivated)&&(t=r(i),h.taggingTokens.isActivated))for(var l=0;l0&&(h.select(null,!0),v.triggerHandler("tagged"));t&&i!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(i)&&h.items.length>0&&p()}),v.on("keyup",function(c){if(e.isVerticalMovement(c.which)||t.$evalAsync(function(){h.activeIndex=h.taggingLabel===!1?-1:0}),h.tagging.isActivated&&h.search.length>0){if(c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which))return;if(h.activeIndex=h.taggingLabel===!1?-1:0,h.taggingLabel===!1)return;var i,l,s,n,a=angular.copy(h.items),r=angular.copy(h.items),o=!1,d=-1;if(void 0!==h.tagging.fct){if(s=h.$filter("filter")(a,{isTag:!0}),s.length>0&&(n=s[0]),a.length>0&&n&&(o=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),i=h.tagging.fct(h.search),i.isTag=!0,r.filter(function(e){return angular.equals(e,h.tagging.fct(h.search))}).length>0)return}else{if(s=h.$filter("filter")(a,function(e){return e.match(h.taggingLabel)}),s.length>0&&(n=s[0]),l=a[0],void 0!==l&&a.length>0&&n&&(o=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),i=h.search+" "+h.taggingLabel,u(h.selected,h.search)>-1)return;if(r.filter(function(e){return e.toUpperCase()===h.search.toUpperCase()}).length>0)return o&&(a=r,t.$evalAsync(function(){h.activeIndex=0,h.items=a})),void 0;if(h.selected.filter(function(e){return e.toUpperCase()===h.search.toUpperCase()}).length>0)return o&&(h.items=r.slice(1,r.length)),void 0}o&&(d=u(h.selected,i)),d>-1?a=a.slice(d+1,a.length-1):(a=[],a.push(i),a=a.concat(r)),t.$evalAsync(function(){h.activeIndex=0,h.items=a})}}),v.on("tagged",function(){i(function(){a()})}),v.on("blur",function(){i(function(){h.activeMatchIndex=-1})}),t.$on("$destroy",function(){v.off("keyup keydown tagged blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,i,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||c.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(c,n,a,r,o){function u(e){var t=!1;t=window.jQuery?window.jQuery.contains(n[0],e.target):n[0].contains(e.target),t||(d.close(),c.$digest())}var d=r[0],p=r[1],h=n.querySelectorAll("input.ui-select-search");d.multiple=angular.isDefined(a.multiple)?""===a.multiple?!0:"true"===a.multiple.toLowerCase():!1,d.onSelectCallback=s(a.onSelect),d.onRemoveCallback=s(a.onRemove),p.$parsers.unshift(function(e){var t,i={};if(d.multiple){for(var l=[],s=d.selected.length-1;s>=0;s--)i={},i[d.parserResult.itemName]=d.selected[s],t=d.parserResult.modelMapper(c,i),l.unshift(t);return l}return i={},i[d.parserResult.itemName]=e,t=d.parserResult.modelMapper(c,i)}),p.$formatters.unshift(function(e){var t,i=d.parserResult.source(c,{$select:{search:""}}),l={};if(i){if(d.multiple){var s=[],n=function(e,i){if(e&&e.length){for(var n=e.length-1;n>=0;n--)if(l[d.parserResult.itemName]=e[n],t=d.parserResult.modelMapper(c,l),t==i)return s.unshift(e[n]),!0;return!1}};if(!e)return s;for(var a=e.length-1;a>=0;a--)n(d.selected,e[a])||n(i,e[a]);return s}var r=function(i){return l[d.parserResult.itemName]=i,t=d.parserResult.modelMapper(c,l),t==e};if(d.selected&&r(d.selected))return d.selected;for(var o=i.length-1;o>=0;o--)if(r(i[o]))return i[o]}return e}),d.ngModel=p;var g=angular.element("");a.tabindex&&a.$observe("tabindex",function(e){d.multiple?h.attr("tabindex",e):g.attr("tabindex",e),n.removeAttr("tabindex")}),l(g)(c),d.focusser=g,d.multiple||(n.append(g),g.bind("focus",function(){c.$evalAsync(function(){d.focus=!0})}),g.bind("blur",function(){c.$evalAsync(function(){d.focus=!1})}),g.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),d.select(void 0),c.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),d.activate()),c.$digest()),void 0)}),g.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(d.activate(g.val()),g.val(""),c.$digest())})),c.$watch("searchEnabled",function(){var e=c.$eval(a.searchEnabled);d.searchEnabled=void 0!==e?e:!0}),a.$observe("disabled",function(){d.disabled=void 0!==a.disabled?a.disabled:!1}),a.$observe("resetSearchInput",function(){var e=c.$eval(a.resetSearchInput);d.resetSearchInput=void 0!==e?e:!0}),a.$observe("tagging",function(){if(void 0!==a.tagging){var e=c.$eval(a.tagging);d.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else d.tagging={isActivated:!1,fct:void 0}}),a.$observe("taggingLabel",function(){void 0!==a.tagging&&void 0!==a.taggingLabel&&(d.taggingLabel="false"===a.taggingLabel?!1:void 0!==a.taggingLabel?a.taggingLabel:"(new)")}),a.$observe("taggingTokens",function(){if(void 0!==a.tagging&&void 0!==a.taggingTokens){var e=void 0!==a.taggingTokens?a.taggingTokens.split("|"):[","];d.taggingTokens={isActivated:!0,tokens:e}}else d.taggingTokens={isActivated:!1,tokens:void 0}}),d.multiple?(c.$watchCollection(function(){return p.$modelValue},function(e,t){t!=e&&(p.$modelValue=null)}),c.$watchCollection("$select.selected",function(){p.$setViewValue(Date.now())}),g.prop("disabled",!0)):c.$watch("$select.selected",function(e){p.$viewValue!==e&&p.$setViewValue(e)}),p.$render=function(){if(d.multiple&&!angular.isArray(p.$viewValue)){if(!angular.isUndefined(p.$viewValue)&&null!==p.$viewValue)throw i("multiarr","Expected model value to be array but got '{0}'",p.$viewValue);d.selected=[]}d.selected=p.$viewValue},t.on("click",u),c.$on("$destroy",function(){t.off("click",u)}),o(c,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);n.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);n.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,s,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,o){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),i(s,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,i,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return c+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,i,l){i.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    • {{$group.name}}
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    {{$group.name}}
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file From ed88969f373f2fac0148213e050420800831ede4 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Mon, 27 Oct 2014 11:04:16 -0400 Subject: [PATCH 23/32] Move ctrl.open check to top --- src/select.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/select.js b/src/select.js index 3f63dc445..64d347e99 100644 --- a/src/select.js +++ b/src/select.js @@ -311,11 +311,14 @@ }; ctrl.isActive = function(itemScope) { + if ( !ctrl.open ) { + return false; + } var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); if ( ctrl.taggingLabel === false && ctrl.activeIndex === -1 ) { return false; } - return ctrl.open && itemIndex === ctrl.activeIndex; + return itemIndex === ctrl.activeIndex; }; ctrl.isDisabled = function(itemScope) { From c6dcd05dfbe6a9711d84800d6746f9122c18e03f Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Mon, 3 Nov 2014 12:29:21 -0500 Subject: [PATCH 24/32] General cleanup, including some bad logic --- src/select.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/select.js b/src/select.js index 64d347e99..d7cf30a07 100644 --- a/src/select.js +++ b/src/select.js @@ -55,7 +55,7 @@ * * jqLite find() is limited to lookups by tag name. * TODO This will change with future versions of AngularJS, to be removed when this happens -5 * + * * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 */ @@ -349,9 +349,7 @@ if ( ctrl.taggingLabel === false ) { if ( ctrl.activeIndex < 0 ) { item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; - if ( ! angular.equals( ctrl.items[0], item ) ) { - item = item; - } else { + if ( angular.equals( ctrl.items[0], item ) ) { return; } } else { @@ -366,7 +364,6 @@ // for `item` if it is a detected duplicate if ( item === undefined ) return; // create new item on the fly - if ( ctrl.taggingLabel && ctrl.taggingLabel.length > 0 ) {} item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : item.replace(ctrl.taggingLabel,''); } } From c3062759a649fb9e35ce8e0361ace8c939865e6b Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Fri, 7 Nov 2014 15:26:00 -0500 Subject: [PATCH 25/32] Ensure a default setting for taggingTokens.isActivated is explicitly disabled, and allow _resetSearchInput to execute any time tagging is enabled --- src/select.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/select.js b/src/select.js index d7cf30a07..85ee67472 100644 --- a/src/select.js +++ b/src/select.js @@ -164,6 +164,7 @@ ctrl.multiple = false; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelect directive link function ctrl.$filter = $filter; + ctrl.taggingTokens = {isActivated: false, tokens: undefined}; ctrl.isEmpty = function() { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; @@ -176,7 +177,7 @@ // Most of the time the user does not want to empty the search input when in typeahead mode function _resetSearchInput() { - if (ctrl.resetSearchInput) { + if (ctrl.resetSearchInput || ctrl.tagging.isActivated ) { ctrl.search = EMPTY_SEARCH; //reset activeIndex if (ctrl.selected && ctrl.items.length && !ctrl.multiple) { @@ -970,21 +971,18 @@ // associated with tagging if ( attrs.taggingLabel === 'false' ) { $select.taggingLabel = false; - } else { + } + else + { $select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)'; } } }); attrs.$observe('taggingTokens', function() { - if(attrs.tagging !== undefined && attrs.taggingTokens !== undefined) - { - var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',']; - $select.taggingTokens = {isActivated: true, tokens: tokens }; - } - else - { - $select.taggingTokens = {isActivated: false, tokens: undefined}; + if (attrs.tagging !== undefined) { + var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',','ENTER']; + $select.taggingTokens = {isActivated: true, tokens: tokens }; } }); From 46b40d9604228fe1d909ffdd278dd7eedbd0e263 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Fri, 14 Nov 2014 10:08:24 -0500 Subject: [PATCH 26/32] Fix wrong test spec assertion and missing $filter injectable --- src/select.js | 12 +++++++++--- test/select.spec.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/select.js b/src/select.js index 538da8239..1c6657146 100644 --- a/src/select.js +++ b/src/select.js @@ -141,8 +141,8 @@ * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested. */ .controller('uiSelectCtrl', - ['$scope', '$element', '$timeout', 'RepeatParser', 'uiSelectMinErr', 'uiSelectConfig', - function($scope, $element, $timeout, RepeatParser, uiSelectMinErr, uiSelectConfig) { + ['$scope', '$element', '$timeout', '$filter', 'RepeatParser', 'uiSelectMinErr', 'uiSelectConfig', + function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr, uiSelectConfig) { var ctrl = this; @@ -313,9 +313,15 @@ }; ctrl.isActive = function(itemScope) { - if ( !ctrl.open ) { + var isActive = ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; + + if ( !isActive ) { return false; } + if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { + itemScope.$eval(ctrl.onHighlightCallback); + } + var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); if ( ctrl.taggingLabel === false && ctrl.activeIndex === -1 ) { return false; diff --git a/test/select.spec.js b/test/select.spec.js index 55eebe82c..21f8cbecc 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -256,7 +256,7 @@ describe('ui-select tests', function() { expect(isDropdownOpened(el2)).toEqual(true); var el3 = createUiSelect(); - expect(el3.scope().$select.disabled).toEqual(false || undefined); + expect(el3.scope().$select.disabled).toBeFalsy(); clickMatch(el3); expect(isDropdownOpened(el3)).toEqual(true); }); From 3321c504b491ab1d80586618e856fedf7bb69373 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Fri, 14 Nov 2014 10:13:39 -0500 Subject: [PATCH 27/32] Add missing `dist` files to ensure tests pass --- dist/select.css | 171 ++++++ dist/select.js | 1233 +++++++++++++++++++++++++++++++++++++++++++ dist/select.min.css | 6 + dist/select.min.js | 7 + 4 files changed, 1417 insertions(+) create mode 100644 dist/select.css create mode 100755 dist/select.js create mode 100644 dist/select.min.css create mode 100755 dist/select.min.js diff --git a/dist/select.css b/dist/select.css new file mode 100644 index 000000000..f8f44c836 --- /dev/null +++ b/dist/select.css @@ -0,0 +1,171 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.8.3 - 2014-11-14T15:12:53.109Z + * License: MIT + */ + + +/* Style when highlighting a search. */ +.ui-select-highlight { + font-weight: bold; +} + +.ui-select-offscreen { + clip: rect(0 0 0 0) !important; + width: 1px !important; + height: 1px !important; + border: 0 !important; + margin: 0 !important; + padding: 0 !important; + overflow: hidden !important; + position: absolute !important; + outline: 0 !important; + left: 0px !important; + top: 0px !important; +} + +/* Select2 theme */ + +/* Mark invalid Select2 */ +.ng-dirty.ng-invalid > a.select2-choice { + border-color: #D44950; +} + +.select2-result-single { + padding-left: 0; +} + +.select2-locked > .select2-search-choice-close{ + display:none; +} + +/* Selectize theme */ + +/* Helper class to show styles when focus */ +.selectize-input.selectize-focus{ + border-color: #007FBB !important; +} + +/* Fix input width for Selectize theme */ +.selectize-control > .selectize-input > input { + width: 100%; +} + +/* Fix dropdown width for Selectize theme */ +.selectize-control > .selectize-dropdown { + width: 100%; +} + +/* Mark invalid Selectize */ +.ng-dirty.ng-invalid > div.selectize-input { + border-color: #D44950; +} + + +/* Bootstrap theme */ + +/* Helper class to show styles when focus */ +.btn-default-focus { + color: #333; + background-color: #EBEBEB; + border-color: #ADADAD; + text-decoration: none; + outline: 5px auto -webkit-focus-ring-color; + outline-offset: -2px; + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); +} + + +/* Fix Bootstrap dropdown position when inside a input-group */ +.input-group > .ui-select-bootstrap.dropdown { + /* Instead of relative */ + position: static; +} + +.input-group > .ui-select-bootstrap > input.ui-select-search.form-control { + border-radius: 4px; /* FIXME hardcoded value :-/ */ + border-top-right-radius: 0; + border-bottom-right-radius: 0; +} + +.ui-select-bootstrap > .ui-select-match { + /* Instead of center because of .btn */ + text-align: left; +} + +.ui-select-bootstrap > .ui-select-match > .caret { + position: absolute; + top: 45%; + right: 15px; +} + +/* See Scrollable Menu with Bootstrap 3 http://stackoverflow.com/questions/19227496 */ +.ui-select-bootstrap > .ui-select-choices { + width: 100%; + height: auto; + max-height: 200px; + overflow-x: hidden; +} + +.ui-select-multiple.ui-select-bootstrap { + height: auto; + padding: .3em; +} + +.ui-select-multiple.ui-select-bootstrap input.ui-select-search { + background-color: transparent !important; /* To prevent double background when disabled */ + border: none; + outline: none; + height: 1.666666em; +} + +.ui-select-multiple.ui-select-bootstrap .ui-select-match .close { + font-size: 1.6em; + line-height: 0.75; +} + +.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{ + outline: 0; +} + +.ui-select-bootstrap .ui-select-choices-row>a { + display: block; + padding: 3px 20px; + clear: both; + font-weight: 400; + line-height: 1.42857143; + color: #333; + white-space: nowrap; +} + +.ui-select-bootstrap .ui-select-choices-row>a:hover, .ui-select-bootstrap .ui-select-choices-row>a:focus { + text-decoration: none; + color: #262626; + background-color: #f5f5f5; +} + +.ui-select-bootstrap .ui-select-choices-row.active>a { + color: #fff; + text-decoration: none; + outline: 0; + background-color: #428bca; +} + +.ui-select-bootstrap .ui-select-choices-row.disabled>a, +.ui-select-bootstrap .ui-select-choices-row.active.disabled>a { + color: #777; + cursor: not-allowed; + background-color: #fff; +} + +/* fix hide/show angular animation */ +.ui-select-match.ng-hide-add, +.ui-select-search.ng-hide-add { + display: none !important; +} + +/* Mark invalid Bootstrap */ +.ui-select-bootstrap.ng-dirty.ng-invalid > button.btn.ui-select-match { + border-color: #D44950; +} diff --git a/dist/select.js b/dist/select.js new file mode 100755 index 000000000..1eebf84e1 --- /dev/null +++ b/dist/select.js @@ -0,0 +1,1233 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.8.3 - 2014-11-14T15:12:53.105Z + * License: MIT + */ + + +(function () { + "use strict"; + + var KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + + MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "SPACE" , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; + } + + if (e.metaKey) return true; + + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k){ + return ~[KEY.UP, KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k){ + return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + } + }; + + /** + * Add querySelectorAll() to jqLite. + * + * jqLite find() is limited to lookups by tag name. + * TODO This will change with future versions of AngularJS, to be removed when this happens + * + * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 + * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 + */ + if (angular.element.prototype.querySelectorAll === undefined) { + angular.element.prototype.querySelectorAll = function(selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; + } + + angular.module('ui.select', []) + + .constant('uiSelectConfig', { + theme: 'bootstrap', + searchEnabled: true, + placeholder: '', // Empty by default, like HTML tag "); + + if(attrs.tabindex){ + //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex + attrs.$observe('tabindex', function(value) { + //If we are using multiple, add tabindex to the search input + if($select.multiple){ + searchInput.attr("tabindex", value); + } else { + focusser.attr("tabindex", value); + } + //Remove the tabindex on the parent so that it is not focusable + element.removeAttr("tabindex"); + }); + } + + $compile(focusser)(scope); + $select.focusser = focusser; + + if (!$select.multiple){ + + element.append(focusser); + focusser.bind("focus", function(){ + scope.$evalAsync(function(){ + $select.focus = true; + }); + }); + focusser.bind("blur", function(){ + scope.$evalAsync(function(){ + $select.focus = false; + }); + }); + focusser.bind("keydown", function(e){ + + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } + + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } + + scope.$digest(); + }); + + focusser.bind("keyup input", function(e){ + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + + }); + + } + + + scope.$watch('searchEnabled', function() { + var searchEnabled = scope.$eval(attrs.searchEnabled); + $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; + }); + + attrs.$observe('disabled', function() { + // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string + $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; + }); + + attrs.$observe('resetSearchInput', function() { + // $eval() is needed otherwise we get a string instead of a boolean + var resetSearchInput = scope.$eval(attrs.resetSearchInput); + $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; + }); + + attrs.$observe('tagging', function() { + if(attrs.tagging !== undefined) + { + // $eval() is needed otherwise we get a string instead of a function or a boolean + var taggingEval = scope.$eval(attrs.tagging); + $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined}; + } + else + { + $select.tagging = {isActivated: false, fct: undefined}; + } + }); + + attrs.$observe('taggingLabel', function() { + if(attrs.tagging !== undefined && attrs.taggingLabel !== undefined) + { + // check eval for FALSE, in this case, we disable the labels + // associated with tagging + if ( attrs.taggingLabel === 'false' ) { + $select.taggingLabel = false; + } + else + { + $select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)'; + } + } + }); + + attrs.$observe('taggingTokens', function() { + if (attrs.tagging !== undefined) { + var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',','ENTER']; + $select.taggingTokens = {isActivated: true, tokens: tokens }; + } + }); + + if ($select.multiple){ + scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { + if (oldValue != newValue) + ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters + }); + scope.$watchCollection('$select.selected', function() { + ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes + }); + focusser.prop('disabled', true); //Focusser isn't needed if multiple + }else{ + scope.$watch('$select.selected', function(newValue) { + if (ngModel.$viewValue !== newValue) { + ngModel.$setViewValue(newValue); + } + }); + } + + ngModel.$render = function() { + if($select.multiple){ + // Make sure that model value is array + if(!angular.isArray(ngModel.$viewValue)){ + // Have tolerance for null or undefined values + if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ + $select.selected = []; + } else { + throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); + } + } + } + $select.selected = ngModel.$viewValue; + }; + + function onDocumentClick(e) { + var contains = false; + + if (window.jQuery) { + // Firefox 3.6 does not support element.contains() + // See Node.contains https://developer.mozilla.org/en-US/docs/Web/API/Node.contains + contains = window.jQuery.contains(element[0], e.target); + } else { + contains = element[0].contains(e.target); + } + + if (!contains) { + $select.close(); + scope.$digest(); + } + } + + // See Click everywhere but here event http://stackoverflow.com/questions/12931369 + $document.on('click', onDocumentClick); + + scope.$on('$destroy', function() { + $document.off('click', onDocumentClick); + }); + + // Move transcluded elements to their correct position in main template + transcludeFn(scope, function(clone) { + // See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html + + // One day jqLite will be replaced by jQuery and we will be able to write: + // var transcludedElement = clone.filter('.my-class') + // instead of creating a hackish DOM element: + var transcluded = angular.element('
    ').append(clone); + + var transcludedMatch = transcluded.querySelectorAll('.ui-select-match'); + transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr + if (transcludedMatch.length !== 1) { + throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", transcludedMatch.length); + } + element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch); + + var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices'); + transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr + if (transcludedChoices.length !== 1) { + throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length); + } + element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices); + }); + } + }; + }]) + + .directive('uiSelectChoices', + ['uiSelectConfig', 'RepeatParser', 'uiSelectMinErr', '$compile', + function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { + + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function(tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + return theme + '/choices.tpl.html'; + }, + + compile: function(tElement, tAttrs) { + + if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); + + return function link(scope, element, attrs, $select, transcludeFn) { + + // var repeat = RepeatParser.parse(attrs.repeat); + var groupByExp = attrs.groupBy; + + $select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult + + $select.disableChoiceExpression = attrs.uiDisableChoice; + $select.onHighlightCallback = attrs.onHighlight; + + if(groupByExp) { + var groups = element.querySelectorAll('.ui-select-choices-group'); + if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); + groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); + } + + var choices = element.querySelectorAll('.ui-select-choices-row'); + if (choices.length !== 1) { + throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length); + } + + choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) + .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed + .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') + .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ')'); + + var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); + if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); + rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat + + $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend + + scope.$watch('$select.search', function(newValue) { + if(newValue && !$select.open && $select.multiple) $select.activate(false, true); + $select.activeIndex = $select.tagging.isActivated ? -1 : 0; + $select.refresh(attrs.refresh); + }); + + attrs.$observe('refreshDelay', function() { + // $eval() is needed otherwise we get a string instead of a number + var refreshDelay = scope.$eval(attrs.refreshDelay); + $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; + }); + }; + } + }; + }]) + // Recreates old behavior of ng-transclude. Used internally. + .directive('uisTranscludeAppend', function () { + return { + link: function (scope, element, attrs, ctrl, transclude) { + transclude(scope, function (clone) { + element.append(clone); + }); + } + }; + }) + .directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) { + return { + restrict: 'EA', + require: '^uiSelect', + replace: true, + transclude: true, + templateUrl: function(tElement) { + // Gets theme attribute from parent (ui-select) + var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; + var multi = tElement.parent().attr('multiple'); + return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); + }, + link: function(scope, element, attrs, $select) { + $select.lockChoiceExpression = attrs.uiLockChoice; + attrs.$observe('placeholder', function(placeholder) { + $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; + }); + + if($select.multiple){ + $select.sizeSearchInput(); + } + + } + }; + }]) + + /** + * Highlights text that matches $select.search. + * + * Taken from AngularUI Bootstrap Typeahead + * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 + */ + .filter('highlight', function() { + function escapeRegexp(queryToEscape) { + return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); + } + + return function(matchItem, query) { + return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; + }; + }); +}()); + +angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
      0\">
    • 0\">
    "); +$templateCache.put("bootstrap/match-multiple.tpl.html"," × "); +$templateCache.put("bootstrap/match.tpl.html",""); +$templateCache.put("bootstrap/select-multiple.tpl.html","
    "); +$templateCache.put("bootstrap/select.tpl.html","
    "); +$templateCache.put("select2/choices.tpl.html","
    "); +$templateCache.put("select2/match-multiple.tpl.html","
  • "); +$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); +$templateCache.put("select2/select-multiple.tpl.html","
    "); +$templateCache.put("select2/select.tpl.html","
    "); +$templateCache.put("selectize/choices.tpl.html","
    "); +$templateCache.put("selectize/match.tpl.html","
    "); +$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.min.css b/dist/select.min.css new file mode 100644 index 000000000..527100269 --- /dev/null +++ b/dist/select.min.css @@ -0,0 +1,6 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.8.3 - 2014-11-14T15:12:53.109Z + * License: MIT + */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select2-locked>.select2-search-choice-close{display:none}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js new file mode 100755 index 000000000..78ae53495 --- /dev/null +++ b/dist/select.min.js @@ -0,0 +1,7 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.8.3 - 2014-11-14T15:12:53.105Z + * License: MIT + */ +!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:"SPACE",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var i=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,i){var l=e+" in "+(i?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","RepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,i,l,s,n,a){function r(){(g.resetSearchInput||void 0===g.resetSearchInput&&a.resetSearchInput)&&(g.search=v,g.selected&&g.items.length&&!g.multiple&&(g.activeIndex=g.items.indexOf(g.selected)))}function o(t){var c=!0;switch(t){case e.DOWN:!g.open&&g.multiple?g.activate(!1,!0):g.activeIndex0||0===g.search.length&&g.tagging.isActivated)&&g.activeIndex--;break;case e.TAB:(!g.multiple||g.open)&&g.select(g.items[g.activeIndex],!0);break;case e.ENTER:g.open?g.select(g.items[g.activeIndex]):g.activate(!1,!0);break;case e.ESC:g.close();break;default:c=!1}return c}function u(t){function c(){switch(t){case e.LEFT:return~g.activeMatchIndex?o:n;case e.RIGHT:return~g.activeMatchIndex&&a!==n?r:(g.activate(),!1);case e.BACKSPACE:return~g.activeMatchIndex?(g.removeChoice(a),o):n;case e.DELETE:return~g.activeMatchIndex?(g.removeChoice(g.activeMatchIndex),a):!1}}var i=p(f[0]),l=g.selected.length,s=0,n=l-1,a=g.activeMatchIndex,r=g.activeMatchIndex+1,o=g.activeMatchIndex-1,u=a;return i>0||g.search.length&&t==e.RIGHT?!1:(g.close(),u=c(),g.activeMatchIndex=g.selected.length&&u!==!1?Math.min(n,Math.max(s,u)):-1,!0)}function d(e,t){for(var c=angular.copy(e),i=-1,l=0;ls?e[0].scrollTop+=l-s:l=g.items.length?0:g.activeIndex,i(function(){g.search=e||g.search,f[0].focus()}))},g.findGroupByName=function(e){return g.groups&&g.groups.filter(function(t){return t.name===e})[0]},g.parseRepeatAttr=function(e,c){function i(e){g.groups=[],angular.forEach(e,function(e){var i=t.$eval(c),l=angular.isFunction(i)?i(e):e[i],s=g.findGroupByName(l);s?s.items.push(e):g.groups.push({name:l,items:[e]})}),g.items=[],g.groups.forEach(function(e){g.items=g.items.concat(e.items)})}function l(e){g.items=e}var a=c?i:l;g.parserResult=s.parse(e),g.isGrouped=!!c,g.itemProperty=g.parserResult.itemName,t.$watchCollection(g.parserResult.source,function(e){if(void 0===e||null===e)g.items=[];else{if(!angular.isArray(e))throw n("items","Expected an array but got '{0}'.",e);if(g.multiple){var t=e.filter(function(e){return g.selected.indexOf(e)<0});a(t)}else a(e);g.ngModel.$modelValue=null}}),g.multiple&&t.$watchCollection("$select.selected",function(e){var c=g.parserResult.source(t);if(e.length){if(void 0!==c){var i=c.filter(function(t){return e.indexOf(t)<0});a(i)}}else a(c);g.sizeSearchInput()})};var m;g.refresh=function(e){void 0!==e&&(m&&i.cancel(m),m=i(function(){t.$eval(e)},g.refreshDelay))},g.setActiveItem=function(e){g.activeIndex=g.items.indexOf(e)},g.isActive=function(e){var t=g.open&&g.items.indexOf(e[g.itemProperty])===g.activeIndex;if(!t)return!1;t&&!angular.isUndefined(g.onHighlightCallback)&&e.$eval(g.onHighlightCallback);var c=g.items.indexOf(e[g.itemProperty]);return g.taggingLabel===!1&&-1===g.activeIndex?!1:c===g.activeIndex},g.isDisabled=function(e){if(g.open){var t,c=g.items.indexOf(e[g.itemProperty]),i=!1;return c>=0&&!angular.isUndefined(g.disableChoiceExpression)&&(t=g.items[c],i=!!e.$eval(g.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i}},g.select=function(e,c){if(!(!g.items&&!g.search||e&&e._uiSelectChoiceDisabled)){if(g.tagging.isActivated){if(g.taggingLabel===!1)if(g.activeIndex<0){if(e=void 0!==g.tagging.fct?g.tagging.fct(g.search):g.search,angular.equals(g.items[0],e))return}else e=g.items[g.activeIndex];else if(0===g.activeIndex){if(void 0===e)return;e=void 0!==g.tagging.fct?g.tagging.fct(g.search):e.replace(g.taggingLabel,"")}if(g.selected&&g.selected.filter(function(t){return angular.equals(t,e)}).length>0)return g.close(c),void 0}var i={};i[g.parserResult.itemName]=e,g.onSelectCallback(t,{$item:e,$model:g.parserResult.modelMapper(t,i)}),g.multiple?(g.selected.push(e),g.sizeSearchInput()):g.selected=e,g.close(c)}},g.close=function(e){g.open&&(r(),g.open=!1,g.multiple||i(function(){g.focusser.prop("disabled",!1),e||g.focusser[0].focus()},0,!1))},g.toggle=function(e){g.open?g.close():g.activate(),e.preventDefault(),e.stopPropagation()},g.isLocked=function(e,t){var c,i=g.selected[t];return i&&!angular.isUndefined(g.lockChoiceExpression)&&(c=!!e.$eval(g.lockChoiceExpression),i._uiSelectChoiceLocked=c),c},g.removeChoice=function(e){var c=g.selected[e];if(!c._uiSelectChoiceLocked){var i={};i[g.parserResult.itemName]=c,g.selected.splice(e,1),g.activeMatchIndex=-1,g.sizeSearchInput(),g.onRemoveCallback(t,{$item:c,$model:g.parserResult.modelMapper(t,i)})}},g.getPlaceholder=function(){return g.multiple&&g.selected.length?void 0:g.placeholder};var $;g.sizeSearchInput=function(){var e=f[0],c=f.parent().parent()[0];f.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),f.css("width",t+"px")};i(function(){0!==c.clientWidth||$?$||l():$=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),$(),$=null)})},0,!1)},f.on("keydown",function(c){var i=c.which;t.$apply(function(){var t=!1;if(g.multiple&&e.isHorizontalMovement(i)&&(t=u(i)),!t&&(g.items.length>0||g.tagging.isActivated)&&(t=o(i),g.taggingTokens.isActivated))for(var l=0;l0&&(g.select(null,!0),f.triggerHandler("tagged"));t&&i!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(i)&&g.items.length>0&&h()}),f.on("keyup",function(c){if(e.isVerticalMovement(c.which)||t.$evalAsync(function(){g.activeIndex=g.taggingLabel===!1?-1:0}),g.tagging.isActivated&&g.search.length>0){if(c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which))return;if(g.activeIndex=g.taggingLabel===!1?-1:0,g.taggingLabel===!1)return;var i,l,s,n,a=angular.copy(g.items),r=angular.copy(g.items),o=!1,u=-1;if(void 0!==g.tagging.fct){if(s=g.$filter("filter")(a,{isTag:!0}),s.length>0&&(n=s[0]),a.length>0&&n&&(o=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),i=g.tagging.fct(g.search),i.isTag=!0,r.filter(function(e){return angular.equals(e,g.tagging.fct(g.search))}).length>0)return}else{if(s=g.$filter("filter")(a,function(e){return e.match(g.taggingLabel)}),s.length>0&&(n=s[0]),l=a[0],void 0!==l&&a.length>0&&n&&(o=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),i=g.search+" "+g.taggingLabel,d(g.selected,g.search)>-1)return;if(r.filter(function(e){return e.toUpperCase()===g.search.toUpperCase()}).length>0)return o&&(a=r,t.$evalAsync(function(){g.activeIndex=0,g.items=a})),void 0;if(g.selected.filter(function(e){return e.toUpperCase()===g.search.toUpperCase()}).length>0)return o&&(g.items=r.slice(1,r.length)),void 0}o&&(u=d(g.selected,i)),u>-1?a=a.slice(u+1,a.length-1):(a=[],a.push(i),a=a.concat(r)),t.$evalAsync(function(){g.activeIndex=0,g.items=a})}}),f.on("tagged",function(){i(function(){r()})}),f.on("blur",function(){i(function(){g.activeMatchIndex=-1})}),t.$on("$destroy",function(){f.off("keyup keydown tagged blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,i,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||c.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(n,a,r,o,u){function d(e){var t=!1;t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),t||(p.close(),n.$digest())}var p=o[0],h=o[1],g=a.querySelectorAll("input.ui-select-search");p.multiple=angular.isDefined(r.multiple)?""===r.multiple?!0:"true"===r.multiple.toLowerCase():!1,p.onSelectCallback=s(r.onSelect),p.onRemoveCallback=s(r.onRemove),h.$parsers.unshift(function(e){var t,c={};if(p.multiple){for(var i=[],l=p.selected.length-1;l>=0;l--)c={},c[p.parserResult.itemName]=p.selected[l],t=p.parserResult.modelMapper(n,c),i.unshift(t);return i}return c={},c[p.parserResult.itemName]=e,t=p.parserResult.modelMapper(n,c)}),h.$formatters.unshift(function(e){var t,c=p.parserResult.source(n,{$select:{search:""}}),i={};if(c){if(p.multiple){var l=[],s=function(e,c){if(e&&e.length){for(var s=e.length-1;s>=0;s--)if(i[p.parserResult.itemName]=e[s],t=p.parserResult.modelMapper(n,i),t==c)return l.unshift(e[s]),!0;return!1}};if(!e)return l;for(var a=e.length-1;a>=0;a--)s(p.selected,e[a])||s(c,e[a]);return l}var r=function(c){return i[p.parserResult.itemName]=c,t=p.parserResult.modelMapper(n,i),t==e};if(p.selected&&r(p.selected))return p.selected;for(var o=c.length-1;o>=0;o--)if(r(c[o]))return c[o]}return e}),p.ngModel=h;var v=angular.element("");r.tabindex&&r.$observe("tabindex",function(e){p.multiple?g.attr("tabindex",e):v.attr("tabindex",e),a.removeAttr("tabindex")}),l(v)(n),p.focusser=v,p.multiple||(a.append(v),v.bind("focus",function(){n.$evalAsync(function(){p.focus=!0})}),v.bind("blur",function(){n.$evalAsync(function(){p.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),p.select(void 0),n.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),p.activate()),n.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(p.activate(v.val()),v.val(""),n.$digest())})),n.$watch("searchEnabled",function(){var e=n.$eval(r.searchEnabled);p.searchEnabled=void 0!==e?e:c.searchEnabled}),r.$observe("disabled",function(){p.disabled=void 0!==r.disabled?r.disabled:!1}),r.$observe("resetSearchInput",function(){var e=n.$eval(r.resetSearchInput);p.resetSearchInput=void 0!==e?e:!0}),r.$observe("tagging",function(){if(void 0!==r.tagging){var e=n.$eval(r.tagging);p.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else p.tagging={isActivated:!1,fct:void 0}}),r.$observe("taggingLabel",function(){void 0!==r.tagging&&void 0!==r.taggingLabel&&(p.taggingLabel="false"===r.taggingLabel?!1:void 0!==r.taggingLabel?r.taggingLabel:"(new)")}),r.$observe("taggingTokens",function(){if(void 0!==r.tagging){var e=void 0!==r.taggingTokens?r.taggingTokens.split("|"):[",","ENTER"];p.taggingTokens={isActivated:!0,tokens:e}}}),p.multiple?(n.$watchCollection(function(){return h.$modelValue},function(e,t){t!=e&&(h.$modelValue=null)}),n.$watchCollection("$select.selected",function(){h.$setViewValue(Date.now())}),v.prop("disabled",!0)):n.$watch("$select.selected",function(e){h.$viewValue!==e&&h.$setViewValue(e)}),h.$render=function(){if(p.multiple&&!angular.isArray(h.$viewValue)){if(!angular.isUndefined(h.$viewValue)&&null!==h.$viewValue)throw i("multiarr","Expected model value to be array but got '{0}'",h.$viewValue);p.selected=[]}p.selected=h.$viewValue},t.on("click",d),n.$on("$destroy",function(){t.off("click",d)}),u(n,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);a.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);a.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,s,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,a.onHighlightCallback=n.onHighlight,o){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),i(s,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,i,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return c+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,i,l){l.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file From e257625d26db5e2271bd9f6ddac0bd70f45a1290 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Fri, 14 Nov 2014 10:21:07 -0500 Subject: [PATCH 28/32] Revert "Add missing `dist` files to ensure tests pass" This reverts commit 3321c504b491ab1d80586618e856fedf7bb69373. --- dist/select.css | 171 ------ dist/select.js | 1233 ------------------------------------------- dist/select.min.css | 6 - dist/select.min.js | 7 - 4 files changed, 1417 deletions(-) delete mode 100644 dist/select.css delete mode 100755 dist/select.js delete mode 100644 dist/select.min.css delete mode 100755 dist/select.min.js diff --git a/dist/select.css b/dist/select.css deleted file mode 100644 index f8f44c836..000000000 --- a/dist/select.css +++ /dev/null @@ -1,171 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-11-14T15:12:53.109Z - * License: MIT - */ - - -/* Style when highlighting a search. */ -.ui-select-highlight { - font-weight: bold; -} - -.ui-select-offscreen { - clip: rect(0 0 0 0) !important; - width: 1px !important; - height: 1px !important; - border: 0 !important; - margin: 0 !important; - padding: 0 !important; - overflow: hidden !important; - position: absolute !important; - outline: 0 !important; - left: 0px !important; - top: 0px !important; -} - -/* Select2 theme */ - -/* Mark invalid Select2 */ -.ng-dirty.ng-invalid > a.select2-choice { - border-color: #D44950; -} - -.select2-result-single { - padding-left: 0; -} - -.select2-locked > .select2-search-choice-close{ - display:none; -} - -/* Selectize theme */ - -/* Helper class to show styles when focus */ -.selectize-input.selectize-focus{ - border-color: #007FBB !important; -} - -/* Fix input width for Selectize theme */ -.selectize-control > .selectize-input > input { - width: 100%; -} - -/* Fix dropdown width for Selectize theme */ -.selectize-control > .selectize-dropdown { - width: 100%; -} - -/* Mark invalid Selectize */ -.ng-dirty.ng-invalid > div.selectize-input { - border-color: #D44950; -} - - -/* Bootstrap theme */ - -/* Helper class to show styles when focus */ -.btn-default-focus { - color: #333; - background-color: #EBEBEB; - border-color: #ADADAD; - text-decoration: none; - outline: 5px auto -webkit-focus-ring-color; - outline-offset: -2px; - box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); -} - - -/* Fix Bootstrap dropdown position when inside a input-group */ -.input-group > .ui-select-bootstrap.dropdown { - /* Instead of relative */ - position: static; -} - -.input-group > .ui-select-bootstrap > input.ui-select-search.form-control { - border-radius: 4px; /* FIXME hardcoded value :-/ */ - border-top-right-radius: 0; - border-bottom-right-radius: 0; -} - -.ui-select-bootstrap > .ui-select-match { - /* Instead of center because of .btn */ - text-align: left; -} - -.ui-select-bootstrap > .ui-select-match > .caret { - position: absolute; - top: 45%; - right: 15px; -} - -/* See Scrollable Menu with Bootstrap 3 http://stackoverflow.com/questions/19227496 */ -.ui-select-bootstrap > .ui-select-choices { - width: 100%; - height: auto; - max-height: 200px; - overflow-x: hidden; -} - -.ui-select-multiple.ui-select-bootstrap { - height: auto; - padding: .3em; -} - -.ui-select-multiple.ui-select-bootstrap input.ui-select-search { - background-color: transparent !important; /* To prevent double background when disabled */ - border: none; - outline: none; - height: 1.666666em; -} - -.ui-select-multiple.ui-select-bootstrap .ui-select-match .close { - font-size: 1.6em; - line-height: 0.75; -} - -.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{ - outline: 0; -} - -.ui-select-bootstrap .ui-select-choices-row>a { - display: block; - padding: 3px 20px; - clear: both; - font-weight: 400; - line-height: 1.42857143; - color: #333; - white-space: nowrap; -} - -.ui-select-bootstrap .ui-select-choices-row>a:hover, .ui-select-bootstrap .ui-select-choices-row>a:focus { - text-decoration: none; - color: #262626; - background-color: #f5f5f5; -} - -.ui-select-bootstrap .ui-select-choices-row.active>a { - color: #fff; - text-decoration: none; - outline: 0; - background-color: #428bca; -} - -.ui-select-bootstrap .ui-select-choices-row.disabled>a, -.ui-select-bootstrap .ui-select-choices-row.active.disabled>a { - color: #777; - cursor: not-allowed; - background-color: #fff; -} - -/* fix hide/show angular animation */ -.ui-select-match.ng-hide-add, -.ui-select-search.ng-hide-add { - display: none !important; -} - -/* Mark invalid Bootstrap */ -.ui-select-bootstrap.ng-dirty.ng-invalid > button.btn.ui-select-match { - border-color: #D44950; -} diff --git a/dist/select.js b/dist/select.js deleted file mode 100755 index 1eebf84e1..000000000 --- a/dist/select.js +++ /dev/null @@ -1,1233 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-11-14T15:12:53.105Z - * License: MIT - */ - - -(function () { - "use strict"; - - var KEY = { - TAB: 9, - ENTER: 13, - ESC: 27, - SPACE: 32, - LEFT: 37, - UP: 38, - RIGHT: 39, - DOWN: 40, - SHIFT: 16, - CTRL: 17, - ALT: 18, - PAGE_UP: 33, - PAGE_DOWN: 34, - HOME: 36, - END: 35, - BACKSPACE: 8, - DELETE: 46, - COMMAND: 91, - - MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "SPACE" , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" - }, - - isControl: function (e) { - var k = e.which; - switch (k) { - case KEY.COMMAND: - case KEY.SHIFT: - case KEY.CTRL: - case KEY.ALT: - return true; - } - - if (e.metaKey) return true; - - return false; - }, - isFunctionKey: function (k) { - k = k.which ? k.which : k; - return k >= 112 && k <= 123; - }, - isVerticalMovement: function (k){ - return ~[KEY.UP, KEY.DOWN].indexOf(k); - }, - isHorizontalMovement: function (k){ - return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); - } - }; - - /** - * Add querySelectorAll() to jqLite. - * - * jqLite find() is limited to lookups by tag name. - * TODO This will change with future versions of AngularJS, to be removed when this happens - * - * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 - * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 - */ - if (angular.element.prototype.querySelectorAll === undefined) { - angular.element.prototype.querySelectorAll = function(selector) { - return angular.element(this[0].querySelectorAll(selector)); - }; - } - - angular.module('ui.select', []) - - .constant('uiSelectConfig', { - theme: 'bootstrap', - searchEnabled: true, - placeholder: '', // Empty by default, like HTML tag "); - - if(attrs.tabindex){ - //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex - attrs.$observe('tabindex', function(value) { - //If we are using multiple, add tabindex to the search input - if($select.multiple){ - searchInput.attr("tabindex", value); - } else { - focusser.attr("tabindex", value); - } - //Remove the tabindex on the parent so that it is not focusable - element.removeAttr("tabindex"); - }); - } - - $compile(focusser)(scope); - $select.focusser = focusser; - - if (!$select.multiple){ - - element.append(focusser); - focusser.bind("focus", function(){ - scope.$evalAsync(function(){ - $select.focus = true; - }); - }); - focusser.bind("blur", function(){ - scope.$evalAsync(function(){ - $select.focus = false; - }); - }); - focusser.bind("keydown", function(e){ - - if (e.which === KEY.BACKSPACE) { - e.preventDefault(); - e.stopPropagation(); - $select.select(undefined); - scope.$apply(); - return; - } - - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { - return; - } - - if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ - e.preventDefault(); - e.stopPropagation(); - $select.activate(); - } - - scope.$digest(); - }); - - focusser.bind("keyup input", function(e){ - - if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { - return; - } - - $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input - focusser.val(''); - scope.$digest(); - - }); - - } - - - scope.$watch('searchEnabled', function() { - var searchEnabled = scope.$eval(attrs.searchEnabled); - $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled; - }); - - attrs.$observe('disabled', function() { - // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string - $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false; - }); - - attrs.$observe('resetSearchInput', function() { - // $eval() is needed otherwise we get a string instead of a boolean - var resetSearchInput = scope.$eval(attrs.resetSearchInput); - $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true; - }); - - attrs.$observe('tagging', function() { - if(attrs.tagging !== undefined) - { - // $eval() is needed otherwise we get a string instead of a function or a boolean - var taggingEval = scope.$eval(attrs.tagging); - $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined}; - } - else - { - $select.tagging = {isActivated: false, fct: undefined}; - } - }); - - attrs.$observe('taggingLabel', function() { - if(attrs.tagging !== undefined && attrs.taggingLabel !== undefined) - { - // check eval for FALSE, in this case, we disable the labels - // associated with tagging - if ( attrs.taggingLabel === 'false' ) { - $select.taggingLabel = false; - } - else - { - $select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)'; - } - } - }); - - attrs.$observe('taggingTokens', function() { - if (attrs.tagging !== undefined) { - var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',','ENTER']; - $select.taggingTokens = {isActivated: true, tokens: tokens }; - } - }); - - if ($select.multiple){ - scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) { - if (oldValue != newValue) - ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters - }); - scope.$watchCollection('$select.selected', function() { - ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes - }); - focusser.prop('disabled', true); //Focusser isn't needed if multiple - }else{ - scope.$watch('$select.selected', function(newValue) { - if (ngModel.$viewValue !== newValue) { - ngModel.$setViewValue(newValue); - } - }); - } - - ngModel.$render = function() { - if($select.multiple){ - // Make sure that model value is array - if(!angular.isArray(ngModel.$viewValue)){ - // Have tolerance for null or undefined values - if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ - $select.selected = []; - } else { - throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); - } - } - } - $select.selected = ngModel.$viewValue; - }; - - function onDocumentClick(e) { - var contains = false; - - if (window.jQuery) { - // Firefox 3.6 does not support element.contains() - // See Node.contains https://developer.mozilla.org/en-US/docs/Web/API/Node.contains - contains = window.jQuery.contains(element[0], e.target); - } else { - contains = element[0].contains(e.target); - } - - if (!contains) { - $select.close(); - scope.$digest(); - } - } - - // See Click everywhere but here event http://stackoverflow.com/questions/12931369 - $document.on('click', onDocumentClick); - - scope.$on('$destroy', function() { - $document.off('click', onDocumentClick); - }); - - // Move transcluded elements to their correct position in main template - transcludeFn(scope, function(clone) { - // See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html - - // One day jqLite will be replaced by jQuery and we will be able to write: - // var transcludedElement = clone.filter('.my-class') - // instead of creating a hackish DOM element: - var transcluded = angular.element('
    ').append(clone); - - var transcludedMatch = transcluded.querySelectorAll('.ui-select-match'); - transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr - if (transcludedMatch.length !== 1) { - throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", transcludedMatch.length); - } - element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch); - - var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices'); - transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr - if (transcludedChoices.length !== 1) { - throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length); - } - element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices); - }); - } - }; - }]) - - .directive('uiSelectChoices', - ['uiSelectConfig', 'RepeatParser', 'uiSelectMinErr', '$compile', - function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) { - - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - return theme + '/choices.tpl.html'; - }, - - compile: function(tElement, tAttrs) { - - if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression."); - - return function link(scope, element, attrs, $select, transcludeFn) { - - // var repeat = RepeatParser.parse(attrs.repeat); - var groupByExp = attrs.groupBy; - - $select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult - - $select.disableChoiceExpression = attrs.uiDisableChoice; - $select.onHighlightCallback = attrs.onHighlight; - - if(groupByExp) { - var groups = element.querySelectorAll('.ui-select-choices-group'); - if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length); - groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression()); - } - - var choices = element.querySelectorAll('.ui-select-choices-row'); - if (choices.length !== 1) { - throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length); - } - - choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp)) - .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed - .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')') - .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ')'); - - var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner'); - if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length); - rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat - - $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend - - scope.$watch('$select.search', function(newValue) { - if(newValue && !$select.open && $select.multiple) $select.activate(false, true); - $select.activeIndex = $select.tagging.isActivated ? -1 : 0; - $select.refresh(attrs.refresh); - }); - - attrs.$observe('refreshDelay', function() { - // $eval() is needed otherwise we get a string instead of a number - var refreshDelay = scope.$eval(attrs.refreshDelay); - $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay; - }); - }; - } - }; - }]) - // Recreates old behavior of ng-transclude. Used internally. - .directive('uisTranscludeAppend', function () { - return { - link: function (scope, element, attrs, ctrl, transclude) { - transclude(scope, function (clone) { - element.append(clone); - }); - } - }; - }) - .directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) { - return { - restrict: 'EA', - require: '^uiSelect', - replace: true, - transclude: true, - templateUrl: function(tElement) { - // Gets theme attribute from parent (ui-select) - var theme = tElement.parent().attr('theme') || uiSelectConfig.theme; - var multi = tElement.parent().attr('multiple'); - return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html'); - }, - link: function(scope, element, attrs, $select) { - $select.lockChoiceExpression = attrs.uiLockChoice; - attrs.$observe('placeholder', function(placeholder) { - $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder; - }); - - if($select.multiple){ - $select.sizeSearchInput(); - } - - } - }; - }]) - - /** - * Highlights text that matches $select.search. - * - * Taken from AngularUI Bootstrap Typeahead - * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340 - */ - .filter('highlight', function() { - function escapeRegexp(queryToEscape) { - return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); - } - - return function(matchItem, query) { - return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '$&') : matchItem; - }; - }); -}()); - -angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
      0\">
    • 0\">
    "); -$templateCache.put("bootstrap/match-multiple.tpl.html"," × "); -$templateCache.put("bootstrap/match.tpl.html",""); -$templateCache.put("bootstrap/select-multiple.tpl.html","
    "); -$templateCache.put("bootstrap/select.tpl.html","
    "); -$templateCache.put("select2/choices.tpl.html","
    "); -$templateCache.put("select2/match-multiple.tpl.html","
  • "); -$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); -$templateCache.put("select2/select-multiple.tpl.html","
    "); -$templateCache.put("select2/select.tpl.html","
    "); -$templateCache.put("selectize/choices.tpl.html","
    "); -$templateCache.put("selectize/match.tpl.html","
    "); -$templateCache.put("selectize/select.tpl.html","
    ");}]); \ No newline at end of file diff --git a/dist/select.min.css b/dist/select.min.css deleted file mode 100644 index 527100269..000000000 --- a/dist/select.min.css +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-11-14T15:12:53.109Z - * License: MIT - */.ui-select-highlight{font-weight:700}.ui-select-offscreen{clip:rect(0 0 0 0)!important;width:1px!important;height:1px!important;border:0!important;margin:0!important;padding:0!important;overflow:hidden!important;position:absolute!important;outline:0!important;left:0!important;top:0!important}.ng-dirty.ng-invalid>a.select2-choice{border-color:#D44950}.select2-result-single{padding-left:0}.select2-locked>.select2-search-choice-close{display:none}.selectize-input.selectize-focus{border-color:#007FBB!important}.selectize-control>.selectize-dropdown,.selectize-control>.selectize-input>input{width:100%}.ng-dirty.ng-invalid>div.selectize-input{border-color:#D44950}.btn-default-focus{color:#333;background-color:#EBEBEB;border-color:#ADADAD;text-decoration:none;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.input-group>.ui-select-bootstrap.dropdown{position:static}.input-group>.ui-select-bootstrap>input.ui-select-search.form-control{border-radius:4px 0 0 4px}.ui-select-bootstrap>.ui-select-match{text-align:left}.ui-select-bootstrap>.ui-select-match>.caret{position:absolute;top:45%;right:15px}.ui-select-bootstrap>.ui-select-choices{width:100%;height:auto;max-height:200px;overflow-x:hidden}.ui-select-multiple.ui-select-bootstrap{height:auto;padding:.3em}.ui-select-multiple.ui-select-bootstrap input.ui-select-search{background-color:transparent!important;border:none;outline:0;height:1.666666em}.ui-select-multiple.ui-select-bootstrap .ui-select-match .close{font-size:1.6em;line-height:.75}.ui-select-multiple.ui-select-bootstrap .ui-select-match-item{outline:0}.ui-select-bootstrap .ui-select-choices-row>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.ui-select-bootstrap .ui-select-choices-row>a:focus,.ui-select-bootstrap .ui-select-choices-row>a:hover{text-decoration:none;color:#262626;background-color:#f5f5f5}.ui-select-bootstrap .ui-select-choices-row.active>a{color:#fff;text-decoration:none;outline:0;background-color:#428bca}.ui-select-bootstrap .ui-select-choices-row.active.disabled>a,.ui-select-bootstrap .ui-select-choices-row.disabled>a{color:#777;cursor:not-allowed;background-color:#fff}.ui-select-match.ng-hide-add,.ui-select-search.ng-hide-add{display:none!important}.ui-select-bootstrap.ng-dirty.ng-invalid>button.btn.ui-select-match{border-color:#D44950} \ No newline at end of file diff --git a/dist/select.min.js b/dist/select.min.js deleted file mode 100755 index 78ae53495..000000000 --- a/dist/select.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ui-select - * http://github.com/angular-ui/ui-select - * Version: 0.8.3 - 2014-11-14T15:12:53.105Z - * License: MIT - */ -!function(){"use strict";var e={TAB:9,ENTER:13,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,SHIFT:16,CTRL:17,ALT:18,PAGE_UP:33,PAGE_DOWN:34,HOME:36,END:35,BACKSPACE:8,DELETE:46,COMMAND:91,MAP:{91:"COMMAND",8:"BACKSPACE",9:"TAB",13:"ENTER",16:"SHIFT",17:"CTRL",18:"ALT",19:"PAUSEBREAK",20:"CAPSLOCK",27:"ESC",32:"SPACE",33:"PAGE_UP",34:"PAGE_DOWN",35:"END",36:"HOME",37:"LEFT",38:"UP",39:"RIGHT",40:"DOWN",43:"+",44:"PRINTSCREEN",45:"INSERT",46:"DELETE",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",96:"0",97:"1",98:"2",99:"3",100:"4",101:"5",102:"6",103:"7",104:"8",105:"9",106:"*",107:"+",109:"-",110:".",111:"/",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NUMLOCK",145:"SCROLLLOCK",186:";",187:"=",188:"SPACE",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},isControl:function(t){var c=t.which;switch(c){case e.COMMAND:case e.SHIFT:case e.CTRL:case e.ALT:return!0}return t.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e},isVerticalMovement:function(t){return~[e.UP,e.DOWN].indexOf(t)},isHorizontalMovement:function(t){return~[e.LEFT,e.RIGHT,e.BACKSPACE,e.DELETE].indexOf(t)}};void 0===angular.element.prototype.querySelectorAll&&(angular.element.prototype.querySelectorAll=function(e){return angular.element(this[0].querySelectorAll(e))}),angular.module("ui.select",[]).constant("uiSelectConfig",{theme:"bootstrap",searchEnabled:!0,placeholder:"",refreshDelay:1e3}).service("uiSelectMinErr",function(){var e=angular.$$minErr("ui.select");return function(){var t=e.apply(this,arguments),c=t.message.replace(new RegExp("\nhttp://errors.angularjs.org/.*"),"");return new Error(c)}}).service("RepeatParser",["uiSelectMinErr","$parse",function(e,t){var c=this;c.parse=function(c){var i=c.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);if(!i)throw e("iexp","Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",c);return{itemName:i[2],source:t(i[3]),trackByExp:i[4],modelMapper:t(i[1]||i[2])}},c.getGroupNgRepeatExpression=function(){return"$group in $select.groups"},c.getNgRepeatExpression=function(e,t,c,i){var l=e+" in "+(i?"$group.items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","$filter","RepeatParser","uiSelectMinErr","uiSelectConfig",function(t,c,i,l,s,n,a){function r(){(g.resetSearchInput||void 0===g.resetSearchInput&&a.resetSearchInput)&&(g.search=v,g.selected&&g.items.length&&!g.multiple&&(g.activeIndex=g.items.indexOf(g.selected)))}function o(t){var c=!0;switch(t){case e.DOWN:!g.open&&g.multiple?g.activate(!1,!0):g.activeIndex0||0===g.search.length&&g.tagging.isActivated)&&g.activeIndex--;break;case e.TAB:(!g.multiple||g.open)&&g.select(g.items[g.activeIndex],!0);break;case e.ENTER:g.open?g.select(g.items[g.activeIndex]):g.activate(!1,!0);break;case e.ESC:g.close();break;default:c=!1}return c}function u(t){function c(){switch(t){case e.LEFT:return~g.activeMatchIndex?o:n;case e.RIGHT:return~g.activeMatchIndex&&a!==n?r:(g.activate(),!1);case e.BACKSPACE:return~g.activeMatchIndex?(g.removeChoice(a),o):n;case e.DELETE:return~g.activeMatchIndex?(g.removeChoice(g.activeMatchIndex),a):!1}}var i=p(f[0]),l=g.selected.length,s=0,n=l-1,a=g.activeMatchIndex,r=g.activeMatchIndex+1,o=g.activeMatchIndex-1,u=a;return i>0||g.search.length&&t==e.RIGHT?!1:(g.close(),u=c(),g.activeMatchIndex=g.selected.length&&u!==!1?Math.min(n,Math.max(s,u)):-1,!0)}function d(e,t){for(var c=angular.copy(e),i=-1,l=0;ls?e[0].scrollTop+=l-s:l=g.items.length?0:g.activeIndex,i(function(){g.search=e||g.search,f[0].focus()}))},g.findGroupByName=function(e){return g.groups&&g.groups.filter(function(t){return t.name===e})[0]},g.parseRepeatAttr=function(e,c){function i(e){g.groups=[],angular.forEach(e,function(e){var i=t.$eval(c),l=angular.isFunction(i)?i(e):e[i],s=g.findGroupByName(l);s?s.items.push(e):g.groups.push({name:l,items:[e]})}),g.items=[],g.groups.forEach(function(e){g.items=g.items.concat(e.items)})}function l(e){g.items=e}var a=c?i:l;g.parserResult=s.parse(e),g.isGrouped=!!c,g.itemProperty=g.parserResult.itemName,t.$watchCollection(g.parserResult.source,function(e){if(void 0===e||null===e)g.items=[];else{if(!angular.isArray(e))throw n("items","Expected an array but got '{0}'.",e);if(g.multiple){var t=e.filter(function(e){return g.selected.indexOf(e)<0});a(t)}else a(e);g.ngModel.$modelValue=null}}),g.multiple&&t.$watchCollection("$select.selected",function(e){var c=g.parserResult.source(t);if(e.length){if(void 0!==c){var i=c.filter(function(t){return e.indexOf(t)<0});a(i)}}else a(c);g.sizeSearchInput()})};var m;g.refresh=function(e){void 0!==e&&(m&&i.cancel(m),m=i(function(){t.$eval(e)},g.refreshDelay))},g.setActiveItem=function(e){g.activeIndex=g.items.indexOf(e)},g.isActive=function(e){var t=g.open&&g.items.indexOf(e[g.itemProperty])===g.activeIndex;if(!t)return!1;t&&!angular.isUndefined(g.onHighlightCallback)&&e.$eval(g.onHighlightCallback);var c=g.items.indexOf(e[g.itemProperty]);return g.taggingLabel===!1&&-1===g.activeIndex?!1:c===g.activeIndex},g.isDisabled=function(e){if(g.open){var t,c=g.items.indexOf(e[g.itemProperty]),i=!1;return c>=0&&!angular.isUndefined(g.disableChoiceExpression)&&(t=g.items[c],i=!!e.$eval(g.disableChoiceExpression),t._uiSelectChoiceDisabled=i),i}},g.select=function(e,c){if(!(!g.items&&!g.search||e&&e._uiSelectChoiceDisabled)){if(g.tagging.isActivated){if(g.taggingLabel===!1)if(g.activeIndex<0){if(e=void 0!==g.tagging.fct?g.tagging.fct(g.search):g.search,angular.equals(g.items[0],e))return}else e=g.items[g.activeIndex];else if(0===g.activeIndex){if(void 0===e)return;e=void 0!==g.tagging.fct?g.tagging.fct(g.search):e.replace(g.taggingLabel,"")}if(g.selected&&g.selected.filter(function(t){return angular.equals(t,e)}).length>0)return g.close(c),void 0}var i={};i[g.parserResult.itemName]=e,g.onSelectCallback(t,{$item:e,$model:g.parserResult.modelMapper(t,i)}),g.multiple?(g.selected.push(e),g.sizeSearchInput()):g.selected=e,g.close(c)}},g.close=function(e){g.open&&(r(),g.open=!1,g.multiple||i(function(){g.focusser.prop("disabled",!1),e||g.focusser[0].focus()},0,!1))},g.toggle=function(e){g.open?g.close():g.activate(),e.preventDefault(),e.stopPropagation()},g.isLocked=function(e,t){var c,i=g.selected[t];return i&&!angular.isUndefined(g.lockChoiceExpression)&&(c=!!e.$eval(g.lockChoiceExpression),i._uiSelectChoiceLocked=c),c},g.removeChoice=function(e){var c=g.selected[e];if(!c._uiSelectChoiceLocked){var i={};i[g.parserResult.itemName]=c,g.selected.splice(e,1),g.activeMatchIndex=-1,g.sizeSearchInput(),g.onRemoveCallback(t,{$item:c,$model:g.parserResult.modelMapper(t,i)})}},g.getPlaceholder=function(){return g.multiple&&g.selected.length?void 0:g.placeholder};var $;g.sizeSearchInput=function(){var e=f[0],c=f.parent().parent()[0];f.css("width","10px");var l=function(){var t=c.clientWidth-e.offsetLeft-10;50>t&&(t=c.clientWidth),f.css("width",t+"px")};i(function(){0!==c.clientWidth||$?$||l():$=t.$watch(function(){return c.clientWidth},function(e){0!==e&&(l(),$(),$=null)})},0,!1)},f.on("keydown",function(c){var i=c.which;t.$apply(function(){var t=!1;if(g.multiple&&e.isHorizontalMovement(i)&&(t=u(i)),!t&&(g.items.length>0||g.tagging.isActivated)&&(t=o(i),g.taggingTokens.isActivated))for(var l=0;l0&&(g.select(null,!0),f.triggerHandler("tagged"));t&&i!=e.TAB&&(c.preventDefault(),c.stopPropagation())}),e.isVerticalMovement(i)&&g.items.length>0&&h()}),f.on("keyup",function(c){if(e.isVerticalMovement(c.which)||t.$evalAsync(function(){g.activeIndex=g.taggingLabel===!1?-1:0}),g.tagging.isActivated&&g.search.length>0){if(c.which===e.TAB||e.isControl(c)||e.isFunctionKey(c)||c.which===e.ESC||e.isVerticalMovement(c.which))return;if(g.activeIndex=g.taggingLabel===!1?-1:0,g.taggingLabel===!1)return;var i,l,s,n,a=angular.copy(g.items),r=angular.copy(g.items),o=!1,u=-1;if(void 0!==g.tagging.fct){if(s=g.$filter("filter")(a,{isTag:!0}),s.length>0&&(n=s[0]),a.length>0&&n&&(o=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),i=g.tagging.fct(g.search),i.isTag=!0,r.filter(function(e){return angular.equals(e,g.tagging.fct(g.search))}).length>0)return}else{if(s=g.$filter("filter")(a,function(e){return e.match(g.taggingLabel)}),s.length>0&&(n=s[0]),l=a[0],void 0!==l&&a.length>0&&n&&(o=!0,a=a.slice(1,a.length),r=r.slice(1,r.length)),i=g.search+" "+g.taggingLabel,d(g.selected,g.search)>-1)return;if(r.filter(function(e){return e.toUpperCase()===g.search.toUpperCase()}).length>0)return o&&(a=r,t.$evalAsync(function(){g.activeIndex=0,g.items=a})),void 0;if(g.selected.filter(function(e){return e.toUpperCase()===g.search.toUpperCase()}).length>0)return o&&(g.items=r.slice(1,r.length)),void 0}o&&(u=d(g.selected,i)),u>-1?a=a.slice(u+1,a.length-1):(a=[],a.push(i),a=a.concat(r)),t.$evalAsync(function(){g.activeIndex=0,g.items=a})}}),f.on("tagged",function(){i(function(){r()})}),f.on("blur",function(){i(function(){g.activeMatchIndex=-1})}),t.$on("$destroy",function(){f.off("keyup keydown tagged blur")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile","$parse",function(t,c,i,l,s){return{restrict:"EA",templateUrl:function(e,t){var i=t.theme||c.theme;return i+(angular.isDefined(t.multiple)?"/select-multiple.tpl.html":"/select.tpl.html")},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(n,a,r,o,u){function d(e){var t=!1;t=window.jQuery?window.jQuery.contains(a[0],e.target):a[0].contains(e.target),t||(p.close(),n.$digest())}var p=o[0],h=o[1],g=a.querySelectorAll("input.ui-select-search");p.multiple=angular.isDefined(r.multiple)?""===r.multiple?!0:"true"===r.multiple.toLowerCase():!1,p.onSelectCallback=s(r.onSelect),p.onRemoveCallback=s(r.onRemove),h.$parsers.unshift(function(e){var t,c={};if(p.multiple){for(var i=[],l=p.selected.length-1;l>=0;l--)c={},c[p.parserResult.itemName]=p.selected[l],t=p.parserResult.modelMapper(n,c),i.unshift(t);return i}return c={},c[p.parserResult.itemName]=e,t=p.parserResult.modelMapper(n,c)}),h.$formatters.unshift(function(e){var t,c=p.parserResult.source(n,{$select:{search:""}}),i={};if(c){if(p.multiple){var l=[],s=function(e,c){if(e&&e.length){for(var s=e.length-1;s>=0;s--)if(i[p.parserResult.itemName]=e[s],t=p.parserResult.modelMapper(n,i),t==c)return l.unshift(e[s]),!0;return!1}};if(!e)return l;for(var a=e.length-1;a>=0;a--)s(p.selected,e[a])||s(c,e[a]);return l}var r=function(c){return i[p.parserResult.itemName]=c,t=p.parserResult.modelMapper(n,i),t==e};if(p.selected&&r(p.selected))return p.selected;for(var o=c.length-1;o>=0;o--)if(r(c[o]))return c[o]}return e}),p.ngModel=h;var v=angular.element("");r.tabindex&&r.$observe("tabindex",function(e){p.multiple?g.attr("tabindex",e):v.attr("tabindex",e),a.removeAttr("tabindex")}),l(v)(n),p.focusser=v,p.multiple||(a.append(v),v.bind("focus",function(){n.$evalAsync(function(){p.focus=!0})}),v.bind("blur",function(){n.$evalAsync(function(){p.focus=!1})}),v.bind("keydown",function(t){return t.which===e.BACKSPACE?(t.preventDefault(),t.stopPropagation(),p.select(void 0),n.$apply(),void 0):(t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||((t.which==e.DOWN||t.which==e.UP||t.which==e.ENTER||t.which==e.SPACE)&&(t.preventDefault(),t.stopPropagation(),p.activate()),n.$digest()),void 0)}),v.bind("keyup input",function(t){t.which===e.TAB||e.isControl(t)||e.isFunctionKey(t)||t.which===e.ESC||t.which==e.ENTER||t.which===e.BACKSPACE||(p.activate(v.val()),v.val(""),n.$digest())})),n.$watch("searchEnabled",function(){var e=n.$eval(r.searchEnabled);p.searchEnabled=void 0!==e?e:c.searchEnabled}),r.$observe("disabled",function(){p.disabled=void 0!==r.disabled?r.disabled:!1}),r.$observe("resetSearchInput",function(){var e=n.$eval(r.resetSearchInput);p.resetSearchInput=void 0!==e?e:!0}),r.$observe("tagging",function(){if(void 0!==r.tagging){var e=n.$eval(r.tagging);p.tagging={isActivated:!0,fct:e!==!0?e:void 0}}else p.tagging={isActivated:!1,fct:void 0}}),r.$observe("taggingLabel",function(){void 0!==r.tagging&&void 0!==r.taggingLabel&&(p.taggingLabel="false"===r.taggingLabel?!1:void 0!==r.taggingLabel?r.taggingLabel:"(new)")}),r.$observe("taggingTokens",function(){if(void 0!==r.tagging){var e=void 0!==r.taggingTokens?r.taggingTokens.split("|"):[",","ENTER"];p.taggingTokens={isActivated:!0,tokens:e}}}),p.multiple?(n.$watchCollection(function(){return h.$modelValue},function(e,t){t!=e&&(h.$modelValue=null)}),n.$watchCollection("$select.selected",function(){h.$setViewValue(Date.now())}),v.prop("disabled",!0)):n.$watch("$select.selected",function(e){h.$viewValue!==e&&h.$setViewValue(e)}),h.$render=function(){if(p.multiple&&!angular.isArray(h.$viewValue)){if(!angular.isUndefined(h.$viewValue)&&null!==h.$viewValue)throw i("multiarr","Expected model value to be array but got '{0}'",h.$viewValue);p.selected=[]}p.selected=h.$viewValue},t.on("click",d),n.$on("$destroy",function(){t.off("click",d)}),u(n,function(e){var t=angular.element("
    ").append(e),c=t.querySelectorAll(".ui-select-match");if(c.removeAttr("ui-select-match"),1!==c.length)throw i("transcluded","Expected 1 .ui-select-match but got '{0}'.",c.length);a.querySelectorAll(".ui-select-match").replaceWith(c);var l=t.querySelectorAll(".ui-select-choices");if(l.removeAttr("ui-select-choices"),1!==l.length)throw i("transcluded","Expected 1 .ui-select-choices but got '{0}'.",l.length);a.querySelectorAll(".ui-select-choices").replaceWith(l)})}}}]).directive("uiSelectChoices",["uiSelectConfig","RepeatParser","uiSelectMinErr","$compile",function(e,t,c,i){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme;return c+"/choices.tpl.html"},compile:function(l,s){if(!s.repeat)throw c("repeat","Expected 'repeat' expression.");return function(l,s,n,a,r){var o=n.groupBy;if(a.parseRepeatAttr(n.repeat,o),a.disableChoiceExpression=n.uiDisableChoice,a.onHighlightCallback=n.onHighlight,o){var u=s.querySelectorAll(".ui-select-choices-group");if(1!==u.length)throw c("rows","Expected 1 .ui-select-choices-group but got '{0}'.",u.length);u.attr("ng-repeat",t.getGroupNgRepeatExpression())}var d=s.querySelectorAll(".ui-select-choices-row");if(1!==d.length)throw c("rows","Expected 1 .ui-select-choices-row but got '{0}'.",d.length);d.attr("ng-repeat",t.getNgRepeatExpression(a.parserResult.itemName,"$select.items",a.parserResult.trackByExp,o)).attr("ng-if","$select.open").attr("ng-mouseenter","$select.setActiveItem("+a.parserResult.itemName+")").attr("ng-click","$select.select("+a.parserResult.itemName+")");var p=s.querySelectorAll(".ui-select-choices-row-inner");if(1!==p.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",p.length);p.attr("uis-transclude-append",""),i(s,r)(l),l.$watch("$select.search",function(e){e&&!a.open&&a.multiple&&a.activate(!1,!0),a.activeIndex=a.tagging.isActivated?-1:0,a.refresh(n.refresh)}),n.$observe("refreshDelay",function(){var t=l.$eval(n.refreshDelay);a.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).directive("uisTranscludeAppend",function(){return{link:function(e,t,c,i,l){l(e,function(e){t.append(e)})}}}).directive("uiSelectMatch",["uiSelectConfig",function(e){return{restrict:"EA",require:"^uiSelect",replace:!0,transclude:!0,templateUrl:function(t){var c=t.parent().attr("theme")||e.theme,i=t.parent().attr("multiple");return c+(i?"/match-multiple.tpl.html":"/match.tpl.html")},link:function(t,c,i,l){l.lockChoiceExpression=i.uiLockChoice,i.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder}),l.multiple&&l.sizeSearchInput()}}}]).filter("highlight",function(){function e(e){return e.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")}return function(t,c){return c&&t?t.replace(new RegExp(e(c),"gi"),'$&'):t}})}(),angular.module("ui.select").run(["$templateCache",function(e){e.put("bootstrap/choices.tpl.html",''),e.put("bootstrap/match-multiple.tpl.html",' × '),e.put("bootstrap/match.tpl.html",''),e.put("bootstrap/select-multiple.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
    '),e.put("select2/match-multiple.tpl.html",'
  • '),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select-multiple.tpl.html",'
    '),e.put("select2/select.tpl.html",'
    '),e.put("selectize/choices.tpl.html",'
    '),e.put("selectize/match.tpl.html",'
    '),e.put("selectize/select.tpl.html",'
    ')}]); \ No newline at end of file From a2f0b28a9768486c43600e28b95657abac386e94 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Fri, 14 Nov 2014 10:21:45 -0500 Subject: [PATCH 29/32] explicittly set tagging default on controller --- src/select.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/select.js b/src/select.js index 1c6657146..88638af71 100644 --- a/src/select.js +++ b/src/select.js @@ -164,6 +164,7 @@ ctrl.multiple = false; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelect directive link function ctrl.$filter = $filter; + ctrl.tagging = {isActivated: false, fct: undefined}; ctrl.taggingTokens = {isActivated: false, tokens: undefined}; ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelect directive link function From 7ee06b30d3faa85d9a536e5268cf22b8bb906ff6 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Fri, 21 Nov 2014 11:03:00 +0100 Subject: [PATCH 30/32] cleanup --- src/select.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/select.js b/src/select.js index 88638af71..ef02e5520 100644 --- a/src/select.js +++ b/src/select.js @@ -163,7 +163,6 @@ ctrl.refreshDelay = undefined; // Initialized inside uiSelectChoices directive link function ctrl.multiple = false; // Initialized inside uiSelect directive link function ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelect directive link function - ctrl.$filter = $filter; ctrl.tagging = {isActivated: false, fct: undefined}; ctrl.taggingTokens = {isActivated: false, tokens: undefined}; ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelect directive link function @@ -977,7 +976,7 @@ attrs.$observe('tagging', function() { if(attrs.tagging !== undefined) { - // $eval() is needed otherwise we get a string instead of a function or a boolean + // $eval() is needed otherwise we get a string instead of a boolean var taggingEval = scope.$eval(attrs.tagging); $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined}; } From e417d2005e5d7d61ed73730de13316c2611203f7 Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Tue, 25 Nov 2014 11:08:28 -0500 Subject: [PATCH 31/32] Restore ctrl.$filter since it's best pinned to ctrl, fix issue with ctrl.isActive method returning false positives in initial empty state --- src/select.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/select.js b/src/select.js index 71f22e577..eb40d1eb2 100644 --- a/src/select.js +++ b/src/select.js @@ -169,6 +169,7 @@ ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelect directive link function ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function ctrl.clickTriggeredSelect = false; + ctrl.$filter = $filter; ctrl.isEmpty = function() { return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === ''; @@ -316,16 +317,19 @@ }; ctrl.isActive = function(itemScope) { - var isActive = ctrl.open && ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex; + if ( !ctrl.open ) { + return false; + } + var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); + var isActive = itemIndex === ctrl.activeIndex; - if ( !isActive ) { + if ( !isActive || itemIndex < 0 ) { return false; } if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { itemScope.$eval(ctrl.onHighlightCallback); } - var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); if ( ctrl.taggingLabel === false && ctrl.activeIndex === -1 ) { return false; } From 5d8fb7e5d84db1b513c94d40affab8e1c438dccc Mon Sep 17 00:00:00 2001 From: Brian Feister Date: Tue, 25 Nov 2014 12:54:37 -0500 Subject: [PATCH 32/32] Fix incorrect initial -1 activeIndex when `taggingLabel !== false` --- src/select.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/select.js b/src/select.js index eb40d1eb2..263d007b6 100644 --- a/src/select.js +++ b/src/select.js @@ -201,6 +201,12 @@ ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex; + // ensure that the index is set to zero for tagging variants + // that where first option is auto-selected + if ( ctrl.activeIndex === -1 && ctrl.taggingLabel !== false ) { + ctrl.activeIndex = 0; + } + // Give it time to appear before focus $timeout(function() { ctrl.search = initSearchValue || ctrl.search; @@ -323,17 +329,15 @@ var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]); var isActive = itemIndex === ctrl.activeIndex; - if ( !isActive || itemIndex < 0 ) { + if ( !isActive || ( itemIndex < 0 && ctrl.taggingLabel !== false ) ||( itemIndex < 0 && ctrl.taggingLabel === false) ) { return false; } + if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) { itemScope.$eval(ctrl.onHighlightCallback); } - if ( ctrl.taggingLabel === false && ctrl.activeIndex === -1 ) { - return false; - } - return itemIndex === ctrl.activeIndex; + return isActive; }; ctrl.isDisabled = function(itemScope) { @@ -1014,6 +1018,10 @@ $select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)'; } } + else + { + $select.taggingLabel = false; + } }); attrs.$observe('taggingTokens', function() {