Handles additional content with a simple plugin manager
This commit is contained in:
parent
8d183a835c
commit
f9641519f4
2 changed files with 58 additions and 4 deletions
|
@ -47,7 +47,12 @@
|
|||
<span ng-repeat="part in bufferline.message" class="text">
|
||||
{{ part.text }}
|
||||
</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>
|
||||
<form ng-submit="sendMessage()">
|
||||
|
|
|
@ -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 buffer_line = {}
|
||||
|
@ -111,11 +156,16 @@ weechat.factory('handlers', ['$rootScope', 'colors', function($rootScope, colors
|
|||
var buffer = message['objects'][0]['content'][0]['buffer'];
|
||||
var message = _.union(prefix, text);
|
||||
buffer_line['message'] = message;
|
||||
buffer_line['metadata'] = findMetaData(text[0]['text']);
|
||||
|
||||
if (!_isActiveBuffer(buffer)) {
|
||||
$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);
|
||||
}
|
||||
|
||||
|
@ -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 null;
|
||||
|
||||
}
|
||||
|
||||
var eventHandlers = {
|
||||
|
|
Loading…
Reference in a new issue