MediaWiki:Common.js

From John Bray Wiki
Revision as of 12:13, 8 March 2021 by John (talk | contribs)
Jump to navigation Jump to search

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. */

function filterImages () {
  var x = document.getElementsByClassName("image");
  var search = "";

  if(document.getElementById("imageinput") !== null && document.getElementById("imageinput").value !== null)
  {
    search = document.getElementById("imageinput").value;  
  } 

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

function filterImages1 () {
  var x = document.getElementsByClassName("image1");
  var search = "";

  if(document.getElementById("image1input") !== null && document.getElementById("image1input").value !== null)
  {
    search = document.getElementById("image1input").value;  
  } 

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


function filterDocuments () {
  var x = document.getElementsByClassName("document");
  var search = "";

  if(document.getElementById("documentinput") !== null && document.getElementById("documentinput").value !== null)
  {
    search = document.getElementById("documentinput").value;  
  } 

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

function filterTable() {
  var input, filter, table, tr, td, i, link, creator, year, notes, txtValue;
  input = document.getElementById("tableinput");
  filter = input.value.toUpperCase();
  table = document.getElementById("filtertable");
  tr = table.getElementsByTagName("tr");
  for (i = 0; i < tr.length; i++) {
    // match text in columns Link, Creator, Year, Notes
    title= tr[i].getElementsByTagName("td")[0];
    if (title) {
      link= tr[i].getElementsByTagName("td")[0];
      creator= tr[i].getElementsByTagName("td")[1];
      year= tr[i].getElementsByTagName("td")[2];  
      notes= tr[i].getElementsByTagName("td")[3];
      txtValue = link.textContent + creator.textContent + year.textContent + notes.textContent;
      if (txtValue.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    }
  }
}

function filterReferences() {
  var input, filter, table, tr, td, i, txtValue, reference, description, creator, date, notes;
  input = document.getElementById("referenceinput");
  filter = input.value.toUpperCase();
  table = document.getElementById("filterreferences");
  tr = table.getElementsByTagName("tr");
  for (i = 0; i < tr.length; i++) {
    // match text in columns Reference, Description, Creator, Date, Notes
    reference = tr[i].getElementsByTagName("td")[0];
    description = tr[i].getElementsByTagName("td")[1];
    creator = tr[i].getElementsByTagName("td")[2];
    date = tr[i].getElementsByTagName("td")[3];
    notes = tr[i].getElementsByTagName("td")[4];
    if (description) {
      txtValue = reference.textContent + description.textContent + creator.textContent + date.textContent + notes.textContent;
      if (txtValue.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    }
  }
}

$('#tablebox').html('<input type="text" id="tableinput" onkeyup="filterTable()" value="" placeholder="Filter..." title="Type in a name">');

$('#imagebox').html('<input type="text" id="imageinput" onkeyup="filterImages()" value="" placeholder="Filter..." title="Type in a name">');

$('#image1box').html('<input type="text" id="image1input" onkeyup="filterImages1()" value="" placeholder="Filter..." title="Type in a name1">');

$('#documentbox').html('<input type="text" id="documentinput" onkeyup="filterDocuments()" value="" placeholder="Filter..." title="Type in a name">');

$('#referencebox').html('<input type="text" id="referenceinput" onkeyup="filterReferences()" value="" placeholder="Filter..." title="Type in a name">');