Commit 29cd930e authored by lauriii's avatar lauriii

Issue #2914946 by drpal, dawehner, droplet: JS codestyle: no-var

parent 6c9c95e1
{
"extends": "./.eslintrc.json",
"rules": {
"no-var": "off",
"no-useless-escape": "off",
"no-use-before-define": "off",
"no-throw-literal": "off",
......
......@@ -136,7 +136,7 @@
}
// Get the desired term and construct the autocomplete URL for it.
var term = autocomplete.extractLastTerm(request.term);
const term = autocomplete.extractLastTerm(request.term);
// Check if the term is already cached.
if (autocomplete.cache[elementId].hasOwnProperty(term)) {
......
......@@ -510,9 +510,9 @@
// Up arrow.
case 38:
// Safari up arrow.
case 63232:
var $previousRow = $(self.rowObject.element).prev('tr:first-of-type');
var previousRow = $previousRow.get(0);
case 63232: {
let $previousRow = $(self.rowObject.element).prev('tr:first-of-type');
let previousRow = $previousRow.get(0);
while (previousRow && $previousRow.is(':hidden')) {
$previousRow = $(previousRow).prev('tr:first-of-type');
previousRow = $previousRow.get(0);
......@@ -549,7 +549,7 @@
handle.trigger('focus');
}
break;
}
// Right arrow.
case 39:
// Safari right arrow.
......@@ -561,9 +561,9 @@
// Down arrow.
case 40:
// Safari down arrow.
case 63233:
var $nextRow = $(self.rowObject.group).eq(-1).next('tr:first-of-type');
var nextRow = $nextRow.get(0);
case 63233: {
let $nextRow = $(self.rowObject.group).eq(-1).next('tr:first-of-type');
let nextRow = $nextRow.get(0);
while (nextRow && $nextRow.is(':hidden')) {
$nextRow = $(nextRow).next('tr:first-of-type');
nextRow = $nextRow.get(0);
......@@ -599,6 +599,7 @@
handle.trigger('focus');
}
break;
}
}
/* eslint-enable no-fallthrough */
......@@ -870,7 +871,7 @@
let row = rows[n];
let $row = $(row);
const rowY = $row.offset().top;
var rowHeight;
let rowHeight;
// Because Safari does not report offsetHeight on table rows, but does on
// table cells, grab the firstChild of the row and use that instead.
// http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in-safari.
......@@ -1035,8 +1036,8 @@
targetElement.value = sourceElement.value;
break;
case 'order':
var siblings = this.rowObject.findSiblings(rowSettings);
case 'order': {
const siblings = this.rowObject.findSiblings(rowSettings);
if ($(targetElement).is('select')) {
// Get a list of acceptable values.
const values = [];
......@@ -1065,6 +1066,7 @@
});
}
break;
}
}
}
};
......
......@@ -289,39 +289,41 @@
case 38:
case 63232:
var $previousRow = $(self.rowObject.element).prev('tr:first-of-type');
var previousRow = $previousRow.get(0);
while (previousRow && $previousRow.is(':hidden')) {
$previousRow = $(previousRow).prev('tr:first-of-type');
previousRow = $previousRow.get(0);
}
if (previousRow) {
self.safeBlur = false;
self.rowObject.direction = 'up';
keyChange = true;
if ($(item).is('.tabledrag-root')) {
groupHeight = 0;
while (previousRow && $previousRow.find('.js-indentation').length) {
$previousRow = $(previousRow).prev('tr:first-of-type');
previousRow = $previousRow.get(0);
groupHeight += $previousRow.is(':hidden') ? 0 : previousRow.offsetHeight;
}
if (previousRow) {
self.rowObject.swap('before', previousRow);
{
var $previousRow = $(self.rowObject.element).prev('tr:first-of-type');
var previousRow = $previousRow.get(0);
while (previousRow && $previousRow.is(':hidden')) {
$previousRow = $(previousRow).prev('tr:first-of-type');
previousRow = $previousRow.get(0);
}
if (previousRow) {
self.safeBlur = false;
self.rowObject.direction = 'up';
keyChange = true;
if ($(item).is('.tabledrag-root')) {
groupHeight = 0;
while (previousRow && $previousRow.find('.js-indentation').length) {
$previousRow = $(previousRow).prev('tr:first-of-type');
previousRow = $previousRow.get(0);
groupHeight += $previousRow.is(':hidden') ? 0 : previousRow.offsetHeight;
}
if (previousRow) {
self.rowObject.swap('before', previousRow);
window.scrollBy(0, -groupHeight);
window.scrollBy(0, -groupHeight);
}
} else if (self.table.tBodies[0].rows[0] !== previousRow || $previousRow.is('.draggable')) {
self.rowObject.swap('before', previousRow);
self.rowObject.interval = null;
self.rowObject.indent(0);
window.scrollBy(0, -parseInt(item.offsetHeight, 10));
}
} else if (self.table.tBodies[0].rows[0] !== previousRow || $previousRow.is('.draggable')) {
self.rowObject.swap('before', previousRow);
self.rowObject.interval = null;
self.rowObject.indent(0);
window.scrollBy(0, -parseInt(item.offsetHeight, 10));
}
handle.trigger('focus');
handle.trigger('focus');
}
break;
}
break;
case 39:
case 63235:
......@@ -331,39 +333,41 @@
case 40:
case 63233:
var $nextRow = $(self.rowObject.group).eq(-1).next('tr:first-of-type');
var nextRow = $nextRow.get(0);
while (nextRow && $nextRow.is(':hidden')) {
$nextRow = $(nextRow).next('tr:first-of-type');
nextRow = $nextRow.get(0);
}
if (nextRow) {
self.safeBlur = false;
self.rowObject.direction = 'down';
keyChange = true;
if ($(item).is('.tabledrag-root')) {
groupHeight = 0;
var nextGroup = new self.row(nextRow, 'keyboard', self.indentEnabled, self.maxDepth, false);
if (nextGroup) {
$(nextGroup.group).each(function () {
groupHeight += $(this).is(':hidden') ? 0 : this.offsetHeight;
});
var nextGroupRow = $(nextGroup.group).eq(-1).get(0);
self.rowObject.swap('after', nextGroupRow);
window.scrollBy(0, parseInt(groupHeight, 10));
}
} else {
self.rowObject.swap('after', nextRow);
self.rowObject.interval = null;
self.rowObject.indent(0);
window.scrollBy(0, parseInt(item.offsetHeight, 10));
{
var $nextRow = $(self.rowObject.group).eq(-1).next('tr:first-of-type');
var nextRow = $nextRow.get(0);
while (nextRow && $nextRow.is(':hidden')) {
$nextRow = $(nextRow).next('tr:first-of-type');
nextRow = $nextRow.get(0);
}
if (nextRow) {
self.safeBlur = false;
self.rowObject.direction = 'down';
keyChange = true;
if ($(item).is('.tabledrag-root')) {
groupHeight = 0;
var nextGroup = new self.row(nextRow, 'keyboard', self.indentEnabled, self.maxDepth, false);
if (nextGroup) {
$(nextGroup.group).each(function () {
groupHeight += $(this).is(':hidden') ? 0 : this.offsetHeight;
});
var nextGroupRow = $(nextGroup.group).eq(-1).get(0);
self.rowObject.swap('after', nextGroupRow);
window.scrollBy(0, parseInt(groupHeight, 10));
}
} else {
self.rowObject.swap('after', nextRow);
self.rowObject.interval = null;
self.rowObject.indent(0);
window.scrollBy(0, parseInt(item.offsetHeight, 10));
}
handle.trigger('focus');
handle.trigger('focus');
}
break;
}
break;
}
if (self.rowObject && self.rowObject.changed === true) {
......@@ -539,7 +543,7 @@
var row = rows[n];
var $row = $(row);
var rowY = $row.offset().top;
var rowHeight;
var rowHeight = void 0;
if (row.offsetHeight === 0) {
rowHeight = parseInt(row.firstChild.offsetHeight, 10) / 2;
......@@ -656,29 +660,31 @@
break;
case 'order':
var siblings = this.rowObject.findSiblings(rowSettings);
if ($(targetElement).is('select')) {
var values = [];
$(targetElement).find('option').each(function () {
values.push(this.value);
});
var maxVal = values[values.length - 1];
$(siblings).find(targetClass).each(function () {
if (values.length > 0) {
this.value = values.shift();
} else {
this.value = maxVal;
}
});
} else {
var weight = parseInt($(siblings[0]).find(targetClass).val(), 10) || 0;
$(siblings).find(targetClass).each(function () {
this.value = weight;
weight++;
});
{
var siblings = this.rowObject.findSiblings(rowSettings);
if ($(targetElement).is('select')) {
var values = [];
$(targetElement).find('option').each(function () {
values.push(this.value);
});
var maxVal = values[values.length - 1];
$(siblings).find(targetClass).each(function () {
if (values.length > 0) {
this.value = values.shift();
} else {
this.value = maxVal;
}
});
} else {
var weight = parseInt($(siblings[0]).find(targetClass).val(), 10) || 0;
$(siblings).find(targetClass).each(function () {
this.value = weight;
weight++;
});
}
break;
}
break;
}
}
};
......
......@@ -133,12 +133,11 @@
// Traverse through the sibling nodes.
for (let i = from[mode]; i; i = i[mode]) {
var $i;
const $i = $(i);
// Make sure that we're only dealing with elements.
if (i.nodeType !== 1) {
continue;
}
$i = $(i);
// Either add or remove the selected class based on the state of the
// target checkbox.
$i.toggleClass('selected', state);
......
......@@ -74,12 +74,11 @@
var mode = from.rowIndex > to.rowIndex ? 'previousSibling' : 'nextSibling';
for (var i = from[mode]; i; i = i[mode]) {
var $i;
var $i = $(i);
if (i.nodeType !== 1) {
continue;
}
$i = $(i);
$i.toggleClass('selected', state);
$i.find('input[type="checkbox"]').prop('checked', state);
......
......@@ -89,7 +89,7 @@
// The frequency with which to check for newly arrived BigPipe placeholders.
// Hence 50 ms means we check 20 times per second. Setting this to 100 ms or
// more would cause the user to see content appear noticeably slower.
var interval = drupalSettings.bigPipeInterval || 50;
const interval = drupalSettings.bigPipeInterval || 50;
// The internal ID to contain the watcher service.
let timeoutID;
......
......@@ -290,7 +290,7 @@
// Create a Drupal dialog that will get a button group name from the user.
const $ckeditorButtonGroupNameForm = $(Drupal.theme('ckeditorButtonGroupNameForm'));
var dialog = Drupal.dialog($ckeditorButtonGroupNameForm.get(0), {
const dialog = Drupal.dialog($ckeditorButtonGroupNameForm.get(0), {
title: Drupal.t('Button group name'),
dialogClass: 'ckeditor-name-toolbar-group',
resizable: false,
......
......@@ -80,7 +80,7 @@
const message = Drupal.t('Changing the text format to %text_format will permanently remove content that is not allowed in that text format.<br><br>Save your changes before switching the text format to avoid losing data.', {
'%text_format': $select.find('option:selected').text(),
});
var confirmationDialog = Drupal.dialog(`<div>${message}</div>`, {
const confirmationDialog = Drupal.dialog(`<div>${message}</div>`, {
title: Drupal.t('Change text format?'),
dialogClass: 'editor-change-text-format-modal',
resizable: false,
......
......@@ -140,9 +140,9 @@
}
break;
case 'active':
var textElement = this.$textElement.get(0);
var toolbarView = fieldModel.toolbarView;
case 'active': {
const textElement = this.$textElement.get(0);
const toolbarView = fieldModel.toolbarView;
this.textEditor.attachInlineEditor(
textElement,
this.textFormat,
......@@ -155,6 +155,7 @@
fieldModel.set('state', 'changed');
});
break;
}
case 'changed':
break;
......
......@@ -73,15 +73,17 @@
break;
case 'active':
var textElement = this.$textElement.get(0);
var toolbarView = fieldModel.toolbarView;
this.textEditor.attachInlineEditor(textElement, this.textFormat, toolbarView.getMainWysiwygToolgroupId(), toolbarView.getFloatedWysiwygToolgroupId());
this.textEditor.onChange(textElement, function (htmlText) {
editorModel.set('currentValue', htmlText);
fieldModel.set('state', 'changed');
});
break;
{
var textElement = this.$textElement.get(0);
var toolbarView = fieldModel.toolbarView;
this.textEditor.attachInlineEditor(textElement, this.textFormat, toolbarView.getMainWysiwygToolgroupId(), toolbarView.getFloatedWysiwygToolgroupId());
this.textEditor.onChange(textElement, function (htmlText) {
editorModel.set('currentValue', htmlText);
fieldModel.set('state', 'changed');
});
break;
}
case 'changed':
break;
......
......@@ -70,15 +70,15 @@
});
break;
case 'active':
var self = this;
case 'active': {
const self = this;
// Indicate that this element is being edited by Quick Edit Image.
this.$el.addClass('quickedit-image-element');
// Render our initial dropzone element. Once the user reverts changes
// or saves a new image, this element is removed.
var $dropzone = this.renderDropzone('upload', Drupal.t('Drop file here or click to upload'));
const $dropzone = this.renderDropzone('upload', Drupal.t('Drop file here or click to upload'));
$dropzone.on('dragenter', function (e) {
$(this).addClass('hover');
......@@ -117,6 +117,7 @@
this.renderToolbar(fieldModel);
break;
}
case 'changed':
break;
......
......@@ -50,41 +50,43 @@
break;
case 'active':
var self = this;
{
var self = this;
this.$el.addClass('quickedit-image-element');
this.$el.addClass('quickedit-image-element');
var $dropzone = this.renderDropzone('upload', Drupal.t('Drop file here or click to upload'));
var $dropzone = this.renderDropzone('upload', Drupal.t('Drop file here or click to upload'));
$dropzone.on('dragenter', function (e) {
$(this).addClass('hover');
});
$dropzone.on('dragleave', function (e) {
$(this).removeClass('hover');
});
$dropzone.on('drop', function (e) {
if (e.originalEvent.dataTransfer && e.originalEvent.dataTransfer.files.length) {
$dropzone.on('dragenter', function (e) {
$(this).addClass('hover');
});
$dropzone.on('dragleave', function (e) {
$(this).removeClass('hover');
self.uploadImage(e.originalEvent.dataTransfer.files[0]);
}
});
});
$dropzone.on('click', function (e) {
$('<input type="file">').trigger('click').on('change', function () {
if (this.files.length) {
self.uploadImage(this.files[0]);
$dropzone.on('drop', function (e) {
if (e.originalEvent.dataTransfer && e.originalEvent.dataTransfer.files.length) {
$(this).removeClass('hover');
self.uploadImage(e.originalEvent.dataTransfer.files[0]);
}
});
});
$dropzone.on('dragover dragenter dragleave drop click', function (e) {
e.preventDefault();
e.stopPropagation();
});
$dropzone.on('click', function (e) {
$('<input type="file">').trigger('click').on('change', function () {
if (this.files.length) {
self.uploadImage(this.files[0]);
}
});
});
this.renderToolbar(fieldModel);
break;
$dropzone.on('dragover dragenter dragleave drop click', function (e) {
e.preventDefault();
e.stopPropagation();
});
this.renderToolbar(fieldModel);
break;
}
case 'changed':
break;
......
......@@ -194,7 +194,7 @@
}
// Create an AJAX object for the form associated with the field.
var formSaveAjax = Drupal.quickedit.util.form.ajaxifySaving({
let formSaveAjax = Drupal.quickedit.util.form.ajaxifySaving({
nocssjs: false,
other_view_modes: fieldModel.findOtherViewModes(),
}, $submit);
......
......@@ -189,9 +189,9 @@
this.set('isActive', true);
break;
case 'committing':
case 'committing': {
// The user indicated they want to save the entity.
var fields = this.get('fields');
const fields = this.get('fields');
// For fields that are in an active state, transition them to
// candidate.
fields.chain()
......@@ -207,9 +207,10 @@
fieldModel.set('state', 'saving');
});
break;
}
case 'deactivating':
var changedFields = this.get('fields')
case 'deactivating': {
const changedFields = this.get('fields')
.filter(fieldModel => _.intersection([fieldModel.get('state')], ['changed', 'invalid']).length);
// If the entity contains unconfirmed or unsaved changes, return the
// entity to an opened state and ask the user if they would like to
......@@ -250,6 +251,7 @@
});
}
break;
}
case 'closing':
// Set all fields to the 'inactive' state.
......@@ -364,7 +366,7 @@
}
break;
case 'committing':
case 'committing': {
// If the field save returned a validation error, set the state of the
// entity back to 'opened'.
if (fieldState === 'invalid') {
......@@ -380,7 +382,7 @@
// Attempt to save the entity. If the entity's fields are not yet all
// in a ready state, the save will not be processed.
var options = {
const options = {
'accept-field-states': Drupal.quickedit.app.readyFieldStates,
};
if (entityModel.set('isCommitting', true, options)) {
......@@ -404,6 +406,7 @@
});
}
break;
}
case 'deactivating':
// When setting the entity to 'closing', require that all fieldModels
......
......@@ -69,48 +69,52 @@
break;
case 'committing':
var fields = this.get('fields');
{
var fields = this.get('fields');
fields.chain().filter(function (fieldModel) {
return _.intersection([fieldModel.get('state')], ['active']).length;
}).each(function (fieldModel) {
fieldModel.set('state', 'candidate');
});
fields.chain().filter(function (fieldModel) {
return _.intersection([fieldModel.get('state')], ['active']).length;
}).each(function (fieldModel) {
fieldModel.set('state', 'candidate');
});
fields.chain().filter(function (fieldModel) {
return _.intersection([fieldModel.get('state')], Drupal.quickedit.app.changedFieldStates).length;
}).each(function (fieldModel) {
fieldModel.set('state', 'saving');
});
break;
fields.chain().filter(function (fieldModel) {
return _.intersection([fieldModel.get('state')], Drupal.quickedit.app.changedFieldStates).length;
}).each(function (fieldModel) {
fieldModel.set('state', 'saving');
});
break;
}
case 'deactivating':
var changedFields = this.get('fields').filter(function (fieldModel) {
return _.intersection([fieldModel.get('state')], ['changed', 'invalid']).length;
});
if ((changedFields.length || this.get('fieldsInTempStore').length) && !options.saved && !options.confirmed) {
this.set('state', 'opened', { confirming: true });
_.defer(function () {
Drupal.quickedit.app.confirmEntityDeactivation(entityModel);
{
var changedFields = this.get('fields').filter(function (fieldModel) {
return _.intersection([fieldModel.get('state')], ['changed', 'invalid']).length;
});
} else {
var invalidFields = this.get('fields').filter(function (fieldModel) {
return _.intersection([fieldModel.get('state')], ['invalid']).length;
});
entityModel.set('reload', this.get('fieldsInTempStore').length || invalidFields.length);
entityModel.get('fields').each(function (fieldModel) {
if (_.intersection([fieldModel.get('state')], ['candidate', 'highlighted']).length) {
fieldModel.trigger('change:state', fieldModel, fieldModel.get('state'), options);
} else {
fieldModel.set('state', 'candidate', options);
}
});
if ((changedFields.length || this.get('fieldsInTempStore').length) && !options.saved && !options.confirmed) {
this.set('state', 'opened', { confirming: true });
_.defer(function () {
Drupal.quickedit.app.confirmEntityDeactivation(entityModel);
});
} else {
var invalidFields = this.get('fields').filter(function (fieldModel) {
return _.intersection([fieldModel.get('state')], ['invalid']).length;
});
entityModel.set('reload', this.get('fieldsInTempStore').length || invalidFields.length);
entityModel.get('fields').each(function (fieldModel) {
if (_.intersection([fieldModel.get('state')], ['candidate', 'highlighted']).length) {
fieldModel.trigger('change:state', fieldModel, fieldModel.get('state'), options);
} else {
fieldModel.set('state', 'candidate', options);
}
});
}
break;
}
break;
case 'closing':
options.reason = 'stop';
......@@ -166,36 +170,38 @@
break;
case 'committing':
if (fieldState === 'invalid') {
_.defer(function () {
entityModel.set('state', 'opened', { reason: 'invalid' });
});
} else {
this._updateInTempStoreAttributes(entityModel, fieldModel);
}
var options = {
'accept-field-states': Drupal.quickedit.app.readyFieldStates
};
if (entityModel.set('isCommitting', true, options)) {
entityModel.save({
success: function success() {
entityModel.set({
state: 'deactivating',
isCommitting: false
}, { saved: true });
},
error: function error() {
entityModel.set('isCommitting', false);
entityModel.set('state', 'opened', { reason: 'networkerror' });
var message = Drupal.t('Your changes to <q>@entity-title</q> could not be saved, either due to a website problem or a network connection problem.<br>Please try again.', { '@entity-title': entityModel.get('label') });
Drupal.quickedit.util.networkErrorModal(Drupal.t('Network problem!'), message);
}
});
{
if (fieldState === 'invalid') {
_.defer(function () {
entityModel.set('state', 'opened', { reason: 'invalid' });