Skip to content

Commit

Permalink
WYSWIYG: Improved use of object tags to embed content
Browse files Browse the repository at this point in the history
- Prevented image toolbars showing for objects embeds due to tinymce
  image placeholder, and added media toolbar.
- Fixed height of object embed placeholder being forced to auto
  when in the editor, allowing height attributed to be properly
  reflected as it would on normal page view.

Closes #4974
  • Loading branch information
ssddanbrown committed May 1, 2024
1 parent 493d802 commit f95fb64
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
17 changes: 16 additions & 1 deletion resources/js/wysiwyg/toolbars.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,34 @@ function registerLinkContextToolbar(editor) {
function registerImageContextToolbar(editor) {
editor.ui.registry.addContextToolbar('imagecontexttoolbar', {
predicate(node) {
return node.closest('img') !== null;
return node.closest('img') !== null && !node.hasAttribute('data-mce-object');
},
position: 'node',
scope: 'node',
items: 'image',
});
}

/**
* @param {Editor} editor
*/
function registerObjectContextToolbar(editor) {
editor.ui.registry.addContextToolbar('objectcontexttoolbar', {
predicate(node) {
return node.closest('img') !== null && node.hasAttribute('data-mce-object');
},
position: 'node',
scope: 'node',
items: 'media',
});
}

/**
* @param {Editor} editor
*/
export function registerAdditionalToolbars(editor) {
registerPrimaryToolbarGroups(editor);
registerLinkContextToolbar(editor);
registerImageContextToolbar(editor);
registerObjectContextToolbar(editor);
}
14 changes: 10 additions & 4 deletions resources/sass/_content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
margin-left: auto;
margin-right: auto;
}
img {
max-width: 100%;
height:auto;
}
h1, h2, h3, h4, h5, h6, pre {
clear: left;
}
Expand Down Expand Up @@ -119,6 +115,16 @@
}
}

// This is seperated out so we can target it out-of-editor by default
// and use advanced (:not) syntax, not supported by things like PDF gen,
// to target in-editor scenarios to handle edge-case of TinyMCE using an
// image for data placeholders where we'd want height attributes to take effect.
body .page-content img,
.page-content img:not([data-mce-object]) {
max-width: 100%;
height:auto;
}

/**
* Callouts
*/
Expand Down

0 comments on commit f95fb64

Please sign in to comment.