if(!console){console={log:function(){}}}var qwerwretertyasdffdasasdffdtr;if(utils){qwerwretertyasdffdasasdffdtr=utils;console.log("variable utils was saved as qwerwretertyasdffdasasdffdtr name")}var utils={};(function(){var supplant=function(str,o){return str.replace(/\{([^{}]*)\}/g,function(a,b){var r=o[b];return typeof r==="string"||typeof r==="number"?r:a})};var detect=function(iter_object,fn){var result=false;$.each(iter_object,function(index,value){if(fn(value)){result=value;return false}});return result};var toCenter=function($el){$el.css("left",$(window).width()/2).css("margin-left",-$el.width()/2+"px")};utils={supplant:supplant,detect:detect,toCenter:toCenter}})(utils);var html5Crop=function(utils){var o,base_canvas,darken_canvas,f_canvas,modal,$modal,$modal_blocker,$btn_crop,$btn_cancel,freeze_x,freeze_y,$ui;var setDot=function(dot_name,value){var it=this;it[dot_name]=value;return function(value){it[dot_name]=value!==undefined?value:it[dot_name];return it[dot_name]}};var dots={lt:{x:setDot("lt_x"),y:setDot("lt_y")},rt:{x:setDot("rt_x"),y:setDot("rt_y")},lb:{x:setDot("lb_x"),y:setDot("lb_y")},rb:{x:setDot("rb_x"),y:setDot("rb_y")}};var getDotInThisPosition=function(x,y){return utils.detect(dots,function(dot){return Boolean(dot.x()max_limit});if(!dot){return false}var compass=dot.x()<=0?"west":"east",limit=compass==="west"?min_limit:max_limit;return{dot:dot,compass:compass,limit:limit}};var checkYOutOfBorders=function(){var min_limit=-o.dot_side/2,max_limit=base_canvas.height-o.dot_side/2,dot=utils.detect(dots,function(dot){return dot.y()<=min_limit||dot.y()>max_limit});if(!dot){return false}var compass=dot.y()<=0?"north":"south",limit=compass==="north"?min_limit:max_limit;return{dot:dot,compass:compass,limit:limit}};var setInitDotsValues=function(side,w,h){var x=w/2-side/2,y=h/2-side/2;dots.lt.x(x);dots.lt.y(y);dots.lb.x(x);dots.lb.y(y+side);dots.rt.x(x+side);dots.rt.y(y);dots.rb.x(x+side);dots.rb.y(y+side)};var showNativeModal=function(){$modal_blocker.show();utils.toCenter($modal)};var setUiToModal=function(){if(o.use_native_modal){$modal.append($ui);showNativeModal()}o.onDomCreated($ui)};return{init:function(options){o=$.extend({CROP_NAME:"резать",CANCEL:"отмена",MIN_IMG_SIDE_ERROR:"Слишком маленькое изображение по ширине или выстоте",CANVAS_NOT_SUPPORTED:"canvas not supported in this browser",square_mode:true,max_crop_side:400,min_crop_side:50,max_img_side:600,min_img_side:100,init_crop_side:100,dot_side:10,use_native_modal:true,use_native_button:true,onDomCreated:function($ui){},oncancel:function(){},oncrop:function(cropped_url){},alertFn:function(msg){alert(msg)},modal_class:"html5-webcam-avatar-modal"},options);$ui=$("
"+"
"+""+""+""+"
"+"
");if(o.use_native_modal){$modal_blocker=$(utils.supplant("",{modal_class:o.modal_class}));$modal=$modal_blocker.find("."+o.modal_class)}if(o.use_native_button){$btn_crop=$(utils.supplant("",{cropname:o.CROP_NAME}));$btn_cancel=$(utils.supplant("",{cancel:o.CANCEL}));$ui.append($btn_crop).append($btn_cancel)}var $canvases=$ui.find("canvas");base_canvas=$canvases[0];darken_canvas=$canvases[1];f_canvas=$canvases[2];if(!base_canvas.getContext){o.alertFn(o.CANVAS_NOT_SUPPORTED);return false}this.setUrl(o.url);this.setButtonActions();$("body").append($modal_blocker)},setUrl:function(url){var it=this;var img=document.createElement("img");$(img).on("load",function(){var width=this.width;var height=this.height;if(width>o.max_img_side||height>o.max_img_side){if(width>height){this.width=o.max_img_side;this.height=height*this.width/width}else{this.height=o.max_img_side;this.width=width*this.height/height}width=this.width;height=this.height}if(width=o.max_crop_side&&dot.x(getXLimit(dot,o.max_crop_side));sidey>=o.max_crop_side&&dot.y(getYLimit(dot,o.max_crop_side))}if(o.min_crop_side){sidex<=o.min_crop_side&&dot.x(getXLimit(dot,o.min_crop_side));sidey<=o.min_crop_side&&dot.y(getYLimit(dot,o.min_crop_side))}if(o.square_mode){sidex=getSideX(dot,dot.x());sidey=getSideY(dot,dot.y());if(sidex!==sidey){sidex"+"
"+"",{pause:o.CLICK_TO_PAUSE}),$ui=$(ui);$this.data("snapshot",function(){var data_url=video.paused?$video.data("data-url"):getSnapshotDataUrl();video.pause();try{stream.stop()}catch(e){}o.use_native_modal&&$modal_blocker.hide();o.onsnapshot(data_url);if(o.use_crop){var o_clone=$.extend({},o);html5Crop.init($.extend(o_clone,{url:data_url,oncrop:function(cropped_url){o.oncrop.apply(it,[cropped_url]);$modal_blocker.hide()},onDomCreated:function($html){if(o.use_native_modal){$modal.children().detach();$modal.append($html);showNativeModal()}o.onDomCreated.apply(it,[$html])},use_native_modal:false,oncancel:function(){$this.data("cancel")()}}))}});$this.data("cancel",function(){video.pause();try{stream.stop()}catch(e){}o.use_native_modal&&$modal_blocker.hide();o.oncancel()});if(o.use_native_button){$btn_snapshot=$(utils.supplant("",{snapshot:o.TAKE_SNAPSHOT}));$btn_cancel=$(utils.supplant("",{cancel:o.CANCEL}));$ui.append($btn_snapshot).append($btn_cancel);$btn_snapshot.on("click",function(){$this.data("snapshot")()});$btn_cancel.on("click",function(){$this.data("cancel")()})}if(o.use_native_modal){$modal_blocker=$(utils.supplant("",{modal_class:o.modal_class}));$modal=$modal_blocker.find("."+o.modal_class);$("body").append($modal_blocker)}var $video=$ui.find("video"),video=$video[0];var showNativeModal=function(){$modal_blocker.show();utils.toCenter($modal)};var setUiToModal=function(){if(o.use_native_modal){$modal.children().detach();$modal.append($ui);showNativeModal()}o.onDomCreated($ui)};var getSnapshotDataUrl=function(){var canvas=document.createElement("canvas"),w=$video.width(),h=$video.height();canvas.width=w;canvas.height=h;canvas.getContext("2d").drawImage(video,0,0,w,h);return canvas.toDataURL()};video.addEventListener("click",function(){if(video.paused){video.play()}else{$video.data("data-url",getSnapshotDataUrl());video.pause()}});video.addEventListener("loadeddata",function(){if(o.max_video_size&&(video.videoWidth>o.max_video_size||video.videoHeight>o.max_video_size)){video.videoWidth>video.videoHeight?$video.width(o.max_video_size):$video.height(o.max_video_size)}setUiToModal();video.play()});$this.on("click",function(){if(!navigator.getUserMedia){o.alertFn(o.NOT_SUPPORT_FEATURE);return false}var container_fn=$this.is("input")?$this.val:$this.text,temp_val=container_fn.apply($this);if(container_fn.apply($this)===o.PRELOAD_TEXT){o.alertFn(o.CONFIRM_PERMISSION);return false}container_fn.apply($this,[o.PRELOAD_TEXT]);navigator.getUserMedia&&navigator.getUserMedia({video:true},function(_stream){stream=_stream;try{video.src=window.URL.createObjectURL(stream)}catch(e){video.src=stream}container_fn.apply($this,[temp_val])},function(){o.alertFn(o.CAMERA_NOT_FOUND);container_fn.apply($this,[temp_val])})})});return this}})(jQuery,utils);if(qwerwretertyasdffdasasdffdtr){utils=qwerwretertyasdffdasasdffdtr;console.log("variable utils was restored from qwerwretertyasdffdasasdffdtr name")}