Skip to content

Commit

Permalink
Merge pull request #118 from Friss/add-instagram
Browse files Browse the repository at this point in the history
Add instagram
  • Loading branch information
gregjacobs committed Oct 18, 2015
2 parents 3961ba6 + b3a2339 commit 3c09a24
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ providing an Object as the second parameter to [Autolinker.link()](http://gregja
Twitter handles. Defaults to `true`.<br /><br />
- [hashtag](http://gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker-cfg-hashtag) : Boolean/String<br />
A string for the service name to have hashtags auto-linked to. Supported
values at this time are 'twitter' and 'facebook'. Pass `false` to skip
values at this time are 'twitter', 'facebook' and 'instagram'. Pass `false` to skip
auto-linking of hashtags. Defaults to `false`.<br /><br />
- [replaceFn](http://gregjacobs.github.io/Autolinker.js/docs/#!/api/Autolinker-cfg-replaceFn) : Function<br />
A function to use to programmatically make replacements of matches in the
Expand Down Expand Up @@ -282,7 +282,7 @@ The full API docs for Autolinker may be referenced at:

Pull requests definitely welcome.

- Make sure to add tests to cover your new functionality/bugfix.
- Make sure to add tests to cover your new functionality/bugfix.
- Run the `grunt` command to build/test (or alternatively, open the `tests/index.html` file to run the tests).
- When committing, please omit checking in the files in the `dist/` folder after building/testing. These are only committed to the repository for users downloading Autolinker via Bower. I will build these files and assign them a version number when merging your PR.
- Please use tabs for indents! Tabs are better for everybody (individuals can set their editors to different tab sizes based on their visual preferences).
Expand Down
3 changes: 2 additions & 1 deletion src/Autolinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var Autolinker = function( cfg ) {

// Validate the value of the `hashtag` cfg.
var hashtag = this.hashtag;
if( hashtag !== false && hashtag !== 'twitter' && hashtag !== 'facebook' ) {
if( hashtag !== false && hashtag !== 'twitter' && hashtag !== 'facebook' && hashtag !== 'instagram' ) {
throw new Error( "invalid `hashtag` cfg - see docs" );
}
};
Expand Down Expand Up @@ -153,6 +153,7 @@ Autolinker.prototype = {
*
* - 'twitter'
* - 'facebook'
* - 'instagram'
*
* Pass `false` to skip auto-linking of hashtags.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/match/Hashtag.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Autolinker.match.Hashtag = Autolinker.Util.extend( Autolinker.match.Match, {
return 'https://twitter.com/hashtag/' + hashtag;
case 'facebook' :
return 'https://www.facebook.com/hashtag/' + hashtag;
case 'instagram' :
return 'https://instagram.com/explore/tags/' + hashtag;

default : // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case.
throw new Error( 'Unknown service name to point hashtag to: ', serviceName );
Expand All @@ -75,4 +77,4 @@ Autolinker.match.Hashtag = Autolinker.Util.extend( Autolinker.match.Match, {
return '#' + this.hashtag;
}

} );
} );
7 changes: 7 additions & 0 deletions tests/AutolinkerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ describe( "Autolinker", function() {
beforeEach( function() {
twitterHashtagAutolinker = new Autolinker( { hashtag: 'twitter', newWindow: false } );
facebookHashtagAutolinker = new Autolinker( { hashtag: 'facebook', newWindow: false } );
instagramHashtagAutolinker = new Autolinker( { hashtag: 'instagram', newWindow: false } );
} );


Expand Down Expand Up @@ -942,6 +943,12 @@ describe( "Autolinker", function() {
expect( result ).toBe( '<a href="https://www.facebook.com/hashtag/test">#test</a>' );
} );

it( "should automatically link hashtags to instagram when the `hashtag` option is 'instagram'", function() {
var result = instagramHashtagAutolinker.link( "#test" );

expect( result ).toBe( '<a href="https://instagram.com/explore/tags/test">#test</a>' );
} );


it( "should automatically link hashtags which are part of a full string", function() {
var result = twitterHashtagAutolinker.link( "my hashtag is #test these days" );
Expand Down

0 comments on commit 3c09a24

Please sign in to comment.