Skip to content
Snippets Groups Projects
Select Git revision
  • 4094ec955cda01de91564dc4265d98e96b704de5
  • master default protected
  • 1.31
  • 4.38.2
  • 4.38.1
  • 4.38.0
  • 4.37.2
  • 4.37.1
  • 4.37.0
  • 4.36.0
  • 4.35.0
  • 4.34.1
  • 4.34.0
  • 4.33.1
  • 4.33.0
  • 4.32.2
  • 4.32.1
  • 4.32.0
  • 4.31.0
  • 4.30.1
  • 4.30.0
  • 4.29.1
  • 4.29.0
23 results

toggle-button.mjs

Blame
  • 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;
    }