Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toolbox on top of each richeditor widget #212

Merged
4 changes: 4 additions & 0 deletions assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ html.is-disabled body {
align-items: center !important;
}

.uie-flex-cross-right {
justify-content: flex-end !important;
}

.uie-flex-main-between {
justify-content: space-between !important;
}
Expand Down
72 changes: 67 additions & 5 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ global.MonsieurBizRichEditorManager = class {
initInterface() {
this.initUiElementsInterface();
this.initUiPanelsInterface();
this.initUiToolsInterface();

document.dispatchEvent(new CustomEvent('mbiz:rich-editor:init-interface-complete', {
'detail': {'editorManager': this}
}));
Expand All @@ -252,6 +254,24 @@ global.MonsieurBizRichEditorManager = class {
}.bind(this));
}

initUiToolsInterface() {
const copyAllButton = this.container.querySelector('.js-uie-tools-copy-all');
const pasteAllButton = this.container.querySelector('.js-uie-tools-paste-all');
const trashAllButton = this.container.querySelector('.js-uie-tools-trash-all');

copyAllButton && copyAllButton.addEventListener('click', e => {
this.saveUiElementsToClipboard(e.currentTarget);
});

pasteAllButton && pasteAllButton.addEventListener('click', e => {
this.pasteUiElementsFromClipboard();
});

trashAllButton && trashAllButton.addEventListener('click', e => {
this.resetUiElements();
});
}

initUiPanelsInterface() {
let panelsWrapper = document.createElement('div');
panelsWrapper.innerHTML = Mustache.render(this.config.panelsHtml, { uid: this.config.uid });
Expand Down Expand Up @@ -324,7 +344,7 @@ global.MonsieurBizRichEditorManager = class {
);
});
// Disabled?
if (!this.isClipboardEmpty()) {
if (!this.isClipboardEmpty('monsieurBizRichEditorElementClipboard')) {
actions.querySelector('.js-uie-paste').classList.remove('disabled');
}

Expand Down Expand Up @@ -645,19 +665,61 @@ global.MonsieurBizRichEditorManager = class {
req.send(data);
}

isClipboardEmpty() {
const clipboard = window.localStorage.getItem('monsieurBizRichEditorClipboard');
isClipboardEmpty(clipboardKey) {
const clipboard = window.localStorage.getItem(clipboardKey);
return null === clipboard || '' === clipboard;
}

resetUiElements() {
if (this.uiElements.length === 0) {
return;
}

this.loadUiConfirmationModal(() => { this.initUiElements([], () => { this.write(); }) })
}

loadUiConfirmationModal(callback) {
const modal = document.querySelector('#monsieurbiz-rich-editor-confirmation-modal');
const confirmButton = modal.querySelector('#monsieurbiz-rich-editor-confirmation-button');

confirmButton.addEventListener('click', () => {
callback();
})

$(modal).modal('show');
}

saveUiElementsToClipboard(button) {
window.localStorage.setItem('monsieurBizRichEditorElementsClipboard', JSON.stringify(this.uiElements));

const originalText = button.dataset.tooltip;
button.dataset.tooltip = button.dataset.alternateText;
window.setTimeout(function () {
button.dataset.tooltip = originalText;
}, 1000);
}

pasteUiElementsFromClipboard() {
const clipboard = window.localStorage.getItem('monsieurBizRichEditorElementsClipboard');
if (clipboard !== null) {
const pastedUiElement = JSON.parse(clipboard);

if (this.uiElements.length > 0) {
this.loadUiConfirmationModal(() => { this.initUiElements(pastedUiElement, () => { this.write(); })})
} else {
this.initUiElements(pastedUiElement, () => { this.write(); });
}
}
}

saveUiElementToClipboard(uiElement, callback) {
window.localStorage.setItem('monsieurBizRichEditorClipboard', JSON.stringify(uiElement));
window.localStorage.setItem('monsieurBizRichEditorElementClipboard', JSON.stringify(uiElement));
callback();
document.dispatchEvent(new CustomEvent('mbiz:rich-editor:uielement:copied', {}));
}

pasteUiElementFromClipboard(futurePosition) {
const clipboard = window.localStorage.getItem('monsieurBizRichEditorClipboard');
const clipboard = window.localStorage.getItem('monsieurBizRichEditorElementClipboard');
if (null !== clipboard) {
const pastedUiElement = JSON.parse(clipboard);
const manager = this;
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/public/css/rich-editor-css.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading