如何在 Drupal 8 上重置 Bootstrap 4 工具提示?

如何解决如何在 Drupal 8 上重置 Bootstrap 4 工具提示?

我有 2 个网站:

  • 使用 Bootstrap 5 的静态网站。
  • 使用 Bootstrap 4 的 Drupal 8 站点。

我的问题与我之前的问题有关:

How does the text of the tooltip change when the button is clicked?

答案适用于 Bootstrap 5,但我在使用 Drupal 8 和 Bootstrap 4 的控制台中出现错误。

我认为tooltip的初始化不正确。

我该如何解决这个问题?这是用于 Bootstap 5 的代码和 Bootstrap 4 的改编版。

我刚刚将 data-bs-original-title 更改为 data-original-title

我也修改了tooltip.js文件的代码

引导程序 5

工具提示.js

var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
  return new bootstrap.Tooltip(tooltipTriggerEl)
})

btn-clipboard.js

(function (doc,clip,boot) {

  var tooltipShareButton = doc.getElementById('btn-clipboard-share');
  var tooltipShare = new boot.Tooltip(tooltipShareButton);
  var clipboardShare = new clip('#btn-clipboard-share',{
    container: doc.getElementById('modal-share')
  });

  clipboardShare.on('success',function(e) {      
    function restoreTitle(e) {
      tooltipShare.hide();
      tooltipShareButton.setAttribute('data-bs-original-title','Copier le lien');
      tooltipShareButton.removeEventListener('mouseleave',restoreTitle);
    }
    tooltipShareButton.setAttribute('data-bs-original-title','Lien copié');
    tooltipShare.update();
    tooltipShare.show();
    tooltipShareButton.addEventListener('mouseleave',restoreTitle);
  });

  clipboardShare.on('error',function(e) {
    tooltipShareButton.setAttribute('data-bs-original-title','Erreur');
    function restoreTitle(e) {
      tooltipShareButton.setAttribute('data-bs-original-title',restoreTitle);
    }
    tooltipShare.update();
    tooltipShare.show();
    tooltipShareButton.addEventListener('mouseleave',restoreTitle);
  });

  var tooltipDonationButton = doc.getElementById('btn-clipboard-donation');
  var tooltipDonation = new boot.Tooltip(tooltipDonationButton);
  var clipboardDonation = new clip('#btn-clipboard-donation',{
    container: doc.getElementById('modal-donation')
  });

  clipboardDonation.on('success',function() {
    function restoreTitle() {
      tooltipDonation.hide();
      tooltipDonationButton.setAttribute('data-bs-original-title',"Copier ladresse");
      tooltipDonationButton.removeEventListener('mouseleave',restoreTitle);
    }
    tooltipDonationButton.setAttribute('data-bs-original-title','Adresse copiée');
    tooltipDonation.hide();
    tooltipDonation.update();
    tooltipDonation.show();
    tooltipDonationButton.addEventListener('mouseleave',restoreTitle);
  });

  clipboardDonation.on('error',function(e) {
    function restoreTitle(e) {
      tooltipDonation.hide();
      tooltipDonationButton.setAttribute('data-bs-original-title','Copier ladresse');
      tooltipDonationButton.removeEventListener('mouseleave','Erreur');
    tooltipDonation.hide();
    tooltipShare.update();
    tooltipShare.show();
    tooltipDonationButton.addEventListener('mouseleave',restoreTitle);
  });

}(document,ClipboardJS,bootstrap));

引导程序 4

enter image description here

工具提示.js

(function ($) {

  $(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();
  });

})(jQuery);

btn-clipboard.js

