Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created September 5, 2019 09:50
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 bjoerntx/861a54b2622ef81e5df182287a386927 to your computer and use it in GitHub Desktop.
Save bjoerntx/861a54b2622ef81e5df182287a386927 to your computer and use it in GitHub Desktop.
TXTextControl.addEventListener("textControlLoaded", function (e) {
// disable the loading progress dialog
TXTextControl.isLoadingDialogEnabled = false;
// restore the document
restoreDocument();
// set auto save to 500 milliseconds
var intervalAutoSave = setInterval(autoSaveDocument, 500);
});
TXTextControl.addEventListener("webSocketClosed", function (e) {
// reload, if connection is lost
location.reload();
});
TXTextControl.addEventListener("documentLoaded", function (e) {
$("#txReconnectMsg").hide(); // show dialog
});
function autoSaveDocument() {
// store the document in the session storage
// which is shared over all browser tabs (complete session)
TXTextControl.saveDocument(
TXTextControl.streamType.InternalUnicodeFormat, function (e) {
sessionStorage.document = e.data;
}
);
}
function restoreDocument() {
// if document exists, load it from the session storage
if (sessionStorage["document"]) {
$("#txReconnectMsg").show(); // hide dialog
TXTextControl.loadDocument(
TXTextControl.streamType.InternalUnicodeFormat,
sessionStorage.document);
}
else
$("#txReconnectMsg").hide(); // hide dialog
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment