-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentServices.DocumentViewer.js
85 lines (68 loc) · 1.85 KB
/
DocumentServices.DocumentViewer.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var DocumentServices = (function (tx) {
var m_clientID,
m_clientSecret,
m_serviceURL,
m_containerID,
m_accessToken,
m_userNames = [ "unknown user" ];
m_isSelectionActivated = true;
m_showThumbnailPane = true;
tx.DocumentViewer = {
setUserNames: function (userNames) {
m_userNames = userNames;
},
setIsSelectionActivated: function (activated) {
m_isSelectionActivated = activated;
},
setShowThumbnailPane: function (show) {
m_showThumbnailPane = show;
},
init: function (clientID, clientSecret, serviceURL, containerID) {
m_clientID = clientID;
m_clientSecret = clientSecret;
m_serviceURL = serviceURL;
m_containerID = containerID;
var script = document.createElement('script');
script.onload = function () {
TXDocumentViewer.init( {
containerID: m_containerID,
viewerSettings: {
toolbarDocked: true,
dock: "Fill",
userNames: m_userNames,
isSelectionActivated: m_isSelectionActivated,
showThumbnailPane: m_showThumbnailPane,
basePath: m_serviceURL + "/documentviewer",
oauthSettings: {
accessToken: m_accessToken
}
}
});
};
getAccessToken(function(token) {
m_accessToken = token;
script.src = m_serviceURL + "/documentviewer/textcontrol/GetResource?Resource=minimized.tx-viewer.min.js&access_token=" + m_accessToken;
document.head.appendChild(script);
});
},
}
function getAccessToken(callback) {
$.ajax({
type: "POST",
headers: {
"Authorization": "Basic " + btoa(m_clientID + ":" + m_clientSecret)
},
url: m_serviceURL + "/OAuth/Token",
data: {
"grant_type": "client_credentials"
},
success: successFunc
});
function successFunc(data, status) {
if (typeof callback == "function") {
callback(data.access_token);
}
}
}
return tx;
} ( DocumentServices || {} ));