MediaWiki:Common.js: Difference between revisions

From John Bray Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 57: Line 57:


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

Revision as of 12:13, 8 March 2021

/* 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">');