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