File: src/lib/UI/NativeDOM/Element.js

Recommend this page to a friend!
  Classes of Dom Hastings  >  JS Webdav Client  >  src/lib/UI/NativeDOM/Element.js  >  Download  
File: src/lib/UI/NativeDOM/Element.js
Role: Class source
Content type: text/plain
Description: Class source
Class: JS Webdav Client
Access files of a Webdav server
Author: By
Last change:
Date: 1 month ago
Size: 823 bytes
 

Contents

Class file image Download
import EventObject from '../../EventObject.js';

export default class Element extends EventObject {
  #element;

  constructor(template = null) {
    super();

    if (template !== null) {
      this.#element = this.createNodeFromString(template);
    }
  }

  get element() {
    return this.#element;
  }

  createNodesFromString(html) {
    const container = document.createElement('div'),
      fragment = document.createDocumentFragment()
    ;

    container.innerHTML = html;

    for (const childNode of container.childNodes) {
      fragment.appendChild(childNode);
    }

    return fragment;
  }

  createNodeFromString(html) {
    return this.createNodesFromString(html).firstChild;
  }

  emptyNode() {
    while (this.element.firstChild) {
      this.element.removeChild(this.element.firstChild);
    }
  }
}