MediaWiki

MediaWiki:Common.js

From WhereToday

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

window.onload = function() {
  sortList("sortclasses","A");
};

function sortList(id,tag) {
  var list, i, seq, switching, b, shouldSwitch;
  list = document.getElementById(id);

  switching = true;
  /* Make a loop that will continue until
  no switching has been done: */
  while (switching) {
    // Start by saying: no switching is done:
    switching = false;
    b = list.getElementsByTagName(tag);
    // Loop through all list items:
    for (i = 0; i < (b.length - 1); i++) {
      // Start by saying there should be no switching:
      shouldSwitch = false;
      /* Check if the next item should
      switch place with the current item: */
      if (b[i].innerHTML.toLowerCase() > b[i + 1].innerHTML.toLowerCase()) { 
      /* if (b[i].id.toLowerCase() > b[i + 1].id.toLowerCase()) { */
        /* If next item is alphabetically lower than current item,
        mark as a switch and break the loop: */
        shouldSwitch = true;
        break;
      }
    }
    if (shouldSwitch) {
      /* If a switch has been marked, make the switch
      and mark the switch as done: */
      /* hard coded to <a href, not sure how to copy structure */
      t=b[i].innerHTML;
      b[i].innerHTML=b[i+1].innerHTML;
      b[i+1].innerHTML=t;
      t=b[i].href;
      b[i].href=b[i+1].href;
      b[i+1].href=t;
      t=b[i].title;
      b[i].title=b[i+1].title;
      b[i+1].title=t; 
      switching = true;
    }
  }
}

function filterAll () {
  var input, filter, td, i, description, keywords, txtValue;
  var map       = document.getElementsByClassName("leaflet-marker-icon"); 
  var items     = document.getElementsByClassName("ItemLine");
  var timeline  = document.getElementsByClassName("TimelineLine"); 
  var gallery   = document.getElementsByClassName("galleryline");
  var documents = document.getElementsByClassName("DocumentLine");
  var dplline   = document.getElementsByClassName("DPLLine");
  var table     = document.getElementById("Table");

  if (table) {var tabletr = table.getElementsByTagName("tr")}

  if (document.getElementById("filterinput") !== null && document.getElementById("filterinput").value !== null)
  {
    input = document.getElementById("filterinput");
    filter = input.value.toUpperCase().replace(/_/g," "); 
    filter1 = input.value.toUpperCase().replace(/ /g,"_");  
    if (filter.search("!") == 0) {
      if (filter.length > 1) {
        for (i = 0; i < map.length; i++) {
          if (map[i].id !== "" && map[i].id.toUpperCase().search(filter.substr(1)) == -1) {
            map[i].style.opacity="1.0";
          } else {
            map[i].style.opacity="0.05";
          }
        }
        for (i = 0; i < items.length; i++) {
          if (items[i].id.toUpperCase().search(filter1.substr(1)) == -1) {
            items[i].style.display = 'inline-block';
          } else {
            items[i].style.display = 'none';
          }
        }

        for (i = 0; i < timeline.length; i++) {
          if (timeline[i].id !== "" && timeline[i].id.toUpperCase().search(filter1.substr(1)) == -1) {
            timeline[i].style.opacity="1.0";
          } else {
            timeline[i].style.opacity="0.1";
          }
        }

        for (i = 0; i < gallery.length; i++) {
          if (gallery[i].id.toUpperCase().search(filter.substr(1)) == -1) {
            gallery[i].style.display = '';
            text=gallery[i].innerHTML;
            gallery[i].innerHTML = text.replace(/slideshowGroup:'exclude/,"slideshowGroup:'gallery");
          } else {
            gallery[i].style.display = 'none';
            text=gallery[i].innerHTML;
            gallery[i].innerHTML = text.replace(/slideshowGroup:'gallery/,"slideshowGroup:'exclude");
          }
        }

        for (i = 0; i < documents.length; i++) {
          if (documents[i].id.toUpperCase().search(filter1.substr(1)) == -1) {
            documents[i].style.display = '';
          } else {
            documents[i].style.display = 'none';
          }
        }
        for (i = 0; i < dplline.length; i++) {
          if (dplline[i].id.toUpperCase().search(filter.substr(1)) == -1) {
            dplline[i].style.display = '';
          } else {
            dplline[i].style.display = 'none';
          }
        }
      
        if (table) {
          for (i = 0; i < tabletr.length; i++) {
            // match text in all columns
            if (tabletr[i].getElementsByTagName("td")[0]) {
              txtValue = tabletr[i].getElementsByTagName("td")[0].textContent
                       + tabletr[i].getElementsByTagName("td")[1].textContent 
                       + tabletr[i].getElementsByTagName("td")[2].textContent 
                       + tabletr[i].getElementsByTagName("td")[3].textContent
                       + tabletr[i].getElementsByTagName("td")[4].textContent
                       + tabletr[i].getElementsByTagName("td")[5].textContent;
              if (txtValue.toUpperCase().search(filter.substr(1)) == -1) {
                tabletr[i].style.display = "";
              } else {
                tabletr[i].style.display = "none";
              }
            }
          }
        }
      }
    } else {
      for (i = 0; i < map.length; i++) {
        if (map[i].id !== "" && map[i].id.toUpperCase().search(filter) > -1) {
          map[i].style.opacity="1.0";
        } else {
          map[i].style.opacity="0.05";
        }
      }
      for (i = 0; i < items.length; i++) {
        if (items[i].id.toUpperCase().search(filter1) > -1) {
          items[i].style.display = 'inline-block';
        } else {
          items[i].style.display = 'none';
        }
       }

      for (i = 0; i < timeline.length; i++) {
        if (timeline[i].id !== "" && timeline[i].id.toUpperCase().search(filter1) > -1) {
          timeline[i].style.opacity="1.0";
        } else {
          timeline[i].style.opacity="0.1";
        }
      }

      for (i = 0; i < gallery.length; i++) {
        if (gallery[i].id.toUpperCase().search(filter) > -1) {
          gallery[i].style.display = '';
          text=gallery[i].innerHTML;
          gallery[i].innerHTML = text.replace(/slideshowGroup:'exclude/,"slideshowGroup:'gallery");
        } else {
          gallery[i].style.display = 'none';
          text=gallery[i].innerHTML;
          gallery[i].innerHTML = text.replace(/slideshowGroup:'gallery/,"slideshowGroup:'exclude");
        }
      }

      for (i = 0; i < documents.length; i++) {
        if (documents[i].id.toUpperCase().search(filter1) > -1) {
          documents[i].style.display = '';
        } else {
          documents[i].style.display = 'none';
        }
      }

      for (i = 0; i < dplline.length; i++) {
        if (dplline[i].id.toUpperCase().search(filter) > -1) {
          dplline[i].style.display = '';
        } else {
          dplline[i].style.display = 'none';
        }
      }
      
      if (table) {
        for (i = 0; i < tabletr.length; i++) {
          // match text in all columns
          if (tabletr[i].getElementsByTagName("td")[0]) {
            txtValue = tabletr[i].getElementsByTagName("td")[0].textContent
                     + tabletr[i].getElementsByTagName("td")[1].textContent 
                     + tabletr[i].getElementsByTagName("td")[2].textContent 
                     + tabletr[i].getElementsByTagName("td")[3].textContent
                     + tabletr[i].getElementsByTagName("td")[4].textContent
                     + tabletr[i].getElementsByTagName("td")[5].textContent;
            if (txtValue !== "" && txtValue.toUpperCase().search(filter) > -1) {
              tabletr[i].style.display = "";
            } else {
              tabletr[i].style.display = "none";
            }
          }
        }
      }
    }
  } 
}

$('#filterbox').html('<input type="text" id="filterinput" onkeyup="filterAll()" value="" placeholder="Filter" title="Filter">');