mirror of
https://github.com/konvajs/konva.git
synced 2025-09-19 02:37:59 +08:00
ids and names hashes used for node selection via get() has moved to Global in order to greatly simplify the selection logic. This means that node ids and names are shared across all stages. If two stages each have a node with the same id, only the last id set will be accessibile (similar to DOM)
This commit is contained in:
50
src/Stage.js
50
src/Stage.js
@@ -46,8 +46,6 @@
|
||||
this._buildDOM();
|
||||
this._bindContentEvents();
|
||||
Kinetic.Global.stages.push(this);
|
||||
this._addId(this);
|
||||
this._addName(this);
|
||||
|
||||
if(Kinetic.DD) {
|
||||
this._initDragLayer();
|
||||
@@ -283,12 +281,6 @@
|
||||
|
||||
return null;
|
||||
},
|
||||
_getNodeById: function(key) {
|
||||
return this.ids[key] || null;
|
||||
},
|
||||
_getNodesByName: function(key) {
|
||||
return this.names[key] || [];
|
||||
},
|
||||
_resizeDOM: function() {
|
||||
if(this.content) {
|
||||
var width = this.attrs.width;
|
||||
@@ -582,41 +574,6 @@
|
||||
|
||||
this._resizeDOM();
|
||||
},
|
||||
_addId: function(node) {
|
||||
if(node.attrs.id !== undefined) {
|
||||
this.ids[node.attrs.id] = node;
|
||||
}
|
||||
},
|
||||
_removeId: function(id) {
|
||||
if(id !== undefined) {
|
||||
delete this.ids[id];
|
||||
}
|
||||
},
|
||||
_addName: function(node) {
|
||||
var name = node.attrs.name;
|
||||
if(name !== undefined) {
|
||||
if(this.names[name] === undefined) {
|
||||
this.names[name] = [];
|
||||
}
|
||||
this.names[name].push(node);
|
||||
}
|
||||
},
|
||||
_removeName: function(name, _id) {
|
||||
if(name !== undefined) {
|
||||
var nodes = this.names[name];
|
||||
if(nodes !== undefined) {
|
||||
for(var n = 0; n < nodes.length; n++) {
|
||||
var no = nodes[n];
|
||||
if(no._id === _id) {
|
||||
nodes.splice(n, 1);
|
||||
}
|
||||
}
|
||||
if(nodes.length === 0) {
|
||||
delete this.names[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* bind event listener to container DOM element
|
||||
* @param {String} typesStr
|
||||
@@ -640,13 +597,6 @@
|
||||
this.clickStart = false;
|
||||
this.touchPos = undefined;
|
||||
this.tapStart = false;
|
||||
|
||||
/*
|
||||
* ids and names hash needs to be stored at the stage level to prevent
|
||||
* id and name collisions between multiple stages in the document
|
||||
*/
|
||||
this.ids = {};
|
||||
this.names = {};
|
||||
}
|
||||
};
|
||||
Kinetic.Global.extend(Kinetic.Stage, Kinetic.Container);
|
||||
|
Reference in New Issue
Block a user