!function(e,a){"use strict";a.utilites.namespace("CherryAjaxHandler"),a.CherryAjaxHandler=function(t){var n=this,r={handlerId:"",cache:!1,processData:!0,url:"",async:!1,beforeSendCallback:function(){},errorCallback:function(){},successCallback:function(){},completeCallback:function(){}};return t&&e.extend(r,t),window[r.handlerId]?(n.handlerSettings=window[r.handlerId]||{},n.ajaxRequest=null,n.ajaxProcessing=!1,n.data={action:n.handlerSettings.action,nonce:n.handlerSettings.nonce},""===r.url&&(r.url="false"===n.handlerSettings.is_public?window.ajaxurl:window.cherryHandlerAjaxUrl.ajax_url),n.send=function(){n.ajaxProcessing&&a.cherryHandlerUtils.noticeCreate("error-notice",n.handlerSettings.sys_messages.wait_processing,n.handlerSettings.is_public),n.ajaxProcessing=!0,n.ajaxRequest=jQuery.ajax({type:n.handlerSettings.type,url:r.url,data:n.data,cache:r.cache,dataType:n.handlerSettings.data_type,processData:r.processData,beforeSend:function(e,a){null===n.ajaxRequest||r.async||n.ajaxRequest.abort(),r.beforeSendCallback&&"function"==typeof r.beforeSendCallback&&r.beforeSendCallback(e,a)},error:function(a,t,n){e(document).trigger({type:"cherry-ajax-handler-error",jqXHR:a,textStatus:t,errorThrown:n}),r.errorCallback&&"function"==typeof r.errorCallback&&r.errorCallback(a,t,n)},success:function(t,c,s){n.ajaxProcessing=!1,e(document).trigger({type:"cherry-ajax-handler-success",response:t,jqXHR:s,textStatus:c}),r.successCallback&&"function"==typeof r.successCallback&&r.successCallback(t,c,s),a.cherryHandlerUtils.noticeCreate(t.type,t.message,n.handlerSettings.is_public)},complete:function(a,t){e(document).trigger({type:"cherry-ajax-handler-complete",jqXHR:a,textStatus:t}),r.completeCallback&&"function"==typeof r.completeCallback&&r.completeCallback(a,t)}})},n.sendData=function(e){var a=e||{};n.data={action:n.handlerSettings.action,nonce:n.handlerSettings.nonce,data:a},n.send()},void(n.sendFormData=function(t){var r,c=e(t);r=a.cherryHandlerUtils.serializeObject(c),n.sendData(r)})):(window.console&&window.console.warn("Handler id not found"),!1)},a.utilites.namespace("cherryHandlerUtils"),a.cherryHandlerUtils={noticeCreate:function(a,t,n){function r(){var a=100;e(".cherry-handler-notice").each(function(){e(this).css({top:a}),a+=e(this).outerHeight(!0)})}var c,s,i=0,o=n||!1;return t&&"true"!==o?(c=e('
'+t+"
"),e("body").prepend(c),r(),i=-1*(c.outerWidth(!0)+10),c.css({right:i}),s=setTimeout(function(){c.css({right:10}).addClass("show-state")},100),s=setTimeout(function(){i=-1*(c.outerWidth(!0)+10),c.css({right:i}).removeClass("show-state")},4e3),void(s=setTimeout(function(){c.remove(),clearTimeout(s)},4500))):!1},serializeObject:function(a){var t=this,n={},r={},c={validate:/^[a-zA-Z][a-zA-Z0-9_-]*(?:\[(?:\d*|[a-zA-Z0-9_-]+)\])*$/,key:/[a-zA-Z0-9_-]+|(?=\[\])/g,push:/^$/,fixed:/^\d+$/,named:/^[a-zA-Z0-9_-]+$/};return this.build=function(e,a,t){return e[a]=t,e},this.push_counter=function(e){return void 0===r[e]&&(r[e]=0),r[e]++},e.each(a.serializeArray(),function(){var a,r,s,i;if(c.validate.test(this.name)){for(r=this.name.match(c.key),s=this.value,i=this.name;void 0!==(a=r.pop());)i=i.replace(new RegExp("\\["+a+"\\]$"),""),a.match(c.push)?s=t.build([],t.push_counter(i),s):a.match(c.fixed)?s=t.build([],a,s):a.match(c.named)&&(s=t.build({},a,s));n=e.extend(!0,n,s)}}),n}}}(jQuery,window.CherryJsCore);