drupal/core/modules/contextual/js/views/VisualView.js

57 lines
1.6 KiB
JavaScript
Raw Normal View History

/**
* DO NOT EDIT THIS FILE.
* All changes should be applied to ./modules/contextual/js/views/VisualView.es6.js
* See the following change record for more information,
* https://www.drupal.org/node/2873849
* @preserve
**/
(function (Drupal, Backbone, Modernizr) {
'use strict';
Drupal.contextual.VisualView = Backbone.View.extend({
events: function events() {
var touchEndToClick = function touchEndToClick(event) {
event.preventDefault();
event.target.click();
};
var mapping = {
'click .trigger': function clickTrigger() {
this.model.toggleOpen();
},
'touchend .trigger': touchEndToClick,
'click .contextual-links a': function clickContextualLinksA() {
this.model.close().blur();
},
'touchend .contextual-links a': touchEndToClick
};
if (!Modernizr.touchevents) {
mapping.mouseenter = function () {
this.model.focus();
};
}
return mapping;
},
initialize: function initialize() {
this.listenTo(this.model, 'change', this.render);
},
render: function render() {
var isOpen = this.model.get('isOpen');
var isVisible = this.model.get('isLocked') || this.model.get('regionIsHovered') || isOpen;
this.$el.toggleClass('open', isOpen).find('.trigger').toggleClass('visually-hidden', !isVisible);
if ('isOpen' in this.model.changed) {
this.$el.closest('.contextual-region').find('.contextual .trigger:not(:first)').toggle(!isOpen);
}
return this;
}
});
})(Drupal, Backbone, Modernizr);