Commit 97bc659c authored by Karl's avatar Karl
Browse files

Man kann jetzt einen Suchfokus auch verändert abspeichern

parent 4b97de6d
...@@ -310,7 +310,9 @@ function productWidget() { ...@@ -310,7 +310,9 @@ function productWidget() {
} }
$(".lightSliderContainer").removeClass("hidden"); $(".lightSliderContainer").removeClass("hidden");
} }
/**
* Creates focus tab and tab selector for every stored focus in local storage
*/
function createCustomFocuses() { function createCustomFocuses() {
for (var key in localStorage) { for (var key in localStorage) {
if (key.startsWith("focus_")) { if (key.startsWith("focus_")) {
...@@ -324,23 +326,25 @@ function createCustomFocuses() { ...@@ -324,23 +326,25 @@ function createCustomFocuses() {
} }
} }
} }
/* /**
@if( $metager->getFokus() === "produktsuche" ) * Adds a focuses tab selector to the tab selector section
<li id="produktsucheTabSelector" class="active tab-selector" role="presentation" data-loaded="1"> *
<a aria-controls="produktsuche" data-href="#produktsuche" href="#produktsuche"> * @if( $metager->getFokus() === "produktsuche" )
<span class='glyphicon glyphicon-shopping-cart'></span> * <li id="produktsucheTabSelector" class="active tab-selector" role="presentation" data-loaded="1">
<span class="hidden-xs">{{ trans('index.foki.produkte') }}</span> * <a aria-controls="produktsuche" data-href="#produktsuche" href="#produktsuche">
</a> * <span class='glyphicon glyphicon-shopping-cart'></span>
</li> * <span class="hidden-xs">{{ trans('index.foki.produkte') }}</span>
@else * </a>
<li id="produktsucheTabSelector" class="tab-selector" role="presentation" data-loaded="0"> * </li>
<a aria-controls="produktsuche" data-href="{!! $metager->generateSearchLink('produktsuche') !!}" href="{!! $metager->generateSearchLink('produktsuche', false) !!}"> * @else
<span class='glyphicon glyphicon-shopping-cart'></span> * <li id="produktsucheTabSelector" class="tab-selector" role="presentation" data-loaded="0">
<span class="hidden-xs">{{ trans('index.foki.produkte') }}</span> * <a aria-controls="produktsuche" data-href="{!! $metager->generateSearchLink('produktsuche') !!}" href="{!! $metager->generateSearchLink('produktsuche', false) !!}">
</a> * <span class='glyphicon glyphicon-shopping-cart'></span>
</li> * <span class="hidden-xs">{{ trans('index.foki.produkte') }}</span>
@endif * </a>
*/ * </li>
* @endif
*/
function addFocus(focus, active = false) { function addFocus(focus, active = false) {
var id = getIdFromName(focus.name); var id = getIdFromName(focus.name);
var foki = document.getElementById("foki"); var foki = document.getElementById("foki");
...@@ -377,21 +381,23 @@ function addFocus(focus, active = false) { ...@@ -377,21 +381,23 @@ function addFocus(focus, active = false) {
focusElementLink.appendChild(focusElementIcon); focusElementLink.appendChild(focusElementIcon);
focusElementLink.appendChild(focusElementName); focusElementLink.appendChild(focusElementName);
} }
/* /**
@if( $metager->getFokus() === "produktsuche" ) * Adds a focuses tab to the tab section
<div role="tabpanel" class="tab-pane active" id="produktsuche"> *
<div class="row"> * @if( $metager->getFokus() === "produktsuche" )
@yield('results') * <div role="tabpanel" class="tab-pane active" id="produktsuche">
</div> * <div class="row">
</div> * @yield('results')
@else * </div>
<div role="tabpanel" class="tab-pane" id="produktsuche"> * </div>
<div class="loader"> * @else
<img src="/img/ajax-loader.gif" alt="" /> * <div role="tabpanel" class="tab-pane" id="produktsuche">
</div> * <div class="loader">
</div> * <img src="/img/ajax-loader.gif" alt="" />
@endif * </div>
*/ * </div>
* @endif
*/
function addTab(focus, active = false) { function addTab(focus, active = false) {
var id = getIdFromName(focus.name); var id = getIdFromName(focus.name);
// create tab div // create tab div
...@@ -415,15 +421,22 @@ function addTab(focus, active = false) { ...@@ -415,15 +421,22 @@ function addTab(focus, active = false) {
tabs.appendChild(tabPane) tabs.appendChild(tabPane)
tabPane.appendChild(row); tabPane.appendChild(row);
} }
/**
* Turns a name into an id
* Converts special characters and spaces
*/
function getIdFromName(name) { function getIdFromName(name) {
return "focus_" + name.split(" ").join("_").toLowerCase(); return "focus_" + name.split(" ").join("_").toLowerCase();
} }
/**
* Loads the focus object for the given id from local storage
*/
function loadFocusById(id) { function loadFocusById(id) {
return JSON.parse(localStorage.getItem(id)); return JSON.parse(localStorage.getItem(id));
} }
/**
* Gets the id of the currently active focus
*/
function getActiveFocusId() { function getActiveFocusId() {
var search = window.location.search; var search = window.location.search;
var from = search.indexOf("focus=") + "focus=".length; var from = search.indexOf("focus=") + "focus=".length;
...@@ -434,11 +447,14 @@ function getActiveFocusId() { ...@@ -434,11 +447,14 @@ function getActiveFocusId() {
id = search.substring(from, to); id = search.substring(from, to);
return id; 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? // TODO catch error if link is http://localhost:8000/meta/meta.ger3?
function generateSearchLinkForFocus(focus) { function generateSearchLinkForFocus(focus) {
var link = document.location.href; var link = document.location.href;
// remove old engine settings // 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) { while (link.indexOf("engine_") !== -1) {
var from = search.indexOf("engine_"); var from = search.indexOf("engine_");
...@@ -460,7 +476,9 @@ function generateSearchLinkForFocus(focus) { ...@@ -460,7 +476,9 @@ function generateSearchLinkForFocus(focus) {
link = replaceFocusInUrl(link); link = replaceFocusInUrl(link);
return link; return link;
} }
/**
* Replaces the focus in a given url with the "angepasst" focus
*/
function replaceFocusInUrl(url) { function replaceFocusInUrl(url) {
var from = url.indexOf("focus="); var from = url.indexOf("focus=");
var to = url.substring(from).indexOf("&") + from; var to = url.substring(from).indexOf("&") + from;
...@@ -470,7 +488,9 @@ function replaceFocusInUrl(url) { ...@@ -470,7 +488,9 @@ function replaceFocusInUrl(url) {
url = url.substring(0, from) + url.substring(to); url = url.substring(0, from) + url.substring(to);
return url + "&focus=angepasst"; return url + "&focus=angepasst";
} }
/**
* Loads the content for a given fokus
*/
function initialLoadContent(fokus) { function initialLoadContent(fokus) {
var link = $("#" + fokus + "TabSelector a").attr("data-href"); var link = $("#" + fokus + "TabSelector a").attr("data-href");
$.get(link, function(data) { $.get(link, function(data) {
......
...@@ -174,7 +174,9 @@ function isUseOnce() { ...@@ -174,7 +174,9 @@ function isUseOnce() {
return false; return false;
} }
} }
/**
* Loads all the custom focuses stored in local storage
*/
function loadInitialCustomFocuses() { function loadInitialCustomFocuses() {
for (var key in localStorage) { for (var key in localStorage) {
if (key.startsWith("focus_")) { if (key.startsWith("focus_")) {
...@@ -183,7 +185,10 @@ function loadInitialCustomFocuses() { ...@@ -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 = "") { function showFocusCreateDialog(id = "") {
document.getElementById("original-id").value = id; document.getElementById("original-id").value = id;
$("#create-focus-modal").modal("show"); $("#create-focus-modal").modal("show");
...@@ -206,17 +211,23 @@ function showFocusCreateDialog(id = "") { ...@@ -206,17 +211,23 @@ function showFocusCreateDialog(id = "") {
} }
} }
} }
/**
* Shows the focus create dialog for a given id
*/
function showFocusEditDialog(id) { function showFocusEditDialog(id) {
showFocusCreateDialog(id); showFocusCreateDialog(id);
} }
/**
* Save the current Focus
* Listens for save button
*/
function saveFocus() { function saveFocus() {
var name = document.getElementById("focus-name").value; var name = document.getElementById("focus-name").value;
if (isValidName(name) && atLeastOneChecked()) { if (isValidName(name) && atLeastOneChecked()) {
var oldId = document.getElementById("original-id").value;
var id = getIdFromName(name); var id = getIdFromName(name);
var overwrite = true; var overwrite = true;
if (alreadyInUse(name)) { if (alreadyInUse(name) && oldId !== id) {
overwrite = confirm("Name bereits genutzt\nüberschreiben?"); overwrite = confirm("Name bereits genutzt\nüberschreiben?");
if (overwrite) { if (overwrite) {
localStorage.removeItem(id); localStorage.removeItem(id);
...@@ -224,7 +235,6 @@ function saveFocus() { ...@@ -224,7 +235,6 @@ function saveFocus() {
} }
} }
if (overwrite) { if (overwrite) {
var oldId = document.getElementById("original-id").value;
var focus = {}; var focus = {};
$("input[type=checkbox]:checked").each(function(el) { $("input[type=checkbox]:checked").each(function(el) {
focus[$(this).attr("name")] = $(this).val(); focus[$(this).attr("name")] = $(this).val();
...@@ -242,37 +252,48 @@ function saveFocus() { ...@@ -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"); 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) { function isValidName(name) {
// no Characters other then a-z, A-Z, 0-9, ä, ö, ü, ß, -, _ allowed // no Characters other then a-z, A-Z, 0-9, ä, ö, ü, ß, -, _ allowed
// at least 1 character // at least 1 character
return /^[a-zA-Z0-9äöüß\-_ ]*$/.test(name); return /^[a-zA-Z0-9äöüß\-_ ]*$/.test(name);
} }
/**
* Is at least one focus selected?
*/
function atLeastOneChecked() { function atLeastOneChecked() {
return $("input[type=checkbox]:checked").length > 0; return $("input[type=checkbox]:checked").length > 0;
} }
/**
* Is there already a focus with this name?
*/
function alreadyInUse(name) { function alreadyInUse(name) {
return localStorage.hasOwnProperty(getIdFromName(name)); return localStorage.hasOwnProperty(getIdFromName(name));
} }
/**
function deleteFocus() { * Adds a focus html-element to the focus selection
var oldId = document.getElementById("original-id").value; *
localStorage.removeItem(oldId); * <input id="NAME" class="hide" type="radio" name="focus" value="NAME" form="searchForm" checked required>
removeFocusById(oldId); * <label id="NAME-label" for="NAME">
$("#create-focus-modal").modal("hide"); * <span class="glyphicon glyphicon-star"></span>
} * <span class="content">NAME</span>
/* * <button class="btn btn-default">
<input id="NAME" class="hide" type="radio" name="focus" value="NAME" form="searchForm" checked required> * <span class="glyphicon glyphicon-pencil"></span>
<label id="NAME-label" for="NAME"> * </button>
<span class="glyphicon glyphicon-star"></span> * </label>
<span class="content">NAME</span> */
<button class="btn btn-default">
<span class="glyphicon glyphicon-pencil"></span>
</button>
</label>
*/
function addFocus(name) { function addFocus(name) {
var id = getIdFromName(name); var id = getIdFromName(name);
var foki = document.getElementById("foki"); var foki = document.getElementById("foki");
...@@ -327,18 +348,25 @@ function addFocus(name) { ...@@ -327,18 +348,25 @@ function addFocus(name) {
wrapper.appendChild(newFocusEditLink); wrapper.appendChild(newFocusEditLink);
newFocusEditLink.appendChild(newFocusEditLinkGlyphicon); newFocusEditLink.appendChild(newFocusEditLinkGlyphicon);
} }
/**
* Remove the focuses html-elements
*/
function removeFocus(name) { function removeFocus(name) {
removeFocusById(getIdFromName(name)); removeFocusById(getIdFromName(name));
} }
/**
* Remove the focuses html-elements
*/
function removeFocusById(id) { function removeFocusById(id) {
var focusRadio = document.getElementById(id); var focusRadio = document.getElementById(id);
var focus = focusRadio.parentNode; var focus = focusRadio.parentNode;
var parent = focus.parentNode; var parent = focus.parentNode;
parent.removeChild(focus); parent.removeChild(focus);
} }
/**
* Turns a name into an id
* Converts special characters and spaces
*/
function getIdFromName(name) { function getIdFromName(name) {
name = name.toLowerCase(); name = name.toLowerCase();
name = name.split(" ").join("_"); name = name.split(" ").join("_");
...@@ -347,15 +375,21 @@ function getIdFromName(name) { ...@@ -347,15 +375,21 @@ function getIdFromName(name) {
name = name.split("ü").join("ue"); name = name.split("ü").join("ue");
return "focus_" + name; return "focus_" + name;
} }
/**
* Loads the focus object for the given id from local storage
*/
function loadFocusById(id) { function loadFocusById(id) {
return JSON.parse(localStorage.getItem(id)); return JSON.parse(localStorage.getItem(id));
} }
/**
* Unchecks all focuses from the focus creator dialog
*/
function uncheckAll() { function uncheckAll() {
$(".focusCheckbox").prop("checked", false); $(".focusCheckbox").prop("checked", false);
} }
/**
* Resets all settings
*/
function resetOptions() { function resetOptions() {
localStorage.removeItem("pers"); localStorage.removeItem("pers");
var keys = []; var keys = [];
......
{ {
"js/editLanguage.js": "js/editLanguage-7a1cbfb2ba.js", "js/editLanguage.js": "js/editLanguage-7a1cbfb2ba.js",
"js/kontakt.js": "js/kontakt-de49d68db3.js", "js/kontakt.js": "js/kontakt-de49d68db3.js",
"js/scriptResultPage.js": "js/scriptResultPage-1eb7e4a36b.js", "js/scriptResultPage.js": "js/scriptResultPage-95d76cf16b.js",
"js/scriptStartPage.js": "js/scriptStartPage-1d6e62e8c9.js", "js/scriptStartPage.js": "js/scriptStartPage-330e649107.js",
"js/settings.js": "js/settings-6ff0eab621.js", "js/settings.js": "js/settings-6ff0eab621.js",
"js/widgets.js": "js/widgets-866379dd63.js" "js/widgets.js": "js/widgets-866379dd63.js"
} }
\ No newline at end of file
This diff is collapsed.
...@@ -224,9 +224,10 @@ function showFocusEditDialog(id) { ...@@ -224,9 +224,10 @@ function showFocusEditDialog(id) {
function saveFocus() { function saveFocus() {
var name = document.getElementById("focus-name").value; var name = document.getElementById("focus-name").value;
if (isValidName(name) && atLeastOneChecked()) { if (isValidName(name) && atLeastOneChecked()) {
var oldId = document.getElementById("original-id").value;
var id = getIdFromName(name); var id = getIdFromName(name);
var overwrite = true; var overwrite = true;
if (alreadyInUse(name)) { if (alreadyInUse(name) && oldId !== id) {
overwrite = confirm("Name bereits genutzt\nüberschreiben?"); overwrite = confirm("Name bereits genutzt\nüberschreiben?");
if (overwrite) { if (overwrite) {
localStorage.removeItem(id); localStorage.removeItem(id);
...@@ -234,7 +235,6 @@ function saveFocus() { ...@@ -234,7 +235,6 @@ function saveFocus() {
} }
} }
if (overwrite) { if (overwrite) {
var oldId = document.getElementById("original-id").value;
var focus = {}; var focus = {};
$("input[type=checkbox]:checked").each(function(el) { $("input[type=checkbox]:checked").each(function(el) {
focus[$(this).attr("name")] = $(this).val(); focus[$(this).attr("name")] = $(this).val();
......
$(document).ready(function() {
$(".hint").tooltip();
$(".language-text-area").each(function() {
auto_grow(this);
});
$(".language-text-area").keyup(function() {
auto_grow(this);
});
});
function auto_grow(element) {
element.style.height = "5px";
element.style.height = (element.scrollHeight + 10) + "px";
}
\ No newline at end of file
//based on https://github.com/encrypt-to/secure.contactform.php
/* The MIT License (MIT)
Copyright (c) 2013 Jan Wiegelmann
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
function encrypt() {
if (window.crypto && window.crypto.getRandomValues) {
var message = document.getElementById("message");
if (message.value.indexOf("-----BEGIN PGP MESSAGE-----") !== -1 && message.value.indexOf("-----END PGP MESSAGE-----") !== -1) {
// encryption done
} else {
var pub_key = openpgp.key.readArmored(document.getElementById("pubkey").innerHTML).keys[0];
var plaintext = message.value;
var ciphertext = openpgp.encryptMessage([pub_key], plaintext);
message.value = ciphertext;
return true;
}
} else {
switch (getLanguage()) {
case "de":
alert("Fehler: Ihr Browser wird nicht unterstützt. Bitte installieren Sie einen aktuellen Browser wie z.B. Mozilla Firefox.");
break;
case "en":
alert("Error: Your browser is not supported. Please install an up to date browser like Mozilla Firefox.");
break;
case "es":
// alert(""); TODO
break;
}
return false;
}
}
$(document).ready(function() {
switch (getLanguage()) {
case "de":
$(".encrypt-btn").html("Verschlüsseln und senden");
break;
case "en":
$(".encrypt-btn").html("encrypt and send");
break;
case "es":
// $(".encrypt-btn").html(""); TODO
break;
}
$(".contact").submit(function() {
return encrypt(this);
});
});
function getLanguage() {
var metaData = document.getElementsByTagName('meta');
for (var m in metaData) {
if (metaData[m]["httpEquiv"] == "language") {
return metaData[m]["content"];
}
}
}
\ No newline at end of file
$(document).ready(function() {
getDocumentReadyForUse($("#foki > li.active > a").attr("aria-controls"));
$('iframe').iFrameResize();
botProtection();
});
function tabs() {
//return;
$("#foki > li.tab-selector > a").each(function() {
if($(this).attr("target") != "_blank") {
$(this).attr("href", "#" + $(this).attr("aria-controls"));
$(this).attr("role", "tab");
$(this).attr("data-toggle", "tab");
}
});
$("#foki > li.tab-selector > a").off();
$("#foki > li.tab-selector > a").on("show.bs.tab", function(e) {
var fokus = $(this).attr("aria-controls");
var link = $("#" + fokus + "TabSelector a").attr("data-href");
if ($("#" + fokus + "TabSelector").attr("data-loaded") != "1") {
$.get(link, function(data) {
$("#" + fokus + "TabSelector").attr("data-loaded", "1");
$("#" + fokus).html(data);
$("input[name=focus]").val($("#foki li.active a").attr("aria-controls"));
getDocumentReadyForUse(fokus);
});
} else {
getDocumentReadyForUse(fokus);
}
});
}
function getDocumentReadyForUse(fokus) {
clickLog();
popovers();