Skip to content

Instantly share code, notes, and snippets.

@ClassCubeGists
Last active February 14, 2018 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClassCubeGists/a3f4ec3c73618a2f3b763b95e3eabc3c to your computer and use it in GitHub Desktop.
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
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'}
});
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