From f6930d0950a8d868076c34c633fac180543f77f2 Mon Sep 17 00:00:00 2001 From: Kan Fushihara Date: Wed, 15 Jul 2015 23:36:22 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E7=89=B9=E5=AE=9A=E3=81=AE=E3=82=B5?= =?UTF-8?q?=E3=83=BC=E3=83=93=E3=82=B9=E3=81=AEURL=E3=81=AF=E5=B1=95?= =?UTF-8?q?=E9=96=8B=E3=81=97=E3=81=A6=E5=9F=8B=E3=82=81=E8=BE=BC=E3=82=80?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/jquery.auto-link.js | 38 ++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/assets/js/jquery.auto-link.js b/assets/js/jquery.auto-link.js index baf9d49..5adace9 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,29 @@ $(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 += '