Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / contextual / js / views / KeyboardView.es6.js
1 /**
2  * @file
3  * A Backbone View that provides keyboard interaction for a contextual link.
4  */
5
6 (function (Drupal, Backbone) {
7   Drupal.contextual.KeyboardView = Backbone.View.extend(/** @lends Drupal.contextual.KeyboardView# */{
8
9     /**
10      * @type {object}
11      */
12     events: {
13       'focus .trigger': 'focus',
14       'focus .contextual-links a': 'focus',
15       'blur .trigger': function () {
16         this.model.blur();
17       },
18       'blur .contextual-links a': function () {
19         // Set up a timeout to allow a user to tab between the trigger and the
20         // contextual links without the menu dismissing.
21         const that = this;
22         this.timer = window.setTimeout(() => {
23           that.model.close().blur();
24         }, 150);
25       },
26     },
27
28     /**
29      * Provides keyboard interaction for a contextual link.
30      *
31      * @constructs
32      *
33      * @augments Backbone.View
34      */
35     initialize() {
36       /**
37        * The timer is used to create a delay before dismissing the contextual
38        * links on blur. This is only necessary when keyboard users tab into
39        * contextual links without edit mode (i.e. without TabbingManager).
40        * That means that if we decide to disable tabbing of contextual links
41        * without edit mode, all this timer logic can go away.
42        *
43        * @type {NaN|number}
44        */
45       this.timer = NaN;
46     },
47
48     /**
49      * Sets focus on the model; Clears the timer that dismisses the links.
50      */
51     focus() {
52       // Clear the timeout that might have been set by blurring a link.
53       window.clearTimeout(this.timer);
54       this.model.focus();
55     },
56
57   });
58 }(Drupal, Backbone));