1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-10 08:26:19 +02:00
This commit is contained in:
mikum
2016-06-08 21:40:29 +08:00
parent 2a9a8aae8f
commit db502d0a50

View File

@ -176,38 +176,15 @@
e.preventDefault();
});
function save_file() {
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();
};
saveHtmlBtn.addEventListener('click', function (e) {
save_file();
save_file();
});
window.addEventListener('keydown',function(event) {
if ((event.ctrlKey)&&(event.keyCode==83)){
event.returnValue=false;
save_file();
}
if ((event.ctrlKey)&&(event.keyCode==83)){
event.preventDefault();
save_file();
}
});
window.addEventListener('click', function(e) {
@ -258,6 +235,29 @@
});
}
function save_file() {
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();
};
init();
})();