Video keeps playing after closing modal - html

When I close my modal, the video keeps playing in the background. It is a really small program with only HTML and CSS, so I don't want to use the YouTube API. This is my modal code:
<div id="lucaModal" class="modal modal-fullscreen" role="dialog">
<button id="lucaButton" class="btn btn-danger closeIFrame" data-dismiss="modal">
CLOSE
</button>
<div class="modal-content">
<iframe class="trailer" id="trailer" title="YoutubeVideoPlayer"
style="height: 100%; width: 100%;"
src="https://www.youtube.com/embed/mYfJxlgR2jw" frameborder="0">
</iframe>
</div>
</div>
I tried jQuery, but my modal wouldn't close this way:
$(document).ready(function(){
$("#lucaModal").modal('show');
$("#lucaButton").click(function(){
$("#lucaModal").modal('hide');
});
});

So I've played around with your code and found a way around this.
Below I used JQuery to solve your.
//below is click detector that checks if the user has clicked anywhere
$('body').on('click',function(){
//if the modal is no longer visible on the screen
if(!$('#lucaModal').is(':visible')){
//we get the src of the current video
var trailer = $('#trailer').attr('src');
//and reset it, that will sort out your problem
$('#trailer').attr('src',trailer);
}
});
Just copy and paste the code above to your js file and see if it works. If it does then play around with it, maybe you can create an even better way of handling this issue.
Thanks.

Related

Materialize Modal not working, staying open

I'm trying to use the materialize modal in my laravel app, I've got a blade file called skeleton which I put all my "scripts" in and stylesheets etc. That yeilds the sections which I define in my single blade files. That works great, however I've had loads of issues with materialize lately.
When I try to use the modal, I use this code from the docs:
$(document).ready(function() {
$('.modal').modal();
});
That's at the bottom of my skeleton file and shows at the bottom of every file. I've tried putting it in my file itself and it didn't work.
My HTML looks like this:
#if($auth >= 5) <a href="#modal1" class="btn waves-effect waves-light green right modal-trigger"
href="#modal1"> Create</a>
#endif
at the bottom of the blade file:
<div id="modal1" class="modal">
<div class="modal-content">
<h4>Modal Header</h4>
<p>A bunch of text</p>
</div>
<div class="modal-footer">
Agree
</div>
My modal appears on screen, but it's automatically "shown" and when I click the open button it doesn't do anything. I'm just using the demo modal, I'll customize it when I can get it to work, thanks.
Here you go with a solution
For opening a modal please use the below code
$('.modal').modal('show');
For closing a modal please use the below code
$('.modal').modal('hide');
It's opening automatically because of
$(document).ready(function() {
$('.modal').modal();
});
Whenever the doument is ready then it's opens the modal.
On click
#if($auth >= 5) Create
#endif
Open the modal using $('.modal').modal('show');
Ok, first up, why two href's on the modal trigger?
#if($auth >= 5) <a href="#modal1" class="btn waves-effect waves-light green right modal-trigger"
href="#modal1"> Create</a>
#endif
Take one off, and let's take it from there.
The answer above incorrectly states that the init below opens the modal:
$(document).ready(function() {
$('.modal').modal();
});
This is just the initialisation, it plugs into the JS to allow it to work.
<!-- this is the initialisation -->
$('.modal').modal();
<!-- this is instruction to open -->
$('.modal').modal('open');
Check the pen here for the two commands, comment each out to see what happens.
Modals are closed by default, and are triggered by clicking the .modal-trigger or using the open command above..
I was being stupid, I had bootstrap js linked for some reason and they were conflicting. Sorry to waste anyone's time.

Bootstrap 4 modal don't appear with data-target

