-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.js
111 lines (73 loc) · 3.36 KB
/
Home.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'use strict';
(function () {
Office.onReady(function () {
// Office is ready
$(document).ready(function () {
try {
var t2 = ' <div id="start-menu"> ' +
' <button class="btn" id="webBtn">Website</button> ' +
' <button class="btn" id="fileBtn">Local file</button> ' +
' ' +
' <div id="start-info"> ' +
' <p> This is a free program which main purpose is to load webpage content into a web-api container. </p> ' +
' <p> If you want to load a website content, press a <strong> Website </strong> button. </p> ' +
' <p> If you want to load a local html, press a <strong> Local URL </strong> button. </p> ' +
' <br> ' +
' <p> After loading a web-element into this container, it will automatically open anywhere without necessity of loading the web-element again.</p> ' +
' <br> ' +
' <p> Created by <strong> sanederchik </strong> </p> ' +
' <p> More on my <a href="https://github.com/sanederchik/OfficeHtmlReader"> github page </a> </p> ' +
' </div> ' +
' ' +
' </div> ';
var t1 = Office.context.document.settings.get('elementHTML');
if (t1 == null) {
$('body').html(t2);
$('#webBtn').click(function () { insertHTML(0); });
$('#fileBtn').click(function () { insertHTML(1); });
} else {
$('body').html(t1);
};
} catch (err) {
$('body').html(t2);
$('#webBtn').click(function () { insertHTML(0); });
$('#fileBtn').click(function () { insertHTML(1); });
}
});
});
function insertHTML(type) {
var text;
// 0: web, other: file
if (type == 0) {
text =
' <input id="web">' +
'<button class = "btn" id="insertURL" onclick="insURL();" >Insert URL</button>' +
' </br> </br> '
} else {
text = ' <input type="file" id="files" onchange = "handleFileSelect(this.files);" /> '
};
$('body').html(text);
}
})();
function handleFileSelect(f) {
var reader = new FileReader();
reader.onload = function () {
var text = reader.result;
$('body').html(text);
Office.context.document.settings.set('elementHTML', text);
Office.context.document.settings.saveAsync();
};
reader.readAsText(f[0]);
}
function insURL() {
var _ = document.getElementById('web');
$("body").html("Loading...");
//
if (_.value.toString() == ''){
alert('Пустое значение!');
} else {
document.body.innerHTML = `
<iframe src = "${_.value}" width="100%" height="100%" frameBorder="0"><Браузер не поддерживает iframe</iframe>
`;
}
}