Skip to content

Instantly share code, notes, and snippets.

@Olical
Created May 3, 2011 11:00
Show Gist options
  • Save Olical/953163 to your computer and use it in GitHub Desktop.
Save Olical/953163 to your computer and use it in GitHub Desktop.
Yet another pre release for Spark v3.0.0
/*
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 d=this.initialise();b&&(a+="?"+this.buildParameterString(b));
c&&this.handleCallback(d,c);d.open("GET",a,typeof c==="function");d.send();if(!c)return d.status===200?d.responseText:!1},post:function(a,b,c){var d=this.initialise();c&&this.handleCallback(d,c);d.open("POST",a,typeof c==="function");d.setRequestHeader("Content-type","application/x-www-form-urlencoded");b?d.send(this.buildParameterString(b)):d.send();if(!c)return d.status===200?d.responseText:!1},getJSON:function(a,b,c){var d=!1;c&&(d=this.buildParameterString(c));this.instance.load(a+"?callback="+
b+(d?"&"+d:""))}});Spark.extend("cookie",function(a,b,c){var d=document.cookie.split(";"),e=null,j=null;e=new Date;if(typeof b==="undefined"){for(e=0;e<d.length;e++)if(j=d[e].replace(/^\s+/g,""),j.indexOf(a+"=")===0)return j.substring(a.length+1,j.length);return!1}else typeof c!=="undefined"?(e.setTime(e.getTime()+c),expires="; expires="+e.toGMTString()):expires="",document.cookie=a+"="+escape(b)+expires+"; path=/"});
Spark.extend("find",function(a,b){function c(a){var b=[],c=a.length,d=null,h=null;for(h=0;h<c;h++){for(d=h+1;d<c;d++)a[h]===a[d]&&(d=++h);b.push(a[h])}return b}function d(a,b){var d=a.split(/\s*,\s*/g),h=null,j=Spark.clone(),e=null,g=null,i=null,s=[],f=null;h=null;g=["^\\[([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 l=[];for(e=0;e<g.length;e++)l.push({search:RegExp(g[e],"i"),remove:RegExp(g[e]+".*","i")});for(e=0;e<d.length;e++){g=d[e].replace(/(>|\+)/g," $1 ").replace(/\s+(>|\+)\s+/g," $1");f=null;h=[];h=[];i=!1;for(f=0;f<g.length;f++)g.indexOf("'",f)===f||g.indexOf('"',f)===f?i===!0?i=!1:i===!1&&(i=!0):g.indexOf(" ",f)===f&&i===!0&&h.push(f);for(f=0;f<h.length;f++)g=g.substr(0,h[f]+f)+"\\s"+g.substr(h[f]+1+f);h=g.split(/\s+/g);for(f=0;f<h.length;f++)h[f]=h[f].replace(/\\s/g,
" ");f=[];for(g=0;g<h.length;g++){i=h[g];for(f.push({});i.length>0;){if(i.indexOf(">")===0)f[g].child=!0,i=i.substr(1);else if(i.indexOf("+")===0)f[g].sibling=!0,i=i.substr(1);if(i.match(l[5].search)){if(typeof f[g].whiteSpaceAttribute==="undefined")f[g].whiteSpaceAttribute={};f[g].whiteSpaceAttribute[i.replace(l[5].remove,"$1")]=i.replace(l[5].remove,"$2");i=i.replace(l[5].search,"")}else if(i.match(l[6].search)){if(typeof f[g].hyphenAttribute==="undefined")f[g].hyphenAttribute={};f[g].hyphenAttribute[i.replace(l[6].remove,
"$1")]=i.replace(l[6].remove,"$2");i=i.replace(l[6].search,"")}else if(i.match(l[0].search)){if(typeof f[g].attribute==="undefined")f[g].attribute={};f[g].attribute[i.replace(l[0].remove,"$1")]=i.replace(l[0].remove,"$2");i=i.replace(l[0].search,"")}else if(i.match(l[1].search)){if(typeof f[g].attribute==="undefined")f[g].attribute={};f[g].attribute[i.replace(l[1].remove,"$1")]=!0;i=i.replace(l[1].search,"")}else if(i.match(l[2].search)){if(typeof f[g].tag==="undefined")f[g].tag=i.replace(l[2].remove,
"$1");else{if(typeof f[g].tag==="string")f[g].tag=[f[g].tag];f[g].tag.push(i.replace(l[2].remove,"$1"))}i=i.replace(l[2].search,"")}else if(i.match(l[3].search)){if(typeof f[g].id==="undefined")f[g].id=i.replace(l[3].remove,"$1");else{if(typeof f[g].id==="string")f[g].id=[f[g].id];f[g].id.push(i.replace(l[3].remove,"$1"))}i=i.replace(l[3].search,"")}else if(i.match(l[4].search)){if(typeof f[g].classes==="undefined")f[g].classes=i.replace(l[4].remove,"$1");else{if(typeof f[g].classes==="string")f[g].classes=
[f[g].classes];f[g].classes.push(i.replace(l[4].remove,"$1"))}i=i.replace(l[4].search,"")}else if(i.match(l[7].search))f[g].first=!0,i=i.replace(l[7].search,"");else if(i.match(l[8].search))f[g].lang=i.replace(l[8].remove,"$1"),i=i.replace(l[8].search,"");else return!1}}h=b;for(g=0;g<f.length;g++)h=h.find(f[g]);s=s.concat(h.elements)}s=c(s);for(e=0;e<s.length;e++)j[e]=s[e];j.elements=s;j.length=s.length;return j}function e(a,b,c,d,h){var e=null,g=null;g=a instanceof Array?a.join(" "):!1;if(typeof b===
"string")if(g)return g.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(e=0;e<b.length;e++)if(g){if(g.match(RegExp("(^| )"+b[e]+"($| )","g")))return!0}else if((c?a.toUpperCase():a)===(c?b[e].toUpperCase():b[e]))return!0;return!1}else{if(typeof b==="object")for(e in b)if(b.hasOwnProperty(e))if(b[e]===!0){if(a.getAttribute(e)===null)return!1}else if(a.getAttribute(e)!==null)if(typeof b[e]===
"string")if(h){if(a.getAttribute(e)!==b[e]&&a.getAttribute(e).indexOf(b[e]+"-")!==0)return!1}else if(d){if(a.getAttribute(e)!==b[e]&&a.getAttribute(e).indexOf(b[e]+" ")!==0)return!1}else{if(a.getAttribute(e)!==b[e])return!1}else{if(b[e]instanceof Array)for(g=0;g<b[e].length;g++)if(h){if(a.getAttribute(e)!==b[e][g]&&a.getAttribute(e).indexOf(b[e][g]+"-")!==0)return!1}else if(d){if(a.getAttribute(e)!==b[e][g]&&a.getAttribute(e).indexOf(b[e][g]+" ")!==0)return!1}else if(a.getAttribute(e)!==b[e][g])return!1}else return!1;
return!0}}function j(a,b,c,e,d,j){var g=null,i=[];if(typeof a==="string"){g=e===!0?b.parentNode.getElementsByTagName(a):b.getElementsByTagName(a);for(h=0;h<g.length;h++)d===!0&&g[h]===(g[h].parentNode.firstElementChild||g[h].parentNode.firstChild)?c===!0&&g[h].parentNode===b?i.push(g[h]):e===!0&&(g[h]===b.nextElementSibling||g[h]===b.nextSibling)?i.push(g[h]):!c&&!e&&i.push(g[h]):d||(c===!0&&g[h].parentNode===b?i.push(g[h]):e===!0&&(g[h]===b.nextElementSibling||g[h]===b.nextSibling)?i.push(g[h]):
!c&&!e&&i.push(g[h]))}else if(a instanceof Array)for(k=0;k<a.length;k++){g=e===!0?b.parentNode.getElementsByTagName(a[k]):b.getElementsByTagName(a[k]);for(h=0;h<g.length;h++)c===!0&&g[h].parentNode===b?i.push(g[h]):e===!0&&(g[h]===b.nextElementSibling||g[h]===b.nextSibling)?i.push(g[h]):!c&&!e&&i.push(g[h])}else{g=e===!0?b.parentNode.getElementsByTagName("*"):b.getElementsByTagName("*");for(h=0;h<g.length;h++)c===!0&&g[h].parentNode===b?i.push(g[h]):e===!0&&(g[h]===b.nextElementSibling||g[h]===b.nextSibling)?
i.push(g[h]):!c&&!e&&i.push(g[h])}if(j){a=null;b=[];c=null;for(c=0;c<i.length;c++)for(a=i[c];a.parentNode;){if(a.getAttribute("lang")===j){b.push(i[c]);break}a=a.parentNode}j=b}else j=i;return j}var n=[],m=[],r=typeof b!=="undefined"?b:document,k=null,h=null,t=null;t=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++){t=j(a.tag,this.elements[k],a.child,a.sibling,a.first,a.lang);for(h=0;h<t.length;h++)n.push(t[h])}else n=j(a.tag,r,a.child,a.sibling,a.first,a.lang);if(typeof a==="string")return d(a,this);for(k=0;k<n.length;k++)h=n[k],t=h.className.split(/\s+/g),e(h.nodeName,a.tag,!0)&&e(t,a.classes)&&e(h.id,a.id)&&e(h,a.attribute)&&e(h,a.whiteSpaceAttribute,!1,!0)&&e(h,a.hyphenAttribute,!1,!1,!0)&&m.push(h);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,d=null;if(typeof b==="undefined")if(typeof this.elements==="undefined")return!1;else d=this.elements;else typeof b==="object"&&(d=b);if(typeof d.length==="number")for(c=0;c<d.length;c++)a(d[c],c);else for(c in d)d.hasOwnProperty(c)===!0&&a(d[c],c);return this});Spark.extend("dataMeta",{keys:[],data:[]});
Spark.extend("data",function(a,b){var c=null,d=null,e=null;if(this.elements instanceof Array&&typeof this.elements[0]==="object"){d=this.elements[0];e=-1;if(typeof this.dataMeta.keys.indexOf!=="undefined")e=this.dataMeta.keys.indexOf(d);else for(c=0;c<this.dataMeta.keys.length;c++)this.dataMeta.keys[c]===d&&(e=c);if(typeof b!=="undefined"){if(e===-1)e=this.dataMeta.keys.length,this.dataMeta.keys.push(d),this.dataMeta.data.push({});this.dataMeta.data[e][a]=b;return this}else{if(e===-1)return!1;return typeof this.dataMeta.data[e][a]!==
"undefined"?this.dataMeta.data[e][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 d(a){return a.replace(/([A-Z])/g,function(a){return"-"+a.toLowerCase()})}function e(a,b,e){var d=null;b=c(b);e=typeof e==="number"&&!RegExp("(^|\\s)"+b+"($|\\s)","i").test("zIndex fontWeight opacity zoom lineHeight scrollTop scrollLeft")?e+"px":e;b==="scrollTop"||b==="scrollLeft"?a[b]=e:a.style[b]=e;if(b==="opacity")a.style.zoom="1",a.style.filter=
"alpha(opacity="+parseFloat(e)*100+")",a.style.MozOpacity=e,a.style.KhtmlOpacity=e}function j(a,b){var c=null;if(b==="scrollTop"||b==="scrollLeft")return a[b];(c=typeof getComputedStyle!=="undefined"?document.defaultView.getComputedStyle(a,null).getPropertyValue(d(b)):a.currentStyle[b])||(c=a.style[b]);!c&&c!==0&&(c=b==="opacity"?"1":"0");b.toLowerCase().indexOf("color")!==-1&&(c=r.color.toRgb(c));return c}var n=null,m=null,r=this,k=null;if(typeof a==="string")if(typeof b==="string"||typeof b==="number")for(n=
0;n<this.length;n++)e(this[n],a,b);else if(a==="padding"||a==="margin"){k=[j(this[0],c(a+"Top")),j(this[0],c(a+"Bottom")),j(this[0],c(a+"Left"))];for(n=1;n<2;n++)if(k[0]!==k[n])return"";return k[0]}else return j(this[0],c(a));else if(typeof a==="object")for(m in a)if(a.hasOwnProperty(m))for(n=0;n<this.length;n++)e(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 d(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 e=null,j="",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(e=0;e<a.length;e++)j+=this.stringify(a[e])+",";return c("["+
j.slice(0,j.length-1)+"]")}else if(typeof a==="object"){for(e in a)a.hasOwnProperty(e)&&(j+=this.stringify(a[e],e)+",");return c("{"+j.slice(0,j.length-1)+"}")}else return typeof a==="string"?c(d(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(d){if(!c.find(d).hasClass(a))b=c.find(d).attribute("class"),d.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 d(a){if(c)a.cancelBubble=!0,a.stopPropagation&&a.stopPropagation();var e=b,d=null,r=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;d=a.target;if(d.offsetParent&&
navigator.userAgent.indexOf("Opera")===-1&&navigator.userAgent.indexOf("MSIE")===-1){do d=d.offsetParent,r+=d.offsetLeft,k+=d.offsetTop;while(d.offsetParent);a.offsetX=r;a.offsetY=k}if(e(a)===!1)a.preventDefault?a.preventDefault():a.returnValue=!1}var e=this;this.each(function(c){e.find(c).data("SparkEvents")||e.find(c).data("SparkEvents",[]);e.find(c).data("SparkEvents").push({type:a,fn:b,reference:d});c.addEventListener?c.addEventListener(a,d,!1):c.attachEvent("on"+a,d)});return this});
Spark.extend("removeEvent",function(a,b){var c=this;this.each(function(d){c.find(d).data("SparkEvents")&&c.each(function(c){c.fn===b&&c.type===a&&(d.removeEventListener?d.removeEventListener(a,c.reference,!1):d.detachEvent("on"+a,c.reference))},c.find(d).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,d){a=document.createElement(a);if(b)a.innerHTML=b;c&&this.find(a).attribute(c);d&&this.find(a).style(d);return a});
Spark.extend("insertElement",function(a,b,c,d){var e=null;e=typeof a==="string"?this.createElement(a,b,c,d):a;this.each(function(a){a.appendChild(e.cloneNode(!0))});return this});Spark.extend("prependElement",function(a,b,c,d){var e=null;e=typeof a==="string"?this.createElement(a,b,c,d):a;this.each(function(a){a.parentNode.insertBefore(e.cloneNode(!0),a)});return this});
Spark.extend("appendElement",function(a,b,c,d){var e=null;e=typeof a==="string"?this.createElement(a,b,c,d):a;this.each(function(a){a.parentNode.insertBefore(e.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(d){b?d[c]+=a:d[c]=a});return this});
Spark.extend("animate",function(a,b,c,d){function e(a,b,c,f){a.data("SparkTimeouts").push(setTimeout(function(){a.style(b,c)},f))}function j(a,b,c){b.data("SparkTimeouts").push(setTimeout(function(){a&&a();b.data("SparkAnimations").shift();n(b)},c))}function n(a){o=a.data("SparkAnimations");if(o.length>0&&o[0].running===!1)p=o[0],p.running=!0,m.each(function(b,c){w=typeof b==="string"?b.replace(t,""):0;b instanceof Array?(q=m.color.toArray(a.style(c)),u=[b[0]-q[0],b[1]-q[1],b[2]-q[2]]):(q=parseFloat(a.style(c)),
b=parseFloat(b),u=b-q);for(k=1;k<=p.frames;k++)x=b instanceof Array?m.color.toRgb([Math.floor(v[p.easing](k,q[0],u[0],p.frames)),Math.floor(v[p.easing](k,q[1],u[1],p.frames)),Math.floor(v[p.easing](k,q[2],u[2],p.frames))]):v[p.easing](k,q,u,p.frames)+w,e(a,c,x,k*(1E3/r))},p.animations),j(p.callback,a,p.timeframe)}var m=this,r=50,k=null,h=null,t=/[\d\.\-]/g,o=null,q=null,w=null,x=null,u=null,p=null,v={inQuad:function(a,b,c,f){return c*(a/=f)*a+b},outQuad:function(a,b,c,f){return-c*(a/=f)*(a-2)+b},
inOutQuad:function(a,b,c,f){if((a/=f/2)<1)return c/2*a*a+b;return-c/2*(--a*(a-2)-1)+b},inCubic:function(a,b,c,f){return c*(a/=f)*a*a+b},outCubic:function(a,b,c,f){return c*((a=a/f-1)*a*a+1)+b},inOutCubic:function(a,b,c,f){if((a/=f/2)<1)return c/2*a*a*a+b;return c/2*((a-=2)*a*a+2)+b},inQuart:function(a,b,c,f){return c*(a/=f)*a*a*a+b},outQuart:function(a,b,c,f){return-c*((a=a/f-1)*a*a*a-1)+b},inOutQuart:function(a,b,c,f){if((a/=f/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,f){return c*(a/=f)*a*a*a*a+b},outQuint:function(a,b,c,f){return c*((a=a/f-1)*a*a*a*a+1)+b},inOutQuint:function(a,b,c,f){if((a/=f/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,f){return-c*Math.cos(a/f*(Math.PI/2))+c+b},outSine:function(a,b,c,f){return c*Math.sin(a/f*(Math.PI/2))+b},inOutSine:function(a,b,c,f){return-c/2*(Math.cos(Math.PI*a/f)-1)+b},inExpo:function(a,b,c,f){return a===0?b:c*Math.pow(2,10*(a/f-1))+b},outExpo:function(a,b,c,f){return a===f?b+c:
c*(-Math.pow(2,-10*a/f)+1)+b},inOutExpo:function(a,b,c,f){if(a===0)return b;else if(a===f)return b+c;else if((a/=f/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,f){return-c*(Math.sqrt(1-(a/=f)*a)-1)+b},outCirc:function(a,b,c,f){return c*Math.sqrt(1-(a=a/f-1)*a)+b},inOutCirc:function(a,b,c,f){if((a/=f/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,f,e,d){var h=null;if(a===0)return b;else if((a/=
f)===1)return b+c;d||(d=f*0.3);e<Math.abs(c)?(e=c,h=d/4):(e=Math.abs(c),h=d/(2*Math.PI)*Math.asin(c/e));return-(e*Math.pow(2,10*(a-=1))*Math.sin((a*f-h)*2*Math.PI/d))+b},outElastic:function(a,b,c,f,e,d){var h=null;if(a===0)return b;else if((a/=f)===1)return b+c;else d||(d=f*0.3);e<Math.abs(c)?(e=c,h=d/4):(e=Math.abs(c),h=d/(2*Math.PI)*Math.asin(c/e));return e*Math.pow(2,-10*a)*Math.sin((a*f-h)*2*Math.PI/d)+c+b},inOutElastic:function(a,b,c,e,d,h){var j=null;if(a===0)return b;else if((a/=e/2)===2)return b+
c;else h||(h=e*0.3*1.5);d<Math.abs(c)?(d=c,j=h/4):(d=Math.abs(c),j=h/(2*Math.PI)*Math.asin(c/d));if(a<1)return-0.5*d*Math.pow(2,10*(a-=1))*Math.sin((a*e-j)*2*Math.PI/h)+b;return d*Math.pow(2,-10*(a-=1))*Math.sin((a*e-j)*2*Math.PI/h)*0.5+c+b},inBack:function(a,b,c,e,d){typeof d==="undefined"&&(d=1.70158);return c*(a/=e)*a*((d+1)*a-d)+b},outBack:function(a,b,c,e,d){typeof d==="undefined"&&(d=1.70158);return c*((a=a/e-1)*a*((d+1)*a+d)+1)+b},inOutBack:function(a,b,c,e,d){typeof d==="undefined"&&(d=1.70158);
if((a/=e/2)<1)return c/2*a*a*(((d*=1.525)+1)*a-d)+b;return c/2*((a-=2)*a*(((d*=1.525)+1)*a+d)+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)}};this.each(function(b,c){c.toLowerCase().indexOf("color")!==-1&&(a[c]=m.color.toArray(b))},a);this.each(function(e,i){h=m.find(e);h.data("SparkAnimations")===!1&&h.data("SparkAnimations",[]);h.data("SparkTimeouts")===!1&&h.data("SparkTimeouts",[]);b=b?b:600;h.data("SparkAnimations").push({animations:a,timeframe:b,frames:b/(1E3/r),easing:c?c:"outQuad",callback:d&&i===m.length-1?d:!1,running:!1});n(h)});return this});
Spark.extend("hide",function(a,b){var c=this;typeof a==="string"?typeof this.transitions.hide[a]==="function"?this.each(function(d){c.transitions.hide[a](c.find(d),b)}):this.hide():this.each(function(a){c.find(a).style("display")!=="none"&&c.find(a).data("SparkDisplayType",c.find(a).style("display")).style("display","none")});return this});
Spark.extend("show",function(a,b){var c=this;typeof a==="string"?typeof this.transitions.show[a]==="function"?this.each(function(d){c.transitions.show[a](c.find(d),b)}):this.show():this.each(function(a){c.find(a).style("display",c.find(a).data("SparkDisplayType"))});return this});
Spark.extend("color",{toArray:function(a){var b=null,c=[],d=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 d)d.hasOwnProperty(b)&&b===a.toLowerCase()&&(c=[d[b][0],d[b][1],d[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]}});Spark.extend("stop",function(){var a=this,b=null;this.each(function(c){b=a.find(c);b.data("SparkTimeouts")&&b.data("SparkAnimations")&&(a.each(function(a){clearTimeout(a)},b.data("SparkTimeouts")),b.data("SparkTimeouts",[]),b.data("SparkAnimations",[]))});return this});
Spark.extend("toggle",function(){var a=this,b=null;this.each(function(c){b=a.find(c);b.style("display")==="none"?b.show():b.hide()});return this});
Spark.extend("transitions",{show:{fade:function(a,b){var c=a.show().style("opacity");a.style("opacity",0).animate({opacity:c},!1,!1,function(){b&&b()})},slide:function(a,b){var c=a.show().style("height"),d=a.style("overflow")||"visible";a.style({height:0,overflow:"hidden"}).animate({height:c},!1,!1,function(){a.style("overflow",d);b&&b()})},smooth:function(a,b){var c=a.show().style("height"),d=a.style("width"),e=a.style("opacity"),j=a.style("overflow")||"visible";a.style({height:0,width:0,opacity:0,
overflow:"hidden"}).animate({height:c,width:d,opacity:e},!1,!1,function(){a.style("overflow",j);b&&b()})}},hide:{fade:function(a,b){var c=a.style("opacity");a.animate({opacity:0},!1,!1,function(){a.style("opacity",c).hide();b&&b()})},slide:function(a,b){var c=a.style("height"),d=a.style("overflow")||"visible";a.style("overflow","hidden").animate({height:0},!1,!1,function(){a.style({height:c,overflow:d}).hide();b&&b()})},smooth:function(a,b){var c=a.style("height"),d=a.style("width"),e=a.style("opacity"),
j=a.style("overflow")||"visible";a.style("overflow","hidden").animate({height:0,width:0,opacity:0},!1,!1,function(){a.style({height:c,width:d,opacity:e,overflow:j}).hide();b&&b()})}}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment