menu_ui.admin.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, Drupal) {
  8. Drupal.behaviors.menuUiChangeParentItems = {
  9. attach: function attach(context, settings) {
  10. var $menu = $('#edit-menu').once('menu-parent');
  11. if ($menu.length) {
  12. Drupal.menuUiUpdateParentList();
  13. $menu.on('change', 'input', Drupal.menuUiUpdateParentList);
  14. }
  15. }
  16. };
  17. Drupal.menuUiUpdateParentList = function () {
  18. var $menu = $('#edit-menu');
  19. var values = [];
  20. $menu.find('input:checked').each(function () {
  21. values.push(Drupal.checkPlain($.trim($(this).val())));
  22. });
  23. $.ajax({
  24. url: window.location.protocol + '//' + window.location.host + Drupal.url('admin/structure/menu/parents'),
  25. type: 'POST',
  26. data: { 'menus[]': values },
  27. dataType: 'json',
  28. success: function success(options) {
  29. var $select = $('#edit-menu-parent');
  30. var selected = $select.val();
  31. $select.children().remove();
  32. var totalOptions = 0;
  33. Object.keys(options || {}).forEach(function (machineName) {
  34. $select.append($('<option ' + (machineName === selected ? ' selected="selected"' : '') + '></option>').val(machineName).text(options[machineName]));
  35. totalOptions++;
  36. });
  37. $select.closest('div').toggle(totalOptions > 0).attr('hidden', totalOptions === 0);
  38. }
  39. });
  40. };
  41. })(jQuery, Drupal);