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