on attr change handler eent object now contains oldVal and newVal property

This commit is contained in:
Eric Rowell 2012-07-13 20:06:28 -07:00
parent 01e2541c9d
commit 9a83d3dfdf
5 changed files with 31 additions and 22 deletions

21
dist/kinetic-core.js vendored
View File

@ -3,7 +3,7 @@
* http://www.kineticjs.com/
* Copyright 2012, Eric Rowell
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Jul 11 2012
* Date: Jul 13 2012
*
* Copyright (C) 2011 - 2012 by Eric Rowell
*
@ -617,6 +617,7 @@ Kinetic.Node = Kinetic.Class.extend({
function setAttrs(obj, c, level) {
for(var key in c) {
var val = c[key];
var oldVal = obj[key];
// if obj doesn't have the val property, then create it
if(obj[key] === undefined && val !== undefined) {
@ -688,7 +689,7 @@ Kinetic.Node = Kinetic.Class.extend({
* level attrs
*/
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) {
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;
},
@ -1218,8 +1223,11 @@ Kinetic.Node = Kinetic.Class.extend({
node.setAttrs(obj);
return node;
},
_fireChangeEvent: function(attr) {
this._handleEvent(attr + 'Change', {});
_fireChangeEvent: function(attr, oldVal, newVal) {
this._handleEvent(attr + 'Change', {
oldVal: oldVal,
newVal: newVal
});
},
_setAttr: function(obj, attr, val) {
if(val !== undefined) {
@ -3363,11 +3371,6 @@ Kinetic.Shape = Kinetic.Node.extend({
var node = family[n];
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();
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
}

File diff suppressed because one or more lines are too long

View File

@ -187,6 +187,7 @@ Kinetic.Node = Kinetic.Class.extend({
function setAttrs(obj, c, level) {
for(var key in c) {
var val = c[key];
var oldVal = obj[key];
// if obj doesn't have the val property, then create it
if(obj[key] === undefined && val !== undefined) {
@ -258,7 +259,7 @@ Kinetic.Node = Kinetic.Class.extend({
* level attrs
*/
if(level === 0) {
that._fireChangeEvent(key);
that._fireChangeEvent(key, oldVal, val);
}
}
}
@ -792,8 +793,11 @@ Kinetic.Node = Kinetic.Class.extend({
node.setAttrs(obj);
return node;
},
_fireChangeEvent: function(attr) {
this._handleEvent(attr + 'Change', {});
_fireChangeEvent: function(attr, oldVal, newVal) {
this._handleEvent(attr + 'Change', {
oldVal: oldVal,
newVal: newVal
});
},
_setAttr: function(obj, attr, val) {
if(val !== undefined) {

View File

@ -2,7 +2,7 @@
<html>
<head>
<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/tiger.js"></script>
<script src="../assets/unitDataUrls.js"></script>

View File

@ -3252,8 +3252,10 @@ Test.prototype.tests = {
var shadowChanged = 0;
var radiusChanged = 0;
rect.on('widthChange', function() {
rect.on('widthChange', function(evt) {
widthChanged++;
test(evt.oldVal === 200, 'old width should be 200');
test(evt.newVal === 210, 'new width should be 210');
});
rect.on('shadowChange', function() {
@ -3655,7 +3657,7 @@ Test.prototype.tests = {
},
'NODE - test getPosition and getAbsolutePosition for transformed parent with center offset': function(containerId) {
var side = 100;
var diagonal = Math.sqrt(side*side*2);
var diagonal = Math.sqrt(side * side * 2);
var stage = new Kinetic.Stage({
container: containerId,
@ -3672,9 +3674,9 @@ Test.prototype.tests = {
name: 'groupName',
id: 'groupId',
rotationDeg: 45,
offset: [side/2, side/2],
x: diagonal/2,
y: diagonal/2
offset: [side / 2, side / 2],
x: diagonal / 2,
y: diagonal / 2
});
var rect = new Kinetic.Rect({
x: 0,
@ -3703,7 +3705,7 @@ Test.prototype.tests = {
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().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) {
var stage = new Kinetic.Stage({