diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs index 4551ac7d..18851a6c 100644 --- a/Core/FormBrowser.cs +++ b/Core/FormBrowser.cs @@ -229,7 +229,12 @@ public void OnTweetSound(){ } - public void DisplayTooltip(string text){ + public void DisplayTooltip(string text, bool showInNotification){ + if (showInNotification){ + notification.DisplayTooltip(text); + return; + } + if (string.IsNullOrEmpty(text)){ toolTip.Hide(this); } diff --git a/Core/FormNotification.Designer.cs b/Core/FormNotification.Designer.cs index 8fab828c..edbbe786 100644 --- a/Core/FormNotification.Designer.cs +++ b/Core/FormNotification.Designer.cs @@ -29,6 +29,7 @@ private void InitializeComponent() { this.panelBrowser = new System.Windows.Forms.Panel(); this.timerProgress = new System.Windows.Forms.Timer(this.components); this.progressBarTimer = new TweetDck.Core.Controls.FlatProgressBar(); + this.toolTip = new System.Windows.Forms.ToolTip(this.components); this.SuspendLayout(); // // panelBrowser @@ -87,5 +88,6 @@ private void InitializeComponent() { private System.Windows.Forms.Panel panelBrowser; private Controls.FlatProgressBar progressBarTimer; private System.Windows.Forms.Timer timerProgress; + private System.Windows.Forms.ToolTip toolTip; } } \ No newline at end of file diff --git a/Core/FormNotification.cs b/Core/FormNotification.cs index 895a4131..83e52503 100644 --- a/Core/FormNotification.cs +++ b/Core/FormNotification.cs @@ -249,5 +249,16 @@ private void MoveToVisibleLocation(){ private void UpdateTitle(){ Text = tweetQueue.Count > 0 ? Program.BrandName+" ("+tweetQueue.Count+" more left)" : Program.BrandName; } + + public void DisplayTooltip(string text){ + if (string.IsNullOrEmpty(text)){ + toolTip.Hide(this); + } + else{ + Point position = PointToClient(Cursor.Position); + position.Offset(20,5); + toolTip.Show(text,this,position); + } + } } } diff --git a/Core/Handling/TweetDeckBridge.cs b/Core/Handling/TweetDeckBridge.cs index f1e5f2ad..42589740 100644 --- a/Core/Handling/TweetDeckBridge.cs +++ b/Core/Handling/TweetDeckBridge.cs @@ -101,9 +101,9 @@ public void OnUpdateDismissed(string versionTag){ }); } - public void DisplayTooltip(string text){ + public void DisplayTooltip(string text, bool showInNotification){ form.InvokeSafe(() => { - form.DisplayTooltip(text); + form.DisplayTooltip(text,showInNotification); }); } diff --git a/Resources/code.js b/Resources/code.js index 6f512832..ece95d76 100644 --- a/Resources/code.js +++ b/Resources/code.js @@ -202,11 +202,11 @@ })(); // - // Block: Expand shortened links on hover. + // Block: Expand shortened links on hover or display tooltip. // (function(){ var cutStart = function(str, search){ - return _.startsWith(str,search) ? str.substr(search.length) : str; + return str.startsWith(search) ? str.substr(search.length) : str; }; var prevMouseX = -1, prevMouseY = -1; @@ -233,7 +233,7 @@ } else{ tooltipTimer = window.setTimeout(function(){ - $TD.displayTooltip(me.attr("data-full-url")); + $TD.displayTooltip(me.attr("data-full-url"),false); tooltipDisplayed = true; },400); } @@ -246,15 +246,16 @@ me.text(prevText); } } - else{ + + if (tooltipDisplayed){ window.clearTimeout(tooltipTimer); tooltipDisplayed = false; - $TD.displayTooltip(null); + $TD.displayTooltip(null,false); } } else if (e.type === "mousemove"){ if (tooltipDisplayed && (prevMouseX != e.clientX || prevMouseY != e.clientY)){ - $TD.displayTooltip(me.attr("data-full-url")); + $TD.displayTooltip(me.attr("data-full-url"),false); prevMouseX = e.clientX; prevMouseY = e.clientY; } diff --git a/Resources/notification.js b/Resources/notification.js index e45b96a8..98515a8e 100644 --- a/Resources/notification.js +++ b/Resources/notification.js @@ -27,4 +27,72 @@ addEventListener(links,"contextmenu",function(e){ $TD.setLastRightClickedLink(e.currentTarget.getAttribute("data-full-url") || ""); }); + + // + // Block: Expand shortened links on hover or display tooltip. + // + (function(){ + var cutStart = function(str, search){ + return str.startsWith(search) ? str.substr(search.length) : str; + }; + + var prevMouseX = -1, prevMouseY = -1; + var tooltipTimer, tooltipDisplayed; + + addEventListener(links,"mouseenter",function(e){ + var url = e.currentTarget.getAttribute("data-full-url"); + if (!url)return; + + var text = e.currentTarget.textContent; + + if (text.charCodeAt(text.length-1) !== 8230){ // horizontal ellipsis + return; + } + + if ($TD.expandLinksOnHover){ + var expanded = url; + expanded = cutStart(expanded,"https://"); + expanded = cutStart(expanded,"http://"); + expanded = cutStart(expanded,"www."); + + e.currentTarget.setAttribute("td-prev-text",text); + e.currentTarget.innerHTML = expanded; + } + else{ + tooltipTimer = window.setTimeout(function(){ + $TD.displayTooltip(url,true); + tooltipDisplayed = true; + },400); + } + }); + + addEventListener(links,"mouseleave",function(e){ + if (!e.currentTarget.hasAttribute("data-full-url"))return; + + if ($TD.expandLinksOnHover){ + var prevText = e.currentTarget.getAttribute("td-prev-text"); + + if (prevText){ + e.currentTarget.innerHTML = prevText; + } + } + + if (tooltipDisplayed){ + window.clearTimeout(tooltipTimer); + tooltipDisplayed = false; + $TD.displayTooltip(null,true); + } + }); + + addEventListener(links,"mousemove",function(e){ + if (tooltipDisplayed && (prevMouseX != e.clientX || prevMouseY != e.clientY)){ + var url = e.currentTarget.getAttribute("data-full-url"); + if (!url)return; + + $TD.displayTooltip(url,true); + prevMouseX = e.clientX; + prevMouseY = e.clientY; + } + }); + })(); })($TD); \ No newline at end of file