diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-11-25 18:26:10 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-11-25 18:26:10 -0500 |
commit | f73d369dd0a451ca6d176a318cdbf940b0a9d63d (patch) | |
tree | cc14fcc87fa8d2035ae0669dcccbb9677e3b3d15 /assets/js/src | |
parent | ff844a9a04d6e6b6d94aeeb9de88b303c5064f36 (diff) |
Rewrite accordion widget in vanilla Javascript
Diffstat (limited to 'assets/js/src')
-rw-r--r-- | assets/js/src/Accordion.js | 18 | ||||
-rw-r--r-- | assets/js/src/Bootstrap.js | 2 | ||||
-rw-r--r-- | assets/js/src/Namespace.js | 123 |
3 files changed, 0 insertions, 143 deletions
diff --git a/assets/js/src/Accordion.js b/assets/js/src/Accordion.js deleted file mode 100644 index f05dc5ff..00000000 --- a/assets/js/src/Accordion.js +++ /dev/null @@ -1,18 +0,0 @@ -Kanboard.Accordion = function(app) { - this.app = app; -}; - -Kanboard.Accordion.prototype.listen = function() { - $(document).on("click", ".accordion-toggle", function(e) { - var section = $(this).parents(".accordion-section"); - e.preventDefault(); - - if (section.hasClass("accordion-collapsed")) { - section.find(".accordion-content").show(); - section.removeClass("accordion-collapsed"); - } else { - section.find(".accordion-content").hide(); - section.addClass("accordion-collapsed"); - } - }); -}; diff --git a/assets/js/src/Bootstrap.js b/assets/js/src/Bootstrap.js index 7f722b04..94b1f2ca 100644 --- a/assets/js/src/Bootstrap.js +++ b/assets/js/src/Bootstrap.js @@ -3,6 +3,4 @@ var _KB = null; jQuery(document).ready(function() { _KB = new Kanboard.App(); _KB.execute(); - - KB.render(); }); diff --git a/assets/js/src/Namespace.js b/assets/js/src/Namespace.js index de825be4..6b4b0543 100644 --- a/assets/js/src/Namespace.js +++ b/assets/js/src/Namespace.js @@ -1,126 +1,3 @@ 'use strict'; var Kanboard = {}; - -var KB = { - components: {}, - utils: {} -}; - -KB.component = function (name, object) { - this.components[name] = object; -}; - -KB.render = function () { - for (var name in this.components) { - var elementList = document.querySelectorAll('.js-' + name); - - for (var i = 0; i < elementList.length; i++) { - var object = this.components[name]; - var component = new object(elementList[i], JSON.parse(elementList[i].dataset.params)); - component.render(); - elementList[i].className = elementList[i].className + '-rendered'; - } - } -}; - -KB.el = function (tag) { - - function DOMBuilder(tag) { - var element = typeof tag === 'string' ? document.createElement(tag) : tag; - - this.attr = function (attribute, value) { - if (value !== null) { - element.setAttribute(attribute, value); - } - return this; - }; - - this.hide = function () { - element.style.display = 'none'; - return this; - }; - - this.show = function () { - element.style.display = 'block'; - return this; - }; - - this.toggle = function () { - if (element.style.display === 'none') { - this.show(); - } else{ - this.hide(); - } - - return this; - }; - - this.click = function (callback) { - element.onclick = function (e) { - e.preventDefault(); - callback(); - }; - return this; - }; - - this.add = function (node) { - element.appendChild(node); - return this; - }; - - this.html = function (html) { - element.innerHTML = html; - return this; - }; - - this.text = function (text) { - element.appendChild(document.createTextNode(text)); - return this; - }; - - this.for = function (tag, list) { - for (var i = 0; i < list.length; i++) { - var dict = list[i]; - - if (typeof dict !== 'object') { - element.appendChild(KB.el(tag).text(dict).build()); - } else { - var node = KB.el(tag); - - for (var attribute in dict) { - if (attribute in this && typeof this[attribute] === 'function') { - node[attribute](dict[attribute]); - } else { - node.attr(attribute, dict[attribute]); - } - } - - element.appendChild(node.build()); - } - } - - return this; - }; - - this.build = function () { - return element; - }; - } - - return new DOMBuilder(tag); -}; - -KB.utils.formatDuration = function(d) { - if (d >= 86400) { - return Math.round(d/86400) + "d"; - } - else if (d >= 3600) { - return Math.round(d/3600) + "h"; - } - else if (d >= 60) { - return Math.round(d/60) + "m"; - } - - return d + "s"; -}; |