diff --git a/index.html b/index.html
index 0cdc1df..24efdf7 100644
--- a/index.html
+++ b/index.html
@@ -10,6 +10,7 @@
+
diff --git a/js/plugins.js b/js/plugins.js
new file mode 100644
index 0000000..76e7ee7
--- /dev/null
+++ b/js/plugins.js
@@ -0,0 +1,84 @@
+var plugins = angular.module('plugins', []);
+
+plugins.factory('pluginManager', ['youtubePlugin', 'urlPlugin', 'imagePlugin', function(youtubePlugin, urlPlugin, imagePlugin) {
+
+ var plugins = [youtubePlugin, urlPlugin, imagePlugin]
+
+ var hookPlugin = function(plugin) {
+ plugins.push(plugin);
+ }
+
+ var contentForMessage = function(message) {
+
+ var content = [];
+ for (var i = 0; i < plugins.length; i++) {
+ var pluginContent = plugins[i].contentForMessage(message);
+ if (pluginContent) {
+ var pluginContent = {'visible': false, 'content': pluginContent }
+ content.push(pluginContent);
+
+ if (plugins[i].exclusive) {
+ break;
+ }
+ }
+ }
+
+ return content;
+ }
+
+ return {
+ hookPlugin: hookPlugin,
+ contentForMessage: contentForMessage
+ }
+
+}]);
+
+plugins.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 '
'
+ }
+ return null;
+ }
+
+ return {
+ contentForMessage: contentForMessage,
+ exclusive: true
+ }
+
+}]);
+
+plugins.factory('urlPlugin', [function() {
+ var contentForMessage = function(message) {
+ var urlPattern = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/;
+ var url = message.match(urlPattern);
+ if (url) {
+ return '
' + message + '';
+ }
+ return null;
+ }
+
+ return {
+ contentForMessage: contentForMessage,
+ exclusive: false
+ }
+}]);
+
+plugins.factory('imagePlugin', [function() {
+ var contentForMessage = function(message) {
+ var urls = message.match(/https?:\/\/[^\s]*\.(jpg|png|gif)\b/)
+ if (urls != null) {
+ var url = urls[0]; /* Actually parse one url per message */
+ return '
';
+ }
+ return null;
+ }
+
+ return {
+ contentForMessage: contentForMessage
+ }
+}]);
+
diff --git a/js/websockets.js b/js/websockets.js
index 3b192ba..c7b4ad2 100644
--- a/js/websockets.js
+++ b/js/websockets.js
@@ -1,4 +1,4 @@
-var weechat = angular.module('weechat', ['localStorage', 'weechatModels']);
+var weechat = angular.module('weechat', ['localStorage', 'weechatModels', 'plugins']);
weechat.factory('colors', [function($scope) {
@@ -109,87 +109,6 @@ weechat.factory('colors', [function($scope) {
}]);
-weechat.factory('pluginManager', ['youtubePlugin', 'urlPlugin', 'imagePlugin', function(youtubePlugin, urlPlugin, imagePlugin) {
-
- var plugins = [youtubePlugin, urlPlugin, imagePlugin]
-
- var hookPlugin = function(plugin) {
- plugins.push(plugin);
- }
-
- var contentForMessage = function(message) {
-
- var content = [];
- for (var i = 0; i < plugins.length; i++) {
- var pluginContent = plugins[i].contentForMessage(message);
- if (pluginContent) {
- var pluginContent = {'visible': false, 'content': pluginContent }
- content.push(pluginContent);
-
- if (plugins[i].exclusive) {
- break;
- }
- }
- }
-
- 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 '
'
- }
- return null;
- }
-
- return {
- contentForMessage: contentForMessage,
- exclusive: true
- }
-
-}]);
-
-weechat.factory('urlPlugin', [function() {
- var contentForMessage = function(message) {
- var urlPattern = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/;
- var url = message.match(urlPattern);
- if (url) {
- return '
' + message + '';
- }
- return null;
- }
-
- return {
- contentForMessage: contentForMessage,
- exclusive: false
- }
-}]);
-
-weechat.factory('imagePlugin', [function() {
- var contentForMessage = function(message) {
- var urls = message.match(/https?:\/\/[^\s]*\.(jpg|png|gif)\b/)
- if (urls != null) {
- var url = urls[0]; /* Actually parse one url per message */
- return '
';
- }
- return null;
- }
-
- return {
- contentForMessage: contentForMessage
- }
-}]);
weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager', function($rootScope, colors, models, pluginManager) {