modified setDefaultAttrs() so that it doesn't overwrite attrs defaulted in a custom class that extends a Kinetic class

This commit is contained in:
Eric Rowell 2012-05-12 15:15:42 -07:00
parent 28f7fc246d
commit 1146919d3d
4 changed files with 28 additions and 12 deletions

18
dist/kinetic-core.js vendored
View File

@ -3,7 +3,7 @@
* http://www.kineticjs.com/ * http://www.kineticjs.com/
* Copyright 2012, Eric Rowell * Copyright 2012, Eric Rowell
* Licensed under the MIT or GPL Version 2 licenses. * Licensed under the MIT or GPL Version 2 licenses.
* Date: May 09 2012 * Date: May 12 2012
* *
* Copyright (C) 2011 - 2012 by Eric Rowell * Copyright (C) 2011 - 2012 by Eric Rowell
* *
@ -308,8 +308,16 @@ Kinetic.Node.prototype = {
if(config) { if(config) {
for(var key in config) { for(var key in config) {
var val = config[key]; /*
this.attrs[key] = config[key]; * only set the attr if it's undefined in case
* a developer writes a custom class that extends
* a Kinetic Class such that their default property
* isn't overwritten by the Kinetic Class default
* property
*/
if(this.attrs[key] === undefined) {
this.attrs[key] = config[key];
}
} }
} }
}, },
@ -831,7 +839,7 @@ Kinetic.Node.prototype = {
* @param {Number} y * @param {Number} y
*/ */
setCenterOffset: function() { setCenterOffset: function() {
var pos = Kinetic.GlobalObject._getPoint(arguments); var pos = Kinetic.GlobalObject._getPoint(arguments);
this.attrs.centerOffset.x = pos.x; this.attrs.centerOffset.x = pos.x;
this.attrs.centerOffset.y = pos.y; this.attrs.centerOffset.y = pos.y;
}, },
@ -1496,7 +1504,7 @@ Kinetic.Stage.prototype = {
this._setDefaults(); this._setDefaults();
// reset node attrs // reset node attrs
this.setDefaultAttrs({ this.setAttrs({
visible: true, visible: true,
listening: true, listening: true,
name: undefined, name: undefined,

File diff suppressed because one or more lines are too long

View File

@ -124,8 +124,16 @@ Kinetic.Node.prototype = {
if(config) { if(config) {
for(var key in config) { for(var key in config) {
var val = config[key]; /*
this.attrs[key] = config[key]; * only set the attr if it's undefined in case
* a developer writes a custom class that extends
* a Kinetic Class such that their default property
* isn't overwritten by the Kinetic Class default
* property
*/
if(this.attrs[key] === undefined) {
this.attrs[key] = config[key];
}
} }
} }
}, },
@ -647,7 +655,7 @@ Kinetic.Node.prototype = {
* @param {Number} y * @param {Number} y
*/ */
setCenterOffset: function() { setCenterOffset: function() {
var pos = Kinetic.GlobalObject._getPoint(arguments); var pos = Kinetic.GlobalObject._getPoint(arguments);
this.attrs.centerOffset.x = pos.x; this.attrs.centerOffset.x = pos.x;
this.attrs.centerOffset.y = pos.y; this.attrs.centerOffset.y = pos.y;
}, },

View File

@ -213,7 +213,7 @@ Kinetic.Stage.prototype = {
this._setDefaults(); this._setDefaults();
// reset node attrs // reset node attrs
this.setDefaultAttrs({ this.setAttrs({
visible: true, visible: true,
listening: true, listening: true,
name: undefined, name: undefined,