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:
Eric Rowell 2012-05-26 18:40:43 -07:00
parent 44ba6f7e5b
commit af31e1ee83
4 changed files with 18 additions and 58 deletions

36
dist/kinetic-core.js vendored
View File

@ -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;

File diff suppressed because one or more lines are too long

View File

@ -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);
}; };

View File

@ -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;