Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy decoded qr #1491

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
55 changes: 50 additions & 5 deletions examples/lib/defaultHtmlStepUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,21 @@ function DefaultHtmlStepUi(_sequencer, options) {

for (var paramName in merged) {
var isInput = inputs.hasOwnProperty(paramName);
if(outputs){
isOutput = outputs.hasOwnProperty(paramName)

}
var html = '';
var inputDesc = isInput ? mapHtmlTypes(inputs[paramName]) : {};
if (!isInput) {
html += '<span class="output"></span>';
if (outputs && isOutput) {
if(outputs[paramName].type.toLowerCase()=='string'){
let paramVal = step.options[paramName] || inputDesc.default;
html += '<p class="output"> ' +
paramVal +
'</p>';
}

else html += '<span class="output"></span>';
}
else if (inputDesc.type.toLowerCase() == 'select') {

Expand All @@ -105,7 +116,7 @@ function DefaultHtmlStepUi(_sequencer, options) {
}
else {
let paramVal = step.options[paramName] || inputDesc.default;

if (inputDesc.id == 'color-picker') { // Separate input field for color-picker
html +=
'<div id="color-picker" class="input-group colorpicker-component">' +
Expand Down Expand Up @@ -353,10 +364,44 @@ function DefaultHtmlStepUi(_sequencer, options) {
.data('initValue', step.options[i]);
}
}
function fallbackCopyTextToClipboard(text) {
var textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position="fixed"; //avoid scrolling to bottom
document.body.appendChild(textArea);
textArea.focus();
textArea.select();

try {
var successful = document.execCommand('copy');
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
}

document.body.removeChild(textArea);
}
for (var i in outputs) {

if (step[i] !== undefined)
$step('div[name="' + i + '"] input')
.val(step[i]);
if(outputs[i].type.toLowerCase()=='string'){
$step('div[name="' + i + '"] .save').remove();
var btn = document.createElement('button');
btn.innerHTML = "COPY"
btn.className = 'save btn btn-primary';
btn.setAttribute("style","margin-top:5px;")
step.ui.querySelector('div[name="' + i + '"] .output').innerHTML=step[i];
$step('div[name="' + i + '"] div.det').append(btn);

$step('div[name="' + i + '"] .save').on('click', () => {
fallbackCopyTextToClipboard(step[i]);
});
}
else {
$step('div[name="' + i + '"] input')
.val(step[i]);
}


}
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/DecodeQr/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
}
},
"docs-link":"https://github.com/publiclab/image-sequencer/blob/main/docs/MODULES.md#decodeqr-module"
}
}