Skip to content

Add a JavaScript event when opening an article#2222

Merged
Alkarex merged 2 commits intoFreshRSS:devfrom
Alkarex:javascript_toggleArticle_event
Jan 24, 2019
Merged

Add a JavaScript event when opening an article#2222
Alkarex merged 2 commits intoFreshRSS:devfrom
Alkarex:javascript_toggleArticle_event

Conversation

@Alkarex
Copy link
Member

@Alkarex Alkarex commented Jan 19, 2019

https://framagit.org/nicofrand/xextension-threepanesview/issues/4

document.body.addEventListener('freshrss:openArticle', function (e) {
		console.log('freshrss:openArticle');
		console.log(e.target);
	});

https://framagit.org/nicofrand/xextension-threepanesview/issues/4

```javascript
document.body.addEventListener('freshrss:openArticle', function (e) {
console.log('freshrss:openArticle');
console.log(e.target);
});
```
@Alkarex Alkarex added this to the 1.13.1 milestone Jan 19, 2019
@Frenzie
Copy link
Member

Frenzie commented Jan 19, 2019

I guess I could rewrite my custom JS now, if I wanted to. ;-)

// all the lame browsers, namely those other than Opera/Presto and Prince, don't
// do CSS generated content on images...

function show_img_titles(img) {
	img.after('<div class="show-img-title">Mouseover title: ' + img.attr('title') + '</div>');
}

function init_show_img_titles() {
	if (window.$) {
		$('img[title]').each(function(){
			show_img_titles($(this));
		});

		var observer = new MutationObserver(function(mutations) {  
			mutations.forEach(function(mutation) {
				for (var i = 0; i < mutation.addedNodes.length; i++) {
					//console.log(mutation.addedNodes[i])
					$(mutation.addedNodes[i]).find('img[title]').each(function(){
						show_img_titles($(this));
					});
				}
			});
		});
		observer.observe(document.querySelector('#stream'), { subtree: true, childList: true });
	}
	else {
		window.setTimeout(init_show_img_titles, 50);
	}
}

init_show_img_titles();

@nicofrand
Copy link
Contributor

Perfect, thanks for adding this, this will help a lot!

@Alkarex Alkarex merged commit da4a80b into FreshRSS:dev Jan 24, 2019
@Alkarex Alkarex deleted the javascript_toggleArticle_event branch January 24, 2019 18:43
@Alkarex Alkarex mentioned this pull request Jan 24, 2019
mdemoss pushed a commit to mdemoss/FreshRSS that referenced this pull request Mar 25, 2021
* 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);
	});
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants