mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-08 20:56:04 +00:00
137 lines
5.2 KiB
HTML
137 lines
5.2 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>WelsonJS Code Editor</title>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.52.2/min/vs/editor/editor.main.css" />
|
|
<link rel="stylesheet" href="https://cdn.metroui.org.ua/current/metro.css">
|
|
<link rel="stylesheet" href="https://cdn.metroui.org.ua/current/icons.css">
|
|
<style>
|
|
html, body {
|
|
margin: 0;
|
|
padding: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
overflow: hidden;
|
|
}
|
|
#container {
|
|
border: 1px solid grey;
|
|
height: calc(100% - 139px);
|
|
overflow: hidden;
|
|
}
|
|
.banner {
|
|
text-align: center;
|
|
padding: 10px;
|
|
background-color: #f1f1f1;
|
|
font-size: 14px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<nav data-role="ribbonmenu">
|
|
<ul class="tabs-holder">
|
|
<li class="static"><a href="#">File</a></li>
|
|
<li><a href="#editor-tab">Editor</a></li>
|
|
</ul>
|
|
<div class="content-holder">
|
|
<div class="section" id="editor-tab">
|
|
<button class="ribbon-button" onclick="openFile()">
|
|
<span class="icon mif-folder-open"></span>
|
|
<span class="caption">Open File</span>
|
|
</button>
|
|
<button class="ribbon-button" onclick="saveFile()">
|
|
<span class="icon mif-floppy-disk"></span>
|
|
<span class="caption">Save File</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div id="container"></div>
|
|
<input type="file" id="fileInput" style="display: none" onchange="handleFileSelect(event)">
|
|
|
|
<div class="banner"><a href="https://github.com/gnh1201/welsonjs">WelsonJS</a> Code Editor powered by <a href="https://github.com/microsoft/monaco-editor">Microsoft Monaco Editor</a>.</div>
|
|
|
|
<script>
|
|
var require = { paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.52.2/min/vs' } };
|
|
</script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.52.2/min/vs/loader.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.52.2/min/vs/editor/editor.main.js"></script>
|
|
<script src="https://cdn.metroui.org.ua/current/metro.js"></script>
|
|
|
|
<script>
|
|
var editor;
|
|
var currentFileName = "sayhello.js";
|
|
|
|
function resizeEditor() {
|
|
if (editor) {
|
|
var ribbonHeight = document.querySelector('nav').offsetHeight;
|
|
var bannerHeight = document.querySelector('.banner').offsetHeight;
|
|
var containerHeight = document.documentElement.clientHeight - ribbonHeight - bannerHeight;
|
|
document.getElementById('container').style.height = containerHeight + 'px';
|
|
editor.layout();
|
|
}
|
|
}
|
|
|
|
require(["vs/editor/editor.main"], function() {
|
|
editor = monaco.editor.create(document.getElementById('container'), {
|
|
value: ['// lib/sayhello.js', 'function say() {', ' console.log("hello");', '}', '', 'exports.say = say;', '', 'exports.VERSIONINFO = "SayHello (sayhello.js) version 0.1";', 'exports.AUTHOR = "abuse@catswords.net";', 'exports.global = global;', 'exports.require = global.require;'].join('\n'),
|
|
language: 'javascript'
|
|
});
|
|
});
|
|
|
|
window.addEventListener('resize', resizeEditor);
|
|
|
|
function openFile() {
|
|
document.getElementById('fileInput').click();
|
|
}
|
|
|
|
function getFileLanguage(fileName) {
|
|
var extension = fileName.split('.').pop().toLowerCase();
|
|
var languageMap = {
|
|
'js': 'javascript',
|
|
'ts': 'typescript',
|
|
'html': 'html',
|
|
'css': 'css',
|
|
'json': 'json',
|
|
'py': 'python',
|
|
'java': 'java',
|
|
'c': 'c',
|
|
'cpp': 'cpp',
|
|
'cs': 'csharp',
|
|
'php': 'php',
|
|
'rb': 'ruby',
|
|
'go': 'go',
|
|
'rs': 'rust'
|
|
};
|
|
return languageMap[extension] || 'plaintext';
|
|
}
|
|
|
|
function handleFileSelect(event) {
|
|
var file = event.target.files[0];
|
|
if (!file) return;
|
|
|
|
currentFileName = file.name;
|
|
var reader = new FileReader();
|
|
reader.onload = function(e) {
|
|
var language = getFileLanguage(file.name);
|
|
monaco.editor.setModelLanguage(editor.getModel(), language);
|
|
editor.setValue(e.target.result);
|
|
};
|
|
reader.readAsText(file);
|
|
}
|
|
|
|
function saveFile() {
|
|
var text = editor.getValue();
|
|
var blob = new Blob([text], { type: 'text/plain' });
|
|
var a = document.createElement('a');
|
|
a.href = URL.createObjectURL(blob);
|
|
a.download = currentFileName;
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
document.body.removeChild(a);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|