1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-16 19:46:19 +02:00

Merge pull request #13 from chinchang/MKFMIKU-func

Add saving key shortcut
This commit is contained in:
Kushagra Gour
2016-07-05 15:29:17 +05:30
committed by GitHub

View File

@@ -114,6 +114,29 @@
}, errorHandler); }, errorHandler);
}; };
function saveFile() {
var html = editur.cm.html.getValue();
var css = editur.cm.css.getValue();
var js = editur.cm.js.getValue();
var fileContent = '<html><head>\n<style>\n'
+ css + '\n</style>\n</head>\n<body>\n'
+ html + '\n<script>\n' + js + '\n</script>\n\n</body>\n</html>';
var d = new Date();
var fileName = [ 'web-maker', d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds() ].join('-');
fileName += '.html';
var a = document.createElement('a');
var blob = new Blob([ fileContent ], {type: "text/html;charset=UTF-8"});
a.href = window.URL.createObjectURL(blob);
a.download = fileName;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
a.remove();
}
function initEditor(element, options) { function initEditor(element, options) {
var cm = CodeMirror(element, { var cm = CodeMirror(element, {
mode: options.mode, mode: options.mode,
@@ -177,26 +200,14 @@
}); });
saveHtmlBtn.addEventListener('click', function () { saveHtmlBtn.addEventListener('click', function () {
var html = editur.cm.html.getValue(); saveFile();
var css = editur.cm.css.getValue(); });
var js = editur.cm.js.getValue();
var fileContent = '<html><head>\n<style>\n' window.addEventListener('keydown', function (event) {
+ css + '\n</style>\n</head>\n<body>\n' if ((event.ctrlKey || event.metaKey) && (event.keyCode === 83)){
+ html + '\n<script>\n' + js + '\n</script>\n\n</body>\n</html>'; event.preventDefault();
saveFile();
var d = new Date(); }
var fileName = [ 'web-maker', d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds() ].join('-');
fileName += '.html';
var a = document.createElement('a');
var blob = new Blob([ fileContent ], {type: "text/html;charset=UTF-8"});
a.href = window.URL.createObjectURL(blob);
a.download = fileName;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
a.remove();
}); });
window.addEventListener('click', function(e) { window.addEventListener('click', function(e) {