|
| 1 | +/** |
| 2 | + * |
| 3 | + * @class |
| 4 | + * |
| 5 | + * @name Neptune_DOMElement |
| 6 | + * |
| 7 | + * @description Create a new HTML DOM element |
| 8 | + * |
| 9 | + * @param {string} parentId - ID of the parent element |
| 10 | + * @param {string} elementType - Is it a **div** or a **span** |
| 11 | + * @param {string} elementId - ID of the new DOM element |
| 12 | + * |
| 13 | + * @example |
| 14 | + * ``` |
| 15 | + * const myDiv = new Neptune_DOMElement("body", "div", "testid"); |
| 16 | + * ``` |
| 17 | + * |
| 18 | + */ |
| 19 | +export default class Neptune_DOMElement { |
| 20 | + constructor(parentId, elementType, elementId) { |
| 21 | + this.parentId = parentId; |
| 22 | + this.elementType = elementType; |
| 23 | + this.elementId = elementId; |
| 24 | + |
| 25 | + this.create(); |
| 26 | + } |
| 27 | + |
| 28 | + create() { |
| 29 | + // Create new element |
| 30 | + const newDOMElement = document.createElement(this.elementType); |
| 31 | + newDOMElement.id = this.elementId; |
| 32 | + |
| 33 | + // Append new element to parent element |
| 34 | + const parentElement = document.getElementById(this.parentId); |
| 35 | + parentElement.appendChild(newDOMElement); |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +/** |
| 40 | + * |
| 41 | + * @class |
| 42 | + * |
| 43 | + * @name Neptune_Button |
| 44 | + * @description Create default button |
| 45 | + * |
| 46 | + * @param {string} parentId - ID of parent element |
| 47 | + * @param {string} elementType - Type of element is always ** * button * ** |
| 48 | + * @param {string} buttonName - Button title |
| 49 | + * @param {string} elementId - ID of the new button element |
| 50 | + * |
| 51 | + * @example |
| 52 | + * const defaultButton = new Neptune_Button("body", "Default Button", "buttonID"); |
| 53 | + * |
| 54 | + */ |
| 55 | +export class Neptune_Button extends Neptune_DOMElement { |
| 56 | + constructor(parentId, elementType, buttonName, elementId) { |
| 57 | + super(parentId, elementType = 'button', 'Test 123', elementId); |
| 58 | + this.buttonName = buttonName; |
| 59 | + this.create(); |
| 60 | + } |
| 61 | + |
| 62 | + create() { |
| 63 | + var newButton = new Neptune_DOMElement(this.parentId, "button", this.elementId); |
| 64 | + this.innerHTML = this.buttonName; |
| 65 | + } |
| 66 | +} |
0 commit comments