Skip to content

Commit f95fb64

Browse files
committed
WYSWIYG: Improved use of object tags to embed content
- 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
1 parent 493d802 commit f95fb64

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

resources/js/wysiwyg/toolbars.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,34 @@ function registerLinkContextToolbar(editor) {
6060
function registerImageContextToolbar(editor) {
6161
editor.ui.registry.addContextToolbar('imagecontexttoolbar', {
6262
predicate(node) {
63-
return node.closest('img') !== null;
63+
return node.closest('img') !== null && !node.hasAttribute('data-mce-object');
6464
},
6565
position: 'node',
6666
scope: 'node',
6767
items: 'image',
6868
});
6969
}
7070

71+
/**
72+
* @param {Editor} editor
73+
*/
74+
function registerObjectContextToolbar(editor) {
75+
editor.ui.registry.addContextToolbar('objectcontexttoolbar', {
76+
predicate(node) {
77+
return node.closest('img') !== null && node.hasAttribute('data-mce-object');
78+
},
79+
position: 'node',
80+
scope: 'node',
81+
items: 'media',
82+
});
83+
}
84+
7185
/**
7286
* @param {Editor} editor
7387
*/
7488
export function registerAdditionalToolbars(editor) {
7589
registerPrimaryToolbarGroups(editor);
7690
registerLinkContextToolbar(editor);
7791
registerImageContextToolbar(editor);
92+
registerObjectContextToolbar(editor);
7893
}

resources/sass/_content.scss

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
margin-left: auto;
3333
margin-right: auto;
3434
}
35-
img {
36-
max-width: 100%;
37-
height:auto;
38-
}
3935
h1, h2, h3, h4, h5, h6, pre {
4036
clear: left;
4137
}
@@ -119,6 +115,16 @@
119115
}
120116
}
121117

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

0 commit comments

Comments
 (0)