Sha256: 1e43d58d168c24232ef04bf7c1f11678ca1a9703b750e2f8d28deed65eb1833f

Contents?: true

Size: 1.07 KB

Versions: 169

Compression:

Stored size: 1.07 KB

Contents

class Component {
  /**
   * Generic constructor for all components
   * @constructor
   * @param {Element} el
   * @param {Object} options
   */
  constructor(classDef, el, options) {
    // Display error if el is valid HTML Element
    if (!(el instanceof Element)) {
      console.error(Error(el + ' is not an HTML Element'));
    }

    // If exists, destroy and reinitialize in child
    let ins = classDef.getInstance(el);
    if (!!ins) {
      ins.destroy();
    }

    this.el = el;
    this.$el = cash(el);
  }

  /**
   * Initializes components
   * @param {class} classDef
   * @param {Element | NodeList | jQuery} els
   * @param {Object} options
   */
  static init(classDef, els, options) {
    let instances = null;
    if (els instanceof Element) {
      instances = new classDef(els, options);
    } else if (!!els && (els.jquery || els.cash || els instanceof NodeList)) {
      let instancesArr = [];
      for (let i = 0; i < els.length; i++) {
        instancesArr.push(new classDef(els[i], options));
      }
      instances = instancesArr;
    }

    return instances;
  }
}

Version data entries

169 entries across 169 versions & 3 rubygems

Version Path
j1-template-2022.3.2 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.3.1 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.3.0 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.2.3 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.2.2 assets/themes/j1/modules/materialize/js/component.js
administrate-materialize-theme-1.0.0 app/assets/javascripts/administrate-materialize-theme/component.js
j1-template-2022.2.1 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.2.0 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.1.3 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.1.2 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.1.1 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.1.0 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.0.18 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.0.17 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.0.16 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.0.15 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.0.14 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.0.13 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.0.12 assets/themes/j1/modules/materialize/js/component.js
j1-template-2022.0.11 assets/themes/j1/modules/materialize/js/component.js