DecoderPopup.js helper for WebCodeCamJS

Initialization - html

<script type="text/javascript" src="js/qrcodelib.js"></script>
<script type="text/javascript" src="js/webcodecamjs.js"></script>
<script type="text/javascript" src="js/decoderpopup.js"></script>

Initialization - javascript

var handler = function(popup, decoder, index) {
  switch (index) {
    case 0:
      decoder.options.decodeQRCodeRate = 5;
      decoder.options.decodeBarCodeRate = false;
      decoder.options.resultFunction = function(result) {
        document.querySelector('#text-box-1').value = result.code;
        document.querySelector('#text-box-2').focus();
      };
      break;
    case 1:
      decoder.options.decodeQRCodeRate = 5;
      decoder.options.decodeBarCodeRate = false;
      decoder.options.resultFunction = function(result) {
        decoder.pause();
        popup.classList.add("hidden");
        document.querySelector('#text-box-2').value = result.code;
      }
      break;
    case 2:
      decoder.options.decodeQRCodeRate = false;
      decoder.options.decodeBarCodeRate = 5;
      decoder.options.resultFunction = function(result) {
        decoder.pause();
        popup.classList.add("hidden");
        document.querySelector('#text-box-3').value = result.code;
      }
      break;
    case 3:
      decoder.options.decodeQRCodeRate = 5;
      decoder.options.decodeBarCodeRate = false;
      decoder.options.resultFunction = function(result) {
        if(isValidURL(result.code)){
          decoder.pause();
          popup.classList.add("hidden");
          window.open(result.code);
        }
      }
      break;
    case 4:
      // And so on ...
      break;
    default:
      decoder.options.resultFunction = function(result) {
        console.log(result);
      }
      break;
  }
}
var popup = new DecoderPopup(handler);
popup.init(/** optional -> see WebCodeCamJS documentation */ args);

On focus scan QR code - focus next

<input id="text-box-1" class="w3-input w3-border" type="text" onfocus="popup.open(event, 0);"></p>

On focus scan QR code

<input id="text-box-2" class="w3-input w3-border" type="text" onfocus="popup.open(event, 1);"></p>

On focus scan Barcode

<input id="text-box-3" class="w3-input w3-border" type="text" onfocus="popup.open(event, 2);"></p>

Jump to URL (QR code)

<button id="read-qr" class="w3-btn w3-blue" onclick="popup.open(event, 3);">Jump to URL (QR code)</button>