2014-01-14 120 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上獲得「示例加載」消息)。

我在做什麼錯?

回答