forked from chinchang/lollipop.css
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
43 lines (36 loc) · 1.17 KB
/
script.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
var docs = [
{ title: 'Menu animation', slug: 'chinchang/pen/yNyaEx/' },
{ title: 'Menu animation', slug: 'chinchang/pen/yNyaEx/' }
];
ui = {};
ui.itemContainerEl = document.querySelector('#js-item-container');
ui.embedIframeContainerEl = document.querySelector('#js-item-container > div');
ui.embedPenEl = document.querySelector('#js-embed-pen');
function fetchCodepenScript() {
var script = document.createElement('script');
script.src = '//assets.codepen.io/assets/embed/ei.js';
document.head.appendChild(script);
}
ui.openItem = function openItem(e) {
var slug = e.currentTarget.getAttribute('href');
var clone = ui.embedPenEl.cloneNode();
clone.removeAttribute('data-dummy-pen');
clone.setAttribute('class', 'codepen');
ui.embedIframeContainerEl.innerHTML = '';
ui.embedIframeContainerEl.appendChild(clone);
CodePenEmbed.init();
document.body.classList.add('item-state');
e.preventDefault();
};
ui.closeItem = function closeItem(e) {
document.body.classList.remove('item-state');
};
window.addEventListener('keyup', function (e) {
if (e.which === 27) {
ui.closeItem();
}
});
// Prefetch codepen embed script
setTimeout(function () {
fetchCodepenScript();
}, 500);