Commit 59fee192 authored by alexpott's avatar alexpott
Browse files

Issue #2264241 by _nod: Fix ESLint errors and fix js bugs.

parent 0b522f36
......@@ -29,7 +29,6 @@
attach: function (context, settings) {
var self = this;
var $context = $(context);
var source_id, options, machine, eventData;
function clickEditHandler(e) {
var data = e.data;
......@@ -42,15 +41,15 @@
function machineNameHandler(e) {
var data = e.data;
var settings = data.options;
var options = data.options;
var baseValue = $(e.target).val();
var rx = new RegExp(settings.replace_pattern, 'g');
var expected = baseValue.toLowerCase().replace(rx, settings.replace).substr(0, settings.maxlength);
var rx = new RegExp(options.replace_pattern, 'g');
var expected = baseValue.toLowerCase().replace(rx, options.replace).substr(0, options.maxlength);
if (baseValue.toLowerCase() !== expected) {
self.transliterate(baseValue, settings).done(function (machine) {
self.showMachineName(machine.substr(0, settings.maxlength), data);
self.transliterate(baseValue, options).done(function (machine) {
self.showMachineName(machine.substr(0, options.maxlength), data);
});
}
else {
......@@ -58,70 +57,69 @@
}
}
for (source_id in settings.machineName) {
if (settings.machineName.hasOwnProperty(source_id)) {
options = settings.machineName[source_id];
Object.keys(settings.machineName).forEach(function (source_id) {
var machine, eventData;
var options = settings.machineName[source_id];
var $source = $context.find(source_id).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('.form-item');
// All elements have to exist.
if (!$source.length || !$target.length || !$suffix.length || !$wrapper.length) {
return;
}
// Skip processing upon a form validation error on the machine name.
if ($target.hasClass('error')) {
return;
}
// Figure out the maximum length for the machine name.
options.maxlength = $target.attr('maxlength');
// Hide the form item container of the machine name form element.
$wrapper.hide();
// Determine the initial machine name value. Unless the machine name form
// element is disabled or not empty, the initial default value is based on
// the human-readable form element value.
if ($target.is(':disabled') || $target.val() !== '') {
machine = $target.val();
}
else {
machine = self.transliterate($source.val(), options);
}
// Append the machine name preview to the source field.
var $preview = $('<span class="machine-name-value">' + options.field_prefix + Drupal.checkPlain(machine) + options.field_suffix + '</span>');
$suffix.empty();
if (options.label) {
$suffix.append(' ').append('<span class="machine-name-label">' + options.label + ':</span>');
}
$suffix.append(' ').append($preview);
var $source = $context.find(source_id).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('.form-item');
// All elements have to exist.
if (!$source.length || !$target.length || !$suffix.length || !$wrapper.length) {
return;
}
// Skip processing upon a form validation error on the machine name.
if ($target.hasClass('error')) {
return;
}
// Figure out the maximum length for the machine name.
options.maxlength = $target.attr('maxlength');
// Hide the form item container of the machine name form element.
$wrapper.hide();
// Determine the initial machine name value. Unless the machine name form
// element is disabled or not empty, the initial default value is based on
// the human-readable form element value.
if ($target.is(':disabled') || $target.val() !== '') {
machine = $target.val();
}
else {
machine = self.transliterate($source.val(), options);
}
// Append the machine name preview to the source field.
var $preview = $('<span class="machine-name-value">' + options.field_prefix + Drupal.checkPlain(machine) + options.field_suffix + '</span>');
$suffix.empty();
if (options.label) {
$suffix.append(' ').append('<span class="machine-name-label">' + options.label + ':</span>');
}
$suffix.append(' ').append($preview);
// If the machine name cannot be edited, stop further processing.
if ($target.is(':disabled')) {
return;
}
// If the machine name cannot be edited, stop further processing.
if ($target.is(':disabled')) {
return;
}
eventData = {
$source: $source,
$target: $target,
$suffix: $suffix,
$wrapper: $wrapper,
$preview: $preview,
options: options
};
// If it is editable, append an edit link.
var $link = $('<span class="admin-link"><button type="button" class="link">' + Drupal.t('Edit') + '</button></span>').on('click', eventData, clickEditHandler);
$suffix.append(' ').append($link);
eventData = {
$source: $source,
$target: $target,
$suffix: $suffix,
$wrapper: $wrapper,
$preview: $preview,
options: options
};
// If it is editable, append an edit link.
var $link = $('<span class="admin-link"><button type="button" class="link">' + Drupal.t('Edit') + '</button></span>').on('click', eventData, clickEditHandler);
$suffix.append(' ').append($link);
// Preview the machine name in realtime when the human-readable name
// changes, but only if there is no machine name yet; i.e., only upon
// initial creation, not when editing.
if ($target.val() === '') {
$source.on('keyup.machineName change.machineName input.machineName', eventData, machineNameHandler)
// Initialize machine name preview.
.trigger('keyup');
}
// Preview the machine name in realtime when the human-readable name
// changes, but only if there is no machine name yet; i.e., only upon
// initial creation, not when editing.
if ($target.val() === '') {
$source.on('keyup.machineName change.machineName input.machineName', eventData, machineNameHandler)
// Initialize machine name preview.
.trigger('keyup');
}
}
});
},
showMachineName: function (machine, data) {
......
......@@ -19,8 +19,8 @@
* Hides the <details> element for a category if it has no visible blocks.
*/
function hideCategoryDetails(index, element) {
var $details = $(element);
$details.toggle($details.find('li:visible').length > 0);
var $catDetails = $(element);
$catDetails.toggle($catDetails.find('li:visible').length > 0);
}
/**
......
......@@ -1178,7 +1178,6 @@
if ($group.hasClass('placeholder')) {
if (view.isProcessing) {
event.stopPropagation();
return;
}
view.isProcessing = true;
......
......@@ -71,7 +71,7 @@
'alt': 'alt',
'width': 'width',
'height': 'height',
'data-editor-file-uuid': 'data-editor-file-uuid',
'data-editor-file-uuid': 'data-editor-file-uuid'
};
// Protected; transforms widget's data object to the format used by the
......
......@@ -162,7 +162,7 @@
CKEDITOR.tools.extend(widgetDefinition._mapDataToDialog, {
'align': 'data-align',
'data-caption': 'data-caption',
'hasCaption': 'hasCaption',
'hasCaption': 'hasCaption'
});
// Override Drupal dialog save callback.
......
......@@ -31,7 +31,7 @@
// @see Drupal.contextualToolbar.VisualView.persist()
isViewing: localStorage.getItem('Drupal.contextualToolbar.isViewing') !== 'false'
}, {
contextualCollection: Drupal.contextual.collection,
contextualCollection: Drupal.contextual.collection
});
var viewOptions = {
......@@ -56,7 +56,7 @@
Drupal.contextualToolbar = {
// The Drupal.contextualToolbar.Model instance.
model: null,
model: null
};
})(jQuery, Drupal, Backbone);
......@@ -207,11 +207,9 @@
this.model.set('activeField', fieldModel);
accept = false;
}
else {
// Do not reject: the field is either in the 'candidate' or
// 'highlighted' state and we allow it to enter the 'activating'
// state!
}
// Do not reject: the field is either in the 'candidate' or
// 'highlighted' state and we allow it to enter the 'activating'
// state!
}
}
// Reject going from activating/active to candidate because of a
......
......@@ -19,9 +19,9 @@
var $rowsAndDetails, $rows, $details;
var searching = false;
function hidePackageDetails(index, element) {
var $details = $(element);
var $visibleRows = $details.find('table:not(.sticky-header)').find('tbody tr:visible');
$details.toggle($visibleRows.length > 0);
var $packDetails = $(element);
var $visibleRows = $packDetails.find('table:not(.sticky-header)').find('tbody tr:visible');
$packDetails.toggle($visibleRows.length > 0);
}
function filterModuleList(e) {
......
......@@ -524,7 +524,7 @@
/**
* Dynamically click the button that adds a new filter group.
*/
clickAddGroupButton: function () {
clickAddGroupButton: function (event) {
// Due to conflicts between Drupal core's AJAX system and the Views AJAX
// system, the only way to get this to work seems to be to trigger both the
// mousedown and submit events.
......
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