1// footer scripts 2// Unescape HTML in Link Library Category Descriptions 3function trimCategoryHTMLQuotes() { 4 console.log('unescaping link library html'); 5 var catDescriptions = document.getElementsByClassName("linkcatdesc"); 6 var catdesc=''; 7 for(var i = 0; i < catDescriptions.length; i++) 8 { 9 catdesc=catDescriptions[i].innerHTML; 10 if (catdesc !== "") { 11 document.getElementsByClassName("linkcatdesc")[i].innerHTML=unescape(catdesc).replace(/</g,"<").replace(/>/g,">"); 12 } 13 } 14} 15 16// add pagination heading 17function add_pagination_heading() { 18console.log('adding pagination heading'); 19 const newNode = document.createElement("li"); 20 const newNode2 = document.createElement("h4"); 21 const textNode = document.createTextNode("Page Numbers: "); 22 newNode2.appendChild(textNode); 23 newNode.appendChild(newNode2); 24 const list = document.getElementsByClassName("page-numbers")[0]; 25 if (list) list.insertBefore(newNode, list.children[0]); 26} 27 28// show / hide image credits 29// 30const creditsBox = document.querySelector(".isc_image_list_box"); 31const creditsList = document.querySelector(".isc_image_list"); 32function showCredits() { 33 creditsList.style.display = "block"; 34} 35function hideCredits() { 36 creditsList.style.display = "none"; 37} 38function addCreditButtons() { 39 console.log('adding credit buttons'); 40 const showButton = document.createElement("button"); 41 const hideButton = document.createElement("button"); 42 const textNodeShow = document.createTextNode("Show"); 43 const textNodeHide = document.createTextNode("Hide"); 44 showButton.appendChild(textNodeShow); 45 hideButton.appendChild(textNodeHide); 46 showButton.setAttribute("onClick","showCredits()"); 47 hideButton.setAttribute("onClick","hideCredits()"); 48 showButton.setAttribute("class","button button-secondary"); 49 hideButton.setAttribute("class","button button-secondary"); 50 var buttonPara = document.querySelector(".isc_image_list_title"); 51 buttonPara.appendChild(showButton); 52 buttonPara.appendChild(hideButton); 53} 54if (creditsBox) { 55 hideCredits(); 56 addCreditButtons(); 57} 58// remove inaccessible and bad hidden elements 59 60function hideButtonsForScreenreaders(buttonList) { 61 console.log('hide repetitive link buttons for screenreaders'); 62 var button; 63 for(var i = 0; i < buttonList.length; i++) { 64 button = buttonList[i]; 65 button.setAttribute("aria-hidden","true"); 66 } 67} 68var linkButtons = document.getElementsByClassName("pcp-readmore-link"); 69if (linkButtons) hideButtonsForScreenreaders(linkButtons); 70 71// change widget titles from paragraphs to 1 h2 and then h3s - works 72function makeWidgetTitlesHeadings() { 73 console.log('making widget titles headings'); 74 const titleList = document.getElementsByClassName("widget-title"); 75 var src, el, attrs; 76 for(var i = 0; i < titleList.length; i++) { 77 src = titleList[i]; 78 if (i > 0) { 79 el = document.createElement('h3'); 80 } else { 81 el = document.createElement('h2'); 82 } 83 attrs = src.attributes; 84 for(var j=0,k=attrs.length;j<k;j++) { 85 el.setAttribute(attrs[j].name, attrs[j].value); 86 } 87 el.innerHTML = src.innerHTML; 88 src.parentNode.replaceChild(el, src); 89 } 90} 91makeWidgetTitlesHeadings(); 92// change widget titles from paragraphs to 1 h2 and then h3s - works 93// 94// Add labels and ids to first text search field in Search and Filter forms 95function makeFormHeadingsLabels(formList) { 96 console.log('making form headings labels'); 97 var formToFix, headingList, inputList, newId, src, el, attrs, inputField, inputType; 98 for(var i = 0; i < formList.length; i++) { 99 formToFix = formList[i]; 100 headingList = formToFix.getElementsByTagName("h4"); 101 inputList = formToFix.getElementsByTagName("input"); 102 var j=0; 103 do { 104 inputField = inputList[j++]; 105 inputType = inputField.getAttribute("type"); 106 } while (inputType=="hidden"); 107 if (headingList.length > 0) { 108 src = headingList[0]; 109 toString(newId = i+"-text"); 110 inputField.setAttribute("id", newId); 111 el = document.createElement('label'); 112 el.setAttribute("for", newId); 113 el.innerHTML = src.innerHTML; 114 src.parentNode.replaceChild(el, src); 115 } 116 } 117} 118var formList = document.getElementsByClassName("searchandfilter"); 119if (formList.length > 0) makeFormHeadingsLabels(formList); 120 121var wpdmForm = document.getElementById("sc_form_wpdm_package_1"); 122 123// fix accessibility in loading gifs 124function fixLoadingGifs(divId, altText) { 125 console.log('fixing loading gifs');
126 const divToFix = document.getElementById(divId); 127 const targetImgs = divToFix.getElementsByTagName("img"); 128 for(var i = 0; i < targetImgs.length; i++) { 129 targetImgs[i].setAttribute("alt", altText); 130 targetImgs[i].setAttribute("src", "https://www.nabohome.org/wp-content/uploads/2024/02/loader.gif"); 131 } 132} 133 134function addTableHeader(divId, headingText, screenreader) { 135 console.log('adding table header'); 136 const divToFix = document.getElementById(divId); 137 const targetTable = divToFix.getElementsByTagName("table")[0]; 138 var head = targetTable.createTHead(); 139 if (screenreader) head.setAttribute("class", "screen-reader-text"); 140 var row = head.insertRow(0); 141 var cell = row.insertCell(0); 142 cell.innerHTML = "<strong>" + headingText + "</strong>"; 143} 144fixLoadingGifs("mpp-cover-uploading", "Loading..."); 145fixLoadingGifs("mpp-loader", "Loading..."); 146if (document.getElementById("es_form_f1-n1")) { 147 fixLoadingGifs("es_form_f1-n1", "Subscribing..."); 148 addTableHeader("es_form_f1-n1", "News Categories:", false); 149} 150if (document.getElementById("es_form_f1-p358-n1")) { 151 fixLoadingGifs("es_form_f1-p358-n1", "Subscribing..."); 152 addTableHeader("es_form_f1-p358-n1", "News and Blog Categories:", false); 153} 154if (document.getElementById("linktable")) { 155 addTableHeader("linktable", "Resource Categories in our Link Library:", true); 156} 157// 158 159// fix text in download buttons 160// 161function fixDownloadButtons(downloadDiv, newText) { 162 console.log('fixing download buttons'); 163 const targetLinks = downloadDiv.getElementsByClassName("wpdm-download-link"); 164 if (document.getElementById("phd-theses-searchable-list")) { 165 newText="Go to Thesis"; 166 } else if (document.getElementById("masters-theses-searchable-list")) { 167 newText="Go to Dissertation"; 168 } else if (document.getElementById("tools")) { 169 newText="Tool Download Page"; 170 } 171 for(var i = 0; i < targetLinks.length; i++) { 172 targetLinks[i].innerHTML = newText; 173 } 174} 175 var downloadDiv = document.getElementById("content_wpdm_package_1"); 176 if (downloadDiv) fixDownloadButtons(downloadDiv, "Go to Download"); 177downloadDiv = document.getElementById("field-school-news"); 178if (downloadDiv) fixDownloadButtons(downloadDiv, "View Document"); 179downloadDiv = document.getElementById("response-references"); 180if (downloadDiv) fixDownloadButtons(downloadDiv, "Go to Research Paper"); 181downloadDiv = document.getElementById("unesco-bridges"); 182if (downloadDiv) fixDownloadButtons(downloadDiv, "Go to Policy Paper"); 183// 184// not using as target is not always blank 185function addWindowInfoToLinks(divId){ 186 console.log('adding new window info to links'); 187 var divToFix = document.getElementById(divId); 188 const targetLinks = divToFix.getElementsByTagName("a"); 189// console.log("Links found: ", targetLinks.length); 190 const screenReaderMsg = document.createElement("span"); 191 const textNode = document.createTextNode(" Opens a new window "); 192 screenReaderMsg.appendChild(textNode); 193 screenReaderMsg.setAttribute("class", "screen-reader-text"); 194 const windowIcon = document.createElement("i"); 195 windowIcon.setAttribute("class", "fas fa-external-link-alt"); 196 windowIcon.setAttribute("aria-hidden", "true"); 197 for(var i = 0; i < targetLinks.length; i++) { 198 targetLinks[i].appendChild(windowIcon); 199 targetLinks[i].appendChild(screenReaderMsg); 200 console.log("added window message"); 201 } 202} 203// addWindowInfoToLinks("featured-image-credits"); // actually target is not always blank 204// but keep in case something else like this turns up in testing 205 206// change link targets in a div to _self - works 207function setLinksTargetSelf(divToFix) { 208 console.log('changing link targets to self'); 209 const targetLinks = divToFix.getElementsByTagName("a"); 210 for(var i = 0; i < targetLinks.length; i++) { 211 targetLinks[i].setAttribute("target", "_self"); 212 } 213} 214var divToFix = document.getElementById("featured-image-credits"); 215if (divToFix) setLinksTargetSelf(divToFix); 216divToFix = document.getElementById("em-wrapper"); 217if (divToFix) setLinksTargetSelf(divToFix); 218divToFix = document.getElementsByClassName("isc_image_list_box")[0]; 219if (divToFix) setLinksTargetSelf(divToFix); 220divToFix = document.getElementById("bp_core_login_widget-3"); 221if (divToFix) setLinksTargetSelf(divToFix); 222 223// remove titles from random images widget 224 225function removeImgTitles(divToFix) { 226 console.log('removing duplicate img titles'); 227 const targetImgs = divToFix.getElementsByTagName("img"); 228 for(var i = 0; i < targetImgs.length; i++) { 229 targetImgs[i].removeAttribute("title"); 230 } 231 const targetLinks = divToFix.getElementsByTagName("a");
232 console.log('removing link titles'); 233 for(var i = 0; i < targetLinks.length; i++) { 234 targetLinks[i].removeAttribute("title"); 235 } 236} 237divToFix = document.getElementById("wp-block-themeisle-blocks-slider-515e8af1"); 238if (divToFix) removeImgTitles(divToFix); 239divToFix = document.getElementById("ngg-images-2"); 240if (divToFix) removeImgTitles(divToFix); 241divToFix = document.getElementById("four-column-gallery"); 242if (divToFix) removeImgTitles(divToFix); 243divToFix = document.getElementById("three-column-gallery"); 244if (divToFix) removeImgTitles(divToFix); 245divToFix = document.getElementById("photo-gallery"); 246if (divToFix) removeImgTitles(divToFix); 247// make links category page title a h2 heading 248// 249function linksCategoryHeading() { 250 console.log('adding links category heading'); 251 const headingToFix = document.getElementsByClassName("linklistcatclass")[0]; 252 var src, el, attrs; 253 src = headingToFix; 254 el = document.createElement('h2'); 255 attrs = src.attributes; 256 for(var j=0,k=attrs.length;j<k;j++) { 257 el.setAttribute(attrs[j].name, attrs[j].value); 258 } 259 el.innerHTML = src.innerHTML; 260 src.parentNode.replaceChild(el, src); 261} 262divToFix = document.getElementById("links-category-page"); 263if (divToFix) linksCategoryHeading(divToFix); 264 265// remove empty heading 266function isEmpty(node) { 267 console.log('removing empty node'); 268 return node.textContent.trim() === ""; 269} 270/* doesn't work because this empty heading is added by jQuery later than this script runs */ 271function removeEmptyHeadings(badHeadingClass) { 272 console.log('removing bad headings'); 273 var modalHeadings = document.getElementsByClassName(badHeadingClass); 274 var headingNoLoop = modalHeadings[0]; 275 headingNoLoop.remove(); 276} 277 278function removeBadElement(badId) { 279 var badElement = document.getElementById(badId); 280 badElement.remove(); 281 console.log(badId, " removed"); 282 // these scripts are running and finding the bad elements but not removing them - again, they are filled in later than this runs 283} 284//removeBadElement("wpdm-popup-link"); // not working, too late on page - try in complianz template? Tried this, still not late enough to make the difference 285function hideBadElement(badId) { 286 var badElement = document.getElementById(badId); 287 badElement.setAttribute("aria-hidden", "true"); 288 badElement.setAttribute("focusable", "false"); 289 console.log(badId, " hidden"); 290} 291 292// add role="button" to top search bar icon and other 'Improper Use of Link' accessibility errors - works 293// NB option to add role=Link must not be enabled in OneClick Accessibility or this won't work 294function addRoleButton(badLinkClasses) { 295 console.log('adding role=button to button links'); 296 var linksToFix = document.querySelectorAll('a.' + badLinkClasses); 297 for(var i = 0; i < linksToFix.length; i++) { 298 linksToFix[i].setAttribute('role', 'button'); 299// console.log("changed link role to button"); 300 } 301} 302addRoleButton('nv-icon.nv-search'); // works 303if (document.getElementsByClassName("author-index-navigation")) addRoleButton("page-link"); 304 305// can't fix - is inside an iframe 306// wpdm-download-link 307// 308// fix missing images on category pages 309function replaceEmptyImages(archivePage) { 310 var archivePosts = archivePage.getElementsByTagName("article"); 311 var thisArticle, imgFound, newNode, postLink; 312 console.log('archive page'); 313 for(var i = 0; i < archivePosts.length; i++) { 314 thisArticle = archivePosts[i].querySelectorAll('div.' + 'content')[0]; 315 imgFound = thisArticle.querySelectorAll('div.' + 'nv-post-thumbnail-wrap')[0]; 316 if (! imgFound) { 317 console.log('replacing missing image'); 318 postLink = thisArticle.getElementsByTagName("a")[0].getAttribute("href"); 319 newNode = document.createElement('div'); 320 newNode.innerHTML = '<a href="'+ postLink + '" rel="bookmark" title=""><img width="930" height="620" src="/wp-content/uploads/2023/08/1246px-nabo-projects-2023-06-23_18-02-48_edited.jpg" class="skip-lazy wp-post-image" alt="Map of NABO project locations" decoding="async" fetchpriority="high" data-opt-lazy-loaded="false"></a>'; 321 newNode.classList.add("nv-post-thumbnail-wrap","img-wrap"); 322 thisArticle.insertBefore(newNode, thisArticle.firstChild); 323 } 324 } 325} 326var archivePage = document.getElementById("nv-edd-grid-container"); 327if (archivePage) replaceEmptyImages(archivePage); 328// Replace Downloads Menu Options 329function replace_downloads_menu_text() { 330// Causes alert in Wordfence but is ok - removes link to a user account age in Download Manager 331 var xpath = '//*[@id="udm-user"]/a[1]/text()'; 332 var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; 333 matchingElement.textContent = "Downloads Overview "; 334 var editOption = document.getElementById("udm-account"); 335 editOption.remove(); 336} 337 338if (window.location) { 339 const currentUrl = window.location.href.toLowerCase(); 340 if (currentUrl.match("downloads/dashboard")) { 341 replace_downloads_menu_text(); 342 } else { 343 if ((currentUrl.match("/category/")) || (currentUrl.match("/tag/"))) { 344 add_pagination_heading(); 345 } 346 } 347 trimCategoryHTMLQuotes(); 348 // Use imagesLoaded() to trigger masonry after all images are loaded 349jQuery('.grid').imagesLoaded( function(){ 350 jQuery('.grid').masonry({ 351 itemSelector: '.ll-grid-item', 352 isAnimated: true, 353 isFitWidth: true 354 }); 355}); 356}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.