2009-10-13 01:25:58 +00:00
|
|
|
(function ($) {
|
|
|
|
|
2012-01-29 21:13:55 +00:00
|
|
|
Drupal.behaviors.menuChangeParentItems = {
|
|
|
|
attach: function (context, settings) {
|
|
|
|
$('fieldset#edit-menu input').each(function () {
|
|
|
|
$(this).change(function () {
|
|
|
|
// Update list of available parent menu items.
|
|
|
|
Drupal.menu_update_parent_list();
|
2009-10-13 01:25:58 +00:00
|
|
|
});
|
2012-01-29 21:13:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2009-10-13 01:25:58 +00:00
|
|
|
|
2012-01-29 21:13:55 +00:00
|
|
|
/**
|
|
|
|
* Function to set the options of the menu parent item dropdown.
|
|
|
|
*/
|
|
|
|
Drupal.menu_update_parent_list = function () {
|
|
|
|
var values = [];
|
2009-10-13 01:25:58 +00:00
|
|
|
|
2012-04-07 07:19:30 +00:00
|
|
|
$('fieldset#edit-menu').find('input:checked').each(function () {
|
2012-01-29 21:13:55 +00:00
|
|
|
// Get the names of all checked menus.
|
|
|
|
values.push(Drupal.checkPlain($.trim($(this).val())));
|
|
|
|
});
|
2009-10-13 01:25:58 +00:00
|
|
|
|
2012-01-29 21:13:55 +00:00
|
|
|
$.ajax({
|
2012-04-29 15:16:27 +00:00
|
|
|
url: location.protocol + '//' + location.host + Drupal.url('admin/structure/menu/parents'),
|
2012-01-29 21:13:55 +00:00
|
|
|
type: 'POST',
|
|
|
|
data: {'menus[]' : values},
|
|
|
|
dataType: 'json',
|
|
|
|
success: function (options) {
|
|
|
|
// Save key of last selected element.
|
|
|
|
var selected = $('fieldset#edit-menu #edit-menu-parent :selected').val();
|
|
|
|
// Remove all exisiting options from dropdown.
|
|
|
|
$('fieldset#edit-menu #edit-menu-parent').children().remove();
|
|
|
|
// Add new options to dropdown.
|
|
|
|
jQuery.each(options, function(index, value) {
|
|
|
|
$('fieldset#edit-menu #edit-menu-parent').append(
|
|
|
|
$('<option ' + (index == selected ? ' selected="selected"' : '') + '></option>').val(index).text(value)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2009-10-13 01:25:58 +00:00
|
|
|
|
|
|
|
})(jQuery);
|