From bb0cef6ba6278aa7913d3b50bd0d8b0d61b0ed8c Mon Sep 17 00:00:00 2001 From: Zachary Friss Date: Fri, 21 Aug 2015 23:47:44 -0400 Subject: [PATCH] Allow linking of instagram hashtags --- src/Autolinker.js | 3 ++- src/match/Hashtag.js | 4 +++- tests/AutolinkerSpec.js | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Autolinker.js b/src/Autolinker.js index 5baf9500..035aa7f9 100644 --- a/src/Autolinker.js +++ b/src/Autolinker.js @@ -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" ); } }; @@ -153,6 +153,7 @@ Autolinker.prototype = { * * - 'twitter' * - 'facebook' + * - 'instagram' * * Pass `false` to skip auto-linking of hashtags. */ diff --git a/src/match/Hashtag.js b/src/match/Hashtag.js index 0d1fb527..e39004ac 100644 --- a/src/match/Hashtag.js +++ b/src/match/Hashtag.js @@ -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 ); @@ -75,4 +77,4 @@ Autolinker.match.Hashtag = Autolinker.Util.extend( Autolinker.match.Match, { return '#' + this.hashtag; } -} ); \ No newline at end of file +} ); diff --git a/tests/AutolinkerSpec.js b/tests/AutolinkerSpec.js index c9b4360c..977ea221 100644 --- a/tests/AutolinkerSpec.js +++ b/tests/AutolinkerSpec.js @@ -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 } ); } ); @@ -942,6 +943,12 @@ describe( "Autolinker", function() { expect( result ).toBe( '#test' ); } ); + it( "should automatically link hashtags to instagram when the `hashtag` option is 'instagram'", function() { + var result = instagramHashtagAutolinker.link( "#test" ); + + expect( result ).toBe( '#test' ); + } ); + it( "should automatically link hashtags which are part of a full string", function() { var result = twitterHashtagAutolinker.link( "my hashtag is #test these days" );