/**
- * @file
- * A Backbone View that provides the visual view of the edit mode toggle.
- */
+* DO NOT EDIT THIS FILE.
+* See the following change record for more information,
+* https://www.drupal.org/node/2815083
+* @preserve
+**/
(function (Drupal, Backbone) {
-
- 'use strict';
-
- Drupal.contextualToolbar.VisualView = Backbone.View.extend(/** @lends Drupal.contextualToolbar.VisualView# */{
-
- /**
- * Events for the Backbone view.
- *
- * @return {object}
- * A mapping of events to be used in the view.
- */
- events: function () {
- // Prevents delay and simulated mouse events.
- var touchEndToClick = function (event) {
+ Drupal.contextualToolbar.VisualView = Backbone.View.extend({
+ events: function events() {
+ var touchEndToClick = function touchEndToClick(event) {
event.preventDefault();
event.target.click();
};
return {
- click: function () {
+ click: function click() {
this.model.set('isViewing', !this.model.get('isViewing'));
},
+
touchend: touchEndToClick
};
},
-
- /**
- * Renders the visual view of the edit mode toggle.
- *
- * Listens to mouse & touch and handles edit mode toggle interactions.
- *
- * @constructs
- *
- * @augments Backbone.View
- */
- initialize: function () {
+ initialize: function initialize() {
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'change:isViewing', this.persist);
},
-
- /**
- * @inheritdoc
- *
- * @return {Drupal.contextualToolbar.VisualView}
- * The current contextual toolbar visual view.
- */
- render: function () {
- // Render the visibility.
+ render: function render() {
this.$el.toggleClass('hidden', !this.model.get('isVisible'));
- // Render the state.
+
this.$el.find('button').toggleClass('is-active', !this.model.get('isViewing'));
return this;
},
-
- /**
- * Model change handler; persists the isViewing value to localStorage.
- *
- * `isViewing === true` is the default, so only stores in localStorage when
- * it's not the default value (i.e. false).
- *
- * @param {Drupal.contextualToolbar.StateModel} model
- * A {@link Drupal.contextualToolbar.StateModel} model.
- * @param {bool} isViewing
- * The value of the isViewing attribute in the model.
- */
- persist: function (model, isViewing) {
+ persist: function persist(model, isViewing) {
if (!isViewing) {
localStorage.setItem('Drupal.contextualToolbar.isViewing', 'false');
- }
- else {
+ } else {
localStorage.removeItem('Drupal.contextualToolbar.isViewing');
}
}
-
});
-
-})(Drupal, Backbone);
+})(Drupal, Backbone);
\ No newline at end of file