embed video in proposal show
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
//= require suggest
|
||||
//= require forms
|
||||
//= require valuation_spending_proposal_form
|
||||
//= require embed_video
|
||||
|
||||
var initialize_modules = function() {
|
||||
App.Comments.initialize();
|
||||
@@ -59,6 +60,7 @@ var initialize_modules = function() {
|
||||
App.Suggest.initialize();
|
||||
App.Forms.initialize();
|
||||
App.ValuationSpendingProposalForm.initialize();
|
||||
App.EmbedVideo.initialize();
|
||||
};
|
||||
|
||||
$(function(){
|
||||
|
||||
7
app/assets/javascripts/embed_video.js.coffee
Normal file
7
app/assets/javascripts/embed_video.js.coffee
Normal file
@@ -0,0 +1,7 @@
|
||||
App.EmbedVideo =
|
||||
|
||||
initialize: ->
|
||||
$('#js-embedded-video').each ->
|
||||
code = $(this).data("video-code")
|
||||
$('#js-embedded-video').html(code)
|
||||
|
||||
30
app/helpers/embed_videos_helper.rb
Normal file
30
app/helpers/embed_videos_helper.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
module EmbedVideosHelper
|
||||
|
||||
def embedded_video_code
|
||||
link = @proposal.video_url
|
||||
if link.match(/vimeo.*/)
|
||||
server = "Vimeo"
|
||||
elsif link.match(/youtu*.*/)
|
||||
server = "YouTube"
|
||||
end
|
||||
|
||||
if server == "Vimeo"
|
||||
regExp = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/
|
||||
src = "https://player.vimeo.com/video/"
|
||||
elsif server == "YouTube"
|
||||
regExp = /youtu.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/
|
||||
src = "https://www.youtube.com/embed/"
|
||||
end
|
||||
|
||||
if regExp
|
||||
match = link.match(regExp)
|
||||
end
|
||||
|
||||
if match and match[2]
|
||||
'<iframe src="' + src + match[2] + '" frameborder="0" allowfullscreen></iframe>'
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -62,7 +62,8 @@
|
||||
<div class="video-link">
|
||||
<%= text_with_links @proposal.video_url %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div id="js-embedded-video" data-video-code="<%= embedded_video_code %>"></div>
|
||||
<% end %>
|
||||
|
||||
<h4><%= @proposal.question %></h4>
|
||||
|
||||
|
||||
@@ -87,6 +87,29 @@ feature 'Proposals' do
|
||||
end
|
||||
end
|
||||
|
||||
context "Embedded video" do
|
||||
scenario "Show YouTube video" do
|
||||
proposal = create(:proposal, video_url: "http://www.youtube.com/watch?v=a7UFm6ErMPU")
|
||||
visit proposal_path(proposal)
|
||||
expect(page).to have_selector("div[id='js-embedded-video']")
|
||||
expect(page.html).to include 'https://www.youtube.com/embed/a7UFm6ErMPU'
|
||||
end
|
||||
|
||||
scenario "Show Vimeo video" do
|
||||
proposal = create(:proposal, video_url: "https://vimeo.com/7232823" )
|
||||
visit proposal_path(proposal)
|
||||
expect(page).to have_selector("div[id='js-embedded-video']")
|
||||
expect(page.html).to include 'https://player.vimeo.com/video/7232823'
|
||||
end
|
||||
|
||||
scenario "Dont show video" do
|
||||
proposal = create(:proposal, video_url: nil)
|
||||
|
||||
visit proposal_path(proposal)
|
||||
expect(page).to_not have_selector("div[id='js-embedded-video']")
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Social Media Cards' do
|
||||
proposal = create(:proposal)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user