|
1 (function ($) { |
|
2 |
|
3 Drupal.behaviors.menuFieldsetSummaries = { |
|
4 attach: function (context) { |
|
5 $('fieldset.menu-link-form', context).drupalSetSummary(function (context) { |
|
6 if ($('.form-item-menu-enabled input', context).is(':checked')) { |
|
7 return Drupal.checkPlain($('.form-item-menu-link-title input', context).val()); |
|
8 } |
|
9 else { |
|
10 return Drupal.t('Not in menu'); |
|
11 } |
|
12 }); |
|
13 } |
|
14 }; |
|
15 |
|
16 /** |
|
17 * Automatically fill in a menu link title, if possible. |
|
18 */ |
|
19 Drupal.behaviors.menuLinkAutomaticTitle = { |
|
20 attach: function (context) { |
|
21 $('fieldset.menu-link-form', context).each(function () { |
|
22 // Try to find menu settings widget elements as well as a 'title' field in |
|
23 // the form, but play nicely with user permissions and form alterations. |
|
24 var $checkbox = $('.form-item-menu-enabled input', this); |
|
25 var $link_title = $('.form-item-menu-link-title input', context); |
|
26 var $title = $(this).closest('form').find('.form-item-title input'); |
|
27 // Bail out if we do not have all required fields. |
|
28 if (!($checkbox.length && $link_title.length && $title.length)) { |
|
29 return; |
|
30 } |
|
31 // If there is a link title already, mark it as overridden. The user expects |
|
32 // that toggling the checkbox twice will take over the node's title. |
|
33 if ($checkbox.is(':checked') && $link_title.val().length) { |
|
34 $link_title.data('menuLinkAutomaticTitleOveridden', true); |
|
35 } |
|
36 // Whenever the value is changed manually, disable this behavior. |
|
37 $link_title.keyup(function () { |
|
38 $link_title.data('menuLinkAutomaticTitleOveridden', true); |
|
39 }); |
|
40 // Global trigger on checkbox (do not fill-in a value when disabled). |
|
41 $checkbox.change(function () { |
|
42 if ($checkbox.is(':checked')) { |
|
43 if (!$link_title.data('menuLinkAutomaticTitleOveridden')) { |
|
44 $link_title.val($title.val()); |
|
45 } |
|
46 } |
|
47 else { |
|
48 $link_title.val(''); |
|
49 $link_title.removeData('menuLinkAutomaticTitleOveridden'); |
|
50 } |
|
51 $checkbox.closest('fieldset.vertical-tabs-pane').trigger('summaryUpdated'); |
|
52 $checkbox.trigger('formUpdated'); |
|
53 }); |
|
54 // Take over any title change. |
|
55 $title.keyup(function () { |
|
56 if (!$link_title.data('menuLinkAutomaticTitleOveridden') && $checkbox.is(':checked')) { |
|
57 $link_title.val($title.val()); |
|
58 $link_title.val($title.val()).trigger('formUpdated'); |
|
59 } |
|
60 }); |
|
61 }); |
|
62 } |
|
63 }; |
|
64 |
|
65 })(jQuery); |