diff --git a/bower.json b/bower.json index a74ef49..ed32df1 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "nya-bootstrap-select", - "version": "2.0.5", + "version": "2.0.6", "main": [ "dist/js/nya-bs-select.js", "dist/css/nya-bs-select.css" diff --git a/dist/css/nya-bs-select.css b/dist/css/nya-bs-select.css index b9eb024..8736de9 100644 --- a/dist/css/nya-bs-select.css +++ b/dist/css/nya-bs-select.css @@ -1,5 +1,5 @@ /** - * nya-bootstrap-select v2.0.5 + * nya-bootstrap-select v2.0.6 * Copyright 2014 Nyasoft * Licensed under MIT license */ diff --git a/dist/css/nya-bs-select.min.css b/dist/css/nya-bs-select.min.css index 945ec92..f9efa16 100644 --- a/dist/css/nya-bs-select.min.css +++ b/dist/css/nya-bs-select.min.css @@ -1,5 +1,5 @@ /** - * nya-bootstrap-select v2.0.5 + * nya-bootstrap-select v2.0.6 * Copyright 2014 Nyasoft * Licensed under MIT license */ diff --git a/dist/js/nya-bs-select.js b/dist/js/nya-bs-select.js index 7468a93..fa70484 100644 --- a/dist/js/nya-bs-select.js +++ b/dist/js/nya-bs-select.js @@ -1,5 +1,5 @@ /** - * nya-bootstrap-select v2.0.5 + * nya-bootstrap-select v2.0.6 * Copyright 2014 Nyasoft * Licensed under MIT license */ @@ -315,6 +315,8 @@ var deepEquals = angular.equals; var deepCopy = angular.copy; +var extend = angular.extend; + var nyaBsSelect = angular.module('nya.bootstrap.select', []); @@ -338,7 +340,7 @@ nyaBsSelect.controller('nyaBsSelectCtrl', function(){ }; }); -nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', function ($parse, $document, $timeout) { +nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', 'nyaBsConfig', function ($parse, $document, $timeout, nyaBsConfig) { var DEFAULT_NONE_SELECTION = 'Nothing selected'; @@ -364,8 +366,32 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', functio controller: 'nyaBsSelectCtrl', compile: function nyaBsSelectCompile (tElement, tAttrs){ + tElement.addClass('btn-group'); + var getDefaultNoneSelectionContent = function() { + // text node or jqLite element. + var content; + + if(tAttrs.titleTpl) { + // use title-tpl attribute value. + content = jqLite(tAttrs.titleTpl); + } else if(tAttrs.title) { + // use title attribute value. + content = document.createTextNode(tAttrs.title); + } else if(localizedText.defaultNoneSelectionTpl){ + // use localized text template. + content = jqLite(localizedText.defaultNoneSelectionTpl); + } else if(localizedText.defaultNoneSelection) { + // use localized text. + content = document.createTextNode(localizedText.defaultNoneSelection); + } else { + // use default. + content = document.createTextNode(DEFAULT_NONE_SELECTION); + } + return content; + }; + var options = tElement.children(), dropdownToggle = jqLite(DROPDOWN_TOGGLE), dropdownContainer = jqLite(DROPDOWN_CONTAINER), @@ -375,7 +401,8 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', functio classList, length, index, - liElement; + liElement, + localizedText = nyaBsConfig; classList = getClassList(tElement[0]); classList.forEach(function(className) { @@ -409,17 +436,21 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', functio if(tAttrs.liveSearch === 'true') { searchBox = jqLite(SEARCH_BOX); + + // set localized text + if(localizedText.noSearchResultTpl) { + NO_SEARCH_RESULT = NO_SEARCH_RESULT.replace('NO SEARCH RESULT', localizedText.noSearchResultTpl); + } else if(localizedText.noSearchResult) { + NO_SEARCH_RESULT = NO_SEARCH_RESULT.replace('NO SEARCH RESULT', localizedText.noSearchResult); + } + noSearchResult = jqLite(NO_SEARCH_RESULT); dropdownContainer.append(searchBox); dropdownMenu.append(noSearchResult); } // set default none selection text - if(tAttrs.title) { - dropdownToggle.children().eq(0).text(tAttrs.title); - } else { - dropdownToggle.children().eq(0).text(DEFAULT_NONE_SELECTION); - } + dropdownToggle.children().eq(0).append(getDefaultNoneSelectionContent()); dropdownContainer.append(dropdownMenu); @@ -1013,15 +1044,8 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', functio return; } if(isMultiple && modelValue.length === 0) { - if($attrs.title) { - // use title attribute value. - filterOption.empty(); - filterOption.append(document.createTextNode($attrs.title)); - } else { - // use default text. - filterOption.empty(); - filterOption.append(document.createTextNode(DEFAULT_NONE_SELECTION)); - } + filterOption.empty(); + filterOption.append(getDefaultNoneSelectionContent()); } else { $timeout(function() { @@ -1044,7 +1068,13 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', functio // data-selected-text-format="count" or data-selected-text-format="count>x" if((typeof count !== 'undefined') && modelValue.length > count) { filterOption.empty(); - filterOption.append(document.createTextNode(modelValue.length + ' items selected')); + if(localizedText.numberItemSelectedTpl) { + filterOption.append(jqLite(localizedText.numberItemSelectedTpl.replace('%d', modelValue.length))); + } else if(localizedText.numberItemSelected) { + filterOption.append(document.createTextNode(localizedText.numberItemSelected.replace('%d', modelValue.length))); + } else { + filterOption.append(document.createTextNode(modelValue.length + ' items selected')); + } return; } @@ -1082,15 +1112,8 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', functio } if(selection.length === 0) { - if($attrs.title) { - // use title attribute value. - filterOption.empty(); - filterOption.append(document.createTextNode($attrs.title)); - } else { - // use default text. - filterOption.empty(); - filterOption.append(document.createTextNode(DEFAULT_NONE_SELECTION)); - } + filterOption.empty(); + filterOption.append(getDefaultNoneSelectionContent()); } else if(selection.length === 1) { // either single or multiple selection will show the only selected content. filterOption.empty(); diff --git a/dist/js/nya-bs-select.min.js b/dist/js/nya-bs-select.min.js index e55282c..d252899 100644 --- a/dist/js/nya-bs-select.min.js +++ b/dist/js/nya-bs-select.min.js @@ -1,6 +1,6 @@ /** - * nya-bootstrap-select v2.0.5 + * nya-bootstrap-select v2.0.6 * Copyright 2014 Nyasoft * Licensed under MIT license */ -!function(){"use strict";function a(){return++j}function b(a){return a&&a.window===a}function c(a){return"string"==typeof a}function d(a){if(null==a||b(a))return!1;var d=a.length;return 1===a.nodeType&&d?!0:c(a)||Array.isArray(a)||0===d||"number"==typeof d&&d>0&&d-1 in a}function e(){return Object.create(null)}function f(b,c){var d,e=typeof b;return"function"==e||"object"==e&&null!==b?"function"==typeof(d=b.$$hashKey)?d=b.$$hashKey():void 0===d&&(d=b.$$hashKey=(c||a)()):d=b,e+":"+d}function g(a,b,c){var d,e,f=[],g=[];for(d=0;dc;c++)if(v(b,a[c]))return!0;return!1},o=function(a,b){var c,d=a.length;if(0===d)return-1;for(c=0;d>c;c++)if(v(b,a[c]))return c;return-1},p=function(a,b,c){var d,e=a,f=typeof c;if(a==b)return null;do if("string"===f){if(d=" "+e.className+" ",1===e.nodeType&&d.replace(/[\t\r\n\f]/g," ").indexOf(c)>=0)return e}else if(e==c)return e;while((e=e.parentNode)&&e!=b&&9!==e.nodeType);return null},q=function(a){var b,c=a.className.replace(/[\t\r\n\f]/g," ").trim();b=c.split(" ");for(var d=0;d0)for(var h=0;g>h;h++){if(c=f.eq(h),d=!0,e=q(c[0]),e.length>0)for(var i=0;id;d++)if(-1!==c.eq(d).text().toLowerCase().indexOf(b.toLowerCase()))return!0;return!1},u=angular.element,v=angular.equals,w=angular.copy,x=angular.module("nya.bootstrap.select",[]);x.controller("nyaBsSelectCtrl",function(){var a=this;a.keyIdentifier=null,a.valueIdentifier=null,a.isMultiple=!1,a.onCollectionChange=function(){},a.setId=function(b){a.id=b||"id#"+Math.floor(1e4*Math.random())}}),x.directive("nyaBsSelect",["$parse","$document","$timeout",function(a,b,c){var d="Nothing selected",e='',f='',g='',h='',j='
  • NO SEARCH RESULT
  • ';return{restrict:"ECA",require:["ngModel","nyaBsSelect"],controller:"nyaBsSelectCtrl",compile:function(k,l){console.log(k.attr("id")+" compiled"),k.addClass("btn-group");var m,x,y,z,A,B,C=k.children(),D=u(e),E=u(f),F=u(h);for(y=q(k[0]),y.forEach(function(a){/btn-(?:primary|info|success|warning|danger|inverse)/.test(a)&&(k.removeClass(a),D.removeClass("btn-default"),D.addClass(a)),"form-control"===a&&D.addClass(a)}),F.append(C),z=C.length,A=0;z>A;A++)B=C.eq(A),(B.hasClass("nya-bs-option")||B.attr("nya-bs-option"))&&B.find("a").attr("tabindex","0");return"true"===l.liveSearch&&(m=u(g),x=u(j),E.append(m),F.append(x)),D.children().eq(0).text(l.title?l.title:d),E.append(F),k.append(D),k.append(E),function(e,f,g,h){function j(){var a,b,c=L.children(),d=c.length;for(a=0;d>a;a++)if(b=c.eq(a),b.hasClass("active")&&b.hasClass("nya-bs-option"))return b;return null}function k(a){for(var b,c=a.childNodes,d=c.length,e=0;d>e;e++)if(b=c[e],1===b.nodeType&&"a"===b.tagName.toLowerCase()){b.focus();break}}function l(a){var b;return b=L.children().eq(a?0:L.children().length-1),!b.hasClass("nya-bs-option")||b.hasClass("disabled")||b.hasClass("not-match")?a?m(b[0],"nextSibling"):m(b[0],"previousSibling"):b[0]}function m(a,b){if(!a||r(a,"nya-bs-option")){for(var c=a;(c=i(c,b))&&c.nodeType;)if(r(c,"nya-bs-option")&&!r(c,"disabled")&&!r(c,"not-match"))return c;return null}}function q(a){var b,c,d,g=E.$modelValue;b=x(a),"undefined"!=typeof b&&(I?(c=Array.isArray(g)?w(g):[],d=o(c,b),-1===d?(c.push(b),a.addClass("selected")):(c.splice(d,1),a.removeClass("selected"))):(L.children().removeClass("selected"),c=b,a.addClass("selected")),E.$setViewValue(c),e.$digest()),I||f.removeClass("open"),z()}function x(a){var b;return D?(b=a.scope(),D(b)):F.valueIdentifier||F.keyIdentifier?(b=a.scope(),b[F.valueIdentifier]||b[F.keyIdentifier]):a.attr("value")}function y(a){var b=a.find("a");return 0===b.children().length||b.children().eq(0).hasClass("check-mark")?b[0].firstChild.cloneNode(!1):b.children().eq(0)[0].cloneNode(!0)}function z(){var a=E.$modelValue,b=J.children().eq(0);a&&(I&&0===a.length?g.title?(b.empty(),b.append(document.createTextNode(g.title))):(b.empty(),b.append(document.createTextNode(d))):c(function(){var c,e,f,h,i,j,k=L.children(),l=k.length,m=[];if(I&&"count"===g.selectedTextFormat?j=1:I&&g.selectedTextFormat&&(i=g.selectedTextFormat.match(/\s*count\s*>\s*(\d+)\s*/))&&(j=parseInt(i[1],10)),"undefined"!=typeof j&&a.length>j)return b.empty(),void b.append(document.createTextNode(a.length+" items selected"));for(f=0;l>f;f++)e=k.eq(f),e.hasClass("nya-bs-option")&&(c=x(e),I?Array.isArray(a)&&n(a,c)&&(h=e.attr("title"),m.push(h?document.createTextNode(h):y(e))):v(a,c)&&(h=e.attr("title"),m.push(h?document.createTextNode(h):y(e))));if(0===m.length)g.title?(b.empty(),b.append(document.createTextNode(g.title))):(b.empty(),b.append(document.createTextNode(d)));else if(1===m.length)b.empty(),b.append(m[0]);else for(b.empty(),f=0;fb;b++)if(a=c.eq(b),a.hasClass("nya-bs-option")||a.attr("nya-bs-option")){B=a[0].clientHeight;break}if(/\d+/.test(g.size)){var e=parseInt(g.size,10);L.css("max-height",e*B+"px"),L.css("overflow-y","auto")}}console.log(f.attr("id")+" linked");var B,C,D,E=h[0],F=h[1],G=!1,H=a(F.valueExp),I="undefined"!=typeof g.multiple,J=s(f,["dropdown-toggle"]),K=J.next(),L=s(K,["dropdown-menu","inner"]),M=s(K,["bs-searchbox"]),N=s(L,["no-search-result"]);F.valueExp&&(D=function(a,b){return H(a,b)}),F.setId(f.attr("id")),I&&(F.isMultiple=!0,E.$isEmpty=function(a){return!a||0===a.length}),"undefined"!=typeof g.disabled&&e.$watch(g.disabled,function(a){a?(J.addClass("disabled"),C=J.attr("tabindex"),J.attr("tabindex","-1"),G=!0):(J.removeClass("disabled"),C?J.attr("tabindex",C):J.removeAttr("tabindex"),G=!1)}),F.onCollectionChange=function(a){var b,c,d=[],f=E.$modelValue;if(f){if(a&&0!==a.length){if(D)for(b=0;ba;a++)b=f.eq(a),b.hasClass("nya-bs-option")&&(t(b.find("a"),d)?(b.removeClass("not-match"),e++):b.addClass("not-match"));0===e?N.addClass("show"):N.removeClass("show")}else{for(a=0;g>a;a++)b=f.eq(a),b.hasClass("nya-bs-option")&&b.removeClass("not-match");N.removeClass("show")}c=l(!0),c&&(f.removeClass("active"),u(c).addClass("active"))}),E.$render=function(){var a,b,c=E.$modelValue,d=L.children(),e=d.length;if("undefined"==typeof c)for(a=0;e>a;a++)d.eq(a).hasClass("nya-bs-option")&&d.eq(a).removeClass("selected");else for(a=0;e>a;a++)d.eq(a).hasClass("nya-bs-option")&&(b=x(d.eq(a)),I?n(c,b)?d.eq(a).addClass("selected"):d.eq(a).removeClass("selected"):v(c,b)?d.eq(a).addClass("selected"):d.eq(a).removeClass("selected"));console.log(F.id+" render end"),z()},f.on("keydown",function(a){var b=a.keyCode;if(27===b||13===b||38===b||40===b){if(a.preventDefault(),G)return void a.stopPropagation();var c,d,e,h,i=p(a.target,f[0],J[0]);"true"===g.liveSearch?d=p(a.target,f[0],M[0]):c=p(a.target,f[0],K[0]),i?(console.log("toggleButton"),13!==b&&38!==b&&40!==b||f.hasClass("open")||(a.stopPropagation(),f.addClass("open"),"undefined"==typeof B&&A(),"true"===g.liveSearch?(M.children().eq(0)[0].focus(),h=l(!0),h&&(L.children().removeClass("active"),u(h).addClass("active"))):(h=l(!0),h&&k(h)))):c?27===b?(J[0].focus(),f.removeClass("open"),a.stopPropagation()):38===b?(a.stopPropagation(),h=m(a.target.parentNode,"previousSibling"),h?k(h):(h=l(!1),h&&k(h))):40===b?(a.stopPropagation(),h=m(a.target.parentNode,"nextSibling"),h?k(h):(h=l(!0),h&&k(h))):13===b&&(a.stopPropagation(),e=u(a.target.parentNode),e.hasClass("nya-bs-option")&&(q(e),I||J[0].focus())):d&&(27===b?(J[0].focus(),f.removeClass("open"),a.stopPropagation()):38===b?(a.stopPropagation(),e=j(),e&&(h=m(e[0],"previousSibling"),h?(e.removeClass("active"),u(h).addClass("active")):(h=l(!1),h&&(e.removeClass("active"),u(h).addClass("active"))))):40===b?(a.stopPropagation(),e=j(),e&&(h=m(e[0],"nextSibling"),h?(e.removeClass("active"),u(h).addClass("active")):(h=l(!0),h&&(e.removeClass("active"),u(h).addClass("active"))))):13===b&&(e=j(),e&&(q(e),I||J[0].focus())))}})}}}}]),x.directive("nyaBsOption",["$parse",function(a){var b=/^\s*(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+group\s+by\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/;return{restrict:"A",transclude:"element",priority:1e3,terminal:!0,require:["^nyaBsSelect","^ngModel"],compile:function(c,i){var j=i.nyaBsOption,o=document.createComment(" end nyaBsOption: "+j+" "),p=j.match(b);if(!p)throw new Error("invalid expression");var q,r,s,t,w,x=i.value,y=x?a(x):null,z=p[3]||p[1],A=p[2],B=p[4],C=p[5]?a(p[5]):null,D=p[6],E={$id:f},F={};return D?t=a(D):(q=function(a,b){return f(b)},r=function(a){return a}),function(a,b,c,f,i){function j(a){var c,f,j,t,x,y,B,C,E,F,H,J,K,L,M=b[0],N=e(),O=[];if(w&&(J=[]),d(a))y=a,x=s||q;else{x=s||r,y=[];for(var P in a)a.hasOwnProperty(P)&&"$"!=P.charAt(0)&&y.push(P);y.sort()}for(B=y.length,C=new Array(B),c=0;B>c;c++)if(f=a===y?c:y[c],j=a[f],t=x(f,j,c),L={},A&&(L[A]=f),L[z]=j,O.push(L),w&&(F=w(f,j),-1===J.indexOf(F)&&F&&J.push(F)),I[t])E=I[t],delete I[t],w&&(E.group=F),E.key=f,E.value=j,N[t]=E,C[c]=E;else{if(N[t])throw C.forEach(function(a){a&&a.scope&&(I[a.id]=a)}),new Error("Duplicates in a select are not allowed. Use 'track by' expression to specify unique keys.");C[c]={id:t,scope:void 0,clone:void 0,key:f,value:j},N[t]=!0,F&&(C[c].group=F)}J&&J.length>0&&(C=g(C,J,"group"));for(var Q in I)E=I[Q],h(E.clone).remove(),E.scope.$destroy();for(c=0;B>c;c++)E=C[c],E.scope?(H=M,k(E)!=H&&u(M).after(E.clone),M=l(E),m(E.scope,c,z,E.value,A,E.key,B,E.group)):i(function(a,b){E.scope=b;var d=o.cloneNode(!1);a[a.length++]=d,u(M).after(a),a.addClass("nya-bs-option"),j=p?p(E.key,E.value):E.value||E.key,D.isMultiple?Array.isArray(G.$modelValue)&&n(G.$modelValue,j)&&a.addClass("selected"):v(j,G.$modelValue)&&a.addClass("selected"),M=d,E.clone=a,N[E.id]=E,m(E.scope,c,z,E.value,A,E.key,B,E.group)}),J&&(K&&K===E.group?E.clone.removeClass("first-in-group"):E.clone.addClass("first-in-group"),K=E.group,E.clone.addClass("group-item"));I=N,D.onCollectionChange(O)}var p,D=f[0],G=f[1],H={};t&&(s=function(b,c,d){return A&&(E[A]=b),E[z]=c,E.$index=d,t(a,E)}),C&&(w=function(b,c){return A&&(F[A]=b),F[z]=c,C(a,F)}),A&&(D.keyIdentifier=A),z&&(D.valueIdentifier=z),y&&(D.valueExp=x,p=function(b,c){return A&&(H[A]=b),H[z]=c,y(a,H)});var I=e();"true"===c.deepWatch?a.$watch(B,j,!0):a.$watchCollection(B,j)}}}}])}(); \ No newline at end of file +!function(){"use strict";function a(){return++j}function b(a){return a&&a.window===a}function c(a){return"string"==typeof a}function d(a){if(null==a||b(a))return!1;var d=a.length;return 1===a.nodeType&&d?!0:c(a)||Array.isArray(a)||0===d||"number"==typeof d&&d>0&&d-1 in a}function e(){return Object.create(null)}function f(b,c){var d,e=typeof b;return"function"==e||"object"==e&&null!==b?"function"==typeof(d=b.$$hashKey)?d=b.$$hashKey():void 0===d&&(d=b.$$hashKey=(c||a)()):d=b,e+":"+d}function g(a,b,c){var d,e,f=[],g=[];for(d=0;dc;c++)if(v(b,a[c]))return!0;return!1},o=function(a,b){var c,d=a.length;if(0===d)return-1;for(c=0;d>c;c++)if(v(b,a[c]))return c;return-1},p=function(a,b,c){var d,e=a,f=typeof c;if(a==b)return null;do if("string"===f){if(d=" "+e.className+" ",1===e.nodeType&&d.replace(/[\t\r\n\f]/g," ").indexOf(c)>=0)return e}else if(e==c)return e;while((e=e.parentNode)&&e!=b&&9!==e.nodeType);return null},q=function(a){var b,c=a.className.replace(/[\t\r\n\f]/g," ").trim();b=c.split(" ");for(var d=0;d0)for(var h=0;g>h;h++){if(c=f.eq(h),d=!0,e=q(c[0]),e.length>0)for(var i=0;id;d++)if(-1!==c.eq(d).text().toLowerCase().indexOf(b.toLowerCase()))return!0;return!1},u=angular.element,v=angular.equals,w=angular.copy,x=(angular.extend,angular.module("nya.bootstrap.select",[]));x.controller("nyaBsSelectCtrl",function(){var a=this;a.keyIdentifier=null,a.valueIdentifier=null,a.isMultiple=!1,a.onCollectionChange=function(){},a.setId=function(b){a.id=b||"id#"+Math.floor(1e4*Math.random())}}),x.directive("nyaBsSelect",["$parse","$document","$timeout","nyaBsConfig",function(a,b,c,d){var e="Nothing selected",f='',g='',h='',j='',k='
  • NO SEARCH RESULT
  • ';return{restrict:"ECA",require:["ngModel","nyaBsSelect"],controller:"nyaBsSelectCtrl",compile:function(l,m){console.log(l.attr("id")+" compiled"),l.addClass("btn-group");var x,y,z,A,B,C,D=function(){var a;return a=m.titleTpl?u(m.titleTpl):m.title?document.createTextNode(m.title):I.defaultNoneSelectionTpl?u(I.defaultNoneSelectionTpl):document.createTextNode(I.defaultNoneSelection?I.defaultNoneSelection:e)},E=l.children(),F=u(f),G=u(g),H=u(j),I=d;for(z=q(l[0]),z.forEach(function(a){/btn-(?:primary|info|success|warning|danger|inverse)/.test(a)&&(l.removeClass(a),F.removeClass("btn-default"),F.addClass(a)),"form-control"===a&&F.addClass(a)}),H.append(E),A=E.length,B=0;A>B;B++)C=E.eq(B),(C.hasClass("nya-bs-option")||C.attr("nya-bs-option"))&&C.find("a").attr("tabindex","0");return"true"===m.liveSearch&&(x=u(h),I.noSearchResultTpl?k=k.replace("NO SEARCH RESULT",I.noSearchResultTpl):I.noSearchResult&&(k=k.replace("NO SEARCH RESULT",I.noSearchResult)),y=u(k),G.append(x),H.append(y)),F.children().eq(0).append(D()),G.append(H),l.append(F),l.append(G),function(d,e,f,g){function h(){var a,b,c=M.children(),d=c.length;for(a=0;d>a;a++)if(b=c.eq(a),b.hasClass("active")&&b.hasClass("nya-bs-option"))return b;return null}function j(a){for(var b,c=a.childNodes,d=c.length,e=0;d>e;e++)if(b=c[e],1===b.nodeType&&"a"===b.tagName.toLowerCase()){b.focus();break}}function k(a){var b;return b=M.children().eq(a?0:M.children().length-1),!b.hasClass("nya-bs-option")||b.hasClass("disabled")||b.hasClass("not-match")?a?l(b[0],"nextSibling"):l(b[0],"previousSibling"):b[0]}function l(a,b){if(!a||r(a,"nya-bs-option")){for(var c=a;(c=i(c,b))&&c.nodeType;)if(r(c,"nya-bs-option")&&!r(c,"disabled")&&!r(c,"not-match"))return c;return null}}function m(a){var b,c,f,g=E.$modelValue;b=q(a),"undefined"!=typeof b&&(J?(c=Array.isArray(g)?w(g):[],f=o(c,b),-1===f?(c.push(b),a.addClass("selected")):(c.splice(f,1),a.removeClass("selected"))):(M.children().removeClass("selected"),c=b,a.addClass("selected")),E.$setViewValue(c),d.$digest()),J||e.removeClass("open"),y()}function q(a){var b;return C?(b=a.scope(),C(b)):F.valueIdentifier||F.keyIdentifier?(b=a.scope(),b[F.valueIdentifier]||b[F.keyIdentifier]):a.attr("value")}function x(a){var b=a.find("a");return 0===b.children().length||b.children().eq(0).hasClass("check-mark")?b[0].firstChild.cloneNode(!1):b.children().eq(0)[0].cloneNode(!0)}function y(){var a=E.$modelValue,b=K.children().eq(0);a&&(J&&0===a.length?(b.empty(),b.append(D())):c(function(){var c,d,e,g,h,i,j=M.children(),k=j.length,l=[];if(J&&"count"===f.selectedTextFormat?i=1:J&&f.selectedTextFormat&&(h=f.selectedTextFormat.match(/\s*count\s*>\s*(\d+)\s*/))&&(i=parseInt(h[1],10)),"undefined"!=typeof i&&a.length>i)return b.empty(),void b.append(I.numberItemSelectedTpl?u(I.numberItemSelectedTpl.replace("%d",a.length)):I.numberItemSelected?document.createTextNode(I.numberItemSelected.replace("%d",a.length)):document.createTextNode(a.length+" items selected"));for(e=0;k>e;e++)d=j.eq(e),d.hasClass("nya-bs-option")&&(c=q(d),J?Array.isArray(a)&&n(a,c)&&(g=d.attr("title"),l.push(g?document.createTextNode(g):x(d))):v(a,c)&&(g=d.attr("title"),l.push(g?document.createTextNode(g):x(d))));if(0===l.length)b.empty(),b.append(D());else if(1===l.length)b.empty(),b.append(l[0]);else for(b.empty(),e=0;eb;b++)if(a=c.eq(b),a.hasClass("nya-bs-option")||a.attr("nya-bs-option")){A=a[0].clientHeight;break}if(/\d+/.test(f.size)){var e=parseInt(f.size,10);M.css("max-height",e*A+"px"),M.css("overflow-y","auto")}}console.log(e.attr("id")+" linked");var A,B,C,E=g[0],F=g[1],G=!1,H=a(F.valueExp),J="undefined"!=typeof f.multiple,K=s(e,["dropdown-toggle"]),L=K.next(),M=s(L,["dropdown-menu","inner"]),N=s(L,["bs-searchbox"]),O=s(M,["no-search-result"]);F.valueExp&&(C=function(a,b){return H(a,b)}),F.setId(e.attr("id")),J&&(F.isMultiple=!0,E.$isEmpty=function(a){return!a||0===a.length}),"undefined"!=typeof f.disabled&&d.$watch(f.disabled,function(a){a?(K.addClass("disabled"),B=K.attr("tabindex"),K.attr("tabindex","-1"),G=!0):(K.removeClass("disabled"),B?K.attr("tabindex",B):K.removeAttr("tabindex"),G=!1)}),F.onCollectionChange=function(a){var b,c,e=[],f=E.$modelValue;if(f){if(a&&0!==a.length){if(C)for(b=0;ba;a++)b=f.eq(a),b.hasClass("nya-bs-option")&&(t(b.find("a"),d)?(b.removeClass("not-match"),e++):b.addClass("not-match"));0===e?O.addClass("show"):O.removeClass("show")}else{for(a=0;g>a;a++)b=f.eq(a),b.hasClass("nya-bs-option")&&b.removeClass("not-match");O.removeClass("show")}c=k(!0),c&&(f.removeClass("active"),u(c).addClass("active"))}),E.$render=function(){var a,b,c=E.$modelValue,d=M.children(),e=d.length;if("undefined"==typeof c)for(a=0;e>a;a++)d.eq(a).hasClass("nya-bs-option")&&d.eq(a).removeClass("selected");else for(a=0;e>a;a++)d.eq(a).hasClass("nya-bs-option")&&(b=q(d.eq(a)),J?n(c,b)?d.eq(a).addClass("selected"):d.eq(a).removeClass("selected"):v(c,b)?d.eq(a).addClass("selected"):d.eq(a).removeClass("selected"));console.log(F.id+" render end"),y()},e.on("keydown",function(a){var b=a.keyCode;if(27===b||13===b||38===b||40===b){if(a.preventDefault(),G)return void a.stopPropagation();var c,d,g,i,n=p(a.target,e[0],K[0]);"true"===f.liveSearch?d=p(a.target,e[0],N[0]):c=p(a.target,e[0],L[0]),n?(console.log("toggleButton"),13!==b&&38!==b&&40!==b||e.hasClass("open")||(a.stopPropagation(),e.addClass("open"),"undefined"==typeof A&&z(),"true"===f.liveSearch?(N.children().eq(0)[0].focus(),i=k(!0),i&&(M.children().removeClass("active"),u(i).addClass("active"))):(i=k(!0),i&&j(i)))):c?27===b?(K[0].focus(),e.removeClass("open"),a.stopPropagation()):38===b?(a.stopPropagation(),i=l(a.target.parentNode,"previousSibling"),i?j(i):(i=k(!1),i&&j(i))):40===b?(a.stopPropagation(),i=l(a.target.parentNode,"nextSibling"),i?j(i):(i=k(!0),i&&j(i))):13===b&&(a.stopPropagation(),g=u(a.target.parentNode),g.hasClass("nya-bs-option")&&(m(g),J||K[0].focus())):d&&(27===b?(K[0].focus(),e.removeClass("open"),a.stopPropagation()):38===b?(a.stopPropagation(),g=h(),g&&(i=l(g[0],"previousSibling"),i?(g.removeClass("active"),u(i).addClass("active")):(i=k(!1),i&&(g.removeClass("active"),u(i).addClass("active"))))):40===b?(a.stopPropagation(),g=h(),g&&(i=l(g[0],"nextSibling"),i?(g.removeClass("active"),u(i).addClass("active")):(i=k(!0),i&&(g.removeClass("active"),u(i).addClass("active"))))):13===b&&(g=h(),g&&(m(g),J||K[0].focus())))}})}}}}]),x.directive("nyaBsOption",["$parse",function(a){var b=/^\s*(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+group\s+by\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/;return{restrict:"A",transclude:"element",priority:1e3,terminal:!0,require:["^nyaBsSelect","^ngModel"],compile:function(c,i){var j=i.nyaBsOption,o=document.createComment(" end nyaBsOption: "+j+" "),p=j.match(b);if(!p)throw new Error("invalid expression");var q,r,s,t,w,x=i.value,y=x?a(x):null,z=p[3]||p[1],A=p[2],B=p[4],C=p[5]?a(p[5]):null,D=p[6],E={$id:f},F={};return D?t=a(D):(q=function(a,b){return f(b)},r=function(a){return a}),function(a,b,c,f,i){function j(a){var c,f,j,t,x,y,B,C,E,F,H,J,K,L,M=b[0],N=e(),O=[];if(w&&(J=[]),d(a))y=a,x=s||q;else{x=s||r,y=[];for(var P in a)a.hasOwnProperty(P)&&"$"!=P.charAt(0)&&y.push(P);y.sort()}for(B=y.length,C=new Array(B),c=0;B>c;c++)if(f=a===y?c:y[c],j=a[f],t=x(f,j,c),L={},A&&(L[A]=f),L[z]=j,O.push(L),w&&(F=w(f,j),-1===J.indexOf(F)&&F&&J.push(F)),I[t])E=I[t],delete I[t],w&&(E.group=F),E.key=f,E.value=j,N[t]=E,C[c]=E;else{if(N[t])throw C.forEach(function(a){a&&a.scope&&(I[a.id]=a)}),new Error("Duplicates in a select are not allowed. Use 'track by' expression to specify unique keys.");C[c]={id:t,scope:void 0,clone:void 0,key:f,value:j},N[t]=!0,F&&(C[c].group=F)}J&&J.length>0&&(C=g(C,J,"group"));for(var Q in I)E=I[Q],h(E.clone).remove(),E.scope.$destroy();for(c=0;B>c;c++)E=C[c],E.scope?(H=M,k(E)!=H&&u(M).after(E.clone),M=l(E),m(E.scope,c,z,E.value,A,E.key,B,E.group)):i(function(a,b){E.scope=b;var d=o.cloneNode(!1);a[a.length++]=d,u(M).after(a),a.addClass("nya-bs-option"),j=p?p(E.key,E.value):E.value||E.key,D.isMultiple?Array.isArray(G.$modelValue)&&n(G.$modelValue,j)&&a.addClass("selected"):v(j,G.$modelValue)&&a.addClass("selected"),M=d,E.clone=a,N[E.id]=E,m(E.scope,c,z,E.value,A,E.key,B,E.group)}),J&&(K&&K===E.group?E.clone.removeClass("first-in-group"):E.clone.addClass("first-in-group"),K=E.group,E.clone.addClass("group-item"));I=N,D.onCollectionChange(O)}var p,D=f[0],G=f[1],H={};t&&(s=function(b,c,d){return A&&(E[A]=b),E[z]=c,E.$index=d,t(a,E)}),C&&(w=function(b,c){return A&&(F[A]=b),F[z]=c,C(a,F)}),A&&(D.keyIdentifier=A),z&&(D.valueIdentifier=z),y&&(D.valueExp=x,p=function(b,c){return A&&(H[A]=b),H[z]=c,y(a,H)});var I=e();"true"===c.deepWatch?a.$watch(B,j,!0):a.$watchCollection(B,j)}}}}])}(); \ No newline at end of file diff --git a/docs/dist/js/app.js b/docs/dist/js/app.js index 7f9a140..c570140 100644 --- a/docs/dist/js/app.js +++ b/docs/dist/js/app.js @@ -52,9 +52,13 @@ angular.module('controllers', []) .controller('ApiCtrl', function($scope, pages){ $scope.articles = []; angular.forEach(pages, function(stateName){ + var words = stateName.split('-'); + var title = words.map(function(word, index) { + return index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1); + }).join(''); $scope.articles.push({ state: stateName, - title: stateName + title: title }); }); }); @@ -144,7 +148,8 @@ angular.module('docApp', ['ui.router', 'nya.bootstrap.select', 'directives', 'fi ], api: [ 'nya-bs-select', - 'nya-bs-option' + 'nya-bs-option', + 'nya-bs-config-provider' ] }; diff --git a/docs/src/content/api/nya-bs-config-provider.md b/docs/src/content/api/nya-bs-config-provider.md new file mode 100644 index 0000000..3b25a94 --- /dev/null +++ b/docs/src/content/api/nya-bs-config-provider.md @@ -0,0 +1,64 @@ +#nyaBsConfigProvider + +This provider help the developer configure the default text appearance of nya-bs-select base on user-agent localization. Default implementation of the locale text is `en-us`. + +There are three default text can be configured. Each one has two form, pure text and custom html template. The priority of template configuration is higher than pure text. + + + + + + + + + + + + + + + + + + + + + + + + + + +
    TextTemplateDetails
    defaultNoneSelectiondefaultNoneSelectionTpldefaultNoneSelection is appeared on dropdown toggle when nothing is selected.
    noSearchResultnoSearchResultTplnoSearchResult is appeared on dropdown menu when using live search and nothing match the filter text
    numberItemSelectednumberItemSelectedTpl +

    numberItemSelected is appeared when select-text-format attribute is set to count or count>x and when user selected multiple items. dropdown button text will be replaced by this text.

    + +

    **To show a count of selected items. this text string or template should contains a `%d` which will be replaced with number**

    +
    + +>NOTE: You shouldn't use any angular directive or expression in template, it will not be parsed. + +###Methods + +####`setLocalizedText(localeId, configObj);` + +Register a new locale configuration or override an existing locale configuration. + +- `localeId` a string formatted as languageId-countryId, e.g. en-us +- `configObj` a localized configuration object. should contain one of the three properties. + +```javascript +{ + defaultNoneSelection: 'Nothing selected', + noSearchResult: 'NO SEARCH RESULT', + numberItemSelected: '%d item selected' +} +``` + +####`useLocale(localeId);` + +Force to use a special locale configuration with given localeId. + +- `localeId` a string formatted as languageId-countryId, e.g. en-us + + + diff --git a/docs/src/content/api/nya-bs-option.md b/docs/src/content/api/nya-bs-option.md index 1ef26bc..8d098ab 100644 --- a/docs/src/content/api/nya-bs-option.md +++ b/docs/src/content/api/nya-bs-option.md @@ -1,9 +1,9 @@ -#nya-bs-option +#nyaBsOption The main function of this directive is manipulating an option list base on given collection. its expression is very similar as `ng-repeat` but add a little magic to support the special scenario of select component. -The `nya-bs-option` instantiates a template once per item from a collection. Each template instance gets its own scope, +The `nyaBsOption` instantiates a template once per item from a collection. Each template instance gets its own scope, where the given loop variable is set to the current collection item, and `$index` is set to the item index or key. If `group by` expression is provided. the generated options list will resorted by the result of the expression, and `$group` is set to each template scope. @@ -61,7 +61,7 @@ the generated options list will resorted by the result of the expression, and `$ ###Special class generated on each element. -When using `group by` expression, the `nya-bs-option` will generate a class `group-item` on each repeated element. +When using `group by` expression, the `nyaBsOption` will generate a class `group-item` on each repeated element. To identify the first element of each group. It will also add a class `first-in-group` on the first element of a group. Theses class has some special styles to build the group header. @@ -163,9 +163,9 @@ as attribute: deep-watch string - When set to true, enable a deep watch to collection_expression. `nya-bs-option` will use $watch(exp, listener, true) to make a deep watch. Turn on this feature will impact the performance. even cause expection. + When set to true, enable a deep watch to collection_expression. `nyaBsOption` will use $watch(exp, listener, true) to make a deep watch. Turn on this feature will impact the performance. even cause expection. It is not recommended. - By default. `nya-bs-option` will use $watchCollection to watch the collection_expression. + By default. `nyaBsOption` will use $watchCollection to watch the collection_expression. diff --git a/docs/src/content/api/nya-bs-select.md b/docs/src/content/api/nya-bs-select.md index e47eecb..f1f7afe 100644 --- a/docs/src/content/api/nya-bs-select.md +++ b/docs/src/content/api/nya-bs-select.md @@ -1,6 +1,6 @@ -#nya-bs-select +#nyaBsSelect -nya-bs-select is the main directive of this module. You can consider it as a select directive. It manipulates the the dropdown-toggle content and all user interaction. +nyaBsSelect is the main directive of this module. You can consider it as a select directive. It manipulates the the dropdown-toggle content and all user interaction. ###Usage diff --git a/package.json b/package.json index d363d7e..6dd1966 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nya-bootstrap-select", - "version": "2.0.5", + "version": "2.0.6", "description": "An angular directive wraps bootstrap-select", "repository": { "type": "git",