{"version":3,"file":"apbct-public--functions.min.js","sources":["apbct-public--functions.js"],"sourcesContent":["function ctSetCookie( cookies, value, expires ){\n\n    if( typeof cookies === 'string' && typeof value === 'string' || typeof value === 'number'){\n        var skip_alt = cookies === 'ct_pointer_data' || cookies === 'ct_user_info';\n        cookies = [ [ cookies, value, expires ] ];\n    }\n\n    // Cookies disabled\n    if( +ctPublicFunctions.data__set_cookies === 0 ){\n        return;\n\n        // Using traditional cookies\n    }else if( +ctPublicFunctions.data__set_cookies === 1 ){\n        cookies.forEach( function (item, i, arr\t) {\n            var expires = typeof item[2] !== 'undefined' ? \"expires=\" + expires + '; ' : '';\n            var ctSecure = location.protocol === 'https:' ? '; secure' : '';\n            document.cookie = item[0] + \"=\" + encodeURIComponent(item[1]) + \"; \" + expires + \"path=/; samesite=lax\" + ctSecure;\n        });\n\n        // Using alternative cookies\n    }else if( +ctPublicFunctions.data__set_cookies === 2 && ! skip_alt ){\n\n        // Using REST API handler\n        if( +ctPublicFunctions.data__set_cookies__alt_sessions_type === 0 ){\n            apbct_public_sendREST(\n                'alt_sessions',\n                {\n                    method: 'POST',\n                    data: { cookies: cookies }\n                }\n            );\n\n            // Using AJAX request and handler\n        }else if( +ctPublicFunctions.data__set_cookies__alt_sessions_type === 1 ) {\n            apbct_public_sendAJAX(\n                {\n                    action: 'apbct_alt_session__save__AJAX',\n                    cookies: cookies,\n                },\n                {\n                    apbct_ajax: 1,\n                    notJson: 1,\n                }\n            );\n        }\n    }\n}\n\nfunction apbct_public_sendAJAX(data, params, obj){\n\n    // Default params\n    var callback    = params.callback    || null;\n    var callback_context = params.callback_context || null;\n    var callback_params = params.callback_params || null;\n    var async = params.async || true;\n    var notJson     = params.notJson     || null;\n    var timeout     = params.timeout     || 15000;\n    var obj         = obj                || null;\n    var button      = params.button      || null;\n    var spinner     = params.spinner     || null;\n    var progressbar = params.progressbar || null;\n    var silent      = params.silent      || null;\n    var no_nonce    = params.no_nonce    || null;\n    var apbct_ajax  = params.apbct_ajax  || null;\n\n    if(typeof (data) === 'string') {\n        if( ! no_nonce )\n            data = data + '&_ajax_nonce=' + ctPublicFunctions._ajax_nonce;\n        data = data + '&no_cache=' + Math.random()\n    } else {\n        if( ! no_nonce )\n            data._ajax_nonce = ctPublicFunctions._ajax_nonce;\n        data.no_cache = Math.random();\n    }\n    // Button and spinner\n    if(button)  {button.setAttribute('disabled', 'disabled'); button.style.cursor = 'not-allowed'; }\n    if(spinner) jQuery(spinner).css('display', 'inline');\n\n    jQuery.ajax({\n        type: \"POST\",\n        url: apbct_ajax ? ctPublicFunctions._apbct_ajax_url : ctPublicFunctions._ajax_url,\n        data: data,\n        async: async,\n        success: function(result){\n            if(button){  button.removeAttribute('disabled'); button.style.cursor = 'pointer'; }\n            if(spinner)  jQuery(spinner).css('display', 'none');\n            if(!notJson) result = JSON.parse(result);\n            if(result.error){\n                setTimeout(function(){ if(progressbar) progressbar.fadeOut('slow'); }, 1000);\n                console.log('Error happens: ' + (result.error || 'Unkown'));\n            }else{\n                if(callback) {\n                    if (callback_params)\n                        callback.apply( callback_context, callback_params.concat( result, data, params, obj ) );\n                    else\n                        callback(result, data, params, obj);\n                }\n            }\n        },\n        error: function(jqXHR, textStatus, errorThrown){\n            if(button){  button.removeAttribute('disabled'); button.style.cursor = 'pointer'; }\n            if(spinner) jQuery(spinner).css('display', 'none');\n            if( errorThrown && ! silent ) {\n                console.log('APBCT_AJAX_ERROR');\n                console.log(jqXHR);\n                console.log(textStatus);\n                console.log('Anti-spam by Cleantalk plugin error: ' + errorThrown + 'Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/');\n            }\n        },\n        timeout: timeout,\n    });\n}\n\nfunction apbct_public_sendREST( route, params ) {\n\n    var callback = params.callback || null;\n    var data     = params.data || [];\n    var method   = params.method || 'POST';\n\n    jQuery.ajax({\n        type: method,\n        url: ctPublicFunctions._rest_url + 'cleantalk-antispam/v1/' + route,\n        data: data,\n        beforeSend : function ( xhr ) {\n            xhr.setRequestHeader( 'X-WP-Nonce', ctPublicFunctions._rest_nonce );\n        },\n        success: function(result){\n            if(result.error){\n                console.log('Error happens: ' + (result.error || 'Unknown'));\n            }else{\n                if(callback) {\n                    var obj = null;\n                    callback(result, route, params, obj);\n                }\n            }\n        },\n        error: function(jqXHR, textStatus, errorThrown){\n            if( errorThrown ) {\n                console.log('APBCT_REST_ERROR');\n                console.log(jqXHR);\n                console.log(textStatus);\n                console.log('Anti-spam by Cleantalk plugin REST API error: ' + errorThrown + ' Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/');\n            }\n        },\n    });\n\n}\n"],"names":["ctSetCookie","cookies","value","expires","skip_alt","ctPublicFunctions","data__set_cookies","forEach","item","i","arr","ctSecure","location","protocol","document","cookie","encodeURIComponent","data__set_cookies__alt_sessions_type","apbct_public_sendREST","method","data","apbct_public_sendAJAX","action","apbct_ajax","notJson","params","obj","callback","callback_context","callback_params","async","timeout","button","spinner","progressbar","silent","no_nonce","_ajax_nonce","Math","random","no_cache","setAttribute","style","cursor","jQuery","css","ajax","type","url","_apbct_ajax_url","_ajax_url","success","result","removeAttribute","JSON","parse","error","setTimeout","fadeOut","console","log","apply","concat","jqXHR","textStatus","errorThrown","route","_rest_url","beforeSend","xhr","setRequestHeader","_rest_nonce"],"mappings":"AAAA,SAASA,YAAaC,EAASC,EAAOC,GAElC,IACQC,GADe,iBAAZH,GAAyC,iBAAVC,GAAuC,iBAAVA,KAC/DE,EAAuB,oBAAZH,GAA6C,iBAAZA,EAChDA,EAAU,CAAE,CAAEA,EAASC,EAAOC,KAIW,IAAxCE,kBAAkBC,oBAI4B,IAAxCD,kBAAkBC,kBACzBL,EAAQM,QAAS,SAAUC,EAAMC,EAAGC,GAChC,IAAIP,OAA6B,IAAZK,EAAK,GAAqB,WAAaL,EAAU,KAAO,GACzEQ,EAAiC,WAAtBC,SAASC,SAAwB,WAAa,GAC7DC,SAASC,OAASP,EAAK,GAAK,IAAMQ,mBAAmBR,EAAK,IAA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