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