Skip to content

Commit

Permalink
Merge pull request #1930 from Alzamer/bugfix
Browse files Browse the repository at this point in the history
Added buttons to website
  • Loading branch information
bitwiseman authored May 4, 2021
2 parents dc44ce7 + 08e044a commit 978edfa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,20 @@ <h1>Online JavaScript Beautifier <span id="version-number"></span></h1>
<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>

Expand Down
25 changes: 24 additions & 1 deletion web/common-function.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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);
}
};
}
}

0 comments on commit 978edfa

Please sign in to comment.