mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 04:42:02 +08:00
added stage.reset() method so that you can reset the stage to its original state. hooked this in with stage.load() so that the stage starts when a clean slate when loading json
This commit is contained in:
parent
9cc380608e
commit
bd17b54aa8
5
dist/kinetic-core.js
vendored
5
dist/kinetic-core.js
vendored
@ -1456,6 +1456,8 @@ Kinetic.Stage.prototype = {
|
||||
* @param {String} JSON string
|
||||
*/
|
||||
load: function(json) {
|
||||
this.reset();
|
||||
|
||||
function loadNode(node, obj) {
|
||||
var children = obj.children;
|
||||
if(children !== undefined) {
|
||||
@ -2173,6 +2175,9 @@ Kinetic.Layer.prototype = {
|
||||
if(timeDiff >= throttle) {
|
||||
this._draw();
|
||||
this.lastDrawTime = time;
|
||||
if(this.drawTimeout !== undefined) {
|
||||
clearTimeout(this.drawTimeout);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* if we cannot draw the layer due to throttling,
|
||||
|
4
dist/kinetic-core.min.js
vendored
4
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
@ -42,6 +42,9 @@ Kinetic.Layer.prototype = {
|
||||
if(timeDiff >= throttle) {
|
||||
this._draw();
|
||||
this.lastDrawTime = time;
|
||||
if(this.drawTimeout !== undefined) {
|
||||
clearTimeout(this.drawTimeout);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* if we cannot draw the layer due to throttling,
|
||||
|
@ -241,6 +241,8 @@ Kinetic.Stage.prototype = {
|
||||
* @param {String} JSON string
|
||||
*/
|
||||
load: function(json) {
|
||||
this.reset();
|
||||
|
||||
function loadNode(node, obj) {
|
||||
var children = obj.children;
|
||||
if(children !== undefined) {
|
||||
|
@ -95,7 +95,8 @@ Test.prototype.tests = {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
height: 200
|
||||
height: 200,
|
||||
x: 100
|
||||
});
|
||||
var layer = new Kinetic.Layer();
|
||||
var group = new Kinetic.Group();
|
||||
@ -115,8 +116,11 @@ Test.prototype.tests = {
|
||||
group.add(circle);
|
||||
layer.draw();
|
||||
|
||||
var expectedJson = '{"attrs":{"width":578,"height":200,"visible":true,"listening":true,"alpha":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"centerOffset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false},"nodeType":"Stage","children":[{"attrs":{"throttle":12,"visible":true,"listening":true,"alpha":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"centerOffset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listening":true,"alpha":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"centerOffset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false},"nodeType":"Group","children":[{"attrs":{"radius":70,"fill":"green","stroke":"black","strokeWidth":4,"detectionType":"path","visible":true,"listening":true,"name":"myCircle","alpha":1,"x":289,"y":100,"scale":{"x":1,"y":1},"rotation":0,"centerOffset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":true},"nodeType":"Shape","shapeType":"Circle"}]}]}]}';
|
||||
test(stage.toJSON() === expectedJson, 'problem with serialization');
|
||||
test(stage.getChildren().length === 1, 'stage should have one child');
|
||||
test(stage.getX() === 100, 'stage x should be 100');
|
||||
stage.reset();
|
||||
test(stage.getChildren().length === 0, 'stage should have no children');
|
||||
test(stage.getX() === 0, 'stage x should be 0');
|
||||
},
|
||||
'STAGE - test getAttrs()': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
|
Loading…
Reference in New Issue
Block a user