aboutsummaryrefslogtreecommitdiffstats
path: root/library/bootstrap/js/bootbox.js
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2015-03-17 23:07:08 +0100
committerMario Vavti <mario@mariovavti.com>2015-03-17 23:07:08 +0100
commit7966c2db4c027775f34ec26ef3b5bfce06f26605 (patch)
tree433ec59143a424138a52d571e60fda5365b0eb5f /library/bootstrap/js/bootbox.js
parentccdb027677aac06749d957383d758afae61320d6 (diff)
downloadvolse-hubzilla-7966c2db4c027775f34ec26ef3b5bfce06f26605.tar.gz
volse-hubzilla-7966c2db4c027775f34ec26ef3b5bfce06f26605.tar.bz2
volse-hubzilla-7966c2db4c027775f34ec26ef3b5bfce06f26605.zip
update bootstrap-3.3.4 and bootbox-4.4.0
Diffstat (limited to 'library/bootstrap/js/bootbox.js')
-rw-r--r--library/bootstrap/js/bootbox.js133
1 files changed, 112 insertions, 21 deletions
diff --git a/library/bootstrap/js/bootbox.js b/library/bootstrap/js/bootbox.js
index a002e4a35..3e8312a85 100644
--- a/library/bootstrap/js/bootbox.js
+++ b/library/bootstrap/js/bootbox.js
@@ -1,5 +1,5 @@
/**
- * bootbox.js [v4.3.0]
+ * bootbox.js [v4.4.0]
*
* http://bootboxjs.com/license.txt
*/
@@ -71,8 +71,8 @@
var defaults = {
// default language
locale: "en",
- // show backdrop or not
- backdrop: true,
+ // show backdrop or not. Default to static so user has to interact with dialog
+ backdrop: "static",
// animate the modal in/out
animate: true,
// additional class string applied to the top level dialog
@@ -105,7 +105,7 @@
// so, if the callback can be invoked and it *explicitly returns false*
// then we'll set a flag to keep the dialog active...
- var preserveDialog = $.isFunction(callback) && callback(e) === false;
+ var preserveDialog = $.isFunction(callback) && callback.call(dialog, e) === false;
// ... otherwise we'll bin it
if (!preserveDialog) {
@@ -148,11 +148,6 @@
options.buttons = {};
}
- // we only support Bootstrap's "static" and false backdrop args
- // supporting true would mean you could dismiss the dialog without
- // explicitly interacting with it
- options.backdrop = options.backdrop ? "static" : false;
-
buttons = options.buttons;
total = getKeyLength(buttons);
@@ -312,7 +307,7 @@
*/
options.buttons.ok.callback = options.onEscape = function() {
if ($.isFunction(options.callback)) {
- return options.callback();
+ return options.callback.call(this);
}
return true;
};
@@ -329,11 +324,11 @@
* overrides; undo anything the user tried to set they shouldn't have
*/
options.buttons.cancel.callback = options.onEscape = function() {
- return options.callback(false);
+ return options.callback.call(this, false);
};
options.buttons.confirm.callback = function() {
- return options.callback(true);
+ return options.callback.call(this, true);
};
// confirm specific validation
@@ -387,7 +382,7 @@
options.message = form;
options.buttons.cancel.callback = options.onEscape = function() {
- return options.callback(null);
+ return options.callback.call(this, null);
};
options.buttons.confirm.callback = function() {
@@ -418,7 +413,7 @@
break;
}
- return options.callback(value);
+ return options.callback.call(this, value);
};
options.show = false;
@@ -454,6 +449,10 @@
var groups = {};
inputOptions = options.inputOptions || [];
+ if (!$.isArray(inputOptions)) {
+ throw new Error("Please pass an array of input options");
+ }
+
if (!inputOptions.length) {
throw new Error("prompt with select requires options");
}
@@ -467,7 +466,6 @@
throw new Error("given options in wrong format");
}
-
// ... but override that element if this option sits in a group
if (option.group) {
@@ -525,14 +523,20 @@
break;
}
+ // @TODO provide an attributes option instead
+ // and simply map that as keys: vals
if (options.placeholder) {
input.attr("placeholder", options.placeholder);
}
- if(options.pattern){
+ if (options.pattern) {
input.attr("pattern", options.pattern);
}
+ if (options.maxlength) {
+ input.attr("maxlength", options.maxlength);
+ }
+
// now place it in our form
form.append(input);
@@ -552,6 +556,8 @@
// ...and replace it with one focusing our input, if possible
dialog.on("shown.bs.modal", function() {
+ // need the closure here since input isn't
+ // an object otherwise
input.focus();
});
@@ -574,6 +580,14 @@
onEscape: options.onEscape
};
+ if ($.fn.modal === undefined) {
+ throw new Error(
+ "$.fn.modal is not defined; please double check you have included " +
+ "the Bootstrap JavaScript library. See http://getbootstrap.com/javascript/ " +
+ "for more details."
+ );
+ }
+
each(buttons, function(key, button) {
// @TODO I don't like this string appending to itself; bit dirty. Needs reworking
@@ -595,9 +609,7 @@
if (options.size === "large") {
innerDialog.addClass("modal-lg");
- }
-
- if (options.size === "small") {
+ } else if (options.size === "small") {
innerDialog.addClass("modal-sm");
}
@@ -661,6 +673,30 @@
* respective triggers
*/
+ if (options.backdrop !== "static") {
+ // A boolean true/false according to the Bootstrap docs
+ // should show a dialog the user can dismiss by clicking on
+ // the background.
+ // We always only ever pass static/false to the actual
+ // $.modal function because with `true` we can't trap
+ // this event (the .modal-backdrop swallows it)
+ // However, we still want to sort of respect true
+ // and invoke the escape mechanism instead
+ dialog.on("click.dismiss.bs.modal", function(e) {
+ // @NOTE: the target varies in >= 3.3.x releases since the modal backdrop
+ // moved *inside* the outer dialog rather than *alongside* it
+ if (dialog.children(".modal-backdrop").length) {
+ e.currentTarget = dialog.children(".modal-backdrop").get(0);
+ }
+
+ if (e.target !== e.currentTarget) {
+ return;
+ }
+
+ dialog.trigger("escape.close.bb");
+ });
+ }
+
dialog.on("escape.close.bb", function(e) {
if (callbacks.onEscape) {
processCallback(e, dialog, callbacks.onEscape);
@@ -676,7 +712,6 @@
var callbackKey = $(this).data("bb-handler");
processCallback(e, dialog, callbacks[callbackKey]);
-
});
dialog.on("click", ".bootbox-close-button", function(e) {
@@ -700,7 +735,7 @@
$(options.container).append(dialog);
dialog.modal({
- backdrop: options.backdrop,
+ backdrop: options.backdrop ? "static": false,
keyboard: false,
show: false
});
@@ -759,6 +794,11 @@
* unlikely to be required. If this gets too large it can be split out into separate JS files.
*/
var locales = {
+ bg_BG : {
+ OK : "Ок",
+ CANCEL : "Отказ",
+ CONFIRM : "Потвърждавам"
+ },
br : {
OK : "OK",
CANCEL : "Cancelar",
@@ -799,6 +839,11 @@
CANCEL : "Katkesta",
CONFIRM : "OK"
},
+ fa : {
+ OK : "قبول",
+ CANCEL : "لغو",
+ CONFIRM : "تایید"
+ },
fi : {
OK : "OK",
CANCEL : "Peruuta",
@@ -814,6 +859,16 @@
CANCEL : "ביטול",
CONFIRM : "אישור"
},
+ hu : {
+ OK : "OK",
+ CANCEL : "Mégsem",
+ CONFIRM : "Megerősít"
+ },
+ hr : {
+ OK : "OK",
+ CANCEL : "Odustani",
+ CONFIRM : "Potvrdi"
+ },
id : {
OK : "OK",
CANCEL : "Batal",
@@ -864,11 +919,21 @@
CANCEL : "Отмена",
CONFIRM : "Применить"
},
+ sq : {
+ OK : "OK",
+ CANCEL : "Anulo",
+ CONFIRM : "Prano"
+ },
sv : {
OK : "OK",
CANCEL : "Avbryt",
CONFIRM : "OK"
},
+ th : {
+ OK : "ตกลง",
+ CANCEL : "ยกเลิก",
+ CONFIRM : "ยืนยัน"
+ },
tr : {
OK : "Tamam",
CANCEL : "İptal",
@@ -886,6 +951,32 @@
}
};
+ exports.addLocale = function(name, values) {
+ $.each(["OK", "CANCEL", "CONFIRM"], function(_, v) {
+ if (!values[v]) {
+ throw new Error("Please supply a translation for '" + v + "'");
+ }
+ });
+
+ locales[name] = {
+ OK: values.OK,
+ CANCEL: values.CANCEL,
+ CONFIRM: values.CONFIRM
+ };
+
+ return exports;
+ };
+
+ exports.removeLocale = function(name) {
+ delete locales[name];
+
+ return exports;
+ };
+
+ exports.setLocale = function(name) {
+ return exports.setDefaults("locale", name);
+ };
+
exports.init = function(_$) {
return init(_$ || $);
};