3 Drupal
.behaviors
.menuChangeParentItems
= {
4 attach: function (context
, settings
) {
5 $('fieldset#edit-menu input').each(function () {
6 $(this).change(function () {
7 // Update list of available parent menu items.
8 Drupal
.menu_update_parent_list();
15 * Function to set the options of the menu parent item dropdown.
17 Drupal
.menu_update_parent_list = function () {
20 $('input:checked', $('fieldset#edit-menu')).each(function () {
21 // Get the names of all checked menus.
22 values
.push(Drupal
.checkPlain($.trim($(this).val())));
25 var url
= Drupal
.settings
.basePath
+ 'admin/structure/menu/parents';
27 url
: location
.protocol
+ '//' + location
.host
+ url
,
29 data
: {'menus[]' : values
},
31 success: function (options
) {
32 // Save key of last selected element.
33 var selected
= $('fieldset#edit-menu #edit-menu-parent :selected').val();
34 // Remove all exisiting options from dropdown.
35 $('fieldset#edit-menu #edit-menu-parent').children().remove();
36 // Add new options to dropdown.
37 jQuery
.each(options
, function(index
, value
) {
38 $('fieldset#edit-menu #edit-menu-parent').append(
39 $('<option ' + (index
== selected
? ' selected="selected"' : '') + '></option>').val(index
).text(value
)