1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-24 00:02:27 +01:00

Refactor HTML generation to use E4X. Could use some refactoring.

This commit is contained in:
Kris Maglione
2008-09-30 23:37:33 +00:00
parent 2a9ad9a18b
commit 1cf325a539
11 changed files with 349 additions and 332 deletions

View File

@@ -231,23 +231,9 @@ liberator.Bookmarks = function () //{{{
function ()
{
var sh = getWebNavigation().sessionHistory;
var list = ":" + (liberator.util.escapeHTML(liberator.commandline.getCommand()) || "jumps") + "<br/>" + "<table>";
list += "<tr class=\"hl-Title\" align=\"left\"><th colspan=\"2\">jump</th><th>title</th><th>URI</th></tr>";
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? "<span style=\"color: blue;\">&gt;</span>": " ";
list += "<tr><td>" + indicator + "<td>" + Math.abs(num) + "</td><td style=\"width: 250px; max-width: 500px; overflow: hidden;\">" + title +
"</td><td><a href=\"#\" class=\"hl-URL jump-list\">" + uri + "</a></td></tr>";
num++;
}
list += "</table>";
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()) + "<br/>" +
"<table><tr class=\"hl-Title\" align=\"left\"><th>title</th><th>URL</th></tr>";
for (let i = 0; i < items.length; i++)
let list = liberator.buffer.template.bookmarks("title", (
{
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)
{
extra = "<span style=\"color: gray;\"> (keyword: <span style=\"color: red;\">" + liberator.util.escapeHTML(keyword) + "</span>";
if (tags)
extra += " tags: <span style=\"color: blue;\">" + liberator.util.escapeHTML(tags) + ")</span>";
else
extra += ")</span>";
}
else if (tags)
{
extra = "<span style=\"color: gray;\"> (tags: <span style=\"color: blue;\">" + liberator.util.escapeHTML(tags) + "</span>)</span>";
}
list += "<tr><td>" + title + "</td><td style=\"width: 100%\"><a href=\"#\" class=\"hl-URL\">" + url + "</a>" + extra + "</td></tr>";
}
list += "</table>";
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()) + "<br/>" +
"<table><tr class=\"hl-Title\" align=\"left\"><th>title</th><th>URL</th></tr>";
for (let i = 0; i < items.length; i++)
let list = liberator.buffer.template.bookmarks("title", (
{
var title = liberator.util.escapeHTML(liberator.util.clip(items[i][1], 50));
var url = liberator.util.escapeHTML(items[i][0]);
list += "<tr><td>" + title + "</td><td><a href=\"#\" class=\"hl-URL\">" + url + "</a></td></tr>";
}
list += "</table>";
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()) + "<br/>" +
"<table><tr class=\"hl-Title\" align=\"left\"><th>QuickMark</th><th>URL</th></tr>";
for (let i = 0; i < marks.length; i++)
{
list += "<tr><td> " + marks[i] +
"</td><td style=\"color: green;\">" + liberator.util.escapeHTML(qmarks.get(marks[i])) + "</td></tr>";
}
list += "</table>";
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);
}
};

View File

