|
|
@ -20,4 +20,99 @@ function fillAttrsInContainerByCb(attrs, intoContainer, cb) { |
|
|
|
cb(keys[i], attrs[keys[i]], intoContainer); |
|
|
|
} |
|
|
|
return intoContainer; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
*/ |
|
|
|
class ObjectAccessObject { |
|
|
|
/** |
|
|
|
* |
|
|
|
* @param {Object} object |
|
|
|
*/ |
|
|
|
constructor(object = null) { |
|
|
|
/** |
|
|
|
* @type {Array<string>} |
|
|
|
*/ |
|
|
|
this.keys = (object ? Object.keys(object) : []); |
|
|
|
/** |
|
|
|
* @type {Object} |
|
|
|
*/ |
|
|
|
this.objects = (object ? object : {}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param {Array<string>} keyArr |
|
|
|
* @param {Object} refObject |
|
|
|
* @returns |
|
|
|
*/ |
|
|
|
fillByArrayReference(keyArr, refObject) { |
|
|
|
this.keys = keyArr; |
|
|
|
refObject = keyArr.reduce((a, c) => Object.assign(a, { [c]: refObject[c] }), {}); |
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param {string} key |
|
|
|
* @param {*} value |
|
|
|
* @returns {ObjectAccessObject} |
|
|
|
*/ |
|
|
|
add(key, value) { |
|
|
|
this.objects[key, value]; |
|
|
|
this.keys.push(key); |
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param {string} key |
|
|
|
* @returns {*} |
|
|
|
*/ |
|
|
|
remove(key) { |
|
|
|
let tmp = this.objects[key]; |
|
|
|
delete this.objects[key]; |
|
|
|
return tmp; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param {string} autocompelSelector |
|
|
|
* @returns {boolean} for true element is now hidden and false it is not hidden. |
|
|
|
*/ |
|
|
|
function toggleElementVisibility(autocompelSelector, ensureHidden = false) { |
|
|
|
/** |
|
|
|
* @type {HTMLElement} |
|
|
|
*/ |
|
|
|
let el = document.querySelector(autocompelSelector); |
|
|
|
let name = el.getAttribute("data-autocompel"); |
|
|
|
|
|
|
|
console.log("De-/hiding", name, autocompelSelector); |
|
|
|
console.log(el); |
|
|
|
|
|
|
|
|
|
|
|
el.classList.toggle("compel-mech-hidden"); |
|
|
|
|
|
|
|
let isNowHidden = false; |
|
|
|
|
|
|
|
if (el.hasAttribute("hidden")) { |
|
|
|
el.removeAttribute("hidden"); |
|
|
|
el.style["display"] = "flex"; |
|
|
|
isNowHidden = false; |
|
|
|
} else { |
|
|
|
el.setAttribute("hidden", "hidden"); |
|
|
|
el.style.removeProperty("display"); |
|
|
|
isNowHidden = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (ensureHidden && !isNowHidden) { |
|
|
|
return toggleElementVisibility(autocompelSelector) |
|
|
|
} else { |
|
|
|
return isNowHidden; |
|
|
|
} |
|
|
|
} |
|
|
|