angular-toastr-1.4.1.tpls.min.js 9.8 KB
Newer Older
J
Jason Song 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
!function () {
    "use strict";
    function t(t, e, s, n, o, r, a) {
        function i(t) {
            if (t)d(t.toastId); else for (var e = 0; e < O.length; e++)d(O[e].toastId)
        }

        function l(t, e, s) {
            var n = m().iconClasses.error;
            return g(n, t, e, s)
        }

        function c(t, e, s) {
            var n = m().iconClasses.info;
            return g(n, t, e, s)
        }

        function u(t, e, s) {
            var n = m().iconClasses.success;
            return g(n, t, e, s)
        }

        function p(t, e, s) {
            var n = m().iconClasses.warning;
            return g(n, t, e, s)
        }

        function d(e, s) {
            function n(t) {
                for (var e = 0; e < O.length; e++)if (O[e].toastId === t)return O[e]
            }

            function o() {
                return !O.length
            }

            var i = n(e);
            i && !i.deleting && (i.deleting = !0, i.isOpened = !1, t.leave(i.el).then(function () {
                i.scope.options.onHidden && i.scope.options.onHidden(s), i.scope.$destroy();
                var t = O.indexOf(i);
                delete B[i.scope.message], O.splice(t, 1);
                var e = r.maxOpened;
                e && O.length >= e && O[e - 1].open.resolve(), o() && (h.remove(), h = null, T = a.defer())
            }))
        }

        function g(t, e, s, n) {
            return angular.isObject(s) && (n = s, s = null), v({iconClass: t, message: e, optionsOverride: n, title: s})
        }

        function m() {
            return angular.extend({}, r)
        }

        function f(e) {
            if (h)return T.promise;
            h = angular.element("<div></div>"), h.attr("id", e.containerId), h.addClass(e.positionClass), h.css({"pointer-events": "auto"});
            var s = angular.element(document.querySelector(e.target));
            if (!s || !s.length)throw"Target for toasts doesn't exist";
            return t.enter(h, s).then(function () {
                T.resolve()
            }), T.promise
        }

        function v(s) {
            function r(t, e, s) {
                s.allowHtml ? (t.scope.allowHtml = !0, t.scope.title = o.trustAsHtml(e.title), t.scope.message = o.trustAsHtml(e.message)) : (t.scope.title = e.title, t.scope.message = e.message), t.scope.toastType = t.iconClass, t.scope.toastId = t.toastId, t.scope.options = {
                    extendedTimeOut: s.extendedTimeOut,
                    messageClass: s.messageClass,
                    onHidden: s.onHidden,
                    onShown: s.onShown,
                    progressBar: s.progressBar,
                    tapToDismiss: s.tapToDismiss,
                    timeOut: s.timeOut,
                    titleClass: s.titleClass,
                    toastClass: s.toastClass
                }, s.closeButton && (t.scope.options.closeHtml = s.closeHtml)
            }

            function i() {
                function t(t) {
                    for (var e = ["containerId", "iconClasses", "maxOpened", "newestOnTop", "positionClass", "preventDuplicates", "preventOpenDuplicates", "templates"], s = 0, n = e.length; n > s; s++)delete t[e[s]];
                    return t
                }

                var e = {toastId: C++, isOpened: !1, scope: n.$new(), open: a.defer()};
                return e.iconClass = s.iconClass, s.optionsOverride && (p = angular.extend(p, t(s.optionsOverride)), e.iconClass = s.optionsOverride.iconClass || e.iconClass), r(e, s, p), e.el = l(e.scope), e
            }

            function l(t) {
                var s = angular.element("<div toast></div>"), n = e.get("$compile");
                return n(s)(t)
            }

            function c() {
                return p.maxOpened && O.length <= p.maxOpened || !p.maxOpened
            }

            function u() {
                var t = p.preventDuplicates && s.message === w, e = p.preventOpenDuplicates && B[s.message];
                return t || e ? !0 : (w = s.message, B[s.message] = !0, !1)
            }

            var p = m();
            if (!u()) {
                var g = i();
                if (O.push(g), p.autoDismiss && p.maxOpened > 0)for (var v = O.slice(0, O.length - p.maxOpened), T = 0, $ = v.length; $ > T; T++)d(v[T].toastId);
                return c() && g.open.resolve(), g.open.promise.then(function () {
                    f(p).then(function () {
                        if (g.isOpened = !0, p.newestOnTop)t.enter(g.el, h).then(function () {
                            g.scope.init()
                        }); else {
                            var e = h[0].lastChild ? angular.element(h[0].lastChild) : null;
                            t.enter(g.el, h, e).then(function () {
                                g.scope.init()
                            })
                        }
                    })
                }), g
            }
        }

        var h, C = 0, O = [], w = "", B = {}, T = a.defer(), $ = {
            clear: i,
            error: l,
            info: c,
            remove: d,
            success: u,
            warning: p
        };
        return $
    }

    angular.module("toastr", []).factory("toastr", t), t.$inject = ["$animate", "$injector", "$document", "$rootScope", "$sce", "toastrConfig", "$q"]
}(), function () {
    "use strict";
    angular.module("toastr").constant("toastrConfig", {
        allowHtml: !1,
        autoDismiss: !1,
        closeButton: !1,
        closeHtml: "<button>&times;</button>",
        containerId: "toast-container",
        extendedTimeOut: 1e3,
        iconClasses: {error: "toast-error", info: "toast-info", success: "toast-success", warning: "toast-warning"},
        maxOpened: 0,
        messageClass: "toast-message",
        newestOnTop: !0,
        onHidden: null,
        onShown: null,
        positionClass: "toast-top-right",
        preventDuplicates: !1,
        preventOpenDuplicates: !1,
        progressBar: !1,
        tapToDismiss: !0,
        target: "body",
        templates: {toast: "directives/toast/toast.html", progressbar: "directives/progressbar/progressbar.html"},
        timeOut: 5e3,
        titleClass: "toast-title",
        toastClass: "toast"
    })
}(), function () {
    "use strict";
    function t(t) {
        function e(t, e, s, n) {
            function o() {
                var t = (i - (new Date).getTime()) / a * 100;
                e.css("width", t + "%")
            }

            var r, a, i;
            n.progressBar = t, t.start = function (t) {
                r && clearInterval(r), a = parseFloat(t), i = (new Date).getTime() + a, r = setInterval(o, 10)
            }, t.stop = function () {
                r && clearInterval(r)
            }, t.$on("$destroy", function () {
                clearInterval(r)
            })
        }

        return {
            replace: !0, require: "^toast", templateUrl: function () {
                return t.templates.progressbar
            }, link: e
        }
    }

    angular.module("toastr").directive("progressBar", t), t.$inject = ["toastrConfig"]
}(), function () {
    "use strict";
    function t() {
        this.progressBar = null, this.startProgressBar = function (t) {
            this.progressBar && this.progressBar.start(t)
        }, this.stopProgressBar = function () {
            this.progressBar && this.progressBar.stop()
        }
    }

    angular.module("toastr").controller("ToastController", t)
}(), function () {
    "use strict";
    function t(t, e, s, n) {
        function o(s, o, r, a) {
            function i(t) {
                return a.startProgressBar(t), e(function () {
                    a.stopProgressBar(), n.remove(s.toastId)
                }, t, 1)
            }

            function l() {
                s.progressBar = !1, a.stopProgressBar()
            }

            function c() {
                return s.options.closeHtml
            }

            var u;
            if (s.toastClass = s.options.toastClass, s.titleClass = s.options.titleClass, s.messageClass = s.options.messageClass, s.progressBar = s.options.progressBar, c()) {
                var p = angular.element(s.options.closeHtml), d = t.get("$compile");
                p.addClass("toast-close-button"), p.attr("ng-click", "close()"), d(p)(s), o.prepend(p)
            }
            s.init = function () {
                s.options.timeOut && (u = i(s.options.timeOut)), s.options.onShown && s.options.onShown()
            }, o.on("mouseenter", function () {
                l(), u && e.cancel(u)
            }), s.tapToast = function () {
                s.options.tapToDismiss && s.close(!0)
            }, s.close = function (t) {
                n.remove(s.toastId, t)
            }, o.on("mouseleave", function () {
                (0 !== s.options.timeOut || 0 !== s.options.extendedTimeOut) && (s.$apply(function () {
                    s.progressBar = s.options.progressBar
                }), u = i(s.options.extendedTimeOut))
            })
        }

        return {
            replace: !0, templateUrl: function () {
                return s.templates.toast
            }, controller: "ToastController", link: o
        }
    }

    angular.module("toastr").directive("toast", t), t.$inject = ["$injector", "$interval", "toastrConfig", "toastr"]
}(), angular.module("toastr").run(["$templateCache", function (t) {
    t.put("directives/progressbar/progressbar.html", '<div class="toast-progress"></div>\n'), t.put("directives/toast/toast.html", '<div class="{{toastClass}} {{toastType}}" ng-click="tapToast()">\n  <div ng-switch on="allowHtml">\n    <div ng-switch-default ng-if="title" class="{{titleClass}}">{{title}}</div>\n    <div ng-switch-default class="{{messageClass}}">{{message}}</div>\n    <div ng-switch-when="true" ng-if="title" class="{{titleClass}}" ng-bind-html="title"></div>\n    <div ng-switch-when="true" class="{{messageClass}}" ng-bind-html="message"></div>\n  </div>\n  <progress-bar ng-if="progressBar"></progress-bar>\n</div>\n')
}]);