diff --git a/components/filemanager/init.js b/components/filemanager/init.js index 77bf518..09423cb 100755 --- a/components/filemanager/init.js +++ b/components/filemanager/init.js @@ -15,14 +15,15 @@ codiad.filemanager = { - + + auto_reload: false, clipboard: '', - controller: 'components/filemanager/controller.php', dialog: 'components/filemanager/dialog.php', dialogUpload: 'components/filemanager/dialog_upload.php', - - init: function() { + preview: null, + + init: async function() { this.noAudio = [ //Audio @@ -58,6 +59,33 @@ // Initialize node listener this.nodeListener(); + this.auto_reload = ( await codiad.settings.get_option( "codiad.filemanager.auto_reload_preview" ) == "true" ); + + console.log( this.auto_reload ); + + amplify.subscribe( 'settings.save', async function() { + + let option = ( await codiad.settings.get_option( "codiad.filemanager.auto_reload_preview" ) == "true" ); + if( option != codiad.filemanager.auto_reload ) { + + //codiad.auto_save.reload_interval(); + window.location.reload(); + } + }); + + /* Subscribe to know when a file become active. */ + amplify.subscribe( 'active.onFocus', async function( path ) { + + let _this = codiad.filemanager; + let editor = codiad.editor.getActive(); + + if( _this.auto_reload && editor !== null ) { + + _this.preview.addEventListener( "beforeunload", _this.closePreview ); + codiad.editor.getActive().addEventListener( "change", _this.refreshPreview ); + } + }); + // Load uploader $.loadScript("components/filemanager/upload_scripts/jquery.ui.widget.js", true); $.loadScript("components/filemanager/upload_scripts/jquery.iframe-transport.js", true); @@ -440,17 +468,50 @@ ////////////////////////////////////////////////////////////////// openInBrowser: function(path) { + + let _this = this; + $.ajax({ url: this.controller + '?action=open_in_browser&path=' + encodeURIComponent(path), success: function(data) { var openIBResponse = codiad.jsend.parse(data); if (openIBResponse != 'error') { - window.open(openIBResponse.url, '_newtab'); + + _this.preview = window.open( openIBResponse.url, '_newtab' ); + + let editor = codiad.editor.getActive(); + + if( _this.auto_reload && editor !== null ) { + + _this.preview.addEventListener( "beforeunload", _this.closePreview ); + codiad.editor.getActive().addEventListener( "change", _this.refreshPreview ); + } + + } }, async: false }); }, + + closePreview: function( event ) { + + _this = codiad.filemanager; + _this.preview = null; + }, + + refreshPreview: function( event ) { + + _this = codiad.filemanager; + + if( _this.preview == null ) { + + return; + } + + _this.preview.location.reload(); + }, + openInModal: function(path) { let type = ""; diff --git a/components/settings/dialog.php b/components/settings/dialog.php index 4712ca7..942dc05 100755 --- a/components/settings/dialog.php +++ b/components/settings/dialog.php @@ -134,11 +134,14 @@ codiad.editor.setOverScroll(val); break; case "codiad.editor.autocomplete": - var bool_val = (val == "true"); + var bool_val = (val == "true"); codiad.editor.setLiveAutocomplete(bool_val) break; case "codiad.settings.autosave": var bool_val = (val == "true"); + break; + case "codiad.filemanager.auto_reload_preview": + var bool_val = (val == "true"); break; } } @@ -161,7 +164,6 @@ /* Notify listeners */ amplify.publish( 'settings.dialog.save', null ); codiad.settings.save( settings ); - codiad.modal.unload(); } - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + +
- -
- -
- -
+ +
+ +
+ +
+ +
diff --git a/js/modal.js b/js/modal.js index 243725e..6147d08 100755 --- a/js/modal.js +++ b/js/modal.js @@ -10,8 +10,7 @@ hide_loading: function() { - let loading = document.getElementById( 'modal' ).getElementsByClassName( 'loading' )[0]; - loading.style.display = "none"; + $('#modal-content .loading').css( "display", "none" ); }, hideOverlay: function() { @@ -55,8 +54,7 @@ show_loading: function() { - let loading = document.getElementById( 'modal' ).getElementsByClassName( 'loading' )[0]; - loading.style.display = "inline-block"; + $('#modal-content .loading').css( "display", "inline-block" ); }, unload: function() {