0
votes

I have a Google Chrome extension that opens a Twitter Bootstrap dialog (using JQuery 1.7.x, but not JQueryUI) from a context menu item click, and I've been trying to do the same thing in the Firefox version (using Add-on SDK 1.6), to no avail.

I can intercept the menu item clicks OK in my lib/main.js, using context-menu, but I can't get a message to the content script (see https://stackoverflow.com/a/8493844/954442) which contains the function that creates the dialog DOM and that displays it. Nor can I create the dialog from my add-on script because there's no DOM there (and attempting to load JQuery into that via @mozilla.org/moz/jssubscript-loader;1 fails with "window is not defined")

I've looked far and wide for examples, but haven't found much that helps. Has anyone got an example of a context-menu Item click opening a dialog?

(What are the advantages/disadvantages of using the Add-on SDK to develop my Firefox extension? is the nearest thing I've found to my issue. I get the impression the poster found an answer eventually, but didn't update the question to say what it was.)

(NB. I'm not prepared to consider XUL, and very reluctant to go back to JQueryUI)

1
Let me understand: you want to add a context item and when the item is clicked display a "DOM made" panel/dialog in the current page. Is that correct? Notice that you don't have DOM in your add-on code, BUT you have DOM in a content script attached to the page.ZER0
In short, yes. I get the menu clicks already in the add-on script, but need to be able to call the content script to insert my dialog into the content DOM.Andrew Regan

1 Answers

0
votes

Ok, so I believe you want to do something like that:

https://builder.addons.mozilla.org/addon/1049738/latest/

Basically you add a contentScriptFile property to your context-menu's Item. A content script doesn't share the js variable with the page, however can access to the DOM. So you can add your panel and display it when the context-menu item is clicked.

Notice that you can pass to contentScriptFile multiple files using an Array, so you can load jQuery as well in this way.

Hope it helps.