Revert "Issue #2916154 by drpal, dawehner, xjm: JS codestyle: no-multi-assign"

This reverts commit 169e867159.
8.5.x
Alex Pott 2017-10-21 21:49:45 +01:00
parent 169e867159
commit 27266234c2
17 changed files with 42 additions and 54 deletions

View File

@ -7,6 +7,7 @@
"no-shadow": "off", "no-shadow": "off",
"no-restricted-syntax": "off", "no-restricted-syntax": "off",
"no-new": "off", "no-new": "off",
"no-multi-assign": "off",
"no-continue": "off", "no-continue": "off",
"new-cap": "off", "new-cap": "off",
"max-len": "off", "max-len": "off",

View File

@ -73,8 +73,7 @@
* @fires event:drupalViewportOffsetChange * @fires event:drupalViewportOffsetChange
*/ */
function displace(broadcast) { function displace(broadcast) {
offsets = calculateOffsets(); offsets = Drupal.displace.offsets = calculateOffsets();
Drupal.displace.offsets = offsets;
if (typeof broadcast === 'undefined' || broadcast) { if (typeof broadcast === 'undefined' || broadcast) {
$(document).trigger('drupalViewportOffsetChange', offsets); $(document).trigger('drupalViewportOffsetChange', offsets);
} }

View File

@ -25,8 +25,7 @@
}; };
function displace(broadcast) { function displace(broadcast) {
offsets = calculateOffsets(); offsets = Drupal.displace.offsets = calculateOffsets();
Drupal.displace.offsets = offsets;
if (typeof broadcast === 'undefined' || broadcast) { if (typeof broadcast === 'undefined' || broadcast) {
$(document).trigger('drupalViewportOffsetChange', offsets); $(document).trigger('drupalViewportOffsetChange', offsets);
} }

View File

@ -12,7 +12,7 @@
* *
* @namespace Drupal.states * @namespace Drupal.states
*/ */
const states = { const states = Drupal.states = {
/** /**
* An array of functions that should be postponed. * An array of functions that should be postponed.
@ -20,8 +20,6 @@
postponed: [], postponed: [],
}; };
Drupal.states = states;
/** /**
* Attaches the states. * Attaches the states.
* *
@ -510,8 +508,7 @@
/** /**
* Original unresolved name. * Original unresolved name.
*/ */
this.pristine = state; this.pristine = this.name = state;
this.name = state;
// Normalize the state name. // Normalize the state name.
let process = true; let process = true;

View File

@ -6,12 +6,10 @@
**/ **/
(function ($, Drupal) { (function ($, Drupal) {
var states = { var states = Drupal.states = {
postponed: [] postponed: []
}; };
Drupal.states = states;
Drupal.behaviors.states = { Drupal.behaviors.states = {
attach: function attach(context, settings) { attach: function attach(context, settings) {
var $states = $(context).find('[data-drupal-states]'); var $states = $(context).find('[data-drupal-states]');
@ -261,8 +259,7 @@
}; };
states.State = function (state) { states.State = function (state) {
this.pristine = state; this.pristine = this.name = state;
this.name = state;
var process = true; var process = true;
do { do {

View File

@ -1107,16 +1107,14 @@
const de = document.documentElement; const de = document.documentElement;
const b = document.body; const b = document.body;
const windowHeight = window.innerHeight || (de.clientHeight && de.clientWidth !== 0 ? de.clientHeight : b.offsetHeight); const windowHeight = this.windowHeight = window.innerHeight || (de.clientHeight && de.clientWidth !== 0 ? de.clientHeight : b.offsetHeight);
this.windowHeight = windowHeight;
let scrollY; let scrollY;
if (document.all) { if (document.all) {
scrollY = !de.scrollTop ? b.scrollTop : de.scrollTop; scrollY = this.scrollY = !de.scrollTop ? b.scrollTop : de.scrollTop;
} }
else { else {
scrollY = window.pageYOffset ? window.pageYOffset : window.scrollY; scrollY = this.scrollY = window.pageYOffset ? window.pageYOffset : window.scrollY;
} }
this.scrollY = scrollY;
const trigger = this.scrollSettings.trigger; const trigger = this.scrollSettings.trigger;
let delta = 0; let delta = 0;

View File

@ -701,15 +701,13 @@
var de = document.documentElement; var de = document.documentElement;
var b = document.body; var b = document.body;
var windowHeight = window.innerHeight || (de.clientHeight && de.clientWidth !== 0 ? de.clientHeight : b.offsetHeight); var windowHeight = this.windowHeight = window.innerHeight || (de.clientHeight && de.clientWidth !== 0 ? de.clientHeight : b.offsetHeight);
this.windowHeight = windowHeight;
var scrollY = void 0; var scrollY = void 0;
if (document.all) { if (document.all) {
scrollY = !de.scrollTop ? b.scrollTop : de.scrollTop; scrollY = this.scrollY = !de.scrollTop ? b.scrollTop : de.scrollTop;
} else { } else {
scrollY = window.pageYOffset ? window.pageYOffset : window.scrollY; scrollY = this.scrollY = window.pageYOffset ? window.pageYOffset : window.scrollY;
} }
this.scrollY = scrollY;
var trigger = this.scrollSettings.trigger; var trigger = this.scrollSettings.trigger;
var delta = 0; var delta = 0;

View File

@ -34,7 +34,7 @@
$configurationForm.append(drupalSettings.ckeditor.toolbarAdmin); $configurationForm.append(drupalSettings.ckeditor.toolbarAdmin);
// Create a configuration model. // Create a configuration model.
Drupal.ckeditor.models.Model = new Drupal.ckeditor.Model({ const model = Drupal.ckeditor.models.Model = new Drupal.ckeditor.Model({
$textarea, $textarea,
activeEditorConfig: JSON.parse($textarea.val()), activeEditorConfig: JSON.parse($textarea.val()),
hiddenEditorConfig: drupalSettings.ckeditor.hiddenCKEditorConfig, hiddenEditorConfig: drupalSettings.ckeditor.hiddenCKEditorConfig,
@ -42,7 +42,7 @@
// Create the configuration Views. // Create the configuration Views.
const viewDefaults = { const viewDefaults = {
model: Drupal.ckeditor.models.Model, model,
el: $('.ckeditor-toolbar-configuration'), el: $('.ckeditor-toolbar-configuration'),
}; };
Drupal.ckeditor.views = { Drupal.ckeditor.views = {

View File

@ -16,14 +16,14 @@
$configurationForm.append(drupalSettings.ckeditor.toolbarAdmin); $configurationForm.append(drupalSettings.ckeditor.toolbarAdmin);
Drupal.ckeditor.models.Model = new Drupal.ckeditor.Model({ var model = Drupal.ckeditor.models.Model = new Drupal.ckeditor.Model({
$textarea: $textarea, $textarea: $textarea,
activeEditorConfig: JSON.parse($textarea.val()), activeEditorConfig: JSON.parse($textarea.val()),
hiddenEditorConfig: drupalSettings.ckeditor.hiddenCKEditorConfig hiddenEditorConfig: drupalSettings.ckeditor.hiddenCKEditorConfig
}); });
var viewDefaults = { var viewDefaults = {
model: Drupal.ckeditor.models.Model, model: model,
el: $('.ckeditor-toolbar-configuration') el: $('.ckeditor-toolbar-configuration')
}; };
Drupal.ckeditor.views = { Drupal.ckeditor.views = {

View File

@ -22,7 +22,7 @@
} }
const contextualToolbar = Drupal.contextualToolbar; const contextualToolbar = Drupal.contextualToolbar;
contextualToolbar.model = new contextualToolbar.StateModel({ const model = contextualToolbar.model = new contextualToolbar.StateModel({
// Checks whether localStorage indicates we should start in edit mode // Checks whether localStorage indicates we should start in edit mode
// rather than view mode. // rather than view mode.
// @see Drupal.contextualToolbar.VisualView.persist // @see Drupal.contextualToolbar.VisualView.persist
@ -33,7 +33,7 @@
const viewOptions = { const viewOptions = {
el: $('.toolbar .toolbar-bar .contextual-toolbar-tab'), el: $('.toolbar .toolbar-bar .contextual-toolbar-tab'),
model: contextualToolbar.model, model,
strings, strings,
}; };
new contextualToolbar.VisualView(viewOptions); new contextualToolbar.VisualView(viewOptions);

View File

@ -18,7 +18,7 @@
} }
var contextualToolbar = Drupal.contextualToolbar; var contextualToolbar = Drupal.contextualToolbar;
contextualToolbar.model = new contextualToolbar.StateModel({ var model = contextualToolbar.model = new contextualToolbar.StateModel({
isViewing: localStorage.getItem('Drupal.contextualToolbar.isViewing') !== 'false' isViewing: localStorage.getItem('Drupal.contextualToolbar.isViewing') !== 'false'
}, { }, {
contextualCollection: Drupal.contextual.collection contextualCollection: Drupal.contextual.collection
@ -26,7 +26,7 @@
var viewOptions = { var viewOptions = {
el: $('.toolbar .toolbar-bar .contextual-toolbar-tab'), el: $('.toolbar .toolbar-bar .contextual-toolbar-tab'),
model: contextualToolbar.model, model: model,
strings: strings strings: strings
}; };
new contextualToolbar.VisualView(viewOptions); new contextualToolbar.VisualView(viewOptions);

View File

@ -95,11 +95,10 @@
const id = `quickedit-form-for-${fieldModel.id.replace(/[\/\[\]]/g, '_')}`; const id = `quickedit-form-for-${fieldModel.id.replace(/[\/\[\]]/g, '_')}`;
// Render form container. // Render form container.
const $formContainer = $(Drupal.theme('quickeditFormContainer', { const $formContainer = this.$formContainer = $(Drupal.theme('quickeditFormContainer', {
id, id,
loadingMsg: Drupal.t('Loading…'), loadingMsg: Drupal.t('Loading…'),
})); }));
this.$formContainer = $formContainer;
$formContainer $formContainer
.find('.quickedit-form') .find('.quickedit-form')
.addClass('quickedit-editable quickedit-highlighted quickedit-editing') .addClass('quickedit-editable quickedit-highlighted quickedit-editing')

View File

@ -59,11 +59,10 @@
var id = 'quickedit-form-for-' + fieldModel.id.replace(/[\/\[\]]/g, '_'); var id = 'quickedit-form-for-' + fieldModel.id.replace(/[\/\[\]]/g, '_');
var $formContainer = $(Drupal.theme('quickeditFormContainer', { var $formContainer = this.$formContainer = $(Drupal.theme('quickeditFormContainer', {
id: id, id: id,
loadingMsg: Drupal.t('Loading…') loadingMsg: Drupal.t('Loading…')
})); }));
this.$formContainer = $formContainer;
$formContainer.find('.quickedit-form').addClass('quickedit-editable quickedit-highlighted quickedit-editing').attr('role', 'dialog'); $formContainer.find('.quickedit-form').addClass('quickedit-editable quickedit-highlighted quickedit-editing').attr('role', 'dialog');
if (this.$el.css('display') === 'inline') { if (this.$el.css('display') === 'inline') {

View File

@ -27,9 +27,14 @@
// Store the original value of this field. Necessary for reverting // Store the original value of this field. Necessary for reverting
// changes. // changes.
let $textElement;
const $fieldItems = this.$el.find('.quickedit-field'); const $fieldItems = this.$el.find('.quickedit-field');
const $textElement = $fieldItems.length ? $fieldItems.eq(0) : this.$el; if ($fieldItems.length) {
this.$textElement = $textElement; $textElement = this.$textElement = $fieldItems.eq(0);
}
else {
$textElement = this.$textElement = this.$el;
}
editorModel.set('originalValue', $.trim(this.$textElement.text())); editorModel.set('originalValue', $.trim(this.$textElement.text()));
// Sets the state to 'changed' whenever the value changes. // Sets the state to 'changed' whenever the value changes.

View File

@ -15,9 +15,13 @@
var editorModel = this.model; var editorModel = this.model;
var fieldModel = this.fieldModel; var fieldModel = this.fieldModel;
var $textElement = void 0;
var $fieldItems = this.$el.find('.quickedit-field'); var $fieldItems = this.$el.find('.quickedit-field');
var $textElement = $fieldItems.length ? $fieldItems.eq(0) : this.$el; if ($fieldItems.length) {
this.$textElement = $textElement; $textElement = this.$textElement = $fieldItems.eq(0);
} else {
$textElement = this.$textElement = this.$el;
}
editorModel.set('originalValue', $.trim(this.$textElement.text())); editorModel.set('originalValue', $.trim(this.$textElement.text()));
var previousText = editorModel.get('originalValue'); var previousText = editorModel.get('originalValue');

View File

@ -46,21 +46,18 @@
// Process the administrative toolbar. // Process the administrative toolbar.
$(context).find('#toolbar-administration').once('toolbar').each(function () { $(context).find('#toolbar-administration').once('toolbar').each(function () {
// Establish the toolbar models and views. // Establish the toolbar models and views.
const model = new Drupal.toolbar.ToolbarModel({ const model = Drupal.toolbar.models.toolbarModel = new Drupal.toolbar.ToolbarModel({
locked: JSON.parse(localStorage.getItem('Drupal.toolbar.trayVerticalLocked')), locked: JSON.parse(localStorage.getItem('Drupal.toolbar.trayVerticalLocked')),
activeTab: document.getElementById(JSON.parse(localStorage.getItem('Drupal.toolbar.activeTabID'))), activeTab: document.getElementById(JSON.parse(localStorage.getItem('Drupal.toolbar.activeTabID'))),
height: $('#toolbar-administration').outerHeight(), height: $('#toolbar-administration').outerHeight(),
}); });
Drupal.toolbar.models.toolbarModel = model;
// Attach a listener to the configured media query breakpoints. // Attach a listener to the configured media query breakpoints.
// Executes it before Drupal.toolbar.views to avoid extra rendering. // Executes it before Drupal.toolbar.views to avoid extra rendering.
for (const label in options.breakpoints) { for (const label in options.breakpoints) {
if (options.breakpoints.hasOwnProperty(label)) { if (options.breakpoints.hasOwnProperty(label)) {
const mq = options.breakpoints[label]; const mq = options.breakpoints[label];
const mql = window.matchMedia(mq); const mql = Drupal.toolbar.mql[label] = window.matchMedia(mq);
Drupal.toolbar.mql[label] = mql;
// Curry the model and the label of the media query breakpoint to // Curry the model and the label of the media query breakpoint to
// the mediaQueryChangeHandler function. // the mediaQueryChangeHandler function.
mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label)); mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label));
@ -91,8 +88,7 @@
model.trigger('change:activeTray', model, model.get('activeTray')); model.trigger('change:activeTray', model, model.get('activeTray'));
// Render collapsible menus. // Render collapsible menus.
const menuModel = new Drupal.toolbar.MenuModel(); const menuModel = Drupal.toolbar.models.menuModel = new Drupal.toolbar.MenuModel();
Drupal.toolbar.models.menuModel = menuModel;
Drupal.toolbar.views.menuVisualView = new Drupal.toolbar.MenuVisualView({ Drupal.toolbar.views.menuVisualView = new Drupal.toolbar.MenuVisualView({
el: $(this).find('.toolbar-menu-administration').get(0), el: $(this).find('.toolbar-menu-administration').get(0),
model: menuModel, model: menuModel,

View File

@ -26,19 +26,16 @@
} }
$(context).find('#toolbar-administration').once('toolbar').each(function () { $(context).find('#toolbar-administration').once('toolbar').each(function () {
var model = new Drupal.toolbar.ToolbarModel({ var model = Drupal.toolbar.models.toolbarModel = new Drupal.toolbar.ToolbarModel({
locked: JSON.parse(localStorage.getItem('Drupal.toolbar.trayVerticalLocked')), locked: JSON.parse(localStorage.getItem('Drupal.toolbar.trayVerticalLocked')),
activeTab: document.getElementById(JSON.parse(localStorage.getItem('Drupal.toolbar.activeTabID'))), activeTab: document.getElementById(JSON.parse(localStorage.getItem('Drupal.toolbar.activeTabID'))),
height: $('#toolbar-administration').outerHeight() height: $('#toolbar-administration').outerHeight()
}); });
Drupal.toolbar.models.toolbarModel = model;
for (var label in options.breakpoints) { for (var label in options.breakpoints) {
if (options.breakpoints.hasOwnProperty(label)) { if (options.breakpoints.hasOwnProperty(label)) {
var mq = options.breakpoints[label]; var mq = options.breakpoints[label];
var mql = window.matchMedia(mq); var mql = Drupal.toolbar.mql[label] = window.matchMedia(mq);
Drupal.toolbar.mql[label] = mql;
mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label)); mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label));
@ -64,8 +61,7 @@
model.trigger('change:isFixed', model, model.get('isFixed')); model.trigger('change:isFixed', model, model.get('isFixed'));
model.trigger('change:activeTray', model, model.get('activeTray')); model.trigger('change:activeTray', model, model.get('activeTray'));
var menuModel = new Drupal.toolbar.MenuModel(); var menuModel = Drupal.toolbar.models.menuModel = new Drupal.toolbar.MenuModel();
Drupal.toolbar.models.menuModel = menuModel;
Drupal.toolbar.views.menuVisualView = new Drupal.toolbar.MenuVisualView({ Drupal.toolbar.views.menuVisualView = new Drupal.toolbar.MenuVisualView({
el: $(this).find('.toolbar-menu-administration').get(0), el: $(this).find('.toolbar-menu-administration').get(0),
model: menuModel, model: menuModel,