1

在Drupal的8,自举的主题,当你创建classdata-dialog-type属性像娄代码的链接:从链接添加自定义类,Drupal的模态的Drupal 8引导主题

<a class="use-ajax" data-dialog-type="modal" 
    href="http://drupal.page/front">text 
</a> 

您将打开

<div id="drupal-modal" class="modal fade in" tabindex="-1" role="dialog" style="display: block;"> 
    <div class="modal-dialog" role="document"> 
     <div class="modal-content"> 

中生成此结构:\themes\bootstrap\js\modal.js我们如何能在link看到具有这些HTML包装#drupal-modal元素的网页的内容。

如何修改它,以便我可以将类名称传递给链接a.use-ajax中的#drupal-modal元素?类名称文本可以是链接属性的值。

具体而言,我想添加modal-lgmodal-sm类或一些自定义类。

+0

http://stackoverflow.com/questions/10626885/passing-data-to-a-bootstrap-modal – Slime

回答

1

感谢@Waxi我已经通过其他问题阅读,我想出了这个:

$(document).on("mousedown", ".use-ajax", function() { 
    var modalClass = $(this).data('dialog-class'); 
    $(document).on('show.bs.modal','.modal', function() { 
     $('.modal-dialog',this).addClass("modal-" + modalClass); 
    }) 
}); 

只好用mousedown事件,怎么click因为它是由一些封锁是行不通的。 然后越来越的data-dialog-class,因此它可以模态实际加载后加入到.modal-dialog元素的含量,因为它的HTML是不存在之前

0

我的解决方案

HTML:

<a class="use-ajax" data-dialog-type="modal" href="#" data-dialog-class="your-class">Click me !</a> 

Javascript:

var modalClass; 

    $(document).on("mousedown", ".use-ajax", function() { 
     modalClass = $(this).data('dialog-class'); 
     $(document).on('show.bs.modal','.modal', function() { 
      $(this).addClass(modalClass); 
     }) 
    }); 

    // Add this part to remove the class when the modal is closed. 
    $(document).on('hide.bs.modal','.modal', function() { 
     $(this).removeClass(modalClass); 
    })