Chris@0: /** Chris@0: * @file Chris@0: * A Backbone View that renders the visual view of a contextual region element. Chris@0: */ Chris@0: Chris@17: (function(Drupal, Backbone, Modernizr) { Chris@17: Drupal.contextual.RegionView = Backbone.View.extend( Chris@17: /** @lends Drupal.contextual.RegionView# */ { Chris@17: /** Chris@17: * Events for the Backbone view. Chris@17: * Chris@17: * @return {object} Chris@17: * A mapping of events to be used in the view. Chris@17: */ Chris@17: events() { Chris@17: let mapping = { Chris@17: mouseenter() { Chris@17: this.model.set('regionIsHovered', true); Chris@17: }, Chris@17: mouseleave() { Chris@17: this.model Chris@17: .close() Chris@17: .blur() Chris@17: .set('regionIsHovered', false); Chris@17: }, Chris@17: }; Chris@17: // We don't want mouse hover events on touch. Chris@17: if (Modernizr.touchevents) { Chris@17: mapping = {}; Chris@17: } Chris@17: return mapping; Chris@17: }, Chris@0: Chris@17: /** Chris@17: * Renders the visual view of a contextual region element. Chris@17: * Chris@17: * @constructs Chris@17: * Chris@17: * @augments Backbone.View Chris@17: */ Chris@17: initialize() { Chris@17: this.listenTo(this.model, 'change:hasFocus', this.render); Chris@17: }, Chris@17: Chris@17: /** Chris@17: * @inheritdoc Chris@17: * Chris@17: * @return {Drupal.contextual.RegionView} Chris@17: * The current contextual region view. Chris@17: */ Chris@17: render() { Chris@17: this.$el.toggleClass('focus', this.model.get('hasFocus')); Chris@17: Chris@17: return this; Chris@17: }, Chris@0: }, Chris@17: ); Chris@17: })(Drupal, Backbone, Modernizr);