layer.toDataURL() now directly returns layer canvas data url if position and size are not specificed. updated unit tests and docs

This commit is contained in:
Eric Rowell
2013-01-02 22:02:00 -08:00
parent 31ad5fca88
commit 66a7e2ac39
6 changed files with 22 additions and 32 deletions

View File

@@ -4,29 +4,6 @@
* @constructor * @constructor
* @augments Kinetic.Node * @augments Kinetic.Node
* @param {Object} config * @param {Object} config
* @param {Number} [config.x]
* @param {Number} [config.y]
* @param {Boolean} [config.visible]
* @param {Boolean} [config.listening] whether or not the node is listening for events
* @param {String} [config.id] unique id
* @param {String} [config.name] non-unique name
* @param {Number} [config.alpha] determines node opacity. Can be any number between 0 and 1
* @param {Object} [config.scale]
* @param {Number} [config.scale.x]
* @param {Number} [config.scale.y]
* @param {Number} [config.rotation] rotation in radians
* @param {Number} [config.rotationDeg] rotation in degrees
* @param {Object} [config.offset] offsets default position point and rotation point
* @param {Number} [config.offset.x]
* @param {Number} [config.offset.y]
* @param {Boolean} [config.draggable]
* @param {String} [config.dragConstraint] can be vertical, horizontal, or none. The default
* is none
* @param {Object} [config.dragBounds]
* @param {Number} [config.dragBounds.top]
* @param {Number} [config.dragBounds.right]
* @param {Number} [config.dragBounds.bottom]
* @param {Number} [config.dragBounds.left]
*/ */
Kinetic.Container = function(config) { Kinetic.Container = function(config) {
this._containerInit(config); this._containerInit(config);

View File

@@ -71,6 +71,19 @@
} }
Kinetic.Container.prototype.drawScene.call(this, canvas); Kinetic.Container.prototype.drawScene.call(this, canvas);
}, },
toDataURL: function(config) {
config = config || {};
var mimeType = config.mimeType || null, quality = config.quality || null, canvas, context, x = config.x || 0, y = config.y || 0;
// if dimension or position is defined, use Node toDataURL
if(config.width || config.height || config.x || config.y) {
return Kinetic.Node.prototype.toDataURL.call(this, config);
}
// otherwise get data url of the currently drawn layer
else {
return this.getCanvas().toDataURL(mimeType, quality);
}
},
/** /**
* set before draw handler * set before draw handler
* @name beforeDraw * @name beforeDraw

File diff suppressed because one or more lines are too long

View File

@@ -102,7 +102,7 @@ Test.prototype = {
if(key.charAt(0) !== '!' && (!testOnlySpecial || key.charAt(0) === '*')) { if(key.charAt(0) !== '!' && (!testOnlySpecial || key.charAt(0) === '*')) {
var obj = this.addTestContainer(key); var obj = this.addTestContainer(key);
this.counter++; this.counter++;
console.log(this.counter + ') ' + key); console.log(this.counter + ') ' + mod + ' - ' + key);
tests[key](key); tests[key](key);
obj.testMessage.innerHTML = this.counter + ') ' + mod + ' - ' + key + ': PASSED'; obj.testMessage.innerHTML = this.counter + ') ' + mod + ' - ' + key + ': PASSED';
obj.testMessage.setAttribute('class', 'gray'); obj.testMessage.setAttribute('class', 'gray');

View File

@@ -76,12 +76,10 @@ Test.Modules.SHAPE = {
strokeWidth: 4, strokeWidth: 4,
id: 'myTriangle', id: 'myTriangle',
draggable: true, draggable: true,
shadow: { shadowColor: 'black',
color: 'black', shadowOpacity: 0.5,
opacity: 0.5, shadowBlur: 10,
blur: 10, shadowOffset: 10
offset: 10
}
}); });
stage.add(layer.add(triangle)); stage.add(layer.add(triangle));

View File

@@ -228,6 +228,8 @@ Test.Modules.Text = {
layer.add(text); layer.add(text);
stage.add(layer); stage.add(layer);
//console.log(layer.toDataURL());
warn(layer.toDataURL() === dataUrls['multiline text with shadows'], 'multi line text with shadows data url is incorrect'); warn(layer.toDataURL() === dataUrls['multiline text with shadows'], 'multi line text with shadows data url is incorrect');
}, },