menu_ui.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.menuUiDetailsSummaries = {
  9. attach: function attach(context) {
  10. $(context).find('.menu-link-form').drupalSetSummary(function (context) {
  11. var $context = $(context);
  12. if ($context.find('.js-form-item-menu-enabled input').is(':checked')) {
  13. return Drupal.checkPlain($context.find('.js-form-item-menu-title input').val());
  14. }
  15. return Drupal.t('Not in menu');
  16. });
  17. }
  18. };
  19. Drupal.behaviors.menuUiLinkAutomaticTitle = {
  20. attach: function attach(context) {
  21. var $context = $(context);
  22. $context.find('.menu-link-form').each(function () {
  23. var $this = $(this);
  24. var $checkbox = $this.find('.js-form-item-menu-enabled input');
  25. var $linkTitle = $context.find('.js-form-item-menu-title input');
  26. var $title = $this.closest('form').find('.js-form-item-title-0-value input');
  27. if (!($checkbox.length && $linkTitle.length && $title.length)) {
  28. return;
  29. }
  30. if ($checkbox.is(':checked') && $linkTitle.val().length) {
  31. $linkTitle.data('menuLinkAutomaticTitleOverridden', true);
  32. }
  33. $linkTitle.on('keyup', function () {
  34. $linkTitle.data('menuLinkAutomaticTitleOverridden', true);
  35. });
  36. $checkbox.on('change', function () {
  37. if ($checkbox.is(':checked')) {
  38. if (!$linkTitle.data('menuLinkAutomaticTitleOverridden')) {
  39. $linkTitle.val($title.val());
  40. }
  41. } else {
  42. $linkTitle.val('');
  43. $linkTitle.removeData('menuLinkAutomaticTitleOverridden');
  44. }
  45. $checkbox.closest('.vertical-tabs-pane').trigger('summaryUpdated');
  46. $checkbox.trigger('formUpdated');
  47. });
  48. $title.on('keyup', function () {
  49. if (!$linkTitle.data('menuLinkAutomaticTitleOverridden') && $checkbox.is(':checked')) {
  50. $linkTitle.val($title.val());
  51. $linkTitle.val($title.val()).trigger('formUpdated');
  52. }
  53. });
  54. });
  55. }
  56. };
  57. })(jQuery, Drupal);