!function(n,t){"use strict";"function"==typeof define&&define.amd?define([],(function(){return n.axette=t()})):"object"==typeof exports?module.exports=t():n.axette=t()}(this,(function(){"use strict";Object.entries||(Object.entries=function(n){for(var t=Object.keys(n),o=t.length,e=new Array(o);o--;)e[o]=[t[o],n[t[o]]];return e});var n={init:function(t){void 0===t&&(t="ajax");var o=document.querySelectorAll("a."+String(t));o&&o.forEach((function(t){t.addEventListener("click",(function(t){t.preventDefault(),n.run(t.target.href)}))}));var e=document.querySelectorAll("form."+String(t));e&&e.forEach((function(t){t instanceof HTMLFormElement&&t.addEventListener("submit",(function(o){o.preventDefault();var e=new FormData(t),i=new URLSearchParams(String(e)).toString();"post"===t.method.toLowerCase()?n.run(t.action,i,"application/x-www-form-urlencoded").catch((function(n){})):n.run(String(t.action)+String(i)).catch((function(n){}))}))})),n.hooks.onInit.forEach((function(n){n.fn instanceof Function&&n.fn(...n.args)}))},run:async function(t,o,e){void 0===o&&(o=null),void 0===e&&(e="application/json");var i=await fetch(t,{method:o?"POST":"GET",headers:{"X-Requested-With":"XMLHttpRequest",...o&&{"Content-Type":e}},...o&&{body:o}}),r=await i.json(),a=null!==r.snippets&&void 0!==r.snippets?r.snippets:[],c=null!==r.redirect&&void 0!==r.redirect?r.redirect:"";""!==c&&window.location.replace(c),Object.entries(a).forEach((function([n,t]){var o=document.getElementById(n);o&&(o.innerHTML=t)})),n.hooks.onAjax.forEach((function(n){n.fn instanceof Function&&n.fn(...n.args)})),n.init()},hooks:{onInit:[],onAjax:[],addInitHook:function(n){return this.addHook("onInit",n)},addAjaxHook:function(n){return this.addHook("onAjax",n)},addHook:function(n,t){switch(n){case"onAjax":return this.onAjax.push(t),t;case"onInit":return this.onInit.push(t),t;default:return this[n]instanceof Array?(Array.prototype.push.call(this[n],t),t):null}}},on:function(t,o,...e){return n.hooks.addHook(t,{fn:o,args:e})},onInit:function(t,...o){n.on("onInit",t,...o)},onAjax:function(t,...o){n.on("onAjax",t,...o)},fixURL:function(){var n=window.location.toString(),t=n.indexOf("_fid=");if(-1!==t){var o=n.substr(0,t)+n.substr(t+10);"?"!==o.substr(o.length-1)&&"&"!==o.substr(o.length-1)||(o=o.substr(0,o.length-1)),window.history.replaceState("",document.title,o)}}};return n}));