Commit 8d06691e authored by webchick's avatar webchick

Issue #2927230 by drpal, dawehner: 3/3 JS codestyle: camelcase

parent 01576f24
......@@ -8,7 +8,6 @@
"no-continue": "off",
"new-cap": "off",
"max-len": "off",
"default-case": "off",
"camelcase": "off"
"default-case": "off"
}
}
This diff is collapsed.
......@@ -10,14 +10,14 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
Drupal.behaviors.AJAX = {
attach: function attach(context, settings) {
function loadAjaxBehavior(base) {
var element_settings = settings.ajax[base];
if (typeof element_settings.selector === 'undefined') {
element_settings.selector = '#' + base;
var elementSettings = settings.ajax[base];
if (typeof elementSettings.selector === 'undefined') {
elementSettings.selector = '#' + base;
}
$(element_settings.selector).once('drupal-ajax').each(function () {
element_settings.element = this;
element_settings.base = base;
Drupal.ajax(element_settings);
$(elementSettings.selector).once('drupal-ajax').each(function () {
elementSettings.element = this;
elementSettings.base = base;
Drupal.ajax(elementSettings);
});
}
......@@ -30,19 +30,19 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
Drupal.ajax.bindAjaxLinks(document.body);
$('.use-ajax-submit').once('ajax').each(function () {
var element_settings = {};
var elementSettings = {};
element_settings.url = $(this.form).attr('action');
elementSettings.url = $(this.form).attr('action');
element_settings.setClick = true;
elementSettings.setClick = true;
element_settings.event = 'click';
elementSettings.event = 'click';
element_settings.progress = { type: 'throbber' };
element_settings.base = $(this).attr('id');
element_settings.element = this;
elementSettings.progress = { type: 'throbber' };
elementSettings.base = $(this).attr('id');
elementSettings.element = this;
Drupal.ajax(element_settings);
Drupal.ajax(elementSettings);
});
},
detach: function detach(context, settings, trigger) {
......@@ -143,7 +143,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
});
};
Drupal.Ajax = function (base, element, element_settings) {
Drupal.Ajax = function (base, element, elementSettings) {
var defaults = {
event: element ? 'mousedown' : null,
keypress: true,
......@@ -160,7 +160,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
}
};
$.extend(this, defaults, element_settings);
$.extend(this, defaults, elementSettings);
this.commands = new Drupal.AjaxCommands();
......@@ -172,7 +172,9 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
this.element = element;
this.element_settings = element_settings;
this.element_settings = elementSettings;
this.elementSettings = elementSettings;
if (this.element && this.element.form) {
this.$form = $(this.element.form);
......@@ -200,12 +202,12 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
ajax.options = {
url: ajax.url,
data: ajax.submit,
beforeSerialize: function beforeSerialize(element_settings, options) {
return ajax.beforeSerialize(element_settings, options);
beforeSerialize: function beforeSerialize(elementSettings, options) {
return ajax.beforeSerialize(elementSettings, options);
},
beforeSubmit: function beforeSubmit(form_values, element_settings, options) {
beforeSubmit: function beforeSubmit(formValues, elementSettings, options) {
ajax.ajaxing = true;
return ajax.beforeSubmit(form_values, element_settings, options);
return ajax.beforeSubmit(formValues, elementSettings, options);
},
beforeSend: function beforeSend(xmlhttprequest, options) {
ajax.ajaxing = true;
......@@ -236,8 +238,8 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
type: 'POST'
};
if (element_settings.dialog) {
ajax.options.data.dialogOptions = element_settings.dialog;
if (elementSettings.dialog) {
ajax.options.data.dialogOptions = elementSettings.dialog;
}
if (ajax.options.url.indexOf('?') === -1) {
......@@ -246,27 +248,27 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
ajax.options.url += '&';
}
var wrapper = 'drupal_' + (element_settings.dialogType || 'ajax');
if (element_settings.dialogRenderer) {
wrapper += '.' + element_settings.dialogRenderer;
var wrapper = 'drupal_' + (elementSettings.dialogType || 'ajax');
if (elementSettings.dialogRenderer) {
wrapper += '.' + elementSettings.dialogRenderer;
}
ajax.options.url += Drupal.ajax.WRAPPER_FORMAT + '=' + wrapper;
$(ajax.element).on(element_settings.event, function (event) {
$(ajax.element).on(elementSettings.event, function (event) {
if (!drupalSettings.ajaxTrustedUrl[ajax.url] && !Drupal.url.isLocal(ajax.url)) {
throw new Error(Drupal.t('The callback URL is not local and not trusted: !url', { '!url': ajax.url }));
}
return ajax.eventResponse(this, event);
});
if (element_settings.keypress) {
if (elementSettings.keypress) {
$(ajax.element).on('keypress', function (event) {
return ajax.keypressResponse(this, event);
});
}
if (element_settings.prevent) {
$(ajax.element).on(element_settings.prevent, false);
if (elementSettings.prevent) {
$(ajax.element).on(elementSettings.prevent, false);
}
};
......@@ -297,7 +299,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
if (event.which === 13 || event.which === 32 && element.type !== 'text' && element.type !== 'textarea' && element.type !== 'tel' && element.type !== 'number') {
event.preventDefault();
event.stopPropagation();
$(element).trigger(ajax.element_settings.event);
$(element).trigger(ajax.elementSettings.event);
}
};
......@@ -342,7 +344,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
options.data['ajax_page_state[libraries]'] = pageState.libraries;
};
Drupal.Ajax.prototype.beforeSubmit = function (form_values, element, options) {};
Drupal.Ajax.prototype.beforeSubmit = function (formValues, element, options) {};
Drupal.Ajax.prototype.beforeSend = function (xmlhttprequest, options) {
if (this.$form) {
......@@ -484,11 +486,11 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
var effect = ajax.getEffect(response);
var settings = void 0;
var $new_content_wrapped = $('<div></div>').html(response.data);
var $new_content = $new_content_wrapped.contents();
var $newContentWrapped = $('<div></div>').html(response.data);
var $newContent = $newContentWrapped.contents();
if ($new_content.length !== 1 || $new_content.get(0).nodeType !== 1) {
$new_content = $new_content_wrapped;
if ($newContent.length !== 1 || $newContent.get(0).nodeType !== 1) {
$newContent = $newContentWrapped;
}
switch (method) {
......@@ -501,23 +503,23 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
Drupal.detachBehaviors($wrapper.get(0), settings);
}
$wrapper[method]($new_content);
$wrapper[method]($newContent);
if (effect.showEffect !== 'show') {
$new_content.hide();
$newContent.hide();
}
if ($new_content.find('.ajax-new-content').length > 0) {
$new_content.find('.ajax-new-content').hide();
$new_content.show();
$new_content.find('.ajax-new-content')[effect.showEffect](effect.showSpeed);
if ($newContent.find('.ajax-new-content').length > 0) {
$newContent.find('.ajax-new-content').hide();
$newContent.show();
$newContent.find('.ajax-new-content')[effect.showEffect](effect.showSpeed);
} else if (effect.showEffect !== 'show') {
$new_content[effect.showEffect](effect.showSpeed);
$newContent[effect.showEffect](effect.showSpeed);
}
if ($new_content.parents('html').length > 0) {
if ($newContent.parents('html').length > 0) {
settings = response.settings || ajax.settings || drupalSettings;
Drupal.attachBehaviors($new_content.get(0), settings);
Drupal.attachBehaviors($newContent.get(0), settings);
}
},
remove: function remove(ajax, response, status) {
......
/**
* @file
* Testing behavior for JSWebAssertTest.
*/
(function ($, Drupal) {
/**
* Test Ajax command.
*
* @param {Drupal.Ajax} [ajax]
* {@link Drupal.Ajax} object created by {@link Drupal.Ajax}.
* @param {object} response
* The response from the Ajax request.
* @param {string} response.selector
* A jQuery selector string.
*/
Drupal.AjaxCommands.prototype.jsAjaxTestCommand = function (ajax, response) {
const $domElement = $(response.selector);
ajax.element_settings.cat = 'catbro';
const data = {
element_settings: ajax.element_settings.cat || {},
elementSettings: ajax.elementSettings.cat || {},
};
$domElement.html(`<div id="js_ajax_test_form_element">${JSON.stringify(data)}</div>`);
};
}(jQuery, Drupal));
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/
(function ($, Drupal) {
Drupal.AjaxCommands.prototype.jsAjaxTestCommand = function (ajax, response) {
var $domElement = $(response.selector);
ajax.element_settings.cat = 'catbro';
var data = {
element_settings: ajax.element_settings.cat || {},
elementSettings: ajax.elementSettings.cat || {}
};
$domElement.html('<div id="js_ajax_test_form_element">' + JSON.stringify(data) + '</div>');
};
})(jQuery, Drupal);
\ No newline at end of file
name: 'JS Ajax test'
description: 'Provides custom ajax commands used for tests'
type: module
package: Testing
version: VERSION
core: 8.x
ajax:
version: VERSION
js:
js/js_ajax_test.ajax.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupal.ajax
js_ajax_test.js_ajax_test:
path: '/js_ajax_test'
defaults:
_form: '\Drupal\js_ajax_test\Form\JsAjaxTestForm'
requirements:
_access: 'TRUE'
<?php
namespace Drupal\js_ajax_test\Ajax;
use Drupal\Core\Ajax\CommandInterface;
/**
* Test Ajax command.
*/
class JsAjaxTestCommand implements CommandInterface {
/**
* {@inheritdoc}
*/
public function render() {
return [
'command' => 'jsAjaxTestCommand',
'selector' => '#js_ajax_test_form_wrapper',
];
}
}
<?php
namespace Drupal\js_ajax_test\Form;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\js_ajax_test\Ajax\JsAjaxTestCommand;
/**
* Test form for js_ajax_test
*
* @internal
*/
class JsAjaxTestForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'js_ajax_test_form';
}
/**
* Form for testing the addition of various types of elements via Ajax.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#attached']['library'][] = 'js_ajax_test/ajax';
$form['custom']['#prefix'] = '<div id="js_ajax_test_form_wrapper">';
$form['custom']['#suffix'] = '</div>';
// Button to test for the waitForButton() assertion.
$form['test_button'] = [
'#type' => 'submit',
'#value' => $this->t('Add button'),
'#button_type' => 'primary',
'#ajax' => [
'callback' => [static::class, 'addButton'],
'progress' => [
'type' => 'throbber',
'message' => NULL,
],
'wrapper' => 'js_ajax_test_form_wrapper',
],
];
return $form;
}
/**
* Ajax callback for the "Add button" button.
*/
public static function addButton(array $form, FormStateInterface $form_state) {
return (new AjaxResponse())
->addCommand(new JsAjaxTestCommand());
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// An empty implementation, as we never submit the actual form.
}
}
......@@ -49,12 +49,12 @@
this.$view = $(selector);
// Retrieve the path to use for views' ajax.
let ajax_path = drupalSettings.views.ajax_path;
let ajaxPath = drupalSettings.views.ajax_path;
// If there are multiple views this might've ended up showing up multiple
// times.
if (ajax_path.constructor.toString().indexOf('Array') !== -1) {
ajax_path = ajax_path[0];
if (ajaxPath.constructor.toString().indexOf('Array') !== -1) {
ajaxPath = ajaxPath[0];
}
// Check if there are any GET parameters to send to views.
......@@ -63,14 +63,14 @@
// Remove the question mark and Drupal path component if any.
queryString = queryString.slice(1).replace(/q=[^&]+&?|&?render=[^&]+/, '');
if (queryString !== '') {
// If there is a '?' in ajax_path, clean url are on and & should be
// If there is a '?' in ajaxPath, clean url are on and & should be
// used to add parameters.
queryString = ((/\?/.test(ajax_path)) ? '&' : '?') + queryString;
queryString = ((/\?/.test(ajaxPath)) ? '&' : '?') + queryString;
}
}
this.element_settings = {
url: ajax_path + queryString,
url: ajaxPath + queryString,
submit: settings,
setClick: true,
event: 'click',
......@@ -97,12 +97,12 @@
// @code
// $('.view-name').trigger('RefreshView');
// @endcode
const self_settings = $.extend({}, this.element_settings, {
const selfSettings = $.extend({}, this.element_settings, {
event: 'RefreshView',
base: this.selector,
element: this.$view.get(0),
});
this.refreshViewAjax = Drupal.ajax(self_settings);
this.refreshViewAjax = Drupal.ajax(selfSettings);
};
/**
......@@ -114,11 +114,11 @@
// Exclude the reset buttons so no AJAX behaviours are bound. Many things
// break during the form reset phase if using AJAX.
$('input[type=submit], input[type=image]', this.$exposed_form).not('[data-drupal-selector=edit-reset]').each(function (index) {
const self_settings = $.extend({}, that.element_settings, {
const selfSettings = $.extend({}, that.element_settings, {
base: $(this).attr('id'),
element: this,
});
that.exposedFormAjax[index] = Drupal.ajax(self_settings);
that.exposedFormAjax[index] = Drupal.ajax(selfSettings);
});
};
......@@ -162,12 +162,12 @@
Drupal.Views.parseViewArgs(href, this.settings.view_base_path),
);
const self_settings = $.extend({}, this.element_settings, {
const selfSettings = $.extend({}, this.element_settings, {
submit: viewData,
base: false,
element: link,
});
this.pagerAjax = Drupal.ajax(self_settings);
this.pagerAjax = Drupal.ajax(selfSettings);
};
/**
......
......@@ -26,22 +26,22 @@
var selector = '.js-view-dom-id-' + settings.view_dom_id;
this.$view = $(selector);
var ajax_path = drupalSettings.views.ajax_path;
var ajaxPath = drupalSettings.views.ajax_path;
if (ajax_path.constructor.toString().indexOf('Array') !== -1) {
ajax_path = ajax_path[0];
if (ajaxPath.constructor.toString().indexOf('Array') !== -1) {
ajaxPath = ajaxPath[0];
}
var queryString = window.location.search || '';
if (queryString !== '') {
queryString = queryString.slice(1).replace(/q=[^&]+&?|&?render=[^&]+/, '');
if (queryString !== '') {
queryString = (/\?/.test(ajax_path) ? '&' : '?') + queryString;
queryString = (/\?/.test(ajaxPath) ? '&' : '?') + queryString;
}
}
this.element_settings = {
url: ajax_path + queryString,
url: ajaxPath + queryString,
submit: settings,
setClick: true,
event: 'click',
......@@ -56,12 +56,12 @@
this.$view.filter($.proxy(this.filterNestedViews, this)).once('ajax-pager').each($.proxy(this.attachPagerAjax, this));
var self_settings = $.extend({}, this.element_settings, {
var selfSettings = $.extend({}, this.element_settings, {
event: 'RefreshView',
base: this.selector,
element: this.$view.get(0)
});
this.refreshViewAjax = Drupal.ajax(self_settings);
this.refreshViewAjax = Drupal.ajax(selfSettings);
};
Drupal.views.ajaxView.prototype.attachExposedFormAjax = function () {
......@@ -69,11 +69,11 @@
this.exposedFormAjax = [];
$('input[type=submit], input[type=image]', this.$exposed_form).not('[data-drupal-selector=edit-reset]').each(function (index) {
var self_settings = $.extend({}, that.element_settings, {
var selfSettings = $.extend({}, that.element_settings, {
base: $(this).attr('id'),
element: this
});
that.exposedFormAjax[index] = Drupal.ajax(self_settings);
that.exposedFormAjax[index] = Drupal.ajax(selfSettings);
});
};
......@@ -92,12 +92,12 @@
$.extend(viewData, this.settings, Drupal.Views.parseQueryString(href), Drupal.Views.parseViewArgs(href, this.settings.view_base_path));
var self_settings = $.extend({}, this.element_settings, {
var selfSettings = $.extend({}, this.element_settings, {
submit: viewData,
base: false,
element: link
});
this.pagerAjax = Drupal.ajax(self_settings);
this.pagerAjax = Drupal.ajax(selfSettings);
};
Drupal.AjaxCommands.prototype.viewsScrollTop = function (ajax, response) {
......
......@@ -36,19 +36,19 @@
// Identify the button that was clicked so that .ajaxSubmit() can use it.
// We need to do this for both .click() and .mousedown() since JavaScript
// code might trigger either behavior.
const $submit_buttons = $form.find('input[type=submit].js-form-submit, button.js-form-submit').once('views-ajax-submit');
$submit_buttons.on('click mousedown', function () {
const $submitButtons = $form.find('input[type=submit].js-form-submit, button.js-form-submit').once('views-ajax-submit');
$submitButtons.on('click mousedown', function () {
this.form.clk = this;
});
$form.once('views-ajax-submit').each(function () {
const $form = $(this);
const element_settings = {
const elementSettings = {
url: response.url,
event: 'submit',
base: $form.attr('id'),
element: this,
};
const ajaxForm = Drupal.ajax(element_settings);
const ajaxForm = Drupal.ajax(elementSettings);
ajaxForm.$form = $form;
});
};
......@@ -159,9 +159,9 @@
$('#views-tabset a').once('views-ajax').on('click', function () {
const href = $(this).attr('href');
// Cut of #views-tabset.
const display_id = href.substr(11);
const displayId = href.substr(11);
// Set the form element.
$('#views-live-preview #preview-display-id').val(display_id);
$('#views-live-preview #preview-display-id').val(displayId);
});
},
};
......@@ -177,20 +177,20 @@
Drupal.behaviors.viewsAjax = {
collapseReplaced: false,
attach(context, settings) {
const base_element_settings = {
const baseElementSettings = {
event: 'click',
progress: { type: 'fullscreen' },
};
// Bind AJAX behaviors to all items showing the class.
$('a.views-ajax-link', context).once('views-ajax').each(function () {
const element_settings = base_element_settings;
element_settings.base = $(this).attr('id');
element_settings.element = this;
const elementSettings = baseElementSettings;
elementSettings.base = $(this).attr('id');
elementSettings.element = this;
// Set the URL to go to the anchor.
if ($(this).attr('href')) {
element_settings.url = $(this).attr('href');
elementSettings.url = $(this).attr('href');
}
Drupal.ajax(element_settings);
Drupal.ajax(elementSettings);
});
$('div#views-live-preview a')
......@@ -200,18 +200,18 @@
return true;
}
const element_settings = base_element_settings;
const elementSettings = baseElementSettings;
// Set the URL to go to the anchor.
element_settings.url = $(this).attr('href');
if (Drupal.Views.getPath(element_settings.url).substring(0, 21) !== 'admin/structure/views') {
elementSettings.url = $(this).attr('href');
if (Drupal.Views.getPath(elementSettings.url).substring(0, 21) !== 'admin/structure/views') {
return true;
}
element_settings.wrapper = 'views-preview-wrapper';
element_settings.method = 'replaceWith';
element_settings.base = $(this).attr('id');
element_settings.element = this;
Drupal.ajax(element_settings);
elementSettings.wrapper = 'views-preview-wrapper';
elementSettings.method = 'replaceWith';
elementSettings.base = $(this).attr('id');
elementSettings.element = this;
Drupal.ajax(elementSettings);
});
// Within a live preview, make exposed widget form buttons re-trigger the
......@@ -224,20 +224,20 @@
this.form.clk = this;
return true;
});
const element_settings = base_element_settings;
const elementSettings = baseElementSettings;
// Set the URL to go to the anchor.
element_settings.url = $(this.form).attr('action');
if (Drupal.Views.getPath(element_settings.url).substring(0, 21) !== 'admin/structure/views') {
elementSettings.url = $(this.form).attr('action');
if (Drupal.Views.getPath(elementSettings.url).substring(0, 21) !== 'admin/structure/views') {
return true;
}
element_settings.wrapper = 'views-preview-wrapper';
element_settings.method = 'replaceWith';
element_settings.event = 'click';
element_settings.base = $(this).attr('id');
element_settings.element = this;
elementSettings.wrapper = 'views-preview-wrapper';
elementSettings.method = 'replaceWith';
elementSettings.event = 'click';
elementSettings.base = $(this).attr('id');
elementSettings.element = this;
Drupal.ajax(element_settings);
Drupal.ajax(elementSettings);
});
},
};
......
......@@ -14,19 +14,19 @@
Drupal.AjaxCommands.prototype.viewsSetForm = function (ajax, response, status) {
var $form = $('.js-views-ui-dialog form');
var $submit_buttons = $form.find('input[type=submit].js-form-submit, button.js-form-submit').once('views-ajax-submit');
$submit_buttons.on('click mousedown', function () {
var $submitButtons = $form.find('input[type=submit].js-form-submit, button.js-form-submit').once('views-ajax-submit');
$submitButtons.on('click mousedown', function () {
this.form.clk = this;
});
$form.once('views-ajax-submit').each(function () {
var $form = $(this);
var element_settings = {
var elementSettings = {
url: response.url,
event: 'submit',
base: $form.attr('id'),
element: this
};
var ajaxForm = Drupal.ajax(element_settings);
var ajaxForm = Drupal.ajax(elementSettings);
ajaxForm.$form = $form;
});
};
......@@ -75,9 +75,9 @@
$('#views-tabset a').once('views-ajax').on('click', function () {
var href = $(this).attr('href');
var display_id = href.substr(11);
var displayId = href.substr(11);
$('#views-live-preview #preview-display-id').val(display_id);
$('#views-live-preview #preview-display-id').val(displayId);
});
}
};
......@@ -85,20 +85,20 @@
Drupal.behaviors.viewsAjax = {
collapseReplaced: false,
attach: function attach(context, settings) {
var base_element_settings = {
var baseElementSettings = {
event: 'click',
progress: { type: 'fullscreen' }
};
$('a.views-ajax-link', context).once('views-ajax').each(function () {
var element_settings = base_element_settings;
element_settings.base = $(this).attr('id');
element_settings.element = this;
var elementSettings = baseElementSettings;