2009-10-13 01:25:58 +00:00
|
|
|
(function ($) {
|
|
|
|
|
2012-05-08 02:57:33 +00:00
|
|
|
"use strict";
|
|
|
|
|
2012-01-29 21:13:55 +00:00
|
|
|
Drupal.behaviors.menuChangeParentItems = {
|
|
|
|
attach: function (context, settings) {
|
2012-08-31 20:26:21 +00:00
|
|
|
// Update list of available parent menu items.
|
|
|
|
$('#edit-menu').on('change', 'input', Drupal.menuUpdateParentList);
|
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.
|
|
|
|
*/
|
2012-08-31 20:26:21 +00:00
|
|
|
Drupal.menuUpdateParentList = function () {
|
2012-11-27 07:06:47 +00:00
|
|
|
var $menu = $('#edit-menu');
|
2012-01-29 21:13:55 +00:00
|
|
|
var values = [];
|
2009-10-13 01:25:58 +00:00
|
|
|
|
2012-11-27 07:06:47 +00:00
|
|
|
$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) {
|
2012-08-31 20:26:21 +00:00
|
|
|
var $select = $('#edit-menu-parent');
|
2012-01-29 21:13:55 +00:00
|
|
|
// Save key of last selected element.
|
2012-08-31 20:26:21 +00:00
|
|
|
var selected = $select.val();
|
2012-01-29 21:13:55 +00:00
|
|
|
// Remove all exisiting options from dropdown.
|
2012-08-31 20:26:21 +00:00
|
|
|
$select.children().remove();
|
2013-04-11 07:51:49 +00:00
|
|
|
// Add new options to dropdown. Keep a count of options for testing later.
|
|
|
|
var totalOptions = 0;
|
2012-08-31 20:26:21 +00:00
|
|
|
for (var machineName in options) {
|
|
|
|
if (options.hasOwnProperty(machineName)) {
|
|
|
|
$select.append(
|
|
|
|
$('<option ' + (machineName === selected ? ' selected="selected"' : '') + '></option>').val(machineName).text(options[machineName])
|
|
|
|
);
|
2013-04-11 07:51:49 +00:00
|
|
|
totalOptions++;
|
2012-08-31 20:26:21 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-11 07:51:49 +00:00
|
|
|
|
|
|
|
// Hide the parent options if there are no options for it.
|
|
|
|
$select.closest('div').toggle(totalOptions > 0).attr('hidden', totalOptions === 0);
|
2012-01-29 21:13:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2009-10-13 01:25:58 +00:00
|
|
|
|
|
|
|
})(jQuery);
|