fix JS function problem
This commit is contained in:
		
							parent
							
								
									de56436a0d
								
							
						
					
					
						commit
						ff28919faf
					
				| @ -36,20 +36,42 @@ let MastodonApi = function (params_) { | ||||
| 	this.mtBodyContainer.addEventListener('click', function (event) { | ||||
| 		// Check if clicked in a toot
 | ||||
| 		if (event.target.localName == 'article' || event.target.offsetParent.localName == 'article') { | ||||
| 			this.openTootURL(event); | ||||
| 			openTootURL(event); | ||||
| 		} | ||||
| 		// Check if clicked in Show More/Less button
 | ||||
| 		if (event.target.localName == 'button' && event.target.className == 'spoiler-link') { | ||||
| 			this.toogleSpoiler(event); | ||||
| 			toogleSpoiler(event); | ||||
| 		} | ||||
| 	}); | ||||
| 	this.mtBodyContainer.addEventListener('keydown', function (event) { | ||||
| 		// Check if Enter key pressed with focus in an article
 | ||||
| 		if (event.code === 'Enter' && event.target.localName == 'article') { | ||||
| 			this.openTootURL(event); | ||||
| 			openTootURL(event); | ||||
| 		} | ||||
| 	}); | ||||
| 
 | ||||
| 	// Open Toot in a new page avoiding any other natural link
 | ||||
| 	function openTootURL(event_) { | ||||
| 		let urlToot = event_.target.closest('.mt-toot').dataset.location; | ||||
| 		if (event_.target.localName !== 'a' && event_.target.localName !== 'span' && event_.target.localName !== 'button' && urlToot) { | ||||
| 			window.open(urlToot, '_blank'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// Spoiler button
 | ||||
| 	function toogleSpoiler(event_) { | ||||
| 		let spoilerText = event_.target.nextSibling; | ||||
| 		let spoilerBtnText = event_.target.textContent; | ||||
| 		spoilerText.classList.toggle('spoiler-text'); | ||||
| 		if (spoilerBtnText == 'Show more') { | ||||
| 			spoilerBtnText = 'Show less'; | ||||
| 			event_.target.setAttribute('aria-expanded', 'true'); | ||||
| 		} else { | ||||
| 			spoilerBtnText = 'Show more'; | ||||
| 			event_.target.setAttribute('aria-expanded', 'false'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// Get the toots
 | ||||
| 	this.getToots(); | ||||
| 
 | ||||
| @ -286,27 +308,7 @@ MastodonApi.prototype.formatDate = function (date_) { | ||||
| 	return displayDate; | ||||
| }; | ||||
| 
 | ||||
| // Open Toot in a new page avoiding any other natural link
 | ||||
| MastodonApi.prototype.openTootURL = function (event_) { | ||||
| 	let urlToot = event_.target.closest('.mt-toot').dataset.location; | ||||
| 	if (event_.target.localName !== 'a' && event_.target.localName !== 'span' && event_.target.localName !== 'button' && urlToot) { | ||||
| 		window.open(urlToot, '_blank'); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // Spoiler button
 | ||||
| MastodonApi.prototype.toogleSpoiler = function (event_) { | ||||
| 	let spoilerText = event_.target.nextSibling; | ||||
| 	let spoilerBtnText = event_.target.textContent; | ||||
| 	spoilerText.classList.toggle('spoiler-text'); | ||||
| 	if (spoilerBtnText == 'Show more') { | ||||
| 		spoilerBtnText = 'Show less'; | ||||
| 		event_.target.setAttribute('aria-expanded', 'true'); | ||||
| 	} else { | ||||
| 		spoilerBtnText = 'Show more'; | ||||
| 		event_.target.setAttribute('aria-expanded', 'false'); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // Loading spinner
 | ||||
| function removeSpinner(element) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 idotj
						idotj