Commit a1298f7a authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Gespeicherte Ergebnisse sind nun auch von der Startseite aus erreichbar

Filter funktioniert nun case-insensitiv
Sortieren nach Hostname ist nun aufsteigend.
parent c53edf9a
......@@ -24,7 +24,9 @@ elixir(function (mix) {
*/
mix.scripts(['lib/jquery.js', 'lib/jquery-ui.min.js', 'lib/bootstrap.js', 'lib/lightslider.js', 'lib/masonry.js', 'lib/imagesloaded.js', 'lib/openpgp.min.js', 'lib/iframeResizer.min.js', 'lib/md5.js'], 'public/js/lib.js')
mix.scripts(['lib/jquery.js', 'lib/iframeResizer.contentWindow.min.js'], 'public/js/quicktips.js')
mix.version(['css/themes/default.css', 'js/lib.js', 'js/quicktips.js'])
mix.scripts(['scriptStartPage.js', 'results.js'], 'public/js/scriptStartPage.js');
mix.scripts(['scriptResultPage.js', 'results.js'], 'public/js/scriptResultPage.js');
mix.version(['css/themes/default.css', 'js/lib.js', 'js/quicktips.js']);
mix.less('metager/beitritt.less', 'public/css/beitritt.css')
mix.version(['css/beitritt.css'])
mix.version(['js/widgets.js', 'js/editLanguage.js', 'js/kontakt.js', 'js/scriptResultPage.js', 'js/scriptStartPage.js', 'js/settings.js'])
......
This diff is collapsed.
......@@ -5,7 +5,10 @@ $(document).ready(function () {
var custom = $('#foki > li.active').hasClass('custom-focus-tab-selector');
getDocumentReadyForUse(focus, custom);
botProtection();
new Results(); // Adds the saved Results if they are present
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");
}
});
function activateJSOnlyContent () {
......@@ -517,6 +520,22 @@ function initialLoadContent (fokus) {
});
}
function resultSaver(index) {
var title = $(".result[data-count=" + index + "] a.title").html();
var link = $(".result[data-count=" + index + "] a.title").attr("href");
var anzeigeLink = $(".result[data-count=" + index + "] div.link-link > a").html();
var gefVon = $(".result[data-count=" + index + "] span.hoster").html();
var hoster = $(".result[data-count=" + index + "] a.title").attr("data-hoster");
var anonym = $(".result[data-count=" + index + "] a.proxy").attr("href");
var description = $(".result[data-count=" + index + "] div.description").html();
var color = $(".result[data-count=" + index + "] div.number").css("color");
var rank = parseFloat($(".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");
$(".result[data-count=" + index + "]").transfer({to: to, duration: 1000});
new Results().updateResultPageInterface();
}
/*
* This object gathers all stored Result Objects and can Update the Interface to show them.
*/
......@@ -525,13 +544,12 @@ function Results(sort){
this.prefix = "result_";
this.results = [];
this.updateResults();
this.length = this.results.length;
this.sortResults(sort);
this.updateInterface(sort);
}
Results.prototype.sortResults = function(sortType){
if(sortType === undefined) sortType = "chronological";
console.log(this.results);
switch(sortType){
case "chronological":
this.results.sort(function(a,b){
......@@ -549,13 +567,12 @@ Results.prototype.sortResults = function(sortType){
break;
case "alphabetical":
this.results.sort(function(a,b){
if(a.hostname > b.hostname) return -1;
if(a.hostname < b.hostname) return 1;
if(b.hostname > a.hostname) return -1;
if(b.hostname < a.hostname) return 1;
return 0;
});
break;
}
console.log(this.results);
}
Results.prototype.updateResults = function(){
......@@ -584,7 +601,7 @@ Results.prototype.deleteResults = function(){
});
}
Results.prototype.updateInterface = function(sortType){
Results.prototype.updateResultPageInterface = function(sortType){
if(this.results.length === 0){
$("#savedFokiTabSelector, #savedFoki").remove();
$($("#foki > li[data-loaded=1]").get(0)).find(">a").tab("show");
......@@ -639,19 +656,19 @@ Results.prototype.addToContainer = function(container, sortType){
$(container).prepend(options);
$(options).find("select").change(function(){
new Results($(this).val());
new Results($(this).val()).updateResultPageInterface();
});
$(options).find("button").click({caller: this}, function(event){
event.data.caller.deleteResults();
new Results();
new Results().updateResultPageInterface();
});
$(options).find("input").keyup(function(){
var search = $(this).val();
$("#savedFoki > div.result").each(function(index, value){
var html = $(this).html();
if(html.indexOf(search) === -1){
if(html.toLowerCase().indexOf(search.toLowerCase()) === -1){
$(value).addClass("hidden");
}else{
$(value).removeClass("hidden");
......@@ -661,22 +678,6 @@ Results.prototype.addToContainer = function(container, sortType){
}
function resultSaver(index) {
var title = $(".result[data-count=" + index + "] a.title").html();
var link = $(".result[data-count=" + index + "] a.title").attr("href");
var anzeigeLink = $(".result[data-count=" + index + "] div.link-link > a").html();
var gefVon = $(".result[data-count=" + index + "] span.hoster").html();
var hoster = $(".result[data-count=" + index + "] a.title").attr("data-hoster");
var anonym = $(".result[data-count=" + index + "] a.proxy").attr("href");
var description = $(".result[data-count=" + index + "] div.description").html();
var color = $(".result[data-count=" + index + "] div.number").css("color");
var rank = parseFloat($(".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");
$(".result[data-count=" + index + "]").transfer({to: to, duration: 1000});
new Results();
}
function Result(title, link, anzeigeLink, gefVon, hoster, anonym, description, color, rank, hash){
this.prefix = "result_"; // Präfix for the localStorage so we can find all Items
......@@ -776,7 +777,7 @@ Result.prototype.setIndex = function(index){
Result.prototype.remove = function(){
localStorage.removeItem(this.prefix + this.hash);
new Results();
new Results().updateResultPageInterface();
}
Result.prototype.toHtml = function(){
......@@ -816,3 +817,4 @@ Result.prototype.toHtml = function(){
});
return result;
}
//# sourceMappingURL=scriptResultPage.js.map
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
{
"js/editLanguage.js": "js/editLanguage-86f3614c41.js",
"js/kontakt.js": "js/kontakt-31431155fb.js",
"js/scriptResultPage.js": "js/scriptResultPage-33313ea55e.js",
"js/scriptStartPage.js": "js/scriptStartPage-26e1d79535.js",
"js/scriptResultPage.js": "js/scriptResultPage-68fe1b7f6e.js",
"js/scriptStartPage.js": "js/scriptStartPage-5b6504d3a1.js",
"js/settings.js": "js/settings-e700ee9828.js",
"js/widgets.js": "js/widgets-858904fda2.js"
}
\ No newline at end of file
......@@ -7839,8 +7839,8 @@ footer a {
display: inline-block;
border-radius: 0px 7px 7px 0px;
}
.startpage-foki label span,
.foki label span {
.startpage-foki label span:not(.badge),
.foki label span:not(.badge) {
background-color: transparent;
}
.focus {
......
This diff is collapsed.
......@@ -5,7 +5,10 @@ $(document).ready(function () {
var custom = $('#foki > li.active').hasClass('custom-focus-tab-selector');
getDocumentReadyForUse(focus, custom);
botProtection();
new Results(); // Adds the saved Results if they are present
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");
}
});
function activateJSOnlyContent () {
......@@ -517,6 +520,22 @@ function initialLoadContent (fokus) {
});
}
function resultSaver(index) {
var title = $(".result[data-count=" + index + "] a.title").html();
var link = $(".result[data-count=" + index + "] a.title").attr("href");
var anzeigeLink = $(".result[data-count=" + index + "] div.link-link > a").html();
var gefVon = $(".result[data-count=" + index + "] span.hoster").html();
var hoster = $(".result[data-count=" + index + "] a.title").attr("data-hoster");
var anonym = $(".result[data-count=" + index + "] a.proxy").attr("href");
var description = $(".result[data-count=" + index + "] div.description").html();
var color = $(".result[data-count=" + index + "] div.number").css("color");
var rank = parseFloat($(".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");
$(".result[data-count=" + index + "]").transfer({to: to, duration: 1000});
new Results().updateResultPageInterface();
}
/*
* This object gathers all stored Result Objects and can Update the Interface to show them.
*/
......@@ -525,13 +544,12 @@ function Results(sort){
this.prefix = "result_";
this.results = [];
this.updateResults();
this.length = this.results.length;
this.sortResults(sort);
this.updateInterface(sort);
}
Results.prototype.sortResults = function(sortType){
if(sortType === undefined) sortType = "chronological";
console.log(this.results);
switch(sortType){
case "chronological":
this.results.sort(function(a,b){
......@@ -549,13 +567,12 @@ Results.prototype.sortResults = function(sortType){
break;
case "alphabetical":
this.results.sort(function(a,b){
if(a.hostname > b.hostname) return -1;
if(a.hostname < b.hostname) return 1;
if(b.hostname > a.hostname) return -1;
if(b.hostname < a.hostname) return 1;
return 0;
});
break;
}
console.log(this.results);
}
Results.prototype.updateResults = function(){
......@@ -584,7 +601,7 @@ Results.prototype.deleteResults = function(){
});
}
Results.prototype.updateInterface = function(sortType){
Results.prototype.updateResultPageInterface = function(sortType){
if(this.results.length === 0){
$("#savedFokiTabSelector, #savedFoki").remove();
$($("#foki > li[data-loaded=1]").get(0)).find(">a").tab("show");
......@@ -639,19 +656,19 @@ Results.prototype.addToContainer = function(container, sortType){
$(container).prepend(options);
$(options).find("select").change(function(){
new Results($(this).val());
new Results($(this).val()).updateResultPageInterface();
});
$(options).find("button").click({caller: this}, function(event){
event.data.caller.deleteResults();
new Results();
new Results().updateResultPageInterface();
});
$(options).find("input").keyup(function(){
var search = $(this).val();
$("#savedFoki > div.result").each(function(index, value){
var html = $(this).html();
if(html.indexOf(search) === -1){
if(html.toLowerCase().indexOf(search.toLowerCase()) === -1){
$(value).addClass("hidden");
}else{
$(value).removeClass("hidden");
......@@ -661,22 +678,6 @@ Results.prototype.addToContainer = function(container, sortType){
}
function resultSaver(index) {
var title = $(".result[data-count=" + index + "] a.title").html();
var link = $(".result[data-count=" + index + "] a.title").attr("href");
var anzeigeLink = $(".result[data-count=" + index + "] div.link-link > a").html();
var gefVon = $(".result[data-count=" + index + "] span.hoster").html();
var hoster = $(".result[data-count=" + index + "] a.title").attr("data-hoster");
var anonym = $(".result[data-count=" + index + "] a.proxy").attr("href");
var description = $(".result[data-count=" + index + "] div.description").html();
var color = $(".result[data-count=" + index + "] div.number").css("color");
var rank = parseFloat($(".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");
$(".result[data-count=" + index + "]").transfer({to: to, duration: 1000});
new Results();
}
function Result(title, link, anzeigeLink, gefVon, hoster, anonym, description, color, rank, hash){
this.prefix = "result_"; // Präfix for the localStorage so we can find all Items
......@@ -776,7 +777,7 @@ Result.prototype.setIndex = function(index){
Result.prototype.remove = function(){
localStorage.removeItem(this.prefix + this.hash);
new Results();
new Results().updateResultPageInterface();
}
Result.prototype.toHtml = function(){
......@@ -816,3 +817,4 @@ Result.prototype.toHtml = function(){
});
return result;
}
//# sourceMappingURL=scriptResultPage.js.map
This diff is collapsed.
......@@ -21,6 +21,7 @@ $(document).ready(function () {
}
setActionListeners();
loadInitialCustomFocuses();
loadSavedResults();
});
function setActionListeners () {
......@@ -428,3 +429,306 @@ function setFocusToDefault () {
function setFocus (focusID) {
$('#' + focusID).prop('checked', true);
}
function loadSavedResults() {
var results = new Results();
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="">\
<label id="saved-results-label" class="focus-label" for="savedResults">\
<span class="glyphicon glyphicon-floppy-disk"></span>\
<span class="content">gespeicherte Ergebnisse</span>\
<span class="badge">' + results.length + '</span>\
</label>\
</div>\
');
$("#addFocusBtnDiv").before(html);
$("#foki input#savedResults").change(function(){
if($(this).prop("checked")) $("#searchForm").submit();
});
}
}
/*
* This object gathers all stored Result Objects and can Update the Interface to show them.
*/
function Results(sort){
if(!localStorage) return;
this.prefix = "result_";
this.results = [];
this.updateResults();
this.length = this.results.length;
this.sortResults(sort);
}
Results.prototype.sortResults = function(sortType){
if(sortType === undefined) sortType = "chronological";
switch(sortType){
case "chronological":
this.results.sort(function(a,b){
if(a.added > b.added) return -1;
if(a.added < b.added) return 1;
return 0;
});
break;
case "rank":
this.results.sort(function(a,b){
if(a.rank > b.rank) return -1;
if(a.rank < b.rank) return 1;
return 0;
});
break;
case "alphabetical":
this.results.sort(function(a,b){
if(b.hostname > a.hostname) return -1;
if(b.hostname < a.hostname) return 1;
return 0;
});
break;
}
}
Results.prototype.updateResults = function(){
// Iterate over all Keys in the LocalStorage
for(var i = 0; i < localStorage.length; i++){
if(localStorage.key(i).indexOf(this.prefix) === 0){
var key = localStorage.key(i);
key = key.substr(this.prefix.length);
var tmpResult = new Result(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, key);
tmpResult.setIndex(i);
this.results.push(tmpResult);
}
}
}
Results.prototype.deleteResults = function(){
var keys = [];
for(var i = 0; i < localStorage.length; i++){
if(localStorage.key(i).indexOf(this.prefix) === 0){
var key = localStorage.key(i);
keys.push(key);
}
}
$.each(keys, function(index, value){
localStorage.removeItem(value);
});
}
Results.prototype.updateResultPageInterface = function(sortType){
if(this.results.length === 0){
$("#savedFokiTabSelector, #savedFoki").remove();
$($("#foki > li[data-loaded=1]").get(0)).find(">a").tab("show");
return;
}
if($("#savedFokiTabSelector").length === 0){
var savedFoki = $('\
<li id="savedFokiTabSelector" data-loaded="1" class="tab-selector" role="presentation">\
<a aria-controls="savedFoki" href="#savedFoki" role="tab" data-toggle="tab">\
<span class="glyphicon glyphicon-floppy-disk"></span> gespeicherte Ergebnisse\
<span class="badge">' + this.results.length + '</span>\
</a>\
</li>\
');
$("#foki").append(savedFoki);
}else{
$("#savedFokiTabSelector span.badge").html(this.results.length);
}
if($("#savedFoki").length === 0){
// Now append the Tab Panel
var tabPanel = $('\
<div role="tabpanel" class="tab-pane" id="savedFoki">\
</div>\
');
$("#main-content-tabs").append(tabPanel);
}else{
$("#savedFoki").html("");
var tabPanel = $("#savedFoki");
}
this.addToContainer(tabPanel, sortType);
}
Results.prototype.addToContainer = function(container, sortType){
$.each(this.results, function(index, result){
$(container).append(result.toHtml());
});
var options = $('\
<div class="saver-options row">\
<input class="form-control" type="text" placeholder="Filtern">\
<select class="form-control">\
<option value="chronological">Chronologisch</option>\
<option value="rank">MetaGer-Ranking</option>\
<option value="alphabetical">Alphabetisch (Hostname)</option>\
</select>\
<button class="btn btn-danger btn-md"><span class="glyphicon glyphicon-trash"></span> <span class="hidden-xs">Ergebnisse</span> löschen</button>\
</div>\
');
$(options).find("option[value=" + sortType + "]").prop("selected", true);
$(container).prepend(options);
$(options).find("select").change(function(){
new Results($(this).val()).updateResultPageInterface();
});
$(options).find("button").click({caller: this}, function(event){
event.data.caller.deleteResults();
new Results().updateResultPageInterface();
});
$(options).find("input").keyup(function(){
var search = $(this).val();
$("#savedFoki > div.result").each(function(index, value){
var html = $(this).html();
if(html.toLowerCase().indexOf(search.toLowerCase()) === -1){
$(value).addClass("hidden");
}else{
$(value).removeClass("hidden");
}
});
});
}
function Result(title, link, anzeigeLink, gefVon, hoster, anonym, description, color, rank, hash){
this.prefix = "result_"; // Präfix for the localStorage so we can find all Items
if(hash !== null && hash !== undefined){
this.hash = hash;
this.load();
}else{
this.hash = MD5(title + link + anzeigeLink + gefVon + hoster + anonym + description);
this.title = title;
this.link = link;
this.anzeigeLink = anzeigeLink;
this.gefVon = gefVon;
this.hoster = hoster;
this.anonym = anonym;
this.description = description;
this.color = color;
this.rank = rank;
this.added = new Date().getTime();
var parser = document.createElement('a');
parser.href = this.anzeigeLink;
this.hostname = parser.hostname;
this.save()
}
}
Result.prototype.load = function(){
if(localStorage){
var result = localStorage.getItem(this. prefix + this.hash);
if(result === null) return false;
result = b64DecodeUnicode(result);
result = JSON.parse(result);
this.title = result.title;
this.link = result.link;
this.anzeigeLink = result.anzeigeLink;
this.gefVon = result.gefVon;
this.hoster = result.hoster;
this.anonym = result.anonym;
this.description = result.description;
this.added = result.added;
this.color = result.color;
this.rank = result.rank;
this.hostname = result.hostname;
return true;
}else{
return false;
}
}
Result.prototype.save = function(){
/*
* This function will save the data of this Result to the LocalStorage
*/
if(localStorage){
var result = {
title: this.title,
link: this.link,
anzeigeLink: this.anzeigeLink,
gefVon: this.gefVon,
hoster: this.hoster,
anonym: this.anonym,
description: this.description,
added: this.added,
color: this.color,
rank: this.rank,
hostname: this.hostname
};
result = JSON.stringify(result);
result = b64EncodeUnicode(result);
localStorage.setItem(this.prefix + this.hash, result);
return true;
}else{
return false;
}
}
function b64EncodeUnicode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
return String.fromCharCode('0x' + p1);
}));
}
function b64DecodeUnicode(str) {
return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
Result.prototype.setIndex = function(index){
this.index = index;
}