Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active July 22, 2019 13:02
Show Gist options
  • Save bjoerntx/e18e3e0fd67e323c9a4d343fdd2e039c to your computer and use it in GitHub Desktop.
Save bjoerntx/e18e3e0fd67e323c9a4d343fdd2e039c to your computer and use it in GitHub Desktop.
var scrollLocation;
var freezedScrollLocation;
var dpiX = 15; // standard resolution server-side
function insertComplexElement() {
// store the current scroll location
freezedScrollLocation = scrollLocation;
var serviceURL = "/api/TXDocument/InsertComplexElement";
TXTextControl.saveDocument(TXTextControl.streamType.InternalUnicodeFormat, function (e) {
$.ajax({
type: "POST",
url: serviceURL,
contentType: 'application/json',
data: JSON.stringify({
Document: e.data
}),
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
//disable loading dialog
TXTextControl.isLoadingDialogEnabled = false;
TXTextControl.enableCommands(); // enable commands
// code that loads a document that is returned by an endpoint
TXTextControl.loadDocument(TXTextControl.streamType.InternalUnicodeFormat, data);
// restore the scroll position
TXTextControl.sendCommand(TXTextControl.Command.ScrollDelta,
freezedScrollLocation.location.x * dpiX,
freezedScrollLocation.location.y * dpiX)
}
function errorFunc() {
console.log("error");
}
}
}
TXTextControl.addEventListener("textViewLocationChanged", function (e) {
scrollLocation = e;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment