diff --git a/bower.json b/bower.json index 8fe4f1b34..795605f28 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ui-select", - "version": "0.5.0", + "version": "0.5.1", "homepage": "https://github.com/angular-ui/ui-select", "authors": [ "AngularUI" diff --git a/dist/select.css b/dist/select.css index 80f9d51d3..1dab88686 100644 --- a/dist/select.css +++ b/dist/select.css @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.5.0 - 2014-07-30T04:47:33.136Z + * Version: 0.5.1 - 2014-08-01T01:09:37.152Z * License: MIT */ diff --git a/dist/select.js b/dist/select.js index b6fdfdb46..ed28f4903 100755 --- a/dist/select.js +++ b/dist/select.js @@ -1,7 +1,7 @@ /*! * ui-select * http://github.com/angular-ui/ui-select - * Version: 0.5.0 - 2014-07-30T04:47:33.132Z + * Version: 0.5.1 - 2014-08-01T01:09:37.148Z * License: MIT */ @@ -72,7 +72,7 @@ return { itemName: match[2], // (lhs) Left-hand side, - source: match[3], // (rhs) Right-hand side, + source: $parse(match[3]), trackByExp: match[4], modelMapper: $parse(match[1] || match[2]) }; @@ -358,8 +358,7 @@ //From model --> view ngModel.$formatters.unshift(function (inputValue) { - var match = $select.parserResult.source.match(/^\s*([\S]+).*$/); - var data = scope[match[1]]; + var data = $select.parserResult.source(scope); if (data){ for (var i = data.length - 1; i >= 0; i--) { var locals = {}; diff --git a/dist/select.min.css b/dist/select.min.css index e8b7426fd..7bd7a643b 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.5.0 - 2014-07-30T04:47:33.136Z + * Version: 0.5.1 - 2014-08-01T01:09:37.152Z * 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-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 diff --git a/dist/select.min.js b/dist/select.min.js index 3a1bac339..e266ce7ca 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.5.0 - 2014-07-30T04:47:33.132Z + * Version: 0.5.1 - 2014-08-01T01:09:37.148Z * License: MIT */ -!function(){"use strict";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",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]+?)\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:s[3],trackByExp:s[4],modelMapper:t(s[1]||s[2])}},c.getGroupNgRepeatExpression=function(){return"($group, $items) in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(e,t,c,s,l){function i(){o.resetSearchInput&&(o.search=a,o.selected&&o.items.length&&(o.activeIndex=o.items.indexOf(o.selected)))}function r(e){var t=!0;switch(e){case d.Down:o.activeIndex0&&o.activeIndex--;break;case d.Tab:case d.Enter:o.select(o.items[o.activeIndex]);break;case d.Escape:o.close();break;default:t=!1}return t}function n(){var e=t.querySelectorAll(".ui-select-choices-content"),c=e.querySelectorAll(".ui-select-choices-row");if(c.length<1)throw l("choices","Expected multiple .ui-select-choices-row but got '{0}'.",c.length);var s=c[o.activeIndex],i=s.offsetTop+s.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;i>r?e[0].scrollTop+=i-r:i=0){var c=t.which;switch(e.$apply(function(){var e=r(c);e&&c!=d.Tab&&(t.preventDefault(),t.stopPropagation())}),c){case d.Down:case d.Up:n()}}}),e.$on("$destroy",function(){u.off("keydown")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",templateUrl:function(e,c){var s=c.theme||t.theme;return s+"/select.tpl.html"},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(t,l,i,r,n){function o(e){var c=!1;c=window.jQuery?window.jQuery.contains(l[0],e.target):l[0].contains(e.target),c||(a.close(),t.$digest())}var a=r[0],u=r[1];u.$parsers.unshift(function(e){var c={};c[a.parserResult.itemName]=e;var s=a.parserResult.modelMapper(t,c);return s}),u.$formatters.unshift(function(e){var c=a.parserResult.source.match(/^\s*([\S]+).*$/),s=t[c[1]];if(s)for(var l=s.length-1;l>=0;l--){var i={};i[a.parserResult.itemName]=s[l];var r=a.parserResult.modelMapper(t,i);if(r==e)return s[l]}return e});var p=angular.element("");s(p)(t),a.focusser=p,l.append(p),p.bind("focus",function(){t.$evalAsync(function(){a.focus=!0})}),p.bind("blur",function(){t.$evalAsync(function(){a.focus=!1})}),p.bind("keydown",function(e){return e.which===d.BACKSPACE?(e.preventDefault(),e.stopPropagation(),a.select(void 0),void t.$digest()):void(e.which===d.TAB||d.isControl(e)||d.isFunctionKey(e)||e.which===d.ESC||((e.which==d.DOWN||e.which==d.UP||e.which==d.ENTER||e.which==d.SPACE)&&(e.preventDefault(),e.stopPropagation(),a.activate()),t.$digest()))}),p.bind("keyup input",function(e){e.which===d.TAB||d.isControl(e)||d.isFunctionKey(e)||e.which===d.ESC||e.which==d.ENTER||e.which===d.BACKSPACE||(a.activate(p.val()),p.val(""),t.$digest())});var d={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,isArrow:function(e){switch(e=e.which?e.which:e){case d.LEFT:case d.RIGHT:case d.UP:case d.DOWN:return!0}return!1},isControl:function(e){var t=e.which;switch(t){case d.SHIFT:case d.CTRL:case d.ALT:return!0}return e.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e}};i.$observe("disabled",function(){a.disabled=void 0!==i.disabled?i.disabled:!1}),i.$observe("resetSearchInput",function(){var e=t.$eval(i.resetSearchInput);a.resetSearchInput=void 0!==e?e:!0}),t.$watch("$select.selected",function(e){u.$viewValue!==e&&u.$setViewValue(e)}),u.$render=function(){a.selected=u.$viewValue},e.on("click",o),t.$on("$destroy",function(){e.off("click",o)}),n(t,function(e){var t=angular.element("
").append(e),s=t.querySelectorAll(".ui-select-match");if(s.removeAttr("ui-select-match"),1!==s.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",s.length);l.querySelectorAll(".ui-select-match").replaceWith(s);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),1!==i.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);l.querySelectorAll(".ui-select-choices").replaceWith(i)})}}}]).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,r,n,o){var a=r.groupBy;if(n.parseRepeatAttr(r.repeat,a),a){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(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,a)).attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+")"),o(function(e){var t=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==t.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",t.length);t.append(e),s(i)(l)}),l.$watch("$select.search",function(){n.activeIndex=0,n.refresh(r.refresh)}),r.$observe("refreshDelay",function(){var t=l.$eval(r.refreshDelay);n.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).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;return c+"/match.tpl.html"},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder})}}}]).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.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("selectize/choices.tpl.html",'
{{$group}}
'),e.put("selectize/match.tpl.html",'
'),e.put("selectize/select.tpl.html",'
'),e.put("select2/choices.tpl.html",'
  • {{$group}}
'),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select.tpl.html",'
')}]); \ No newline at end of file +!function(){"use strict";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",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]+?)\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, $items) in $select.groups"},c.getNgRepeatExpression=function(e,t,c,s){var l=e+" in "+(s?"$items":t);return c&&(l+=" track by "+c),l}}]).controller("uiSelectCtrl",["$scope","$element","$timeout","RepeatParser","uiSelectMinErr",function(e,t,c,s,l){function i(){o.resetSearchInput&&(o.search=a,o.selected&&o.items.length&&(o.activeIndex=o.items.indexOf(o.selected)))}function r(e){var t=!0;switch(e){case d.Down:o.activeIndex0&&o.activeIndex--;break;case d.Tab:case d.Enter:o.select(o.items[o.activeIndex]);break;case d.Escape:o.close();break;default:t=!1}return t}function n(){var e=t.querySelectorAll(".ui-select-choices-content"),c=e.querySelectorAll(".ui-select-choices-row");if(c.length<1)throw l("choices","Expected multiple .ui-select-choices-row but got '{0}'.",c.length);var s=c[o.activeIndex],i=s.offsetTop+s.clientHeight-e[0].scrollTop,r=e[0].offsetHeight;i>r?e[0].scrollTop+=i-r:i=0){var c=t.which;switch(e.$apply(function(){var e=r(c);e&&c!=d.Tab&&(t.preventDefault(),t.stopPropagation())}),c){case d.Down:case d.Up:n()}}}),e.$on("$destroy",function(){u.off("keydown")})}]).directive("uiSelect",["$document","uiSelectConfig","uiSelectMinErr","$compile",function(e,t,c,s){return{restrict:"EA",templateUrl:function(e,c){var s=c.theme||t.theme;return s+"/select.tpl.html"},replace:!0,transclude:!0,require:["uiSelect","ngModel"],scope:!0,controller:"uiSelectCtrl",controllerAs:"$select",link:function(t,l,i,r,n){function o(e){var c=!1;c=window.jQuery?window.jQuery.contains(l[0],e.target):l[0].contains(e.target),c||(a.close(),t.$digest())}var a=r[0],u=r[1];u.$parsers.unshift(function(e){var c={};c[a.parserResult.itemName]=e;var s=a.parserResult.modelMapper(t,c);return s}),u.$formatters.unshift(function(e){var c=a.parserResult.source(t);if(c)for(var s=c.length-1;s>=0;s--){var l={};l[a.parserResult.itemName]=c[s];var i=a.parserResult.modelMapper(t,l);if(i==e)return c[s]}return e});var p=angular.element("");s(p)(t),a.focusser=p,l.append(p),p.bind("focus",function(){t.$evalAsync(function(){a.focus=!0})}),p.bind("blur",function(){t.$evalAsync(function(){a.focus=!1})}),p.bind("keydown",function(e){return e.which===d.BACKSPACE?(e.preventDefault(),e.stopPropagation(),a.select(void 0),void t.$digest()):void(e.which===d.TAB||d.isControl(e)||d.isFunctionKey(e)||e.which===d.ESC||((e.which==d.DOWN||e.which==d.UP||e.which==d.ENTER||e.which==d.SPACE)&&(e.preventDefault(),e.stopPropagation(),a.activate()),t.$digest()))}),p.bind("keyup input",function(e){e.which===d.TAB||d.isControl(e)||d.isFunctionKey(e)||e.which===d.ESC||e.which==d.ENTER||e.which===d.BACKSPACE||(a.activate(p.val()),p.val(""),t.$digest())});var d={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,isArrow:function(e){switch(e=e.which?e.which:e){case d.LEFT:case d.RIGHT:case d.UP:case d.DOWN:return!0}return!1},isControl:function(e){var t=e.which;switch(t){case d.SHIFT:case d.CTRL:case d.ALT:return!0}return e.metaKey?!0:!1},isFunctionKey:function(e){return e=e.which?e.which:e,e>=112&&123>=e}};i.$observe("disabled",function(){a.disabled=void 0!==i.disabled?i.disabled:!1}),i.$observe("resetSearchInput",function(){var e=t.$eval(i.resetSearchInput);a.resetSearchInput=void 0!==e?e:!0}),t.$watch("$select.selected",function(e){u.$viewValue!==e&&u.$setViewValue(e)}),u.$render=function(){a.selected=u.$viewValue},e.on("click",o),t.$on("$destroy",function(){e.off("click",o)}),n(t,function(e){var t=angular.element("
").append(e),s=t.querySelectorAll(".ui-select-match");if(s.removeAttr("ui-select-match"),1!==s.length)throw c("transcluded","Expected 1 .ui-select-match but got '{0}'.",s.length);l.querySelectorAll(".ui-select-match").replaceWith(s);var i=t.querySelectorAll(".ui-select-choices");if(i.removeAttr("ui-select-choices"),1!==i.length)throw c("transcluded","Expected 1 .ui-select-choices but got '{0}'.",i.length);l.querySelectorAll(".ui-select-choices").replaceWith(i)})}}}]).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,r,n,o){var a=r.groupBy;if(n.parseRepeatAttr(r.repeat,a),a){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(n.parserResult.itemName,"$select.items",n.parserResult.trackByExp,a)).attr("ng-mouseenter","$select.setActiveItem("+n.parserResult.itemName+")").attr("ng-click","$select.select("+n.parserResult.itemName+")"),o(function(e){var t=i.querySelectorAll(".ui-select-choices-row-inner");if(1!==t.length)throw c("rows","Expected 1 .ui-select-choices-row-inner but got '{0}'.",t.length);t.append(e),s(i)(l)}),l.$watch("$select.search",function(){n.activeIndex=0,n.refresh(r.refresh)}),r.$observe("refreshDelay",function(){var t=l.$eval(r.refreshDelay);n.refreshDelay=void 0!==t?t:e.refreshDelay})}}}}]).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;return c+"/match.tpl.html"},link:function(t,c,s,l){s.$observe("placeholder",function(t){l.placeholder=void 0!==t?t:e.placeholder})}}}]).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.tpl.html",''),e.put("bootstrap/select.tpl.html",''),e.put("select2/choices.tpl.html",'
  • {{$group}}
'),e.put("select2/match.tpl.html",'{{$select.placeholder}} '),e.put("select2/select.tpl.html",'
'),e.put("selectize/choices.tpl.html",'
{{$group}}
'),e.put("selectize/match.tpl.html",'
'),e.put("selectize/select.tpl.html",'
')}]); \ No newline at end of file diff --git a/package.json b/package.json index bf5dc62ab..9d20cba2c 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "repository": { "url": "git://github.com/angular-ui/ui-select.git" }, - "version": "0.5.0", + "version": "0.5.1", "devDependencies": { "bower": "~1.3", "del": "~0.1.1", diff --git a/src/select.js b/src/select.js index fd0102da0..a718101a7 100644 --- a/src/select.js +++ b/src/select.js @@ -64,7 +64,7 @@ return { itemName: match[2], // (lhs) Left-hand side, - source: match[3], // (rhs) Right-hand side, + source: $parse(match[3]), trackByExp: match[4], modelMapper: $parse(match[1] || match[2]) }; @@ -350,8 +350,7 @@ //From model --> view ngModel.$formatters.unshift(function (inputValue) { - var match = $select.parserResult.source.match(/^\s*([\S]+).*$/); - var data = scope[match[1]]; + var data = $select.parserResult.source(scope); if (data){ for (var i = data.length - 1; i >= 0; i--) { var locals = {};