2016-11-24 53 views
0

我需要攔截Magento 2中Modal彈出窗口的「關閉」事件,但我不知道在哪裏以及如何做。攔截Magento 2中模態功能的事件

這是模板文件中的腳本,它工作的很好,但是,正如我寫的,我需要攔截關閉的事件來停止視頻播放。

<script> 
 
    require(
 
      [ 
 
       'jquery', 
 
       'Magento_Ui/js/modal/modal' 
 
      ], 
 
      function ($, modal) { 
 
       var options = { 
 
        type: 'popup', 
 
        responsive: true, 
 
        title: $.mage.__('Title Text'), 
 
        buttons: [{ 
 
          text: $.mage.__('Close'), 
 
          class: '', 
 
          click: function() { 
 
           this.closeModal(); 
 
           var video = document.getElementById("Video1"); 
 
           video.pause(); 
 
          } 
 
         }] 
 
       }; 
 
       var popup = modal(options, $('#modalVideo')); 
 
       $("#modalVideoOpen").on("click", function() { 
 
        $('#modalVideo').modal('openModal'); 
 
        var video = document.getElementById("Video1"); 
 
        video.play(); 
 
       }); 
 
      } 
 
    ); 
 
</script>

回答

3
$('#modalVideoOpen').data('mage-modal').modal.on('modalclosed', function(){console.log('closed')}) 

模態窗口小部件觸發「關閉」事件和jquery doc說:「事件類型是通過連接插件名稱和回調名稱決定」,我們應該訂閱的「 modalclosed」

0

,你還可以在選項中指定它:

var options = { 
    type: 'popup', 
    responsive: true, 
    title: $.mage.__('Title Text'), 
    close: function (e) { 
     // fun here! 
    } 
};