summaryrefslogtreecommitdiff
path: root/assets/js/core
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-12-11 15:46:54 -0500
committerFrederic Guillot <fred@kanboard.net>2016-12-11 15:46:54 -0500
commitffb392617895095b824a35150e620a68920f9260 (patch)
tree25bee1b1833e9f9bde608c38c3f46fb4e291c2b4 /assets/js/core
parenta2b44371e050aca123e0e16c3458c7af2f11b48f (diff)
Replace Chosen jQuery plugin by custom UI component
Diffstat (limited to 'assets/js/core')
-rw-r--r--assets/js/core/base.js25
-rw-r--r--assets/js/core/dom.js6
2 files changed, 29 insertions, 2 deletions
diff --git a/assets/js/core/base.js b/assets/js/core/base.js
index 1da72357..d304d8bd 100644
--- a/assets/js/core/base.js
+++ b/assets/js/core/base.js
@@ -6,6 +6,7 @@ var KB = {
listeners: {
clicks: {},
changes: {},
+ keys: {},
internals: {}
}
};
@@ -36,6 +37,10 @@ KB.onChange = function (selector, callback) {
this.listeners.changes[selector] = callback;
};
+KB.onKey = function (key, callback) {
+ this.listeners.keys[key] = callback;
+};
+
KB.listen = function () {
var self = this;
@@ -56,8 +61,28 @@ KB.listen = function () {
}
}
+ function onKeypress(e) {
+ var key = (typeof e.which === 'number') ? e.which : e.keyCode;
+ var element = e.target;
+
+ if (element.tagName === 'INPUT' ||
+ element.tagName === 'SELECT' ||
+ element.tagName === 'TEXTAREA' ||
+ element.isContentEditable) {
+ return;
+ }
+
+ for (var keyMap in self.listeners.keys) {
+ if (self.listeners.keys.hasOwnProperty(keyMap) && key === parseInt(keyMap)) {
+ e.preventDefault();
+ self.listeners.keys[key](e);
+ }
+ }
+ }
+
document.addEventListener('click', onClick, false);
document.addEventListener('change', onChange, false);
+ document.addEventListener('keypress', onKeypress, false);
};
KB.component = function (name, object) {
diff --git a/assets/js/core/dom.js b/assets/js/core/dom.js
index 20510d44..2c44de58 100644
--- a/assets/js/core/dom.js
+++ b/assets/js/core/dom.js
@@ -43,9 +43,11 @@ KB.dom = function (tag) {
return this;
};
- this.on = function (eventName, callback) {
+ this.on = function (eventName, callback, ignorePrevent) {
element.addEventListener(eventName, function (e) {
- e.preventDefault();
+ if (! ignorePrevent) {
+ e.preventDefault();
+ }
callback(e.target);
});