簡體   English   中英

工具提示突然不起作用

[英]Tooltipster suddenly not working

我一直在為我正在構建的需要工具提示的網站使用jQuery插件。 在將鼠標懸停時,工具提示使用AJAX提供數據,並且一切正常,直到我為項目添加了工具提示部分。 添加代碼並保存后,我注意到工具提示和某些jQuery元素不再起作用(xbbcode插件也停止了工作,但是引導程序,顏色選擇器和放大仍然可以正常工作)。

我回去刪除了代碼,看看我在那兒做錯了什么,但錯誤仍然存​​在! 除了附加的工具提示外,我沒有進行任何其他更改,因此我不明白為什么突然之間現在不起作用。 這是使用的代碼,包括我嘗試添加的項目工具提示(在底部定位.item )。

$(document).ready(function() {

// Retrieve stored data
var bannerData = amplify.store("banner");
var haData = amplify.store("ha");
var petData = amplify.store("pet");

if (bannerData === true) {
    $('#banner').addClass('hidden');
    $('#banner-collapse').text("Expand [+]");
}

if (haData === true) {
    $('#ha').addClass('hidden');
    $('#collapse-ha').text("Expand Avatar [+]");
}

if (petData === true) {
    $('#pet').addClass('hidden');
    $('#collapse-pet').text("Expand Pet [+]");
}

// Section collapse
$('#banner-collapse').click(function () {
    if (bannerData === true) {
        $('#banner').slideToggle(function () {
            $(this).removeClass("hidden");
        });

        amplify.store("banner", null);
        $(this).text(function(i, text) {
            return text === "Expand [+]" ? "Collapse [-]" : "Expand [+]";
        });
    }

    else {
        $('#banner').slideToggle();
        amplify.store("banner", true);
        $(this).text(function (i, text) {
            return text === "Collapse [-]" ? "Expand [+]" : "Collapse [-]";
        });
    }
});

// Avatar Collapse
$('#collapse-ha').click(function () {
    if (haData === true) {
        $('#ha').slideToggle(function () {
            $(this).removeClass("hidden");
        });

        amplify.store("ha", null);
        $(this).text(function(i, text) {
            return text === "Expand Avatar [+]" ? "Collapse Avatar [-]" : "Expand Avatar [+]";
        });
    }

    else {
        $('#ha').slideToggle();
        amplify.store("ha", true);
        $(this).text(function (i, text) {
            return text === "Collapse Avatar [-]" ? "Expand Avatar [+]" : "Collapse Avatar [-]";
        });
    }
});

// Pet Collapse
$('#collapse-pet').click(function () {
    if (petData === true) {
        $('#pet').slideToggle(function () {
            $(this).removeClass("hidden");
        });

        amplify.store("pet", null);
        $(this).text(function(i, text) {
            return text === "Expand Pet [+]" ? "Collapse Pet [-]" : "Expand Pet [+]";
        });
    }

    else {
        $('#pet').slideToggle();
        amplify.store("pet", true);
        $(this).text(function (i, text) {
            return text === "Collapse Pet [-]" ? "Expand Pet [+]" : "Collapse Pet [-]";
        });
    }
});

//Formats date
var now = moment().format("dddd, MMMM Do, <b>h:mm A</b>");
$('#date').append(now);

// Tooltips
$('.tooltip-ha').tooltipster({
    animation: 'grow',
    delay: 200,
    trigger: 'hover',
    position: 'right',
    contentAsHTML: true,
    functionInit: function(origin, content) {
        // when the request has finished loading, we will change the tooltip's content
        $.ajax({
            type: 'GET',
            url: '/haTooltip',
            success: function(data) {
                origin.tooltipster('content', data);
            }
        });

        // this returned string will overwrite the content of the tooltip for the time being
        return 'Wait while we load new content...';

    }
});

$('.tooltip').tooltipster({
    animation: 'grow',
    delay: 200,
    trigger: 'hover',
    position: 'right',
    contentAsHTML: true,
    functionInit: function(origin, content) {
        // when the request has finished loading, we will change the tooltip's content
        $.ajax({
            type: 'GET',
            url: '/petTooltip',
            success: function(data) {
                origin.tooltipster('content', data);
            }
        });

        // this returned string will overwrite the content of the tooltip for the time being
        return 'Wait while we load new content...';

    }
});

$('.item').tooltipster({
    animation: 'grow',
    delay: 200,
    trigger: 'hover',
    position: 'right',
    contentAsHTML: true,
    functionInit: function(origin, content) {
        // when the request has finished loading, we will change the tooltip's content
        $.ajax({
            type: 'GET',
            url: '/itemTooltip',
            success: function(data) {
                origin.tooltipster('content', data);
            }
        });

        // this returned string will overwrite the content of the tooltip for the time being
        return 'Wait while we load new content...';

    }
});
});

我在這里看不到任何可見的錯誤,我將所有插件腳本都放在一個文件中,並進行了最小化以最大程度地減少加載時間,但是在試圖弄清楚為什么xbbcode和tooltipster突然不起作用時,我繼續進行並重新下載了單獨的版本。 通常,在這種情況下,我懷疑工具提示和xbbcode之間存在某種兼容性錯誤,但是在添加工具提示項之前,它們工作得很好,當我臨時刪除xbbcode以查看工具提示是否可以再次開始工作時,結果是相同。

你有幾個問題。

關於xbbcode

您似乎已經刪除了實際上初始化XBBCODE的Javascript調用。

將以下內容添加到您的JavaScript中可以解決該問題:

   $('.bbcode').each(function(){
       var $this = $(this);
       var myText = $this.html();
       var result = XBBCODE.process({
            text: myText
        }); 
       $this.html(result.html);
   });

關於工具提示

  1. 您需要包含可在此處下載的CSS文件
  2. 將您的初始化代碼更改為此:

  $('.item').tooltipster({
        content: 'Loading...',
        updateAnimation: false,
        functionBefore: function(origin, continueTooltip) {
            continueTooltip();

            if (origin.data('ajax') !== 'cached') {

                // when the request has finished loading, we will change the tooltip's content
            $.ajax({
                type: 'POST', 
                url: 'http://dodsoftware.com/sotests/xbbcode/itemTooltip', // change to your file location
                success: function(data) {
                    origin.tooltipster('content', data);
                },
                error: function(jqXHR, textStatus, errorThrown) {
                     console.log(textStatus, errorThrown);
                }
            });
                origin.data('ajax', 'cached');
            }
        }
    });

我沒有受過教育,認為帶有“ item”類的對象對工具提示無效。

如果我知道HTML代碼,我將能夠做出更好的猜測。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM