summaryrefslogtreecommitdiffstats
path: root/client/lib
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-05-27 02:48:15 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-05-27 02:48:15 +0200
commit42f6dc686f313ba294e3cbcfb0ebde50678580fe (patch)
treedc14152cc8c98895f800c84cd2737fe6a5b22b7f /client/lib
parent40c2411f2a1ce0bbd177f377828f9d6700112b06 (diff)
downloadwekan-42f6dc686f313ba294e3cbcfb0ebde50678580fe.tar.gz
wekan-42f6dc686f313ba294e3cbcfb0ebde50678580fe.tar.bz2
wekan-42f6dc686f313ba294e3cbcfb0ebde50678580fe.zip
Prioritize escape actions with a label hierarchy instead of an integer
Diffstat (limited to 'client/lib')
-rw-r--r--client/lib/keyboard.js33
-rw-r--r--client/lib/popup.js5
2 files changed, 29 insertions, 9 deletions
diff --git a/client/lib/keyboard.js b/client/lib/keyboard.js
index 723d498b..0fbdbfd5 100644
--- a/client/lib/keyboard.js
+++ b/client/lib/keyboard.js
@@ -35,15 +35,28 @@ Mousetrap.bind(['down', 'up'], function(evt, key) {
});
// Pressing `Escape` should close the last opened “element” and only the last
-// one. Components can register themself using a priority number (smaller is
-// closed first), a condition, and an action.This is used by Popup or
-// inlinedForm for instance. When we press escape we execute the action which
-// condition is valid with the highest priority.
+// one. Components can register themselves using a label a condition, and an
+// action. This is used by Popup or inlinedForm for instance. When we press
+// escape we execute the action which have a condition is valid and his the the
+// highest in the label hierarchy.
EscapeActions = {
_actions: [],
- register: function(priority, condition, action) {
+ // Executed in order
+ hierarchy: [
+ 'textcomplete',
+ 'popup',
+ 'inlinedForm',
+ 'sidebarView',
+ 'detailedPane'
+ ],
+
+ register: function(label, condition, action) {
// XXX Rewrite this with ES6: .push({ priority, condition, action })
+ var priority = this.hierarchy.indexOf(label);
+ if (priority === -1) {
+ throw Error('You must define the label in the EscapeActions hierarchy');
+ }
this._actions.push({
priority: priority,
condition: condition,
@@ -60,9 +73,13 @@ EscapeActions = {
return topActiveAction && topActiveAction.action();
},
- executeLowerThan: function(maxPriority) {
- maxPriority = maxPriority || Infinity;
- var currentAction;
+ executeLowerThan: function(label) {
+ var maxPriority, currentAction;
+ if (! label)
+ maxPriority = Infinity;
+ else
+ maxPriority = this.hierarchy.indexOf(label);
+
for (var i = 0; i < this._actions.length; i++) {
currentAction = this._actions[i];
if (currentAction.priority > maxPriority)
diff --git a/client/lib/popup.js b/client/lib/popup.js
index 70f2660f..6298ba81 100644
--- a/client/lib/popup.js
+++ b/client/lib/popup.js
@@ -204,4 +204,7 @@ $(document).on('click', function(evt) {
// Press escape to close the popup.
var bindPopup = function(f) { return _.bind(f, Popup); };
-EscapeActions.register(20, bindPopup(Popup.isOpen), bindPopup(Popup.close));
+EscapeActions.register('popup',
+ bindPopup(Popup.isOpen),
+ bindPopup(Popup.close)
+);