3 * A Backbone View that provides the visual view of a contextual link.
6 (function (Drupal, Backbone, Modernizr) {
10 Drupal.contextual.VisualView = Backbone.View.extend(/** @lends Drupal.contextual.VisualView# */{
13 * Events for the Backbone view.
16 * A mapping of events to be used in the view.
19 // Prevents delay and simulated mouse events.
20 var touchEndToClick = function (event) {
21 event.preventDefault();
25 'click .trigger': function () { this.model.toggleOpen(); },
26 'touchend .trigger': touchEndToClick,
27 'click .contextual-links a': function () { this.model.close().blur(); },
28 'touchend .contextual-links a': touchEndToClick
30 // We only want mouse hover events on non-touch.
31 if (!Modernizr.touchevents) {
32 mapping.mouseenter = function () { this.model.focus(); };
38 * Renders the visual view of a contextual link. Listens to mouse & touch.
42 * @augments Backbone.View
44 initialize: function () {
45 this.listenTo(this.model, 'change', this.render);
51 * @return {Drupal.contextual.VisualView}
52 * The current contextual visual view.
55 var isOpen = this.model.get('isOpen');
56 // The trigger should be visible when:
57 // - the mouse hovered over the region,
58 // - the trigger is locked,
59 // - and for as long as the contextual menu is open.
60 var isVisible = this.model.get('isLocked') || this.model.get('regionIsHovered') || isOpen;
63 // The open state determines if the links are visible.
64 .toggleClass('open', isOpen)
65 // Update the visibility of the trigger.
66 .find('.trigger').toggleClass('visually-hidden', !isVisible);
68 // Nested contextual region handling: hide any nested contextual triggers.
69 if ('isOpen' in this.model.changed) {
70 this.$el.closest('.contextual-region')
71 .find('.contextual .trigger:not(:first)')
80 })(Drupal, Backbone, Modernizr);