konva/dist/kinetic-Layer-current.min.js

2 lines
3.2 KiB
JavaScript

Kinetic.Layer=function(a){this._initLayer(a)},Kinetic.Layer.prototype={_initLayer:function(a){this.setDefaultAttrs({clearBeforeDraw:!0}),this.nodeType="Layer",this.beforeDrawFunc=undefined,this.afterDrawFunc=undefined,this.canvas=new Kinetic.Canvas,this.canvas.getElement().style.position="absolute",this.bufferCanvas=new Kinetic.Canvas,this.bufferCanvas.name="buffer",Kinetic.Container.call(this,a)},draw:function(a){this.beforeDrawFunc!==undefined&&this.beforeDrawFunc.call(this);var b=[];a?b.push(a):(b.push(this.getCanvas()),b.push(this.bufferCanvas));var c=b.length;for(var d=0;d<c;d++){var a=b[d];Kinetic.Node.prototype._shouldDraw.call(this,a)&&(this.attrs.clearBeforeDraw&&a.clear(),Kinetic.Container.prototype.draw.call(this,a))}this.afterDrawFunc!==undefined&&this.afterDrawFunc.call(this)},drawBuffer:function(){this.draw(this.bufferCanvas)},drawScene:function(){this.draw(this.getCanvas())},beforeDraw:function(a){this.beforeDrawFunc=a},afterDraw:function(a){this.afterDrawFunc=a},getCanvas:function(){return this.canvas},getContext:function(){return this.canvas.context},clear:function(){this.getCanvas().clear()},setVisible:function(a){Kinetic.Node.prototype.setVisible.call(this,a),a?(this.canvas.element.style.display="block",this.bufferCanvas.element.style.display="block"):(this.canvas.element.style.display="none",this.bufferCanvas.element.style.display="none")},setZIndex:function(a){Kinetic.Node.prototype.setZIndex.call(this,a);var b=this.getStage();b&&(b.content.removeChild(this.canvas.element),a<b.getChildren().length-1?b.content.insertBefore(this.canvas.element,b.getChildren()[a+1].canvas.element):b.content.appendChild(this.canvas.element))},moveToTop:function(){Kinetic.Node.prototype.moveToTop.call(this);var a=this.getStage();a&&(a.content.removeChild(this.canvas.element),a.content.appendChild(this.canvas.element))},moveUp:function(){if(Kinetic.Node.prototype.moveUp.call(this)){var a=this.getStage();a&&(a.content.removeChild(this.canvas.element),this.index<a.getChildren().length-1?a.content.insertBefore(this.canvas.element,a.getChildren()[this.index+1].canvas.element):a.content.appendChild(this.canvas.element))}},moveDown:function(){if(Kinetic.Node.prototype.moveDown.call(this)){var a=this.getStage();if(a){var b=a.getChildren();a.content.removeChild(this.canvas.element),a.content.insertBefore(this.canvas.element,b[this.index+1].canvas.element)}}},moveToBottom:function(){if(Kinetic.Node.prototype.moveToBottom.call(this)){var a=this.getStage();if(a){var b=a.getChildren();a.content.removeChild(this.canvas.element),a.content.insertBefore(this.canvas.element,b[1].canvas.element)}}},getLayer:function(){return this},toDataURL:function(a){var b,c=a&&a.mimeType?a.mimeType:null,d=a&&a.quality?a.quality:null;if(!this.isVisible()){var e=this.getStage();b=new Kinetic.Canvas(e.getWidth(),e.getHeight())}else a&&a.width&&a.height?(b=new Kinetic.Canvas(a.width,a.height),this.draw(b)):b=this.getCanvas();return b.toDataURL(c,d)},remove:function(){Kinetic.Node.prototype.remove.call(this);try{this.getStage().content.removeChild(this.canvas.element)}catch(a){Kinetic.Global.warn("unable to remove layer scene canvas element from the document")}}},Kinetic.Global.extend(Kinetic.Layer,Kinetic.Container),Kinetic.Node.addGettersSetters(Kinetic.Layer,["clearBeforeDraw"]);