This repository has been archived by the owner on Apr 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 127
/
qr.code.reader.min.js
1 lines (1 loc) · 4.46 KB
/
qr.code.reader.min.js
1
var gCtx=null;var gCanvas=null;var imageData=null;var c=0;function passLine(h){var d=h.split("-");for(var a=0;a<320;a++){var f=parseInt(d[a]);r=(f>>16)&255;g=(f>>8)&255;b=(f)&255;imageData.data[c+0]=r;imageData.data[c+1]=g;imageData.data[c+2]=b;imageData.data[c+3]=255;c+=4}if(c>=320*240*4){c=0;gCtx.putImageData(imageData,0,0);try{qrcode.decode()}catch(j){}}}function captureToCanvas(){try{flash=document.getElementById("embedflash");if(!flash){return}flash.ccCapture()}catch(a){console.log(a)}}var QRCodeReader={video:"",container:"",canvas:"",ctx:"",out:"",found:false,timer:"",_stream:null,isCanvasSupported:function(){var a=document.createElement("canvas");return !!(a.getContext&&a.getContext("2d"))},loop:function(){QRCodeReader.captureToCanvas()},captureToCanvas:function(){QRCodeReader.ctx.drawImage(QRCodeReader.video,0,0,QRCodeReader.video.videoWidth,QRCodeReader.video.videoHeight,0,0,QRCodeReader.canvas.width,QRCodeReader.canvas.height);qrcode.decode(QRCodeReader.canvas.toDataURL())},canvasInit:function(){QRCodeReader.canvas=document.createElement("canvas");QRCodeReader.canvas.width=320;QRCodeReader.canvas.height=240;QRCodeReader.ctx=QRCodeReader.canvas.getContext("2d")},stop:function(){if(QRCodeReader.interval){clearInterval(QRCodeReader.interval);QRCodeReader.interval=null}if(QRCodeReader.reader_container){QRCodeReader.reader_container.empty();QRCodeReader.reader_container=null}try{if(this._stream){this._stream.stop();this._stream=null}}catch(a){console.log(a)}},init:function(h,j,d){if(!QRCodeReader.isCanvasSupported()){d("Sorry your browser does not support canvas. Please try Firefox, Chrome or safari.");return}var a=false;try{var f=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if(f){a=true}}catch(i){if(navigator.mimeTypes["application/x-shockwave-flash"]!=undefined){a=true}}loadScript("wallet-legacy/llqrcode",function(){navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;window.URL=window.URL||window.webkitURL||window.mozURL||window.msURL;QRCodeReader.reader_container=h.find(".qr-code-reader");if(navigator.getUserMedia){QRCodeReader.reader_container.html('<video style="width:320px;height:240px" autoplay id="sourcevid"></video>');QRCodeReader.video=QRCodeReader.reader_container.find("video").get(0);QRCodeReader.flash=null;navigator.getUserMedia({video:true},function(p){QRCodeReader._stream=p;QRCodeReader.video.src=window.URL.createObjectURL(p)||p;setTimeout(function(){QRCodeReader.canvasInit();QRCodeReader.interval=setInterval(QRCodeReader.loop,500)},250)},d);qrcode.callback=function(p){if(p){QRCodeReader.stop();j(p)}}}else{if(window.File&&window.FileReader&&window.FileList&&window.Blob){var e=$('<div class="well"><div style="font-weight:bold;margin-top:0px" class="page-header">Please Scan a QR Code:</div><input type="file" align="center" name="image" accept="image/*" capture/></div>');QRCodeReader.reader_container.append(e);QRCodeReader.canvasInit();var m=e.find("input");qrcode.callback=function(p){QRCodeReader.stop();if(p){j(p)}else{d("Error Reading QR Code")}};function o(q){var t=q.target.files;for(var s=0,u;u=t[s];s++){if(!u.type.match("image.*")){continue}var p=new FileReader();p.addEventListener("load",function(x){var w=x.target;var v=new Image;v.onload=function(){QRCodeReader.ctx.drawImage(v,0,0,QRCodeReader.canvas.width,QRCodeReader.canvas.height);qrcode.decode(QRCodeReader.canvas.toDataURL())};v.src=w.result});p.readAsDataURL(u)}}m.get(0).addEventListener("change",o,false)}else{if(a){function l(t,q){gCanvas=document.getElementById("qr-canvas");var p=t;var s=q;gCanvas.style.width=p+"px";gCanvas.style.height=s+"px";gCanvas.width=p;gCanvas.height=s;gCtx=gCanvas.getContext("2d");gCtx.clearRect(0,0,p,s);imageData=gCtx.getImageData(0,0,320,240)}function k(p){return $('<embed style="z-index:10;" allowScriptAccess="always" id="embedflash" src="'+p+'camcanvas.swf" quality="high" width="1" height="1" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" mayscript="true" />')}function n(){return $('<canvas style="z-index:-1;width:800px;height:600px; display:none;" id="qr-canvas" width="800" height="600"></canvas>')}QRCodeReader.reader_container.html(k(resource+"wallet-legacy/").width(320).height(240));QRCodeReader.reader_container.append(n());l(800,600);QRCodeReader.interval=setInterval(captureToCanvas,1000);qrcode.callback=function(p){if(p){QRCodeReader.stop();j(p)}}}else{d("Sorry your browser is not supported. Please try Firefox, Chrome or safari.")}}}})}};