mirror of
https://github.com/konvajs/konva.git
synced 2025-05-04 04:57:59 +08:00
changed listen property to listening, listen() to setListening(), and isListening() to getListening() for consistency
This commit is contained in:
parent
c8d8aa6028
commit
76c85a639e
38
dist/kinetic-core.js
vendored
38
dist/kinetic-core.js
vendored
@ -395,7 +395,7 @@ window.requestAnimFrame = (function(callback) {
|
|||||||
Kinetic.Node = function(config) {
|
Kinetic.Node = function(config) {
|
||||||
this.defaultNodeAttrs = {
|
this.defaultNodeAttrs = {
|
||||||
visible: true,
|
visible: true,
|
||||||
listen: true,
|
listening: true,
|
||||||
name: undefined,
|
name: undefined,
|
||||||
alpha: 1,
|
alpha: 1,
|
||||||
x: 0,
|
x: 0,
|
||||||
@ -859,21 +859,6 @@ Kinetic.Node.prototype = {
|
|||||||
rotation: this.getRotation() + (deg * Math.PI / 180)
|
rotation: this.getRotation() + (deg * Math.PI / 180)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* listen or don't listen to events
|
|
||||||
* @param {Boolean} listen
|
|
||||||
*/
|
|
||||||
listen: function(listen) {
|
|
||||||
this.setAttrs({
|
|
||||||
listen: listen
|
|
||||||
});
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* is listening or not
|
|
||||||
*/
|
|
||||||
isListening: function() {
|
|
||||||
return this.attrs.listen;
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* move node to top
|
* move node to top
|
||||||
*/
|
*/
|
||||||
@ -1200,8 +1185,8 @@ Kinetic.Node.prototype = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// add setters and getters
|
// add setters and getters
|
||||||
Kinetic.GlobalObject.addSetters(Kinetic.Node, ['x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'dragConstraint', 'dragBounds']);
|
Kinetic.GlobalObject.addSetters(Kinetic.Node, ['x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'dragConstraint', 'dragBounds', 'listening']);
|
||||||
Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'offset', 'dragConstraint', 'dragBounds']);
|
Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'offset', 'dragConstraint', 'dragBounds', 'listening']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set node x position
|
* set node x position
|
||||||
@ -1265,6 +1250,13 @@ Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType
|
|||||||
* @config {Number} [bottom] bottom bounds position
|
* @config {Number} [bottom] bottom bounds position
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* listen or don't listen to events
|
||||||
|
* @name setListening
|
||||||
|
* @methodOf Kinetic.Node.prototype
|
||||||
|
* @param {Boolean} listening
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get scale
|
* get scale
|
||||||
* @name getScale
|
* @name getScale
|
||||||
@ -1338,6 +1330,12 @@ Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType
|
|||||||
* @name getDragBounds
|
* @name getDragBounds
|
||||||
* @methodOf Kinetic.Node.prototype
|
* @methodOf Kinetic.Node.prototype
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* determine if listening to events or not
|
||||||
|
* @name getListening
|
||||||
|
* @methodOf Kinetic.Node.prototype
|
||||||
|
*/
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
// Container
|
// Container
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
@ -2099,7 +2097,7 @@ else if(!isDragging && this.mouseMove) {
|
|||||||
// propapgate backwards through children
|
// propapgate backwards through children
|
||||||
for(var i = children.length - 1; i >= 0; i--) {
|
for(var i = children.length - 1; i >= 0; i--) {
|
||||||
var child = children[i];
|
var child = children[i];
|
||||||
if(child.attrs.listen) {
|
if(child.getListening()) {
|
||||||
if(child.nodeType === 'Shape') {
|
if(child.nodeType === 'Shape') {
|
||||||
var exit = this._detectEvent(child, evt);
|
var exit = this._detectEvent(child, evt);
|
||||||
if(exit) {
|
if(exit) {
|
||||||
@ -2143,7 +2141,7 @@ else if(!isDragging && this.mouseMove) {
|
|||||||
var shapeDetected = false;
|
var shapeDetected = false;
|
||||||
for(var n = this.children.length - 1; n >= 0; n--) {
|
for(var n = this.children.length - 1; n >= 0; n--) {
|
||||||
var layer = this.children[n];
|
var layer = this.children[n];
|
||||||
if(layer.isVisible() && n >= 0 && layer.attrs.listen) {
|
if(layer.isVisible() && n >= 0 && layer.getListening()) {
|
||||||
if(this._traverseChildren(layer, evt)) {
|
if(this._traverseChildren(layer, evt)) {
|
||||||
shapeDetected = true;
|
shapeDetected = true;
|
||||||
break;
|
break;
|
||||||
|
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
34
src/Node.js
34
src/Node.js
@ -11,7 +11,7 @@
|
|||||||
Kinetic.Node = function(config) {
|
Kinetic.Node = function(config) {
|
||||||
this.defaultNodeAttrs = {
|
this.defaultNodeAttrs = {
|
||||||
visible: true,
|
visible: true,
|
||||||
listen: true,
|
listening: true,
|
||||||
name: undefined,
|
name: undefined,
|
||||||
alpha: 1,
|
alpha: 1,
|
||||||
x: 0,
|
x: 0,
|
||||||
@ -475,21 +475,6 @@ Kinetic.Node.prototype = {
|
|||||||
rotation: this.getRotation() + (deg * Math.PI / 180)
|
rotation: this.getRotation() + (deg * Math.PI / 180)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* listen or don't listen to events
|
|
||||||
* @param {Boolean} listen
|
|
||||||
*/
|
|
||||||
listen: function(listen) {
|
|
||||||
this.setAttrs({
|
|
||||||
listen: listen
|
|
||||||
});
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* is listening or not
|
|
||||||
*/
|
|
||||||
isListening: function() {
|
|
||||||
return this.attrs.listen;
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* move node to top
|
* move node to top
|
||||||
*/
|
*/
|
||||||
@ -816,8 +801,8 @@ Kinetic.Node.prototype = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// add setters and getters
|
// add setters and getters
|
||||||
Kinetic.GlobalObject.addSetters(Kinetic.Node, ['x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'dragConstraint', 'dragBounds']);
|
Kinetic.GlobalObject.addSetters(Kinetic.Node, ['x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'dragConstraint', 'dragBounds', 'listening']);
|
||||||
Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'offset', 'dragConstraint', 'dragBounds']);
|
Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'offset', 'dragConstraint', 'dragBounds', 'listening']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set node x position
|
* set node x position
|
||||||
@ -881,6 +866,13 @@ Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType
|
|||||||
* @config {Number} [bottom] bottom bounds position
|
* @config {Number} [bottom] bottom bounds position
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* listen or don't listen to events
|
||||||
|
* @name setListening
|
||||||
|
* @methodOf Kinetic.Node.prototype
|
||||||
|
* @param {Boolean} listening
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get scale
|
* get scale
|
||||||
* @name getScale
|
* @name getScale
|
||||||
@ -954,3 +946,9 @@ Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType
|
|||||||
* @name getDragBounds
|
* @name getDragBounds
|
||||||
* @methodOf Kinetic.Node.prototype
|
* @methodOf Kinetic.Node.prototype
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* determine if listening to events or not
|
||||||
|
* @name getListening
|
||||||
|
* @methodOf Kinetic.Node.prototype
|
||||||
|
*/
|
@ -531,7 +531,7 @@ else if(!isDragging && this.mouseMove) {
|
|||||||
// propapgate backwards through children
|
// propapgate backwards through children
|
||||||
for(var i = children.length - 1; i >= 0; i--) {
|
for(var i = children.length - 1; i >= 0; i--) {
|
||||||
var child = children[i];
|
var child = children[i];
|
||||||
if(child.attrs.listen) {
|
if(child.getListening()) {
|
||||||
if(child.nodeType === 'Shape') {
|
if(child.nodeType === 'Shape') {
|
||||||
var exit = this._detectEvent(child, evt);
|
var exit = this._detectEvent(child, evt);
|
||||||
if(exit) {
|
if(exit) {
|
||||||
@ -575,7 +575,7 @@ else if(!isDragging && this.mouseMove) {
|
|||||||
var shapeDetected = false;
|
var shapeDetected = false;
|
||||||
for(var n = this.children.length - 1; n >= 0; n--) {
|
for(var n = this.children.length - 1; n >= 0; n--) {
|
||||||
var layer = this.children[n];
|
var layer = this.children[n];
|
||||||
if(layer.isVisible() && n >= 0 && layer.attrs.listen) {
|
if(layer.isVisible() && n >= 0 && layer.getListening()) {
|
||||||
if(this._traverseChildren(layer, evt)) {
|
if(this._traverseChildren(layer, evt)) {
|
||||||
shapeDetected = true;
|
shapeDetected = true;
|
||||||
break;
|
break;
|
||||||
|
@ -2948,19 +2948,19 @@ Test.prototype.tests = {
|
|||||||
width: 200,
|
width: 200,
|
||||||
height: 50,
|
height: 50,
|
||||||
fill: 'red',
|
fill: 'red',
|
||||||
listen: false
|
listening: false
|
||||||
});
|
});
|
||||||
|
|
||||||
layer.add(rect).add(rect2);
|
layer.add(rect).add(rect2);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
test(rect.isListening() === true, 'rect should be listening');
|
test(rect.getListening() === true, 'rect should be listening');
|
||||||
rect.listen(false);
|
rect.setListening(false);
|
||||||
test(rect.isListening() === false, 'rect should not be listening');
|
test(rect.getListening() === false, 'rect should not be listening');
|
||||||
|
|
||||||
test(rect2.isListening() === false, 'rect2 should not be listening');
|
test(rect2.getListening() === false, 'rect2 should not be listening');
|
||||||
rect2.listen(true);
|
rect2.setListening(true);
|
||||||
test(rect2.isListening() === true, 'rect2 should be listening');
|
test(rect2.getListening() === true, 'rect2 should be listening');
|
||||||
},
|
},
|
||||||
'NODE - test offset attr change': function(containerId) {
|
'NODE - test offset attr change': function(containerId) {
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user