Skip to content

Commit

Permalink
Merge pull request #61 from saiury92/feature/google_drive_iframe
Browse files Browse the repository at this point in the history
Allow google drive iframe with editor input (redactor)
  • Loading branch information
minhdung authored Jul 10, 2019
2 parents 304bc3a + 2f53387 commit 8bb5b55
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion vendor/assets/javascripts/redactor-rails/plugins/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
return {
reUrlYoutube: /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w.-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/ig,
reUrlVimeo: /https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/,
reUrlGoogleDrive: /^(https?:\/\/(www\.)?drive.google.com\/)file\/d\/([^\/]+)((\/.*)|(\/([a-zA-z])))*$/,

getTemplate: function() {
return String() + '<section id="redactor-modal-video-insert">' + '<label>' + this.lang.get('video_html_code') + '</label>' + '<textarea id="redactor-insert-video-area" style="height: 160px;"></textarea>' + '</section>';
},
Expand Down Expand Up @@ -31,14 +33,16 @@
if (!data.match(/<iframe|<video/gi)) {
data = this.clean.stripTags(data);

// parse if it is link on youtube & vimeo
// parse if it is link on youtube or vimeo or google drive
var iframeStart = '<div class="embed-container"><iframe src="',
iframeEnd = '" frameborder="0" allowfullscreen></iframe></div>';

if (data.match(this.video.reUrlYoutube)) {
data = data.replace(this.video.reUrlYoutube, iframeStart + '//www.youtube.com/embed/$1' + iframeEnd);
} else if (data.match(this.video.reUrlVimeo)) {
data = data.replace(this.video.reUrlVimeo, iframeStart + '//player.vimeo.com/video/$2' + iframeEnd);
} else if (data.match(this.video.reUrlGoogleDrive)) {
data = data.replace(this.video.reUrlGoogleDrive, iframeStart + '//drive.google.com/file/d/$3/preview' + iframeEnd);
}
}

Expand Down

0 comments on commit 8bb5b55

Please sign in to comment.