@@ -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 = "<table><tr><th class='hl-Title' align='left' colspan='2'>" +
data[data.length - 1][0] + "</th></tr>";
if (data.length - 1)
{
for (let i = 0; i < data.length - 1; i++)
ret += "<tr><td style='font-weight: bold; min-width: 150px'> " + data[i][0] + ": </td><td>" + data[i][1] + "</td></tr>";
}
else
{
ret += "<tr><td colspan='2'> (" + data[data.length - 1][1] + ")</td></tr>";
}
return ret + "</table>";
}
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) + " <span style='color: gray;'>(" + type + ")</span>"]);
}
pageFeeds.push([feed.title, liberator.util.highlightURL(feed.href, true) + <span style="color: gray;"> ({type})</span>]);
}
}
});
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()));
pageMeta = [[node[0], liberator.util.highlightURL(node[1], false)]
for each (node in nodes)];
}
// 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.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);
let opt = options[option];
if (opt && opt[0].length > 0)
pageInfoText += br + liberator.buffer.template.table(opt[1], opt[0]);
if (!br)
br = "<br/>";
}
break;
case "f":
if (pageFeeds.length > 1)
{
pageInfoText += br + createTable(pageFeeds);
if (!br)
br = "<br/>";
}
break;
case "m":
if (pageMeta.length > 1)
{
pageInfoText += br + createTable(pageMeta);
if (!br)
br = "<br/>";
}
break;
}
}
);
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()}<br/></> + xml).toXMLString();
},
bookmarks: function (header, items)
{
XML.prettyPrinting = false;
return this.generic(
<table>
<tr align="left" class="hl-Title">
<th>{header}</th><th>URL</th>
</tr>
{[
<tr>
<td>{liberator.util.clip(item.title, 50)}</td>
<td style="width: 100%">
<a href="#" class="hl-URL">{item.url}</a>&#160;
{
(item.extra && item.extra.length) ?
<span style="color: gray;">
({
[<>{e[0]}: <span color={e[2]}>{e[1]}</span></>
for each (e in item.extra)].reduce(this.add, <></>)
})
</span>
: ""
}
</td>
</tr>
for each (item in items)].reduce(this.add, <></>)
}
</table>);
},
jumps: function (index, elems)
{
XML.prettyPrinting = false;
return this.generic(
<table>
<tr style="text-align: left;" class="hl-Title">
<th colspan="2">jump</th><th>title</th><th>URI</th>
</tr>
{[
<tr>
<td>{idx == index ? <span style="color: blue;">&gt;</span> : ""}</td> <!-- } //vim :( -->
<td>{Math.abs(idx - index)}</td>
<td style="width: 250px; max-width: 500px; overflow: hidden;">{val.title}</td>
<td><a href="#" class="hl-URL jump-list">{val.URI.spec}</a></td>
</tr>
for ([idx, val] in Iterator(elems))].reduce(this.add, <></>)
}
</table>);
},
marks: function (marks)
{
XML.prettyPrinting = false;
return this.generic(
<table>
<tr class="hl-Title" align="left">
<th>mark</th>
<th>line</th>
<th>col</th>
<th>file</th>
</tr>
{[
<tr>
<td>{mark[0]}</td>
<td align="right">{Math.round(mark[1].position.y & 100)}%</td>
<td align="right">{Math.round(mark[1].position.x & 100)}%</td>
<td style="color: green;">{mark[1].location}</td>
</tr>
for each (mark in marks)].reduce(this.add, <></>)
}
</table>);
},
table: function (title, data)
{
XML.prettyPrinting = false;
return this.generic(
<table>
<tr>
<th class="hl-Title" align="left" colspan="2">{title}</th>
</tr>
{
[<tr>
<td style="font-weight: bold; min-width: 150px">{datum[0]}</td>
<td>{this.maybeXML(datum[1])}</td>
</tr>
for each (datum in data)].reduce(this.add, <></>)
}
</table>);
}
},
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()) + "<br/>" +
"<table><tr class=\"hl-Title\" align=\"left\"><th>mark</th><th>line</th><th>col</th><th>file</th></tr>";
for (let i = 0; i < marks.length; i++)
{
list += "<tr>" +
"<td> " + marks[i][0] + "</td>" +
"<td align=\"right\">" + Math.round(marks[i][1].position.y * 100) + "%</td>" +
"<td align=\"right\">" + Math.round(marks[i][1].position.x * 100) + "%</td>" +
"<td style=\"color: green;\">" + liberator.util.escapeHTML(marks[i][1].location) + "</td>" +
"</tr>";
}
list += "</table>";
var list = liberator.buffer.template.marks(marks);
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}

View File

@@ -697,15 +697,23 @@ liberator.Commands = function () //{{{
var cmdlist = getMatchingUserCommands(cmd);
if (cmdlist.length > 0)
{
var str = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" +
"<table><tr class=\"hl-Title\" align=\"left\"><th>Name</th><th>Args</th><th>Definition</th></tr>";
for (let i = 0; i < cmdlist.length; i++)
{
// programmatically added user commands have a null replacementText
str += "<tr><td>" + cmdlist[i].name + "</td><td>" + "*" + "</td><td>" + liberator.util.escapeHTML(cmdlist[i].replacementText || "function () { ... }") + "</td></tr>";
XML.prettyPrinting = false;
var str = liberator.buffer.template.generic(
<table>
<tr class="hl-Title" align="left">
<th>Name</th>
<th>Args</th>
<th>Definition</th>
</tr>
{[
<tr>
<td>{cmd.name}</td>
<td>*</td>
<td>{cmd.replacementText || "function () { ... }"}</td>
</tr>
for each (cmd in cmdlist)].reduce(liberator.buffer.template.add, <></>)
}
str += "</table>";
</table>);
liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}
else

View File

@@ -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 = "<table>";
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 += "<tr>";
list += "<td> " + abbrev[tmplhs][i][0] + "</td>";
list += "<td> " + liberator.util.escapeHTML(tmplhs) + "</td>";
list += "<td> " + liberator.util.escapeHTML(abbrev[tmplhs][i][1]) + "</td>";
list += "</tr>";
}
list += <tr>
<td>{abbr[0]}</td>
<td>{tmplhs}</td>
<td>{abbr[1]}</td>
</tr>;
}
});
}
if (!flagFound)
if (!list.length())
{
liberator.echoerr("No abbreviations found");
return;
}
list += "</table>";
list = <table>{list}</table>
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}
},

