mirror of
https://github.com/konvajs/konva.git
synced 2025-11-08 02:24:44 +08:00
in addition to Collection each() and apply(), I wanted to make it easier to attach event listeners to node collections, so I went with David Johansson's approach for whitelisting on() and off().
The difference now is that the on() and off() methods are dynamically added to the Collections prototype from Node, which acts as a wrapper around each()
This commit is contained in:
18
dist/kinetic-core.js
vendored
18
dist/kinetic-core.js
vendored
@@ -1507,6 +1507,7 @@ Kinetic.Node.prototype = {
|
||||
addChildren(nodes);
|
||||
}
|
||||
}
|
||||
|
||||
if(that.nodeType !== 'Stage') {
|
||||
addChildren(that.getStage().getChildren());
|
||||
}
|
||||
@@ -2280,6 +2281,22 @@ Kinetic.Node.prototype.isListening = Kinetic.Node.prototype.getListening;
|
||||
*/
|
||||
Kinetic.Node.prototype.isDraggable = Kinetic.Node.prototype.getDraggable;
|
||||
|
||||
// collection mappings
|
||||
(function() {
|
||||
var collectionMappings = ['on', 'off'];
|
||||
for(var n = 0; n < collectionMappings.length; n++) {
|
||||
// induce scope
|
||||
(function(i) {
|
||||
var method = collectionMappings[i];
|
||||
Kinetic.Collection.prototype[method] = function() {
|
||||
var args = [].slice.call(arguments);
|
||||
args.unshift(method);
|
||||
this.apply.apply(this, args);
|
||||
};
|
||||
})(n);
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* set node x position
|
||||
* @name setX
|
||||
@@ -2413,7 +2430,6 @@ Kinetic.Node.prototype.isDraggable = Kinetic.Node.prototype.getDraggable;
|
||||
* @name getListening
|
||||
* @methodOf Kinetic.Node.prototype
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Container
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
6
dist/kinetic-core.min.js
vendored
6
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
17
src/Node.js
17
src/Node.js
@@ -284,6 +284,7 @@ Kinetic.Node.prototype = {
|
||||
addChildren(nodes);
|
||||
}
|
||||
}
|
||||
|
||||
if(that.nodeType !== 'Stage') {
|
||||
addChildren(that.getStage().getChildren());
|
||||
}
|
||||
@@ -1057,6 +1058,22 @@ Kinetic.Node.prototype.isListening = Kinetic.Node.prototype.getListening;
|
||||
*/
|
||||
Kinetic.Node.prototype.isDraggable = Kinetic.Node.prototype.getDraggable;
|
||||
|
||||
// collection mappings
|
||||
(function() {
|
||||
var collectionMappings = ['on', 'off'];
|
||||
for(var n = 0; n < collectionMappings.length; n++) {
|
||||
// induce scope
|
||||
(function(i) {
|
||||
var method = collectionMappings[i];
|
||||
Kinetic.Collection.prototype[method] = function() {
|
||||
var args = [].slice.call(arguments);
|
||||
args.unshift(method);
|
||||
this.apply.apply(this, args);
|
||||
};
|
||||
})(n);
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* set node x position
|
||||
* @name setX
|
||||
|
||||
@@ -742,7 +742,7 @@ Test.prototype.tests = {
|
||||
|
||||
test(shapes.length === 2, 'shapes array should have 2 elements');
|
||||
var a = 0;
|
||||
shapes.apply('on', 'mouseover', function() {
|
||||
shapes.on('mouseover', function() {
|
||||
a++;
|
||||
});
|
||||
circle.simulate('mouseover');
|
||||
|
||||
Reference in New Issue
Block a user