Fix working of Gefes IDs
This commit is contained in:
parent
8877f3e4af
commit
bbbfc0f043
@ -62,6 +62,7 @@ export abstract class GefestElement {
|
|||||||
*/
|
*/
|
||||||
constructor (content : (GefestElement | string)[] | string = []) {
|
constructor (content : (GefestElement | string)[] | string = []) {
|
||||||
this.gefestId = GefestEngine.register(this);
|
this.gefestId = GefestEngine.register(this);
|
||||||
|
this.attributes["data-gefest-id"] = this.gefestId;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +94,7 @@ export abstract class GefestElement {
|
|||||||
* @param key The attribute key.
|
* @param key The attribute key.
|
||||||
*/
|
*/
|
||||||
checkReservedAttribute(key: string): void {
|
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 "${
|
throw new Error(`The attribute "${
|
||||||
key
|
key
|
||||||
}" is reserved. Use the setPersonalStyle method for styles and setClass method for classes.`);
|
}" is reserved. Use the setPersonalStyle method for styles and setClass method for classes.`);
|
||||||
|
|||||||
@ -7,8 +7,10 @@ export class GefestEngine {
|
|||||||
static register (element: GefestElement) : string {
|
static register (element: GefestElement) : string {
|
||||||
elements.add(element);
|
elements.add(element);
|
||||||
// Generate GefestID for the element
|
// Generate GefestID for the element
|
||||||
const gefestId = `gefest-${Math.random().toString(36).substr(2, 9)}`;
|
let gefestId : string;
|
||||||
element.setAttribute('data-gefest-id', gefestId);
|
do {
|
||||||
|
gefestId = `gefest-${Math.random().toString(36).substr(2, 9)}`;
|
||||||
|
} while(!!elementsMapping.get(gefestId));
|
||||||
elementsMapping.set(gefestId, element);
|
elementsMapping.set(gefestId, element);
|
||||||
|
|
||||||
return gefestId;
|
return gefestId;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user