diff options
author | Eric Guzman | 2012-05-30 17:29:40 -0700 |
---|---|---|
committer | Eric Guzman | 2012-05-30 17:29:40 -0700 |
commit | 535a2fae0f4820f9b5a9f33cec250f11c0ee5bb9 (patch) | |
tree | 9a382beae1b19d520282532ccb3c55611ebf94d6 /node_modules/tools/template/template-creator.js | |
parent | 26683016ea28aac61e7c563df769dfafe40dce12 (diff) | |
parent | d49c909cff7f0c5e5d0b127ad84a2fefc6677dc6 (diff) | |
download | ninja-535a2fae0f4820f9b5a9f33cec250f11c0ee5bb9.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into CSSPanelUpdates
Diffstat (limited to 'node_modules/tools/template/template-creator.js')
-rwxr-xr-x | node_modules/tools/template/template-creator.js | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/node_modules/tools/template/template-creator.js b/node_modules/tools/template/template-creator.js index 374353f0..c5d3cffd 100755 --- a/node_modules/tools/template/template-creator.js +++ b/node_modules/tools/template/template-creator.js | |||
@@ -35,11 +35,13 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le | |||
35 | var serializer = this.serializer, | 35 | var serializer = this.serializer, |
36 | objects = {}, | 36 | objects = {}, |
37 | components = {}, | 37 | components = {}, |
38 | componentsChildComponents = {}, | ||
38 | doc, | 39 | doc, |
39 | script, | 40 | script, |
40 | self = this; | 41 | self = this; |
41 | 42 | ||
42 | this._componentNamesIndex = {}; | 43 | this._componentNamesIndex = {}; |
44 | this._objectNamesIndex = {}; | ||
43 | doc = this._document = document.implementation.createHTMLDocument(""); | 45 | doc = this._document = document.implementation.createHTMLDocument(""); |
44 | 46 | ||
45 | function copyNode(sourceNode, targetNode, isRootNode) { | 47 | function copyNode(sourceNode, targetNode, isRootNode) { |
@@ -51,10 +53,11 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le | |||
51 | component = isRootNode ? null : sourceNode.controller; | 53 | component = isRootNode ? null : sourceNode.controller; |
52 | 54 | ||
53 | if (component) { | 55 | if (component) { |
54 | label = self._generateLabelForComponent(component); | 56 | label = self._generateLabelForComponent(component, Object.keys(components)); |
55 | targetNode.setAttribute("id", label); | ||
56 | component._element = targetNode; | 57 | component._element = targetNode; |
57 | components[label] = component; | 58 | components[label] = component; |
59 | componentsChildComponents[label] = component.childComponents; | ||
60 | delete component.childComponents; | ||
58 | } else { | 61 | } else { |
59 | for (var i = 0; (childNode = childNodes[i]); i++) { | 62 | for (var i = 0; (childNode = childNodes[i]); i++) { |
60 | targetChildNode = targetNode.appendChild(childNode.cloneNode(false)); | 63 | targetChildNode = targetNode.appendChild(childNode.cloneNode(false)); |
@@ -85,6 +88,10 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le | |||
85 | 88 | ||
86 | copyNode(body, this._document.body, true); | 89 | copyNode(body, this._document.body, true); |
87 | this._ownerSerialization = serializer.serialize(components); | 90 | this._ownerSerialization = serializer.serialize(components); |
91 | for (var label in components) { | ||
92 | components[label].childComponents = componentsChildComponents[label]; | ||
93 | } | ||
94 | components = componentsChildComponents = null; | ||
88 | this._externalObjects = serializer.getExternalObjects(); | 95 | this._externalObjects = serializer.getExternalObjects(); |
89 | 96 | ||
90 | return this; | 97 | return this; |
@@ -94,8 +101,8 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le | |||
94 | _componentNamesIndex: { | 101 | _componentNamesIndex: { |
95 | value: null | 102 | value: null |
96 | }, | 103 | }, |
97 | 104 | ||
98 | _generateLabelForComponent: {value: function(component) { | 105 | _generateLabelForComponent: {value: function(component, labels) { |
99 | var componentInfo = Montage.getInfoForObject(component), | 106 | var componentInfo = Montage.getInfoForObject(component), |
100 | componentLabel = componentInfo.label, | 107 | componentLabel = componentInfo.label, |
101 | componentName, | 108 | componentName, |
@@ -105,8 +112,11 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le | |||
105 | return componentLabel; | 112 | return componentLabel; |
106 | } else { | 113 | } else { |
107 | componentName = componentInfo.objectName.toLowerCase(); | 114 | componentName = componentInfo.objectName.toLowerCase(); |
108 | index = this._componentNamesIndex[componentName] || 1; | 115 | do { |
109 | this._componentNamesIndex[componentName] = index + 1; | 116 | index = this._componentNamesIndex[componentName] || 1; |
117 | this._componentNamesIndex[componentName] = index + 1; | ||
118 | } while (labels.indexOf(componentName+index) >= 0); | ||
119 | |||
110 | return componentName + index; | 120 | return componentName + index; |
111 | } | 121 | } |
112 | }}, | 122 | }}, |