diff options
author | Armen Kesablyan | 2012-02-07 16:55:34 -0800 |
---|---|---|
committer | Armen Kesablyan | 2012-02-07 16:55:34 -0800 |
commit | 10f0ad4c15f090b2d0d50d11e4c7aaf291e9eb0e (patch) | |
tree | 12b31910a3c7c7fa2ee0b26d8aaa611710e139a5 /node_modules/montage/core/serializer.js | |
parent | 7f8730c3add146f1ba107e6fc22d1f5a8348ed8b (diff) | |
parent | 668510892537eaaeb2e11520831d87b44b2489b7 (diff) | |
download | ninja-10f0ad4c15f090b2d0d50d11e4c7aaf291e9eb0e.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into text-tool
Conflicts:
_scss/compass_app_log.txt
css/ninja.css
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 | ||