forked from g21589/PPTX2HTML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpptx2html.js
237 lines (202 loc) · 6.52 KB
/
pptx2html.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
$(document).ready(function() {
if (window.Worker) {
var $result = $("#result");
var isDone = false;
$("#uploadBtn").on("change", function(evt) {
isDone = false;
$result.html("");
$("#load-progress").text("0%").attr("aria-valuenow", 0).css("width", "0%");
$("#result_block").removeClass("hidden").addClass("show");
var fileName = evt.target.files[0];
// Read the file
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
// Web Worker
var worker = new Worker('./js/worker.js');
worker.addEventListener('message', function(e) {
var msg = e.data;
switch(msg.type) {
case "progress-update":
$("#load-progress").text(msg.data.toFixed(2) + "%")
.attr("aria-valuenow", msg.data.toFixed(2))
.css("width", msg.data.toFixed(2) + "%");
break;
case "slide":
$result.append(msg.data);
break;
case "processMsgQueue":
processMsgQueue(msg.data);
break;
case "pptx-thumb":
$("#pptx-thumb").attr("src", "data:image/jpeg;base64," + msg.data);
break;
case "slideSize":
if (localStorage) {
localStorage.setItem("slideWidth", msg.data.width);
localStorage.setItem("slideHeight", msg.data.height);
} else {
alert("Browser don't support Web Storage!");
}
break;
case "globalCSS":
$result.append("<style>" + msg.data + "</style>");
break;
case "ExecutionTime":
$("#info_block").html("Execution Time: " + msg.data + " (ms)");
isDone = true;
worker.postMessage({
"type": "getMsgQueue"
});
break;
case "WARN":
console.warn('Worker: ', msg.data);
break;
case "ERROR":
console.error('Worker: ', msg.data);
$("#error_block").text(msg.data);
break;
case "DEBUG":
console.debug('Worker: ', msg.data);
break;
case "INFO":
default:
console.info('Worker: ', msg.data);
//$("#info_block").html($("#info_block").html() + "<br><br>" + msg.data);
}
}, false);
worker.postMessage({
"type": "processPPTX",
"data": e.target.result
});
}
})(fileName);
reader.readAsArrayBuffer(fileName);
});
$("#slideContentModel").on("show.bs.modal", function (e) {
if (!isDone) { return; }
$("#slideContentModel .modal-body textarea").text($result.html());
});
$("#download-btn").click(function () {
if (!isDone) { return; }
var cssText = "";
$.get("css/pptx2html.css", function (data) {
cssText = data;
}).done(function () {
var headHtml = "<style>" + cssText + "</style>";
var bodyHtml = $result.html();
var html = "<!DOCTYPE html><html><head>" + headHtml + "</head><body>" + bodyHtml + "</body></html>";
var blob = new Blob([html], {type: "text/html;charset=utf-8"});
saveAs(blob, "slides_p.html");
});
});
$("#download-reveal-btn").click(function () {
if (!isDone) { return; }
var cssText = "";
$.get("css/pptx2html.css", function (data) {
cssText = data;
}).done(function () {
var revealPrefix =
"<script type='text/javascript'>\
Reveal.initialize({\
controls: true,\
progress: true,\
history: true,\
center: true,\
keyboard: true,\
slideNumber: true,\
\
theme: Reveal.getQueryHash().theme,\
transition: Reveal.getQueryHash().transition || 'default',\
\
dependencies: [\
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },\
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },\
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },\
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },\
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },\
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }\
]\
});\
</script>";
var headHtml = "<style>" + cssText + "</style>";
var bodyHtml = "<div id='slides' class='slides'>" + $result.html() + "</div>";
var html = revealPrefix + headHtml + bodyHtml;
var blob = new Blob([html], {type: "text/html;charset=utf-8"});
saveAs(blob, "slides.html");
});
});
$("#to-reveal-btn").click(function () {
if (localStorage) {
localStorage.setItem("slides", LZString.compressToUTF16($result.html()));
window.open("./reveal/demo.html", "_blank");
} else {
alert("Browser don't support Web Storage!");
}
});
} else {
alert("Browser don't support Web Worker!");
}
});
function processMsgQueue(queue) {
for (var i=0; i<queue.length; i++) {
processSingleMsg(queue[i].data);
}
}
function processSingleMsg(d) {
var chartID = d.chartID;
var chartType = d.chartType;
var chartData = d.chartData;
var data = [];
var chart = null;
switch (chartType) {
case "lineChart":
data = chartData;
chart = nv.models.lineChart()
.useInteractiveGuideline(true);
chart.xAxis.tickFormat(function(d) { return chartData[0].xlabels[d] || d; });
break;
case "barChart":
data = chartData;
chart = nv.models.multiBarChart();
chart.xAxis.tickFormat(function(d) { return chartData[0].xlabels[d] || d; });
break;
case "pieChart":
case "pie3DChart":
data = chartData[0].values;
chart = nv.models.pieChart();
break;
case "areaChart":
data = chartData;
chart = nv.models.stackedAreaChart()
.clipEdge(true)
.useInteractiveGuideline(true);
chart.xAxis.tickFormat(function(d) { return chartData[0].xlabels[d] || d; });
break;
case "scatterChart":
for (var i=0; i<chartData.length; i++) {
var arr = [];
for (var j=0; j<chartData[i].length; j++) {
arr.push({x: j, y: chartData[i][j]});
}
data.push({key: 'data' + (i + 1), values: arr});
}
//data = chartData;
chart = nv.models.scatterChart()
.showDistX(true)
.showDistY(true)
.color(d3.scale.category10().range());
chart.xAxis.axisLabel('X').tickFormat(d3.format('.02f'));
chart.yAxis.axisLabel('Y').tickFormat(d3.format('.02f'));
break;
default:
}
if (chart !== null) {
d3.select("#" + chartID)
.append("svg")
.datum(data)
.transition().duration(500)
.call(chart);
nv.utils.windowResize(chart.update);
}
}