/*! ng-dialog - v0.3.12 (https://github.com/likeastore/ngDialog) */
!function (a, b) { "undefined" != typeof module && module.exports ? module.exports = b(require("angular")) : "function" == typeof define && define.amd ? define(["angular"], b) : b(a.angular) }(this, function (a) { "use strict"; var b = a.module("ngDialog", []), c = a.element, d = a.isDefined, e = (document.body || document.documentElement).style, f = d(e.animation) || d(e.WebkitAnimation) || d(e.MozAnimation) || d(e.MsAnimation) || d(e.OAnimation), g = "animationend webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend", h = "a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]", i = !1, j = {}; return b.provider("ngDialog", function () { var b = this.defaults = { className: "ngdialog-theme-default", plain: !1, showClose: !0, closeByDocument: !0, closeByEscape: !0, closeByNavigation: !1, appendTo: !1, preCloseCallback: !1, overlay: !0, cache: !0, trapFocus: !0, preserveFocus: !0, ariaAuto: !0, ariaRole: null, ariaLabelledById: null, ariaLabelledBySelector: null, ariaDescribedById: null, ariaDescribedBySelector: null }; this.setForceBodyReload = function (a) { i = a || !1 }, this.setDefaults = function (c) { a.extend(b, c) }; var d, e = 0, k = 0, l = {}; this.$get = ["$document", "$templateCache", "$compile", "$q", "$http", "$rootScope", "$timeout", "$window", "$controller", "$injector", function (m, n, o, p, q, r, s, t, u, v) { var w = m.find("body"); i && r.$on("$locationChangeSuccess", function () { w = m.find("body") }); var x = { onDocumentKeydown: function (a) { 27 === a.keyCode && y.close("$escape") }, activate: function (a) { var b = a.data("$ngDialogOptions"); b.trapFocus && (a.on("keydown", x.onTrapFocusKeydown), w.on("keydown", x.onTrapFocusKeydown)) }, deactivate: function (a) { a.off("keydown", x.onTrapFocusKeydown), w.off("keydown", x.onTrapFocusKeydown) }, deactivateAll: function () { a.forEach(function (b) { var c = a.element(b); x.deactivate(c) }) }, setBodyPadding: function (a) { var b = parseInt(w.css("padding-right") || 0, 10); w.css("padding-right", b + a + "px"), w.data("ng-dialog-original-padding", b) }, resetBodyPadding: function () { var a = w.data("ng-dialog-original-padding"); a ? w.css("padding-right", a + "px") : w.css("padding-right", "") }, performCloseDialog: function (a, b) { var c = a.attr("id"), e = j[c]; if ("undefined" != typeof t.Hammer) { var h = e.hammerTime; h.off("tap", d), h.destroy && h.destroy(), delete e.hammerTime } else a.unbind("click"); 1 === k && w.unbind("keydown"), a.hasClass("ngdialog-closing") || (k -= 1); var i = a.data("$ngDialogPreviousFocus"); i && i.focus(), r.$broadcast("ngDialog.closing", a), k = 0 > k ? 0 : k, f ? (e.$destroy(), a.unbind(g).bind(g, function () { a.remove(), 0 === k && (w.removeClass("ngdialog-open"), x.resetBodyPadding()), r.$broadcast("ngDialog.closed", a) }).addClass("ngdialog-closing")) : (e.$destroy(), a.remove(), 0 === k && (w.removeClass("ngdialog-open"), x.resetBodyPadding()), r.$broadcast("ngDialog.closed", a)), l[c] && (l[c].resolve({ id: c, value: b, $dialog: a, remainingDialogs: k }), delete l[c]), j[c] && delete j[c] }, closeDialog: function (b, c) { var d = b.data("$ngDialogPreCloseCallback"); if (d && a.isFunction(d)) { var e = d.call(b, c); a.isObject(e) ? e.closePromise ? e.closePromise.then(function () { x.performCloseDialog(b, c) }) : e.then(function () { x.performCloseDialog(b, c) }, function () { }) : e !== !1 && x.performCloseDialog(b, c) } else x.performCloseDialog(b, c) }, onTrapFocusKeydown: function (b) { var c, d = a.element(b.currentTarget); if (d.hasClass("ngdialog")) c = d; else if (c = x.getActiveDialog(), null === c) return; var e = 9 === b.keyCode, f = b.shiftKey === !0; e && x.handleTab(c, b, f) }, handleTab: function (a, b, c) { var d = x.getFocusableElements(a); if (0 === d.length) return document.activeElement && document.activeElement.blur(), void 0; var e = document.activeElement, f = Array.prototype.indexOf.call(d, e), g = -1 === f, h = 0 === f, i = f === d.length - 1, j = !1; c ? (g || h) && (d[d.length - 1].focus(), j = !0) : (g || i) && (d[0].focus(), j = !0), j && (b.preventDefault(), b.stopPropagation()) }, autoFocus: function (a) { var b = a[0], d = b.querySelector("*[autofocus]"); if (null === d || (d.focus(), document.activeElement !== d)) { var e = x.getFocusableElements(a); if (e.length > 0) return e[0].focus(), void 0; var f = x.filterVisibleElements(b.querySelectorAll("h1,h2,h3,h4,h5,h6,p,span")); if (f.length > 0) { var g = f[0]; c(g).attr("tabindex", "0"), g.focus() } } }, getFocusableElements: function (a) { var b = a[0], c = b.querySelectorAll(h); return x.filterVisibleElements(c) }, filterVisibleElements: function (a) { for (var b = [], c = 0; c < a.length; c++) { var d = a[c]; (d.offsetWidth > 0 || d.offsetHeight > 0) && b.push(d) } return b }, getActiveDialog: function () { var a = document.querySelectorAll(".ngdialog"); return 0 === a.length ? null : c(a[a.length - 1]) }, applyAriaAttributes: function (a, b) { if (b.ariaAuto) { if (!b.ariaRole) { var c = x.getFocusableElements(a).length > 0 ? "dialog" : "alertdialog"; b.ariaRole = c } b.ariaLabelledBySelector || (b.ariaLabelledBySelector = "h1,h2,h3,h4,h5,h6"), b.ariaDescribedBySelector || (b.ariaDescribedBySelector = "article,section,p") } b.ariaRole && a.attr("role", b.ariaRole), x.applyAriaAttribute(a, "aria-labelledby", b.ariaLabelledById, b.ariaLabelledBySelector), x.applyAriaAttribute(a, "aria-describedby", b.ariaDescribedById, b.ariaDescribedBySelector) }, applyAriaAttribute: function (a, b, d, e) { if (d && a.attr(b, d), e) { var f = a.attr("id"), g = a[0].querySelector(e); if (!g) return; var h = f + "-" + b; return c(g).attr("id", h), a.attr(b, h), h } } }, y = { open: function (f) { function g(a, b) { return q.get(a, b || {}).then(function (a) { return a.data || "" }) } function h(b) { return b ? a.isString(b) && i.plain ? b : "boolean" != typeof i.cache || i.cache ? n.get(b) || g(b, { cache: !0 }) : g(b, { cache: !1 }) : "Empty template" } var i = a.copy(b), m = ++e, z = "ngdialog" + m; f = f || {}, a.extend(i, f); var A; l[z] = A = p.defer(); var B; j[z] = B = a.isObject(i.scope) ? i.scope.$new() : r.$new(); var C, D, E = a.extend({}, i.resolve); return a.forEach(E, function (b, c) { E[c] = a.isString(b) ? v.get(b) : v.invoke(b, null, null, c) }), p.all({ template: h(i.template || i.templateUrl), locals: p.all(E) }).then(function (b) { var e = b.template, f = b.locals; if (n.put(i.template || i.templateUrl, e), i.showClose && (e += '<div class="ngdialog-close"></div>'), C = c('<div id="ngdialog' + m + '" class="ngdialog"></div>'), C.html(i.overlay ? '<div class="ngdialog-overlay"></div><div class="ngdialog-content" role="document">' + e + "</div>" : '<div class="ngdialog-content" role="document">' + e + "</div>"), C.data("$ngDialogOptions", i), i.data && a.isString(i.data)) { var g = i.data.replace(/^\s*/, "")[0]; B.ngDialogData = "{" === g || "[" === g ? a.fromJson(i.data) : i.data } else i.data && a.isObject(i.data) && (B.ngDialogData = i.data); if (i.controller && (a.isString(i.controller) || a.isArray(i.controller) || a.isFunction(i.controller))) { var h = i.controller; i.controllerAs && a.isString(i.controllerAs) && (h += " as " + i.controllerAs); var j = u(h, a.extend(f, { $scope: B, $element: C })); C.data("$ngDialogControllerController", j) } if (i.className && C.addClass(i.className), D = i.appendTo && a.isString(i.appendTo) ? a.element(document.querySelector(i.appendTo)) : w, x.applyAriaAttributes(C, i), i.preCloseCallback) { var l; a.isFunction(i.preCloseCallback) ? l = i.preCloseCallback : a.isString(i.preCloseCallback) && B && (a.isFunction(B[i.preCloseCallback]) ? l = B[i.preCloseCallback] : B.$parent && a.isFunction(B.$parent[i.preCloseCallback]) ? l = B.$parent[i.preCloseCallback] : r && a.isFunction(r[i.preCloseCallback]) && (l = r[i.preCloseCallback])), l && C.data("$ngDialogPreCloseCallback", l) } if (B.closeThisDialog = function (a) { x.closeDialog(C, a) }, s(function () { var a = document.querySelectorAll(".ngdialog"); x.deactivateAll(a), o(C)(B); var b = t.innerWidth - w.prop("clientWidth"); w.addClass("ngdialog-open"); var c = b - (t.innerWidth - w.prop("clientWidth")); c > 0 && x.setBodyPadding(c), D.append(C), x.activate(C), i.trapFocus && x.autoFocus(C), i.name ? r.$broadcast("ngDialog.opened", { dialog: C, name: i.name }) : r.$broadcast("ngDialog.opened", C) }), i.closeByEscape && w.bind("keydown", x.onDocumentKeydown), i.closeByNavigation && r.$on("$locationChangeSuccess", function () { x.closeDialog(C) }), i.preserveFocus && C.data("$ngDialogPreviousFocus", document.activeElement), d = function (a) { var b = i.closeByDocument ? c(a.target).hasClass("ngdialog-overlay") : !1, d = c(a.target).hasClass("ngdialog-close"); (b || d) && y.close(C.attr("id"), d ? "$closeButton" : "$document") }, "undefined" != typeof t.Hammer) { var p = B.hammerTime = t.Hammer(C[0]); p.on("tap", d) } else C.bind("click", d); return k += 1, y }), { id: z, closePromise: A.promise, close: function (a) { x.closeDialog(C, a) } } }, openConfirm: function (b) { var d = p.defer(), e = { closeByEscape: !1, closeByDocument: !1 }; a.extend(e, b), e.scope = a.isObject(e.scope) ? e.scope.$new() : r.$new(), e.scope.confirm = function (a) { d.resolve(a); var b = c(document.getElementById(f.id)); x.performCloseDialog(b, a) }; var f = y.open(e); return f.closePromise.then(function (a) { return a ? d.reject(a.value) : d.reject() }), d.promise }, isOpen: function (a) { var b = c(document.getElementById(a)); return b.length > 0 }, close: function (a, b) { var d = c(document.getElementById(a)); return d.length ? x.closeDialog(d, b) : y.closeAll(b), y }, closeAll: function (a) { for (var b = document.querySelectorAll(".ngdialog"), d = b.length - 1; d >= 0; d--) { var e = b[d]; x.closeDialog(c(e), a) } }, getDefaults: function () { return b } }; return y }] }), b.directive("ngDialog", ["ngDialog", function (b) { return { restrict: "A", scope: { ngDialogScope: "=" }, link: function (c, d, e) { d.on("click", function (d) { d.preventDefault(); var f = a.isDefined(c.ngDialogScope) ? c.ngDialogScope : "noScope"; a.isDefined(e.ngDialogClosePrevious) && b.close(e.ngDialogClosePrevious); var g = b.getDefaults(); b.open({ template: e.ngDialog, className: e.ngDialogClass || g.className, controller: e.ngDialogController, controllerAs: e.ngDialogControllerAs, scope: f, data: e.ngDialogData, showClose: "false" === e.ngDialogShowClose ? !1 : "true" === e.ngDialogShowClose ? !0 : g.showClose, closeByDocument: "false" === e.ngDialogCloseByDocument ? !1 : "true" === e.ngDialogCloseByDocument ? !0 : g.closeByDocument, closeByEscape: "false" === e.ngDialogCloseByEscape ? !1 : "true" === e.ngDialogCloseByEscape ? !0 : g.closeByEscape, preCloseCallback: e.ngDialogPreCloseCallback || g.preCloseCallback }) }) } } }]), b });