Skip to content

Commit 1553b5f

Browse files
committed
Fixed lint
1 parent 2ddd2e0 commit 1553b5f

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/web/Manager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Manager.prototype.initialiseEventListeners = function() {
142142

143143
// Output
144144
document.getElementById("save-to-file").addEventListener("click", this.output.saveClick.bind(this.output));
145+
document.getElementById("copy-output").addEventListener("click", this.output.copyClick.bind(this.output));
145146
document.getElementById("switch").addEventListener("click", this.output.switchClick.bind(this.output));
146147
document.getElementById("undo-switch").addEventListener("click", this.output.undoSwitchClick.bind(this.output));
147148
document.getElementById("maximise-output").addEventListener("click", this.output.maximiseOutputClick.bind(this.output));

src/web/OutputWaiter.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,20 @@ OutputWaiter.prototype.setOutputInfo = function(length, lines, duration) {
105105
OutputWaiter.prototype.adjustWidth = function() {
106106
const output = document.getElementById("output");
107107
const saveToFile = document.getElementById("save-to-file");
108+
const copyOutput = document.getElementById("copy-output");
108109
const switchIO = document.getElementById("switch");
109110
const undoSwitch = document.getElementById("undo-switch");
110111
const maximiseOutput = document.getElementById("maximise-output");
111112

112113
if (output.clientWidth < 680) {
113114
saveToFile.childNodes[1].nodeValue = "";
115+
copyOutput.childNodes[1].nodeValue = "";
114116
switchIO.childNodes[1].nodeValue = "";
115117
undoSwitch.childNodes[1].nodeValue = "";
116118
maximiseOutput.childNodes[1].nodeValue = "";
117119
} else {
118120
saveToFile.childNodes[1].nodeValue = " Save to file";
121+
copyOutput.childNodes[1].nodeValue = " Copy output";
119122
switchIO.childNodes[1].nodeValue = " Move output to input";
120123
undoSwitch.childNodes[1].nodeValue = " Undo";
121124
maximiseOutput.childNodes[1].nodeValue =
@@ -147,6 +150,44 @@ OutputWaiter.prototype.saveClick = function() {
147150
};
148151

149152

153+
/**
154+
* Handler for copy click events.
155+
* Copies the output to the clipboard.
156+
*/
157+
OutputWaiter.prototype.copyClick = function() {
158+
// Create invisible textarea to populate with the raw dishStr (not the printable version that
159+
// contains dots instead of the actual bytes)
160+
const textarea = document.createElement("textarea");
161+
textarea.style.position = "fixed";
162+
textarea.style.top = 0;
163+
textarea.style.left = 0;
164+
textarea.style.width = 0;
165+
textarea.style.height = 0;
166+
textarea.style.border = "none";
167+
168+
textarea.value = this.app.dishStr;
169+
document.body.appendChild(textarea);
170+
171+
// Select and copy the contents of this textarea
172+
let success = false;
173+
try {
174+
textarea.select();
175+
success = document.execCommand("copy");
176+
} catch (err) {
177+
success = false;
178+
}
179+
180+
if (success) {
181+
this.app.alert("Copied raw output successfully.", "success", 2000);
182+
} else {
183+
this.app.alert("Sorry, the output could not be copied.", "danger", 2000);
184+
}
185+
186+
// Clean up
187+
document.body.removeChild(textarea);
188+
};
189+
190+
150191
/**
151192
* Handler for switch click events.
152193
* Moves the current output into the input textarea.

src/web/html/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
<label for="output-text">Output</label>
190190
<div class="btn-group io-btn-group">
191191
<button type="button" class="btn btn-default btn-sm" id="save-to-file" title="Save to file"><img aria-hidden="true" src="<%- require('../static/images/save_as-16x16.png') %>" alt="Save Icon"/> Save to file</button>
192+
<button type="button" class="btn btn-default btn-sm" id="copy-output" title="Copy output"><img aria-hidden="true" src="<%- require('../static/images/copy-16x16.png') %>" alt="Copy Icon"/> Copy raw output</button>
192193
<button type="button" class="btn btn-default btn-sm" id="switch" title="Move output to input"><img aria-hidden="true" src="<%- require('../static/images/switch-16x16.png') %>" alt="Switch Icon"/> Move output to input</button>
193194
<button type="button" class="btn btn-default btn-sm" id="undo-switch" title="Undo move" disabled="disabled"><img aria-hidden="true" src="<%- require('../static/images/undo-16x16.png') %>" alt="Undo Icon"/> Undo</button>
194195
<button type="button" class="btn btn-default btn-sm" id="maximise-output" title="Maximise"><img aria-hidden="true" src="<%- require('../static/images/maximise-16x16.png') %>" alt="Maximise Icon"/> Max</button>

0 commit comments

Comments
 (0)