MediaWiki

Common.js: Difference between revisions

From WhereToday

(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: function filterImages1 () { var x = document.getElementsByClassName("image1"); var input, filter; var text= ""; if (document.getElementById("image1input") !== null && document.getElementById("image1input").value !== null) { input = document.getElementById("image1input"); filter = input.value.toUpperCase(); if (filter.search("!") == 0) { filter="^((?!"+filter.sub...")
 
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


function filterAll () {
  var input, filter, td, i, description, keywords, txtValue;
  var map      = document.getElementsByClassName("leaflet-marker-icon");
  var objects  = document.getElementsByClassName("ObjectLine");
  var timeline  = document.getElementsByClassName("TimelineLine");
  var gallery  = document.getElementsByClassName("galleryline");
  var documents = document.getElementsByClassName("documentline");
  var table    = document.getElementById("Table");
  if (table)    {var tabletr = table.getElementsByTagName("tr")}


 
   if (document.getElementById("filterinput") !== null && document.getElementById("filterinput").value !== null)
 
function filterImages1 () {
  var x = document.getElementsByClassName("image1");
  var input, filter;
  var text= "";
 
   if (document.getElementById("image1input") !== null && document.getElementById("image1input").value !== null)
   {
   {
     input = document.getElementById("image1input");
     input = document.getElementById("filterinput");
     filter = input.value.toUpperCase();  
     filter = input.value.toUpperCase().replace("_"," ");
    filter1 = input.value.toUpperCase().replace(" ","_");
     if (filter.search("!") == 0) {
     if (filter.search("!") == 0) {
       filter="^((?!"+filter.substr(1)+").)*$";  
       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 < objects.length; i++) {
          if (objects[i].id.toUpperCase().search(filter1.substr(1)) == -1) {
            objects[i].style.display = 'inline-block';
          } else {
            objects[i].style.display = 'none';
          }
        }


  for (i = 0; i < x.length; i++) {
        for (i = 0; i < timeline.length; i++) {
    if (x[i].id.toUpperCase().search(filter) > -1) {
          if (timeline[i].id !== "" && timeline[i].id.toUpperCase().search(filter1.substr(1)) == -1) {
      x[i].style.display = '';
            timeline[i].style.opacity="1.0";
      text=x[i].innerHTML;
          } else {
      x[i].innerHTML = text.replace(/slideshowGroup:'exclude/,"slideshowGroup:'include");
            timeline[i].style.opacity="0.1";
    } else {
          }
      x[i].style.display = 'none';
        }
      text=x[i].innerHTML;
      x[i].innerHTML = text.replace(/slideshowGroup:'include/,"slideshowGroup:'exclude");
    }
  }
}


function filterMap () {
        for (i = 0; i < gallery.length; i++) {
  var x = document.getElementsByClassName("leaflet-marker-icon");  
          if (gallery[i].id.toUpperCase().search(filter.substr(1)) == -1) {
  var input, filter;
            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");
          }
        }


  if (document.getElementById("mapinput") !== null && document.getElementById("mapinput").value !== null)
        for (i = 0; i < documents.length; i++) {
  {
          if (documents[i].id.toUpperCase().search(filter.substr(1)) == -1) {
    input = document.getElementById("mapinput");
            documents[i].style.display = '';
    filter = input.value.toUpperCase();
            text=documents[i].innerHTML;
    if (filter.search("!") == 0) {
            documents[i].innerHTML = text.replace(/slideshowGroup:'exclude/,"slideshowGroup:'documents");
      filter="^((?!"+filter.substr(1)+").)*$";  
          } else {
    }  
            documents[i].style.display = 'none';
  }  
            text=documents[i].innerHTML;
 
            documents[i].innerHTML = text.replace(/slideshowGroup:'documents/,"slideshowGroup:'exclude");
  for (i = 0; i < x.length; i++) {
          }
    if (x[i].id !== "" && x[i].id.toUpperCase().search(filter) > -1) {
        }
      x[i].style.opacity="1.0";
     
        if (table) {
          for (i = 0; i < tabletr.length; i++) {
            // match text in four 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;
              if (txtValue.toUpperCase().search(filter.substr(1)) == -1) {
                tabletr[i].style.display = "";
              } else {
                tabletr[i].style.display = "none";
              }
            }
          }
        }
      }
     } else {
     } else {
       x[i].style.opacity="0.1";
       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 < objects.length; i++) {
        if (objects[i].id.toUpperCase().search(filter1) > -1) {
          objects[i].style.display = 'inline-block';
        } else {
          objects[i].style.display = 'none';
        }
      }


function filterDocuments () {
      for (i = 0; i < timeline.length; i++) {
  var x = document.getElementsByClassName("document");
        if (timeline[i].id !== "" && timeline[i].id.toUpperCase().search(filter1) > -1) {
  var input, filter;
          timeline[i].style.opacity="1.0";
        } else {
          timeline[i].style.opacity="0.1";
        }
      }


  if (document.getElementById("documentinput") !== null && document.getElementById("documentinput").value !== null)
       for (i = 0; i < gallery.length; i++) {
  {
        if (gallery[i].id.toUpperCase().search(filter) > -1) {
    input = document.getElementById("documentinput");
          gallery[i].style.display = '';
    filter = input.value.toUpperCase(); 
          text=gallery[i].innerHTML;
    if (filter.search("!") == 0) {
          gallery[i].innerHTML = text.replace(/slideshowGroup:'exclude/,"slideshowGroup:'gallery");
       filter="^((?!"+filter.substr(1)+").)*$";
        } else {
    }
          gallery[i].style.display = 'none';
  }
          text=gallery[i].innerHTML;
 
          gallery[i].innerHTML = text.replace(/slideshowGroup:'gallery/,"slideshowGroup:'exclude");
  for (i = 0; i < x.length; i++) {
        }
    if (txtValue.toUpperCase().search(filter) > -1) {
      }
      x[i].style.display = '';
    } else {
      x[i].style.display = 'none';
    }
  }
}


function filterShortTable() {
      for (i = 0; i < documents.length; i++) {
  var input, filter, table, tr, td, i, start, description, notes, txtValue;
        if (documents[i].id.toUpperCase().search(filter) > -1) {
  input = document.getElementById("shorttableinput");
          documents[i].style.display = '';
  filter = input.value.toUpperCase();
          text=documents[i].innerHTML;
  if (filter.search("!") == 0) {
          documents[i].innerHTML = text.replace(/slideshowGroup:'exclude/,"slideshowGroup:'documents");
    filter="^((?!"+filter.substr(1)+").)*$";
        } else {
  }
          documents[i].style.display = 'none';
  table = document.getElementById("shorttable");
          text=documents[i].innerHTML;
  tr = table.getElementsByTagName("tr");
          documents[i].innerHTML = text.replace(/slideshowGroup:'documents/,"slideshowGroup:'exclude");
  for (i = 0; i < tr.length; i++) {
        }
    // match text in three columns
    title= tr[i].getElementsByTagName("td")[0];
    if (title) {
      start      = tr[i].getElementsByTagName("td")[0];  
      description = tr[i].getElementsByTagName("td")[1];  
      notes      = tr[i].getElementsByTagName("td")[2];  
      txtValue = start.textContent + description.textContent + notes.textContent;
      if (txtValue.toUpperCase().search(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
       }
       }
    }
     
  }
      if (table) {
}
        for (i = 0; i < tabletr.length; i++) {
 
          // match text in four columns
function filterLongTable() {
          if (tabletr[i].getElementsByTagName("td")[0]) {
  var input, filter, table, tr, td, i, start, description, notes, txtValue;
            txtValue = tabletr[i].getElementsByTagName("td")[0].textContent
  input = document.getElementById("longtableinput");
                    + tabletr[i].getElementsByTagName("td")[1].textContent
  filter = input.value.toUpperCase();
                    + tabletr[i].getElementsByTagName("td")[2].textContent  
  if (filter.search("!") == 0) {
                    + tabletr[i].getElementsByTagName("td")[3].textContent;
    filter="^((?!"+filter.substr(1)+").)*$";
            if (txtValue !== "" && txtValue.toUpperCase().search(filter) > -1) {
  }
              tabletr[i].style.display = "";
  table = document.getElementById("longtable");
            } else {
  tr = table.getElementsByTagName("tr");
              tabletr[i].style.display = "none";
  for (i = 0; i < tr.length; i++) {
            }
    // match text in both columns
          }
    title= tr[i].getElementsByTagName("td")[0];
        }
    if (title) {
      start      = tr[i].getElementsByTagName("td")[0];
      description = tr[i].getElementsByTagName("td")[1];
      notes      = tr[i].getElementsByTagName("td")[2];
      txtValue = start.textContent + description.textContent + notes.textContent;
      if (txtValue.toUpperCase().search(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
       }
       }
     }
     }
   }
   }  
}
}


$('#shorttablebox').html('<input type="text" id="shorttableinput" onkeyup="filterShortTable()" value="" placeholder="Filter table" title="Type in a name">');
$('#filterbox').html('<input type="text" id="filterinput" onkeyup="filterAll()" value="" placeholder="Filter" title="Filter">');
 
$('#longtablebox').html('<input type="text" id="longtableinput" onkeyup="filterLongTable()" value="" placeholder="Filter table" title="Type in a name">');
 
$('#image1box').html('<input type="text" id="image1input" onkeyup="filterImages1()" value="" placeholder="Filter images" title="Type in a name1">');
 
$('#documentbox').html('<input type="text" id="documentinput" onkeyup="filterDocuments()" value="" placeholder="Filter documents" title="Type in a name">');
 
$('#mapbox').html('<input type="text" id="mapinput" onkeyup="filterMap()" value="" placeholder="Filter map" title="Type in a name">');

Revision as of 22:47, 4 February 2024

/* Any JavaScript here will be loaded for all users on every page load. */

function filterAll () {
  var input, filter, td, i, description, keywords, txtValue;
  var map       = document.getElementsByClassName("leaflet-marker-icon"); 
  var objects   = document.getElementsByClassName("ObjectLine");
  var timeline  = document.getElementsByClassName("TimelineLine"); 
  var gallery   = document.getElementsByClassName("galleryline");
  var documents = document.getElementsByClassName("documentline");
  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("_"," "); 
    filter1 = input.value.toUpperCase().replace(" ","_");  
    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 < objects.length; i++) {
          if (objects[i].id.toUpperCase().search(filter1.substr(1)) == -1) {
            objects[i].style.display = 'inline-block';
          } else {
            objects[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(filter.substr(1)) == -1) {
            documents[i].style.display = '';
            text=documents[i].innerHTML;
            documents[i].innerHTML = text.replace(/slideshowGroup:'exclude/,"slideshowGroup:'documents");
          } else {
            documents[i].style.display = 'none';
            text=documents[i].innerHTML;
            documents[i].innerHTML = text.replace(/slideshowGroup:'documents/,"slideshowGroup:'exclude");
          }
        }
      
        if (table) {
          for (i = 0; i < tabletr.length; i++) {
            // match text in four 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;
              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 < objects.length; i++) {
        if (objects[i].id.toUpperCase().search(filter1) > -1) {
          objects[i].style.display = 'inline-block';
        } else {
          objects[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(filter) > -1) {
          documents[i].style.display = '';
          text=documents[i].innerHTML;
          documents[i].innerHTML = text.replace(/slideshowGroup:'exclude/,"slideshowGroup:'documents");
        } else {
          documents[i].style.display = 'none';
          text=documents[i].innerHTML;
          documents[i].innerHTML = text.replace(/slideshowGroup:'documents/,"slideshowGroup:'exclude");
        }
      }
      
      if (table) {
        for (i = 0; i < tabletr.length; i++) {
          // match text in four 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;
            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">');