﻿// --------------------------------
//  Plugin author: Robert Koritnik
// --------------------------------
//  Depends on Plugin.Timer.js
// --------------------------------
(function(a) { a.fn.popup = function(d) { var c = function() { }; d = a.extend({ closeSelectorInside: ".close-popup", closeSelectorOutside: ".toggle-popup", title: "Notify window title should be set.", messageSuccess: "Notify window success message should be set.", messageFail: "Notify window fail message should be set.", useAjax: true, autoFocus: true, closeOnFail: false, onShow: c, onSuccess: c, onFail: c, onReset: c }, d || {}); openedPopup = 0; togglePopup = function(e) { openedPopup && openedPopup.slideUp("fast"); if (openedPopup === null || e.data("unique") != openedPopup.data("unique")) { e.slideDown("fast", function() { if (d.autoFocus === true) { a(":input[value='']:first", e).focus() } if (a.isFunction(d.onShow)) { d.onShow(e) } }); openedPopup = e; return } openedPopup = null }; var b = this.each(function(f, g) { var e = a(g); if (e.attr("viva-popup") && e.attr("viva-popup") === "enabled") { return } e.attr("viva-popup", "enabled"); d.title = e.attr("title") || d.title; d.messageSuccess = e.attr("message-success") || d.messageSuccess; d.messageFail = e.attr("message-fail") || d.messageFail; e.hide(); e.prev(d.closeSelectorOutside).click(function(h) { h.preventDefault(); togglePopup(e) }); e.data("unique", openedPopup++); a(d.closeSelectorInside, e).click(function(h) { h.preventDefault(); togglePopup(e) }); if (a("form", e).length > 0 && d.useAjax === true) { a("form", e).submit(function(h) { h.preventDefault() }); a("button[type=submit]", e).click(function(k) { k.preventDefault(); var h = a(this).closest("form"); var j = a(d.closeSelectorInside + ":first", e); if (h && h.length == 1) { var i = h.serializeArray(); jQuery.ajax({ type: "POST", url: h.attr("action"), data: i, success: function(m, l, n) { h[0].reset(); if (a.isFunction(d.onReset)) { d.onReset(e) } j.click(); Viva.Notify.show(Viva.Notify.InformationType.Info, d.title, d.messageSuccess); if (a.isFunction(d.onSuccess)) { a.runOnce("CreateSuccess", function() { d.onSuccess(e, m) }, 250, true, this) } }, error: function(n, l, m) { if (d.closeOnFail === true) { h[0].reset(); if (a.isFunction(d.onReset)) { d.onReset(e) } j.click() } if (n.status == 400) { Viva.Notify.show(Viva.Notify.InformationType.Warning, d.title, n.responseText) } else { Viva.Notify.show(Viva.Notify.InformationType.Error, d.title, d.messageFail) } if (a.isFunction(d.onFail)) { a.runOnce("CreateFail", function() { d.onFail(e) }, 250, true, this) } } }) } }) } }); openedPopup = null; return b } })(jQuery);

