jquery.linky

Linkify URLs, mentions & hashtags

View the Project on GitHub AnSavvides/jquery.linky

Linky

Linky is a jQuery plugin for linkifying URLs, mentions (for Twitter, Instagram or GitHub) and hashtags (for Twitter); that is, taking plain text references of URLs, mentions and hashtags and turning them to the appropriate links. Existing linkified URLs are kept untouched.

Usage

The only dependency is jQuery.

All you have to do is include jquery.linky.js or jquery.linky.min.js just after you've included jQuery and you are all set.

Install using Bower

Linky is also available as a Bower package; you can simply install it by doing bower install jquery.linky.

Options

Option Default Type Description
mentions false boolean Identify if mentions should be linkified.
hashtags false boolean Identify if hashtags should be linkified.
urls true boolean Identify if URLs should be linkified.
linkTo "twitter" string Identify location mentions and hashtags should link to

Example

Linky would come in handy if you are pulling data from any of Twitter's or Instagram's APIs where you will end up having just a plain text string like below:

@andreassavvides works on his #opensource projects over at https://github.com/AnSavvides

If you are displaying this information in your UI, you would want to linkify any mentions, hashtags and/or URLs. Linky does exactly that, giving you control over what you want linkified. In this case, let's linkify everything given a div containing the aforementioned tweet:

<div class="tweet">
    @andreassavvides works on his #opensource projects over at https://github.com/AnSavvides        
</div>
$(".tweet").linkify({
    mentions: true,
    hashtags: true,
    urls: true,
    linkTo: "twitter"
});

This would transform the div's content to the following:

<div class="url">
    <a href="https://twitter.com/andreassavvides" target="_blank">@andreassavvides</a> works on his <a href="https://twitter.com/search?q=opensource" target="_blank">#opensource</a> projects over at <a href="https://github.com/AnSavvides" target="_blank">https://github.com/AnSavvides</a>
</div>

Have a look at examples.html for more examples.

Contributing

All contributions are welcome; just fork the repository, make your changes and open a pull request.

License

The MIT License (MIT)

Copyright (c) 2013 Andreas Savvides