Sha256: 03d69dfaee97a87db13203c0fdc1a7ebf8547e25d6c9981663b3f1b265747930
Contents?: true
Size: 1.5 KB
Versions: 133
Compression:
Stored size: 1.5 KB
Contents
import ElementObserver from './element_observer.js' export default class PbEnhancedElement { static get elements() { return this._elements = (this._elements || new Map) } static get observer() { return this._observer = (this._observer || new ElementObserver(this)) } static get selector() { // eslint-disable-next-line no-console console.warn('Define a static property for selector or redefine the matches function in a subclass.', this) return null } static matches(node) { if (!this.selector) return [] const matches = [] if (node.nodeType === Node.ELEMENT_NODE && node.matches(this.selector)) matches.push(node) matches.push(...node.querySelectorAll(this.selector)) return (matches) } static addMatch(element) { if (element._pbEnhanced || this.elements.has(element)) return const enhansedElement = new this(element) enhansedElement.connect() this.elements.set(element, enhansedElement) element._pbEnhanced = enhansedElement } static removeMatch(element) { if (!this.elements.has(element)) return const enhansedElement = this.elements.get(element) enhansedElement.disconnect() this.elements.delete(element) } static start() { this.observer.start() } static stop() { this.mutationObserver.stop() } constructor(element) { this.element = element } connect() { // eslint-disable-next-line no-console console.warn('Redefine the connect function in a subclass.', this) } disconnect() { } }
Version data entries
133 entries across 133 versions & 1 rubygems