From 98ad8d152d3fd997cb3d0fb3b238b2e61a738c43 Mon Sep 17 00:00:00 2001
From: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Date: Mon, 21 Oct 2013 16:10:10 -0400
Subject: [PATCH] plugins: add Dailymotion support

---
 js/plugins.js | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/js/plugins.js b/js/plugins.js
index f3edc5a..fd69257 100644
--- a/js/plugins.js
+++ b/js/plugins.js
@@ -169,6 +169,28 @@ plugins.factory('userPlugins', function() {
     });
     youtubePlugin.name = 'YouTube video';
 
+    /*
+     * Dailymotion Embedded Player
+     *
+     * See: http://www.dailymotion.com/doc/api/player.html
+     */
+    var dailymotionPlugin = new Plugin(function(message) {
+
+        var rPath = /dailymotion.com\/.*video\/([^_?# ]+)/;
+        var rAnchor = /dailymotion.com\/.*#video=([^_& ]+)/;
+        var rShorten = /dai.ly\/([^_?# ]+)/;
+
+        var match = message.match(rPath) || message.match(rAnchor) || message.match(rShorten);
+        if (match) {
+            var id = match[1];
+            var embedurl = 'http://www.dailymotion.com/embed/video/' + id + '?html&controls=html&startscreen=html&info=0&logo=0&related=0';
+            return '<iframe frameborder="0" width="480" height="270" src="' + embedurl + '"></iframe>';
+        }
+
+        return null;
+    });
+    dailymotionPlugin.name = 'Dailymotion video';
+
     /*
      * Image Preview
      */
@@ -240,6 +262,6 @@ plugins.factory('userPlugins', function() {
     googlemapPlugin.name = 'Google Map';
 
     return {
-        plugins: [youtubePlugin, imagePlugin, spotifyPlugin, cloudmusicPlugin, googlemapPlugin]
+        plugins: [youtubePlugin, dailymotionPlugin, imagePlugin, spotifyPlugin, cloudmusicPlugin, googlemapPlugin]
     }
 });