mirror of
https://github.com/RustyRaptor/CanvasLoader.git
synced 2026-12-03 17:55:15 -07:00
Major bugfix in constructor
- The options parameter wasn't checked and handled properly in the constructor, this issue is now fixed, - Minified file and documentation is updated
This commit is contained in:
1 parent
4887e28697
commit
fb007fcfba
3 files changed
+14
-12
No files matched your search
@@ -97,6 +97,7 @@
|
||||
<span class="cm"> * <li><strong>safeVML (Boolean):</strong> If set to true, the amount of CanvasLoader shapes are limited in VML mode. It prevents CPU overkilling when rendering loaders with high density. The default value is true.</li></span>
|
||||
<span class="cm"> **/</span>
|
||||
<span class="kd">var</span> <span class="nx">CanvasLoader</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">id</span><span class="p">,</span> <span class="nx">opt</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span><span class="p">(</span><span class="nx">opt</span><span class="p">)</span> <span class="o">==</span> <span class="s2">"undefined"</span><span class="p">)</span> <span class="p">{</span> <span class="nx">opt</span> <span class="o">=</span> <span class="p">{};</span> <span class="p">}</span>
|
||||
<span class="k">this</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span><span class="nx">id</span><span class="p">,</span> <span class="nx">opt</span><span class="p">);</span>
|
||||
<span class="p">},</span> <span class="nx">p</span> <span class="o">=</span> <span class="nx">CanvasLoader</span><span class="p">.</span><span class="nx">prototype</span><span class="p">,</span> <span class="nx">engine</span><span class="p">,</span> <span class="nx">engines</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"canvas"</span><span class="p">,</span> <span class="s2">"vml"</span><span class="p">],</span> <span class="nx">shapes</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"oval"</span><span class="p">,</span> <span class="s2">"spiral"</span><span class="p">,</span> <span class="s2">"square"</span><span class="p">,</span> <span class="s2">"rect"</span><span class="p">,</span> <span class="s2">"roundRect"</span><span class="p">],</span> <span class="nx">cRX</span> <span class="o">=</span> <span class="sr">/^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/</span><span class="p">,</span> <span class="nx">ie8</span> <span class="o">=</span> <span class="nx">navigator</span><span class="p">.</span><span class="nx">appVersion</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s2">"MSIE"</span><span class="p">)</span> <span class="o">!==</span> <span class="o">-</span><span class="mi">1</span> <span class="o">&&</span> <span class="nb">parseFloat</span><span class="p">(</span><span class="nx">navigator</span><span class="p">.</span><span class="nx">appVersion</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">"MSIE"</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span> <span class="o">===</span> <span class="mi">8</span> <span class="o">?</span> <span class="kc">true</span> <span class="o">:</span> <span class="kc">false</span><span class="p">,</span> <span class="nx">canSup</span> <span class="o">=</span> <span class="o">!!</span><span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s1">'canvas'</span><span class="p">).</span><span class="nx">getContext</span><span class="p">,</span> <span class="nx">safeDensity</span> <span class="o">=</span> <span class="mi">40</span><span class="p">,</span> <span class="nx">safeVML</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span>
|
||||
<span class="cm">/**</span>
|
||||
@@ -515,7 +516,7 @@
|
||||
<span class="k">if</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">shape</span> <span class="o">===</span> <span class="nx">shapes</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span> <span class="p">{</span>
|
||||
<span class="nx">c</span><span class="p">.</span><span class="nx">fillRect</span><span class="p">(</span><span class="nx">x</span><span class="p">,</span> <span class="nx">y</span> <span class="o">-</span> <span class="nx">h</span> <span class="o">*</span> <span class="mf">0.5</span><span class="p">,</span> <span class="nx">w</span><span class="p">,</span> <span class="nx">h</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
|
||||
<span class="nx">rad</span> <span class="o">=</span> <span class="nx">h</span> <span class="o">*</span> <span class="mf">0.2</span><span class="p">;</span>
|
||||
<span class="nx">rad</span> <span class="o">=</span> <span class="nx">h</span> <span class="o">*</span> <span class="mf">0.55</span><span class="p">;</span>
|
||||
<span class="nx">c</span><span class="p">.</span><span class="nx">moveTo</span><span class="p">(</span><span class="nx">x</span> <span class="o">+</span> <span class="nx">rad</span><span class="p">,</span> <span class="nx">y</span> <span class="o">-</span> <span class="nx">h</span> <span class="o">*</span> <span class="mf">0.5</span><span class="p">);</span>
|
||||
<span class="nx">c</span><span class="p">.</span><span class="nx">lineTo</span><span class="p">(</span><span class="nx">x</span> <span class="o">+</span> <span class="nx">w</span> <span class="o">-</span> <span class="nx">rad</span><span class="p">,</span> <span class="nx">y</span> <span class="o">-</span> <span class="nx">h</span> <span class="o">*</span> <span class="mf">0.5</span><span class="p">);</span>
|
||||
<span class="nx">c</span><span class="p">.</span><span class="nx">quadraticCurveTo</span><span class="p">(</span><span class="nx">x</span> <span class="o">+</span> <span class="nx">w</span><span class="p">,</span> <span class="nx">y</span> <span class="o">-</span> <span class="nx">h</span> <span class="o">*</span> <span class="mf">0.5</span><span class="p">,</span> <span class="nx">x</span> <span class="o">+</span> <span class="nx">w</span><span class="p">,</span> <span class="nx">y</span> <span class="o">-</span> <span class="nx">h</span> <span class="o">*</span> <span class="mf">0.5</span> <span class="o">+</span> <span class="nx">rad</span><span class="p">);</span>
|
||||
|
||||
Vendored
+10
-10
@@ -1,12 +1,12 @@
|
||||
(function(w){var k=function(b,c){this.init(b,c)},a=k.prototype,o,p=["canvas","vml"],h=["oval","spiral","square","rect","roundRect"],x=/^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,v=navigator.appVersion.indexOf("MSIE")!==-1&&parseFloat(navigator.appVersion.split("MSIE")[1])===8?true:false,y=!!document.createElement("canvas").getContext,q=true,n=function(b,c,a){var b=document.createElement(b),d;for(d in a)b[d]=a[d];typeof c!=="undefined"&&c.appendChild(b);return b},m=function(b,c){for(var a in c)b.style[a]=
|
||||
c[a];return b},t=function(b,c){for(var a in c)b.setAttribute(a,c[a]);return b},u=function(b,c,a,d){b.save();b.translate(c,a);b.rotate(d);b.translate(-c,-a);b.beginPath()};a.init=function(b,c){if(typeof c.safeVML==="boolean")q=c.safeVML;try{this.mum=document.getElementById(b)!==void 0?document.getElementById(b):document.body}catch(a){this.mum=document.body}c.id=typeof c.id!=="undefined"?c.id:"canvasLoader";this.cont=n("div",this.mum,{id:c.id});if(y)o=p[0],this.can=n("canvas",this.cont),this.con=this.can.getContext("2d"),
|
||||
this.cCan=m(n("canvas",this.cont),{display:"none"}),this.cCon=this.cCan.getContext("2d");else{o=p[1];if(typeof k.vmlSheet==="undefined"){document.getElementsByTagName("head")[0].appendChild(n("style"));k.vmlSheet=document.styleSheets[document.styleSheets.length-1];var d=["group","oval","roundrect","fill"],e;for(e in d)k.vmlSheet.addRule(d[e],"behavior:url(#default#VML); position:absolute;")}this.vml=n("group",this.cont)}this.setColor(this.color);this.ready=true;this.draw();m(this.cont,{display:"none"})};
|
||||
a.cont={};a.can={};a.con={};a.cCan={};a.cCon={};a.ready=false;a.timer={};a.activeId=0;a.diameter=40;a.setDiameter=function(b){this.diameter=Math.round(Math.abs(b));this.redraw()};a.getDiameter=function(){return this.diameter};a.cRGB={};a.color="#000000";a.setColor=function(b){this.color=x.test(b)?b:"#000000";this.cRGB=this.getRGB(this.color);this.redraw()};a.getColor=function(){return this.color};a.shape=h[0];a.setShape=function(b){for(var c in h)if(b===h[c]){this.shape=b;this.redraw();break}};a.getShape=
|
||||
function(){return this.shape};a.density=40;a.setDensity=function(b){this.density=q&&o===p[1]?Math.round(Math.abs(b))<=40?Math.round(Math.abs(b)):40:Math.round(Math.abs(b));this.redraw()};a.getDensity=function(){return this.density};a.range=1.3;a.setRange=function(b){this.range=Math.abs(b);this.redraw()};a.getRange=function(){return this.range};a.speed=2;a.setSpeed=function(b){this.speed=Math.round(Math.abs(b));this.reset()};a.getSpeed=function(){return this.speed};a.fps=24;a.setFPS=function(b){this.fps=
|
||||
Math.round(Math.abs(b));this.reset()};a.getFPS=function(){return this.fps};a.getRGB=function(b){b=b.charAt(0)==="#"?b.substring(1,7):b;return{r:parseInt(b.substring(0,2),16),g:parseInt(b.substring(2,4),16),b:parseInt(b.substring(4,6),16)}};a.draw=function(){var b=0,c,a,d,e,g,k,j,r=this.density,s=Math.round(r*this.range),l,i,q=0;i=this.cCon;var f=this.diameter;if(o===p[0]){i.clearRect(0,0,1E3,1E3);t(this.can,{width:f,height:f});for(t(this.cCan,{width:f,height:f});b<r;){l=b<=s?1-1/s*b:l=0;k=360-360/
|
||||
r*b;j=k/180*Math.PI;i.fillStyle="rgba("+this.cRGB.r+","+this.cRGB.g+","+this.cRGB.b+","+l.toString()+")";switch(this.shape){case h[0]:case h[1]:c=f*0.07;e=f*0.5+Math.cos(j)*(f*0.5-c)-f*0.5;g=f*0.5+Math.sin(j)*(f*0.5-c)-f*0.5;i.beginPath();this.shape===h[1]?i.arc(f*0.5+e,f*0.5+g,c*l,0,Math.PI*2,false):i.arc(f*0.5+e,f*0.5+g,c,0,Math.PI*2,false);break;case h[2]:c=f*0.12;e=Math.cos(j)*(f*0.5-c)+f*0.5;g=Math.sin(j)*(f*0.5-c)+f*0.5;u(i,e,g,j);i.fillRect(e,g-c*0.5,c,c);break;case h[3]:case h[4]:a=f*0.3,
|
||||
d=a*0.27,e=Math.cos(j)*(d+(f-d)*0.13)+f*0.5,g=Math.sin(j)*(d+(f-d)*0.13)+f*0.5,u(i,e,g,j),this.shape===h[3]?i.fillRect(e,g-d*0.5,a,d):(c=d*0.2,i.moveTo(e+c,g-d*0.5),i.lineTo(e+a-c,g-d*0.5),i.quadraticCurveTo(e+a,g-d*0.5,e+a,g-d*0.5+c),i.lineTo(e+a,g-d*0.5+d-c),i.quadraticCurveTo(e+a,g-d*0.5+d,e+a-c,g-d*0.5+d),i.lineTo(e+c,g-d*0.5+d),i.quadraticCurveTo(e,g-d*0.5+d,e,g-d*0.5+d-c),i.lineTo(e,g-d*0.5+c),i.quadraticCurveTo(e,g-d*0.5,e+c,g-d*0.5))}i.closePath();i.fill();i.restore();++b}}else{m(this.cont,
|
||||
{width:f,height:f});m(this.vml,{width:f,height:f});switch(this.shape){case h[0]:case h[1]:j="oval";c=140;break;case h[2]:j="roundrect";c=120;break;case h[3]:case h[4]:j="roundrect",c=300}a=d=c;e=500-d;for(g=-d*0.5;b<r;){l=b<=s?1-1/s*b:l=0;k=270-360/r*b;switch(this.shape){case h[1]:a=d=c*l;e=500-c*0.5-c*l*0.5;g=(c-c*l)*0.5;break;case h[0]:case h[2]:v&&(g=0,this.shape===h[2]&&(e=500-d*0.5));break;case h[3]:case h[4]:a=c*0.95,d=a*0.28,v?(e=0,g=500-d*0.5):(e=500-a,g=-d*0.5),q=this.shape===h[4]?0.6:0}i=
|
||||
t(m(n("group",this.vml),{width:1E3,height:1E3,rotation:k}),{coordsize:"1000,1000",coordorigin:"-500,-500"});i=m(n(j,i,{stroked:false,arcSize:q}),{width:a,height:d,top:g,left:e});n("fill",i,{color:this.color,opacity:l});++b}}this.tick(true)};a.clean=function(){if(o===p[0])this.con.clearRect(0,0,1E4,1E4);else{var b=this.vml;if(b.hasChildNodes())for(;b.childNodes.length>=1;)b.removeChild(b.firstChild)}};a.redraw=function(){this.ready&&(this.clean(),this.draw())};a.reset=function(){typeof this.timer===
|
||||
(function(w){var k=function(b,c){typeof c=="undefined"&&(c={});this.init(b,c)},a=k.prototype,o,p=["canvas","vml"],h=["oval","spiral","square","rect","roundRect"],x=/^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,v=navigator.appVersion.indexOf("MSIE")!==-1&&parseFloat(navigator.appVersion.split("MSIE")[1])===8?true:false,y=!!document.createElement("canvas").getContext,q=true,n=function(b,c,a){var b=document.createElement(b),d;for(d in a)b[d]=a[d];typeof c!=="undefined"&&c.appendChild(b);return b},m=function(b,
|
||||
c){for(var a in c)b.style[a]=c[a];return b},t=function(b,c){for(var a in c)b.setAttribute(a,c[a]);return b},u=function(b,c,a,d){b.save();b.translate(c,a);b.rotate(d);b.translate(-c,-a);b.beginPath()};a.init=function(b,c){if(typeof c.safeVML==="boolean")q=c.safeVML;try{this.mum=document.getElementById(b)!==void 0?document.getElementById(b):document.body}catch(a){this.mum=document.body}c.id=typeof c.id!=="undefined"?c.id:"canvasLoader";this.cont=n("div",this.mum,{id:c.id});if(y)o=p[0],this.can=n("canvas",
|
||||
this.cont),this.con=this.can.getContext("2d"),this.cCan=m(n("canvas",this.cont),{display:"none"}),this.cCon=this.cCan.getContext("2d");else{o=p[1];if(typeof k.vmlSheet==="undefined"){document.getElementsByTagName("head")[0].appendChild(n("style"));k.vmlSheet=document.styleSheets[document.styleSheets.length-1];var d=["group","oval","roundrect","fill"],e;for(e in d)k.vmlSheet.addRule(d[e],"behavior:url(#default#VML); position:absolute;")}this.vml=n("group",this.cont)}this.setColor(this.color);this.ready=
|
||||
true;this.draw();m(this.cont,{display:"none"})};a.cont={};a.can={};a.con={};a.cCan={};a.cCon={};a.ready=false;a.timer={};a.activeId=0;a.diameter=40;a.setDiameter=function(b){this.diameter=Math.round(Math.abs(b));this.redraw()};a.getDiameter=function(){return this.diameter};a.cRGB={};a.color="#000000";a.setColor=function(b){this.color=x.test(b)?b:"#000000";this.cRGB=this.getRGB(this.color);this.redraw()};a.getColor=function(){return this.color};a.shape=h[0];a.setShape=function(b){for(var c in h)if(b===
|
||||
h[c]){this.shape=b;this.redraw();break}};a.getShape=function(){return this.shape};a.density=40;a.setDensity=function(b){this.density=q&&o===p[1]?Math.round(Math.abs(b))<=40?Math.round(Math.abs(b)):40:Math.round(Math.abs(b));this.redraw()};a.getDensity=function(){return this.density};a.range=1.3;a.setRange=function(b){this.range=Math.abs(b);this.redraw()};a.getRange=function(){return this.range};a.speed=2;a.setSpeed=function(b){this.speed=Math.round(Math.abs(b));this.reset()};a.getSpeed=function(){return this.speed};
|
||||
a.fps=24;a.setFPS=function(b){this.fps=Math.round(Math.abs(b));this.reset()};a.getFPS=function(){return this.fps};a.getRGB=function(b){b=b.charAt(0)==="#"?b.substring(1,7):b;return{r:parseInt(b.substring(0,2),16),g:parseInt(b.substring(2,4),16),b:parseInt(b.substring(4,6),16)}};a.draw=function(){var b=0,c,a,d,e,g,k,j,r=this.density,s=Math.round(r*this.range),l,i,q=0;i=this.cCon;var f=this.diameter;if(o===p[0]){i.clearRect(0,0,1E3,1E3);t(this.can,{width:f,height:f});for(t(this.cCan,{width:f,height:f});b<
|
||||
r;){l=b<=s?1-1/s*b:l=0;k=360-360/r*b;j=k/180*Math.PI;i.fillStyle="rgba("+this.cRGB.r+","+this.cRGB.g+","+this.cRGB.b+","+l.toString()+")";switch(this.shape){case h[0]:case h[1]:c=f*0.07;e=f*0.5+Math.cos(j)*(f*0.5-c)-f*0.5;g=f*0.5+Math.sin(j)*(f*0.5-c)-f*0.5;i.beginPath();this.shape===h[1]?i.arc(f*0.5+e,f*0.5+g,c*l,0,Math.PI*2,false):i.arc(f*0.5+e,f*0.5+g,c,0,Math.PI*2,false);break;case h[2]:c=f*0.12;e=Math.cos(j)*(f*0.5-c)+f*0.5;g=Math.sin(j)*(f*0.5-c)+f*0.5;u(i,e,g,j);i.fillRect(e,g-c*0.5,c,c);break;
|
||||
case h[3]:case h[4]:a=f*0.3,d=a*0.27,e=Math.cos(j)*(d+(f-d)*0.13)+f*0.5,g=Math.sin(j)*(d+(f-d)*0.13)+f*0.5,u(i,e,g,j),this.shape===h[3]?i.fillRect(e,g-d*0.5,a,d):(c=d*0.55,i.moveTo(e+c,g-d*0.5),i.lineTo(e+a-c,g-d*0.5),i.quadraticCurveTo(e+a,g-d*0.5,e+a,g-d*0.5+c),i.lineTo(e+a,g-d*0.5+d-c),i.quadraticCurveTo(e+a,g-d*0.5+d,e+a-c,g-d*0.5+d),i.lineTo(e+c,g-d*0.5+d),i.quadraticCurveTo(e,g-d*0.5+d,e,g-d*0.5+d-c),i.lineTo(e,g-d*0.5+c),i.quadraticCurveTo(e,g-d*0.5,e+c,g-d*0.5))}i.closePath();i.fill();i.restore();
|
||||
++b}}else{m(this.cont,{width:f,height:f});m(this.vml,{width:f,height:f});switch(this.shape){case h[0]:case h[1]:j="oval";c=140;break;case h[2]:j="roundrect";c=120;break;case h[3]:case h[4]:j="roundrect",c=300}a=d=c;e=500-d;for(g=-d*0.5;b<r;){l=b<=s?1-1/s*b:l=0;k=270-360/r*b;switch(this.shape){case h[1]:a=d=c*l;e=500-c*0.5-c*l*0.5;g=(c-c*l)*0.5;break;case h[0]:case h[2]:v&&(g=0,this.shape===h[2]&&(e=500-d*0.5));break;case h[3]:case h[4]:a=c*0.95,d=a*0.28,v?(e=0,g=500-d*0.5):(e=500-a,g=-d*0.5),q=this.shape===
|
||||
h[4]?0.6:0}i=t(m(n("group",this.vml),{width:1E3,height:1E3,rotation:k}),{coordsize:"1000,1000",coordorigin:"-500,-500"});i=m(n(j,i,{stroked:false,arcSize:q}),{width:a,height:d,top:g,left:e});n("fill",i,{color:this.color,opacity:l});++b}}this.tick(true)};a.clean=function(){if(o===p[0])this.con.clearRect(0,0,1E4,1E4);else{var b=this.vml;if(b.hasChildNodes())for(;b.childNodes.length>=1;)b.removeChild(b.firstChild)}};a.redraw=function(){this.ready&&(this.clean(),this.draw())};a.reset=function(){typeof this.timer===
|
||||
"number"&&(this.hide(),this.show())};a.tick=function(b){var a=this.density,a=a>360?a/360:360/a,h=this.con,d=this.diameter;a*=this.speed;b||(this.activeId+=a);this.activeId>=360&&(this.activeId-=360);o===p[0]?(h.clearRect(0,0,d,d),u(h,d*0.5,d*0.5,Math.PI/180*this.activeId),h.drawImage(this.cCan,0,0,d,d),h.restore()):m(this.vml,{rotation:this.activeId})};a.show=function(){if(typeof this.timer!=="number"){var a=this;this.timer=self.setInterval(function(){a.tick()},Math.round(1E3/this.fps));m(this.cont,
|
||||
{display:"block"})}};a.hide=function(){typeof this.timer==="number"&&(clearInterval(this.timer),delete this.timer,m(this.cont,{display:"none"}))};a.kill=function(){var a=this.cont;typeof this.timer==="number"&&this.hide();o===p[0]?(a.removeChild(this.can),a.removeChild(this.cCan)):a.removeChild(this.vml);for(var c in this)delete this[c]};w.CanvasLoader=k})(window);
|
||||
@@ -48,6 +48,7 @@
|
||||
* <li><strong>safeVML (Boolean):</strong> If set to true, the amount of CanvasLoader shapes are limited in VML mode. It prevents CPU overkilling when rendering loaders with high density. The default value is true.</li>
|
||||
**/
|
||||
var CanvasLoader = function (id, opt) {
|
||||
if (typeof(opt) == "undefined") { opt = {}; }
|
||||
this.init(id, opt);
|
||||
}, p = CanvasLoader.prototype, engine, engines = ["canvas", "vml"], shapes = ["oval", "spiral", "square", "rect", "roundRect"], cRX = /^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/, ie8 = navigator.appVersion.indexOf("MSIE") !== -1 && parseFloat(navigator.appVersion.split("MSIE")[1]) === 8 ? true : false, canSup = !!document.createElement('canvas').getContext, safeDensity = 40, safeVML = true,
|
||||
/**
|
||||
@@ -466,7 +467,7 @@
|
||||
if(this.shape === shapes[3]) {
|
||||
c.fillRect(x, y - h * 0.5, w, h);
|
||||
} else {
|
||||
rad = h * 0.2;
|
||||
rad = h * 0.55;
|
||||
c.moveTo(x + rad, y - h * 0.5);
|
||||
c.lineTo(x + w - rad, y - h * 0.5);
|
||||
c.quadraticCurveTo(x + w, y - h * 0.5, x + w, y - h * 0.5 + rad);
|
||||
|
||||
Reference in new issue
Block a user