From c2647692df96e4705513b10b97604f4911ead9d7 Mon Sep 17 00:00:00 2001 From: staltz Date: Sat, 22 Mar 2014 23:30:44 +0200 Subject: [PATCH 1/2] RichTextProcessor can embed Youtube videos as iframe; Fix #149 --- app/css/app.css | 14 +++++++++++++- app/js/services.js | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/css/app.css b/app/css/app.css index 24202659..38f3e2d0 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -1067,7 +1067,19 @@ div.im_message_video_thumb { background-image: url(../img/icons/IconsetW_1x.png); } - +.im_message_iframe_video { + position: relative; + padding-bottom: 56.25%; // 16/9 ratio + height: 0; + overflow: hidden; +} +.im_message_iframe_video iframe, object, embed { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; +} .im_message_document, .im_message_audio, diff --git a/app/js/services.js b/app/js/services.js index aa2b9866..80cd2372 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -2545,6 +2545,13 @@ angular.module('myApp.services', []) } // console.log(4, text, html); + var youtubeRegex = /(?:https?:\/\/)?(?:www\.)?youtu(?:|.be|be.com|.b)(?:\/v\/|\/watch\\?v=|e\/|\/watch(?:.+)v=)(.{11})(?:\&[^\s]*)?/; + if (!options.noLinks && youtubeRegex.test(text)) { + var videoID = youtubeRegex.exec(text)[1]; + text = text + '
'; + } return $sce.trustAs('html', text); } From 78d855cc1b93c3f007d368c7d8d676110200f4f9 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sun, 23 Mar 2014 18:13:20 +0400 Subject: [PATCH 2/2] Merged youtube embed --- app/css/app.css | 3 ++- app/js/services.js | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/css/app.css b/app/css/app.css index 38f3e2d0..59654759 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -1072,8 +1072,9 @@ div.im_message_video_thumb { padding-bottom: 56.25%; // 16/9 ratio height: 0; overflow: hidden; + margin-top: 5px; } -.im_message_iframe_video iframe, object, embed { +.im_message_iframe_video iframe { position: absolute; top: 0; left: 0; diff --git a/app/js/services.js b/app/js/services.js index 80cd2372..b0c9e0a6 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -2427,6 +2427,7 @@ angular.module('myApp.services', []) } var regExp = new RegExp('((?:(ftp|https?)://|(?:mailto:)?([A-Za-z0-9._%+-]+@))(\\S*\\.\\S*[^\\s.;,(){}<>"\']))|(\\n)|(' + emojiUtf.join('|') + ')', 'i'); + var youtubeRegex = /(?:https?:\/\/)?(?:www\.)?youtu(?:|.be|be.com|.b)(?:\/v\/|\/watch\\?v=|e\/|\/watch(?:.+)v=)(.{11})(?:\&[^\s]*)?/; return { wrapRichText: wrapRichText @@ -2545,12 +2546,15 @@ angular.module('myApp.services', []) } // console.log(4, text, html); - var youtubeRegex = /(?:https?:\/\/)?(?:www\.)?youtu(?:|.be|be.com|.b)(?:\/v\/|\/watch\\?v=|e\/|\/watch(?:.+)v=)(.{11})(?:\&[^\s]*)?/; - if (!options.noLinks && youtubeRegex.test(text)) { - var videoID = youtubeRegex.exec(text)[1]; + if (!options.noLinks) { + var youtubeMatches = text.match(youtubeRegex), + videoID = youtubeMatches && youtubeMatches[1]; + + if (videoID) { text = text + '
'; + 'src="http://www.youtube.com/embed/' + videoID + + '?autoplay=0&controls=2">' + } } return $sce.trustAs('html', text);