diff --git a/README.md b/README.md index af0edbb9..61dfe4a3 100644 --- a/README.md +++ b/README.md @@ -119,3 +119,4 @@ With the function `register_hook` you can hook into several functions. The follo * `state-get`: modules can add values into the current state. Parameters: `state`: an object, which can be modified by modules. * `state-apply`: when a state is applied to the app. Parameters: `state`: state which should be applied. * `show-details`: called when details are being displayed. Parameters: data (see properties in doc/TwigJS.md), category, dom, callback. +* `options_save`: called when options are saved. Parameters: options (the new object), old_options (before save) diff --git a/src/language.js b/src/language.js index e1c1185f..aaa651b0 100644 --- a/src/language.js +++ b/src/language.js @@ -111,10 +111,10 @@ register_hook('options_form', function (def) { } }) -register_hook('options_save', function (data) { - if ('data_lang' in data) { - if ('data_lang' in options && options.data_lang !== data.data_lang) { - tagTranslations.setTagLanguage(data.data_lang) +register_hook('options_save', function (options, old_options) { + if ('data_lang' in options) { + if (old_options.data_lang !== options.data_lang) { + tagTranslations.setTagLanguage(options.data_lang) baseCategory.recalc() } } diff --git a/src/options.js b/src/options.js index 84ed0932..59fc6e8c 100644 --- a/src/options.js +++ b/src/options.js @@ -59,16 +59,17 @@ moduleOptions.submit = function (optionsForm) { } } - if (reload) { - location.reload() - } - ajax('options_save', null, data, function (ret) { - call_hooks('options_save', data) - + old_options = options options = data document.getElementById('content').className = prevPage + + call_hooks('options_save', data, old_options) + + if (reload) { + location.reload() + } }) return false