I'm stuck and can't figure it out. I have multiple triggers that are very similar
<a style="margin: 4px 4px 4px 4px !important"
data-toggle="modal"
data-target="#video_modal"
data-title="YouTube video title"
data-youtube-url="YouTube/url/">Montenegro protesters decry opposition's use of Serbian symbols
</a>
<a style="margin: 4px 4px 4px 4px !important"
data-toggle="modal"
data-target="#audio_modal"
data-title="Soundcloud item title"
data-soundcloud-url="soundcloud/url">Katarina Panic: Montenegro elections-The real winners are citizens
</a>
The modal setups are below:
<div class="modal fade bd-example-modal-lg" id="video_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item youtube-iframe" src=""></iframe>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<div class="modal fade" id="submission-modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item soundcloud-iframe" src=""></iframe>
</div>
</div>
</div>
</div>
</div>
And the JavaScript functions for those modals.
//SOUNDCLOUD MODAL SCRIPT
$('#audio_modal').on('show.bs.modal', function (event) {
var source = $(event.relatedTarget); // Button that triggered the modal
console.log(source + "Audio Modal JS");
var title = source.data('title');
var soundcloudurl = source.data('soundcloud-url');
var iframeLink = soundcloudurl.replace(soundcloudrurl, 'https://w.soundcloud.com/player/?url=$1');
var modal = $(this);
modal.find('.modal-title').text(title);
modal.find('.audio-iframe').attr("src",iframeLink);
})
//YOUTUBE MODAL SCRIPT
$('#video_modal').on('show.bs.modal', function (event) {
var source= $(event.relatedTarget);
console.log(source + "Video Modal JS");
var title = source.data('title');
var youtube_url = source.data('youtube-url');
var iframeLink = youtube_url.replace(/(?:http:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g, 'www.youtube.com/embed/$1');
var modal = $(this);
modal.find('.modal-title').text(title);
modal.find('.youtube-iframe').attr("src",iframeLink);
})
Oddly enough, the YouTube modal
works perfectly fine, but the sound-cloud modal doesn't appear at all.
I'm certain that my classes and IDs are correct because the YouTube modal is functioning. There must be something else I'm missing. Any suggestions?