-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathimageMaker.min.js
1 lines (1 loc) · 30.6 KB
/
imageMaker.min.js
1
!function(e,t){void 0===t&&console.error("Image Maker requires jQuery."),t.fn.imageMaker=function(e){var a={wrapperMain:".wrapper-memes-main",wrapperOperations:".wrapper-memes-operations",wrapperUploadImage:".wrapper_upload_image",wrapperTextBoxes:".amm-text-boxes",wrapperMemesPreview:".wrapper-memes-preview",wrapperMemesPreviewOperations:".wrapper-memes-preview-operations",wrapperCanvasBackground:".wrapper_canvas_background",wrapperCanvas:".wrapper_canvas",wrapperSelectImageAmm:".wrapper_select_image_amm",wrapperHoverTitleMemeAmm:".wrapper_hover_title_meme_amm",wrapperThumbnailMeme:".wrapper_thumbnail_meme",ammCanvas:".amm_canvas",addTextBox:".add_textbox",generateMeme:"generateMeme"};t(this).each(function(n){var r=t(this),s={id:this.id?this.id:Math.floor(Math.random()*Math.floor(Math.random()*Date.now())),canvas:null,ctx:null,final_width:0,final_height:0,_maxWidth:500,_maxHeight:700,position_left:0,ratio_image:1,ratio_width:0,ratio_height:0,height_div:100,text_boxes_count:2,merge_images:[],merge_image_thumbnail_width:"auto",merge_image_thumbnail_height:50,template_thumbnail_width:50,template_thumbnail_height:50,templates:[],img:null,downloadGeneratedImage:!0,onGenerate:function(e,t){},preRender:function(e){return e},onInitialize:function(e){},onLoad:function(e){},alterTextInfo:function(e){},alterFontFamilies:function(e){},i18n:{fontFamilyText:"Font Family",enterTextText:"Enter Text",topText:"Top Text",bottomText:"Bottom Text",sizeText:"Size",uperCaseText:"UperCase",mergeImageText:"Merge Image",drawText:"Draw",addTextBoxText:"Add TextBox",previewText:"Preview",addTemplateText:"Add template",resetText:"Reset",imageGeneratorText:"Image maker",stopBrushingText:"Stop Brushing",canvasLoadingText:"Canvas Loading"},weight:"brushes"};t.extend(!0,s,e),s.templates.length||s.templates.push({url:"data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs",title:"Empty black"});var o=function(e){var a='<div class="view-images-memes-ar-amm">';a+='<div class="wrapper_hover_title_meme_amm"></div>',a+='<div class="wrapper_thumbnail_meme">',t.each(e.templates,function(t,n){a+='<div class="wrapper_select_image_amm">',a+='<img typeof="foaf:Image" width="'+e.template_thumbnail_width+'" height="'+e.template_thumbnail_height+'" src="'+n.url+'" title="'+n.title+'">',a+="</div>"}),a+="</div>",a+="</div>";var n='<div class="wrapper-amm-select-merge-images">';return n+='<div class="wrapper-amm-hover-title-merge-images"></div>',n+='<div class="wrapper-thumbnail-merge-images">',t.each(e.merge_images,function(t,a){n+='<div class="wrapper-select-merge-image-amm">',n+='<img typeof="foaf:Image" width="'+e.merge_image_thumbnail_width+'" height="'+e.merge_image_thumbnail_height+'" src="'+a.url+'" title="'+a.title+'">',n+="</div>"}),n+="</div>",n+="</div>",'<div class="wrapper-memes-main">\n \n <div class="wrapper-memes-preview">\n <div class="wrapper-memes-preview-operations">\n \n <button class="trigger-element first fileUpload btn btn-sm btn-default" target_element_triggered=".amm-addImage" id="amm-merge-image-trigger">\n <input type="file" class="upload amm-addImage" name="addImage"> \n <span class="glyphicon glyphicon-picture"></span> \n <span class="text_value">'+e.i18n.mergeImageText+'</span>\n </button> \n <button class="trigger-element btn btn-sm btn-default" id="amm-brushes">\n <span class="glyphicon glyphicon-pencil"></span> <span class="text_value">'+e.i18n.drawText+'</span>\n </button> \n \n <button class="responsive-button hide-responsive-button last btn btn-sm btn-default" id="amm-preview-responsive">\n <span class="glyphicon glyphicon-eye-open"></span> <span class="text_value">'+e.i18n.previewText+'</span>\n </button> \n <button href="#" class="trigger-element responsive-button hide-responsive-button first fileUpload btn btn-sm btn-default" \n target_element_triggered="#amm-input-upload-image-meme-responsive" id="amm-upload-image-meme-responsive">\n <input type="file" class="upload" id="amm-input-upload-image-meme-responsive" name="addImage-responsive"> <span class="glyphicon glyphicon-paperclip"></span> <span class="text_value">'+e.i18n.addTemplateText+'</span>\n </button> \n \n \n <div class="wrapper-amm-stop-brushes">\n <button type="submit" class="btn btn-danger" value="Clear" id="amm-clear-brush">Clear</button>\n <button type="submit" class="btn btn-default" value="Stop Brushing" id="amm-stop-brushing">'+e.i18n.stopBrushingText+'</button>\n <input type="color" data-on="brushes" class="amm-color-picker colorSelectorBrushes" name="colorSelectorBrushes" value="#ffffff" List/>\n <div class="clear_both"></div>\n </div>\n \n <div class="clear_both"></div>\n </div>\n \n <div id="wrapper_canvas_background">\n <div class="wrapper_canvas">\n <canvas id="'+e.id+'" class="amm_canvas"></canvas>\t \n </div>\n <div class="canvas_loading">'+e.i18n.canvasLoadingText+'</div>\n \n </div> \n \n <form class="form-generat-meme" action="meme-generator-callback" method="post" enctype="multipart/form-data">\n <a href="#" type="submit" class="generate_meme btn btn-default btn-primary form-submit" disabled="disabled" >'+e.i18n.imageGeneratorText+'</a>\n <button type="submit" class="btn btn-default btn-danger form-submit reset_meme" >'+e.i18n.resetText+'</button>\n </form>\n \n </div>\n \n\n <div class="wrapper-memes-operations">\n '+n+"\n "+a+'\n <div class="amm-text-boxes"></div>\n <form action="/" method="post" class="advanced-options-operations-form" accept-charset="UTF-8"><div><input type="hidden" name="form_build_id" value="form-C56rQ956oZXaasEGaFTd4nA7cf4GnkPvYCU0HEoO-fg">\n <input type="hidden" name="form_id" value="advanced_options_operations_form">\n <button class="add_textbox btn btn-success form-submit edit-add-textbox" name="op" value="add_textbox" type="button">'+e.i18n.addTextBoxText+'</button>\n </div></form>\n </div>\n\n <div class="clear_both"> </div>\n\n </div>'}(s);o=s.preRender(o),r.append(o),s.onInitialize(s),Texts=function(){},Object.defineProperty(Texts.prototype,"length",{get:function(){var e=0;for(var t in this)this.hasOwnProperty(t)&&e++;return e}}),Object.defineProperty(Texts.prototype,"keys",{get:function(){var e=[];for(var t in this)this.hasOwnProperty(t)&&e.push(t);return e}}),Object.defineProperty(Texts.prototype,"empty",{get:function(){for(var e in this)if(this.hasOwnProperty(e)&&null!=this[e]&&t.trim(this[e].text))return!1;return!0}}),Texts.prototype.reset=function(){for(var e in this)this[e].text="";return t(_.get_texts_class()).val(""),r.trigger({type:"CanvasPostChange",value:this,on:"resetTexts"}),!0};var l=new Texts,d=function(){},m=new FormData;Object.defineProperty(d.prototype,"length",{get:function(){var e=0;for(var t in this)this.hasOwnProperty(t)&&e++;return e}}),Object.defineProperty(d.prototype,"keys",{get:function(){var e=[];for(var t in this)this.hasOwnProperty(t)&&e.push(t);return e}}),d.prototype.reset=function(){for(var e in this)delete this[e];return t(_.get_images_class()).remove(),r.trigger({type:"CanvasPostChange",value:this,on:"resetImages"}),!0};var p=function(){};Object.defineProperty(p.prototype,"length",{get:function(){var e=0;for(var t in this)this.hasOwnProperty(t)&&e++;return e}}),Object.defineProperty(p.prototype,"add",{get:function(e){this[this.length]=e}}),Object.defineProperty(p.prototype,"keys",{get:function(){var e=[];for(var t in this)this.hasOwnProperty(t)&&e.push(t);return e}}),p.prototype.reset=function(){for(var e in this)delete this[e];return r.trigger({type:"CanvasPostChange",value:this,on:"resetBrushes"}),!0};var c=new p,u={lineWidth:3,strokeStyle:"#ffffff"},h=function(e,t){this.x=e,this.y=t,h.prototype.lineWidth=3,h.prototype.strokeStyle="#ffffff"},g=new d,f=function(){this.id=null,this.delta=null,this.top=20,this.left=20,this.height=100,this.width=100,this.ratioWidth=this.width/s.final_width,this.ratioHeight=this.height/s.final_height,this.ratioLeft=this.left/r.find(a.ammCanvas).width(),this.ratioTop=this.top/r.find(a.ammCanvas).height(),this.img=null},v={originalImage:null,memeGenerator:0,text:0},_={};function x(e){e.id="imageBoxDR_"+s.id+"_"+g.length,e.delta=g.length,g[e.id]=e,e.img.onload=function(){r.trigger({type:"CanvasPreChange",value:e.img,on:"addImage"}),y.canvas_addimage(),r.trigger({type:"CanvasPostChange",value:e.img,on:"addImage"});var n=t('<div id="'+e.id+'" class="imageBoxDR"></div>'),i=t('<button class="delete-box-amm delete-pr-merge-image"></button>');n.append(i),i.on("click tap touchstart",function(){r.find("#"+e.id).resizable("destroy").draggable("destroy").remove(),delete g[e.id],r.trigger({type:"CanvasPreChange",value:s.img,on:"deleteMergeImage"}),y.canvas_reset(s.img),y.drawBrushesPoints(),y.canvas_addimage(null,null),y.canvas_filltext(null,null),r.trigger({type:"CanvasPostChange",value:s.img,on:"deleteMergeImage"})}),r.find(".wrapper_canvas").prepend(n),r.find("#"+e.id).draggable({containment:r.find(a.wrapperCanvas),refreshPositions:!0,create:function(e,t){},start:function(e,a){a.position.top+=t(window).scrollTop()},drag:function(a,n){r.trigger({type:"CanvasPreChange",value:{ui:n,delta:e.delta,this:t(this)},on:"dragImage"}),y.canvas_reset(s.img),y.drawBrushesPoints(),y.canvas_filltext(null,null),y.canvas_addimage(n,t(this).attr("id")),r.trigger({type:"CanvasPostChange",value:{ui:n,delta:e.delta,this:t(this)},on:"dragImage"})},stop:function(e,t){}}).resizable({handles:"all",resize:function(a,n){r.trigger({type:"CanvasPreChange",value:{ui:n,delta:e.delta,this:t(this)},on:"resizeImage"}),y.canvas_reset(s.img),y.drawBrushesPoints(),y.canvas_filltext(null,null),y.canvas_addimage(n,t(this).attr("id")),r.trigger({type:"CanvasPostChange",value:{ui:n,delta:e.delta,this:t(this)},on:"resizeImage"})},containment:r.find(a.wrapperCanvas),minHeight:50,minWidth:50}).css({border:"1px dashed white",position:"absolute",width:e.width+"px",height:e.height+"px"}).animate({opacity:0},1e3,function(){}),t(window).resize()}}_={get_pointOptions:function(){return u},get_brushesPoints:function(){return c},get_texts:function(){return l},get_texts_class:function(){return".amm-text"},get_images_class:function(){return".imageBoxDR"},get_images:function(){return g},set_images:function(e){g=e},get_text_id:function(e){return"text_"+s.id+"_"+e},get_text:function(e){return l["text_"+s.id+"_"+e]},set_text:function(e){l["text_"+s.id+"_"+e.delta]=e},set_texts:function(e){l=e},get_canvas_info:function(){return s},set_canvas_info:function(e){s=e},is_responsive:function(){return t(window).width()<=800},is_parent_mobile_screen:function(){return r.width()<=800},focusout:function(){r.find("textarea").blur()},find_highest_ZIndex:function(){return Math.max.apply(null,t.map(t("body *"),function(e,a){if("static"!=t(e).css("position"))return parseInt(t(e).css("z-index"))||1}))}},window.onload=function(){},r.on("click",".add_textbox",function(e){e.preventDefault();var n={toUpperCase:!0,id:null,id_box:null,delta:null,ratioWidth:1,ratioHeight:s.height_div/s.final_height,ratioLeft:0,ratioTop:0,text:"",shadowColor:"black",shadowBlur:3,textColor:"#ffffff",textAlign:"center",strokeColor:"#000000",lineWidth:3,fontStyle:"normal",fontVariant:"normal",fontWeight:"bold",fontFamily:"impact",fontSize:50,inputFontSize:50,top:0,left:0,heigth:0,width:0,placeholder:s.i18n.enterTextText,elementChanged:null,event:null,isNew:!0,getParent:function(){return t('.wrapper-text[delta="'+this.delta+'"]')},getParentClass:function(){return'.wrapper-text[delta="'+this.delta+'"]'},getInfo:function(){return""},clone:function(){var e={};return jQuery.extend(e,this),e}},i=l.length;t.each(l.keys,function(e,t){if(null==l[t]){var a=t.split("_","");i=a[a.length-1]}}),n.id="text_"+s.id+"_"+i,n.id_box="boxDR_"+s.id+"_"+i,n.delta=i,s.alterTextInfo(n);var o=0;0==i&&(n.placeholder=s.i18n.topText),1==i&&(n.placeholder=s.i18n.bottomText,o=r.find(a.ammCanvas).height()-r.find(a.ammCanvas).outerHeight()*n.ratioHeight),i>1&&(o=r.find(a.ammCanvas).height()/2-r.find(a.ammCanvas).outerHeight()*n.ratioHeight/2),n.ratioTop=o/r.find(a.ammCanvas).height(),l[n.id]=n;var d=T.wrapper_text(n);r.find(".amm-text-boxes").append(d);var m=t('<div id="'+n.id_box+'" font="20px Arial" class="boxDR"></div>'),p=t('<button href="#" class="delete-box-amm delete-text-boxes"></button>');m.append(p),p.on("click tap touchstart",function(){r.find("#"+n.id).closest(".wrapper-text").remove(),r.find("#"+n.id_box).resizable("destroy").draggable("destroy").remove(),l[n.id]=null,r.trigger({type:"CanvasPreChange",value:s.img,on:"fillText"}),y.canvas_reset(s.img),y.drawBrushesPoints(),y.canvas_addimage(null,null),y.canvas_filltext(null,null),r.trigger({type:"CanvasPostChange",value:s.img,on:"fillText"})}),r.find(".wrapper_canvas").prepend(m),r.find("#"+n.id_box).draggable({containment:r.find(a.wrapperCanvas),refreshPositionsType:!0,create:function(e,t){},start:function(e,t){},drag:function(e,a){r.trigger({type:"CanvasPreChange",value:{ui:a,delta:i,this:t(this)},on:"dragText"}),y.canvas_reset(s.img),y.drawBrushesPoints(),y.canvas_addimage(null,null),y.canvas_filltext(a,t(this).attr("id")),r.trigger({type:"CanvasPostChange",value:{ui:a,delta:i,this:t(this)},on:"dragText"})},stop:function(e,t){}}).resizable({handles:"all",resize:function(e,a){r.trigger({type:"CanvasPreChange",value:{ui:a,delta:i,this:t(this)},on:"resizeText"}),y.canvas_reset(s.img),y.drawBrushesPoints(),y.canvas_addimage(null,null),y.canvas_filltext(a,t(this).attr("id")),r.trigger({type:"CanvasPostChange",value:{ui:a,delta:i,this:t(this)},on:"resizeText"})},containment:r.find(a.wrapperCanvas),minHeight:50,minWidth:50}).css({border:"1px dashed white",position:"absolute",width:s.final_width+"px",height:s.height_div+"px"}).animate({opacity:0},1e3,function(){}),t(window).resize()}),r.on("click",".btn",function(e){var a=t(this).attr("target_element_triggered");t(e.target).is(a)||t(this).hasClass("trigger-element")&&r.find(t(this).attr("target_element_triggered")).click()}),t("#amm-preview-responsive").click(function(e){t(".boxDR, .imageBoxDR").hasClass("ForceHide")?(t(this).removeClass("active"),t(".boxDR, .imageBoxDR").removeClass("ForceHide")):(t(this).addClass("active"),t(".boxDR, .imageBoxDR").addClass("ForceHide"))}),t(window).resize(function(e){e.target==window&&(t.each(l.keys,function(e,t){null!=l[t]&&(r.find("#"+l[t].id_box).width(r.find(a.ammCanvas).outerWidth()*l[t].ratioWidth),r.find("#"+l[t].id_box).height(r.find(a.ammCanvas).outerHeight()*l[t].ratioHeight),r.find("#"+l[t].id_box).css("left",r.find(a.ammCanvas).outerWidth()*l[t].ratioLeft+"px"),r.find("#"+l[t].id_box).css("top",r.find(a.ammCanvas).outerHeight()*l[t].ratioTop+"px"))}),t.each(g.keys,function(e,t){r.find("#"+g[t].id).width(r.find(a.ammCanvas).outerWidth()*g[t].ratioWidth),r.find("#"+g[t].id).height(r.find(a.ammCanvas).outerHeight()*g[t].ratioHeight),r.find("#"+g[t].id).css("left",r.find(a.ammCanvas).outerWidth()*g[t].ratioLeft+"px"),r.find("#"+g[t].id).css("top",r.find(a.ammCanvas).outerHeight()*g[t].ratioTop+"px")}))}),r.on("keyup",".wrapper-text .amm-text",function(e){var a=t(this).closest(".wrapper-text").attr("delta"),n="text_"+s.id+"_"+a;l[n].event=e,l[n].text=t("#"+l[n].id).val(),r.trigger({type:"CanvasPreChange",value:a,on:"fillText"}),y.canvas_reset(s.img),y.drawBrushesPoints(),y.canvas_addimage(null,null),y.canvas_filltext(null,null),r.trigger({type:"CanvasPostChange",value:a,on:"fillText"})}),r.find(".amm-addImage").change(function(e){var t=new f;t.img=new Image;var a=new FileReader;a.onload=function(e){t.img.src=e.target.result,x(t)},a.readAsDataURL(this.files[0])}),r.find(".reset_meme").click(function(e){e.preventDefault(),y.canvas_reset(s.img),c.reset(),l.reset(),g.reset()}),r.on("click",".wrapper-select-merge-image-amm",function(e){r.find(".wrapper-amm-hover-title-merge-images").text(t(this).find("img").attr("title")),r.find("*").removeClass("SI_amm_mi_selected"),t(this).addClass("SI_amm_mi_selected");var a=new f;a.img=new Image,a.img.src=t(this).find("img").attr("src"),/^([\w]+\:)?\/\//.test(s.img.src)&&-1===s.img.src.indexOf(location.host)&&(a.img.crossOrigin="anonymous"),x(a)}),r.on("click",".wrapper_select_image_amm",function(e){m.append("originalMeme",null);var a=t(this).find("img").attr("src");r.find(".wrapper_hover_title_meme_amm").text(t(this).find("img").attr("title")),r.find("*").removeClass("SI_amm_selected"),t(this).addClass("SI_amm_selected"),s.img=new Image,s.img.src=a,/^([\w]+\:)?\/\//.test(s.img.src)&&-1===s.img.src.indexOf(location.host)&&(s.img.crossOrigin="anonymous"),s.img.onload=function(){if(v.originalImage=s.img,r.trigger({type:"CanvasPreChange",value:a,on:"selectImage"}),y.canvas_reset(s.img),y.drawBrushesPoints(),y.canvas_addimage(null,null),y.canvas_filltext(null,null),r.trigger({type:"CanvasPostChange",value:a,on:"selectImage"}),r.find(".canvas_loading").remove(),s.canvas.css("display","block"),0==l.length)for(i=0;i<s.text_boxes_count;i++)r.find(".add_textbox").click();t(window).resize()}}),r.find("#amm-input-upload-image-meme-responsive").change(function(e){var a=new FileReader;a.onload=function(a){s.img=new Image,s.img.onload=function(){r.trigger({type:"CanvasPreChange",value:s.img,on:"uploadImage"}),y.canvas_reset(s.img),y.drawBrushesPoints(),y.canvas_addimage(null,null),y.canvas_filltext(null,null),r.trigger({type:"CanvasPostChange",value:s.img,on:"uploadImage"})},s.img.src=a.target.result,m.append("originalMeme",e.target.files[0]),t(window).resize()},a.readAsDataURL(e.target.files[0])}),r.on("change",".wrapper-memes-main .EventChange",function(e){var a=e.target.value;"checkbox"!=t(this).attr("type")||t(this).is(":checked")||(a=0);var n=t(this);t.each(t(this).attr("var").split(","),function(e,t){var i=_.get_text_id(n.closest(".wrapper-text").attr("delta"));l[i][t]=a,r.trigger({type:"CanvasPreChange",value:t,on:"buttonsEventChange"}),y.canvas_reset(s.img),y.drawBrushesPoints(),y.canvas_addimage(null,null),y.canvas_filltext(null,null),r.trigger({type:"CanvasPostChange",value:t,on:"buttonsEventChange"})})}),r.click(function(e){t(e.target).closest(".amm-popup, .amm-popup-trigger").length||r.find(".amm-popup").is(":visible")&&r.find(".amm-popup-trigger.opened").click()}),r.on("click",".wrapper_canvas_background",function(e){e.preventDefault(),_.focusout()}),r.on("click",".moreOption",function(e){var a=t(this).closest(".wrapper-text").attr("delta");if(t(this).hasClass("opened"))t(this).closest(".wrapper-text").find(".wrapperRenderPopupMoreOptions").remove(),t(this).removeClass("opened");else{r.find(".amm-popup-trigger.opened").click(),t(this).addClass("opened");var n=_.get_text_id(a);l[n].elementChanged=t(this),y.popupMoreOption(l[n]),l[n].elementChanged=null}e.preventDefault()}),r.on("CanvasPreChange",function(e){if("dragText"==e.on||"resizeText"==e.on){var t="text_"+s.id+"_"+e.value.delta;"resizeText"==e.on&&(l[t].ratioWidth=e.value.ui.size.width/r.find(a.ammCanvas).width(),l[t].ratioHeight=e.value.ui.size.height/r.find(a.ammCanvas).height()),l[t].ratioTop=e.value.ui.position.top/r.find(a.ammCanvas).height(),l[t].ratioLeft=e.value.ui.position.left/r.find(a.ammCanvas).width(),_.focusout()}if("dragImage"==e.on||"resizeImage"==e.on){t="imageBoxDR_"+s.id+"_"+e.value.delta;"resizeImage"==e.on&&(g[t].ratioWidth=e.value.ui.size.width/r.find(a.ammCanvas).width(),g[t].ratioHeight=e.value.ui.size.height/r.find(a.ammCanvas).height()),g[t].ratioTop=e.value.ui.position.top/r.find(a.ammCanvas).height(),g[t].ratioLeft=e.value.ui.position.left/r.find(a.ammCanvas).width(),_.focusout()}r.hasClass("amm_loaded")||(r.addClass("amm_loaded"),s.onLoad(s))}),r.on("CanvasPostChange",function(e){switch(e.on){case"fillText":case"addImage":case"brushes":case"resetTexts":case"resetImages":case"resetBrushes":!l.empty||c.length||g.length?r.find(".generate_meme").removeAttr("disabled"):r.find(".generate_meme").attr("disabled","disabled")}}),r.on("OnChangeColor",function(e){var t="text_"+s.id+"_"+e.delta;"text"==e.on?l[t].textColor=e.color:"outline"==e.on?l[t].strokeColor=e.color:"brushes"==e.on&&(u.strokeStyle=e.color,r.find("#amm-stop-brushing").css("background",e.color)),r.trigger({type:"CanvasPreChange",value:e,on:"changeColor"}),y.canvas_reset(s.img),y.drawBrushesPoints(),y.canvas_addimage(null,null),y.canvas_filltext(null,null),r.trigger({type:"CanvasPostChange",value:e,on:"changeColor"})});var w=!1;t(r).on("click","#amm-brushes, #amm-clear-brush, #amm-stop-brushing",function(e){switch(e.preventDefault(),this.id){case"amm-brushes":s.canvas.addClass("MouseCrossHair"),r.find(".boxDR, .imageBoxDR").addClass("ForceHide"),r.find(".wrapper-amm-stop-brushes").addClass("show"),r.find("#amm-merge-image-trigger, #amm-brushes, .wrapper-memes-preview-operations .responsive-button").hide(),w=!0,t("*").hasClass("pickpop-brushes");break;case"amm-stop-brushing":s.canvas.removeClass("MouseCrossHair"),r.find(".boxDR, .imageBoxDR").removeClass("ForceHide"),r.find(".wrapper-amm-stop-brushes").removeClass("show"),r.find("#amm-merge-image-trigger, #amm-brushes, .wrapper-memes-preview-operations .responsive-button").show(),_.is_responsive()&&r.find(".wrapper-memes-preview-operations .responsive-button").show(),w=!1;break;case"amm-clear-brush":c.reset(),y.canvas_reset(s.img),y.canvas_addimage(null,null),y.canvas_filltext(null,null),y.drawBrushesPoints()}});var b=!1,C=r.find(a.ammCanvas).get(0);document.addEventListener("mouseup",function(){b=!1,null!=c[c.length-1]&&(c[c.length]=void 0)},!1),C.addEventListener("mousedown",function(e){e.preventDefault(),b=!0},!1),C.addEventListener("mousemove",function(e){if(w&&b){var t,n,i=r.find(a.ammCanvas).get(0),o=i.getBoundingClientRect(),l=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop,d=document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft,m=o.left+d,p=o.top+l;document.all?(t=e.clientX+d-m,n=e.clientY+l-p):(t=e.pageX-m,n=e.pageY-p),console.log(t,n);var g=new h(t,n);g.strokeStyle=u.strokeStyle;var f=s.final_width/r.find(a.ammCanvas).width(),v=s.final_height/r.find(a.ammCanvas).height();g.x=g.x*f,g.y=g.y*v,c[c.length]=g,r.trigger({type:"CanvasPreChange",value:c,on:"brushes"}),y.canvas_reset(s.img),y.canvas_addimage(null,null),y.canvas_filltext(null,null),y.drawBrushesPoints(),r.trigger({type:"CanvasPostChange",value:c,on:"brushes"}),delete t}},!1),C.addEventListener("touchstart",function(e){var t,a;mousePos=(t=e,a=C.getBoundingClientRect(),{x:t.touches[0].clientX-a.left,y:t.touches[0].clientY-a.top});var n=e.touches[0],i=new MouseEvent("mousedown",{clientX:n.clientX,clientY:n.clientY});C.dispatchEvent(i)},!1),C.addEventListener("touchend",function(e){var t=new MouseEvent("mouseup",{});C.dispatchEvent(t)},!1),C.addEventListener("touchmove",function(e){if(0==e.changedTouches.length)C.dispatchEvent(new MouseEvent("mouseup",{}));else{var t=e.touches[0],a=new MouseEvent("mousemove",{clientX:t.clientX,clientY:t.clientY});C.dispatchEvent(a)}},!1),t(r).on("hover",".wrapper_select_image_amm img",function(e){var a=t(this).attr("title");"mouseenter"==e.type&&r.find(".wrapper_hover_title_meme_amm").text(a),"mouseleave"==e.type&&r.find(".wrapper_hover_title_meme_amm").text(t(".SI_amm_selected img").attr("title"))}),r.find(".generate_meme").click(function(e){s.downloadGeneratedImage||e.preventDefault();t(this);var n=[];t.each(l.keys,function(e,t){l[t].text&&n.push(l[t].text)});var i=s.canvas.get(0).toDataURL();if(s.downloadGeneratedImage){var o=s.canvas.get(0).toDataURL("image/png").replace("image/png","image/octet-stream");t(this).attr("download",r.find(a.wrapperHoverTitleMemeAmm).text()+".png"),t(this).attr("href",o)}var d=i;m.append("amm_canvas",d),m.append("all_texts",JSON.stringify(n)),m.append("textsIsEmpty",l.empty),m.append("drwaIsEmpty",!c.length),m.append("imagesIsEmpty",!g.length),s.onGenerate({amm_canvas:d,all_texts:n,drwaIsEmpty:c.length,imagesIsEmpty:g.length},m)}),r.on("change",".amm-color-picker",function(){var e=t(this).data("on"),a=t(this).attr("id"),n="brushes"!=e?t(this).closest(".wrapper-text").attr("delta"):null,i=t(this).val().replace("#","");"brushes"==e&&r.find("#colorSelectorBrushes div").css("backgroundColor","#"+i),r.trigger({type:"OnChangeColor",id:a,color:"#"+i,this:t(this),on:e,delta:n})});var y={currentScriptPath:function(){var e=document.querySelectorAll("script[src]"),t=e[e.length-1].src,a=t.split("/"),n=a[a.length-1];return t.replace(n,"")},window_width:function(){var e=parseInt(r.find(".main-container").css("padding-left").replace("px","")),a=parseInt(r.find(".main-container").css("padding-right").replace("px",""));return t(window).width()>600?500:t(window).width()-e-a},wrapText:function(e,t,a,n,i,r,s){var o=t.split(" "),l=e,d="";if(1==o.length){d=t;for(var m=e.measureText(d);m.width>i;)y.decrease_font_size(e,s),m=e.measureText(d);n+=s.fontSize,e.strokeText(d,a,n+3),e.fillText(d,a,n+3)}else{for(var p=0,c=0;c<o.length;c++){var u=d+o[c]+" ";if((m=l.measureText(u)).width>i){for(;(p+2)*s.fontSize+3*(p+2)>r;)y.decrease_font_size(l,s);for(d=o[c]+" ",m=l.measureText(d);m.width>i;)y.decrease_font_size(l,s),m=l.measureText(d);p++}else d+=o[c]+" "}d="";p=0;var h=null;for(c=0;c<o.length;c++){u=d+o[c]+" ";(m=e.measureText(u)).width>i?(h=n+s.fontSize*(p+1)+3*(p+1),e.strokeText(d,a,h),e.fillText(d,a,h),d=o[c]+" ",p++):d+=o[c]+" "}h=n+s.fontSize*(p+1)+3*(p+1),e.strokeText(d,a,h),e.fillText(d,a,h)}y.reset_font_size(e,s)},drawBrushesPoints:function(){var e=_.get_canvas_info(),a=null,n=_.get_brushesPoints();t.each(n,function(t,n){null!=n&&null!=n||(a=n),null!=a&&(e.ctx.beginPath(),e.ctx.moveTo(a.x,a.y),e.ctx.lineTo(n.x,n.y),e.ctx.strokeStyle=n.strokeStyle,e.ctx.stroke(),e.ctx.lineWidth=n.lineWidth,e.ctx.shadowBlur=0),a=n})},skipWidth:function(e,t,a,n,i){var r=t.fontSize;t.fontSize=i,e.font=y.buildFont(t);var s=e.measureText(a);return t.fontSize=r,e.font=y.buildFont(t),s.width>n-20},reset_font_size:function(e,t){t.fontSize=t.inputFontSize,e.font=y.buildFont(t)},decrease_font_size:function(e,t){t.fontSize-=1,e.font=y.buildFont(t)},increase_font_size:function(e,t){t.fontSize+=1,e.font=y.buildFont(t)},canvas_reset:function(e){var t=_.get_canvas_info();t.ratio_width=t._maxWidth/e.width,t.ratio_height=t._maxHeight/e.height,t.ratio_width<t.ratio_height?t.ratio_image=t.ratio_width:t.ratio_image=t.ratio_height,t.final_width=e.width*t.ratio_image,t.final_height=e.height*t.ratio_image,r.find(a.ammCanvas+","+a.wrapperCanvas).attr("width",t.final_width).attr("height",t.final_height),t.ctx.drawImage(e,0,0,e.width,e.height,0,0,t.final_width,t.final_height)},canvas_addimage:function(e,a){var n=_.get_images(),i=null;t.each(n.keys,function(t,r){i=n[r],a==i.id&&(i.left=e.position?e.position.left:i.left,i.top=e.position?e.position.top:i.top,i.width=e.size?e.size.width:i.width,i.height=e.size?e.size.height:i.height),s.ctx.drawImage(i.img,s.final_width*i.ratioLeft,s.final_height*i.ratioTop,s.final_width*i.ratioWidth,s.final_height*i.ratioHeight)})},canvas_filltext:function(e,a){var n=_.get_canvas_info(),i=_.get_texts(),s=null;t.each(i.keys,function(t,o){if(null!=i[o]){(s=i[o]).fontSize=parseInt(s.fontSize);var l=r.find("#"+s.id_box),d=r.find("#"+o).val();if(null==d||""==d)return;var m=l.position();n.final_height<m.top+l.outerHeight()&&(m.top=n.final_height-l.outerHeight(),i[o].top=m.top);var p=l.outerWidth(),c=l.outerHeight();a==s.id_box&&(m=e.position,p=e.size?e.size.width:p,c=e.size?e.size.height:c),n.ctx.font=y.buildFont(s),n.ctx.shadowBlur=s.shadowBlur,n.ctx.shadowColor=s.shadowColor,n.ctx.strokeStyle=s.strokeColor,n.ctx.lineWidth=s.lineWidth,n.ctx.fillStyle=s.textColor,n.ctx.textAlign=s.textAlign,s.toUpperCase&&(d=d.toUpperCase()),p=n.final_width*s.ratioWidth,c=n.final_height*s.ratioHeight;var u=n.final_width*s.ratioLeft,h=n.final_height*s.ratioTop;y.wrapText(n.ctx,d,u+p/2,h,p,c,s)}})},buildFont:function(e){switch(e.fontFamily){case"impact":return e.fontSize+"px impact"}return e.fontStyle+" "+e.fontVariant+" "+e.fontWeight+" "+e.fontSize+"px "+e.fontFamily},popupMoreOption:function(e){var a=T.renderPopupMoreOptions(e);e.getParent().append(a);var n=e.elementChanged.position(),i=e.elementChanged.css("margin-left");r.find(".wrapperRenderPopupMoreOptions").css({left:n.left+parseFloat(i)+e.elementChanged.outerWidth()-t(".wrapperRenderPopupMoreOptions").outerWidth()+"px","z-index":_.find_highest_ZIndex()}).show()},rgb2hex:function(e){var t,a=new String,n=new Number,i=e.match(/\d+/g);for(t=0;t<i.length;t+=1)(n=(n=1*i[t]).toString(16)).length<2&&(n="0"+n),a+=n;return a}},T={wrapper_text:function(e){return'<div class="wrapper-text" delta="'+e.delta+'">\n <textarea placeholder="'+e.placeholder+'" id="'+e.id+'" class="amm-text"></textarea>\n <div class="fontOps">\n <input type="color" data-on="text" class="amm-color-picker pickerTextColor" title="Change Font Color" name="pickerTextColor" value="'+e.textColor+'" list>\n <input type="color" data-on="outline" class="amm-color-picker pickerStrokeColor" title="Change Outline Color" name="pickerStrokeColor" value="'+e.strokeColor+'" list>\n <input id="ow0" class="ow EventChange" var="lineWidth" value="'+e.lineWidth+'" type="number" maxlength="1" min="0" max="9" title="Change Outline Width" tabindex="-1">\n <a href="#" class="btn btn-xs btn-default moreOption amm-popup-trigger"></a>\n </div>\n <div class="clear_both"></div> </div>'},renderPopupMoreOptions:function(e){var a='<div class="wrapperInputFontSize"><label>'+s.i18n.sizeText+': </label><input class="InputFontSize EventChange" var="fontSize,inputFontSize" type="number" maxlength="1" max="100" min="10" title="Change Size Text" tabindex="-1" value="'+e.inputFontSize+'"></div>',n=["Verdana","impact","Times New Roman","Arial","Courier New","serif","sans-serif"];s.alterFontFamilies(n);var i="",r="";t(n).each(function(t,a){e.fontFamily==a?i+='<option selected="selected">'+a+"</option>":i+="<option>"+a+"</option>"});var o='<div class="wrapperInputFontFamily"><label>'+s.i18n.fontFamilyText+': </label><select var="fontFamily" class="InputFontFamily EventChange" >'+i+"</select></div>";return r="",e.shadowBlur&&(r='checked="checked"'),'<div class="wrapperRenderPopupMoreOptions amm-popup">'+o+a+('<div class="wrapperInputFontFamily"><label>Shadow: </label><input class="InputShadow EventChange" var="shadowBlur" value="'+e.shadowBlur+'" type="checkbox" '+r+"></div>")+('<div class="wrapperInputUpperCase"><label>'+s.i18n.uperCaseText+': </label><input class="InputUpperCase EventChange" var="toUpperCase" value="'+e.shadowBlur+'" type="checkbox" '+(e.toUpperCase?'checked="checked"':"")+"></div>")+"</div>"},popupDownloadCanvas:function(e){return'<div class="wrapper-popup-download-canvas">\n <img class="done-image-canvas" src="'+Drupal.meme_generator.get_canvas_info().canvas.toDataURL()+'">\n <div class="PDC-wrapper-share-download">Loading</div>\n </div>'}};s.canvas=r.find(a.ammCanvas),s.ctx=s.canvas.get(0).getContext("2d"),r.find(".wrapper_select_image_amm:first").click()})}}(0,window.jQuery);