VisualView.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function (Drupal, Backbone, Modernizr) {
  8. Drupal.contextual.VisualView = Backbone.View.extend({
  9. events: function events() {
  10. var touchEndToClick = function touchEndToClick(event) {
  11. event.preventDefault();
  12. event.target.click();
  13. };
  14. var mapping = {
  15. 'click .trigger': function clickTrigger() {
  16. this.model.toggleOpen();
  17. },
  18. 'touchend .trigger': touchEndToClick,
  19. 'click .contextual-links a': function clickContextualLinksA() {
  20. this.model.close().blur();
  21. },
  22. 'touchend .contextual-links a': touchEndToClick
  23. };
  24. if (!Modernizr.touchevents) {
  25. mapping.mouseenter = function () {
  26. this.model.focus();
  27. };
  28. }
  29. return mapping;
  30. },
  31. initialize: function initialize() {
  32. this.listenTo(this.model, 'change', this.render);
  33. },
  34. render: function render() {
  35. var isOpen = this.model.get('isOpen');
  36. var isVisible = this.model.get('isLocked') || this.model.get('regionIsHovered') || isOpen;
  37. this.$el.toggleClass('open', isOpen).find('.trigger').toggleClass('visually-hidden', !isVisible);
  38. if ('isOpen' in this.model.changed) {
  39. this.$el.closest('.contextual-region').find('.contextual .trigger:not(:first)').toggle(!isOpen);
  40. }
  41. return this;
  42. }
  43. });
  44. })(Drupal, Backbone, Modernizr);