1
0
mirror of https://codeberg.org/nobody/LocalCDN.git synced 2025-02-23 15:17:49 +01:00
2020-11-14 09:12:44 +01:00

2 lines
15 KiB
JavaScript

!function(t,o){"use strict";"function"==typeof define&&define.amd?define(["jquery"],o):"object"==typeof exports?module.exports=o(require("jquery")):t.bootbox=o(t.jQuery)}(this,function o(p,u){"use strict";var r,n,i,l;Object.keys||(Object.keys=(r=Object.prototype.hasOwnProperty,n=!{toString:null}.propertyIsEnumerable("toString"),l=(i=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"]).length,function(t){if("function"!=typeof t&&("object"!=typeof t||null===t))throw new TypeError("Object.keys called on non-object");var o,e,a=[];for(o in t)r.call(t,o)&&a.push(o);if(n)for(e=0;e<l;e++)r.call(t,i[e])&&a.push(i[e]);return a}));var d={};d.VERSION="5.0.0";var b={en:{OK:"OK",CANCEL:"Cancel",CONFIRM:"OK"}},f={dialog:'<div class="bootbox modal" tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-body"><div class="bootbox-body"></div></div></div></div></div>',header:'<div class="modal-header"><h5 class="modal-title"></h5></div>',footer:'<div class="modal-footer"></div>',closeButton:'<button type="button" class="bootbox-close-button close" aria-hidden="true">&times;</button>',form:'<form class="bootbox-form"></form>',button:'<button type="button" class="btn"></button>',option:"<option></option>",promptMessage:'<div class="bootbox-prompt-message"></div>',inputs:{text:'<input class="bootbox-input bootbox-input-text form-control" autocomplete="off" type="text" />',textarea:'<textarea class="bootbox-input bootbox-input-textarea form-control"></textarea>',email:'<input class="bootbox-input bootbox-input-email form-control" autocomplete="off" type="email" />',select:'<select class="bootbox-input bootbox-input-select form-control"></select>',checkbox:'<div class="form-check checkbox"><label class="form-check-label"><input class="form-check-input bootbox-input bootbox-input-checkbox" type="checkbox" /></label></div>',radio:'<div class="form-check radio"><label class="form-check-label"><input class="form-check-input bootbox-input bootbox-input-radio" type="radio" name="bootbox-radio" /></label></div>',date:'<input class="bootbox-input bootbox-input-date form-control" autocomplete="off" type="date" />',time:'<input class="bootbox-input bootbox-input-time form-control" autocomplete="off" type="time" />',number:'<input class="bootbox-input bootbox-input-number form-control" autocomplete="off" type="number" />',password:'<input class="bootbox-input bootbox-input-password form-control" autocomplete="off" type="password" />',range:'<input class="bootbox-input bootbox-input-range form-control-range" autocomplete="off" type="range" />'}},m={locale:"en",backdrop:"static",animate:!0,className:null,closeButton:!0,show:!0,container:"body",value:"",inputType:"text",swapButtonOrder:!1,centerVertical:!1,multiple:!1,scrollable:!1};function c(t,o,e){return p.extend(!0,{},t,function(t,o){var e=t.length,a={};if(e<1||2<e)throw new Error("Invalid argument length");return 2===e||"string"==typeof t[0]?(a[o[0]]=t[0],a[o[1]]=t[1]):a=t[0],a}(o,e))}function h(t,o,e,a){var r;a&&a[0]&&(r=a[0].locale||m.locale,(a[0].swapButtonOrder||m.swapButtonOrder)&&(o=o.reverse()));var n,i,l,s={className:"bootbox-"+t,buttons:function(t,o){for(var e={},a=0,r=t.length;a<r;a++){var n=t[a],i=n.toLowerCase(),l=n.toUpperCase();e[i]={label:(s=l,(c=b[o])?c[s]:b.en[s])}}var s,c;return e}(o,r)};return n=c(s,a,e),l={},g(i=o,function(t,o){l[o]=!0}),g(n.buttons,function(t){if(l[t]===u)throw new Error('button key "'+t+'" is not allowed (options are '+i.join(" ")+")")}),n}function w(t){return Object.keys(t).length}function g(t,e){var a=0;p.each(t,function(t,o){e(t,o,a++)})}function v(t){t.data.dialog.find(".bootbox-accept").first().trigger("focus")}function y(t){t.target===t.data.dialog[0]&&t.data.dialog.remove()}function x(t){t.target===t.data.dialog[0]&&(t.data.dialog.off("escape.close.bb"),t.data.dialog.off("click"))}function k(t,o,e){t.stopPropagation(),t.preventDefault(),p.isFunction(e)&&!1===e.call(o,t)||o.modal("hide")}function E(t){return/([01][0-9]|2[0-3]):[0-5][0-9]?:[0-5][0-9]/.test(t)}function O(t){return/(\d{4})-(\d{2})-(\d{2})/.test(t)}return d.locales=function(t){return t?b[t]:b},d.addLocale=function(t,e){return p.each(["OK","CANCEL","CONFIRM"],function(t,o){if(!e[o])throw new Error('Please supply a translation for "'+o+'"')}),b[t]={OK:e.OK,CANCEL:e.CANCEL,CONFIRM:e.CONFIRM},d},d.removeLocale=function(t){if("en"===t)throw new Error('"en" is used as the default and fallback locale and cannot be removed.');return delete b[t],d},d.setLocale=function(t){return d.setDefaults("locale",t)},d.setDefaults=function(){var t={};return 2===arguments.length?t[arguments[0]]=arguments[1]:t=arguments[0],p.extend(m,t),d},d.hideAll=function(){return p(".bootbox").modal("hide"),d},d.init=function(t){return o(t||p)},d.dialog=function(t){if(p.fn.modal===u)throw new Error('"$.fn.modal" is not defined; please double check you have included the Bootstrap JavaScript library. See https://getbootstrap.com/docs/4.4/getting-started/javascript/ for more details.');var o;t=function(r){var n,i;if("object"!=typeof r)throw new Error("Please supply an object of options");if(!r.message)throw new Error('"message" option must not be null or an empty string.');(r=p.extend({},m,r)).backdrop?r.backdrop="string"!=typeof r.backdrop||"static"!==r.backdrop.toLowerCase()||"static":r.backdrop=!1!==r.backdrop&&0!==r.backdrop&&"static";r.buttons||(r.buttons={});return n=r.buttons,i=w(n),g(n,function(t,o,e){if(p.isFunction(o)&&(o=n[t]={callback:o}),"object"!==p.type(o))throw new Error('button with key "'+t+'" must be an object');var a;o.label||(o.label=t),o.className||(a=!1,a=r.swapButtonOrder?0===e:e===i-1,o.className=i<=2&&a?"btn-primary":"btn-secondary btn-default")}),r}(t),p.fn.modal.Constructor.VERSION?(t.fullBootstrapVersion=p.fn.modal.Constructor.VERSION,o=t.fullBootstrapVersion.indexOf("."),t.bootstrap=t.fullBootstrapVersion.substring(0,o)):(t.bootstrap="2",t.fullBootstrapVersion="2.3.2",console.warn("Bootbox will *mostly* work with Bootstrap 2, but we do not officially support it. Please upgrade, if possible."));var e,a=p(f.dialog),r=a.find(".modal-dialog"),n=a.find(".modal-body"),i=p(f.header),l=p(f.footer),s=t.buttons,c={onEscape:t.onEscape};if(n.find(".bootbox-body").html(t.message),0<w(t.buttons)&&(g(s,function(t,o){var e=p(f.button);switch(e.data("bb-handler",t),e.addClass(o.className),t){case"ok":case"confirm":e.addClass("bootbox-accept");break;case"cancel":e.addClass("bootbox-cancel")}e.html(o.label),l.append(e),c[t]=o.callback}),n.after(l)),!0===t.animate&&a.addClass("fade"),t.className&&a.addClass(t.className),t.size)switch(t.fullBootstrapVersion.substring(0,3)<"3.1"&&console.warn('"size" requires Bootstrap 3.1.0 or higher. You appear to be using '+t.fullBootstrapVersion+". Please upgrade to use this option."),t.size){case"small":case"sm":r.addClass("modal-sm");break;case"large":case"lg":r.addClass("modal-lg");break;case"extra-large":case"xl":r.addClass("modal-xl"),t.fullBootstrapVersion.substring(0,3)<"4.2"&&console.warn('Using size "xl"/"extra-large" requires Bootstrap 4.2.0 or higher. You appear to be using '+t.fullBootstrapVersion+". Please upgrade to use this option.")}if(t.scrollable&&(r.addClass("modal-dialog-scrollable"),t.fullBootstrapVersion.substring(0,3)<"4.3"&&console.warn('Using "scrollable" requires Bootstrap 4.3.0 or higher. You appear to be using '+t.fullBootstrapVersion+". Please upgrade to use this option.")),t.title&&(n.before(i),a.find(".modal-title").html(t.title)),t.closeButton&&(e=p(f.closeButton),t.title?3<t.bootstrap?a.find(".modal-header").append(e):a.find(".modal-header").prepend(e):e.prependTo(n)),t.centerVertical&&(r.addClass("modal-dialog-centered"),t.fullBootstrapVersion<"4.0.0"&&console.warn('"centerVertical" requires Bootstrap 4.0.0-beta.3 or higher. You appear to be using '+t.fullBootstrapVersion+". Please upgrade to use this option.")),a.one("hide.bs.modal",{dialog:a},x),t.onHide){if(!p.isFunction(t.onHide))throw new Error('Argument supplied to "onHide" must be a function');a.on("hide.bs.modal",t.onHide)}if(a.one("hidden.bs.modal",{dialog:a},y),t.onHidden){if(!p.isFunction(t.onHidden))throw new Error('Argument supplied to "onHidden" must be a function');a.on("hidden.bs.modal",t.onHidden)}if(t.onShow){if(!p.isFunction(t.onShow))throw new Error('Argument supplied to "onShow" must be a function');a.on("show.bs.modal",t.onShow)}if(a.one("shown.bs.modal",{dialog:a},v),t.onShown){if(!p.isFunction(t.onShown))throw new Error('Argument supplied to "onShown" must be a function');a.on("shown.bs.modal",t.onShown)}return!0===t.backdrop&&a.on("click.dismiss.bs.modal",function(t){a.children(".modal-backdrop").length&&(t.currentTarget=a.children(".modal-backdrop").get(0)),t.target===t.currentTarget&&a.trigger("escape.close.bb")}),a.on("escape.close.bb",function(t){c.onEscape&&k(t,a,c.onEscape)}),a.on("click",".modal-footer button:not(.disabled)",function(t){var o=p(this).data("bb-handler");o!==u&&k(t,a,c[o])}),a.on("click",".bootbox-close-button",function(t){k(t,a,c.onEscape)}),a.on("keyup",function(t){27===t.which&&a.trigger("escape.close.bb")}),p(t.container).append(a),a.modal({backdrop:t.backdrop,keyboard:!1,show:!1}),t.show&&a.modal("show"),a},d.alert=function(){var t=h("alert",["ok"],["message","callback"],arguments);if(t.callback&&!p.isFunction(t.callback))throw new Error('alert requires the "callback" property to be a function when provided');return t.buttons.ok.callback=t.onEscape=function(){return!p.isFunction(t.callback)||t.callback.call(this)},d.dialog(t)},d.confirm=function(){var t=h("confirm",["cancel","confirm"],["message","callback"],arguments);if(!p.isFunction(t.callback))throw new Error("confirm requires a callback");return t.buttons.cancel.callback=t.onEscape=function(){return t.callback.call(this,!1)},t.buttons.confirm.callback=function(){return t.callback.call(this,!0)},d.dialog(t)},d.prompt=function(){var o,r,t,e,a=p(f.form),n=h("prompt",["cancel","confirm"],["title","callback"],arguments);if(n.value||(n.value=m.value),n.inputType||(n.inputType=m.inputType),t=n.show===u?m.show:n.show,n.show=!1,n.buttons.cancel.callback=n.onEscape=function(){return n.callback.call(this,null)},n.buttons.confirm.callback=function(){var t;if("checkbox"===n.inputType)t=r.find("input:checked").map(function(){return p(this).val()}).get();else if("radio"===n.inputType)t=r.find("input:checked").val();else{if(r[0].checkValidity&&!r[0].checkValidity())return!1;t="select"===n.inputType&&!0===n.multiple?r.find("option:selected").map(function(){return p(this).val()}).get():r.val()}return n.callback.call(this,t)},!n.title)throw new Error("prompt requires a title");if(!p.isFunction(n.callback))throw new Error("prompt requires a callback");if(!f.inputs[n.inputType])throw new Error("Invalid prompt type");switch(r=p(f.inputs[n.inputType]),n.inputType){case"text":case"textarea":case"email":case"password":r.val(n.value),n.placeholder&&r.attr("placeholder",n.placeholder),n.pattern&&r.attr("pattern",n.pattern),n.maxlength&&r.attr("maxlength",n.maxlength),n.required&&r.prop({required:!0}),n.rows&&!isNaN(parseInt(n.rows))&&"textarea"===n.inputType&&r.attr({rows:n.rows});break;case"date":case"time":case"number":case"range":if(r.val(n.value),n.placeholder&&r.attr("placeholder",n.placeholder),n.pattern&&r.attr("pattern",n.pattern),n.required&&r.prop({required:!0}),"date"!==n.inputType&&n.step){if(!("any"===n.step||!isNaN(n.step)&&0<parseFloat(n.step)))throw new Error('"step" must be a valid positive number or the value "any". See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-step for more information.');r.attr("step",n.step)}!function(t,o,e){var a=!1,r=!0,n=!0;if("date"===t)o===u||(r=O(o))?e===u||(n=O(e))||console.warn('Browsers which natively support the "date" input type expect date values to be of the form "YYYY-MM-DD" (see ISO-8601 https://www.iso.org/iso-8601-date-and-time-format.html). Bootbox does not enforce this rule, but your max value may not be enforced by this browser.'):console.warn('Browsers which natively support the "date" input type expect date values to be of the form "YYYY-MM-DD" (see ISO-8601 https://www.iso.org/iso-8601-date-and-time-format.html). Bootbox does not enforce this rule, but your min value may not be enforced by this browser.');else if("time"===t){if(o!==u&&!(r=E(o)))throw new Error('"min" is not a valid time. See https://www.w3.org/TR/2012/WD-html-markup-20120315/datatypes.html#form.data.time for more information.');if(e!==u&&!(n=E(e)))throw new Error('"max" is not a valid time. See https://www.w3.org/TR/2012/WD-html-markup-20120315/datatypes.html#form.data.time for more information.')}else{if(o!==u&&isNaN(o))throw r=!1,new Error('"min" must be a valid number. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-min for more information.');if(e!==u&&isNaN(e))throw n=!1,new Error('"max" must be a valid number. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-max for more information.')}if(r&&n){if(e<=o)throw new Error('"max" must be greater than "min". See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-max for more information.');a=!0}return a}(n.inputType,n.min,n.max)||(n.min!==u&&r.attr("min",n.min),n.max!==u&&r.attr("max",n.max));break;case"select":var i={},l=n.inputOptions||[];if(!p.isArray(l))throw new Error("Please pass an array of input options");if(!l.length)throw new Error('prompt with "inputType" set to "select" requires at least one option');n.placeholder&&r.attr("placeholder",n.placeholder),n.required&&r.prop({required:!0}),n.multiple&&r.prop({multiple:!0}),g(l,function(t,o){var e=r;if(o.value===u||o.text===u)throw new Error('each option needs a "value" property and a "text" property');o.group&&(i[o.group]||(i[o.group]=p("<optgroup />").attr("label",o.group)),e=i[o.group]);var a=p(f.option);a.attr("value",o.value).text(o.text),e.append(a)}),g(i,function(t,o){r.append(o)}),r.val(n.value);break;case"checkbox":var s=p.isArray(n.value)?n.value:[n.value];if(!(l=n.inputOptions||[]).length)throw new Error('prompt with "inputType" set to "checkbox" requires at least one option');r=p('<div class="bootbox-checkbox-list"></div>'),g(l,function(t,e){if(e.value===u||e.text===u)throw new Error('each option needs a "value" property and a "text" property');var a=p(f.inputs[n.inputType]);a.find("input").attr("value",e.value),a.find("label").append("\n"+e.text),g(s,function(t,o){o===e.value&&a.find("input").prop("checked",!0)}),r.append(a)});break;case"radio":if(n.value!==u&&p.isArray(n.value))throw new Error('prompt with "inputType" set to "radio" requires a single, non-array value for "value"');if(!(l=n.inputOptions||[]).length)throw new Error('prompt with "inputType" set to "radio" requires at least one option');r=p('<div class="bootbox-radiobutton-list"></div>');var c=!0;g(l,function(t,o){if(o.value===u||o.text===u)throw new Error('each option needs a "value" property and a "text" property');var e=p(f.inputs[n.inputType]);e.find("input").attr("value",o.value),e.find("label").append("\n"+o.text),n.value!==u&&o.value===n.value&&(e.find("input").prop("checked",!0),c=!1),r.append(e)}),c&&r.find('input[type="radio"]').first().prop("checked",!0)}return a.append(r),a.on("submit",function(t){t.preventDefault(),t.stopPropagation(),o.find(".bootbox-accept").trigger("click")}),""!==p.trim(n.message)&&(e=p(f.promptMessage).html(n.message),a.prepend(e)),n.message=a,(o=d.dialog(n)).off("shown.bs.modal",v),o.on("shown.bs.modal",function(){r.focus()}),!0===t&&o.modal("show"),o},d});