简体   繁体   中英

firefox extension with jquery and qtip

I just found this great post here on stackoverflow, which explains how to use jquery within a firefox extension and which also works great for me. But I have to do a bit more than that, because I need to make a tooltip. For this I also included the qtip2 library:

<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>

My example.js looks like this now:

(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);

})();

So basically I just added to the post on stackoverflow this:

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

But sadly the links on a page do not have a tooltip on them with that change. Note that the functionality of the initial post on stackoverflow works for me (I get the "Example loaded" message on stackoverflow.com).

What am I doing wrong?

因此,我只是被告知了一种使用Firefox插件中的工具提示来解决问题的更简便,更优雅的方法: https : //developer.mozilla.org/en-US/docs/XUL/panel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM