-
Notifications
You must be signed in to change notification settings - Fork 0
/
postalypse.min.js
1 lines (1 loc) · 4.99 KB
/
postalypse.min.js
1
!function () { if (Event.prototype.preventDefault || (Event.prototype.preventDefault = function () { this.returnValue = !1 }), Event.prototype.stopPropagation || (Event.prototype.stopPropagation = function () { this.cancelBubble = !0 }), !Element.prototype.addEventListener) { var e = [], t = function (t, n) { var o = this, r = function (e) { e.target = e.srcElement, e.currentTarget = o, n.handleEvent ? n.handleEvent(e) : n.call(o, e) }; if ("DOMContentLoaded" == t) { var s = function (e) { "complete" == document.readyState && r(e) }; if (document.attachEvent("onreadystatechange", s), e.push({ object: this, type: t, listener: n, wrapper: s }), "complete" == document.readyState) { var a = new Event; a.srcElement = window, s(a) } } else this.attachEvent("on" + t, r), e.push({ object: this, type: t, listener: n, wrapper: r }) }, n = function (t, n) { for (var o = 0; o < e.length;) { var r = e[o]; if (r.object == this && r.type == t && r.listener == n) { "DOMContentLoaded" == t ? this.detachEvent("onreadystatechange", r.wrapper) : this.detachEvent("on" + t, r.wrapper), e.splice(o, 1); break } ++o } }; Element.prototype.addEventListener = t, Element.prototype.removeEventListener = n, HTMLDocument && (HTMLDocument.prototype.addEventListener = t, HTMLDocument.prototype.removeEventListener = n), Window && (Window.prototype.addEventListener = t, Window.prototype.removeEventListener = n) } }(), +function (e) { function t(e, t) { if (e && "FORM" === e.nodeName) { var n, o, r = []; for (n = e.elements.length - 1; n >= 0; n -= 1) if ("" !== e.elements[n].name) switch (e.elements[n].nodeName) { case "INPUT": switch (e.elements[n].type) { case "text": case "hidden": case "password": case "button": case "reset": case "submit": r.push(e.elements[n].name + "=" + encodeURIComponent(e.elements[n].value)); break; case "checkbox": case "radio": e.elements[n].checked && r.push(e.elements[n].name + "=" + encodeURIComponent(e.elements[n].value)); break; case "file": } break; case "TEXTAREA": r.push(e.elements[n].name + "=" + encodeURIComponent(e.elements[n].value)); break; case "SELECT": switch (e.elements[n].type) { case "select-one": r.push(e.elements[n].name + "=" + encodeURIComponent(e.elements[n].value)); break; case "select-multiple": for (o = e.elements[n].options.length - 1; o >= 0; o -= 1) e.elements[n].options[o].selected && r.push(e.elements[n].name + "=" + encodeURIComponent(e.elements[n].options[o].value)) } break; case "BUTTON": switch (e.elements[n].type) { case "reset": case "submit": case "button": r.push(e.elements[n].name + "=" + encodeURIComponent(e.elements[n].value)) } } var s = r.join("&"); return t ? s.replace("%20", "+") : s } } function n(e, t, o) { this.options = r({}, n.DEFAULT, o), this.form = this.getForm(e), this.urls = "string" == typeof t ? [t] : t, this.init(this.form, this.urls) } function o(e) { e = e || {}; var t = e.url || "", n = e.action ? e.action.toUpperCase() : "POST", o = e.hasOwnProperty("async") ? e.async : !0, r = e.contentType ? e.contentType : "application/x-www-form-urlencoded", s = e.headers ? e.header : {}, a = e.body ? e.body : "", i = e.success || function () { }, c = e.error || function () { }, p = e.complete || function () { }; s["Content-Type"] || (s["Content-Type"] = r); var l; if (window.XMLHttpRequest) l = new XMLHttpRequest; else if (window.ActiveXObject) try { l = new ActiveXObject("Msxml2.XMLHTTP") } catch (u) { try { l = new ActiveXObject("Microsoft.XMLHTTP") } catch (u) { } } if (!l) throw "Cannot create XMLHTTP instance"; l.open(n, t, o); for (var m in s) l.setRequestHeader(m, s[m]); return l.onreadystatechange = function () { 4 === l.readyState && ("2" === l.status.toString()[0] ? i(l) : c(l), p()) }, l.timeout = 6e4, l.send("POST" === n ? a : null), l } function r(e) { for (var t = Object.prototype.hasOwnProperty, n = 1; n < arguments.length; n++) { var o = arguments[n]; for (var r in o) t.call(o, r) && (e[r] = o[r]) } return e } function s() { var e = c(); return a(e, "form") } function a(e, t) { for (var n = e.previousSibling, o = e.nextSibling, r = !1; n || o;) { if (n && (r = i(n, t))) return r; if (o && (r = i(o, t))) return r; n = n ? n.previousSibling : !1, o = o ? o.nextSibling : !1 } return e.parentNode ? a(e.parentNode, t) : !1 } function i(e, t) { return t = t.toLowerCase(), e.tagName && e.tagName.toLowerCase() === t ? e : e.getElementsByTagName ? e.getElementsByTagName(t).item(0) : null } function c() { var e = document.getElementsByTagName("script"); return e = e[e.length - 1] } n.DEFAULT = {}, n.prototype = { constructor: n, getForm: function (e) { if ("closest" === e) return s(); if ("string" == typeof e) return document.querySelector(e); if (e instanceof HTMLFormElement) return e; throw "Postalypse: Expected form element to be a string or HTMLFormElement" }, init: function (e) { var n = this; e.addEventListener("submit", function () { for (var r = t(e, !0), s = 0; s < n.urls.length; s++) o({ url: n.urls[s], action: "POST", body: r }) }) } }, e.Postalypse = e.Postalypse || {}, e.Postalypse.gopostal = function (e, t, o) { return new n(e, t, o) } }(window);