mirror of
https://github.com/konvajs/konva.git
synced 2026-03-03 16:58:33 +08:00
all methods are now copied to Collection prototype so that you don't have to use the each() method all the time
This commit is contained in:
@@ -394,4 +394,6 @@
|
||||
* // set clip height<br>
|
||||
* container.clipHeight(100);
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Container);
|
||||
})();
|
||||
|
||||
@@ -13,4 +13,6 @@
|
||||
}
|
||||
});
|
||||
Kinetic.Util.extend(Kinetic.Group, Kinetic.Container);
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Group);
|
||||
})();
|
||||
|
||||
@@ -333,5 +333,5 @@
|
||||
* layer.hitGraphEnabled(true);
|
||||
*/
|
||||
|
||||
Kinetic.Layer.prototype.isHitGraphEnabled = Kinetic.Layer.prototype.getHitGraphEnabled;
|
||||
Kinetic.Collection.mapMethods(Kinetic.Layer);
|
||||
})();
|
||||
|
||||
20
src/Node.js
20
src/Node.js
@@ -594,7 +594,7 @@
|
||||
*/
|
||||
shouldDrawHit: function() {
|
||||
var layer = this.getLayer();
|
||||
return layer && layer.isHitGraphEnabled() && this.isListening() && this.isVisible() && !Kinetic.isDragging();
|
||||
return layer && layer.hitGraphEnabled() && this.isListening() && this.isVisible() && !Kinetic.isDragging();
|
||||
},
|
||||
/**
|
||||
* show node
|
||||
@@ -1934,21 +1934,5 @@
|
||||
getRotationDeg: 'getRotation'
|
||||
});
|
||||
|
||||
Kinetic.Collection.mapMethods([
|
||||
'on',
|
||||
'off',
|
||||
'remove',
|
||||
'destroy',
|
||||
'show',
|
||||
'hide',
|
||||
'move',
|
||||
'rotate',
|
||||
'moveToTop',
|
||||
'moveUp',
|
||||
'moveDown',
|
||||
'moveToBottom',
|
||||
'moveTo',
|
||||
'fire',
|
||||
'draw'
|
||||
]);
|
||||
Kinetic.Collection.mapMethods(Kinetic.Node);
|
||||
})();
|
||||
|
||||
@@ -1420,4 +1420,6 @@
|
||||
getDrawHitFunc: 'getHitFunc',
|
||||
setDrawHitFunc: 'setHitFunc'
|
||||
});
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Shape);
|
||||
})();
|
||||
|
||||
17
src/Util.js
17
src/Util.js
@@ -64,24 +64,23 @@
|
||||
return collection;
|
||||
};
|
||||
|
||||
Kinetic.Collection.mapMethods = function(arr) {
|
||||
var leng = arr.length,
|
||||
n;
|
||||
Kinetic.Collection.mapMethods = function(constructor) {
|
||||
var prot = constructor.prototype,
|
||||
key;
|
||||
|
||||
for(n = 0; n < leng; n++) {
|
||||
for(key in prot) {
|
||||
// induce scope
|
||||
(function(i) {
|
||||
var method = arr[i];
|
||||
Kinetic.Collection.prototype[method] = function() {
|
||||
(function(methodName) {
|
||||
Kinetic.Collection.prototype[methodName] = function() {
|
||||
var len = this.length,
|
||||
i;
|
||||
|
||||
args = [].slice.call(arguments);
|
||||
for(i = 0; i < len; i++) {
|
||||
this[i][method].apply(this[i], args);
|
||||
this[i][methodName].apply(this[i], args);
|
||||
}
|
||||
};
|
||||
})(n);
|
||||
})(key);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -154,6 +154,8 @@
|
||||
|
||||
Kinetic.Util.extend(Kinetic.Label, Kinetic.Group);
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Label);
|
||||
|
||||
/**
|
||||
* Tag constructor. A Tag can be configured
|
||||
* to have a pointer element that points up, right, down, or left
|
||||
@@ -291,4 +293,6 @@
|
||||
* @method
|
||||
* @memberof Kinetic.Tag.prototype
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Tag);
|
||||
})();
|
||||
|
||||
@@ -599,4 +599,6 @@
|
||||
* @method
|
||||
* @memberof Kinetic.Path.prototype
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Path);
|
||||
})();
|
||||
|
||||
@@ -84,4 +84,6 @@
|
||||
* @method
|
||||
* @memberof Kinetic.RegularPolygon.prototype
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.RegularPolygon);
|
||||
})();
|
||||
|
||||
@@ -105,4 +105,6 @@
|
||||
* @method
|
||||
* @memberof Kinetic.Star.prototype
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Star);
|
||||
})();
|
||||
|
||||
@@ -375,4 +375,6 @@
|
||||
* @method
|
||||
* @memberof Kinetic.TextPath.prototype
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.TextPath);
|
||||
})();
|
||||
|
||||
@@ -117,4 +117,6 @@
|
||||
* // draw arc clockwise<br>
|
||||
* arc.clockwise(true);
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Arc);
|
||||
})();
|
||||
|
||||
@@ -76,4 +76,6 @@
|
||||
* // set radius<br>
|
||||
* circle.radius(10);<br>
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Circle);
|
||||
})();
|
||||
|
||||
@@ -118,4 +118,6 @@
|
||||
* ellipse.radiusY(200);
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Ellipse);
|
||||
|
||||
})();
|
||||
@@ -196,4 +196,6 @@
|
||||
* // set crop height<br>
|
||||
* image.cropHeight(20);
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Image);
|
||||
})();
|
||||
|
||||
@@ -198,4 +198,6 @@
|
||||
* // push a new point<br>
|
||||
* line.points(line.points().concat([70, 80]));
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Line);
|
||||
})();
|
||||
@@ -73,4 +73,6 @@
|
||||
* // set corner radius<br>
|
||||
* rect.cornerRadius(10);
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Rect);
|
||||
})();
|
||||
|
||||
@@ -63,9 +63,7 @@
|
||||
Kinetic.Util.extend(Kinetic.Ring, Kinetic.Shape);
|
||||
|
||||
// add getters setters
|
||||
Kinetic.Factory.addGetterSetter(Kinetic.Ring, 'innerRadius', function() {
|
||||
return 0;
|
||||
});
|
||||
Kinetic.Factory.addGetterSetter(Kinetic.Ring, 'innerRadius', 0);
|
||||
|
||||
/**
|
||||
* get/set innerRadius
|
||||
@@ -82,9 +80,7 @@
|
||||
* ring.innerRadius(20);
|
||||
*/
|
||||
|
||||
Kinetic.Factory.addGetterSetter(Kinetic.Ring, 'outerRadius', function() {
|
||||
return 0;
|
||||
});
|
||||
Kinetic.Factory.addGetterSetter(Kinetic.Ring, 'outerRadius', 0);
|
||||
|
||||
/**
|
||||
* get/set outerRadius
|
||||
@@ -100,4 +96,6 @@
|
||||
* // set outer radius<br>
|
||||
* ring.outerRadius(20);
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Ring);
|
||||
})();
|
||||
|
||||
@@ -256,4 +256,6 @@
|
||||
getIndex: 'getFrameIndex',
|
||||
setIndex: 'setFrameIndex'
|
||||
});
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Sprite);
|
||||
})();
|
||||
|
||||
@@ -450,4 +450,6 @@
|
||||
* // set text<br>
|
||||
* text.text('Hello world!');
|
||||
*/
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Text);
|
||||
})();
|
||||
|
||||
@@ -101,4 +101,6 @@
|
||||
getAngleDeg: 'getAngle',
|
||||
setAngleDeg: 'setAngle'
|
||||
});
|
||||
|
||||
Kinetic.Collection.mapMethods(Kinetic.Wedge);
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user