Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
121
core/modules/contextual/js/toolbar/models/StateModel.js
Normal file
121
core/modules/contextual/js/toolbar/models/StateModel.js
Normal file
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
* @file
|
||||
* A Backbone Model for the state of Contextual module's edit toolbar tab.
|
||||
*/
|
||||
|
||||
(function (Drupal, Backbone) {
|
||||
|
||||
"use strict";
|
||||
|
||||
Drupal.contextualToolbar.StateModel = Backbone.Model.extend(/** @lends Drupal.contextualToolbar.StateModel# */{
|
||||
|
||||
/**
|
||||
* @type {object}
|
||||
*
|
||||
* @prop {bool} isViewing
|
||||
* @prop {bool} isVisible
|
||||
* @prop {number} contextualCount
|
||||
* @prop {Drupal~TabbingContext} tabbingContext
|
||||
*/
|
||||
defaults: /** @lends Drupal.contextualToolbar.StateModel# */{
|
||||
|
||||
/**
|
||||
* Indicates whether the toggle is currently in "view" or "edit" mode.
|
||||
*
|
||||
* @type {bool}
|
||||
*/
|
||||
isViewing: true,
|
||||
|
||||
/**
|
||||
* Indicates whether the toggle should be visible or hidden. Automatically
|
||||
* calculated, depends on contextualCount.
|
||||
*
|
||||
* @type {bool}
|
||||
*/
|
||||
isVisible: false,
|
||||
|
||||
/**
|
||||
* Tracks how many contextual links exist on the page.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
contextualCount: 0,
|
||||
|
||||
/**
|
||||
* A TabbingContext object as returned by {@link Drupal~TabbingManager}:
|
||||
* the set of tabbable elements when edit mode is enabled.
|
||||
*
|
||||
* @type {?Drupal~TabbingContext}
|
||||
*/
|
||||
tabbingContext: null
|
||||
},
|
||||
|
||||
/**
|
||||
* Models the state of the edit mode toggle.
|
||||
*
|
||||
* @constructs
|
||||
*
|
||||
* @augments Backbone.Model
|
||||
*
|
||||
* @param {object} attrs
|
||||
* @param {object} options
|
||||
* An object with the following option:
|
||||
* @param {Backbone.collection} options.contextualCollection
|
||||
* The collection of {@link Drupal.contextual.StateModel} models that
|
||||
* represent the contextual links on the page.
|
||||
*/
|
||||
initialize: function (attrs, options) {
|
||||
// Respond to new/removed contextual links.
|
||||
this.listenTo(options.contextualCollection, {
|
||||
'reset remove add': this.countContextualLinks,
|
||||
'add': this.lockNewContextualLinks
|
||||
});
|
||||
|
||||
this.listenTo(this, {
|
||||
// Automatically determine visibility.
|
||||
'change:contextualCount': this.updateVisibility,
|
||||
// Whenever edit mode is toggled, lock all contextual links.
|
||||
'change:isViewing': function (model, isViewing) {
|
||||
options.contextualCollection.each(function (contextualModel) {
|
||||
contextualModel.set('isLocked', !isViewing);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Tracks the number of contextual link models in the collection.
|
||||
*
|
||||
* @param {Drupal.contextual.StateModel} contextualModel
|
||||
* The contextual links model that was added or removed.
|
||||
* @param {Backbone.Collection} contextualCollection
|
||||
* The collection of contextual link models.
|
||||
*/
|
||||
countContextualLinks: function (contextualModel, contextualCollection) {
|
||||
this.set('contextualCount', contextualCollection.length);
|
||||
},
|
||||
|
||||
/**
|
||||
* Lock newly added contextual links if edit mode is enabled.
|
||||
*
|
||||
* @param {Drupal.contextual.StateModel} contextualModel
|
||||
* The contextual links model that was added.
|
||||
* @param {Backbone.Collection} [contextualCollection]
|
||||
* The collection of contextual link models.
|
||||
*/
|
||||
lockNewContextualLinks: function (contextualModel, contextualCollection) {
|
||||
if (!this.get('isViewing')) {
|
||||
contextualModel.set('isLocked', true);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Automatically updates visibility of the view/edit mode toggle.
|
||||
*/
|
||||
updateVisibility: function () {
|
||||
this.set('isVisible', this.get('contextualCount') > 0);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})(Drupal, Backbone);
|
101
core/modules/contextual/js/toolbar/views/AuralView.js
Normal file
101
core/modules/contextual/js/toolbar/views/AuralView.js
Normal file
|
@ -0,0 +1,101 @@
|
|||
/**
|
||||
* @file
|
||||
* A Backbone View that provides the aural view of the edit mode toggle.
|
||||
*/
|
||||
|
||||
(function ($, Drupal, Backbone, _) {
|
||||
|
||||
"use strict";
|
||||
|
||||
Drupal.contextualToolbar.AuralView = Backbone.View.extend(/** @lends Drupal.contextualToolbar.AuralView# */{
|
||||
|
||||
/**
|
||||
* Tracks whether the tabbing constraint announcement has been read once.
|
||||
*
|
||||
* @type {bool}
|
||||
*/
|
||||
announcedOnce: false,
|
||||
|
||||
/**
|
||||
* Renders the aural view of the edit mode toggle (screen reader support).
|
||||
*
|
||||
* @constructs
|
||||
*
|
||||
* @augments Backbone.View
|
||||
*
|
||||
* @param {object} options
|
||||
*/
|
||||
initialize: function (options) {
|
||||
this.options = options;
|
||||
|
||||
this.listenTo(this.model, 'change', this.render);
|
||||
this.listenTo(this.model, 'change:isViewing', this.manageTabbing);
|
||||
|
||||
$(document).on('keyup', _.bind(this.onKeypress, this));
|
||||
},
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @return {Drupal.contextualToolbar.AuralView}
|
||||
*/
|
||||
render: function () {
|
||||
// Render the state.
|
||||
this.$el.find('button').attr('aria-pressed', !this.model.get('isViewing'));
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Limits tabbing to the contextual links and edit mode toolbar tab.
|
||||
*/
|
||||
manageTabbing: function () {
|
||||
var tabbingContext = this.model.get('tabbingContext');
|
||||
// Always release an existing tabbing context.
|
||||
if (tabbingContext) {
|
||||
tabbingContext.release();
|
||||
Drupal.announce(this.options.strings.tabbingReleased);
|
||||
}
|
||||
// Create a new tabbing context when edit mode is enabled.
|
||||
if (!this.model.get('isViewing')) {
|
||||
tabbingContext = Drupal.tabbingManager.constrain($('.contextual-toolbar-tab, .contextual'));
|
||||
this.model.set('tabbingContext', tabbingContext);
|
||||
this.announceTabbingConstraint();
|
||||
this.announcedOnce = true;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Announces the current tabbing constraint.
|
||||
*/
|
||||
announceTabbingConstraint: function () {
|
||||
var strings = this.options.strings;
|
||||
Drupal.announce(Drupal.formatString(strings.tabbingConstrained, {
|
||||
'@contextualsCount': Drupal.formatPlural(Drupal.contextual.collection.length, '@count contextual link', '@count contextual links')
|
||||
}));
|
||||
Drupal.announce(strings.pressEsc);
|
||||
},
|
||||
|
||||
/**
|
||||
* Responds to esc and tab key press events.
|
||||
*
|
||||
* @param {jQuery.Event} event
|
||||
*/
|
||||
onKeypress: function (event) {
|
||||
// The first tab key press is tracked so that an annoucement about tabbing
|
||||
// constraints can be raised if edit mode is enabled when the page is
|
||||
// loaded.
|
||||
if (!this.announcedOnce && event.keyCode === 9 && !this.model.get('isViewing')) {
|
||||
this.announceTabbingConstraint();
|
||||
// Set announce to true so that this conditional block won't run again.
|
||||
this.announcedOnce = true;
|
||||
}
|
||||
// Respond to the ESC key. Exit out of edit mode.
|
||||
if (event.keyCode === 27) {
|
||||
this.model.set('isViewing', true);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})(jQuery, Drupal, Backbone, _);
|
80
core/modules/contextual/js/toolbar/views/VisualView.js
Normal file
80
core/modules/contextual/js/toolbar/views/VisualView.js
Normal file
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
* @file
|
||||
* A Backbone View that provides the visual view of the edit mode toggle.
|
||||
*/
|
||||
|
||||
(function (Drupal, Backbone) {
|
||||
|
||||
"use strict";
|
||||
|
||||
Drupal.contextualToolbar.VisualView = Backbone.View.extend(/** @lends Drupal.contextualToolbar.VisualView# */{
|
||||
|
||||
/**
|
||||
* @return {object}
|
||||
*/
|
||||
events: function () {
|
||||
// Prevents delay and simulated mouse events.
|
||||
var touchEndToClick = function (event) {
|
||||
event.preventDefault();
|
||||
event.target.click();
|
||||
};
|
||||
|
||||
return {
|
||||
'click': function () {
|
||||
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 () {
|
||||
this.listenTo(this.model, 'change', this.render);
|
||||
this.listenTo(this.model, 'change:isViewing', this.persist);
|
||||
},
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @return {Drupal.contextualToolbar.VisualView}
|
||||
*/
|
||||
render: function () {
|
||||
// Render the visibility.
|
||||
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) {
|
||||
if (!isViewing) {
|
||||
localStorage.setItem('Drupal.contextualToolbar.isViewing', 'false');
|
||||
}
|
||||
else {
|
||||
localStorage.removeItem('Drupal.contextualToolbar.isViewing');
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})(Drupal, Backbone);
|
Reference in a new issue