kopia lustrzana https://github.com/wagtail/wagtail
Add Draftail init fallback for StreamField/InlinePanel templated fields. Fix #4295
rodzic
f6bcfbf31e
commit
c62c58c492
|
@ -50,7 +50,9 @@ export const wrapWagtailIcon = type => {
|
|||
const initEditor = (selector, options, currentScript) => {
|
||||
// document.currentScript is not available in IE11. Use a fallback instead.
|
||||
const context = currentScript ? currentScript.parentNode : document.body;
|
||||
const field = context.querySelector(selector);
|
||||
// If the field is not in the current context, look for it in the whole body.
|
||||
// Fallback for sequence.js jQuery eval-ed scripts running in document.head.
|
||||
const field = context.querySelector(selector) || document.body.querySelector(selector);
|
||||
|
||||
const editorWrapper = document.createElement('div');
|
||||
editorWrapper.className = 'Draftail-Editor__wrapper';
|
||||
|
|
|
@ -88,6 +88,18 @@ describe('Draftail', () => {
|
|||
|
||||
expect(document.querySelector('[name="last"]').draftailEditor).toBeDefined();
|
||||
});
|
||||
|
||||
it('uses fallback document.body when currentScript context is wrong', () => {
|
||||
window.draftail = draftail;
|
||||
document.body.innerHTML = `
|
||||
<input id="description" value="null" />
|
||||
<div>
|
||||
<script>window.draftail.initEditor('#description', {}, document.currentScript);</script>
|
||||
</div>
|
||||
`;
|
||||
|
||||
expect(document.querySelector('#description').draftailEditor).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue