Sfoglia il codice sorgente

More robust JS (#8595)

Avoid JS errors:
* Following an SQL / paging issue
* When using a limited view such as `&ajax=1`
Alexandre Alapetite 2 settimane fa
parent
commit
36e1c59d8d
1 ha cambiato i file con 14 aggiunte e 4 eliminazioni
  1. 14 4
      p/scripts/main.js

+ 14 - 4
p/scripts/main.js

@@ -1048,7 +1048,11 @@ function init_column_categories() {
 		}
 	}
 
-	document.getElementById('aside_feed').onclick = function (ev) {
+	const asideFeed = document.getElementById('aside_feed');
+	if (!asideFeed) {
+		return;
+	}
+	asideFeed.onclick = function (ev) {
 		let a = ev.target.closest('.tree-folder > .tree-folder-title > button.dropdown-toggle');
 		if (a) {
 			const icon = a.querySelector('.icon');
@@ -2158,7 +2162,9 @@ function load_more_posts() {
 
 		const streamFooterOld = streamFooter.querySelector('.stream-footer-inner');
 		const streamFooterNew = streamAdopted.querySelector('.stream-footer-inner');
-		streamFooter.replaceChild(streamFooterNew, streamFooterOld);
+		if (streamFooterOld !== null && streamFooterNew !== null) {
+			streamFooter.replaceChild(streamFooterNew, streamFooterOld);
+		}
 
 		const bigMarkAsRead = document.getElementById('bigMarkAsRead');
 		const readAll = document.querySelector('#nav_menu_read_all .read_all');
@@ -2234,8 +2240,12 @@ function faviconNbUnread(n) {
 		const t = document.querySelector('.category.all .title');
 		n = t ? str2int(t.getAttribute('data-unread')) : 0;
 	}
-	const svgBase = document.querySelector('template#dynamic_favicon_base').innerHTML;
-	const link = document.getElementById('favicon').cloneNode(true);
+	const dynamicFaviconBase = document.querySelector('template#dynamic_favicon_base');
+	if (!dynamicFaviconBase) {
+		return;
+	}
+	const svgBase = dynamicFaviconBase.innerHTML;
+	const link = document.getElementById('favicon')?.cloneNode(true);
 	if (link) {
 		let svgOutput = '';
 		if (n > 0) {