forked from bootboxjs/bootbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootbox.min.js
16 lines (16 loc) · 5.27 KB
/
bootbox.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
* bootbox.js v2.4.2
*
* http://bootboxjs.com/license.txt
*/
var bootbox=window.bootbox||function(k){function h(b,a){null==a&&(a=l);return"string"==typeof j[a][b]?j[a][b]:a!=m?h(b,m):b}var l="en",m="en",r=!0,q="static",s="",i={},e={},j={en:{OK:"OK",CANCEL:"Cancel",CONFIRM:"OK"},fr:{OK:"OK",CANCEL:"Annuler",CONFIRM:"D'accord"},de:{OK:"OK",CANCEL:"Abbrechen",CONFIRM:"Akzeptieren"},es:{OK:"OK",CANCEL:"Cancelar",CONFIRM:"Aceptar"},br:{OK:"OK",CANCEL:"Cancelar",CONFIRM:"Sim"},nl:{OK:"OK",CANCEL:"Annuleren",CONFIRM:"Accepteren"},ru:{OK:"OK",CANCEL:"\u041e\u0442\u043c\u0435\u043d\u0430",
CONFIRM:"\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c"},it:{OK:"OK",CANCEL:"Annulla",CONFIRM:"Conferma"}};e.setLocale=function(b){for(var a in j)if(a==b){l=b;return}throw Error("Invalid locale: "+b);};e.addLocale=function(b,a){"undefined"==typeof j[b]&&(j[b]={});for(var c in a)j[b][c]=a[c]};e.setIcons=function(b){i=b;if("object"!==typeof i||null==i)i={}};e.alert=function(){var b="",a=h("OK"),c=null;switch(arguments.length){case 1:b=arguments[0];break;case 2:b=arguments[0];"function"==typeof arguments[1]?
c=arguments[1]:a=arguments[1];break;case 3:b=arguments[0];a=arguments[1];c=arguments[2];break;default:throw Error("Incorrect number of arguments: expected 1-3");}return e.dialog(b,{label:a,icon:i.OK,callback:c},{onEscape:c})};e.confirm=function(){var b="",a=h("CANCEL"),c=h("CONFIRM"),f=null;switch(arguments.length){case 1:b=arguments[0];break;case 2:b=arguments[0];"function"==typeof arguments[1]?f=arguments[1]:a=arguments[1];break;case 3:b=arguments[0];a=arguments[1];"function"==typeof arguments[2]?
f=arguments[2]:c=arguments[2];break;case 4:b=arguments[0];a=arguments[1];c=arguments[2];f=arguments[3];break;default:throw Error("Incorrect number of arguments: expected 1-4");}return e.dialog(b,[{label:a,icon:i.CANCEL,callback:function(){"function"==typeof f&&f(!1)}},{label:c,icon:i.CONFIRM,callback:function(){"function"==typeof f&&f(!0)}}])};e.prompt=function(){var b="",a=h("CANCEL"),c=h("CONFIRM"),f=null,t="";switch(arguments.length){case 1:b=arguments[0];break;case 2:b=arguments[0];"function"==
typeof arguments[1]?f=arguments[1]:a=arguments[1];break;case 3:b=arguments[0];a=arguments[1];"function"==typeof arguments[2]?f=arguments[2]:c=arguments[2];break;case 4:b=arguments[0];a=arguments[1];c=arguments[2];f=arguments[3];break;case 5:b=arguments[0];a=arguments[1];c=arguments[2];f=arguments[3];t=arguments[4];break;default:throw Error("Incorrect number of arguments: expected 1-5");}var n=k("<form></form>");n.append("<input autocomplete=off type=text value='"+t+"' />");var d=e.dialog(n,[{label:a,
icon:i.CANCEL,callback:function(){"function"==typeof f&&f(null)}},{label:c,icon:i.CONFIRM,callback:function(){"function"==typeof f&&f(n.find("input[type=text]").val())}}],{header:b});d.on("shown",function(){n.find("input[type=text]").focus();n.on("submit",function(a){a.preventDefault();d.find(".btn-primary").click()})});return d};e.modal=function(){var b,a,c,f={onEscape:null,keyboard:!0,backdrop:q};switch(arguments.length){case 1:b=arguments[0];break;case 2:b=arguments[0];"object"==typeof arguments[1]?
c=arguments[1]:a=arguments[1];break;case 3:b=arguments[0];a=arguments[1];c=arguments[2];break;default:throw Error("Incorrect number of arguments: expected 1-3");}f.header=a;c="object"==typeof c?k.extend(f,c):f;return e.dialog(b,[],c)};e.dialog=function(b,a,c){var f=null,e="",i=[],c=c||{};null==a?a=[]:"undefined"==typeof a.length&&(a=[a]);for(var d=a.length;d--;){var h=null,j=null,l="",m=null;if("undefined"==typeof a[d].label&&"undefined"==typeof a[d]["class"]&&"undefined"==typeof a[d].callback){var h=
0,u=null,p;for(p in a[d])if(u=p,1<++h)break;1==h&&"function"==typeof a[d][p]&&(a[d].label=u,a[d].callback=a[d][p])}"function"==typeof a[d].callback&&(m=a[d].callback);a[d]["class"]?j=a[d]["class"]:d==a.length-1&&2>=a.length&&(j="btn-primary");h=a[d].label?a[d].label:"Option "+(d+1);a[d].icon&&(l="<i class='"+a[d].icon+"'></i> ");e+="<a data-handler='"+d+"' class='btn "+j+"' href='javascript:;'>"+l+""+h+"</a>";i[d]=m}a=["<div class='bootbox modal' style='overflow:hidden;'>"];if(c.header){d="";if("undefined"==
typeof c.headerCloseButton||c.headerCloseButton)d="<a href='javascript:;' class='close'>×</a>";a.push("<div class='modal-header'>"+d+"<h3>"+c.header+"</h3></div>")}a.push("<div class='modal-body'></div>");e&&a.push("<div class='modal-footer'>"+e+"</div>");a.push("</div>");var g=k(a.join("\n"));("undefined"===typeof c.animate?r:c.animate)&&g.addClass("fade");(e="undefined"===typeof c.classes?s:c.classes)&&g.addClass(e);k(".modal-body",g).html(b);g.bind("hidden",function(){g.remove()});g.bind("hide",
function(){if("escape"==f&&"function"==typeof c.onEscape)c.onEscape()});k(document).bind("keyup.modal",function(a){27==a.which&&(f="escape")});g.bind("shown",function(){k("a.btn-primary:last",g).focus()});g.on("click",".modal-footer a, a.close",function(a){var b=k(this).data("handler"),b=i[b],c=null;"function"==typeof b&&(c=b());!1!==c&&(a.preventDefault(),f="button",g.modal("hide"))});null==c.keyboard&&(c.keyboard="function"==typeof c.onEscape);k("body").append(g);g.modal({backdrop:"undefined"===
typeof c.backdrop?q:c.backdrop,keyboard:c.keyboard});return g};e.hideAll=function(){k(".bootbox").modal("hide")};e.animate=function(b){r=b};e.backdrop=function(b){q=b};e.classes=function(b){s=b};return e}(window.jQuery);