menu.admin.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. (function ($) {
  2. Drupal.behaviors.menuChangeParentItems = {
  3. attach: function (context, settings) {
  4. $('fieldset#edit-menu input').each(function () {
  5. $(this).change(function () {
  6. // Update list of available parent menu items.
  7. Drupal.menu_update_parent_list();
  8. });
  9. });
  10. }
  11. };
  12. /**
  13. * Function to set the options of the menu parent item dropdown.
  14. */
  15. Drupal.menu_update_parent_list = function () {
  16. var values = [];
  17. $('input:checked', $('fieldset#edit-menu')).each(function () {
  18. // Get the names of all checked menus.
  19. values.push(Drupal.checkPlain($.trim($(this).val())));
  20. });
  21. var url = Drupal.settings.basePath + 'admin/structure/menu/parents';
  22. $.ajax({
  23. url: location.protocol + '//' + location.host + url,
  24. type: 'POST',
  25. data: {'menus[]' : values},
  26. dataType: 'json',
  27. success: function (options) {
  28. // Save key of last selected element.
  29. var selected = $('fieldset#edit-menu #edit-menu-parent :selected').val();
  30. // Remove all exisiting options from dropdown.
  31. $('fieldset#edit-menu #edit-menu-parent').children().remove();
  32. // Add new options to dropdown.
  33. jQuery.each(options, function(index, value) {
  34. $('fieldset#edit-menu #edit-menu-parent').append(
  35. $('<option ' + (index == selected ? ' selected="selected"' : '') + '></option>').val(index).text(value)
  36. );
  37. });
  38. }
  39. });
  40. };
  41. })(jQuery);