metadin
clone your own copy | download snapshot

Snapshots | iceberg

Inside this repository

jquery.spin.js
application/javascript

Download raw (1.4 KB)

/*

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.

*/
(function($) {
	$.fn.spin = function(opts, color) {
		var presets = {
			"tiny": { lines: 12, length: 2, width: 2, radius: 3, color: '#000', speed: 1.4, trail: 74, shadow: false },
			"small": { lines: 12, length: 4, width: 3, radius: 5, color: '#000', speed: 1.4, trail: 74, shadow: false },
			"large": { lines: 12, length: 8, width: 5, radius: 11, color: '#000', speed: 1.4, trail: 74, shadow: false }
		};
		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.";
		}
	};
})(jQuery);