将使用jQuery的Chrome扩展移植到Firefox SDK插件 [英] Porting Chrome extension using jQuery to Firefox SDK Add-on
问题描述
我的Chrome扩展在后台页面中使用jQuery,用于像 将此代码迁移到 Firefox SDK插件,没有后台 jQuery.extend()
, jQuery.ajax() code>,
jQuery.deferred()
,(不是DOM操作的东西,在后台页面中没有意义)。 b
窗口
对象,jQuery需要工作,所以像
这就是jQuery在类CommonJS环境中的工作方式,失败了,jQuery本身抛出一个<$ jQuery需要一个带有文档异常的窗口。
有没有办法在基于Firefox SDK的add-上? 页面工作人员似乎很有希望,但我无法获取底层窗口
对象。
Andy
var {Cc,Ci} =要求 (铬);
_window = Cc [@ mozilla.org/appshell/appShellService;1]
.getService(Ci.nsIAppShellService)。hiddenDOMWindow;
$ = require('../ 3rdparty / jquery')(_ window);
然而,我不得不修补jQuery(2.1.3)本身,将行3441改为
window.setTimeout(jQuery.ready);
我相当有信心这是一个jQuery错误。
My Chrome extension makes use of jQuery in the background page, for things like jQuery.extend()
, jQuery.ajax()
, jQuery.deferred()
, (not DOM manipulation stuff, which doesn't make sense in a background page).
Migrating this code to a Firefox SDK Add-on, there's no background window
object, which jQuery requires to work, so something like
var $ = require('../3rdparty/jquery.min')(window);
which is how jQuery works in a CommonJS-like environment, fails, with jQuery itself throwing a jQuery requires a window with a document
exception.
Is there any way to use jQuery in a Firefox SDK-based add-on? Page Workers seemed promising, but I can't get hold of the underlying window
object.
Andy
This works:
var {Cc, Ci} = require("chrome");
_window = Cc["@mozilla.org/appshell/appShellService;1"]
.getService(Ci.nsIAppShellService).hiddenDOMWindow;
$ = require('../3rdparty/jquery')(_window);
However, I had to patch jQuery (2.1.3) itself, changing line 3441 to
window.setTimeout( jQuery.ready );
I'm reasonably confident this is a jQuery bug.
这篇关于将使用jQuery的Chrome扩展移植到Firefox SDK插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!