Commit 0a9c24b3 authored by Karl Hasselbring's avatar Karl Hasselbring
Browse files

Refactoring
parent 1dd8e610
......@@ -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();
}
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();
});
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment