Fix EscapeActions click in handling

Fixes a bug introduced in 07cc454 and one introduced in 22e854c.
This commit is contained in:
Maxime Quandalle 2015-08-25 22:18:43 +02:00
parent 22e854cc30
commit 60712e1ac4
3 changed files with 32 additions and 20 deletions

View file

@ -118,6 +118,6 @@ Template.cardMorePopup.events({
EscapeActions.register('detailsPane', EscapeActions.register('detailsPane',
function() { Utils.goBoardId(Session.get('currentBoard')); }, function() { Utils.goBoardId(Session.get('currentBoard')); },
function() { return ! Session.equals('currentCard', null); }, { function() { return ! Session.equals('currentCard', null); }, {
noClickEscapeOn: '.js-card-details' noClickEscapeOn: '.js-card-details,.board-sidebar,#header'
} }
); );

View file

@ -14,9 +14,14 @@ FlowRouter.route('/', {
FlowRouter.route('/b/:id/:slug', { FlowRouter.route('/b/:id/:slug', {
name: 'board', name: 'board',
action: function(params) { action: function(params) {
let currentBoard = params.id;
// If we close a card, we'll execute again this route action but we don't
// want to excape every current actions (filters, etc.)
if (Session.get('currentBoard') !== currentBoard) {
EscapeActions.executeAll(); EscapeActions.executeAll();
}
Session.set('currentBoard', params.id); Session.set('currentBoard', currentBoard);
Session.set('currentCard', null); Session.set('currentCard', null);
BlazeLayout.render('defaultLayout', { content: 'board' }); BlazeLayout.render('defaultLayout', { content: 'board' });

View file

@ -18,19 +18,25 @@ EscapeActions = {
], ],
register: function(label, action, condition = () => true, options = {}) { register: function(label, action, condition = () => true, options = {}) {
var priority = this.hierarchy.indexOf(label); const priority = this.hierarchy.indexOf(label);
if (priority === -1) { if (priority === -1) {
throw Error('You must define the label in the EscapeActions hierarchy'); throw Error('You must define the label in the EscapeActions hierarchy');
} }
this._actions.push({ let enabledOnClick = options.enabledOnClick;
if (_.isUndefined(enabledOnClick)) {
enabledOnClick = true;
}
let noClickEscapeOn = options.noClickEscapeOn;
this._actions[priority] = {
priority, priority,
condition, condition,
action, action,
noClickEscapeOn: options.noClickEscapeOn, noClickEscapeOn,
enabledOnClick: !! options.enabledOnClick enabledOnClick
}); };
this._actions = _.sortBy(this._actions, (a) => { return a.priority; });
}, },
executeLowest: function() { executeLowest: function() {
@ -69,27 +75,28 @@ EscapeActions = {
}, },
_execute: function(options) { _execute: function(options) {
var maxLabel = options.maxLabel; const maxLabel = options.maxLabel;
var multipleActions = options.multipleActions; const multipleActions = options.multipleActions;
var isClick = !! options.isClick; const isClick = !! options.isClick;
var clickTarget = options.clickTarget; const clickTarget = options.clickTarget;
let executedAtLeastOne = false;
let maxPriority;
var maxPriority, currentAction;
var executedAtLeastOne = false;
if (! maxLabel) if (! maxLabel)
maxPriority = Infinity; maxPriority = Infinity;
else else
maxPriority = this.hierarchy.indexOf(maxLabel); maxPriority = this.hierarchy.indexOf(maxLabel);
for (var i = 0; i < this._actions.length; i++) { for (let i = 0; i < this._actions.length; i++) {
currentAction = this._actions[i]; let currentAction = this._actions[i];
if (currentAction.priority > maxPriority) if (currentAction.priority > maxPriority)
return executedAtLeastOne; return executedAtLeastOne;
if (isClick && this._stopClick(currentAction, clickTarget)) if (isClick && this._stopClick(currentAction, clickTarget))
return executedAtLeastOne; return executedAtLeastOne;
var isEnabled = currentAction.enabledOnClick || ! isClick; let isEnabled = currentAction.enabledOnClick || ! isClick;
if (isEnabled && currentAction.condition()) { if (isEnabled && currentAction.condition()) {
currentAction.action(); currentAction.action();
executedAtLeastOne = true; executedAtLeastOne = true;
@ -150,8 +157,8 @@ Mousetrap.bindGlobal('esc', function() {
// On a left click on the document, we try to exectute one escape action (eg, // On a left click on the document, we try to exectute one escape action (eg,
// close the popup). We don't execute any action if the user has clicked on a // close the popup). We don't execute any action if the user has clicked on a
// link or a button. // link or a button.
$(document.body).on('click', function(evt) { $(document).on('click', function(evt) {
if (evt.which === 1 && if (evt.button === 0 &&
$(evt.target).closest('a,button,.is-editable').length === 0) { $(evt.target).closest('a,button,.is-editable').length === 0) {
EscapeActions.clickExecute(evt.target, 'multiselection'); EscapeActions.clickExecute(evt.target, 'multiselection');
} }