Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active March 1, 2017 21:36
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/19b956ed949b0074fd88405c0eae2052 to your computer and use it in GitHub Desktop.
Save bjoerntx/19b956ed949b0074fd88405c0eae2052 to your computer and use it in GitHub Desktop.
function InsertSubTextPart(name, protect) {
// retrieve the JS Selection object
var sel = TXTextControl.selection
// check, if something has been selected
sel.getBounds(function (e) {
if (e.length == 0) {
alert('SubTextPart cannot be added - please select text.');
return;
}
else {
// save the current selection
TXTextControl.saveSelection(
TXTextControl.streamType.InternalUnicodeFormat,
function (e) {
var serviceURL = "/Home/InsertSubTextPart";
$.ajax({
type: "POST",
url: serviceURL,
contentType: 'application/json',
data: JSON.stringify({
Name: name,
BinaryDocument: e.data,
Protected: protect
}),
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
// load the created SubTextPart into the current Selection
TXTextControl.loadSelection(
TXTextControl.StreamType.InternalUnicodeFormat, data);
}
function errorFunc() {
alert('Error');
}
});
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment