2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Drupal) {
9 function DropButton(dropbutton, settings) {
10 var options = $.extend({ title: Drupal.t('List additional actions') }, settings);
11 var $dropbutton = $(dropbutton);
13 this.$dropbutton = $dropbutton;
15 this.$list = $dropbutton.find('.dropbutton');
17 this.$actions = this.$list.find('li').addClass('dropbutton-action');
19 if (this.$actions.length > 1) {
20 var $primary = this.$actions.slice(0, 1);
22 var $secondary = this.$actions.slice(1);
23 $secondary.addClass('secondary-action');
25 $primary.after(Drupal.theme('dropbuttonToggle', options));
27 this.$dropbutton.addClass('dropbutton-multiple').on({
28 'mouseleave.dropbutton': $.proxy(this.hoverOut, this),
30 'mouseenter.dropbutton': $.proxy(this.hoverIn, this),
32 'focusout.dropbutton': $.proxy(this.focusOut, this),
34 'focusin.dropbutton': $.proxy(this.focusIn, this)
37 this.$dropbutton.addClass('dropbutton-single');
41 function dropbuttonClickHandler(e) {
43 $(e.target).closest('.dropbutton-wrapper').toggleClass('open');
46 Drupal.behaviors.dropButton = {
47 attach: function attach(context, settings) {
48 var $dropbuttons = $(context).find('.dropbutton-wrapper').once('dropbutton');
49 if ($dropbuttons.length) {
50 var $body = $('body').once('dropbutton-click');
52 $body.on('click', '.dropbutton-toggle', dropbuttonClickHandler);
55 var il = $dropbuttons.length;
56 for (var i = 0; i < il; i++) {
57 DropButton.dropbuttons.push(new DropButton($dropbuttons[i], settings.dropbutton));
63 $.extend(DropButton, {
67 $.extend(DropButton.prototype, {
68 toggle: function toggle(show) {
69 var isBool = typeof show === 'boolean';
70 show = isBool ? show : !this.$dropbutton.hasClass('open');
71 this.$dropbutton.toggleClass('open', show);
73 hoverIn: function hoverIn() {
75 window.clearTimeout(this.timerID);
78 hoverOut: function hoverOut() {
79 this.timerID = window.setTimeout($.proxy(this, 'close'), 500);
81 open: function open() {
84 close: function close() {
87 focusOut: function focusOut(e) {
88 this.hoverOut.call(this, e);
90 focusIn: function focusIn(e) {
91 this.hoverIn.call(this, e);
95 $.extend(Drupal.theme, {
96 dropbuttonToggle: function dropbuttonToggle(options) {
97 return '<li class="dropbutton-toggle"><button type="button"><span class="dropbutton-arrow"><span class="visually-hidden">' + options.title + '</span></span></button></li>';
101 Drupal.DropButton = DropButton;