aboutsummaryrefslogtreecommitdiff
path: root/node_modules
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules')
-rwxr-xr-xnode_modules/tools/template/template-creator.js22
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 }},