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
74
core/modules/quickedit/js/views/ContextualLinkView.js
Normal file
74
core/modules/quickedit/js/views/ContextualLinkView.js
Normal file
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
* @file
|
||||
* A Backbone View that provides a dynamic contextual link.
|
||||
*/
|
||||
|
||||
(function ($, Backbone, Drupal) {
|
||||
|
||||
"use strict";
|
||||
|
||||
Drupal.quickedit.ContextualLinkView = Backbone.View.extend(/** @lends Drupal.quickedit.ContextualLinkView# */{
|
||||
|
||||
/**
|
||||
* Define all events to listen to.
|
||||
*
|
||||
* @return {object}
|
||||
*/
|
||||
events: function () {
|
||||
// Prevents delay and simulated mouse events.
|
||||
function touchEndToClick(event) {
|
||||
event.preventDefault();
|
||||
event.target.click();
|
||||
}
|
||||
|
||||
return {
|
||||
'click a': function (event) {
|
||||
event.preventDefault();
|
||||
this.model.set('state', 'launching');
|
||||
},
|
||||
'touchEnd a': touchEndToClick
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* @constructs
|
||||
*
|
||||
* @augments Backbone.View
|
||||
*
|
||||
* @param {object} options
|
||||
* An object with the following keys:
|
||||
* @param {Drupal.quickedit.EntityModel} options.model
|
||||
* The associated entity's model.
|
||||
* @param {Drupal.quickedit.AppModel} options.appModel
|
||||
* The application state model.
|
||||
* @param {object} options.strings
|
||||
* The strings for the "Quick edit" link.
|
||||
*/
|
||||
initialize: function (options) {
|
||||
// Insert the text of the quick edit toggle.
|
||||
this.$el.find('a').text(options.strings.quickEdit);
|
||||
// Initial render.
|
||||
this.render();
|
||||
// Re-render whenever this entity's isActive attribute changes.
|
||||
this.listenTo(this.model, 'change:isActive', this.render);
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Drupal.quickedit.EntityModel} entityModel
|
||||
* @param {bool} isActive
|
||||
*
|
||||
* @return {Drupal.quickedit.ContextualLinkView}
|
||||
*/
|
||||
render: function (entityModel, isActive) {
|
||||
this.$el.find('a').attr('aria-pressed', isActive);
|
||||
|
||||
// Hides the contextual links if an in-place editor is active.
|
||||
this.$el.closest('.contextual').toggle(!isActive);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})(jQuery, Backbone, Drupal);
|
Reference in a new issue