Backup of db before drupal security update
[yaffs-website] / web / core / modules / menu_ui / menu_ui.admin.js
1 /**
2  * @file
3  * Menu UI admin behaviors.
4  */
5
6 (function ($, Drupal) {
7
8   'use strict';
9
10   /**
11    *
12    * @type {Drupal~behavior}
13    */
14   Drupal.behaviors.menuUiChangeParentItems = {
15     attach: function (context, settings) {
16       var $menu = $('#edit-menu').once('menu-parent');
17       if ($menu.length) {
18         // Update the list of available parent menu items to match the initial
19         // available menus.
20         Drupal.menuUiUpdateParentList();
21
22         // Update list of available parent menu items.
23         $menu.on('change', 'input', Drupal.menuUiUpdateParentList);
24       }
25     }
26   };
27
28   /**
29    * Function to set the options of the menu parent item dropdown.
30    */
31   Drupal.menuUiUpdateParentList = function () {
32     var $menu = $('#edit-menu');
33     var values = [];
34
35     $menu.find('input:checked').each(function () {
36       // Get the names of all checked menus.
37       values.push(Drupal.checkPlain($.trim($(this).val())));
38     });
39
40     $.ajax({
41       url: location.protocol + '//' + location.host + Drupal.url('admin/structure/menu/parents'),
42       type: 'POST',
43       data: {'menus[]': values},
44       dataType: 'json',
45       success: function (options) {
46         var $select = $('#edit-menu-parent');
47         // Save key of last selected element.
48         var selected = $select.val();
49         // Remove all existing options from dropdown.
50         $select.children().remove();
51         // Add new options to dropdown. Keep a count of options for testing later.
52         var totalOptions = 0;
53         for (var machineName in options) {
54           if (options.hasOwnProperty(machineName)) {
55             $select.append(
56               $('<option ' + (machineName === selected ? ' selected="selected"' : '') + '></option>').val(machineName).text(options[machineName])
57             );
58             totalOptions++;
59           }
60         }
61
62         // Hide the parent options if there are no options for it.
63         $select.closest('div').toggle(totalOptions > 0).attr('hidden', totalOptions === 0);
64       }
65     });
66   };
67
68 })(jQuery, Drupal);