Commit bc9854f7 authored by Karl Hasselbring's avatar Karl Hasselbring
Browse files

Refactoring: Globales results objekt hunzugefügt

parent aaceaa18
/**
* Global Results type element
*/
RESULTS_GLOBAL = null;
/**
* Returns the global results object,
* creates it if necessary
* @returns {Results} The global results object
*/
function results() {
if (!RESULTS_GLOBAL) {
RESULTS_GLOBAL = new Results();
}
return RESULTS_GLOBAL;
}
/** /**
* Load all saved results and sort them * Load all saved results and sort them
* @param {String} sort The type of sorting function to call for these results * @param {String} sort The type of sorting function to call for these results
*/ */
function Results (sort) { function Results () { //TODO remove sort
if (!localStorage) return false; if (!localStorage) return;
this.prefix = 'result_'; this.prefix = 'result_';
this.sort = sort; this.sort = 'chronological';
this.results = []; this.results = [];
this.loadAllResults(); this.loadAllResults();
this.length = this.results.length; this.length = this.results.length;
this.sortResults(); this.sortResults();
results = this;
} }
/** /**
...@@ -113,8 +132,6 @@ Results.prototype.updateResultPageInterface = function () { ...@@ -113,8 +132,6 @@ Results.prototype.updateResultPageInterface = function () {
* @param {HTML-Element} container The element to add the saved-results to * @param {HTML-Element} container The element to add the saved-results to
*/ */
Results.prototype.addToContainer = function (container) { Results.prototype.addToContainer = function (container) {
var results = this;
// Create the saver-options element, which is a bar containing // Create the saver-options element, which is a bar containing
// options for filtering, sorting and deleting all results // options for filtering, sorting and deleting all results
var options = $('\ var options = $('\
...@@ -146,14 +163,14 @@ Results.prototype.addToContainer = function (container) { ...@@ -146,14 +163,14 @@ Results.prototype.addToContainer = function (container) {
// When the sorting select value is changed, // When the sorting select value is changed,
// Sort all results with the selected sorting function and update their appearance // Sort all results with the selected sorting function and update their appearance
$(options).find('select').change(function () { $(options).find('select').change(function () {
results.sortResults($(this).val()).updateResultPageInterface(); results().sortResults($(this).val()).updateResultPageInterface();
}); });
// When the delete button is clicked, // When the delete button is clicked,
// Delete all results and update their appearance // Delete all results and update their appearance
$(options).find('#saver-options-delete-btn').click(function (event) { $(options).find('#saver-options-delete-btn').click(function (event) {
results.deleteAllResults(); results().deleteAllResults();
results.updateResultPageInterface(); results().updateResultPageInterface();
}); });
// When the user is done typing into the filter input field, // When the user is done typing into the filter input field,
...@@ -316,6 +333,7 @@ Result.prototype.remove = function () { ...@@ -316,6 +333,7 @@ Result.prototype.remove = function () {
/** /**
* Converts this result object into an html element * Converts this result object into an html element
* @returns {HTML-Element} The converted HTML-Element
*/ */
Result.prototype.toHtml = function () { Result.prototype.toHtml = function () {
// Create the saved-result element // Create the saved-result element
...@@ -376,10 +394,10 @@ function resultSaver (index) { ...@@ -376,10 +394,10 @@ function resultSaver (index) {
var description = $('.result[data-count=' + index + '] .result-description').html(); var description = $('.result[data-count=' + index + '] .result-description').html();
// Create the result object // Create the result object
new Result(title, link, anzeigeLink, gefVon, hoster, anonym, description, index, undefined); var result = new Result(title, link, anzeigeLink, gefVon, hoster, anonym, description, index, undefined);
// Update the saved results // Update the saved results
new Results().updateResultPageInterface(); results().updateResultPageInterface();
// Animate the result transfer to the saved results // Animate the result transfer to the saved results
var transferTarget = $('.saved-result[data-count=' + index + ']'); var transferTarget = $('.saved-result[data-count=' + index + ']');
......
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