Skip to content

Instantly share code, notes, and snippets.

@thm-design
Forked from Spinarooni/gist:4353952
Created March 21, 2013 09:41
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 thm-design/5211843 to your computer and use it in GitHub Desktop.
Save thm-design/5211843 to your computer and use it in GitHub Desktop.
/*
AMD Module for jQuery.Spinner plugin for Spin
Adapted from: https://gist.github.com/1290439
Spin.js: http://fgnass.github.com/spin.js/
You can now create a spinner using any of the variants below:
$("#el").spin(); // Produces default Spinner using the text color of #el.
$("#el").spin("small"); // Produces a 'small' Spinner using the text color of #el.
$("#el").spin("large", "white"); // Produces a 'large' Spinner in white (or any valid CSS color).
$("#el").spin({ ... }); // Produces a Spinner using your custom settings.
$("#el").spin(false); // Kills the spinner.
*/
define([
// Libraries
'jquery',
// Plugins
'plugins/spin'
],
function($, Spinner) {
$.fn.spin = function(opts, color) {
var presets = {
"tiny": { lines: 8, length: 2, width: 2, radius: 3 },
"small": { lines: 8, length: 4, width: 3, radius: 5 },
"large": { lines: 10, length: 8, width: 4, radius: 8 }
};
if (Spinner) {
return this.each(function() {
var $this = $(this),
data = $this.data();
if (data.spinner) {
data.spinner.stop();
delete data.spinner;
}
if (opts !== false) {
if (typeof opts === "string") {
if (opts in presets) {
opts = presets[opts];
} else {
opts = {};
}
if (color) {
opts.color = color;
}
}
data.spinner = new Spinner(
$.extend({color: $this.css('color')}, opts)
).spin(this);
}
});
} else {
throw "Spinner class not available.";
}
};
return $;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment