From c197f531a407c76f3bbdbe5ab992c2198f8fa01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 30 Dec 2013 23:34:19 +0100 Subject: [PATCH] Implement options.asString for Item#exportJSON() --- src/core/Base.js | 7 +++++-- src/item/Item.js | 9 ++++++--- src/project/Project.js | 9 ++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/core/Base.js b/src/core/Base.js index 73406462..04c78dff 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -40,7 +40,7 @@ Base.inject(/** @lends Base# */{ /** * Serializes this object to a JSON string. * - * @param {Object} [options={ precision: 5 }] + * @param {Object} [options={ asString: true, precision: 5 }] */ exportJSON: function(options) { return Base.exportJSON(this, options); @@ -433,7 +433,10 @@ Base.inject(/** @lends Base# */{ }, exportJSON: function(obj, options) { - return JSON.stringify(Base.serialize(obj, options)); + var json = Base.serialize(obj, options); + return options && options.asString === false + ? json + : JSON.stringify(json); }, importJSON: function(json, target) { diff --git a/src/item/Item.js b/src/item/Item.js index 4c0103ed..5027d8d5 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -1804,12 +1804,15 @@ var Item = Base.extend(Callback, /** @lends Item# */{ * data string. * * The options object offers control over some aspects of the SVG export: + * options.asString: {@code Boolean} – wether the JSON is returned as + * a {@code Object} or a {@code String}. * options.precision: {@code Number} – the amount of fractional * digits in numbers used in JSON data. * * @name Item#exportJSON * @function - * @param {Object} [options={ precision: 5 }] the serialization options + * @param {Object} [options={ asString: true, precision: 5 }] the + * serialization options * @return {String} the exported JSON data */ @@ -1836,8 +1839,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{ * Exports the item with its content and child items as an SVG DOM. * * The options object offers control over some aspects of the SVG export: - * options.asString: {@code Boolean} – wether a SVG node or a String - * is to be returned. + * options.asString: {@code Boolean} – wether a SVG node or a + * {@code String} is to be returned. * options.precision: {@code Number} – the amount of fractional * digits in numbers used in SVG data. * options.matchShapes: {@code Boolean} – wether imported path diff --git a/src/project/Project.js b/src/project/Project.js index f7b09d3f..df1ebd88 100644 --- a/src/project/Project.js +++ b/src/project/Project.js @@ -335,12 +335,15 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{ * a JSON data string. * * The options object offers control over some aspects of the SVG export: + * options.asString: {@code Boolean} – wether the JSON is returned as + * a {@code Object} or a {@code String}. * options.precision: {@code Number} – the amount of fractional * digits in numbers used in JSON data. * * @name Project#exportJSON * @function - * @param {Object} [options={ precision: 5 }] the serialization options + * @param {Object} [options={ asString: true, precision: 5 }] the + * serialization options * @return {String} the exported JSON data */ @@ -364,8 +367,8 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{ * all contained in one top level SVG group node. * * The options object offers control over some aspects of the SVG export: - * options.asString: {@code Boolean} – wether a SVG node or a String - * is to be returned. + * options.asString: {@code Boolean} – wether a SVG node or a + * {@code String} is to be returned. * options.precision: {@code Number} – the amount of fractional * digits in numbers used in SVG data. * options.matchShapes: {@code Boolean} – wether imported path