Last active
February 14, 2018 20:27
-
-
Save ClassCubeGists/a3f4ec3c73618a2f3b763b95e3eabc3c to your computer and use it in GitHub Desktop.
Example code for blocking browser refreshes when using the Ace editor. Written for a blog post at https://clsc.be/1w
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var edit = ace.edit('editor'); | |
edit.commands.addCommand({ | |
name: "blockCtrlR", | |
exec: function () { | |
editor.promptRefresh(false); | |
}, | |
bindKey: {mac: "cmd-r", win: "ctrl-r"} | |
}); | |
edit.commands.addCommand({ | |
name: 'blockRefreshF5', | |
exec: function () { | |
editor.promptRefresh(false); | |
}, | |
bindKey: {mac: 'f5', win: 'f5'} | |
}); | |
edit.commands.addCommand({ | |
name: 'blockHardRefresh', | |
exec: function () { | |
editor.promptRefresh(true); | |
}, | |
bindKey: {mac: 'cmd-f5', win: 'ctrl-f5'} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function promptRefresh (force_reload) { | |
bootbox.confirm({ | |
title: "Refresh Page?", | |
message: "Are you sure you want to refresh this page? You may lose any work since the last time you tested your code.", | |
callback: function (result) { | |
if (result) { | |
window.location.reload(force_reload); | |
} else { | |
/* Set focus back to the editor */ | |
ace.edit('editor').focus(); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment