diff --git a/Resources/notification.js b/Resources/notification.js index 45312aae..4f49677f 100644 --- a/Resources/notification.js +++ b/Resources/notification.js @@ -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); \ No newline at end of file