Sha256: 32891e1b54fe86f9e62afa29e5f4ee36f7ce454888bb189b560179af3d3f4d29

Contents?: true

Size: 1.44 KB

Versions: 277

Compression:

Stored size: 1.44 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 (this.elements.has(element)) return

    const enhansedElement = new this(element)
    enhansedElement.connect()
    this.elements.set(element, 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

277 entries across 277 versions & 1 rubygems

Version Path
playbook_ui-7.16.0.pre.alpha4 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.16.0.pre.alpha3 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.16.0.pre.alpha2 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.16.0.pre.alpha1 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.14.0.pre.alpha1 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.16.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.15.1 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.15.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.14.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.13.0.pre.alpha1 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.13.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.12.1 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.12.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.11.1 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.11.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.11.0.pre.alpha1 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.10.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.9.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.8.4 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-7.8.3 app/pb_kits/playbook/pb_enhanced_element/index.js