Browse files

Add `fabric.Canvas#cloneWithoutData`. Fix broken unit tests. Bump ver…

…sion to 0.8.
  • Loading branch information...
1 parent fd4a7d2 commit 0a0ab70f68556ceb026f4eafe5a20999598ff8f4 @kangax committed Apr 20, 2012
Showing with 55 additions and 25 deletions.
  1. +1 −1 HEADER.js
  2. +26 −11 dist/all.js
  3. +2 −2 dist/all.min.js
  4. BIN dist/all.min.js.gz
  5. +1 −1 package.json
  6. +25 −10 src/canvas.serialization.js
View
2 HEADER.js
@@ -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;
View
37 dist/all.js
@@ -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) {
View
4 dist/all.min.js
2 additions, 2 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
BIN dist/all.min.js.gz
Binary file not shown.
View
2 package.json
@@ -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
35 src/canvas.serialization.js
@@ -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);
+ }
}
});

0 comments on commit 0a0ab70

Please sign in to comment.