View File

@@ -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()) + "<br/>" +
"<table><tr><td class=\"hl-Title\" colspan=\"2\">---- Auto-Commands ----</td></tr>";
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 += "<tr><td class=\"hl-Title\" colspan=\"2\">" +
liberator.util.escapeHTML(item) + "</td></tr>";
flag = false;
// Okay, maybe a bit scary. --Kris
XML.prettyPrinting = false;
var list = liberator.buffer.template.generic(
<table>
<tr>
<td class="hl-Title" colspan="2">----- Auto Commands -----</td>
</tr>
{[
<tr>
<td class="hl-Title" colspan="2">{event}</td>
</tr>
+ [<tr>
<td>&#160;{item[0]}</td>
<td>{item[1]}</td>
</tr>
for each (item in items)].reduce(liberator.buffer.template.add)
for ([event, items] in cmds)].reduce(liberator.buffer.template.add, <></>)
}
</table>);
list += "<tr>";
list += "<td> &nbsp; " + liberator.util.escapeHTML(autoCommands[item][i][0]) + "</td>";
list += "<td>" + liberator.util.escapeHTML(autoCommands[item][i][1]) + "</td>";
list += "</tr>";
}
}
}
}
list += "</table>";
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 = "<table>";
var macroRef = liberator.events.getMacros(args);
for (let [macro, keys] in macroRef)
str += "<tr><td> " + macro + " &nbsp; </td><td>" +
liberator.util.escapeHTML(keys) + "</td></tr>";
str += "</table>";
XML.prettyPrinting = false;
var str = <table>
{[
<tr>
<td>{macro}</td>
<td>{keys}</td>
</tr>
for ([macro, keys] in Iterator(liberator.events.getMacros(args)))
].reduce(liberator.buffer.template.add, <></>)
}
</table>.toXMLString();
liberator.echo(str, liberator.commandline.FORCE_MULTILINE);
},
{

View File

@@ -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)
});

View File

@@ -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 = "<table>";
for (let i = 0; i < scriptNames.length; i++)
list += "<tr><td style=\"text-align: right\">" + (i + 1) + ".</td><td>" + scriptNames[i] + "</td></tr>";
list += "</table>";
XML.prettyPrinting = false;
var list =
<table>
{[
<tr>
<td style="text-align: right">{i+1}</td>
<td>{name}</td>
</tr>
for ([i, name] in Iterator(striptNames))].reduce(liberator.buffer.template.add, <></>)
}
</table>.toXMLString();
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
},
{ argCount: "0" });

View File

