summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/quickedit/js/quickedit.js
diff options
context:
space:
mode:
authorAlex Pott <alex.a.pott@googlemail.com>2020-01-28 11:36:14 +0000
committerAlex Pott <alex.a.pott@googlemail.com>2020-01-28 11:36:14 +0000
commit2dadb738bfd48510db2174323528fe769731c05a (patch)
treef6319d9bfa9af8b41dc0ca7c187bef1eaf17aee4 /core/modules/quickedit/js/quickedit.js
parent09b78ffb1bc1bb62d21fb3abb85e1349a674597a (diff)
downloaddrupal-2dadb738bfd48510db2174323528fe769731c05a.tar.gz
drupal-2dadb738bfd48510db2174323528fe769731c05a.zip
Issue #3101543 by lauriii, bnjmnm, ravi.shankar: Update core JavaScript dependencies listed in package.json
Diffstat (limited to 'core/modules/quickedit/js/quickedit.js')
-rw-r--r--core/modules/quickedit/js/quickedit.js62
1 files changed, 30 insertions, 32 deletions
diff --git a/core/modules/quickedit/js/quickedit.js b/core/modules/quickedit/js/quickedit.js
index 56bb74646a0c..8461e0f2ee9a 100644
--- a/core/modules/quickedit/js/quickedit.js
+++ b/core/modules/quickedit/js/quickedit.js
@@ -11,19 +11,14 @@
quickEdit: Drupal.t('Quick edit')
}
});
-
var fieldsMetadataQueue = [];
-
var fieldsAvailableQueue = [];
-
var contextualLinksQueue = [];
-
var entityInstancesTracker = {};
function initQuickEdit(bodyElement) {
Drupal.quickedit.collections.entities = new Drupal.quickedit.EntityCollection();
Drupal.quickedit.collections.fields = new Drupal.quickedit.FieldCollection();
-
Drupal.quickedit.app = new Drupal.quickedit.AppView({
el: bodyElement,
model: new Drupal.quickedit.AppModel(),
@@ -34,6 +29,7 @@
function processEntity(entityElement) {
var entityID = entityElement.getAttribute('data-quickedit-entity-id');
+
if (!entityInstancesTracker.hasOwnProperty(entityID)) {
entityInstancesTracker[entityID] = 0;
} else {
@@ -49,33 +45,32 @@
entityID: entityID,
entityInstanceID: entityInstanceID
});
-
$(fieldElement).addClass('quickedit-field');
-
var field = new Drupal.quickedit.FieldModel({
el: fieldElement,
fieldID: fieldID,
- id: fieldID + '[' + entity.get('entityInstanceID') + ']',
+ id: "".concat(fieldID, "[").concat(entity.get('entityInstanceID'), "]"),
entity: entity,
metadata: Drupal.quickedit.metadata.get(fieldID),
acceptStateChange: _.bind(Drupal.quickedit.app.acceptEditorStateChange, Drupal.quickedit.app)
});
-
Drupal.quickedit.collections.fields.add(field);
}
function loadMissingEditors(callback) {
var loadedEditors = _.keys(Drupal.quickedit.editors);
+
var missingEditors = [];
Drupal.quickedit.collections.fields.each(function (fieldModel) {
var metadata = Drupal.quickedit.metadata.get(fieldModel.get('fieldID'));
+
if (metadata.access && _.indexOf(loadedEditors, metadata.editor) === -1) {
missingEditors.push(metadata.editor);
-
Drupal.quickedit.editors[metadata.editor] = false;
}
});
missingEditors = _.uniq(missingEditors);
+
if (missingEditors.length === 0) {
callback();
return;
@@ -83,12 +78,15 @@
var loadEditorsAjax = Drupal.ajax({
url: Drupal.url('quickedit/attachments'),
- submit: { 'editors[]': missingEditors }
+ submit: {
+ 'editors[]': missingEditors
+ }
});
-
var realInsert = Drupal.AjaxCommands.prototype.insert;
+
loadEditorsAjax.commands.insert = function (ajax, response, status) {
_.defer(callback);
+
realInsert(ajax, response, status);
};
@@ -101,10 +99,12 @@
function hasFieldWithPermission(fieldIDs) {
for (var i = 0; i < fieldIDs.length; i++) {
var fieldID = fieldIDs[i];
+
if (metadata.get(fieldID, 'access') === true) {
return true;
}
}
+
return false;
}
@@ -116,6 +116,7 @@
entityID: contextualLink.entityID,
entityInstanceID: contextualLink.entityInstanceID
});
+
var fieldIDs = _.pluck(fields, 'fieldID');
if (fieldIDs.length === 0) {
@@ -127,11 +128,10 @@
el: contextualLink.region,
entityID: contextualLink.entityID,
entityInstanceID: contextualLink.entityInstanceID,
- id: contextualLink.entityID + '[' + contextualLink.entityInstanceID + ']',
+ id: "".concat(contextualLink.entityID, "[").concat(contextualLink.entityInstanceID, "]"),
label: Drupal.quickedit.metadata.get(contextualLink.entityID, 'label')
});
Drupal.quickedit.collections.entities.add(entityModel);
-
var entityDecorationView = new Drupal.quickedit.EntityDecorationView({
el: contextualLink.region,
model: entityModel
@@ -141,6 +141,7 @@
_.each(fields, function (field) {
initializeField(field.el, field.fieldID, contextualLink.entityID, contextualLink.entityInstanceID);
});
+
fieldsAvailableQueue = _.difference(fieldsAvailableQueue, fields);
var initContextualLink = _.once(function () {
@@ -154,7 +155,6 @@
});
loadMissingEditors(initContextualLink);
-
return true;
}
@@ -173,19 +173,20 @@
var metadata = Drupal.quickedit.metadata;
var fieldID = fieldElement.getAttribute('data-quickedit-field-id');
var entityID = extractEntityID(fieldID);
-
- var entityElementSelector = '[data-quickedit-entity-id="' + entityID + '"]';
+ var entityElementSelector = "[data-quickedit-entity-id=\"".concat(entityID, "\"]");
var $entityElement = $(entityElementSelector);
if (!$entityElement.length) {
- throw new Error('Quick Edit could not associate the rendered entity field markup (with [data-quickedit-field-id="' + fieldID + '"]) with the corresponding rendered entity markup: no parent DOM node found with [data-quickedit-entity-id="' + entityID + '"]. This is typically caused by the theme\'s template for this entity type forgetting to print the attributes.');
+ throw new Error("Quick Edit could not associate the rendered entity field markup (with [data-quickedit-field-id=\"".concat(fieldID, "\"]) with the corresponding rendered entity markup: no parent DOM node found with [data-quickedit-entity-id=\"").concat(entityID, "\"]. This is typically caused by the theme's template for this entity type forgetting to print the attributes."));
}
+
var entityElement = $(fieldElement).closest($entityElement);
if (entityElement.length === 0) {
var $lowestCommonParent = $entityElement.parents().has(fieldElement).first();
entityElement = $lowestCommonParent.find($entityElement);
}
+
var entityInstanceID = entityElement.get(0).getAttribute('data-quickedit-entity-instance-id');
if (!metadata.has(fieldID)) {
@@ -222,13 +223,12 @@
var entityModel = Drupal.quickedit.collections.entities.findWhere({
el: entityElement
});
+
if (entityModel) {
var contextualLinkView = entityModel.get('contextualLinkView');
contextualLinkView.undelegateEvents();
contextualLinkView.remove();
-
entityModel.get('entityDecorationView').remove();
-
entityModel.destroy();
}
@@ -238,7 +238,6 @@
contextualLinksQueue = _.filter(contextualLinksQueue, hasOtherRegion);
});
-
$context.find('[data-quickedit-field-id]').addBack('[data-quickedit-field-id]').each(function (index, fieldElement) {
Drupal.quickedit.collections.fields.chain().filter(function (fieldModel) {
return fieldModel.get('el') === fieldElement;
@@ -256,12 +255,13 @@
function fetchMissingMetadata(callback) {
if (fieldsMetadataQueue.length) {
var fieldIDs = _.pluck(fieldsMetadataQueue, 'fieldID');
+
var fieldElementsWithoutMetadata = _.pluck(fieldsMetadataQueue, 'el');
+
var entityIDs = _.uniq(_.pluck(fieldsMetadataQueue, 'entityID'), true);
entityIDs = _.difference(entityIDs, Drupal.quickedit.metadata.intersection(entityIDs));
fieldsMetadataQueue = [];
-
$.ajax({
url: Drupal.url('quickedit/metadata'),
type: 'POST',
@@ -284,8 +284,8 @@
Drupal.behaviors.quickedit = {
attach: function attach(context) {
$('body').once('quickedit-init').each(initQuickEdit);
-
var $fields = $(context).find('[data-quickedit-field-id]').once('quickedit');
+
if ($fields.length === 0) {
return;
}
@@ -293,15 +293,12 @@
$(context).find('[data-quickedit-entity-id]').once('quickedit').each(function (index, entityElement) {
processEntity(entityElement);
});
-
$fields.each(function (index, fieldElement) {
processField(fieldElement);
});
-
contextualLinksQueue = _.filter(contextualLinksQueue, function (contextualLink) {
return !initializeEntityContextualLink(contextualLink);
});
-
fetchMissingMetadata(function (fieldElementsWithFreshMetadata) {
_.each(fieldElementsWithFreshMetadata, processField);
@@ -316,18 +313,13 @@
}
}
};
-
Drupal.quickedit = {
app: null,
-
collections: {
entities: null,
-
fields: null
},
-
editors: {},
-
metadata: {
has: function has(fieldID) {
return storage.getItem(this._prefixFieldID(fieldID)) !== null;
@@ -340,22 +332,26 @@
return typeof key === 'undefined' ? metadata : metadata[key];
},
_prefixFieldID: function _prefixFieldID(fieldID) {
- return 'Drupal.quickedit.metadata.' + fieldID;
+ return "Drupal.quickedit.metadata.".concat(fieldID);
},
_unprefixFieldID: function _unprefixFieldID(fieldID) {
return fieldID.substring(26);
},
intersection: function intersection(fieldIDs) {
var prefixedFieldIDs = _.map(fieldIDs, this._prefixFieldID);
+
var intersection = _.intersection(prefixedFieldIDs, _.keys(sessionStorage));
+
return _.map(intersection, this._unprefixFieldID);
}
}
};
var permissionsHashKey = Drupal.quickedit.metadata._prefixFieldID('permissionsHash');
+
var permissionsHashValue = storage.getItem(permissionsHashKey);
var permissionsHash = drupalSettings.user.permissionsHash;
+
if (permissionsHashValue !== permissionsHash) {
if (typeof permissionsHash === 'string') {
_.chain(storage).keys().each(function (key) {
@@ -364,6 +360,7 @@
}
});
}
+
storage.setItem(permissionsHashKey, permissionsHash);
}
@@ -373,6 +370,7 @@
data.$region.once('quickedit');
processEntity(data.$region.get(0));
}
+
var contextualLink = {
entityID: data.$region.attr('data-quickedit-entity-id'),
entityInstanceID: data.$region.attr('data-quickedit-entity-instance-id'),