From 08e044a9ecd1f9e41fa4304217472cd230625ed7 Mon Sep 17 00:00:00 2001 From: Alzamer Date: Tue, 4 May 2021 17:56:07 +0200 Subject: [PATCH] Added buttons to website --- index.html | 4 ++++ web/common-function.js | 25 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 8b51ac814..772f6019b 100644 --- a/index.html +++ b/index.html @@ -185,16 +185,20 @@

Online JavaScript Beautifier

+ +
+ +
diff --git a/web/common-function.js b/web/common-function.js index 83e387441..f341a010f 100644 --- a/web/common-function.js +++ b/web/common-function.js @@ -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); + } + }; + } +}