load file to edit async to prevent browser page caching issues

This commit is contained in:
Kyle Drake 2016-07-19 14:40:22 -07:00
parent 83ee577a14
commit 21299e3abc

View file

@ -92,7 +92,7 @@
<div class="row editor"> <div class="row editor">
<div class="col col-100"> <div class="col col-100">
<div id="editor"><%==encoding_fix(@file_data) %></div> <div id="editor"><h3>Loading...</h3></div>
</div> </div>
</div> </div>
@ -154,35 +154,41 @@
var editor = {} var editor = {}
$(document).ready(function() { $.get('/site_files/download/<%= @filename %>', function(resp) {
editor = ace.edit("editor") $(document).ready(function() {
setTheme() $.get('/site_files/download/<%= @filename %>', function(resp) {
<% if @ace_mode %> editor = ace.edit("editor")
editor.getSession().setMode("ace/mode/<%= @ace_mode %>") setTheme()
<% end %> <% if @ace_mode %>
editor.getSession().setTabSize(2) editor.getSession().setMode("ace/mode/<%= @ace_mode %>")
editor.getSession().setUseWrapMode(true) <% end %>
editor.setFontSize(14) editor.getSession().setTabSize(2)
editor.setShowPrintMargin(false) editor.getSession().setUseWrapMode(true)
editor.setOptions({ editor.setFontSize(14)
maxLines: Infinity, editor.setShowPrintMargin(false)
autoScrollEditorIntoView: true editor.setOptions({
}) maxLines: Infinity,
autoScrollEditorIntoView: true
})
// Disable autocomplete // Disable autocomplete
editor.setBehavioursEnabled(false) editor.setBehavioursEnabled(false)
editor.on('change', function(obj) { editor.setValue(resp, -1)
$('a#saveButton,a#saveAndExitButton').css('opacity', 1)
unsavedChanges = true
})
editor.commands.addCommand({ editor.on('change', function(obj) {
name: 'saveCommand', $('a#saveButton,a#saveAndExitButton').css('opacity', 1)
bindKey: {win: 'Ctrl-S', mac: 'Command-S'}, unsavedChanges = true
exec: function(editor) { })
saveTextFile(false)
} editor.commands.addCommand({
name: 'saveCommand',
bindKey: {win: 'Ctrl-S', mac: 'Command-S'},
exec: function(editor) {
saveTextFile(false)
}
})
})
}) })
}) })