Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaned up source a bit. New minified version.

  • Loading branch information...
commit 81accbd60d141410a89c888ecda023805a647575 1 parent 7ffbf2c
@rsandor authored
Showing with 26 additions and 11 deletions.
  1. +1 −10 gury.js
  2. +24 −1 gury.min.js
  3. +1 −0  gury.min.js.old
View
11 gury.js
@@ -538,23 +538,14 @@ window.$g = window.Gury = (function(window, jQuery) {
},
/*
- * TODO Document me
* TODO Add Tagging
- *
- * for adding global transformations to all objects
- *
- * {
- * up : // runs before drawing all other objects,
- * down: // runs after all other objects
- * }
- *
*/
addTransform: function(object) {
this._transforms.add(object);
},
/*
- * TODO Document me, add tagging.
+ * TODO Add Tagging
*/
removeTransform: function(object) {
this._transforms.remove(object);
View
25 gury.min.js
@@ -1 +1,24 @@
-window.$g=window.Gury=(function(g,k){function c(){for(var x=0;x<arguments.length;x++){var w=arguments[x];if(typeof w=="undefined"||w==null){return false;}}return arguments.length>0;}function l(w){return typeof w=="string";}function i(w){return typeof w=="object";}function b(w){return typeof w=="function";}function u(w){return i(w)||b(w);}function p(w){return i(w)&&c(w.getContext);}function r(w){return c(w.tagName)&&w.tagName=="IMG";}var e=k;function a(){return e!=null;}var f=true;function j(w){if(f){throw"Gury: "+w;}}var o=0;function q(){var x=this.table={};var w=0;function y(z){if(l(z)){return z;}if(!c(z._gury_hash)){z._gury_hash=o++;}return z._gury_hash;}this.set=function(z,B){if(c(B)){var A=y(z);x[A]=B;w++;}};this.has=function(z){var A=y(z);return c(x[A]);};this.get=function(z){var A=y(z);return x[A];};this.remove=function(z){if(c(z)){var A=y(z);delete x[A];w--;}};this.each=function(A){for(var z in x){A(x[z],z);}return this;};this.__defineGetter__("length",function(){return w;});}function t(x){var y=this.table=new q();var w=this.ordered=x?[]:false;this.__defineGetter__("length",function(){return y.length;});this.has=function(z){return y.has(z);};this.add=function(z){if(y.has(z)){return this;}if(w){w.push(z);}y.set(z,z);return this;};this.remove=function(A){if(!y.has(A)){return null;}else{if(w){for(var z=0;z<w.length;z++){if(w[z]==A){w.splice(z,1);break;}}}}y.remove(A);return A;};this.each=function(A){if(w){for(var z=0;z<w.length;z++){A.call(this,w[z],z);}}else{y.each(A);}return this;};this.clear=function(){this.each(function(A,z){this.remove(A);});return this;};this.sort=function(z){if(c(w)){w.sort(z);}return this;};this.first=function(){if(y.length<1||!c(w)){return null;}return w[0];};}function h(){this.name=name;this._children={};this._objects=new t();}h.prototype=(function(){var w=/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*$/;return{hasChild:function(x){return i(this._children[x]);},addChild:function(x){return this._children[x]=new h(x);},getChild:function(x){return this._children[x];},getObjects:function(){return this._objects;},find:function(x){if(!x.match(w)){return null;}var B=this;var z=x.split(".");var y=z[z.length-1];for(var A=0;A<z.length;A++){if(!B.hasChild(z[A])){return null;}B=B.getChild(z[A]);}return B;},add:function(x,A){var z=x.split(".");var C=this;var y=z[z.length-1];for(var B=0;B<z.length;B++){if(C.hasChild(z[B])){C=C.getChild(z[B]);}else{C=C.addChild(z[B]);}}C._objects.add(A);return A;},clearObjects:function(){this._objects=new t();},_remove_object:function(y){this._objects.remove(y);for(var x in this._children){var z=this._children[x];z._remove_object(y);}},remove:function(y){var z=new t();if(l(y)){var x=this.find(y);if(!x){return z;}z=x.getObjects();x.clearObjects();}else{this._remove_object(y);z.add(y);}return z;}};})();var v=(function(D,y){var w=document.createElement("canvas");var E=w.getContext("2d");if(D){w.style.position="absolute";w.style.top="10px";w.style.left="10px";w.style.background="white";document.body.appendChild(w);}var x,A;function z(F){var H=F.canvas;if(!c(H)){return false;}var G=H.width;var I=H.height;if(G!=x||I!=A){w.width=x=G;w.height=A=I;}E.clearRect(0,0,G,I);return true;}function B(F,G){if(b(G)){ob.call(F,E,F.canvas);}else{if(i(G)&&c(G.draw)){G.draw(E,F.canvas);}}}function C(N,L){if(E==null){return false;}var F=E.getImageData(0,0,x,A);var P=F.width;var K=F.height;var J=F.data;if(N<0||N>=P||L<0||L>=K){return false;}var M=P*4*L+N*4;var G=F.data[M];var I=F.data[M+1];var O=F.data[M+2];var H=F.data[M+3];return(G>0||I>0||O>0||H>0);}return{hit:function(G,I,F,K){var J;if(y){J=new Date().getTime();}var H=false;if(u(I)){if(!z(G)){return false;}B(G,I);H=C(F,K);}if(y&&console&&console.log){console.log("Hit detection completed in "+(new Date().getTime()-J)+"ms");}return H;}};})(false,false);var s=new q();function m(w){this.canvas=null;this.ctx=null;this._objects=new t(true);this._tags=new h("__global");this._paused=false;this._loop_interval=null;this._clear_on_draw=true;this._events={};var x=0;this.nextZ=function(){return x++;};}m.prototype={register:function(w){if(p(w)){this.canvas=w;this.ctx=w.getContext("2d");if(s.has(w)){s.get(w).unregister(w);}s.set(w,this);n.bind(this,w);}else{j("register() - Gury only supports registration of Canvas elements at this time.");}return this;},unregister:function(w){if(p(w)){s.remove(w);n.unbind(this,w);this.canvas=null;this.ctx=null;}return this;},place:function(x){var w=this.canvas;if(a()){e(x).append(w);}else{if(typeof x=="object"&&typeof x.addChild=="function"){x.addChild(w);}else{j("place() - Unable to place canvas tag (is jQuery loaded?)");}}return this;},size:function(x,y){this.canvas.width=x;this.canvas.height=y;return this;},background:function(w){this.canvas.style.background=w;return this;},add:function(){var w=null,y;if(arguments.length<1){return this;}else{if(arguments.length<2){y=arguments[0];if(!u(y)){return this;}}else{w=arguments[0];y=arguments[1];if(!l(name)||!u(y)){return this;}}}if(w!=null){this._tags.add(w,y);}if(this._objects.has(y)){return this;}if(!c(y._gury)){y._gury={visible:true,paused:false,z:this.nextZ()};}this._objects.add(y);var z=["click","mousedown","mouseup","mousemove","mouseenter","mouseleave"];for(var A in z){var x=z[A];if(c(y[x])&&b(y[x])){this.bind(y,x,y[x]);}}return this;},remove:function(x){if(c(x)){var w=this;var y=this._tags.remove(x);y.each(function(z){w._objects.remove(z);delete z._gury;});}return this;},clear:function(w){if(typeof w!="undefined"){this._clear_on_draw=w;return this;}this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);return this;},update:function(){var w=this;w._objects.each(function(x){if(c(x.update)&&!x._gury.paused){x.update(w);}});return this;},draw:function(){if(this._clear_on_draw){this.clear();}var w=this;w._objects.each(function(x){if(!x._gury.visible||!u(x)){return;}if(typeof x=="function"){x.call(w,w.ctx,w.canvas);}else{if(typeof x=="object"&&typeof x.draw!="undefined"){x.draw(w.ctx,w.canvas);}}});return this;},play:function(x){if(this._loop_interval!=null){return this;}this.draw();var w=this;this._loop_interval=setInterval(function(){if(!w._paused){w.update().draw();}},x);return this;},pause:function(){if(arguments.length>0){for(var x=0;x<arguments.length;x++){var w=arguments[x];if(l(w)){this.each(w,function(y){y._gury.paused=!y._gury.paused;});}else{if(c(w._gury)){w._gury.paused=!w._gury.paused;}}}return this;}else{this._paused=!this._paused;return this;}},stop:function(){if(this._loop_interval!=null){clearInterval(this._loop_interval);this._paused=false;}return this;},each:function(){var w,y;if(arguments.length<2&&b(arguments[0])){y=arguments[0];this._objects.each(y);}else{if(l(arguments[0])&&b(arguments[1])){w=arguments[0];y=arguments[1];var x=this._tags.find(w);if(x){x.getObjects().each(y);}}else{if(b(arguments[0])){y=arguments[0];this._objects.each(y);}else{if(b(arguments[1])){y=arguments[1];this._objects.each(y);}}}}return this;},hide:function(w){return this.each(w,function(y,x){y._gury.visible=false;});},show:function(w){return this.each(w,function(y,x){y._gury.visible=true;});},toggle:function(w){return this.each(w,function(y,x){y._gury.visible=!y._gury.visible;});}};var n=(function(){function y(B,E){var D=new t();if(l(E)){var C=B._tags.find(E);if(C!=null){D=C.getObjects();}}else{if(c(E)&&B._objects.has(E)){D.add(E);}}return D;}m.prototype.bind=function(E,D,F){if(c(E,D,F)){var B=this;var C=B._events;y(B,E).each(function(G){if(!c(C[D])){C[D]=new q();}if(!C[D].has(G)){C[D].set(G,{target:G,handlers:[]});}C[D].get(G).handlers.push(F);});}return this;};m.prototype.unbind=function(E,D,F){if(c(E,D)){var B=this;var C=B._events;y(B,E).each(function(H){if(!c(C[D])){return;}if(!C[D].has(H)){return;}if(c(F)){var G=C[D].get(H).handlers;for(var I=0;I<G.length;I++){if(G[I]==F){G.splice(I,1);break;}}}else{C[D].remove(H);}});}return this;};m.prototype.trigger=function(E,C,F){if(c(E,this._events[E],C)){if(this._events[E].has(C)){var B=this._events[E].get(C).handlers;for(var D=0;D<B.length;D++){B[D].call(C,F);}}}return this;};function x(B){return function(C,D){if(c(C)){if(c(D)){this.bind(C,B,D);}else{this.trigger(C,B);}}return this;};}m.prototype.click=x("click");m.prototype.mousedown=x("mousedown");m.prototype.mouseup=x("mouseup");m.prototype.mousemove=x("mousemove");m.prototype.mouseenter=x("mouseenter");m.prototype.mouseleave=x("mouseleave");function w(B,E){var D=0,C=0;if(B.offsetParent){while(B){D+=B.offsetLeft;C+=B.offsetTop;B=B.offsetParent;}}return{x:E.pageX-D,y:E.pageY-C};}function A(B,F,D,H){if(c(B._events[D])){var G=w(F.canvas,F);F.canvasX=G.x;F.canvasY=G.y;var E=false;var C=new t(true);B._events[D].each(function(I){C.add(I.target);});C.sort(function(J,I){if(J._gury.z<I._gury.z){return 1;}else{return -1;}}).each(function(I){if(!E&&v.hit(B,I,G.x,G.y)){E=true;B.trigger(D,I,F);if(H){H.call(I);}}});if(!E&&H){H.call(null);}}}var z=null;return{bind:function(B,C){C.onclick=function(D){D.canvas=this;A(B,D,"click");};C.onmousedown=function(D){D.canvas=this;A(B,D,"mousedown");};C.onmouseup=function(D){D.canvas=this;A(B,D,"mouseup");};C.onmousemove=function(D){D.canvas=this;A(B,D,"mousemove",function(){if(this!=z){if(c(z)){B.trigger("mouseleave",z,D);}B.trigger("mouseenter",this);z=this;}});};C.onmouseout=function(D){D.canvas=this;if(z!=null){B.trigger("mouseleave",z,D);z=null;}};},unbind:function(B,C){C.onclick=null;C.onmousedown=null;C.onmouseup=null;C.onmousemove=null;C.onmouseleave=null;}};})();function d(B,A){var x={};for(var y in x){if(!c(A[y])){A[y]=x[y];}}var w=new m(A);var z;if(l(B)){z=document.getElementById(B);if(!c(z)){j('Unable to find canvas with id="'+B+'"');}else{if(s.has(z)){return s.get(z);}}w.register(z);}else{if(i(B)){z=B;if(s.has(z)){return s.get(z);}w.register(z);}else{w.register(document.createElement("canvas"));}}return w;}d.failWithException=function(w){if(!w){return f;}return f=w?true:false;};return d;})(window,window.jQuery);
+/*
+ gury.js - A jQuery inspired canvas utility library
+
+ Copyright (c) 2010 Ryan Sandor Richards
+
+ 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.
+*/
+window.$g=window.Gury=(function(G,K){function C(){for(var X=0;X<arguments.length;X++){var W=arguments[X];if(typeof W=="undefined"||W==null){return false;}}return arguments.length>0;}function L(W){return typeof W=="string";}function I(W){return typeof W=="object";}function B(W){return typeof W=="function";}function U(W){return I(W)||B(W);}function P(W){return I(W)&&C(W.getContext);}function R(W){return C(W.tagName)&&W.tagName=="IMG";}var E=K;function A(){return E!=null;}var F=true;function J(W){if(F){throw"Gury: "+W;}}var O=0;function Q(){var X=this.table={};var W=0;function Y(Z){if(L(Z)){return Z;}if(!C(Z._gury_hash)){Z._gury_hash=O++;}return Z._gury_hash;}this.set=function(Z,b){if(C(b)){var a=Y(Z);X[a]=b;W++;}};this.has=function(Z){var a=Y(Z);return C(X[a]);};this.get=function(Z){var a=Y(Z);return X[a];};this.remove=function(Z){if(C(Z)){var a=Y(Z);delete X[a];W--;}};this.each=function(a){for(var Z in X){a(X[Z],Z);}return this;};this.__defineGetter__("length",function(){return W;});}function T(X){var Y=this.table=new Q();var W=this.ordered=X?[]:false;this.__defineGetter__("length",function(){return Y.length;});this.has=function(Z){return Y.has(Z);};this.add=function(Z){if(Y.has(Z)){return this;}if(W){W.push(Z);}Y.set(Z,Z);return this;};this.remove=function(a){if(!Y.has(a)){return null;}else{if(W){for(var Z=0;Z<W.length;Z++){if(W[Z]==a){W.splice(Z,1);break;}}}}Y.remove(a);return a;};this.each=function(a){if(W){for(var Z=0;Z<W.length;Z++){a.call(this,W[Z],Z);}}else{Y.each(a);}return this;};this.clear=function(){this.each(function(a,Z){this.remove(a);});return this;};this.sort=function(Z){if(C(W)){W.sort(Z);}return this;};this.first=function(){if(Y.length<1||!C(W)){return null;}return W[0];};}function H(){this.name=name;this._children={};this._objects=new T();}H.prototype=(function(){var W=/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*$/;return{hasChild:function(X){return I(this._children[X]);},addChild:function(X){return this._children[X]=new H(X);},getChild:function(X){return this._children[X];},getObjects:function(){return this._objects;},find:function(X){if(!X.match(W)){return null;}var b=this;var Z=X.split(".");var Y=Z[Z.length-1];for(var a=0;a<Z.length;a++){if(!b.hasChild(Z[a])){return null;}b=b.getChild(Z[a]);}return b;},add:function(X,a){var Z=X.split(".");var c=this;var Y=Z[Z.length-1];for(var b=0;b<Z.length;b++){if(c.hasChild(Z[b])){c=c.getChild(Z[b]);}else{c=c.addChild(Z[b]);}}c._objects.add(a);return a;},clearObjects:function(){this._objects=new T();},_remove_object:function(Y){this._objects.remove(Y);for(var X in this._children){var Z=this._children[X];Z._remove_object(Y);}},remove:function(Y){var Z=new T();if(L(Y)){var X=this.find(Y);if(!X){return Z;}Z=X.getObjects();X.clearObjects();}else{this._remove_object(Y);Z.add(Y);}return Z;}};})();var V=(function(d,Y){var W=document.createElement("canvas");var e=W.getContext("2d");if(d){W.style.position="absolute";W.style.top="10px";W.style.left="10px";W.style.background="white";document.body.appendChild(W);}var X,a;function Z(f){var i=f.canvas;if(!C(i)){return false;}var g=i.width;var j=i.height;if(g!=X||j!=a){W.width=X=g;W.height=a=j;}e.clearRect(0,0,g,j);return true;}function b(f,g){if(B(g)){ob.call(f,e,f.canvas);}else{if(I(g)&&C(g.draw)){g.draw(e,f.canvas);}}}function c(o,m){if(e==null){return false;}var f=e.getImageData(0,0,X,a);var q=f.width;var l=f.height;var k=f.data;if(o<0||o>=q||m<0||m>=l){return false;}var n=q*4*m+o*4;var g=f.data[n];var j=f.data[n+1];var p=f.data[n+2];var i=f.data[n+3];return(g>0||j>0||p>0||i>0);}return{hit:function(g,i,f,k){var j;if(Y){j=new Date().getTime();}var h=false;if(U(i)){if(!Z(g)){return false;}b(g,i);h=c(f,k);}if(Y&&console&&console.log){console.log("Hit detection completed in "+(new Date().getTime()-j)+"ms");}return h;}};})(false,false);var S=new Q();function M(W){this.canvas=null;this.ctx=null;this._objects=new T(true);this._tags=new H("__global");this._transforms=new T(true);this._paused=false;this._loop_interval=null;this._clear_on_draw=true;this._events={};var X=0;this.nextZ=function(){return X++;};}M.prototype={register:function(W){if(P(W)){this.canvas=W;this.ctx=W.getContext("2d");if(S.has(W)){S.get(W).unregister(W);}S.set(W,this);N.bind(this,W);}else{J("register() - Gury only supports registration of Canvas elements at this time.");}return this;},unregister:function(W){if(P(W)){S.remove(W);N.unbind(this,W);this.canvas=null;this.ctx=null;}return this;},place:function(X){var W=this.canvas;if(A()){E(X).append(W);}else{if(typeof X=="object"&&typeof X.addChild=="function"){X.addChild(W);}else{J("place() - Unable to place canvas tag (is jQuery loaded?)");}}return this;},size:function(W,X){this.canvas.width=W;this.canvas.height=X;return this;},background:function(W){this.canvas.style.background=W;return this;},add:function(){var W=null,Y;if(arguments.length<1){return this;}else{if(arguments.length<2){Y=arguments[0];if(!U(Y)){return this;}}else{W=arguments[0];Y=arguments[1];if(!L(name)||!U(Y)){return this;}}}if(W!=null){this._tags.add(W,Y);}if(this._objects.has(Y)){return this;}if(!C(Y._gury)){Y._gury={visible:true,paused:false,z:this.nextZ()};}this._objects.add(Y);var Z=["click","mousedown","mouseup","mousemove","mouseenter","mouseleave"];for(var a in Z){var X=Z[a];if(C(Y[X])&&B(Y[X])){this.bind(Y,X,Y[X]);}}return this;},addTransform:function(W){this._transforms.add(W);},removeTransform:function(W){this._transforms.remove(W);},remove:function(X){if(C(X)){var W=this;var Y=this._tags.remove(X);Y.each(function(Z){W._objects.remove(Z);delete Z._gury;});}return this;},clear:function(W){if(typeof W!="undefined"){this._clear_on_draw=W;return this;}this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);return this;},update:function(){var W=this;W._objects.each(function(X){if(C(X.update)&&!X._gury.paused){X.update(W);}});return this;},draw:function(){if(this._clear_on_draw){this.clear();}var W=this;W._transforms.each(function(X){X.up(W.ctx,W.canvas);});W._objects.each(function(X){if(!X._gury.visible||!U(X)){return ;}if(typeof X=="function"){X.call(W,W.ctx,W.canvas);}else{if(typeof X=="object"&&typeof X.draw!="undefined"){X.draw(W.ctx,W.canvas);}}});W._transforms.each(function(X){X.down(W.ctx,W.canvas);});return this;},play:function(X){if(this._loop_interval!=null){return this;}this.draw();var W=this;this._loop_interval=setInterval(function(){if(!W._paused){W.update().draw();}},X);return this;},pause:function(){if(arguments.length>0){for(var X=0;X<arguments.length;X++){var W=arguments[X];if(L(W)){this.each(W,function(Y){Y._gury.paused=!Y._gury.paused;});}else{if(C(W._gury)){W._gury.paused=!W._gury.paused;}}}return this;}else{this._paused=!this._paused;return this;}},stop:function(){if(this._loop_interval!=null){clearInterval(this._loop_interval);this._paused=false;}return this;},each:function(){var W,Y;if(arguments.length<2&&B(arguments[0])){Y=arguments[0];this._objects.each(Y);}else{if(L(arguments[0])&&B(arguments[1])){W=arguments[0];Y=arguments[1];var X=this._tags.find(W);if(X){X.getObjects().each(Y);}}else{if(B(arguments[0])){Y=arguments[0];this._objects.each(Y);}else{if(B(arguments[1])){Y=arguments[1];this._objects.each(Y);}}}}return this;},hide:function(W){return this.each(W,function(Y,X){Y._gury.visible=false;});},show:function(W){return this.each(W,function(Y,X){Y._gury.visible=true;});},toggle:function(W){return this.each(W,function(Y,X){Y._gury.visible=!Y._gury.visible;});}};var N=(function(){function Y(b,e){var d=new T();if(L(e)){var c=b._tags.find(e);if(c!=null){d=c.getObjects();}}else{if(C(e)&&b._objects.has(e)){d.add(e);}}return d;}M.prototype.bind=function(e,d,f){if(C(e,d,f)){var b=this;var c=b._events;Y(b,e).each(function(g){if(!C(c[d])){c[d]=new Q();}if(!c[d].has(g)){c[d].set(g,{target:g,handlers:[]});}c[d].get(g).handlers.push(f);});}return this;};M.prototype.unbind=function(e,d,f){if(C(e,d)){var b=this;var c=b._events;Y(b,e).each(function(h){if(!C(c[d])){return ;}if(!c[d].has(h)){return ;}if(C(f)){var g=c[d].get(h).handlers;for(var j=0;j<g.length;j++){if(g[j]==f){g.splice(j,1);break;}}}else{c[d].remove(h);}});}return this;};M.prototype.trigger=function(f,c,g){if(C(f,this._events[f],c)){if(this._events[f].has(c)){var b=this._events[f].get(c).handlers;for(var d=0;d<b.length;d++){b[d].call(c,g);}}}return this;};function X(b){return function(c,d){if(C(c)){if(C(d)){this.bind(c,b,d);}else{this.trigger(c,b);}}return this;};}M.prototype.click=X("click");M.prototype.mousedown=X("mousedown");M.prototype.mouseup=X("mouseup");M.prototype.mousemove=X("mousemove");M.prototype.mouseenter=X("mouseenter");M.prototype.mouseleave=X("mouseleave");function W(b,f){var d=0,c=0;if(b.offsetParent){while(b){d+=b.offsetLeft;c+=b.offsetTop;b=b.offsetParent;}}return{x:f.pageX-d,y:f.pageY-c};}function a(b,g,d,i){if(C(b._events[d])){var h=W(g.canvas,g);g.canvasX=h.x;g.canvasY=h.y;var f=false;var c=new T(true);b._events[d].each(function(e){c.add(e.target);});c.sort(function(j,e){if(j._gury.z<e._gury.z){return 1;}else{return -1;}}).each(function(e){if(!f&&V.hit(b,e,h.x,h.y)){f=true;b.trigger(d,e,g);if(i){i.call(e);}}});if(!f&&i){i.call(null);}}}var Z=null;return{bind:function(b,c){c.onclick=function(d){d.canvas=this;a(b,d,"click");};c.onmousedown=function(d){d.canvas=this;a(b,d,"mousedown");};c.onmouseup=function(d){d.canvas=this;a(b,d,"mouseup");};c.onmousemove=function(d){d.canvas=this;a(b,d,"mousemove",function(){if(this!=Z){if(C(Z)){b.trigger("mouseleave",Z,d);}b.trigger("mouseenter",this);Z=this;}});};c.onmouseout=function(d){d.canvas=this;if(Z!=null){b.trigger("mouseleave",Z,d);Z=null;}};},unbind:function(b,c){c.onclick=null;c.onmousedown=null;c.onmouseup=null;c.onmousemove=null;c.onmouseleave=null;}};})();function D(b,a){var X={};for(var Y in X){if(!C(a[Y])){a[Y]=X[Y];}}var W=new M(a);var Z;if(L(b)){Z=document.getElementById(b);if(!C(Z)){J('Unable to find canvas with id="'+b+'"');}else{if(S.has(Z)){return S.get(Z);}}W.register(Z);}else{if(I(b)){Z=b;if(S.has(Z)){return S.get(Z);}W.register(Z);}else{W.register(document.createElement("canvas"));}}return W;}D.failWithException=function(W){if(!W){return F;}return F=W?true:false;};return D;})(window,window.jQuery);
View
1  gury.min.js.old
@@ -0,0 +1 @@
+window.$g=window.Gury=(function(g,k){function c(){for(var x=0;x<arguments.length;x++){var w=arguments[x];if(typeof w=="undefined"||w==null){return false;}}return arguments.length>0;}function l(w){return typeof w=="string";}function i(w){return typeof w=="object";}function b(w){return typeof w=="function";}function u(w){return i(w)||b(w);}function p(w){return i(w)&&c(w.getContext);}function r(w){return c(w.tagName)&&w.tagName=="IMG";}var e=k;function a(){return e!=null;}var f=true;function j(w){if(f){throw"Gury: "+w;}}var o=0;function q(){var x=this.table={};var w=0;function y(z){if(l(z)){return z;}if(!c(z._gury_hash)){z._gury_hash=o++;}return z._gury_hash;}this.set=function(z,B){if(c(B)){var A=y(z);x[A]=B;w++;}};this.has=function(z){var A=y(z);return c(x[A]);};this.get=function(z){var A=y(z);return x[A];};this.remove=function(z){if(c(z)){var A=y(z);delete x[A];w--;}};this.each=function(A){for(var z in x){A(x[z],z);}return this;};this.__defineGetter__("length",function(){return w;});}function t(x){var y=this.table=new q();var w=this.ordered=x?[]:false;this.__defineGetter__("length",function(){return y.length;});this.has=function(z){return y.has(z);};this.add=function(z){if(y.has(z)){return this;}if(w){w.push(z);}y.set(z,z);return this;};this.remove=function(A){if(!y.has(A)){return null;}else{if(w){for(var z=0;z<w.length;z++){if(w[z]==A){w.splice(z,1);break;}}}}y.remove(A);return A;};this.each=function(A){if(w){for(var z=0;z<w.length;z++){A.call(this,w[z],z);}}else{y.each(A);}return this;};this.clear=function(){this.each(function(A,z){this.remove(A);});return this;};this.sort=function(z){if(c(w)){w.sort(z);}return this;};this.first=function(){if(y.length<1||!c(w)){return null;}return w[0];};}function h(){this.name=name;this._children={};this._objects=new t();}h.prototype=(function(){var w=/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*$/;return{hasChild:function(x){return i(this._children[x]);},addChild:function(x){return this._children[x]=new h(x);},getChild:function(x){return this._children[x];},getObjects:function(){return this._objects;},find:function(x){if(!x.match(w)){return null;}var B=this;var z=x.split(".");var y=z[z.length-1];for(var A=0;A<z.length;A++){if(!B.hasChild(z[A])){return null;}B=B.getChild(z[A]);}return B;},add:function(x,A){var z=x.split(".");var C=this;var y=z[z.length-1];for(var B=0;B<z.length;B++){if(C.hasChild(z[B])){C=C.getChild(z[B]);}else{C=C.addChild(z[B]);}}C._objects.add(A);return A;},clearObjects:function(){this._objects=new t();},_remove_object:function(y){this._objects.remove(y);for(var x in this._children){var z=this._children[x];z._remove_object(y);}},remove:function(y){var z=new t();if(l(y)){var x=this.find(y);if(!x){return z;}z=x.getObjects();x.clearObjects();}else{this._remove_object(y);z.add(y);}return z;}};})();var v=(function(D,y){var w=document.createElement("canvas");var E=w.getContext("2d");if(D){w.style.position="absolute";w.style.top="10px";w.style.left="10px";w.style.background="white";document.body.appendChild(w);}var x,A;function z(F){var H=F.canvas;if(!c(H)){return false;}var G=H.width;var I=H.height;if(G!=x||I!=A){w.width=x=G;w.height=A=I;}E.clearRect(0,0,G,I);return true;}function B(F,G){if(b(G)){ob.call(F,E,F.canvas);}else{if(i(G)&&c(G.draw)){G.draw(E,F.canvas);}}}function C(N,L){if(E==null){return false;}var F=E.getImageData(0,0,x,A);var P=F.width;var K=F.height;var J=F.data;if(N<0||N>=P||L<0||L>=K){return false;}var M=P*4*L+N*4;var G=F.data[M];var I=F.data[M+1];var O=F.data[M+2];var H=F.data[M+3];return(G>0||I>0||O>0||H>0);}return{hit:function(G,I,F,K){var J;if(y){J=new Date().getTime();}var H=false;if(u(I)){if(!z(G)){return false;}B(G,I);H=C(F,K);}if(y&&console&&console.log){console.log("Hit detection completed in "+(new Date().getTime()-J)+"ms");}return H;}};})(false,false);var s=new q();function m(w){this.canvas=null;this.ctx=null;this._objects=new t(true);this._tags=new h("__global");this._paused=false;this._loop_interval=null;this._clear_on_draw=true;this._events={};var x=0;this.nextZ=function(){return x++;};}m.prototype={register:function(w){if(p(w)){this.canvas=w;this.ctx=w.getContext("2d");if(s.has(w)){s.get(w).unregister(w);}s.set(w,this);n.bind(this,w);}else{j("register() - Gury only supports registration of Canvas elements at this time.");}return this;},unregister:function(w){if(p(w)){s.remove(w);n.unbind(this,w);this.canvas=null;this.ctx=null;}return this;},place:function(x){var w=this.canvas;if(a()){e(x).append(w);}else{if(typeof x=="object"&&typeof x.addChild=="function"){x.addChild(w);}else{j("place() - Unable to place canvas tag (is jQuery loaded?)");}}return this;},size:function(x,y){this.canvas.width=x;this.canvas.height=y;return this;},background:function(w){this.canvas.style.background=w;return this;},add:function(){var w=null,y;if(arguments.length<1){return this;}else{if(arguments.length<2){y=arguments[0];if(!u(y)){return this;}}else{w=arguments[0];y=arguments[1];if(!l(name)||!u(y)){return this;}}}if(w!=null){this._tags.add(w,y);}if(this._objects.has(y)){return this;}if(!c(y._gury)){y._gury={visible:true,paused:false,z:this.nextZ()};}this._objects.add(y);var z=["click","mousedown","mouseup","mousemove","mouseenter","mouseleave"];for(var A in z){var x=z[A];if(c(y[x])&&b(y[x])){this.bind(y,x,y[x]);}}return this;},remove:function(x){if(c(x)){var w=this;var y=this._tags.remove(x);y.each(function(z){w._objects.remove(z);delete z._gury;});}return this;},clear:function(w){if(typeof w!="undefined"){this._clear_on_draw=w;return this;}this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);return this;},update:function(){var w=this;w._objects.each(function(x){if(c(x.update)&&!x._gury.paused){x.update(w);}});return this;},draw:function(){if(this._clear_on_draw){this.clear();}var w=this;w._objects.each(function(x){if(!x._gury.visible||!u(x)){return;}if(typeof x=="function"){x.call(w,w.ctx,w.canvas);}else{if(typeof x=="object"&&typeof x.draw!="undefined"){x.draw(w.ctx,w.canvas);}}});return this;},play:function(x){if(this._loop_interval!=null){return this;}this.draw();var w=this;this._loop_interval=setInterval(function(){if(!w._paused){w.update().draw();}},x);return this;},pause:function(){if(arguments.length>0){for(var x=0;x<arguments.length;x++){var w=arguments[x];if(l(w)){this.each(w,function(y){y._gury.paused=!y._gury.paused;});}else{if(c(w._gury)){w._gury.paused=!w._gury.paused;}}}return this;}else{this._paused=!this._paused;return this;}},stop:function(){if(this._loop_interval!=null){clearInterval(this._loop_interval);this._paused=false;}return this;},each:function(){var w,y;if(arguments.length<2&&b(arguments[0])){y=arguments[0];this._objects.each(y);}else{if(l(arguments[0])&&b(arguments[1])){w=arguments[0];y=arguments[1];var x=this._tags.find(w);if(x){x.getObjects().each(y);}}else{if(b(arguments[0])){y=arguments[0];this._objects.each(y);}else{if(b(arguments[1])){y=arguments[1];this._objects.each(y);}}}}return this;},hide:function(w){return this.each(w,function(y,x){y._gury.visible=false;});},show:function(w){return this.each(w,function(y,x){y._gury.visible=true;});},toggle:function(w){return this.each(w,function(y,x){y._gury.visible=!y._gury.visible;});}};var n=(function(){function y(B,E){var D=new t();if(l(E)){var C=B._tags.find(E);if(C!=null){D=C.getObjects();}}else{if(c(E)&&B._objects.has(E)){D.add(E);}}return D;}m.prototype.bind=function(E,D,F){if(c(E,D,F)){var B=this;var C=B._events;y(B,E).each(function(G){if(!c(C[D])){C[D]=new q();}if(!C[D].has(G)){C[D].set(G,{target:G,handlers:[]});}C[D].get(G).handlers.push(F);});}return this;};m.prototype.unbind=function(E,D,F){if(c(E,D)){var B=this;var C=B._events;y(B,E).each(function(H){if(!c(C[D])){return;}if(!C[D].has(H)){return;}if(c(F)){var G=C[D].get(H).handlers;for(var I=0;I<G.length;I++){if(G[I]==F){G.splice(I,1);break;}}}else{C[D].remove(H);}});}return this;};m.prototype.trigger=function(E,C,F){if(c(E,this._events[E],C)){if(this._events[E].has(C)){var B=this._events[E].get(C).handlers;for(var D=0;D<B.length;D++){B[D].call(C,F);}}}return this;};function x(B){return function(C,D){if(c(C)){if(c(D)){this.bind(C,B,D);}else{this.trigger(C,B);}}return this;};}m.prototype.click=x("click");m.prototype.mousedown=x("mousedown");m.prototype.mouseup=x("mouseup");m.prototype.mousemove=x("mousemove");m.prototype.mouseenter=x("mouseenter");m.prototype.mouseleave=x("mouseleave");function w(B,E){var D=0,C=0;if(B.offsetParent){while(B){D+=B.offsetLeft;C+=B.offsetTop;B=B.offsetParent;}}return{x:E.pageX-D,y:E.pageY-C};}function A(B,F,D,H){if(c(B._events[D])){var G=w(F.canvas,F);F.canvasX=G.x;F.canvasY=G.y;var E=false;var C=new t(true);B._events[D].each(function(I){C.add(I.target);});C.sort(function(J,I){if(J._gury.z<I._gury.z){return 1;}else{return -1;}}).each(function(I){if(!E&&v.hit(B,I,G.x,G.y)){E=true;B.trigger(D,I,F);if(H){H.call(I);}}});if(!E&&H){H.call(null);}}}var z=null;return{bind:function(B,C){C.onclick=function(D){D.canvas=this;A(B,D,"click");};C.onmousedown=function(D){D.canvas=this;A(B,D,"mousedown");};C.onmouseup=function(D){D.canvas=this;A(B,D,"mouseup");};C.onmousemove=function(D){D.canvas=this;A(B,D,"mousemove",function(){if(this!=z){if(c(z)){B.trigger("mouseleave",z,D);}B.trigger("mouseenter",this);z=this;}});};C.onmouseout=function(D){D.canvas=this;if(z!=null){B.trigger("mouseleave",z,D);z=null;}};},unbind:function(B,C){C.onclick=null;C.onmousedown=null;C.onmouseup=null;C.onmousemove=null;C.onmouseleave=null;}};})();function d(B,A){var x={};for(var y in x){if(!c(A[y])){A[y]=x[y];}}var w=new m(A);var z;if(l(B)){z=document.getElementById(B);if(!c(z)){j('Unable to find canvas with id="'+B+'"');}else{if(s.has(z)){return s.get(z);}}w.register(z);}else{if(i(B)){z=B;if(s.has(z)){return s.get(z);}w.register(z);}else{w.register(document.createElement("canvas"));}}return w;}d.failWithException=function(w){if(!w){return f;}return f=w?true:false;};return d;})(window,window.jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.