|
/* $.randy - Simple canvas spinner animation with gif fallback and all CSS included - written by Frederik Ring ([email protected]) */ |
|
|
|
/* Copyright (c) 2013 Frederik Ring */ |
|
/* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: */ |
|
/* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. */ |
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
|
|
|
/* see https://gist.github.com/m90/6044597 for documentation */ |
|
|
|
$.randy = function(options){ |
|
|
|
var useFallback = false; |
|
var gifSpinner; //base64 gif for IE8 and below |
|
|
|
if (!document.createElement('canvas').getContext){ //canvas is not supported |
|
|
|
useFallback = true; |
|
gifSpinner = 'data:image/gif;base64,R0lGODlhIAAgAPUAAP////////7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v////7+/gAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAA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z0FNGpEgIFAggwkBEyQIGHBAgEWQo5UcdIIiVcPBQp8QICAAAMKCUB4GKAgQ4cFEiygMJFCRRIJBDayJGA0QQQQA5jChDrBhFUmE0AQLdo16dKmThegcKFFAggMLRkk2AtWrIQUeix0GPB1b9gOAkwwCQIAIfkECQcAAAAsAAAAACAAIAAABv9AgHBInAw8xKRymVx8Sqcbc8oUEErYU4nKHS4e2LCN0KVmLthR+HQoMxeX0SgUCjcQbuXEEJr3SwYZeUsMIiIhhyIJg0sLGhuGIhsDjEsEjxuQEZVKEhcajxptnEkDn6AagqREGBeuFxCrSQcVFQ4Oi7JDD7a3lLpCDbYNDarADQ4NDw8KwEIGy9C/wAUG1gabzgzXBnjOAwYQEAcHHc4C4+QHDJU0SwnqBQXNeTM07kkSBQfyHwjmZWTMsOfu3hAQ/AogQECAHpUYMAQSxCdkAoEC/hgSACGBCQsWNSDCGDhDyYKFCwkwoJCAwwIBJkykcJGihQoWL0SOXEKCAAZVDCoZRADhgUOGDhIsoHBhE2ROGFMEUABKgCWIAQMUdFiQ1IQLFTdDcrEwQGWCBEOzHn2JwquLFTXcCBhwNsFVox1ILJiwdEUlCwsUDOCQdasFE1yCAAA7AAAAAAAAAAAA'; |
|
|
|
} |
|
|
|
var setup = $.extend({ //override options by passing them to the function on init |
|
|
|
container : 'spinner-container', //id -> uses element if it already exists |
|
background : 'rgba(0, 0 , 0, .3)', //color used as background -> falls back to plain grey in browsers not supporting rgba |
|
color: '#fff', //stroke color |
|
stroke : 5, //stroke width |
|
strokeLength : 20, //stroke length |
|
width: 400, //canvas width |
|
height: 300, // canvas height |
|
speed : 25, //speed -> higher number is slower!!! |
|
fps : 25, //frames per second |
|
numLines : 8, //number of lines in spinner |
|
ajaxToggle : false |
|
|
|
}, options); |
|
|
|
|
|
var containerExists = !!$('#' + setup.container).length; //does the passed container exist? |
|
|
|
if (!$('style#' + setup.container + '-style').length){ |
|
|
|
$('head').append([ //inject stylesheet via JS |
|
'<style id="' + setup.container + '-style">#' + setup.container + '{', |
|
'background-color: black;', //fallback for ie8 |
|
'filter: alpha(opacity=70);', |
|
'background-color: ' + setup.background + ';', |
|
'text-align: center;', |
|
'position: ' + (containerExists ? 'absolute' : 'fixed') + ';', //use absolute positioning when inititalized inside an existing container element |
|
'width: 100%;', |
|
'height: 100%;', |
|
'top: 0;', |
|
'left: 0;', |
|
'display: table;', |
|
'z-index: 99999;', |
|
'}', |
|
'#' + setup.container + ' .wrap{', |
|
'width: 100%;', |
|
'height: 100%;', |
|
'display: table-cell;', |
|
'vertical-align: middle;', |
|
'}', |
|
'</style>' |
|
].join('')); |
|
|
|
} |
|
|
|
var $container = containerExists ? $('#' + setup.container).empty() : $('<div>').attr('id', setup.container).hide(); //empty container if $.spinner is called a second time |
|
$container.append($('<div>').addClass('wrap')); |
|
|
|
if ($container.data('rotate')){ |
|
clearInterval($container.data('rotate')); |
|
} |
|
|
|
if (!containerExists){ |
|
$('body').prepend($container); |
|
} |
|
|
|
if (setup.ajaxToggle){ |
|
|
|
$(document).ajaxStart(function(){ |
|
$container.show(); |
|
}).ajaxStop(function(){ |
|
$container.hide(); |
|
}); |
|
|
|
} |
|
|
|
var drawLoader; |
|
|
|
if (useFallback){ |
|
|
|
var $gif = $('<img>').attr('src', gifSpinner); |
|
$container.find('.wrap').append($gif); |
|
|
|
} else { |
|
|
|
var $canvas = $('<canvas>').attr({ |
|
|
|
width: setup.width, |
|
height: setup.height |
|
|
|
}).css('z-index', '99999').appendTo($container.find('.wrap')); |
|
|
|
var ctx = $canvas[0].getContext('2d'); |
|
ctx.strokeStyle = setup.color; |
|
ctx.lineWidth = setup.stroke; |
|
ctx.lineCap = 'round'; |
|
ctx.translate(setup.width / 2, setup.height / 2); |
|
|
|
drawLoader = function(rotation){ |
|
|
|
ctx.clearRect(- setup.width / 2, - setup.height / 2, setup.width, setup.height); |
|
ctx.rotate(rotation); |
|
ctx.beginPath(); |
|
|
|
for (var i = 0; i < setup.numLines; i++){ |
|
ctx.moveTo(0, - setup.strokeLength / 2); |
|
ctx.lineTo(0, - setup.strokeLength); |
|
ctx.rotate((Math.PI / (setup.numLines / 2))); |
|
} |
|
|
|
ctx.rotate((-Math.PI / (setup.numLines / 2))); |
|
|
|
ctx.stroke(); |
|
|
|
}; |
|
|
|
var step = Math.PI / setup.speed; |
|
|
|
$container.data('rotate', setInterval(function(){ |
|
|
|
if (window.requestAnimationFrame){ //use rAF if available -> not polyfilled |
|
|
|
requestAnimationFrame(function(){ |
|
drawLoader(step); |
|
}); |
|
|
|
} else { |
|
|
|
drawLoader(step); |
|
|
|
} |
|
|
|
}, 1000 / setup.fps)); |
|
|
|
} |
|
|
|
return $container; //return hidden jquery object |
|
|
|
}; |