diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-11-26 16:00:52 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-11-26 16:00:52 -0500 |
commit | 04ff67e26b880dde8bfb6462f312cf434457cd46 (patch) | |
tree | a3961289cbe8c60ca524490df1716229c555b379 /assets/js/core/base.js | |
parent | e64faae69aec404b2641b8ae281afe20806e8292 (diff) |
Rewrite task move position component and remove Vuejs
Diffstat (limited to 'assets/js/core/base.js')
-rw-r--r-- | assets/js/core/base.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/assets/js/core/base.js b/assets/js/core/base.js new file mode 100644 index 00000000..7346575c --- /dev/null +++ b/assets/js/core/base.js @@ -0,0 +1,70 @@ +var KB = { + components: {}, + utils: {}, + html: {}, + http: {}, + listeners: { + clicks: {}, + internals: {} + } +}; + +KB.on = function (eventType, callback) { + if (! this.listeners.internals.hasOwnProperty(eventType)) { + this.listeners.internals[eventType] = []; + } + + this.listeners.internals[eventType].push(callback); +}; + +KB.trigger = function (eventType, eventData) { + if (this.listeners.internals.hasOwnProperty(eventType)) { + for (var i = 0; i < this.listeners.internals[eventType].length; i++) { + if (! this.listeners.internals[eventType][i](eventData)) { + break; + } + } + } +}; + +KB.onClick = function (selector, callback) { + this.listeners.clicks[selector] = callback; +}; + +KB.listen = function () { + var self = this; + + function onClick(e) { + for (var selector in self.listeners.clicks) { + if (self.listeners.clicks.hasOwnProperty(selector) && e.target.matches(selector)) { + e.preventDefault(); + self.listeners.clicks[selector](e); + } + } + } + + document.addEventListener('click', onClick, false); +}; + +KB.component = function (name, object) { + this.components[name] = object; +}; + +KB.getComponent = function (name, containerElement, options) { + var object = this.components[name]; + return new object(containerElement, options); +}; + +KB.render = function () { + for (var name in this.components) { + var elementList = document.querySelectorAll('.js-' + name); + + for (var i = 0; i < elementList.length; i++) { + if (this.components.hasOwnProperty(name)) { + var component = KB.getComponent(name, elementList[i], JSON.parse(elementList[i].dataset.params)); + component.render(); + elementList[i].className = elementList[i].className + '-rendered'; + } + } + } +}; |