From 75a01802f73e791b082229f065eeb3df6a48a962 Mon Sep 17 00:00:00 2001 From: António Afonso Date: Wed, 30 May 2012 10:17:49 -0700 Subject: Avoid duplicate labels in template creator This is the fix for Motorola-Mobility/montage#649--- node_modules/tools/template/template-creator.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'node_modules/tools') diff --git a/node_modules/tools/template/template-creator.js b/node_modules/tools/template/template-creator.js index 374353f0..dc6b1190 100755 --- a/node_modules/tools/template/template-creator.js +++ b/node_modules/tools/template/template-creator.js @@ -51,8 +51,8 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le component = isRootNode ? null : sourceNode.controller; if (component) { - label = self._generateLabelForComponent(component); targetNode.setAttribute("id", label); + label = self._generateLabelForComponent(component, Object.keys(components)); component._element = targetNode; components[label] = component; } else { @@ -94,8 +94,8 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le _componentNamesIndex: { value: null }, - - _generateLabelForComponent: {value: function(component) { + + _generateLabelForComponent: {value: function(component, labels) { var componentInfo = Montage.getInfoForObject(component), componentLabel = componentInfo.label, componentName, @@ -105,8 +105,11 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le return componentLabel; } else { componentName = componentInfo.objectName.toLowerCase(); - index = this._componentNamesIndex[componentName] || 1; - this._componentNamesIndex[componentName] = index + 1; + do { + index = this._componentNamesIndex[componentName] || 1; + this._componentNamesIndex[componentName] = index + 1; + } while (labels.indexOf(componentName+index) >= 0); + return componentName + index; } }}, -- cgit v1.2.3