diff --git a/frontend/src/modules/Gefest/element.ts b/frontend/src/modules/Gefest/element.ts index df36fdb..dff6820 100644 --- a/frontend/src/modules/Gefest/element.ts +++ b/frontend/src/modules/Gefest/element.ts @@ -62,6 +62,7 @@ export abstract class GefestElement { */ constructor (content : (GefestElement | string)[] | string = []) { this.gefestId = GefestEngine.register(this); + this.attributes["data-gefest-id"] = this.gefestId; this.content = content; } @@ -93,7 +94,7 @@ export abstract class GefestElement { * @param key The attribute key. */ checkReservedAttribute(key: string): void { - if (({ "style": true, "class": true })[key]) + if (({ "style": true, "class": true, "data-gefest-id": true })[key]) throw new Error(`The attribute "${ key }" is reserved. Use the setPersonalStyle method for styles and setClass method for classes.`); diff --git a/frontend/src/modules/Gefest/engine.ts b/frontend/src/modules/Gefest/engine.ts index 688c77f..b561e95 100644 --- a/frontend/src/modules/Gefest/engine.ts +++ b/frontend/src/modules/Gefest/engine.ts @@ -7,8 +7,10 @@ export class GefestEngine { static register (element: GefestElement) : string { elements.add(element); // Generate GefestID for the element - const gefestId = `gefest-${Math.random().toString(36).substr(2, 9)}`; - element.setAttribute('data-gefest-id', gefestId); + let gefestId : string; + do { + gefestId = `gefest-${Math.random().toString(36).substr(2, 9)}`; + } while(!!elementsMapping.get(gefestId)); elementsMapping.set(gefestId, element); return gefestId;