added plugin support for giphy gifs as embedded content and created testcases
This commit is contained in:
parent
f17a976e1a
commit
03a6e391f6
2 changed files with 29 additions and 1 deletions
|
@ -353,6 +353,25 @@ plugins.factory('userPlugins', function() {
|
|||
}
|
||||
});
|
||||
|
||||
/* match giphy links and display the assocaited gif images
|
||||
* sample input: http://giphy.com/gifs/eyes-shocked-bird-feqkVgjJpYtjy
|
||||
* sample output: https://media.giphy.com/media/feqkVgjJpYtjy/giphy.gif
|
||||
*/
|
||||
var giphyPlugin = new UrlPlugin('Giphy', function(url) {
|
||||
var regex = /^https?:\/\/giphy.com\/gifs\/.*-.*\/?/i;
|
||||
if (url.match(regex)) {
|
||||
/* if the url does not contain a trailing slash, add it */
|
||||
if (! url.match(/\/$/i)) { url = url + "/"; }
|
||||
/* upgrade any http links to tls, yeah crypto */
|
||||
if (url.match(/^http:/i)) { url.replace(/http:/, "https:"); }
|
||||
/* change the url to refrence the giphy cdn url, not the userfacing webserver */
|
||||
url = url.replace(/\/giphy.com\//i,"/media.giphy.com/");
|
||||
url = url.replace(/\/gifs\/.*-/i,"/media/");
|
||||
url = url + "giphy.gif";
|
||||
return '<a target="_blank" href="'+url+'"><img class="embed" src="' + url + '"></a>';
|
||||
}
|
||||
});
|
||||
|
||||
var tweetPlugin = new UrlPlugin('Tweet', function(url) {
|
||||
var regexp = /^https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(?:es)?\/(\d+)/i;
|
||||
var match = url.match(regexp);
|
||||
|
@ -391,7 +410,7 @@ plugins.factory('userPlugins', function() {
|
|||
});
|
||||
|
||||
return {
|
||||
plugins: [youtubePlugin, dailymotionPlugin, allocinePlugin, imagePlugin, videoPlugin, spotifyPlugin, cloudmusicPlugin, googlemapPlugin, asciinemaPlugin, yrPlugin, gistPlugin, tweetPlugin, vinePlugin]
|
||||
plugins: [youtubePlugin, dailymotionPlugin, allocinePlugin, imagePlugin, videoPlugin, spotifyPlugin, cloudmusicPlugin, googlemapPlugin, asciinemaPlugin, yrPlugin, gistPlugin, giphyPlugin, tweetPlugin, vinePlugin]
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -139,6 +139,15 @@ describe('filter', function() {
|
|||
plugins);
|
||||
}));
|
||||
|
||||
it('should recognize giphy gifs', inject(function(plugins) {
|
||||
expectTheseMessagesToContain([
|
||||
'https://giphy.com/gifs/eyes-shocked-bird-feqkVgjJpYtjy/',
|
||||
'http://giphy.com/gifs/funny-cat-FiGiRei2ICzzG',
|
||||
],
|
||||
'Giphy',
|
||||
plugins);
|
||||
}));
|
||||
|
||||
it('should recognize tweets', inject(function(plugins) {
|
||||
expectTheseMessagesToContain([
|
||||
'https://twitter.com/DFB_Team_EN/statuses/488436782959448065',
|
||||
|
|
Loading…
Reference in a new issue