/*! Aladdin.js v1.0.21 (c) 2016-2019 Aladdin */
!function (t, e) {
    "object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : t.aladdin = e()
}(this, function () {
    "use strict";

    function t(t, e, n) {
        if (void 0 === n && (n = "string"), void 0 === e || typeof e !== n) throw new TypeError("The " + t + " must be a " + n + " and a value")
    }

    function e(t) {
        var e = function (e) {
            e && this.emit("error", e), t.apply(null, arguments)
        }.bind(this);
        return e.keep = t.keep, e
    }

    function n() {
        this._ts = (new Date).getTime(), this._callTimes = 0, this._handlers = {}, this._subscribers = {}
    }

    function i(t, e) {
        if (void 0 === e && (e = !1), !t || "object" != typeof t) return "";
        var n = [];
        for (var i in t) {
            var o = t[i];
            if (Array.isArray(o)) for (var r in o) n.push((e ? i : i + "[]") + "=" + encodeURIComponent(o[r])); else n.push(i + "=" + encodeURIComponent(o))
        }
        return n.join("&")
    }

    function o(t, e, n) {
        void 0 === n && (n = !1);
        var o = i(e, n);
        return "" !== o && (o = (/\?/.test(t) ? "&" : "?") + o), t + o
    }

    function r(t) {
        this._aladdin = t
    }

    function a(t) {
        var e = this;
        for (var n in t) e[n] = t[n]
    }

    function s(t) {
        return function (e, n) {
            t(e, new a(n))
        }
    }

    function c(t) {
        return t = t || {}, t.method = t.method ? t.method.toLowerCase() : "get", t.headers || (t.headers = {}), "post" !== t.method && "put" !== t.method && "patch" !== t.method && "delete" !== t.method || t.headers["Content-Type"] || (t.headers["Content-Type"] = "application/x-www-form-urlencoded"), t.qs && "[object Object]" === I.call(t.qs) && (t.url = o(t.url, t.qs, t.traditional)), t.body && "[object Object]" === I.call(t.body) && (/x-www-form-urlencoded/.test(t.headers["Content-Type"]) ? t.body = i(t.body, t.traditional) : t.body = JSON.stringify(t.body)), t
    }

    function l(t) {
        this._aladdin = t
    }

    function d(t) {
        this._aladdin = t
    }

    function u(t) {
        d.call(this, t)
    }

    function p(t) {
        d.call(this, t)
    }

    function h(t) {
        this._aladdin = t
    }

    function f(t) {
        this._aladdin = t
    }

    function y(t) {
        this._aladdin = t, this.clickStart = "_click_start", this.forwardStart = "_forward_start", this.isHybird = /AladdinHybrid/.test(navigator.userAgent).toString()
    }

    function m(t) {
        this._aladdin = t
    }

    var v, _, b, g, w = function (t) {
        setTimeout(t)
    }, S = navigator.userAgent;
    g = -1 !== S.indexOf("CFB/") ? /AladdinHybrid\/(\d+\.\d+\.?\d*.*?) \((.*?)\/(\d+\.\d+\.?\d*.*?)\)/i.exec(S) : /AladdinHybrid\/(\d+\.\d+\.?\d*.*?) \((.*?) (\d+\.\d+\.?\d*.*?)\)/i.exec(S), Array.isArray(g) && (v = g[1], _ = g[2], b = g[3]);
    var D, A = {
        hybridVersion: v,
        appName: _,
        appVersion: b,
        isMobile: /Mobile/i.test(S),
        isAndroid: /Android/i.test(S),
        isiOS: !!S.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i),
        isiPhone: /iPhone/i.test(S),
        isiPad: /iPad/i.test(S),
        isiPod: /iPod/i.test(S),
        isHybrid: !!v,
        isBrowser: !v,
        isWechat: /MicroMessenger/i.test(S),
        isQQ: / QQ\//i.test(S)
    }, k = function (t, e, n) {
        Object.defineProperty(t, e, {value: n, writable: !1})
    }, I = Object.prototype.toString, C = {};
    k(n.prototype, "version", "1.0.21"), n.prototype.on = function (e, n) {
        return t("event name", e), t("event listener", n, "function"), (this._subscribers[e] || (this._subscribers[e] = [])).push(n), this
    }, n.prototype.once = function (t, e) {
        var n = this, i = function () {
            n.off(t, i), e.apply(this, arguments)
        };
        return i.listener = e, this.on(t, i), this
    }, n.prototype.off = function (e, n) {
        var i = this;
        if (!arguments.length) {
            for (e in i._subscribers) delete i._subscribers[e];
            return this
        }
        if (t("event name", e), !n && this._subscribers[e]) return delete this._subscribers[e], this;
        var o = this._subscribers[e];
        if (!o) return this;
        for (var r, a = o.length; a--;) if ((r = o[a]) === n || r.listener === n) {
            i._subscribers[e].splice(a, 1);
            break
        }
        return this
    }, n.prototype.emit = function (e) {
        for (var n = [], i = arguments.length - 1; i-- > 0;) n[i] = arguments[i + 1];
        return t("event name", e), this._emit("event", [{eventName: e, args: n}]), this._emit(e, n), this
    }, n.prototype._emit = function (t, e) {
        var n = this._subscribers[t];
        if (n) for (var i = 0; i < n.length; i++) "function" == typeof n[i] && n[i].apply(null, e);
        return this
    }, n.prototype.broadcast = function (e, n, i, o) {
        return t("event name", e), "function" == typeof n ? (o = n, n = {}) : "function" == typeof i && (o = i, i = ""), this.call("aladdin", "broadcast", {
            eventName: e,
            event: n,
            url: i
        }, o), this
    }, n.prototype.use = function (e, n) {
        t("Component", e, "function");
        var i = new e(this);
        return n = n || i.name || e.name.replace(/^([A-Z])/, function (t) {
            return t.toLowerCase()
        }), t("Component's name", n), this[n] = i, this
    }, n.prototype.support = function (e, n, i) {
        return t("component name", e), "function" == typeof n && (i = n, n = ""), this.call("aladdin", "support", {
            component: e,
            action: n
        }, i), this
    }, n.prototype._transformHandlers = function (t, n, i, o) {
        var r = this;
        for (var a in i) {
            var s = i[a];
            if (s) {
                var c = I.call(s);
                if ("[object Object]" !== c && "[object Array]" !== c || r._transformHandlers(t, n, s, o, D), "[object Function]" === c) {
                    var l = o + "_function_" + ++D + "_" + t + "_" + n + "_" + (isNaN(a) ? a : "callback");
                    i[a] = l, r._handlers[l] = e.call(r, s)
                }
            }
        }
    }, n.prototype.call = function () {
        var t = arguments, e = this;
        w(function () {
            e.callSync.apply(e, t)
        })
    }, n.prototype.callSync = function (t, e) {
        for (var n = [], i = arguments.length - 2; i-- > 0;) n[i] = arguments[i + 2];
        var o = {component: t, action: e, args: n, callId: (this._ts + ++this._callTimes).toString(16)};
        this.emit("call", o), D = 0, this._transformHandlers(o.component, o.action, o.args, o.callId), o.message = o.component + "." + o.action + "?" + encodeURIComponent(JSON.stringify(o.args));
        var r;
        if (A.isAndroid) r = prompt("aladdin://" + o.message, "aladdin://" + o.message); else if (A.isiOS) {
            C[o.callId] = o.message;
            var a = document.createElement("IFRAME");
            a.setAttribute("src", "aladdin://delay-fetch?callId=" + o.callId), a.setAttribute("style", "display: none;"), document.documentElement.appendChild(a), a.parentNode.removeChild(a), a = null, r = window.__ALADDIN__.retValue, window.__ALADDIN__.retValue = void 0
        }
        return r
    }, n.prototype.callback = function (t) {
        for (var e = [], n = arguments.length - 1; n-- > 0;) e[n] = arguments[n + 1];
        if (t) {
            var i = this._handlers[t];
            this.emit("callback", {
                handlerKey: t,
                handler: i,
                args: e
            }), i && "function" == typeof i && (i.apply(null, e), i.keep || delete this._handlers[t])
        }
    }, n.prototype.fetch = function (t) {
        var e = C[t];
        return void 0 !== e && delete C[t], e
    };
    k(r.prototype, "name", "navigator"), r.prototype._to = function (t, e, n) {
        return e = e || {}, e.qs && "object" == typeof e.qs && (e.url = o(e.url, e.qs, e.traditional)), this._aladdin.burypoint && this._aladdin.burypoint.trigger(e.url), this._aladdin.call(this.name, t, e, n), this
    }, r.prototype.forward = function (t, e) {
        return this._to("forward", t, e)
    }, r.prototype.replace = function (t, e) {
        return this._to("replace", t, e)
    }, r.prototype.back = function (t, e) {
        return t = t || {}, "function" == typeof t && (e = t, t = {}), this._aladdin.call(this.name, "back", t, e), this
    }, r.prototype.backTop = function (t) {
        return this._aladdin.call(this.name, "backTop", t), this
    }, r.prototype.close = function (t) {
        return this._aladdin.call(this.name, "close", t), this
    }, a.prototype.json = function () {
        return this.body ? JSON.parse(this.body) : {}
    }, a.prototype.text = function () {
        return this.body
    }, a.prototype.header = function (t) {
        var e = this;
        if (!this.headers) return "";
        t = t.toLowerCase();
        for (var n in e.headers) if (n.toLowerCase() === t) return e.headers[n];
        return ""
    }, k(l.prototype, "name", "http"), l.prototype.request = function (t, e) {
        return t = c(t), e = s(e), this._aladdin.call(this.name, "request", t, e), this
    }, l.prototype.setCookie = function (t, e) {
        return this._aladdin.call(this.name, "setCookie", t, e), this
    }, l.prototype.getCookie = function (t, e, n) {
        return this._aladdin.call(this.name, "getCookie", t, e, n), this
    }, l.prototype.removeCookie = function (t, e, n) {
        return this._aladdin.call(this.name, "removeCookie", t, e, n), this
    }, l.prototype.upload = function (t, e) {
        return t = t || {}, t.method = t.method || "post", t = c(t), this._aladdin.call(this.name, "upload", t, e), this
    }, l.prototype.download = function (t, e) {
        return t = c(t), this._aladdin.call(this.name, "download", t, e), this
    };
    var N = function (t) {
        return "string" != typeof t && ("[object Null]" === I.call(t) || void 0 === t ? t += "" : t = t.toString()), t
    }, E = function (t, e) {
        function n() {
            this.constructor = t
        }

        for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
        t.prototype = null === e ? Object.create(e) : (n.prototype = e.prototype, new n)
    };
    d.prototype.getItem = function (t, e, n, i) {
        "function" == typeof e ? (i = e, e = !1, n = "3DES") : "function" == typeof n ? (e = !!e, i = n, n = "3DES") : (e = !!e, n = n || "3DES"), t = N(t);
        var o = {key: t, share: e, crypto: n};
        return this._aladdin.call(this.name, "getItem", o, function (t, e) {
            try {
                e = "undefined" !== e ? JSON.parse(e) : void 0
            } catch (t) {
            }
            i(t, e)
        }), this
    }, d.prototype.setItem = function (t, e, n, i, o) {
        t = N(t), e = void 0 !== e ? JSON.stringify(e) : "undefined", "function" == typeof n ? (o = n, n = !1, i = "3DES") : "function" == typeof i ? (n = !!n, o = i, i = "3DES") : (n = !!n, i = i || "3DES");
        var r = {key: t, value: e, share: n, crypto: i};
        return this._aladdin.call(this.name, "setItem", r, o), this
    }, d.prototype.removeItem = function (t, e, n) {
        t = N(t), "function" == typeof e && (n = e, e = !1);
        var i = {key: t, share: e};
        return this._aladdin.call(this.name, "removeItem", i, n), this
    }, d.prototype.clear = function (t) {
        return this._aladdin.call(this.name, "clear", t), this
    }, E(u, d), k(u.prototype, "name", "localStorage"), E(p, d), k(p.prototype, "name", "sessionStorage"), k(h.prototype, "name", "header"), h.prototype.config = function (t, e) {
        return this._aladdin.call(this.name, "config", t || {}, e), this
    }, h.prototype.toggle = function (t, e) {
        return t = t || {}, "function" == typeof t && (e = t, t = {}), this._aladdin.call(this.name, "toggle", t, e), this
    }, k(f.prototype, "name", "page"), f.prototype.bounce = function (t, e) {
        return this.config({bounce: !!t}, e)
    }, f.prototype.swipe = function (t, e) {
        return this.config({swipe: !!t}, e)
    }, f.prototype.config = function (t, e) {
        return this._aladdin.call(this.name, "config", t || {}, e), this
    }, k(y.prototype, "name", "burypoint"), y.prototype.trigger = function (t) {
        var e = {}, n = window.location.href || "", i = +new Date;
        e.currentUrl = n, e.isHybird = this.isHybird, e.t2 = i, e.targetUrl = t && t.trim() || "", this.setlocalData(this.forwardStart, e)
    }, y.prototype.getlocalData = function (t) {
        return JSON.parse(window.localStorage.getItem(t))
    }, y.prototype.setlocalData = function (t, e) {
        window.localStorage.setItem(t, JSON.stringify(e))
    }, y.prototype.removelocalData = function (t) {
        window.localStorage.removeItem(t)
    }, y.prototype.deletelocalData = function () {
        this.removelocalData(this.clickStart), this.removelocalData(this.forwardStart)
    }, y.prototype.extend = function (t, e) {
        return e.forEach(function (e) {
            for (var n in e) t[n] = e[n]
        }), t
    }, y.prototype.publish = function (t, e, n) {
        var i = this._aladdin.env.appVersion;
        if (t && e && n) {
            var o = {type: "F", data: this.extend({}, [t, e, n])};
            this._aladdin.universal && i >= "4.13.0" && this._aladdin.universal.traceUniversalPoint(o)
        }
        return this.deletelocalData(), this
    }, y.prototype.init = function () {
        var t = "";
        if (document.addEventListener("touchend", function (t) {
            var t = t || window.event, e = +new Date, n = t.target,
                i = n.innerText || n.getAttribute("id") || n.className || "", o = {};
            o.domInfo = n.className ? i.toString().trim() : i.toString().replace(/[\ \n]/g, ""), o.t1 = e, this.getlocalData(this.clickStart) && this.removelocalData(this.clickStart), this.setlocalData(this.clickStart, o)
        }.bind(this), !0), window.performance) {
            t = window.performance.timing.navigationStart;
            var e = window.location.href, n = this.getlocalData(this.clickStart),
                i = this.getlocalData(this.forwardStart);
            n && i && t > i.t2 && e.indexOf(i.targetUrl.replace(/(\.*\/)*/i, "")) > -1 ? this.publish(n, i, {t3: t}) : this.deletelocalData()
        }
    }, k(m.prototype, "name", "universal"), m.prototype.traceUniversalPoint = function (t, e) {
        return t = t || {}, e = e || function () {
        }, this._aladdin.call(this.name, "traceUniversalPoint", t, e)
    };
    var O = new n;
    return O.env = A, O.use(r).use(l).use(h).use(u).use(p).use(f).use(y).use(m), O.burypoint.init(), function (t) {
        window.__ALADDIN__ = {}, window.__ALADDIN_CALLBACK__ = function () {
            var e = arguments;
            w(function () {
                t.callback.apply(t, e)
            })
        }, window.__ALADDIN_EVENT_EMIT__ = function () {
            var e = arguments;
            w(function () {
                t.emit.apply(t, e)
            })
        }, window.__ALADDIN_FETCH__ = function (e) {
            return t.fetch(e)
        }
    }(O), function (t) {
        var e;
        try {
            e = new Event("aladdinReady")
        } catch (t) {
            e = document.createEvent("Event"), e.initEvent("aladdinReady")
        }
        e.aladdin = t, document.dispatchEvent(e)
    }(O), O
});
