summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-08-23 11:04:35 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-08-23 11:12:04 +0200
commitd2af2ed521eb283ef7499789f23cccc4308812fa (patch)
tree83dea87a338f4b6b4ccc6e7683d925a4653440d9 /client
parent2248671b7c022f889584e0931948fe5fbe4f54a6 (diff)
downloadwekan-d2af2ed521eb283ef7499789f23cccc4308812fa.tar.gz
wekan-d2af2ed521eb283ef7499789f23cccc4308812fa.tar.bz2
wekan-d2af2ed521eb283ef7499789f23cccc4308812fa.zip
Close the Popup when all escape actions are executed
Diffstat (limited to 'client')
-rw-r--r--client/components/sidebar/sidebar.js2
-rw-r--r--client/config/router.js2
-rw-r--r--client/lib/escapeActions.js23
-rw-r--r--client/lib/popup.js17
4 files changed, 27 insertions, 17 deletions
diff --git a/client/components/sidebar/sidebar.js b/client/components/sidebar/sidebar.js
index 701e176b..17175ad4 100644
--- a/client/components/sidebar/sidebar.js
+++ b/client/components/sidebar/sidebar.js
@@ -184,7 +184,7 @@ var draggableMembersLabelsWidgets = function() {
snap: false,
snapMode: 'both',
start: function() {
- EscapeActions.executeUpTo('popup');
+ EscapeActions.executeUpTo('popup-back');
}
});
});
diff --git a/client/config/router.js b/client/config/router.js
index e251aea0..4545f220 100644
--- a/client/config/router.js
+++ b/client/config/router.js
@@ -28,7 +28,7 @@ FlowRouter.route('/b/:boardId/:slug/:cardId', {
action: function(params) {
Session.set('currentBoard', params.boardId);
Session.set('currentCard', params.cardId);
- EscapeActions.executeUpTo('popup');
+ EscapeActions.executeUpTo('popup-close');
BlazeLayout.render('defaultLayout', { content: 'board' });
}
diff --git a/client/lib/escapeActions.js b/client/lib/escapeActions.js
index c1a8cca5..3d08e2e3 100644
--- a/client/lib/escapeActions.js
+++ b/client/lib/escapeActions.js
@@ -9,7 +9,8 @@ EscapeActions = {
// Executed in order
hierarchy: [
'textcomplete',
- 'popup',
+ 'popup-back',
+ 'popup-close',
'inlinedForm',
'detailsPane',
'multiselection',
@@ -30,7 +31,8 @@ EscapeActions = {
priority: priority,
condition: condition,
action: action,
- noClickEscapeOn: options.noClickEscapeOn
+ noClickEscapeOn: options.noClickEscapeOn,
+ enabledOnClick: !! options.enabledOnClick
});
// XXX Rewrite this with ES6: => function
this._actions = _.sortBy(this._actions, function(a) { return a.priority; });
@@ -55,11 +57,12 @@ EscapeActions = {
});
},
- clickExecute: function(evt, maxLabel) {
+ clickExecute: function(target, maxLabel) {
return this._execute({
maxLabel: maxLabel,
multipleActions: false,
- evt: evt
+ isClick: true,
+ clickTarget: target
});
},
@@ -72,8 +75,9 @@ EscapeActions = {
_execute: function(options) {
var maxLabel = options.maxLabel;
- var evt = options.evt || {};
var multipleActions = options.multipleActions;
+ var isClick = !! options.isClick;
+ var clickTarget = options.clickTarget;
var maxPriority, currentAction;
var executedAtLeastOne = false;
@@ -87,11 +91,12 @@ EscapeActions = {
if (currentAction.priority > maxPriority)
return executedAtLeastOne;
- if (evt.type === 'click' && this._stopClick(currentAction, evt.target))
+ if (isClick && this._stopClick(currentAction, clickTarget))
return executedAtLeastOne;
- if (currentAction.condition()) {
- currentAction.action(evt);
+ var isEnabled = currentAction.enabledOnClick || ! isClick;
+ if (isEnabled && currentAction.condition()) {
+ currentAction.action();
executedAtLeastOne = true;
if (! multipleActions)
return executedAtLeastOne;
@@ -153,6 +158,6 @@ Mousetrap.bindGlobal('esc', function() {
$(document).on('click', function(evt) {
if (evt.which === 1 &&
$(evt.target).closest('a,button,.is-editable').length === 0) {
- EscapeActions.clickExecute(evt, 'multiselection');
+ EscapeActions.clickExecute(evt.target, 'multiselection');
}
});
diff --git a/client/lib/popup.js b/client/lib/popup.js
index 84d4b63a..6435eac6 100644
--- a/client/lib/popup.js
+++ b/client/lib/popup.js
@@ -194,9 +194,14 @@ Popup = {
// We close a potential opened popup on any left click on the document, or go
// one step back by pressing escape.
-EscapeActions.register('popup',
- function(evt) { Popup[evt.type === 'click' ? 'close' : 'back'](); },
- _.bind(Popup.isOpen, Popup), {
- noClickEscapeOn: '.js-pop-over'
- }
-);
+var escapeActions = ['back', 'close'];
+_.each(escapeActions, function(actionName) {
+ EscapeActions.register('popup-' + actionName,
+ _.bind(Popup[actionName], Popup),
+ _.bind(Popup.isOpen, Popup), {
+ noClickEscapeOn: '.js-pop-over',
+ enabledOnClick: actionName === 'close'
+ }
+ );
+});
+