Add fabric.Canvas#cloneWithoutData. Fix broken unit tests. Bump version to 0.8.

This commit is contained in:
kangax 2012-04-20 13:15:30 +02:00
parent fd4a7d2886
commit 0a0ab70f68
6 changed files with 55 additions and 25 deletions

View file

@ -1,6 +1,6 @@
/*! Fabric.js Copyright 2008-2012, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */
var fabric = fabric || { version: "0.7.25" };
var fabric = fabric || { version: "0.8" };
if (typeof exports != 'undefined') {
exports.fabric = fabric;

37
dist/all.js vendored
View file

@ -1,6 +1,6 @@
/*! Fabric.js Copyright 2008-2012, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */
var fabric = fabric || { version: "0.7.25" };
var fabric = fabric || { version: "0.8" };
if (typeof exports != 'undefined') {
exports.fabric = fabric;
@ -6898,24 +6898,39 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
/**
* Clones canvas instance
* @method clone
* @param {Object} [callback] Expects `onBeforeClone` and `onAfterClone` functions
* @return {fabric.Canvas} Clone of this instance
* @param {Object} [callback] Receives cloned instance as a first argument
*/
clone: function (callback) {
var data = JSON.stringify(this);
this.cloneWithoutData(function(clone) {
clone.loadFromJSON(data, function() {
if (callback) {
callback(clone);
}
});
});
},
/**
* Clones canvas instance without cloning existing data.
* This essentially copies canvas dimensions, clipping properties, etc.
* but leaves data empty (so that you can populate it with your own)
* @method cloneWithoutData
* @param {Object} [callback] Receives cloned instance as a first argument
*/
cloneWithoutData: function(callback) {
var el = fabric.document.createElement('canvas');
el.width = this.getWidth();
el.height = this.getHeight();
// cache
var clone = this.__clone || (this.__clone = new fabric.Canvas(el));
clone.clipTo = this.clipTo;
return clone.loadFromJSON(JSON.stringify(this.toJSON()), function () {
if (callback) {
callback(clone);
}
});
if (callback) {
callback(clone);
}
}
});
(function(global) {

4
dist/all.min.js vendored

File diff suppressed because one or more lines are too long

BIN
dist/all.min.js.gz vendored

Binary file not shown.

View file

@ -1,7 +1,7 @@
{
"name": "fabric",
"description": "Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.",
"version": "0.7.25",
"version": "0.8",
"author": "Juriy Zaytsev <kangax@gmail.com>",
"keywords": ["canvas", "graphic", "graphics", "SVG", "node-canvas", "parser", "HTML5", "object model"],
"repository": "git://github.com/kangax/fabric.js",

View file

@ -244,23 +244,38 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
/**
* Clones canvas instance
* @method clone
* @param {Object} [callback] Expects `onBeforeClone` and `onAfterClone` functions
* @return {fabric.Canvas} Clone of this instance
* @param {Object} [callback] Receives cloned instance as a first argument
*/
clone: function (callback) {
var data = JSON.stringify(this);
this.cloneWithoutData(function(clone) {
clone.loadFromJSON(data, function() {
if (callback) {
callback(clone);
}
});
});
},
/**
* Clones canvas instance without cloning existing data.
* This essentially copies canvas dimensions, clipping properties, etc.
* but leaves data empty (so that you can populate it with your own)
* @method cloneWithoutData
* @param {Object} [callback] Receives cloned instance as a first argument
*/
cloneWithoutData: function(callback) {
var el = fabric.document.createElement('canvas');
el.width = this.getWidth();
el.height = this.getHeight();
// cache
var clone = this.__clone || (this.__clone = new fabric.Canvas(el));
clone.clipTo = this.clipTo;
return clone.loadFromJSON(JSON.stringify(this.toJSON()), function () {
if (callback) {
callback(clone);
}
});
if (callback) {
callback(clone);
}
}
});