Mercurial > hg > isophonics-drupal-site
view core/modules/menu_ui/menu_ui.admin.es6.js @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children | 1fec387a4317 |
line wrap: on
line source
/** * @file * Menu UI admin behaviors. */ (function ($, Drupal) { /** * * @type {Drupal~behavior} */ Drupal.behaviors.menuUiChangeParentItems = { attach(context, settings) { const $menu = $('#edit-menu').once('menu-parent'); if ($menu.length) { // Update the list of available parent menu items to match the initial // available menus. Drupal.menuUiUpdateParentList(); // Update list of available parent menu items. $menu.on('change', 'input', Drupal.menuUiUpdateParentList); } }, }; /** * Function to set the options of the menu parent item dropdown. */ Drupal.menuUiUpdateParentList = function () { const $menu = $('#edit-menu'); const values = []; $menu.find('input:checked').each(function () { // Get the names of all checked menus. values.push(Drupal.checkPlain($.trim($(this).val()))); }); $.ajax({ url: `${location.protocol}//${location.host}${Drupal.url('admin/structure/menu/parents')}`, type: 'POST', data: { 'menus[]': values }, dataType: 'json', success(options) { const $select = $('#edit-menu-parent'); // Save key of last selected element. const selected = $select.val(); // Remove all existing options from dropdown. $select.children().remove(); // Add new options to dropdown. Keep a count of options for testing later. let totalOptions = 0; for (const machineName in options) { if (options.hasOwnProperty(machineName)) { $select.append( $(`<option ${machineName === selected ? ' selected="selected"' : ''}></option>`).val(machineName).text(options[machineName]), ); totalOptions++; } } // Hide the parent options if there are no options for it. $select.closest('div').toggle(totalOptions > 0).attr('hidden', totalOptions === 0); }, }); }; }(jQuery, Drupal));