From 227f84ee1ae388f2f665ba123ac6cb49f949799e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Tue, 12 Sep 2017 20:59:33 +0200 Subject: [PATCH] Options: bugfix, first save options, then reload; set var options before hook options_save; +docu --- README.md | 1 + src/language.js | 8 ++++---- src/options.js | 13 +++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) 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