1 line
No EOL
4.4 KiB
JavaScript
1 line
No EOL
4.4 KiB
JavaScript
!function(a,d){"use strict";"undefined"!=typeof module&&module.exports?module.exports=d(require("jquery"),require("bootstrap")):"function"==typeof define&&define.amd?define("bootstrap4dialog",["jquery","bootstrap"],function(a){return d(a)}):a.Bootstrap4Dialog=d(a.jQuery)}(this?this:window,function(a){var d=function(d){a.extend(!0,this.defaultOptions,d)};d.TYPE_PRIMARY="primary",d.TYPE_SECONDARY="secondary",d.TYPE_SUCCESS="success",d.TYPE_DANGER="danger",d.TYPE_WARNING="warning",d.TYPE_INFO="info",d.TYPE_LIGHT="light",d.TYPE_DARK="dark",d.SIZE_SMALL="modal-sm",d.SIZE_MEDIUM="",d.SIZE_LARGE="modal-lg",d.SIZE_EXTRA_LARGE="modal-xl",d.BACKDROP_YES="true",d.BACKDROP_NO="",d.BACKDROP_STATIC="static",d.defaultOptions={title:"",message:"",type:d.TYPE_PRIMARY,size:d.SIZE_MEDIUM,keyboard:!0,focus:!0,scrollable:!1,centered:!1,backdrop:d.BACKDROP_YES,duration:0,autodestroy:!0,open:null,close:null,buttons:[]},d.dialog=function(d){var o,s=a.extend(!1,this.defaultOptions,d);s.show=!1;try{if(!(s.title||s.message||s.buttons&&s.buttons.length))return!1;var l=s.id||"modalWindow_"+t(),n='<div id="'+l+'" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-dialog" role="document"><div class="modal-content">';s.title&&(n+='<div class="modal-header rounded"><h6 class="modal-title"></h6><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div>'),s.message&&(n+='<div class="modal-body"></div>'),s.buttons&&s.buttons.length&&(n+='<div class="modal-footer text-center"></div>'),a("body").append(n);var r=a("#"+l);switch(s.title&&s.title.length&&r.find(".modal-title").html(s.title),s.message&&s.message.length&&r.find(".modal-body").html(s.message),!s.title||s.message||s.buttons&&s.buttons.length||r.find(".modal-header").css({"border-bottom":"0px"}),!s.title&&!s.message&&s.buttons&&s.buttons.length&&r.find(".modal-footer").css({"border-top":"0px"}),s.size&&s.size.length&&r.find(".modal-dialog").addClass(s.size),s.centered&&r.find(".modal-dialog").addClass("modal-dialog-centered"),s.scrollable&&r.find(".modal-dialog").addClass("modal-dialog-scrollable"),!0){case"primary"==s.type:r.find(".modal-header").addClass("bg-primary").find(".modal-title").addClass("text-white"),r.find(".modal-body").addClass("text-primary");break;case"secondary"==s.type:r.find(".modal-header").addClass("bg-secondary").find(".modal-title").addClass("text-white"),r.find(".modal-body").addClass("text-secondary");break;case"success"==s.type:r.find(".modal-header").addClass("bg-success").find(".modal-title").addClass("text-white"),r.find(".modal-body").addClass("text-success");break;case"danger"==s.type:r.find(".modal-header").addClass("bg-danger").find(".modal-title").addClass("text-white"),r.find(".modal-body").addClass("text-danger");break;case"warning"==s.type:r.find(".modal-header").addClass("bg-warning"),r.find(".modal-body").addClass("text-warning");break;case"info"==s.type:r.find(".modal-header").addClass("bg-info").find(".modal-title").addClass("text-white"),r.find(".modal-body").addClass("text-info");break;case"light"==s.type:r.find(".modal-header").addClass("bg-light").find(".modal-title").addClass("text-black"),r.find(".modal-body").addClass("text-black");break;case"dark"==s.type:r.find(".modal-header").addClass("bg-dark").find(".modal-title").addClass("text-white"),r.find(".modal-body").addClass("text-dark")}o=r.modal(s);try{var c=r.find(".modal-footer");for(i in s.buttons){var m=s.buttons[i];c.append('<button class="btn" />');var f=c.find("button").eq(i);m.id&&f.attr("id",m.id),m.label&&f.html(m.label),m.cssClass&&f.addClass(m.cssClass),"function"==typeof m.action&&function(a,d,e){a.bind("click",function(){d(e,a)})}(f,m.action,o)}}catch(a){console.log(a.message)}return"function"==typeof s.open&&o.on("shown.bs.modal",s.open),"function"==typeof s.close&&o.on("hidden.bs.modal",s.close),s.autodestroy&&o.on("hidden.bs.modal",function(){e(o)}),s.duration&&o.on("shown.bs.modal",function(){setTimeout(function(){o.modal("hide")},1e3*parseFloat(s.duration))}),o}catch(a){console.warn(a.message)}},d.show=function(a){try{return this.dialog(a).modal("show")}catch(a){console.warn(a.message)}};var e=function(a){try{setTimeout(function(){a.remove()},200)}catch(a){console.warn(a.message)}},t=function(){for(var a=[],d=0;d<=15;d++)a[d]=d.toString(16);var e="";for(d=1;d<=36;d++)e+=9===d||14===d||19===d||24===d?"-":15===d?4:20===d?a[4*Math.random()|8]:a[16*Math.random()|0];return e};return d}); |