plugins: fix imagePlugin

This commit is contained in:
David Cormier 2013-10-13 15:14:43 -04:00
parent 741416cb79
commit 2377253676
1 changed files with 11 additions and 6 deletions

View File

@ -110,6 +110,8 @@ plugins.service('plugins', ['userPlugins', '$sce', function(userPlugins, $sce)
*/ */
plugins.factory('userPlugins', function() { plugins.factory('userPlugins', function() {
var urlRegexp = RegExp(/(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/);
var youtubePlugin = new Plugin(function(message) { var youtubePlugin = new Plugin(function(message) {
if (message.indexOf('youtube.com') != -1) { if (message.indexOf('youtube.com') != -1) {
@ -123,8 +125,7 @@ plugins.factory('userPlugins', function() {
youtubePlugin.name = 'youtube video'; youtubePlugin.name = 'youtube video';
var urlPlugin = new Plugin(function(message) { var urlPlugin = new Plugin(function(message) {
var urlPattern = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/; var url = message.match(urlRegexp);
var url = message.match(urlPattern);
if (url) { if (url) {
return '<a target="_blank" href="' + url[0] + '">' + message + '</a>'; return '<a target="_blank" href="' + url[0] + '">' + message + '</a>';
} }
@ -134,11 +135,15 @@ plugins.factory('userPlugins', function() {
urlPlugin.name = 'url'; urlPlugin.name = 'url';
var imagePlugin = new Plugin(function(message) { var imagePlugin = new Plugin(function(message) {
var urls = message.match(/https?:\/\/[^\s]*\.(jpg|png|gif)\b/)
if (urls != null) { var url = message.match(urlRegexp);
var url = urls[0]; /* Actually parse one url per message */
if (url) {
var url = url[0]; /* Actually parse one url per message */
if (url.match(/png$|gif$|jpg$|jpeg$/)) {
return '<img src="' + url + '" height="300">'; return '<img src="' + url + '" height="300">';
} }
}
return null; return null;
}); });
imagePlugin.name = 'image'; imagePlugin.name = 'image';