diff --git a/assets/js/jquery.auto-link.js b/assets/js/jquery.auto-link.js index baf9d49..d00b40d 100644 --- a/assets/js/jquery.auto-link.js +++ b/assets/js/jquery.auto-link.js @@ -7,9 +7,28 @@ */ $(function(){ + // load twitter widget + window.twttr = (function(d, s, id) { + var js, fjs = d.getElementsByTagName(s)[0], + t = window.twttr || {}; + if (d.getElementById(id)) return t; + js = d.createElement(s); + js.id = id; + js.src = "https://platform.twitter.com/widgets.js"; + fjs.parentNode.insertBefore(js, fjs); + + t._e = []; + t.ready = function(f) { + t._e.push(f); + }; + + return t; + }(document, "script", "twitter-wjs")); + $.fn.autoLink = function(config){ this.each(function(){ var re = /((https?|ftp):\/\/[\(\)%#!\/0-9a-zA-Z_$@.&+-,'"*=;?:~-]+|^#[^#\s]+|\s#[^#\s]+)/g; + var embed = ""; $(this).html( $(this).html().replace(re, function(u){ try { @@ -20,12 +39,25 @@ $(function(){ return prefix + ''+tag+''; } else { var url = $.url(u); + if (u.match(/https?:\/\/twitter\.com\/.+\/status\/(\d+)$/)) { + // embed tweet + var tweet_id = RegExp.$1; + embed += '
'; + twttr.ready(function() { + twttr.widgets.createTweet(tweet_id, $('#tw'+tweet_id).get(0),{cards:'hidden'}); + }); + } + else if (u.match(/https?:\/\/www\.youtube\.com\/watch\?v=([0-9a-zA-Z_]+)/)) { + embed += '