Răsfoiți Sursa

Add a JavaScript event when opening an article (#2222)

* Add a JavaScript event when opening an article
https://framagit.org/nicofrand/xextension-threepanesview/issues/4

```javascript
document.body.addEventListener('freshrss:openArticle', function (e) {
		console.log('freshrss:openArticle');
		console.log(e.target);
	});
```
Alexandre Alapetite 7 ani în urmă
părinte
comite
da4a80b88a
2 a modificat fișierele cu 10 adăugiri și 2 ștergeri
  1. 2 0
      CHANGELOG.md
  2. 8 2
      p/scripts/main.js

+ 2 - 0
CHANGELOG.md

@@ -17,6 +17,8 @@
 	* New `TZ` timezone environment variable [#2153](https://github.com/FreshRSS/FreshRSS/issues/2153)
 	* Run Docker cron job with Apache user instead of root [#2208](https://github.com/FreshRSS/FreshRSS/pull/2208)
 	* Accept HTTP header `X-WebAuth-User` for delegated HTTP Authentication [#2204](https://github.com/FreshRSS/FreshRSS/pull/2204)
+* Extensions
+	* Trigger a `freshrss:openArticle` JavaScript event [#2222](https://github.com/FreshRSS/FreshRSS/pull/2222)
 * API
 	* Automatic test of API configuration [#2207](https://github.com/FreshRSS/FreshRSS/pull/2207)
 	* Performance + compatibility: Use Apache `SetEnvIf` module if available and fall-back to `RewriteRule` [#2202](https://github.com/FreshRSS/FreshRSS/pull/2202)

+ 8 - 2
p/scripts/main.js

@@ -237,6 +237,9 @@ function mark_favorite(active) {
 	});
 }
 
+var freshrssOpenArticleEvent = document.createEvent('Event');
+freshrssOpenArticleEvent.initEvent('freshrss:openArticle', true, true);
+
 function toggleContent(new_active, old_active, skipping) {
 	// If skipping, move current without activating or marking as read
 	if (new_active.length === 0) {
@@ -299,8 +302,11 @@ function toggleContent(new_active, old_active, skipping) {
 		}
 	}
 
-	if (context.auto_mark_article && new_active.hasClass('active') && !skipping) {
-		mark_read(new_active, true);
+	if (new_active.hasClass('active') && !skipping) {
+		if (context.auto_mark_article) {
+			mark_read(new_active, true);
+		}
+		new_active[0].dispatchEvent(freshrssOpenArticleEvent);
 	}
 }