-
Notifications
You must be signed in to change notification settings - Fork 1
/
Stratiscape-min.js
11 lines (11 loc) · 5.08 KB
/
Stratiscape-min.js
1
2
3
4
5
6
7
8
9
10
11
(function(){var a=!1,b=/xyz/.test(function(){})?/\b_super\b/:/.*/;this.Class=function(){};Class.extend=function(d){function c(){!a&&this.init&&this.init.apply(this,arguments)}var f=this.prototype;a=!0;var g=new this;a=!1;for(var e in d)g[e]=typeof d[e]=="function"&&typeof f[e]=="function"&&b.test(d[e])?function(a,b){return function(){var c=this._super;this._super=f[a];var d=b.apply(this,arguments);this._super=c;return d}}(e,d[e]):d[e];c.prototype=g;c.constructor=c;c.extend=arguments.callee;return c}})();Stratiscape=function(a){this.inverseScaleRatio=1;this.layers=[];this.layersByName={};this.container=document.getElementById(a.containerId);var b=this.container.innerHTML;if(document.createElement("canvas").getContext){this.canvasSupported=!0;a.layers.sort(this.layerSortFunction);for(var d in a.layers){var c=a.layers[d];if(c.zIndex>=0){if(Stratiscape.Global.layerNextZIndex<=c.zIndex)Stratiscape.Global.layerNextZIndex=c.zIndex+1}else c.zIndex=Stratiscape.Global.layerNextZIndex++;var f="lyr_"+c.name+
c.zIndex,g="";c.backgroundColor&&(g="background-color:"+c.backgroundColor+";");b+='<canvas id="'+f+'" width="'+c.width+'" height="'+c.height+'" style="position:absolute;left:'+c.x+"px;top:"+c.y+"px;z-index:"+c.zIndex+";"+g+'"></canvas>'}this.container.innerHTML=b;for(d in a.layers){c=a.layers[d];f="lyr_"+c.name+c.zIndex;b=null;if(c.mouseHitId){var e=this,b=document.getElementById(c.mouseHitId);if(c.clickCallback)b.layerConfig=c,Stratiscape.Global.onEvent(b,"click",function(a){var b=e.getScaledCursorPosition(a);
(a.srcElement||a.target).layerConfig.clickCallback(b)});if(c.dblclickCallback)b.layerConfig=c,Stratiscape.Global.onEvent(b,"dblclick",function(a){var b=e.getScaledCursorPosition(a);(a.srcElement||a.target).layerConfig.dblclickCallback(b)})}c=new Stratiscape.Layer(f,c.name,c.x,c.y,c.width,c.height,c.zIndex,b);this.layers.push(c);this.layersByName[c.name]=c}}else this.canvasSupported=!1,a.canvasNotSupportedCallback&&a.canvasNotSupportedCallback()};
Stratiscape.prototype.getScaledCursorPosition=function(a){a=Stratiscape.Global.getCursorPosition(a);this.inverseScaleRatio&&(a.x*=this.inverseScaleRatio,a.y*=this.inverseScaleRatio);return a};Stratiscape.Global={layerNextZIndex:1};
Stratiscape.Global.getCursorPosition=function(a){var b={x:null,y:null};a.pageX!=void 0&&a.pageY!=void 0?(b.x=a.pageX,b.y=a.pageY):(b.x=a.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,b.y=a.clientY+document.body.scrollTop+document.documentElement.scrollTop);a=a.srcElement||a.target;do b.x-=a.offsetLeft||0,b.y-=a.offsetTop||0,a=a.offsetParent;while(a);return b};
Stratiscape.Global.onEvent=function(a,b,d){a.addEventListener?a.addEventListener(b,d,!1):a.attachEvent&&a.attachEvent("on"+b,d)};Stratiscape.Global.scaleElement=function(a,b,d){if(a&&(a.style.width=(a.width||a.clientWidth)*b.widthScale+"px",a.style.height=(a.height||a.clientHeight)*b.heightScale+"px",!d)){if(a.offsetLeft!=0)a.style.left=a.offsetLeft*b.widthScale+"px";if(a.offsetTop!=0)a.style.top=a.offsetTop*b.heightScale+"px"}};
Stratiscape.prototype.scaleLayers=function(a){var b={widthScale:1,heightScale:1},d=window.innerWidth,c=window.innerHeight,f=d/c,g=a.mainWidth/a.mainHeight,e=1,e=a.ratioTolerance||0.02;if(f<g-e||f>g+e){var e=Math.min(d/(a.mainWidth+(a.paddingWidth||0)),c/(a.mainHeight+(a.paddingHeight||0))),b={widthScale:e,heightScale:e},h;for(h in this.layers)d=document.StratiscapeDraw.layers[h],Stratiscape.Global.scaleElement(d.canvas,b),d.mouseHitElm&&Stratiscape.Global.scaleElement(d.mouseHitElm,b);if(a.additionalElementIds)for(h in a.additionalElementIds)Stratiscape.Global.scaleElement(document.getElementById(a.additionalElementIds[h]),
b,!0);this.inverseScaleRatio=1/e}return b};Stratiscape.prototype.getLayer=function(a){return this.layersByName[a]?this.layersByName[a]:null};Stratiscape.prototype.draw=function(){for(var a in this.layers)this.layers[a].needsDisplay&&this.layers[a].draw()};Stratiscape.prototype.layerSortFunction=function(a,b){return a.zIndex>b.zIndex?1:a.zIndex<b.zIndex?-1:0};
Stratiscape.Layer=function(a,b,d,c,f,g,e,h){this.name=b;this.x=d;this.y=c;this.width=f;this.height=g;this.zIndex=e;this.children=[];this.needsDisplay=!1;this.canvas=document.getElementById(a);this.ctx=this.canvas.getContext("2d");this.mouseHitElm=null;if(h)this.mouseHitElm=h};
Stratiscape.Layer.prototype.draw=function(){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);for(var a in this.children)typeof this.children[a].draw=="function"&&this.children[a].draw(this.ctx);this.needsDisplay=!1};Stratiscape.Layer.prototype.isInBounds=function(a,b){return this.x<=a&&this.y<=b&&this.x+this.width>=a&&this.y+this.height>=b?!0:!1};Stratiscape.Layer.prototype.addChild=function(a){a.layer=this;this.children.push(a);this.needsDisplay=!0};
Stratiscape.Layer.prototype.removeChild=function(a){var b=this.children.indexOf(a);if(b!=-1)a.layer=null,this.children.splice(b,1),this.needsDisplay=!0};Stratiscape.Layer.prototype.clear=function(){for(var a in this.children)this.children[a].layer=null;this.children=[];this.needsDisplay=!0};Stratiscape.DrawnObject=Class.extend({init:function(){this.y=this.x=0;this.layer=null},draw:function(){},isInBounds:function(){return!1}});