Skip to content

Commit 6059985

Browse files
committed
Polishing Dialog fixes
* returned more accidentally removed code * relocated haxies into init callback -> got rid of fragile setTimeout haxies
1 parent 7836696 commit 6059985

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

src/main/resources/META-INF/resources/frontend/tinymceConnector.js

+31-19
Original file line numberDiff line numberDiff line change
@@ -67,49 +67,61 @@ window.Vaadin.Flow.tinymceConnector = {
6767
if(!enabled) {
6868
baseconfig['readonly'] = true;
6969
}
70+
7071

7172
baseconfig['setup'] = function(ed) {
72-
c.$connector.editor = ed;
73+
c.$connector.editor = ed;
7374

74-
ed.on('change', function(e) {
75+
ed.on('init', e => {
76+
if(c.$connector.isInDialog()) {
77+
// This is inside a shadowroot (Dialog in Vaadin)
78+
// and needs some hacks to make this nagigateable with keyboard
79+
if(c.tabIndex < 0) {
80+
// make the wrapping element also focusable
81+
c.setAttribute("tabindex", 0);
82+
}
83+
// on focus to wrapping element, pass forward to editor
84+
c.addEventListener("focus", e=> {
85+
ed.focus();
86+
});
87+
// Move aux element as child from body to element to fix menus in modal Dialog
88+
const aux = document.getElementsByClassName('tox-tinymce-aux')[0];
89+
aux.parentElement.removeChild(aux);
90+
// Fix to allow menu grow outside Dialog
91+
aux.style.position = 'absolute';
92+
c.appendChild(aux);
93+
}
94+
});
95+
96+
ed.on('change', function(e) {
7597
// console.log("TMCE change");
7698
const event = new Event("tchange");
7799
event.htmlString = ed.getContent();
78100
c.dispatchEvent(event);
79-
});
80-
ed.on('blur', function(e) {
101+
});
102+
ed.on('blur', function(e) {
81103
//console.log("TMCE blur");
82104
const event = new Event("tblur");
83105
c.dispatchEvent(event);
84-
});
85-
ed.on('focus', function(e) {
106+
});
107+
ed.on('focus', function(e) {
86108
//console.log("TMCE focus");
87109
const event = new Event("tfocus");
88110
c.dispatchEvent(event);
89-
});
111+
});
90112

91-
ed.on('input', function(e) {
113+
ed.on('input', function(e) {
92114
//console.log("TMCE input");
93115
const event = new Event("tchange");
94116
event.htmlString = ed.getContent();
95117
c.dispatchEvent(event);
96-
});
118+
});
97119

98120
};
99121

100122
ta.innerHTML = initialContent;
101123

102124
tinymce.init(baseconfig);
103125

104-
// Move aux element as child to fix Dialog issues, TinyMCE is slow
105-
// to init, thus timeout needed
106-
setTimeout(() => {
107-
const aux = document.getElementsByClassName('tox-tinymce-aux')[0];
108-
aux.parentElement.removeChild(aux);
109-
// Fix to allow menu grow outside Dialog
110-
aux.style.position = 'absolute';
111-
c.appendChild(aux);
112-
}, 500);
113-
114126
}
115127
}

0 commit comments

Comments
 (0)