Commit c56e41ae authored by catch's avatar catch

Issue #1751398 by oxyc: Selectors clean-up: menu module.

parent 6e74154a
......@@ -4,22 +4,19 @@
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();
});
});
// Update list of available parent menu items.
$('#edit-menu').on('change', 'input', Drupal.menuUpdateParentList);
}
};
/**
* Function to set the options of the menu parent item dropdown.
*/
Drupal.menu_update_parent_list = function () {
Drupal.menuUpdateParentList = function () {
var $menuFieldset = $('#edit-menu');
var values = [];
$('fieldset#edit-menu').find('input:checked').each(function () {
$menuFieldset.find('input:checked').each(function () {
// Get the names of all checked menus.
values.push(Drupal.checkPlain($.trim($(this).val())));
});
......@@ -30,16 +27,19 @@ Drupal.menu_update_parent_list = function () {
data: {'menus[]' : values},
dataType: 'json',
success: function (options) {
var $select = $('#edit-menu-parent');
// Save key of last selected element.
var selected = $('fieldset#edit-menu #edit-menu-parent :selected').val();
var selected = $select.val();
// Remove all exisiting options from dropdown.
$('fieldset#edit-menu #edit-menu-parent').children().remove();
$select.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)
);
});
for (var machineName in options) {
if (options.hasOwnProperty(machineName)) {
$select.append(
$('<option ' + (machineName === selected ? ' selected="selected"' : '') + '></option>').val(machineName).text(options[machineName])
);
}
}
}
});
};
......
......@@ -43,7 +43,7 @@ Drupal.behaviors.menuLinkAutomaticTitle = {
$link_title.data('menuLinkAutomaticTitleOveridden', true);
});
// Global trigger on checkbox (do not fill-in a value when disabled).
$checkbox.change(function () {
$checkbox.on('change', function () {
if ($checkbox.is(':checked')) {
if (!$link_title.data('menuLinkAutomaticTitleOveridden')) {
$link_title.val($title.val());
......
......@@ -780,10 +780,10 @@ function menu_form_node_type_form_alter(&$form, $form_state) {
'#attributes' => array('class' => array('menu-title-select')),
);
// Call Drupal.menu_update_parent_list() to filter the list of
// Call Drupal.menuUpdateParentList() to filter the list of
// available default parent menu items based on the selected menus.
drupal_add_js(
'(function ($) { Drupal.menu_update_parent_list(); })(jQuery);',
'(function ($) { Drupal.menuUpdateParentList(); })(jQuery);',
array('scope' => 'footer', 'type' => 'inline')
);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment