2015-06-05 20:17:55 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Menu UI admin behaviors.
|
|
|
|
*/
|
|
|
|
|
2009-10-13 01:25:58 +00:00
|
|
|
(function ($) {
|
|
|
|
|
2015-10-13 22:37:56 +00:00
|
|
|
'use strict';
|
2014-01-27 21:41:32 +00:00
|
|
|
|
2015-06-05 20:17:55 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @type {Drupal~behavior}
|
|
|
|
*/
|
2014-04-13 19:04:02 +00:00
|
|
|
Drupal.behaviors.menuUiChangeParentItems = {
|
2014-01-27 21:41:32 +00:00
|
|
|
attach: function (context, settings) {
|
2015-03-23 10:29:17 +00:00
|
|
|
var $menu = $('#edit-menu').once('menu-parent');
|
|
|
|
if ($menu.length) {
|
2014-01-27 21:41:32 +00:00
|
|
|
// Update the list of available parent menu items to match the initial
|
|
|
|
// available menus.
|
2014-04-13 19:04:02 +00:00
|
|
|
Drupal.menuUiUpdateParentList();
|
2014-01-27 21:41:32 +00:00
|
|
|
|
|
|
|
// Update list of available parent menu items.
|
2014-04-13 19:04:02 +00:00
|
|
|
$menu.on('change', 'input', Drupal.menuUiUpdateParentList);
|
2015-03-23 10:29:17 +00:00
|
|
|
}
|
2014-01-27 21:41:32 +00:00
|
|
|
}
|
|
|
|
};
|
2012-05-08 02:57:33 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
/**
|
|
|
|
* Function to set the options of the menu parent item dropdown.
|
|
|
|
*/
|
2014-04-13 19:04:02 +00:00
|
|
|
Drupal.menuUiUpdateParentList = function () {
|
2014-01-06 16:47:16 +00:00
|
|
|
var $menu = $('#edit-menu');
|
2014-01-27 21:41:32 +00:00
|
|
|
var values = [];
|
2014-01-06 16:47:16 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
$menu.find('input:checked').each(function () {
|
|
|
|
// Get the names of all checked menus.
|
|
|
|
values.push(Drupal.checkPlain($.trim($(this).val())));
|
2014-01-06 16:47:16 +00:00
|
|
|
});
|
2014-01-27 21:41:32 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: location.protocol + '//' + location.host + Drupal.url('admin/structure/menu/parents'),
|
|
|
|
type: 'POST',
|
|
|
|
data: {'menus[]': values},
|
|
|
|
dataType: 'json',
|
|
|
|
success: function (options) {
|
|
|
|
var $select = $('#edit-menu-parent');
|
|
|
|
// Save key of last selected element.
|
|
|
|
var selected = $select.val();
|
2015-05-12 23:54:27 +00:00
|
|
|
// Remove all existing options from dropdown.
|
2014-01-27 21:41:32 +00:00
|
|
|
$select.children().remove();
|
|
|
|
// Add new options to dropdown. Keep a count of options for testing later.
|
|
|
|
var totalOptions = 0;
|
|
|
|
for (var machineName in options) {
|
|
|
|
if (options.hasOwnProperty(machineName)) {
|
|
|
|
$select.append(
|
|
|
|
$('<option ' + (machineName === selected ? ' selected="selected"' : '') + '></option>').val(machineName).text(options[machineName])
|
|
|
|
);
|
|
|
|
totalOptions++;
|
|
|
|
}
|
2012-08-31 20:26:21 +00:00
|
|
|
}
|
2013-04-11 07:51:49 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
// Hide the parent options if there are no options for it.
|
|
|
|
$select.closest('div').toggle(totalOptions > 0).attr('hidden', totalOptions === 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2009-10-13 01:25:58 +00:00
|
|
|
|
|
|
|
})(jQuery);
|