From 49fa7626b6796354ec7bffa1ea7fa66a15171eb0 Mon Sep 17 00:00:00 2001
From: chylex <info@chylex.com>
Date: Sun, 24 Apr 2016 20:47:10 +0200
Subject: [PATCH] Expand shortened links on hover

Closes #12
---
 Resources/code.js | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/Resources/code.js b/Resources/code.js
index bd87b186..ea8d1029 100644
--- a/Resources/code.js
+++ b/Resources/code.js
@@ -177,6 +177,42 @@
     };
   })();
   
+  //
+  // Block: Expand shortened links.
+  //
+  (function(){
+    var cutStart = function(str, search){
+      return _.startsWith(str,search) ? str.substr(search.length) : str;
+    };
+    
+    $(document.body).delegate("a[data-full-url]","mouseenter mouseleave",function(e){
+      var me = $(this);
+
+      if (e.type == "mouseenter"){
+        var text = me.text();
+        
+        if (text.charCodeAt(text.length-1) !== 8230){ // horizontal ellipsis
+          return;
+        }
+        
+        var expanded = me.attr("data-full-url");
+        expanded = cutStart(expanded,"https://");
+        expanded = cutStart(expanded,"http://");
+        expanded = cutStart(expanded,"www.");
+        
+        me.attr("td-prev-text",text);
+        me.text(expanded);
+      }
+      else{
+        var prevText = me.attr("td-prev-text");
+        
+        if (prevText){
+          me.text(prevText);
+        }
+      }
+    });
+  })();
+  
   //
   // Block: Hook into mp4 video element clicking 
   //