angular-chosen-localytics
Advanced tools
Comparing version 1.8.0 to 1.9.0
/** | ||
* angular-chosen-localytics - Angular Chosen directive is an AngularJS Directive that brings the Chosen jQuery in a Angular way | ||
* @version v1.8.0 | ||
* @version v1.9.0 | ||
* @link http://github.com/leocaseiro/angular-chosen | ||
@@ -29,3 +29,3 @@ * @license MIT | ||
chosenModule.directive('chosen', [ | ||
'chosen', '$timeout', function(config, $timeout) { | ||
'chosen', '$timeout', '$parse', function(config, $timeout, $parse) { | ||
var CHOSEN_OPTION_WHITELIST, NG_OPTIONS_REGEXP, isEmpty, snakeCase; | ||
@@ -54,9 +54,14 @@ NG_OPTIONS_REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/; | ||
restrict: 'A', | ||
require: '?ngModel', | ||
require: ['select', '?ngModel'], | ||
priority: 1, | ||
link: function(scope, element, attr, ngModel) { | ||
var chosen, directiveOptions, empty, initOrUpdate, match, options, origRender, startLoading, stopLoading, updateMessage, valuesExpr, viewWatch; | ||
link: function(scope, element, attr, ctrls) { | ||
var $render, chosen, directiveOptions, empty, init, match, ngModel, ngSelect, options, startLoading, stopLoading, trackBy, updateMessage, valuesExpr, viewWatch; | ||
scope.disabledValuesHistory = scope.disabledValuesHistory ? scope.disabledValuesHistory : []; | ||
element = $(element); | ||
element.addClass('localytics-chosen'); | ||
ngSelect = ctrls[0]; | ||
ngModel = ctrls[1]; | ||
match = attr.ngOptions && attr.ngOptions.match(NG_OPTIONS_REGEXP); | ||
valuesExpr = match && $parse(match[7]); | ||
trackBy = match && match[8]; | ||
directiveOptions = scope.$eval(attr.chosen) || {}; | ||
@@ -89,18 +94,6 @@ options = angular.copy(config); | ||
empty = false; | ||
initOrUpdate = function() { | ||
var defaultText, dropListDom; | ||
if (chosen) { | ||
dropListDom = $(element.next('.chosen-with-drop')); | ||
if (dropListDom && dropListDom.length > 0) { | ||
return; | ||
} | ||
return element.trigger('chosen:updated'); | ||
} else { | ||
scope.$evalAsync(function() { | ||
chosen = element.chosen(options).data('chosen'); | ||
}); | ||
if (angular.isObject(chosen)) { | ||
return defaultText = chosen.default_text; | ||
} | ||
} | ||
init = function() { | ||
return scope.$evalAsync(function() { | ||
return chosen = element.chosen(options).data('chosen'); | ||
}); | ||
}; | ||
@@ -115,7 +108,19 @@ updateMessage = function() { | ||
}; | ||
init(); | ||
if (ngModel) { | ||
origRender = ngModel.$render; | ||
$render = ngModel.$render; | ||
ngModel.$render = function() { | ||
origRender(); | ||
return initOrUpdate(); | ||
var isNotPrimitive, nextValue, previousValue, valueChanged; | ||
try { | ||
previousValue = ngSelect.readValue(); | ||
} catch (error) {} | ||
$render(); | ||
try { | ||
nextValue = ngSelect.readValue(); | ||
} catch (error) {} | ||
isNotPrimitive = trackBy || attr.multiple; | ||
valueChanged = isNotPrimitive ? !angular.equals(previousValue, nextValue) : previousValue !== nextValue; | ||
if (valueChanged) { | ||
return element.trigger('chosen:updated'); | ||
} | ||
}; | ||
@@ -133,4 +138,2 @@ element.on('chosen:hiding_dropdown', function() { | ||
} | ||
} else { | ||
initOrUpdate(); | ||
} | ||
@@ -141,4 +144,2 @@ attr.$observe('disabled', function() { | ||
if (attr.ngOptions && ngModel) { | ||
match = attr.ngOptions.match(NG_OPTIONS_REGEXP); | ||
valuesExpr = match[7]; | ||
scope.$watchCollection(valuesExpr, function(newVal, oldVal) { | ||
@@ -145,0 +146,0 @@ var timer; |
/** | ||
* angular-chosen-localytics - Angular Chosen directive is an AngularJS Directive that brings the Chosen jQuery in a Angular way | ||
* @version v1.8.0 | ||
* @version v1.9.0 | ||
* @link http://github.com/leocaseiro/angular-chosen | ||
* @license MIT | ||
*/ | ||
(function(){var e,t=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1};angular.module("localytics.directives",[]),e=angular.module("localytics.directives"),e.provider("chosen",function(){var e;return e={},{setOption:function(t){angular.extend(e,t)},$get:function(){return e}}}),e.directive("chosen",["chosen","$timeout",function(e,n){var r,i,a,s;return i=/^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/,r=["persistentCreateOption","createOptionText","createOption","skipNoResults","noResultsText","allowSingleDeselect","disableSearchThreshold","disableSearch","enableSplitWordSearch","inheritSelectClasses","maxSelectedOptions","placeholderTextMultiple","placeholderTextSingle","searchContains","singleBackstrokeDelete","displayDisabledOptions","displaySelectedOptions","width","includeGroupLabelInSelected","maxShownResults"],s=function(e){return e.replace(/[A-Z]/g,function(e){return"_"+e.toLowerCase()})},a=function(e){var t;if(angular.isArray(e))return 0===e.length;if(angular.isObject(e))for(t in e)if(e.hasOwnProperty(t))return!1;return!0},{restrict:"A",require:"?ngModel",priority:1,link:function(o,l,u,c){var d,f,h,g,p,b,v,y,S,w,O,m;if(o.disabledValuesHistory=o.disabledValuesHistory?o.disabledValuesHistory:[],l=$(l),l.addClass("localytics-chosen"),f=o.$eval(u.chosen)||{},b=angular.copy(e),angular.extend(b,f),angular.forEach(u,function(e,n){if(t.call(r,n)>=0)return u.$observe(n,function(e){var t;return t=String(l.attr(u.$attr[n])).slice(0,2),b[s(n)]="{{"===t?e:o.$eval(e),w()})}),y=function(){return l.addClass("loading").attr("disabled",!0).trigger("chosen:updated")},S=function(){return l.removeClass("loading"),angular.isDefined(u.disabled)?l.attr("disabled",u.disabled):l.attr("disabled",!1),l.trigger("chosen:updated")},d=null,h=!1,g=function(){var e,t;if(d){if(t=$(l.next(".chosen-with-drop")),t&&t.length>0)return;return l.trigger("chosen:updated")}if(o.$evalAsync(function(){d=l.chosen(b).data("chosen")}),angular.isObject(d))return e=d.default_text},w=function(){return d&&h?l.attr("data-placeholder",d.results_none_found).attr("disabled",!0):l.removeAttr("data-placeholder"),l.trigger("chosen:updated")},c?(v=c.$render,c.$render=function(){return v(),g()},l.on("chosen:hiding_dropdown",function(){return o.$apply(function(){return c.$setTouched()})}),u.multiple&&(m=function(){return c.$viewValue},o.$watch(m,c.$render,!0))):g(),u.$observe("disabled",function(){return l.trigger("chosen:updated")}),u.ngOptions&&c)return p=u.ngOptions.match(i),O=p[7],o.$watchCollection(O,function(e,t){var r;return r=n(function(){return angular.isUndefined(e)?y():(h=a(e),S(),w())})}),o.$on("$destroy",function(e){if("undefined"!=typeof timer&&null!==timer)return n.cancel(timer)})}}}])}).call(this); | ||
(function(){var e,t=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1};angular.module("localytics.directives",[]),e=angular.module("localytics.directives"),e.provider("chosen",function(){var e;return e={},{setOption:function(t){angular.extend(e,t)},$get:function(){return e}}}),e.directive("chosen",["chosen","$timeout","$parse",function(e,n,r){var a,i,s,l;return i=/^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/,a=["persistentCreateOption","createOptionText","createOption","skipNoResults","noResultsText","allowSingleDeselect","disableSearchThreshold","disableSearch","enableSplitWordSearch","inheritSelectClasses","maxSelectedOptions","placeholderTextMultiple","placeholderTextSingle","searchContains","singleBackstrokeDelete","displayDisabledOptions","displaySelectedOptions","width","includeGroupLabelInSelected","maxShownResults"],l=function(e){return e.replace(/[A-Z]/g,function(e){return"_"+e.toLowerCase()})},s=function(e){var t;if(angular.isArray(e))return 0===e.length;if(angular.isObject(e))for(t in e)if(e.hasOwnProperty(t))return!1;return!0},{restrict:"A",require:["select","?ngModel"],priority:1,link:function(o,u,c,d){var f,h,p,g,v,b,y,S,w,m,O,x,C,T,V;if(o.disabledValuesHistory=o.disabledValuesHistory?o.disabledValuesHistory:[],u=$(u),u.addClass("localytics-chosen"),S=d[0],y=d[1],b=c.ngOptions&&c.ngOptions.match(i),T=b&&r(b[7]),x=b&&b[8],p=o.$eval(c.chosen)||{},w=angular.copy(e),angular.extend(w,p),angular.forEach(c,function(e,n){if(t.call(a,n)>=0)return c.$observe(n,function(e){var t;return t=String(u.attr(c.$attr[n])).slice(0,2),w[l(n)]="{{"===t?e:o.$eval(e),C()})}),m=function(){return u.addClass("loading").attr("disabled",!0).trigger("chosen:updated")},O=function(){return u.removeClass("loading"),angular.isDefined(c.disabled)?u.attr("disabled",c.disabled):u.attr("disabled",!1),u.trigger("chosen:updated")},h=null,g=!1,v=function(){return o.$evalAsync(function(){return h=u.chosen(w).data("chosen")})},C=function(){return h&&g?u.attr("data-placeholder",h.results_none_found).attr("disabled",!0):u.removeAttr("data-placeholder"),u.trigger("chosen:updated")},v(),y&&(f=y.$render,y.$render=function(){var e,t,n,r;try{n=S.readValue()}catch(a){}f();try{t=S.readValue()}catch(a){}if(e=x||c.multiple,r=e?!angular.equals(n,t):n!==t)return u.trigger("chosen:updated")},u.on("chosen:hiding_dropdown",function(){return o.$apply(function(){return y.$setTouched()})}),c.multiple&&(V=function(){return y.$viewValue},o.$watch(V,y.$render,!0))),c.$observe("disabled",function(){return u.trigger("chosen:updated")}),c.ngOptions&&y)return o.$watchCollection(T,function(e,t){var r;return r=n(function(){return angular.isUndefined(e)?m():(g=s(e),O(),C())})}),o.$on("$destroy",function(e){if("undefined"!=typeof timer&&null!==timer)return n.cancel(timer)})}}}])}).call(this); |
@@ -5,3 +5,3 @@ { | ||
"main": "dist/angular-chosen.js", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "Angular Chosen directive is an AngularJS Directive that brings the Chosen jQuery in a Angular way", | ||
@@ -8,0 +8,0 @@ "homepage": "http://github.com/leocaseiro/angular-chosen", |
Angular Chosen Localytics [![Bower](https://img.shields.io/bower/v/angular-chosen-localytics.svg)](https://github.com/leocaseiro/angular-chosen) [![npm](https://img.shields.io/npm/v/angular-chosen-localytics.svg)](https://www.npmjs.com/package/angular-chosen-localytics) | ||
============== | ||
> *WARNING: It seems since the version 1.4.3 the angular-chosen is not updating the chosen dinamically. If you have this issue, please install the 1.4.2 while I'm still investigating the issue.* | ||
AngularJS Chosen directive | ||
@@ -33,3 +31,3 @@ | ||
```html | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chosen-localytics/1.7.0/angular-chosen.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chosen-localytics/1.9.0/angular-chosen.min.js"></script> | ||
``` | ||
@@ -40,3 +38,3 @@ | ||
Or download zip file | ||
> [Download v1.7.0](https://github.com/leocaseiro/angular-chosen/archive/1.7.0.zip) | ||
> [Download v1.9.0](https://github.com/leocaseiro/angular-chosen/archive/1.9.0.zip) | ||
@@ -43,0 +41,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
311
34327
13
160