mirror of
https://github.com/konvajs/konva.git
synced 2026-01-02 20:42:42 +08:00
on attr change handler eent object now contains oldVal and newVal property
This commit is contained in:
21
dist/kinetic-core.js
vendored
21
dist/kinetic-core.js
vendored
@@ -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: Jul 11 2012
|
* Date: Jul 13 2012
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 - 2012 by Eric Rowell
|
* Copyright (C) 2011 - 2012 by Eric Rowell
|
||||||
*
|
*
|
||||||
@@ -617,6 +617,7 @@ Kinetic.Node = Kinetic.Class.extend({
|
|||||||
function setAttrs(obj, c, level) {
|
function setAttrs(obj, c, level) {
|
||||||
for(var key in c) {
|
for(var key in c) {
|
||||||
var val = c[key];
|
var val = c[key];
|
||||||
|
var oldVal = obj[key];
|
||||||
|
|
||||||
// if obj doesn't have the val property, then create it
|
// if obj doesn't have the val property, then create it
|
||||||
if(obj[key] === undefined && val !== undefined) {
|
if(obj[key] === undefined && val !== undefined) {
|
||||||
@@ -688,7 +689,7 @@ Kinetic.Node = Kinetic.Class.extend({
|
|||||||
* level attrs
|
* level attrs
|
||||||
*/
|
*/
|
||||||
if(level === 0) {
|
if(level === 0) {
|
||||||
that._fireChangeEvent(key);
|
that._fireChangeEvent(key, oldVal, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1178,6 +1179,10 @@ Kinetic.Node = Kinetic.Class.extend({
|
|||||||
if(this.attrs.scale.x !== 1 || this.attrs.scale.y !== 1) {
|
if(this.attrs.scale.x !== 1 || this.attrs.scale.y !== 1) {
|
||||||
m.scale(this.attrs.scale.x, this.attrs.scale.y);
|
m.scale(this.attrs.scale.x, this.attrs.scale.y);
|
||||||
}
|
}
|
||||||
|
// center offset
|
||||||
|
if(this.attrs.offset.x !== 0 || this.attrs.offset.y !== 0) {
|
||||||
|
m.translate(-1 * this.attrs.offset.x, -1 * this.attrs.offset.y);
|
||||||
|
}
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
},
|
},
|
||||||
@@ -1218,8 +1223,11 @@ Kinetic.Node = Kinetic.Class.extend({
|
|||||||
node.setAttrs(obj);
|
node.setAttrs(obj);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
_fireChangeEvent: function(attr) {
|
_fireChangeEvent: function(attr, oldVal, newVal) {
|
||||||
this._handleEvent(attr + 'Change', {});
|
this._handleEvent(attr + 'Change', {
|
||||||
|
oldVal: oldVal,
|
||||||
|
newVal: newVal
|
||||||
|
});
|
||||||
},
|
},
|
||||||
_setAttr: function(obj, attr, val) {
|
_setAttr: function(obj, attr, val) {
|
||||||
if(val !== undefined) {
|
if(val !== undefined) {
|
||||||
@@ -3363,11 +3371,6 @@ Kinetic.Shape = Kinetic.Node.extend({
|
|||||||
var node = family[n];
|
var node = family[n];
|
||||||
var t = node.getTransform();
|
var t = node.getTransform();
|
||||||
|
|
||||||
// center offset
|
|
||||||
if(node.attrs.offset.x !== 0 || node.attrs.offset.y !== 0) {
|
|
||||||
t.translate(-1 * node.attrs.offset.x, -1 * node.attrs.offset.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
var m = t.getMatrix();
|
var m = t.getMatrix();
|
||||||
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||||
}
|
}
|
||||||
|
|||||||
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
10
src/Node.js
10
src/Node.js
@@ -187,6 +187,7 @@ Kinetic.Node = Kinetic.Class.extend({
|
|||||||
function setAttrs(obj, c, level) {
|
function setAttrs(obj, c, level) {
|
||||||
for(var key in c) {
|
for(var key in c) {
|
||||||
var val = c[key];
|
var val = c[key];
|
||||||
|
var oldVal = obj[key];
|
||||||
|
|
||||||
// if obj doesn't have the val property, then create it
|
// if obj doesn't have the val property, then create it
|
||||||
if(obj[key] === undefined && val !== undefined) {
|
if(obj[key] === undefined && val !== undefined) {
|
||||||
@@ -258,7 +259,7 @@ Kinetic.Node = Kinetic.Class.extend({
|
|||||||
* level attrs
|
* level attrs
|
||||||
*/
|
*/
|
||||||
if(level === 0) {
|
if(level === 0) {
|
||||||
that._fireChangeEvent(key);
|
that._fireChangeEvent(key, oldVal, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -792,8 +793,11 @@ Kinetic.Node = Kinetic.Class.extend({
|
|||||||
node.setAttrs(obj);
|
node.setAttrs(obj);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
_fireChangeEvent: function(attr) {
|
_fireChangeEvent: function(attr, oldVal, newVal) {
|
||||||
this._handleEvent(attr + 'Change', {});
|
this._handleEvent(attr + 'Change', {
|
||||||
|
oldVal: oldVal,
|
||||||
|
newVal: newVal
|
||||||
|
});
|
||||||
},
|
},
|
||||||
_setAttr: function(obj, attr, val) {
|
_setAttr: function(obj, attr, val) {
|
||||||
if(val !== undefined) {
|
if(val !== undefined) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" type="text/css"href="../base.css">
|
<link rel="stylesheet" type="text/css"href="../base.css">
|
||||||
<script src="../../dist/kinetic-core.min.js"></script>
|
<script src="../../dist/kinetic-core.js"></script>
|
||||||
<script src="../assets/worldMap.js"></script>
|
<script src="../assets/worldMap.js"></script>
|
||||||
<script src="../assets/tiger.js"></script>
|
<script src="../assets/tiger.js"></script>
|
||||||
<script src="../assets/unitDataUrls.js"></script>
|
<script src="../assets/unitDataUrls.js"></script>
|
||||||
|
|||||||
@@ -3252,8 +3252,10 @@ Test.prototype.tests = {
|
|||||||
var shadowChanged = 0;
|
var shadowChanged = 0;
|
||||||
var radiusChanged = 0;
|
var radiusChanged = 0;
|
||||||
|
|
||||||
rect.on('widthChange', function() {
|
rect.on('widthChange', function(evt) {
|
||||||
widthChanged++;
|
widthChanged++;
|
||||||
|
test(evt.oldVal === 200, 'old width should be 200');
|
||||||
|
test(evt.newVal === 210, 'new width should be 210');
|
||||||
});
|
});
|
||||||
|
|
||||||
rect.on('shadowChange', function() {
|
rect.on('shadowChange', function() {
|
||||||
@@ -3655,7 +3657,7 @@ Test.prototype.tests = {
|
|||||||
},
|
},
|
||||||
'NODE - test getPosition and getAbsolutePosition for transformed parent with center offset': function(containerId) {
|
'NODE - test getPosition and getAbsolutePosition for transformed parent with center offset': function(containerId) {
|
||||||
var side = 100;
|
var side = 100;
|
||||||
var diagonal = Math.sqrt(side*side*2);
|
var diagonal = Math.sqrt(side * side * 2);
|
||||||
|
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
@@ -3672,9 +3674,9 @@ Test.prototype.tests = {
|
|||||||
name: 'groupName',
|
name: 'groupName',
|
||||||
id: 'groupId',
|
id: 'groupId',
|
||||||
rotationDeg: 45,
|
rotationDeg: 45,
|
||||||
offset: [side/2, side/2],
|
offset: [side / 2, side / 2],
|
||||||
x: diagonal/2,
|
x: diagonal / 2,
|
||||||
y: diagonal/2
|
y: diagonal / 2
|
||||||
});
|
});
|
||||||
var rect = new Kinetic.Rect({
|
var rect = new Kinetic.Rect({
|
||||||
x: 0,
|
x: 0,
|
||||||
@@ -3703,7 +3705,7 @@ Test.prototype.tests = {
|
|||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
test(Math.round(marker.getAbsolutePosition().x) === Math.round(diagonal), 'marker absolute position x should be about ' + Math.round(diagonal) + ' but is about ' + Math.round(marker.getAbsolutePosition().x));
|
test(Math.round(marker.getAbsolutePosition().x) === Math.round(diagonal), 'marker absolute position x should be about ' + Math.round(diagonal) + ' but is about ' + Math.round(marker.getAbsolutePosition().x));
|
||||||
test(Math.round(marker.getAbsolutePosition().y) === Math.round(diagonal/2), 'marker absolute position y should be about ' + Math.round(diagonal/2) + ' but is about ' + Math.round(marker.getAbsolutePosition().y));
|
test(Math.round(marker.getAbsolutePosition().y) === Math.round(diagonal / 2), 'marker absolute position y should be about ' + Math.round(diagonal / 2) + ' but is about ' + Math.round(marker.getAbsolutePosition().y));
|
||||||
},
|
},
|
||||||
'NODE - test get() selector by adding shape, then group, then layer': function(containerId) {
|
'NODE - test get() selector by adding shape, then group, then layer': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
|||||||
Reference in New Issue
Block a user