mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 13:03:10 +08:00
new setAttrs() method which enables you to set attributes in bulk
This commit is contained in:
parent
b7f14ca821
commit
5c7b969974
103
dist/kinetic-core.js
vendored
103
dist/kinetic-core.js
vendored
@ -183,50 +183,10 @@ Kinetic.Node = function(config) {
|
|||||||
this.attrs.dragConstraint = 'none';
|
this.attrs.dragConstraint = 'none';
|
||||||
this.attrs.dragBounds = {};
|
this.attrs.dragBounds = {};
|
||||||
this.attrs.draggable = false;
|
this.attrs.draggable = false;
|
||||||
|
|
||||||
this.eventListeners = {};
|
this.eventListeners = {};
|
||||||
|
|
||||||
// set properties from config
|
// set attrs
|
||||||
if(config) {
|
this.setAttrs(config);
|
||||||
for(var key in config) {
|
|
||||||
// handle special keys
|
|
||||||
switch (key) {
|
|
||||||
/*
|
|
||||||
* config properties that require a method to
|
|
||||||
* be set
|
|
||||||
*/
|
|
||||||
case 'draggable':
|
|
||||||
this.draggable(config[key]);
|
|
||||||
break;
|
|
||||||
case 'listening':
|
|
||||||
this.listen(config[key]);
|
|
||||||
break;
|
|
||||||
case 'rotationDeg':
|
|
||||||
this.attrs.rotation = config[key] * Math.PI / 180;
|
|
||||||
break;
|
|
||||||
/*
|
|
||||||
* config objects that we don't want in attrs
|
|
||||||
*/
|
|
||||||
case 'drawFunc':
|
|
||||||
break;
|
|
||||||
case 'image':
|
|
||||||
break;
|
|
||||||
case 'container':
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
this.attrs[key] = config[key];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// overrides
|
|
||||||
if(this.attrs.centerOffset.x === undefined) {
|
|
||||||
this.attrs.centerOffset.x = 0;
|
|
||||||
}
|
|
||||||
if(this.attrs.centerOffset.y === undefined) {
|
|
||||||
this.attrs.centerOffset.y = 0;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
* Node methods
|
* Node methods
|
||||||
@ -307,6 +267,65 @@ Kinetic.Node.prototype = {
|
|||||||
getAttrs: function() {
|
getAttrs: function() {
|
||||||
return this.attrs;
|
return this.attrs;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* set attrs
|
||||||
|
* @param {Object} config
|
||||||
|
*/
|
||||||
|
setAttrs: function(config) {
|
||||||
|
// set properties from config
|
||||||
|
if(config) {
|
||||||
|
for(var key in config) {
|
||||||
|
var val = config[key];
|
||||||
|
// handle special keys
|
||||||
|
switch (key) {
|
||||||
|
/*
|
||||||
|
* config properties that require a method to
|
||||||
|
* be set
|
||||||
|
*/
|
||||||
|
case 'draggable':
|
||||||
|
this.draggable(config[key]);
|
||||||
|
break;
|
||||||
|
case 'listening':
|
||||||
|
this.listen(config[key]);
|
||||||
|
break;
|
||||||
|
case 'rotationDeg':
|
||||||
|
this.attrs.rotation = config[key] * Math.PI / 180;
|
||||||
|
break;
|
||||||
|
/*
|
||||||
|
* config objects
|
||||||
|
*/
|
||||||
|
case 'centerOffset':
|
||||||
|
if(val.x !== undefined) {
|
||||||
|
this.attrs[key].x = val.x;
|
||||||
|
}
|
||||||
|
if(val.y !== undefined) {
|
||||||
|
this.attrs[key].y = val.y;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'scale':
|
||||||
|
if(val.x !== undefined) {
|
||||||
|
this.attrs[key].x = val.x;
|
||||||
|
}
|
||||||
|
if(val.y !== undefined) {
|
||||||
|
this.attrs[key].y = val.y;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/*
|
||||||
|
* config properties that we don't want in attrs
|
||||||
|
*/
|
||||||
|
case 'drawFunc':
|
||||||
|
break;
|
||||||
|
case 'image':
|
||||||
|
break;
|
||||||
|
case 'container':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.attrs[key] = config[key];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* show node
|
* show node
|
||||||
*/
|
*/
|
||||||
|
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
103
src/Node.js
103
src/Node.js
@ -31,50 +31,10 @@ Kinetic.Node = function(config) {
|
|||||||
this.attrs.dragConstraint = 'none';
|
this.attrs.dragConstraint = 'none';
|
||||||
this.attrs.dragBounds = {};
|
this.attrs.dragBounds = {};
|
||||||
this.attrs.draggable = false;
|
this.attrs.draggable = false;
|
||||||
|
|
||||||
this.eventListeners = {};
|
this.eventListeners = {};
|
||||||
|
|
||||||
// set properties from config
|
// set attrs
|
||||||
if(config) {
|
this.setAttrs(config);
|
||||||
for(var key in config) {
|
|
||||||
// handle special keys
|
|
||||||
switch (key) {
|
|
||||||
/*
|
|
||||||
* config properties that require a method to
|
|
||||||
* be set
|
|
||||||
*/
|
|
||||||
case 'draggable':
|
|
||||||
this.draggable(config[key]);
|
|
||||||
break;
|
|
||||||
case 'listening':
|
|
||||||
this.listen(config[key]);
|
|
||||||
break;
|
|
||||||
case 'rotationDeg':
|
|
||||||
this.attrs.rotation = config[key] * Math.PI / 180;
|
|
||||||
break;
|
|
||||||
/*
|
|
||||||
* config objects that we don't want in attrs
|
|
||||||
*/
|
|
||||||
case 'drawFunc':
|
|
||||||
break;
|
|
||||||
case 'image':
|
|
||||||
break;
|
|
||||||
case 'container':
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
this.attrs[key] = config[key];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// overrides
|
|
||||||
if(this.attrs.centerOffset.x === undefined) {
|
|
||||||
this.attrs.centerOffset.x = 0;
|
|
||||||
}
|
|
||||||
if(this.attrs.centerOffset.y === undefined) {
|
|
||||||
this.attrs.centerOffset.y = 0;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
* Node methods
|
* Node methods
|
||||||
@ -155,6 +115,65 @@ Kinetic.Node.prototype = {
|
|||||||
getAttrs: function() {
|
getAttrs: function() {
|
||||||
return this.attrs;
|
return this.attrs;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* set attrs
|
||||||
|
* @param {Object} config
|
||||||
|
*/
|
||||||
|
setAttrs: function(config) {
|
||||||
|
// set properties from config
|
||||||
|
if(config) {
|
||||||
|
for(var key in config) {
|
||||||
|
var val = config[key];
|
||||||
|
// handle special keys
|
||||||
|
switch (key) {
|
||||||
|
/*
|
||||||
|
* config properties that require a method to
|
||||||
|
* be set
|
||||||
|
*/
|
||||||
|
case 'draggable':
|
||||||
|
this.draggable(config[key]);
|
||||||
|
break;
|
||||||
|
case 'listening':
|
||||||
|
this.listen(config[key]);
|
||||||
|
break;
|
||||||
|
case 'rotationDeg':
|
||||||
|
this.attrs.rotation = config[key] * Math.PI / 180;
|
||||||
|
break;
|
||||||
|
/*
|
||||||
|
* config objects
|
||||||
|
*/
|
||||||
|
case 'centerOffset':
|
||||||
|
if(val.x !== undefined) {
|
||||||
|
this.attrs[key].x = val.x;
|
||||||
|
}
|
||||||
|
if(val.y !== undefined) {
|
||||||
|
this.attrs[key].y = val.y;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'scale':
|
||||||
|
if(val.x !== undefined) {
|
||||||
|
this.attrs[key].x = val.x;
|
||||||
|
}
|
||||||
|
if(val.y !== undefined) {
|
||||||
|
this.attrs[key].y = val.y;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/*
|
||||||
|
* config properties that we don't want in attrs
|
||||||
|
*/
|
||||||
|
case 'drawFunc':
|
||||||
|
break;
|
||||||
|
case 'image':
|
||||||
|
break;
|
||||||
|
case 'container':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.attrs[key] = config[key];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* show node
|
* show node
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user