mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
get() now returns a Node.Array array which has node methods. This means that you can do stuff like layer.get('.shape').setX(300)
This commit is contained in:
parent
b56bd6618a
commit
8d6103d1e0
@ -1,5 +1,5 @@
|
|||||||
#Building the KineticJS library
|
#Building the KineticJS library
|
||||||
To build the library, you need to have Ruby and Rubygems installed. After that, run `gem install thor` and `gem install json_pure` to install the dependencies.
|
To build the library, you need to have Ruby and Rubygems installed. After that, run `gem install thor`, `gem install json_pure`, and `gem install uglifier` to install the dependencies.
|
||||||
|
|
||||||
To build a development version of the library, run `thor build:dev VERSION`, where VERSION is a string that can be anything you like. For example, using `thor build:dev core` will produce `kinetic-core.js`. To build a minified version of the library, run `thor build:prod VERSION`. If you want to add a release date other than the current day, use `-d="DATE"` (e.g. `-d="Mar 07 2012"`).
|
To build a development version of the library, run `thor build:dev VERSION`, where VERSION is a string that can be anything you like. For example, using `thor build:dev core` will produce `kinetic-core.js`. To build a minified version of the library, run `thor build:prod VERSION`. If you want to add a release date other than the current day, use `-d="DATE"` (e.g. `-d="Mar 07 2012"`).
|
||||||
|
|
||||||
|
36
dist/kinetic-core.js
vendored
36
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: Sep 18 2012
|
* Date: Sep 22 2012
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 - 2012 by Eric Rowell
|
* Copyright (C) 2011 - 2012 by Eric Rowell
|
||||||
*
|
*
|
||||||
@ -2262,6 +2262,37 @@ Kinetic.Node._addGetter = function(constructor, attr) {
|
|||||||
Kinetic.Node.addGettersSetters(Kinetic.Node, ['x', 'y', 'scale', 'rotation', 'opacity', 'name', 'id', 'offset', 'draggable', 'dragConstraint', 'dragBounds', 'listening']);
|
Kinetic.Node.addGettersSetters(Kinetic.Node, ['x', 'y', 'scale', 'rotation', 'opacity', 'name', 'id', 'offset', 'draggable', 'dragConstraint', 'dragBounds', 'listening']);
|
||||||
Kinetic.Node.addSetters(Kinetic.Node, ['rotationDeg']);
|
Kinetic.Node.addSetters(Kinetic.Node, ['rotationDeg']);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Node array constructor. Node.Array extends
|
||||||
|
* Array. This class is used to run node methods on
|
||||||
|
* an array of nodes returned from get()
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
Kinetic.Node.Array = function() {
|
||||||
|
var args = [].slice.call( arguments ),
|
||||||
|
length = args.length, i = 0;
|
||||||
|
|
||||||
|
this.length = length;
|
||||||
|
for (; i < length; i++ ) {
|
||||||
|
this[ i ] = args[ i ];
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
Kinetic.Node.Array.prototype = new Array();
|
||||||
|
// node methods
|
||||||
|
for(var key in Kinetic.Node.prototype) {
|
||||||
|
if(!(key in Kinetic.Node.Array.prototype)) {
|
||||||
|
(function(k) {
|
||||||
|
Kinetic.Node.Array.prototype[k] = function() {
|
||||||
|
for (var n=0; n< this.length; n++) {
|
||||||
|
Kinetic.Node.prototype[k].apply(this[n], arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set node x position
|
* set node x position
|
||||||
* @name setX
|
* @name setX
|
||||||
@ -2418,6 +2449,7 @@ Kinetic.Node.addSetters(Kinetic.Node, ['rotationDeg']);
|
|||||||
* @name getListening
|
* @name getListening
|
||||||
* @methodOf Kinetic.Node.prototype
|
* @methodOf Kinetic.Node.prototype
|
||||||
*/
|
*/
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
// Container
|
// Container
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
@ -2577,7 +2609,7 @@ Kinetic.Container.prototype = {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var retArr = [];
|
var retArr = new Kinetic.Node.Array();
|
||||||
for(var n = 0; n < arr.length; n++) {
|
for(var n = 0; n < arr.length; n++) {
|
||||||
var node = arr[n];
|
var node = arr[n];
|
||||||
if(this.isAncestorOf(node)) {
|
if(this.isAncestorOf(node)) {
|
||||||
|
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
@ -157,7 +157,7 @@ Kinetic.Container.prototype = {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var retArr = [];
|
var retArr = new Kinetic.Node.Array();
|
||||||
for(var n = 0; n < arr.length; n++) {
|
for(var n = 0; n < arr.length; n++) {
|
||||||
var node = arr[n];
|
var node = arr[n];
|
||||||
if(this.isAncestorOf(node)) {
|
if(this.isAncestorOf(node)) {
|
||||||
|
31
src/Node.js
31
src/Node.js
@ -1106,6 +1106,37 @@ Kinetic.Node._addGetter = function(constructor, attr) {
|
|||||||
Kinetic.Node.addGettersSetters(Kinetic.Node, ['x', 'y', 'scale', 'rotation', 'opacity', 'name', 'id', 'offset', 'draggable', 'dragConstraint', 'dragBounds', 'listening']);
|
Kinetic.Node.addGettersSetters(Kinetic.Node, ['x', 'y', 'scale', 'rotation', 'opacity', 'name', 'id', 'offset', 'draggable', 'dragConstraint', 'dragBounds', 'listening']);
|
||||||
Kinetic.Node.addSetters(Kinetic.Node, ['rotationDeg']);
|
Kinetic.Node.addSetters(Kinetic.Node, ['rotationDeg']);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Node array constructor. Node.Array extends
|
||||||
|
* Array. This class is used to run node methods on
|
||||||
|
* an array of nodes returned from get()
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
Kinetic.Node.Array = function() {
|
||||||
|
var args = [].slice.call( arguments ),
|
||||||
|
length = args.length, i = 0;
|
||||||
|
|
||||||
|
this.length = length;
|
||||||
|
for (; i < length; i++ ) {
|
||||||
|
this[ i ] = args[ i ];
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
Kinetic.Node.Array.prototype = new Array();
|
||||||
|
// node methods
|
||||||
|
for(var key in Kinetic.Node.prototype) {
|
||||||
|
if(!(key in Kinetic.Node.Array.prototype)) {
|
||||||
|
(function(k) {
|
||||||
|
Kinetic.Node.Array.prototype[k] = function() {
|
||||||
|
for (var n=0; n< this.length; n++) {
|
||||||
|
Kinetic.Node.prototype[k].apply(this[n], arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set node x position
|
* set node x position
|
||||||
* @name setX
|
* @name setX
|
||||||
|
@ -617,6 +617,53 @@ Test.prototype.tests = {
|
|||||||
test(stage.names.myRect === undefined, 'rect still in hash');
|
test(stage.names.myRect === undefined, 'rect still in hash');
|
||||||
test(Kinetic.Global.shapes[circleColorKey] === undefined, 'circle color key should not be in shapes hash');
|
test(Kinetic.Global.shapes[circleColorKey] === undefined, 'circle color key should not be in shapes hash');
|
||||||
test(Kinetic.Global.shapes[rectColorKey] === undefined, 'rect color key should not be in shapes hash');
|
test(Kinetic.Global.shapes[rectColorKey] === undefined, 'rect color key should not be in shapes hash');
|
||||||
|
},
|
||||||
|
'*SELECTOR - show and hide an array of nodes': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
|
var circle = new Kinetic.Circle({
|
||||||
|
x: stage.getWidth() / 2,
|
||||||
|
y: stage.getHeight() / 2,
|
||||||
|
radius: 70,
|
||||||
|
fill: 'green',
|
||||||
|
stroke: 'black',
|
||||||
|
strokeWidth: 4,
|
||||||
|
name: 'myShape'
|
||||||
|
});
|
||||||
|
|
||||||
|
var rect = new Kinetic.Rect({
|
||||||
|
x: 300,
|
||||||
|
y: 100,
|
||||||
|
width: 100,
|
||||||
|
height: 50,
|
||||||
|
fill: 'purple',
|
||||||
|
stroke: 'black',
|
||||||
|
strokeWidth: 4,
|
||||||
|
name: 'myShape'
|
||||||
|
});
|
||||||
|
|
||||||
|
layer.add(circle);
|
||||||
|
layer.add(rect);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
var shapes = layer.get('.myShape');
|
||||||
|
|
||||||
|
test(shapes.length === 2, 'shapes array should have 2 elements');
|
||||||
|
|
||||||
|
shapes.setX(200);
|
||||||
|
layer.draw();
|
||||||
|
|
||||||
|
for (var n=0; n<shapes.length; n++) {
|
||||||
|
test(shapes[n].getX() === 200, 'shape x should be 200');
|
||||||
|
}
|
||||||
|
|
||||||
|
shapes.setDraggable(true);
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
'STAGE - test ids and names hashes': function(containerId) {
|
'STAGE - test ids and names hashes': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
|
Loading…
Reference in New Issue
Block a user