Last active
August 29, 2015 14:15
-
-
Save vivien/500e8abbf8dbfa1efc1e to your computer and use it in GitHub Desktop.
Draft for a single URL plugin in Glowing Bear
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/js/plugins.js b/js/plugins.js | |
index 839df4c..b5559b8 100644 | |
--- a/js/plugins.js | |
+++ b/js/plugins.js | |
@@ -94,6 +94,44 @@ var UrlPlugin = function(name, urlCallback) { | |
}; | |
}; | |
+var urlHandlers = [{ | |
+ /* | |
+ * YouTube Embedded Player | |
+ * | |
+ * See: https://developers.google.com/youtube/player_parameters | |
+ */ | |
+ name: 'YouTube', | |
+ check: function(url) { | |
+ var token = null; | |
+ | |
+ if (underDomain(url.domain, ['com', 'youtube'])) { | |
+ if (url.path[0] == 'watch') { | |
+ token = url.params.v; | |
+ } else if (url.path[0] == 'embed') { | |
+ token = url.path[1]; | |
+ } | |
+ } else if (underDomain(url.domain, ['be', 'youtu'])) { | |
+ token = url.path[0]; | |
+ } | |
+ | |
+ if (token) { | |
+ var embedurl = "https://www.youtube.com/embed/" + token + "?html5=1&iv_load_policy=3&modestbranding=1&rel=0&showinfo=0"; | |
+ return '<iframe width="560" height="315" src="'+ embedurl + '" frameborder="0" allowfullscreen frameborder="0"></iframe>'; | |
+ } | |
+ | |
+ return null; | |
+ } | |
+}, { | |
+ /* | |
+ * FooBar | |
+ * | |
+ * See: https://developers.google.com/youtube/player_parameters | |
+ */ | |
+ name: 'foobar', | |
+ check: function() { | |
+ } | |
+}]; | |
+ | |
/* | |
* This service provides access to the plugin manager | |
* | |
@@ -218,6 +256,25 @@ plugins.factory('userPlugins', function() { | |
document.body.appendChild(script); | |
}; | |
+ var urlPlugin = new Plugin('URL', function(message) { | |
+ var urls = message.match(urlRegexp) || []; | |
+ var content = []; | |
+ | |
+ for (var i = 0; i < urls.length; i++) { | |
+ var url = parseURL(urls[i]); | |
+ | |
+ for (var j = 0; j < urlPlugins.length; j++) { | |
+ var handler = urlHandlers[j]; | |
+ var result = handler.check(url); | |
+ if (result) { | |
+ content.push(result); | |
+ } | |
+ } | |
+ } | |
+ | |
+ return content; | |
+ }); | |
+ | |
/* | |
* Spotify Embedded Player | |
* | |
@@ -239,32 +296,6 @@ plugins.factory('userPlugins', function() { | |
}); | |
/* | |
- * YouTube Embedded Player | |
- * | |
- * See: https://developers.google.com/youtube/player_parameters | |
- */ | |
- var youtubePlugin = new UrlPlugin('YouTube video', function(url) { | |
- var token = null; | |
- | |
- if (underDomain(url.domain, ['com', 'youtube'])) { | |
- if (url.path[0] == 'watch') { | |
- token = url.params.v; | |
- } else if (url.path[0] == 'embed') { | |
- token = url.path[1]; | |
- } | |
- } else if (underDomain(url.domain, ['be', 'youtu'])) { | |
- token = url.path[0]; | |
- } | |
- | |
- if (token) { | |
- var embedurl = "https://www.youtube.com/embed/" + token + "?html5=1&iv_load_policy=3&modestbranding=1&rel=0&showinfo=0"; | |
- return '<iframe width="560" height="315" src="'+ embedurl + '" frameborder="0" allowfullscreen frameborder="0"></iframe>'; | |
- } | |
- | |
- return null; | |
- }); | |
- | |
- /* | |
* Dailymotion Embedded Player | |
* | |
* See: http://www.dailymotion.com/doc/api/player.html | |
@@ -437,7 +468,7 @@ plugins.factory('userPlugins', function() { | |
}); | |
return { | |
- plugins: [youtubePlugin, dailymotionPlugin, allocinePlugin, imagePlugin, spotifyPlugin, cloudmusicPlugin, googlemapPlugin, asciinemaPlugin, yrPlugin, gistPlugin, tweetPlugin, vinePlugin] | |
+ plugins: [urlPlugin, dailymotionPlugin, allocinePlugin, spotifyPlugin] | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment