scriptStartPage.js.map 28.7 KB
Newer Older
1
{"version":3,"sources":["scriptStartPage.js","results.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACncA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"scriptStartPage.js","sourcesContent":["$(document).ready(function () {\r\n  // checkPlugin()\r\n  if (location.href.indexOf('#plugin-modal') > -1) {\r\n    $('#plugin-modal').modal('show');\r\n  }\r\n  $('#addFocusBtn').removeClass('hide');\r\n  $('button').popover();\r\n  if (localStorage) {\r\n    var theme = localStorage.getItem('theme');\r\n    if (theme != null) {\r\n      if ((theme.match(/,/g) || []).length != 3) {\r\n        localStorage.removeItem('theme');\r\n      } else {\r\n        theme = theme.split(',');\r\n        $('#theme').attr('href', '/css/theme.css.php?r=' + theme[0] + '&g=' + theme[1] + '&b=' + theme[2] + '&a=' + theme[3]);\r\n      }\r\n    }\r\n    if (localStorage.getItem('pers') && !isUseOnce()) {\r\n      setSettings();\r\n    }\r\n  }\r\n  setActionListeners();\r\n  loadInitialCustomFocuses();\r\n  loadSavedResults();\r\n});\r\n\r\nfunction setActionListeners () {\r\n  $('button').on('shown.bs.popover', function () {\r\n    $('#color-chooser a').click(function () {\r\n      var theme = $(this).attr('data-rgba');\r\n      if (localStorage) {\r\n        localStorage.setItem('theme', theme);\r\n        location.href = '/';\r\n      }\r\n    });\r\n  });\r\n  $('#mobileFoki').change(function () {\r\n    var focus = $('#mobileFoki > option:selected').val();\r\n    if (focus == 'angepasst') {\r\n      window.location = './settings/';\r\n    } else {\r\n      window.location = './?focus=' + focus;\r\n    }\r\n  });\r\n  if ($('fieldset#foki.mobile').length) {\r\n    $('fieldset#foki.mobile label#anpassen-label').click(function () {\r\n      window.location = './settings/';\r\n    });\r\n  }\r\n  $('#addFocusBtn').click(function () {\r\n    showFocusCreateDialog('');\r\n  });\r\n  $('#save-focus-btn').click(saveFocus);\r\n  $('#delete-focus-btn').click(deleteFocus);\r\n  $('#focus-name').keyup(function (event) {\r\n    if (event.keyCode == 13) {\r\n      $('#save-focus-btn').click();\r\n    }\r\n  });\r\n  $('#create-focus-modal').on('shown.bs.modal', function () {\r\n    $('#focus-name').focus();\r\n  });\r\n}\r\n\r\nfunction setSettings () {\r\n  for (var i = 0; i < localStorage.length; i++) {\r\n    var key = localStorage.key(i);\r\n    var value = localStorage.getItem(key);\r\n    if (key.startsWith('param_') && !key.endsWith('lang') && !key.endsWith('autocomplete')) {\r\n      key = key.substring(key.indexOf('param_') + 6);\r\n      $('#searchForm').append('<input type=\"hidden\" name=\"' + key + '\" value=\"' + value + '\">');\r\n    }\r\n    $('#foki input[type=radio]#angepasst').attr('checked', true);\r\n  }\r\n  if (localStorage.getItem('param_lang') !== null) {\r\n    var value = localStorage.getItem('param_lang');\r\n    // Change the value of the lang input field to the given parameter\r\n    $('input[name=lang]').val(value);\r\n  }\r\n  if (localStorage.getItem('param_autocomplete') !== null) {\r\n    var value = localStorage.getItem('param_autocomplete');\r\n    // Change the value of the lang input field to the given parameter\r\n    $('input[name=eingabe]').attr('autocomplete', value);\r\n  }\r\n  if ($('fieldset#foki.mobile').length) {\r\n    $('fieldset.mobile input#bilder').val('angepasst');\r\n    $('fieldset.mobile input#bilder').prop('checked', true);\r\n    $('fieldset.mobile input#bilder').attr('id', 'angepasst');\r\n    $('fieldset.mobile label#bilder-label').attr('id', 'anpassen-label');\r\n    $('fieldset.mobile label#anpassen-label').attr('for', 'angepasst');\r\n    $('fieldset.mobile label#anpassen-label i.fa').attr('class', 'fa fa-cog');\r\n    $('fieldset.mobile label#anpassen-label span.content').html('angepasst');\r\n  }\r\n}\r\n// Polyfill for form attribute\r\n(function ($) {\r\n  /**\r\n   * polyfill for html5 form attr\r\n   */\r\n  // detect if browser supports this\r\n  var sampleElement = $('[form]').get(0);\r\n  var isIE11 = !(window.ActiveXObject) && 'ActiveXObject' in window;\r\n  if (sampleElement && window.HTMLFormElement && sampleElement.form instanceof HTMLFormElement && !isIE11) {\r\n    // browser supports it, no need to fix\r\n    return;\r\n  }\r\n  /**\r\n   * Append a field to a form\r\n   *\r\n   */\r\n  $.fn.appendField = function (data) {\r\n    // for form only\r\n    if (!this.is('form')) return;\r\n    // wrap data\r\n    if (!$.isArray(data) && data.name && data.value) {\r\n      data = [data];\r\n    }\r\n    var $form = this;\r\n    // attach new params\r\n    $.each(data, function (i, item) {\r\n      $('<input/>').attr('type', 'hidden').attr('name', item.name).val(item.value).appendTo($form);\r\n    });\r\n    return $form;\r\n  };\r\n  /**\r\n   * Find all input fields with form attribute point to jQuery object\r\n   * \r\n   */\r\n  $('form[id]').submit(function (e) {\r\n    var $form = $(this);\r\n    // serialize data\r\n    var data = $('[form=' + $form.attr('id') + ']').serializeArray();\r\n    // append data to form\r\n    $form.appendField(data);\r\n  }).each(function () {\r\n    var form = this,\r\n      $form = $(form),\r\n      $fields = $('[form=' + $form.attr('id') + ']');\r\n    $fields.filter('button, input').filter('[type=reset],[type=submit]').click(function () {\r\n      var type = this.type.toLowerCase();\r\n      if (type === 'reset') {\r\n        // reset form\r\n        form.reset();\r\n        // for elements outside form\r\n        $fields.each(function () {\r\n          this.value = this.defaultValue;\r\n          this.checked = this.defaultChecked;\r\n        }).filter('select').each(function () {\r\n          $(this).find('option').each(function () {\r\n            this.selected = this.defaultSelected;\r\n          });\r\n        });\r\n      } else if (type.match(/^submit|image$/i)) {\r\n        $(form).appendField({\r\n          name: this.name,\r\n          value: this.value\r\n        }).submit();\r\n      }\r\n    });\r\n  });\r\n})(jQuery);\r\n// Opera 8.0+\r\nvar isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;\r\n// Firefox 1.0+\r\nvar isFirefox = typeof InstallTrigger !== 'undefined';\r\n// At least Safari 3+: \"[object HTMLElementConstructor]\"\r\nvar isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;\r\n// Internet Explorer 6-11\r\nvar isIE = /*@cc_on!@*/ false || !!document.documentMode;\r\n// Edge 20+\r\nvar isEdge = !isIE && !!window.StyleMedia;\r\n// Chrome 1+\r\nvar isChrome = !!window.chrome && !!window.chrome.webstore;\r\n// Blink engine detection\r\nvar isBlink = (isChrome || isOpera) && !!window.CSS;\r\n// Prüft, ob der URL-Parameter \"usage\" auf \"once\" gesetzt ist.\r\nfunction isUseOnce () {\r\n  var url = document.location.search;\r\n  var pos = url.indexOf('usage=');\r\n  if (pos >= 0 && url.substring(pos + 6, pos + 11) == 'once') {\r\n    return true;\r\n  } else {\r\n    return false;\r\n  }\r\n}\r\n/**\r\n * Loads all the custom focuses stored in local storage\r\n */\r\nfunction loadInitialCustomFocuses () {\r\n  for (var key in localStorage) {\r\n    if (key.startsWith('focus_')) {\r\n      var focus = loadFocusById(key);\r\n      addFocus(focus.name);\r\n    }\r\n  }\r\n}\r\n/**\r\n * Shows the focus create dialog\r\n * If an id is given it will try to load a focus for the given id\r\n */\r\nfunction showFocusCreateDialog (id) {\r\n  if (id === undefined) {\r\n    id = '';\r\n  }\r\n  document.getElementById('original-id').value = id;\r\n  $('#create-focus-modal').modal('show');\r\n  var storedFocus = loadFocusById(id);\r\n  var focus = {};\r\n  // Try to load a focus for the given id\r\n  $('#focus-name').val('');\r\n  uncheckAll();\r\n  if (storedFocus !== null) {\r\n    try {\r\n      focus = JSON.parse(localStorage.getItem(id));\r\n      $('#focus-name').val(focus.name);\r\n      for (var key in focus) {\r\n        if (key.startsWith('engine_')) {\r\n          $('.focusCheckbox[name=' + key + ']').prop('checked', true);\r\n        }\r\n      }\r\n    } catch (ex) {\r\n      console.error(ex);\r\n    }\r\n  }\r\n}\r\n/**\r\n * Shows the focus create dialog for a given id\r\n */\r\nfunction showFocusEditDialog (id) {\r\n  showFocusCreateDialog(id);\r\n}\r\n/**\r\n * Save the current Focus\r\n * Listens for save button\r\n */\r\nfunction saveFocus () {\r\n  var name = document.getElementById('focus-name').value;\r\n  if (isValidName(name) && atLeastOneChecked()) {\r\n    var oldId = document.getElementById('original-id').value;\r\n    var id = getIdFromName(name);\r\n    var overwrite = true;\r\n    if (alreadyInUse(name) && oldId !== id) {\r\n      overwrite = confirm('Name bereits genutzt\\nüberschreiben?');\r\n      if (overwrite) {\r\n        localStorage.removeItem(id);\r\n        removeFocusById(id);\r\n      }\r\n    }\r\n    if (overwrite) {\r\n      var focus = {};\r\n      $('input[type=checkbox]:checked').each(function (el) {\r\n        focus[$(this).attr('name')] = $(this).val();\r\n      });\r\n      focus['name'] = name;\r\n      if (oldId !== '') {\r\n        localStorage.removeItem(oldId);\r\n        removeFocusById(oldId);\r\n      }\r\n      localStorage.setItem(id, JSON.stringify(focus));\r\n      addFocus(name);\r\n      $('#create-focus-modal').modal('hide');\r\n    }\r\n  } else {\r\n    alert('Bitte gültigen Namen eingeben:\\n* Keine Sonderzeichen\\n* Mindestens 1 Buchstabe\\n* Mindestens 1 Suchmaschine auswählen');\r\n  }\r\n}\r\n/**\r\n * Delete current Focus\r\n * Listens for delete button\r\n */\r\nfunction deleteFocus () {\r\n  var oldId = document.getElementById('original-id').value;\r\n  if ($('#' + oldId).prop('checked')) {\r\n    setFocusToDefault();\r\n  }\r\n  localStorage.removeItem(oldId);\r\n  removeFocusById(oldId);\r\n  $('#create-focus-modal').modal('hide');\r\n}\r\n/**\r\n * Is the name valid (in terms of characters)?\r\n */\r\nfunction isValidName (name) {\r\n  // no Characters other then a-z, A-Z, 0-9, ä, ö, ü, ß, -, _ allowed\r\n  // at least 1 character\r\n  return /^[a-zA-Z0-9äöüß\\-_ ]*$/.test(name);\r\n}\r\n/**\r\n * Is at least one focus selected?\r\n */\r\nfunction atLeastOneChecked () {\r\n  return $('input[type=checkbox]:checked').length > 0;\r\n}\r\n/**\r\n * Is there already a focus with this name?\r\n */\r\nfunction alreadyInUse (name) {\r\n  return localStorage.hasOwnProperty(getIdFromName(name));\r\n}\r\n/**\r\n * Adds a focus html-element to the focus selection\r\n * \r\n * <input id=\"NAME\" class=\"hide\" type=\"radio\" name=\"focus\" value=\"NAME\" form=\"searchForm\" checked required>\r\n * <label id=\"NAME-label\" for=\"NAME\">\r\n *     <i class=\"fa fa-star\" aria-hidden=\"true\"></i>\r\n *     <span class=\"content\">NAME</span>\r\n *     <button class=\"btn btn-default\">\r\n *         <i class=\"fa fa-pencil\" aria-hidden=\"true\"></i>\r\n *     </button>\r\n * </label>\r\n */\r\nfunction addFocus (name) {\r\n  var id = getIdFromName(name);\r\n  var foki = document.getElementById('foki');\r\n  // create <div> to wrap all Elements\r\n  var wrapper = document.createElement('div');\r\n  wrapper.classList.add('focus');\r\n  // create <input>\r\n  var newFocus = document.createElement('input');\r\n  newFocus.id = id;\r\n  newFocus.classList.add('focus-radio');\r\n  newFocus.classList.add('custom-focus');\r\n  newFocus.classList.add('hide');\r\n  newFocus.type = 'radio';\r\n  newFocus.name = 'focus';\r\n  newFocus.value = id;\r\n  newFocus.setAttribute('Form', 'searchForm');\r\n  newFocus.checked = true;\r\n  newFocus.required = true;\r\n  // create <label>\r\n  var newFocusLabel = document.createElement('label');\r\n  newFocusLabel.id = id + '-label';\r\n  newFocusLabel.classList.add('focus-label');\r\n  newFocusLabel.classList.add('custom-focus-label');\r\n  newFocusLabel.htmlFor = id;\r\n  // create <i> icon\r\n  var newFocusIcon = document.createElement('i');\r\n  newFocusIcon.classList.add('fa');\r\n  newFocusIcon.classList.add('fa-star');\r\n  newFocusIcon.setAttribute('aria-hidden', 'true');\r\n  // create content\r\n  var newFocusContent = document.createElement('span');\r\n  newFocusIcon.classList.add('content');\r\n  newFocusContent.textContent = ' ' + name;\r\n  // create edit button\r\n  var newFocusEditLink = document.createElement('a');\r\n  newFocusEditLink.classList.add('focus-edit');\r\n  newFocusEditLink.classList.add('custom-focus-edit');\r\n  newFocusEditLink.classList.add('mutelink');\r\n  newFocusEditLink.href = '#';\r\n  newFocusEditLink.onclick = function () {\r\n    showFocusEditDialog(id);\r\n  };\r\n  var newFocusEditLinkIcon = document.createElement('i');\r\n  newFocusEditLinkIcon.classList.add('fa');\r\n  newFocusEditLinkIcon.classList.add('fa-pencil');\r\n  newFocusEditLinkIcon.setAttribute('aria-hidden', 'true');\r\n  // add new elements\r\n  var addFocusBtn = document.getElementById('addFocusBtnDiv');\r\n  foki.insertBefore(wrapper, addFocusBtn);\r\n  wrapper.appendChild(newFocus);\r\n  wrapper.appendChild(newFocusLabel);\r\n  newFocusLabel.appendChild(newFocusIcon);\r\n  newFocusLabel.appendChild(newFocusContent);\r\n  wrapper.appendChild(newFocusEditLink);\r\n  newFocusEditLink.appendChild(newFocusEditLinkIcon);\r\n}\r\n/**\r\n * Remove the focuses html-elements\r\n */\r\nfunction removeFocus (name) {\r\n  removeFocusById(getIdFromName(name));\r\n}\r\n/**\r\n * Remove the focuses html-elements\r\n */\r\nfunction removeFocusById (id) {\r\n  var focusRadio = document.getElementById(id);\r\n  var focus = focusRadio.parentNode;\r\n  var parent = focus.parentNode;\r\n  parent.removeChild(focus);\r\n}\r\n/**\r\n * Turns a name into an id\r\n * Converts special characters and spaces\r\n */\r\nfunction getIdFromName (name) {\r\n  name = name.toLowerCase();\r\n  name = name.split(' ').join('_');\r\n  name = name.split('ä').join('ae');\r\n  name = name.split('ö').join('oe');\r\n  name = name.split('ü').join('ue');\r\n  return 'focus_' + name;\r\n}\r\n/**\r\n * Loads the focus object for the given id from local storage\r\n */\r\nfunction loadFocusById (id) {\r\n  return JSON.parse(localStorage.getItem(id));\r\n}\r\n/**\r\n * Unchecks all focuses from the focus creator dialog\r\n */\r\nfunction uncheckAll () {\r\n  $('.focusCheckbox').prop('checked', false);\r\n}\r\n/**\r\n * Resets all settings\r\n */\r\nfunction resetOptions () {\r\n  localStorage.removeItem('pers');\r\n  var keys = [];\r\n  for (var i = 0; i < localStorage.length; i++) {\r\n    var key = localStorage.key(i);\r\n    keys.push(key);\r\n  }\r\n  for (var i = 0; i < keys.length; i++) {\r\n    var key = keys[i];\r\n    if (key.startsWith('param_' || key.startsWith('focus'))) {\r\n      localStorage.removeItem(key);\r\n    }\r\n  }\r\n}\r\n\r\nfunction setFocusToDefault () {\r\n  setFocus('web');\r\n}\r\n\r\nfunction setFocus (focusID) {\r\n  $('#' + focusID).prop('checked', true);\r\n}\r\n\r\nfunction loadSavedResults() {\r\n  var results = new Results();\r\n  if(results.length > 0){\r\n    var html = $('\\\r\n    <div class=\"focus\">\\\r\n      <input id=\"savedResults\" class=\"focus-radio hide\" name=\"focus\" value=\"container\" form=\"searchForm\" type=\"radio\" required=\"\">\\\r\n      <label id=\"saved-results-label\" class=\"focus-label\" for=\"savedResults\">\\\r\n        <span class=\"glyphicon glyphicon-floppy-disk\"></span>\\\r\n        <span class=\"content\">gespeicherte Ergebnisse</span>\\\r\n        <span class=\"badge\">' + results.length + '</span>\\\r\n      </label>\\\r\n    </div>\\\r\n    ');\r\n    $(\"#addFocusBtnDiv\").before(html);\r\n    $(\"#foki input#savedResults\").change(function(){\r\n      if($(this).prop(\"checked\")) $(\"#searchForm\").submit();\r\n    });\r\n  }\r\n}\r\n","/*\r\n * This object gathers all stored Result Objects and can Update the Interface to show them.\r\n*/\r\nfunction Results(sort){\r\n  if(!localStorage) return;\r\n  this.prefix = \"result_\";\r\n  this.results = [];\r\n  this.updateResults();\r\n  this.length = this.results.length;\r\n  this.sortResults(sort);\r\n}\r\n\r\nResults.prototype.sortResults = function(sortType){\r\n  if(sortType === undefined) sortType = \"chronological\";\r\n  switch(sortType){\r\n    case \"chronological\":\r\n      this.results.sort(function(a,b){\r\n        if(a.added > b.added) return -1;\r\n        if(a.added < b.added) return 1;\r\n        return 0;\r\n      });\r\n      break;\r\n    case \"rank\":\r\n      this.results.sort(function(a,b){\r\n        if(a.rank > b.rank) return -1;\r\n        if(a.rank < b.rank) return 1;\r\n        return 0;\r\n      });\r\n      break;\r\n    case \"alphabetical\":\r\n      this.results.sort(function(a,b){\r\n        if(b.hostname > a.hostname) return -1;\r\n        if(b.hostname < a.hostname) return 1;\r\n        return 0;\r\n      });\r\n      break;\r\n  }\r\n}\r\n\r\nResults.prototype.updateResults = function(){\r\n  // Iterate over all Keys in the LocalStorage\r\n  for(var i = 0; i < localStorage.length; i++){\r\n    if(localStorage.key(i).indexOf(this.prefix) === 0){\r\n      var key = localStorage.key(i);\r\n      key = key.substr(this.prefix.length);\r\n      var tmpResult = new Result(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, key);\r\n      tmpResult.setIndex(i);\r\n      this.results.push(tmpResult);\r\n    }\r\n  }\r\n}\r\n\r\nResults.prototype.deleteResults = function(){\r\n  var keys = [];\r\n  for(var i = 0; i < localStorage.length; i++){\r\n    if(localStorage.key(i).indexOf(this.prefix) === 0){\r\n      var key = localStorage.key(i);\r\n      keys.push(key);\r\n    }\r\n  }\r\n  $.each(keys, function(index, value){\r\n    localStorage.removeItem(value);\r\n  });\r\n}\r\n\r\nResults.prototype.updateResultPageInterface = function(sortType){\r\n  if(this.results.length === 0){\r\n    $(\"#savedFokiTabSelector, #savedFoki\").remove();\r\n    $($(\"#foki > li[data-loaded=1]\").get(0)).find(\">a\").tab(\"show\");\r\n    return;\r\n  }\r\n  if($(\"#savedFokiTabSelector\").length === 0){\r\n    var savedFoki = $('\\\r\n      <li id=\"savedFokiTabSelector\" data-loaded=\"1\" class=\"tab-selector\" role=\"presentation\">\\\r\n        <a aria-controls=\"savedFoki\" href=\"#savedFoki\" role=\"tab\" data-toggle=\"tab\">\\\r\n          <span class=\"glyphicon glyphicon-floppy-disk\"></span> gespeicherte Ergebnisse\\\r\n          <span class=\"badge\">' + this.results.length + '</span>\\\r\n        </a>\\\r\n      </li>\\\r\n      ');\r\n    $(\"#foki\").append(savedFoki);\r\n  }else{\r\n    $(\"#savedFokiTabSelector span.badge\").html(this.results.length);\r\n  }\r\n    if($(\"#savedFoki\").length === 0){\r\n      // Now append the Tab Panel\r\n      var tabPanel = $('\\\r\n        <div role=\"tabpanel\" class=\"tab-pane\" id=\"savedFoki\">\\\r\n        </div>\\\r\n        ');\r\n      $(\"#main-content-tabs\").append(tabPanel);\r\n    }else{\r\n      $(\"#savedFoki\").html(\"\");\r\n      var tabPanel = $(\"#savedFoki\");\r\n    }\r\n    this.addToContainer(tabPanel, sortType);\r\n}\r\n\r\nResults.prototype.addToContainer = function(container, sortType){\r\n  $.each(this.results, function(index, result){\r\n    $(container).append(result.toHtml());\r\n  });\r\n\r\n  var options = $('\\\r\n      <div class=\"saver-options row\">\\\r\n          <input class=\"form-control\" type=\"text\" placeholder=\"Filtern\">\\\r\n          <select class=\"form-control\">\\\r\n            <option value=\"chronological\">Chronologisch</option>\\\r\n            <option value=\"rank\">MetaGer-Ranking</option>\\\r\n            <option value=\"alphabetical\">Alphabetisch (Hostname)</option>\\\r\n          </select>\\\r\n          <button class=\"btn btn-danger btn-md\"><span class=\"glyphicon glyphicon-trash\"></span> <span class=\"hidden-xs\">Ergebnisse</span> löschen</button>\\\r\n      </div>\\\r\n    ');\r\n\r\n  $(options).find(\"option[value=\" + sortType + \"]\").prop(\"selected\", true);\r\n\r\n  $(container).prepend(options);\r\n\r\n  $(options).find(\"select\").change(function(){\r\n    new Results($(this).val()).updateResultPageInterface();\r\n  });\r\n\r\n  $(options).find(\"button\").click({caller: this}, function(event){\r\n      event.data.caller.deleteResults();\r\n      new Results().updateResultPageInterface();\r\n  });\r\n\r\n  $(options).find(\"input\").keyup(function(){\r\n    var search = $(this).val();\r\n    $(\"#savedFoki > div.result\").each(function(index, value){\r\n      var html = $(this).html();\r\n      if(html.toLowerCase().indexOf(search.toLowerCase()) === -1){\r\n        $(value).addClass(\"hidden\");\r\n      }else{\r\n        $(value).removeClass(\"hidden\");\r\n      }\r\n    });\r\n  });\r\n\r\n}\r\n\r\nfunction Result(title, link, anzeigeLink, gefVon, hoster, anonym, description, color, rank, hash){\r\n  this.prefix = \"result_\";  // Präfix for the localStorage so we can find all Items\r\n\r\n  if(hash !== null && hash !== undefined){\r\n    this.hash = hash;\r\n    this.load();\r\n  }else{\r\n    this.hash = MD5(title + link + anzeigeLink + gefVon + hoster + anonym + description);\r\n\r\n    this.title = title;\r\n    this.link = link;\r\n    this.anzeigeLink = anzeigeLink;\r\n    this.gefVon = gefVon;\r\n    this.hoster = hoster;\r\n    this.anonym = anonym;\r\n    this.description = description;\r\n    this.color = color;\r\n    this.rank = rank;\r\n    this.added = new Date().getTime();\r\n    var parser = document.createElement('a');\r\n    parser.href = this.anzeigeLink;\r\n    this.hostname = parser.hostname;\r\n    this.save()\r\n  }\r\n}\r\n\r\nResult.prototype.load = function(){\r\n  if(localStorage){\r\n    var result = localStorage.getItem(this. prefix + this.hash);\r\n    if(result === null) return false;\r\n    result = b64DecodeUnicode(result);\r\n    result = JSON.parse(result);\r\n    this.title = result.title;\r\n    this.link = result.link;\r\n    this.anzeigeLink = result.anzeigeLink;\r\n    this.gefVon = result.gefVon;\r\n    this.hoster = result.hoster;\r\n    this.anonym = result.anonym;\r\n    this.description = result.description;\r\n    this.added = result.added;\r\n    this.color = result.color;\r\n    this.rank = result.rank;\r\n    this.hostname = result.hostname;\r\n    return true;\r\n  }else{\r\n    return false;\r\n  }\r\n}\r\n\r\nResult.prototype.save = function(){\r\n  /*\r\n  * This function will save the data of this Result to the LocalStorage\r\n  */\r\n  if(localStorage){\r\n\r\n    var result = {\r\n      title: this.title,\r\n      link: this.link,\r\n      anzeigeLink: this.anzeigeLink,\r\n      gefVon: this.gefVon,\r\n      hoster: this.hoster,\r\n      anonym: this.anonym,\r\n      description: this.description,\r\n      added: this.added,\r\n      color: this.color,\r\n      rank: this.rank,\r\n      hostname: this.hostname\r\n    };\r\n\r\n    result = JSON.stringify(result);\r\n    result = b64EncodeUnicode(result);\r\n\r\n    localStorage.setItem(this.prefix + this.hash, result);\r\n\r\n    return true;\r\n  }else{\r\n    return false;\r\n  }\r\n}\r\n\r\nfunction b64EncodeUnicode(str) {\r\n    return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {\r\n        return String.fromCharCode('0x' + p1);\r\n    }));\r\n}\r\n\r\nfunction b64DecodeUnicode(str) {\r\n    return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {\r\n        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);\r\n    }).join(''));\r\n}\r\n\r\n\r\nResult.prototype.setIndex = function(index){\r\n  this.index = index;\r\n}\r\n\r\nResult.prototype.remove = function(){\r\n  localStorage.removeItem(this.prefix + this.hash);\r\n  new Results().updateResultPageInterface();\r\n}\r\n\r\nResult.prototype.toHtml = function(){\r\n  var result = $('\\\r\n    <div class=\"result row\">\\\r\n      <div class=\"col-sm-1 glyphicon glyphicon-trash remover\" title=\"Ergebnis aus dem Speicher löschen\">\\\r\n      </div>\\\r\n      <div class=\"resultInformation col-xs-12 col-sm-11\">\\\r\n        <div class=\"col-xs-10 col-sm-11\" style=\"padding:0; \">\\\r\n          <p class=\"title\">\\\r\n            <a class=\"title\" href=\"' + this.link + '\" target=\"_blank\" data-hoster=\"' + this.hoster + '\" data-count=\"1\" rel=\"noopener\">\\\r\n              ' + this.title + '\\\r\n            </a>\\\r\n          </p>\\\r\n          <div class=\"link\">\\\r\n            <div>\\\r\n              <div class=\"link-link\">\\\r\n                <a href=\"' + this.link + '\" target=\"_blank\" data-hoster=\"' + this.hoster + '\" data-count=\"' + this.index + '\" rel=\"noopener\">\\\r\n                  ' + this.anzeigeLink + '\\\r\n                </a>\\\r\n            </div>\\\r\n          </div>\\\r\n          <span class=\"hoster\">\\\r\n            ' + this.gefVon + '\\\r\n          </span>\\\r\n          <a class=\"proxy\" onmouseover=\"$(this).popover(\\'show\\');\" onmouseout=\"$(this).popover(\\'hide\\');\" data-toggle=\"popover\" data-placement=\"auto right\" data-container=\"body\" data-content=\"Der Link wird anonymisiert geöffnet. Ihre Daten werden nicht zum Zielserver übertragen. Möglicherweise funktionieren manche Webseiten nicht wie gewohnt.\" href=\"' + this.proxy + '\" target=\"_blank\" rel=\"noopener\" data-original-title=\"\" title=\"\">\\\r\n            <img src=\"/img/proxyicon.png\" alt=\"\">\\\r\n            anonym öffnen\\\r\n          </a>\\\r\n        </div>\\\r\n      </div>\\\r\n      <div class=\"description\">' + this.description + '</div>\\\r\n      </div>\\\r\n    </div>');\r\n  $(result).find(\".remover\").click({caller: this}, function(event){\r\n    event.data.caller.remove();\r\n  });\r\n  return result;\r\n}"]}