1.0.21 • Published 3 years ago

bound-element v1.0.21

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

Bound Element

CI

The purpose of this library is to have the ability two work with elements without having to query them in the dom. It is setup in a manner to easily work with server side frameworks that generate most of the markup.

The first think you'll want to do is bind the body element (or any parent element that contains elements with bind-as):

const bodyEl = document.querySelector('body');
const bodyBoundElement = new BoundElement('body', bodyEl);

By binding the body element, we have now setup a top level bound element that will then quickly run through its child elements and bind any elements that are necessary.

Next you'll want to create a class that extends BoundElement:

export default class Dropdown extends BoundElement {
    constructor(name, elementType, parent) {
        super(name, elementType, parent);

        this.template((options) => {
            return `<option selector-template-id="0">New</option>
            ${_.map(options, function (option) {
                return `<option value="${option.id}">${option.name}</option>`;
            }).join("")}`
        });

        this.onChange(_.bind(this.onDropdownChange, this), false);
    }

    onDropdownChange(event) {
        const test = 1;
    }
}

By doing this you can add your own custom functionality to an element that includes listening to events and setting the template.

<body>
<select bind-as="dropdown"></select>
</body>

Now if you want to reference child elements you can easily do that since the child elements are added as properties:

bodyBoundElement.dropdown
1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago