1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-23 12:15:48 +02:00

Fix clicking on nested/complex links in notification.js not triggering the hooks

This commit is contained in:
chylex 2016-04-25 16:17:28 +02:00
parent dd4c89b9dd
commit a335aa037a

View File

@ -1,10 +1,25 @@
(function($TD){
//
// Function: Bubbles up the parents until it hits an element with the specified tag (includes the first element), and returns true if the search was successful.
//
var bubbleParents = function(element, tag, callback){
do{
if (element.tagName == "A"){
callback(element);
return true;
}
}while((element = element.parentElement) != null);
return false;
};
//
// Block: Hook into links to bypass default open function.
//
document.body.addEventListener("click",function(e){
if (e.target.tagName == "A"){
$TD.openBrowser(e.target.getAttribute("href"));
if (bubbleParents(e.target,"A",function(ele){
$TD.openBrowser(ele.getAttribute("href"));
})){
e.preventDefault();
}
});
@ -13,13 +28,8 @@
// Block: Allow bypassing of t.co in context menus.
//
document.body.addEventListener("contextmenu",function(e){
var element = e.target;
do{
if (element.tagName == "A"){
$TD.setLastRightClickedLink(element.getAttribute("data-full-url") || "");
break;
}
}while((element = element.parentElement) != null);
bubbleParents(e.target,"A",function(ele){
$TD.setLastRightClickedLink(element.getAttribute("data-full-url") || "");
});
});
})($TD);