mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	refactor: simplified ajaxify.check and likely made it equally more confusing
This commit is contained in:
		| @@ -32,10 +32,12 @@ ajaxify.widgets = { render: render }; | ||||
| 		 *   null  (no action) | ||||
| 		 */ | ||||
| 		let urlObj; | ||||
| 		let pathname; | ||||
| 		let pathname = item instanceof Element ? item.getAttribute('href') : undefined; | ||||
| 		try { | ||||
| 			urlObj = new URL(item, `${document.location.origin}${config.relative_path}`); | ||||
| 			if (!pathname) { | ||||
| 				({ pathname } = urlObj); | ||||
| 			} | ||||
| 		} catch (e) { | ||||
| 			return false; | ||||
| 		} | ||||
| @@ -44,35 +46,39 @@ ajaxify.widgets = { render: render }; | ||||
| 		// eslint-disable-next-line no-script-url | ||||
| 		const hrefEmpty = href => href === undefined || href === '' || href === 'javascript:;'; | ||||
|  | ||||
| 		if (item instanceof Element && item.getAttribute('data-ajaxify') === 'false') { | ||||
| 		if (item instanceof Element) { | ||||
| 			if (item.getAttribute('data-ajaxify') === 'false') { | ||||
| 				if (!internalLink) { | ||||
| 				return; | ||||
| 					return false; | ||||
| 				} | ||||
|  | ||||
| 				return null; | ||||
| 			} | ||||
|  | ||||
| 		// Default behaviour for rss feeds | ||||
| 		if (internalLink && pathname.endsWith('.rss')) { | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		// Default behaviour for sitemap | ||||
| 		if (internalLink && String(pathname).startsWith(config.relative_path + '/sitemap') && pathname.endsWith('.xml')) { | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		// Default behaviour for uploads and direct links to API urls | ||||
| 		if (internalLink && ['/uploads', '/assets/', '/api/'].some(function (prefix) { | ||||
| 			return String(pathname).startsWith(config.relative_path + prefix); | ||||
| 		})) { | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 			// eslint-disable-next-line no-script-url | ||||
| 			if (hrefEmpty(urlObj.href) || urlObj.protocol === 'javascript:' || pathname === '#' || pathname === '') { | ||||
| 				return null; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if (internalLink) { | ||||
| 			// Default behaviour for rss feeds | ||||
| 			if (pathname.endsWith('.rss')) { | ||||
| 				return false; | ||||
| 			} | ||||
|  | ||||
| 			// Default behaviour for sitemap | ||||
| 			if (String(pathname).startsWith(config.relative_path + '/sitemap') && pathname.endsWith('.xml')) { | ||||
| 				return false; | ||||
| 			} | ||||
|  | ||||
| 			// Default behaviour for uploads and direct links to API urls | ||||
| 			if (['/uploads', '/assets/', '/api/'].some(function (prefix) { | ||||
| 				return String(pathname).startsWith(config.relative_path + prefix); | ||||
| 			})) { | ||||
| 				return false; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		return true; | ||||
| 	}; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user