Skip to content

Instantly share code, notes, and snippets.

@lightyrs
Created January 8, 2012 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lightyrs/1576969 to your computer and use it in GitHub Desktop.
Save lightyrs/1576969 to your computer and use it in GitHub Desktop.
Loadingdotdot.js (modified)
(function($) {
$.Loadingdotdotdot = function(el, options) {
var base = this;
base.$el = $(el);
base.$el.data("Loadingdotdotdot", base);
base.dotItUp = function($element, maxDots) {
if ($element.text().length == maxDots) {
$element.text("");
} else {
$element.append(".");
}
};
base.stopInterval = function() {
clearInterval(base.theInterval);
};
base.init = function() {
if ( typeof( speed ) === "undefined" || speed === null ) speed = 300;
if ( typeof( maxDots ) === "undefined" || maxDots === null ) maxDots = 3;
base.speed = speed;
base.maxDots = maxDots;
base.options = $.extend({},$.Loadingdotdotdot.defaultOptions, options);
base.$el.html("<span>" + base.options.word + "<em></em></span>");
base.$dots = base.$el.find("em");
base.$loadingText = base.$el.find("span");
base.$el.css("position", "relative");
base.$loadingText.css({
"position": "absolute",
"top": (base.$el.outerHeight() / 2) - (base.$loadingText.outerHeight() / 2),
"left": (base.$el.width() / 2) - (base.$loadingText.width() / 2)
});
base.theInterval = setInterval(base.dotItUp, base.options.speed, base.$dots, base.options.maxDots);
};
base.init();
};
$.Loadingdotdotdot.defaultOptions = {
speed: 300,
maxDots: 3,
word: "Loading"
};
$.fn.Loadingdotdotdot = function(options) {
if (typeof(options) == "string") {
var safeGuard = $(this).data('Loadingdotdotdot');
if (safeGuard) {
safeGuard.stopInterval();
}
} else {
return this.each(function(){
(new $.Loadingdotdotdot(this, options));
});
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment