mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
Fix clone function to support custom Shapes. close #71
This commit is contained in:
parent
42eda94675
commit
744dd61992
@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- context wrapper is more capable with native context.
|
- context wrapper is more capable with native context.
|
||||||
So you can use `context.fillStyle` property in your `sceneFunc` without accessing native context.
|
So you can use `context.fillStyle` property in your `sceneFunc` without accessing native context.
|
||||||
- `toDataURL` now handle pixelRatio. So image for stage 400x400 for retina will be 800x800.
|
- `toDataURL` now handle pixelRatio. So image for stage 400x400 for retina will be 800x800.
|
||||||
|
- Correct `clone()` for custom nodes
|
||||||
|
|
||||||
|
|
||||||
## [0.9.0][2015-02-27]
|
## [0.9.0][2015-02-27]
|
||||||
|
@ -1340,7 +1340,7 @@
|
|||||||
attrs[key] = obj[key];
|
attrs[key] = obj[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
var node = new Konva[className](attrs);
|
var node = new this.constructor(attrs);
|
||||||
// copy over listeners
|
// copy over listeners
|
||||||
for(key in this.eventListeners) {
|
for(key in this.eventListeners) {
|
||||||
allListeners = this.eventListeners[key];
|
allListeners = this.eventListeners[key];
|
||||||
|
22
src/Util.js
22
src/Util.js
@ -835,18 +835,20 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
extend: function(child, parent) {
|
extend: function(child, parent) {
|
||||||
function Ctor() {
|
function Ctor() {
|
||||||
this.constructor = child;
|
this.constructor = child;
|
||||||
}
|
}
|
||||||
Ctor.prototype = parent.prototype;
|
Ctor.prototype = parent.prototype;
|
||||||
var old_proto = child.prototype;
|
var old_proto = child.prototype;
|
||||||
child.prototype = new Ctor();
|
child.prototype = new Ctor();
|
||||||
for (var key in old_proto) {
|
for (var key in old_proto) {
|
||||||
if (old_proto.hasOwnProperty(key)) {
|
if (old_proto.hasOwnProperty(key)) {
|
||||||
child.prototype[key] = old_proto[key];
|
child.prototype[key] = old_proto[key];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
child.__super__ = parent.prototype;
|
}
|
||||||
|
child.__super__ = parent.prototype;
|
||||||
|
// create reference to parent
|
||||||
|
child.super = parent;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* adds methods to a constructor prototype
|
* adds methods to a constructor prototype
|
||||||
|
@ -1178,4 +1178,28 @@ suite('Shape', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('clone custom shape', function() {
|
||||||
|
var className = 'myCustomName'
|
||||||
|
var CustomShape = function() {
|
||||||
|
CustomShape.super.apply(this, arguments);
|
||||||
|
this.className = className;
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomShape.prototype.foo = function() {};
|
||||||
|
|
||||||
|
Konva.Util.extend(CustomShape, Konva.Shape);
|
||||||
|
|
||||||
|
var myShape = new CustomShape({
|
||||||
|
fill : 'grey'
|
||||||
|
});
|
||||||
|
|
||||||
|
var clone = myShape.clone();
|
||||||
|
assert.equal(clone instanceof CustomShape, true);
|
||||||
|
assert.equal(clone instanceof Konva.Shape, true);
|
||||||
|
assert.equal(clone.className, className);
|
||||||
|
assert.equal(clone.fill(), 'grey');
|
||||||
|
assert.equal(clone.foo, CustomShape.prototype.foo);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user