/** # mod_jvslidepro - JV Slide Pro # @versions: 1.5.x,1.6.x,1.7.x,2.5.x # ------------------------------------------------------------------------ # author Open Source Code Solutions Co # copyright Copyright (C) 2011 joomlavi.com. All Rights Reserved. # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL or later. # Websites: http://www.joomlavi.com # Technical Support: http://www.joomlavi.com/my-tickets.html -------------------------------------------------------------------------*/ var JVPreload = (function($){ var preload = function(_selector){ var selector = $(_selector), wait = new JVWait(selector,{modal: true ,fixed: false}), i = 0, images = selector.find('img').map(function(){ return $(this).attr('src'); }), couterPanel = wait.gif.clone().css({ 'display': 'block', 'margin-top': 20, 'width': 60 }), couter = couterPanel.children().css({ 'background-image':'none', 'width': 'auto', 'height': 'auto' }), states = { load: 0, error: 0, abort: 0, all: images.length }, isLoad = function(){ return images.length === 0; }, eventsImageObj = { onload: function(){ states.load++; images.splice(0, 1); selector.trigger('preload_load',[states]); }, onabort: function(){ states.error++; images.splice(0, 1); selector.trigger('preload_abort',[states]); }, onerror: function(){ states.abort++; images.splice(0, 1); selector.trigger('preload_error',[states]); } }, imageObj = {}, timeOut, loaded, startPreload = function () { $.extend(imageObj,{onload: null,onabort:null,onerror:null}); if (isLoad()) { if(!loaded){ loaded = true; selector.trigger('preload_complete', [states]); } return; } clearTimeout(timeOut); var img = images[0]; imageObj = new Image(); $.extend(imageObj, eventsImageObj); imageObj.src = img; timeOut = setTimeout(startPreload, 300); } ; selector.bind({ 'preload_abort': startPreload, 'preload_error': startPreload, 'preload_load': function (e, p) { couter.html(p.load + ' / ' + p.all); startPreload(); }, 'preload_complete': function(){ wait.hide(); couterPanel.fadeOut(300,function(){ couterPanel.remove(); }); } }); $.extend(this,{ load: function(){ if(images.length){ wait.show(); wait.gif.after(couterPanel); startPreload(); } } }); } return preload; })(jQuery);