Skip to content

Commit c9f798e

Browse files
authored
Classic Editor: Fix initial state (#118)
1 parent e835ee8 commit c9f798e

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/classic-editor/index.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,11 @@ import initLoader from '../lib/loader';
1414
initLoader().then( ( monaco ) => {
1515
let isMonacoEditorEnabled = false;
1616

17-
const isEditorEnabled = null !== document.getElementById( 'content' );
18-
const isVisualEditorEnabled =
19-
null !== document.getElementById( 'content-tmce' ) &&
20-
null !== document.getElementById( 'content-html' );
17+
const isEditorEnabled = !! document.getElementById( 'content' );
2118

22-
const cookieHtml = document.cookie.indexOf( 'editor%3Dhtml' );
23-
const cookieTinyMce = document.cookie.indexOf( 'editor%3Dtinymce' );
24-
const isVisualEditMode =
25-
( -1 === cookieHtml && -1 !== cookieTinyMce ) ||
26-
( -1 !== cookieHtml && -1 !== cookieTinyMce && cookieTinyMce > cookieHtml );
19+
if ( ! isEditorEnabled ) {
20+
return;
21+
}
2722

2823
const tabTmce = document.getElementById( 'content-tmce' );
2924
const tabHtml = document.getElementById( 'content-html' );
@@ -308,20 +303,21 @@ initLoader().then( ( monaco ) => {
308303
};
309304

310305
// Initialize
311-
if ( ! isEditorEnabled ) {
312-
return;
313-
}
314-
315306
runObserve();
316307

317-
if ( ! isVisualEditorEnabled ) {
318-
runEditor();
319-
replaceIndentButton.style.display = 'inline-block';
320-
} else if ( isVisualEditMode ) {
321-
tabHtml.onclick = toHtml;
308+
const isVisualEditorEnabled = document
309+
.getElementById( 'wp-content-wrap' )
310+
.classList.contains( 'tmce-active' );
311+
312+
if ( isVisualEditorEnabled ) {
313+
if ( tabHtml ) {
314+
tabHtml.onclick = toHtml;
315+
}
322316
} else {
323317
runEditor();
324318
replaceIndentButton.style.display = 'inline-block';
325-
tabTmce.onclick = toVisual;
319+
if ( tabTmce ) {
320+
tabTmce.onclick = toVisual;
321+
}
326322
}
327323
} );

0 commit comments

Comments
 (0)