7 function xul_createappendchild (node, childtype, attributes)
9 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
10 var child = document.createElementNS (XUL_NS, childtype);
12 for (i = 0, j = 1; j < attributes.length; i+=2, j+=2)
15 child.setAttribute (attributes[i], attributes[j]);
17 node.appendChild (child);
22 /// XUL DOM Menu Procedures
24 /// (layer: xuldommenu
27 function add_submenu (menu, id, label, key)
29 return xul_createappendchild (menu, "menu", ["id", id, "label", label, "accesskey", key]);
32 function add_menupopup (menu)
34 return xul_createappendchild (menu, "menupopup", []);
37 function add_menuitem (menu, id, label, key, oncommand)
39 return xul_createappendchild (menu, "menuitem", ["id", id, "label", label, "accesskey", key, "oncommand", oncommand]);
42 function add_menuseparator (menu, id)
44 return xul_createappendchild (menu, "menuseparator", ["id", id]);
57 function node_mathml_p (node)
59 const NS_MathML = "http://www.w3.org/1998/Math/MathML";
60 if ((node.nodeType == Node.TEXT_NODE && // JJF: where is Node.TEXT_NODE defined? outer space?
61 node.parentNode.namespaceURI == NS_MathML)
62 || (node.namespaceURI == NS_MathML))
68 function text_selected_p () {
69 return (document.commandDispatcher.focusedWindow.getSelection().toString().length > 0);
73 function content_selected_p () {
74 return !document.commandDispatcher.focusedWindow.getSelection().isCollapsed;
79 function image_node_p (node)
81 if (node instanceof Components.interfaces.nsIImageLoadingContent && node.currentURI)
86 function image_node_loaded_p (node)
88 var request = node.getRequest (Components.interfaces.nsIImageLoadingContent.CURRENT_REQUEST);
89 if (request && (request.imageStatus & request.STATUS_SIZE_AVAILABLE))
94 function image_node_url_spec (node)
96 return node.currentURI.spec;
99 function image_standalone_p (node)
101 if (node.ownerDocument instanceof ImageDocument)
106 function html_input_node_p (node)
108 return node instanceof HTMLInputElement;
112 function html_textarea_node_p (node)
114 return node instanceof HTMLTextAreaElement;
118 function html_html_node_p (node)
120 return node instanceof HTMLHtmlElement;
124 function textbox_node_p (node)
126 // JJF: I'm not quite sure why password inputs count as textboxes, but
127 // this is right out of firefox.
128 if (node instanceof HTMLInputElement)
129 return (node.type == "text" || node.type == "password");
131 return (node instanceof HTMLTextAreaElement);
135 function keyword_field_node_p (node)
137 // JJF: this is out of firefox.. not quite sure yet what it's useful for.
138 var form = node.form;
141 var method = form.method.toUpperCase();
143 // These are the following types of forms we can create keywords for:
145 // method encoding type can create keyword
149 // POST application/x-www-form-urlencoded YES
150 // POST text/plain NO (a little tricky to do)
151 // POST multipart/form-data NO
152 // POST everything else YES
153 return (method == "GET" || method == "") ||
154 (form.enctype != "text/plain") && (form.enctype != "multipart/form-data");
158 function xul_node_p (node) {
159 const xulNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
160 return (node.namespaceURI == xulNS);
164 function url_saveable_p (url_s) {
165 var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
167 try { uri = ioService.newURI (url_s, null, null); }
168 catch (ex) { return false; }
169 var protocol = uri.scheme; // can be |undefined|
170 return protocol && !(protocol == "mailto" ||
171 protocol == "javascript" ||
172 protocol == "news" ||
173 protocol == "snews" );
177 function metadata_item_p (node) {
178 // a metadata_item is an item for which, in firefox, you can view the
179 // Properties window.
180 return image_node_p (node) ||
181 ( (node instanceof HTMLAnchorElement && node.href) ||
182 node instanceof HTMLAreaElement ||
183 node instanceof HTMLLinkElement ||
184 node.getAttributeNS( "http://www.w3.org/1999/xlink", "type") == "simple" ) ||
185 ( ( node instanceof HTMLQuoteElement && node.cite) ||
186 ( node instanceof HTMLTableElement && node.summary) ||
187 ( node instanceof HTMLModElement &&
188 ( node.cite || node.dateTime ) ) ||
189 ( node instanceof HTMLElement &&
190 ( node.title || node.lang ) ) ||
191 node.getAttributeNS(XMLNS, "lang") );
195 // Returns a "url"-type computed style attribute value, with the url() stripped.
196 function get_computed_url (elem, prop) {
197 var url = elem.ownerDocument.defaultView.getComputedStyle (elem, '').getPropertyCSSValue (prop);
198 return (url.primitiveType == CSSPrimitiveValue.CSS_URI) ? url.getStringValue () : null;
202 // Generate fully qualified URL for clicked-on link.
203 function get_link_url (node) {
204 var href = node.href;
210 var href = node.getAttributeNS("http://www.w3.org/1999/xlink",
213 if (!href || !href.match(/\S/)) {
214 throw "Empty href"; // Without this we try to save as the current doc, for example, HTML case also throws if empty
216 href = makeURLAbsolute (node.baseURI, href);
221 function get_link_uri (linkURL) {
222 var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
224 return ioService.newURI(linkURL, null, null);
226 // e.g. empty URL string