3 * A Backbone View that provides the visual view of the edit mode toggle.
6 (function (Drupal, Backbone) {
10 Drupal.contextualToolbar.VisualView = Backbone.View.extend(/** @lends Drupal.contextualToolbar.VisualView# */{
13 * Events for the Backbone view.
16 * A mapping of events to be used in the view.
19 // Prevents delay and simulated mouse events.
20 var touchEndToClick = function (event) {
21 event.preventDefault();
27 this.model.set('isViewing', !this.model.get('isViewing'));
29 touchend: touchEndToClick
34 * Renders the visual view of the edit mode toggle.
36 * Listens to mouse & touch and handles edit mode toggle interactions.
40 * @augments Backbone.View
42 initialize: function () {
43 this.listenTo(this.model, 'change', this.render);
44 this.listenTo(this.model, 'change:isViewing', this.persist);
50 * @return {Drupal.contextualToolbar.VisualView}
51 * The current contextual toolbar visual view.
54 // Render the visibility.
55 this.$el.toggleClass('hidden', !this.model.get('isVisible'));
57 this.$el.find('button').toggleClass('is-active', !this.model.get('isViewing'));
63 * Model change handler; persists the isViewing value to localStorage.
65 * `isViewing === true` is the default, so only stores in localStorage when
66 * it's not the default value (i.e. false).
68 * @param {Drupal.contextualToolbar.StateModel} model
69 * A {@link Drupal.contextualToolbar.StateModel} model.
70 * @param {bool} isViewing
71 * The value of the isViewing attribute in the model.
73 persist: function (model, isViewing) {
75 localStorage.setItem('Drupal.contextualToolbar.isViewing', 'false');
78 localStorage.removeItem('Drupal.contextualToolbar.isViewing');