diff --git a/dist/modal.min.js b/dist/modal.min.js index 631e25a..d0e12b0 100644 --- a/dist/modal.min.js +++ b/dist/modal.min.js @@ -1 +1 @@ -!function(){function t(){var t='';$("#bsModalContent").length||(t+=''),$("#bsModalConfirmContent").length||(t+=''),$("#bsModalConfirmButtons").length||(t+=''),$("body").append(t)}function o(t){var o=$(this);$(document).trigger("bsmodal.js-modal.clicked",[o]),e($("#bsModalContent")),i(o),c.modal("show"),t.preventDefault()}function d(t){var o=new FormData(this);$(document).trigger("bsmodal.js-form.submitted",[$(this),o]),$.ajax({url:$(this).attr("action"),type:$(this).attr("method"),data:o,processData:!1,contentType:!1,success:function(t,o,d){$(document).trigger("bsmodal.js-form.success",[t,o,d])},complete:function(){$(document).trigger("bsmodal.js-form.completed")}}),t.preventDefault()}function a(t,o,d,a){201==a.status?(c.modal("hide"),o.redirect?window.location=o.redirect:window.location.reload()):s(o)}function n(t){var o=$(this).data("title")||"Delete",d=$(this).data("text")||"Are you sure you want to remove this item?",a=this,n=$("#bsModalConfirmButtons");e($("#bsModalConfirmContent")),l.find("#bsModalTitle").html(o),n.data("append")?(l.find(".modal-body").html(d),l.find(".modal-content").append(n.html())):l.find(".modal-body").html(d+n.html()),c.modal("show"),l.find(".js-confirm-btn").off().on("click",function(){return $(a).data("no-ajax")||$(a).hasClass("js-no-ajax")?window.location.href=$(a).attr("href"):void $.ajax({url:$(a).attr("href"),type:"GET",success:function(){window.location.reload()}})}),t.preventDefault()}function i(t){var o=t.data("url")||t.attr("href");$.get(o,function(t){s(t),$(document).trigger("bsmodal.js-modal.loaded",[t,o])})}function e(t){s(t?t.html():"")}function s(t){var o=$('');l.html(o.append(t))}var l,c;$(document).ready(function(){t(),c=$("#modalHolder"),l=c.find(".modal-dialog"),$(document).on("click",".js-modal",o),$(document).on("submit",".js-form",d),$(document).on("click",".js-confirm",n),$(document).on("bsmodal.js-form.success",a)})}(); \ No newline at end of file +!function(){function t(){var t='';$("#bsModalContent").length||(t+=''),$("#bsModalConfirmContent").length||(t+=''),$("#bsModalConfirmButtons").length||(t+=''),$("body").append(t)}function o(t){var o=$(this);$(document).trigger("bsmodal.js-modal.clicked",[o]),e($("#bsModalContent")),i(o),r.modal("show"),t.preventDefault()}function d(t){var o=$(this),d=new FormData(this);$(document).trigger("bsmodal.js-form.submitted",[$(this),d]),$.ajax({url:o.attr("action"),type:o.attr("method"),data:d,processData:!1,contentType:!1,success:function(t,d,a){$(document).trigger("bsmodal.js-form.success",[t,d,a,o])},complete:function(){$(document).trigger("bsmodal.js-form.completed",[o])}}),t.preventDefault()}function a(t,o,d,a,n){201==a.status?(r.modal("hide"),o.redirect?window.location=o.redirect:window.location.reload()):r.hasClass("in")&&r.find(".js-form")?s(o):n.attr("id")?n.html($(o).find("#"+n.attr("id"))):console.debug(".js-form must have an id attribute or be in modal window")}function n(t){var o=$(this).data("title")||"Delete",d=$(this).data("text")||"Are you sure you want to remove this item?",a=this,n=$("#bsModalConfirmButtons");e($("#bsModalConfirmContent")),l.find("#bsModalTitle").html(o),n.data("append")?(l.find(".modal-body").html(d),l.find(".modal-content").append(n.html())):l.find(".modal-body").html(d+n.html()),r.modal("show"),l.find(".js-confirm-btn").off().on("click",function(){return $(a).data("no-ajax")||$(a).hasClass("js-no-ajax")?window.location.href=$(a).attr("href"):void $.ajax({url:$(a).attr("href"),type:"GET",success:function(){window.location.reload()}})}),t.preventDefault()}function i(t){var o=t.data("url")||t.attr("href");$.get(o,function(t){s(t),$(document).trigger("bsmodal.js-modal.loaded",[t,o])})}function e(t){s(t?t.html():"")}function s(t){var o=$('');l.html(o.append(t))}var l,r;$(document).ready(function(){t(),r=$("#modalHolder"),l=r.find(".modal-dialog"),$(document).on("click",".js-modal",o),$(document).on("submit",".js-form",d),$(document).on("click",".js-confirm",n),$(document).on("bsmodal.js-form.success",a)})}(); \ No newline at end of file diff --git a/modal.js b/modal.js index 7e524aa..7c1f1c0 100644 --- a/modal.js +++ b/modal.js @@ -65,28 +65,29 @@ } function onJsFormSubmit(event) { + var form = $(this); var formData = new FormData(this); $(document).trigger('bsmodal.js-form.submitted', [$(this), formData]); $.ajax({ - url: $(this).attr("action"), - type: $(this).attr("method"), + url: form.attr("action"), + type: form.attr("method"), data: formData, processData: false, contentType: false, success: function(data, status, xhr) { - $(document).trigger('bsmodal.js-form.success', [data, status, xhr]); + $(document).trigger('bsmodal.js-form.success', [data, status, xhr, form]); }, complete: function() { - $(document).trigger('bsmodal.js-form.completed'); + $(document).trigger('bsmodal.js-form.completed', [form]); } }); event.preventDefault(); } - function onJsFormSuccess(event, data, status, xhr) { + function onJsFormSuccess(event, data, status, xhr, form) { if (xhr.status == 201) { modal.modal('hide'); @@ -96,7 +97,13 @@ window.location.reload(); } } else { - displayContent(data); + if (modal.hasClass('in') && modal.find('.js-form')) { + displayContent(data); + } else if (form.attr('id')) { + form.html($(data).find('#' + form.attr('id'))); + } else { + console.debug(".js-form must have an id attribute or be in modal window") + } } }