Commit 4b97de6d authored by Karl's avatar Karl
Browse files

JS-Dateien sind kommentiert und alles aufgeräumt

parent df0ab925
......@@ -310,7 +310,9 @@ function productWidget() {
}
$(".lightSliderContainer").removeClass("hidden");
}
/**
* Creates focus tab and tab selector for every stored focus in local storage
*/
function createCustomFocuses() {
for (var key in localStorage) {
if (key.startsWith("focus_")) {
......@@ -324,23 +326,25 @@ function createCustomFocuses() {
}
}
}
/*
@if( $metager->getFokus() === "produktsuche" )
<li id="produktsucheTabSelector" class="active tab-selector" role="presentation" data-loaded="1">
<a aria-controls="produktsuche" data-href="#produktsuche" href="#produktsuche">
<span class='glyphicon glyphicon-shopping-cart'></span>
<span class="hidden-xs">{{ trans('index.foki.produkte') }}</span>
</a>
</li>
@else
<li id="produktsucheTabSelector" class="tab-selector" role="presentation" data-loaded="0">
<a aria-controls="produktsuche" data-href="{!! $metager->generateSearchLink('produktsuche') !!}" href="{!! $metager->generateSearchLink('produktsuche', false) !!}">
<span class='glyphicon glyphicon-shopping-cart'></span>
<span class="hidden-xs">{{ trans('index.foki.produkte') }}</span>
</a>
</li>
@endif
*/
/**
* Adds a focuses tab selector to the tab selector section
*
* @if( $metager->getFokus() === "produktsuche" )
* <li id="produktsucheTabSelector" class="active tab-selector" role="presentation" data-loaded="1">
* <a aria-controls="produktsuche" data-href="#produktsuche" href="#produktsuche">
* <span class='glyphicon glyphicon-shopping-cart'></span>
* <span class="hidden-xs">{{ trans('index.foki.produkte') }}</span>
* </a>
* </li>
* @else
* <li id="produktsucheTabSelector" class="tab-selector" role="presentation" data-loaded="0">
* <a aria-controls="produktsuche" data-href="{!! $metager->generateSearchLink('produktsuche') !!}" href="{!! $metager->generateSearchLink('produktsuche', false) !!}">
* <span class='glyphicon glyphicon-shopping-cart'></span>
* <span class="hidden-xs">{{ trans('index.foki.produkte') }}</span>
* </a>
* </li>
* @endif
*/
function addFocus(focus, active = false) {
var id = getIdFromName(focus.name);
var foki = document.getElementById("foki");
......@@ -377,21 +381,23 @@ function addFocus(focus, active = false) {
focusElementLink.appendChild(focusElementIcon);
focusElementLink.appendChild(focusElementName);
}
/*
@if( $metager->getFokus() === "produktsuche" )
<div role="tabpanel" class="tab-pane active" id="produktsuche">
<div class="row">
@yield('results')
</div>
</div>
@else
<div role="tabpanel" class="tab-pane" id="produktsuche">
<div class="loader">
<img src="/img/ajax-loader.gif" alt="" />
</div>
</div>
@endif
*/
/**
* Adds a focuses tab to the tab section
*
* @if( $metager->getFokus() === "produktsuche" )
* <div role="tabpanel" class="tab-pane active" id="produktsuche">
* <div class="row">
* @yield('results')
* </div>
* </div>
* @else
* <div role="tabpanel" class="tab-pane" id="produktsuche">
* <div class="loader">
* <img src="/img/ajax-loader.gif" alt="" />
* </div>
* </div>
* @endif
*/
function addTab(focus, active = false) {
var id = getIdFromName(focus.name);
// create tab div
......@@ -415,15 +421,22 @@ function addTab(focus, active = false) {
tabs.appendChild(tabPane)
tabPane.appendChild(row);
}
/**
* Turns a name into an id
* Converts special characters and spaces
*/
function getIdFromName(name) {
return "focus_" + name.split(" ").join("_").toLowerCase();
}
/**
* Loads the focus object for the given id from local storage
*/
function loadFocusById(id) {
return JSON.parse(localStorage.getItem(id));
}
/**
* Gets the id of the currently active focus
*/
function getActiveFocusId() {
var search = window.location.search;
var from = search.indexOf("focus=") + "focus=".length;
......@@ -434,11 +447,14 @@ function getActiveFocusId() {
id = search.substring(from, to);
return id;
}
/**
* Turns the link of the current page into a search link for the given focus
*/
// TODO catch error if link is http://localhost:8000/meta/meta.ger3?
function generateSearchLinkForFocus(focus) {
var link = document.location.href;
// remove old engine settings
// not yet tested
// not yet tested, only for compability problems with old versions of bookmarks and plugins
/*
while (link.indexOf("engine_") !== -1) {
var from = search.indexOf("engine_");
......@@ -460,7 +476,9 @@ function generateSearchLinkForFocus(focus) {
link = replaceFocusInUrl(link);
return link;
}
/**
* Replaces the focus in a given url with the "angepasst" focus
*/
function replaceFocusInUrl(url) {
var from = url.indexOf("focus=");
var to = url.substring(from).indexOf("&") + from;
......@@ -470,7 +488,9 @@ function replaceFocusInUrl(url) {
url = url.substring(0, from) + url.substring(to);
return url + "&focus=angepasst";
}
/**
* Loads the content for a given fokus
*/
function initialLoadContent(fokus) {
var link = $("#" + fokus + "TabSelector a").attr("data-href");
$.get(link, function(data) {
......
......@@ -174,7 +174,9 @@ function isUseOnce() {
return false;
}
}
/**
* Loads all the custom focuses stored in local storage
*/
function loadInitialCustomFocuses() {
for (var key in localStorage) {
if (key.startsWith("focus_")) {
......@@ -183,7 +185,10 @@ function loadInitialCustomFocuses() {
}
}
}
/**
* Shows the focus create dialog
* If an id is given it will try to load a focus for the given id
*/
function showFocusCreateDialog(id = "") {
document.getElementById("original-id").value = id;
$("#create-focus-modal").modal("show");
......@@ -206,11 +211,16 @@ function showFocusCreateDialog(id = "") {
}
}
}
/**
* Shows the focus create dialog for a given id
*/
function showFocusEditDialog(id) {
showFocusCreateDialog(id);
}
/**
* Save the current Focus
* Listens for save button
*/
function saveFocus() {
var name = document.getElementById("focus-name").value;
if (isValidName(name) && atLeastOneChecked()) {
......@@ -242,37 +252,48 @@ function saveFocus() {
alert("Bitte gültigen Namen eingeben:\n* Keine Sonderzeichen\n* Mindestens 1 Buchstabe\n* Mindestens 1 Suchmaschine auswählen");
}
}
/**
* Delete current Focus
* Listens for delete button
*/
function deleteFocus() {
var oldId = document.getElementById("original-id").value;
localStorage.removeItem(oldId);
removeFocusById(oldId);
$("#create-focus-modal").modal("hide");
}
/**
* Is the name valid (in terms of characters)?
*/
function isValidName(name) {
// no Characters other then a-z, A-Z, 0-9, ä, ö, ü, ß, -, _ allowed
// at least 1 character
return /^[a-zA-Z0-9äöüß\-_ ]*$/.test(name);
}
/**
* Is at least one focus selected?
*/
function atLeastOneChecked() {
return $("input[type=checkbox]:checked").length > 0;
}
/**
* Is there already a focus with this name?
*/
function alreadyInUse(name) {
return localStorage.hasOwnProperty(getIdFromName(name));
}
function deleteFocus() {
var oldId = document.getElementById("original-id").value;
localStorage.removeItem(oldId);
removeFocusById(oldId);
$("#create-focus-modal").modal("hide");
}
/*
<input id="NAME" class="hide" type="radio" name="focus" value="NAME" form="searchForm" checked required>
<label id="NAME-label" for="NAME">
<span class="glyphicon glyphicon-star"></span>
<span class="content">NAME</span>
<button class="btn btn-default">
<span class="glyphicon glyphicon-pencil"></span>
</button>
</label>
*/
/**
* Adds a focus html-element to the focus selection
*
* <input id="NAME" class="hide" type="radio" name="focus" value="NAME" form="searchForm" checked required>
* <label id="NAME-label" for="NAME">
* <span class="glyphicon glyphicon-star"></span>
* <span class="content">NAME</span>
* <button class="btn btn-default">
* <span class="glyphicon glyphicon-pencil"></span>
* </button>
* </label>
*/
function addFocus(name) {
var id = getIdFromName(name);
var foki = document.getElementById("foki");
......@@ -327,18 +348,25 @@ function addFocus(name) {
wrapper.appendChild(newFocusEditLink);
newFocusEditLink.appendChild(newFocusEditLinkGlyphicon);
}
/**
* Remove the focuses html-elements
*/
function removeFocus(name) {
removeFocusById(getIdFromName(name));
}
/**
* Remove the focuses html-elements
*/
function removeFocusById(id) {
var focusRadio = document.getElementById(id);
var focus = focusRadio.parentNode;
var parent = focus.parentNode;
parent.removeChild(focus);
}
/**
* Turns a name into an id
* Converts special characters and spaces
*/
function getIdFromName(name) {
name = name.toLowerCase();
name = name.split(" ").join("_");
......@@ -347,15 +375,21 @@ function getIdFromName(name) {
name = name.split("ü").join("ue");
return "focus_" + name;
}
/**
* Loads the focus object for the given id from local storage
*/
function loadFocusById(id) {
return JSON.parse(localStorage.getItem(id));
}
/**
* Unchecks all focuses from the focus creator dialog
*/
function uncheckAll() {
$(".focusCheckbox").prop("checked", false);
}
/**
* Resets all settings
*/
function resetOptions() {
localStorage.removeItem("pers");
var keys = [];
......
......@@ -7,9 +7,6 @@ return [
'foki.wissenschaft' => 'Wissenschaft',
'foki.produkte' => 'Produkte',
'foki.angepasst' => 'Angepasst',
'foki.eigene' => 'Eigene Suche',
'foki.eigene.entfernen' => 'Eigene Suche entfernen',
'foki.angepasst.entfernen' => 'Einstellungen zurücksetzen',
'foki.maps' => 'Maps.metager.de <span class="badge new-feature">Neu</span>',
'design' => 'Persönliches Design auswählen',
......
Markdown is supported
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