Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active June 7, 2022 14:12
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/f4d70181bd4a95b7ae47d4fd21e6f961 to your computer and use it in GitHub Desktop.
Save bjoerntx/f4d70181bd4a95b7ae47d4fd21e6f961 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
// event for previous tab
$(".nav-tabs button").on("hide.bs.tab", function(){
// previous tab name
var oldTab = $(this).attr("aria-controls");
// save the document to local storage
TXTextControl.saveDocument(TXTextControl.StreamType.InternalUnicodeFormat,
function (e) {
localStorage.setItem('tx-document_' + oldTab, e.data);
});
});
// event for current tab
$(".nav-tabs button").on("show.bs.tab", function(){
// current tab name
var newTab = $(this).attr("aria-controls");
// get the previously stored document from local storage
const document = localStorage.getItem('tx-document_' + newTab);
// if document is not null, load the document
// and move the editorin DOM to new tab location
if (document !== null) {
TXTextControl.loadDocument(TXTextControl.StreamType.InternalUnicodeFormat,
document, function() {
$("#tx-editor").appendTo("#" + newTab);
});
}
// if document is null, clear the Text Control and move in DOM
else {
TXTextControl.resetContents(function() {
$("#tx-editor").appendTo("#" + newTab);
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment