Looking for Help on Message Passing and Program Structure
I am working on an addon that uses the context menu to modify selected text in an edit area I have some fairly basic questions on how to handle certain aspects of this.
This will seem fairly basic to a lot of people, but this is my first foray into extension writing and into Javascript programming.
Assume that the following text is in an edit box:
I will not buy this record, it is scratched
My hovercraft is full of eels
I have highlighted the word “full”.
The addon should proceed as follows:
- Select text and right click on menu item.
- This has the background script run a function, let’s call it “Moo”, sending a signal to the content script. The function argument in this would be something like Moo ("[b]",ZZSELECT,"[/b]");
- The content script calls a function which takes the content of the edit box, and reduces it to three variables, the text before the selection, the selected text, and the text after the selection. (I already have a javascript function which does break-up of the text running a web page. This leads to my first question, how do I send a signal to the content page that specifically invokes this function and not others on the page?
- The content script sends message back to the background script with these three variables. This is my next question, I cannot see from the documentation how to pass three variables back to the background script page and into function moo.
- The background script page takes these variables, along with other modifiers included in the case statement for the specific menu item, and creates a string, which is passed back to the content script of this form:
I will not buy this record, it is scratched
My hovercraft is [b]full[/b] of eels - The content script reads in this variable, and replaces the content of the edit box.
My questions are:
- What is the syntax for this message passing, the documentation leaves me clueless.
- Have I allocated the functions between the scripts properly?
Please note that I am operating from a position of deep and profound ignorance.