forked from bootboxjs/bootbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootbox.min.js
6 lines (6 loc) · 2.84 KB
/
bootbox.min.js
1
2
3
4
5
6
var bootbox=window.bootbox||function(){function h(b,a){a==null&&(a=k);return typeof i[a][b]=="string"?i[a][b]:a!=_defaultLocale?h(b,_defaultLocale):b}var e={},k=_defaultLocale="en",i={en:{OK:"OK",CANCEL:"Cancel",CONFIRM:"OK"},fr:{OK:"OK",CANCEL:"Annuler",CONFIRM:"D'accord"},de:{OK:"OK",CANCEL:"K\u00fcndigen",CONFIRM:"Akzeptieren"}};e.setLocale=function(b){for(var a in i)if(a==b){k=b;return}throw Error("Invalid locale: "+b);};e.addLocale=function(b,a){typeof i[b]=="undefined"&&(i[b]={});for(var c in a)i[b][c]=
a[c]};e.alert=function(){var b="",a=h("OK"),c=null;switch(arguments.length){case 1:b=arguments[0];break;case 2:b=arguments[0];typeof arguments[1]=="function"?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,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];typeof arguments[1]=="function"?f=arguments[1]:a=arguments[1];break;case 3:b=arguments[0];a=arguments[1];typeof arguments[2]=="function"?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,callback:function(){typeof f=="function"&&f(false)}},{label:c,callback:function(){typeof f=="function"&&f(true)}}])};e.dialog=function(b,a,c){var f=
null,e="",i=[],c=c||{};a==null?a=[]:typeof a.length=="undefined"&&(a=[a]);for(var d=a.length;d--;){var j=null,h=null,k=null;if(typeof a[d].label=="undefined"&&typeof a[d]["class"]=="undefined"&&typeof a[d].callback=="undefined"){var j=0,m=null,l;for(l in a[d])if(m=l,j++,j>1)break;if(j==1&&typeof a[d][l]=="function")a[d].label=m,a[d].callback=a[d][l]}typeof a[d].callback=="function"&&(k=a[d].callback);a[d]["class"]?h=a[d]["class"]:d==a.length-1&&a.length<=2?h="primary":d==0&&a.length==2&&(h="danger");
j=a[d].label?a[d].label:"Option "+(d+1);e+="<a data-handler='"+d+"' class='btn "+h+"' href='#'>"+j+"</a>";i[d]=k}var g=$(["<div class='bootbox modal hide fade'>\n<div class='modal-body'>",b,"</div>\n<div class='modal-footer'>",e,"</div>\n</div>"].join("\n"));g.bind("hidden",function(){g.remove()});g.bind("hide",function(){if(f=="escape"&&typeof c.onEscape=="function")c.onEscape()});$(document).bind("keyup.modal",function(a){a.which==27&&(f="escape")});g.bind("shown",function(){$("a.primary:last",
g).focus()});$("a",g).click(function(a){a.preventDefault();f="button";g.modal("hide");a=$(this).data("handler");a=i[a];typeof a=="function"&&a()});if(c.keyboard==null)c.keyboard=typeof c.onEscape=="function";g.modal({backdrop:c.backdrop||"static",show:c.show||true,keyboard:c.keyboard});$("body").append(g);return g};e.hideAll=function(){$(".bootbox").modal("hide")};return e}();