@@ -274,15 +274,16 @@ const liberator = (function () //{{{
else
{
// TODO: clicking on these should open the help
var usage = "<table>";
for (let command in liberator.commands)
{
usage += "<tr><td class=\"hl-Title\" style=\"padding-right: 20px\"> :" +
liberator.util.escapeHTML(command.name) + "</td><td>" +
liberator.util.escapeHTML(command.description) + "</td></tr>";
XML.prettyPrinting = false;
var usage = <table>
{[
<tr>
<td class="hl-Title" style="padding-right: 20px">{command.name}</td>
<td>{command.description}</td>
</tr>
for each (command in liberator.commands)].reduce(liberator.buffer.template.add)
}
usage += "</table>";
</table>.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()) + "<br/>" +
"<table>" +
"<tr class=\"hl-Title\" align=\"left\"><th colspan=\"3\">Code execution summary</th></tr>" +
"<tr><td> Executed:</td><td align=\"right\"><span style=\"color: green\">" + count + "</span></td><td>times</td></tr>" +
"<tr><td> Average time:</td><td align=\"right\"><span style=\"color: green\">" + each.toFixed(2) + "</span></td><td>" + eachUnits + "</td></tr>" +
"<tr><td> Total time:</td><td align=\"right\"><span style=\"color: red\">" + total.toFixed(2) + "</span></td><td>" + totalUnits + "</td></tr>" +
"</table>";
XML.prettyPrinting = false;
var str = liberator.buffer.template.generic(
<table>
<tr class="hl-Title" align="left">
<th colspan="3">Code execution summary</th>
</tr>
<tr><td> Executed:</td><td align="right"><span style="color: green">{count}</span></td><td>times</td></tr>
<tr><td> Average time:</td><td align="right"><span style="color: green">{each.toFixed(2)}</span></td><td>{eachUnits}</td></tr>
<tr><td> Total time:</td><td align="right"><span style="color: red">{total.toFixed(2)}</span></td><td>{totalUnits}</td></tr>
</table>);
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 = "<table>";
for (let mapping in liberator.mappings)
{
usage += "<tr><td class=\"hl-Title\" style=\"padding-right: 20px\"> " +
liberator.util.escapeHTML(mapping.names[0]) + "</td><td>" +
liberator.util.escapeHTML(mapping.description) + "</td></tr>";
XML.prettyPrinting = false;
var usage = <table>
{[
<tr>
<td class="hl-Title" style="padding-right: 20px"> {mapping.names[0]}</td>
<td>{mapping.description}</td>
</tr>
for each (mapping in liberator.mappings)].reduce(liberator.buffer.template.add)
}
usage += "</table>";
</table>.toXMLString();
liberator.echo(usage, liberator.commandline.FORCE_MULTILINE);
}

View File

@@ -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 = "<table>";
for (let i = 0; i < maps.length; i++)
{
if (!output[i])
continue;
for (let j = 0; j < maps[i].names.length; j++)
{
list += "<tr>";
list += "<td> " + modeSign + " " + liberator.util.escapeHTML(maps[i].names[j]) + "</td>";
list += "<td> " + (maps[i].noremap ? "*" : " ") + "</td>";
list += "<td>" + liberator.util.escapeHTML(maps[i].rhs || "function () { ... }") + "</td>";
list += "</tr>";
let _maps = (map for ([i, map] in Iterator(maps))
if (output[i]));
XML.prettyPrinting = false;
let list = <table>
{[
[
<tr>
<td>{modeSign} {name}</td>
<td>{map.noremap ? "*" : " "}</td>
<td>{map.rhs || "function () { ... }"}</td>
</tr>
for each (name in map.names)].reduce(liberator.buffer.template.add)
for each (map in _maps)].reduce(liberator.buffer.template.add)
}
}
list += "</table>";
</table>
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}

View File

@@ -841,47 +841,54 @@ liberator.Options = function () //{{{
list: function (onlyNonDefault, scope)
{
var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" +
"<table><tr class=\"hl-Title\" align=\"left\"><th>--- Options ---</th></tr>";
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: <>&#160;&#160;</>,
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 = "<span style=\"font-weight: bold\">" + name + "</span><span style=\"color: gray\"> (default: " + (def ? "" : "no") + opt.name + ")</span>";
list += "<tr><td>" + name + "</td></tr>";
if (!opt.value)
option.pre = "no";
option.default = (option.default ? "" : "no") + opt.name;
}
else
{
if (value != def)
{
name = "<span style=\"font-weight: bold\">" + name + "</span>";
value = liberator.util.colorize(value, false) + "<span style=\"color: gray\"> (default: " + def + ")</span>";
}
else
value = liberator.util.colorize(value, false);
list += "<tr><td>" + " " + name + "=" + value + "</td></tr>";
option.value = <>={liberator.util.colorize(opt.value, false)}</>;
}
opts.push(option);
}
list += "</table>";
XML.prettyPrinting = false;
let list = liberator.buffer.template.generic(
<table>
<tr class="hl-Title" align="left">
<th>--- Options ---</th>
</tr>
{[
<tr>
<td>
<span style={opt.isDefault ? "" : "font-weight: bold"}>{opt.pre}{opt.name}{opt.value}</span>
{opt.isDefault ? "" : <span style="color: gray"> (default: {opt.default})</span>}
</td>
</tr>
for each (opt in opts)].reduce(liberator.buffer.template.add, <></>)
}
</table>);
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()) + "<br/>" +

View File

@@ -45,22 +45,22 @@ liberator.util = { //{{{
{
if (type == "number")
{
return "<span style=\"color: red;\">" + arg + "</span>";
return <span style="color: red;">{arg}</span>;
}
else if (type == "string")
{
if (processStrings)
arg = '"' + liberator.util.escapeHTML(arg.replace(/\n/, "\\n")) + '"';
arg = <>"{arg.replace(/\n/, "\\n")}"</>;
return "<span style=\"color: green;\">" + arg + "</span>";
return <span style="color: green;">{arg}</span>;
}
else if (type == "boolean")
{
return "<span style=\"color: blue;\">" + arg + "</span>";
return <span style="color: blue;">{arg}</span>;
}
else if (arg == null || arg == "undefined")
{
return "<span style=\"color: blue;\">" + arg + "</span>";
return <span style="color: blue;">{arg}</span>;
}
else if (type == "object" || type == "function")
{
@@ -193,7 +193,7 @@ liberator.util = { //{{{
highlightURL: function (str, force)
{
if (force || /^[a-zA-Z]+:\/\//.test(str))
return "<a class='hl-URL' href='#'>" + liberator.util.escapeHTML(str) + "</a>";
return <a class="hl-URL" href="#">{str}</a>;
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 ()
{