diff --git a/content/bookmarks.js b/content/bookmarks.js index b340ec5d..9810ea59 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -231,23 +231,9 @@ liberator.Bookmarks = function () //{{{ function () { var sh = getWebNavigation().sessionHistory; - var list = ":" + (liberator.util.escapeHTML(liberator.commandline.getCommand()) || "jumps") + "
" + ""; - list += ""; - var num = -sh.index; - - for (let i = 0; i < sh.count; i++) - { - var entry = sh.getEntryAtIndex(i, false); - var uri = entry.URI.spec; - var title = entry.title; - var indicator = i == sh.index? ">": " "; - list += ""; - num++; - } - - list += "
jumptitleURI
" + indicator + "" + Math.abs(num) + "" + title + - "" + uri + "
"; + let entries = [sh.getEntryAtIndex(i, false) for (i in liberator.util.range(0, sh.count))]; + let list = liberator.buffer.template.jumps(sh.index, entries); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); }, { argCount: "0" }); @@ -496,33 +482,13 @@ liberator.Bookmarks = function () //{{{ if (openItems) return liberator.open([i[0] for each (i in items)], liberator.NEW_TAB); - var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "
" + - ""; - for (let i = 0; i < items.length; i++) - { - let title = liberator.util.escapeHTML(liberator.util.clip(items[i][1], 50)); - let url = liberator.util.escapeHTML(items[i][0]); - let keyword = items[i][2]; - let tags = items[i][3].join(", "); - - extra = ""; - if (keyword) + let list = liberator.buffer.template.bookmarks("title", ( { - extra = " (keyword: " + liberator.util.escapeHTML(keyword) + ""; - if (tags) - extra += " tags: " + liberator.util.escapeHTML(tags) + ")"; - else - extra += ")"; - } - else if (tags) - { - extra = " (tags: " + liberator.util.escapeHTML(tags) + ")"; - } - - list += ""; - } - list += "
titleURL
" + title + "" + url + "" + extra + "
"; - + url: item[0], + title: item[1], + extra: [['keyword', item[2], 'red'], + ['tags', item[3].join(', '), 'blue']].filter(function(i) i[1]) + } for each (item in items))); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); }, @@ -802,15 +768,11 @@ liberator.History = function () //{{{ } else { - var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "
" + - ""; - for (let i = 0; i < items.length; i++) - { - var title = liberator.util.escapeHTML(liberator.util.clip(items[i][1], 50)); - var url = liberator.util.escapeHTML(items[i][0]); - list += ""; - } - list += "
titleURL
" + title + "" + url + "
"; + let list = liberator.buffer.template.bookmarks("title", ( + { + title: item[1], + url: item[0], + } for each (item in items))); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); } } @@ -980,17 +942,8 @@ liberator.QuickMarks = function () //{{{ } } - var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "
" + - ""; - - for (let i = 0; i < marks.length; i++) - { - list += ""; - } - - list += "
QuickMarkURL
" + marks[i] + - "" + liberator.util.escapeHTML(qmarks.get(marks[i])) + "
"; - + let items = ({title: mark, url: qmarks.get(mark)} for each (mark in marks)); + let list = liberator.buffer.template.bookmarks("QuickMark", items); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); } }; diff --git a/content/buffer.js b/content/buffer.js index 2fb6a16b..7fc7c847 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -911,12 +911,12 @@ liberator.Buffer = function () //{{{ elem.focus(); var evt = doc.createEvent("MouseEvents"); - for ([,event] in Iterator(["mousedown", "mouseup", "click"])) + ["mousedown", "mouseup", "click"].forEach(function(event) { evt.initMouseEvent(event, true, true, view, 1, offsetX, offsetY, 0, 0, ctrlKey, /*altKey*/0, shiftKey, /*metaKey*/ ctrlKey, 0, null); elem.dispatchEvent(evt); - } + }) }, saveLink: function (elem, skipPrompt) @@ -1099,6 +1099,8 @@ liberator.Buffer = function () //{{{ showPageInfo: function (verbose) { + var doc = window.content.document; + const feedTypes = { "application/rss+xml": "RSS", "application/atom+xml": "Atom", @@ -1146,25 +1148,6 @@ liberator.Buffer = function () //{{{ return isFeed; } - // TODO: could this be useful for other commands? - function createTable(data) - { - var ret = ""; - - if (data.length - 1) - { - for (let i = 0; i < data.length - 1; i++) - ret += ""; - } - else - { - ret += ""; - } - - return ret + "
" + - data[data.length - 1][0] + "
" + data[i][0] + ": " + data[i][1] + "
(" + data[data.length - 1][1] + ")
"; - } - var pageGeneral = []; var pageFeeds = []; var pageMeta = []; @@ -1178,7 +1161,7 @@ liberator.Buffer = function () //{{{ var ftpCacheSession = cacheService.createSession("FTP", 0, true); httpCacheSession.doomEntriesIfExpired = false; ftpCacheSession.doomEntriesIfExpired = false; - var cacheKey = window.content.document.location.toString().replace(/#.*$/, ""); + var cacheKey = doc.location.toString().replace(/#.*$/, ""); try { var cacheEntryDescriptor = httpCacheSession.openCacheEntry(cacheKey, ACCESS_READ, false); @@ -1202,42 +1185,39 @@ liberator.Buffer = function () //{{{ } // put feeds rss into pageFeeds[] - var linkNodes = window.content.document.getElementsByTagName("link"); - var length = linkNodes.length; - for (let i = 0; i < length; i++) - { - var link = linkNodes[i]; + var linkNodes = doc.getElementsByTagName("link"); + Array.forEach(linkNodes, function(link) { if (!link.href) - continue; + return; + /* Ok... I don't know what this insanity was trying + * to do, but, as far as I can tell, it was: + */ var rel = link.rel && link.rel.toLowerCase(); - var rels = {}; - if (rel) - rels[rel] = true; - if (rels.feed || (link.type && rels.alternate && !rels.stylesheet)) + if (rel == "feed" || (link.type && rel == "alternate")) { var feed = { title: link.title, href: link.href, type: link.type || "" }; - if (isValidFeed(feed, window.content.document.nodePrincipal, rels.feed)) + if (isValidFeed(feed, doc.nodePrincipal, rel == "feed")) { var type = feedTypes[feed.type] || feedTypes["application/rss+xml"]; - pageFeeds.push([feed.title, liberator.util.highlightURL(feed.href, true) + " (" + type + ")"]); + pageFeeds.push([feed.title, liberator.util.highlightURL(feed.href, true) + ({type})]); } } - } + }); - var lastModVerbose = new Date(window.content.document.lastModified).toLocaleString(); - var lastMod = new Date(window.content.document.lastModified).toLocaleFormat("%x %X"); + var lastModVerbose = new Date(doc.lastModified).toLocaleString(); + var lastMod = new Date(doc.lastModified).toLocaleFormat("%x %X"); // FIXME: probably not portable across different language versions - if (lastModVerbose == "Invalid Date" || new Date(window.content.document.lastModified).getFullYear() == 1970) + if (lastModVerbose == "Invalid Date" || new Date(doc.lastModified).getFullYear() == 1970) lastModVerbose = lastMod = null; // Ctrl-g single line output if (!verbose) { var info = []; // tmp array for joining later - var file = window.content.document.location.pathname.split("/").pop() || "[No Name]"; - var title = window.content.document.title || "[No Title]"; + var file = doc.location.pathname.split("/").pop() || "[No Name]"; + var title = doc.title || "[No Title]"; if (pageSize[0]) info.push(pageSize[1] || pageSize[0]); @@ -1261,10 +1241,10 @@ liberator.Buffer = function () //{{{ } // get general infos - pageGeneral.push(["Title", window.content.document.title]); - pageGeneral.push(["URL", liberator.util.highlightURL(window.content.document.location.toString(), true)]); + pageGeneral.push(["Title", doc.title]); + pageGeneral.push(["URL", liberator.util.highlightURL(doc.location.toString(), true)]); - var ref = "referrer" in window.content.document && window.content.document.referrer; + var ref = "referrer" in doc && doc.referrer; if (ref) pageGeneral.push(["Referrer", liberator.util.highlightURL(ref, true)]); @@ -1276,75 +1256,157 @@ liberator.Buffer = function () //{{{ pageGeneral.push(["File Size", pageSize[0]]); } - pageGeneral.push(["Mime-Type", content.document.contentType]); - pageGeneral.push(["Encoding", content.document.characterSet]); - pageGeneral.push(["Compatibility", content.document.compatMode == "BackCompat" ? "Quirks Mode" : "Full/Almost Standards Mode"]); + pageGeneral.push(["Mime-Type", doc.contentType]); + pageGeneral.push(["Encoding", doc.characterSet]); + pageGeneral.push(["Compatibility", doc.compatMode == "BackCompat" ? "Quirks Mode" : "Full/Almost Standards Mode"]); if (lastModVerbose) pageGeneral.push(["Last Modified", lastModVerbose]); // get meta tag data, sort and put into pageMeta[] - var metaNodes = window.content.document.getElementsByTagName("meta"); - var length = metaNodes.length; - if (length) + var metaNodes = doc.getElementsByTagName("meta"); + if (metaNodes.length) { - var tmpSort = []; - var tmpDict = []; + let nodes = []; + let i = 0; - for (let i = 0; i < length; i++) - { - var tmpTag = metaNodes[i].name || metaNodes[i].httpEquiv;// + - var tmpTagNr = tmpTag + "-" + i; // allows multiple (identical) meta names - tmpDict[tmpTagNr] = [tmpTag, metaNodes[i].content]; - tmpSort.push(tmpTagNr); // array for sorting - } + nodes = Array.map(metaNodes, function(node) [node.name || node.httpEquiv, node.content]); + nodes.sort(function(a, b) String.localeCompare(a[0].toLowerCase(), b[0].toLowerCase())); - // sort: ignore-case - tmpSort.sort(function (a, b) a.toLowerCase() > b.toLowerCase() ? 1 : -1); - for (let i = 0; i < tmpSort.length; i++) - pageMeta.push([tmpDict[tmpSort[i]][0], liberator.util.highlightURL(tmpDict[tmpSort[i]][1], false)]); + pageMeta = [[node[0], liberator.util.highlightURL(node[1], false)] + for each (node in nodes)]; } - pageMeta.push(["Meta Tags", ""]); // add extra text to the end - pageGeneral.push(["General Info", ""]); - pageFeeds.push(["Feeds", ""]); - var pageInfoText = ""; var option = liberator.options["pageinfo"]; var br = ""; - for (let i = 0; i < option.length; i++) + let options = { + g: [pageGeneral, "General Info"], + f: [pageFeeds, "Feeds"], + m: [pageMeta, "Meta Tags"], + }; + Array.forEach(option, function (option) { - switch (option[i]) - { - case "g": - if (pageGeneral.length > 1) - { - pageInfoText += br + createTable(pageGeneral); - if (!br) - br = "
"; - } - break; - case "f": - if (pageFeeds.length > 1) - { - pageInfoText += br + createTable(pageFeeds); - if (!br) - br = "
"; - } - break; - case "m": - if (pageMeta.length > 1) - { - pageInfoText += br + createTable(pageMeta); - if (!br) - br = "
"; - } - break; + let opt = options[option]; + if (opt && opt[0].length > 0) + pageInfoText += br + liberator.buffer.template.table(opt[1], opt[0]); + if (!br) + br = "
"; } - } + ); liberator.echo(pageInfoText, liberator.commandline.FORCE_MULTILINE); }, + template: + { + add: function (a, b) a + b, + maybeXML: function (xml) + { + try + { + return new XML(xml) + } + catch (e) {} + return xml; + }, + + generic: function (xml) + { + return (<>:{liberator.commandline.getCommand()}
+ xml).toXMLString(); + }, + + bookmarks: function (header, items) + { + XML.prettyPrinting = false; + return this.generic( + + + + + {[ + + + + + for each (item in items)].reduce(this.add, <>) + } +
{header}URL
{liberator.util.clip(item.title, 50)} + {item.url}  + { + (item.extra && item.extra.length) ? + + ({ + [<>{e[0]}: {e[1]} + for each (e in item.extra)].reduce(this.add, <>) + }) + + : "" + } +
); + }, + + jumps: function (index, elems) + { + XML.prettyPrinting = false; + return this.generic( + + + + + {[ + + + + + + + for ([idx, val] in Iterator(elems))].reduce(this.add, <>) + } +
jumptitleURI
{idx == index ? > : ""} {Math.abs(idx - index)}{val.title}{val.URI.spec}
); + }, + + marks: function (marks) + { + XML.prettyPrinting = false; + return this.generic( + + + + + + + + {[ + + + + + + + for each (mark in marks)].reduce(this.add, <>) + } +
marklinecolfile
{mark[0]}{Math.round(mark[1].position.y & 100)}%{Math.round(mark[1].position.x & 100)}%{mark[1].location}
); + }, + + table: function (title, data) + { + XML.prettyPrinting = false; + return this.generic( + + + + + { + [ + + + + for each (datum in data)].reduce(this.add, <>) + } +
{title}
{datum[0]}{this.maybeXML(datum[1])}
); + } + }, + viewSelectionSource: function () { // copied (and tuned somebit) from browser.jar -> nsContextMenu.js @@ -1751,19 +1813,7 @@ liberator.Marks = function () //{{{ } } - var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "
" + - ""; - for (let i = 0; i < marks.length; i++) - { - list += "" + - "" + - "" + - "" + - "" + - ""; - } - list += "
marklinecolfile
" + marks[i][0] + "" + Math.round(marks[i][1].position.y * 100) + "%" + Math.round(marks[i][1].position.x * 100) + "%" + liberator.util.escapeHTML(marks[i][1].location) + "
"; - + var list = liberator.buffer.template.marks(marks); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); } diff --git a/content/commands.js b/content/commands.js index f037db45..d862c5a6 100644 --- a/content/commands.js +++ b/content/commands.js @@ -697,15 +697,23 @@ liberator.Commands = function () //{{{ var cmdlist = getMatchingUserCommands(cmd); if (cmdlist.length > 0) { - var str = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "
" + - ""; - for (let i = 0; i < cmdlist.length; i++) - { - // programmatically added user commands have a null replacementText - str += ""; - } - str += "
NameArgsDefinition
" + cmdlist[i].name + "" + "*" + "" + liberator.util.escapeHTML(cmdlist[i].replacementText || "function () { ... }") + "
"; - + XML.prettyPrinting = false; + var str = liberator.buffer.template.generic( + + + + + + + {[ + + + + + + for each (cmd in cmdlist)].reduce(liberator.buffer.template.add, <>) + } +
NameArgsDefinition
{cmd.name}*{cmd.replacementText || "function () { ... }"}
); liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); } else diff --git a/content/editor.js b/content/editor.js index 01cdc912..0a518b2e 100644 --- a/content/editor.js +++ b/content/editor.js @@ -930,33 +930,30 @@ liberator.Editor = function () //{{{ } else // list all (for that filter {i,c,!}) { - var flagFound = false; var searchFilter = (filter == "!") ? "!ci" : filter + "!"; // ! -> list all, on c or i ! matches too) - var list = ""; + XML.prettyPrinting = false; + let list = <>; for (let tmplhs in abbrev) { - for (let i = 0; i < abbrev[tmplhs].length; i++) + abbrev[tmplhs].forEach(function (abbr) { - if (searchFilter.indexOf(abbrev[tmplhs][i][0]) > -1) + if (searchFilter.indexOf(abbr[0]) > -1) { - if (!flagFound) - flagFound = true; - - list += ""; - list += ""; - list += ""; - list += ""; - list += ""; + list += + + + + ; } - } + }); } - if (!flagFound) + if (!list.length()) { liberator.echoerr("No abbreviations found"); return; } - list += "
" + abbrev[tmplhs][i][0] + " " + liberator.util.escapeHTML(tmplhs) + " " + liberator.util.escapeHTML(abbrev[tmplhs][i][1]) + "
{abbr[0]}{tmplhs}{abbr[1]}
"; + list = {list}
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); } }, diff --git a/content/events.js b/content/events.js index 0fe7da60..eed1eef4 100644 --- a/content/events.js +++ b/content/events.js @@ -202,36 +202,29 @@ liberator.AutoCommands = function () //{{{ list: function (auEvent, regex) // arguments are filters (NULL = all) { - var flag; - var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "
" + - ""; + let cmds = (item for (item in Iterator(autoCommands)) + if ((!auEvent || item[0] == auEvent) && item[1].length)); - for (let item in autoCommands) - { - flag = true; - if (!auEvent || item == auEvent) // filter event - { - for (let i = 0; i < autoCommands[item].length; i++) - { - if (!regex || regex == autoCommands[item][i][0]) // filter regex - { - if (flag == true) - { - list += ""; - flag = false; - } - - list += ""; - list += ""; - list += ""; - list += ""; - } + // Okay, maybe a bit scary. --Kris + XML.prettyPrinting = false; + var list = liberator.buffer.template.generic( +
---- Auto-Commands ----
" + - liberator.util.escapeHTML(item) + "
  " + liberator.util.escapeHTML(autoCommands[item][i][0]) + "" + liberator.util.escapeHTML(autoCommands[item][i][1]) + "
