3 * A Backbone View that provides the visual view of a contextual link.
6 (function (Drupal, Backbone, Modernizr) {
7 Drupal.contextual.VisualView = Backbone.View.extend(/** @lends Drupal.contextual.VisualView# */{
10 * Events for the Backbone view.
13 * A mapping of events to be used in the view.
16 // Prevents delay and simulated mouse events.
17 const touchEndToClick = function (event) {
18 event.preventDefault();
22 'click .trigger': function () {
23 this.model.toggleOpen();
25 'touchend .trigger': touchEndToClick,
26 'click .contextual-links a': function () {
27 this.model.close().blur();
29 'touchend .contextual-links a': touchEndToClick,
31 // We only want mouse hover events on non-touch.
32 if (!Modernizr.touchevents) {
33 mapping.mouseenter = function () {
41 * Renders the visual view of a contextual link. Listens to mouse & touch.
45 * @augments Backbone.View
48 this.listenTo(this.model, 'change', this.render);
54 * @return {Drupal.contextual.VisualView}
55 * The current contextual visual view.
58 const isOpen = this.model.get('isOpen');
59 // The trigger should be visible when:
60 // - the mouse hovered over the region,
61 // - the trigger is locked,
62 // - and for as long as the contextual menu is open.
63 const isVisible = this.model.get('isLocked') || this.model.get('regionIsHovered') || isOpen;
66 // The open state determines if the links are visible.
67 .toggleClass('open', isOpen)
68 // Update the visibility of the trigger.
69 .find('.trigger').toggleClass('visually-hidden', !isVisible);
71 // Nested contextual region handling: hide any nested contextual triggers.
72 if ('isOpen' in this.model.changed) {
73 this.$el.closest('.contextual-region')
74 .find('.contextual .trigger:not(:first)')
82 }(Drupal, Backbone, Modernizr));