带有jQuery和QTIP的Firefox扩展



我刚刚在stackoverflow上找到了这篇很棒的文章,它解释了如何在Firefox扩展中使用jquery,并且对我来说也很有用。但我必须做的不止这些,因为我需要制作一个工具提示。为此,我还包含了 qtip2 库:

<script type="application/x-javascript" src="chrome://extension/content/jquery-2.0.3.min.js"></script>
<script type="application/x-javascript" src="chrome://extension/content/jquery.qtip.min.js"></script>
<script type="application/x-javascript" src="example.js"></script>

我的例子.js现在看起来像这样:

(function() {
jQuery.noConflict();
$ = function(selector,context) { 
    return new jQuery.fn.init(selector,context||example.doc); 
};
$.fn = $.prototype = jQuery.fn;
example = new function(){};
example.log = function() { 
    Firebug.Console.logFormatted(arguments,null,"log"); 
};
example.run = function(doc,aEvent) {
     // Check for website
    if (!doc.location.href.match(/^http://(.*.)?stackoverflow.com(/.*)?$/i))  
        return;
    // Check if already loaded
    if (doc.getElementById("plugin-example")) return;
    // Setup
    this.win = aEvent.target.defaultView.wrappedJSObject;
    this.doc = doc;
    // Hello World
    this.main = main = $('<div id="plugin-example">').appendTo(doc.body).html('Example Loaded!');
    main.css({ 
        background:'#FFF',color:'#000',position:'absolute',top:0,left:0,padding:8
    });
    main.html(main.html() + ' - jQuery <b>' + $.fn.jquery + '</b>');

    //This is the part I added in addition to the post from stackoverflow:
    $('a').qtip({ // Grab some elements to apply the tooltip to
        content: {
            text: 'My common piece of text here'
        }
       });
};
// Bind Plugin
var delay = function(aEvent) { 
    var doc = aEvent.originalTarget; setTimeout(function() { 
        example.run(doc,aEvent); 
    }, 1); 
 };
var load = function() { 
    gBrowser.addEventListener("DOMContentLoaded", delay, true); 
};
window.addEventListener("pageshow", load, false);
})();

所以基本上我只是在堆栈溢出的帖子中添加了这个:

    $('a').qtip({ // Grab some elements to apply the tooltip to
        content: {
            text: 'My common piece of text here'
        }
       });

但遗憾的是,页面上的链接没有工具提示。请注意,堆栈溢出上初始帖子的功能对我有用(我在 stackoverflow.com 上收到"示例加载"消息)。

我做错了什么?

所以我

刚刚被告知一种更简单、更优雅的方式来解决 Firefox 插件中的工具提示问题:https://developer.mozilla.org/en-US/docs/XUL/panel

最新更新