plugins: define plugins as Plugin objects
This commit is contained in:
parent
cc2eda7057
commit
e457e96cd6
|
@ -49,52 +49,39 @@ plugins.service('plugins', function() {
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
plugins.factory('youtubePlugin', [function() {
|
plugins.factory('userPlugins', function() {
|
||||||
|
|
||||||
|
var youtubePlugin = new Plugin(function(message) {
|
||||||
|
|
||||||
var contentForMessage = function(message) {
|
|
||||||
if (message.indexOf('youtube.com') != -1) {
|
if (message.indexOf('youtube.com') != -1) {
|
||||||
var index = message.indexOf("?v=");
|
var index = message.indexOf("?v=");
|
||||||
var token = message.substr(index+3);
|
var token = message.substr(index+3);
|
||||||
return '<iframe width="560" height="315" src="http://www.youtube.com/embed/' + token + '" frameborder="0" allowfullscreen></iframe>'
|
return '<iframe width="560" height="315" src="http://www.youtube.com/embed/' + token + '" frameborder="0" allowfullscreen></iframe>'
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
});
|
||||||
|
|
||||||
return {
|
var urlPlugin = new Plugin(function(message) {
|
||||||
contentForMessage: contentForMessage,
|
|
||||||
exclusive: true
|
|
||||||
}
|
|
||||||
|
|
||||||
}]);
|
|
||||||
|
|
||||||
plugins.factory('urlPlugin', [function() {
|
|
||||||
var contentForMessage = function(message) {
|
|
||||||
var urlPattern = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/;
|
var urlPattern = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/;
|
||||||
var url = message.match(urlPattern);
|
var url = message.match(urlPattern);
|
||||||
if (url) {
|
if (url) {
|
||||||
return '<a href="' + url[0] + '">' + message + '</a>';
|
return '<a href="' + url[0] + '">' + message + '</a>';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
});
|
||||||
contentForMessage: contentForMessage,
|
|
||||||
exclusive: false
|
|
||||||
}
|
|
||||||
}]);
|
|
||||||
|
|
||||||
plugins.factory('imagePlugin', [function() {
|
var imagePlugin = new Plugin(function(message) {
|
||||||
var contentForMessage = function(message) {
|
|
||||||
var urls = message.match(/https?:\/\/[^\s]*\.(jpg|png|gif)\b/)
|
var urls = message.match(/https?:\/\/[^\s]*\.(jpg|png|gif)\b/)
|
||||||
if (urls != null) {
|
if (urls != null) {
|
||||||
var url = urls[0]; /* Actually parse one url per message */
|
var url = urls[0]; /* Actually parse one url per message */
|
||||||
return '<img src="' + url + '" height="300">';
|
return '<img src="' + url + '" height="300">';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
contentForMessage: contentForMessage
|
plugins: [youtubePlugin, urlPlugin, imagePlugin]
|
||||||
}
|
}
|
||||||
}]);
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue