app-decorators-todomvc
Version:
Todomvc with app-decorators
170 lines (117 loc) • 4.94 kB
JavaScript
System.register(['app-decorators/src/libs/element-to-function', 'app-decorators', './utils'], function (_export, _context) {
"use strict";
var _elementToFunc, Eventhandler, forEach, _getNodeList, hasClass, addClass, removeClass, toggleClass, append, remove, show, hide, text, attribute, find, findAll, parent, click, addListener, $;
return {
setters: [function (_appDecoratorsSrcLibsElementToFunction) {
_elementToFunc = _appDecoratorsSrcLibsElementToFunction.default;
}, function (_appDecorators) {
Eventhandler = _appDecorators.Eventhandler;
}, function (_utils) {
forEach = _utils.forEach;
}],
execute: function () {
_getNodeList = function _getNodeList(value) {
return value.forEach ? value : [value];
};
_export('hasClass', hasClass = function hasClass(cls) {
this.classList.contains(cls);
return this;
});
_export('addClass', addClass = function addClass(cls) {
var nodeList = _getNodeList(this);
forEach.call(nodeList, function (el) {
return el.classList.add(cls);
});
return this;
});
_export('removeClass', removeClass = function removeClass(cls) {
var nodeList = _getNodeList(this);
forEach.call(nodeList, function (el) {
return el.classList.remove(cls);
});
return this;
});
_export('toggleClass', toggleClass = function toggleClass(cls) {
var nodeList = _getNodeList(this);
forEach.call(nodeList, function (el) {
return el.classList.toggle(cls);
});
return this;
});
_export('append', append = function append(node) {
this.appendChild(node);
return this;
});
_export('remove', remove = function remove() {
this.parentElement.removeChild(this);
});
_export('show', show = function show() {
var nodeList = _getNodeList(this);
forEach.call(nodeList, function (el) {
return el.style.display = 'block';
});
return this;
});
_export('hide', hide = function hide() {
var nodeList = _getNodeList(this);
forEach.call(nodeList, function (el) {
return el.style.display = 'none';
});
return this;
});
_export('text', text = function text(_text) {
var nodeList = _getNodeList(this);
forEach.call(nodeList, function (el) {
return el.textContent = _text;
});
return this;
});
_export('attribute', attribute = function attribute(key, value) {
if (key && value) {
this.setAttribute(key, value);
return this;
} else if (key && !value) {
return this.getAttribute(key);
}
});
_export('find', find = function find(selector) {
return this.querySelector(selector);
});
_export('findAll', findAll = function findAll(selector) {
return this.querySelectorAll(selector);
});
_export('parent', parent = function parent() {
return this.parentElement;
});
_export('click', click = function click() {
this.click();
return this;
});
_export('addListener', addListener = function addListener(eventName, callback) {
var listener = Eventhandler.create({
element: this
});
listener.on(eventName, callback);
return this;
});
$ = function $(query) {
return document.querySelectorAll(query);
};
_export('hasClass', hasClass);
_export('addClass', addClass);
_export('removeClass', removeClass);
_export('toggleClass', toggleClass);
_export('append', append);
_export('remove', remove);
_export('show', show);
_export('hide', hide);
_export('text', text);
_export('attribute', attribute);
_export('find', find);
_export('findAll', findAll);
_export('parent', parent);
_export('click', click);
_export('addListener', addListener);
}
};
});