Add comments to page_format.js

This commit is contained in:
manfromhuh 2022-07-05 14:29:43 -04:00
parent e1ac241f2a
commit 93514c0e1d

View File

@ -1,8 +1,10 @@
//
function format_page(){//Set the title of the page based on the main header, <h1>, tag.le != '' )){
if ( document.getElementsByTagName('h1').length !== 0){
document.title = document.getElementsByTagName('h1')[0].innerText;
}
//detect if the page contains code blocks to be highlighted and loads the prisim.js and prism.css files to accomplish this.
//Detect if the page contains code blocks to be highlighted and loads the
//prisim.js and prism.css files if codeblocks are found.
code_tag = document.getElementsByTagName('code').length;
if ( code_tag !== 0 ){
var script = document.createElement('script');
@ -15,11 +17,14 @@ function format_page(){//Set the title of the page based on the main header, <h1
document.head.appendChild(script);
document.head.appendChild(style_sheet);
}
if ( document.getElementById("font_btns") ){//Show the font selection buttons.
//Sets the displayed fontsize.
//This functionality won't work without JavaScript enabled. For this reason the
//buttons won't be shown if this script isn't run.
if ( document.getElementById("font_btns") ){//Show the font selection buttons.
document.getElementById("font_btns").style.display = 'inline';
var font_size = read_cookie("font_size");
var font_size = read_cookie("font_size");//reads a saved value for fontsize from the site cookie
if ( font_size != "" || font_size != "medium" ){
font_set(font_size);
font_set(font_size);//insure a sane default
}
}
if ( document.getElementById("search_inputs") ){//Show the search box and button on the tags page.
@ -43,7 +48,7 @@ function format_page(){//Set the title of the page based on the main header, <h1
});
}
}
function font_set(size_to_set){
function font_set(size_to_set){//Set a cookie to remember the fontsize selection.
document.getElementById("article").style.fontSize = size_to_set;
set_cookie("font_size",size_to_set);
}
@ -52,7 +57,7 @@ function focus_element(element_id){
ele_to_focus.focus();
ele_to_focus.select();
}
function tag_search(){
function tag_search(){//searches in the avaliable tags and displays all articles matching the searched tag.
var search_input, filter, tag_list, li, a, i;
search_input = document.getElementById("tag_sort");
filter = search_input.value.toUpperCase();
@ -66,9 +71,8 @@ function tag_search(){
li[i].style.display = "none";
}
}
}
function title_search(){
function title_search(){//searches for matches in the article titles rather than tags. Allows more granular search
var search_input, filter, tag_list, li_list, ol, a, i;
search_input = document.getElementById("title_sort");
filter = search_input.value.toUpperCase();
@ -88,7 +92,7 @@ function title_search(){
}
}
function search_toggle(){
function search_toggle(){//Toggles if the unit being sorted on is the article title or tag
if (document.getElementById("tag_sort")){
document.getElementById("tag_sort").placeholder = "Search Titles";
document.getElementById("tag_sort").onkeyup = function() {title_search()};
@ -107,10 +111,10 @@ function search_toggle(){
focus_element("tag_sort");
}
}
function set_cookie(prop_name, prop_value){
function set_cookie(prop_name, prop_value){//sets a passed cookie property and value.
document.cookie = prop_name + "=" + prop_value + ";path=/;SameSite=Strict;";
}
function read_cookie(cname){
function read_cookie(cname){//reads a property value
let prop_name = cname + '=';
let decoded_cookie = decodeURIComponent(document.cookie);
let split_cookie = decoded_cookie.split(';');
@ -125,11 +129,11 @@ function read_cookie(cname){
}
return "";
}
function printDiv(divName) {
function printDiv(divName) {//Formats the page for printing.
var printContents = document.getElementById(divName).innerHTML;
w=window.open();
w.document.write(printContents);
w.print();
w.close();
}
window.onload = format_page;
window.onload = format_page;//loades the page formatting script.