Giter VIP home page Giter VIP logo

mentionify.js's Introduction

mentionify.js

A tiny JS library that renders @'s in the DOM's text to social media profile links

See demo

build status dependency status

mentionify.js is a tiny JavaScript library that looks for all intances of @'s in the DOM's text nodes and injects an HTML a tag that links to that user's social media profile.

For example, if your document has something like:

<p id="twitter">
    My Twitter handle is @jcvno!
<p>

You can add mentionify.js and run it with some options:

<script src="mentionify.js"></script>
<script>
    var mentionify = new Mentionify();
    mentionify.run({
        elementId: "twitter",
        account: "twitter"
    });
</script>

Your document will then be rendered as:

<p id="twitter">
    My Twitter handle is
    <a href="//twitter.com/jcvno" class="mentionified">@jcvno</a>!
</p>

Installation

Install mentionify.js using one of options below and include it as a <script> in your project.

Option 1

Download the latest stable mentionify.js

Option 2

npm install mentionify

Usage

You can use mentionify.js in the <body> of your HTML document:

<div id="container">
    <p>
        My Twitter handle is @jcvno!
    <p>
</div>

<script src="mentionify.js"></script>
<script>
    var mentionify = new Mentionify();
    mentionify.run({
        account: "twitter"
    });
</script>

The default account option is twitter which links to the user's Twitter profile, but can be overridden:

<div id="container">
    <p>
        My GitHub handle is @earthican!
    <p>
</div>

<script src="mentionify.js"></script>
<script>
    var mentionify = new Mentionify();
    mentionify.run({
        account: "github"
    });
</script>

The above HTML will be rendered as:

<div id="container">
    <p>
        My GitHub handle is
        <a href="//github.com/earthican" class="mentionified">@earthican</a>!
    </p>
</div>

API

Mentionify.run()

Runs mentionify.js using the specified options, which are described below.

Options

The following options can be passed into Mentionify.run()

elementId (string)

The id of the element to find and render "@user" text to a tags. Default: container

account (string)

The social media account to link to. Default: twitter

Any social media account can be used to link to its web profile, provided that it has the following URL format: http://account.com/username

Additional account support

mentionify.js now also supports linkedin and reddit accounts:

<ul>
    <li id="reddit">reddit: /u/canoj</li>
    <li id="linkedin">LinkedIn: /in/justincano</li>
</ul>

<script src="mentionify.js"></script>
<script>
    var mentionify = new Mentionify();
    mentionify.run({
        elementId: "reddit",
        account: "reddit"
    });
    mentionify.run({
        elementId: "linkedin",
        account: "linkedin"
    });
</script>

Contributing

Build

Fork this repository and clone to your local machine. Make sure node and npm are installed, then cd into project dir and run:

$ npm install

Any pull requests that relate to a new or existing feature, please write unit tests for your implementation. It's good practice!

Future

Have a request? File an issue or, better yet, create a pull request ;)

Credits

Justin Cano

License

ISC

mentionify.js's People

Contributors

earthican avatar bumrush avatar rclanan avatar efexen avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar

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.