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