Files
openlayers/examples/resources/common.js
Frederic Junod 2f28f89c59 Create codesandbox using the 'parcel' template
The default template is `create-react-app` and this one ignores the `head` tag defined in out `index.html`
2019-03-14 15:08:01 +01:00

51 lines
1.4 KiB
JavaScript

(function() {
function compress(json) {
return LZString.compressToBase64(JSON.stringify(json))
.replace(/\+/g, `-`)
.replace(/\//g, `_`)
.replace(/=+$/, ``);
}
var htmlClipboard = new Clipboard('#copy-html-button');
htmlClipboard.on('success', function(e) {
e.clearSelection();
});
var jsClipboard = new Clipboard('#copy-js-button');
jsClipboard.on('success', function(e) {
e.clearSelection();
});
var pkgClipboard = new Clipboard('#copy-pkg-button');
pkgClipboard.on('success', function(e) {
e.clearSelection();
});
var codepenButton = document.getElementsByClassName('codepen-button')[0];
if (codepenButton) {
codepenButton.onclick = function(event) {
event.preventDefault();
var form = document.getElementById('codepen-form');
const html = document.getElementById('example-html-source').innerText;
const js = document.getElementById('example-js-source').innerText;
const pkgJson = document.getElementById('example-pkg-source').innerText;
form.parameters.value = compress({
files: {
'index.html': {
content: html
},
'index.js': {
content: js
},
"package.json": {
content: pkgJson
},
'sandbox.config.json': {
content: '{"template": "parcel"}'
}
}
});
form.submit();
};
}
})();