forked from openlayers/openlayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
43 lines (36 loc) · 1.31 KB
/
common.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
(function() {
var clipboard = new Clipboard('#copy-button');
clipboard.on('success', function(e) {
e.clearSelection();
});
var codepenButton = document.getElementById('codepen-button');
if (codepenButton) {
codepenButton.onclick = function(event) {
event.preventDefault();
var form = document.getElementById('codepen-form');
// Doc : https://blog.codepen.io/documentation/api/prefill/
var resources = form.resources.value.split(',');
var data = {
title: form.title.value,
description: form.description.value,
layout: 'left',
html: form.html.value,
css: form.css.value,
js: form.js.value,
css_external: resources.filter(function(resource) {
return resource.lastIndexOf('.css') === resource.length - 4;
}).join(';'),
js_external: resources.filter(function(resource) {
return resource.lastIndexOf('.js') === resource.length - 3;
}).join(';')
};
// binary flags to display html, css, js and/or console tabs
data.editors = '' + Number(data.html.length > 0) +
Number(data.css.length > 0) +
Number(data.js.length > 0) +
Number(data.js.indexOf('console') > 0);
form.data.value = JSON.stringify(data);
form.submit();
};
}
})();