forked from lepture/github-cards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.js
64 lines (53 loc) · 1.63 KB
/
site.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
function githubCard() {
var d = document, timer;
var input = d.getElementById('howto-input');
var select = d.getElementById('howto-select');
function preview(value) {
if (!value) {
return;
}
var card = d.createElement('div');
card.className = 'github-card';
card.setAttribute('data-github', value);
var container = d.getElementById('howto-preview');
while (container.hasChildNodes()) {
container.removeChild(container.lastChild);
}
container.appendChild(card);
var iframe = githubCard.render(card, 'cards/' + select.value + '.html');
iframe.onload = function() {
var textarea = d.getElementById('howto-code');
card.setAttribute('data-width', iframe.width);
card.setAttribute('data-height', iframe.height);
card.setAttribute('data-theme', select.value);
var html = card.outerHTML;
html += '\n<script src="//cdn.jsdelivr.net/github-cards/latest/widget.js"></script>';
textarea.value = html;
if (location.hash.slice(1) !== value) {
location.hash = '#' + value + '|' + select.value;
}
d.documentElement.scrollTop = 630;
};
}
input.onkeyup = function() {
clearTimeout(timer);
timer = setTimeout(function() {
preview(input.value);
}, 800);
};
select.onchange = function() {
preview(input.value);
};
input.onkeydown = function() {
clearTimeout(timer);
};
if (location.hash) {
window.onload = function() {
var bits = location.hash.slice(1).split('|');
input.value = bits[0];
select.value = bits[1] || 'default';
preview(input.value);
};
}
}
githubCard();