GithubHelp home page GithubHelp logo

terenceponce / jquery.tweet-linkify Goto Github PK

View Code? Open in Web Editor NEW
13.0 8.0 1.0 140 KB

A jQuery plugin that transforms Twitter related entities from plain text into hyperlinks.

Home Page: http://terenceponce.github.com/jquery.tweet-linkify

JavaScript 100.00%

jquery.tweet-linkify's Introduction

jQuery Tweet Linkify

This is a small jQuery plugin that transforms @mention texts into hyperlinks pointing to the actual Twitter profile, #hashtag texts into real hashtag searches, as well as hyperlink texts into actual hyperlinks.

The hyperlink text transforming was based off of jLinker.js by Michalis Tzikas and Vasilis Lolos.

How to use

Basic Usage

Let's say you have this tweet:

This is a test tweet to @terenceponce http://t.co/something #YOLO

<p class="tweet">This is a test tweet to @terenceponce http://t.co/something</p> #YOLO

Doing $('p.tweet').tweetLinkify(); will transform the text into this:

This is a test tweet to @terenceponce http://t.co/something #YOLO

<p class="tweet">This is a test tweet to <a href="http://twitter.com/terenceponce">@terenceponce</a> <a href="http://t.co/something">http://t.co/something</a> <a href="https://twitter.com/search/?src=hash&q=%23YOLO">#YOLO</a></p>

Advanced Usage

The plugin accepts multiple options:

  • excludeHyperlinks - Excludes hyperlink texts from being transformed. Defaults to false
  • excludeMentions - Excludes @mention texts from being transformed. Defaults to false
  • excludeHashtags - Excludes #hashtag texts from being transformed. Defaults to false
  • hyperlinkTarget - The target attribute for hyperlinks. Options are blank, self, parent, and top
  • mentionTarget - The target attribute for mentions. Options are blank, self, parent, and top
  • mentionIntent - Transforms the mention into a Twitter web user intent. Defaults to false
  • hashtagTarget - The target attribute for hashtags. Options are blank, self, parent, and top
  • hyperlinkClass - The class attribute for hyperlinks.
  • mentionClass - The class attribute for mentions.
  • hashtagClass - The class attribute for hashtags.
  • hyperlinkRel - The rel attribute for hyperlinks.
  • mentionRel - The rel attribute for mentions.
  • hashtagRel - The rel attribute for hashtags.

Let's say I want the hyperlinks and mentions to have a class name and the hyperlinks to open to a new tab instead of the same window. Using the previous example:

var options = {
  hyperlinkTarget: 'blank',
  hyperlinkClass: 'yolo',
  mentionClass: 'swag'
};

$('p.tweet').tweetLinkify(options);

Will transform into this:

<p class="tweet">This is a test tweet to <a href="http://twitter.com/terenceponce" class="swag">@terenceponce</a> <a href="http://t.co/something" target="_blank" class="yolo">http://t.co/something</a> <a href="https://twitter.com/search/?src=hash&q=%23YOLO">#YOLO</a></p>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.