mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-23 04:40:06 +00:00
Add copy to clipboard and select all buttons
This commit is contained in:
parent
0500e50479
commit
f0f866aeff
12
index.html
12
index.html
@ -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>
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -36,6 +36,13 @@ button.submit em {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
button.control {
|
||||
width: 10%;
|
||||
padding: 5px 0;
|
||||
cursor: pointer;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
label {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user