bootbox.js 5.4 KB

12345
  1. /**
  2. * bootbox.js v4.0.0
  3. *
  4. * http://bootboxjs.com/license.txt
  5. */window.bootbox=window.bootbox||function a(f,p){function m(b,c,d){b.preventDefault();f.isFunction(d)&&!1===d(b)||c.modal("hide")}function w(b){var c,d=0;for(c in b)d++;return d}function l(b,c){var d=0;f.each(b,function(b,e){c(b,e,d++)})}function x(b){var c,d;if("object"!=typeof b)throw Error("Please supply an object of options");if(!b.message)throw Error("Please specify a message");return b=f.extend({},n,b),b.buttons||(b.buttons={}),b.backdrop=b.backdrop?"static":!1,c=b.buttons,d=w(c),l(c,function(b,e,h){if(f.isFunction(e)&&(e=c[b]={callback:e}),"object"!==f.type(e))throw Error("button with key "+b+" must be an object");e.label||(e.label=b);e.className||(e.className=2>=d&&h===d-1?"btn-primary":"btn-default")}),b}function y(b,c){var d=b.length,g={};if(1>d||2<d)throw Error("Invalid argument length");return 2===d||"string"==typeof b[0]?(g[c[0]]=b[0],g[c[1]]=b[1]):g=b[0],g}function q(b,c,d){return f.extend(!0,{},b,y(c,d))}function r(b,c,d){return t(q(z.apply(null,b),c,d),b)}function u(){for(var b={},c=0,d=arguments.length;d>c;c++){var g=arguments[c],e=g.toLowerCase(),g=g.toUpperCase(),f=v[n.locale];b[e]={label:f?f[g]:v.en[g]}}return b}function z(){return{buttons:u.apply(null,arguments)}}function t(b,c){var d={};return l(c,function(b,c){d[c]=!0}),l(b.buttons,function(b){if(d[b]===p)throw Error("button key "+b+" is not allowed (options are "+c.join("\n")+")");}),b}var A=f("body"),n={locale:"en",backdrop:!0,animate:!0,className:null,closeButton:!0,show:!0},k={alert:function(){var b;if(b=r(["ok"],arguments,["message","callback"]),b.callback&&!f.isFunction(b.callback))throw Error("alert requires callback property to be a function when provided");return b.buttons.ok.callback=b.onEscape=function(){return f.isFunction(b.callback)?b.callback():!0},k.dialog(b)},confirm:function(){var b;if(b=r(["cancel","confirm"],arguments,["message","callback"]),b.buttons.cancel.callback=b.onEscape=function(){return b.callback(!1)},b.buttons.confirm.callback=function(){return b.callback(!0)},!f.isFunction(b.callback))throw Error("confirm requires a callback");return k.dialog(b)},prompt:function(){var b,c,d,g,e,h;if(g=f("\x3cform class\x3d'bootbox-form'\x3e\x3c/form\x3e"),c={buttons:u("cancel","confirm"),value:""},b=t(q(c,arguments,["title","callback"]),["cancel","confirm"]),h=b.show===p?!0:b.show,b.message=g,b.buttons.cancel.callback=b.onEscape=function(){return b.callback(null)},b.buttons.confirm.callback=function(){return b.callback(e.val())},b.show=!1,!b.title)throw Error("prompt requires a title");if(!f.isFunction(b.callback))throw Error("prompt requires a callback");return e=f("\x3cinput class\x3d'bootbox-input form-control' autocomplete\x3doff type\x3dtext /\x3e"),e.val(b.value),g.append(e),g.on("submit",function(b){b.preventDefault();d.find(".btn-primary").click()}),d=k.dialog(b),d.off("shown.bs.modal"),d.on("shown.bs.modal",function(){e.focus()}),!0===h&&d.modal("show"),d},dialog:function(b){b=x(b);var c=f("\x3cdiv class\x3d'bootbox modal' tabindex\x3d'-1' role\x3d'dialog'\x3e\x3cdiv class\x3d'modal-dialog'\x3e\x3cdiv class\x3d'modal-content'\x3e\x3cdiv class\x3d'modal-body'\x3e\x3cdiv class\x3d'bootbox-body'\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e"),d=c.find(".modal-body"),g="",e={onEscape:b.onEscape};if(l(b.buttons,function(b,c){g+="\x3cbutton data-bb-handler\x3d'"+b+"' type\x3d'button' class\x3d'btn "+c.className+"'\x3e"+c.label+"\x3c/button\x3e";e[b]=c.callback}),d.find(".bootbox-body").html(b.message),!0===b.animate&&c.addClass("fade"),b.className&&c.addClass(b.className),b.title&&d.before("\x3cdiv class\x3d'modal-header'\x3e\x3ch4 class\x3d'modal-title'\x3e\x3c/h4\x3e\x3c/div\x3e"),b.closeButton){var h=f("\x3cbutton type\x3d'button' class\x3d'bootbox-close-button close'\x3e\x26times;\x3c/button\x3e");b.title?c.find(".modal-header").prepend(h):h.css("margin-top","-10px").prependTo(d)}return b.title&&c.find(".modal-title").html(b.title),g.length&&(d.after("\x3cdiv class\x3d'modal-footer'\x3e\x3c/div\x3e"),c.find(".modal-footer").html(g)),c.on("hidden.bs.modal",function(b){b.target===this&&c.remove()}),c.on("shown.bs.modal",function(){c.find(".btn-primary:first").focus()}),c.on("escape.close.bb",function(b){e.onEscape&&m(b,c,e.onEscape)}),c.on("click",".modal-footer button",function(b){var d=f(this).data("bb-handler");m(b,c,e[d])}),c.on("click",".bootbox-close-button",function(b){m(b,c,e.onEscape)}),c.on("keyup",function(b){27===b.which&&c.trigger("escape.close.bb")}),A.append(c),c.modal({backdrop:b.backdrop,keyboard:!1,show:!1}),b.show&&c.modal("show"),c},setDefaults:function(b){f.extend(n,b)},hideAll:function(){f(".bootbox").modal("hide")}},v={br:{OK:"OK",CANCEL:"Cancelar",CONFIRM:"Sim"},da:{OK:"OK",CANCEL:"Annuller",CONFIRM:"Accepter"},de:{OK:"OK",CANCEL:"Abbrechen",CONFIRM:"Akzeptieren"},en:{OK:"OK",CANCEL:"Cancel",CONFIRM:"OK"},es:{OK:"OK",CANCEL:"Cancelar",CONFIRM:"Aceptar"},fi:{OK:"OK",CANCEL:"Peruuta",CONFIRM:"OK"},fr:{OK:"OK",CANCEL:"Annuler",CONFIRM:"D'accord"},it:{OK:"OK",CANCEL:"Annulla",CONFIRM:"Conferma"},nl:{OK:"OK",CANCEL:"Annuleren",CONFIRM:"Accepteren"},pl:{OK:"OK",CANCEL:"Anuluj",CONFIRM:"Potwierd\u017a"},ru:{OK:"OK",CANCEL:"\u041e\u0442\u043c\u0435\u043d\u0430",CONFIRM:"\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c"},zh_CN:{OK:"OK",CANCEL:"\u53d6\u6d88",CONFIRM:"\u786e\u8ba4"},zh_TW:{OK:"OK",CANCEL:"\u53d6\u6d88",CONFIRM:"\u78ba\u8a8d"}};return k.init=function(b){window.bootbox=a(b||f)},k}(window.jQuery);