57048a77d68d0968d5d537aff0b3f06f04575956
[yaffs-website] / web / core / modules / contextual / js / views / RegionView.es6.js
1 /**
2  * @file
3  * A Backbone View that renders the visual view of a contextual region element.
4  */
5
6 (function(Drupal, Backbone, Modernizr) {
7   Drupal.contextual.RegionView = Backbone.View.extend(
8     /** @lends Drupal.contextual.RegionView# */ {
9       /**
10        * Events for the Backbone view.
11        *
12        * @return {object}
13        *   A mapping of events to be used in the view.
14        */
15       events() {
16         let mapping = {
17           mouseenter() {
18             this.model.set('regionIsHovered', true);
19           },
20           mouseleave() {
21             this.model
22               .close()
23               .blur()
24               .set('regionIsHovered', false);
25           },
26         };
27         // We don't want mouse hover events on touch.
28         if (Modernizr.touchevents) {
29           mapping = {};
30         }
31         return mapping;
32       },
33
34       /**
35        * Renders the visual view of a contextual region element.
36        *
37        * @constructs
38        *
39        * @augments Backbone.View
40        */
41       initialize() {
42         this.listenTo(this.model, 'change:hasFocus', this.render);
43       },
44
45       /**
46        * @inheritdoc
47        *
48        * @return {Drupal.contextual.RegionView}
49        *   The current contextual region view.
50        */
51       render() {
52         this.$el.toggleClass('focus', this.model.get('hasFocus'));
53
54         return this;
55       },
56     },
57   );
58 })(Drupal, Backbone, Modernizr);