mirror of
https://github.com/wekan/wekan.git
synced 2025-12-18 00:10:13 +01:00
Enforce a consistent ES6 coding style
Replace the old (and broken) jshint + jscsrc by eslint and configure it to support some of the ES6 features. The command `eslint` currently has one error which is a bug that was discovered by its static analysis and should be fixed (usage of a dead object).
This commit is contained in:
parent
039cfe7edf
commit
b3851817ec
60 changed files with 1604 additions and 1692 deletions
|
|
@ -31,7 +31,7 @@ EscapeActions = {
|
|||
enabledOnClick = true;
|
||||
}
|
||||
|
||||
let noClickEscapeOn = options.noClickEscapeOn;
|
||||
const noClickEscapeOn = options.noClickEscapeOn;
|
||||
|
||||
this._actions = _.sortBy([...this._actions, {
|
||||
priority,
|
||||
|
|
@ -44,20 +44,20 @@ EscapeActions = {
|
|||
|
||||
executeLowest() {
|
||||
return this._execute({
|
||||
multipleAction: false
|
||||
multipleAction: false,
|
||||
});
|
||||
},
|
||||
|
||||
executeAll() {
|
||||
return this._execute({
|
||||
multipleActions: true
|
||||
multipleActions: true,
|
||||
});
|
||||
},
|
||||
|
||||
executeUpTo(maxLabel) {
|
||||
return this._execute({
|
||||
maxLabel: maxLabel,
|
||||
multipleActions: true
|
||||
maxLabel,
|
||||
multipleActions: true,
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -66,10 +66,10 @@ EscapeActions = {
|
|||
this._nextclickPrevented = false;
|
||||
} else {
|
||||
return this._execute({
|
||||
maxLabel: maxLabel,
|
||||
maxLabel,
|
||||
multipleActions: false,
|
||||
isClick: true,
|
||||
clickTarget: target
|
||||
clickTarget: target,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
@ -79,7 +79,7 @@ EscapeActions = {
|
|||
},
|
||||
|
||||
_stopClick(action, clickTarget) {
|
||||
if (! _.isString(action.noClickEscapeOn))
|
||||
if (!_.isString(action.noClickEscapeOn))
|
||||
return false;
|
||||
else
|
||||
return $(clickTarget).closest(action.noClickEscapeOn).length > 0;
|
||||
|
|
@ -88,86 +88,46 @@ EscapeActions = {
|
|||
_execute(options) {
|
||||
const maxLabel = options.maxLabel;
|
||||
const multipleActions = options.multipleActions;
|
||||
const isClick = !! options.isClick;
|
||||
const isClick = Boolean(options.isClick);
|
||||
const clickTarget = options.clickTarget;
|
||||
|
||||
let executedAtLeastOne = false;
|
||||
let maxPriority;
|
||||
|
||||
if (! maxLabel)
|
||||
if (!maxLabel)
|
||||
maxPriority = Infinity;
|
||||
else
|
||||
maxPriority = this.hierarchy.indexOf(maxLabel);
|
||||
|
||||
for (let currentAction of this._actions) {
|
||||
for (const currentAction of this._actions) {
|
||||
if (currentAction.priority > maxPriority)
|
||||
return executedAtLeastOne;
|
||||
|
||||
if (isClick && this._stopClick(currentAction, clickTarget))
|
||||
return executedAtLeastOne;
|
||||
|
||||
let isEnabled = currentAction.enabledOnClick || ! isClick;
|
||||
const isEnabled = currentAction.enabledOnClick || !isClick;
|
||||
if (isEnabled && currentAction.condition()) {
|
||||
currentAction.action();
|
||||
executedAtLeastOne = true;
|
||||
if (! multipleActions)
|
||||
if (!multipleActions)
|
||||
return executedAtLeastOne;
|
||||
}
|
||||
}
|
||||
return executedAtLeastOne;
|
||||
}
|
||||
};
|
||||
|
||||
// MouseTrap plugin bindGlobal plugin. Adds a bindGlobal method to Mousetrap
|
||||
// that allows you to bind specific keyboard shortcuts that will still work
|
||||
// inside a text input field.
|
||||
//
|
||||
// usage:
|
||||
// Mousetrap.bindGlobal('ctrl+s', _saveChanges);
|
||||
//
|
||||
// source:
|
||||
// https://github.com/ccampbell/mousetrap/tree/master/plugins/global-bind
|
||||
var _globalCallbacks = {};
|
||||
var _originalStopCallback = Mousetrap.stopCallback;
|
||||
|
||||
Mousetrap.stopCallback = function(e, element, combo, sequence) {
|
||||
var self = this;
|
||||
|
||||
if (self.paused) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_globalCallbacks[combo] || _globalCallbacks[sequence]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return _originalStopCallback.call(self, e, element, combo);
|
||||
};
|
||||
|
||||
Mousetrap.bindGlobal = function(keys, callback, action) {
|
||||
var self = this;
|
||||
self.bind(keys, callback, action);
|
||||
|
||||
if (keys instanceof Array) {
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
_globalCallbacks[keys[i]] = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
_globalCallbacks[keys] = true;
|
||||
},
|
||||
};
|
||||
|
||||
// Pressing escape to execute one escape action. We use `bindGloabal` vecause
|
||||
// the shortcut sould work on textarea and inputs as well.
|
||||
Mousetrap.bindGlobal('esc', function() {
|
||||
Mousetrap.bindGlobal('esc', () => {
|
||||
EscapeActions.executeLowest();
|
||||
});
|
||||
|
||||
// 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
|
||||
// link or a button.
|
||||
$(document).on('click', function(evt) {
|
||||
$(document).on('click', (evt) => {
|
||||
if (evt.button === 0 &&
|
||||
$(evt.target).closest('a,button,.is-editable').length === 0) {
|
||||
EscapeActions.clickExecute(evt.target, 'multiselection');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue