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-9.19.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.19.0.pre.alphafonts app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.18.0.flow.bin.alpha app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.18.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.17.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.16.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.15.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.15.0.pre.decouple.website1 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.14.1.alpha.radio.alignment app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.14.1.alpha.highcharts9 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.14.1 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.13.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.12.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.12.0.pre.text.addon app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.11.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.10.0 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.10.0.pre.date.time.stacked.1 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.10.0.pre.alpha2 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.10.0.pre.alpha1 app/pb_kits/playbook/pb_enhanced_element/index.js
playbook_ui-9.9.0.alpha.inline1 app/pb_kits/playbook/pb_enhanced_element/index.js