UiDialog.rebuild(id);
}
else if (method === 'option') {
- if (args.length === 3 && args[1] === 'title' && typeof args[2] === 'string') {
- UiDialog.setTitle(id, args[2]);
+ if (args.length === 3) {
+ if (args[1] === 'title' && typeof args[2] === 'string') {
+ UiDialog.setTitle(id, args[2]);
+ }
+ else if (args[1].indexOf('on') === 0) {
+ UiDialog.setCallback(id, args[1], args[2]);
+ }
+ else if (args[1] === 'closeConfirmMessage' && args[2] === null) {
+ UiDialog.setCallback(id, 'onBeforeClose', null);
+ }
}
}
else {
var _dialogFullHeight = false;
var _keyupListener = null;
var _staticDialogs = elByClass('jsStaticDialog');
+ var _validCallbacks = ['onBeforeClose', 'onClose', 'onShow'];
/**
* @exports WoltLabSuite/Core/Ui/Dialog
}
},
+ /**
+ * Sets a callback function on runtime.
+ *
+ * @param {(string|object)} id element id
+ * @param {string} key callback identifier
+ * @param {?function} value callback function or `null`
+ */
+ setCallback: function(id, key, value) {
+ if (typeof id === 'object') {
+ var dialogData = _dialogObjects.get(id);
+ if (dialogData !== undefined) {
+ id = dialogData.id;
+ }
+ }
+
+ var data = _dialogs.get(id);
+ if (data === undefined) {
+ throw new Error("Expected a valid dialog id, '" + id + "' does not match any active dialog.");
+ }
+
+ if (_validCallbacks.indexOf(key) === -1) {
+ throw new Error("Invalid callback identifier, '" + key + "' is not recognized.");
+ }
+
+ if (typeof value !== 'function' && value !== null) {
+ throw new Error("Only functions or the 'null' value are acceptable callback values ('" + typeof value+ "' given).");
+ }
+
+ data[key] = value;
+ },
+
/**
* Creates the DOM for a new dialog and opens it.
*