diff --git a/resources/assets/js/scriptResultPage.js b/resources/assets/js/scriptResultPage.js index 203f5ec4e3ec5010387720eaf60731324c430034..4c935c8c89bcc771593f445d2fe3eced7e9f0384 100644 --- a/resources/assets/js/scriptResultPage.js +++ b/resources/assets/js/scriptResultPage.js @@ -5,9 +5,9 @@ $(document).ready(function () { var custom = $('#foki > li.active').hasClass('custom-focus-tab-selector'); getDocumentReadyForUse(focus, custom); botProtection(); - new Results().updateResultPageInterface(); // Adds the saved Results if they are present - if(document.location.href.indexOf("focus=container") !== -1){ - $($("#foki > li#savedFokiTabSelector").get(0)).find(">a").tab("show"); + new Results().updateResultPageInterface(); // Adds the saved Results if they are present + if (document.location.href.indexOf('focus=container') !== -1) { + $($('#foki > li#savedFokiTabSelector').get(0)).find('>a').tab('show'); } }); @@ -70,8 +70,6 @@ function pluginInfo () { } } - - function theme () { if (localStorage) { var theme = localStorage.getItem('theme'); @@ -520,18 +518,18 @@ function initialLoadContent (fokus) { }); } -function resultSaver(index) { - var title = $("div.tab-pane.active .result[data-count=" + index + "] a.title").html(); - var link = $("div.tab-pane.active .result[data-count=" + index + "] a.title").attr("href"); - var anzeigeLink = $("div.tab-pane.active .result[data-count=" + index + "] div.link-link > a").html(); - var gefVon = $("div.tab-pane.active .result[data-count=" + index + "] span.hoster").html(); - var hoster = $("div.tab-pane.active .result[data-count=" + index + "] a.title").attr("data-hoster"); - var anonym = $("div.tab-pane.active .result[data-count=" + index + "] a.proxy").attr("href"); - var description = $("div.tab-pane.active .result[data-count=" + index + "] div.description").html(); - var color = $("div.tab-pane.active .result[data-count=" + index + "] div.number").css("color"); - var rank = parseFloat($("div.tab-pane.active .result[data-count=" + index + "]").attr("data-rank")); +function resultSaver (index) { + var title = $('div.tab-pane.active .result[data-count=' + index + '] a.title').html(); + var link = $('div.tab-pane.active .result[data-count=' + index + '] a.title').attr('href'); + var anzeigeLink = $('div.tab-pane.active .result[data-count=' + index + '] div.link-link > a').html(); + var gefVon = $('div.tab-pane.active .result[data-count=' + index + '] span.hoster').html(); + var hoster = $('div.tab-pane.active .result[data-count=' + index + '] a.title').attr('data-hoster'); + var anonym = $('div.tab-pane.active .result[data-count=' + index + '] a.proxy').attr('href'); + var description = $('div.tab-pane.active .result[data-count=' + index + '] div.description').html(); + var color = $('div.tab-pane.active .result[data-count=' + index + '] div.number').css('color'); + var rank = parseFloat($('div.tab-pane.active .result[data-count=' + index + ']').attr('data-rank')); new Result(title, link, anzeigeLink, gefVon, hoster, anonym, description, color, rank, undefined); - var to = $("#savedFokiTabSelector").length ? $("#savedFokiTabSelector") : $("#foki"); - $("div.tab-pane.active .result[data-count=" + index + "]").transfer({to: to, duration: 1000}); + var to = $('#savedFokiTabSelector').length ? $('#savedFokiTabSelector') : $('#foki'); + $('div.tab-pane.active .result[data-count=' + index + ']').transfer({to: to, duration: 1000}); new Results().updateResultPageInterface(); } diff --git a/resources/assets/js/scriptStartPage.js b/resources/assets/js/scriptStartPage.js index d9c1c762619277b02694e2f174362dfd79d27164..77130f495497108d4efc76656ed7186954e9660b 100644 --- a/resources/assets/js/scriptStartPage.js +++ b/resources/assets/js/scriptStartPage.js @@ -1,3 +1,5 @@ +const DEFAULT_FOCUS = 'web'; + $(document).ready(function () { // checkPlugin() if (location.href.indexOf('#plugin-modal') > -1) { @@ -5,6 +7,17 @@ $(document).ready(function () { } $('#addFocusBtn').removeClass('hide'); $('button').popover(); + + loadLocalStorage(); + setActionListeners(); + loadInitialCustomFocuses(); + loadSavedResults(); +}); + +/** + * Loads the user theme and stored settings from local storage + */ +function loadLocalStorage () { if (localStorage) { var theme = localStorage.getItem('theme'); if (theme != null) { @@ -19,11 +32,11 @@ $(document).ready(function () { setSettings(); } } - setActionListeners(); - loadInitialCustomFocuses(); - loadSavedResults(); -}); +} +/** + * Sets all action listeners for this page + */ function setActionListeners () { $('button').on('shown.bs.popover', function () { $('#color-chooser a').click(function () { @@ -47,11 +60,10 @@ function setActionListeners () { window.location = './settings/'; }); } - $('#addFocusBtn').click(function () { - showFocusCreateDialog(''); - }); + $('#addFocusBtn').click(() => showFocusCreateDialog('')); $('#save-focus-btn').click(saveFocus); $('#delete-focus-btn').click(deleteFocus); + // Save Focus on clicking enter while in the focus name input $('#focus-name').keyup(function (event) { if (event.keyCode == 13) { $('#save-focus-btn').click(); @@ -62,9 +74,11 @@ function setActionListeners () { }); } +/** + * Loads stored settings from local storage + */ function setSettings () { - for (var i = 0; i < localStorage.length; i++) { - var key = localStorage.key(i); + for (var key in localStorage) { var value = localStorage.getItem(key); if (key.startsWith('param_') && !key.endsWith('lang') && !key.endsWith('autocomplete')) { key = key.substring(key.indexOf('param_') + 6); @@ -72,15 +86,15 @@ function setSettings () { } $('#foki input[type=radio]#angepasst').attr('checked', true); } - if (localStorage.getItem('param_lang') !== null) { - var value = localStorage.getItem('param_lang'); - // Change the value of the lang input field to the given parameter - $('input[name=lang]').val(value); + // 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); } - if (localStorage.getItem('param_autocomplete') !== null) { - var value = localStorage.getItem('param_autocomplete'); - // Change the value of the lang input field to the given parameter - $('input[name=eingabe]').attr('autocomplete', value); + // 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); } if ($('fieldset#foki.mobile').length) { $('fieldset.mobile input#bilder').val('angepasst'); @@ -422,17 +436,24 @@ function resetOptions () { } } +/** + * Sets the selected focus to default + */ function setFocusToDefault () { - setFocus('web'); + setFocus(DEFAULT_FOCUS); } +/** + * Sets the selected focus + * @param {String} focusID The id of the focus, without # + */ function setFocus (focusID) { $('#' + focusID).prop('checked', true); } -function loadSavedResults() { +function loadSavedResults () { var results = new Results(); - if(results.length > 0){ + if (results.length > 0) { var html = $('\ <div class="focus">\ <input id="savedResults" class="focus-radio hide" name="focus" value="container" form="searchForm" type="radio" required="">\ @@ -443,9 +464,9 @@ function loadSavedResults() { </label>\ </div>\ '); - $("#addFocusBtnDiv").before(html); - $("#foki input#savedResults").change(function(){ - if($(this).prop("checked")) $("#searchForm").submit(); + $('#addFocusBtnDiv').before(html); + $('#foki input#savedResults').change(function () { + if ($(this).prop('checked')) $('#searchForm').submit(); }); } }