MediaWiki:TwitterFollowButton/code.js

/** * This script allows users to embed Twitter follow buttons. * To embed a follow button, use the following HTML: * Follow @username * See https://dev.twitter.com/web/follow-button for more information. var followButtons = $('.twitter-follow-button');

$(followButtons).each(function {	var href = $(this).attr('data-href'),		regex = /^http(s)?\:\/\/(www\.)?twitter\.com\/(@)?[A-Za-z0-9_]+$/,		attributes = $(this).prop('attributes'),		text = $(this).text,		anchor = $('');	// Check if the URL matches a valid Twitter user account link, otherwise continue to the next item.	if(regex.test(href) !== true) {		return true;	}	$.each(attributes, function { anchor.attr(this.name, this.value); });	$(anchor).text(text);	$(anchor).attr('href', href);	$(anchor).removeAttr('data-href');	$(this).replaceWith(anchor); });

if (followButtons.length > 0) { loadTwitterJavaScript; }

function loadTwitterJavaScript { 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"));	}