I am returning an Json object from an local API, it's working fine, with the object I feed my table with rows and columns, each column has a search button, which should open a modal with more detailed info about that line, which was already loaded with the table.
Here is a sample of my button looks like:
<tr>
...
<td><button type="button" class="btn btn-primary form-control"
id="id5bb3b60d870f3809e8e4403d" data-toggle="modal"
data-target="#5bb3b60d870f3809e8e4403dmodal">+</button></td>
</tr>
And here is a modal example:
<div id="5bb3b60d870f3809e8e4403dmodal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="5bb3b60d870f3809e8e4403dLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="5bb3b60d870f3809e8e4403dLabel">whatever</h5>
</div>
<div class="modal-body"></div>
<div class="modal-footer"></div>
</div>
</div>
</div>
As you can see, my data target and div id are matching, I also tried to remove the aria-labelledby and aria-hidden, if I use the browser inspector I can see that the modal is already loaded. I also can successfully use the getElementById using my modal id.
I'm sorry that this is a noob mistake, but I already wasted a whole day trying to solve it. I get no exception, nor error, nor any view of the modal.
#David Liang was right, since I'm loading my table dynamically it didn't works.
To solve it using JQuery delegation I just needed to:
$("#rastreioTable tbody").on('click', 'button', function (event) {
$("#" + this.id + "modal").modal();
});
Where "rastreioTable" was my table Id and "tbody" was the element where the rows where being loaded. As far as I could understand the issue is that when we add a new item or modify an html element you broke the event handlers that were loaded initially.
If it was to be solved with vanilla JS an event listener would solve it, something like the code below:
document.getElementById("rastreioTable").addEventListener('click', function (e) {
if (e.target.type == "button") {
$("#" + e.target.id + "modal").modal();
}
}, false);
Here I would also need to add an if to check if the item pressed is a button, because the event would be triggered if the user clicked anywhere in the table.

NON JS youtube popup (plain html?)

Does anybody know of a non Javascript youtube video pop up. I have a button on my homepage which I want to open a pop up with a youtube video inside.
Thanks guys
this is my link
<span class="cta floatL">through the eyes of a bigsmile advert</span><span class="playIco floatL"></span>
this is my iframe
<iframe width="420" height="345" src="<iframe width="420" height="345" src="http://www.youtube.com/embed/krlR2-YGk4sI?autoplay=1" frameborder="0" allowfullscreen></iframe>" frameborder="0" allowfullscreen></iframe>'
I just need to find a way to make it pop up in the center of the screen like a fancybox, without javascript. Thanks guys
no i dont think there is a method without using JS but it is very simple with JS for a piece like this. you should just be able to place the popup in a div and then use CSS to make it hidden then on the button click a JS function that will bring it to the top.
Hope this helps :)
<div id='PopUp' style='display:none;'>
<iframe></iframe>
</div>
<button onclick='showPopUp()'>click Me</button>
<script>
function showPopUp()
{
document.getElementById('PopUp').style.display = 'block';
}
</script>

custom close button for youtube popup

I have a youtube video pop up that works well but I want to include a custom close button. I have done research but this has all come to nothing so I am hoping my stack buddies can help.
What I am estmiating from your question is you want a custom close button to close the DIV or iframe that your YouTube videos are in. I suggest jQuery for this:
$(function(){
$(".closeBtn").click(function(){
$($(this).data("target")).hide();
});
});
Then in the HTML:
<div class="video" id="v1">
<div class="closeBtn" data-target="#v1"></div>
<iframe></iframe>
</div>
JS Fiddle
What the data-target (data-target="#v1") does is target the ID of the div (<div class="video" id="v1">) then in jQuery, adding the animation effect .hide() , .fadeOut(500) to the ID.

Bootstrap Modals misbehaving

I'm trying to add a BootStrap modal to an already-existing page and I'm running into the following problem:
The modal displays exactly as I would expect it to, content in place looking quite beautiful but I have two problems. If I specify only class="modal" the modal displays by default when the page loads and will not close. If I include class="modal hide" then the modal does not display at page load but also doesn't close when the appropriate buttons are clicked.
I'm not making any big departures from the modals sample code on the Bootstrap site, any ideas what's going wrong?
Here's the button that's supposed to launch the modal:
<a class="btn" data-toggle="modal" href="#testmodal" >About</a>
And here's the modal itself:
<div class="modal hide fade in" id="testmodal">
<div class="modal-header">
<button class="close" data-dismiss="modal">x</button>
<h3>Modal Header</h3>
</div>
<div class="modal-body">
<p>body</p>
</div>
<div class="modal-footer">
Close
</div>
</div>
And for the record, yes I did remember to include bootstrap-modal.js and bootstrap-transition.js
Glad your problem is resolved.
Also if you want the default bootstrap functionality without customizing anything just use the big download button on the main page. This zip file contains a default bootstrap.min.js file that includes all the plugins (like the modal dialogs etc). If you use that one instead of all the seperate javascript files your page has to make less requests and load faster.
your close link should be like this:
<a class="close" data-dismiss="modal">×</a>
since, data-dismiss is a custom HTML5 data attribute. Here it is used to close the modal window.