Handles additional content with a simple plugin manager

This commit is contained in:
David Cormier 2013-08-06 16:39:10 -04:00
parent 8d183a835c
commit f9641519f4
2 changed files with 58 additions and 4 deletions

View file

@ -47,7 +47,12 @@
<span ng-repeat="part in bufferline.message" class="text"> <span ng-repeat="part in bufferline.message" class="text">
{{ part.text }} {{ part.text }}
</span> </span>
<div ng-visible="bufferline.metadata" ng-bind-html-unsafe="bufferline.metadata"></div> <div ng-visible="bufferline.metadata">
<div ng-repeat="metadata in bufferline.metadata">
<div ng-bind-html-unsafe="bufferline.metadata"></div>
</div>
</div>
</div> </div>
<form ng-submit="sendMessage()"> <form ng-submit="sendMessage()">

View file

@ -101,8 +101,53 @@ weechat.factory('colors', [function($scope) {
}]); }]);
weechat.factory('pluginManager', ['youtubePlugin', function(youtubePlugin) {
weechat.factory('handlers', ['$rootScope', 'colors', function($rootScope, colors) { var plugins = [youtubePlugin]
var hookPlugin = function(plugin) {
plugins.push(plugin);
}
var contentForMessage = function(message) {
console.log('Message: ', message);
var content = [];
for (var i = 0; i < plugins.length; i++) {
var pluginContent = plugins[i].contentForMessage(message);
if (pluginContent) {
content.push(pluginContent);
}
}
console.log('Content: ', content);
return content;
}
return {
hookPlugin: hookPlugin,
contentForMessage: contentForMessage
}
}]);
weechat.factory('youtubePlugin', [function() {
var contentForMessage = function(message) {
if (message.indexOf('youtube.com') != -1) {
var index = message.indexOf("?v=");
var token = message.substr(index+3);
return '<iframe width="560" height="315" src="http://www.youtube.com/embed/' + token + '" frameborder="0" allowfullscreen></iframe>'
}
return null;
}
return {
contentForMessage: contentForMessage
}
}]);
weechat.factory('handlers', ['$rootScope', 'colors', 'pluginManager', function($rootScope, colors, pluginManager) {
var handleBufferLineAdded = function(message) { var handleBufferLineAdded = function(message) {
var buffer_line = {} var buffer_line = {}
@ -111,11 +156,16 @@ weechat.factory('handlers', ['$rootScope', 'colors', function($rootScope, colors
var buffer = message['objects'][0]['content'][0]['buffer']; var buffer = message['objects'][0]['content'][0]['buffer'];
var message = _.union(prefix, text); var message = _.union(prefix, text);
buffer_line['message'] = message; buffer_line['message'] = message;
buffer_line['metadata'] = findMetaData(text[0]['text']);
if (!_isActiveBuffer(buffer)) { if (!_isActiveBuffer(buffer)) {
$rootScope.buffers[buffer]['notification'] = true; $rootScope.buffers[buffer]['notification'] = true;
} }
var additionalContent = pluginManager.contentForMessage(text[0]['text']);
if (additionalContent) {
buffer_line['metadata'] = additionalContent;
}
$rootScope.buffers[buffer]['lines'].push(buffer_line); $rootScope.buffers[buffer]['lines'].push(buffer_line);
} }
@ -172,7 +222,6 @@ weechat.factory('handlers', ['$rootScope', 'colors', function($rootScope, colors
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;
} }
var eventHandlers = { var eventHandlers = {