2014-01-14 86 views
0

我刚刚发现this很棒的帖子在这里stackoverflow,它解释了如何在Firefox扩展中使用jquery,这也很适合我。但我必须做更多的事情,因为我需要提供一个工具提示。为此,我还包括qtip2库:jquery和qtip的firefox扩展

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

我example.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上的初始职位的功能适用于我(我在stackoverflow.com上获得“示例加载”消息)。

我在做什么错?

回答