Răsfoiți Sursa

Close the Popup when all escape actions are executed

Maxime Quandalle 9 ani în urmă
părinte
comite
d2af2ed521

+ 1 - 1
client/components/sidebar/sidebar.js

@@ -184,7 +184,7 @@ var draggableMembersLabelsWidgets = function() {
         snap: false,
         snap: false,
         snapMode: 'both',
         snapMode: 'both',
         start: function() {
         start: function() {
-          EscapeActions.executeUpTo('popup');
+          EscapeActions.executeUpTo('popup-back');
         }
         }
       });
       });
     });
     });

+ 1 - 1
client/config/router.js

@@ -28,7 +28,7 @@ FlowRouter.route('/b/:boardId/:slug/:cardId', {
   action: function(params) {
   action: function(params) {
     Session.set('currentBoard', params.boardId);
     Session.set('currentBoard', params.boardId);
     Session.set('currentCard', params.cardId);
     Session.set('currentCard', params.cardId);
-    EscapeActions.executeUpTo('popup');
+    EscapeActions.executeUpTo('popup-close');
 
 
     BlazeLayout.render('defaultLayout', { content: 'board' });
     BlazeLayout.render('defaultLayout', { content: 'board' });
   }
   }

+ 14 - 9
client/lib/escapeActions.js

@@ -9,7 +9,8 @@ EscapeActions = {
   // Executed in order
   // Executed in order
   hierarchy: [
   hierarchy: [
     'textcomplete',
     'textcomplete',
-    'popup',
+    'popup-back',
+    'popup-close',
     'inlinedForm',
     'inlinedForm',
     'detailsPane',
     'detailsPane',
     'multiselection',
     'multiselection',
@@ -30,7 +31,8 @@ EscapeActions = {
       priority: priority,
       priority: priority,
       condition: condition,
       condition: condition,
       action: action,
       action: action,
-      noClickEscapeOn: options.noClickEscapeOn
+      noClickEscapeOn: options.noClickEscapeOn,
+      enabledOnClick: !! options.enabledOnClick
     });
     });
     // XXX Rewrite this with ES6: => function
     // XXX Rewrite this with ES6: => function
     this._actions = _.sortBy(this._actions, function(a) { return a.priority; });
     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({
     return this._execute({
       maxLabel: maxLabel,
       maxLabel: maxLabel,
       multipleActions: false,
       multipleActions: false,
-      evt: evt
+      isClick: true,
+      clickTarget: target
     });
     });
   },
   },
 
 
@@ -72,8 +75,9 @@ EscapeActions = {
 
 
   _execute: function(options) {
   _execute: function(options) {
     var maxLabel = options.maxLabel;
     var maxLabel = options.maxLabel;
-    var evt = options.evt || {};
     var multipleActions = options.multipleActions;
     var multipleActions = options.multipleActions;
+    var isClick = !! options.isClick;
+    var clickTarget = options.clickTarget;
 
 
     var maxPriority, currentAction;
     var maxPriority, currentAction;
     var executedAtLeastOne = false;
     var executedAtLeastOne = false;
@@ -87,11 +91,12 @@ EscapeActions = {
       if (currentAction.priority > maxPriority)
       if (currentAction.priority > maxPriority)
         return executedAtLeastOne;
         return executedAtLeastOne;
 
 
-      if (evt.type === 'click' && this._stopClick(currentAction, evt.target))
+      if (isClick && this._stopClick(currentAction, clickTarget))
         return executedAtLeastOne;
         return executedAtLeastOne;
 
 
-      if (currentAction.condition()) {
-        currentAction.action(evt);
+      var isEnabled = currentAction.enabledOnClick || ! isClick;
+      if (isEnabled && currentAction.condition()) {
+        currentAction.action();
         executedAtLeastOne = true;
         executedAtLeastOne = true;
         if (! multipleActions)
         if (! multipleActions)
           return executedAtLeastOne;
           return executedAtLeastOne;
@@ -153,6 +158,6 @@ Mousetrap.bindGlobal('esc', function() {
 $(document).on('click', function(evt) {
 $(document).on('click', function(evt) {
   if (evt.which === 1 &&
   if (evt.which === 1 &&
     $(evt.target).closest('a,button,.is-editable').length === 0) {
     $(evt.target).closest('a,button,.is-editable').length === 0) {
-    EscapeActions.clickExecute(evt, 'multiselection');
+    EscapeActions.clickExecute(evt.target, 'multiselection');
   }
   }
 });
 });

+ 11 - 6
client/lib/popup.js

@@ -194,9 +194,14 @@ Popup = {
 
 
 // We close a potential opened popup on any left click on the document, or go
 // We close a potential opened popup on any left click on the document, or go
 // one step back by pressing escape.
 // 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'
+    }
+  );
+});
+