diff options
author | Valerio Virgillito | 2012-02-02 00:11:51 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-02 15:33:42 -0800 |
commit | a3024011a91d3941f81481dd4d600e9684eb0fd4 (patch) | |
tree | 084b4856910f1db53973dd11617f7ffa03a6dd46 /node_modules/montage/core/serializer.js | |
parent | 97255032921178bdfbc25512ddf3e0867e353f7a (diff) | |
download | ninja-a3024011a91d3941f81481dd4d600e9684eb0fd4.tar.gz |
upgrading to Montage v0.6
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'node_modules/montage/core/serializer.js')
-rwxr-xr-x | node_modules/montage/core/serializer.js | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/node_modules/montage/core/serializer.js b/node_modules/montage/core/serializer.js index 129c3e80..449ebf7d 100755 --- a/node_modules/montage/core/serializer.js +++ b/node_modules/montage/core/serializer.js | |||
@@ -12,6 +12,14 @@ | |||
12 | var Montage = require("montage").Montage; | 12 | var Montage = require("montage").Montage; |
13 | var Uuid = require("core/uuid").Uuid; | 13 | var Uuid = require("core/uuid").Uuid; |
14 | var Deserializer = require("core/deserializer").Deserializer; | 14 | var Deserializer = require("core/deserializer").Deserializer; |
15 | var logger = require("core/logger").logger("serializer"); | ||
16 | var Element; | ||
17 | |||
18 | // Shadowing the global with a local allows us to feature-test without typeof | ||
19 | // Element does not exist on the server-side | ||
20 | if (typeof window !== "undefined") { | ||
21 | Element = window.Element; | ||
22 | } | ||
15 | 23 | ||
16 | /** | 24 | /** |
17 | @class module:montage/core/serializer.Serializer | 25 | @class module:montage/core/serializer.Serializer |
@@ -19,6 +27,7 @@ var Deserializer = require("core/deserializer").Deserializer; | |||
19 | @extends module:montage/core/core.Montage | 27 | @extends module:montage/core/core.Montage |
20 | */ | 28 | */ |
21 | var Serializer = Montage.create(Montage, /** @lends module:montage/serializer.Serializer# */ { | 29 | var Serializer = Montage.create(Montage, /** @lends module:montage/serializer.Serializer# */ { |
30 | _MONTAGE_ID_ATTRIBUTE: {value: "data-montage-id"}, | ||
22 | _serializedObjects: {value: {}}, // uuid -> string | 31 | _serializedObjects: {value: {}}, // uuid -> string |
23 | _serializedReferences: {value: {}}, // uuid -> string | 32 | _serializedReferences: {value: {}}, // uuid -> string |
24 | _externalObjects: {value: null}, // label -> object | 33 | _externalObjects: {value: null}, // label -> object |
@@ -358,7 +367,7 @@ var Serializer = Montage.create(Montage, /** @lends module:montage/serializer.Se | |||
358 | if (value instanceof RegExp) { | 367 | if (value instanceof RegExp) { |
359 | return this._serializeRegExp(value); | 368 | return this._serializeRegExp(value); |
360 | } else if (value && (typeof value === "object" || typeof value === "function")) { | 369 | } else if (value && (typeof value === "object" || typeof value === "function")) { |
361 | if (value instanceof Element) { | 370 | if (Element && value instanceof Element) { |
362 | return this._serializeElement(value); | 371 | return this._serializeElement(value); |
363 | } else if (Array.isArray(value)) { | 372 | } else if (Array.isArray(value)) { |
364 | return this._serializeArray(value, indent + 1); | 373 | return this._serializeArray(value, indent + 1); |
@@ -378,11 +387,15 @@ var Serializer = Montage.create(Montage, /** @lends module:montage/serializer.Se | |||
378 | @private | 387 | @private |
379 | */ | 388 | */ |
380 | _serializeElement: {value: function(element) { | 389 | _serializeElement: {value: function(element) { |
381 | if (element.id) { | 390 | var attribute = element.getAttribute(this._MONTAGE_ID_ATTRIBUTE), |
391 | // TODO: element.id only here for backwards compatibility | ||
392 | id = attribute || element.id; | ||
393 | |||
394 | if (id) { | ||
382 | this._externalElements.push(element); | 395 | this._externalElements.push(element); |
383 | return '{"#":"' + element.id + '"}'; | 396 | return '{"#":"' + id + '"}'; |
384 | } else { | 397 | } else { |
385 | throw "Error: Not possible to serialize a DOM element with no id assigned: " + element.outerHTML; | 398 | logger.error("Error: Not possible to serialize a DOM element with no id assigned: " + element.outerHTML); |
386 | } | 399 | } |
387 | }}, | 400 | }}, |
388 | 401 | ||