Commit bbf32331 authored by Zéfling's avatar Zéfling 🎨
Browse files

Add event in BakuJS DOM

- add event/rmEvent on elements and lists of elements
- remove space
- up to 0.3 a2
parent 80763d64
Pipeline #3 canceled with stage
/**
* BakuJs DOM shortcut library
*/
baku.dom = {
/**
* get a element by id ( id="xxx" )
......@@ -211,6 +214,30 @@ Element.prototype._first = function (selector) { return this.querySelector(selec
*/
Element.prototype._list = function (selector) { return this.querySelectorAll(selector) }
/**
* add event on element
* @param event name of event ('click', 'keyup', 'select' ...)
* @param func the function to attach from the element
* @param funcReturn if true returns function, else returns the element (default : false)
* @return the function or element
*/
Element.prototype._event = function (event, func, funcReturn) {
this.addEventLister(event, func, false);
return funcReturn ? this : func;
}
/**
* remove event on element
* @param event name of event ('click', 'keyup', 'select' ...)
* @param func function to be detached from the element
* @param funcReturn if true returns function, else returns the element (default : false)
* @return the function or element
*/
Element.prototype._rmEvent = function (event, func, funcReturn) {
this.removeEventListener(event, func, false);
return funcReturn ? this : func;
}
/**
* add a style on elements list.
* @get if value === undefined
......@@ -234,7 +261,7 @@ DomArray.prototype._css = function (name, value) {
* @param classes name of class or a list of classes. Ex. "class1 class2" or ["class1", "class2"]
* @return the list
*/
NodeList.prototype._addClass =
NodeList.prototype._addClass =
DomArray.prototype._addClass = function (classes) {
for (var i in this) {
if (this[i] instanceof Element) {
......@@ -249,8 +276,8 @@ DomArray.prototype._addClass = function (classes) {
* @param classes name of class or a list of classes. Ex. "class1 class2" or ["class1", "class2"]
* @return the list
*/
NodeList.prototype._rmClass =
DomArray.prototype._rmClass = function (classes) {
NodeList.prototype._rmClass =
DomArray.prototype._rmClass = function (classes) {
for (var i in this) {
if (this[i] instanceof Element) {
this[i]._rmClass(name);
......@@ -265,18 +292,48 @@ DomArray.prototype._rmClass = function (classes) {
* @param active if true add classes, id false remove classes
* @return the list
*/
NodeList.prototype._toggleClass =
DomArray.prototype._toggleClass = function (classes, active) {
NodeList.prototype._toggleClass =
DomArray.prototype._toggleClass = function (classes, active) {
this[active ? '_addClass' : '_rmClass' ](classes);
return this;
};
/**
* add event on list of elements
* @param event name of event ('click', 'keyup', 'select' ...)
* @param func the function to attach from the list of elements
* @param funcReturn if true returns function, else returns the element (default : false)
* @return the function or the list of elements
*/
NodeList.prototype._event =
DomArray.prototype._event = function (event, func, modeReturn) {
for (var i in this) {
this[i].addEventLister(event, func, false);
}
return funcReturn ? this : func;
};
/**
* remove event on list of elements
* @param event name of event ('click', 'keyup', 'select' ...)
* @param func function to be detached from the list of elements
* @param funcReturn if true returns function, else returns the element (default : false)
* @return the function or the list of elements
*/
NodeList.prototype._rmEvent =
DomArray.prototype._event = function (event, func, modeReturn) {
for (var i in this) {
this[i].removeEventListener(event, func, false);
}
return funcReturn ? this : func;
};
/**
* use a selector on a list element and return the first found
* @param selector CSS selector
* @return the list
*/
NodeList.prototype._first =
NodeList.prototype._first =
DomArray.prototype._first = function (selector) {
var e = new HTMLElement();
for (var i in this) {
......@@ -292,7 +349,7 @@ DomArray.prototype._first = function (selector) {
* @param selector CSS selector
* @return the list
*/
NodeList.prototype._list =
NodeList.prototype._list =
DomArray.prototype._list = function (selector) {
var e, i, j, list = new DomArray();
for (i in this) {
......
var baku = {};
baku.version = '0.3 a1';
baku.version = '0.3 a2';
/**
* test if it's a string
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment