Skip to content

Instantly share code, notes, and snippets.

@lavoiesl
Created November 8, 2012 19:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lavoiesl/4040784 to your computer and use it in GitHub Desktop.
Save lavoiesl/4040784 to your computer and use it in GitHub Desktop.
Ajax loader overlay
/*
* Ajax overlay 1.0
* Author: Simon Ilett @ aplusdesign.com.au
* Descrip: Creates and inserts an ajax loader for ajax calls / timed events
* Date: 03/08/2011
*/
function ajaxLoader (el, options) {
// Becomes this.options
var defaults = {
bgColor : '#fff',
duration : 800,
opacity : 0.7,
classOveride : false
};
this.options = jQuery.extend(defaults, options);
this.container = $(el);
this.init = function() {
var container = this.container;
// Delete any other loaders
this.remove();
// Create the overlay
var overlay = $('<div></div>').css({
'background-color': this.options.bgColor,
'opacity':this.options.opacity,
'width': container.width(),
'height': container.height(),
'position': 'absolute',
// 'top':'0px',
// 'left':'0px',
'content' : ' ',
'z-index':99999,
'display': 'none'
}).addClass('ajax_overlay');
// add an overiding class name to set new loader style
if (this.options.classOveride) {
overlay.addClass(this.options.classOveride);
}
// insert overlay and loader into DOM
container.prepend(
overlay.prepend(
$('<div></div>').addClass('ajax_loader')
).fadeIn(this.options.duration)
);
};
this.remove = function(){
var overlay = this.container.children(".ajax_overlay");
if (overlay.length) {
overlay.fadeOut(this.options.classOveride, function() {
overlay.remove();
});
}
};
this.init();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment