2
0
mirror of https://github.com/esiur/iui.git synced 2026-04-03 22:48:21 +00:00
Files
iui/src/Core/RefsCollection.js
2021-11-15 00:11:12 +03:00

46 lines
1.1 KiB
JavaScript

export default class RefsCollection
{
constructor(rootElement){
this._rootElement = rootElement;
}
_build(element, append) {
if (element == undefined)
element = this._rootElement;
if (!append)
for(var i in this)
if (i != "_rootElement" && i != "_build")
delete this[i];
for(var i = 0; i < element.children.length; i++)
{
let child = element.children[i];
if (child.hasAttribute("ref"))
{
let ref = child.getAttribute("ref");
if (this[ref] == null)
this[ref] = child;
else if (this[ref] == child){
// do nothing
}
else if (this[ref] instanceof Array){
this[ref].push(child);
} else {
var firstRef = this[ref];
this[ref] =[firstRef, child];
}
}
if (child.refs != undefined)
// opt out if the element handles referencing
break;
else
this._build(child, true);
}
}
}