diff -u b/core/misc/ajax.js b/core/misc/ajax.js --- b/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -378,8 +378,10 @@ /** * Request parameter to indicate that a request is a Drupal Ajax request. + * + * @const */ - Drupal.ajax.AJAX_REQUEST_PARAMETER = '_drupal_ajax'; + Drupal.Ajax.AJAX_REQUEST_PARAMETER = '_drupal_ajax'; /** * Execute the ajax request. @@ -497,7 +499,7 @@ } // Inform Drupal that this is an AJAX request. - options.data[Drupal.ajax.AJAX_REQUEST_PARAMETER] = 1; + options.data[Drupal.Ajax.AJAX_REQUEST_PARAMETER] = 1; // Allow Drupal to return new JavaScript and CSS files to load without // returning the ones already loaded. diff -u b/core/modules/block/js/block.js b/core/modules/block/js/block.js --- b/core/modules/block/js/block.js +++ b/core/modules/block/js/block.js @@ -34,9 +34,9 @@ return vals.join(', '); } - $('[data-drupal-selector="visibility-node-type"], [data-drupal-selector="visibility-language"], [data-drupal-selector="visibility-user-role"]').drupalSetSummary(checkboxesSummary); + $('[data-drupal-selector="edit-visibility-node-type"], [data-drupal-selector="edit-visibility-language"], [data-drupal-selector="edit-visibility-user-role"]').drupalSetSummary(checkboxesSummary); - $('[data-drupal-selector="visibility-request-path"]').drupalSetSummary(function (context) { + $('[data-drupal-selector="edit-visibility-request-path"]').drupalSetSummary(function (context) { var $pages = $(context).find('textarea[name="visibility[request_path][pages]"]'); if (!$pages.val()) { return Drupal.t('Not restricted'); @@ -63,7 +63,7 @@ return; } - var table = $('[data-drupal-selector="blocks"]'); + var table = $('#blocks'); // Get the blocks tableDrag object. var tableDrag = Drupal.tableDrag.blocks; // Add a handler for when a row is swapped, update empty regions. reverted: --- b/core/modules/block/src/BlockForm.php +++ a/core/modules/block/src/BlockForm.php @@ -233,7 +233,6 @@ if (isset($form['node_type'])) { $form['node_type']['#title'] = $this->t('Content types'); - $form['node_type']['#attributes']['data-drupal-selector'] = 'visibility-node-type'; $form['node_type']['bundles']['#title'] = $this->t('Content types'); $form['node_type']['negate']['#type'] = 'value'; $form['node_type']['negate']['#title_display'] = 'invisible'; @@ -241,14 +240,12 @@ } if (isset($form['user_role'])) { $form['user_role']['#title'] = $this->t('Roles'); - $form['user_role']['#attributes']['data-drupal-selector'] = 'visibility-user-role'; unset($form['user_role']['roles']['#description']); $form['user_role']['negate']['#type'] = 'value'; $form['user_role']['negate']['#value'] = $form['user_role']['negate']['#default_value']; } if (isset($form['request_path'])) { $form['request_path']['#title'] = $this->t('Pages'); - $form['request_path']['#attributes']['data-drupal-selector'] = 'visibility-request-path'; $form['request_path']['negate']['#type'] = 'radios'; $form['request_path']['negate']['#default_value'] = (int) $form['request_path']['negate']['#default_value']; $form['request_path']['negate']['#title_display'] = 'invisible'; @@ -258,7 +255,6 @@ ]; } if (isset($form['language'])) { - $form['language']['#attributes']['data-drupal-selector'] = 'visibility-language'; $form['language']['negate']['#type'] = 'value'; $form['language']['negate']['#value'] = $form['language']['negate']['#default_value']; } reverted: --- b/core/modules/block/src/BlockListBuilder.php +++ a/core/modules/block/src/BlockListBuilder.php @@ -177,7 +177,6 @@ ), '#attributes' => array( 'id' => 'blocks', - 'data-drupal-selector' => 'blocks', ), ); reverted: --- b/core/modules/ckeditor/js/ckeditor.admin.js +++ a/core/modules/ckeditor/js/ckeditor.admin.js @@ -343,7 +343,7 @@ Drupal.behaviors.ckeditorAdminButtonPluginSettings = { attach: function (context) { var $context = $(context); + var $ckeditorPluginSettings = $context.find('#ckeditor-plugin-settings').once('ckeditor-plugin-settings'); - var $ckeditorPluginSettings = $context.find('[data-drupal-selector="ckeditor-plugin-settings"]').once('ckeditor-plugin-settings'); if ($ckeditorPluginSettings.length) { // Hide all button-dependent plugin settings initially. $ckeditorPluginSettings.find('[data-ckeditor-buttons]').each(function () { diff -u b/core/modules/ckeditor/js/ckeditor.drupalimage.admin.js b/core/modules/ckeditor/js/ckeditor.drupalimage.admin.js --- b/core/modules/ckeditor/js/ckeditor.drupalimage.admin.js +++ b/core/modules/ckeditor/js/ckeditor.drupalimage.admin.js @@ -7,14 +7,14 @@ */ Drupal.behaviors.ckeditorDrupalImageSettingsSummary = { attach: function () { - $('[data-ckeditor-plugin-id="drupalimage"]').drupalSetSummary(function (context) { + $('#edit-editor-settings-plugins-drupalimage').drupalSetSummary(function (context) { var root = 'input[name="editor[settings][plugins][drupalimage][image_upload]'; var $status = $(root + '[status]"]'); var $maxFileSize = $(root + '[max_size]"]'); */ Drupal.behaviors.ckeditorDrupalImageSettingsSummary = { attach: function () { - $('#edit-editor-settings-plugins-drupalimage').drupalSetSummary(function (context) { + $('[data-ckeditor-plugin-id="drupalimage"]').drupalSetSummary(function (context) { var root = 'input[name="editor[settings][plugins][drupalimage][image_upload]'; var $status = $(root + '[status]"]'); var $maxFileSize = $(root + '[max_size]"]'); diff -u b/core/modules/ckeditor/js/ckeditor.stylescombo.admin.js b/core/modules/ckeditor/js/ckeditor.stylescombo.admin.js --- b/core/modules/ckeditor/js/ckeditor.stylescombo.admin.js +++ b/core/modules/ckeditor/js/ckeditor.stylescombo.admin.js @@ -26,14 +26,14 @@ var that = this; $context.find('[name="editor[settings][plugins][stylescombo][styles]"]') .on('blur.ckeditorStylesComboSettings', function () { - var styles = $.trim($(this).val()); + var styles = $.trim($('#edit-editor-settings-plugins-stylescombo-styles').val()); var stylesSet = that._generateStylesSetSetting(styles); if (!_.isEqual(previousStylesSet, stylesSet)) { previousStylesSet = stylesSet; var that = this; $context.find('[name="editor[settings][plugins][stylescombo][styles]"]') .on('blur.ckeditorStylesComboSettings', function () { - var styles = $.trim($('#edit-editor-settings-plugins-stylescombo-styles').val()); + var styles = $.trim($(this).val()); var stylesSet = that._generateStylesSetSetting(styles); if (!_.isEqual(previousStylesSet, stylesSet)) { previousStylesSet = stylesSet; @@ -96,8 +96,8 @@ */ Drupal.behaviors.ckeditorStylesComboSettingsSummary = { attach: function () { - $('[data-ckeditor-plugin-id="stylescombo"]').drupalSetSummary(function (context) { - var styles = $.trim($('[name="editor[settings][plugins][stylescombo][styles]"]').val()); + $('#edit-editor-settings-plugins-stylescombo').drupalSetSummary(function (context) { + var styles = $.trim($('#edit-editor-settings-plugins-stylescombo-styles').val()); if (styles.length === 0) { return Drupal.t('No styles configured'); } @@ -105,8 +105,8 @@ */ Drupal.behaviors.ckeditorStylesComboSettingsSummary = { attach: function () { - $('#edit-editor-settings-plugins-stylescombo').drupalSetSummary(function (context) { - var styles = $.trim($('#edit-editor-settings-plugins-stylescombo-styles').val()); + $('[data-ckeditor-plugin-id="stylescombo"]').drupalSetSummary(function (context) { + var styles = $.trim($('[data-drupal-selector="edit-editor-settings-plugins-stylescombo-styles"]').val()); if (styles.length === 0) { return Drupal.t('No styles configured'); } reverted: --- b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php +++ a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php @@ -165,7 +165,6 @@ '#title' => t('CKEditor plugin settings'), '#attributes' => array( 'id' => 'ckeditor-plugin-settings', - 'data-drupal-selector' => 'ckeditor-plugin-settings', ), ); $this->ckeditorPluginManager->injectPluginSettingsForm($form, $form_state, $editor); diff -u b/core/modules/field_ui/field_ui.js b/core/modules/field_ui/field_ui.js --- b/core/modules/field_ui/field_ui.js +++ b/core/modules/field_ui/field_ui.js @@ -61,7 +61,7 @@ */ Drupal.behaviors.fieldUIDisplayOverview = { attach: function (context, settings) { - $(context).find('[data-drupal-selector="field-display-overview"]').once('field-display-overview').each(function () { + $(context).find('table#field-display-overview').once('field-display-overview').each(function () { Drupal.fieldUIOverview.attach(this, settings.fieldUIRowsData, Drupal.fieldUIDisplayOverview); }); } @@ -214,7 +214,7 @@ // Fire the Ajax update. $('input[name=refresh_rows]').val(rowNames.join(' ')); - $('input[data-drupal-selector="field-ui-refresh"]').trigger('mousedown'); + $('input[data-drupal-selector="edit-refresh"]').trigger('mousedown'); // Disabled elements do not appear in POST ajax data, so we mark the // elements disabled only after firing the request. reverted: --- b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php +++ a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php @@ -167,7 +167,6 @@ '#attributes' => array( 'class' => array('field-ui-overview'), 'id' => 'field-display-overview', - 'data-drupal-selector' => 'field-display-overview', ), // Add Ajax wrapper. '#prefix' => '
', @@ -248,10 +247,7 @@ // spinners will be added manually by the client-side script. 'progress' => 'none', ), + '#attributes' => array('class' => array('visually-hidden')) - '#attributes' => array( - 'class' => array('visually-hidden'), - 'data-drupal-selector' => 'field-ui-refresh', - ) ); $form['actions'] = array('#type' => 'actions'); reverted: --- b/core/modules/field_ui/src/Form/FieldStorageAddForm.php +++ a/core/modules/field_ui/src/Form/FieldStorageAddForm.php @@ -125,8 +125,6 @@ } } - $form['#attributes']['data-drupal-selector'] = 'field-ui-field-storage-add-form'; - $form['add'] = array( '#type' => 'container', '#attributes' => array('class' => array('form--inline', 'clearfix')), reverted: --- b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -412,10 +412,7 @@ '#type' => 'submit', '#value' => $this->t('Grouped filters'), '#submit' => array(array($this, 'buildGroupForm')), + '#attributes' => array('class' => array('use-ajax-submit')), - '#attributes' => array( - 'class' => array('use-ajax-submit'), - 'data-drupal-selector' => 'options-group-button-button', - ), ); $form['group_button']['radios']['radios']['#default_value'] = 0; } @@ -425,10 +422,7 @@ '#type' => 'submit', '#value' => $this->t('Single filter'), '#submit' => array(array($this, 'buildGroupForm')), + '#attributes' => array('class' => array('use-ajax-submit')), - '#attributes' => array( - 'class' => array('use-ajax-submit'), - 'data-drupal-selector' => 'options-group-button-button', - ), ); $form['group_button']['radios']['radios']['#default_value'] = 1; } @@ -493,10 +487,7 @@ '#type' => 'submit', '#value' => $this->t('Expose filter'), '#submit' => array(array($this, 'displayExposedForm')), + '#attributes' => array('class' => array('use-ajax-submit')), - '#attributes' => array( - 'class' => array('use-ajax-submit'), - 'data-drupal-selector' => 'options-expose-button-button', - ), ); $form['expose_button']['checkbox']['checkbox']['#default_value'] = 0; } @@ -509,10 +500,7 @@ '#type' => 'submit', '#value' => $this->t('Hide filter'), '#submit' => array(array($this, 'displayExposedForm')), + '#attributes' => array('class' => array('use-ajax-submit')), - '#attributes' => array( - 'class' => array('use-ajax-submit'), - 'data-drupal-selector' => 'options-expose-button-button', - ), ); $form['expose_button']['checkbox']['checkbox']['#default_value'] = 1; } reverted: --- b/core/modules/views/src/Plugin/views/sort/SortPluginBase.php +++ a/core/modules/views/src/Plugin/views/sort/SortPluginBase.php @@ -124,10 +124,7 @@ '#type' => 'submit', '#value' => $this->t('Expose sort'), '#submit' => array(array($this, 'displayExposedForm')), + '#attributes' => array('class' => array('use-ajax-submit')), - '#attributes' => array( - 'class' => array('use-ajax-submit'), - 'data-drupal-selector' => 'options-expose-button-button', - ), ); $form['expose_button']['checkbox']['checkbox']['#default_value'] = 0; } @@ -140,10 +137,7 @@ '#type' => 'submit', '#value' => $this->t('Hide sort'), '#submit' => array(array($this, 'displayExposedForm')), + '#attributes' => array('class' => array('use-ajax-submit')), - '#attributes' => array( - 'class' => array('use-ajax-submit'), - 'data-drupal-selector' => 'options-expose-button-button', - ), ); $form['expose_button']['checkbox']['checkbox']['#default_value'] = 1; } diff -u b/core/modules/views_ui/js/views-admin.js b/core/modules/views_ui/js/views-admin.js --- b/core/modules/views_ui/js/views-admin.js +++ b/core/modules/views_ui/js/views-admin.js @@ -21,7 +21,7 @@ attach: function () { // Only show the SQL rewrite warning when the user has chosen the // corresponding checkbox. - $('[name="query[options][disable_sql_rewrite]"]').on('click', function () { + $('[data-drupal-selector="edit-query-options-disable-sql-rewrite"]').on('click', function () { $('.sql-rewrite-warning').toggleClass('js-hide'); }); } @@ -412,7 +412,7 @@ /** * Add a keyup handler to the search box. */ - this.$searchBox = this.$form.find('[name="override[controls][options_search]"]'); + this.$searchBox = this.$form.find('[data-drupal-selector="edit-override-controls-options-search"]'); this.$searchBox.on('keyup', $.proxy(this.handleKeyup, this)); /** @@ -950,25 +950,27 @@ */ Drupal.behaviors.viewsFilterConfigSelectAll = { attach: function (context) { - // Show the select all checkbox. - $(context).find('[data-drupal-selector="views-ui-handler-form"] div.form-item-options-value-all').once('filterConfigSelectAll') - .show() - .find('input[type=checkbox]') - .on('click', function () { - var checked = $(this).is(':checked'); + var $context = $(context); + + var $selectAll = $context.find('.form-item-options-value-all').once('filterConfigSelectAll'); + var $selectAllCheckbox = $selectAll.find('input[type=checkbox]'); + var $checkboxes = $selectAll.closest('.form-checkboxes').find('.js-form-type-checkbox:not(.form-item-options-value-all) input[type="checkbox"]'); + + if ($selectAll.length) { + // Show the select all checkbox. + $selectAll.show(); + $selectAllCheckbox.on('click', function () { // Update all checkbox beside the select all checkbox. - $(this).parents('.form-checkboxes').find('input[type=checkbox]').each(function () { - $(this).attr('checked', checked); - }); + $checkboxes.prop('checked', $(this).is(':checked')); }); - // Uncheck the select all checkbox if any of the others are unchecked. - $('[data-drupal-selector="views-ui-handler-form"]').find('div.js-form-type-checkbox').not($('.form-item-options-value-all')) - .find('input[type=checkbox]') - .on('click', function () { + + // Uncheck the select all checkbox if any of the others are unchecked. + $checkboxes.on('click', function () { if ($(this).is('checked') === false) { - $('#edit-options-value-all').prop('checked', false); + $selectAllCheckbox.prop('checked', false); } }); + } } }; @@ -990,7 +992,7 @@ */ Drupal.behaviors.viewsUiCheckboxify = { attach: function (context, settings) { - var $buttons = $('[data-drupal-selector="options-expose-button-button"], [data-drupal-selector="options-group-button-button"]').once('views-ui-checkboxify'); + var $buttons = $('[data-drupal-selector="edit-options-expose-button-button"], [data-drupal-selector="edit-options-group-button-button"]').once('views-ui-checkboxify'); var length = $buttons.length; var i; for (i = 0; i < length; i++) { @@ -1066,7 +1068,7 @@ */ Drupal.behaviors.viewsUiOverrideSelect = { attach: function (context) { - $(context).find('[name="override[dropdown]"]').once('views-ui-override-button-text').each(function () { + $(context).find('[data-drupal-selector="edit-override-dropdown"]').once('views-ui-override-button-text').each(function () { // Closures! :( var $context = $(context); var $submit = $context.find('[id^=edit-submit]'); reverted: --- b/core/modules/views_ui/src/Form/Ajax/AddHandler.php +++ a/core/modules/views_ui/src/Form/Ajax/AddHandler.php @@ -59,7 +59,6 @@ '#theme_wrappers' => array('container'), '#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE), ), - '#attributes' => array('data-drupal-selector' => 'views-ui-handler-form'), ); $executable = $view->getExecutable(); only in patch2: unchanged: --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -629,6 +629,8 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) { } if (!isset($form['#id'])) { $form['#id'] = Html::getUniqueId($form_id); + // Add a non-random identifier for use with JavaScript. + $form['#attributes']['data-drupal-selector'] = Html::getId($form_id); } $form += $this->elementInfo->getInfo('form'); @@ -746,7 +748,14 @@ public function doBuildForm($form_id, &$element, FormStateInterface &$form_state } if (!isset($element['#id'])) { - $element['#id'] = Html::getUniqueId('edit-' . implode('-', $element['#parents'])); + $unprocessed_id = 'edit-' . implode('-', $element['#parents']); + $element['#id'] = Html::getUniqueId($unprocessed_id); + // Add a non-random identifier for use with JavaScript. + $element['#attributes']['data-drupal-selector'] = HTML::getId($unprocessed_id); + } + else { + // Add a non-random identifier for use with JavaScript. + $element['#attributes']['data-drupal-selector'] = Html::getId($element['#id']); } // Add the aria-describedby attribute to associate the form control with its