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

53 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/
(function (Drupal, Backbone, Modernizr) {
Drupal.contextual.VisualView = Backbone.View.extend({
events() {
const touchEndToClick = function (event) {
event.preventDefault();
event.target.click();
};
const mapping = {
'click .trigger': function () {
this.model.toggleOpen();
},
'touchend .trigger': touchEndToClick,
'click .contextual-links a': function () {
this.model.close().blur();
},
'touchend .contextual-links a': touchEndToClick
};
if (!Modernizr.touchevents) {
mapping.mouseenter = function () {
this.model.focus();
};
}
return mapping;
},
initialize() {
this.listenTo(this.model, 'change', this.render);
},
render() {
const isOpen = this.model.get('isOpen');
const 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);