/* * jquery.loading * * Shows the IAG loading screen. Will add two children (that should be styled): .loadingMessage and .loadingImage. * * options: * jqmModal (Optional, defaults to true) should the jquery modal used be modal? * jqmOverlay (Optional, defaults to 70) the opacity to use for the jquery modal. * Dependencies: * jquery-1.3.1 * jquery.bgiframe * jqmodal */ $.loading = { //Default options (overridden by passing in options in the initialise function). defaults: { jqmModal : true, jqmOverlay : 70 }, //Plugin locals. progress : {0:""}, loading_time: 0, options : null, lastKey : 0 }; /* * Initialises the plugin. See the header/examples for options. */ $.fn.loading=function(options) { var e = $(this); $.loading.options = $.extend({}, $.loading.defaults, options); //Configure the div as a jquery modal. e.addClass("jqmWindow"); e.jqm({modal: true, overlay:$.loading.options.jqmOverlay}); //Add the image and message elements. e.append('

'); }; /* * Show the loading screen. * * parameters: * progress (Required) a map of times to either strings or functions. If string, the contents of a message * will be set. If a function, the function will be executed. */ $.fn.showLoading=function(progress) { var e = $(this); $.loading.loading_time = new Date().getTime(); $.loading.lastKey = -1; $.loading.progress = progress; //The message loop definition. var loop = function(time) { if(e.css('display') != 'none') { var timeGoneBy = new Date().getTime() - $.loading.loading_time; for(var key in $.loading.progress) { var keyInt = parseInt(key) if(keyInt > $.loading.lastKey && timeGoneBy > keyInt) { $.loading.lastKey = keyInt; var marker = $.loading.progress[key]; if(marker instanceof Function) { marker(); } else { var message = e.find(".loadingMessage"); message.html($.loading.progress[key]); } break; } } //Continue Looping. setTimeout(loop, 50); } } //Start the message loop. setTimeout(loop, 0); //Show the modal. e.jqmShow(); } /* * Hide the loading screen. */ $.fn.hideLoading=function() { var e = $(this); e.jqmHide(); }