← All changes
|
assets/src/js/frontend/course-builder/builder-popup.js
+34
-12
4.3.7
→
4.4.9
View file →
| @@ -1001,20 +1001,51 @@ | ||
| 1001 | 1001 | |
| 1002 | 1002 | const editorId = `${ this.currentType }_description_editor`; |
| 1003 | 1003 | const editor = tinymce.get( editorId ); |
| 1004 | 1004 | |
| 1005 | - if ( editor ) { | |
| 1005 | + if ( editor && ! this.isEditorInCodeMode( editorId ) ) { | |
| 1006 | 1006 | editor.save(); |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | // Sync additional editors |
| 1010 | 1010 | tinymce.editors.forEach( ( ed ) => { |
| 1011 | - if ( ed.id?.includes( this.currentType ) ) { | |
| 1011 | + if ( ed.id?.includes( this.currentType ) && ! this.isEditorInCodeMode( ed.id ) ) { | |
| 1012 | 1012 | ed.save(); |
| 1013 | 1013 | } |
| 1014 | 1014 | } ); |
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | + isEditorInCodeMode( editorId ) { | |
| 1018 | + const wrapper = | |
| 1019 | + document.getElementById( `wp-${ editorId }-wrap` ) || | |
| 1020 | + document.getElementById( `${ editorId }-wrap` ); | |
| 1021 | + if ( wrapper?.classList.contains( 'html-active' ) ) { | |
| 1022 | + return true; | |
| 1023 | + } | |
| 1024 | + | |
| 1025 | + const editor = typeof tinymce !== 'undefined' ? tinymce.get( editorId ) : null; | |
| 1026 | + | |
| 1027 | + return !! ( editor?.isHidden && editor.isHidden() ); | |
| 1028 | + } | |
| 1029 | + | |
| 1030 | + getEditorContent( editorId, root = document ) { | |
| 1031 | + const textarea = | |
| 1032 | + root?.querySelector?.( `#${ editorId }` ) || document.getElementById( editorId ); | |
| 1033 | + | |
| 1034 | + if ( this.isEditorInCodeMode( editorId ) ) { | |
| 1035 | + return textarea ? textarea.value : ''; | |
| 1036 | + } | |
| 1037 | + | |
| 1038 | + if ( typeof tinymce !== 'undefined' ) { | |
| 1039 | + const editor = tinymce.get( editorId ); | |
| 1040 | + if ( editor ) { | |
| 1041 | + return editor.getContent(); | |
| 1042 | + } | |
| 1043 | + } | |
| 1044 | + | |
| 1045 | + return textarea ? textarea.value : ''; | |
| 1046 | + } | |
| 1047 | + | |
| 1017 | 1048 | /** |
| 1018 | 1049 | * Destroy specific TinyMCE instance |
| 1019 | 1050 | */ |
| 1020 | 1051 | destroyTinyMCE( editorId ) { |
| @@ -1586,18 +1617,9 @@ | ||
| 1586 | 1617 | } |
| 1587 | 1618 | |
| 1588 | 1619 | // Get description |
| 1589 | 1620 | const editorId = `${ this.currentType }_description_editor`; |
| 1590 | - let descContent = ''; | |
| 1591 | - | |
| 1592 | - if ( typeof tinymce !== 'undefined' && tinymce.get( editorId ) ) { | |
| 1593 | - descContent = tinymce.get( editorId ).getContent(); | |
| 1594 | - } else { | |
| 1595 | - const descTextarea = popup.querySelector( `#${ editorId }` ); | |
| 1596 | - if ( descTextarea ) { | |
| 1597 | - descContent = descTextarea.value; | |
| 1598 | - } | |
| 1599 | - } | |
| 1621 | + const descContent = this.getEditorContent( editorId, popup ); | |
| 1600 | 1622 | |
| 1601 | 1623 | data[ `${ this.currentType }_description` ] = descContent; |
| 1602 | 1624 | |
| 1603 | 1625 | // Get form settings |