summaryrefslogtreecommitdiffstats
path: root/client/lib/keyboard.js
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-06-07 10:30:27 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-06-07 10:34:19 +0200
commit92dd05d06ddeb2a9434df6038c432e6b167c1c99 (patch)
treeecb93138c1dd0ab0c1fcf2682a6eae600a4bbca9 /client/lib/keyboard.js
parent12919cbfc6c3fd0793624776b3afb70e3a0cdd1a (diff)
downloadwekan-92dd05d06ddeb2a9434df6038c432e6b167c1c99.tar.gz
wekan-92dd05d06ddeb2a9434df6038c432e6b167c1c99.tar.bz2
wekan-92dd05d06ddeb2a9434df6038c432e6b167c1c99.zip
Click on the page to escape the last action
This is a generalization of what we had for closing a popup by clicking outside of it. It now works for inlinedForms and detailsPane as well.
Diffstat (limited to 'client/lib/keyboard.js')
-rw-r--r--client/lib/keyboard.js69
1 files changed, 0 insertions, 69 deletions
diff --git a/client/lib/keyboard.js b/client/lib/keyboard.js
index 8b105c28..bd78390a 100644
--- a/client/lib/keyboard.js
+++ b/client/lib/keyboard.js
@@ -33,72 +33,3 @@ Mousetrap.bind(['down', 'up'], function(evt, key) {
Utils.goCardId(nextCardId);
}
});
-
-// Pressing `Escape` should close the last opened “element” and only the last
-// 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: [],
-
- // Executed in order
- hierarchy: [
- 'textcomplete',
- 'popup',
- 'inlinedForm',
- 'multiselection-disable',
- 'sidebarView',
- 'detailsPane',
- 'multiselection-reset'
- ],
-
- register: function(label, action, condition) {
- if (_.isUndefined(condition))
- condition = function() { return true; };
-
- // 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,
- action: action
- });
- // XXX Rewrite this with ES6: => function
- this._actions = _.sortBy(this._actions, function(a) { return a.priority; });
- },
-
- executeLowest: function() {
- var topActiveAction = _.find(this._actions, function(a) {
- return !! a.condition();
- });
- return topActiveAction && topActiveAction.action();
- },
-
- 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)
- return;
- if (!! currentAction.condition())
- currentAction.action();
- }
- },
-
- executeAll: function() {
- return this.executeLowerThan();
- }
-};
-
-Mousetrap.bind('esc', function() {
- EscapeActions.executeLowest();
-});