Last active
June 7, 2022 14:12
-
-
Save bjoerntx/f4d70181bd4a95b7ae47d4fd21e6f961 to your computer and use it in GitHub Desktop.
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
$(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