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
 
(One intermediate revision by the same user not shown)
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. */


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


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


 
   switching = true;
function filterImages1 () {
   /* Make a loop that will continue until
   var x = document.getElementsByClassName("image1");
   no switching has been done: */
   var input, filter;
   while (switching) {
   var text= "";
     // Start by saying: no switching is done:
 
     switching = false;
   if (document.getElementById("image1input") !== null && document.getElementById("image1input").value !== null)
     b = list.getElementsByTagName(tag);
  {
     // Loop through all list items:
     input = document.getElementById("image1input");
    for (i = 0; i < (b.length - 1); i++) {
     filter = input.value.toUpperCase();  
      // Start by saying there should be no switching:
     if (filter.search("!") == 0) {
      shouldSwitch = false;
      filter="^((?!"+filter.substr(1)+").)*$";  
      /* 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()) { */
  for (i = 0; i < x.length; i++) {
        /* If next item is alphabetically lower than current item,
    if (x[i].id.toUpperCase().search(filter) > -1) {
        mark as a switch and break the loop: */
       x[i].style.display = '';
        shouldSwitch = true;
       text=x[i].innerHTML;
        break;
       x[i].innerHTML = text.replace(/slideshowGroup:'exclude/,"slideshowGroup:'include");
       }
    } else {
    }
       x[i].style.display = 'none';
    if (shouldSwitch) {
       text=x[i].innerHTML;
      /* If a switch has been marked, make the switch
       x[i].innerHTML = text.replace(/slideshowGroup:'include/,"slideshowGroup:'exclude");
      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 filterMap () {
function filterAll () {
   var x = document.getElementsByClassName("leaflet-marker-icon");  
   var input, filter, td, i, description, keywords, txtValue;
   var input, filter;
  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("mapinput") !== null && document.getElementById("mapinput").value !== null)
   if (document.getElementById("filterinput") !== null && document.getElementById("filterinput").value !== null)
   {
   {
     input = document.getElementById("mapinput");
     input = document.getElementById("filterinput");
     filter = input.value.toUpperCase();   
     filter = input.value.toUpperCase().replace(/_/g," ");
    filter1 = input.value.toUpperCase().replace(/ /g,"_");   
     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";
  for (i = 0; i < x.length; i++) {
          } else {
    if (x[i].id !== "" && x[i].id.toUpperCase().search(filter) > -1) {
            map[i].style.opacity="0.05";
      x[i].style.opacity="1.0";
          }
    } else {
        }
      x[i].style.opacity="0.1";
        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';
          }
        }


function filterDocuments () {
        for (i = 0; i < timeline.length; i++) {
  var x = document.getElementsByClassName("document");
          if (timeline[i].id !== "" && timeline[i].id.toUpperCase().search(filter1.substr(1)) == -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.substr(1)) == -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++) {
        for (i = 0; i < documents.length; i++) {
    if (txtValue.toUpperCase().search(filter) > -1) {
          if (documents[i].id.toUpperCase().search(filter1.substr(1)) == -1) {
      x[i].style.display = '';
            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 {
     } else {
       x[i].style.display = 'none';
       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");
        }
      }


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(filter1) > -1) {
  input = document.getElementById("shorttableinput");
          documents[i].style.display = '';
  filter = input.value.toUpperCase();
        } else {
  if (filter.search("!") == 0) {
          documents[i].style.display = 'none';
    filter="^((?!"+filter.substr(1)+").)*$";
        }
  }
  table = document.getElementById("shorttable");
  tr = table.getElementsByTagName("tr");
  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";
       }
       }
    }
  }
}


function filterLongTable() {
      for (i = 0; i < dplline.length; i++) {
  var input, filter, table, tr, td, i, start, description, notes, txtValue;
        if (dplline[i].id.toUpperCase().search(filter) > -1) {
  input = document.getElementById("longtableinput");
          dplline[i].style.display = '';
  filter = input.value.toUpperCase();
        } else {
  if (filter.search("!") == 0) {
          dplline[i].style.display = 'none';
    filter="^((?!"+filter.substr(1)+").)*$";  
        }
  }
      }
  table = document.getElementById("longtable");
     
  tr = table.getElementsByTagName("tr");
      if (table) {
  for (i = 0; i < tr.length; i++) {
        for (i = 0; i < tabletr.length; i++) {
    // match text in both columns
          // match text in all columns
    title= tr[i].getElementsByTagName("td")[0];
          if (tabletr[i].getElementsByTagName("td")[0]) {
    if (title) {
            txtValue = tabletr[i].getElementsByTagName("td")[0].textContent
      start      = tr[i].getElementsByTagName("td")[0];
                    + tabletr[i].getElementsByTagName("td")[1].textContent
      description = tr[i].getElementsByTagName("td")[1];
                    + tabletr[i].getElementsByTagName("td")[2].textContent
      notes      = tr[i].getElementsByTagName("td")[2];
                    + tabletr[i].getElementsByTagName("td")[3].textContent
      txtValue = start.textContent + description.textContent + notes.textContent;
                    + tabletr[i].getElementsByTagName("td")[4].textContent
      if (txtValue.toUpperCase().search(filter) > -1) {
                    + tabletr[i].getElementsByTagName("td")[5].textContent;
        tr[i].style.display = "";
            if (txtValue !== "" && txtValue.toUpperCase().search(filter) > -1) {
      } else {
              tabletr[i].style.display = "";
        tr[i].style.display = "none";
            } else {
              tabletr[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">');

Latest revision as of 09:45, 3 August 2024

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