Commit ce86e09d authored by webchick's avatar webchick

Issue #2915784 by dawehner, drpal, mikejw, justafish, tedbow, xjm, webchick:...

Issue #2915784 by dawehner, drpal, mikejw, justafish, tedbow, xjm, webchick: 1/3 JS codestyle: camelcase
parent 148db4be
......@@ -86,11 +86,11 @@
}
}
Object.keys(settings.machineName).forEach((source_id) => {
Object.keys(settings.machineName).forEach((sourceId) => {
let machine = '';
const options = settings.machineName[source_id];
const options = settings.machineName[sourceId];
const $source = $context.find(source_id).addClass('machine-name-source').once('machine-name');
const $source = $context.find(sourceId).addClass('machine-name-source').once('machine-name');
const $target = $context.find(options.target).addClass('machine-name-target');
const $suffix = $context.find(options.suffix);
const $wrapper = $target.closest('.js-form-item');
......
......@@ -49,11 +49,11 @@
}
}
Object.keys(settings.machineName).forEach(function (source_id) {
Object.keys(settings.machineName).forEach(function (sourceId) {
var machine = '';
var options = settings.machineName[source_id];
var options = settings.machineName[sourceId];
var $source = $context.find(source_id).addClass('machine-name-source').once('machine-name');
var $source = $context.find(sourceId).addClass('machine-name-source').once('machine-name');
var $target = $context.find(options.target).addClass('machine-name-target');
var $suffix = $context.find(options.suffix);
var $wrapper = $target.closest('.js-form-item');
......
......@@ -61,7 +61,7 @@
$(context).find('[data-vertical-tabs-panes]').once('vertical-tabs').each(function () {
const $this = $(this).addClass('vertical-tabs__panes');
const focusID = $this.find(':hidden.vertical-tabs__active-tab').val();
let tab_focus;
let tabFocus;
// Check if there are some details that can be converted to
// vertical-tabs.
......@@ -71,45 +71,45 @@
}
// Create the tab column.
const tab_list = $('<ul class="vertical-tabs__menu"></ul>');
$this.wrap('<div class="vertical-tabs clearfix"></div>').before(tab_list);
const tabList = $('<ul class="vertical-tabs__menu"></ul>');
$this.wrap('<div class="vertical-tabs clearfix"></div>').before(tabList);
// Transform each details into a tab.
$details.each(function () {
const $that = $(this);
const vertical_tab = new Drupal.verticalTab({
const verticalTab = new Drupal.verticalTab({
title: $that.find('> summary').text(),
details: $that,
});
tab_list.append(vertical_tab.item);
tabList.append(verticalTab.item);
$that
.removeClass('collapsed')
// prop() can't be used on browsers not supporting details element,
// the style won't apply to them if prop() is used.
.attr('open', true)
.addClass('vertical-tabs__pane')
.data('verticalTab', vertical_tab);
.data('verticalTab', verticalTab);
if (this.id === focusID) {
tab_focus = $that;
tabFocus = $that;
}
});
$(tab_list).find('> li').eq(0).addClass('first');
$(tab_list).find('> li').eq(-1).addClass('last');
$(tabList).find('> li').eq(0).addClass('first');
$(tabList).find('> li').eq(-1).addClass('last');
if (!tab_focus) {
if (!tabFocus) {
// If the current URL has a fragment and one of the tabs contains an
// element that matches the URL fragment, activate that tab.
const $locationHash = $this.find(window.location.hash);
if (window.location.hash && $locationHash.length) {
tab_focus = $locationHash.closest('.vertical-tabs__pane');
tabFocus = $locationHash.closest('.vertical-tabs__pane');
}
else {
tab_focus = $this.find('> .vertical-tabs__pane').eq(0);
tabFocus = $this.find('> .vertical-tabs__pane').eq(0);
}
}
if (tab_focus.length) {
tab_focus.data('verticalTab').focus();
if (tabFocus.length) {
tabFocus.data('verticalTab').focus();
}
});
},
......
......@@ -26,42 +26,42 @@
$(context).find('[data-vertical-tabs-panes]').once('vertical-tabs').each(function () {
var $this = $(this).addClass('vertical-tabs__panes');
var focusID = $this.find(':hidden.vertical-tabs__active-tab').val();
var tab_focus = void 0;
var tabFocus = void 0;
var $details = $this.find('> details');
if ($details.length === 0) {
return;
}
var tab_list = $('<ul class="vertical-tabs__menu"></ul>');
$this.wrap('<div class="vertical-tabs clearfix"></div>').before(tab_list);
var tabList = $('<ul class="vertical-tabs__menu"></ul>');
$this.wrap('<div class="vertical-tabs clearfix"></div>').before(tabList);
$details.each(function () {
var $that = $(this);
var vertical_tab = new Drupal.verticalTab({
var verticalTab = new Drupal.verticalTab({
title: $that.find('> summary').text(),
details: $that
});
tab_list.append(vertical_tab.item);
$that.removeClass('collapsed').attr('open', true).addClass('vertical-tabs__pane').data('verticalTab', vertical_tab);
tabList.append(verticalTab.item);
$that.removeClass('collapsed').attr('open', true).addClass('vertical-tabs__pane').data('verticalTab', verticalTab);
if (this.id === focusID) {
tab_focus = $that;
tabFocus = $that;
}
});
$(tab_list).find('> li').eq(0).addClass('first');
$(tab_list).find('> li').eq(-1).addClass('last');
$(tabList).find('> li').eq(0).addClass('first');
$(tabList).find('> li').eq(-1).addClass('last');
if (!tab_focus) {
if (!tabFocus) {
var $locationHash = $this.find(window.location.hash);
if (window.location.hash && $locationHash.length) {
tab_focus = $locationHash.closest('.vertical-tabs__pane');
tabFocus = $locationHash.closest('.vertical-tabs__pane');
} else {
tab_focus = $this.find('> .vertical-tabs__pane').eq(0);
tabFocus = $this.find('> .vertical-tabs__pane').eq(0);
}
}
if (tab_focus.length) {
tab_focus.data('verticalTab').focus();
if (tabFocus.length) {
tabFocus.data('verticalTab').focus();
}
});
}
......
......@@ -24,7 +24,7 @@
attach(context, settings) {
const $input = $('input.block-filter-text').once('block-filter-text');
const $table = $($input.attr('data-element'));
let $filter_rows;
let $filterRows;
/**
* Filters the block list.
......@@ -52,7 +52,7 @@
// Filter if the length of the query is at least 2 characters.
if (query.length >= 2) {
$filter_rows.each(toggleBlockEntry);
$filterRows.each(toggleBlockEntry);
Drupal.announce(
Drupal.formatPlural(
$table.find('tr:visible').length - 1,
......@@ -62,14 +62,14 @@
);
}
else {
$filter_rows.each(function (index) {
$filterRows.each(function (index) {
$(this).parent().parent().show();
});
}
}
if ($table.length) {
$filter_rows = $table.find('div.block-filter-text-source');
$filterRows = $table.find('div.block-filter-text-source');
$input.on('keyup', debounce(filterBlockList, 200));
}
},
......
......@@ -10,7 +10,7 @@
attach: function attach(context, settings) {
var $input = $('input.block-filter-text').once('block-filter-text');
var $table = $($input.attr('data-element'));
var $filter_rows = void 0;
var $filterRows = void 0;
function filterBlockList(e) {
var query = $(e.target).val().toLowerCase();
......@@ -23,17 +23,17 @@
}
if (query.length >= 2) {
$filter_rows.each(toggleBlockEntry);
$filterRows.each(toggleBlockEntry);
Drupal.announce(Drupal.formatPlural($table.find('tr:visible').length - 1, '1 block is available in the modified list.', '@count blocks are available in the modified list.'));
} else {
$filter_rows.each(function (index) {
$filterRows.each(function (index) {
$(this).parent().parent().show();
});
}
}
if ($table.length) {
$filter_rows = $table.find('div.block-filter-text-source');
$filterRows = $table.find('div.block-filter-text-source');
$input.on('keyup', debounce(filterBlockList, 200));
}
}
......
......@@ -195,14 +195,14 @@
// Find the correct region and insert the row as the last in the
// region.
tableDrag.rowObject = new tableDrag.row(row[0]);
const region_message = table.find(`.region-${select[0].value}-message`);
const region_items = region_message.nextUntil('.region-message, .region-title');
if (region_items.length) {
region_items.last().after(row);
const regionMessage = table.find(`.region-${select[0].value}-message`);
const regionItems = regionMessage.nextUntil('.region-message, .region-title');
if (regionItems.length) {
regionItems.last().after(row);
}
// We found that region_message is the last row.
// We found that regionMessage is the last row.
else {
region_message.after(row);
regionMessage.after(row);
}
updateBlockWeights(table, select[0].value);
// Modify empty regions with added or removed fields.
......
......@@ -119,12 +119,12 @@
var select = $(this);
tableDrag.rowObject = new tableDrag.row(row[0]);
var region_message = table.find('.region-' + select[0].value + '-message');
var region_items = region_message.nextUntil('.region-message, .region-title');
if (region_items.length) {
region_items.last().after(row);
var regionMessage = table.find('.region-' + select[0].value + '-message');
var regionItems = regionMessage.nextUntil('.region-message, .region-title');
if (regionItems.length) {
regionItems.last().after(row);
} else {
region_message.after(row);
regionMessage.after(row);
}
updateBlockWeights(table, select[0].value);
......
......@@ -17,11 +17,11 @@
const $context = $(context);
const options = drupalSettings.contentTranslationDependentOptions;
let $fields;
let dependent_columns;
let dependentColumns;
function fieldsChangeHandler($fields, dependent_columns) {
function fieldsChangeHandler($fields, dependentColumns) {
return function (e) {
Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependent_columns, $(e.target));
Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependentColumns, $(e.target));
};
}
......@@ -32,15 +32,15 @@
for (const field in options.dependent_selectors) {
if (options.dependent_selectors.hasOwnProperty(field)) {
$fields = $context.find(`input[name^="${field}"]`);
dependent_columns = options.dependent_selectors[field];
dependentColumns = options.dependent_selectors[field];
$fields.on('change', fieldsChangeHandler($fields, dependent_columns));
Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependent_columns);
$fields.on('change', fieldsChangeHandler($fields, dependentColumns));
Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependentColumns);
}
}
}
},
check($fields, dependent_columns, $changed) {
check($fields, dependentColumns, $changed) {
let $element = $changed;
let column;
......@@ -50,9 +50,9 @@
// A field that has many different translatable parts can also define one
// or more columns that require all columns to be translatable.
for (const index in dependent_columns) {
if (dependent_columns.hasOwnProperty(index)) {
column = dependent_columns[index];
for (const index in dependentColumns) {
if (dependentColumns.hasOwnProperty(index)) {
column = dependentColumns[index];
if (!$changed) {
$element = $fields.filter(filterFieldsList);
......
......@@ -11,11 +11,11 @@
var $context = $(context);
var options = drupalSettings.contentTranslationDependentOptions;
var $fields = void 0;
var dependent_columns = void 0;
var dependentColumns = void 0;
function fieldsChangeHandler($fields, dependent_columns) {
function fieldsChangeHandler($fields, dependentColumns) {
return function (e) {
Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependent_columns, $(e.target));
Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependentColumns, $(e.target));
};
}
......@@ -23,15 +23,15 @@
for (var field in options.dependent_selectors) {
if (options.dependent_selectors.hasOwnProperty(field)) {
$fields = $context.find('input[name^="' + field + '"]');
dependent_columns = options.dependent_selectors[field];
dependentColumns = options.dependent_selectors[field];
$fields.on('change', fieldsChangeHandler($fields, dependent_columns));
Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependent_columns);
$fields.on('change', fieldsChangeHandler($fields, dependentColumns));
Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependentColumns);
}
}
}
},
check: function check($fields, dependent_columns, $changed) {
check: function check($fields, dependentColumns, $changed) {
var $element = $changed;
var column = void 0;
......@@ -39,9 +39,9 @@
return $(field).val() === column;
}
for (var index in dependent_columns) {
if (dependent_columns.hasOwnProperty(index)) {
column = dependent_columns[index];
for (var index in dependentColumns) {
if (dependentColumns.hasOwnProperty(index)) {
column = dependentColumns[index];
if (!$changed) {
$element = $fields.filter(filterFieldsList);
......
......@@ -14,10 +14,10 @@
* The text area DOM element, if it was found.
*/
function findFieldForFormatSelector($formatSelector) {
const field_id = $formatSelector.attr('data-editor-for');
const fieldId = $formatSelector.attr('data-editor-for');
// This selector will only find text areas in the top-level document. We do
// not support attaching editors on text areas within iframes.
return $(`#${field_id}`).get(0);
return $(`#${fieldId}`).get(0);
}
/**
......
......@@ -7,9 +7,9 @@
(function ($, Drupal, drupalSettings) {
function findFieldForFormatSelector($formatSelector) {
var field_id = $formatSelector.attr('data-editor-for');
var fieldId = $formatSelector.attr('data-editor-for');
return $('#' + field_id).get(0);
return $('#' + fieldId).get(0);
}
function changeTextEditor(field, newFormatID) {
......
......@@ -43,41 +43,41 @@
// in the form, but play nicely with user permissions and form
// alterations.
const $checkbox = $this.find('.js-form-item-menu-enabled input');
const $link_title = $context.find('.js-form-item-menu-title input');
const $linkTitle = $context.find('.js-form-item-menu-title input');
const $title = $this.closest('form').find('.js-form-item-title-0-value input');
// Bail out if we do not have all required fields.
if (!($checkbox.length && $link_title.length && $title.length)) {
if (!($checkbox.length && $linkTitle.length && $title.length)) {
return;
}
// If there is a link title already, mark it as overridden. The user
// expects that toggling the checkbox twice will take over the node's
// title.
if ($checkbox.is(':checked') && $link_title.val().length) {
$link_title.data('menuLinkAutomaticTitleOverridden', true);
if ($checkbox.is(':checked') && $linkTitle.val().length) {
$linkTitle.data('menuLinkAutomaticTitleOverridden', true);
}
// Whenever the value is changed manually, disable this behavior.
$link_title.on('keyup', () => {
$link_title.data('menuLinkAutomaticTitleOverridden', true);
$linkTitle.on('keyup', () => {
$linkTitle.data('menuLinkAutomaticTitleOverridden', true);
});
// Global trigger on checkbox (do not fill-in a value when disabled).
$checkbox.on('change', () => {
if ($checkbox.is(':checked')) {
if (!$link_title.data('menuLinkAutomaticTitleOverridden')) {
$link_title.val($title.val());
if (!$linkTitle.data('menuLinkAutomaticTitleOverridden')) {
$linkTitle.val($title.val());
}
}
else {
$link_title.val('');
$link_title.removeData('menuLinkAutomaticTitleOverridden');
$linkTitle.val('');
$linkTitle.removeData('menuLinkAutomaticTitleOverridden');
}
$checkbox.closest('.vertical-tabs-pane').trigger('summaryUpdated');
$checkbox.trigger('formUpdated');
});
// Take over any title change.
$title.on('keyup', () => {
if (!$link_title.data('menuLinkAutomaticTitleOverridden') && $checkbox.is(':checked')) {
$link_title.val($title.val());
$link_title.val($title.val()).trigger('formUpdated');
if (!$linkTitle.data('menuLinkAutomaticTitleOverridden') && $checkbox.is(':checked')) {
$linkTitle.val($title.val());
$linkTitle.val($title.val()).trigger('formUpdated');
}
});
});
......
......@@ -26,38 +26,38 @@
var $this = $(this);
var $checkbox = $this.find('.js-form-item-menu-enabled input');
var $link_title = $context.find('.js-form-item-menu-title input');
var $linkTitle = $context.find('.js-form-item-menu-title input');
var $title = $this.closest('form').find('.js-form-item-title-0-value input');
if (!($checkbox.length && $link_title.length && $title.length)) {
if (!($checkbox.length && $linkTitle.length && $title.length)) {
return;
}
if ($checkbox.is(':checked') && $link_title.val().length) {
$link_title.data('menuLinkAutomaticTitleOverridden', true);
if ($checkbox.is(':checked') && $linkTitle.val().length) {
$linkTitle.data('menuLinkAutomaticTitleOverridden', true);
}
$link_title.on('keyup', function () {
$link_title.data('menuLinkAutomaticTitleOverridden', true);
$linkTitle.on('keyup', function () {
$linkTitle.data('menuLinkAutomaticTitleOverridden', true);
});
$checkbox.on('change', function () {
if ($checkbox.is(':checked')) {
if (!$link_title.data('menuLinkAutomaticTitleOverridden')) {
$link_title.val($title.val());
if (!$linkTitle.data('menuLinkAutomaticTitleOverridden')) {
$linkTitle.val($title.val());
}
} else {
$link_title.val('');
$link_title.removeData('menuLinkAutomaticTitleOverridden');
$linkTitle.val('');
$linkTitle.removeData('menuLinkAutomaticTitleOverridden');
}
$checkbox.closest('.vertical-tabs-pane').trigger('summaryUpdated');
$checkbox.trigger('formUpdated');
});
$title.on('keyup', function () {
if (!$link_title.data('menuLinkAutomaticTitleOverridden') && $checkbox.is(':checked')) {
$link_title.val($title.val());
$link_title.val($title.val()).trigger('formUpdated');
if (!$linkTitle.data('menuLinkAutomaticTitleOverridden') && $checkbox.is(':checked')) {
$linkTitle.val($title.val());
$linkTitle.val($title.val()).trigger('formUpdated');
}
});
});
......
......@@ -35,10 +35,10 @@
$colorPreview.find('.color-preview-footer-wrapper').css('background-color', $colorPalette.find('input[name="palette[footer]"]').val());
// CSS3 Gradients.
const gradient_start = $colorPalette.find('input[name="palette[top]"]').val();
const gradient_end = $colorPalette.find('input[name="palette[bottom]"]').val();
const gradientStart = $colorPalette.find('input[name="palette[top]"]').val();
const gradientEnd = $colorPalette.find('input[name="palette[bottom]"]').val();
$colorPreview.find('.color-preview-header').attr('style', `background-color: ${gradient_start}; background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(${gradient_start}), to(${gradient_end})); background-image: -moz-linear-gradient(-90deg, ${gradient_start}, ${gradient_end});`);
$colorPreview.find('.color-preview-header').attr('style', `background-color: ${gradientStart}; background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(${gradientStart}), to(${gradientEnd})); background-image: -moz-linear-gradient(-90deg, ${gradientStart}, ${gradientEnd});`);
$colorPreview.find('.color-preview-site-name').css('color', $colorPalette.find('input[name="palette[titleslogan]"]').val());
},
......
......@@ -32,10 +32,10 @@
$colorPreview.find('.color-preview-footer-wrapper').css('background-color', $colorPalette.find('input[name="palette[footer]"]').val());
var gradient_start = $colorPalette.find('input[name="palette[top]"]').val();
var gradient_end = $colorPalette.find('input[name="palette[bottom]"]').val();
var gradientStart = $colorPalette.find('input[name="palette[top]"]').val();
var gradientEnd = $colorPalette.find('input[name="palette[bottom]"]').val();
$colorPreview.find('.color-preview-header').attr('style', 'background-color: ' + gradient_start + '; background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(' + gradient_start + '), to(' + gradient_end + ')); background-image: -moz-linear-gradient(-90deg, ' + gradient_start + ', ' + gradient_end + ');');
$colorPreview.find('.color-preview-header').attr('style', 'background-color: ' + gradientStart + '; background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(' + gradientStart + '), to(' + gradientEnd + ')); background-image: -moz-linear-gradient(-90deg, ' + gradientStart + ', ' + gradientEnd + ');');
$colorPreview.find('.color-preview-site-name').css('color', $colorPalette.find('input[name="palette[titleslogan]"]').val());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment