diff options
Diffstat (limited to 'assets/js/core/base.js')
-rw-r--r-- | assets/js/core/base.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/assets/js/core/base.js b/assets/js/core/base.js index 4ea3ffc2..1da72357 100644 --- a/assets/js/core/base.js +++ b/assets/js/core/base.js @@ -5,6 +5,7 @@ var KB = { http: {}, listeners: { clicks: {}, + changes: {}, internals: {} } }; @@ -31,6 +32,10 @@ KB.onClick = function (selector, callback) { this.listeners.clicks[selector] = callback; }; +KB.onChange = function (selector, callback) { + this.listeners.changes[selector] = callback; +}; + KB.listen = function () { var self = this; @@ -43,7 +48,16 @@ KB.listen = function () { } } + function onChange(e) { + for (var selector in self.listeners.changes) { + if (self.listeners.changes.hasOwnProperty(selector) && e.target.matches(selector)) { + self.listeners.changes[selector](e.target); + } + } + } + document.addEventListener('click', onClick, false); + document.addEventListener('change', onChange, false); }; KB.component = function (name, object) { @@ -74,3 +88,7 @@ KB.render = function () { } } }; + +KB.interval = function (seconds, callback) { + setInterval(callback, seconds * 1000); +}; |