aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/core/serializer.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage/core/serializer.js')
-rwxr-xr-xnode_modules/montage/core/serializer.js21
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 @@
12var Montage = require("montage").Montage; 12var Montage = require("montage").Montage;
13var Uuid = require("core/uuid").Uuid; 13var Uuid = require("core/uuid").Uuid;
14var Deserializer = require("core/deserializer").Deserializer; 14var Deserializer = require("core/deserializer").Deserializer;
15var logger = require("core/logger").logger("serializer");
16var 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
20if (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 */
21var Serializer = Montage.create(Montage, /** @lends module:montage/serializer.Serializer# */ { 29var 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