From f91f2a26d7145e871cb9167f79619a35b781d41f Mon Sep 17 00:00:00 2001 From: Florian Husquinet Date: Tue, 9 Feb 2016 17:08:13 +0100 Subject: [PATCH 1/2] Reset the width to 0 when loadie is finished It allows the plugin to be reused directly after it's done. --- js/jquery.loadie.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/js/jquery.loadie.js b/js/jquery.loadie.js index 506443a..a89b5e5 100644 --- a/js/jquery.loadie.js +++ b/js/jquery.loadie.js @@ -14,7 +14,9 @@ */ Loadie.finish = function(dom) { var loadie = $('#loadie-' + dom.data('loadie-id'), dom); - loadie.fadeOut(200); + loadie.fadeOut(200,function(){ + loadie.css('width',"0px"); + }); } /* @@ -43,17 +45,17 @@ $.fn.loadie = function(percent, callback) { var percent = percent || 0; var parent = $(this); + if(percent >= 1) { + setTimeout(function() { + Loadie.finish(parent); + }, 200); + } if(parent.data('loadie-loaded') !== 1) { Loadie.init(parent, percent); } else { Loadie.update(parent, percent); } - if(percent >= 1) { - setTimeout(function() { - Loadie.finish(parent); - }, 200); - } parent.data('loadie-loaded', 1); return this; }; From e6f788b386ff8fec30407174cca35ae15a42b557 Mon Sep 17 00:00:00 2001 From: Florian Husquinet Date: Tue, 9 Feb 2016 17:09:53 +0100 Subject: [PATCH 2/2] Reset the width to 0 when loadie is finished --- js/jquery.loadie.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/jquery.loadie.min.js b/js/jquery.loadie.min.js index 886266c..de5464f 100644 --- a/js/jquery.loadie.min.js +++ b/js/jquery.loadie.min.js @@ -1 +1 @@ -!function($){var Loadie={};Loadie.uid=function(){var newDate=new Date;return newDate.getTime()};Loadie.finish=function(dom){var loadie=$("#loadie-"+dom.data("loadie-id"),dom);loadie.fadeOut(200)};Loadie.update=function(dom,percent){var loadie=$("#loadie-"+dom.data("loadie-id"),dom);var parentWidth=dom.width();loadie.css("width",Math.floor(percent*parentWidth)+"px")};Loadie.init=function(dom,percent){var uid=this.uid();var loadie=dom.append($('
'));dom.data("loadie-id",uid);dom.css("position","relative");this.update(dom,percent)};$.fn.loadie=function(percent,callback){var percent=percent||0;var parent=$(this);if(parent.data("loadie-loaded")!==1){Loadie.init(parent,percent)}else{Loadie.update(parent,percent)}if(percent>=1){setTimeout(function(){Loadie.finish(parent)},200)}parent.data("loadie-loaded",1);return this}}(jQuery); \ No newline at end of file +!function(i){var a={};a.uid=function(){var i=new Date;return i.getTime()},a.finish=function(a){var d=i("#loadie-"+a.data("loadie-id"),a);d.fadeOut(200,function(){d.css("width","0px")})},a.update=function(a,d){var t=i("#loadie-"+a.data("loadie-id"),a),e=a.width();t.css("width",Math.floor(d*e)+"px")},a.init=function(a,d){var t=this.uid();a.append(i('
'));a.data("loadie-id",t),a.css("position","relative"),this.update(a,d)},i.fn.loadie=function(d,t){var d=d||0,e=i(this);return d>=1&&setTimeout(function(){a.finish(e)},200),1!==e.data("loadie-loaded")?a.init(e,d):a.update(e,d),e.data("loadie-loaded",1),this}}(jQuery);