MediaWiki:Common.js

From John Bray Wiki
Revision as of 15:40, 1 April 2021 by John (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 filterRefs () {
  var x = document.getElementsByClassName("ref");
  var search = "";

  if (document.getElementById("refinput") !== null && document.getElementById("refinput").value !== null)
  {
    search = document.getElementById("refinput").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 filterRecognitions () {
  var x = document.getElementsByClassName("recognition");
  var search = "";

  if (document.getElementById("recognitioninput") !== null && document.getElementById("recognitioninput").value !== null)
  {
    search = document.getElementById("recognitioninput").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, type, link, creator, source,date, 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, Date, Notes
    title= tr[i].getElementsByTagName("td")[0];
    if (title) {
      type    = tr[i].getElementsByTagName("td")[0];
      link    = tr[i].getElementsByTagName("td")[1];
      creator = tr[i].getElementsByTagName("td")[2];
      source  = tr[i].getElementsByTagName("td")[3];
      date    = tr[i].getElementsByTagName("td")[4];  
      notes   = tr[i].getElementsByTagName("td")[6];
      txtValue = type.textContent + link.textContent + creator.textContent + source.textContent + date.textContent + notes.textContent;
      if (txtValue.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    }
  }
}

function filterWebsites() {
  var input, filter, table, tr, td, i, link, txtValue;
  input = document.getElementById("websiteinput");
  filter = input.value.toUpperCase();
  table = document.getElementById("filterwebsite");
  tr = table.getElementsByTagName("tr");
  for (i = 0; i < tr.length; i++) {
    // match text in columns Link, Creator, Date, Notes
    title= tr[i].getElementsByTagName("td")[0];
    if (title) {
      link= tr[i].getElementsByTagName("td")[0];
      txtValue = link.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">');

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

$('#imagebox').html('<input type="text" id="imageinput" onkeyup="filterImages()" value="" placeholder="Filter...0" 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">');

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

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