-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentity.js
More file actions
68 lines (59 loc) · 1.99 KB
/
entity.js
File metadata and controls
68 lines (59 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* globals Office */
/* jshint browser: true */
Office.initialize = function ( reason ) {
// Checks for the DOM to load using the jQuery ready function.
$( document ).ready(
function () {
// void
}
);
};
function insertWordLink ( link ) {
// get the selected data as HTML
Office.context.document.getSelectedDataAsync(
Office.CoercionType.Html,
function ( result ) {
if ( result.status == "succeeded" ) {
// the selected data as HTML, i.e. incl. formatting
var res = $( result.value );
// there should be exactly one p in there that contains the selected text
// it is a p due to schema constraints
var ret = res.find( 'p' );
// the selected text is inside spans that correspond to Word's "runs" (w:r)
// @style contains all styling information and needs to be kept
var text = ret.html();
//we simply wrap the contents of that p in an html:a and write it back
var ref = '<a href="' + link + '" style="text-decoration:none">' + text + '</a>';
Office.context.document.setSelectedDataAsync(
ref,
{ coercionType: Office.CoercionType.Html },
function ( asyncResult ) {
console.log( asyncResult.status );
}
);
}
}
);
}
function insertWordText ( text ) {
Office.context.document.getSelectedDataAsync(
Office.coercionType.Html,
function (result) {
if (result.status == "succeeded") {
var ins = "<span>" + text + "</span>";
Office.context.document.setSelectedDataAsync(
ins,
{coercionType: Office.CoercionType.Html},
function (syncResult) {
console.log(asyncResult.status);
}
);
}
});
}
function process ( data, type ) {
console.log(data);
var result = { results: [] };
evalResult(result, data, type);
return result.results;
}