Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created November 8, 2024 14:20
Show Gist options
  • Save bjoerntx/b4eaf83b6a28f692073a38afb2b63bae to your computer and use it in GitHub Desktop.
Save bjoerntx/b4eaf83b6a28f692073a38afb2b63bae to your computer and use it in GitHub Desktop.
TXTextControl.addEventListener("textControlLoaded", e => {
let idleTimeout;
function onIdle() {
mergeTemplate();
}
function resetIdleTimer() {
clearTimeout(idleTimeout);
idleTimeout = setTimeout(onIdle, 2000); // Set idle time to 2 seconds
}
// Attach event listener to TXTextControl's "changed" event
TXTextControl.addEventListener("changed", e => {
resetIdleTimer();
});
// Initialize the idle timer
resetIdleTimer();
});
function mergeTemplate() {
TXTextControl.saveDocument(TXTextControl.StreamType.InternalUnicodeFormat, document => {
// call web api endpoint with ajax
$.ajax({
url: '/mailmerge/merge',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(document.data),
success: function (data) {
// load the document into the viewer
TXDocumentViewer.loadDocument(data);
}
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment