Select Git revision
toggle-button.mjs
attributes.mjs 10.34 KiB
/**
* Copyright schukai GmbH and contributors 2023. All Rights Reserved.
* Node module: @schukai/monster
* This file is licensed under the AGPLv3 License.
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
*/
import { getGlobalFunction } from "../types/global.mjs";
import { TokenList } from "../types/tokenlist.mjs";
import { validateInstance, validateString, validateSymbol } from "../types/validate.mjs";
import { ATTRIBUTE_OBJECTLINK } from "./constants.mjs";
export {
findClosestObjectLink,
addToObjectLink,
removeObjectLink,
hasObjectLink,
getLinkedObjects,
toggleAttributeToken,
addAttributeToken,
removeAttributeToken,
containsAttributeToken,
replaceAttributeToken,
clearAttributeTokens,
findClosestByAttribute,
findClosestByClass,
};
/**
* Get the closest object link of a node
*
* if a node is specified without a object link, a recursive search upwards is performed until the corresponding
* object link is found, or undefined is returned.
*
* @param {HTMLElement} element
* @return {HTMLElement|undefined}
* @license AGPLv3
* @since 1.10.0
* @copyright schukai GmbH
* @memberOf Monster.DOM
* @throws {TypeError} value is not an instance of HTMLElement
*/
function findClosestObjectLink(element) {
return findClosestByAttribute(element, ATTRIBUTE_OBJECTLINK);
}
/**
* Adds a class attribute to an element.
*
* @license AGPLv3
* @since 1.9.0
* @copyright schukai GmbH
* @memberOf Monster.DOM
* @param {HTMLElement} element
* @param {Symbol} symbol
* @param {Object} object
* @return {boolean}
*/
function addToObjectLink(element, symbol, object) {
validateInstance(element, HTMLElement);
validateSymbol(symbol);
if (element?.[symbol] === undefined) {
element[symbol] = new Set();
}
addAttributeToken(element, ATTRIBUTE_OBJECTLINK, symbol.toString());
element[symbol].add(object);
return element;
}