Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / misc / dropbutton / dropbutton.js
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
8 (function ($, Drupal) {
9   function DropButton(dropbutton, settings) {
10     var options = $.extend({ title: Drupal.t('List additional actions') }, settings);
11     var $dropbutton = $(dropbutton);
12
13     this.$dropbutton = $dropbutton;
14
15     this.$list = $dropbutton.find('.dropbutton');
16
17     this.$actions = this.$list.find('li').addClass('dropbutton-action');
18
19     if (this.$actions.length > 1) {
20       var $primary = this.$actions.slice(0, 1);
21
22       var $secondary = this.$actions.slice(1);
23       $secondary.addClass('secondary-action');
24
25       $primary.after(Drupal.theme('dropbuttonToggle', options));
26
27       this.$dropbutton.addClass('dropbutton-multiple').on({
28         'mouseleave.dropbutton': $.proxy(this.hoverOut, this),
29
30         'mouseenter.dropbutton': $.proxy(this.hoverIn, this),
31
32         'focusout.dropbutton': $.proxy(this.focusOut, this),
33
34         'focusin.dropbutton': $.proxy(this.focusIn, this)
35       });
36     } else {
37       this.$dropbutton.addClass('dropbutton-single');
38     }
39   }
40
41   function dropbuttonClickHandler(e) {
42     e.preventDefault();
43     $(e.target).closest('.dropbutton-wrapper').toggleClass('open');
44   }
45
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');
51         if ($body.length) {
52           $body.on('click', '.dropbutton-toggle', dropbuttonClickHandler);
53         }
54
55         var il = $dropbuttons.length;
56         for (var i = 0; i < il; i++) {
57           DropButton.dropbuttons.push(new DropButton($dropbuttons[i], settings.dropbutton));
58         }
59       }
60     }
61   };
62
63   $.extend(DropButton, {
64     dropbuttons: []
65   });
66
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);
72     },
73     hoverIn: function hoverIn() {
74       if (this.timerID) {
75         window.clearTimeout(this.timerID);
76       }
77     },
78     hoverOut: function hoverOut() {
79       this.timerID = window.setTimeout($.proxy(this, 'close'), 500);
80     },
81     open: function open() {
82       this.toggle(true);
83     },
84     close: function close() {
85       this.toggle(false);
86     },
87     focusOut: function focusOut(e) {
88       this.hoverOut.call(this, e);
89     },
90     focusIn: function focusIn(e) {
91       this.hoverIn.call(this, e);
92     }
93   });
94
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>';
98     }
99   });
100
101   Drupal.DropButton = DropButton;
102 })(jQuery, Drupal);