view core/modules/menu_ui/menu_ui.admin.js @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
line wrap: on
line source
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/

(function ($, Drupal) {
  Drupal.behaviors.menuUiChangeParentItems = {
    attach: function attach(context, settings) {
      var $menu = $('#edit-menu').once('menu-parent');
      if ($menu.length) {
        Drupal.menuUiUpdateParentList();

        $menu.on('change', 'input', Drupal.menuUiUpdateParentList);
      }
    }
  };

  Drupal.menuUiUpdateParentList = function () {
    var $menu = $('#edit-menu');
    var values = [];

    $menu.find('input:checked').each(function () {
      values.push(Drupal.checkPlain($.trim($(this).val())));
    });

    $.ajax({
      url: location.protocol + '//' + location.host + Drupal.url('admin/structure/menu/parents'),
      type: 'POST',
      data: { 'menus[]': values },
      dataType: 'json',
      success: function success(options) {
        var $select = $('#edit-menu-parent');

        var selected = $select.val();

        $select.children().remove();

        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++;
          }
        }

        $select.closest('div').toggle(totalOptions > 0).attr('hidden', totalOptions === 0);
      }
    });
  };
})(jQuery, Drupal);