/**
* bootbox.js v3.2.0
*
* http://bootboxjs.com/license.txt
*/
var bootbox = window.bootbox || (function(document, $) {
/*jshint scripturl:true sub:true */
var _locale = 'en',
_defaultLocale = 'en',
_animate = true,
_backdrop = 'static',
_defaultHref = 'javascript:;',
_classes = '',
_btnClasses = {},
_icons = {},
/* last var should always be the public object we'll return */
that = {};
/**
* public API
*/
that.setLocale = function(locale) {
for (var i in _locales) {
if (i == locale) {
_locale = locale;
return;
}
}
throw new Error('Invalid locale: '+locale);
};
that.addLocale = function(locale, translations) {
if (typeof _locales[locale] === 'undefined') {
_locales[locale] = {};
}
for (var str in translations) {
_locales[locale][str] = translations[str];
}
};
that.setIcons = function(icons) {
_icons = icons;
if (typeof _icons !== 'object' || _icons === null) {
_icons = {};
}
};
that.setBtnClasses = function(btnClasses) {
_btnClasses = btnClasses;
if (typeof _btnClasses !== 'object' || _btnClasses === null) {
_btnClasses = {};
}
};
that.alert = function(/*str, label, cb*/) {
var str = "",
label = _translate('OK'),
cb = null;
switch (arguments.length) {
case 1:
// no callback, default button label
str = arguments[0];
break;
case 2:
// callback *or* custom button label dependent on type
str = arguments[0];
if (typeof arguments[1] == 'function') {
cb = arguments[1];
} else {
label = arguments[1];
}
break;
case 3:
// callback and custom button label
str = arguments[0];
label = arguments[1];
cb = arguments[2];
break;
default:
throw new Error("Incorrect number of arguments: expected 1-3");
}
return that.dialog(str, {
// only button (ok)
"label" : label,
"icon" : _icons.OK,
"class" : _btnClasses.OK,
"callback": cb
}, {
// ensure that the escape key works; either invoking the user's
// callback or true to just close the dialog
"onEscape": cb || true
});
};
that.success = function(/*str, label, cb*/) {
var str = "",
label = _translate('OK'),
cb = null;
switch (arguments.length) {
case 1:
// no callback, default button label
str = arguments[0];
break;
case 2:
// callback *or* custom button label dependent on type
str = arguments[0];
if (typeof arguments[1] == 'function') {
cb = arguments[1];
} else {
label = arguments[1];
}
break;
case 3:
// callback and custom button label
str = arguments[0];
label = arguments[1];
cb = arguments[2];
break;
default:
throw new Error("Incorrect number of arguments: expected 1-3");
}
// var info = '';
str = " ";
// alert(label);
return that.dialog(str, {
// only button (ok)
"label" : label,
"icon" : _icons.OK,
"class" : _btnClasses.OK,
"callback": cb
}, {
// ensure that the escape key works; either invoking the user's
// callback or true to just close the dialog
"onEscape": cb || true
});
};
that.error = function(/*str, label, cb*/) {
var str = str,
label = _translate('OK'),
cb = null;
switch (arguments.length) {
case 1:
// no callback, default button label
str = arguments[0];
break;
case 2:
// callback *or* custom button label dependent on type
str = arguments[0];
if (typeof arguments[1] == 'function') {
cb = arguments[1];
} else {
label = arguments[1];
}
break;
case 3:
// callback and custom button label
str = arguments[0];
label = arguments[1];
cb = arguments[2];
break;
default:
throw new Error("Incorrect number of arguments: expected 1-3");
}
// var info = '
';
str = " ";
return that.dialog(str, {
// only button (ok)
"label" : label,
"icon" : _icons.OK,
"class" : 'btn-danger',
"callback": cb
}, {
// ensure that the escape key works; either invoking the user's
// callback or true to just close the dialog
"onEscape": cb || true
});
};
that.confirm = function(/*str, labelCancel, labelOk, cb*/) {
var str = "",
labelCancel = _translate('CANCEL'),
labelOk = _translate('CONFIRM'),
cb = null;
switch (arguments.length) {
case 1:
str = arguments[0];
break;
case 2:
str = arguments[0];
if (typeof arguments[1] == 'function') {
cb = arguments[1];
} else {
labelCancel = arguments[1];
}
break;
case 3:
str = arguments[0];
labelCancel = arguments[1];
if (typeof arguments[2] == 'function') {
cb = arguments[2];
} else {
labelOk = arguments[2];
}
break;
case 4:
str = arguments[0];
labelCancel = arguments[1];
labelOk = arguments[2];
cb = arguments[3];
break;
default:
throw new Error("Incorrect number of arguments: expected 1-4");
}
var cancelCallback = function() {
if (typeof cb === 'function') {
return cb(false);
}
};
var confirmCallback = function() {
if (typeof cb === 'function') {
return cb(true);
}
};
return that.dialog(str, [{
// first button (cancel)
"label" : labelCancel,
"icon" : _icons.CANCEL,
"class" : _btnClasses.CANCEL,
"callback": cancelCallback
}, {
// second button (confirm)
"label" : labelOk,
"icon" : _icons.CONFIRM,
"class" : _btnClasses.CONFIRM,
"callback": confirmCallback
}], {
// escape key bindings
"onEscape": cancelCallback
});
};
that.prompt = function(/*str, labelCancel, labelOk, cb, defaultVal*/) {
var str = "",
labelCancel = _translate('CANCEL'),
labelOk = _translate('CONFIRM'),
cb = null,
defaultVal = "";
switch (arguments.length) {
case 1:
str = arguments[0];
break;
case 2:
str = arguments[0];
if (typeof arguments[1] == 'function') {
cb = arguments[1];
} else {
labelCancel = arguments[1];
}
break;
case 3:
str = arguments[0];
labelCancel = arguments[1];
if (typeof arguments[2] == 'function') {
cb = arguments[2];
} else {
labelOk = arguments[2];
}
break;
case 4:
str = arguments[0];
labelCancel = arguments[1];
labelOk = arguments[2];
cb = arguments[3];
break;
case 5:
str = arguments[0];
labelCancel = arguments[1];
labelOk = arguments[2];
cb = arguments[3];
defaultVal = arguments[4];
break;
default:
throw new Error("Incorrect number of arguments: expected 1-5");
}
var header = str;
// let's keep a reference to the form object for later
var form = $("