Add copy to clipboard and select all buttons

This commit is contained in:
mayankshouche 2020-07-25 17:26:52 -05:00
parent 0500e50479
commit f0f866aeff
3 changed files with 38 additions and 1 deletions

View File

@ -183,7 +183,19 @@
<div>
<button class="submit"><strong>Beautify Code</strong> <em>(ctrl-enter)</em>
</button>
<div style="text-align: center;">
<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>
</div>
<textarea id="source" rows="30" cols="160"></textarea>
<div style="text-align: center;">
<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>
</div>
<button class="submit"><strong>Beautify Code</strong> <em>(ctrl-enter)</em>
</button>
</div>

View File

@ -1,5 +1,5 @@
/*jshint strict:false, node:false */
/*exported run_tests, read_settings_from_cookie, beautify, submitIssue */
/*exported run_tests, read_settings_from_cookie, beautify, submitIssue, copyText, selectAll*/
var the = {
use_codemirror: !window.location.href.match(/without-codemirror/),
beautifier_file: window.location.href.match(/debug/) ? 'beautifier' : './beautifier.min',
@ -315,3 +315,21 @@ function getSubmitIssueBody(trucate) {
];
return submit_body.join('\n');
}
function copyText() {
var currentText = the.editor.getValue();
var copyArea = $('<textarea />')
.text(currentText)
.attr('readonly', '')
.css({ 'position': 'absolute', 'left': '-9999px' });
$('body').append(copyArea);
copyArea.select();
document.execCommand('copy');
copyArea.remove();
}
function selectAll() {
the.editor.execCommand('selectAll');
}

View File

@ -36,6 +36,13 @@ button.submit em {
color: #999;
}
button.control {
width: 10%;
padding: 5px 0;
cursor: pointer;
margin: 0;
}
label {
cursor: pointer;
}