(function(t){function i(){var n=Error.apply(this,arguments);n.name=this.name="FlashError";this.stack=n.stack;this.message=n.message}function r(){var n=Error.apply(this,arguments);n.name=this.name="WebcamError";this.stack=n.stack;this.message=n.message}var f,e=function(){},u;e.prototype=Error.prototype;i.prototype=new e;r.prototype=new e;u={version:"1.0.26",protocol:location.protocol.match(/https/i)?"https":"http",loaded:!1,live:!1,userMedia:!0,iOS:/iPad|iPhone|iPod/.test(navigator.userAgent)&&!t.MSStream,params:{width:0,height:0,dest_width:0,dest_height:0,image_format:"jpeg",jpeg_quality:90,enable_flash:!0,force_flash:!1,flip_horiz:!1,fps:30,upload_name:"webcam",constraints:null,swfURL:"",flashNotDetectedText:"ERROR: No Adobe Flash Player detected. Webcam.js relies on Flash for browsers that do not support getUserMedia (like yours).",noInterfaceFoundText:"No supported webcam interface found.",unfreeze_snap:!0,iosPlaceholderText:"Click here to open camera.",user_callback:null,user_canvas:null},errors:{FlashError:i,WebcamError:r},hooks:{},init:function(){var n=this;this.mediaDevices=navigator.mediaDevices&&navigator.mediaDevices.getUserMedia?navigator.mediaDevices:navigator.mozGetUserMedia||navigator.webkitGetUserMedia?{getUserMedia:function(n){return new Promise(function(t,i){(navigator.mozGetUserMedia||navigator.webkitGetUserMedia).call(navigator,n,t,i)})}}:null;t.URL=t.URL||t.webkitURL||t.mozURL||t.msURL;this.userMedia=this.userMedia&&!!this.mediaDevices&&!!t.URL;navigator.userAgent.match(/Firefox\D+(\d+)/)&&parseInt(RegExp.$1,10)<21&&(this.userMedia=null);this.userMedia&&t.addEventListener("beforeunload",function(){n.reset()})},exifOrientation:function(t){var i=new DataView(t),r,s,h,u,c,l,y,o,f,a,v,e;if(i.getUint8(0)!=255||i.getUint8(1)!=216)return console.log("Not a valid JPEG file"),0;for(r=2,s=null;r8)?(console.log("Invalid EXIF orientation value ("+e+")"),0):e}else r+=2+i.getUint16(r+2)}return 0},fixOrientation:function(n,t,i){var r=new Image;r.addEventListener("load",function(){var u=document.createElement("canvas"),n=u.getContext("2d");t<5?(u.width=r.width,u.height=r.height):(u.width=r.height,u.height=r.width);switch(t){case 2:n.transform(-1,0,0,1,r.width,0);break;case 3:n.transform(-1,0,0,-1,r.width,r.height);break;case 4:n.transform(1,0,0,-1,0,r.height);break;case 5:n.transform(0,1,1,0,0,0);break;case 6:n.transform(0,1,-1,0,r.height,0);break;case 7:n.transform(0,-1,-1,0,r.height,r.width);break;case 8:n.transform(0,-1,1,0,0,r.width)}n.drawImage(r,0,0);i.src=u.toDataURL()},!1);r.src=n},attach:function(n){var y,c,l,i,v,a,s,o,h,e,p,w;if(typeof n=="string"&&(n=document.getElementById(n)||document.querySelector(n)),!n)return this.dispatch("error",new r("Could not locate DOM element to attach to."));if(this.container=n,n.innerHTML="",y=document.createElement("div"),n.appendChild(y),this.peg=y,this.params.width||(this.params.width=n.offsetWidth),this.params.height||(this.params.height=n.offsetHeight),!this.params.width||!this.params.height)return this.dispatch("error",new r("No width and/or height for webcam. Please call set() first, or attach to a visible element."));this.params.dest_width||(this.params.dest_width=this.params.width);this.params.dest_height||(this.params.dest_height=this.params.height);this.userMedia=f===undefined?this.userMedia:f;this.params.force_flash&&(f=this.userMedia,this.userMedia=null);typeof this.params.fps!="number"&&(this.params.fps=30);c=this.params.width/this.params.dest_width;l=this.params.height/this.params.dest_height;this.userMedia?(i=document.createElement("video"),i.setAttribute("autoplay","autoplay"),i.setAttribute("playsinline","playsinline"),i.style.width=""+this.params.dest_width+"px",i.style.height=""+this.params.dest_height+"px",(c!=1||l!=1)&&(n.style.overflow="hidden",i.style.webkitTransformOrigin="0px 0px",i.style.mozTransformOrigin="0px 0px",i.style.msTransformOrigin="0px 0px",i.style.oTransformOrigin="0px 0px",i.style.transformOrigin="0px 0px",i.style.webkitTransform="scaleX("+c+") scaleY("+l+")",i.style.mozTransform="scaleX("+c+") scaleY("+l+")",i.style.msTransform="scaleX("+c+") scaleY("+l+")",i.style.oTransform="scaleX("+c+") scaleY("+l+")",i.style.transform="scaleX("+c+") scaleY("+l+")"),n.appendChild(i),this.video=i,o=this,this.mediaDevices.getUserMedia({audio:!1,video:this.params.constraints||{mandatory:{minWidth:this.params.dest_width,minHeight:this.params.dest_height}}}).then(function(n){i.onloadedmetadata=function(){o.stream=n;o.loaded=!0;o.live=!0;o.dispatch("load");o.dispatch("live");o.flip()};"srcObject"in i?i.srcObject=n:i.src=t.URL.createObjectURL(n)}).catch(function(t){o.params.enable_flash&&o.detectFlash()?setTimeout(function(){o.params.force_flash=1;o.attach(n)},1):o.dispatch("error",t)})):this.iOS?(e=document.createElement("div"),e.id=this.container.id+"-ios_div",e.className="webcamjs-ios-placeholder",e.style.width=""+this.params.width+"px",e.style.height=""+this.params.height+"px",e.style.textAlign="center",e.style.display="table-cell",e.style.verticalAlign="middle",e.style.backgroundRepeat="no-repeat",e.style.backgroundSize="contain",e.style.backgroundPosition="center",v=document.createElement("span"),v.className="webcamjs-ios-text",v.innerHTML=this.params.iosPlaceholderText,e.appendChild(v),a=document.createElement("img"),a.id=this.container.id+"-ios_img",a.style.width=""+this.params.dest_width+"px",a.style.height=""+this.params.dest_height+"px",a.style.display="none",e.appendChild(a),s=document.createElement("input"),s.id=this.container.id+"-ios_input",s.setAttribute("type","file"),s.setAttribute("accept","image/*"),s.setAttribute("capture","camera"),o=this,h=this.params,s.addEventListener("change",function(n){var r,t,u,i;n.target.files.length>0&&n.target.files[0].type.indexOf("image/")==0&&(r=URL.createObjectURL(n.target.files[0]),t=new Image,t.addEventListener("load",function(){var n=document.createElement("canvas"),r,i;n.width=h.dest_width;n.height=h.dest_height;r=n.getContext("2d");ratio=Math.min(t.width/h.dest_width,t.height/h.dest_height);var u=h.dest_width*ratio,f=h.dest_height*ratio,o=(t.width-u)/2,s=(t.height-f)/2;r.drawImage(t,o,s,u,f,0,0,h.dest_width,h.dest_height);i=n.toDataURL();a.src=i;e.style.backgroundImage="url('"+i+"')"},!1),u=new FileReader,u.addEventListener("load",function(n){var i=o.exifOrientation(n.target.result);i>1?o.fixOrientation(r,i,t):t.src=r},!1),i=new XMLHttpRequest,i.open("GET",r,!0),i.responseType="blob",i.onload=function(){(this.status==200||this.status===0)&&u.readAsArrayBuffer(this.response)},i.send())},!1),s.style.display="none",n.appendChild(s),e.addEventListener("click",function(){h.user_callback?o.snap(h.user_callback,h.user_canvas):(s.style.display="block",s.focus(),s.click(),s.style.display="none")},!1),n.appendChild(e),this.loaded=!0,this.live=!0):this.params.enable_flash&&this.detectFlash()?(t.Webcam=u,e=document.createElement("div"),e.innerHTML=this.getSWFHTML(),n.appendChild(e)):this.dispatch("error",new r(this.params.noInterfaceFoundText));this.params.crop_width&&this.params.crop_height?(p=Math.floor(this.params.crop_width*c),w=Math.floor(this.params.crop_height*l),n.style.width=""+p+"px",n.style.height=""+w+"px",n.style.overflow="hidden",n.scrollLeft=Math.floor(this.params.width/2-p/2),n.scrollTop=Math.floor(this.params.height/2-w/2)):(n.style.width=""+this.params.width+"px",n.style.height=""+this.params.height+"px")},reset:function(){var n,t;this.preview_active&&this.unfreeze();this.unflip();this.userMedia&&(this.stream&&(this.stream.getVideoTracks?(n=this.stream.getVideoTracks(),n&&n[0]&&n[0].stop&&n[0].stop()):this.stream.stop&&this.stream.stop()),delete this.stream,delete this.video);this.userMedia!==!0&&this.loaded&&!this.iOS&&(t=this.getMovie(),t&&t._releaseCamera&&t._releaseCamera());this.container&&(this.container.innerHTML="",delete this.container);this.loaded=!1;this.live=!1},set:function(){if(arguments.length==1)for(var n in arguments[0])this.params[n]=arguments[0][n];else this.params[arguments[0]]=arguments[1]},on:function(n,t){n=n.replace(/^on/i,"").toLowerCase();this.hooks[n]||(this.hooks[n]=[]);this.hooks[n].push(t)},off:function(n,t){if(n=n.replace(/^on/i,"").toLowerCase(),this.hooks[n])if(t){var i=this.hooks[n].indexOf(t);i>-1&&this.hooks[n].splice(i,1)}else this.hooks[n]=[]},dispatch:function(){var f=arguments[0].replace(/^on/i,"").toLowerCase(),u=Array.prototype.slice.call(arguments,1),e,o,n,s;if(this.hooks[f]&&this.hooks[f].length){for(e=0,o=this.hooks[f].length;eERROR: the Webcam.js Flash fallback does not work from local disk. Please run it from a web server.<\/h3>';if(!this.detectFlash())return this.dispatch("error",new i("Adobe Flash Player not found. Please install from get.adobe.com/flashplayer and try again.")),'

'+this.params.flashNotDetectedText+"<\/h3>";if(!u){for(f="",o=document.getElementsByTagName("script"),r=0,s=o.length;r<\/embed><\/object>')},getMovie:function(){if(!this.loaded)return this.dispatch("error",new i("Flash Movie is not loaded yet"));var n=document.getElementById("webcam_movie_obj");return n&&n._snap||(n=document.getElementById("webcam_movie_embed")),n||this.dispatch("error",new i("Cannot locate Flash movie in DOM")),n},freeze:function(){var r=this,u=this.params,t,i,f;this.preview_active&&this.unfreeze();t=this.params.width/this.params.dest_width;i=this.params.height/this.params.dest_height;this.unflip();var e=u.crop_width||u.dest_width,o=u.crop_height||u.dest_height,n=document.createElement("canvas");n.width=e;n.height=o;f=n.getContext("2d");this.preview_canvas=n;this.preview_context=f;(t!=1||i!=1)&&(n.style.webkitTransformOrigin="0px 0px",n.style.mozTransformOrigin="0px 0px",n.style.msTransformOrigin="0px 0px",n.style.oTransformOrigin="0px 0px",n.style.transformOrigin="0px 0px",n.style.webkitTransform="scaleX("+t+") scaleY("+i+")",n.style.mozTransform="scaleX("+t+") scaleY("+i+")",n.style.msTransform="scaleX("+t+") scaleY("+i+")",n.style.oTransform="scaleX("+t+") scaleY("+i+")",n.style.transform="scaleX("+t+") scaleY("+i+")");this.snap(function(){n.style.position="relative";n.style.left=""+r.container.scrollLeft+"px";n.style.top=""+r.container.scrollTop+"px";r.container.insertBefore(n,r.peg);r.container.style.overflow="hidden";r.preview_active=!0},n)},unfreeze:function(){this.preview_active&&(this.container.removeChild(this.preview_canvas),delete this.preview_context,delete this.preview_canvas,this.preview_active=!1,this.flip())},flip:function(){if(this.params.flip_horiz){var n=this.container.style;n.webkitTransform="scaleX(-1)";n.mozTransform="scaleX(-1)";n.msTransform="scaleX(-1)";n.oTransform="scaleX(-1)";n.transform="scaleX(-1)";n.filter="FlipH";n.msFilter="FlipH"}},unflip:function(){if(this.params.flip_horiz){var n=this.container.style;n.webkitTransform="scaleX(1)";n.mozTransform="scaleX(1)";n.msTransform="scaleX(1)";n.oTransform="scaleX(1)";n.transform="scaleX(1)";n.filter="";n.msFilter=""}},savePreview:function(n,t){var r=this.params,i=this.preview_canvas,f=this.preview_context,u;t&&(u=t.getContext("2d"),u.drawImage(i,0,0));n(t?null:i.toDataURL("image/"+r.image_format,r.jpeg_quality/100),i,f);this.params.unfreeze_snap&&this.unfreeze()},snap:function(n,t){var c,i,u,f,s,h,e;if(n||(n=this.params.user_callback),t||(t=this.params.user_canvas),c=this,i=this.params,!this.loaded)return this.dispatch("error",new r("Webcam is not loaded yet"));if(!n)return this.dispatch("error",new r("Please provide a callback function or canvas to snap()"));if(this.preview_active)return this.savePreview(n,t),null;if(u=document.createElement("canvas"),u.width=this.params.dest_width,u.height=this.params.dest_height,f=u.getContext("2d"),this.params.flip_horiz&&(f.translate(i.dest_width,0),f.scale(-1,1)),s=function(){var r,e,o;this.src&&this.width&&this.height&&f.drawImage(this,0,0,i.dest_width,i.dest_height);i.crop_width&&i.crop_height&&(r=document.createElement("canvas"),r.width=i.crop_width,r.height=i.crop_height,e=r.getContext("2d"),e.drawImage(u,Math.floor(i.dest_width/2-i.crop_width/2),Math.floor(i.dest_height/2-i.crop_height/2),i.crop_width,i.crop_height,0,0,i.crop_width,i.crop_height),f=e,u=r);t&&(o=t.getContext("2d"),o.drawImage(u,0,0));n(t?null:u.toDataURL("image/"+i.image_format,i.jpeg_quality/100),u,f)},this.userMedia)f.drawImage(this.video,0,0,this.params.dest_width,this.params.dest_height),s();else if(this.iOS){var l=document.getElementById(this.container.id+"-ios_div"),e=document.getElementById(this.container.id+"-ios_img"),o=document.getElementById(this.container.id+"-ios_input");iFunc=function(){s.call(e);e.removeEventListener("load",iFunc);l.style.backgroundImage="none";e.removeAttribute("src");o.value=null};o.value?iFunc(null):(e.addEventListener("load",iFunc),o.style.display="block",o.focus(),o.click(),o.style.display="none")}else h=this.getMovie()._snap(),e=new Image,e.onload=s,e.src="data:image/"+this.params.image_format+";base64,"+h;return null},configure:function(n){n||(n="camera");this.getMovie()._configure(n)},flashNotify:function(n,t){switch(n){case"flashLoadComplete":this.loaded=!0;this.dispatch("load");break;case"cameraLive":this.live=!0;this.dispatch("live");break;case"error":this.dispatch("error",new i(t))}},b64ToUint6:function(n){return n>64&&n<91?n-65:n>96&&n<123?n-71:n>47&&n<58?n+4:n===43?62:n===47?63:0},base64DecToArr:function(n,t){for(var s=n.replace(/[^A-Za-z0-9\+\/]/g,""),r=s.length,h=t?Math.ceil((r*3+1>>2)/t)*t:r*3+1>>2,c=new Uint8Array(h),u,f,e=0,o=0,i=0;i>>(16>>>u&24)&255;e=0}return c},upload:function(n,t,i){var o=this.params.upload_name||"webcam",f="",s,r,h,c,e;if(n.match(/^data\:image\/(\w+)/))f=RegExp.$1;else throw"Cannot locate image format in Data URI";s=n.replace(/^data\:image\/\w+\;base64\,/,"");r=new XMLHttpRequest;r.open("POST",t,!0);r.upload&&r.upload.addEventListener&&r.upload.addEventListener("progress",function(n){if(n.lengthComputable){var t=n.loaded/n.total;u.dispatch("uploadProgress",t,n)}},!1);h=this;r.onload=function(){i&&i.apply(h,[r.status,r.responseText,r.statusText]);u.dispatch("uploadComplete",r.status,r.responseText,r.statusText)};c=new Blob([this.base64DecToArr(s)],{type:"image/"+f});e=new FormData;e.append(o,c,o+"."+f.replace(/e/,""));r.send(e)}};u.init();typeof define=="function"&&define.amd?define(function(){return u}):typeof module=="object"&&module.exports?module.exports=u:t.Webcam=u})(window),function(n,t,i,r){"use strict";var u=function(u,f,e){var o=this;if(o.uploadUrl=u,o.dropTarget=f,o.uploadProgressContainer=e,o._uploadFilesInput=null,o.uploadFiles=function(){!o._uploadFilesInput||o._uploadFilesInput.remove();o._uploadFilesInput=i("");o._uploadFilesInput.attr({type:"file",multiple:"multiple",title:"Disco ICT File Uploading"}).hide().change(function(n){var t=n.target.files;!!t&&t.length>0&&o._uploadFiles(t);o._uploadFilesInput.remove()}).appendTo(o.uploadProgressContainer).click()},!!o.dropTarget){var c=i(t),s=!1,h=null;c.on("dragover",function(){o.dropTarget.addClass("dragHighlight");o.dropTarget.removeClass("dragHover");s=!1});c.on("dragleave",function(){!h||n.clearInterval(h);s=!0;n.setTimeout(function(){s&&o.dropTarget.removeClass("dragHighlight");h=null},200)});o.dropTarget.on("dragover",function(n){n.stopPropagation();n.preventDefault();o.dropTarget.addClass("dragHover");s=!1;n.originalEvent.dataTransfer.dropEffect="copy"});o.dropTarget.on("drop",function(n){n.stopPropagation();n.preventDefault();s=!0;o.dropTarget.removeClass("dragHighlight");var t=n.originalEvent.dataTransfer.files;o._uploadFiles(t)})}return o.uploadImage=function(){function s(){var n=r.snap();o._uploadImage(n)}var u=720,f=540,t=i("
").attr({id:"Disco_AttachmentUpload_ImageDialog",title:"Upload Image","class":"dialog Disco-AttachmentUpload-ImageDialog"}),e;t.dialog({autoOpen:!0,draggable:!1,modal:!0,resizable:!1,width:u,height:f,close:function(){r.reset();n.setTimeout(function(){t.dialog("destroy")},1)}}).closest(".ui-dialog").children(".ui-dialog-titlebar").css("border-bottom","none");e=[{text:"Capture",click:s}];r.set({width:u,height:f,dest_width:u*1.5,dest_height:f*1.5,jpeg_quality:95});r.setSWFLocation("/ClientSource/Scripts/Modules/Disco-AttachmentUploader/webcam.swf");r.on("error",function(n){alert(n);t.dialog("close")});r.on("live",function(){t.dialog("option","buttons",e);t.closest(".ui-dialog").children(".ui-dialog-buttonpane").css("margin-top",0).find(".ui-button:first").focus()});r.attach(t.attr("id"))},o.getFileComments=function(t,r,u){var o=!1,f=i("
").attr({title:"Upload File","class":"dialog Disco-AttachmentUpload-CommentDialog"}),s,h,e;f.html('
File Name:<\/th><\/td><\/tr>
Comments:<\/th><\/input><\/td><\/tr>
<\/td><\/tr><\/table>');!r||(s=f.find("td.thumbnail"),h=s.find("img"),r(h)&&s.show());f.find("td.filename").text(t).attr("title",t);e=f.find("input.comments").keypress(function(n){n.which===13&&(!e.val()||(o=!0,f.dialog("close")))});f.dialog({resizable:!1,width:400,modal:!0,autoOpen:!0,buttons:{Upload:function(){e.val()?(o=!0,f.dialog("close"),n.setTimeout(function(){e.focus()},1)):alert("Please provide a comment for this attachment.")},Cancel:function(){f.dialog("close")}},close:function(){var n=e.val();f.dialog("destroy").remove();u(o,n)}})},o._uploadImage=function(n){o._hideFlashVideoOverlay()&&i("#webcam_movie_obj, #webcam_movie_embed").css("display","none");var u=n.replace(/^data\:image\/\w+\;base64\,/,""),f=new Blob([r.base64DecToArr(u)],{type:"image/jpeg"}),t="CapturedImage-"+moment().format("YYYYMMDD-HHmmss")+".jpg";o.getFileComments(t,function(t){return t.attr("src",n),!0},function(n,r){(o._hideFlashVideoOverlay()&&i("#webcam_movie_obj, #webcam_movie_embed").css("display",""),n)&&o._uploadFile(f,t,r)})},o._uploadFiles=function(n){var t=i.makeArray(n),r=function(){if(t&&t.length!==0){var n=t.shift();o.getFileComments(n.name,function(t){if(!!n.type&&n.type.indexOf("image/")===0){var i=new FileReader;return i.onload=function(n){t.attr("src",n.target.result)},i.readAsDataURL(n),!0}return!1},function(t,i){t&&(o._uploadFile(n,n.name,i),r())})}};r()},o._uploadFile=function(n,t,r){var f=new FormData,u=new XMLHttpRequest,e=i("
").append(i("").addClass("fa fa-cog fa-spin")).append(i("").text("Uploading: "+t)).appendTo(o.uploadProgressContainer);f.append("Comments",r);f.append("File",n,t);u.open("POST",o.uploadUrl,!0);u.onreadystatechange=function(){u.readyState===4&&(u.status!==200&&alert("Error Uploading ["+t+"]: "+u.statusText),e.slideUp(400,function(){e.remove()}))};u.send(f)},o.__hideFlashVideoOverlay=null,o._hideFlashVideoOverlay=function(){if(o.__hideFlashVideoOverlay===null){o.__hideFlashVideoOverlay=!1;try{var n=/(windows nt) ([\w.]+)/.exec(navigator.userAgent.toLowerCase());!!n&&parseFloat(n[2])<=6.2&&(o.__hideFlashVideoOverlay=!0)}catch(t){}}return o.__hideFlashVideoOverlay},o};t.Disco||(t.Disco={});t.Disco.AttachmentUploader=u}(this,document,$,Webcam);