File tree Expand file tree Collapse file tree 5 files changed +58
-9
lines changed
Expand file tree Collapse file tree 5 files changed +58
-9
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,18 @@ $(document).on('turbo-migration:load', function() {
2525 }
2626} ) ;
2727
28+ $ ( document ) . one ( 'turbo-migration:load' , function ( ) {
29+ if ( $ . isController ( 'community_solutions' ) && $ ( '#community-solution-editor' ) . isPresent ( ) ) {
30+ $ ( document ) . one ( 'turbo:visit' , unloadEditorHandler ) ;
31+ $ ( window ) . one ( 'beforeunload' , unloadEditorHandler ) ;
32+ }
33+ } ) ;
34+
35+ function unloadEditorHandler ( ) {
36+ CodeOceanEditor . autosaveIfChanged ( ) ;
37+ CodeOceanEditor . unloadEditor ( ) ;
38+ }
39+
2840function submitCode ( event ) {
2941 const button = $ ( event . target ) || $ ( '#submit' ) ;
3042 this . newSentryTransaction ( button , async ( ) => {
@@ -35,10 +47,7 @@ function submitCode(event) {
3547 if ( ! submission ) return ;
3648 if ( ! submission . redirect ) return ;
3749
38- this . autosaveIfChanged ( ) ;
39- await this . stopCode ( event ) ;
40- this . editors = [ ] ;
41- Turbo . cache . clear ( ) ;
50+ unloadEditorHandler ( ) ;
4251 Turbo . visit ( submission . redirect ) ;
4352 } ) ;
4453}
Original file line number Diff line number Diff line change @@ -1111,9 +1111,14 @@ var CodeOceanEditor = {
11111111 unloadEverything : function ( ) {
11121112 App . synchronized_editor ?. disconnect ( ) ;
11131113 this . autosaveIfChanged ( ) ;
1114- this . cacheEditorContent ( ) ;
1114+ this . unloadEditor ( ) ;
11151115 this . teardownEventHandlers ( ) ;
1116- this . destroyEditors ( ) ;
1116+ } ,
1117+
1118+ unloadEditor : function ( ) {
1119+ $ ( document ) . off ( 'theme:change:ace' ) ;
1120+ CodeOceanEditor . cacheEditorContent ( ) ;
1121+ CodeOceanEditor . destroyEditors ( ) ;
11171122 } ,
11181123
11191124 cacheEditorContent : function ( ) {
Original file line number Diff line number Diff line change @@ -34,6 +34,17 @@ $(document).on('turbo-migration:load', function () {
3434 session . setTabSize ( element_selector . data ( 'indent-size' ) ) ;
3535 session . setUseSoftTabs ( true ) ;
3636 session . setUseWrapMode ( true ) ;
37+
38+ function unloadTeacherEditor ( ) {
39+ $ ( document ) . off ( 'theme:change:ace' ) ;
40+ const value = editor . getValue ( ) ;
41+ editor . destroy ( ) ;
42+ // "Restore" the editor's content to the original element for caching.
43+ textarea . val = value ;
44+ }
45+
46+ $ ( document ) . one ( 'turbo:visit' , unloadTeacherEditor ) ;
47+ $ ( window ) . one ( 'beforeunload' , unloadTeacherEditor ) ;
3748 }
3849
3950 const handleAceThemeChangeEvent = function ( _event ) {
@@ -42,12 +53,11 @@ $(document).on('turbo-migration:load', function () {
4253 } . bind ( this ) ) ;
4354 } ;
4455
45- $ ( document ) . on ( 'theme:change:ace' , handleAceThemeChangeEvent . bind ( this ) ) ;
46-
4756 var initializeEditors = function ( ) {
4857 // initialize ace editors for all code textareas in the dom except the last one. The last one is the dummy area for new files, which is cloned when needed.
4958 // this one must NOT! be initialized.
5059 $ ( '.editor:not(:last)' ) . each ( initializeEditor )
60+ $ ( document ) . on ( 'theme:change:ace' , handleAceThemeChangeEvent . bind ( this ) ) ;
5161 } ;
5262
5363 var addFileForm = function ( event ) {
Original file line number Diff line number Diff line change @@ -394,4 +394,18 @@ $(document).on('turbo-migration:load', function () {
394394 showPermanent : response . status === 422 ,
395395 } ) ;
396396 }
397+
398+ function unloadRfCEditors ( ) {
399+ $ ( document ) . off ( 'theme:change:ace' ) ;
400+ $ ( '.editor' ) . each ( function ( _ , editor ) {
401+ const aceEditor = ace . edit ( editor ) ;
402+ const value = aceEditor . getValue ( ) ;
403+ aceEditor . destroy ( ) ;
404+ // "Restore" the editor's content to the original element for caching.
405+ editor . textContent = value ;
406+ } ) ;
407+ }
408+
409+ $ ( document ) . one ( 'turbo:visit' , unloadRfCEditors ) ;
410+ $ ( window ) . one ( 'beforeunload' , unloadRfCEditors ) ;
397411} ) ;
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ $(document).on('turbo-migration:load', function(event) {
110110
111111 slider . on ( 'change' , onSliderChange ) ;
112112
113- stopReplay = function ( ) {
113+ const stopReplay = function ( ) {
114114 clearInterval ( playInterval ) ;
115115 playInterval = undefined ;
116116 playButton . find ( 'span.fa-solid' ) . removeClass ( 'fa-pause' ) . addClass ( 'fa-play' )
@@ -145,6 +145,17 @@ $(document).on('turbo-migration:load', function(event) {
145145 // Start with newest submission
146146 slider . val ( submissions . length - 1 ) ;
147147 onSliderChange ( ) ;
148+
149+ const unloadSubmissionStatistics = function ( ) {
150+ if ( playInterval ) {
151+ stopReplay ( ) ;
152+ }
153+ $ ( document ) . off ( 'theme:change:ace' ) ;
154+ editor . destroy ( ) ;
155+ }
156+
157+ $ ( document ) . on ( 'turbo:visit' , unloadSubmissionStatistics ) ;
158+ $ ( window ) . on ( 'beforeunload' , unloadSubmissionStatistics ) ;
148159 }
149160
150161} ) ;
You can’t perform that action at this time.
0 commit comments