(function (doc,function(e) {      
    function restoreTitle(e) {
      tooltipShare.hide();
      tooltipShareButton.setAttribute('data-original-title',restoreTitle);
    }
    tooltipShareButton.setAttribute('data-original-title',function(e) {
    tooltipShareButton.setAttribute('data-original-title','Erreur');
    function restoreTitle(e) {
      tooltipShareButton.setAttribute('data-original-title',function() {
    function restoreTitle() {
      tooltipDonation.hide();
      tooltipDonationButton.setAttribute('data-original-title',restoreTitle);
    }
    tooltipDonationButton.setAttribute('data-original-title',function(e) {
    function restoreTitle(e) {
      tooltipDonation.hide();
      tooltipDonationButton.setAttribute('data-original-title',bootstrap));

解决方法

按照您使用 ClipboardJS 使用 Bootstrap 的工具提示复制模态按钮内容的方式,以显示复制到剪贴板在您提供的 Bootstrap 5 示例中成功,我已经复制了 Bootstrap 4 的功能.

虽然 Bootstrap 5 具有工具提示功能作为 Bootstrap 的 JavaScript 的一部分,但 Bootstrap 4 扩展了 jQuery 来处理工具提示功能,所以我用 jQuery 函数替换了工具提示的 Bootstrap 5 实例。

(function ($,doc,clip) {
    var $shareBtn = $("#btn-clipboard-share");
    var $donateBtn = $("#btn-clipboard-donation");
    var clipboardShare;
    var clipboardDonation;

    // Initialize tooltips
    $shareBtn.tooltip();
    $donateBtn.tooltip();

    clipboardShare = new clip("#btn-clipboard-share",{
        container: doc.getElementById("modal-share")
    });

    clipboardShare.on("success",function () {

        function restoreTitle() {
            $shareBtn.tooltip("hide");
            $shareBtn.attr("data-original-title","Copier l'adresse");
            $shareBtn.off("mouseleave.clipboard",restoreTitle);
        }

        $shareBtn.attr("data-original-title","Lien copié");
        $shareBtn.tooltip("update");
        $shareBtn.tooltip("show");
        $shareBtn.on("mouseleave.clipboard",restoreTitle);
    });

    clipboardShare.on("error","Erreur");
        $shareBtn.tooltip("update");
        $shareBtn.tooltip("show");
        $shareBtn.on("mouseleave.clipboard",restoreTitle);
    });

    clipboardDonation = new clip("#btn-clipboard-donation",{
        container: doc.getElementById("modal-donation")
    });

    clipboardDonation.on("success",function () {

        function restoreTitle() {
            $donateBtn.tooltip("hide");
            $donateBtn.attr("data-original-title","Copier l'adresse");
            $donateBtn.off("mouseleave.clipboard",restoreTitle);
        }

        $donateBtn.attr("data-original-title","Adresse copiée");
        $donateBtn.tooltip("update");
        $donateBtn.tooltip("show");
        $donateBtn.on("mouseleave.clipboard",restoreTitle);
    });

    clipboardDonation.on("error","Erreur");
        $donateBtn.tooltip("update");
        $donateBtn.tooltip("show");
        $donateBtn.on("mouseleave.clipboard",restoreTitle);
    });
}(jQuery,document,ClipboardJS));
<link href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js"></script>

<div class="container d-flex justify-content-center mt-5">
    <!-- Buttons triggering modals -->
    <button type="button" class="btn btn-outline-success mr-3" data-toggle="modal" data-target="#modal-share">
        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-share" viewBox="0 0 16 16">
            <path d="M13.5 1a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zM11 2.5a2.5 2.5 0 1 1 .603 1.628l-6.718 3.12a2.499 2.499 0 0 1 0 1.504l6.718 3.12a2.5 2.5 0 1 1-.488.876l-6.718-3.12a2.5 2.5 0 1 1 0-3.256l6.718-3.12A2.5 2.5 0 0 1 11 2.5zm-8.5 4a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm11 5.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z"></path>
        </svg> Partager
    </button>

    <button type="button" class="btn btn-outline-success ml-3" data-toggle="modal" data-target="#modal-donation">
        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-suit-heart-fill" viewBox="0 0 16 16">
            <path d="M4 1c2.21 0 4 1.755 4 3.92C8 2.755 9.79 1 12 1s4 1.755 4 3.92c0 3.263-3.234 4.414-7.608 9.608a.513.513 0 0 1-.784 0C3.234 9.334 0 8.183 0 4.92 0 2.755 1.79 1 4 1z"></path>
        </svg> Faire un don
    </button>

    <!-- Modals -->
    <div class="modal fade show" id="modal-share" tabindex="-1" aria-labelledby="partager" aria-hidden="true" aria-modal="true" role="dialog">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="partager">Partager cette page</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <p class="text-justify">Lorem ipsum dolor sit amet consectetur adipisicing elit. Numquam expedita consectetur laudantium iusto necessitatibus minima.</p>
                    <button id="btn-clipboard-share" class="btn btn-outline-dark btn-sm w-100" data-toggle="tooltip" data-placement="top" title="" data-clipboard-text="https://www.example.com/fr/groupe/le-blog" data-original-title="Copier l'adresse">
                        https://www.example.com/fr/groupe/le-blog
                        <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" class="bi bi-clipboard" viewBox="0 0 16 16">
                            <path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"></path>
                            <path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"></path>
                        </svg>
                    </button>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade show" id="modal-donation" tabindex="-1" aria-labelledby="donation" aria-hidden="true" aria-modal="true" role="dialog">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="donation">Faire un don</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="message-donation">
                        <p class="text-justify">Si le contenu de ce groupe vous plaît,vous pouvez faire un don à son l'auteur en Bitcoin (BTC).</p>
                        <p class="mb-3"><a href="https://www.example.com/btc/address/1A5GqrNbpo7xwurpt1VQVvcA5yzoEcgaFvff" rel="nofollow" target="_blank">Voir les transactions sur la Blockchain</a></p>
                        <h5>Adresse BTC :</h5>
                        <p><img class="img-fluid" src="https://via.placeholder.com/300x300.png?text=QR%20Code" alt="Sample QR Code">
                        </p>
                        <button id="btn-clipboard-donation" class="btn btn-outline-dark btn-sm text-break" data-toggle="tooltip" data-placement="top" title="" data-clipboard-text="1A5GqrNbpo7xwurpt1VQVvcA5yzoEcgaFvff" data-original-title="Copier l'adresse">
                            1A5GqrNbpo7xwurpt1VQVvcA5yzoEcgaFvff
                            <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" class="bi bi-clipboard" viewBox="0 0 16 16">
                                <path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"></path>
                                <path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"></path>
                            </svg>
                        </button>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
</div>

我确实对代码进行了匿名化处理,使用 example.com 代替了您的 URL,用灰色图像替换了二维码,并替换了地址哈希。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res