+ + + + {[ + + + + + [ + + + + for each (item in items)].reduce(liberator.buffer.template.add) + for ([event, items] in cmds)].reduce(liberator.buffer.template.add, <>) } - } - } +
----- Auto Commands -----
{event}
 {item[0]}{item[1]}
); - list += ""; liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); }, @@ -665,14 +658,17 @@ liberator.Events = function () //{{{ "List all macros", function (args) { - var str = ""; - var macroRef = liberator.events.getMacros(args); - for (let [macro, keys] in macroRef) - str += ""; - - str += "
" + macro + "   " + - liberator.util.escapeHTML(keys) + "
"; - + XML.prettyPrinting = false; + var str = + {[ + + + + + for ([macro, keys] in Iterator(liberator.events.getMacros(args))) + ].reduce(liberator.buffer.template.add, <>) + } +
{macro}{keys}
.toXMLString(); liberator.echo(str, liberator.commandline.FORCE_MULTILINE); }, { diff --git a/content/hints.js b/content/hints.js index 205d52c0..37024e52 100644 --- a/content/hints.js +++ b/content/hints.js @@ -593,7 +593,7 @@ liberator.Hints = function () //{{{ { completer: function (filter) { - return ["contains", "wordstartswith", "firstletters", "custom"].map(function (m) [m, ""]); + return [[m, ""] for each (m in ["contains", "wordstartswith", "firstletters", "custom"])]; }, validator: function (value) /^(contains|wordstartswith|firstletters|custom)$/.test(value) }); diff --git a/content/io.js b/content/io.js index 82b3842d..0911aec8 100644 --- a/content/io.js +++ b/content/io.js @@ -63,12 +63,7 @@ liberator.IO = function () //{{{ function expandPathList(list) { - var expanded = []; - - for (let [,path] in Iterator(list.split(","))) - expanded.push(liberator.io.expandPath(path)); - - return expanded.join(","); + return list.split(",").map(liberator.io.expandPath).join(","); } // TODO: why are we passing around so many strings? I know that the XPCOM @@ -308,13 +303,17 @@ liberator.IO = function () //{{{ "List all sourced script names", function () { - var list = ""; - - for (let i = 0; i < scriptNames.length; i++) - list += ""; - - list += "
" + (i + 1) + "." + scriptNames[i] + "
"; - + XML.prettyPrinting = false; + var list = + + {[ + + + + + for ([i, name] in Iterator(striptNames))].reduce(liberator.buffer.template.add, <>) + } +
{i+1}{name}
.toXMLString(); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); }, { argCount: "0" }); diff --git a/content/liberator.js b/content/liberator.js index 230d89c8..2c5d1a53 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -274,15 +274,16 @@ const liberator = (function () //{{{ else { // TODO: clicking on these should open the help - var usage = ""; - for (let command in liberator.commands) - { - usage += ""; - } - usage += "
:" + - liberator.util.escapeHTML(command.name) + "" + - liberator.util.escapeHTML(command.description) + "
"; - + XML.prettyPrinting = false; + var usage = + {[ + + + + + for each (command in liberator.commands)].reduce(liberator.buffer.template.add) + } +
{command.name}{command.description}
.toXMLString(); liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); } }, @@ -427,13 +428,16 @@ const liberator = (function () //{{{ var totalUnits = "msec"; } - var str = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "
" + - "" + - "" + - "" + - "" + - "" + - "
Code execution summary
Executed:" + count + "times
Average time:" + each.toFixed(2) + "" + eachUnits + "
Total time:" + total.toFixed(2) + "" + totalUnits + "
"; + XML.prettyPrinting = false; + var str = liberator.buffer.template.generic( + + + + + + + +
Code execution summary
Executed:{count}times
Average time:{each.toFixed(2)}{eachUnits}
Total time:{total.toFixed(2)}{totalUnits}
); liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); } @@ -495,14 +499,16 @@ const liberator = (function () //{{{ else { // TODO: clicking on these should open the help - var usage = ""; - for (let mapping in liberator.mappings) - { - usage += ""; - } - usage += "
" + - liberator.util.escapeHTML(mapping.names[0]) + "" + - liberator.util.escapeHTML(mapping.description) + "
"; + XML.prettyPrinting = false; + var usage = + {[ + + + + + for each (mapping in liberator.mappings)].reduce(liberator.buffer.template.add) + } +
{mapping.names[0]}{mapping.description}
.toXMLString(); liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); } diff --git a/content/mappings.js b/content/mappings.js index 27af4aeb..da7061a7 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -372,24 +372,21 @@ liberator.Mappings = function () //{{{ return; } - for (let i = 0; i < maps.length; i++) // check on maps items (first mode) + for (let [i, map] in Iterator(maps)) // check on maps items (first mode) { - output.push(true); - if (filter && maps[i].names[0] != filter) // does it match the filter first of all? - { - output[output.length - 1] = false; + output[i] = !filter || map.names[0] == filter; + if (!output[i]) // does it match the filter first of all? continue; - } - for (let j = 1; j < modes.length; j++) // check if found in the other modes (1(2nd)-last) + for (let [, mode] in Iterator(modes)) { - output[output.length - 1] = false; // toggle false, only true whan also found in this mode - for (let k = 0; k < user[modes[j]].length; k++) // maps on the other modes + output[i] = false; // toggle false, only true whan also found in this mode + for (let [, usermode] in Iterator(user[mode])) { // NOTE: when other than user maps, there might be more than only one names[x]. // since only user mappings gets queried here, only names[0] gets checked for equality. - if (maps[i].rhs == user[modes[j]][k].rhs && maps[i].names[0] == user[modes[j]][k].names[0]) + if (map.rhs == usermode.rhs && map.names[0] == usermode.names[0]) { - output[output.length - 1] = true; + output[i] = true; break; // found on this mode - ok, check next mode... } } @@ -398,11 +395,7 @@ liberator.Mappings = function () //{{{ } // anything found? - var flag = false; - for (let i = 0; i < output.length; i++) - if (output[i]) - flag = true; - + var flag = output.some(function (x) x); if (!flag) { liberator.echo("No mappings found"); @@ -410,33 +403,33 @@ liberator.Mappings = function () //{{{ } var modeSign = ""; - for (let i = 0; i < modes.length; i++) + modes.forEach(function (mode) { - if (modes[i] == liberator.modes.NORMAL) + if (mode == liberator.modes.NORMAL) modeSign += "n"; - if ((modes[i] == liberator.modes.INSERT || modes[i] == liberator.modes.TEXTAREA) && modeSign.indexOf("i") == -1) + if ((mode == liberator.modes.INSERT || mode == liberator.modes.TEXTAREA) && modeSign.indexOf("i") == -1) modeSign += "i"; - if (modes[i] == liberator.modes.COMMAND_LINE) + if (mode == liberator.modes.COMMAND_LINE) modeSign += "c"; - if (modes[i] == liberator.modes.MESSAGRE) + if (mode == liberator.modes.MESSAGRE) modeSign += "m"; - } + }); - var list = ""; - for (let i = 0; i < maps.length; i++) - { - if (!output[i]) - continue; - for (let j = 0; j < maps[i].names.length; j++) - { - list += ""; - list += ""; - list += ""; - list += ""; - list += ""; - } - } - list += "
" + modeSign + " " + liberator.util.escapeHTML(maps[i].names[j]) + " " + (maps[i].noremap ? "*" : " ") + "" + liberator.util.escapeHTML(maps[i].rhs || "function () { ... }") + "
"; + let _maps = (map for ([i, map] in Iterator(maps)) + if (output[i])); + XML.prettyPrinting = false; + let list = + {[ + [ + + + + + + for each (name in map.names)].reduce(liberator.buffer.template.add) + for each (map in _maps)].reduce(liberator.buffer.template.add) + } +
{modeSign} {name}{map.noremap ? "*" : " "}{map.rhs || "function () { ... }"}
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); } diff --git a/content/options.js b/content/options.js index 562e8b7b..faa54b7d 100644 --- a/content/options.js +++ b/content/options.js @@ -841,47 +841,54 @@ liberator.Options = function () //{{{ list: function (onlyNonDefault, scope) { - var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "
" + - ""; - var name, value, def; - if (!scope) scope = liberator.options.OPTION_SCOPE_BOTH; + let opts = [] for (let opt in Iterator(this)) { - name = opt.name; - value = opt.value; - def = opt.defaultValue; + let option = { + isDefault: opt.value == opt.defaultValue, + name: opt.name, + default: opt.defaultValue, + pre: <>  , + value: <>, + }; - if (onlyNonDefault && value == def) + if (onlyNonDefault && option.isDefault) continue; - if (!(opt.scope & scope)) continue; if (opt.type == "boolean") { - name = value ? " " + name : "no" + name; - if (value != def) - name = "" + name + " (default: " + (def ? "" : "no") + opt.name + ")"; - list += ""; + if (!opt.value) + option.pre = "no"; + option.default = (option.default ? "" : "no") + opt.name; } else { - if (value != def) - { - name = "" + name + ""; - value = liberator.util.colorize(value, false) + " (default: " + def + ")"; - } - else - value = liberator.util.colorize(value, false); - - list += ""; + option.value = <>={liberator.util.colorize(opt.value, false)}; } + opts.push(option); } - list += "
--- Options ---
" + name + "
" + " " + name + "=" + value + "
"; + XML.prettyPrinting = false; + let list = liberator.buffer.template.generic( + + + + + {[ + + + + for each (opt in opts)].reduce(liberator.buffer.template.add, <>) + } +
--- Options ---
+ {opt.pre}{opt.name}{opt.value} + {opt.isDefault ? "" : (default: {opt.default})} +
); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); }, @@ -891,6 +898,8 @@ liberator.Options = function () //{{{ if (!filter) filter = ""; + /* Argh. Later. */ + var prefArray = prefService.getChildList("", { value: 0 }); prefArray.sort(); var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "
" + diff --git a/content/util.js b/content/util.js index 42fcf195..32f33aad 100644 --- a/content/util.js +++ b/content/util.js @@ -45,22 +45,22 @@ liberator.util = { //{{{ { if (type == "number") { - return "" + arg + ""; + return {arg}; } else if (type == "string") { if (processStrings) - arg = '"' + liberator.util.escapeHTML(arg.replace(/\n/, "\\n")) + '"'; + arg = <>"{arg.replace(/\n/, "\\n")}"; - return "" + arg + ""; + return {arg}; } else if (type == "boolean") { - return "" + arg + ""; + return {arg}; } else if (arg == null || arg == "undefined") { - return "" + arg + ""; + return {arg}; } else if (type == "object" || type == "function") { @@ -193,7 +193,7 @@ liberator.util = { //{{{ highlightURL: function (str, force) { if (force || /^[a-zA-Z]+:\/\//.test(str)) - return "" + liberator.util.escapeHTML(str) + ""; + return {str}; else return str; }, @@ -251,6 +251,12 @@ liberator.util = { //{{{ return string; }, + range: function (start, end) + { + while (start < end) + yield start++; + }, + // same as Firefox's readFromClipboard function, but needed for apps like Thunderbird readFromClipboard: function () {