$('.hashTag textarea').on('keyup',
function() {
var regExpForUserGroup = /(^|\s)(@|#)(\w+)/g;
var valueOfTextarea = $(this).val();
var matched = valueOfTextarea.match(regExpForUserGroup);
var valueOfQuery;
var replaced;
// from http://stackoverflow.com/questions/28298748/how-to-strip-specific-tag-into-div-in-javascript/28300163?noredirect=1#comment44952991_28300163
var temp = valueOfTextarea.replace(/[\<]/g, "<");
var result = temp.replace(/[\>]/g, ">");
if ( regExpForUserGroup.test(valueOfTextarea) ) {
valueOfQuery = result.replace(regExpForUserGroup, "$1<a href=\"http://www.twitter.com/$3\">$2$3</a>");
}
// remove the link into the div
if( typeof valueOfQuery === "undefined") {
$('#result').find('a').remove();
}
// Set the new content of div#result
$('#result').html(
valueOfQuery
);
// Loop over the link element
// and add @ before the link or #.
$('#result a').each(
function() {
var linkText = $(this).text();
if ( /@/g.test(linkText) ) {
$(this)[0].href = "http://www.twitter.com/" + linkText.split('@')[1];
}
if ( /#/g.test(linkText) ) {
$(this)[0].href = "http://www.twitter.com/hashtag?q=" + linkText.split('#')[1];
}
$(this).mousedown(
function() {
//console.log('yeah')
// TODO: autocomplete
}
);
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.