Commit 612c1fa6 authored by lauriii's avatar lauriii

Issue #2880007 by drpal, nod_, droplet: Auto-fix ESLint errors and warnings

parent 062c2556
......@@ -4,9 +4,6 @@
*/
(function (Drupal, drupalSettings) {
'use strict';
/**
* Append is-active class.
*
......@@ -22,13 +19,13 @@
* @type {Drupal~behavior}
*/
Drupal.behaviors.activeLinks = {
attach: function (context) {
attach(context) {
// Start by finding all potentially active links.
var path = drupalSettings.path;
var queryString = JSON.stringify(path.currentQuery);
var querySelector = path.currentQuery ? "[data-drupal-link-query='" + queryString + "']" : ':not([data-drupal-link-query])';
var originalSelectors = ['[data-drupal-link-system-path="' + path.currentPath + '"]'];
var selectors;
const path = drupalSettings.path;
const queryString = JSON.stringify(path.currentQuery);
const querySelector = path.currentQuery ? `[data-drupal-link-query='${queryString}']` : ':not([data-drupal-link-query])';
const originalSelectors = [`[data-drupal-link-system-path="${path.currentPath}"]`];
let selectors;
// If this is the front page, we have to check for the <front> path as
// well.
......@@ -39,30 +36,29 @@
// Add language filtering.
selectors = [].concat(
// Links without any hreflang attributes (most of them).
originalSelectors.map(function (selector) { return selector + ':not([hreflang])'; }),
originalSelectors.map(selector => `${selector}:not([hreflang])`),
// Links with hreflang equals to the current language.
originalSelectors.map(function (selector) { return selector + '[hreflang="' + path.currentLanguage + '"]'; })
originalSelectors.map(selector => `${selector}[hreflang="${path.currentLanguage}"]`),
);
// Add query string selector for pagers, exposed filters.
selectors = selectors.map(function (current) { return current + querySelector; });
selectors = selectors.map(current => current + querySelector);
// Query the DOM.
var activeLinks = context.querySelectorAll(selectors.join(','));
var il = activeLinks.length;
for (var i = 0; i < il; i++) {
const activeLinks = context.querySelectorAll(selectors.join(','));
const il = activeLinks.length;
for (let i = 0; i < il; i++) {
activeLinks[i].classList.add('is-active');
}
},
detach: function (context, settings, trigger) {
detach(context, settings, trigger) {
if (trigger === 'unload') {
var activeLinks = context.querySelectorAll('[data-drupal-link-system-path].is-active');
var il = activeLinks.length;
for (var i = 0; i < il; i++) {
const activeLinks = context.querySelectorAll('[data-drupal-link-system-path].is-active');
const il = activeLinks.length;
for (let i = 0; i < il; i++) {
activeLinks[i].classList.remove('is-active');
}
}
}
},
};
})(Drupal, drupalSettings);
}(Drupal, drupalSettings));
......@@ -6,16 +6,13 @@
**/
(function (Drupal, drupalSettings) {
'use strict';
Drupal.behaviors.activeLinks = {
attach: function attach(context) {
var path = drupalSettings.path;
var queryString = JSON.stringify(path.currentQuery);
var querySelector = path.currentQuery ? "[data-drupal-link-query='" + queryString + "']" : ':not([data-drupal-link-query])';
var querySelector = path.currentQuery ? '[data-drupal-link-query=\'' + queryString + '\']' : ':not([data-drupal-link-query])';
var originalSelectors = ['[data-drupal-link-system-path="' + path.currentPath + '"]'];
var selectors;
var selectors = void 0;
if (path.isFront) {
originalSelectors.push('[data-drupal-link-system-path="<front>"]');
......
This diff is collapsed.
......@@ -4,14 +4,11 @@
* https://www.drupal.org/node/2815083
* @preserve
**/
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
(function ($, window, Drupal, drupalSettings) {
'use strict';
Drupal.behaviors.AJAX = {
attach: function attach(context, settings) {
function loadAjaxBehavior(base) {
var element_settings = settings.ajax[base];
if (typeof element_settings.selector === 'undefined') {
......@@ -63,7 +60,6 @@
Drupal.ajax(element_settings);
});
},
detach: function detach(context, settings, trigger) {
if (trigger === 'unload') {
Drupal.ajax.expired().forEach(function (instance) {
......@@ -74,12 +70,11 @@
};
Drupal.AjaxError = function (xmlhttp, uri, customMessage) {
var statusCode;
var statusText;
var pathText;
var responseText;
var readyStateText;
var statusCode = void 0;
var statusText = void 0;
var pathText = void 0;
var responseText = void 0;
var readyStateText = void 0;
if (xmlhttp.status) {
statusCode = '\n' + Drupal.t('An AJAX HTTP error occurred.') + '\n' + Drupal.t('HTTP Result Code: !status', { '!status': xmlhttp.status });
} else {
......@@ -231,6 +226,7 @@
return ajax.error(xmlhttprequest, ajax.url);
}
},
dataType: 'json',
type: 'POST'
};
......@@ -476,7 +472,7 @@
var $wrapper = response.selector ? $(response.selector) : $(ajax.wrapper);
var method = response.method || ajax.method;
var effect = ajax.getEffect(response);
var settings;
var settings = void 0;
var $new_content_wrapped = $('<div></div>').html(response.data);
var $new_content = $new_content_wrapped.contents();
......@@ -514,14 +510,12 @@
Drupal.attachBehaviors($new_content.get(0), settings);
}
},
remove: function remove(ajax, response, status) {
var settings = response.settings || ajax.settings || drupalSettings;
$(response.selector).each(function () {
Drupal.detachBehaviors(this, settings);
}).remove();
},
changed: function changed(ajax, response, status) {
var $element = $(response.selector);
if (!$element.hasClass('ajax-changed')) {
......@@ -531,19 +525,15 @@
}
}
},
alert: function alert(ajax, response, status) {
window.alert(response.text, response.title);
},
redirect: function redirect(ajax, response, status) {
window.location = response.url;
},
css: function css(ajax, response, status) {
$(response.selector).css(response.argument);
},
settings: function settings(ajax, response, status) {
var ajaxSettings = drupalSettings.ajax;
......@@ -565,28 +555,23 @@
ajax.settings = response.settings;
}
},
data: function data(ajax, response, status) {
$(response.selector).data(response.name, response.value);
},
invoke: function invoke(ajax, response, status) {
var $element = $(response.selector);
$element[response.method].apply($element, response.args);
$element[response.method].apply($element, _toConsumableArray(response.args));
},
restripe: function restripe(ajax, response, status) {
$(response.selector).find('> tbody > tr:visible, > tr:visible').removeClass('odd even').filter(':even').addClass('odd').end().filter(':odd').addClass('even');
},
update_build_id: function update_build_id(ajax, response, status) {
$('input[name="form_build_id"][value="' + response.old + '"]').val(response.new);
},
add_css: function add_css(ajax, response, status) {
$('head').prepend(response.data);
var match;
var match = void 0;
var importMatch = /^@import url\("(.*)"\);$/igm;
if (document.styleSheets[0].addImport && importMatch.test(response.data)) {
importMatch.lastIndex = 0;
......
......@@ -19,11 +19,8 @@
*/
(function (Drupal, debounce) {
'use strict';
var liveElement;
var announcements = [];
let liveElement;
const announcements = [];
/**
* Builds a div element with the aria-live attribute and add it to the DOM.
......@@ -34,7 +31,7 @@
* Attaches the behavior for drupalAnnouce.
*/
Drupal.behaviors.drupalAnnounce = {
attach: function (context) {
attach(context) {
// Create only one aria-live element.
if (!liveElement) {
liveElement = document.createElement('div');
......@@ -44,21 +41,21 @@
liveElement.setAttribute('aria-busy', 'false');
document.body.appendChild(liveElement);
}
}
},
};
/**
* Concatenates announcements to a single string; appends to the live region.
*/
function announce() {
var text = [];
var priority = 'polite';
var announcement;
const text = [];
let priority = 'polite';
let announcement;
// Create an array of announcement strings to be joined and appended to the
// aria live region.
var il = announcements.length;
for (var i = 0; i < il; i++) {
const il = announcements.length;
for (let i = 0; i < il; i++) {
announcement = announcements.pop();
text.unshift(announcement.text);
// If any of the announcements has a priority of assertive then the group
......@@ -109,8 +106,8 @@
// Save the text and priority into a closure variable. Multiple simultaneous
// announcements will be concatenated and read in sequence.
announcements.push({
text: text,
priority: priority
text,
priority,
});
// Immediately invoke the function that debounce returns. 200 ms is right at
// the cusp where humans notice a pause, so we will wait
......
......@@ -6,10 +6,7 @@
**/
(function (Drupal, debounce) {
'use strict';
var liveElement;
var liveElement = void 0;
var announcements = [];
Drupal.behaviors.drupalAnnounce = {
......@@ -28,7 +25,7 @@
function announce() {
var text = [];
var priority = 'polite';
var announcement;
var announcement = void 0;
var il = announcements.length;
for (var i = 0; i < il; i++) {
......
......@@ -4,10 +4,7 @@
*/
(function ($, Drupal) {
'use strict';
var autocomplete;
let autocomplete;
/**
* Helper splitting terms from the autocomplete value.
......@@ -22,13 +19,13 @@
*/
function autocompleteSplitValues(value) {
// We will match the value against comma-separated terms.
var result = [];
var quote = false;
var current = '';
var valueLength = value.length;
var character;
const result = [];
let quote = false;
let current = '';
const valueLength = value.length;
let character;
for (var i = 0; i < valueLength; i++) {
for (let i = 0; i < valueLength; i++) {
character = value.charAt(i);
if (character === '"') {
current += character;
......@@ -76,13 +73,13 @@
* Whether to perform a search or not.
*/
function searchHandler(event) {
var options = autocomplete.options;
const options = autocomplete.options;
if (options.isComposing) {
return false;
}
var term = autocomplete.extractLastTerm(event.target.value);
const term = autocomplete.extractLastTerm(event.target.value);
// Abort search if the first character is in firstCharacterBlacklist.
if (term.length > 0 && options.firstCharacterBlacklist.indexOf(term[0]) !== -1) {
return false;
......@@ -100,7 +97,7 @@
* The function to call with the response.
*/
function sourceData(request, response) {
var elementId = this.element.attr('id');
const elementId = this.element.attr('id');
if (!(elementId in autocomplete.cache)) {
autocomplete.cache[elementId] = {};
......@@ -114,10 +111,10 @@
* Suggestions returned by the server.
*/
function showSuggestions(suggestions) {
var tagged = autocomplete.splitValues(request.term);
var il = tagged.length;
for (var i = 0; i < il; i++) {
var index = suggestions.indexOf(tagged[i]);
const tagged = autocomplete.splitValues(request.term);
const il = tagged.length;
for (let i = 0; i < il; i++) {
const index = suggestions.indexOf(tagged[i]);
if (index >= 0) {
suggestions.splice(index, 1);
}
......@@ -146,7 +143,7 @@
showSuggestions(autocomplete.cache[elementId][term]);
}
else {
var options = $.extend({success: sourceCallbackHandler, data: {q: term}}, autocomplete.ajax);
const options = $.extend({ success: sourceCallbackHandler, data: { q: term } }, autocomplete.ajax);
$.ajax(this.element.attr('data-autocomplete-path'), options);
}
}
......@@ -173,7 +170,7 @@
* Returns false to indicate the event status.
*/
function selectHandler(event, ui) {
var terms = autocomplete.splitValues(event.target.value);
const terms = autocomplete.splitValues(event.target.value);
// Remove the current input.
terms.pop();
// Add the selected item.
......@@ -212,14 +209,14 @@
* Detaches the autocomplete behaviors.
*/
Drupal.behaviors.autocomplete = {
attach: function (context) {
attach(context) {
// Act on textfields with the "form-autocomplete" class.
var $autocomplete = $(context).find('input.form-autocomplete').once('autocomplete');
const $autocomplete = $(context).find('input.form-autocomplete').once('autocomplete');
if ($autocomplete.length) {
// Allow options to be overriden per instance.
var blacklist = $autocomplete.attr('data-autocomplete-first-character-blacklist');
const blacklist = $autocomplete.attr('data-autocomplete-first-character-blacklist');
$.extend(autocomplete.options, {
firstCharacterBlacklist: (blacklist) ? blacklist : ''
firstCharacterBlacklist: (blacklist) || '',
});
// Use jQuery UI Autocomplete on the textfield.
$autocomplete.autocomplete(autocomplete.options)
......@@ -228,21 +225,21 @@
});
// Use CompositionEvent to handle IME inputs. It requests remote server on "compositionend" event only.
$autocomplete.on('compositionstart.autocomplete', function () {
$autocomplete.on('compositionstart.autocomplete', () => {
autocomplete.options.isComposing = true;
});
$autocomplete.on('compositionend.autocomplete', function () {
$autocomplete.on('compositionend.autocomplete', () => {
autocomplete.options.isComposing = false;
});
}
},
detach: function (context, settings, trigger) {
detach(context, settings, trigger) {
if (trigger === 'unload') {
$(context).find('input.form-autocomplete')
.removeOnce('autocomplete')
.autocomplete('destroy');
}
}
},
};
/**
......@@ -254,7 +251,7 @@
cache: {},
// Exposes options to allow overriding by contrib.
splitValues: autocompleteSplitValues,
extractLastTerm: extractLastTerm,
extractLastTerm,
// jQuery UI autocomplete options.
/**
......@@ -267,18 +264,17 @@
focus: focusHandler,
search: searchHandler,
select: selectHandler,
renderItem: renderItem,
renderItem,
minLength: 1,
// Custom options, used by Drupal.autocomplete.
firstCharacterBlacklist: '',
// Custom options, indicate IME usage status.
isComposing: false
isComposing: false,
},
ajax: {
dataType: 'json'
}
dataType: 'json',
},
};
Drupal.autocomplete = autocomplete;
})(jQuery, Drupal);
}(jQuery, Drupal));
......@@ -6,17 +6,14 @@
**/
(function ($, Drupal) {
'use strict';
var autocomplete;
var autocomplete = void 0;
function autocompleteSplitValues(value) {
var result = [];
var quote = false;
var current = '';
var valueLength = value.length;
var character;
var character = void 0;
for (var i = 0; i < valueLength; i++) {
character = value.charAt(i);
......@@ -118,7 +115,7 @@
if ($autocomplete.length) {
var blacklist = $autocomplete.attr('data-autocomplete-first-character-blacklist');
$.extend(autocomplete.options, {
firstCharacterBlacklist: blacklist ? blacklist : ''
firstCharacterBlacklist: blacklist || ''
});
$autocomplete.autocomplete(autocomplete.options).each(function () {
......
......@@ -4,25 +4,22 @@
*/
(function ($, Drupal) {
'use strict';
/**
* Attaches the batch behavior to progress bars.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.batch = {
attach: function (context, settings) {
var batch = settings.batch;
var $progress = $('[data-drupal-progress]').once('batch');
var progressBar;
attach(context, settings) {
const batch = settings.batch;
const $progress = $('[data-drupal-progress]').once('batch');
let progressBar;
// Success: redirect to the summary.
function updateCallback(progress, status, pb) {
if (progress === '100') {
pb.stopMonitoring();
window.location = batch.uri + '&op=finished';
window.location = `${batch.uri}&op=finished`;
}
}
......@@ -34,13 +31,12 @@
if ($progress.length) {
progressBar = new Drupal.ProgressBar('updateprogress', updateCallback, 'POST', errorCallback);
progressBar.setProgress(-1, batch.initMessage);
progressBar.startMonitoring(batch.uri + '&op=do', 10);
progressBar.startMonitoring(`${batch.uri}&op=do`, 10);
// Remove HTML from no-js progress bar.
$progress.empty();
// Append the JS progressbar element.
$progress.append(progressBar.element);
}
}
},
};
})(jQuery, Drupal);
}(jQuery, Drupal));
......@@ -6,14 +6,11 @@
**/
(function ($, Drupal) {
'use strict';
Drupal.behaviors.batch = {
attach: function attach(context, settings) {
var batch = settings.batch;
var $progress = $('[data-drupal-progress]').once('batch');
var progressBar;
var progressBar = void 0;
function updateCallback(progress, status, pb) {
if (progress === '100') {
......
......@@ -4,9 +4,6 @@
*/
(function ($, Modernizr, Drupal) {
'use strict';
/**
* The collapsible details object represents a single details element.
*
......@@ -20,8 +17,8 @@
this.$node.data('details', this);
// Expand details if there are errors inside, or if it contains an
// element that is targeted by the URI fragment identifier.
var anchor = location.hash && location.hash !== '#' ? ', ' + location.hash : '';
if (this.$node.find('.error' + anchor).length) {
const anchor = location.hash && location.hash !== '#' ? `, ${location.hash}` : '';
if (this.$node.find(`.error${anchor}`).length) {
this.$node.attr('open', true);
}
// Initialize and setup the summary,
......@@ -37,7 +34,7 @@
*
* @type {Array.<Drupal.CollapsibleDetails>}
*/
instances: []
instances: [],
});
$.extend(CollapsibleDetails.prototype, /** @lends Drupal.CollapsibleDetails# */{
......@@ -49,7 +46,7 @@
*
* @listens event:summaryUpdated
*/
setupSummary: function () {
setupSummary() {
this.$summary = $('<span class="summary"></span>');
this.$node
.on('summaryUpdated', $.proxy(this.onSummaryUpdated, this))
......@@ -59,9 +56,9 @@
/**
* Initialize and setup legend markup.