Added buttons to website

This commit is contained in:
Alzamer 2021-05-04 17:56:07 +02:00
parent dc44ce76f7
commit 08e044a9ec
2 changed files with 28 additions and 1 deletions

View File

@ -185,16 +185,20 @@
<div>
<div style="text-align: center;">
<button class="submit"><strong>Beautify Code</strong> <em>(ctrl-enter)</em></button>
<input type="file" onchange="changeToFileContent(this)">
<button class="control" type="button" onclick="copyText()"><strong>Copy to Clipboard</strong></button>
<button class="control" type="button" onclick="selectAll()"><strong>Select All</strong></button>
<button class="control" type="button" onclick="clearAll()"><strong>Clear</strong></button>
</div>
<textarea id="source" rows="30" cols="160"></textarea>
<div style="text-align: center;">
<button class="submit"><strong>Beautify Code</strong> <em>(ctrl-enter)</em></button>
<input type="file" onchange="changeToFileContent(this)">
<button class="control" type="button" onclick="copyText()"><strong>Copy to Clipboard</strong></button>
<button class="control" type="button" onclick="selectAll()"><strong>Select All</strong></button>
<button class="control" type="button" onclick="clearAll()"><strong>Clear</strong></button>
</div>
</div>

View File

@ -1,5 +1,5 @@
/*jshint strict:false, node:false */
/*exported run_tests, read_settings_from_cookie, beautify, submitIssue, copyText, selectAll*/
/*exported run_tests, read_settings_from_cookie, beautify, submitIssue, copyText, selectAll, clearAll, changeToFileContent*/
var the = {
use_codemirror: !window.location.href.match(/without-codemirror/),
beautifier_file: window.location.href.match(/debug/) ? 'beautifier' : './beautifier.min',
@ -342,3 +342,26 @@ function selectAll() {
$('#source').select();
}
}
function clearAll() {
if (the.editor) {
the.editor.setValue('');
} else {
$('#source').val('');
}
}
function changeToFileContent(input) {
var file = input.files[0];
if (file) {
var reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = function(event) {
if (the.editor) {
the.editor.setValue(event.target.result);
} else {
$('#source').val(event.target.result);
}
};
}
}