2 This file is used to allow external editors to work inside your chrome XUL.
4 ***** How To Use This API *****
5 Add this script line to your .xul file:
6 <script type="application/javascript" src="chrome://itsalltext/content/API.js"/>
8 If "It's All Text!" isn't installed in the browser, it will fail safely.
9 It only generates an info message in the error console.
11 You then have two choices. You can call ItsAllTextopenEditor() directly
12 via JavaScript or you can add one or two attributes to a XUL element and
13 it'll automatically be set up right.
15 The suggested method is to add the correct attributes to your XUL button
16 or menuitem and let "It's All Text!" do it for you.
19 'itsalltext-control' -- This should be set to the id of the textbox
20 that you want to edit when command is executed
21 on this XUL element. This is required.
22 'itsalltext-extension' -- This is the file extension. Include the
23 leading dot character. Example: '.css'
24 It defaults to '.txt' and is optional.
26 If you don't want this XUL element to be visible unless "It's All Text!"
27 is installed, then you should set it's CSS style display to 'none'.
29 Example using attributes (recommended method):
32 <button label="It's All Text!"
33 itsalltext-control="code"
34 itsalltext-extension=".css"
35 style="display: none;"
39 Example calling openEditor() directly:
40 if(some_condition && ItsAllText) {
41 ItsAllText.openEditor('id-of-textarea', '.extension');
47 /* Load up the main It's All Text! file */
48 var objScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
49 objScriptLoader.loadSubScript('chrome://itsalltext/content/itsalltext.js');
51 var onload = function (event) {
52 /* Start watching the document, but force it. */
53 ItsAllText.monitor.watch(document, true);
55 /* Turn on all the hidden CSS */
57 var nodesIter = document.evaluate("//node()[@itsalltext-control]",
59 XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
61 var node = nodesIter.iterateNext();
64 node = nodesIter.iterateNext();
66 var command = function(event) {
67 ItsAllText.openEditor( this.getAttribute("itsalltext-control"),
68 this.getAttribute("itsalltext-extension") );
73 node.addEventListener('command', command, true);
74 node.style.display = '-moz-box';
78 window.addEventListener("load", onload, true);
82 * This is part of the public XUL API.
83 * Use this to open an editor for a specific textarea or textbox with
84 * the id 'id'. The file will have the extension 'extension'. Include
85 * the leading dot in the extension.
86 * @param {String} id The id of textarea or textbody that should be opened in the editor.
87 * @param {String} extension The extension of the file used as a temporary file. Example: '.css' (optional)
89 ItsAllText.openEditor = function(id, extension) {
90 var node = document.getElementById(id);
91 /* The only way I can adjust the background of the textbox is
92 * to turn off the -moz-appearance attribute.
94 node.style.MozAppearance = 'none';
95 var cache_object = node && ItsAllText.getCacheObj(node);
96 if(!cache_object) { return; }
97 cache_object.edit(extension);