5 lines
3.5 KiB
JavaScript
5 lines
3.5 KiB
JavaScript
/**
|
|
* BSDialog
|
|
* @version v0.1.0.029a (2019/11/09 2239)
|
|
*/
|
|
var BSDialog={Create:function(o,t,e,d,a,s){var l=this;l.id=o,l.title=t,l.url=e,l.isBig=void 0!==d&&1==d,l.showSize=void 0===s||1==s;var n=void 0===a||1==a;l.Exists(o)||l.renderContent(null),null!=e&&$.ajax({url:e,cache:!1,xhrFields:{withCredentials:!0},timeout:6e4,success:function(t,e,d){200==d.status||302==d.status||301==d.status?n?l.updateContentBody(o,t):$("#dlg"+o).find(".modal-content").html(t):l.updateContentBody(o,d.statusText+" ("+d.status+")")},error:function(t){l.updateContentBody(o,t.statusText+" ("+t.status+")")},complete:function(o,t){}}),l.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.isBig=void 0!==d&&1==d,a.renderContent(e),a.initialiseComponents())},Exists:function(o){return $("body > div[id='dlg"+o+"']").length>0},generateModalHtml:function(o){var t=this,e=1==t.isBig?"lg":"md",d="";return d+='<div class="modal fade" id="dlg'+t.id+'" tabindex="-1" role="dialog" aria-labelledby="dlg'+t.id+'Label" aria-hidden="true">',d+=' <div class="modal-dialog modal-'+e+'">',d+=' <div class="modal-content">',d+=' <div class="modal-header">',d+=' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>',t.showSize&&(d+=' <span class="close"> </span>',d+=' <button type="button" class="close" data-modal-action="restore" aria-hidden="true">−</button>'),d+=' <strong class="modal-title" style="cursor:default; ">'+t.title+"</strong>",d+=" </div>",$.trim(o).length<=0?d+=' <div class="modal-body custom-loading" style="background-position: center center; background-repeat: no-repeat;"></div>':d+=' <div class="modal-body">'+o+"</div>",d+=' <div class="modal-footer">',d+=' <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>',d+=" </div>",d+=" </div>",d+=" </div>",d+="</div>"},renderContent:function(o){$("body").append(this.generateModalHtml(o))},initialiseComponents:function(){var o=this,t=o.getElement();if(o.showSize){var 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-md")))}}; |