jQuery AutoLink is a jQuery plugin for automatically converting text containing URLs, mentions (for Twitter, Instagram, GitHub, or a locally hosted site) and hashtags (for Twitter or a locally hosted site) into URLs. It automatically transforms plain text URLs, mentions, & hashtags into clickable URLs.
This fork (@MarQuisKnox/jQuery.AutoLink) of Linky has the following changes:
- Adds the option to link locally
- Adds the option to specify the href target
- Adds e-mail autolinking
- Fixes YouTube Embeds
- Fixes URL RegEx
- Matches URLs w/ Parameters
- Matches all TLDs except for those w/ unicode characters
The only dependency is jQuery.
All you have to do is include jquery.autolink.js
or jquery.autolink.min.js
just after you've included jQuery
and you're all set.
Option | Default | Type | Description |
---|---|---|---|
emails | true |
boolean |
Identify if e-mail addresses should be linkified. |
mentions | true |
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. |
jQuery AutoLink 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="status">
@andreassavvides works on his #opensource projects over at https://github.com/AnSavvides
</div>
$(".status").autolink({
mentions: true,
hashtags: true,
urls: true,
linkTo: "local"
});
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.
Unit testing is done using QUnit; all tests can be found under the tests folder.
All contributions are welcome; just fork the repository, make your changes and open a pull request. Don't forget to add tests if applicable!
The MIT License (MIT)
Copyright (c) 2013 - 2015 Andreas Savvides
Copyright (c) 2014 - 2017 MarQuis Knox
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.