Skip to content

Instantly share code, notes, and snippets.

@Olical
Created April 29, 2011 16:06
Show Gist options
  • Save Olical/948535 to your computer and use it in GitHub Desktop.
Save Olical/948535 to your computer and use it in GitHub Desktop.
Spark 3 pre release (29/04/11)
/*
Spark JavaScript Library v3.0.0
http://sparkjs.co.uk/
Copyright 2011, Oliver Caldwell
Dual licensed under the MIT or GPL Version 2 licenses.
http://sparkjs.co.uk/licence.html
*/
var Spark=function(){function a(){}a.prototype.extend=function(b,c){a.prototype[b]=c;if(typeof c==="object")c.instance=this};a.prototype.clone=function(){return new a};return new a}();if(typeof window.$==="undefined")var $=function(a,b){return Spark.find(a,b)};
Spark.extend("ready",function(a){function b(){c.find(document).data("domReady",!0);a()}var c=this.clone();c.find(document).data("domReady")?a():window.addEventListener?document.addEventListener("DOMContentLoaded",b,!1):function(){var a=document.createElement("document:ready");try{a.doScroll("left"),b()}catch(c){setTimeout(arguments.callee,0)}}()});
Spark.extend("ajax",{initialise:function(){return typeof XMLHttpRequest==="undefined"?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest},buildParameterString:function(a){var b=null,c="";for(b in a)a.hasOwnProperty(b)&&(c+=encodeURIComponent(b)+"="+encodeURIComponent(a[b])+"&");return c.slice(0,c.length-1)},handleCallback:function(a,b){a.onreadystatechange=function(){a.readyState===4&&(a.status===200?b(a.responseText):b(!1))}},get:function(a,b,c){var e=this.initialise();b&&(a+="?"+this.buildParameterString(b));
c&&this.handleCallback(e,c);e.open("GET",a,typeof c==="function");e.send();if(!c)return e.status===200?e.responseText:!1},post:function(a,b,c){var e=this.initialise();c&&this.handleCallback(e,c);e.open("POST",a,typeof c==="function");e.setRequestHeader("Content-type","application/x-www-form-urlencoded");b?e.send(this.buildParameterString(b)):e.send();if(!c)return e.status===200?e.responseText:!1},getJSON:function(a,b,c){var e=!1;c&&(e=this.buildParameterString(c));this.instance.load(a+"?callback="+
b+(e?"&"+e:""))}});Spark.extend("cookie",function(a,b,c){var e=document.cookie.split(";"),d=null,l=null;d=new Date;if(typeof b==="undefined"){for(d=0;d<e.length;d++)if(l=e[d].replace(/^\s+/g,""),l.indexOf(a+"=")===0)return l.substring(a.length+1,l.length);return!1}else typeof c!=="undefined"?(d.setTime(d.getTime()+c),expires="; expires="+d.toGMTString()):expires="",document.cookie=a+"="+escape(b)+expires+"; path=/"});
Spark.extend("find",function(a,b){function c(a){var b=[],c=a.length,e=null,g=null;for(g=0;g<c;g++){for(e=g+1;e<c;e++)a[g]===a[e]&&(e=++g);b.push(a[g])}return b}function e(a,b){var e=a.split(/\s*,\s*/g),g=null,l=Spark.clone(),j=null,f=null,h=null,s=[],i=null;g=null;f=["^\\[([a-z_][\\-a-z0-9_]+)=['\"](.*)['\"]\\]","^\\[([a-z_][\\-a-z0-9_]+)\\]","^([a-z0-9*]+)","^#([a-z][a-z0-9-_]*)","^\\.(-?[_a-z]+[_a-z0-9\\-]*)","^\\[([a-z_][\\-a-z0-9_]+)~=['\"](.*)['\"]\\]","^\\[([a-z_][\\-a-z0-9_]+)\\|=['\"](.*)['\"]\\]",
"^:first-child","^:lang\\((.*)\\)"];var d=[];for(j=0;j<f.length;j++)d.push({search:RegExp(f[j],"i"),remove:RegExp(f[j]+".*","i")});for(j=0;j<e.length;j++){f=e[j].replace(/(>|\+)/g," $1 ").replace(/\s+(>|\+)\s+/g," $1");i=null;g=[];g=[];h=!1;for(i=0;i<f.length;i++)f.indexOf("'",i)===i||f.indexOf('"',i)===i?h===!0?h=!1:h===!1&&(h=!0):f.indexOf(" ",i)===i&&h===!0&&g.push(i);for(i=0;i<g.length;i++)f=f.substr(0,g[i]+i)+"\\s"+f.substr(g[i]+1+i);g=f.split(/\s+/g);for(i=0;i<g.length;i++)g[i]=g[i].replace(/\\s/g,
" ");i=[];for(f=0;f<g.length;f++){h=g[f];for(i.push({});h.length>0;){if(h.indexOf(">")===0)i[f].child=!0,h=h.substr(1);else if(h.indexOf("+")===0)i[f].sibling=!0,h=h.substr(1);if(h.match(d[5].search)){if(typeof i[f].whiteSpaceAttribute==="undefined")i[f].whiteSpaceAttribute={};i[f].whiteSpaceAttribute[h.replace(d[5].remove,"$1")]=h.replace(d[5].remove,"$2");h=h.replace(d[5].search,"")}else if(h.match(d[6].search)){if(typeof i[f].hyphenAttribute==="undefined")i[f].hyphenAttribute={};i[f].hyphenAttribute[h.replace(d[6].remove,
"$1")]=h.replace(d[6].remove,"$2");h=h.replace(d[6].search,"")}else if(h.match(d[0].search)){if(typeof i[f].attribute==="undefined")i[f].attribute={};i[f].attribute[h.replace(d[0].remove,"$1")]=h.replace(d[0].remove,"$2");h=h.replace(d[0].search,"")}else if(h.match(d[1].search)){if(typeof i[f].attribute==="undefined")i[f].attribute={};i[f].attribute[h.replace(d[1].remove,"$1")]=!0;h=h.replace(d[1].search,"")}else if(h.match(d[2].search)){if(typeof i[f].tag==="undefined")i[f].tag=h.replace(d[2].remove,
"$1");else{if(typeof i[f].tag==="string")i[f].tag=[i[f].tag];i[f].tag.push(h.replace(d[2].remove,"$1"))}h=h.replace(d[2].search,"")}else if(h.match(d[3].search)){if(typeof i[f].id==="undefined")i[f].id=h.replace(d[3].remove,"$1");else{if(typeof i[f].id==="string")i[f].id=[i[f].id];i[f].id.push(h.replace(d[3].remove,"$1"))}h=h.replace(d[3].search,"")}else if(h.match(d[4].search)){if(typeof i[f].classes==="undefined")i[f].classes=h.replace(d[4].remove,"$1");else{if(typeof i[f].classes==="string")i[f].classes=
[i[f].classes];i[f].classes.push(h.replace(d[4].remove,"$1"))}h=h.replace(d[4].search,"")}else if(h.match(d[7].search))i[f].first=!0,h=h.replace(d[7].search,"");else if(h.match(d[8].search))i[f].lang=h.replace(d[8].remove,"$1"),h=h.replace(d[8].search,"");else return!1}}g=b;for(f=0;f<i.length;f++)g=g.find(i[f]);s=s.concat(g.elements)}s=c(s);for(j=0;j<s.length;j++)l[j]=s[j];l.elements=s;l.length=s.length;return l}function d(a,b,c,g,d){var j=null,f=null;f=a instanceof Array?a.join(" "):!1;if(typeof b===
"string")if(f)return f.match(RegExp("(^| )"+b+"($| )","g"))?!0:!1;else if((c?a.toUpperCase():a)===(c?b.toUpperCase():b))return!0;else{if(c&&b==="*")return!0;return!1}else if(b instanceof Array){for(j=0;j<b.length;j++)if(f){if(f.match(RegExp("(^| )"+b[j]+"($| )","g")))return!0}else if((c?a.toUpperCase():a)===(c?b[j].toUpperCase():b[j]))return!0;return!1}else{if(typeof b==="object")for(j in b)if(b.hasOwnProperty(j))if(b[j]===!0){if(a.getAttribute(j)===null)return!1}else if(a.getAttribute(j)!==null)if(typeof b[j]===
"string")if(d){if(a.getAttribute(j)!==b[j]&&a.getAttribute(j).indexOf(b[j]+"-")!==0)return!1}else if(g){if(a.getAttribute(j)!==b[j]&&a.getAttribute(j).indexOf(b[j]+" ")!==0)return!1}else{if(a.getAttribute(j)!==b[j])return!1}else{if(b[j]instanceof Array)for(f=0;f<b[j].length;f++)if(d){if(a.getAttribute(j)!==b[j][f]&&a.getAttribute(j).indexOf(b[j][f]+"-")!==0)return!1}else if(g){if(a.getAttribute(j)!==b[j][f]&&a.getAttribute(j).indexOf(b[j][f]+" ")!==0)return!1}else if(a.getAttribute(j)!==b[j][f])return!1}else return!1;
return!0}}function l(a,b,c,d,e,j){var f=null,h=[];if(typeof a==="string"){f=d===!0?b.parentNode.getElementsByTagName(a):b.getElementsByTagName(a);for(g=0;g<f.length;g++)e===!0&&f[g]===(f[g].parentNode.firstElementChild||f[g].parentNode.firstChild)?c===!0&&f[g].parentNode===b?h.push(f[g]):d===!0&&(f[g]===b.nextElementSibling||f[g]===b.nextSibling)?h.push(f[g]):!c&&!d&&h.push(f[g]):e||(c===!0&&f[g].parentNode===b?h.push(f[g]):d===!0&&(f[g]===b.nextElementSibling||f[g]===b.nextSibling)?h.push(f[g]):
!c&&!d&&h.push(f[g]))}else if(a instanceof Array)for(k=0;k<a.length;k++){f=d===!0?b.parentNode.getElementsByTagName(a[k]):b.getElementsByTagName(a[k]);for(g=0;g<f.length;g++)c===!0&&f[g].parentNode===b?h.push(f[g]):d===!0&&(f[g]===b.nextElementSibling||f[g]===b.nextSibling)?h.push(f[g]):!c&&!d&&h.push(f[g])}else{f=d===!0?b.parentNode.getElementsByTagName("*"):b.getElementsByTagName("*");for(g=0;g<f.length;g++)c===!0&&f[g].parentNode===b?h.push(f[g]):d===!0&&(f[g]===b.nextElementSibling||f[g]===b.nextSibling)?
h.push(f[g]):!c&&!d&&h.push(f[g])}if(j){a=null;b=[];c=null;for(c=0;c<h.length;c++)for(a=h[c];a.parentNode;){if(a.getAttribute("lang")===j){b.push(h[c]);break}a=a.parentNode}j=b}else j=h;return j}var n=[],m=[],p=typeof b!=="undefined"?b:document,k=null,g=null,q=null;q=null;var o=this.clone();if(typeof a==="object")if(typeof a.nodeName==="string")return o[0]=a,o.elements=[a],o.length=1,o;else if(typeof a.target==="object")return o[0]=a.target,o.elements=[a.target],o.length=1,o;if(this.elements instanceof
Array)for(k=0;k<this.length;k++){q=l(a.tag,this.elements[k],a.child,a.sibling,a.first,a.lang);for(g=0;g<q.length;g++)n.push(q[g])}else n=l(a.tag,p,a.child,a.sibling,a.first,a.lang);if(typeof a==="string")return e(a,this);for(k=0;k<n.length;k++)g=n[k],q=g.className.split(/\s+/g),d(g.nodeName,a.tag,!0)&&d(q,a.classes)&&d(g.id,a.id)&&d(g,a.attribute)&&d(g,a.whiteSpaceAttribute,!1,!0)&&d(g,a.hyphenAttribute,!1,!1,!0)&&m.push(g);m=c(m);for(k=0;k<m.length;k++)o[k]=m[k];o.elements=m;o.length=m.length;typeof a.find===
"object"&&(o=o.find(a.find));return o});Spark.extend("each",function(a,b){var c=null,e=null;if(typeof b==="undefined")if(typeof this.elements==="undefined")return!1;else e=this.elements;else typeof b==="object"&&(e=b);if(typeof e.length==="number")for(c=0;c<e.length;c++)a(e[c],c);else for(c in e)e.hasOwnProperty(c)===!0&&a(e[c],c);return this});Spark.extend("dataMeta",{keys:[],data:[]});
Spark.extend("data",function(a,b){var c=null,e=null,d=null;if(this.elements instanceof Array&&typeof this.elements[0]==="object"){e=this.elements[0];d=-1;if(typeof this.dataMeta.keys.indexOf!=="undefined")d=this.dataMeta.keys.indexOf(e);else for(c=0;c<this.dataMeta.keys.length;c++)this.dataMeta.keys[c]===e&&(d=c);if(typeof b!=="undefined"){if(d===-1)d=this.dataMeta.keys.length,this.dataMeta.keys.push(e),this.dataMeta.data.push({});this.dataMeta.data[d][a]=b;return this}else{if(d===-1)return!1;return typeof this.dataMeta.data[d][a]!==
"undefined"?this.dataMeta.data[d][a]:!1}}return!1});Spark.extend("attribute",function(a,b){var c=this;if(typeof a==="string")if(typeof b==="string")this.each(function(c){c.setAttribute(a,b)});else return this[0].getAttribute(a);else typeof a==="object"&&this.each(function(a,b){c.each(function(c){c.setAttribute(b,a)})},a);return this});
Spark.extend("style",function(a,b){function c(a){if(a.indexOf("-")!==-1)return a.replace(/-([a-z])/gi,function(a,b){return b.toUpperCase()});return a}function e(a){return a.replace(/([A-Z])/g,function(a){return"-"+a.toLowerCase()})}function d(a,b,d){var e=null;b=c(b);d=typeof d==="number"&&!RegExp("(^|\\s)"+b+"($|\\s)","i").test("zIndex fontWeight opacity zoom lineHeight")?d+"px":d;a.style[b]=d;if(b==="opacity")a.style.zoom="1",a.style.filter="alpha(opacity="+Math.floor(parseFloat(d)*100)+")",a.style.MozOpacity=
d,a.style.KhtmlOpacity=d}function l(a,b){var c=null;(c=typeof getComputedStyle!=="undefined"?document.defaultView.getComputedStyle(a,null).getPropertyValue(e(b)):a.currentStyle[b])||(c=a.style[b]);b.toLowerCase().indexOf("color")!==-1&&(c=p.color.toRgb(c));return c}var n=null,m=null,p=this,k=null;if(typeof a==="string")if(typeof b==="string"||typeof b==="number")for(n=0;n<this.length;n++)d(this[n],a,b);else if(a==="padding"||a==="margin"||a==="border"){k=[l(this[0],c(a+"Top")),l(this[0],c(a+"Bottom")),
l(this[0],c(a+"Left"))];for(n=1;n<2;n++)if(k[0]!==k[n])return"";return k[0]}else return l(this[0],c(a));else if(typeof a==="object")for(m in a)if(a.hasOwnProperty(m))for(n=0;n<this.length;n++)d(this[n],m,a[m]);return this});
Spark.extend("json",{parse:function(a){if(typeof JSON!=="undefined")try{return JSON.parse(a)}catch(b){throw new SyntaxError("Invalid JSON");}if(/^[\],:{}\s]*$/.test(a.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return eval("("+a+")");else throw new SyntaxError("Invalid JSON");},stringify:function(a,b){function c(a){return b?'"'+b+'":'+a:a}function e(a){m.lastIndex=0;return m.test(a)?
'"'+a.replace(m,function(a){var b=n[a];return typeof b==="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}var d=null,l="",n={"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},m=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;if(typeof JSON!=="undefined")return JSON.stringify(a);if(a instanceof Array){for(d=0;d<a.length;d++)l+=this.stringify(a[d])+",";return c("["+
l.slice(0,l.length-1)+"]")}else if(typeof a==="object"){for(d in a)a.hasOwnProperty(d)&&(l+=this.stringify(a[d],d)+",");return c("{"+l.slice(0,l.length-1)+"}")}else return typeof a==="string"?c(e(a)):c(a.toString())}});Spark.extend("hasClass",function(a){return RegExp("\\b"+a+"\\b").test(this[0].className)});Spark.extend("addClass",function(a){var b=null,c=this;this.each(function(e){if(!c.find(e).hasClass(a))b=c.find(e).attribute("class"),e.className=(b?b+" "+a:a).replace(/^\s+|\s+$/i,"")});return this});
Spark.extend("removeClass",function(a){this.each(function(b){b.className=b.className.replace(RegExp("(^|\\s)"+a+"($|\\s)"),"")});return this});
Spark.extend("addEvent",function(a,b,c){function e(a){if(c)a.cancelBubble=!0,a.stopPropagation&&a.stopPropagation();var d=b,e=null,p=0,k=0;if(typeof a.target==="undefined")a.target=a.srcElement;if(a.target.nodeType===3)a.target=a.target.parentNode;if(typeof a.keyCode==="undefined")a.keyCode=a.which;if(typeof a.pageX==="undefined")a.pageX=a.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,a.pageY=a.clientY+document.body.scrollTop+document.documentElement.scrollTop;e=a.target;if(e.offsetParent&&
navigator.userAgent.indexOf("Opera")===-1&&navigator.userAgent.indexOf("MSIE")===-1){do e=e.offsetParent,p+=e.offsetLeft,k+=e.offsetTop;while(e.offsetParent);a.offsetX=p;a.offsetY=k}if(d(a)===!1)a.preventDefault?a.preventDefault():a.returnValue=!1}var d=this;this.each(function(c){d.find(c).data("SparkEvents")||d.find(c).data("SparkEvents",[]);d.find(c).data("SparkEvents").push({type:a,fn:b,reference:e});c.addEventListener?c.addEventListener(a,e,!1):c.attachEvent("on"+a,e)});return this});
Spark.extend("removeEvent",function(a,b){var c=this;this.each(function(e){c.find(e).data("SparkEvents")&&c.each(function(c){c.fn===b&&c.type===a&&(e.removeEventListener?e.removeEventListener(a,c.reference,!1):e.detachEvent("on"+a,c.reference))},c.find(e).data("SparkEvents"))});return this});
Spark.extend("triggerEvent",function(a){var b=null;this.each(function(c){document.createEventObject?(b=document.createEventObject(),c.fireEvent("on"+a,b)):(b=document.createEvent("HTMLEvents"),b.initEvent(a,!0,!0),c.dispatchEvent(b))});return this});Spark.extend("createElement",function(a,b,c,e){a=document.createElement(a);if(b)a.innerHTML=b;c&&this.find(a).attribute(c);e&&this.find(a).style(e);return a});
Spark.extend("insertElement",function(a,b,c,e){var d=null;d=typeof a==="string"?this.createElement(a,b,c,e):a;this.each(function(a){a.appendChild(d.cloneNode(!0))});return this});Spark.extend("prependElement",function(a,b,c,e){var d=null;d=typeof a==="string"?this.createElement(a,b,c,e):a;this.each(function(a){a.parentNode.insertBefore(d.cloneNode(!0),a)});return this});
Spark.extend("appendElement",function(a,b,c,e){var d=null;d=typeof a==="string"?this.createElement(a,b,c,e):a;this.each(function(a){a.parentNode.insertBefore(d.cloneNode(!0),a.nextSibling)});return this});Spark.extend("removeElement",function(){this.each(function(a){a.parentNode.removeChild(a)});return this});Spark.extend("load",function(a){this.clone().find("head").insertElement("script",!1,{type:"text/javascript",src:a})});
Spark.extend("html",function(a,b){if(typeof a==="undefined")return this[0].innerHTML;this.each(function(c){b?c.innerHTML+=a:c.innerHTML=a});return this});Spark.extend("text",function(a,b){var c=document.body.innerText?"innerText":"textContent";if(typeof a==="undefined")return this[0][c];this.each(function(e){b?e[c]+=a:e[c]=a});return this});
Spark.extend("animate",function(a,b,c,e){function d(a,f,b,c){setTimeout(function(){a.style(f,b)},c)}function l(a,f,b,c){setTimeout(function(){a.animate(f,b,c)},a.data("SparkOffset"))}function n(a,f){setTimeout(function(){a.data("SparkOffset",a.data("SparkOffset")-f)},f)}var m=this,p=null,k=null,g=null,q=null,o=null,r=null,t=null,u=null,w=/[^%|in|cm|mm|em|ex|pt|pc|px]/gi,v={inQuad:function(a,f,b,c){return b*(a/=c)*a+f},outQuad:function(a,f,b,c){return-b*(a/=c)*(a-2)+f},inOutQuad:function(a,f,b,c){if((a/=
c/2)<1)return b/2*a*a+f;return-b/2*(--a*(a-2)-1)+f},inCubic:function(a,b,c,d){return c*(a/=d)*a*a+b},outCubic:function(a,b,c,d){return c*((a=a/d-1)*a*a+1)+b},inOutCubic:function(a,b,c,d){if((a/=d/2)<1)return c/2*a*a*a+b;return c/2*((a-=2)*a*a+2)+b},inQuart:function(a,b,c,d){return c*(a/=d)*a*a*a+b},outQuart:function(a,b,c,d){return-c*((a=a/d-1)*a*a*a-1)+b},inOutQuart:function(a,b,c,d){if((a/=d/2)<1)return c/2*a*a*a*a+b;return-c/2*((a-=2)*a*a*a-2)+b},inQuint:function(a,b,c,d){return c*(a/=d)*a*a*a*
a+b},outQuint:function(a,b,c,d){return c*((a=a/d-1)*a*a*a*a+1)+b},inOutQuint:function(a,b,c,d){if((a/=d/2)<1)return c/2*a*a*a*a*a+b;return c/2*((a-=2)*a*a*a*a+2)+b},inSine:function(a,b,c,d){return-c*Math.cos(a/d*(Math.PI/2))+c+b},outSine:function(a,b,c,d){return c*Math.sin(a/d*(Math.PI/2))+b},inOutSine:function(a,b,c,d){return-c/2*(Math.cos(Math.PI*a/d)-1)+b},inExpo:function(a,b,c,d){return a===0?b:c*Math.pow(2,10*(a/d-1))+b},outExpo:function(a,b,c,d){return a===d?b+c:c*(-Math.pow(2,-10*a/d)+1)+b},
inOutExpo:function(a,b,c,d){if(a===0)return b;else if(a===d)return b+c;else if((a/=d/2)<1)return c/2*Math.pow(2,10*(a-1))+b;return c/2*(-Math.pow(2,-10*--a)+2)+b},inCirc:function(a,b,c,d){return-c*(Math.sqrt(1-(a/=d)*a)-1)+b},outCirc:function(a,b,c,d){return c*Math.sqrt(1-(a=a/d-1)*a)+b},inOutCirc:function(a,b,c,d){if((a/=d/2)<1)return-c/2*(Math.sqrt(1-a*a)-1)+b;return c/2*(Math.sqrt(1-(a-=2)*a)+1)+b},inElastic:function(a,b,c,d,i,e){var g=null;if(a===0)return b;else if((a/=d)===1)return b+c;e||(e=
d*0.3);i<Math.abs(c)?(i=c,g=e/4):(i=Math.abs(c),g=e/(2*Math.PI)*Math.asin(c/i));return-(i*Math.pow(2,10*(a-=1))*Math.sin((a*d-g)*2*Math.PI/e))+b},outElastic:function(a,b,c,d,e,g){var k=null;if(a===0)return b;else if((a/=d)===1)return b+c;else g||(g=d*0.3);e<Math.abs(c)?(e=c,k=g/4):(e=Math.abs(c),k=g/(2*Math.PI)*Math.asin(c/e));return e*Math.pow(2,-10*a)*Math.sin((a*d-k)*2*Math.PI/g)+c+b},inOutElastic:function(a,b,c,d,e,g){var k=null;if(a===0)return b;else if((a/=d/2)===2)return b+c;else g||(g=d*0.3*
1.5);e<Math.abs(c)?(e=c,k=g/4):(e=Math.abs(c),k=g/(2*Math.PI)*Math.asin(c/e));if(a<1)return-0.5*e*Math.pow(2,10*(a-=1))*Math.sin((a*d-k)*2*Math.PI/g)+b;return e*Math.pow(2,-10*(a-=1))*Math.sin((a*d-k)*2*Math.PI/g)*0.5+c+b},inBack:function(a,b,c,d,e){typeof e==="undefined"&&(e=1.70158);return c*(a/=d)*a*((e+1)*a-e)+b},outBack:function(a,b,c,d,e){typeof e==="undefined"&&(e=1.70158);return c*((a=a/d-1)*a*((e+1)*a+e)+1)+b},inOutBack:function(a,b,c,d,e){typeof e==="undefined"&&(e=1.70158);if((a/=d/2)<
1)return c/2*a*a*(((e*=1.525)+1)*a-e)+b;return c/2*((a-=2)*a*(((e*=1.525)+1)*a+e)+2)+b},inBounce:function(a,b,c,d){return c-this.outBounce(d-a,0,c,d)+b},outBounce:function(a,b,c,d){return(a/=d)<1/2.75?c*7.5625*a*a+b:a<2/2.75?c*(7.5625*(a-=1.5/2.75)*a+0.75)+b:a<2.5/2.75?c*(7.5625*(a-=2.25/2.75)*a+0.9375)+b:c*(7.5625*(a-=2.625/2.75)*a+0.984375)+b},inOutBounce:function(a,b,c,d){if(a<d/2)return this.inBounce(a*2,0,c,d)*0.5+b;return this.outBounce(a*2-d,0,c,d)*0.5+c*0.5+b},linear:function(a,b,c,d){return b+
a*(c/d)}};b=b?b:600;c=c?c:"outQuad";this.each(function(b,c){c.toLowerCase().indexOf("color")!==-1&&(a[c]=m.color.toArray(b))},a);this.each(function(e){r=m.find(e);r.data("SparkOffset")===!1&&r.data("SparkOffset",0);if(r.data("SparkOffset")>0)return l(r,a,b,c),!1;r.data("SparkOffset",r.data("SparkOffset")+b);n(r,b);m.each(function(a,e){k=typeof a==="string"?a.replace(w,""):"";a instanceof Array?(p=m.color.toArray(r.style(e)),g=[a[0]-p[0],a[1]-p[1],a[2]-p[2]]):(a=parseFloat(a),u=r.style(e),p=u!==""&&
typeof u==="string"?parseFloat(r.style(e)):typeof u==="number"?u:e==="opacity"?1:0,g=a-p);o=b/20;for(q=1;q<=o;q++)a instanceof Array?(t=m.color.toRgb([Math.floor(v[c](q,p[0],g[0],o)),Math.floor(v[c](q,p[1],g[1],o)),Math.floor(v[c](q,p[2],g[2],o))]),d(r,e,t,q*20)):(t=v[c](q,p,g,o)+k,d(r,e,t.replace(w,"").length===0?parseFloat(t):t,q*20))},a)});typeof e==="function"&&setTimeout(e,b);return this});
Spark.extend("hide",function(){var a=this.clone();this.each(function(b){a.find(b).style("display")!=="none"&&a.find(b).data("SparkDisplayType",a.find(b).style("display")).style("display","none")});return this});Spark.extend("show",function(){var a=this.clone();this.each(function(b){a.find(b).style("display",a.find(b).data("SparkDisplayType"))});return this});
Spark.extend("color",{toArray:function(a){var b=null,c=[],e=this.names;if(a instanceof Array)return a;else if(a.indexOf("rgb")===0)c=a.replace(/rgb\(|\)|\s/gi,"").split(",");else if(a.indexOf("#")===0){a=a.slice(1);a.length===3&&(a=a.replace(/([0-9a-f])/ig,"$1$1"));for(b=0;b<3;b++)c.push(parseInt(a.slice(b*2,(b+1)*2),16))}else for(b in e)e.hasOwnProperty(b)&&b===a.toLowerCase()&&(c=[e[b][0],e[b][1],e[b][2]]);for(b=0;b<3;b++)c[b]=parseInt(c[b],10);return c},toRgb:function(a){return"rgb("+this.toArray(a).join(", ")+
")"},toHex:function(a){var b=null;a=this.toArray(a);for(b=0;b<3;b++)a[b]=a[b].toString(16).toUpperCase(),a[b].length===1&&(a[b]+=a[b]);return"#"+a.join("")},toName:function(a){var b=null,c=this.names;a=this.toArray(a);for(b in c)if(c.hasOwnProperty(b)&&a[0]===c[b][0]&&a[1]===c[b][1]&&a[2]===c[b][2])return b;return!1},names:{aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,
235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,
50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,
128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,
160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,216],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,
21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[216,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,
230],purple:[128,0,128],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,
130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment