1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 22:22: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 () function ()
{ {
var sh = getWebNavigation().sessionHistory; 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); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}, },
{ argCount: "0" }); { argCount: "0" });
@@ -496,33 +482,13 @@ liberator.Bookmarks = function () //{{{
if (openItems) if (openItems)
return liberator.open([i[0] for each (i in items)], liberator.NEW_TAB); return liberator.open([i[0] for each (i in items)], liberator.NEW_TAB);
var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" + let list = liberator.buffer.template.bookmarks("title", (
"<table><tr class=\"hl-Title\" align=\"left\"><th>title</th><th>URL</th></tr>";
for (let i = 0; i < items.length; i++)
{ {
let title = liberator.util.escapeHTML(liberator.util.clip(items[i][1], 50)); url: item[0],
let url = liberator.util.escapeHTML(items[i][0]); title: item[1],
let keyword = items[i][2]; extra: [['keyword', item[2], 'red'],
let tags = items[i][3].join(", "); ['tags', item[3].join(', '), 'blue']].filter(function(i) i[1])
} for each (item in items)));
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>";
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}, },
@@ -802,15 +768,11 @@ liberator.History = function () //{{{
} }
else else
{ {
var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" + let list = liberator.buffer.template.bookmarks("title", (
"<table><tr class=\"hl-Title\" align=\"left\"><th>title</th><th>URL</th></tr>";
for (let i = 0; i < items.length; i++)
{ {
var title = liberator.util.escapeHTML(liberator.util.clip(items[i][1], 50)); title: item[1],
var url = liberator.util.escapeHTML(items[i][0]); url: item[0],
list += "<tr><td>" + title + "</td><td><a href=\"#\" class=\"hl-URL\">" + url + "</a></td></tr>"; } for each (item in items)));
}
list += "</table>";
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); 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/>" + let items = ({title: mark, url: qmarks.get(mark)} for each (mark in marks));
"<table><tr class=\"hl-Title\" align=\"left\"><th>QuickMark</th><th>URL</th></tr>"; let list = liberator.buffer.template.bookmarks("QuickMark", items);
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>";
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
} }
}; };

View File

@@ -911,12 +911,12 @@ liberator.Buffer = function () //{{{
elem.focus(); elem.focus();
var evt = doc.createEvent("MouseEvents"); 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, evt.initMouseEvent(event, true, true, view, 1, offsetX, offsetY, 0, 0,
ctrlKey, /*altKey*/0, shiftKey, /*metaKey*/ ctrlKey, 0, null); ctrlKey, /*altKey*/0, shiftKey, /*metaKey*/ ctrlKey, 0, null);
elem.dispatchEvent(evt); elem.dispatchEvent(evt);
} })
}, },
saveLink: function (elem, skipPrompt) saveLink: function (elem, skipPrompt)
@@ -1099,6 +1099,8 @@ liberator.Buffer = function () //{{{
showPageInfo: function (verbose) showPageInfo: function (verbose)
{ {
var doc = window.content.document;
const feedTypes = { const feedTypes = {
"application/rss+xml": "RSS", "application/rss+xml": "RSS",
"application/atom+xml": "Atom", "application/atom+xml": "Atom",
@@ -1146,25 +1148,6 @@ liberator.Buffer = function () //{{{
return isFeed; 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 pageGeneral = [];
var pageFeeds = []; var pageFeeds = [];
var pageMeta = []; var pageMeta = [];
@@ -1178,7 +1161,7 @@ liberator.Buffer = function () //{{{
var ftpCacheSession = cacheService.createSession("FTP", 0, true); var ftpCacheSession = cacheService.createSession("FTP", 0, true);
httpCacheSession.doomEntriesIfExpired = false; httpCacheSession.doomEntriesIfExpired = false;
ftpCacheSession.doomEntriesIfExpired = false; ftpCacheSession.doomEntriesIfExpired = false;
var cacheKey = window.content.document.location.toString().replace(/#.*$/, ""); var cacheKey = doc.location.toString().replace(/#.*$/, "");
try try
{ {
var cacheEntryDescriptor = httpCacheSession.openCacheEntry(cacheKey, ACCESS_READ, false); var cacheEntryDescriptor = httpCacheSession.openCacheEntry(cacheKey, ACCESS_READ, false);
@@ -1202,42 +1185,39 @@ liberator.Buffer = function () //{{{
} }
// put feeds rss into pageFeeds[] // put feeds rss into pageFeeds[]
var linkNodes = window.content.document.getElementsByTagName("link"); var linkNodes = doc.getElementsByTagName("link");
var length = linkNodes.length; Array.forEach(linkNodes, function(link) {
for (let i = 0; i < length; i++)
{
var link = linkNodes[i];
if (!link.href) 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 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 || "" }; 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"]; 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 lastModVerbose = new Date(doc.lastModified).toLocaleString();
var lastMod = new Date(window.content.document.lastModified).toLocaleFormat("%x %X"); var lastMod = new Date(doc.lastModified).toLocaleFormat("%x %X");
// FIXME: probably not portable across different language versions // 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; lastModVerbose = lastMod = null;
// Ctrl-g single line output // Ctrl-g single line output
if (!verbose) if (!verbose)
{ {
var info = []; // tmp array for joining later var info = []; // tmp array for joining later
var file = window.content.document.location.pathname.split("/").pop() || "[No Name]"; var file = doc.location.pathname.split("/").pop() || "[No Name]";
var title = window.content.document.title || "[No Title]"; var title = doc.title || "[No Title]";
if (pageSize[0]) if (pageSize[0])
info.push(pageSize[1] || pageSize[0]); info.push(pageSize[1] || pageSize[0]);
@@ -1261,10 +1241,10 @@ liberator.Buffer = function () //{{{
} }
// get general infos // get general infos
pageGeneral.push(["Title", window.content.document.title]); pageGeneral.push(["Title", doc.title]);
pageGeneral.push(["URL", liberator.util.highlightURL(window.content.document.location.toString(), true)]); 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) if (ref)
pageGeneral.push(["Referrer", liberator.util.highlightURL(ref, true)]); pageGeneral.push(["Referrer", liberator.util.highlightURL(ref, true)]);
@@ -1276,75 +1256,157 @@ liberator.Buffer = function () //{{{
pageGeneral.push(["File Size", pageSize[0]]); pageGeneral.push(["File Size", pageSize[0]]);
} }
pageGeneral.push(["Mime-Type", content.document.contentType]); pageGeneral.push(["Mime-Type", doc.contentType]);
pageGeneral.push(["Encoding", content.document.characterSet]); pageGeneral.push(["Encoding", doc.characterSet]);
pageGeneral.push(["Compatibility", content.document.compatMode == "BackCompat" ? "Quirks Mode" : "Full/Almost Standards Mode"]); pageGeneral.push(["Compatibility", doc.compatMode == "BackCompat" ? "Quirks Mode" : "Full/Almost Standards Mode"]);
if (lastModVerbose) if (lastModVerbose)
pageGeneral.push(["Last Modified", lastModVerbose]); pageGeneral.push(["Last Modified", lastModVerbose]);
// get meta tag data, sort and put into pageMeta[] // get meta tag data, sort and put into pageMeta[]
var metaNodes = window.content.document.getElementsByTagName("meta"); var metaNodes = doc.getElementsByTagName("meta");
var length = metaNodes.length; if (metaNodes.length)
if (length)
{ {
var tmpSort = []; let nodes = [];
var tmpDict = []; let i = 0;
for (let i = 0; i < length; i++) 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()));
var tmpTag = metaNodes[i].name || metaNodes[i].httpEquiv;// +
var tmpTagNr = tmpTag + "-" + i; // allows multiple (identical) meta names pageMeta = [[node[0], liberator.util.highlightURL(node[1], false)]
tmpDict[tmpTagNr] = [tmpTag, metaNodes[i].content]; for each (node in nodes)];
tmpSort.push(tmpTagNr); // array for sorting
} }
// 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 pageInfoText = "";
var option = liberator.options["pageinfo"]; var option = liberator.options["pageinfo"];
var br = ""; 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]) let opt = options[option];
{ if (opt && opt[0].length > 0)
case "g": pageInfoText += br + liberator.buffer.template.table(opt[1], opt[0]);
if (pageGeneral.length > 1)
{
pageInfoText += br + createTable(pageGeneral);
if (!br) if (!br)
br = "<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); 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 () viewSelectionSource: function ()
{ {
// copied (and tuned somebit) from browser.jar -> nsContextMenu.js // 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/>" + var list = liberator.buffer.template.marks(marks);
"<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>";
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); 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); var cmdlist = getMatchingUserCommands(cmd);
if (cmdlist.length > 0) if (cmdlist.length > 0)
{ {
var str = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" + XML.prettyPrinting = false;
"<table><tr class=\"hl-Title\" align=\"left\"><th>Name</th><th>Args</th><th>Definition</th></tr>"; var str = liberator.buffer.template.generic(
for (let i = 0; i < cmdlist.length; i++) <table>
{ <tr class="hl-Title" align="left">
// programmatically added user commands have a null replacementText <th>Name</th>
str += "<tr><td>" + cmdlist[i].name + "</td><td>" + "*" + "</td><td>" + liberator.util.escapeHTML(cmdlist[i].replacementText || "function () { ... }") + "</td></tr>"; <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); liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
} }
else else

View File

@@ -930,33 +930,30 @@ liberator.Editor = function () //{{{
} }
else // list all (for that filter {i,c,!}) 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 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 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) list += <tr>
flagFound = true; <td>{abbr[0]}</td>
<td>{tmplhs}</td>
list += "<tr>"; <td>{abbr[1]}</td>
list += "<td> " + abbrev[tmplhs][i][0] + "</td>"; </tr>;
list += "<td> " + liberator.util.escapeHTML(tmplhs) + "</td>";
list += "<td> " + liberator.util.escapeHTML(abbrev[tmplhs][i][1]) + "</td>";
list += "</tr>";
}
} }
});
} }
if (!flagFound) if (!list.length())
{ {
liberator.echoerr("No abbreviations found"); liberator.echoerr("No abbreviations found");
return; return;
} }
list += "</table>"; list = <table>{list}</table>
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); 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) list: function (auEvent, regex) // arguments are filters (NULL = all)
{ {
var flag; let cmds = (item for (item in Iterator(autoCommands))
var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" + if ((!auEvent || item[0] == auEvent) && item[1].length));
"<table><tr><td class=\"hl-Title\" colspan=\"2\">---- Auto-Commands ----</td></tr>";
for (let item in autoCommands) // Okay, maybe a bit scary. --Kris
{ XML.prettyPrinting = false;
flag = true; var list = liberator.buffer.template.generic(
if (!auEvent || item == auEvent) // filter event <table>
{ <tr>
for (let i = 0; i < autoCommands[item].length; i++) <td class="hl-Title" colspan="2">----- Auto Commands -----</td>
{ </tr>
if (!regex || regex == autoCommands[item][i][0]) // filter regex {[
{ <tr>
if (flag == true) <td class="hl-Title" colspan="2">{event}</td>
{ </tr>
list += "<tr><td class=\"hl-Title\" colspan=\"2\">" + + [<tr>
liberator.util.escapeHTML(item) + "</td></tr>"; <td>&#160;{item[0]}</td>
flag = false; <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); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}, },
@@ -665,14 +658,17 @@ liberator.Events = function () //{{{
"List all macros", "List all macros",
function (args) function (args)
{ {
var str = "<table>"; XML.prettyPrinting = false;
var macroRef = liberator.events.getMacros(args); var str = <table>
for (let [macro, keys] in macroRef) {[
str += "<tr><td> " + macro + " &nbsp; </td><td>" + <tr>
liberator.util.escapeHTML(keys) + "</td></tr>"; <td>{macro}</td>
<td>{keys}</td>
str += "</table>"; </tr>
for ([macro, keys] in Iterator(liberator.events.getMacros(args)))
].reduce(liberator.buffer.template.add, <></>)
}
</table>.toXMLString();
liberator.echo(str, liberator.commandline.FORCE_MULTILINE); liberator.echo(str, liberator.commandline.FORCE_MULTILINE);
}, },
{ {

View File

@@ -593,7 +593,7 @@ liberator.Hints = function () //{{{
{ {
completer: function (filter) 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) validator: function (value) /^(contains|wordstartswith|firstletters|custom)$/.test(value)
}); });

View File

@@ -63,12 +63,7 @@ liberator.IO = function () //{{{
function expandPathList(list) function expandPathList(list)
{ {
var expanded = []; return list.split(",").map(liberator.io.expandPath).join(",");
for (let [,path] in Iterator(list.split(",")))
expanded.push(liberator.io.expandPath(path));
return expanded.join(",");
} }
// TODO: why are we passing around so many strings? I know that the XPCOM // 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", "List all sourced script names",
function () function ()
{ {
var list = "<table>"; XML.prettyPrinting = false;
var list =
for (let i = 0; i < scriptNames.length; i++) <table>
list += "<tr><td style=\"text-align: right\">" + (i + 1) + ".</td><td>" + scriptNames[i] + "</td></tr>"; {[
<tr>
list += "</table>"; <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); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}, },
{ argCount: "0" }); { argCount: "0" });

View File

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

View File

@@ -372,24 +372,21 @@ liberator.Mappings = function () //{{{
return; 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); output[i] = !filter || map.names[0] == filter;
if (filter && maps[i].names[0] != filter) // does it match the filter first of all? if (!output[i]) // does it match the filter first of all?
{
output[output.length - 1] = false;
continue; continue;
} for (let [, mode] in Iterator(modes))
for (let j = 1; j < modes.length; j++) // check if found in the other modes (1(2nd)-last)
{ {
output[output.length - 1] = false; // toggle false, only true whan also found in this mode output[i] = 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 for (let [, usermode] in Iterator(user[mode]))
{ {
// NOTE: when other than user maps, there might be more than only one names[x]. // 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. // 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... break; // found on this mode - ok, check next mode...
} }
} }
@@ -398,11 +395,7 @@ liberator.Mappings = function () //{{{
} }
// anything found? // anything found?
var flag = false; var flag = output.some(function (x) x);
for (let i = 0; i < output.length; i++)
if (output[i])
flag = true;
if (!flag) if (!flag)
{ {
liberator.echo("No mappings found"); liberator.echo("No mappings found");
@@ -410,33 +403,33 @@ liberator.Mappings = function () //{{{
} }
var modeSign = ""; 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"; 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"; modeSign += "i";
if (modes[i] == liberator.modes.COMMAND_LINE) if (mode == liberator.modes.COMMAND_LINE)
modeSign += "c"; modeSign += "c";
if (modes[i] == liberator.modes.MESSAGRE) if (mode == liberator.modes.MESSAGRE)
modeSign += "m"; modeSign += "m";
} });
var list = "<table>"; let _maps = (map for ([i, map] in Iterator(maps))
for (let i = 0; i < maps.length; i++) if (output[i]));
{ XML.prettyPrinting = false;
if (!output[i]) let list = <table>
continue; {[
for (let j = 0; j < maps[i].names.length; j++) [
{ <tr>
list += "<tr>"; <td>{modeSign} {name}</td>
list += "<td> " + modeSign + " " + liberator.util.escapeHTML(maps[i].names[j]) + "</td>"; <td>{map.noremap ? "*" : " "}</td>
list += "<td> " + (maps[i].noremap ? "*" : " ") + "</td>"; <td>{map.rhs || "function () { ... }"}</td>
list += "<td>" + liberator.util.escapeHTML(maps[i].rhs || "function () { ... }") + "</td>"; </tr>
list += "</tr>"; for each (name in map.names)].reduce(liberator.buffer.template.add)
for each (map in _maps)].reduce(liberator.buffer.template.add)
} }
} </table>
list += "</table>";
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); 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) 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) if (!scope)
scope = liberator.options.OPTION_SCOPE_BOTH; scope = liberator.options.OPTION_SCOPE_BOTH;
let opts = []
for (let opt in Iterator(this)) for (let opt in Iterator(this))
{ {
name = opt.name; let option = {
value = opt.value; isDefault: opt.value == opt.defaultValue,
def = opt.defaultValue; name: opt.name,
default: opt.defaultValue,
pre: <>&#160;&#160;</>,
value: <></>,
};
if (onlyNonDefault && value == def) if (onlyNonDefault && option.isDefault)
continue; continue;
if (!(opt.scope & scope)) if (!(opt.scope & scope))
continue; continue;
if (opt.type == "boolean") if (opt.type == "boolean")
{ {
name = value ? " " + name : "no" + name; if (!opt.value)
if (value != def) option.pre = "no";
name = "<span style=\"font-weight: bold\">" + name + "</span><span style=\"color: gray\"> (default: " + (def ? "" : "no") + opt.name + ")</span>"; option.default = (option.default ? "" : "no") + opt.name;
list += "<tr><td>" + name + "</td></tr>";
} }
else else
{ {
if (value != def) option.value = <>={liberator.util.colorize(opt.value, false)}</>;
{
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>";
} }
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); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}, },
@@ -891,6 +898,8 @@ liberator.Options = function () //{{{
if (!filter) if (!filter)
filter = ""; filter = "";
/* Argh. Later. */
var prefArray = prefService.getChildList("", { value: 0 }); var prefArray = prefService.getChildList("", { value: 0 });
prefArray.sort(); prefArray.sort();
var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" + var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" +

View File

@@ -45,22 +45,22 @@ liberator.util = { //{{{
{ {
if (type == "number") if (type == "number")
{ {
return "<span style=\"color: red;\">" + arg + "</span>"; return <span style="color: red;">{arg}</span>;
} }
else if (type == "string") else if (type == "string")
{ {
if (processStrings) 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") else if (type == "boolean")
{ {
return "<span style=\"color: blue;\">" + arg + "</span>"; return <span style="color: blue;">{arg}</span>;
} }
else if (arg == null || arg == "undefined") 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") else if (type == "object" || type == "function")
{ {
@@ -193,7 +193,7 @@ liberator.util = { //{{{
highlightURL: function (str, force) highlightURL: function (str, force)
{ {
if (force || /^[a-zA-Z]+:\/\//.test(str)) 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 else
return str; return str;
}, },
@@ -251,6 +251,12 @@ liberator.util = { //{{{
return string; return string;
}, },
range: function (start, end)
{
while (start < end)
yield start++;
},
// same as Firefox's readFromClipboard function, but needed for apps like Thunderbird // same as Firefox's readFromClipboard function, but needed for apps like Thunderbird
readFromClipboard: function () readFromClipboard: function ()
{ {