Skip to content

Commit

Permalink
Item5389: JQueryLibPlugin adding spinner plugin.
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 1 deletion.
26 changes: 25 additions & 1 deletion data/Sandbox/JQueryLibPluginFoswikiDemo.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="BaseUserMapping_333" date="1235489385" format="1.1" version="1.3"}%
%META:TOPICINFO{author="BaseUserMapping_333" date="1235499581" format="1.1" reprev="1.4" version="1.4"}%
<pre class="ui-helper-hidden">
<style type="text/css">
ul#icons {margin: 0; padding: 0;}
Expand Down Expand Up @@ -455,6 +455,30 @@

<br /><br />

---++ Spinner

<button class="fw-button ui-state-default ui-corner-all" onclick="$('#spinner').spinner({image: '%PUBURLPATH%/System/JQueryLibPlugin/plugins/spinner/spinner.png'});$('#spinner').show();">Start spinner</button>
<button class="fw-button ui-state-default ui-corner-all" onclick="$('#spinner').spinner('stop').hide();">Stop</button>

<div id="spinner"></div>

<button class="fw-button ui-state-default ui-corner-all" onclick="$('#spinnerbig').spinner({height: 48,width: 48,speed: 50, frames:12, image: '%PUBURLPATH%/System/JQueryLibPlugin/plugins/spinner/spinner_big.png'}).show();">Start big spinner</button>
<button class="fw-button ui-state-default ui-corner-all" onclick="$('#spinnerbig').spinner('stop').hide();">Stop</button>

<div id="spinnerbig"></div>

<button class="fw-button ui-state-default ui-corner-all" onclick="$('#spinnerfast').spinner({height: 32,width: 32,speed: 25, image: '%PUBURLPATH%/System/JQueryLibPlugin/plugins/spinner/spinner.png'}).show();">Start fast spinner</button>
<button class="fw-button ui-state-default ui-corner-all" onclick="$('#spinnerfast').spinner('stop').hide();">Stop</button>

<div id="spinnerfast"></div>


<button class="fw-button ui-state-default ui-corner-all" onclick="$('#spinnerbigfast').spinner({height: 48,width: 48,speed: 25, frames:12, image: '%PUBURLPATH%/System/JQueryLibPlugin/plugins/spinner/spinner_big.png'}).show();">Start big fast spinner</button>
<button class="fw-button ui-state-default ui-corner-all" onclick="$('#spinnerbigfast').spinner('stop').hide();">Stop</button>

<div id="spinnerbigfast"></div>




%META:TOPICMOVED{by="BaseUserMapping_333" date="1235488861" from="Sandbox.JQueryLibPluginFoswikiUIDemo" to="Sandbox.JQueryLibPluginFoswikiDemo"}%
6 changes: 6 additions & 0 deletions lib/Foswiki/Plugins/JQueryLibPlugin/MANIFEST
Expand Up @@ -204,4 +204,10 @@ pub/System/JQueryLibPlugin/plugins/farbtastic/wheel.png
pub/System/JQueryLibPlugin/plugins/foswiki/foswiki.css
pub/System/JQueryLibPlugin/plugins/foswiki/foswiki.js

#
# Spinner plugin
#
pub/System/JQueryLibPlugin/plugins/spinner/jquery.spinner.js
pub/System/JQueryLibPlugin/plugins/spinner/spinner.png
pub/System/JQueryLibPlugin/plugins/spinner/spinner_big.png

177 changes: 177 additions & 0 deletions pub/System/JQueryLibPlugin/plugins/spinner/jquery.spinner.js
@@ -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.

0 comments on commit a379f34

Please sign in to comment.