Back to XUL: Completing the JavaScript Logic - Finishing up the Functions
(Page 6 of 6 )
As you can see it isn’t as good as standard parameter passing, in which case any value can be used as a parameter, but it works in its own quirky kind of way and saves some code (somewhere) too. Add the code for the other two insert functions:
function insert2(str) {
var str1 = '<radiogroup> <radio id="" label=""/> </radiogroup>';
var str2 = '<window id="" title="" height="" width="" xmlns="http://www.mozilla.org/keymaster/gatekeeper/
there.is.only.xul"/> </window>';
var str3 = '<wizard id="" title="" xmlns="http://www.mozilla.org/keymaster/gatekeeper/
there.is.only.xul"> <wizardpage> </wizardpage> </wizard>';
var str4 = '<editor id="" editortype="" type="" src=""/>';
var str5 = '<browser id="" homepage="" type=""/>';
var str6 = '<iframe id="" src=""/>';
var editor = document.getElementById('mainContent');
editor = editor.getEditor(editor.contentWindow).QueryInterface
(Components.interfaces.nsIPlaintextEditor);
if (str == menubar) {
editor.insertText(str1);
} else if (str == toolbar) {
editor.insertText(str2);
} else if (str == directories) {
editor.insertText(str3);
} else if (str == locationbar) {
editor.insertText(str4);
} else if (str == statusbar) {
editor.insertText(str5);
} else if (str == scrollbars) {
editor.insertText(str6);
}
}
function insert3(str) {
var str1 = '<titlebar id=""/>'
var editor = document.getElementById('mainContent');
editor = editor.getEditor(editor.contentWindow).QueryInterface
(Components.interfaces.nsIPlaintextEditor);
if (str == menubar) {
editor.insertText(str1);
}
}
The last curly brace above sees the end of the code required in the JavaScript file, but you still need to add calls to the insert() function to each of the menuitems, passing in one of the BarProp parameters, for example:
<menuitem id="buttonMenubar" label="&menubarLabel;"
oncommand="insert(menubar)"/>
With both the XUL and JS files saved, your application (version 1 at least) is complete. Now, it’s still a little buggy in places; the new file command (where we set the src of the editor to about:blank) only seems to work once for example. Overall however, I don’t think this is too much of a problem; look at the number of bugs in a Windows OS release!
This also now sees the end of this series on creating an application with XUL. I hope you’ve followed along with the tutorial and I hope that you haven’t had too many difficulties getting it to work. If this has just got your appetite for XUL going, please continue to build, adapt and refine the application; you can extend the program in any way you can think of by simply adding elements to the XUL file and functions to the script file and are limited only by the bounds of your imagination.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |