mootools_在MooTools中实现String.Tweetify

mootools

TwitterGitter

Twitter has damn near taken over the world. Everything's Twitter. Twitter this. Twitter that. TwitterGitter. Twitter everything. I'm more used to reading Twitter-speak (short condensed sentences, #'s, @'s, etc.) now than I am plain English. And since Twitter is only going to continue to get more popular, we better get used to using it on our websites and providing users with formatted tweets. MooTools makes it easy to format tweets with links.

Twitter几乎已经接管了整个世界。 一切都是Twitter。 推特这个。 Twitter的。 TwitterGitter 。 推特一切。 我现在比普通英语更习惯阅读Twitter讲话(简短的简写,#,@等)。 而且由于Twitter只会继续变得越来越流行,因此我们最好习惯于在我们的网站上使用它,并为用户提供格式化的推文。 MooTools使格式化带有链接的推文变得容易。

MooTools JavaScript (The MooTools JavaScript)


//implement
String.implement({
	tweetify: function() {
		return this.replace(/(https?:\/\/\S+)/gi,'<a href="$1">$1</a>').replace(/(^|\s)@(\w+)/g,'$1<a href="http://twitter.com/$2">@$2</a>').replace(/(^|\s)#(\w+)/g,'$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>');
	}
});
//usage
var original = '@davidwalshblog I love your #Mootools LazyLoad plugin!  https://davidwalsh.name/lazyload';
var tweetified = original.tweetify(); //becomes: <a href="http://twitter.com/davidwalshblog">@davidwalshblog</a> I love your <a href="http://search.twitter.com/search?q=%23Mootools">#Mootools</a> LazyLoad plugin! <a href="https://davidwalsh.name/lazyload">https://davidwalsh.name/lazyload </a>


Now you can instantly tweetify any string!

现在,您可以立即对任何字符串进行鸣叫!

翻译自: https://davidwalsh.name/tweetify

mootools

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值