Search code examples
jqueryfancyboxbrightcove

jQuery FancyBox issue with Brightcove .addeventlistener function


Okay guys here's the problem i'm having, i have a video coming from brightcove and i have an event listener added from their api to close the fancybox 2.0 modal window after playback is completed. but the even listener is not happening because fancybox is duplicating the content from the div but not the javascript so the event listener is not being activated.

here is the code

   <!-- Start Brightcove API -->
   <script language="JavaScript" type="text/javascript" src="http://admin.brightcove.com/js/APIModules_all.js"></script>
   <script type="text/javascript">
       var bcExp;
       var modVP;
       function onTemplateLoaded(experienceID) {
           alert("EVENT: TEMPLATE_LOAD");
           bcExp = brightcove.getExperience(experienceID);
           modVP = bcExp.getModule(APIModules.VIDEO_PLAYER);
           modVP.addEventListener(
           BCMediaEvent.COMPLETE, 
           function(event) {
               alert("EVENT: Close Modal Activated");
               jQuery.fancybox.close(true);
           }
       );
       }

       /*   
       function onTemplateLoaded(experienceID) {
           alert("EVENT: TEMPLATE_LOAD");
           bcExp = brightcove.getExperience(experienceID);
           modVP = bcExp.getModule(APIModules.VIDEO_PLAYER);
           modVP.addEventListener(BCMediaEvent.COMPLETE, closeModal);
       }
       function closeModal(event) {
           alert("EVENT: Close Modal Activated");
           jQuery.fancybox.close(true);
       }
        */
   </script>
   <!-- End Brightcove API -->

Any ideas or solutions?


Solution

  • Thanks for the message but i actually figured it out it was a huge goof on my part I was calling fancybox like this

    jQuery.document().ready(function() { 
    if (document.location.hash === '#video') { 
    jQuery.fancybox.open([{ 
    content: jQuery('.video').html(), 
    

    the rest isnt important because thats what is breaking it the .html() but whatever glad its fixed now