From f6a07c9bbe7b3ba0d1644335a80397ed734db235 Mon Sep 17 00:00:00 2001 From: Lior Chen Date: Sun, 28 Aug 2016 12:17:52 +0300 Subject: [PATCH] Use evalAsync instead of timeout evalAsync runs after the digest and before the browser render. This will help avoid the jitter that happens in the initialization, when you see the browser rendering the select and then rendering the "chosen" --- dist/angular-chosen.js | 2 +- dist/angular-chosen.min.js | 2 +- src/chosen.coffee | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/angular-chosen.js b/dist/angular-chosen.js index 7ae9807..b1e28eb 100644 --- a/dist/angular-chosen.js +++ b/dist/angular-chosen.js @@ -75,7 +75,7 @@ } return element.trigger('chosen:updated'); } else { - $timeout(function() { + scope.$evalAsync(function() { chosen = element.chosen(options).data('chosen'); }); if (angular.isObject(chosen)) { diff --git a/dist/angular-chosen.min.js b/dist/angular-chosen.min.js index d1262d0..00df1b3 100644 --- a/dist/angular-chosen.min.js +++ b/dist/angular-chosen.min.js @@ -4,4 +4,4 @@ * @link http://github.com/leocaseiro/angular-chosen * @license MIT */ -(function(){var e=[].indexOf||function(e){for(var t=0,n=this.length;t=0)return o.$observe(r,function(e){var t;return t=String(l.attr(o.$attr[r])).slice(0,2),p[s(r)]="{{"===t?e:a.$eval(e),S()})}),b=function(){return l.addClass("loading").attr("disabled",!0).trigger("chosen:updated")},v=function(){return l.removeClass("loading"),angular.isDefined(o.disabled)?l.attr("disabled",o.disabled):l.attr("disabled",!1),l.trigger("chosen:updated")},d=null,c=!1,f=function(){var e,n;if(d){if(n=$(l.parent()).find("div.chosen-drop"),n&&n.length>0&&n.css("left").indexOf("0")>=0)return;return l.trigger("chosen:updated")}if(t(function(){d=l.chosen(p).data("chosen")}),angular.isObject(d))return e=d.default_text},S=function(){return d&&c?l.attr("data-placeholder",d.results_none_found).attr("disabled",!0):l.removeAttr("data-placeholder"),l.trigger("chosen:updated")},u?(g=u.$render,u.$render=function(){return g(),f()},l.on("chosen:hiding_dropdown",function(){return a.$apply(function(){return u.$setTouched()})}),o.multiple&&(w=function(){return u.$viewValue},a.$watch(w,u.$render,!0))):f(),o.$observe("disabled",function(){return l.trigger("chosen:updated")}),o.ngOptions&&u)return h=o.ngOptions.match(r),y=h[7],a.$watchCollection(y,function(e,n){var r;return r=t(function(){return angular.isUndefined(e)?b():(c=i(e),v(),S())})}),a.$on("$destroy",function(e){if("undefined"!=typeof timer&&null!==timer)return t.cancel(timer)})}}}])}).call(this); \ No newline at end of file +(function(){var e=[].indexOf||function(e){for(var t=0,n=this.length;t=0)return o.$observe(r,function(e){var t;return t=String(l.attr(o.$attr[r])).slice(0,2),p[s(r)]="{{"===t?e:a.$eval(e),y()})}),b=function(){return l.addClass("loading").attr("disabled",!0).trigger("chosen:updated")},v=function(){return l.removeClass("loading"),angular.isDefined(o.disabled)?l.attr("disabled",o.disabled):l.attr("disabled",!1),l.trigger("chosen:updated")},d=null,c=!1,f=function(){var e,t;if(d){if(t=$(l.parent()).find("div.chosen-drop"),t&&t.length>0&&t.css("left").indexOf("0")>=0)return;return l.trigger("chosen:updated")}if(a.$evalAsync(function(){d=l.chosen(p).data("chosen")}),angular.isObject(d))return e=d.default_text},y=function(){return d&&c?l.attr("data-placeholder",d.results_none_found).attr("disabled",!0):l.removeAttr("data-placeholder"),l.trigger("chosen:updated")},u?(g=u.$render,u.$render=function(){return g(),f()},l.on("chosen:hiding_dropdown",function(){return a.$apply(function(){return u.$setTouched()})}),o.multiple&&(w=function(){return u.$viewValue},a.$watch(w,u.$render,!0))):f(),o.$observe("disabled",function(){return l.trigger("chosen:updated")}),o.ngOptions&&u)return h=o.ngOptions.match(r),S=h[7],a.$watchCollection(S,function(e,n){var r;return r=t(function(){return angular.isUndefined(e)?b():(c=i(e),v(),y())})}),a.$on("$destroy",function(e){if("undefined"!=typeof timer&&null!==timer)return t.cancel(timer)})}}}])}).call(this); \ No newline at end of file diff --git a/src/chosen.coffee b/src/chosen.coffee index 02dc2ad..ec3af63 100644 --- a/src/chosen.coffee +++ b/src/chosen.coffee @@ -82,7 +82,7 @@ angular.module('localytics.directives').directive 'chosen', ['$timeout', ($timeo return return element.trigger('chosen:updated') else - $timeout -> + scope.$evalAsync -> chosen = element.chosen(options).data('chosen') return if angular.isObject(chosen)