From 609b75dbc4d58a8549cd349c0c08156196b7693a Mon Sep 17 00:00:00 2001 From: Karl Hasselbring <Karl Hasselbring> Date: Mon, 30 Oct 2017 08:35:37 +0100 Subject: [PATCH] =?UTF-8?q?Fixed:=20LocalStorage=20erg=C3=A4nzt=20jetzt=20?= =?UTF-8?q?gespeicherte=20Get-Parameter=20wenn=20nicht=20gesetzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/StartpageController.php | 27 ++++++++++++++------ resources/assets/js/scriptStartPage.js | 24 ++++++----------- resources/views/index.blade.php | 13 ++++------ 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/app/Http/Controllers/StartpageController.php b/app/Http/Controllers/StartpageController.php index 65cc6dab7..1eb1bfbff 100644 --- a/app/Http/Controllers/StartpageController.php +++ b/app/Http/Controllers/StartpageController.php @@ -22,8 +22,23 @@ class StartpageController extends Controller $focusPages = []; $theme = "default"; + $optionParams = ['param_sprueche', 'param_newtab', 'param_maps', 'param_autocomplete', 'param_lang', 'param_key']; + $option_values = []; + + foreach ($optionParams as $param) { + $value = $request->input($param); + if ($value) { + $option_values[$param] = $value; + } + } + + $autocomplete = 'on'; + if(in_array('autocomplete', array_keys($option_values))) { + $autocomplete = $option_values['autocomplete']; + } + foreach ($request->all() as $key => $value) { - if ($value === 'on' && $key != 'param_sprueche' && $key != 'param_newtab' && $key !== 'param_maps' && $key !== 'param_autocomplete' && $key !== 'param_lang') { + if ($value === 'on' && !in_array($key, $optionParams)) { $focusPages[] = str_replace('param_', '', $key); } if ($key === 'param_theme') { @@ -43,16 +58,12 @@ class StartpageController extends Controller ->with('browser', (new Agent())->browser()) ->with('navbarFocus', 'suche') ->with('theme', $theme) - ->with('autocomplete', $request->input('param_autocomplete', 'on')) ->with('foki', $this->loadFoki()) ->with('focus', $request->input('focus', 'web')) - ->with('lang', $request->input('param_lang', $lang)) - ->with('resultCount', $request->input('param_resultCount', '20')) ->with('time', $request->input('param_time', '1500')) - ->with('sprueche', $request->input('param_sprueche', 'on')) - ->with('newtab', $request->input('param_newtab', 'on')) - ->with('maps', $maps = $request->input('param_maps', 'off')) - ->with('key', $request->input('param_key', '')); + ->with('request', $request->input('request', 'GET')) + ->with('option_values', $option_values) + ->with('autocomplete', $autocomplete); } public function loadPage($subpage) diff --git a/resources/assets/js/scriptStartPage.js b/resources/assets/js/scriptStartPage.js index 071411f56..32893b828 100644 --- a/resources/assets/js/scriptStartPage.js +++ b/resources/assets/js/scriptStartPage.js @@ -28,9 +28,7 @@ function loadLocalStorage () { $('#theme').attr('href', '/css/theme.css.php?r=' + theme[0] + '&g=' + theme[1] + '&b=' + theme[2] + '&a=' + theme[3]); } } - if (localStorage.getItem('pers') && !isUseOnce()) { - setSettings(); - } + setSettings(); } } @@ -79,9 +77,9 @@ function setActionListeners () { * Loads stored settings from local storage */ function setSettings () { + var acceptedParams = ['autocomplete', 'key', 'lang', 'newtab', 'sprueche']; for (var key in localStorage) { var value = localStorage.getItem(key); - var acceptedParams = ['autocomplete', 'key', 'lang', 'maps', 'newtab', 'sprueche', 'autocomplete']; var accepted = false; for (var i in acceptedParams) { if (key === 'param_' + acceptedParams[i]) { @@ -90,19 +88,13 @@ function setSettings () { } if (accepted) { key = key.substring(6); - $('#searchForm').append('<input type="hidden" name="' + key + '" value="' + value + '">'); + // Check for existing hidden fields for this key + var existing = $('.search-hidden input[name="' + key + '"]'); + if (existing.length === 0) { + // if none exist, create a new one + $('.search-hidden').append('<input type="hidden" name="' + key + '" value="' + value + '">'); + } } - $('#foki input[type=radio]#angepasst').attr('checked', true); - } - // Change the value of the lang input field to the given parameter - var lang = localStorage.getItem('param_lang'); - if (lang !== null) { - $('input[name=lang]').val(lang); - } - // Change the value of the lang input field to the given parameter - var autocomplete = localStorage.getItem('param_autocomplete'); - if (autocomplete !== null) { - $('input[name=eingabe]').attr('autocomplete', autocomplete); } // Change the request method to the given parameter var requestMethod = localStorage.getItem('request'); diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index b7336e05b..940fc8307 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -263,7 +263,7 @@ </div> </div>--> <fieldset> - <form id="searchForm" @if(Request::has('request') && Request::input('request') === "POST") method="POST" @elseif(Request::has('request') && Request::input('request') === "GET") method="GET" @else method="GET" @endif action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/meta/meta.ger3") }}" accept-charset="UTF-8"> + <form id="searchForm" method={{ $request }} action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/meta/meta.ger3") }}" accept-charset="UTF-8"> <div class="search-bar"> <div class="search-focus-selector"> <select name="focus" style="font-family: FontAwesome, sans-serif;"> @@ -286,13 +286,10 @@ </div> <div class="search-hidden"> <input type="hidden" name="encoding" value="utf8"> - <input type="hidden" name="lang" value={{ $lang }} > - <input type="hidden" name="resultCount" value={{ $resultCount }} > - <input type="hidden" name="time" value={{ $time }} > - <input type="hidden" name="sprueche" value={{ $sprueche }} > - <input type="hidden" name="newtab" value={{ $newtab }} > - <input type="hidden" name="maps" value={{ $maps }} > - <input type="hidden" name="key" value={{ $key }} > + @foreach($option_values as $option => $value) + <input type="hidden" name={{ $option }} value={{ $value }}> + @endforeach + <input type="hidden" name="time" value={{ $time }}> @foreach ($focusPages as $fp) <input type="hidden" name={{ $fp }} value="on"> @endforeach -- GitLab