Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.7' into 1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
dew326 committed Jul 30, 2018
2 parents 754d2b3 + e76d702 commit d78e48a
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 13 deletions.
26 changes: 20 additions & 6 deletions Resources/public/js/alloyeditor/plugins/embed.js
Expand Up @@ -7,7 +7,8 @@ YUI.add('ez-alloyeditor-plugin-embed', function (Y) {
"use strict";

var IMAGE_TYPE_CLASS = 'ez-embed-type-image',
DATA_ALIGNMENT_ATTR = 'ezalign';
DATA_ALIGNMENT_ATTR = 'ezalign',
reloadEmbedTimeout = null;

if (CKEDITOR.plugins.get('ezembed')) {
return;
Expand Down Expand Up @@ -63,6 +64,8 @@ YUI.add('ez-alloyeditor-plugin-embed', function (Y) {
temp = new CKEDITOR.dom.documentFragment(wrapper.getDocument()),
instance;

editor.undoManager.lock();

temp.append(wrapper);
editor.widgets.initOn(element, this.name);
editor.eZ.appendElement(wrapper);
Expand Down Expand Up @@ -94,16 +97,27 @@ YUI.add('ez-alloyeditor-plugin-embed', function (Y) {
this._getEzConfigElement();
this.setWidgetContent('');
this._cancelEditEvents();
this.disableUndo();
this._attachUndoListener();
},

/**
* Disables the undo in CKEditor.
* Attaches event listener for the undo in CKEditor.
*
* @method disableUndo
* @method _attachUndoListener
* @private
*/
disableUndo: function() {
editor.setKeystroke(CKEDITOR.CTRL + 90, false);
_attachUndoListener: function () {
editor.on('afterCommandExec', function(e) {
if (e.data.name === 'undo') {
window.clearTimeout(reloadEmbedTimeout);

editor.fire('showLoading');

reloadEmbedTimeout = window.setTimeout(function() {
editor.fire('snapshotRestored');
}, 1000);
}
});
},

/**
Expand Down
6 changes: 5 additions & 1 deletion Resources/public/js/alloyeditor/plugins/yui3.js
Expand Up @@ -10,7 +10,11 @@ YUI.add('ez-alloyeditor-plugin-yui3', function (Y) {
return;
}

function cleanUpIds(editor) {
function cleanUpIds(editor, event) {
if (event.data.name === 'undo') {
return;
}

editor.undoManager.lock();
Array.prototype.forEach.call(
editor.element.$.querySelectorAll('[id]'),
Expand Down
22 changes: 22 additions & 0 deletions Resources/public/js/views/fields/ez-richtext-editview.js
Expand Up @@ -186,6 +186,28 @@ YUI.add('ez-richtext-editview', function (Y) {
nativeEd.on(evtName, Y.bind(this._forwardEditorEvent, this));
}, this);

nativeEd.on('showLoading', Y.bind(function () {
if (!nativeEd.undoManager.locked) {
nativeEd.undoManager.lock(false, true);
}

this.get('processors').forEach(function (info) {
info.processor.showLoading(this);
}, this);
}, this));

nativeEd.on('snapshotRestored', Y.bind(function () {
this.get('processors').forEach(function (info) {
info.processor.loadEmbeds(this);
}, this);
}, this));

this.after('unlockUndoManager', function () {
if (nativeEd.undoManager.locked) {
nativeEd.undoManager.unlock();
}
});

nativeEd.on('blur', valid);
nativeEd.on('focus', valid);
nativeEd.on('change', valid);
Expand Down
Expand Up @@ -51,6 +51,39 @@ YUI.add('ez-richtext-resolveembed', function (Y) {
}
};

/**
* Shows the loading spinner.
*
* @method showLoading
* @param {eZ.FieldView|eZ.FieldEditView} view
*/
ResolveEmbed.prototype.showLoading = function (view) {
var embeds = this._getEmbedList(view),
mapNodes = this._buildEmbedMapNodes(embeds);

if ( !Y.Object.isEmpty(mapNodes) ) {
this._renderLoadingEmbedElements(mapNodes);
}
};
/**
* Loads the embedded contents.
*
* @method loadEmbeds
* @param {eZ.FieldView|eZ.FieldEditView} view
*/
ResolveEmbed.prototype.loadEmbeds = function (view) {
var embeds = this._getEmbedList(view, true),
mapNodes = this._buildEmbedMapNodes(embeds);

if (!Object.keys(mapNodes).length) {
view.fire('unlockUndoManager');

return;
}

this._loadEmbeds(mapNodes, view);
};

/**
* Renders the embed from the embedStruct provided in the event parameters
* that triggered the process.
Expand All @@ -65,6 +98,8 @@ YUI.add('ez-richtext-resolveembed', function (Y) {
var embedNodes = mapNodes[embedStruct.contentInfo.get('contentId')];

if ( !embedNodes ) {
view.fire('unlockUndoManager');

return;
}

Expand All @@ -73,6 +108,8 @@ YUI.add('ez-richtext-resolveembed', function (Y) {
.setContent(embedStruct.contentInfo.get('name'));
}, this);
delete mapNodes[embedStruct.contentInfo.get('contentId')];

view.fire('unlockUndoManager');
};

/**
Expand All @@ -84,12 +121,12 @@ YUI.add('ez-richtext-resolveembed', function (Y) {
* @param {eZ.FieldView|eZ.FieldEditView} view
* @return {Y.NodeList}
*/
ResolveEmbed.prototype._getEmbedList = function (view) {
ResolveEmbed.prototype._getEmbedList = function (view, force) {
var embeds = view.get('container').all('[data-ezelement="ezembed"]'),
list = new Y.NodeList();

embeds.each(function (embed) {
if ( !this._getEmbedContent(embed) ) {
if ( !this._getEmbedContent(embed) || force ) {
list.push(embed);
}
}, this);
Expand Down Expand Up @@ -153,7 +190,7 @@ YUI.add('ez-richtext-resolveembed', function (Y) {
filter: {'ContentIdCriterion': Object.keys(mapNode).join(',')},
offset: 0,
},
callback: Y.bind(this._renderEmbed, this, mapNode),
callback: Y.bind(this._renderEmbed, this, mapNode, view),
});
};

Expand All @@ -166,11 +203,13 @@ YUI.add('ez-richtext-resolveembed', function (Y) {
* @param {Error|false} error
* @param {Array} results
*/
ResolveEmbed.prototype._renderEmbed = function (mapNode, error, results) {
ResolveEmbed.prototype._renderEmbed = function (mapNode, view, error, results) {
var localMapNode = Y.merge(mapNode);

if ( error ) {
this._renderNotLoadedEmbed(localMapNode);
view.fire('unlockUndoManager');

return;
}

Expand All @@ -181,6 +220,8 @@ YUI.add('ez-richtext-resolveembed', function (Y) {
delete localMapNode[content.get('contentId')];
}, this);
this._renderNotLoadedEmbed(localMapNode);

view.fire('unlockUndoManager');
};

/**
Expand Down
Expand Up @@ -25,12 +25,12 @@ YUI.add('ez-richtext-resolveimage', function (Y) {

Y.extend(ResolveImage, Y.eZ.RichTextResolveEmbed);

ResolveImage.prototype._getEmbedList = function (view) {
ResolveImage.prototype._getEmbedList = function (view, force) {
var embeds = view.get('container').all('.ez-embed-type-image[data-ezelement="ezembed"]'),
list = new Y.NodeList();

embeds.each(function (embed) {
if ( !this._getEmbedContent(embed) ) {
if ( !this._getEmbedContent(embed) || force ) {
list.push(embed);
}
}, this);
Expand All @@ -45,6 +45,8 @@ YUI.add('ez-richtext-resolveimage', function (Y) {
imageField;

if ( !embedNodes ) {
view.fire('unlockUndoManager');

return;
}

Expand All @@ -57,6 +59,8 @@ YUI.add('ez-richtext-resolveimage', function (Y) {
this._loadVariation(view, content, imageField, node);
}, this);
delete mapNodes[contentId];

view.fire('unlockUndoManager');
};

ResolveImage.prototype._loadEmbeds = function (mapNode, view) {
Expand All @@ -77,6 +81,8 @@ YUI.add('ez-richtext-resolveimage', function (Y) {

if ( error ) {
this._renderNotLoadedEmbed(localMapNode);
view.fire('unlockUndoManager');

return;
}

Expand All @@ -101,6 +107,8 @@ YUI.add('ez-richtext-resolveimage', function (Y) {
delete localMapNode[contentId];
}, this);
this._renderNotLoadedEmbed(localMapNode);

view.fire('unlockUndoManager');
};

ResolveImage.prototype._setEmptyImage = function (embedNode) {
Expand Down

0 comments on commit d78e48a

Please sign in to comment.