mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
better extend function
This commit is contained in:
parent
46bb48e470
commit
87236a88e2
@ -3,8 +3,10 @@
|
|||||||
* Bug Fixes
|
* Bug Fixes
|
||||||
* working "this-example" as name for nodes
|
* working "this-example" as name for nodes
|
||||||
* Kinetic.Text() with no config throws exception
|
* Kinetic.Text() with no config throws exception
|
||||||
|
* Kinetic.Line() with no config throws exception
|
||||||
* Enhancements
|
* Enhancements
|
||||||
* `black` is default fill for shapes
|
* `black` is default fill for text
|
||||||
|
* true class extending. Now `rect instanceOf Kinetic.Shape` will return true
|
||||||
|
|
||||||
## 5.1.9 2014-01-09
|
## 5.1.9 2014-01-09
|
||||||
|
|
||||||
|
110
kinetic.js
110
kinetic.js
@ -3,7 +3,7 @@
|
|||||||
* KineticJS JavaScript Framework v5.1.10
|
* KineticJS JavaScript Framework v5.1.10
|
||||||
* http://lavrton.github.io/KineticJS/
|
* http://lavrton.github.io/KineticJS/
|
||||||
* Licensed under the MIT or GPL Version 2 licenses.
|
* Licensed under the MIT or GPL Version 2 licenses.
|
||||||
* Date: 2015-01-15
|
* Date: 2015-01-20
|
||||||
*
|
*
|
||||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell
|
||||||
* Modified work Copyright 2015 Anton Lavrenov
|
* Modified work Copyright 2015 Anton Lavrenov
|
||||||
@ -1264,12 +1264,19 @@ var Kinetic = {};
|
|||||||
console.warn(KINETIC_WARNING + str);
|
console.warn(KINETIC_WARNING + str);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
extend: function(c1, c2) {
|
extend: function(child, parent) {
|
||||||
for(var key in c2.prototype) {
|
function ctor() {
|
||||||
if(!( key in c1.prototype)) {
|
this.constructor = child;
|
||||||
c1.prototype[key] = c2.prototype[key];
|
|
||||||
}
|
}
|
||||||
}
|
ctor.prototype = parent.prototype;
|
||||||
|
var old_proto = child.prototype;
|
||||||
|
child.prototype = new ctor();
|
||||||
|
for (var key in old_proto) {
|
||||||
|
if (old_proto.hasOwnProperty(key)) {
|
||||||
|
child.prototype[key] = old_proto[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
child.__super__ = parent.prototype;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* adds methods to a constructor prototype
|
* adds methods to a constructor prototype
|
||||||
@ -2606,17 +2613,6 @@ var Kinetic = {};
|
|||||||
name: name,
|
name: name,
|
||||||
handler: handler
|
handler: handler
|
||||||
});
|
});
|
||||||
|
|
||||||
// NOTE: this flag is set to true when any event handler is added, even non
|
|
||||||
// mouse or touch gesture events. This improves performance for most
|
|
||||||
// cases where users aren't using events, but is still very light weight.
|
|
||||||
// To ensure perfect accuracy, devs can explicitly set listening to false.
|
|
||||||
/*
|
|
||||||
if (name !== KINETIC) {
|
|
||||||
this._listeningEnabled = true;
|
|
||||||
this._clearSelfAndAncestorCache(LISTENING_ENABLED);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -2797,7 +2793,7 @@ var Kinetic = {};
|
|||||||
|
|
||||||
if(config) {
|
if(config) {
|
||||||
for(key in config) {
|
for(key in config) {
|
||||||
if (key === CHILDREN) {
|
if (key === CHILDREN || config[key] instanceof Kinetic.Node) {
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -4103,6 +4099,7 @@ var Kinetic = {};
|
|||||||
/**
|
/**
|
||||||
* get/set offset x
|
* get/set offset x
|
||||||
* @name offsetX
|
* @name offsetX
|
||||||
|
* @method
|
||||||
* @memberof Kinetic.Node.prototype
|
* @memberof Kinetic.Node.prototype
|
||||||
* @param {Number} x
|
* @param {Number} x
|
||||||
* @returns {Number}
|
* @returns {Number}
|
||||||
@ -4116,26 +4113,6 @@ var Kinetic = {};
|
|||||||
|
|
||||||
Kinetic.Factory.addGetterSetter(Kinetic.Node, 'offsetY', 0);
|
Kinetic.Factory.addGetterSetter(Kinetic.Node, 'offsetY', 0);
|
||||||
|
|
||||||
/**
|
|
||||||
* get/set drag distance
|
|
||||||
* @name dragDistance
|
|
||||||
* @memberof Kinetic.Node.prototype
|
|
||||||
* @param {Number} distance
|
|
||||||
* @returns {Number}
|
|
||||||
* @example
|
|
||||||
* // get drag distance
|
|
||||||
* var dragDistance = node.dragDistance();
|
|
||||||
*
|
|
||||||
* // set distance
|
|
||||||
* // node starts dragging only if pointer moved more then 3 pixels
|
|
||||||
* node.dragDistance(3);
|
|
||||||
* // or set globally
|
|
||||||
* Kinetic.dragDistance = 3;
|
|
||||||
*/
|
|
||||||
|
|
||||||
Kinetic.Factory.addSetter(Kinetic.Node, 'dragDistance');
|
|
||||||
Kinetic.Factory.addOverloadedGetterSetter(Kinetic.Node, 'dragDistance');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get/set offset y
|
* get/set offset y
|
||||||
* @name offsetY
|
* @name offsetY
|
||||||
@ -4151,6 +4128,28 @@ var Kinetic = {};
|
|||||||
* node.offsetY(3);
|
* node.offsetY(3);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Kinetic.Factory.addSetter(Kinetic.Node, 'dragDistance');
|
||||||
|
Kinetic.Factory.addOverloadedGetterSetter(Kinetic.Node, 'dragDistance');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get/set drag distance
|
||||||
|
* @name dragDistance
|
||||||
|
* @method
|
||||||
|
* @memberof Kinetic.Node.prototype
|
||||||
|
* @param {Number} distance
|
||||||
|
* @returns {Number}
|
||||||
|
* @example
|
||||||
|
* // get drag distance
|
||||||
|
* var dragDistance = node.dragDistance();
|
||||||
|
*
|
||||||
|
* // set distance
|
||||||
|
* // node starts dragging only if pointer moved more then 3 pixels
|
||||||
|
* node.dragDistance(3);
|
||||||
|
* // or set globally
|
||||||
|
* Kinetic.dragDistance = 3;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
Kinetic.Factory.addSetter(Kinetic.Node, 'width', 0);
|
Kinetic.Factory.addSetter(Kinetic.Node, 'width', 0);
|
||||||
Kinetic.Factory.addOverloadedGetterSetter(Kinetic.Node, 'width');
|
Kinetic.Factory.addOverloadedGetterSetter(Kinetic.Node, 'width');
|
||||||
/**
|
/**
|
||||||
@ -8483,6 +8482,9 @@ var Kinetic = {};
|
|||||||
*
|
*
|
||||||
* // set fill color with rgba and make it 50% opaque
|
* // set fill color with rgba and make it 50% opaque
|
||||||
* shape.fill('rgba(0,255,0,0.5');
|
* shape.fill('rgba(0,255,0,0.5');
|
||||||
|
*
|
||||||
|
* // shape without fill
|
||||||
|
* shape.fill(null);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Kinetic.Factory.addGetterSetter(Kinetic.Shape, 'fillRed', 0, Kinetic.Validators.RGBComponent);
|
Kinetic.Factory.addGetterSetter(Kinetic.Shape, 'fillRed', 0, Kinetic.Validators.RGBComponent);
|
||||||
@ -9958,7 +9960,12 @@ var Kinetic = {};
|
|||||||
* @param {Number} [bounds.height]
|
* @param {Number} [bounds.height]
|
||||||
* @example
|
* @example
|
||||||
* layer.clear();
|
* layer.clear();
|
||||||
* layer.clear(0, 0, 100, 100);
|
* layer.clear({
|
||||||
|
* x : 0,
|
||||||
|
* y : 0,
|
||||||
|
* width : 100,
|
||||||
|
* height : 100
|
||||||
|
* });
|
||||||
*/
|
*/
|
||||||
clear: function(bounds) {
|
clear: function(bounds) {
|
||||||
this.getContext().clear(bounds);
|
this.getContext().clear(bounds);
|
||||||
@ -10294,7 +10301,12 @@ var Kinetic = {};
|
|||||||
* @param {Number} [bounds.height]
|
* @param {Number} [bounds.height]
|
||||||
* @example
|
* @example
|
||||||
* layer.clear();
|
* layer.clear();
|
||||||
* layer.clear(0, 0, 100, 100);
|
* layer.clear({
|
||||||
|
* x : 0,
|
||||||
|
* y : 0,
|
||||||
|
* width : 100,
|
||||||
|
* height : 100
|
||||||
|
* });
|
||||||
*/
|
*/
|
||||||
clear: function(bounds) {
|
clear: function(bounds) {
|
||||||
this.getContext().clear(bounds);
|
this.getContext().clear(bounds);
|
||||||
@ -10426,7 +10438,12 @@ var Kinetic = {};
|
|||||||
* @param {Number} [bounds.height]
|
* @param {Number} [bounds.height]
|
||||||
* @example
|
* @example
|
||||||
* layer.clear();
|
* layer.clear();
|
||||||
* layer.clear(0, 0, 100, 100);
|
* layer.clear({
|
||||||
|
* x : 0,
|
||||||
|
* y : 0,
|
||||||
|
* width : 100,
|
||||||
|
* height : 100
|
||||||
|
* });
|
||||||
*/
|
*/
|
||||||
clear: function(bounds) {
|
clear: function(bounds) {
|
||||||
this.getContext().clear(bounds);
|
this.getContext().clear(bounds);
|
||||||
@ -11915,7 +11932,8 @@ var Kinetic = {};
|
|||||||
|
|
||||||
Kinetic.Text.prototype = {
|
Kinetic.Text.prototype = {
|
||||||
___init: function(config) {
|
___init: function(config) {
|
||||||
var that = this;
|
config = config || {};
|
||||||
|
config.fill = config.fill || 'black';
|
||||||
|
|
||||||
if (config.width === undefined) {
|
if (config.width === undefined) {
|
||||||
config.width = AUTO;
|
config.width = AUTO;
|
||||||
@ -11933,7 +11951,7 @@ var Kinetic = {};
|
|||||||
|
|
||||||
// update text data for certain attr changes
|
// update text data for certain attr changes
|
||||||
for(var n = 0; n < attrChangeListLen; n++) {
|
for(var n = 0; n < attrChangeListLen; n++) {
|
||||||
this.on(ATTR_CHANGE_LIST[n] + CHANGE_KINETIC, that._setTextData);
|
this.on(ATTR_CHANGE_LIST[n] + CHANGE_KINETIC, this._setTextData);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._setTextData();
|
this._setTextData();
|
||||||
@ -12447,6 +12465,10 @@ var Kinetic = {};
|
|||||||
closed = this.getClosed(),
|
closed = this.getClosed(),
|
||||||
tp, len, n;
|
tp, len, n;
|
||||||
|
|
||||||
|
if (!length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
context.moveTo(points[0], points[1]);
|
context.moveTo(points[0], points[1]);
|
||||||
|
|
||||||
@ -12582,7 +12604,7 @@ var Kinetic = {};
|
|||||||
* line.tension(3);
|
* line.tension(3);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Kinetic.Factory.addGetterSetter(Kinetic.Line, 'points');
|
Kinetic.Factory.addGetterSetter(Kinetic.Line, 'points', []);
|
||||||
/**
|
/**
|
||||||
* get/set points array
|
* get/set points array
|
||||||
* @name points
|
* @name points
|
||||||
|
10
kinetic.min.js
vendored
10
kinetic.min.js
vendored
File diff suppressed because one or more lines are too long
@ -528,7 +528,7 @@
|
|||||||
|
|
||||||
if(config) {
|
if(config) {
|
||||||
for(key in config) {
|
for(key in config) {
|
||||||
if (key === CHILDREN) {
|
if (key === CHILDREN || config[key] instanceof Kinetic.Node) {
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
17
src/Util.js
17
src/Util.js
@ -633,12 +633,19 @@
|
|||||||
console.warn(KINETIC_WARNING + str);
|
console.warn(KINETIC_WARNING + str);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
extend: function(c1, c2) {
|
extend: function(child, parent) {
|
||||||
for(var key in c2.prototype) {
|
function ctor() {
|
||||||
if(!( key in c1.prototype)) {
|
this.constructor = child;
|
||||||
c1.prototype[key] = c2.prototype[key];
|
|
||||||
}
|
}
|
||||||
}
|
ctor.prototype = parent.prototype;
|
||||||
|
var old_proto = child.prototype;
|
||||||
|
child.prototype = new ctor();
|
||||||
|
for (var key in old_proto) {
|
||||||
|
if (old_proto.hasOwnProperty(key)) {
|
||||||
|
child.prototype[key] = old_proto[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
child.__super__ = parent.prototype;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* adds methods to a constructor prototype
|
* adds methods to a constructor prototype
|
||||||
|
@ -689,4 +689,12 @@ suite('Shape', function() {
|
|||||||
//TODO: can't get this to pass
|
//TODO: can't get this to pass
|
||||||
assert.equal(click, true, 'click event should have been fired when mousing down and then up on rect');
|
assert.equal(click, true, 'click event should have been fired when mousing down and then up on rect');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('class inherince', function() {
|
||||||
|
var rect = new Kinetic.Rect();
|
||||||
|
assert.equal(rect instanceof Kinetic.Rect, true);
|
||||||
|
assert.equal(rect instanceof Kinetic.Shape, true);
|
||||||
|
assert.equal(rect instanceof Kinetic.Node, true);
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
@ -1,6 +1,4 @@
|
|||||||
suite('Util', function(){
|
suite('Util', function(){
|
||||||
var util;
|
|
||||||
|
|
||||||
test('get()', function(){
|
test('get()', function(){
|
||||||
assert.equal(Kinetic.Util.get(1, 2), 1);
|
assert.equal(Kinetic.Util.get(1, 2), 1);
|
||||||
assert.equal(Kinetic.Util.get(undefined, 2), 2);
|
assert.equal(Kinetic.Util.get(undefined, 2), 2);
|
||||||
|
Loading…
Reference in New Issue
Block a user