1.0.2 • Published 7 years ago

ndom v1.0.2

Weekly downloads
8
License
MIT
Repository
github
Last release
7 years ago

ndom

A DOM wrapper with IntelliSense.

Installation

npm install --save ndom

The UMD build is in the dist directory.

Short story

Why not any of the others? Because I like this syntax more, actual property getters for every get operation. The collection of elements extends a real Array object so you get all the methods of the Array prototype. Small code. Only necessary functions, maybe even missing some.

const ndom = require('ndom');

ndom('body').html = '<div id="div1">DIV IN BODY</div>';
ndom('#div1').html = '<a>l1</a><a>l2</a><a>l3</a>';

console.log(ndom('#div1').width, ndom('#div1').size.width === ndom('#div1').width);
console.log(ndom('#div1 a').html);

ndom('#div1 a').forEach((a, i) => {
    console.log(a);
    ndom(a).html += ' - <b>' + i + '</b>';
});

ndom('#div1 a').on('click', e => console.log('CLICK', e));
ndom('#div1 a').once('click', (e, node) => console.log('CLICK ONCE', node, e));
ndom('#div1 a').on('click', function(e) {
    console.log('Binds to: ', this);
});

// etc...

Long story

Classes

ndom

ndom(selector, parent)
ParamType
selector*
parent*

ndom.match(el, selector) ⇒ boolean
ParamType
el*
selector*

ndom.onLoad(callback) ⇒ ndom
ParamType
callbackfunction

ndom.onReady(callback) ⇒ ndom
ParamType
callbackfunction

Collection ⇐ Array

Kind: global class
Extends: Array

collection.node ⇒ HTMLElement

collection.parent ⇒ Collection

collection.size ⇒ Object

collection.width ⇒ number

collection.height ⇒ number

collection.outerSize ⇒ Object

collection.offset ⇒ Object

collection.offsetParent ⇒ Collection

collection.offsetViewport ⇒ ClientRect

collection.position ⇒ Object

collection.left ⇒ number

collection.top ⇒ number

collection.html ⇒ string

collection.outerHtml ⇒ string

collection.text ⇒ string

collection.class ⇒ string

collection.classes ⇒ Array

collection.children ⇒ Collection

collection.length ⇒ number

collection.html
ParamType
htmlstring

collection.text
ParamType
textstring

collection.query(selector) ⇒ Collection
ParamType
selectorstring | Collection | HTMLElement | *

collection.queryParents(selector) ⇒ Collection
ParamType
selectorstring | Collection | HTMLElement | *

collection.contains(child) ⇒ boolean
ParamType
childstring | Collection | HTMLElement | *

collection.clone() ⇒ Collection

collection.getAttr(name) ⇒ string | null
ParamType
namestring

collection.hasClass(name) ⇒ boolean
ParamType
namestring

collection.setAttr(name, value) ⇒ Collection
ParamType
namestring
value*

collection.addClass(name) ⇒ Collection
ParamType
namestring

collection.removeClass(name) ⇒ Collection
ParamType
namestring

collection.setHtml(html) ⇒ Collection
ParamType
htmlstring

collection.setText(text) ⇒ Collection
ParamType
textstring

collection.serialize(asObject) ⇒ string | object
ParamType
asObjectboolean

collection.append(children) ⇒ Collection
ParamType
childrenCollection | HTMLElement | Array | *

collection.prepend(children) ⇒ Collection
ParamType
childrenCollection | HTMLElement | *

collection.remove() ⇒ Collection

collection.replace(html) ⇒ Collection
ParamType
htmlstring | Collection | HTMLElement | *

collection.insertAfter(html) ⇒ Collection
ParamType
htmlstring | Collection | HTMLElement | *

collection.insertBefore(html) ⇒ Collection
ParamType
htmlstring | Collection | HTMLElement | *

collection.empty() ⇒ Collection

collection.on(type, selector, handler) ⇒ Collection
ParamType
typestring
selectorstring | function
handlerfunction

collection.once(type, selector, handler) ⇒ Collection
ParamType
typestring
selectorstring | function
handlerfunction

collection.off(type, selector, handler) ⇒ Collection
ParamType
typestring
selectorstring | function
handlerfunction

collection.emit(eventName) ⇒ Collection
ParamType
eventNamestring

collection.dispatch(event) ⇒ Collection
ParamType
eventEvent | *

Collection.wrap(collection, ndom, window) ⇒ Collection
ParamType
collectionArray | Collection | NodeList
ndomndom
windowWindow

TODO

Test test test.

1.0.2

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago