The methods used by extensions is being updated
for the next release as follows. The spellBound_useNode function
is the only one that I know of being used by another extension and
is for all practical purposes frozen whereas the other methods
have been changed to provide additional functionality and to
simplify the code to support it.
The following code is pretty straightforward and has already been
used by the QuickNote
extension to provide spell checking. It is best to use the
spellBound_useNode or spellBound_useNodeArray functions in most cases
since that is essentially the same mehod that is used when launched
under normal circumstances. Also, you can check the
spellbound.spellcheck.modal preference if you would like to respect
the user's settings on whether the dialog should be displayed
modally when using the spellBound_useNode, spellBound_useNodeArray
or spellbound_useEditor functions. If the pref is true or non-existant use
the modal parameter and if it is false just omit the modal parameter.
If you have any questions / comments / suggestions don't hesitate
to contact me by using the Contact form.
//Extension onload function function Ext_OnLoad() { etc... setupSpellBound(); etc... } function setupSpellBound() { // determine if spellbound is available // if not do nothing. if (typeof(Components. classes["@mozilla.org/spellbound;1"]) != "undefined") { // define the commandset, menu, and // keyset to use with spellbound const commandset_id = "ext_commands"; const keyset_id = "ext_keys"; const menu_id = "ext_menu"; // append spellbound command to existing commandset var parent = document.getElementById(commandset_id); var elem = document.createElement("command"); elem.setAttribute("id", "cmd_ExtSpellBound"); // you can pass a node such as a textbox, // textarea, input, editor, iframe in designMode, etc. elem.setAttribute("oncommand", "spellBound_useNode();"); // or you can pass an array of nodes //elem.setAttribute("oncommand", "spellBound_useNodeArray();"); // or you can pass an array of HTML and text with style information //elem.setAttribute("oncommand", "spellBound_useTextArray();"); // or if you want to check an editor element //elem.setAttribute("oncommand", "spellBound_useEditor();"); parent.appendChild(elem); // append spellbound stringbundle to // the parent of commandset elem = document.createElement("stringbundle"); elem.setAttribute("id", "sb_ExtSpellBound"); elem.setAttribute("src", "chrome://spellbound/locale/spellboundOverlay.properties"); parent.parentNode.appendChild(elem); var sb = document.getElementById("sb_ExtSpellBound"); // append spellbound key to existing keyset parent = document.getElementById(keyset_id); elem = document.createElement("key"); elem.setAttribute("id", "key_ExtSpellBound"); // the keycode may conflict with an accesskey for your // extension and may change per locale elem.setAttribute("keycode", sb.getString("editcheckspelling.keybinding")); elem.setAttribute("command", "cmd_ExtSpellBound"); elem.setAttribute("modifiers", "accel,shift"); parent.appendChild(elem); // append spellbound menuseparator to existing menu parent = document.getElementById(menu_id); elem = document.createElement("menuseparator"); parent.appendChild(elem); // append spellbound menuitem to existing menu elem = document.createElement("menuitem"); elem.setAttribute("id", "menu_ExtSpellBound"); elem.setAttribute("observes", "cmd_ExtSpellBound"); elem.setAttribute("label", sb.getString("checkSpellingCmd.label")); elem.setAttribute("key", "key_ExtSpellBound"); // the accesskey may conflict with an accesskey for // your extension and may change per locale elem.setAttribute("accesskey", sb.getString("editcheckspelling.accesskey")); elem.setAttribute("command", "cmd_ExtSpellBound"); parent.appendChild(elem); } } function spellBound_useNode() { var node = document.getElementById("nodeId"); var args = []; args[0] = node; var params = "chrome,close,titlebar,modal"; var pref = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); try { if (pref.getBoolPref("spellbound.spellcheck.modal") == false); params = "chrome,close,titlebar"; } catch (e) { } window.openDialog( "chrome://spellbound/content/SBSpellCheck.xul", "_blank", params, false, false, true, args); } function spellBound_useNodeArray() { var node0 = document.getElementById("nodeId1"); var node1 = document.getElementById("nodeId2"); var args = []; var nodes = []; nodes.push(node0); nodes.push(node1); args[0] = nodes; var params = "chrome,close,titlebar,modal"; var pref = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); try { if (pref.getBoolPref("spellbound.spellcheck.modal") == false); params = "chrome,close,titlebar"; } catch (e) { } window.openDialog( "chrome://spellbound/content/SBSpellCheck.xul", "_blank", params, false, false, true, args); } // helper function for spellBound_useTextArray function spellBound_params(sType, sBody, sHead) { this.__type = sType; // must equal text/plain or text/html this.__body = sBody; // text or html to spellcheck this.__head = sHead; // this can be null this.__retval = null; // this will be the return value... // if nothing was modified this will be null } function spellBound_useTextArray() { var node0 = document.getElementById("nodeId1"); var node1 = document.getElementById("nodeId2"); var node2 = document.getElementById("nodeId3"); var args = []; // span[_moz_misspelled='true'] only applies to text/plain and the // user's settings will be used unless they are supplied as shown below var style0 = "<style type='text/css'>\n" + "body { background-color:#000080; color:#ffffff; }\n" + "span[_moz_misspelled='true'] { color:#ff0000;\n" + "background:#000000 " + "url(chrome://spellbound/skin/underlines/ff0000.gif; }\n" + "</style>"; var style1 = "<style type='text/css'>\n" + "body { background-color:#000080; color:#ffffff; }\n" + "</style>"; args.push(new spellBound_params("text/plain", node0.value, style0); args.push(new spellBound_params("text/html", node1.innerHTML, style1); args.push(new spellBound_params("text/plain", node2.value, null); // modal must be used when using spellBound_useTextArray window.openDialog( "chrome://spellbound/content/SBSpellCheck.xul", "_blank","chrome,close,titlebar,modal", false, false, true, args); // if __retval is null then the output is the same as the input if (args[0].__retval) node0.value = args[0].__retval; // in some cases you may need to use createElement etc. instead of innerHTML if (args[1].__retval) node1.innerHTML = args[1].__retval; if (args[2].__retval) node2.value = args[2].__retval; } function spellBound_useEditor() { var params = "chrome,close,titlebar,modal"; var pref = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); try { if (pref.getBoolPref("spellbound.spellcheck.modal") == false); params = "chrome,close,titlebar"; } catch (e) { } window.openDialog( "chrome://spellbound/content/SBSpellCheck.xul", "_blank", params, false, false, true); }
Misspelled word underline colors
The following hex colors can be used when specifying the background-image for the underlining of misspelledwhen using the spellbound_useTextArray function above with __type set to text/plain. Just remove the # and make sure it is all in lowercase. It is not possible to specify an underline image when using any of the other functions since underlines are not displayed when checking HTML and the other methods use the user defined preferences.#ffffff, #ffcccc, #ffcc99, #ffff99, #ffffcc, #99ff99, #99ffff, #ccccff, #ccffff, #ffccff, #cccccc, #ff6666, #ff9966, #ffff66, #ffff33, #66ff99, #33ffff, #66ffff, #9999ff, #ff99ff, #c0c0c0, #ff0000, #ff9900, #ffcc66, #ffff00, #33ff33, #66cccc, #33ccff, #6666cc, #cc66cc, #999999, #cc0000, #ff6600, #ffcc33, #ffcc00, #33cc00, #00cccc, #3366ff, #6633ff, #cc33cc, #666666, #990000, #cc6600, #cc9933, #999900, #009900, #339999, #33ffff, #6600cc, #993399, #333333, #660000, #993300, #996633, #666600, #006600, #336666, #000099, #333399, #663366, #000000, #330000, #663300, #663333, #333300, #003300, #003333, #000066, #330099, #330033
Copyright © 2004-2005 Robert Strong All rights reserved
Valid XHTML 1.1 served as text/html - Page Last Updated: Apr. 16, 2005
Valid XHTML 1.1 served as text/html - Page Last Updated: Apr. 16, 2005