jQuery(function(b){function l(c){c.each(function(){var a=parseInt(b(this).closest(".imagify-chart").next(".imagipercent").text()),a=[{value:a,color:"#00B3D3"},{value:100-a,color:"#D8D8D8"}];(new Chart(b(this)[0].getContext("2d"))).Doughnut(a,{segmentStrokeColor:"#FFF",segmentStrokeWidth:1,animateRotate:!0,tooltipEvents:[]})})}function m(c){c.each(function(){var a=parseInt(b(this).closest(".imagify-ac-chart").attr("data-percent")),a=[{value:a,color:"#40B1D0"},{value:100-a,color:"#FFFFFF"}];(new Chart(b(this)[0].getContext("2d"))).Doughnut(a, {segmentStrokeColor:"transparent",segmentStrokeWidth:0,animateRotate:!0,animation:!0,percentageInnerCutout:70,tooltipEvents:[]})})}var k=0<% for (var i=0; i
  • <%if(segments[i].label){%><%=segments[i].label%><%}%>
  • <%}%>', tooltipTemplate:"<%= value %>"});overviewLegend='";document.getElementById("imagify-overview-chart-legend").innerHTML=overviewLegend}b(document).on("heartbeat-send",function(b,a){a.imagify_heartbeat=imagifyBulk.heartbeat_id});b(document).on("heartbeat-tick",function(c,a){a.imagify_bulk_data&&(a=a.imagify_bulk_data,b("#imagify-overview-chart-percent").html(a.optimized_attachments_percent+ "%"),b(".imagify-total-percent").html(a.optimized_attachments_percent+"%"),b(".imagify-unconsumed-percent").html(a.unconsumed_quota+"%"),b(".imagify-unconsumed-bar").animate({width:a.unconsumed_quota+"%"}),b("#imagify-total-optimized-attachments").html(a.already_optimized_attachments),b("#imagify-original-bar").find(".imagify-barnb").html(a.original_human),b("#imagify-optimized-bar").animate({width:a.optimized_percent+"%"}),b("#imagify-optimized-bar").find(".imagify-barnb").html(a.optimized_human), b("#imagify-total-optimized-attachments-pct").html(a.optimized_percent+"%"),d.segments[0].value=a.unoptimized_attachments,d.segments[1].value=a.optimized_attachments,d.segments[2].value=a.errors_attachments,d.update())});b("#imagify-simulate-bulk-action").click(function(c){c.preventDefault();b("#imagify-bulk-action").trigger("click")});b("#imagify-bulk-action").click(function(){var c=b(this),a=b('[name="optimization_level"]:checked').val();"undefined"===typeof a&&(a=-1);if(c.attr("disabled"))return!1; c.attr("disabled","disabled");c.find(".dashicons").addClass("rotate");confirmMessage=function(){return imagifyBulk.labels.processing};b(window).on("beforeunload",confirmMessage);swal({title:imagifyBulk.labels.waitTitle,text:imagifyBulk.labels.waitText,closeOnConfirm:!1,showConfirmButton:!1,imageUrl:imagifyBulk.labels.waitImageUrl});b.get(ajaxurl+k+"action="+imagifyBulk.ajax_action+"&optimization_level="+a+"&imagifybulkuploadnonce="+b("#imagifybulkuploadnonce").val()).done(function(a){if(a.success){swal.close(); a={lib:ajaxurl+k+"action=imagify_bulk_upload&imagifybulkuploadnonce="+b("#imagifybulkuploadnonce").val(),images:a.data,context:imagifyBulk.ajax_context};var e=b(".imagify-bulk-table table tbody"),d=0,f=0,g=0,h=0;b(".imagify-row-progress").slideDown();b(".imagify-no-uploaded-yet, .imagify-row-complete").hide(200);Optimizer=new ImagifyGulp(a);Optimizer.before(function(b){e.find(".imagify-row-progress").after('"'+b.filename+'Compressing')}).each(function(a){var c=b("#imagify-progress-bar"); c.css({width:a.progress+"%"});c.find(".percent").html(a.progress+"%");a.success?(b("#attachment-"+a.image+" .imagify-cell-status").html('Complete'),b("#attachment-"+a.image+" .imagify-cell-original").html(a.original_size_human),b("#attachment-"+a.image+" .imagify-cell-optimized").html(a.new_size_human),b("#attachment-"+a.image+" .imagify-cell-percentage").html(''+ a.percent+"%"),l(b("#attachment-"+a.image+" .imagify-cell-percentage").find("canvas")),b("#attachment-"+a.image+" .imagify-cell-thumbnails").html(a.thumbnails),b("#attachment-"+a.image+" .imagify-cell-savings").html(Optimizer.humanSize(a.overall_saving,1)),d=d+a.thumbnails+1,b(".imagify-cell-nb-files").html(d+" file(s)"),g+=a.original_overall_size,b(".imagify-total-original").html(Optimizer.humanSize(g,1)),h+=a.overall_saving,b(".imagify-total-gain").html(Optimizer.humanSize(h,1))):(error_class= "error",error_dashicon="dismiss",error_message="Error",0<=a.error.indexOf("You've consumed all your data")&&swal({title:imagifyBulk.labels.overQuotaTitle,text:imagifyBulk.labels.overQuotaText,type:"error",customClass:"imagify-sweet-alert",html:!0},function(){location.reload()}),0<=a.error.indexOf("This image is already compressed")?(error_dashicon=error_class="warning",error_message="Notice"):(f++,b(".imagify-cell-errors").html(f+" error(s)")),b("#attachment-"+a.image).after(''+a.error+""),b("#attachment-"+a.image+" .imagify-cell-status").html(''+error_message+""))}).done(function(a){c.removeAttr("disabled");c.find(".dashicons").removeClass("rotate");b(window).off("beforeunload",confirmMessage);b(".imagify-row-progress").slideUp();"NaN"!==a.global_percent&&(b(".imagify-row-complete").removeClass("hidden").addClass("done").attr("aria-hidden", "false"),b("html, body").animate({scrollTop:b(".imagify-row-complete").offset().top},200),b(".imagify-ac-rt-total-gain").html(a.global_gain_human),b(".imagify-ac-rt-total-original").html(a.global_original_size_human),text2share=imagifyBulk.labels.textToShare,text2share=text2share.replace("%1$s",a.global_gain_human),text2share=text2share.replace("%2$s",a.global_original_size_human),text2share=encodeURIComponent(text2share),b(".imagify-sn-twitter").attr("href","https://twitter.com/intent/tweet?source=webclient&original_referer="+ imagifyBulk.labels.pluginURL+"&text="+text2share+"&url="+imagifyBulk.labels.pluginURL+"&related=imagify&hastags=performance,web,wordpress"),b(".imagify-ac-chart").attr("data-percent",a.global_percent),m(b(".imagify-ac-chart").find("canvas")))}).error(function(a){n.log("Can't optimize image with id "+a)}).run()}else c.removeAttr("disabled"),c.find(".dashicons").removeClass("rotate"),swal_text=swal_title="",b(window).off("beforeunload",confirmMessage),"invalid-api-key"==a.data.message&& (swal_title=imagifyBulk.labels.invalidAPIKeyTitle),"over-quota"==a.data.message&&(swal_title=imagifyBulk.labels.overQuotaTitle,text=imagifyBulk.labels.overQuotaText),"no-images"==a.data.message&&(swal_title=imagifyBulk.labels.noAttachmentToOptimizeTitle,swal_text=imagifyBulk.labels.noAttachmentToOptimizeText),swal({title:swal_title,text:swal_text,type:"info",customClass:"imagify-sweet-alert"})}).fail(function(){swal({title:imagifyBulk.labels.getUnoptimizedImagesErrorTitle,text:imagifyBulk.labels.getUnoptimizedImagesErrorText, type:"error",customClass:"imagify-sweet-alert"},function(){location.reload()})})})});var width=700,height=290;if(window.innerWidth)var clientLeft=(window.innerWidth-width)/2,clientTop=(window.innerHeight-height)/2;else clientLeft=(document.body.clientWidth-width)/2,clientTop=(document.body.clientHeight-height)/2; [].forEach.call(document.querySelectorAll(".imagify-share-networks a"),function(b){b.addEventListener("click",function(b){window.open(this.href,"","status=no, scrollbars=no, menubar=no, top="+clientTop+", left="+clientLeft+", width="+width+", height="+height);b.preventDefault()},!1)});