-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadhtmlslides.js
44 lines (37 loc) · 1.66 KB
/
loadhtmlslides.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
// Modified from markdown.js from Hakim to handle external html files
(function () {
/*jslint loopfunc: true, browser: true*/
/*globals alert*/
'use strict';
var querySlidingHtml = function () {
var sections = document.querySelectorAll('[data-html]'),
section, j, jlen;
for (j = 0, jlen = sections.length; j < jlen; j++) {
section = sections[j];
if (section.getAttribute('data-html').length) {
var xhr = new XMLHttpRequest(),
url = section.getAttribute('data-html'),
cb = function () {
if (xhr.readyState === 4) {
if (
(xhr.status >= 200 && xhr.status < 300) ||
xhr.status === 0 // file protocol yields status code 0 (useful for local debug, mobile applications etc.)
) {
section.innerHTML = xhr.responseText;
} else {
section.outerHTML = '<section data-state="alert">ERROR: The attempt to fetch ' + url + ' failed with the HTTP status ' + xhr.status + '. Check your browser\'s JavaScript console for more details.</p></section>';
}
}
};
xhr.onreadystatechange = cb;
xhr.open('GET', url, false);
try {
xhr.send();
} catch (e) {
alert('Failed to get file' + url + '.' + e);
}
}
}
};
querySlidingHtml();
})();