Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Item5389: JQueryLibPlugin adding spinner plugin.
git-svn-id: http://svn.foswiki.org/trunk/JQueryLibPlugin@2662 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
- Loading branch information
StephaneLenclud
authored and
StephaneLenclud
committed
Feb 24, 2009
1 parent
cc22b8e
commit a379f34
Showing
5 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
pub/System/JQueryLibPlugin/plugins/spinner/jquery.spinner.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/* | ||
* Simple jQuery spinner. | ||
* Based on: http://jquery.com/plugins/Authoring/ | ||
* Original work from http://www.command-tab.com/2007/05/07/jquery-spinner-plugin/ | ||
* Rewritten by Stéphane Lenclud to support multiple spinner per page and nicer API | ||
* | ||
* @version 20080225 | ||
* @since 2008-02-25 | ||
* @copyright Copyright (c) 2007 www.command-tab.com, Copyright (c) 2008 Stéphane Lenclud. | ||
* @author Stéphane Lenclud <jquery@lenclud.com> | ||
* @license GPL | ||
* @requires >= jQuery 1.2.3 | ||
*/ | ||
|
||
|
||
// | ||
// create closure | ||
// | ||
(function($) { | ||
|
||
|
||
//Prevent compilation error in case jquery.debug.js is not loaded | ||
function log(msg) | ||
{ | ||
if ($.log) | ||
{ | ||
$.log(msg); | ||
} | ||
} | ||
|
||
// | ||
// plugin definition | ||
// | ||
$.fn.spinner = function(options) { | ||
|
||
//debug(this); | ||
// build main options before element iteration | ||
var opts = $.extend({}, $.fn.spinner.defaults, options); | ||
// iterate and reformat each matched element | ||
return this.each(function() { | ||
//Stop it first, to prevent double start | ||
//$.fn.spinner.stop(); | ||
|
||
$this = $(this); | ||
|
||
//check if we get a command option | ||
if (typeof options == "string") { | ||
if (options == "stop") | ||
{ | ||
// | ||
var o = $.data(this,"spinner"); //restore | ||
if(o.intervalId) | ||
{ | ||
log("stop " + this.id); | ||
clearInterval(o.intervalId); | ||
o.intervalId=undefined; | ||
$.data(this,"spinner",o); //store | ||
} | ||
return; | ||
} | ||
else if (options == "redraw") | ||
{ | ||
//Do redraw | ||
var o = $.data(this,"spinner"); | ||
log("redraw " + this.id); | ||
log(o); | ||
//log("frame" + o.frame); | ||
//if(o.intervalId) clearInterval(o.intervalId); | ||
|
||
//alert(o.frame); | ||
|
||
// If we've reached the last frame, loop back around | ||
if(o.frame >= o.frames) { | ||
o.frame = 1; | ||
} | ||
|
||
// Set the background-position for this frame | ||
pos = "-"+(o.frame*o.width)+"px 0px"; | ||
$this.css("background-position",pos); | ||
|
||
// Increment the frame count | ||
o.frame=o.frame+1; | ||
$.data(this,"spinner",o); | ||
|
||
return; | ||
} | ||
} | ||
|
||
//Normal contructor/starter | ||
// build element specific options | ||
var o = $.extend({}, opts, $.data(this,"spinner")); | ||
|
||
log("dump " + this.id); | ||
log(o); //dump | ||
if (o.intervalId) | ||
{ | ||
//Make sure we stop before starting again | ||
$this.spinner('stop'); | ||
} | ||
|
||
|
||
// Set the height | ||
if(o.height) { | ||
$this.height(o.height); | ||
} | ||
|
||
// Set the width | ||
if(o.width) { | ||
$this.width(o.width); | ||
} | ||
|
||
// Set or get the spinner image | ||
//if(o.image) { | ||
$this.css("background-image","url("+o.image+")"); | ||
$this.css("background-position","0px 0px"); | ||
$this.css("background-repeat","no-repeat"); | ||
//} else { | ||
// o.image = $this.css("background-image"); | ||
//} | ||
|
||
// Store our data | ||
//$.data(this,"spinner",o); | ||
|
||
// Determine how many frames exist | ||
img = new Image(); | ||
img.src = o.image; | ||
img.onload = function() { | ||
//var o = $.data(this,"spinner"); //restore | ||
log("image.onload " + this.id); | ||
o.frames = img.width/o.width; | ||
log(o); | ||
$.data(this,"spinner",o); //store | ||
}; | ||
|
||
// Set the frame speed | ||
if(!o.speed) { | ||
o.speed = 25; | ||
} | ||
|
||
|
||
log("start " + this.id); | ||
|
||
o.frame=0; | ||
|
||
//o.intervalId=setInterval("$.fn.spinner.redraw(this)",o.speed); | ||
|
||
// Kick off the animation | ||
o.intervalId=setInterval("$('#" + this.id +"').spinner('redraw')",o.speed); | ||
|
||
// Store our data | ||
$.data(this,"spinner",o); | ||
//var spinnerAnimation = setInterval(spinnerRedraw,options.speed); | ||
|
||
}); | ||
}; | ||
|
||
|
||
// | ||
// plugin defaults | ||
// | ||
$.fn.spinner.defaults = { | ||
height: 32, | ||
width: 32, | ||
speed: 50, | ||
frame: 0, | ||
frames: 31, | ||
intervalId: 0 | ||
}; | ||
|
||
|
||
|
||
// | ||
// end of closure | ||
// | ||
})(jQuery); | ||
|
||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.