mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
refactored stage.reset method. Now storing node default attrs as an object which can be used by the stage to reset itself
This commit is contained in:
parent
44ba6f7e5b
commit
af31e1ee83
36
dist/kinetic-core.js
vendored
36
dist/kinetic-core.js
vendored
@ -373,7 +373,7 @@ window.requestAnimFrame = (function(callback) {
|
|||||||
* @param {Object} config
|
* @param {Object} config
|
||||||
*/
|
*/
|
||||||
Kinetic.Node = function(config) {
|
Kinetic.Node = function(config) {
|
||||||
this.setDefaultAttrs({
|
this.defaultNodeAttrs = {
|
||||||
visible: true,
|
visible: true,
|
||||||
listening: true,
|
listening: true,
|
||||||
name: undefined,
|
name: undefined,
|
||||||
@ -392,8 +392,9 @@ Kinetic.Node = function(config) {
|
|||||||
dragConstraint: 'none',
|
dragConstraint: 'none',
|
||||||
dragBounds: {},
|
dragBounds: {},
|
||||||
draggable: false
|
draggable: false
|
||||||
});
|
};
|
||||||
|
|
||||||
|
this.setDefaultAttrs(this.defaultNodeAttrs);
|
||||||
this.eventListeners = {};
|
this.eventListeners = {};
|
||||||
this.setAttrs(config);
|
this.setAttrs(config);
|
||||||
};
|
};
|
||||||
@ -1485,7 +1486,7 @@ Kinetic.Stage = function(config) {
|
|||||||
this.content = document.createElement('div');
|
this.content = document.createElement('div');
|
||||||
this.dblClickWindow = 400;
|
this.dblClickWindow = 400;
|
||||||
|
|
||||||
this._setDefaults();
|
this._setStageDefaultProperties();
|
||||||
|
|
||||||
// set stage id
|
// set stage id
|
||||||
this._id = Kinetic.GlobalObject.idCounter++;
|
this._id = Kinetic.GlobalObject.idCounter++;
|
||||||
@ -1670,30 +1671,9 @@ Kinetic.Stage.prototype = {
|
|||||||
// remove children
|
// remove children
|
||||||
this.removeChildren();
|
this.removeChildren();
|
||||||
|
|
||||||
// reset stage defaults
|
// defaults
|
||||||
this._setDefaults();
|
this._setStageDefaultProperties();
|
||||||
|
this.setAttrs(this.defaultNodeAttrs);
|
||||||
// reset node attrs
|
|
||||||
this.setAttrs({
|
|
||||||
visible: true,
|
|
||||||
listening: true,
|
|
||||||
name: undefined,
|
|
||||||
alpha: 1,
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
scale: {
|
|
||||||
x: 1,
|
|
||||||
y: 1
|
|
||||||
},
|
|
||||||
rotation: 0,
|
|
||||||
centerOffset: {
|
|
||||||
x: 0,
|
|
||||||
y: 0
|
|
||||||
},
|
|
||||||
dragConstraint: 'none',
|
|
||||||
dragBounds: {},
|
|
||||||
draggable: false
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* load stage with JSON string. De-serializtion does not generate custom
|
* load stage with JSON string. De-serializtion does not generate custom
|
||||||
@ -2359,7 +2339,7 @@ Kinetic.Stage.prototype = {
|
|||||||
/**
|
/**
|
||||||
* set defaults
|
* set defaults
|
||||||
*/
|
*/
|
||||||
_setDefaults: function() {
|
_setStageDefaultProperties: function() {
|
||||||
this.clickStart = false;
|
this.clickStart = false;
|
||||||
this.targetShape = undefined;
|
this.targetShape = undefined;
|
||||||
this.targetFound = false;
|
this.targetFound = false;
|
||||||
|
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
@ -9,7 +9,7 @@
|
|||||||
* @param {Object} config
|
* @param {Object} config
|
||||||
*/
|
*/
|
||||||
Kinetic.Node = function(config) {
|
Kinetic.Node = function(config) {
|
||||||
this.setDefaultAttrs({
|
this.defaultNodeAttrs = {
|
||||||
visible: true,
|
visible: true,
|
||||||
listening: true,
|
listening: true,
|
||||||
name: undefined,
|
name: undefined,
|
||||||
@ -28,8 +28,9 @@ Kinetic.Node = function(config) {
|
|||||||
dragConstraint: 'none',
|
dragConstraint: 'none',
|
||||||
dragBounds: {},
|
dragBounds: {},
|
||||||
draggable: false
|
draggable: false
|
||||||
});
|
};
|
||||||
|
|
||||||
|
this.setDefaultAttrs(this.defaultNodeAttrs);
|
||||||
this.eventListeners = {};
|
this.eventListeners = {};
|
||||||
this.setAttrs(config);
|
this.setAttrs(config);
|
||||||
};
|
};
|
||||||
|
31
src/Stage.js
31
src/Stage.js
@ -34,7 +34,7 @@ Kinetic.Stage = function(config) {
|
|||||||
this.content = document.createElement('div');
|
this.content = document.createElement('div');
|
||||||
this.dblClickWindow = 400;
|
this.dblClickWindow = 400;
|
||||||
|
|
||||||
this._setDefaults();
|
this._setStageDefaultProperties();
|
||||||
|
|
||||||
// set stage id
|
// set stage id
|
||||||
this._id = Kinetic.GlobalObject.idCounter++;
|
this._id = Kinetic.GlobalObject.idCounter++;
|
||||||
@ -219,30 +219,9 @@ Kinetic.Stage.prototype = {
|
|||||||
// remove children
|
// remove children
|
||||||
this.removeChildren();
|
this.removeChildren();
|
||||||
|
|
||||||
// reset stage defaults
|
// defaults
|
||||||
this._setDefaults();
|
this._setStageDefaultProperties();
|
||||||
|
this.setAttrs(this.defaultNodeAttrs);
|
||||||
// reset node attrs
|
|
||||||
this.setAttrs({
|
|
||||||
visible: true,
|
|
||||||
listening: true,
|
|
||||||
name: undefined,
|
|
||||||
alpha: 1,
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
scale: {
|
|
||||||
x: 1,
|
|
||||||
y: 1
|
|
||||||
},
|
|
||||||
rotation: 0,
|
|
||||||
centerOffset: {
|
|
||||||
x: 0,
|
|
||||||
y: 0
|
|
||||||
},
|
|
||||||
dragConstraint: 'none',
|
|
||||||
dragBounds: {},
|
|
||||||
draggable: false
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* load stage with JSON string. De-serializtion does not generate custom
|
* load stage with JSON string. De-serializtion does not generate custom
|
||||||
@ -908,7 +887,7 @@ Kinetic.Stage.prototype = {
|
|||||||
/**
|
/**
|
||||||
* set defaults
|
* set defaults
|
||||||
*/
|
*/
|
||||||
_setDefaults: function() {
|
_setStageDefaultProperties: function() {
|
||||||
this.clickStart = false;
|
this.clickStart = false;
|
||||||
this.targetShape = undefined;
|
this.targetShape = undefined;
|
||||||
this.targetFound = false;
|
this.targetFound = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user