]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/help.jsm
Import r6923 from upstream hg supporting Firefox up to 22.0a1
[dactyl.git] / common / modules / help.jsm
index dadadfcd6993d2e78dd960a290fd91ca9762f2d4..a092ad5c8a71fc02de197919eda53dd9b58b6957 100644 (file)
@@ -1,17 +1,17 @@
-// Copyright (c) 2008-2011 by Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2008-2012 Kris Maglione <maglione.k@gmail.com>
 //
 // This work is licensed for reuse under an MIT license. Details are
 // given in the LICENSE.txt file included with this file.
-/* use strict */
+"use strict";
 
-Components.utils.import("resource://dactyl/bootstrap.jsm");
 defineModule("help", {
     exports: ["help"],
     require: ["cache", "dom", "protocol", "services", "util"]
-}, this);
+});
 
-this.lazyRequire("completion", ["completion"]);
-this.lazyRequire("overlay", ["overlay"]);
+lazyRequire("completion", ["completion"]);
+lazyRequire("overlay", ["overlay"]);
+lazyRequire("template", ["template"]);
 
 var HelpBuilder = Class("HelpBuilder", {
     init: function init() {
@@ -108,7 +108,7 @@ var Help = Module("Help", {
                                     { mimeType: "text/plain;charset=UTF-8" })
                            .responseText;
 
-            let re = util.regexp(UTF8(<![CDATA[
+            let re = util.regexp(UTF8(literal(/*
                   ^ (?P<comment> \s* # .*\n)
 
                 | ^ (?P<space> \s*)
@@ -124,7 +124,7 @@ var Help = Module("Help", {
                   )
 
                 | (?: ^ [^\S\n]* \n) +
-            ]]>), "gmxy");
+            */)), "gmxy");
 
             let betas = util.regexp(/\[((?:b|rc)\d)\]/, "gx");
 
@@ -132,11 +132,8 @@ var Help = Module("Help", {
                         .map(function (m) m[1]).uniq().slice(-1)[0];
 
 
-            default xml namespace = NS;
             function rec(text, level, li) {
-                XML.ignoreWhitespace = XML.prettyPrinting = false;
-
-                let res = <></>;
+                let res = [];
                 let list, space, i = 0;
 
 
@@ -145,10 +142,13 @@ var Help = Module("Help", {
                         continue;
                     else if (match.char) {
                         if (!list)
-                            res += list = <ul/>;
-                        let li = <li/>;
-                        li.* += rec(match.content.replace(RegExp("^" + match.space, "gm"), ""), level + 1, li);
-                        list.* += li;
+                            res.push(list = ["ul", {}]);
+                        let li = ["li", {}];
+                        li.push(rec(match.content
+                                         .replace(RegExp("^" + match.space, "gm"), ""),
+                                    level + 1,
+                                    li));
+                        list.push(li);
                     }
                     else if (match.par) {
                         let [, par, tags] = /([^]*?)\s*((?:\[[^\]]+\])*)\n*$/.exec(match.par);
@@ -158,58 +158,52 @@ var Help = Module("Help", {
                         let group = !tags.length                       ? "" :
                                     !tags.some(function (t) t == beta) ? "HelpNewsOld" : "HelpNewsNew";
                         if (i === 0 && li) {
-                            li.@highlight = group;
+                            li[1]["dactyl:highlight"] = group;
                             group = "";
                         }
 
                         list = null;
                         if (level == 0 && /^.*:\n$/.test(match.par)) {
                             let text = par.slice(0, -1);
-                            res += <h2 tag={"news-" + text}>{template.linkifyHelp(text, true)}</h2>;
+                            res.push(["h2", { tag: "news-" + text },
+                                          template.linkifyHelp(text, true)]);
                         }
                         else {
                             let [, a, b] = /^(IMPORTANT:?)?([^]*)/.exec(par);
-                            res += <p highlight={group + " HelpNews"}>{
-                                !tags.length ? "" :
-                                <hl key="HelpNewsTag">{tags.join(" ")}</hl>
-                            }{
-                                a ? <hl key="HelpWarning">{a}</hl> : ""
-                            }{
-                                template.linkifyHelp(b, true)
-                            }</p>;
+
+                            res.push(["p", { "dactyl:highlight": group + " HelpNews" },
+                                !tags.length ? "" : ["hl", { key: "HelpNewsTag" }, tags.join(" ")],
+                                a ? ["hl", { key: "HelpWarning" }, a] : "",
+                                template.linkifyHelp(b, true)]);
                         }
                     }
                     i++;
                 }
-                for each (let attr in res..@highlight) {
-                    attr.parent().@NS::highlight = attr;
-                    delete attr.parent().@highlight;
-                }
+
                 return res;
             }
 
-            XML.ignoreWhitespace = XML.prettyPrinting = false;
             let body = rec(NEWS, 0);
-            for each (let li in body..li) {
-                let list = li..li.(@NS::highlight == "HelpNewsOld");
-                if (list.length() && list.length() == li..li.(@NS::highlight != "").length()) {
-                    for each (let li in list)
-                        li.@NS::highlight = "";
-                    li.@NS::highlight = "HelpNewsOld";
-                }
-            }
+
+            // E4X-FIXME
+            // for each (let li in body..li) {
+            //     let list = li..li.(@NS::highlight == "HelpNewsOld");
+            //     if (list.length() && list.length() == li..li.(@NS::highlight != "").length()) {
+            //         for each (let li in list)
+            //             li.@NS::highlight = "";
+            //         li.@NS::highlight = "HelpNewsOld";
+            //     }
+            // }
 
 
             return '<?xml version="1.0"?>\n' +
                    '<?xml-stylesheet type="text/xsl" href="dactyl://content/help.xsl"?>\n' +
-                   '<!DOCTYPE document SYSTEM "resource://dactyl-content/dactyl.dtd">\n' +
-                   <document xmlns={NS} xmlns:dactyl={NS}
-                       name="versions" title={config.appName + " Versions"}>
-                       <h1 tag="versions news NEWS">{config.appName} Versions</h1>
-                       <toc start="2"/>
-
-                       {body}
-                   </document>.toXMLString()
+                   DOM.toXML(["document", { xmlns: "dactyl", name: "versions",
+                                  title: config.appName + " Versions" },
+                       ["h1", { tag: "versions news NEWS" }, config.appName + " Versions"],
+                       ["toc", { start: "2" }],
+
+                       body]);
         });
     },
 
@@ -234,7 +228,7 @@ var Help = Module("Help", {
         init: function init() {
             dactyl.commands["dactyl.help"] = function (event) {
                 let elem = event.originalTarget;
-                help.help(elem.getAttribute("tag") || elem.textContent);
+                modules.help.help(elem.getAttribute("tag") || elem.textContent);
             };
         },
 
@@ -304,7 +298,7 @@ var Help = Module("Help", {
                 var addURIEntry  = function addURIEntry(file, uri) addDataEntry(file, util.httpGet(uri).responseText);
             }
             else {
-                var zip = services.ZipWriter(FILE, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE);
+                var zip = services.ZipWriter(FILE.file, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE);
 
                 addURIEntry = function addURIEntry(file, uri)
                     zip.addEntryChannel(PATH + file, TIME, 9,
@@ -321,10 +315,10 @@ var Help = Module("Help", {
                     if (isinstance(node, [Ci.nsIDOMHTMLBaseElement]))
                         return;
 
-                    data.push("<"); data.push(node.localName);
+                    data.push("<"node.localName);
                     if (node instanceof Ci.nsIDOMHTMLHtmlElement)
-                        data.push(" xmlns=" + XHTML.uri.quote(),
-                                  " xmlns:dactyl=" + NS.uri.quote());
+                        data.push(" xmlns=" + XHTML.quote(),
+                                  " xmlns:dactyl=" + NS.quote());
 
                     for (let { name, value } in array.iterValues(node.attributes)) {
                         if (name == "dactyl:highlight") {
@@ -352,22 +346,20 @@ var Help = Module("Help", {
                             value = value.replace(/.*\//, "");
                         }
 
-                        data.push(" ", name, '="',
-                                  <>{value}</>.toXMLString().replace(/"/g, "&quot;"),
-                                  '"');
+                        data.push(" ", name, '="', DOM.escapeHTML(value), '"');
                     }
                     if (node.localName in empty)
                         data.push(" />");
                     else {
                         data.push(">");
                         if (node instanceof Ci.nsIDOMHTMLHeadElement)
-                            data.push(<link rel="stylesheet" type="text/css" href="help.css"/>.toXMLString());
+                            data.push('<link rel="stylesheet" type="text/css" href="help.css"/>');
                         Array.map(node.childNodes, fix);
                         data.push("</", node.localName, ">");
                     }
                     break;
                 case Ci.nsIDOMNode.TEXT_NODE:
-                    data.push(<>{node.textContent}</>.toXMLString());
+                    data.push(DOM.escapeHTML(node.textContent, true));
                 }
             }
 
@@ -414,7 +406,7 @@ var Help = Module("Help", {
     })
 }, {
 }, {
-    commands: function init_commands(dactyl, modules, window) {
+    commands: function initCommands(dactyl, modules, window) {
         const { commands, completion, help } = modules;
 
         [
@@ -441,7 +433,7 @@ var Help = Module("Help", {
                 });
         });
     },
-    completion: function init_completion(dactyl, modules, window) {
+    completion: function initCompletion(dactyl, modules, window) {
         const { completion } = modules;
 
         completion.help = function completion_help(context, consolidated) {
@@ -453,18 +445,7 @@ var Help = Module("Help", {
                 context.keys = { text: 0, description: function () "all" };
         };
     },
-    mappings: function init_mappings(dactyl, modules, window) {
-        const { help, mappings, modes } = modules;
-
-        mappings.add([modes.MAIN], ["<open-help>", "<F1>"],
-            "Open the introductory help page",
-            function () { help.help(); });
-
-        mappings.add([modes.MAIN], ["<open-single-help>", "<A-F1>"],
-            "Open the single, consolidated help page",
-            function () { modules.ex.helpall(); });
-    },
-    javascript: function init_javascript(dactyl, modules, window) {
+    javascript: function initJavascript(dactyl, modules, window) {
         modules.JavaScript.setCompleter([modules.help.exportHelp],
             [function (context, args) overlay.activeModules.completion.file(context)]);
     }