diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index ff65d129..ffc839f1 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -4,7 +4,7 @@ // // 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"; defineModule("buffer", { exports: ["Buffer", "buffer"], @@ -16,7 +16,7 @@ lazyRequire("io", ["io"]); lazyRequire("finder", ["RangeFind"]); lazyRequire("overlay", ["overlay"]); lazyRequire("storage", ["File", "storage"]); -lazyRequire("template", ["template"]); +lazyRequire("template", ["template", "template_"]); /** * A class to manage the primary web content buffer. The name comes @@ -888,8 +888,7 @@ var Buffer = Module("Buffer", { showElementInfo: function showElementInfo(elem) { let { dactyl } = this.modules; - XML.ignoreWhitespace = XML.prettyPrinting = false; - dactyl.echo(<>Element:
{util.objectToString(elem, true)}); + dactyl.echo(["", /*L*/"Element:", ["br"], util.objectToString(elem, true)]); }, /** @@ -918,15 +917,15 @@ var Buffer = Module("Buffer", { if (bookmarkcache.isBookmarked(this.URL)) info += ", " + _("buffer.bookmarked"); - let pageInfoText = <>{file.quote()} [{info}] {title}; + let pageInfoText = [file.quote(), " [", info, "] ", title].join(""); dactyl.echo(pageInfoText, commandline.FORCE_SINGLELINE); return; } - let list = template.map(sections || options["pageinfo"], function (option) { + let list = template_.map(sections || options["pageinfo"], function (option) { let { action, title } = Buffer.pageInfo[option]; - return template.table(title, action.call(self, true)); - },
); + return template_.table(title, action.call(self, true)); + }, ["br"]); commandline.commandOutput(list); }, @@ -1693,7 +1692,7 @@ var Buffer = Module("Buffer", { function (file) { let output = io.system(filename.substr(1), file); commandline.command = command; - commandline.commandOutput({output}); + commandline.commandOutput(["span", { highlight: "CmdOutput" }, output]); }); if (/^>>/.test(filename)) { @@ -2372,9 +2371,9 @@ Buffer.addPageInfoSection("e", "Search Engines", function (verbose) { if (verbose) for (let link in engines) yield [link.title || /*L*/ "Engine " + n++, - {link.href}]; + ["a", { href: link.href, highlight: "URL", + onclick: "if (event.button == 0) { window.external.AddSearchProvider(this.href); return false; }" }, + link.href]]; } if (!verbose && nEngines) @@ -2430,7 +2429,8 @@ Buffer.addPageInfoSection("f", "Feeds", function (verbose) { nFeed++; let type = feedTypes[feed.type] || "RSS"; if (verbose) - yield [feed.title, template.highlightURL(feed.href, true) +  ({type})]; + yield [feed.title, [template.highlightURL(feed.href, true), + ["span", { class: "extra-info" }, " (" + type + ")"]]]; } } diff --git a/common/modules/dom.jsm b/common/modules/dom.jsm index 0dd3f059..ae52068f 100644 --- a/common/modules/dom.jsm +++ b/common/modules/dom.jsm @@ -1384,9 +1384,12 @@ var DOM = Class("DOM", { ? function (elem, dir) services.dactyl.getScrollable(elem) & (dir ? services.dactyl["DIRECTION_" + dir.toUpperCase()] : ~0) : function (elem, dir) true), - isJSONXML: function isJSONXML(val) isArray(val) && (isString(val[0]) || isArray(val[0])) || isObject(val) && "toDOM" in val, + isJSONXML: function isJSONXML(val) isArray(val) && isinstance(val[0], ["String", "Array", "XML", DOM.DOMString]) + || isObject(val) && "toDOM" in val, + + DOMString: function DOMString(val) ({ + __proto__: DOMString.prototype, - DOMString: function (val) ({ toDOM: function toDOM(doc) doc.createTextNode(val) }), @@ -1558,11 +1561,13 @@ var DOM = Class("DOM", { if (isinstance(args, ["String", _])) return doc.createTextNode(args); + if (isXML(args)) + return DOM.fromXML(args, doc, nodes); let [name, attr] = args; attr = attr || {}; - if (Array.isArray(name) || args.length == 0 || name == "") { + if (!isString(name) || args.length == 0 || name === "") { var frag = doc.createDocumentFragment(); Array.forEach(args, function (arg) { if (!isArray(arg[0])) diff --git a/common/modules/io.jsm b/common/modules/io.jsm index bd8ed81e..744c0de4 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -918,7 +918,7 @@ unlet s:cpo_save result.output += "\n" + _("io.shellReturn", result.returnValue); modules.commandline.command = args.commandName.replace("run", "$& ") + arg; - modules.commandline.commandOutput({result.output}); + modules.commandline.commandOutput(["span", { highlight: "CmdOutput" }, result.output]); modules.autocommands.trigger("ShellCmdPost", {}); }, { diff --git a/common/modules/javascript.jsm b/common/modules/javascript.jsm index 0d0efe16..32af91b9 100644 --- a/common/modules/javascript.jsm +++ b/common/modules/javascript.jsm @@ -751,7 +751,7 @@ var JavaScript = Module("javascript", { message: Class.Memoize(function () { default xml namespace = XHTML; - util.xmlToDom(
, + DOM.fromJSON(["div", { highlight: "REPL", key: "rootNode" }], this.document, this); return this.rootNode; diff --git a/common/modules/main.jsm b/common/modules/main.jsm index 1321ab5e..da124441 100644 --- a/common/modules/main.jsm +++ b/common/modules/main.jsm @@ -2,7 +2,7 @@ // // 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"; try { diff --git a/common/modules/messages.jsm b/common/modules/messages.jsm index abdcc528..d581cc63 100644 --- a/common/modules/messages.jsm +++ b/common/modules/messages.jsm @@ -2,7 +2,7 @@ // // 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"; defineModule("messages", { exports: ["Messages", "messages", "_"], diff --git a/common/modules/template.jsm b/common/modules/template.jsm index 947d8c28..e6eafc5a 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -6,7 +6,7 @@ let global = this; defineModule("template", { - exports: ["Binding", "Template", "template"], + exports: ["Binding", "Template", "template", "template_"], require: ["util"] }); @@ -553,6 +553,40 @@ var Template = Module("Template", { } }); +var Template_ = Module("Template_", { + map: function map(iter, func, sep, interruptable) { + if (typeof iter.length == "number") // FIXME: Kludge? + iter = array.iterValues(iter); + + let res = []; + let n = 0; + for each (let i in Iterator(iter)) { + let val = func(i, n); + if (val == undefined) + continue; + if (n++ && sep) + res.push(sep); + if (interruptable && n % interruptable == 0) + util.threadYield(true, true); + res.push(val); + } + return res; + }, + + table: function table(title, data, indent) { + let table = ["table", {}, + ["tr", { highlight: "Title", align: "left" }, + ["th", { colspan: "2" }, title]], + this.map(data, function (datum) + ["tr", {}, + ["td", { style: "font-weight: bold; min-width: 150px; padding-left: " + (indent || "2ex") }, datum[0]], + ["td", {}, datum[1]]])]; + + if (table[3].length) + return table; + }, +}); + endModule(); // vim: set fdm=marker sw=4 ts=4 et ft=javascript: