Projet

Général

Profil

Paste
Télécharger (1,39 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / menu / menu.admin.js @ 01dfd3b5

1
(function ($) {
2

    
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();
9
      });
10
    });
11
  }
12
};
13

    
14
/**
15
 * Function to set the options of the menu parent item dropdown.
16
 */
17
Drupal.menu_update_parent_list = function () {
18
  var values = [];
19

    
20
  $('input:checked', $('fieldset#edit-menu')).each(function () {
21
    // Get the names of all checked menus.
22
    values.push(Drupal.checkPlain($.trim($(this).val())));
23
  });
24

    
25
  var url = Drupal.settings.basePath + 'admin/structure/menu/parents';
26
  $.ajax({
27
    url: location.protocol + '//' + location.host + url,
28
    type: 'POST',
29
    data: {'menus[]' : values},
30
    dataType: 'json',
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)
40
        );
41
      });
42
    }
43
  });
44
};
45

    
46
})(jQuery);