Remove URLplugin, replace URLs inline with a hrefs

This commit is contained in:
Tor Hveem 2013-10-15 18:58:00 +02:00
parent 5ed02a5e54
commit b2174db197
3 changed files with 23 additions and 18 deletions

View File

@ -162,7 +162,7 @@
<span ng-repeat="part in bufferline.prefix" class="text" style="{{ part.fg }}">{{ part.text }}</span> <span ng-repeat="part in bufferline.prefix" class="text" style="{{ part.fg }}">{{ part.text }}</span>
</td> </td>
<td class="message"> <td class="message">
<span ng-repeat="part in bufferline.content" class="text" style="{{ part.fg }}">{{ part.text }} </span> <span ng-repeat="part in bufferline.content" class="text" style="{{ part.fg }}" ng-bind-html="part.text"></span>
<div ng-repeat="metadata in bufferline.metadata"> <div ng-repeat="metadata in bufferline.metadata">
<div ng-show="metadata.visible"> <div ng-show="metadata.visible">

View File

@ -55,31 +55,46 @@ plugins.service('plugins', ['userPlugins', '$sce', function(userPlugins, $sce)
*/ */
var contentForMessage = function(message) { var contentForMessage = function(message) {
var content = []; message.metadata = [];
for (var i = 0; i < plugins.length; i++) { for (var i = 0; i < plugins.length; i++) {
var nsfw = false; var nsfw = false;
var visible = true; var visible = true;
if (message.match(nsfwRegexp)) { if (message.text.match(nsfwRegexp)) {
var nsfw = true; var nsfw = true;
var visible = false; var visible = false;
} }
var pluginContent = plugins[i].contentForMessage(message); var pluginContent = plugins[i].contentForMessage(message.text);
if (pluginContent) { if (pluginContent) {
var pluginContent = {'visible': visible, var pluginContent = {'visible': visible,
'content': $sce.trustAsHtml(pluginContent), 'content': $sce.trustAsHtml(pluginContent),
'nsfw': nsfw, 'nsfw': nsfw,
'name': plugins[i].name } 'name': plugins[i].name }
content.push(pluginContent); message.metadata.push(pluginContent);
if (plugins[i].exclusive) { if (plugins[i].exclusive) {
break; break;
} }
} }
} }
return content;
/* Replace all URLs with hyperlinks */
var urlRegexp = RegExp(/(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:\/~+#-]*[\w@?^=%&amp;\/~+#-])?/g);
for(k in message.content) {
var text = message.content[k].text;
var url = text.match(urlRegexp);
for(i in url) {
var u = url[i];
text = text.replace(u, '<a target="_blank" href="' + u + '">' + u + '</a>');
}
message.content[k].text = $sce.trustAsHtml(text);
}
return message;
} }
return { return {
@ -124,16 +139,6 @@ plugins.factory('userPlugins', function() {
}); });
youtubePlugin.name = 'youtube video'; youtubePlugin.name = 'youtube video';
var urlPlugin = new Plugin(function(message) {
var url = message.match(urlRegexp);
if (url) {
return '<a target="_blank" href="' + url[0] + '">' + url[0] + '</a>';
}
return null;
});
urlPlugin.name = 'url';
var imagePlugin = new Plugin(function(message) { var imagePlugin = new Plugin(function(message) {
var url = message.match(urlRegexp); var url = message.match(urlRegexp);
@ -149,6 +154,6 @@ plugins.factory('userPlugins', function() {
imagePlugin.name = 'image'; imagePlugin.name = 'image';
return { return {
plugins: [youtubePlugin, urlPlugin, imagePlugin] plugins: [youtubePlugin, imagePlugin]
} }
}); });

View File

@ -191,7 +191,7 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'plugins', functi
// Only react to line if its displayed // Only react to line if its displayed
if(message.displayed) { if(message.displayed) {
var buffer = models.getBuffer(message.buffer); var buffer = models.getBuffer(message.buffer);
message.metadata = plugins.PluginManager.contentForMessage(message.text); message = plugins.PluginManager.contentForMessage(message);
buffer.addLine(message); buffer.addLine(message);
if (buffer.active) { if (buffer.active) {