bsdialog4/bsdialog4.min.js
2023-08-03 11:29:44 +01:00

5 lines
3.6 KiB
JavaScript

/**
* BSDialog4
* @version v0.1.0.002 (2021/04/25 1713)
*/
var BSDialog={Create:function(o,t,e,d){var a=this;a.id=o,a.title=t,a.url=e,a.size=void 0===d?"md":!0===d?"lg":!1===d?"md":d,a.Exists(o)||a.renderContent(null),null!=e&&$.ajax({url:e,cache:!1,xhrFields:{withCredentials:!0},timeout:3e4,success:function(t,e,d){200==d.status||302==d.status||301==d.status?a.updateContentBody(o,t):a.updateContentBody(o,d.statusText+" ("+d.status+")")},error:function(t){a.updateContentBody(o,t.statusText+" ("+t.status+")")},complete:function(o,t){}}),a.initialiseComponents()},Close:function(o){$("#dlg"+o).modal("hide")},Clear:function(){$("body > div[class~='modal'][role='dialog']").remove(),$("body > div[class~='modal-backdrop']").remove(),$("body").removeClass("modal-open")},ShowToast:function(o,t,e,d){var a=this;a.Exists(o)||(a.id=o,a.title=t,a.url=null,a.size=void 0===d?"md":d,a.renderContent(e),a.initialiseComponents())},Exists:function(o){return $("body > div[id='dlg"+o+"']").length>0},generateModalHtml:function(o){var t=this,e="";return e+='<div class="modal fade" id="dlg'+t.id+'" tabindex="-1" role="dialog">',e+=' <div class="modal-dialog modal-'+t.size+'">',e+=' <div class="modal-content">',e+=' <div class="modal-header">',e+=' <strong class="modal-title" style="cursor:default; ">'+t.title+"</strong>",e+=' <button type="button" class="close" data-modal-action="restore" aria-hidden="true">&#8722;</button>',e+=' <button type="button" class="close ml-0" data-dismiss="modal" aria-hidden="true">&times;</button>',e+=" </div>",$.trim(o).length<=0?(e+=' <div class="modal-body">',e+=' <div class="text-center">',e+=' <div class="spinner-border text-secondary text-center" role="status">',e+=' <span class="sr-only">Loading...</span>',e+=" </div>",e+=" </div>",e+=" </div>"):e+=' <div class="modal-body">'+o+"</div>",e+=' <div class="modal-footer">',e+=' <button type="button" class="btn btn-outline-dark" data-dismiss="modal">Close</button>',e+=" </div>",e+=" </div>",e+=" </div>",e+="</div>"},renderContent:function(o){$("body").append(this.generateModalHtml(o))},initialiseComponents:function(){var o=this,t=o.getElement(),e=$(t).find("button[data-modal-action='restore']");$(e).length>0&&($(e).off("click"),$(e).on("click",function(){o.toggleSize()})),$(t).modal("show"),$(t).off("hide.bs.modal"),$(t).on("hide.bs.modal",function(){$(t).next().is("div[class~='modal-backdrop']")&&$(t).next().remove(),$(t).remove()}),$(t).find(".modal-header").off("mousedown"),$(t).find(".modal-header").on("mousedown",function(o){var e=o.pageX-$(this).offset().left,d=o.pageY-$(this).offset().top;$("body").off("mousemove.draggable"),$("body").on("mousemove.draggable",function(o){$(t).children(".modal-dialog").offset({left:o.pageX-e,top:o.pageY-d})}),$("body").off("mouseup"),$("body").on("mouseup",function(){$("body").off("mousemove.draggable")}),$(t).off("bs.modal.hide"),$(t).on("bs.modal.hide",function(){$("body").off("mousemove.draggable")})})},updateContentBody:function(o,t){var e=$("#dlg"+o).find(".modal-body");$(e).hasClass("custom-loading")&&$(e).removeClass("custom-loading"),$(e).html(t)},getElement:function(){return $("#dlg"+this.id)},toggleSize:function(){var o=$(this.getElement()).find("div[class^='modal-dialog']");$(o).length<=0||($(o).hasClass("modal-md")?($(o).removeClass("modal-md"),$(o).addClass("modal-lg")):$(o).hasClass("modal-lg")?($(o).removeClass("modal-lg"),$(o).addClass("modal-xl")):$(o).hasClass("modal-xl")?($(o).removeClass("modal-xl"),$(o).addClass("modal-md")):$(o).hasClass("modal-sm")&&($(o).removeClass("modal-sm"),$(o).addClass("modal-md")))}};